refactor(schemas): share portable identifier and base64 patterns (#1227)

* refactor(schemas): share identifier and canonical base64 patterns

* test: hold the offset datetime schema to the validator it replaces

The module documents that its accepted set matches z.string().datetime({ offset: true }), and nothing in the suite checked that claim. Adds table-driven accept and reject cases (leap years including the 1900/2000 century pair, month, day, hour and offset ranges, fractional and omitted seconds, missing offset, basic format) plus a differential assertion that classifies every case exactly as the replaced validator does, and asserts the emitted pattern compiles under u and v while the replaced pattern does not compile under v.

---------

Co-authored-by: felipeatp <felipe.troncosopt@gmail.com>
This commit is contained in:
morluto
2026-10-09 16:47:09 +08:00
committed by GitHub
co-authored by felipeatp
parent fef38e4d22
commit 954badbaaa
14 changed files with 224 additions and 29 deletions
+3 -5
View File
@@ -1,14 +1,12 @@
import { z } from "zod";
import { CANONICAL_BASE64_PATTERN } from "../stringPatterns.js";
const unsignedHex = z.string().regex(/^0x(?:0|[1-9a-f][0-9a-f]{0,15})$/);
const index = z.number().int().nonnegative();
const scalar = z.union([z.string(), z.number().int()]);
const range = z.strictObject({ offset: unsignedHex, bytes: unsignedHex });
const canonicalBase64 = z
.string()
.regex(
/^(?:[A-Za-z0-9+\x2f]{4})*(?:[A-Za-z0-9+\x2f][AQgw]==|[A-Za-z0-9+\x2f]{2}[AEIMQUYcgkosw048]=)?$/,
);
const canonicalBase64 = z.string().regex(CANONICAL_BASE64_PATTERN);
const name = z.strictObject({
display: z.string(),
bytes_base64: canonicalBase64.nullable(),