@modulify/validator 0.2.1 → 0.3.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/CHANGELOG.md +29 -1
- package/README.md +12 -2
- package/dist/assert.cjs +99 -63
- package/dist/assert.d.cts +37 -0
- package/dist/assert.d.mts +37 -0
- package/dist/assert.d.ts +24 -3
- package/dist/assert.mjs +94 -64
- package/dist/assertions.cjs +283 -178
- package/dist/assertions.d.cts +56 -0
- package/dist/assertions.d.mts +56 -0
- package/dist/assertions.d.ts +43 -45
- package/dist/assertions.mjs +274 -201
- package/dist/checkers.cjs +23 -0
- package/dist/checkers.d.cts +8 -0
- package/dist/checkers.d.mts +8 -0
- package/dist/checkers.d.ts +1 -1
- package/dist/checkers.mjs +16 -0
- package/dist/combinators.cjs +305 -304
- package/dist/combinators.d.cts +16 -0
- package/dist/combinators.d.mts +16 -0
- package/dist/combinators.d.ts +15 -16
- package/dist/combinators.mjs +305 -314
- package/dist/constraints.cjs +23 -0
- package/dist/constraints.d.cts +4 -0
- package/dist/constraints.d.mts +4 -0
- package/dist/constraints.d.ts +2 -2
- package/dist/constraints.mjs +21 -0
- package/dist/extractors.cjs +6 -0
- package/dist/extractors.d.cts +2 -0
- package/dist/extractors.d.mts +2 -0
- package/dist/extractors.mjs +5 -0
- package/dist/index.cjs +140 -219
- package/dist/index.d.cts +12 -0
- package/dist/index.d.mts +12 -0
- package/dist/index.d.ts +9 -9
- package/dist/index.mjs +93 -222
- package/dist/json-schema.cjs +364 -489
- package/dist/json-schema.d.cts +14 -0
- package/dist/json-schema.d.mts +14 -0
- package/dist/json-schema.d.ts +3 -3
- package/dist/json-schema.mjs +365 -492
- package/dist/metadata.cjs +98 -7
- package/dist/metadata.d.cts +8 -0
- package/dist/metadata.d.mts +8 -0
- package/dist/metadata.d.ts +2 -2
- package/dist/metadata.mjs +93 -7
- package/dist/predicates.cjs +98 -41
- package/dist/predicates.d.cts +77 -0
- package/dist/predicates.d.mts +77 -0
- package/dist/predicates.d.ts +25 -4
- package/dist/predicates.mjs +92 -66
- package/dist/types/index.d.cts +984 -0
- package/dist/types/index.d.mts +984 -0
- package/dist/types/index.d.ts +984 -0
- package/dist/types/json-schema.d.cts +75 -0
- package/dist/types/json-schema.d.mts +75 -0
- package/dist/types/json-schema.d.ts +75 -0
- package/dist/violations.cjs +81 -0
- package/dist/violations.d.cts +29 -0
- package/dist/violations.d.mts +29 -0
- package/dist/violations.d.ts +1 -1
- package/dist/violations.mjs +80 -0
- package/docs/RELEASING.md +66 -0
- package/docs/en/00-index.md +2 -0
- package/docs/en/01-shape-api.md +35 -10
- package/docs/en/02-metadata-and-introspection.md +2 -1
- package/docs/en/03-violations.md +1 -1
- package/docs/en/04-json-schema-export.md +5 -0
- package/docs/en/05-public-api.md +35 -3
- package/docs/en/06-common-recipes.md +2 -1
- package/docs/en/07-ai-reference.md +5 -2
- package/docs/en/08-violation-code-types.md +28 -2
- package/docs/en/09-migration.md +75 -0
- package/docs/ru/00-index.md +2 -0
- package/docs/ru/01-shape-api.md +35 -10
- package/docs/ru/02-metadata-and-introspection.md +2 -1
- package/docs/ru/03-violations.md +1 -1
- package/docs/ru/04-json-schema-export.md +5 -0
- package/docs/ru/05-public-api.md +35 -3
- package/docs/ru/06-common-recipes.md +2 -1
- package/docs/ru/07-ai-reference.md +5 -2
- package/docs/ru/08-violation-code-types.md +28 -2
- package/docs/ru/09-migration.md +76 -0
- package/docs/ru/README.md +10 -2
- package/package.json +63 -37
- package/types/index.d.ts +275 -115
- package/dist/metadata.cjs.js +0 -130
- package/dist/metadata.es.js +0 -131
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
const require_assert = require("./assert.cjs");
|
|
2
|
+
//#region src/constraints.ts
|
|
3
|
+
var isValidator = (constraint) => "run" in constraint;
|
|
4
|
+
function arrayify(value) {
|
|
5
|
+
return Array.isArray(value) ? [...value] : [value];
|
|
6
|
+
}
|
|
7
|
+
function matchesConstraints(value, constraints) {
|
|
8
|
+
let establishedDomain = false;
|
|
9
|
+
return arrayify(constraints).every((constraint) => {
|
|
10
|
+
if (isValidator(constraint)) {
|
|
11
|
+
establishedDomain = false;
|
|
12
|
+
return constraint.check(value);
|
|
13
|
+
}
|
|
14
|
+
if (!establishedDomain && require_assert.isRefinementAssertion(constraint)) return false;
|
|
15
|
+
const matched = establishedDomain && require_assert.isRefinementAssertion(constraint) ? require_assert.checkRefinementAssertion(constraint, value) : constraint.check(value);
|
|
16
|
+
if (matched) establishedDomain = true;
|
|
17
|
+
return matched;
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
//#endregion
|
|
21
|
+
exports.arrayify = arrayify;
|
|
22
|
+
exports.isValidator = isValidator;
|
|
23
|
+
exports.matchesConstraints = matchesConstraints;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { CompatibleConstraints, Constraint, InferConstraints, MaybeMany, Validator } from './types/index.cjs';
|
|
2
|
+
export declare const isValidator: <T = unknown>(constraint: Constraint<T>) => constraint is Validator<T>;
|
|
3
|
+
export declare function arrayify<T>(value: MaybeMany<T>): T[];
|
|
4
|
+
export declare function matchesConstraints<C extends MaybeMany<Constraint>>(value: unknown, constraints: CompatibleConstraints<C>): value is InferConstraints<C>;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { CompatibleConstraints, Constraint, InferConstraints, MaybeMany, Validator } from './types/index.mjs';
|
|
2
|
+
export declare const isValidator: <T = unknown>(constraint: Constraint<T>) => constraint is Validator<T>;
|
|
3
|
+
export declare function arrayify<T>(value: MaybeMany<T>): T[];
|
|
4
|
+
export declare function matchesConstraints<C extends MaybeMany<Constraint>>(value: unknown, constraints: CompatibleConstraints<C>): value is InferConstraints<C>;
|
package/dist/constraints.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Constraint, InferConstraints, MaybeMany, Validator } from '
|
|
1
|
+
import { CompatibleConstraints, Constraint, InferConstraints, MaybeMany, Validator } from './types/index.js';
|
|
2
2
|
export declare const isValidator: <T = unknown>(constraint: Constraint<T>) => constraint is Validator<T>;
|
|
3
3
|
export declare function arrayify<T>(value: MaybeMany<T>): T[];
|
|
4
|
-
export declare function matchesConstraints<C extends MaybeMany<Constraint>>(value: unknown, constraints: C): value is InferConstraints<C>;
|
|
4
|
+
export declare function matchesConstraints<C extends MaybeMany<Constraint>>(value: unknown, constraints: CompatibleConstraints<C>): value is InferConstraints<C>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { checkRefinementAssertion, isRefinementAssertion } from "./assert.mjs";
|
|
2
|
+
//#region src/constraints.ts
|
|
3
|
+
var isValidator = (constraint) => "run" in constraint;
|
|
4
|
+
function arrayify(value) {
|
|
5
|
+
return Array.isArray(value) ? [...value] : [value];
|
|
6
|
+
}
|
|
7
|
+
function matchesConstraints(value, constraints) {
|
|
8
|
+
let establishedDomain = false;
|
|
9
|
+
return arrayify(constraints).every((constraint) => {
|
|
10
|
+
if (isValidator(constraint)) {
|
|
11
|
+
establishedDomain = false;
|
|
12
|
+
return constraint.check(value);
|
|
13
|
+
}
|
|
14
|
+
if (!establishedDomain && isRefinementAssertion(constraint)) return false;
|
|
15
|
+
const matched = establishedDomain && isRefinementAssertion(constraint) ? checkRefinementAssertion(constraint, value) : constraint.check(value);
|
|
16
|
+
if (matched) establishedDomain = true;
|
|
17
|
+
return matched;
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
//#endregion
|
|
21
|
+
export { arrayify, isValidator, matchesConstraints };
|
package/dist/index.cjs
CHANGED
|
@@ -1,230 +1,151 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
2
|
+
const require_constraints = require("./constraints.cjs");
|
|
3
|
+
const require_metadata = require("./metadata.cjs");
|
|
4
|
+
const require_assert = require("./assert.cjs");
|
|
5
|
+
const require_assertions = require("./assertions.cjs");
|
|
6
|
+
const require_combinators = require("./combinators.cjs");
|
|
7
|
+
const require_violations = require("./violations.cjs");
|
|
8
|
+
//#region src/index.ts
|
|
9
|
+
var collectViolations = async (value, constraints, path = []) => {
|
|
10
|
+
const validations = [];
|
|
11
|
+
let establishedAssertionDomain = false;
|
|
12
|
+
for (const c of require_constraints.arrayify(constraints)) {
|
|
13
|
+
if (require_constraints.isValidator(c)) {
|
|
14
|
+
establishedAssertionDomain = false;
|
|
15
|
+
validations.push(...c.run(collectViolations, value, path).map((v) => v instanceof Promise ? v : Promise.resolve(v)));
|
|
16
|
+
continue;
|
|
17
|
+
}
|
|
18
|
+
if (!establishedAssertionDomain && require_assert.isRefinementAssertion(c)) throw new Error(`Refinement ${String(c.name)} requires a compatible preceding guard`);
|
|
19
|
+
const v = establishedAssertionDomain && require_assert.isRefinementAssertion(c) ? require_assert.runRefinementAssertion(c, value) : c(value);
|
|
20
|
+
if (v instanceof Promise) {
|
|
21
|
+
establishedAssertionDomain = false;
|
|
22
|
+
if (c.bail) {
|
|
23
|
+
const awaited = await v;
|
|
24
|
+
if (awaited) {
|
|
25
|
+
validations.push(Promise.resolve([Object.assign(awaited, { path: [...path] })]));
|
|
26
|
+
break;
|
|
27
|
+
}
|
|
28
|
+
} else validations.push(v.then((v) => v ? [Object.assign(v, { path: [...path] })] : []));
|
|
29
|
+
} else if (v) {
|
|
30
|
+
establishedAssertionDomain = false;
|
|
31
|
+
validations.push(Promise.resolve([Object.assign(v, { path: [...path] })]));
|
|
32
|
+
if (c.bail) break;
|
|
33
|
+
} else establishedAssertionDomain = true;
|
|
34
|
+
}
|
|
35
|
+
return settle(value, path, validations);
|
|
15
36
|
};
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
at(path) {
|
|
38
|
-
if (!isPathPrefix(path, this.path)) {
|
|
39
|
-
return void 0;
|
|
40
|
-
}
|
|
41
|
-
if (path.length === this.path.length) {
|
|
42
|
-
return this;
|
|
43
|
-
}
|
|
44
|
-
const child = this.children.get(path[this.path.length]);
|
|
45
|
-
return child?.at(path);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
const buildTree = (violations) => {
|
|
49
|
-
const root = createTreeState(ROOT_PATH);
|
|
50
|
-
violations.forEach((violation) => {
|
|
51
|
-
const path = normalizePath(violation.path);
|
|
52
|
-
root.subtree.push(violation);
|
|
53
|
-
if (path.length === 0) {
|
|
54
|
-
root.self.push(violation);
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
let current = root;
|
|
58
|
-
const currentPath = [];
|
|
59
|
-
path.forEach((segment, index) => {
|
|
60
|
-
currentPath.push(segment);
|
|
61
|
-
let child = current.children.get(segment);
|
|
62
|
-
if (!child) {
|
|
63
|
-
child = createTreeState(currentPath);
|
|
64
|
-
current.children.set(segment, child);
|
|
65
|
-
}
|
|
66
|
-
child.subtree.push(violation);
|
|
67
|
-
if (index === path.length - 1) {
|
|
68
|
-
child.self.push(violation);
|
|
69
|
-
}
|
|
70
|
-
current = child;
|
|
71
|
-
});
|
|
72
|
-
});
|
|
73
|
-
return new TreeNode(root);
|
|
74
|
-
};
|
|
75
|
-
class ViolationCollection {
|
|
76
|
-
constructor(violations) {
|
|
77
|
-
this.violations = [...violations];
|
|
78
|
-
this.size = this.violations.length;
|
|
79
|
-
}
|
|
80
|
-
[Symbol.iterator]() {
|
|
81
|
-
return this.violations[Symbol.iterator]();
|
|
82
|
-
}
|
|
83
|
-
forEach(callback) {
|
|
84
|
-
this.violations.forEach((violation, index) => callback(violation, index, this));
|
|
85
|
-
}
|
|
86
|
-
map(callback) {
|
|
87
|
-
return this.violations.map((violation, index) => callback(violation, index, this));
|
|
88
|
-
}
|
|
89
|
-
at(path) {
|
|
90
|
-
return new ViolationCollection(this.violations.filter((violation) => isSamePath(violation.path, path)));
|
|
91
|
-
}
|
|
92
|
-
tree() {
|
|
93
|
-
return buildTree(this.violations);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
const collection = (violations) => new ViolationCollection(violations);
|
|
97
|
-
const collectViolations = async (value, constraints, path = []) => {
|
|
98
|
-
const validations = [];
|
|
99
|
-
for (const c of metadata.arrayify(constraints)) {
|
|
100
|
-
if (metadata.isValidator(c)) {
|
|
101
|
-
validations.push(...c.run(collectViolations, value, path).map((v2) => v2 instanceof Promise ? v2 : Promise.resolve(v2)));
|
|
102
|
-
continue;
|
|
103
|
-
}
|
|
104
|
-
const v = c(value);
|
|
105
|
-
if (v instanceof Promise) {
|
|
106
|
-
if (c.bail) {
|
|
107
|
-
const awaited = await v;
|
|
108
|
-
if (awaited) {
|
|
109
|
-
validations.push(Promise.resolve([Object.assign(awaited, { path: [...path] })]));
|
|
110
|
-
break;
|
|
111
|
-
}
|
|
112
|
-
} else {
|
|
113
|
-
validations.push(v.then((v2) => v2 ? [Object.assign(v2, { path: [...path] })] : []));
|
|
114
|
-
}
|
|
115
|
-
} else if (v) {
|
|
116
|
-
validations.push(Promise.resolve([Object.assign(v, { path: [...path] })]));
|
|
117
|
-
if (c.bail) {
|
|
118
|
-
break;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
return settle(value, path, validations);
|
|
123
|
-
};
|
|
124
|
-
const collectViolationsSync = (value, constraints, path = []) => {
|
|
125
|
-
const violations = [];
|
|
126
|
-
for (const c of metadata.arrayify(constraints)) {
|
|
127
|
-
if (metadata.isValidator(c)) {
|
|
128
|
-
violations.push(...c.run(collectViolationsSync, value, path));
|
|
129
|
-
continue;
|
|
130
|
-
}
|
|
131
|
-
const v = c(value);
|
|
132
|
-
if (v instanceof Promise) {
|
|
133
|
-
throw new Error("Found asynchronous validator " + String(c.name));
|
|
134
|
-
} else if (v) {
|
|
135
|
-
violations.push(Object.assign(v, { path: [...path] }));
|
|
136
|
-
if (c.bail) break;
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
return flatten(violations);
|
|
37
|
+
collectViolations.sync = false;
|
|
38
|
+
var collectViolationsSync = (value, constraints, path = []) => {
|
|
39
|
+
const violations = [];
|
|
40
|
+
let establishedAssertionDomain = false;
|
|
41
|
+
for (const c of require_constraints.arrayify(constraints)) {
|
|
42
|
+
if (require_constraints.isValidator(c)) {
|
|
43
|
+
establishedAssertionDomain = false;
|
|
44
|
+
violations.push(...c.run(collectViolationsSync, value, path));
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
if (!establishedAssertionDomain && require_assert.isRefinementAssertion(c)) throw new Error(`Refinement ${String(c.name)} requires a compatible preceding guard`);
|
|
48
|
+
const v = establishedAssertionDomain && require_assert.isRefinementAssertion(c) ? require_assert.runRefinementAssertion(c, value) : c(value);
|
|
49
|
+
if (v instanceof Promise) throw new Error("Found asynchronous validator " + String(c.name));
|
|
50
|
+
else if (v) {
|
|
51
|
+
establishedAssertionDomain = false;
|
|
52
|
+
violations.push(Object.assign(v, { path: [...path] }));
|
|
53
|
+
if (c.bail) break;
|
|
54
|
+
} else establishedAssertionDomain = true;
|
|
55
|
+
}
|
|
56
|
+
return flatten(violations);
|
|
140
57
|
};
|
|
58
|
+
collectViolationsSync.sync = true;
|
|
141
59
|
function toResult(value, violations) {
|
|
142
|
-
|
|
60
|
+
return violations.length === 0 ? [
|
|
61
|
+
true,
|
|
62
|
+
value,
|
|
63
|
+
[]
|
|
64
|
+
] : [
|
|
65
|
+
false,
|
|
66
|
+
value,
|
|
67
|
+
violations
|
|
68
|
+
];
|
|
143
69
|
}
|
|
144
70
|
function flatten(recursive) {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
71
|
+
const flattened = [];
|
|
72
|
+
recursive.forEach((element) => {
|
|
73
|
+
flattened.push(...Array.isArray(element) ? flatten(element) : [element]);
|
|
74
|
+
});
|
|
75
|
+
return flattened;
|
|
150
76
|
}
|
|
151
77
|
async function settle(value, path, validations) {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
78
|
+
const violations = [];
|
|
79
|
+
(await Promise.allSettled(validations)).forEach((result) => {
|
|
80
|
+
if (result.status === "fulfilled") violations.push(...result.value);
|
|
81
|
+
else violations.push({
|
|
82
|
+
value,
|
|
83
|
+
path,
|
|
84
|
+
violates: {
|
|
85
|
+
kind: "runtime",
|
|
86
|
+
name: "validate",
|
|
87
|
+
code: "runtime.rejection",
|
|
88
|
+
args: [result.reason]
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
return violations;
|
|
166
93
|
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
exports.
|
|
191
|
-
exports.
|
|
192
|
-
exports.
|
|
193
|
-
exports.
|
|
194
|
-
exports.
|
|
195
|
-
exports.
|
|
196
|
-
exports.
|
|
197
|
-
exports.
|
|
198
|
-
exports.
|
|
199
|
-
exports.
|
|
200
|
-
exports.
|
|
201
|
-
exports.
|
|
202
|
-
exports.
|
|
203
|
-
exports.
|
|
204
|
-
exports.
|
|
205
|
-
exports.
|
|
206
|
-
exports.
|
|
207
|
-
exports.isSet =
|
|
208
|
-
exports.isString =
|
|
209
|
-
exports.isSymbol =
|
|
210
|
-
exports.
|
|
211
|
-
exports.oneOf = assertions.oneOf;
|
|
212
|
-
exports.startsWith = assertions.startsWith;
|
|
213
|
-
exports.discriminatedUnion = combinators.discriminatedUnion;
|
|
214
|
-
exports.each = combinators.each;
|
|
215
|
-
exports.exact = combinators.exact;
|
|
216
|
-
exports.nullable = combinators.nullable;
|
|
217
|
-
exports.nullish = combinators.nullish;
|
|
218
|
-
exports.optional = combinators.optional;
|
|
219
|
-
exports.record = combinators.record;
|
|
220
|
-
exports.shape = combinators.shape;
|
|
221
|
-
exports.tuple = combinators.tuple;
|
|
222
|
-
exports.union = combinators.union;
|
|
223
|
-
exports.custom = metadata.custom;
|
|
224
|
-
exports.describe = metadata.describe;
|
|
225
|
-
exports.meta = metadata.meta;
|
|
226
|
-
exports.assert = assert.assert;
|
|
227
|
-
exports.ViolationCollection = ViolationCollection;
|
|
228
|
-
exports.collection = collection;
|
|
94
|
+
var matches = { sync(value, constraints) {
|
|
95
|
+
return collectViolationsSync(value, constraints).length === 0;
|
|
96
|
+
} };
|
|
97
|
+
var validate = /* @__PURE__ */ Object.assign(async (value, constraints) => {
|
|
98
|
+
return toResult(value, await collectViolations(value, constraints));
|
|
99
|
+
}, { sync(value, constraints) {
|
|
100
|
+
return toResult(value, collectViolationsSync(value, constraints));
|
|
101
|
+
} });
|
|
102
|
+
//#endregion
|
|
103
|
+
exports.ViolationCollection = require_violations.ViolationCollection;
|
|
104
|
+
exports.assert = require_assert.assert;
|
|
105
|
+
exports.collection = require_violations.collection;
|
|
106
|
+
exports.custom = require_metadata.custom;
|
|
107
|
+
exports.describe = require_metadata.describe;
|
|
108
|
+
exports.discriminatedUnion = require_combinators.discriminatedUnion;
|
|
109
|
+
exports.each = require_combinators.each;
|
|
110
|
+
exports.endsWith = require_assertions.endsWith;
|
|
111
|
+
exports.exact = require_combinators.exact;
|
|
112
|
+
exports.hasLength = require_assertions.hasLength;
|
|
113
|
+
exports.hasPattern = require_assertions.hasPattern;
|
|
114
|
+
exports.hasSize = require_assertions.hasSize;
|
|
115
|
+
exports.hasValue = require_assertions.hasValue;
|
|
116
|
+
exports.isBigInt = require_assertions.isBigInt;
|
|
117
|
+
exports.isBlob = require_assertions.isBlob;
|
|
118
|
+
exports.isBoolean = require_assertions.isBoolean;
|
|
119
|
+
exports.isDate = require_assertions.isDate;
|
|
120
|
+
exports.isDefined = require_assertions.isDefined;
|
|
121
|
+
exports.isEmail = require_assertions.isEmail;
|
|
122
|
+
exports.isError = require_assertions.isError;
|
|
123
|
+
exports.isFile = require_assertions.isFile;
|
|
124
|
+
exports.isFiniteNumber = require_assertions.isFiniteNumber;
|
|
125
|
+
exports.isFunction = require_assertions.isFunction;
|
|
126
|
+
exports.isInteger = require_assertions.isInteger;
|
|
127
|
+
exports.isMap = require_assertions.isMap;
|
|
128
|
+
exports.isNaN = require_assertions.isNaN;
|
|
129
|
+
exports.isNull = require_assertions.isNull;
|
|
130
|
+
exports.isNumber = require_assertions.isNumber;
|
|
131
|
+
exports.isPromiseLike = require_assertions.isPromiseLike;
|
|
132
|
+
exports.isRegExp = require_assertions.isRegExp;
|
|
133
|
+
exports.isSafeInteger = require_assertions.isSafeInteger;
|
|
134
|
+
exports.isSet = require_assertions.isSet;
|
|
135
|
+
exports.isString = require_assertions.isString;
|
|
136
|
+
exports.isSymbol = require_assertions.isSymbol;
|
|
137
|
+
exports.isValidDate = require_assertions.isValidDate;
|
|
229
138
|
exports.matches = matches;
|
|
139
|
+
exports.meta = require_metadata.meta;
|
|
140
|
+
exports.multipleOf = require_assertions.multipleOf;
|
|
141
|
+
exports.nullable = require_combinators.nullable;
|
|
142
|
+
exports.nullish = require_combinators.nullish;
|
|
143
|
+
exports.oneOf = require_assertions.oneOf;
|
|
144
|
+
exports.optional = require_combinators.optional;
|
|
145
|
+
exports.record = require_combinators.record;
|
|
146
|
+
exports.refine = require_assert.refine;
|
|
147
|
+
exports.shape = require_combinators.shape;
|
|
148
|
+
exports.startsWith = require_assertions.startsWith;
|
|
149
|
+
exports.tuple = require_combinators.tuple;
|
|
150
|
+
exports.union = require_combinators.union;
|
|
230
151
|
exports.validate = validate;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { CompatibleConstraints, Constraint, InferConstraints, InferViolations, MaybeMany, ValidationResult } from './types/index.cjs';
|
|
2
|
+
export * from './assertions.cjs';
|
|
3
|
+
export * from './combinators.cjs';
|
|
4
|
+
export { collection, ViolationCollection, } from './violations.cjs';
|
|
5
|
+
export { custom, describe, meta, } from './metadata.cjs';
|
|
6
|
+
export type { AllOfConstraintDescriptor, AssertionDescriptor, AssertionStage, AssertionConstraintDescriptor, AsyncObjectShapeRuleDescriptor, BaseConstraintDescriptor, CompatibleConstraints, CompatibleConstraintTuple, CompatibleShapeDescriptor, Constraint, ConstraintDescriptor, ConstraintMetadata, CustomConstraintDescriptor, DescribeAssertionConstraint, DescribeAssertionConstraintTuple, DescribeConstraint, DescribeConstraintTuple, DescribeConstraints, DescribeShapeDescriptor, DescribedValidator, DiscriminatedUnionValidator, EachValidator, FieldsMatchObjectShapeRuleDescriptor, Guard, InferShape, InferConstraint, InferConstraints, InferConstraintViolations, InferViolations, MergeShapeDescriptors, OpaqueValidatorDescriptor, PartialShapeDescriptor, DiscriminatedUnionConstraintDescriptor, EachConstraintDescriptor, NullableValidator, NullishValidator, KnownViolationCode, KnownViolationSubject, ObjectShapeRuleDescriptor, ObjectShapeRuleDescriptorBase, OptionalValidator, RecordValidator, Refinement, RecordConstraintDescriptor, ShapeDescriptor, ShapeFieldSelector, ShapeRefinement, ShapeRefineMethod, ShapeRefineMethodSync, ShapeRefinementViolationInput, ShapeConstraintDescriptor, SyncObjectShapeRuleDescriptor, SyncShapeRefinement, TupleValidator, TupleConstraintDescriptor, UnionValidator, ValidationFailure, ValidationSuccess, ViolationArgs, ViolationCode, ViolationCodeEntry, ViolationCodeRegistry, ViolationEntry, ViolationKind, ViolationKindOf, ViolationNameOf, ViolationSubject, ViolationTreeNode, UnionConstraintDescriptor, ValidationResult, Validator, Violation, WrapperConstraintDescriptor, } from './types/index.cjs';
|
|
7
|
+
export declare const matches: {
|
|
8
|
+
sync<const C extends MaybeMany<Constraint>>(value: unknown, constraints: C & CompatibleConstraints<C>): value is InferConstraints<C>;
|
|
9
|
+
};
|
|
10
|
+
export declare const validate: (<const C extends MaybeMany<Constraint>>(value: unknown, constraints: C & CompatibleConstraints<C>) => Promise<ValidationResult<InferConstraints<C>, InferViolations<C>>>) & {
|
|
11
|
+
sync<const C extends MaybeMany<Constraint>>(value: unknown, constraints: C & CompatibleConstraints<C>): ValidationResult<InferConstraints<C>, InferViolations<C>>;
|
|
12
|
+
};
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { CompatibleConstraints, Constraint, InferConstraints, InferViolations, MaybeMany, ValidationResult } from './types/index.mjs';
|
|
2
|
+
export * from './assertions.mjs';
|
|
3
|
+
export * from './combinators.mjs';
|
|
4
|
+
export { collection, ViolationCollection, } from './violations.mjs';
|
|
5
|
+
export { custom, describe, meta, } from './metadata.mjs';
|
|
6
|
+
export type { AllOfConstraintDescriptor, AssertionDescriptor, AssertionStage, AssertionConstraintDescriptor, AsyncObjectShapeRuleDescriptor, BaseConstraintDescriptor, CompatibleConstraints, CompatibleConstraintTuple, CompatibleShapeDescriptor, Constraint, ConstraintDescriptor, ConstraintMetadata, CustomConstraintDescriptor, DescribeAssertionConstraint, DescribeAssertionConstraintTuple, DescribeConstraint, DescribeConstraintTuple, DescribeConstraints, DescribeShapeDescriptor, DescribedValidator, DiscriminatedUnionValidator, EachValidator, FieldsMatchObjectShapeRuleDescriptor, Guard, InferShape, InferConstraint, InferConstraints, InferConstraintViolations, InferViolations, MergeShapeDescriptors, OpaqueValidatorDescriptor, PartialShapeDescriptor, DiscriminatedUnionConstraintDescriptor, EachConstraintDescriptor, NullableValidator, NullishValidator, KnownViolationCode, KnownViolationSubject, ObjectShapeRuleDescriptor, ObjectShapeRuleDescriptorBase, OptionalValidator, RecordValidator, Refinement, RecordConstraintDescriptor, ShapeDescriptor, ShapeFieldSelector, ShapeRefinement, ShapeRefineMethod, ShapeRefineMethodSync, ShapeRefinementViolationInput, ShapeConstraintDescriptor, SyncObjectShapeRuleDescriptor, SyncShapeRefinement, TupleValidator, TupleConstraintDescriptor, UnionValidator, ValidationFailure, ValidationSuccess, ViolationArgs, ViolationCode, ViolationCodeEntry, ViolationCodeRegistry, ViolationEntry, ViolationKind, ViolationKindOf, ViolationNameOf, ViolationSubject, ViolationTreeNode, UnionConstraintDescriptor, ValidationResult, Validator, Violation, WrapperConstraintDescriptor, } from './types/index.mjs';
|
|
7
|
+
export declare const matches: {
|
|
8
|
+
sync<const C extends MaybeMany<Constraint>>(value: unknown, constraints: C & CompatibleConstraints<C>): value is InferConstraints<C>;
|
|
9
|
+
};
|
|
10
|
+
export declare const validate: (<const C extends MaybeMany<Constraint>>(value: unknown, constraints: C & CompatibleConstraints<C>) => Promise<ValidationResult<InferConstraints<C>, InferViolations<C>>>) & {
|
|
11
|
+
sync<const C extends MaybeMany<Constraint>>(value: unknown, constraints: C & CompatibleConstraints<C>): ValidationResult<InferConstraints<C>, InferViolations<C>>;
|
|
12
|
+
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { Constraint, InferConstraints,
|
|
2
|
-
export * from './assertions';
|
|
3
|
-
export * from './combinators';
|
|
4
|
-
export { collection, ViolationCollection, } from './violations';
|
|
5
|
-
export { custom, describe, meta, } from './metadata';
|
|
6
|
-
export type { AllOfConstraintDescriptor, AssertionDescriptor,
|
|
1
|
+
import { CompatibleConstraints, Constraint, InferConstraints, InferViolations, MaybeMany, ValidationResult } from './types/index.js';
|
|
2
|
+
export * from './assertions.js';
|
|
3
|
+
export * from './combinators.js';
|
|
4
|
+
export { collection, ViolationCollection, } from './violations.js';
|
|
5
|
+
export { custom, describe, meta, } from './metadata.js';
|
|
6
|
+
export type { AllOfConstraintDescriptor, AssertionDescriptor, AssertionStage, AssertionConstraintDescriptor, AsyncObjectShapeRuleDescriptor, BaseConstraintDescriptor, CompatibleConstraints, CompatibleConstraintTuple, CompatibleShapeDescriptor, Constraint, ConstraintDescriptor, ConstraintMetadata, CustomConstraintDescriptor, DescribeAssertionConstraint, DescribeAssertionConstraintTuple, DescribeConstraint, DescribeConstraintTuple, DescribeConstraints, DescribeShapeDescriptor, DescribedValidator, DiscriminatedUnionValidator, EachValidator, FieldsMatchObjectShapeRuleDescriptor, Guard, InferShape, InferConstraint, InferConstraints, InferConstraintViolations, InferViolations, MergeShapeDescriptors, OpaqueValidatorDescriptor, PartialShapeDescriptor, DiscriminatedUnionConstraintDescriptor, EachConstraintDescriptor, NullableValidator, NullishValidator, KnownViolationCode, KnownViolationSubject, ObjectShapeRuleDescriptor, ObjectShapeRuleDescriptorBase, OptionalValidator, RecordValidator, Refinement, RecordConstraintDescriptor, ShapeDescriptor, ShapeFieldSelector, ShapeRefinement, ShapeRefineMethod, ShapeRefineMethodSync, ShapeRefinementViolationInput, ShapeConstraintDescriptor, SyncObjectShapeRuleDescriptor, SyncShapeRefinement, TupleValidator, TupleConstraintDescriptor, UnionValidator, ValidationFailure, ValidationSuccess, ViolationArgs, ViolationCode, ViolationCodeEntry, ViolationCodeRegistry, ViolationEntry, ViolationKind, ViolationKindOf, ViolationNameOf, ViolationSubject, ViolationTreeNode, UnionConstraintDescriptor, ValidationResult, Validator, Violation, WrapperConstraintDescriptor, } from './types/index.js';
|
|
7
7
|
export declare const matches: {
|
|
8
|
-
sync<const C extends MaybeMany<Constraint>>(value: unknown, constraints: C): value is InferConstraints<C>;
|
|
8
|
+
sync<const C extends MaybeMany<Constraint>>(value: unknown, constraints: C & CompatibleConstraints<C>): value is InferConstraints<C>;
|
|
9
9
|
};
|
|
10
|
-
export declare const validate: (<const C extends MaybeMany<Constraint>>(value: unknown, constraints: C) => Promise<
|
|
11
|
-
sync<const C extends MaybeMany<Constraint>>(value: unknown, constraints: C):
|
|
10
|
+
export declare const validate: (<const C extends MaybeMany<Constraint>>(value: unknown, constraints: C & CompatibleConstraints<C>) => Promise<ValidationResult<InferConstraints<C>, InferViolations<C>>>) & {
|
|
11
|
+
sync<const C extends MaybeMany<Constraint>>(value: unknown, constraints: C & CompatibleConstraints<C>): ValidationResult<InferConstraints<C>, InferViolations<C>>;
|
|
12
12
|
};
|