@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.
Files changed (84) hide show
  1. package/CHANGELOG.md +27 -1
  2. package/README.md +12 -2
  3. package/dist/assert-BDOtHdLx.cjs +289 -0
  4. package/dist/assert-CzMg5aO7.mjs +206 -0
  5. package/dist/assert.cjs +7 -65
  6. package/dist/assert.d.cts +37 -0
  7. package/dist/assert.d.mts +37 -0
  8. package/dist/assert.d.ts +24 -3
  9. package/dist/assert.mjs +2 -66
  10. package/dist/assertions-DPYCHREw.mjs +297 -0
  11. package/dist/assertions-nfOKqcjs.cjs +476 -0
  12. package/dist/assertions.cjs +34 -206
  13. package/dist/assertions.d.cts +56 -0
  14. package/dist/assertions.d.mts +56 -0
  15. package/dist/assertions.d.ts +43 -45
  16. package/dist/assertions.mjs +3 -207
  17. package/dist/checkers.d.cts +8 -0
  18. package/dist/checkers.d.mts +8 -0
  19. package/dist/checkers.d.ts +1 -1
  20. package/dist/combinators.cjs +303 -304
  21. package/dist/combinators.d.cts +16 -0
  22. package/dist/combinators.d.mts +16 -0
  23. package/dist/combinators.d.ts +15 -16
  24. package/dist/combinators.mjs +304 -315
  25. package/dist/constraints.d.cts +4 -0
  26. package/dist/constraints.d.mts +4 -0
  27. package/dist/constraints.d.ts +2 -2
  28. package/dist/extractors.d.cts +2 -0
  29. package/dist/extractors.d.mts +2 -0
  30. package/dist/index.cjs +210 -213
  31. package/dist/index.d.cts +12 -0
  32. package/dist/index.d.mts +12 -0
  33. package/dist/index.d.ts +9 -9
  34. package/dist/index.mjs +165 -218
  35. package/dist/json-schema.cjs +364 -489
  36. package/dist/json-schema.d.cts +14 -0
  37. package/dist/json-schema.d.mts +14 -0
  38. package/dist/json-schema.d.ts +3 -3
  39. package/dist/json-schema.mjs +365 -492
  40. package/dist/metadata.cjs +6 -7
  41. package/dist/metadata.d.cts +8 -0
  42. package/dist/metadata.d.mts +8 -0
  43. package/dist/metadata.d.ts +2 -2
  44. package/dist/metadata.mjs +2 -8
  45. package/dist/predicates.cjs +98 -41
  46. package/dist/predicates.d.cts +77 -0
  47. package/dist/predicates.d.mts +77 -0
  48. package/dist/predicates.d.ts +25 -4
  49. package/dist/predicates.mjs +92 -66
  50. package/dist/types/index.d.cts +984 -0
  51. package/dist/types/index.d.mts +984 -0
  52. package/dist/types/index.d.ts +984 -0
  53. package/dist/types/json-schema.d.cts +75 -0
  54. package/dist/types/json-schema.d.mts +75 -0
  55. package/dist/types/json-schema.d.ts +75 -0
  56. package/dist/violations.d.cts +29 -0
  57. package/dist/violations.d.mts +29 -0
  58. package/dist/violations.d.ts +1 -1
  59. package/docs/RELEASING.md +66 -0
  60. package/docs/en/00-index.md +2 -0
  61. package/docs/en/01-shape-api.md +35 -10
  62. package/docs/en/02-metadata-and-introspection.md +2 -1
  63. package/docs/en/03-violations.md +1 -1
  64. package/docs/en/04-json-schema-export.md +5 -0
  65. package/docs/en/05-public-api.md +35 -3
  66. package/docs/en/06-common-recipes.md +2 -1
  67. package/docs/en/07-ai-reference.md +5 -2
  68. package/docs/en/08-violation-code-types.md +28 -2
  69. package/docs/en/09-migration.md +75 -0
  70. package/docs/ru/00-index.md +2 -0
  71. package/docs/ru/01-shape-api.md +35 -10
  72. package/docs/ru/02-metadata-and-introspection.md +2 -1
  73. package/docs/ru/03-violations.md +1 -1
  74. package/docs/ru/04-json-schema-export.md +5 -0
  75. package/docs/ru/05-public-api.md +35 -3
  76. package/docs/ru/06-common-recipes.md +2 -1
  77. package/docs/ru/07-ai-reference.md +5 -2
  78. package/docs/ru/08-violation-code-types.md +28 -2
  79. package/docs/ru/09-migration.md +76 -0
  80. package/docs/ru/README.md +10 -2
  81. package/package.json +63 -37
  82. package/types/index.d.ts +275 -115
  83. package/dist/metadata.cjs.js +0 -130
  84. package/dist/metadata.es.js +0 -131
@@ -1,4 +1,4 @@
1
- import { Constraint, InferConstraints, MaybeMany, Validator } from '../types';
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,2 @@
1
+ export declare const length: <T extends unknown[] | string>(value: T) => number;
2
+ export declare const size: <T extends Map<unknown, unknown> | Set<unknown>>(value: T) => number;
@@ -0,0 +1,2 @@
1
+ export declare const length: <T extends unknown[] | string>(value: T) => number;
2
+ export declare const size: <T extends Map<unknown, unknown> | Set<unknown>>(value: T) => number;
package/dist/index.cjs CHANGED
@@ -1,230 +1,227 @@
1
- "use strict";
2
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const assertions = require("./assertions.cjs");
4
- const combinators = require("./combinators.cjs");
5
- const metadata = require("./metadata.cjs.js");
6
- const assert = require("./assert.cjs");
7
- const ROOT_PATH = Object.freeze([]);
8
- const normalizePath = (path) => path ?? ROOT_PATH;
9
- const isSamePath = (left, right = ROOT_PATH) => {
10
- const normalizedLeft = normalizePath(left);
11
- if (normalizedLeft.length !== right.length) {
12
- return false;
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
- const isPathPrefix = (path, prefix) => {
17
- if (prefix.length > path.length) {
18
- return false;
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
- const createTreeState = (path) => ({
23
- path: Object.freeze([...path]),
24
- self: [],
25
- subtree: [],
26
- children: /* @__PURE__ */ new Map()
17
+ var createTreeState = (path) => ({
18
+ path: Object.freeze([...path]),
19
+ self: [],
20
+ subtree: [],
21
+ children: /* @__PURE__ */ new Map()
27
22
  });
28
- class TreeNode {
29
- constructor(state) {
30
- this.path = state.path;
31
- this.self = new ViolationCollection(state.self);
32
- this.subtree = new ViolationCollection(state.subtree);
33
- this.children = new Map(
34
- [...state.children.entries()].map(([key, child]) => [key, new TreeNode(child)])
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);
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
- 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);
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
- 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);
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
- return violations.length === 0 ? [true, value, []] : [false, value, violations];
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
- const flattened = [];
146
- recursive.forEach((element) => {
147
- flattened.push(...Array.isArray(element) ? flatten(element) : [element]);
148
- });
149
- return flattened;
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
- const violations = [];
153
- const settled = await Promise.allSettled(validations);
154
- settled.forEach((result) => {
155
- if (result.status === "fulfilled") {
156
- violations.push(...result.value);
157
- } else {
158
- violations.push({
159
- value,
160
- path,
161
- violates: { kind: "runtime", name: "validate", code: "runtime.rejection", args: [result.reason] }
162
- });
163
- }
164
- });
165
- return violations;
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
- const matches = {
168
- sync(value, constraints) {
169
- return collectViolationsSync(value, constraints).length === 0;
170
- }
171
- };
172
- const validate = Object.assign(
173
- async (value, constraints) => {
174
- const violations = await collectViolations(value, constraints);
175
- return toResult(
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;
@@ -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
+ };
@@ -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, InferMaybeManyViolations, MaybeMany, ValidationTuple } from '../types';
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, AssertionDescriptorConstraint, Constraint, ConstraintDescriptor, ConstraintDescriptorBase, ConstraintMetadata, CustomConstraintDescriptor, DescribeAssertionConstraint, DescribeAssertionConstraintTuple, DescribeConstraint, DescribeConstraintTuple, DescribeMaybeMany, DescribeObjectDescriptor, DescribedValidator, DiscriminatedUnionValidator, EachValidator, FieldsMatchObjectShapeRuleDescriptor, GenericObjectShapeRuleDescriptor, InferConstraint, InferConstraints, InferConstraintViolations, InferMaybeManyViolations, DiscriminatedUnionConstraintDescriptor, EachConstraintDescriptor, NullableValidator, NullishValidator, KnownViolationCode, KnownViolationSubject, ObjectShapeFieldSelector, ObjectShapeRefinement, ObjectShapeRefinementIssue, ObjectShapeRuleDescriptor, ObjectShapeRuleDescriptorBase, OptionalValidator, RecordValidator, RecordConstraintDescriptor, ShapeConstraintDescriptor, TupleValidator, TupleConstraintDescriptor, UnionValidator, ValidationFailure, ValidationSuccess, ViolationArgs, ViolationCode, ViolationCodeEntry, ViolationCodeRegistry, ViolationEntry, ViolationKind, ViolationKindOf, ViolationNameOf, ViolationSubject, ViolationTreeNode, UnionConstraintDescriptor, ValidationTuple, ValidationResult, Validator, ValidatorDescriptor, Violation, WrapperConstraintDescriptor, } from '../types';
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<ValidationTuple<InferConstraints<C>, InferMaybeManyViolations<C>>>) & {
11
- sync<const C extends MaybeMany<Constraint>>(value: unknown, constraints: C): ValidationTuple<InferConstraints<C>, InferMaybeManyViolations<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
  };