@zmdb/validator 1.0.0-beta.1
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/LICENSE +674 -0
- package/README.md +35 -0
- package/dist/advanced/index.d.ts +53 -0
- package/dist/advanced/index.d.ts.map +1 -0
- package/dist/advanced/index.js +132 -0
- package/dist/advanced/index.js.map +1 -0
- package/dist/errors.d.ts +8 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +24 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +102 -0
- package/dist/index.js.map +1 -0
- package/dist/regex-complexity.d.ts +6 -0
- package/dist/regex-complexity.d.ts.map +1 -0
- package/dist/regex-complexity.js +42 -0
- package/dist/regex-complexity.js.map +1 -0
- package/dist/serialization/index.d.ts +20 -0
- package/dist/serialization/index.d.ts.map +1 -0
- package/dist/serialization/index.js +64 -0
- package/dist/serialization/index.js.map +1 -0
- package/dist/utilities/index.d.ts +29 -0
- package/dist/utilities/index.d.ts.map +1 -0
- package/dist/utilities/index.js +694 -0
- package/dist/utilities/index.js.map +1 -0
- package/dist/validation-error.d.ts +31 -0
- package/dist/validation-error.d.ts.map +1 -0
- package/dist/validation-error.js +43 -0
- package/dist/validation-error.js.map +1 -0
- package/package.json +61 -0
- package/src/advanced/index.ts +188 -0
- package/src/errors.ts +27 -0
- package/src/index.ts +115 -0
- package/src/regex-complexity.ts +45 -0
- package/src/serialization/index.ts +70 -0
- package/src/utilities/index.ts +748 -0
- package/src/validation-error.ts +53 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utilities/index.ts"],"names":[],"mappings":"AAAA,6DAA6D;AAC7D,EAAE;AACF,wFAAwF;AACxF,yFAAyF;AACzF,mFAAmF;AACnF,sFAAsF;AACtF,uFAAuF;AACvF,+BAA+B;AAC/B,EAAE;AACF,4DAA4D;A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AAI,GAAG,OAAO;IACtE,MAAM,IAAI,GAAG,MAAM,CAAC;IACpB,MAAM,MAAM,GAAsB,EAAE,CAAC;IACrC,aAAa,CAAC,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;IACvD,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export interface ValidationIssue {
|
|
2
|
+
readonly path: string;
|
|
3
|
+
readonly message: string;
|
|
4
|
+
readonly expected?: string;
|
|
5
|
+
readonly value?: unknown;
|
|
6
|
+
}
|
|
7
|
+
export declare class ValidationError extends Error {
|
|
8
|
+
readonly issues: readonly ValidationIssue[];
|
|
9
|
+
constructor(message: string, issues?: readonly ValidationIssue[]);
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Whether a thrown value claims to be about validation.
|
|
13
|
+
*
|
|
14
|
+
* Structural rather than `instanceof ValidationError`, because a validator a caller wrote
|
|
15
|
+
* themselves throws its own error type — zod's, io-ts's, or one of their own — and the HTTP
|
|
16
|
+
* adapters that ask this question have no business caring which. Carrying an `issues`
|
|
17
|
+
* property is the claim; {@link validationIssuesOf} decides whether it holds up.
|
|
18
|
+
*/
|
|
19
|
+
export declare function claimsValidationIssues(error: unknown): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* The issues on a thrown error, or `undefined` if it carries none worth reporting.
|
|
22
|
+
*
|
|
23
|
+
* Every entry is checked rather than asserted. These end up in a 400 body that a client
|
|
24
|
+
* reads, and "it has an `issues` property" is no evidence that the property holds issues —
|
|
25
|
+
* an error whose `issues` was a string used to be serialized into the response as though it
|
|
26
|
+
* were the list. An entry missing a `path` or a `message` is dropped rather than passed on
|
|
27
|
+
* half-formed; a `ValidationError` with an empty list still answers with the empty list,
|
|
28
|
+
* which is what tells a caller "validation, and it declined to say more".
|
|
29
|
+
*/
|
|
30
|
+
export declare function validationIssuesOf(error: unknown): readonly ValidationIssue[] | undefined;
|
|
31
|
+
//# sourceMappingURL=validation-error.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation-error.d.ts","sourceRoot":"","sources":["../src/validation-error.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED,qBAAa,eAAgB,SAAQ,KAAK;IACxC,QAAQ,CAAC,MAAM,EAAE,SAAS,eAAe,EAAE,CAAC;IAE5C,YAAY,OAAO,EAAE,MAAM,EAAE,MAAM,GAAE,SAAS,eAAe,EAAO,EAInE;CACF;AAED;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAE9D;AAED;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,SAAS,eAAe,EAAE,GAAG,SAAS,CAazF"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export class ValidationError extends Error {
|
|
2
|
+
issues;
|
|
3
|
+
constructor(message, issues = []) {
|
|
4
|
+
super(message);
|
|
5
|
+
this.name = 'ValidationError';
|
|
6
|
+
this.issues = issues;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Whether a thrown value claims to be about validation.
|
|
11
|
+
*
|
|
12
|
+
* Structural rather than `instanceof ValidationError`, because a validator a caller wrote
|
|
13
|
+
* themselves throws its own error type — zod's, io-ts's, or one of their own — and the HTTP
|
|
14
|
+
* adapters that ask this question have no business caring which. Carrying an `issues`
|
|
15
|
+
* property is the claim; {@link validationIssuesOf} decides whether it holds up.
|
|
16
|
+
*/
|
|
17
|
+
export function claimsValidationIssues(error) {
|
|
18
|
+
return error !== null && typeof error === 'object' && 'issues' in error;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* The issues on a thrown error, or `undefined` if it carries none worth reporting.
|
|
22
|
+
*
|
|
23
|
+
* Every entry is checked rather than asserted. These end up in a 400 body that a client
|
|
24
|
+
* reads, and "it has an `issues` property" is no evidence that the property holds issues —
|
|
25
|
+
* an error whose `issues` was a string used to be serialized into the response as though it
|
|
26
|
+
* were the list. An entry missing a `path` or a `message` is dropped rather than passed on
|
|
27
|
+
* half-formed; a `ValidationError` with an empty list still answers with the empty list,
|
|
28
|
+
* which is what tells a caller "validation, and it declined to say more".
|
|
29
|
+
*/
|
|
30
|
+
export function validationIssuesOf(error) {
|
|
31
|
+
if (error === null || typeof error !== 'object' || !('issues' in error))
|
|
32
|
+
return undefined;
|
|
33
|
+
const issues = error.issues;
|
|
34
|
+
if (!Array.isArray(issues))
|
|
35
|
+
return undefined;
|
|
36
|
+
return issues.filter((issue) => issue !== null &&
|
|
37
|
+
typeof issue === 'object' &&
|
|
38
|
+
'path' in issue &&
|
|
39
|
+
typeof issue.path === 'string' &&
|
|
40
|
+
'message' in issue &&
|
|
41
|
+
typeof issue.message === 'string');
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=validation-error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation-error.js","sourceRoot":"","sources":["../src/validation-error.ts"],"names":[],"mappings":"AAOA,MAAM,OAAO,eAAgB,SAAQ,KAAK;IAC/B,MAAM,CAA6B;IAE5C,YAAY,OAAe,EAAE,MAAM,GAA+B,EAAE;QAClE,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;QAC9B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;CACF;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,sBAAsB,CAAC,KAAc;IACnD,OAAO,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,QAAQ,IAAI,KAAK,CAAC;AAC1E,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,kBAAkB,CAAC,KAAc;IAC/C,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,CAAC,QAAQ,IAAI,KAAK,CAAC;QAAE,OAAO,SAAS,CAAC;IAC1F,MAAM,MAAM,GAAY,KAAK,CAAC,MAAM,CAAC;IACrC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC;QAAE,OAAO,SAAS,CAAC;IAC7C,OAAO,MAAM,CAAC,MAAM,CAClB,CAAC,KAAc,EAA4B,EAAE,CAC3C,KAAK,KAAK,IAAI;QACd,OAAO,KAAK,KAAK,QAAQ;QACzB,MAAM,IAAI,KAAK;QACf,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ;QAC9B,SAAS,IAAI,KAAK;QAClB,OAAO,KAAK,CAAC,OAAO,KAAK,QAAQ,CACpC,CAAC;AACJ,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@zmdb/validator",
|
|
3
|
+
"version": "1.0.0-beta.1",
|
|
4
|
+
"description": "Runtime helpers for ahead-of-time validation and JSON serialization: is/assert/validate/equals/random, unions, transforms, and generated-code errors.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"aot",
|
|
7
|
+
"json",
|
|
8
|
+
"runtime-types",
|
|
9
|
+
"serialization",
|
|
10
|
+
"typescript",
|
|
11
|
+
"validation",
|
|
12
|
+
"zmdb"
|
|
13
|
+
],
|
|
14
|
+
"homepage": "https://github.com/ambasta/zmdb#readme",
|
|
15
|
+
"bugs": {
|
|
16
|
+
"url": "https://github.com/ambasta/zmdb/issues"
|
|
17
|
+
},
|
|
18
|
+
"license": "GPL-3.0-or-later",
|
|
19
|
+
"author": "zmdb contributors",
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "git+https://github.com/ambasta/zmdb.git",
|
|
23
|
+
"directory": "packages/validator"
|
|
24
|
+
},
|
|
25
|
+
"type": "module",
|
|
26
|
+
"sideEffects": false,
|
|
27
|
+
"exports": {
|
|
28
|
+
".": {
|
|
29
|
+
"types": "./dist/index.d.ts",
|
|
30
|
+
"import": "./dist/index.js"
|
|
31
|
+
},
|
|
32
|
+
"./advanced": {
|
|
33
|
+
"types": "./dist/advanced/index.d.ts",
|
|
34
|
+
"import": "./dist/advanced/index.js"
|
|
35
|
+
},
|
|
36
|
+
"./errors": {
|
|
37
|
+
"types": "./dist/errors.d.ts",
|
|
38
|
+
"import": "./dist/errors.js"
|
|
39
|
+
},
|
|
40
|
+
"./serialization": {
|
|
41
|
+
"types": "./dist/serialization/index.d.ts",
|
|
42
|
+
"import": "./dist/serialization/index.js"
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
"publishConfig": {
|
|
46
|
+
"access": "public",
|
|
47
|
+
"tag": "beta"
|
|
48
|
+
},
|
|
49
|
+
"scripts": {
|
|
50
|
+
"build": "node ../../scripts/build-package.mjs",
|
|
51
|
+
"test": "vitest run"
|
|
52
|
+
},
|
|
53
|
+
"dependencies": {
|
|
54
|
+
"@zmdb/schema": "1.0.0-beta.1"
|
|
55
|
+
},
|
|
56
|
+
"engines": {
|
|
57
|
+
"node": ">=26"
|
|
58
|
+
},
|
|
59
|
+
"main": "./dist/index.js",
|
|
60
|
+
"types": "./dist/index.d.ts"
|
|
61
|
+
}
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
// Advanced validation — implementation.
|
|
2
|
+
// #46 refinement compilation (refine + refinement-aware validateObject with
|
|
3
|
+
// exact error paths). Coercion + object strictness (#49) are co-implemented
|
|
4
|
+
// because the same validateObject drives them. #47 transform remains a rule
|
|
5
|
+
// constructor only; no validator path applies it.
|
|
6
|
+
import { type Rule, type ValidationIssue } from '../index.js';
|
|
7
|
+
|
|
8
|
+
export type { ValidationIssue };
|
|
9
|
+
|
|
10
|
+
// #49 — branded (nominal) types. Compile-time only; erases to the base type at
|
|
11
|
+
// runtime (no footprint). `Brand<number, 'UserId'>` is assignable to `number`
|
|
12
|
+
// but distinct from `Brand<number, 'OrderId'>`.
|
|
13
|
+
declare const __brand: unique symbol;
|
|
14
|
+
export type Brand<Base, Tag extends string> = Base & { readonly [__brand]: Tag };
|
|
15
|
+
|
|
16
|
+
/** True for a non-null, non-array object — proves a keyed read is safe. */
|
|
17
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
18
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export type RefinePredicate = (v: unknown) => boolean;
|
|
22
|
+
export type TransformFn = (v: unknown) => unknown;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* A refinement rule: a real predicate plus its intrinsic source text for inspection.
|
|
26
|
+
*
|
|
27
|
+
* The predicate is passed in as a *function value*, not a source string that we
|
|
28
|
+
* compile or interpret at import time. A string form creates a second executable
|
|
29
|
+
* language whose property and call reachability must be secured; a function is
|
|
30
|
+
* instead typechecked at the call site. `source` records the function's intrinsic
|
|
31
|
+
* text for inspection; the current emitter does not consume advanced-rule source
|
|
32
|
+
* (PRD §9.5).
|
|
33
|
+
*/
|
|
34
|
+
export interface RefineRule extends Rule {
|
|
35
|
+
readonly kind: 'refine';
|
|
36
|
+
readonly source: string;
|
|
37
|
+
readonly message: string;
|
|
38
|
+
readonly predicate: RefinePredicate;
|
|
39
|
+
}
|
|
40
|
+
/** A post-validation conversion. Same function-not-source rule as {@link RefineRule}. */
|
|
41
|
+
export interface TransformRule extends Rule {
|
|
42
|
+
readonly kind: 'transform';
|
|
43
|
+
readonly source: string;
|
|
44
|
+
readonly apply: TransformFn;
|
|
45
|
+
}
|
|
46
|
+
export interface UnionRule extends Rule {
|
|
47
|
+
readonly kind: 'union';
|
|
48
|
+
readonly branches: readonly Rule[];
|
|
49
|
+
}
|
|
50
|
+
export interface DiscriminatedRule extends Rule {
|
|
51
|
+
readonly kind: 'discriminated';
|
|
52
|
+
readonly key: string;
|
|
53
|
+
readonly map: Record<string, Rule>;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function refine(predicate: RefinePredicate, message: string): RefineRule {
|
|
57
|
+
if (typeof predicate !== 'function') {
|
|
58
|
+
throw new TypeError('refine() requires a function value; source strings are not supported');
|
|
59
|
+
}
|
|
60
|
+
const source = Function.prototype.toString.call(predicate);
|
|
61
|
+
return Object.freeze({
|
|
62
|
+
kind: 'refine',
|
|
63
|
+
args: Object.freeze([source, message]),
|
|
64
|
+
source,
|
|
65
|
+
message,
|
|
66
|
+
predicate,
|
|
67
|
+
} satisfies RefineRule);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function transform(apply: TransformFn): TransformRule {
|
|
71
|
+
if (typeof apply !== 'function') {
|
|
72
|
+
throw new TypeError('transform() requires a function value; source strings are not supported');
|
|
73
|
+
}
|
|
74
|
+
const source = Function.prototype.toString.call(apply);
|
|
75
|
+
return Object.freeze({
|
|
76
|
+
kind: 'transform',
|
|
77
|
+
args: Object.freeze([source]),
|
|
78
|
+
source,
|
|
79
|
+
apply,
|
|
80
|
+
} satisfies TransformRule);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function union(...rules: readonly Rule[]): UnionRule {
|
|
84
|
+
return Object.freeze({ kind: 'union', args: Object.freeze(rules), branches: rules } satisfies UnionRule);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export function discriminated(key: string, map: Record<string, Rule>): DiscriminatedRule {
|
|
88
|
+
return Object.freeze({
|
|
89
|
+
kind: 'discriminated',
|
|
90
|
+
args: Object.freeze([key]),
|
|
91
|
+
key,
|
|
92
|
+
map,
|
|
93
|
+
} satisfies DiscriminatedRule);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// `Rule` is an open interface (any package may add a kind), so `rule.kind === x`
|
|
97
|
+
// cannot narrow it the way a closed union would. These guards check the tag *and*
|
|
98
|
+
// the payload it implies, which is what makes the narrowing sound without a cast.
|
|
99
|
+
function isRefine(rule: Rule): rule is RefineRule {
|
|
100
|
+
return rule.kind === 'refine' && 'predicate' in rule && typeof rule.predicate === 'function';
|
|
101
|
+
}
|
|
102
|
+
function isUnion(rule: Rule): rule is UnionRule {
|
|
103
|
+
return rule.kind === 'union' && 'branches' in rule && Array.isArray(rule.branches);
|
|
104
|
+
}
|
|
105
|
+
function isDiscriminated(rule: Rule): rule is DiscriminatedRule {
|
|
106
|
+
return rule.kind === 'discriminated' && 'key' in rule && typeof rule.key === 'string' && 'map' in rule;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// Runtime evaluator for the rule-value API. The type-first emitter is a separate path.
|
|
110
|
+
export function evalRule(rule: Rule, value: unknown): boolean {
|
|
111
|
+
if (isUnion(rule)) return rule.branches.some(b => evalRule(b, value));
|
|
112
|
+
if (isDiscriminated(rule)) {
|
|
113
|
+
if (!isRecord(value)) return false;
|
|
114
|
+
const disc = value[rule.key];
|
|
115
|
+
if (typeof disc !== 'string') return false;
|
|
116
|
+
const branch = rule.map[disc];
|
|
117
|
+
if (!branch) return false;
|
|
118
|
+
return evalRule(branch, value.value);
|
|
119
|
+
}
|
|
120
|
+
return checkRule(rule, value).ok;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export const coerce = {
|
|
124
|
+
number(expr: unknown): number {
|
|
125
|
+
const n = Number(expr);
|
|
126
|
+
if (Number.isNaN(n)) throw new TypeError(`cannot coerce to number: ${String(expr)}`);
|
|
127
|
+
return n;
|
|
128
|
+
},
|
|
129
|
+
} as const;
|
|
130
|
+
|
|
131
|
+
export type ObjectMode = 'strict' | 'strip' | 'passthrough';
|
|
132
|
+
|
|
133
|
+
function checkRule(rule: Rule, value: unknown): { ok: boolean; expected: string; message: string } {
|
|
134
|
+
// Refinement rule.
|
|
135
|
+
if (isRefine(rule)) {
|
|
136
|
+
return { ok: rule.predicate(value), expected: rule.source, message: rule.message };
|
|
137
|
+
}
|
|
138
|
+
// Primitive tag rules (mirror the aot-validator runtime fallback).
|
|
139
|
+
const [arg] = rule.args;
|
|
140
|
+
switch (rule.kind) {
|
|
141
|
+
case 'Min':
|
|
142
|
+
return {
|
|
143
|
+
ok: typeof value === 'number' && typeof arg === 'number' && value >= arg,
|
|
144
|
+
expected: `number >= ${String(arg)}`,
|
|
145
|
+
message: `must be >= ${String(arg)}`,
|
|
146
|
+
};
|
|
147
|
+
case 'MaxLength':
|
|
148
|
+
return {
|
|
149
|
+
ok: typeof value === 'string' && typeof arg === 'number' && value.length <= arg,
|
|
150
|
+
expected: `string length <= ${String(arg)}`,
|
|
151
|
+
message: `length must be <= ${String(arg)}`,
|
|
152
|
+
};
|
|
153
|
+
default:
|
|
154
|
+
return { ok: true, expected: rule.kind, message: '' };
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export function validateObject(
|
|
159
|
+
value: unknown,
|
|
160
|
+
rules: Record<string, Rule>,
|
|
161
|
+
mode: ObjectMode,
|
|
162
|
+
): { success: boolean; issues: readonly ValidationIssue[] } {
|
|
163
|
+
const issues: ValidationIssue[] = [];
|
|
164
|
+
const obj = isRecord(value) ? value : {};
|
|
165
|
+
|
|
166
|
+
// Excess-key handling for strict mode.
|
|
167
|
+
if (mode === 'strict') {
|
|
168
|
+
for (const key of Object.keys(obj)) {
|
|
169
|
+
if (!(key in rules)) {
|
|
170
|
+
issues.push({
|
|
171
|
+
path: `input.${key}`,
|
|
172
|
+
expected: 'no excess property',
|
|
173
|
+
value: obj[key],
|
|
174
|
+
message: `unexpected property "${key}"`,
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
for (const [key, rule] of Object.entries(rules)) {
|
|
181
|
+
const res = checkRule(rule, obj[key]);
|
|
182
|
+
if (!res.ok) {
|
|
183
|
+
issues.push({ path: `input.${key}`, expected: res.expected, value: obj[key], message: res.message });
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
return { success: issues.length === 0, issues };
|
|
188
|
+
}
|
package/src/errors.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// The one thing emitted code imports at runtime.
|
|
2
|
+
//
|
|
3
|
+
// `assert<T>(x)` has to throw something, and the interesting question is *what*. A
|
|
4
|
+
// hoisted class in the emitted prelude would make `err instanceof AssertError` false in
|
|
5
|
+
// a built bundle and true in dev — the exact class of bug the AOT path exists to avoid,
|
|
6
|
+
// since the two paths are supposed to be indistinguishable (REQ-AV-4).
|
|
7
|
+
//
|
|
8
|
+
// So the emitted prelude imports this module, and it is kept in its own file precisely
|
|
9
|
+
// so that import costs a few lines rather than the whole runtime walker.
|
|
10
|
+
|
|
11
|
+
import { type ValidationIssue } from './index.js';
|
|
12
|
+
|
|
13
|
+
export class AssertError extends Error {
|
|
14
|
+
readonly issues: readonly ValidationIssue[];
|
|
15
|
+
|
|
16
|
+
constructor(message: string, issues: readonly ValidationIssue[] = []) {
|
|
17
|
+
super(message);
|
|
18
|
+
this.name = 'AssertError';
|
|
19
|
+
this.issues = issues;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Throw an `AssertError` carrying `issues`; the first issue supplies the message. */
|
|
24
|
+
export function failWith(issues: readonly ValidationIssue[]): never {
|
|
25
|
+
const first = issues[0];
|
|
26
|
+
throw new AssertError(first ? first.message : 'validation failed', issues);
|
|
27
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
// @zmdb/validator — the runtime half.
|
|
2
|
+
//
|
|
3
|
+
// Nothing reachable from this entry point may import `typescript`. The compiler is a
|
|
4
|
+
// build-time dependency, and an application that imports `tags` to declare a
|
|
5
|
+
// constraint must not pull it into a runtime bundle. Compiler ownership lives in
|
|
6
|
+
// `@zmdb/compiler`; `.github/scripts/verify-exports.mjs` enforces the split.
|
|
7
|
+
|
|
8
|
+
import { getCachedRegExp, MAX_REGEX_CACHE_SIZE, validatePatternComplexity } from './regex-complexity.js';
|
|
9
|
+
|
|
10
|
+
export { AssertError, failWith } from './errors.js';
|
|
11
|
+
export { getCachedRegExp, MAX_REGEX_CACHE_SIZE, validatePatternComplexity } from './regex-complexity.js';
|
|
12
|
+
|
|
13
|
+
export interface Rule {
|
|
14
|
+
readonly kind: string;
|
|
15
|
+
readonly args: readonly unknown[];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function rule(kind: string, ...args: readonly unknown[]): Rule {
|
|
19
|
+
return Object.freeze({ kind, args: Object.freeze(args) });
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// One spelling per constraint, and it is the tag's. `Min`/`Max` used to be `Minimum`/
|
|
23
|
+
// `Maximum` here while the type-level tag has always been `Min<N>`/`Max<N>`, which left
|
|
24
|
+
// `ir/index.ts` folding case *and* mapping two names onto one kind. Now that a constraint
|
|
25
|
+
// is declared as `number & Min<18>`, the `tags.Min(18)` call has no declaration role
|
|
26
|
+
// left — the `Rule` object is the AOT's pre-transform fallback representation — so the
|
|
27
|
+
// name that stays is the one you write in a type.
|
|
28
|
+
export const tags = {
|
|
29
|
+
Min(n: number): Rule {
|
|
30
|
+
return rule('Min', n);
|
|
31
|
+
},
|
|
32
|
+
Max(n: number): Rule {
|
|
33
|
+
return rule('Max', n);
|
|
34
|
+
},
|
|
35
|
+
MinLength(n: number): Rule {
|
|
36
|
+
return rule('MinLength', n);
|
|
37
|
+
},
|
|
38
|
+
MaxLength(n: number): Rule {
|
|
39
|
+
return rule('MaxLength', n);
|
|
40
|
+
},
|
|
41
|
+
Pattern(re: string): Rule {
|
|
42
|
+
validatePatternComplexity(re);
|
|
43
|
+
return rule('Pattern', re);
|
|
44
|
+
},
|
|
45
|
+
Enum(...values: readonly string[]): Rule {
|
|
46
|
+
return rule('Enum', ...values);
|
|
47
|
+
},
|
|
48
|
+
} as const;
|
|
49
|
+
|
|
50
|
+
// Caches for zero-allocation fallback validation.
|
|
51
|
+
const regexCache = new Map<string, RegExp>();
|
|
52
|
+
export function getRegExp(pattern: string): RegExp {
|
|
53
|
+
let re = regexCache.get(pattern);
|
|
54
|
+
if (re) {
|
|
55
|
+
regexCache.delete(pattern);
|
|
56
|
+
regexCache.set(pattern, re);
|
|
57
|
+
return re;
|
|
58
|
+
}
|
|
59
|
+
if (regexCache.size >= MAX_REGEX_CACHE_SIZE) {
|
|
60
|
+
const oldestKey = regexCache.keys().next().value;
|
|
61
|
+
if (oldestKey !== undefined) {
|
|
62
|
+
regexCache.delete(oldestKey);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
re = new RegExp(pattern);
|
|
66
|
+
regexCache.set(pattern, re);
|
|
67
|
+
return re;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const enumSetCache = new WeakMap<readonly unknown[], Set<unknown>>();
|
|
71
|
+
export function getEnumSet(values: readonly unknown[]): Set<unknown> {
|
|
72
|
+
let set = enumSetCache.get(values);
|
|
73
|
+
if (!set) {
|
|
74
|
+
set = new Set(values);
|
|
75
|
+
enumSetCache.set(values, set);
|
|
76
|
+
}
|
|
77
|
+
return set;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Runtime-safety fallback: identical boolean semantics to the inlined form.
|
|
81
|
+
// This is what executes pre-transform (dev / ts-node).
|
|
82
|
+
export function validateRule(r: Rule, expr: unknown): boolean {
|
|
83
|
+
// `args` is `readonly unknown[]` (any package may define a kind), so the bound
|
|
84
|
+
// is re-checked rather than asserted: `typeof arg === 'number'` costs nothing a
|
|
85
|
+
// JIT can't fold, and this is the fallback path — the AOT emission is what the
|
|
86
|
+
// benchmarks measure.
|
|
87
|
+
const [arg] = r.args;
|
|
88
|
+
switch (r.kind) {
|
|
89
|
+
case 'Min':
|
|
90
|
+
return typeof expr === 'number' && typeof arg === 'number' && expr >= arg;
|
|
91
|
+
case 'Max':
|
|
92
|
+
return typeof expr === 'number' && typeof arg === 'number' && expr <= arg;
|
|
93
|
+
case 'MinLength':
|
|
94
|
+
return typeof expr === 'string' && typeof arg === 'number' && expr.length >= arg;
|
|
95
|
+
case 'MaxLength':
|
|
96
|
+
return typeof expr === 'string' && typeof arg === 'number' && expr.length <= arg;
|
|
97
|
+
case 'Pattern':
|
|
98
|
+
// No input-length cap. There used to be one — 10 000 characters, and a throw past it
|
|
99
|
+
// — but the inlined form is `/pat/.test(x)` with no such limit, so the same call
|
|
100
|
+
// answered `false` in a build and threw in dev. REQ-AV-4 does not allow that, and of
|
|
101
|
+
// the two behaviours the cap is the one with no counterpart to move it to.
|
|
102
|
+
// Re-checked, not asserted, for the reason above: an unchecked `args[0]` would have
|
|
103
|
+
// reached `new RegExp` and been coerced, so `Pattern` with a number in it compiled a
|
|
104
|
+
// pattern rather than answering `false` like every other rule with a bad argument.
|
|
105
|
+
return typeof expr === 'string' && typeof arg === 'string' && getCachedRegExp(arg).test(expr);
|
|
106
|
+
case 'Enum':
|
|
107
|
+
return getEnumSet(r.args).has(expr);
|
|
108
|
+
default:
|
|
109
|
+
throw new Error(`unknown rule kind: ${r.kind}`);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export { ValidationError, claimsValidationIssues, validationIssuesOf } from './validation-error.js';
|
|
114
|
+
export type { ValidationIssue } from './validation-error.js';
|
|
115
|
+
export * from './utilities/index.js';
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// Regular expression syntax validation and a bounded compiled-RegExp cache.
|
|
2
|
+
//
|
|
3
|
+
// This validates syntax only; there is no static ReDoS analysis here, and the name is a
|
|
4
|
+
// leftover from when there was meant to be.
|
|
5
|
+
//
|
|
6
|
+
// There used to also be a `safeTestPattern` that refused inputs over 10 000 characters. It
|
|
7
|
+
// is gone, because the emitted form of the same check is `/pat/.test(x)` and has no such
|
|
8
|
+
// limit: keeping it meant one call site answering `false` after a build and throwing before
|
|
9
|
+
// one, which is precisely the divergence REQ-AV-4 exists to rule out. A cap that only one
|
|
10
|
+
// of the two paths can honour is not a safety feature.
|
|
11
|
+
|
|
12
|
+
import { ValidationError } from './index.js';
|
|
13
|
+
|
|
14
|
+
export { ValidationError };
|
|
15
|
+
|
|
16
|
+
export function validatePatternComplexity(pattern: string): void {
|
|
17
|
+
try {
|
|
18
|
+
RegExp(pattern);
|
|
19
|
+
} catch (err: unknown) {
|
|
20
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
21
|
+
throw new ValidationError(`Invalid regular expression pattern: ${msg}`);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export const MAX_REGEX_CACHE_SIZE = 1000;
|
|
26
|
+
const patternCache = new Map<string, RegExp>();
|
|
27
|
+
|
|
28
|
+
export function getCachedRegExp(pattern: string): RegExp {
|
|
29
|
+
let re = patternCache.get(pattern);
|
|
30
|
+
if (re) {
|
|
31
|
+
patternCache.delete(pattern);
|
|
32
|
+
patternCache.set(pattern, re);
|
|
33
|
+
return re;
|
|
34
|
+
}
|
|
35
|
+
validatePatternComplexity(pattern);
|
|
36
|
+
if (patternCache.size >= MAX_REGEX_CACHE_SIZE) {
|
|
37
|
+
const oldestKey = patternCache.keys().next().value;
|
|
38
|
+
if (oldestKey !== undefined) {
|
|
39
|
+
patternCache.delete(oldestKey);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
re = new RegExp(pattern);
|
|
43
|
+
patternCache.set(pattern, re);
|
|
44
|
+
return re;
|
|
45
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// JSON serialization and validated parsing.
|
|
2
|
+
import { type ValidationIssue } from '../advanced/index.js';
|
|
3
|
+
import { assert, AssertError, type TypeIR } from '../index.js';
|
|
4
|
+
|
|
5
|
+
// Native JSON owns property traversal and toJSON calls. Primitive bigint is
|
|
6
|
+
// rejected before a root toJSON hook can run; native JSON rejects nested bigint.
|
|
7
|
+
export function stringify(value: unknown): string {
|
|
8
|
+
if (typeof value === 'bigint') {
|
|
9
|
+
throw new TypeError('Do not know how to serialize a BigInt');
|
|
10
|
+
}
|
|
11
|
+
return JSON.stringify(value);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// `TypeIR`: the witness a user has is the generated one, and there is no longer a
|
|
15
|
+
// hand-written form of it to accept (REQ-TF-9).
|
|
16
|
+
export function assertStringify(value: unknown, schema?: TypeIR): string {
|
|
17
|
+
// Validate first (throws AssertError on failure), then serialize.
|
|
18
|
+
assert(value, schema);
|
|
19
|
+
return stringify(value);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface ParseResult<T> {
|
|
23
|
+
readonly success: boolean;
|
|
24
|
+
readonly data?: T;
|
|
25
|
+
readonly issues?: readonly ValidationIssue[];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Parse JSON without rebuilding the object graph. Reports malformed input as
|
|
30
|
+
* structured issues instead of throwing.
|
|
31
|
+
*
|
|
32
|
+
* `T` is an *unvalidated* claim about the payload — exactly as much as
|
|
33
|
+
* `JSON.parse` gives you, and no more. Use {@link decode} when you need the
|
|
34
|
+
* claim checked against a schema.
|
|
35
|
+
*/
|
|
36
|
+
export function parse<T = unknown>(text: string): ParseResult<T> {
|
|
37
|
+
try {
|
|
38
|
+
// boundary: JSON.parse is `any` by definition; the caller's `T` is asserted,
|
|
39
|
+
// not proven. `decode` is the proving variant.
|
|
40
|
+
const data = JSON.parse(text) as T;
|
|
41
|
+
return { success: true, data };
|
|
42
|
+
} catch (err) {
|
|
43
|
+
return {
|
|
44
|
+
success: false,
|
|
45
|
+
issues: [
|
|
46
|
+
{
|
|
47
|
+
path: 'input',
|
|
48
|
+
expected: 'valid JSON',
|
|
49
|
+
value: text,
|
|
50
|
+
message: err instanceof Error ? err.message : 'invalid JSON',
|
|
51
|
+
},
|
|
52
|
+
],
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// #54 — typed parse/decode: parse JSON then validate into T against a schema.
|
|
58
|
+
// Malformed JSON or a validation failure yields success:false with structured
|
|
59
|
+
// issues (exact paths).
|
|
60
|
+
export function decode<T = unknown>(text: string, schema?: TypeIR): ParseResult<T> {
|
|
61
|
+
const parsed = parse<T>(text);
|
|
62
|
+
if (!parsed.success) return parsed;
|
|
63
|
+
try {
|
|
64
|
+
const data = assert<T>(parsed.data, schema);
|
|
65
|
+
return { success: true, data };
|
|
66
|
+
} catch (err) {
|
|
67
|
+
const issues = err instanceof AssertError ? err.issues : [];
|
|
68
|
+
return { success: false, issues };
|
|
69
|
+
}
|
|
70
|
+
}
|