All files / apps/web/src/handlers validation.ts

100% Statements 12/12
100% Branches 0/0
100% Functions 2/2
100% Lines 12/12

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40              70x   70x   70x           70x 70x 70x 70x 70x 53x         47x             70x   70x      
import { z } from "zod";
 
import type { CurrencyCode } from "~app/utils/currency";
import { flavored } from "~app/utils/validation";
import type { DebtId, ReceiptId, ReceiptItemId, SessionId } from "~db/ids";
import { isCurrencyCode } from "~utils/currency-data";
 
export const assignableRoleSchema = z.literal(["viewer", "editor"]);
 
export const roleSchema = assignableRoleSchema.or(z.literal("owner"));
 
export const currencyCodeSchema = flavored<CurrencyCode>(
	z.string().toUpperCase(),
).refine(isCurrencyCode, {
	params: { i18nKey: "validation.currencyDoesNotExist" },
});
 
export const receiptIdSchema = flavored<ReceiptId>(z.uuid());
export const receiptItemIdSchema = flavored<ReceiptItemId>(z.uuid());
export const sessionIdSchema = flavored<SessionId>(z.uuid());
export const debtIdSchema = flavored<DebtId>(z.uuid());
export const emailSchema = z.codec(
	z.string().refine((value) => z.email().safeParse(value).success, {
		params: { i18nKey: "validation.invalidEmail" },
	}),
	z.object({ lowercase: z.email(), original: z.email() }),
	{
		decode: (email) => ({ lowercase: email.toLowerCase(), original: email }),
		/* c8 ignore next */
		encode: ({ original }) => original,
	},
);
 
export const UUID_REGEX =
	/^[0-9A-F]{8}-[0-9A-F]{4}-[4][0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i;
 
export const MAX_INTENTIONS_AMOUNT = 3;
 
export { userIdSchema, peerIdSchema } from "~app/utils/validation";