@modulify/validator 0.2.1 → 0.3.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/CHANGELOG.md +27 -1
- package/README.md +12 -2
- package/dist/assert-BDOtHdLx.cjs +289 -0
- package/dist/assert-CzMg5aO7.mjs +206 -0
- package/dist/assert.cjs +7 -65
- 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 +2 -66
- package/dist/assertions-DPYCHREw.mjs +297 -0
- package/dist/assertions-nfOKqcjs.cjs +476 -0
- package/dist/assertions.cjs +34 -206
- 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 +3 -207
- package/dist/checkers.d.cts +8 -0
- package/dist/checkers.d.mts +8 -0
- package/dist/checkers.d.ts +1 -1
- package/dist/combinators.cjs +303 -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 +304 -315
- package/dist/constraints.d.cts +4 -0
- package/dist/constraints.d.mts +4 -0
- package/dist/constraints.d.ts +2 -2
- package/dist/extractors.d.cts +2 -0
- package/dist/extractors.d.mts +2 -0
- package/dist/index.cjs +210 -213
- 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 +165 -218
- 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 +6 -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 +2 -8
- 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.d.cts +29 -0
- package/dist/violations.d.mts +29 -0
- package/dist/violations.d.ts +1 -1
- 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
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>;
|
package/dist/index.cjs
CHANGED
|
@@ -1,230 +1,227 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
return normalizedLeft.every((part, index) => Object.is(part, right[index]));
|
|
2
|
+
const require_assert = require("./assert-BDOtHdLx.cjs");
|
|
3
|
+
const require_assertions = require("./assertions-nfOKqcjs.cjs");
|
|
4
|
+
const require_combinators = require("./combinators.cjs");
|
|
5
|
+
//#region src/violations.ts
|
|
6
|
+
var ROOT_PATH = Object.freeze([]);
|
|
7
|
+
var normalizePath = (path) => path ?? ROOT_PATH;
|
|
8
|
+
var isSamePath = (left, right = ROOT_PATH) => {
|
|
9
|
+
const normalizedLeft = normalizePath(left);
|
|
10
|
+
if (normalizedLeft.length !== right.length) return false;
|
|
11
|
+
return normalizedLeft.every((part, index) => Object.is(part, right[index]));
|
|
15
12
|
};
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
return prefix.every((part, index) => Object.is(part, path[index]));
|
|
13
|
+
var isPathPrefix = (path, prefix) => {
|
|
14
|
+
if (prefix.length > path.length) return false;
|
|
15
|
+
return prefix.every((part, index) => Object.is(part, path[index]));
|
|
21
16
|
};
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
17
|
+
var createTreeState = (path) => ({
|
|
18
|
+
path: Object.freeze([...path]),
|
|
19
|
+
self: [],
|
|
20
|
+
subtree: [],
|
|
21
|
+
children: /* @__PURE__ */ new Map()
|
|
27
22
|
});
|
|
28
|
-
class TreeNode {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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);
|
|
23
|
+
var TreeNode = class TreeNode {
|
|
24
|
+
constructor(state) {
|
|
25
|
+
this.path = state.path;
|
|
26
|
+
this.self = new ViolationCollection(state.self);
|
|
27
|
+
this.subtree = new ViolationCollection(state.subtree);
|
|
28
|
+
this.children = new Map([...state.children.entries()].map(([key, child]) => [key, new TreeNode(child)]));
|
|
29
|
+
}
|
|
30
|
+
at(path) {
|
|
31
|
+
if (!isPathPrefix(path, this.path)) return;
|
|
32
|
+
if (path.length === this.path.length) return this;
|
|
33
|
+
return this.children.get(path[this.path.length])?.at(path);
|
|
34
|
+
}
|
|
74
35
|
};
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
return settle(value, path, validations);
|
|
36
|
+
var buildTree = (violations) => {
|
|
37
|
+
const root = createTreeState(ROOT_PATH);
|
|
38
|
+
violations.forEach((violation) => {
|
|
39
|
+
const path = normalizePath(violation.path);
|
|
40
|
+
root.subtree.push(violation);
|
|
41
|
+
if (path.length === 0) {
|
|
42
|
+
root.self.push(violation);
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
let current = root;
|
|
46
|
+
const currentPath = [];
|
|
47
|
+
path.forEach((segment, index) => {
|
|
48
|
+
currentPath.push(segment);
|
|
49
|
+
let child = current.children.get(segment);
|
|
50
|
+
if (!child) {
|
|
51
|
+
child = createTreeState(currentPath);
|
|
52
|
+
current.children.set(segment, child);
|
|
53
|
+
}
|
|
54
|
+
child.subtree.push(violation);
|
|
55
|
+
if (index === path.length - 1) child.self.push(violation);
|
|
56
|
+
current = child;
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
return new TreeNode(root);
|
|
60
|
+
};
|
|
61
|
+
var ViolationCollection = class ViolationCollection {
|
|
62
|
+
constructor(violations) {
|
|
63
|
+
this.violations = [...violations];
|
|
64
|
+
this.size = this.violations.length;
|
|
65
|
+
}
|
|
66
|
+
[Symbol.iterator]() {
|
|
67
|
+
return this.violations[Symbol.iterator]();
|
|
68
|
+
}
|
|
69
|
+
forEach(callback) {
|
|
70
|
+
this.violations.forEach((violation, index) => callback(violation, index, this));
|
|
71
|
+
}
|
|
72
|
+
map(callback) {
|
|
73
|
+
return this.violations.map((violation, index) => callback(violation, index, this));
|
|
74
|
+
}
|
|
75
|
+
at(path) {
|
|
76
|
+
return new ViolationCollection(this.violations.filter((violation) => isSamePath(violation.path, path)));
|
|
77
|
+
}
|
|
78
|
+
tree() {
|
|
79
|
+
return buildTree(this.violations);
|
|
80
|
+
}
|
|
123
81
|
};
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
82
|
+
var collection = (violations) => new ViolationCollection(violations);
|
|
83
|
+
//#endregion
|
|
84
|
+
//#region src/index.ts
|
|
85
|
+
var collectViolations = async (value, constraints, path = []) => {
|
|
86
|
+
const validations = [];
|
|
87
|
+
let establishedAssertionDomain = false;
|
|
88
|
+
for (const c of require_assert.arrayify(constraints)) {
|
|
89
|
+
if (require_assert.isValidator(c)) {
|
|
90
|
+
establishedAssertionDomain = false;
|
|
91
|
+
validations.push(...c.run(collectViolations, value, path).map((v) => v instanceof Promise ? v : Promise.resolve(v)));
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
if (!establishedAssertionDomain && require_assert.isRefinementAssertion(c)) throw new Error(`Refinement ${String(c.name)} requires a compatible preceding guard`);
|
|
95
|
+
const v = establishedAssertionDomain && require_assert.isRefinementAssertion(c) ? require_assert.runRefinementAssertion(c, value) : c(value);
|
|
96
|
+
if (v instanceof Promise) {
|
|
97
|
+
establishedAssertionDomain = false;
|
|
98
|
+
if (c.bail) {
|
|
99
|
+
const awaited = await v;
|
|
100
|
+
if (awaited) {
|
|
101
|
+
validations.push(Promise.resolve([Object.assign(awaited, { path: [...path] })]));
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
} else validations.push(v.then((v) => v ? [Object.assign(v, { path: [...path] })] : []));
|
|
105
|
+
} else if (v) {
|
|
106
|
+
establishedAssertionDomain = false;
|
|
107
|
+
validations.push(Promise.resolve([Object.assign(v, { path: [...path] })]));
|
|
108
|
+
if (c.bail) break;
|
|
109
|
+
} else establishedAssertionDomain = true;
|
|
110
|
+
}
|
|
111
|
+
return settle(value, path, validations);
|
|
140
112
|
};
|
|
113
|
+
collectViolations.sync = false;
|
|
114
|
+
var collectViolationsSync = (value, constraints, path = []) => {
|
|
115
|
+
const violations = [];
|
|
116
|
+
let establishedAssertionDomain = false;
|
|
117
|
+
for (const c of require_assert.arrayify(constraints)) {
|
|
118
|
+
if (require_assert.isValidator(c)) {
|
|
119
|
+
establishedAssertionDomain = false;
|
|
120
|
+
violations.push(...c.run(collectViolationsSync, value, path));
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
if (!establishedAssertionDomain && require_assert.isRefinementAssertion(c)) throw new Error(`Refinement ${String(c.name)} requires a compatible preceding guard`);
|
|
124
|
+
const v = establishedAssertionDomain && require_assert.isRefinementAssertion(c) ? require_assert.runRefinementAssertion(c, value) : c(value);
|
|
125
|
+
if (v instanceof Promise) throw new Error("Found asynchronous validator " + String(c.name));
|
|
126
|
+
else if (v) {
|
|
127
|
+
establishedAssertionDomain = false;
|
|
128
|
+
violations.push(Object.assign(v, { path: [...path] }));
|
|
129
|
+
if (c.bail) break;
|
|
130
|
+
} else establishedAssertionDomain = true;
|
|
131
|
+
}
|
|
132
|
+
return flatten(violations);
|
|
133
|
+
};
|
|
134
|
+
collectViolationsSync.sync = true;
|
|
141
135
|
function toResult(value, violations) {
|
|
142
|
-
|
|
136
|
+
return violations.length === 0 ? [
|
|
137
|
+
true,
|
|
138
|
+
value,
|
|
139
|
+
[]
|
|
140
|
+
] : [
|
|
141
|
+
false,
|
|
142
|
+
value,
|
|
143
|
+
violations
|
|
144
|
+
];
|
|
143
145
|
}
|
|
144
146
|
function flatten(recursive) {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
147
|
+
const flattened = [];
|
|
148
|
+
recursive.forEach((element) => {
|
|
149
|
+
flattened.push(...Array.isArray(element) ? flatten(element) : [element]);
|
|
150
|
+
});
|
|
151
|
+
return flattened;
|
|
150
152
|
}
|
|
151
153
|
async function settle(value, path, validations) {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
154
|
+
const violations = [];
|
|
155
|
+
(await Promise.allSettled(validations)).forEach((result) => {
|
|
156
|
+
if (result.status === "fulfilled") violations.push(...result.value);
|
|
157
|
+
else violations.push({
|
|
158
|
+
value,
|
|
159
|
+
path,
|
|
160
|
+
violates: {
|
|
161
|
+
kind: "runtime",
|
|
162
|
+
name: "validate",
|
|
163
|
+
code: "runtime.rejection",
|
|
164
|
+
args: [result.reason]
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
return violations;
|
|
166
169
|
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
value,
|
|
177
|
-
violations
|
|
178
|
-
);
|
|
179
|
-
},
|
|
180
|
-
{
|
|
181
|
-
sync(value, constraints) {
|
|
182
|
-
const violations = collectViolationsSync(value, constraints);
|
|
183
|
-
return toResult(
|
|
184
|
-
value,
|
|
185
|
-
violations
|
|
186
|
-
);
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
);
|
|
190
|
-
exports.endsWith = assertions.endsWith;
|
|
191
|
-
exports.hasLength = assertions.hasLength;
|
|
192
|
-
exports.hasPattern = assertions.hasPattern;
|
|
193
|
-
exports.hasSize = assertions.hasSize;
|
|
194
|
-
exports.hasValue = assertions.hasValue;
|
|
195
|
-
exports.isBigInt = assertions.isBigInt;
|
|
196
|
-
exports.isBlob = assertions.isBlob;
|
|
197
|
-
exports.isBoolean = assertions.isBoolean;
|
|
198
|
-
exports.isDate = assertions.isDate;
|
|
199
|
-
exports.isDefined = assertions.isDefined;
|
|
200
|
-
exports.isEmail = assertions.isEmail;
|
|
201
|
-
exports.isFile = assertions.isFile;
|
|
202
|
-
exports.isFunction = assertions.isFunction;
|
|
203
|
-
exports.isMap = assertions.isMap;
|
|
204
|
-
exports.isNaN = assertions.isNaN;
|
|
205
|
-
exports.isNull = assertions.isNull;
|
|
206
|
-
exports.isNumber = assertions.isNumber;
|
|
207
|
-
exports.isSet = assertions.isSet;
|
|
208
|
-
exports.isString = assertions.isString;
|
|
209
|
-
exports.isSymbol = assertions.isSymbol;
|
|
210
|
-
exports.multipleOf = assertions.multipleOf;
|
|
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;
|
|
170
|
+
var matches = { sync(value, constraints) {
|
|
171
|
+
return collectViolationsSync(value, constraints).length === 0;
|
|
172
|
+
} };
|
|
173
|
+
var validate = /* @__PURE__ */ Object.assign(async (value, constraints) => {
|
|
174
|
+
return toResult(value, await collectViolations(value, constraints));
|
|
175
|
+
}, { sync(value, constraints) {
|
|
176
|
+
return toResult(value, collectViolationsSync(value, constraints));
|
|
177
|
+
} });
|
|
178
|
+
//#endregion
|
|
227
179
|
exports.ViolationCollection = ViolationCollection;
|
|
180
|
+
exports.assert = require_assert.assert;
|
|
228
181
|
exports.collection = collection;
|
|
182
|
+
exports.custom = require_assert.custom;
|
|
183
|
+
exports.describe = require_assert.describe;
|
|
184
|
+
exports.discriminatedUnion = require_combinators.discriminatedUnion;
|
|
185
|
+
exports.each = require_combinators.each;
|
|
186
|
+
exports.endsWith = require_assertions.endsWith;
|
|
187
|
+
exports.exact = require_combinators.exact;
|
|
188
|
+
exports.hasLength = require_assertions.hasLength;
|
|
189
|
+
exports.hasPattern = require_assertions.hasPattern;
|
|
190
|
+
exports.hasSize = require_assertions.hasSize;
|
|
191
|
+
exports.hasValue = require_assertions.hasValue;
|
|
192
|
+
exports.isBigInt = require_assertions.isBigInt;
|
|
193
|
+
exports.isBlob = require_assertions.isBlob;
|
|
194
|
+
exports.isBoolean = require_assertions.isBoolean;
|
|
195
|
+
exports.isDate = require_assertions.isDate;
|
|
196
|
+
exports.isDefined = require_assertions.isDefined;
|
|
197
|
+
exports.isEmail = require_assertions.isEmail;
|
|
198
|
+
exports.isError = require_assertions.isError;
|
|
199
|
+
exports.isFile = require_assertions.isFile;
|
|
200
|
+
exports.isFiniteNumber = require_assertions.isFiniteNumber;
|
|
201
|
+
exports.isFunction = require_assertions.isFunction;
|
|
202
|
+
exports.isInteger = require_assertions.isInteger;
|
|
203
|
+
exports.isMap = require_assertions.isMap;
|
|
204
|
+
exports.isNaN = require_assertions.isNaN;
|
|
205
|
+
exports.isNull = require_assertions.isNull;
|
|
206
|
+
exports.isNumber = require_assertions.isNumber;
|
|
207
|
+
exports.isPromiseLike = require_assertions.isPromiseLike;
|
|
208
|
+
exports.isRegExp = require_assertions.isRegExp;
|
|
209
|
+
exports.isSafeInteger = require_assertions.isSafeInteger;
|
|
210
|
+
exports.isSet = require_assertions.isSet;
|
|
211
|
+
exports.isString = require_assertions.isString;
|
|
212
|
+
exports.isSymbol = require_assertions.isSymbol;
|
|
213
|
+
exports.isValidDate = require_assertions.isValidDate;
|
|
229
214
|
exports.matches = matches;
|
|
215
|
+
exports.meta = require_assert.meta;
|
|
216
|
+
exports.multipleOf = require_assertions.multipleOf;
|
|
217
|
+
exports.nullable = require_combinators.nullable;
|
|
218
|
+
exports.nullish = require_combinators.nullish;
|
|
219
|
+
exports.oneOf = require_assertions.oneOf;
|
|
220
|
+
exports.optional = require_combinators.optional;
|
|
221
|
+
exports.record = require_combinators.record;
|
|
222
|
+
exports.refine = require_assert.refine;
|
|
223
|
+
exports.shape = require_combinators.shape;
|
|
224
|
+
exports.startsWith = require_assertions.startsWith;
|
|
225
|
+
exports.tuple = require_combinators.tuple;
|
|
226
|
+
exports.union = require_combinators.union;
|
|
230
227
|
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
|
};
|