@vielzeug/spell 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +68 -0
- package/dist/_dev.cjs +2 -0
- package/dist/_dev.cjs.map +1 -0
- package/dist/_dev.d.ts +2 -0
- package/dist/_dev.d.ts.map +1 -0
- package/dist/_dev.js +2 -0
- package/dist/_dev.js.map +1 -0
- package/dist/core.cjs +2 -0
- package/dist/core.cjs.map +1 -0
- package/dist/core.d.ts +108 -0
- package/dist/core.d.ts.map +1 -0
- package/dist/core.js +2 -0
- package/dist/core.js.map +1 -0
- package/dist/errors.cjs +3 -0
- package/dist/errors.cjs.map +1 -0
- package/dist/errors.d.ts +53 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +3 -0
- package/dist/errors.js.map +1 -0
- package/dist/formats.cjs +2 -0
- package/dist/formats.cjs.map +1 -0
- package/dist/formats.d.ts +41 -0
- package/dist/formats.d.ts.map +1 -0
- package/dist/formats.js +2 -0
- package/dist/formats.js.map +1 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1 -0
- package/dist/json-schema.cjs +2 -0
- package/dist/json-schema.cjs.map +1 -0
- package/dist/json-schema.d.ts +15 -0
- package/dist/json-schema.d.ts.map +1 -0
- package/dist/json-schema.js +2 -0
- package/dist/json-schema.js.map +1 -0
- package/dist/messages.cjs +2 -0
- package/dist/messages.cjs.map +1 -0
- package/dist/messages.d.ts +228 -0
- package/dist/messages.d.ts.map +1 -0
- package/dist/messages.js +2 -0
- package/dist/messages.js.map +1 -0
- package/dist/s.cjs +2 -0
- package/dist/s.cjs.map +1 -0
- package/dist/s.d.ts +65 -0
- package/dist/s.d.ts.map +1 -0
- package/dist/s.js +2 -0
- package/dist/s.js.map +1 -0
- package/dist/safe-object.cjs +2 -0
- package/dist/safe-object.cjs.map +1 -0
- package/dist/safe-object.d.ts +6 -0
- package/dist/safe-object.d.ts.map +1 -0
- package/dist/safe-object.js +2 -0
- package/dist/safe-object.js.map +1 -0
- package/dist/schemas/array.cjs +2 -0
- package/dist/schemas/array.cjs.map +1 -0
- package/dist/schemas/array.d.ts +49 -0
- package/dist/schemas/array.d.ts.map +1 -0
- package/dist/schemas/array.js +2 -0
- package/dist/schemas/array.js.map +1 -0
- package/dist/schemas/bigint.cjs +2 -0
- package/dist/schemas/bigint.cjs.map +1 -0
- package/dist/schemas/bigint.d.ts +42 -0
- package/dist/schemas/bigint.d.ts.map +1 -0
- package/dist/schemas/bigint.js +2 -0
- package/dist/schemas/bigint.js.map +1 -0
- package/dist/schemas/boolean.cjs +2 -0
- package/dist/schemas/boolean.cjs.map +1 -0
- package/dist/schemas/boolean.d.ts +18 -0
- package/dist/schemas/boolean.d.ts.map +1 -0
- package/dist/schemas/boolean.js +2 -0
- package/dist/schemas/boolean.js.map +1 -0
- package/dist/schemas/date.cjs +2 -0
- package/dist/schemas/date.cjs.map +1 -0
- package/dist/schemas/date.d.ts +25 -0
- package/dist/schemas/date.d.ts.map +1 -0
- package/dist/schemas/date.js +2 -0
- package/dist/schemas/date.js.map +1 -0
- package/dist/schemas/enum.cjs +2 -0
- package/dist/schemas/enum.cjs.map +1 -0
- package/dist/schemas/enum.d.ts +14 -0
- package/dist/schemas/enum.d.ts.map +1 -0
- package/dist/schemas/enum.js +2 -0
- package/dist/schemas/enum.js.map +1 -0
- package/dist/schemas/instanceof.cjs +2 -0
- package/dist/schemas/instanceof.cjs.map +1 -0
- package/dist/schemas/instanceof.d.ts +11 -0
- package/dist/schemas/instanceof.d.ts.map +1 -0
- package/dist/schemas/instanceof.js +2 -0
- package/dist/schemas/instanceof.js.map +1 -0
- package/dist/schemas/intersect.cjs +2 -0
- package/dist/schemas/intersect.cjs.map +1 -0
- package/dist/schemas/intersect.d.ts +16 -0
- package/dist/schemas/intersect.d.ts.map +1 -0
- package/dist/schemas/intersect.js +2 -0
- package/dist/schemas/intersect.js.map +1 -0
- package/dist/schemas/lazy.cjs +2 -0
- package/dist/schemas/lazy.cjs.map +1 -0
- package/dist/schemas/lazy.d.ts +16 -0
- package/dist/schemas/lazy.d.ts.map +1 -0
- package/dist/schemas/lazy.js +2 -0
- package/dist/schemas/lazy.js.map +1 -0
- package/dist/schemas/literal.cjs +2 -0
- package/dist/schemas/literal.cjs.map +1 -0
- package/dist/schemas/literal.d.ts +11 -0
- package/dist/schemas/literal.d.ts.map +1 -0
- package/dist/schemas/literal.js +2 -0
- package/dist/schemas/literal.js.map +1 -0
- package/dist/schemas/map.cjs +2 -0
- package/dist/schemas/map.cjs.map +1 -0
- package/dist/schemas/map.d.ts +29 -0
- package/dist/schemas/map.d.ts.map +1 -0
- package/dist/schemas/map.js +2 -0
- package/dist/schemas/map.js.map +1 -0
- package/dist/schemas/never.cjs +2 -0
- package/dist/schemas/never.cjs.map +1 -0
- package/dist/schemas/never.d.ts +10 -0
- package/dist/schemas/never.d.ts.map +1 -0
- package/dist/schemas/never.js +2 -0
- package/dist/schemas/never.js.map +1 -0
- package/dist/schemas/number.cjs +2 -0
- package/dist/schemas/number.cjs.map +1 -0
- package/dist/schemas/number.d.ts +50 -0
- package/dist/schemas/number.d.ts.map +1 -0
- package/dist/schemas/number.js +2 -0
- package/dist/schemas/number.js.map +1 -0
- package/dist/schemas/object.cjs +2 -0
- package/dist/schemas/object.cjs.map +1 -0
- package/dist/schemas/object.d.ts +95 -0
- package/dist/schemas/object.d.ts.map +1 -0
- package/dist/schemas/object.js +2 -0
- package/dist/schemas/object.js.map +1 -0
- package/dist/schemas/pipe.d.ts +2 -0
- package/dist/schemas/pipe.d.ts.map +1 -0
- package/dist/schemas/raw-or.cjs +2 -0
- package/dist/schemas/raw-or.cjs.map +1 -0
- package/dist/schemas/raw-or.d.ts +17 -0
- package/dist/schemas/raw-or.d.ts.map +1 -0
- package/dist/schemas/raw-or.js +2 -0
- package/dist/schemas/raw-or.js.map +1 -0
- package/dist/schemas/record.cjs +2 -0
- package/dist/schemas/record.cjs.map +1 -0
- package/dist/schemas/record.d.ts +16 -0
- package/dist/schemas/record.d.ts.map +1 -0
- package/dist/schemas/record.js +2 -0
- package/dist/schemas/record.js.map +1 -0
- package/dist/schemas/set.cjs +2 -0
- package/dist/schemas/set.cjs.map +1 -0
- package/dist/schemas/set.d.ts +28 -0
- package/dist/schemas/set.d.ts.map +1 -0
- package/dist/schemas/set.js +2 -0
- package/dist/schemas/set.js.map +1 -0
- package/dist/schemas/string.cjs +2 -0
- package/dist/schemas/string.cjs.map +1 -0
- package/dist/schemas/string.d.ts +155 -0
- package/dist/schemas/string.d.ts.map +1 -0
- package/dist/schemas/string.js +2 -0
- package/dist/schemas/string.js.map +1 -0
- package/dist/schemas/tuple.cjs +2 -0
- package/dist/schemas/tuple.cjs.map +1 -0
- package/dist/schemas/tuple.d.ts +22 -0
- package/dist/schemas/tuple.d.ts.map +1 -0
- package/dist/schemas/tuple.js +2 -0
- package/dist/schemas/tuple.js.map +1 -0
- package/dist/schemas/union.cjs +2 -0
- package/dist/schemas/union.cjs.map +1 -0
- package/dist/schemas/union.d.ts +13 -0
- package/dist/schemas/union.d.ts.map +1 -0
- package/dist/schemas/union.js +2 -0
- package/dist/schemas/union.js.map +1 -0
- package/dist/schemas/variant.cjs +2 -0
- package/dist/schemas/variant.cjs.map +1 -0
- package/dist/schemas/variant.d.ts +26 -0
- package/dist/schemas/variant.d.ts.map +1 -0
- package/dist/schemas/variant.js +2 -0
- package/dist/schemas/variant.js.map +1 -0
- package/dist/spell.cjs +3 -0
- package/dist/spell.cjs.map +1 -0
- package/dist/spell.iife.js +3 -0
- package/dist/spell.iife.js.map +1 -0
- package/dist/spell.js +3 -0
- package/dist/spell.js.map +1 -0
- package/dist/types.cjs +2 -0
- package/dist/types.cjs.map +1 -0
- package/dist/types.d.ts +326 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/validators.cjs +2 -0
- package/dist/validators.cjs.map +1 -0
- package/dist/validators.d.ts +20 -0
- package/dist/validators.d.ts.map +1 -0
- package/dist/validators.js +2 -0
- package/dist/validators.js.map +1 -0
- package/package.json +43 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formats.d.ts","sourceRoot":"","sources":["../src/formats.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,wBAAgB,OAAO,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAE1C;AAID,wBAAgB,KAAK,CAAC,CAAC,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO,CASvE;AAED,wBAAgB,MAAM,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAEzC;AAED,wBAAgB,SAAS,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAM5C;AAED,wBAAgB,aAAa,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAKhD;AAED,wBAAgB,IAAI,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAkBvC;AAED,wBAAgB,MAAM,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAEzC;AAED,wBAAgB,OAAO,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAE1C;AAED,wBAAgB,MAAM,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAEzC;AAED;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,SAAK,GAAG,OAAO,CAExD;AAED,wBAAgB,QAAQ,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAE3C;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAI9C;AAED,wBAAgB,KAAK,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAExC;AAED,wBAAgB,UAAU,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAE7C;AAED,wBAAgB,OAAO,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAE1C;AAED,wBAAgB,KAAK,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAExC;AAED,wBAAgB,MAAM,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAEzC;AAED,wBAAgB,UAAU,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAE7C;AAED,wBAAgB,QAAQ,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAI3C;AAED,wBAAgB,MAAM,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAEzC;AAED,wBAAgB,SAAS,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAE5C"}
|
package/dist/formats.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
function e(e){return/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/.test(e)}var t=new Set([`http`,`https`]);function n(e,n){try{let r=new URL(e);return(n?new Set(n.map(e=>e.toLowerCase())):t).has(r.protocol.replace(`:`,``).toLowerCase())}catch{return!1}}function r(e){return/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(e)}function i(e){if(!/^\d{4}-\d{2}-\d{2}$/.test(e))return!1;let t=new Date(e);return!Number.isNaN(t.getTime())&&t.toISOString().startsWith(e)}function a(e){return/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?(?:Z|[+-]\d{2}:\d{2})?$/.test(e)&&!Number.isNaN(new Date(e).getTime())}function o(e){if(/^(\d{1,3}\.){3}\d{1,3}$/.test(e))return e.split(`.`).every(e=>{let t=parseInt(e,10);return t>=0&&t<=255});try{return new URL(`http://[${e}]/`),!0}catch{return!1}}function s(e){return/^c[a-z0-9]{8,}$/.test(e)}function c(e){return/^[a-z][a-z0-9]{23}$/.test(e)}function l(e){return/^[0-7][0-9A-HJKMNP-TV-Z]{25}$/.test(e)}function u(e,t=21){return e.length===t&&/^[A-Za-z0-9_-]+$/.test(e)}function d(e){return/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{4})$/.test(e)}function f(e){return e.length===0||e.length%4==1?!1:/^[A-Za-z0-9_-]*={0,2}$/.test(e)}function p(e){return/^[A-Fa-f0-9]+$/.test(e)}function m(e){return/^#(?:[A-Fa-f0-9]{3}|[A-Fa-f0-9]{6}|[A-Fa-f0-9]{8})$/.test(e)}function h(e){return/^\p{Extended_Pictographic}+$/u.test(e)}function g(e){return/^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+$/.test(e)}function _(e){return/^(?:[01]\d|2[0-3]):[0-5]\d(?::[0-5]\d)?$/.test(e)}function v(e){return/^P(?=\d|T\d)(\d+Y)?(\d+M)?(\d+W)?(\d+D)?(T(\d+H)?(\d+M)?(\d+(?:\.\d+)?S)?)?$/.test(e)}function y(e){return/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[A-Za-z-][0-9A-Za-z-]*)(?:\.(?:0|[1-9]\d*|\d*[A-Za-z-][0-9A-Za-z-]*))*))?(?:\+([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?$/.test(e)}function b(e){return/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(e)}function x(e){return/^[-+]?(?:\d+\.?\d*|\.\d+)(?:e[-+]?\d+)?$/i.test(e)}export{d as isBase64,f as isBase64url,s as isCuid,c as isCuid2,v as isDuration,e as isEmail,h as isEmoji,p as isHex,m as isHexColor,o as isIp,i as isIsoDate,a as isIsoDateTime,g as isJwt,u as isNanoid,x as isNumeric,y as isSemver,b as isSlug,_ as isTime,l as isUlid,n as isUrl,r as isUuid};
|
|
2
|
+
//# sourceMappingURL=formats.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formats.js","names":[],"sources":["../src/formats.ts"],"sourcesContent":["/**\n * Pure string format validators.\n *\n * All functions take a `string` and return `boolean`. They are exported as part of the\n * public API so callers can use them independently of any Schema.\n *\n * ```ts\n * import { isEmail, isUuid } from '@vielzeug/spell';\n * isEmail('foo@bar.com'); // true\n * ```\n */\n\nexport function isEmail(v: string): boolean {\n return /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$/.test(v);\n}\n\nconst _DEFAULT_URL_PROTOCOLS = new Set(['http', 'https']);\n\nexport function isUrl(v: string, protocols?: readonly string[]): boolean {\n try {\n const parsed = new URL(v);\n const allowed = protocols ? new Set(protocols.map((p) => p.toLowerCase())) : _DEFAULT_URL_PROTOCOLS;\n\n return allowed.has(parsed.protocol.replace(':', '').toLowerCase());\n } catch {\n return false;\n }\n}\n\nexport function isUuid(v: string): boolean {\n return /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(v);\n}\n\nexport function isIsoDate(v: string): boolean {\n if (!/^\\d{4}-\\d{2}-\\d{2}$/.test(v)) return false;\n\n const d = new Date(v);\n\n return !Number.isNaN(d.getTime()) && d.toISOString().startsWith(v);\n}\n\nexport function isIsoDateTime(v: string): boolean {\n return (\n /^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}(?::\\d{2}(?:\\.\\d+)?)?(?:Z|[+-]\\d{2}:\\d{2})?$/.test(v) &&\n !Number.isNaN(new Date(v).getTime())\n );\n}\n\nexport function isIp(v: string): boolean {\n // IPv4\n if (/^(\\d{1,3}\\.){3}\\d{1,3}$/.test(v)) {\n return v.split('.').every((o) => {\n const n = parseInt(o, 10);\n\n return n >= 0 && n <= 255;\n });\n }\n\n // IPv6 — rely on URL parser\n try {\n new URL(`http://[${v}]/`);\n\n return true;\n } catch {\n return false;\n }\n}\n\nexport function isCuid(v: string): boolean {\n return /^c[a-z0-9]{8,}$/.test(v);\n}\n\nexport function isCuid2(v: string): boolean {\n return /^[a-z][a-z0-9]{23}$/.test(v);\n}\n\nexport function isUlid(v: string): boolean {\n return /^[0-7][0-9A-HJKMNP-TV-Z]{25}$/.test(v);\n}\n\n/**\n * Validates a NanoID string. The default NanoID length is 21 characters; pass a\n * custom length to validate IDs generated with non-default sizes.\n */\nexport function isNanoid(v: string, length = 21): boolean {\n return v.length === length && /^[A-Za-z0-9_-]+$/.test(v);\n}\n\nexport function isBase64(v: string): boolean {\n return /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{4})$/.test(v);\n}\n\n/**\n * Validates a base64url-encoded string (RFC 4648 §5). Accepts unpadded and padded forms.\n * A string whose length % 4 === 1 is never valid base64url.\n */\nexport function isBase64url(v: string): boolean {\n if (v.length === 0 || v.length % 4 === 1) return false;\n\n return /^[A-Za-z0-9_-]*={0,2}$/.test(v);\n}\n\nexport function isHex(v: string): boolean {\n return /^[A-Fa-f0-9]+$/.test(v);\n}\n\nexport function isHexColor(v: string): boolean {\n return /^#(?:[A-Fa-f0-9]{3}|[A-Fa-f0-9]{6}|[A-Fa-f0-9]{8})$/.test(v);\n}\n\nexport function isEmoji(v: string): boolean {\n return /^\\p{Extended_Pictographic}+$/u.test(v);\n}\n\nexport function isJwt(v: string): boolean {\n return /^[A-Za-z0-9_-]+\\.[A-Za-z0-9_-]+\\.[A-Za-z0-9_-]+$/.test(v);\n}\n\nexport function isTime(v: string): boolean {\n return /^(?:[01]\\d|2[0-3]):[0-5]\\d(?::[0-5]\\d)?$/.test(v);\n}\n\nexport function isDuration(v: string): boolean {\n return /^P(?=\\d|T\\d)(\\d+Y)?(\\d+M)?(\\d+W)?(\\d+D)?(T(\\d+H)?(\\d+M)?(\\d+(?:\\.\\d+)?S)?)?$/.test(v);\n}\n\nexport function isSemver(v: string): boolean {\n return /^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[A-Za-z-][0-9A-Za-z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[A-Za-z-][0-9A-Za-z-]*))*))?(?:\\+([0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*))?$/.test(\n v,\n );\n}\n\nexport function isSlug(v: string): boolean {\n return /^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(v);\n}\n\nexport function isNumeric(v: string): boolean {\n return /^[-+]?(?:\\d+\\.?\\d*|\\.\\d+)(?:e[-+]?\\d+)?$/i.test(v);\n}\n"],"mappings":"AAYA,SAAgB,EAAQ,EAAoB,CAC1C,MAAO,mDAAmD,KAAK,CAAC,CAClE,CAEA,IAAM,EAAyB,IAAI,IAAI,CAAC,OAAQ,OAAO,CAAC,EAExD,SAAgB,EAAM,EAAW,EAAwC,CACvE,GAAI,CACF,IAAM,EAAS,IAAI,IAAI,CAAC,EAGxB,OAFgB,EAAY,IAAI,IAAI,EAAU,IAAK,GAAM,EAAE,YAAY,CAAC,CAAC,EAAI,EAAA,CAE9D,IAAI,EAAO,SAAS,QAAQ,IAAK,EAAE,CAAC,CAAC,YAAY,CAAC,CACnE,MAAQ,CACN,MAAO,EACT,CACF,CAEA,SAAgB,EAAO,EAAoB,CACzC,MAAO,kEAAkE,KAAK,CAAC,CACjF,CAEA,SAAgB,EAAU,EAAoB,CAC5C,GAAI,CAAC,sBAAsB,KAAK,CAAC,EAAG,MAAO,GAE3C,IAAM,EAAI,IAAI,KAAK,CAAC,EAEpB,MAAO,CAAC,OAAO,MAAM,EAAE,QAAQ,CAAC,GAAK,EAAE,YAAY,CAAC,CAAC,WAAW,CAAC,CACnE,CAEA,SAAgB,EAAc,EAAoB,CAChD,MACE,6EAA6E,KAAK,CAAC,GACnF,CAAC,OAAO,MAAM,IAAI,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC,CAEvC,CAEA,SAAgB,EAAK,EAAoB,CAEvC,GAAI,0BAA0B,KAAK,CAAC,EAClC,OAAO,EAAE,MAAM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B,CAC5C,MAAO,4CAA4C,KAAK,CAAC,CAC3D"}
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./types.cjs"),t=require("./errors.cjs"),n=require("./json-schema.cjs"),r=require("./messages.cjs"),i=require("./core.cjs"),a=require("./validators.cjs"),o=require("./formats.cjs"),s=require("./s.cjs");exports.ErrorCode=e.ErrorCode,exports.PipeSchema=i.PipeSchema,exports.Schema=i.Schema,exports.SpellError=t.SpellError,exports.SpellValidationError=t.SpellValidationError,exports.descriptorToJsonSchema=n.descriptorToJsonSchema,exports.errorsAt=t.errorsAt,exports.fail=t.fail,exports.hasMaxLength=a.hasMaxLength,exports.hasMinLength=a.hasMinLength,exports.isArray=a.isArray,exports.isBase64=o.isBase64,exports.isBase64url=o.isBase64url,exports.isBoolean=a.isBoolean,exports.isCuid=o.isCuid,exports.isCuid2=o.isCuid2,exports.isDate=a.isDate,exports.isDuration=o.isDuration,exports.isEmail=o.isEmail,exports.isEmoji=o.isEmoji,exports.isHex=o.isHex,exports.isHexColor=o.isHexColor,exports.isInRange=a.isInRange,exports.isInteger=a.isInteger,exports.isIp=o.isIp,exports.isIsoDate=o.isIsoDate,exports.isIsoDateTime=o.isIsoDateTime,exports.isJwt=o.isJwt,exports.isMultipleOf=a.isMultipleOf,exports.isNanoid=o.isNanoid,exports.isNegative=a.isNegative,exports.isNonNegative=a.isNonNegative,exports.isNullOrUndefined=a.isNullOrUndefined,exports.isNumber=a.isNumber,exports.isNumeric=o.isNumeric,exports.isPositive=a.isPositive,exports.isSemver=o.isSemver,exports.isSlug=o.isSlug,exports.isString=a.isString,exports.isTime=o.isTime,exports.isUlid=o.isUlid,exports.isUrl=o.isUrl,exports.isUuid=o.isUuid,exports.prependIssuePath=t.prependIssuePath,exports.resetMessages=r.resetMessages,exports.s=s.s,exports.schemaToJsonSchema=n.schemaToJsonSchema,exports.setLogger=r.setLogger,exports.setMessages=r.setMessages;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { ErrorCode, PipeSchema, Schema, SpellError, SpellValidationError, errorsAt, fail, type AnySchema, type CheckContext, type FlatError, type FlatErrorFirst, type FormattedErrors, type Infer, type InferInput, type InferOutput, type Issue, type JsonSchema, type MessageFn, type Messages, type ParseContext, type ParseResult, type SchemaDescriptor, type SchemaWalker, type ValidateFn, type ValidateResult, prependIssuePath, } from './core';
|
|
2
|
+
export { resetMessages, setLogger, setMessages, type DeepPartial, type Logger } from './messages';
|
|
3
|
+
export { descriptorToJsonSchema, schemaToJsonSchema } from './json-schema';
|
|
4
|
+
export { hasMaxLength, hasMinLength, isArray, isBoolean, isDate, isInteger, isMultipleOf, isNegative, isNonNegative, isNullOrUndefined, isNumber, isPositive, isString, isInRange, } from './validators';
|
|
5
|
+
export { isBase64, isBase64url, isCuid, isCuid2, isDuration, isEmail, isEmoji, isHex, isHexColor, isIp, isIsoDate, isIsoDateTime, isJwt, isNanoid, isNumeric, isSemver, isSlug, isTime, isUlid, isUrl, isUuid, } from './formats';
|
|
6
|
+
export { s } from './s';
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,UAAU,EACV,MAAM,EACN,UAAU,EACV,oBAAoB,EACpB,QAAQ,EACR,IAAI,EACJ,KAAK,SAAS,EACd,KAAK,YAAY,EACjB,KAAK,SAAS,EACd,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,KAAK,KAAK,EACV,KAAK,UAAU,EACf,KAAK,WAAW,EAChB,KAAK,KAAK,EACV,KAAK,UAAU,EACf,KAAK,SAAS,EACd,KAAK,QAAQ,EACb,KAAK,YAAY,EACjB,KAAK,WAAW,EAChB,KAAK,gBAAgB,EACrB,KAAK,YAAY,EACjB,KAAK,UAAU,EACf,KAAK,cAAc,EACnB,gBAAgB,GACjB,MAAM,QAAQ,CAAC;AAEhB,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,WAAW,EAAE,KAAK,WAAW,EAAE,KAAK,MAAM,EAAE,MAAM,YAAY,CAAC;AAElG,OAAO,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAE3E,OAAO,EACL,YAAY,EACZ,YAAY,EACZ,OAAO,EACP,SAAS,EACT,MAAM,EACN,SAAS,EACT,YAAY,EACZ,UAAU,EACV,aAAa,EACb,iBAAiB,EACjB,QAAQ,EACR,UAAU,EACV,QAAQ,EACR,SAAS,GACV,MAAM,cAAc,CAAC;AAEtB,OAAO,EACL,QAAQ,EACR,WAAW,EACX,MAAM,EACN,OAAO,EACP,UAAU,EACV,OAAO,EACP,OAAO,EACP,KAAK,EACL,UAAU,EACV,IAAI,EACJ,SAAS,EACT,aAAa,EACb,KAAK,EACL,QAAQ,EACR,SAAS,EACT,QAAQ,EACR,MAAM,EACN,MAAM,EACN,MAAM,EACN,KAAK,EACL,MAAM,GACP,MAAM,WAAW,CAAC;AAEnB,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{ErrorCode as e}from"./types.js";import{SpellError as t,SpellValidationError as n,errorsAt as r,fail as i,prependIssuePath as a}from"./errors.js";import{descriptorToJsonSchema as o,schemaToJsonSchema as s}from"./json-schema.js";import{resetMessages as c,setLogger as l,setMessages as u}from"./messages.js";import{PipeSchema as d,Schema as f}from"./core.js";import{hasMaxLength as p,hasMinLength as m,isArray as h,isBoolean as g,isDate as _,isInRange as v,isInteger as y,isMultipleOf as b,isNegative as x,isNonNegative as S,isNullOrUndefined as C,isNumber as w,isPositive as T,isString as E}from"./validators.js";import{isBase64 as D,isBase64url as O,isCuid as k,isCuid2 as A,isDuration as j,isEmail as M,isEmoji as N,isHex as P,isHexColor as F,isIp as I,isIsoDate as L,isIsoDateTime as R,isJwt as z,isNanoid as B,isNumeric as V,isSemver as H,isSlug as U,isTime as W,isUlid as G,isUrl as K,isUuid as q}from"./formats.js";import{s as J}from"./s.js";export{e as ErrorCode,d as PipeSchema,f as Schema,t as SpellError,n as SpellValidationError,o as descriptorToJsonSchema,r as errorsAt,i as fail,p as hasMaxLength,m as hasMinLength,h as isArray,D as isBase64,O as isBase64url,g as isBoolean,k as isCuid,A as isCuid2,_ as isDate,j as isDuration,M as isEmail,N as isEmoji,P as isHex,F as isHexColor,v as isInRange,y as isInteger,I as isIp,L as isIsoDate,R as isIsoDateTime,z as isJwt,b as isMultipleOf,B as isNanoid,x as isNegative,S as isNonNegative,C as isNullOrUndefined,w as isNumber,V as isNumeric,T as isPositive,H as isSemver,U as isSlug,E as isString,W as isTime,G as isUlid,K as isUrl,q as isUuid,a as prependIssuePath,c as resetMessages,J as s,s as schemaToJsonSchema,l as setLogger,u as setMessages};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const e=require("./safe-object.cjs");function t(e){return n(e.toDescriptor())}function n(e){let t=r(e),n=t;return e.isNullable&&(n={anyOf:[t,{type:`null`}]}),e.description&&(n={...n,description:e.description}),n}function r(t){switch(t.kind){case`any`:case`unknown`:return{};case`array`:{let e={items:n(t.items),type:`array`};return t.minItems!==void 0&&(e.minItems=t.minItems),t.maxItems!==void 0&&(e.maxItems=t.maxItems),e}case`bigint`:return{type:`integer`};case`boolean`:return{type:`boolean`};case`date`:return{$comment:`Date objects are not representable in JSON Schema. Validate as a string with a date format in JSON contexts.`};case`enum`:return{enum:[...t.values]};case`instanceof`:return{$comment:`Instances of "${t.className}" are not representable in JSON Schema.`};case`intersect`:return{allOf:t.branches.map(n)};case`lazy`:return{};case`literal`:return t.value===null?{type:`null`}:t.value===void 0?{}:{const:t.value};case`map`:return{$comment:`Map type — represented as an object with arbitrary string keys.`,additionalProperties:n(t.value),type:`object`};case`never`:return{not:{}};case`number`:{let e={type:t.typeHint===`integer`?`integer`:`number`};return t.minimum!==void 0&&(e.minimum=t.minimum),t.maximum!==void 0&&(e.maximum=t.maximum),t.exclusiveMinimum!==void 0&&(e.exclusiveMinimum=t.exclusiveMinimum),t.exclusiveMaximum!==void 0&&(e.exclusiveMaximum=t.exclusiveMaximum),t.multipleOf!==void 0&&(e.multipleOf=t.multipleOf),e}case`object`:{let r={},i=[];for(let[a,o]of Object.entries(t.fields))e.defineOwnProperty(r,a,n(o)),o.isOptional||i.push(a);let a={properties:r,type:`object`};return i.length>0&&(a.required=i),t.strict&&(a.additionalProperties=!1),a}case`pipe`:return n(t.to);case`record`:return{additionalProperties:n(t.value),type:`object`};case`set`:return{$comment:`Set<T> — no standard JSON Schema equivalent; treated as an ordered unique-item array.`,items:n(t.items),type:`array`,uniqueItems:!0};case`string`:{let e={type:`string`};return t.minLength!==void 0&&(e.minLength=t.minLength),t.maxLength!==void 0&&(e.maxLength=t.maxLength),t.pattern!=null&&(e.pattern=t.pattern),t.format!==void 0&&(e.format=t.format),t.contentEncoding!==void 0&&(e.contentEncoding=t.contentEncoding),e}case`tuple`:{let e={prefixItems:t.items.map(n),type:`array`};return t.rest===null?e.items=!1:e.items=n(t.rest),e}case`union`:return{anyOf:t.branches.map(n)};case`variant`:return{discriminator:{propertyName:t.discriminator},oneOf:Object.values(t.branches).map(n)}}}exports.descriptorToJsonSchema=n,exports.schemaToJsonSchema=t;
|
|
2
|
+
//# sourceMappingURL=json-schema.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json-schema.cjs","names":[],"sources":["../src/json-schema.ts"],"sourcesContent":["import type { AnySchema, JsonSchema, SchemaDescriptor } from './types';\n\nimport { defineOwnProperty } from './safe-object';\n\n/**\n * Converts a `Schema` to a JSON Schema object by first calling `toDescriptor()`.\n * This is the entry point used by `Schema.toJsonSchema()`.\n */\nexport function schemaToJsonSchema(schema: AnySchema): JsonSchema {\n return descriptorToJsonSchema(schema.toDescriptor());\n}\n\n/**\n * Converts a `SchemaDescriptor` to a JSON Schema object (draft 2020-12 compatible).\n *\n * This is the single authoritative JSON Schema serializer. `Schema.toJsonSchema()`\n * delegates to this function so there is one code path for both introspection and\n * JSON Schema output.\n */\nexport function descriptorToJsonSchema(d: SchemaDescriptor): JsonSchema {\n const base = _descriptorToBase(d);\n let result: JsonSchema = base;\n\n if (d.isNullable) result = { anyOf: [base, { type: 'null' }] };\n\n if (d.description) result = { ...result, description: d.description };\n\n return result;\n}\n\nfunction _descriptorToBase(d: SchemaDescriptor): JsonSchema {\n switch (d.kind) {\n case 'any':\n case 'unknown':\n return {};\n\n case 'array': {\n const out: JsonSchema = { items: descriptorToJsonSchema(d.items), type: 'array' };\n\n if (d.minItems !== undefined) out['minItems'] = d.minItems;\n\n if (d.maxItems !== undefined) out['maxItems'] = d.maxItems;\n\n return out;\n }\n\n case 'bigint':\n return { type: 'integer' };\n\n case 'boolean':\n return { type: 'boolean' };\n\n case 'date':\n return {\n $comment:\n 'Date objects are not representable in JSON Schema. Validate as a string with a date format in JSON contexts.',\n };\n\n case 'enum':\n return { enum: [...d.values] };\n\n case 'instanceof':\n return {\n $comment: `Instances of \"${d.className}\" are not representable in JSON Schema.`,\n };\n\n case 'intersect':\n return { allOf: d.branches.map(descriptorToJsonSchema) };\n\n case 'lazy':\n return {};\n\n case 'literal':\n if (d.value === null) return { type: 'null' };\n\n if (d.value === undefined) return {};\n\n return { const: d.value };\n\n case 'map':\n return {\n $comment: 'Map type — represented as an object with arbitrary string keys.',\n additionalProperties: descriptorToJsonSchema(d.value),\n type: 'object',\n };\n\n case 'never':\n return { not: {} };\n\n case 'number': {\n const out: JsonSchema = { type: d.typeHint === 'integer' ? 'integer' : 'number' };\n\n if (d.minimum !== undefined) out['minimum'] = d.minimum;\n\n if (d.maximum !== undefined) out['maximum'] = d.maximum;\n\n if (d.exclusiveMinimum !== undefined) out['exclusiveMinimum'] = d.exclusiveMinimum;\n\n if (d.exclusiveMaximum !== undefined) out['exclusiveMaximum'] = d.exclusiveMaximum;\n\n if (d.multipleOf !== undefined) out['multipleOf'] = d.multipleOf;\n\n return out;\n }\n\n case 'object': {\n const properties: Record<string, JsonSchema> = {};\n const required: string[] = [];\n\n for (const [key, fieldDescriptor] of Object.entries(d.fields)) {\n defineOwnProperty(properties, key, descriptorToJsonSchema(fieldDescriptor));\n\n if (!fieldDescriptor.isOptional) required.push(key);\n }\n\n const out: JsonSchema = { properties, type: 'object' };\n\n if (required.length > 0) out['required'] = required;\n\n if (d.strict) out['additionalProperties'] = false;\n\n return out;\n }\n\n case 'pipe':\n return descriptorToJsonSchema(d.to);\n\n case 'record':\n return {\n additionalProperties: descriptorToJsonSchema(d.value),\n type: 'object',\n };\n\n case 'set':\n return {\n $comment: 'Set<T> — no standard JSON Schema equivalent; treated as an ordered unique-item array.',\n items: descriptorToJsonSchema(d.items),\n type: 'array',\n uniqueItems: true,\n };\n\n case 'string': {\n const out: JsonSchema = { type: 'string' };\n\n if (d.minLength !== undefined) out['minLength'] = d.minLength;\n\n if (d.maxLength !== undefined) out['maxLength'] = d.maxLength;\n\n if (d.pattern != null) out['pattern'] = d.pattern;\n\n if (d.format !== undefined) out['format'] = d.format;\n\n if (d.contentEncoding !== undefined) out['contentEncoding'] = d.contentEncoding;\n\n return out;\n }\n\n case 'tuple': {\n const out: JsonSchema = {\n prefixItems: d.items.map(descriptorToJsonSchema),\n type: 'array',\n };\n\n if (d.rest !== null) {\n out['items'] = descriptorToJsonSchema(d.rest);\n } else {\n out['items'] = false;\n }\n\n return out;\n }\n\n case 'union':\n return { anyOf: d.branches.map(descriptorToJsonSchema) };\n case 'variant':\n return {\n discriminator: { propertyName: d.discriminator },\n oneOf: Object.values(d.branches).map(descriptorToJsonSchema),\n };\n }\n}\n"],"mappings":"qCAQA,SAAgB,EAAmB,EAA+B,CAChE,OAAO,EAAuB,EAAO,aAAa,CAAC,CACrD,CASA,SAAgB,EAAuB,EAAiC,CACtE,IAAM,EAAO,EAAkB,CAAC,EAC5B,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,EAAE,IAAI,EAKvC,CACT,CAEA,IAAK,QACH,MAAO,CAAE,MAAO,EAAE,SAAS,IAAI,CAAsB,CAAE,EACzD,IAAK,UACH,MAAO,CACL,cAAe,CAAE,aAAc,EAAE,aAAc,EAC/C,MAAO,OAAO,OAAO,EAAE,QAAQ,CAAC,CAAC,IAAI,CAAsB,CAC7D,CACJ,CACF"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { AnySchema, JsonSchema, SchemaDescriptor } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Converts a `Schema` to a JSON Schema object by first calling `toDescriptor()`.
|
|
4
|
+
* This is the entry point used by `Schema.toJsonSchema()`.
|
|
5
|
+
*/
|
|
6
|
+
export declare function schemaToJsonSchema(schema: AnySchema): JsonSchema;
|
|
7
|
+
/**
|
|
8
|
+
* Converts a `SchemaDescriptor` to a JSON Schema object (draft 2020-12 compatible).
|
|
9
|
+
*
|
|
10
|
+
* This is the single authoritative JSON Schema serializer. `Schema.toJsonSchema()`
|
|
11
|
+
* delegates to this function so there is one code path for both introspection and
|
|
12
|
+
* JSON Schema output.
|
|
13
|
+
*/
|
|
14
|
+
export declare function descriptorToJsonSchema(d: SchemaDescriptor): JsonSchema;
|
|
15
|
+
//# sourceMappingURL=json-schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json-schema.d.ts","sourceRoot":"","sources":["../src/json-schema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAIvE;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,SAAS,GAAG,UAAU,CAEhE;AAED;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CAAC,CAAC,EAAE,gBAAgB,GAAG,UAAU,CAStE"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{defineOwnProperty as e}from"./safe-object.js";function t(e){return n(e.toDescriptor())}function n(e){let t=r(e),n=t;return e.isNullable&&(n={anyOf:[t,{type:`null`}]}),e.description&&(n={...n,description:e.description}),n}function r(t){switch(t.kind){case`any`:case`unknown`:return{};case`array`:{let e={items:n(t.items),type:`array`};return t.minItems!==void 0&&(e.minItems=t.minItems),t.maxItems!==void 0&&(e.maxItems=t.maxItems),e}case`bigint`:return{type:`integer`};case`boolean`:return{type:`boolean`};case`date`:return{$comment:`Date objects are not representable in JSON Schema. Validate as a string with a date format in JSON contexts.`};case`enum`:return{enum:[...t.values]};case`instanceof`:return{$comment:`Instances of "${t.className}" are not representable in JSON Schema.`};case`intersect`:return{allOf:t.branches.map(n)};case`lazy`:return{};case`literal`:return t.value===null?{type:`null`}:t.value===void 0?{}:{const:t.value};case`map`:return{$comment:`Map type — represented as an object with arbitrary string keys.`,additionalProperties:n(t.value),type:`object`};case`never`:return{not:{}};case`number`:{let e={type:t.typeHint===`integer`?`integer`:`number`};return t.minimum!==void 0&&(e.minimum=t.minimum),t.maximum!==void 0&&(e.maximum=t.maximum),t.exclusiveMinimum!==void 0&&(e.exclusiveMinimum=t.exclusiveMinimum),t.exclusiveMaximum!==void 0&&(e.exclusiveMaximum=t.exclusiveMaximum),t.multipleOf!==void 0&&(e.multipleOf=t.multipleOf),e}case`object`:{let r={},i=[];for(let[a,o]of Object.entries(t.fields))e(r,a,n(o)),o.isOptional||i.push(a);let a={properties:r,type:`object`};return i.length>0&&(a.required=i),t.strict&&(a.additionalProperties=!1),a}case`pipe`:return n(t.to);case`record`:return{additionalProperties:n(t.value),type:`object`};case`set`:return{$comment:`Set<T> — no standard JSON Schema equivalent; treated as an ordered unique-item array.`,items:n(t.items),type:`array`,uniqueItems:!0};case`string`:{let e={type:`string`};return t.minLength!==void 0&&(e.minLength=t.minLength),t.maxLength!==void 0&&(e.maxLength=t.maxLength),t.pattern!=null&&(e.pattern=t.pattern),t.format!==void 0&&(e.format=t.format),t.contentEncoding!==void 0&&(e.contentEncoding=t.contentEncoding),e}case`tuple`:{let e={prefixItems:t.items.map(n),type:`array`};return t.rest===null?e.items=!1:e.items=n(t.rest),e}case`union`:return{anyOf:t.branches.map(n)};case`variant`:return{discriminator:{propertyName:t.discriminator},oneOf:Object.values(t.branches).map(n)}}}export{n as descriptorToJsonSchema,t as schemaToJsonSchema};
|
|
2
|
+
//# sourceMappingURL=json-schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json-schema.js","names":[],"sources":["../src/json-schema.ts"],"sourcesContent":["import type { AnySchema, JsonSchema, SchemaDescriptor } from './types';\n\nimport { defineOwnProperty } from './safe-object';\n\n/**\n * Converts a `Schema` to a JSON Schema object by first calling `toDescriptor()`.\n * This is the entry point used by `Schema.toJsonSchema()`.\n */\nexport function schemaToJsonSchema(schema: AnySchema): JsonSchema {\n return descriptorToJsonSchema(schema.toDescriptor());\n}\n\n/**\n * Converts a `SchemaDescriptor` to a JSON Schema object (draft 2020-12 compatible).\n *\n * This is the single authoritative JSON Schema serializer. `Schema.toJsonSchema()`\n * delegates to this function so there is one code path for both introspection and\n * JSON Schema output.\n */\nexport function descriptorToJsonSchema(d: SchemaDescriptor): JsonSchema {\n const base = _descriptorToBase(d);\n let result: JsonSchema = base;\n\n if (d.isNullable) result = { anyOf: [base, { type: 'null' }] };\n\n if (d.description) result = { ...result, description: d.description };\n\n return result;\n}\n\nfunction _descriptorToBase(d: SchemaDescriptor): JsonSchema {\n switch (d.kind) {\n case 'any':\n case 'unknown':\n return {};\n\n case 'array': {\n const out: JsonSchema = { items: descriptorToJsonSchema(d.items), type: 'array' };\n\n if (d.minItems !== undefined) out['minItems'] = d.minItems;\n\n if (d.maxItems !== undefined) out['maxItems'] = d.maxItems;\n\n return out;\n }\n\n case 'bigint':\n return { type: 'integer' };\n\n case 'boolean':\n return { type: 'boolean' };\n\n case 'date':\n return {\n $comment:\n 'Date objects are not representable in JSON Schema. Validate as a string with a date format in JSON contexts.',\n };\n\n case 'enum':\n return { enum: [...d.values] };\n\n case 'instanceof':\n return {\n $comment: `Instances of \"${d.className}\" are not representable in JSON Schema.`,\n };\n\n case 'intersect':\n return { allOf: d.branches.map(descriptorToJsonSchema) };\n\n case 'lazy':\n return {};\n\n case 'literal':\n if (d.value === null) return { type: 'null' };\n\n if (d.value === undefined) return {};\n\n return { const: d.value };\n\n case 'map':\n return {\n $comment: 'Map type — represented as an object with arbitrary string keys.',\n additionalProperties: descriptorToJsonSchema(d.value),\n type: 'object',\n };\n\n case 'never':\n return { not: {} };\n\n case 'number': {\n const out: JsonSchema = { type: d.typeHint === 'integer' ? 'integer' : 'number' };\n\n if (d.minimum !== undefined) out['minimum'] = d.minimum;\n\n if (d.maximum !== undefined) out['maximum'] = d.maximum;\n\n if (d.exclusiveMinimum !== undefined) out['exclusiveMinimum'] = d.exclusiveMinimum;\n\n if (d.exclusiveMaximum !== undefined) out['exclusiveMaximum'] = d.exclusiveMaximum;\n\n if (d.multipleOf !== undefined) out['multipleOf'] = d.multipleOf;\n\n return out;\n }\n\n case 'object': {\n const properties: Record<string, JsonSchema> = {};\n const required: string[] = [];\n\n for (const [key, fieldDescriptor] of Object.entries(d.fields)) {\n defineOwnProperty(properties, key, descriptorToJsonSchema(fieldDescriptor));\n\n if (!fieldDescriptor.isOptional) required.push(key);\n }\n\n const out: JsonSchema = { properties, type: 'object' };\n\n if (required.length > 0) out['required'] = required;\n\n if (d.strict) out['additionalProperties'] = false;\n\n return out;\n }\n\n case 'pipe':\n return descriptorToJsonSchema(d.to);\n\n case 'record':\n return {\n additionalProperties: descriptorToJsonSchema(d.value),\n type: 'object',\n };\n\n case 'set':\n return {\n $comment: 'Set<T> — no standard JSON Schema equivalent; treated as an ordered unique-item array.',\n items: descriptorToJsonSchema(d.items),\n type: 'array',\n uniqueItems: true,\n };\n\n case 'string': {\n const out: JsonSchema = { type: 'string' };\n\n if (d.minLength !== undefined) out['minLength'] = d.minLength;\n\n if (d.maxLength !== undefined) out['maxLength'] = d.maxLength;\n\n if (d.pattern != null) out['pattern'] = d.pattern;\n\n if (d.format !== undefined) out['format'] = d.format;\n\n if (d.contentEncoding !== undefined) out['contentEncoding'] = d.contentEncoding;\n\n return out;\n }\n\n case 'tuple': {\n const out: JsonSchema = {\n prefixItems: d.items.map(descriptorToJsonSchema),\n type: 'array',\n };\n\n if (d.rest !== null) {\n out['items'] = descriptorToJsonSchema(d.rest);\n } else {\n out['items'] = false;\n }\n\n return out;\n }\n\n case 'union':\n return { anyOf: d.branches.map(descriptorToJsonSchema) };\n case 'variant':\n return {\n discriminator: { propertyName: d.discriminator },\n oneOf: Object.values(d.branches).map(descriptorToJsonSchema),\n };\n }\n}\n"],"mappings":"qDAQA,SAAgB,EAAmB,EAA+B,CAChE,OAAO,EAAuB,EAAO,aAAa,CAAC,CACrD,CASA,SAAgB,EAAuB,EAAiC,CACtE,IAAM,EAAO,EAAkB,CAAC,EAC5B,EAAqB,EAMzB,OAJI,EAAE,aAAY,EAAS,CAAE,MAAO,CAAC,EAAM,CAAE,KAAM,MAAO,CAAC,CAAE,GAEzD,EAAE,cAAa,EAAS,CAAE,GAAG,EAAQ,YAAa,EAAE,WAAY,GAE7D,CACT,CAEA,SAAS,EAAkB,EAAiC,CAC1D,OAAQ,EAAE,KAAV,CACE,IAAK,MACL,IAAK,UACH,MAAO,CAAC,EAEV,IAAK,QAAS,CACZ,IAAM,EAAkB,CAAE,MAAO,EAAuB,EAAE,KAAK,EAAG,KAAM,OAAQ,EAMhF,OAJI,EAAE,WAAa,IAAA,KAAW,EAAI,SAAc,EAAE,UAE9C,EAAE,WAAa,IAAA,KAAW,EAAI,SAAc,EAAE,UAE3C,CACT,CAEA,IAAK,SACH,MAAO,CAAE,KAAM,SAAU,EAE3B,IAAK,UACH,MAAO,CAAE,KAAM,SAAU,EAE3B,IAAK,OACH,MAAO,CACL,SACE,8GACJ,EAEF,IAAK,OACH,MAAO,CAAE,KAAM,CAAC,GAAG,EAAE,MAAM,CAAE,EAE/B,IAAK,aACH,MAAO,CACL,SAAU,iBAA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ACV,MAAO,EAAuB,EAAE,KAAK,EACrC,KAAM,QACN,YAAa,EACf,EAEF,IAAK,SAAU,CACb,IAAM,EAAkB,CAAE,KAAM,QAAS,EAYzC,OAVI,EAAE,YAAc,IAAA,KAAW,EAAI,UAAe,EAAE,WAEhD,EAAE,YAAc,IAAA,KAAW,EAAI,UAAe,EAAE,WAEhD,EAAE,SAAW,OAAM,EAAI,QAAa,EAAE,SAEtC,EAAE,SAAW,IAAA,KAAW,EAAI,OAAY,EAAE,QAE1C,EAAE,kBAAoB,IAAA,KAAW,EAAI,gBAAqB,EAAE,iBAEzD,CACT,CAEA,IAAK,QAAS,CACZ,IAAM,EAAkB,CACtB,YAAa,EAAE,MAAM,IAAI,CAAsB,EAC/C,KAAM,OACR,EAQA,OANI,EAAE,OAAS,KAGb,EAAI,MAAW,GAFf,EAAI,MAAW,EAAuB,EAAE,IAAI,EAKvC,CACT,CAEA,IAAK,QACH,MAAO,CAAE,MAAO,EAAE,SAAS,IAAI,CAAsB,CAAE,EACzD,IAAK,UACH,MAAO,CACL,cAAe,CAAE,aAAc,EAAE,aAAc,EAC/C,MAAO,OAAO,OAAO,EAAE,QAAQ,CAAC,CAAC,IAAI,CAAsB,CAC7D,CACJ,CACF"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const e=require("./safe-object.cjs"),t=require("./_dev.cjs");var n={array:{length:({exact:e})=>`Must have exactly ${e} items`,max:({max:e})=>`Must have at most ${e} items`,min:({min:e})=>`Must have at least ${e} items`,nonEmpty:()=>`Cannot be empty`,type:()=>`Expected array`,unique:()=>`All items must be unique`},bigint:{max:({max:e})=>`Must be at most ${e}`,min:({min:e})=>`Must be at least ${e}`,multipleOf:({step:e})=>`Must be a multiple of ${e}`,negative:()=>`Must be negative`,nonNegative:()=>`Must be non-negative`,nonPositive:()=>`Must be non-positive`,positive:()=>`Must be positive`,type:()=>`Expected bigint`},boolean:{type:()=>`Expected boolean`},check:{default:()=>`Invalid value`},date:{max:({max:e})=>`Must be before ${e.toISOString()}`,min:({min:e})=>`Must be after ${e.toISOString()}`,type:()=>`Expected valid date`},enum:{invalid:({values:e})=>`Expected one of: ${e.map(e=>JSON.stringify(e)).join(`, `)}`},instanceof:{type:({className:e})=>`Expected instance of ${e}`},literal:{expected:({expected:e})=>`Expected ${JSON.stringify(e)}`},map:{max:({max:e})=>`Must contain at most ${e} entries`,min:({min:e})=>`Must contain at least ${e} entries`,nonEmpty:()=>`Cannot be empty`,size:({exact:e})=>`Must contain exactly ${e} entries`,type:()=>`Expected map`},never:{invalid:()=>`Value is not allowed`},number:{finite:()=>`Must be finite`,int:()=>`Must be an integer`,max:({max:e})=>`Must be at most ${e}`,min:({min:e})=>`Must be at least ${e}`,multipleOf:({step:e})=>`Must be a multiple of ${e}`,negative:()=>`Must be negative`,nonNegative:()=>`Must be non-negative`,nonPositive:()=>`Must be non-positive`,positive:()=>`Must be positive`,safe:()=>`Must be a safe integer`,type:()=>`Expected number`},object:{invalidKeys:({keys:e})=>`Unrecognized keys: ${e.join(`, `)}`,type:()=>`Expected object`},set:{max:({max:e})=>`Must contain at most ${e} items`,min:({min:e})=>`Must contain at least ${e} items`,nonEmpty:()=>`Cannot be empty`,size:({exact:e})=>`Must contain exactly ${e} items`,type:()=>`Expected set`},string:{base64:()=>`Invalid base64`,base64url:()=>`Invalid base64url`,cuid:()=>`Invalid CUID`,cuid2:()=>`Invalid CUID2`,date:()=>`Invalid date`,dateTime:()=>`Invalid datetime`,duration:()=>`Invalid ISO 8601 duration`,email:()=>`Invalid email address`,emoji:()=>`Invalid emoji sequence`,endsWith:({suffix:e})=>`Must end with "${e}"`,hex:()=>`Invalid hex`,hexColor:()=>`Invalid hex color`,includes:({substr:e})=>`Must include "${e}"`,ip:()=>`Invalid IP address`,jwt:()=>`Invalid JWT`,length:({exact:e})=>`Must be exactly ${e} characters`,max:({max:e})=>`Must be at most ${e} characters`,min:({min:e})=>`Must be at least ${e} characters`,nanoid:()=>`Invalid NanoID`,nonEmpty:()=>`Cannot be empty`,numeric:()=>`Invalid numeric string`,regex:()=>`Invalid format`,semver:()=>`Invalid semver`,slug:()=>`Invalid slug`,startsWith:({prefix:e})=>`Must start with "${e}"`,time:()=>`Invalid time`,type:()=>`Expected string`,ulid:()=>`Invalid ULID`,url:()=>`Invalid URL`,uuid:()=>`Invalid UUID`},tuple:{length:({exact:e})=>`Expected tuple of length ${e}`,min:({min:e})=>`Expected tuple with at least ${e} items`,type:()=>`Expected array`},union:{invalid:()=>`Does not match any of the expected types`},variant:{invalidDiscriminator:({discriminator:e,expected:t})=>`Invalid discriminator value at "${e}": expected ${t.map(e=>JSON.stringify(e)).join(` | `)}`,type:()=>`Expected object`}},r=n,i=e=>{t.warn(e)};function a(e){i(e)}function o(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function s(t,n){let r=e.cloneRecord(t);for(let[t,i]of Object.entries(n)){if(i===void 0)continue;if(e.isUnsafeObjectKey(t)){a(`[spell] Ignoring unsafe message override key "${t}" to prevent prototype mutation.`);continue}let n=r[t];o(n)&&o(i)?e.defineOwnProperty(r,t,s(n,i)):e.defineOwnProperty(r,t,i)}return r}function c(e){r=s(n,e)}function l(e){i=e??(()=>{})}function u(){r=n}function d(){return r}exports._dev=a,exports._messages=d,exports.resetMessages=u,exports.setLogger=l,exports.setMessages=c;
|
|
2
|
+
//# sourceMappingURL=messages.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messages.cjs","names":[],"sources":["../src/messages.ts"],"sourcesContent":["import { warn as _warnFn } from './_dev';\nimport { cloneRecord, defineOwnProperty, isUnsafeObjectKey } from './safe-object';\n\nexport type Messages = {\n array: {\n length: (ctx: { exact: number; value: unknown[] }) => string;\n max: (ctx: { max: number; value: unknown[] }) => string;\n min: (ctx: { min: number; value: unknown[] }) => string;\n nonEmpty: () => string;\n type: () => string;\n unique: () => string;\n };\n bigint: {\n max: (ctx: { max: bigint; value: bigint }) => string;\n min: (ctx: { min: bigint; value: bigint }) => string;\n multipleOf: (ctx: { step: bigint; value: bigint }) => string;\n negative: () => string;\n nonNegative: () => string;\n nonPositive: () => string;\n positive: () => string;\n type: () => string;\n };\n boolean: {\n type: () => string;\n };\n check: {\n default: () => string;\n };\n date: {\n max: (ctx: { max: Date; value: Date }) => string;\n min: (ctx: { min: Date; value: Date }) => string;\n type: () => string;\n };\n enum: {\n invalid: (ctx: { values: readonly unknown[] }) => string;\n };\n instanceof: {\n type: (ctx: { className: string }) => string;\n };\n literal: {\n expected: (ctx: { expected: unknown }) => string;\n };\n map: {\n max: (ctx: { max: number; value: Map<unknown, unknown> }) => string;\n min: (ctx: { min: number; value: Map<unknown, unknown> }) => string;\n nonEmpty: () => string;\n size: (ctx: { exact: number; value: Map<unknown, unknown> }) => string;\n type: () => string;\n };\n never: {\n invalid: () => string;\n };\n number: {\n finite: () => string;\n int: () => string;\n max: (ctx: { max: number; value: number }) => string;\n min: (ctx: { min: number; value: number }) => string;\n multipleOf: (ctx: { step: number; value: number }) => string;\n negative: () => string;\n nonNegative: () => string;\n nonPositive: () => string;\n positive: () => string;\n safe: () => string;\n type: () => string;\n };\n object: {\n invalidKeys: (ctx: { keys: string[] }) => string;\n type: () => string;\n };\n set: {\n max: (ctx: { max: number; value: Set<unknown> }) => string;\n min: (ctx: { min: number; value: Set<unknown> }) => string;\n nonEmpty: () => string;\n size: (ctx: { exact: number; value: Set<unknown> }) => string;\n type: () => string;\n };\n string: {\n base64: () => string;\n base64url: () => string;\n cuid: () => string;\n cuid2: () => string;\n date: () => string;\n dateTime: () => string;\n duration: () => string;\n email: () => string;\n emoji: () => string;\n endsWith: (ctx: { suffix: string; value: string }) => string;\n hex: () => string;\n hexColor: () => string;\n includes: (ctx: { substr: string; value: string }) => string;\n ip: () => string;\n jwt: () => string;\n length: (ctx: { exact: number; value: string }) => string;\n max: (ctx: { max: number; value: string }) => string;\n min: (ctx: { min: number; value: string }) => string;\n nanoid: () => string;\n nonEmpty: () => string;\n numeric: () => string;\n regex: (ctx: { value: string }) => string;\n semver: () => string;\n slug: () => string;\n startsWith: (ctx: { prefix: string; value: string }) => string;\n time: () => string;\n type: () => string;\n ulid: () => string;\n url: () => string;\n uuid: () => string;\n };\n tuple: {\n length: (ctx: { exact: number }) => string;\n min: (ctx: { min: number }) => string;\n type: () => string;\n };\n union: {\n invalid: () => string;\n };\n variant: {\n invalidDiscriminator: (ctx: { discriminator: string; expected: string[] }) => string;\n type: () => string;\n };\n};\n\nexport type DeepPartial<T> = {\n [K in keyof T]?: T[K] extends Record<string, unknown> ? DeepPartial<T[K]> : T[K];\n};\n\nconst _builtinMessages: Messages = {\n array: {\n length: ({ exact }) => `Must have exactly ${exact} items`,\n max: ({ max }) => `Must have at most ${max} items`,\n min: ({ min }) => `Must have at least ${min} items`,\n nonEmpty: () => 'Cannot be empty',\n type: () => 'Expected array',\n unique: () => 'All items must be unique',\n },\n bigint: {\n max: ({ max }) => `Must be at most ${max}`,\n min: ({ min }) => `Must be at least ${min}`,\n multipleOf: ({ step }) => `Must be a multiple of ${step}`,\n negative: () => 'Must be negative',\n nonNegative: () => 'Must be non-negative',\n nonPositive: () => 'Must be non-positive',\n positive: () => 'Must be positive',\n type: () => 'Expected bigint',\n },\n boolean: {\n type: () => 'Expected boolean',\n },\n check: {\n default: () => 'Invalid value',\n },\n date: {\n max: ({ max }) => `Must be before ${max.toISOString()}`,\n min: ({ min }) => `Must be after ${min.toISOString()}`,\n type: () => 'Expected valid date',\n },\n enum: {\n invalid: ({ values }) => `Expected one of: ${values.map((v) => JSON.stringify(v)).join(', ')}`,\n },\n instanceof: {\n type: ({ className }) => `Expected instance of ${className}`,\n },\n literal: {\n expected: ({ expected }) => `Expected ${JSON.stringify(expected)}`,\n },\n map: {\n max: ({ max }) => `Must contain at most ${max} entries`,\n min: ({ min }) => `Must contain at least ${min} entries`,\n nonEmpty: () => 'Cannot be empty',\n size: ({ exact }) => `Must contain exactly ${exact} entries`,\n type: () => 'Expected map',\n },\n never: {\n invalid: () => 'Value is not allowed',\n },\n number: {\n finite: () => 'Must be finite',\n int: () => 'Must be an integer',\n max: ({ max }) => `Must be at most ${max}`,\n min: ({ min }) => `Must be at least ${min}`,\n multipleOf: ({ step }) => `Must be a multiple of ${step}`,\n negative: () => 'Must be negative',\n nonNegative: () => 'Must be non-negative',\n nonPositive: () => 'Must be non-positive',\n positive: () => 'Must be positive',\n safe: () => 'Must be a safe integer',\n type: () => 'Expected number',\n },\n object: {\n invalidKeys: ({ keys }) => `Unrecognized keys: ${keys.join(', ')}`,\n type: () => 'Expected object',\n },\n set: {\n max: ({ max }) => `Must contain at most ${max} items`,\n min: ({ min }) => `Must contain at least ${min} items`,\n nonEmpty: () => 'Cannot be empty',\n size: ({ exact }) => `Must contain exactly ${exact} items`,\n type: () => 'Expected set',\n },\n string: {\n base64: () => 'Invalid base64',\n base64url: () => 'Invalid base64url',\n cuid: () => 'Invalid CUID',\n cuid2: () => 'Invalid CUID2',\n date: () => 'Invalid date',\n dateTime: () => 'Invalid datetime',\n duration: () => 'Invalid ISO 8601 duration',\n email: () => 'Invalid email address',\n emoji: () => 'Invalid emoji sequence',\n endsWith: ({ suffix }) => `Must end with \"${suffix}\"`,\n hex: () => 'Invalid hex',\n hexColor: () => 'Invalid hex color',\n includes: ({ substr }) => `Must include \"${substr}\"`,\n ip: () => 'Invalid IP address',\n jwt: () => 'Invalid JWT',\n length: ({ exact }) => `Must be exactly ${exact} characters`,\n max: ({ max }) => `Must be at most ${max} characters`,\n min: ({ min }) => `Must be at least ${min} characters`,\n nanoid: () => 'Invalid NanoID',\n nonEmpty: () => 'Cannot be empty',\n numeric: () => 'Invalid numeric string',\n regex: () => 'Invalid format',\n semver: () => 'Invalid semver',\n slug: () => 'Invalid slug',\n startsWith: ({ prefix }) => `Must start with \"${prefix}\"`,\n time: () => 'Invalid time',\n type: () => 'Expected string',\n ulid: () => 'Invalid ULID',\n url: () => 'Invalid URL',\n uuid: () => 'Invalid UUID',\n },\n tuple: {\n length: ({ exact }) => `Expected tuple of length ${exact}`,\n min: ({ min }) => `Expected tuple with at least ${min} items`,\n type: () => 'Expected array',\n },\n union: {\n invalid: () => 'Does not match any of the expected types',\n },\n variant: {\n invalidDiscriminator: ({ discriminator, expected }) =>\n `Invalid discriminator value at \"${discriminator}\": expected ${expected.map((k) => JSON.stringify(k)).join(' | ')}`,\n type: () => 'Expected object',\n },\n};\n\nlet _activeMessages: Messages = _builtinMessages;\n\n/** A function that receives internal warning messages from spell. */\nexport type Logger = (message: string) => void;\n\nlet _logger: Logger = (msg) => {\n _warnFn(msg);\n};\n\n/** @internal */\nexport function _dev(message: string): void {\n _logger(message);\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return value !== null && typeof value === 'object' && !Array.isArray(value);\n}\n\nfunction mergeMessages<T extends Record<string, unknown>>(base: T, patch: DeepPartial<T>): T {\n const out = cloneRecord(base) as Record<string, unknown>;\n\n for (const [key, value] of Object.entries(patch)) {\n if (value === undefined) continue;\n\n if (isUnsafeObjectKey(key)) {\n _dev(`[spell] Ignoring unsafe message override key \"${key}\" to prevent prototype mutation.`);\n continue;\n }\n\n const baseValue = out[key];\n\n if (isRecord(baseValue) && isRecord(value)) {\n defineOwnProperty(out, key, mergeMessages(baseValue, value as DeepPartial<typeof baseValue>));\n } else {\n defineOwnProperty(out, key, value);\n }\n }\n\n return out as T;\n}\n\n/**\n * Override any subset of the default validation messages globally.\n * Merges deeply into the current active messages — call again to update.\n *\n * For locale integration (e.g. with \\@vielzeug/lingua), call this inside\n * your locale-change handler:\n * ```ts\n * i18n.subscribe(() => setMessages(spellMessages[i18n.locale]));\n * ```\n */\nexport function setMessages(messages: DeepPartial<Messages>): void {\n _activeMessages = mergeMessages(_builtinMessages, messages);\n}\n\n/**\n * Override the internal warning logger.\n * Pass `null` to silence all internal warnings.\n */\nexport function setLogger(logger: Logger | null): void {\n _logger = logger ?? (() => {});\n}\n\n/** Reset all messages to the built-in defaults. */\nexport function resetMessages(): void {\n _activeMessages = _builtinMessages;\n}\n\n/** @internal — returns the active (possibly overridden) message set. */\nexport function _messages(): Messages {\n return _activeMessages;\n}\n"],"mappings":"6DA8HA,IAAM,EAA6B,CACjC,MAAO,CACL,QAAS,CAAE,WAAY,qBAAqB,EAAM,QAClD,KAAM,CAAE,SAAU,qBAAqB,EAAI,QAC3C,KAAM,CAAE,SAAU,sBAAsB,EAAI,QAC5C,aAAgB,kBAChB,SAAY,iBACZ,WAAc,0BAChB,EACA,OAAQ,CACN,KAAM,CAAE,SAAU,mBAAmB,IACrC,KAAM,CAAE,SAAU,oBAAoB,IACtC,YAAa,CAAE,UAAW,yBAAyB,IACnD,aAAgB,mBAChB,gBAAmB,uBACnB,gBAAmB,uBACnB,aAAgB,mBAChB,SAAY,iBACd,EACA,QAAS,CACP,SAAY,kBACd,EACA,MAAO,CACL,YAAe,eACjB,EACA,KAAM,CACJ,KAAM,CAAE,SAAU,kBAAkB,EAAI,YAAY,IACpD,KAAM,CAAE,SAAU,iBAAiB,EAAI,YAAY,IACnD,SAAY,qBACd,EACA,KAAM,CACJ,SAAU,CAAE,YAAa,oBAAoB,EAAO,IAAK,GAAM,KAAK,UAAU,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI,GAC7F,EACA,WAAY,CACV,MAAO,CAAE,eAAgB,wBAAwB,GACnD,EACA,QAAS,CACP,UAAW,CAAE,cAAe,YAAY,KAAK,UAAU,CAAQ,GACjE,EACA,IAAK,CACH,KAAM,CAAE,SAAU,wBAAwB,EAAI,UAC9C,KAAM,CAAE,SAAU,yBAAyB,EAAI,UAC/C,aAAgB,kBAChB,MAAO,CAAE,WAAY,wBAAwB,EAAM,UACnD,SAAY,cACd,EACA,MAAO,CACL,YAAe,sBACjB,EACA,OAAQ,CACN,WAAc,iBACd,QAAW,qBACX,KAAM,CAAE,SAAU,mBAAmB,IACrC,KAAM,CAAE,SAAU,oBAAoB,IACtC,YAAa,CAAE,UAAW,yBAAyB,IACnD,aAAgB,mBAChB,gBAAmB,uBACnB,gBAAmB,uBACnB,aA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S,EAAS,EAAkD,CAClE,OAAyB,OAAO,GAAU,YAAnC,GAA+C,CAAC,MAAM,QAAQ,CAAK,CAC5E,CAEA,SAAS,EAAiD,EAAS,EAA0B,CAC3F,IAAM,EAAM,EAAA,YAAY,CAAI,EAE5B,IAAK,GAAM,CAAC,EAAK,KAAU,OAAO,QAAQ,CAAK,EAAG,CAChD,GAAI,IAAU,IAAA,GAAW,SAEzB,GAAI,EAAA,kBAAkB,CAAG,EAAG,CAC1B,EAAK,iDAAiD,EAAI,iCAAiC,EAC3F,QACF,CAEA,IAAM,EAAY,EAAI,GAElB,EAAS,CAAS,GAAK,EAAS,CAAK,EACvC,EAAA,kBAAkB,EAAK,EAAK,EAAc,EAAW,CAAsC,CAAC,EAE5F,EAAA,kBAAkB,EAAK,EAAK,CAAK,CAErC,CAEA,OAAO,CACT,CAYA,SAAgB,EAAY,EAAuC,CACjE,EAAkB,EAAc,EAAkB,CAAQ,CAC5D,CAMA,SAAgB,EAAU,EAA6B,CACrD,EAAU,QAAiB,CAAC,EAC9B,CAGA,SAAgB,GAAsB,CACpC,EAAkB,CACpB,CAGA,SAAgB,GAAsB,CACpC,OAAO,CACT"}
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
export type Messages = {
|
|
2
|
+
array: {
|
|
3
|
+
length: (ctx: {
|
|
4
|
+
exact: number;
|
|
5
|
+
value: unknown[];
|
|
6
|
+
}) => string;
|
|
7
|
+
max: (ctx: {
|
|
8
|
+
max: number;
|
|
9
|
+
value: unknown[];
|
|
10
|
+
}) => string;
|
|
11
|
+
min: (ctx: {
|
|
12
|
+
min: number;
|
|
13
|
+
value: unknown[];
|
|
14
|
+
}) => string;
|
|
15
|
+
nonEmpty: () => string;
|
|
16
|
+
type: () => string;
|
|
17
|
+
unique: () => string;
|
|
18
|
+
};
|
|
19
|
+
bigint: {
|
|
20
|
+
max: (ctx: {
|
|
21
|
+
max: bigint;
|
|
22
|
+
value: bigint;
|
|
23
|
+
}) => string;
|
|
24
|
+
min: (ctx: {
|
|
25
|
+
min: bigint;
|
|
26
|
+
value: bigint;
|
|
27
|
+
}) => string;
|
|
28
|
+
multipleOf: (ctx: {
|
|
29
|
+
step: bigint;
|
|
30
|
+
value: bigint;
|
|
31
|
+
}) => string;
|
|
32
|
+
negative: () => string;
|
|
33
|
+
nonNegative: () => string;
|
|
34
|
+
nonPositive: () => string;
|
|
35
|
+
positive: () => string;
|
|
36
|
+
type: () => string;
|
|
37
|
+
};
|
|
38
|
+
boolean: {
|
|
39
|
+
type: () => string;
|
|
40
|
+
};
|
|
41
|
+
check: {
|
|
42
|
+
default: () => string;
|
|
43
|
+
};
|
|
44
|
+
date: {
|
|
45
|
+
max: (ctx: {
|
|
46
|
+
max: Date;
|
|
47
|
+
value: Date;
|
|
48
|
+
}) => string;
|
|
49
|
+
min: (ctx: {
|
|
50
|
+
min: Date;
|
|
51
|
+
value: Date;
|
|
52
|
+
}) => string;
|
|
53
|
+
type: () => string;
|
|
54
|
+
};
|
|
55
|
+
enum: {
|
|
56
|
+
invalid: (ctx: {
|
|
57
|
+
values: readonly unknown[];
|
|
58
|
+
}) => string;
|
|
59
|
+
};
|
|
60
|
+
instanceof: {
|
|
61
|
+
type: (ctx: {
|
|
62
|
+
className: string;
|
|
63
|
+
}) => string;
|
|
64
|
+
};
|
|
65
|
+
literal: {
|
|
66
|
+
expected: (ctx: {
|
|
67
|
+
expected: unknown;
|
|
68
|
+
}) => string;
|
|
69
|
+
};
|
|
70
|
+
map: {
|
|
71
|
+
max: (ctx: {
|
|
72
|
+
max: number;
|
|
73
|
+
value: Map<unknown, unknown>;
|
|
74
|
+
}) => string;
|
|
75
|
+
min: (ctx: {
|
|
76
|
+
min: number;
|
|
77
|
+
value: Map<unknown, unknown>;
|
|
78
|
+
}) => string;
|
|
79
|
+
nonEmpty: () => string;
|
|
80
|
+
size: (ctx: {
|
|
81
|
+
exact: number;
|
|
82
|
+
value: Map<unknown, unknown>;
|
|
83
|
+
}) => string;
|
|
84
|
+
type: () => string;
|
|
85
|
+
};
|
|
86
|
+
never: {
|
|
87
|
+
invalid: () => string;
|
|
88
|
+
};
|
|
89
|
+
number: {
|
|
90
|
+
finite: () => string;
|
|
91
|
+
int: () => string;
|
|
92
|
+
max: (ctx: {
|
|
93
|
+
max: number;
|
|
94
|
+
value: number;
|
|
95
|
+
}) => string;
|
|
96
|
+
min: (ctx: {
|
|
97
|
+
min: number;
|
|
98
|
+
value: number;
|
|
99
|
+
}) => string;
|
|
100
|
+
multipleOf: (ctx: {
|
|
101
|
+
step: number;
|
|
102
|
+
value: number;
|
|
103
|
+
}) => string;
|
|
104
|
+
negative: () => string;
|
|
105
|
+
nonNegative: () => string;
|
|
106
|
+
nonPositive: () => string;
|
|
107
|
+
positive: () => string;
|
|
108
|
+
safe: () => string;
|
|
109
|
+
type: () => string;
|
|
110
|
+
};
|
|
111
|
+
object: {
|
|
112
|
+
invalidKeys: (ctx: {
|
|
113
|
+
keys: string[];
|
|
114
|
+
}) => string;
|
|
115
|
+
type: () => string;
|
|
116
|
+
};
|
|
117
|
+
set: {
|
|
118
|
+
max: (ctx: {
|
|
119
|
+
max: number;
|
|
120
|
+
value: Set<unknown>;
|
|
121
|
+
}) => string;
|
|
122
|
+
min: (ctx: {
|
|
123
|
+
min: number;
|
|
124
|
+
value: Set<unknown>;
|
|
125
|
+
}) => string;
|
|
126
|
+
nonEmpty: () => string;
|
|
127
|
+
size: (ctx: {
|
|
128
|
+
exact: number;
|
|
129
|
+
value: Set<unknown>;
|
|
130
|
+
}) => string;
|
|
131
|
+
type: () => string;
|
|
132
|
+
};
|
|
133
|
+
string: {
|
|
134
|
+
base64: () => string;
|
|
135
|
+
base64url: () => string;
|
|
136
|
+
cuid: () => string;
|
|
137
|
+
cuid2: () => string;
|
|
138
|
+
date: () => string;
|
|
139
|
+
dateTime: () => string;
|
|
140
|
+
duration: () => string;
|
|
141
|
+
email: () => string;
|
|
142
|
+
emoji: () => string;
|
|
143
|
+
endsWith: (ctx: {
|
|
144
|
+
suffix: string;
|
|
145
|
+
value: string;
|
|
146
|
+
}) => string;
|
|
147
|
+
hex: () => string;
|
|
148
|
+
hexColor: () => string;
|
|
149
|
+
includes: (ctx: {
|
|
150
|
+
substr: string;
|
|
151
|
+
value: string;
|
|
152
|
+
}) => string;
|
|
153
|
+
ip: () => string;
|
|
154
|
+
jwt: () => string;
|
|
155
|
+
length: (ctx: {
|
|
156
|
+
exact: number;
|
|
157
|
+
value: string;
|
|
158
|
+
}) => string;
|
|
159
|
+
max: (ctx: {
|
|
160
|
+
max: number;
|
|
161
|
+
value: string;
|
|
162
|
+
}) => string;
|
|
163
|
+
min: (ctx: {
|
|
164
|
+
min: number;
|
|
165
|
+
value: string;
|
|
166
|
+
}) => string;
|
|
167
|
+
nanoid: () => string;
|
|
168
|
+
nonEmpty: () => string;
|
|
169
|
+
numeric: () => string;
|
|
170
|
+
regex: (ctx: {
|
|
171
|
+
value: string;
|
|
172
|
+
}) => string;
|
|
173
|
+
semver: () => string;
|
|
174
|
+
slug: () => string;
|
|
175
|
+
startsWith: (ctx: {
|
|
176
|
+
prefix: string;
|
|
177
|
+
value: string;
|
|
178
|
+
}) => string;
|
|
179
|
+
time: () => string;
|
|
180
|
+
type: () => string;
|
|
181
|
+
ulid: () => string;
|
|
182
|
+
url: () => string;
|
|
183
|
+
uuid: () => string;
|
|
184
|
+
};
|
|
185
|
+
tuple: {
|
|
186
|
+
length: (ctx: {
|
|
187
|
+
exact: number;
|
|
188
|
+
}) => string;
|
|
189
|
+
min: (ctx: {
|
|
190
|
+
min: number;
|
|
191
|
+
}) => string;
|
|
192
|
+
type: () => string;
|
|
193
|
+
};
|
|
194
|
+
union: {
|
|
195
|
+
invalid: () => string;
|
|
196
|
+
};
|
|
197
|
+
variant: {
|
|
198
|
+
invalidDiscriminator: (ctx: {
|
|
199
|
+
discriminator: string;
|
|
200
|
+
expected: string[];
|
|
201
|
+
}) => string;
|
|
202
|
+
type: () => string;
|
|
203
|
+
};
|
|
204
|
+
};
|
|
205
|
+
export type DeepPartial<T> = {
|
|
206
|
+
[K in keyof T]?: T[K] extends Record<string, unknown> ? DeepPartial<T[K]> : T[K];
|
|
207
|
+
};
|
|
208
|
+
/** A function that receives internal warning messages from spell. */
|
|
209
|
+
export type Logger = (message: string) => void;
|
|
210
|
+
/**
|
|
211
|
+
* Override any subset of the default validation messages globally.
|
|
212
|
+
* Merges deeply into the current active messages — call again to update.
|
|
213
|
+
*
|
|
214
|
+
* For locale integration (e.g. with \@vielzeug/lingua), call this inside
|
|
215
|
+
* your locale-change handler:
|
|
216
|
+
* ```ts
|
|
217
|
+
* i18n.subscribe(() => setMessages(spellMessages[i18n.locale]));
|
|
218
|
+
* ```
|
|
219
|
+
*/
|
|
220
|
+
export declare function setMessages(messages: DeepPartial<Messages>): void;
|
|
221
|
+
/**
|
|
222
|
+
* Override the internal warning logger.
|
|
223
|
+
* Pass `null` to silence all internal warnings.
|
|
224
|
+
*/
|
|
225
|
+
export declare function setLogger(logger: Logger | null): void;
|
|
226
|
+
/** Reset all messages to the built-in defaults. */
|
|
227
|
+
export declare function resetMessages(): void;
|
|
228
|
+
//# sourceMappingURL=messages.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../src/messages.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,QAAQ,GAAG;IACrB,KAAK,EAAE;QACL,MAAM,EAAE,CAAC,GAAG,EAAE;YAAE,KAAK,EAAE,MAAM,CAAC;YAAC,KAAK,EAAE,OAAO,EAAE,CAAA;SAAE,KAAK,MAAM,CAAC;QAC7D,GAAG,EAAE,CAAC,GAAG,EAAE;YAAE,GAAG,EAAE,MAAM,CAAC;YAAC,KAAK,EAAE,OAAO,EAAE,CAAA;SAAE,KAAK,MAAM,CAAC;QACxD,GAAG,EAAE,CAAC,GAAG,EAAE;YAAE,GAAG,EAAE,MAAM,CAAC;YAAC,KAAK,EAAE,OAAO,EAAE,CAAA;SAAE,KAA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SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAErD;AAED,mDAAmD;AACnD,wBAAgB,aAAa,IAAI,IAAI,CAEpC"}
|
package/dist/messages.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{cloneRecord as e,defineOwnProperty as t,isUnsafeObjectKey as n}from"./safe-object.js";import{warn as r}from"./_dev.js";var i={array:{length:({exact:e})=>`Must have exactly ${e} items`,max:({max:e})=>`Must have at most ${e} items`,min:({min:e})=>`Must have at least ${e} items`,nonEmpty:()=>`Cannot be empty`,type:()=>`Expected array`,unique:()=>`All items must be unique`},bigint:{max:({max:e})=>`Must be at most ${e}`,min:({min:e})=>`Must be at least ${e}`,multipleOf:({step:e})=>`Must be a multiple of ${e}`,negative:()=>`Must be negative`,nonNegative:()=>`Must be non-negative`,nonPositive:()=>`Must be non-positive`,positive:()=>`Must be positive`,type:()=>`Expected bigint`},boolean:{type:()=>`Expected boolean`},check:{default:()=>`Invalid value`},date:{max:({max:e})=>`Must be before ${e.toISOString()}`,min:({min:e})=>`Must be after ${e.toISOString()}`,type:()=>`Expected valid date`},enum:{invalid:({values:e})=>`Expected one of: ${e.map(e=>JSON.stringify(e)).join(`, `)}`},instanceof:{type:({className:e})=>`Expected instance of ${e}`},literal:{expected:({expected:e})=>`Expected ${JSON.stringify(e)}`},map:{max:({max:e})=>`Must contain at most ${e} entries`,min:({min:e})=>`Must contain at least ${e} entries`,nonEmpty:()=>`Cannot be empty`,size:({exact:e})=>`Must contain exactly ${e} entries`,type:()=>`Expected map`},never:{invalid:()=>`Value is not allowed`},number:{finite:()=>`Must be finite`,int:()=>`Must be an integer`,max:({max:e})=>`Must be at most ${e}`,min:({min:e})=>`Must be at least ${e}`,multipleOf:({step:e})=>`Must be a multiple of ${e}`,negative:()=>`Must be negative`,nonNegative:()=>`Must be non-negative`,nonPositive:()=>`Must be non-positive`,positive:()=>`Must be positive`,safe:()=>`Must be a safe integer`,type:()=>`Expected number`},object:{invalidKeys:({keys:e})=>`Unrecognized keys: ${e.join(`, `)}`,type:()=>`Expected object`},set:{max:({max:e})=>`Must contain at most ${e} items`,min:({min:e})=>`Must contain at least ${e} items`,nonEmpty:()=>`Cannot be empty`,size:({exact:e})=>`Must contain exactly ${e} items`,type:()=>`Expected set`},string:{base64:()=>`Invalid base64`,base64url:()=>`Invalid base64url`,cuid:()=>`Invalid CUID`,cuid2:()=>`Invalid CUID2`,date:()=>`Invalid date`,dateTime:()=>`Invalid datetime`,duration:()=>`Invalid ISO 8601 duration`,email:()=>`Invalid email address`,emoji:()=>`Invalid emoji sequence`,endsWith:({suffix:e})=>`Must end with "${e}"`,hex:()=>`Invalid hex`,hexColor:()=>`Invalid hex color`,includes:({substr:e})=>`Must include "${e}"`,ip:()=>`Invalid IP address`,jwt:()=>`Invalid JWT`,length:({exact:e})=>`Must be exactly ${e} characters`,max:({max:e})=>`Must be at most ${e} characters`,min:({min:e})=>`Must be at least ${e} characters`,nanoid:()=>`Invalid NanoID`,nonEmpty:()=>`Cannot be empty`,numeric:()=>`Invalid numeric string`,regex:()=>`Invalid format`,semver:()=>`Invalid semver`,slug:()=>`Invalid slug`,startsWith:({prefix:e})=>`Must start with "${e}"`,time:()=>`Invalid time`,type:()=>`Expected string`,ulid:()=>`Invalid ULID`,url:()=>`Invalid URL`,uuid:()=>`Invalid UUID`},tuple:{length:({exact:e})=>`Expected tuple of length ${e}`,min:({min:e})=>`Expected tuple with at least ${e} items`,type:()=>`Expected array`},union:{invalid:()=>`Does not match any of the expected types`},variant:{invalidDiscriminator:({discriminator:e,expected:t})=>`Invalid discriminator value at "${e}": expected ${t.map(e=>JSON.stringify(e)).join(` | `)}`,type:()=>`Expected object`}},a=i,o=e=>{r(e)};function s(e){o(e)}function c(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function l(r,i){let a=e(r);for(let[e,r]of Object.entries(i)){if(r===void 0)continue;if(n(e)){s(`[spell] Ignoring unsafe message override key "${e}" to prevent prototype mutation.`);continue}let i=a[e];c(i)&&c(r)?t(a,e,l(i,r)):t(a,e,r)}return a}function u(e){a=l(i,e)}function d(e){o=e??(()=>{})}function f(){a=i}function p(){return a}export{s as _dev,p as _messages,f as resetMessages,d as setLogger,u as setMessages};
|
|
2
|
+
//# sourceMappingURL=messages.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messages.js","names":[],"sources":["../src/messages.ts"],"sourcesContent":["import { warn as _warnFn } from './_dev';\nimport { cloneRecord, defineOwnProperty, isUnsafeObjectKey } from './safe-object';\n\nexport type Messages = {\n array: {\n length: (ctx: { exact: number; value: unknown[] }) => string;\n max: (ctx: { max: number; value: unknown[] }) => string;\n min: (ctx: { min: number; value: unknown[] }) => string;\n nonEmpty: () => string;\n type: () => string;\n unique: () => string;\n };\n bigint: {\n max: (ctx: { max: bigint; value: bigint }) => string;\n min: (ctx: { min: bigint; value: bigint }) => string;\n multipleOf: (ctx: { step: bigint; value: bigint }) => string;\n negative: () => string;\n nonNegative: () => string;\n nonPositive: () => string;\n positive: () => string;\n type: () => string;\n };\n boolean: {\n type: () => string;\n };\n check: {\n default: () => string;\n };\n date: {\n max: (ctx: { max: Date; value: Date }) => string;\n min: (ctx: { min: Date; value: Date }) => string;\n type: () => string;\n };\n enum: {\n invalid: (ctx: { values: readonly unknown[] }) => string;\n };\n instanceof: {\n type: (ctx: { className: string }) => string;\n };\n literal: {\n expected: (ctx: { expected: unknown }) => string;\n };\n map: {\n max: (ctx: { max: number; value: Map<unknown, unknown> }) => string;\n min: (ctx: { min: number; value: Map<unknown, unknown> }) => string;\n nonEmpty: () => string;\n size: (ctx: { exact: number; value: Map<unknown, unknown> }) => string;\n type: () => string;\n };\n never: {\n invalid: () => string;\n };\n number: {\n finite: () => string;\n int: () => string;\n max: (ctx: { max: number; value: number }) => string;\n min: (ctx: { min: number; value: number }) => string;\n multipleOf: (ctx: { step: number; value: number }) => string;\n negative: () => string;\n nonNegative: () => string;\n nonPositive: () => string;\n positive: () => string;\n safe: () => string;\n type: () => string;\n };\n object: {\n invalidKeys: (ctx: { keys: string[] }) => string;\n type: () => string;\n };\n set: {\n max: (ctx: { max: number; value: Set<unknown> }) => string;\n min: (ctx: { min: number; value: Set<unknown> }) => string;\n nonEmpty: () => string;\n size: (ctx: { exact: number; value: Set<unknown> }) => string;\n type: () => string;\n };\n string: {\n base64: () => string;\n base64url: () => string;\n cuid: () => string;\n cuid2: () => string;\n date: () => string;\n dateTime: () => string;\n duration: () => string;\n email: () => string;\n emoji: () => string;\n endsWith: (ctx: { suffix: string; value: string }) => string;\n hex: () => string;\n hexColor: () => string;\n includes: (ctx: { substr: string; value: string }) => string;\n ip: () => string;\n jwt: () => string;\n length: (ctx: { exact: number; value: string }) => string;\n max: (ctx: { max: number; value: string }) => string;\n min: (ctx: { min: number; value: string }) => string;\n nanoid: () => string;\n nonEmpty: () => string;\n numeric: () => string;\n regex: (ctx: { value: string }) => string;\n semver: () => string;\n slug: () => string;\n startsWith: (ctx: { prefix: string; value: string }) => string;\n time: () => string;\n type: () => string;\n ulid: () => string;\n url: () => string;\n uuid: () => string;\n };\n tuple: {\n length: (ctx: { exact: number }) => string;\n min: (ctx: { min: number }) => string;\n type: () => string;\n };\n union: {\n invalid: () => string;\n };\n variant: {\n invalidDiscriminator: (ctx: { discriminator: string; expected: string[] }) => string;\n type: () => string;\n };\n};\n\nexport type DeepPartial<T> = {\n [K in keyof T]?: T[K] extends Record<string, unknown> ? DeepPartial<T[K]> : T[K];\n};\n\nconst _builtinMessages: Messages = {\n array: {\n length: ({ exact }) => `Must have exactly ${exact} items`,\n max: ({ max }) => `Must have at most ${max} items`,\n min: ({ min }) => `Must have at least ${min} items`,\n nonEmpty: () => 'Cannot be empty',\n type: () => 'Expected array',\n unique: () => 'All items must be unique',\n },\n bigint: {\n max: ({ max }) => `Must be at most ${max}`,\n min: ({ min }) => `Must be at least ${min}`,\n multipleOf: ({ step }) => `Must be a multiple of ${step}`,\n negative: () => 'Must be negative',\n nonNegative: () => 'Must be non-negative',\n nonPositive: () => 'Must be non-positive',\n positive: () => 'Must be positive',\n type: () => 'Expected bigint',\n },\n boolean: {\n type: () => 'Expected boolean',\n },\n check: {\n default: () => 'Invalid value',\n },\n date: {\n max: ({ max }) => `Must be before ${max.toISOString()}`,\n min: ({ min }) => `Must be after ${min.toISOString()}`,\n type: () => 'Expected valid date',\n },\n enum: {\n invalid: ({ values }) => `Expected one of: ${values.map((v) => JSON.stringify(v)).join(', ')}`,\n },\n instanceof: {\n type: ({ className }) => `Expected instance of ${className}`,\n },\n literal: {\n expected: ({ expected }) => `Expected ${JSON.stringify(expected)}`,\n },\n map: {\n max: ({ max }) => `Must contain at most ${max} entries`,\n min: ({ min }) => `Must contain at least ${min} entries`,\n nonEmpty: () => 'Cannot be empty',\n size: ({ exact }) => `Must contain exactly ${exact} entries`,\n type: () => 'Expected map',\n },\n never: {\n invalid: () => 'Value is not allowed',\n },\n number: {\n finite: () => 'Must be finite',\n int: () => 'Must be an integer',\n max: ({ max }) => `Must be at most ${max}`,\n min: ({ min }) => `Must be at least ${min}`,\n multipleOf: ({ step }) => `Must be a multiple of ${step}`,\n negative: () => 'Must be negative',\n nonNegative: () => 'Must be non-negative',\n nonPositive: () => 'Must be non-positive',\n positive: () => 'Must be positive',\n safe: () => 'Must be a safe integer',\n type: () => 'Expected number',\n },\n object: {\n invalidKeys: ({ keys }) => `Unrecognized keys: ${keys.join(', ')}`,\n type: () => 'Expected object',\n },\n set: {\n max: ({ max }) => `Must contain at most ${max} items`,\n min: ({ min }) => `Must contain at least ${min} items`,\n nonEmpty: () => 'Cannot be empty',\n size: ({ exact }) => `Must contain exactly ${exact} items`,\n type: () => 'Expected set',\n },\n string: {\n base64: () => 'Invalid base64',\n base64url: () => 'Invalid base64url',\n cuid: () => 'Invalid CUID',\n cuid2: () => 'Invalid CUID2',\n date: () => 'Invalid date',\n dateTime: () => 'Invalid datetime',\n duration: () => 'Invalid ISO 8601 duration',\n email: () => 'Invalid email address',\n emoji: () => 'Invalid emoji sequence',\n endsWith: ({ suffix }) => `Must end with \"${suffix}\"`,\n hex: () => 'Invalid hex',\n hexColor: () => 'Invalid hex color',\n includes: ({ substr }) => `Must include \"${substr}\"`,\n ip: () => 'Invalid IP address',\n jwt: () => 'Invalid JWT',\n length: ({ exact }) => `Must be exactly ${exact} characters`,\n max: ({ max }) => `Must be at most ${max} characters`,\n min: ({ min }) => `Must be at least ${min} characters`,\n nanoid: () => 'Invalid NanoID',\n nonEmpty: () => 'Cannot be empty',\n numeric: () => 'Invalid numeric string',\n regex: () => 'Invalid format',\n semver: () => 'Invalid semver',\n slug: () => 'Invalid slug',\n startsWith: ({ prefix }) => `Must start with \"${prefix}\"`,\n time: () => 'Invalid time',\n type: () => 'Expected string',\n ulid: () => 'Invalid ULID',\n url: () => 'Invalid URL',\n uuid: () => 'Invalid UUID',\n },\n tuple: {\n length: ({ exact }) => `Expected tuple of length ${exact}`,\n min: ({ min }) => `Expected tuple with at least ${min} items`,\n type: () => 'Expected array',\n },\n union: {\n invalid: () => 'Does not match any of the expected types',\n },\n variant: {\n invalidDiscriminator: ({ discriminator, expected }) =>\n `Invalid discriminator value at \"${discriminator}\": expected ${expected.map((k) => JSON.stringify(k)).join(' | ')}`,\n type: () => 'Expected object',\n },\n};\n\nlet _activeMessages: Messages = _builtinMessages;\n\n/** A function that receives internal warning messages from spell. */\nexport type Logger = (message: string) => void;\n\nlet _logger: Logger = (msg) => {\n _warnFn(msg);\n};\n\n/** @internal */\nexport function _dev(message: string): void {\n _logger(message);\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return value !== null && typeof value === 'object' && !Array.isArray(value);\n}\n\nfunction mergeMessages<T extends Record<string, unknown>>(base: T, patch: DeepPartial<T>): T {\n const out = cloneRecord(base) as Record<string, unknown>;\n\n for (const [key, value] of Object.entries(patch)) {\n if (value === undefined) continue;\n\n if (isUnsafeObjectKey(key)) {\n _dev(`[spell] Ignoring unsafe message override key \"${key}\" to prevent prototype mutation.`);\n continue;\n }\n\n const baseValue = out[key];\n\n if (isRecord(baseValue) && isRecord(value)) {\n defineOwnProperty(out, key, mergeMessages(baseValue, value as DeepPartial<typeof baseValue>));\n } else {\n defineOwnProperty(out, key, value);\n }\n }\n\n return out as T;\n}\n\n/**\n * Override any subset of the default validation messages globally.\n * Merges deeply into the current active messages — call again to update.\n *\n * For locale integration (e.g. with \\@vielzeug/lingua), call this inside\n * your locale-change handler:\n * ```ts\n * i18n.subscribe(() => setMessages(spellMessages[i18n.locale]));\n * ```\n */\nexport function setMessages(messages: DeepPartial<Messages>): void {\n _activeMessages = mergeMessages(_builtinMessages, messages);\n}\n\n/**\n * Override the internal warning logger.\n * Pass `null` to silence all internal warnings.\n */\nexport function setLogger(logger: Logger | null): void {\n _logger = logger ?? (() => {});\n}\n\n/** Reset all messages to the built-in defaults. */\nexport function resetMessages(): void {\n _activeMessages = _builtinMessages;\n}\n\n/** @internal — returns the active (possibly overridden) message set. */\nexport function _messages(): Messages {\n return _activeMessages;\n}\n"],"mappings":"8HA8HA,IAAM,EAA6B,CACjC,MAAO,CACL,QAAS,CAAE,WAAY,qBAAqB,EAAM,QAClD,KAAM,CAAE,SAAU,qBAAqB,EAAI,QAC3C,KAAM,CAAE,SAAU,sBAAsB,EAAI,QAC5C,aAAgB,kBAChB,SAAY,iBACZ,WAAc,0BAChB,EACA,OAAQ,CACN,KAAM,CAAE,SAAU,mBAAmB,IACrC,KAAM,CAAE,SAAU,oBAAoB,IACtC,YAAa,CAAE,UAAW,yBAAyB,IACnD,aAAgB,mBAChB,gBAAmB,uBACnB,gBAAmB,uBACnB,aAAgB,mBAChB,SAAY,iBACd,EACA,QAAS,CACP,SAAY,kBACd,EACA,MAAO,CACL,YAAe,eACjB,EACA,KAAM,CACJ,KAAM,CAAE,SAAU,kBAAkB,EAAI,YAAY,IACpD,KAAM,CAAE,SAAU,iBAAiB,EAAI,YAAY,IACnD,SAAY,qBACd,EACA,KAAM,CACJ,SAAU,CAAE,YAA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AgB,GAAsB,CACpC,OAAO,CACT"}
|
package/dist/s.cjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const e=require("./core.cjs"),t=require("./schemas/array.cjs"),n=require("./schemas/bigint.cjs"),r=require("./schemas/boolean.cjs"),i=require("./schemas/date.cjs"),a=require("./schemas/enum.cjs"),o=require("./schemas/instanceof.cjs"),s=require("./schemas/intersect.cjs"),c=require("./schemas/lazy.cjs"),l=require("./schemas/literal.cjs"),u=require("./schemas/map.cjs"),d=require("./schemas/never.cjs"),f=require("./schemas/number.cjs"),p=require("./schemas/union.cjs"),m=require("./schemas/object.cjs"),h=require("./schemas/raw-or.cjs"),g=require("./schemas/record.cjs"),_=require("./schemas/set.cjs"),v=require("./schemas/string.cjs"),y=require("./schemas/tuple.cjs"),b=require("./schemas/variant.cjs");var x=(e,t)=>k(e,t),S=()=>new e.Schema,C=e=>new t.ArraySchema(e),w=()=>new n.BigIntSchema,T=()=>new r.BooleanSchema,E=()=>new i.DateSchema,D=e=>new a.EnumSchema(e),O=e=>new o.InstanceOfSchema(e),k=(...e)=>new s.IntersectSchema(h.normalizeToSchemas(e)),A=e=>new c.LazySchema(e),j=e=>new l.LiteralSchema(e),M=(e,t)=>new u.MapSchema(e,t),N=()=>new d.NeverSchema,P=()=>new l.LiteralSchema(null),F=()=>new f.NumberSchema,I=e=>new m.ObjectSchema(e),L=(e,t)=>new g.RecordSchema(e,t),R=e=>new _.SetSchema(e),z=()=>new v.StringSchema,B=e=>new y.TupleSchema(e),V=()=>new l.LiteralSchema(void 0),H=(...e)=>new p.UnionSchema(h.normalizeToSchemas(e)),U={and:x,any:S,array:C,bigint:w,boolean:T,coerce:{bigint:()=>n.BigIntSchema.coerce(),boolean:()=>r.BooleanSchema.coerce(),date:()=>i.DateSchema.coerce(),number:()=>f.NumberSchema.coerce(),string:()=>v.StringSchema.coerce()},date:E,enum:D,instanceof:O,intersect:k,lazy:A,literal:j,map:M,never:N,null:P,number:F,object:I,or:(e,t)=>H(e,t),record:L,set:R,string:z,tuple:B,undefined:V,union:H,unknown:()=>new e.Schema,variant:(e,t)=>new b.VariantSchema(e,t)};exports.s=U;
|
|
2
|
+
//# sourceMappingURL=s.cjs.map
|
package/dist/s.cjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"s.cjs","names":[],"sources":["../src/s.ts"],"sourcesContent":["import { type AnySchema, Schema } from './core';\nimport { ArraySchema } from './schemas/array';\nimport { BigIntSchema } from './schemas/bigint';\nimport { BooleanSchema } from './schemas/boolean';\nimport { DateSchema } from './schemas/date';\nimport { EnumSchema, type EnumValues } from './schemas/enum';\nimport { InstanceOfSchema } from './schemas/instanceof';\nimport { IntersectSchema } from './schemas/intersect';\nimport { LazySchema } from './schemas/lazy';\nimport { LiteralSchema } from './schemas/literal';\nimport { MapSchema } from './schemas/map';\nimport { NeverSchema } from './schemas/never';\nimport { NumberSchema } from './schemas/number';\nimport { ObjectSchema, type ObjectShape } from './schemas/object';\nimport { type NormalizeItems, normalizeToSchemas, type RawOrSchema } from './schemas/raw-or';\nimport { RecordSchema } from './schemas/record';\nimport { SetSchema } from './schemas/set';\nimport { StringSchema } from './schemas/string';\nimport { TupleSchema, type TupleSchemas } from './schemas/tuple';\nimport { UnionSchema } from './schemas/union';\nimport { VariantSchema } from './schemas/variant';\n\n/* -------------------- Internal factory functions -------------------- */\n\nconst sAnd = <A, B>(a: Schema<A, any>, b: Schema<B, any>): IntersectSchema<readonly [Schema<A, any>, Schema<B, any>]> =>\n sIntersect(a, b);\nconst sAny = (): Schema<any> => new Schema();\nconst sArray = <T>(schema: Schema<T, any>): ArraySchema<T> => new ArraySchema(schema);\nconst sBigint = (): BigIntSchema => new BigIntSchema();\nconst sBoolean = (): BooleanSchema => new BooleanSchema();\nconst sDate = (): DateSchema => new DateSchema();\nconst sEnum = <const T extends EnumValues>(values: T): EnumSchema<T> => new EnumSchema(values);\nconst sInstanceof = <T>(cls: new (...args: any[]) => T): InstanceOfSchema<T> => new InstanceOfSchema(cls);\nconst sIntersect = <T extends readonly [RawOrSchema, RawOrSchema, ...RawOrSchema[]]>(\n ...items: T\n): IntersectSchema<NormalizeItems<T> & readonly AnySchema[]> =>\n new IntersectSchema(normalizeToSchemas(items) as NormalizeItems<T> & readonly AnySchema[]);\nconst sLazy = <T>(getter: () => Schema<T, any>): LazySchema<T> => new LazySchema(getter);\nconst sLiteral = <T extends string | number | boolean | null | undefined>(value: T): LiteralSchema<T> =>\n new LiteralSchema(value);\nconst sMap = <K, V>(keySchema: Schema<K, any>, valueSchema: Schema<V, any>): MapSchema<K, V> =>\n new MapSchema(keySchema, valueSchema);\nconst sNever = (): NeverSchema => new NeverSchema();\nconst sNull = (): LiteralSchema<null> => new LiteralSchema(null);\nconst sNumber = (): NumberSchema => new NumberSchema();\nconst sObject = <T extends ObjectShape>(shape: T): ObjectSchema<T> => new ObjectSchema(shape);\nconst sRecord = <K extends string, V>(keySchema: Schema<K, any>, valueSchema: Schema<V, any>): RecordSchema<K, V> =>\n new RecordSchema(keySchema, valueSchema);\nconst sSet = <T>(schema: Schema<T, any>): SetSchema<T> => new SetSchema(schema);\nconst sString = (): StringSchema => new StringSchema();\nconst sTuple = <const T extends TupleSchemas>(items: T): TupleSchema<T> => new TupleSchema(items);\nconst sUndefined = (): LiteralSchema<undefined> => new LiteralSchema(undefined);\nconst sUnion = <T extends readonly [RawOrSchema, RawOrSchema, ...RawOrSchema[]]>(\n ...items: T\n): UnionSchema<NormalizeItems<T> & readonly AnySchema[]> =>\n new UnionSchema(normalizeToSchemas(items) as NormalizeItems<T> & readonly AnySchema[]);\nconst sOr = <A, B>(a: Schema<A, any>, b: Schema<B, any>): UnionSchema<readonly [Schema<A, any>, Schema<B, any>]> =>\n sUnion(a, b);\nconst sUnknown = (): Schema<unknown> => new Schema();\nconst sVariant = <K extends string, M extends Record<string, ObjectSchema<any>>>(\n discriminator: K,\n map: M,\n): VariantSchema<K, M> => new VariantSchema(discriminator, map);\nconst sCoerce = {\n bigint: (): BigIntSchema => BigIntSchema.coerce(),\n boolean: (): BooleanSchema => BooleanSchema.coerce(),\n date: (): DateSchema => DateSchema.coerce(),\n number: (): NumberSchema => NumberSchema.coerce(),\n string: (): StringSchema => StringSchema.coerce(),\n};\n\n/* -------------------- `s` namespace — the public API -------------------- */\n\n/**\n * Namespace of all schema factories. Use `s.string()`, `s.object()`, etc.\n *\n * @example\n * import { s, type Infer } from '@vielzeug/spell';\n *\n * const User = s.object({ name: s.string(), age: s.number().int().positive() });\n * type User = Infer<typeof User>;\n */\nexport const s = {\n and: sAnd,\n any: sAny,\n array: sArray,\n bigint: sBigint,\n boolean: sBoolean,\n coerce: sCoerce,\n date: sDate,\n enum: sEnum,\n instanceof: sInstanceof,\n intersect: sIntersect,\n lazy: sLazy,\n literal: sLiteral,\n map: sMap,\n never: sNever,\n null: sNull,\n number: sNumber,\n object: sObject,\n or: sOr,\n record: sRecord,\n set: sSet,\n string: sString,\n tuple: sTuple,\n undefined: sUndefined,\n union: sUnion,\n unknown: sUnknown,\n variant: sVariant,\n};\n"],"mappings":"gsBAwBA,IAAM,GAAc,EAAmB,IACrC,EAAW,EAAG,CAAC,EACX,MAA0B,IAAI,EAAA,OAC9B,EAAa,GAA2C,IAAI,EAAA,YAAY,CAAM,EAC9E,MAA8B,IAAI,EAAA,aAClC,MAAgC,IAAI,EAAA,cACpC,MAA0B,IAAI,EAAA,WAC9B,EAAqC,GAA6B,IAAI,EAAA,WAAW,CAAM,EACvF,EAAkB,GAAwD,IAAI,EAAA,iBAAiB,CAAG,EAClG,GACJ,GAAG,IAEH,IAAI,EAAA,gBAAgB,EAAA,mBAAmB,CAAK,CAA6C,EACrF,EAAY,GAAgD,IAAI,EAAA,WAAW,CAAM,EACjF,EAAoE,GACxE,IAAI,EAAA,cAAc,CAAK,EACnB,GAAc,EAA2B,IAC7C,IAAI,EAAA,UAAU,EAAW,CAAW,EAChC,MAA4B,IAAI,EAAA,YAChC,MAAmC,IAAI,EAAA,cAAc,IAAI,EACzD,MAA8B,IAAI,EAAA,aAClC,EAAkC,GAA8B,IAAI,EAAA,aAAa,CAAK,EACtF,GAAgC,EAA2B,IAC/D,IAAI,EAAA,aAAa,EAAW,CAAW,EACnC,EAAW,GAAyC,IAAI,EAAA,UAAU,CAAM,EACxE,MAA8B,IAAI,EAAA,aAClC,EAAwC,GAA6B,IAAI,EAAA,YAAY,CAAK,EAC1F,MAA6C,IAAI,EAAA,cAAc,IAAA,EAAS,EACxE,GACJ,GAAG,IAEH,IAAI,EAAA,YAAY,EAAA,mBAAmB,CAAK,CAA6C,EA2B1E,EAAI,CACf,IAAK,EACL,IAAK,EACL,MAAO,EACP,OAAQ,EACR,QAAS,EACT,OAAQ,CAxBR,WAA4B,EAAA,aAAa,OAAO,EAChD,YAA8B,EAAA,cAAc,OAAO,EACnD,SAAwB,EAAA,WAAW,OAAO,EAC1C,WAA4B,EAAA,aAAa,OAAO,EAChD,WAA4B,EAAA,aAAa,OAAO,CAoBxC,EACR,KAAM,EACN,KAAM,EACN,WAAY,EACZ,UAAW,EACX,KAAM,EACN,QAAS,EACT,IAAK,EACL,MAAO,EACP,KAAM,EACN,OAAQ,EACR,OAAQ,EACR,IA5CiB,EAAmB,IACpC,EAAO,EAAG,CAAC,EA4CX,OAAQ,EACR,IAAK,EACL,OAAQ,EACR,MAAO,EACP,UAAW,EACX,MAAO,EACP,YAjDsC,IAAI,EAAA,OAkD1C,SAhDA,EACA,IACwB,IAAI,EAAA,cAAc,EAAe,CAAG,CA+C9D"}
|
package/dist/s.d.ts
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { type AnySchema, Schema } from './core';
|
|
2
|
+
import { ArraySchema } from './schemas/array';
|
|
3
|
+
import { BigIntSchema } from './schemas/bigint';
|
|
4
|
+
import { BooleanSchema } from './schemas/boolean';
|
|
5
|
+
import { DateSchema } from './schemas/date';
|
|
6
|
+
import { EnumSchema, type EnumValues } from './schemas/enum';
|
|
7
|
+
import { InstanceOfSchema } from './schemas/instanceof';
|
|
8
|
+
import { IntersectSchema } from './schemas/intersect';
|
|
9
|
+
import { LazySchema } from './schemas/lazy';
|
|
10
|
+
import { LiteralSchema } from './schemas/literal';
|
|
11
|
+
import { MapSchema } from './schemas/map';
|
|
12
|
+
import { NeverSchema } from './schemas/never';
|
|
13
|
+
import { NumberSchema } from './schemas/number';
|
|
14
|
+
import { ObjectSchema, type ObjectShape } from './schemas/object';
|
|
15
|
+
import { type NormalizeItems, type RawOrSchema } from './schemas/raw-or';
|
|
16
|
+
import { RecordSchema } from './schemas/record';
|
|
17
|
+
import { SetSchema } from './schemas/set';
|
|
18
|
+
import { StringSchema } from './schemas/string';
|
|
19
|
+
import { TupleSchema, type TupleSchemas } from './schemas/tuple';
|
|
20
|
+
import { UnionSchema } from './schemas/union';
|
|
21
|
+
import { VariantSchema } from './schemas/variant';
|
|
22
|
+
/**
|
|
23
|
+
* Namespace of all schema factories. Use `s.string()`, `s.object()`, etc.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* import { s, type Infer } from '@vielzeug/spell';
|
|
27
|
+
*
|
|
28
|
+
* const User = s.object({ name: s.string(), age: s.number().int().positive() });
|
|
29
|
+
* type User = Infer<typeof User>;
|
|
30
|
+
*/
|
|
31
|
+
export declare const s: {
|
|
32
|
+
and: <A, B>(a: Schema<A, any>, b: Schema<B, any>) => IntersectSchema<readonly [Schema<A, any>, Schema<B, any>]>;
|
|
33
|
+
any: () => Schema<any>;
|
|
34
|
+
array: <T>(schema: Schema<T, any>) => ArraySchema<T>;
|
|
35
|
+
bigint: () => BigIntSchema;
|
|
36
|
+
boolean: () => BooleanSchema;
|
|
37
|
+
coerce: {
|
|
38
|
+
bigint: () => BigIntSchema;
|
|
39
|
+
boolean: () => BooleanSchema;
|
|
40
|
+
date: () => DateSchema;
|
|
41
|
+
number: () => NumberSchema;
|
|
42
|
+
string: () => StringSchema;
|
|
43
|
+
};
|
|
44
|
+
date: () => DateSchema;
|
|
45
|
+
enum: <const T extends EnumValues>(values: T) => EnumSchema<T>;
|
|
46
|
+
instanceof: <T>(cls: new (...args: any[]) => T) => InstanceOfSchema<T>;
|
|
47
|
+
intersect: <T extends readonly [RawOrSchema, RawOrSchema, ...RawOrSchema[]]>(...items: T) => IntersectSchema<NormalizeItems<T> & readonly AnySchema[]>;
|
|
48
|
+
lazy: <T>(getter: () => Schema<T, any>) => LazySchema<T>;
|
|
49
|
+
literal: <T extends string | number | boolean | null | undefined>(value: T) => LiteralSchema<T>;
|
|
50
|
+
map: <K, V>(keySchema: Schema<K, any>, valueSchema: Schema<V, any>) => MapSchema<K, V>;
|
|
51
|
+
never: () => NeverSchema;
|
|
52
|
+
null: () => LiteralSchema<null>;
|
|
53
|
+
number: () => NumberSchema;
|
|
54
|
+
object: <T extends ObjectShape>(shape: T) => ObjectSchema<T>;
|
|
55
|
+
or: <A, B>(a: Schema<A, any>, b: Schema<B, any>) => UnionSchema<readonly [Schema<A, any>, Schema<B, any>]>;
|
|
56
|
+
record: <K extends string, V>(keySchema: Schema<K, any>, valueSchema: Schema<V, any>) => RecordSchema<K, V>;
|
|
57
|
+
set: <T>(schema: Schema<T, any>) => SetSchema<T>;
|
|
58
|
+
string: () => StringSchema;
|
|
59
|
+
tuple: <const T extends TupleSchemas>(items: T) => TupleSchema<T>;
|
|
60
|
+
undefined: () => LiteralSchema<undefined>;
|
|
61
|
+
union: <T extends readonly [RawOrSchema, RawOrSchema, ...RawOrSchema[]]>(...items: T) => UnionSchema<NormalizeItems<T> & readonly AnySchema[]>;
|
|
62
|
+
unknown: () => Schema<unknown>;
|
|
63
|
+
variant: <K extends string, M extends Record<string, ObjectSchema<any>>>(discriminator: K, map: M) => VariantSchema<K, M>;
|
|
64
|
+
};
|
|
65
|
+
//# sourceMappingURL=s.d.ts.map
|
package/dist/s.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"s.d.ts","sourceRoot":"","sources":["../src/s.ts"],"names":[],"mappings":"AA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AAC,CAAC;SAWrD,CAAC,EAAE,CAAC,KAAK,MAAM,CAAC,CAAC,EAAE,GAAG,CAAC,KAAK,MAAM,CAAC,CAAC,EAAE,GAAG,CAAC,KAAG,WAAW,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,MAAM,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC;aAV/F,CAAC,SAAS,MAAM,EAAE,CAAC,aAAa,MAAM,CAAC,CAAC,EAAE,GAAG,CAAC,eAAe,MAAM,CAAC,CAAC,EAAE,GAAG,CAAC,KAAG,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC;UAEnG,CAAC,UAAU,MAAM,CAAC,CAAC,EAAE,GAAG,CAAC,KAAG,SAAS,CAAC,CAAC,CAAC;kBAClC,YAAY;kBACV,CAAC,SAAS,YAAY,SAAS,CAAC,KAAG,WAAW,CAAC,CAAC,CAAC;qBAChD,aAAa,CAAC,SAAS,CAAC;YAC/B,CAAC,SAAS,SAAS,CAAC,WAAW,EAAE,WAAW,EAAE,GAAG,WAAW,EAAE,CAAC,YACnE,CAAC,KACV,WAAW,CAAC,cAAc,CAAC,CAAC,CAAC,GAAG,SAAS,SAAS,EAAE,CAAC;mBAInC,MAAM,CAAC,OAAO,CAAC;cAClB,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,GAAG,CAAC,CAAC,iBAC9D,CAAC,OACX,CAAC,KACL,aAAa,CAAC,CAAC,EAAE,CAAC,CAAC;CA+CrB,CAAC"}
|
package/dist/s.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{Schema as e}from"./core.js";import{ArraySchema as t}from"./schemas/array.js";import{BigIntSchema as n}from"./schemas/bigint.js";import{BooleanSchema as r}from"./schemas/boolean.js";import{DateSchema as i}from"./schemas/date.js";import{EnumSchema as a}from"./schemas/enum.js";import{InstanceOfSchema as o}from"./schemas/instanceof.js";import{IntersectSchema as s}from"./schemas/intersect.js";import{LazySchema as c}from"./schemas/lazy.js";import{LiteralSchema as l}from"./schemas/literal.js";import{MapSchema as u}from"./schemas/map.js";import{NeverSchema as d}from"./schemas/never.js";import{NumberSchema as f}from"./schemas/number.js";import{UnionSchema as p}from"./schemas/union.js";import{ObjectSchema as m}from"./schemas/object.js";import{normalizeToSchemas as h}from"./schemas/raw-or.js";import{RecordSchema as g}from"./schemas/record.js";import{SetSchema as _}from"./schemas/set.js";import{StringSchema as v}from"./schemas/string.js";import{TupleSchema as y}from"./schemas/tuple.js";import{VariantSchema as b}from"./schemas/variant.js";var x=(e,t)=>k(e,t),S=()=>new e,C=e=>new t(e),w=()=>new n,T=()=>new r,E=()=>new i,D=e=>new a(e),O=e=>new o(e),k=(...e)=>new s(h(e)),A=e=>new c(e),j=e=>new l(e),M=(e,t)=>new u(e,t),N=()=>new d,P=()=>new l(null),F=()=>new f,I=e=>new m(e),L=(e,t)=>new g(e,t),R=e=>new _(e),z=()=>new v,B=e=>new y(e),V=()=>new l(void 0),H=(...e)=>new p(h(e)),U={and:x,any:S,array:C,bigint:w,boolean:T,coerce:{bigint:()=>n.coerce(),boolean:()=>r.coerce(),date:()=>i.coerce(),number:()=>f.coerce(),string:()=>v.coerce()},date:E,enum:D,instanceof:O,intersect:k,lazy:A,literal:j,map:M,never:N,null:P,number:F,object:I,or:(e,t)=>H(e,t),record:L,set:R,string:z,tuple:B,undefined:V,union:H,unknown:()=>new e,variant:(e,t)=>new b(e,t)};export{U as s};
|
|
2
|
+
//# sourceMappingURL=s.js.map
|
package/dist/s.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"s.js","names":[],"sources":["../src/s.ts"],"sourcesContent":["import { type AnySchema, Schema } from './core';\nimport { ArraySchema } from './schemas/array';\nimport { BigIntSchema } from './schemas/bigint';\nimport { BooleanSchema } from './schemas/boolean';\nimport { DateSchema } from './schemas/date';\nimport { EnumSchema, type EnumValues } from './schemas/enum';\nimport { InstanceOfSchema } from './schemas/instanceof';\nimport { IntersectSchema } from './schemas/intersect';\nimport { LazySchema } from './schemas/lazy';\nimport { LiteralSchema } from './schemas/literal';\nimport { MapSchema } from './schemas/map';\nimport { NeverSchema } from './schemas/never';\nimport { NumberSchema } from './schemas/number';\nimport { ObjectSchema, type ObjectShape } from './schemas/object';\nimport { type NormalizeItems, normalizeToSchemas, type RawOrSchema } from './schemas/raw-or';\nimport { RecordSchema } from './schemas/record';\nimport { SetSchema } from './schemas/set';\nimport { StringSchema } from './schemas/string';\nimport { TupleSchema, type TupleSchemas } from './schemas/tuple';\nimport { UnionSchema } from './schemas/union';\nimport { VariantSchema } from './schemas/variant';\n\n/* -------------------- Internal factory functions -------------------- */\n\nconst sAnd = <A, B>(a: Schema<A, any>, b: Schema<B, any>): IntersectSchema<readonly [Schema<A, any>, Schema<B, any>]> =>\n sIntersect(a, b);\nconst sAny = (): Schema<any> => new Schema();\nconst sArray = <T>(schema: Schema<T, any>): ArraySchema<T> => new ArraySchema(schema);\nconst sBigint = (): BigIntSchema => new BigIntSchema();\nconst sBoolean = (): BooleanSchema => new BooleanSchema();\nconst sDate = (): DateSchema => new DateSchema();\nconst sEnum = <const T extends EnumValues>(values: T): EnumSchema<T> => new EnumSchema(values);\nconst sInstanceof = <T>(cls: new (...args: any[]) => T): InstanceOfSchema<T> => new InstanceOfSchema(cls);\nconst sIntersect = <T extends readonly [RawOrSchema, RawOrSchema, ...RawOrSchema[]]>(\n ...items: T\n): IntersectSchema<NormalizeItems<T> & readonly AnySchema[]> =>\n new IntersectSchema(normalizeToSchemas(items) as NormalizeItems<T> & readonly AnySchema[]);\nconst sLazy = <T>(getter: () => Schema<T, any>): LazySchema<T> => new LazySchema(getter);\nconst sLiteral = <T extends string | number | boolean | null | undefined>(value: T): LiteralSchema<T> =>\n new LiteralSchema(value);\nconst sMap = <K, V>(keySchema: Schema<K, any>, valueSchema: Schema<V, any>): MapSchema<K, V> =>\n new MapSchema(keySchema, valueSchema);\nconst sNever = (): NeverSchema => new NeverSchema();\nconst sNull = (): LiteralSchema<null> => new LiteralSchema(null);\nconst sNumber = (): NumberSchema => new NumberSchema();\nconst sObject = <T extends ObjectShape>(shape: T): ObjectSchema<T> => new ObjectSchema(shape);\nconst sRecord = <K extends string, V>(keySchema: Schema<K, any>, valueSchema: Schema<V, any>): RecordSchema<K, V> =>\n new RecordSchema(keySchema, valueSchema);\nconst sSet = <T>(schema: Schema<T, any>): SetSchema<T> => new SetSchema(schema);\nconst sString = (): StringSchema => new StringSchema();\nconst sTuple = <const T extends TupleSchemas>(items: T): TupleSchema<T> => new TupleSchema(items);\nconst sUndefined = (): LiteralSchema<undefined> => new LiteralSchema(undefined);\nconst sUnion = <T extends readonly [RawOrSchema, RawOrSchema, ...RawOrSchema[]]>(\n ...items: T\n): UnionSchema<NormalizeItems<T> & readonly AnySchema[]> =>\n new UnionSchema(normalizeToSchemas(items) as NormalizeItems<T> & readonly AnySchema[]);\nconst sOr = <A, B>(a: Schema<A, any>, b: Schema<B, any>): UnionSchema<readonly [Schema<A, any>, Schema<B, any>]> =>\n sUnion(a, b);\nconst sUnknown = (): Schema<unknown> => new Schema();\nconst sVariant = <K extends string, M extends Record<string, ObjectSchema<any>>>(\n discriminator: K,\n map: M,\n): VariantSchema<K, M> => new VariantSchema(discriminator, map);\nconst sCoerce = {\n bigint: (): BigIntSchema => BigIntSchema.coerce(),\n boolean: (): BooleanSchema => BooleanSchema.coerce(),\n date: (): DateSchema => DateSchema.coerce(),\n number: (): NumberSchema => NumberSchema.coerce(),\n string: (): StringSchema => StringSchema.coerce(),\n};\n\n/* -------------------- `s` namespace — the public API -------------------- */\n\n/**\n * Namespace of all schema factories. Use `s.string()`, `s.object()`, etc.\n *\n * @example\n * import { s, type Infer } from '@vielzeug/spell';\n *\n * const User = s.object({ name: s.string(), age: s.number().int().positive() });\n * type User = Infer<typeof User>;\n */\nexport const s = {\n and: sAnd,\n any: sAny,\n array: sArray,\n bigint: sBigint,\n boolean: sBoolean,\n coerce: sCoerce,\n date: sDate,\n enum: sEnum,\n instanceof: sInstanceof,\n intersect: sIntersect,\n lazy: sLazy,\n literal: sLiteral,\n map: sMap,\n never: sNever,\n null: sNull,\n number: sNumber,\n object: sObject,\n or: sOr,\n record: sRecord,\n set: sSet,\n string: sString,\n tuple: sTuple,\n undefined: sUndefined,\n union: sUnion,\n unknown: sUnknown,\n variant: sVariant,\n};\n"],"mappings":"yhCAwBA,IAAM,GAAc,EAAmB,IACrC,EAAW,EAAG,CAAC,EACX,MAA0B,IAAI,EAC9B,EAAa,GAA2C,IAAI,EAAY,CAAM,EAC9E,MAA8B,IAAI,EAClC,MAAgC,IAAI,EACpC,MAA0B,IAAI,EAC9B,EAAqC,GAA6B,IAAI,EAAW,CAAM,EACvF,EAAkB,GAAwD,IAAI,EAAiB,CAAG,EAClG,GACJ,GAAG,IAEH,IAAI,EAAgB,EAAmB,CAAK,CAA6C,EACrF,EAAY,GAAgD,IAAI,EAAW,CAAM,EACjF,EAAoE,GACxE,IAAI,EAAc,CAAK,EACnB,GAAc,EAA2B,IAC7C,IAAI,EAAU,EAAW,CAAW,EAChC,MAA4B,IAAI,EAChC,MAAmC,IAAI,EAAc,IAAI,EACzD,MAA8B,IAAI,EAClC,EAAkC,GAA8B,IAAI,EAAa,CAAK,EACtF,GAAgC,EAA2B,IAC/D,IAAI,EAAa,EAAW,CAAW,EACnC,EAAW,GAAyC,IAAI,EAAU,CAAM,EACxE,MAA8B,IAAI,EAClC,EAAwC,GAA6B,IAAI,EAAY,CAAK,EAC1F,MAA6C,IAAI,EAAc,IAAA,EAAS,EACxE,GACJ,GAAG,IAEH,IAAI,EAAY,EAAmB,CAAK,CAA6C,EA2B1E,EAAI,CACf,IAAK,EACL,IAAK,EACL,MAAO,EACP,OAAQ,EACR,QAAS,EACT,OAAQ,CAxBR,WAA4B,EAAa,OAAO,EAChD,YAA8B,EAAc,OAAO,EACnD,SAAwB,EAAW,OAAO,EAC1C,WAA4B,EAAa,OAAO,EAChD,WAA4B,EAAa,OAAO,CAoBxC,EACR,KAAM,EACN,KAAM,EACN,WAAY,EACZ,UAAW,EACX,KAAM,EACN,QAAS,EACT,IAAK,EACL,MAAO,EACP,KAAM,EACN,OAAQ,EACR,OAAQ,EACR,IA5CiB,EAAmB,IACpC,EAAO,EAAG,CAAC,EA4CX,OAAQ,EACR,IAAK,EACL,OAAQ,EACR,MAAO,EACP,UAAW,EACX,MAAO,EACP,YAjDsC,IAAI,EAkD1C,SAhDA,EACA,IACwB,IAAI,EAAc,EAAe,CAAG,CA+C9D"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var e=new Set([`__proto__`,`constructor`,`prototype`]);function t(t){return e.has(t)}function n(e,t,n){Object.defineProperty(e,t,{configurable:!0,enumerable:!0,value:n,writable:!0})}function r(e){let t={};for(let[r,i]of e)n(t,r,i);return t}function i(e){return r(Object.entries(e))}exports.UNSAFE_OBJECT_KEYS=e,exports.cloneRecord=i,exports.defineOwnProperty=n,exports.isUnsafeObjectKey=t,exports.objectFromEntries=r;
|
|
2
|
+
//# sourceMappingURL=safe-object.cjs.map
|