justus 0.1.6 → 0.2.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.
Files changed (117) hide show
  1. package/dist/{dts-generator.js → dts-generator.cjs} +6 -15
  2. package/dist/dts-generator.cjs.map +6 -0
  3. package/{dts-generator.d.ts → dist/dts-generator.d.ts} +1 -1
  4. package/dist/dts-generator.mjs +5 -23
  5. package/dist/dts-generator.mjs.map +2 -2
  6. package/dist/errors.cjs +113 -0
  7. package/dist/errors.cjs.map +6 -0
  8. package/dist/errors.d.ts +55 -0
  9. package/dist/errors.mjs +85 -0
  10. package/dist/errors.mjs.map +6 -0
  11. package/dist/index.cjs +133 -0
  12. package/dist/index.cjs.map +6 -0
  13. package/dist/index.d.ts +47 -0
  14. package/dist/index.mjs +23 -817
  15. package/dist/index.mjs.map +3 -3
  16. package/dist/schema.cjs +43 -0
  17. package/dist/schema.cjs.map +6 -0
  18. package/dist/schema.d.ts +16 -0
  19. package/dist/schema.mjs +17 -0
  20. package/dist/schema.mjs.map +6 -0
  21. package/dist/types.cjs +60 -0
  22. package/dist/types.cjs.map +6 -0
  23. package/dist/types.d.ts +138 -0
  24. package/dist/types.mjs +33 -0
  25. package/dist/types.mjs.map +6 -0
  26. package/dist/utilities.cjs +52 -0
  27. package/dist/utilities.cjs.map +6 -0
  28. package/dist/utilities.d.ts +7 -0
  29. package/dist/utilities.mjs +27 -0
  30. package/dist/utilities.mjs.map +6 -0
  31. package/dist/validators/any.cjs +39 -0
  32. package/dist/validators/any.cjs.map +6 -0
  33. package/dist/validators/any.d.ts +7 -0
  34. package/dist/validators/any.mjs +13 -0
  35. package/dist/validators/any.mjs.map +6 -0
  36. package/dist/validators/array.cjs +104 -0
  37. package/dist/validators/array.cjs.map +6 -0
  38. package/dist/validators/array.d.ts +32 -0
  39. package/dist/validators/array.mjs +76 -0
  40. package/dist/validators/array.mjs.map +6 -0
  41. package/dist/validators/boolean.cjs +56 -0
  42. package/dist/validators/boolean.cjs.map +6 -0
  43. package/dist/validators/boolean.d.ts +21 -0
  44. package/dist/validators/boolean.mjs +30 -0
  45. package/dist/validators/boolean.mjs.map +6 -0
  46. package/dist/validators/constant.cjs +51 -0
  47. package/dist/validators/constant.cjs.map +6 -0
  48. package/dist/validators/constant.d.ts +12 -0
  49. package/dist/validators/constant.mjs +24 -0
  50. package/dist/validators/constant.mjs.map +6 -0
  51. package/dist/validators/date.cjs +80 -0
  52. package/dist/validators/date.cjs.map +6 -0
  53. package/dist/validators/date.d.ts +22 -0
  54. package/dist/validators/date.mjs +54 -0
  55. package/dist/validators/date.mjs.map +6 -0
  56. package/dist/validators/never.cjs +44 -0
  57. package/dist/validators/never.cjs.map +6 -0
  58. package/dist/validators/never.d.ts +9 -0
  59. package/dist/validators/never.mjs +18 -0
  60. package/dist/validators/never.mjs.map +6 -0
  61. package/dist/validators/number.cjs +153 -0
  62. package/dist/validators/number.cjs.map +6 -0
  63. package/dist/validators/number.d.ts +48 -0
  64. package/dist/validators/number.mjs +126 -0
  65. package/dist/validators/number.mjs.map +6 -0
  66. package/dist/validators/object.cjs +129 -0
  67. package/dist/validators/object.cjs.map +6 -0
  68. package/dist/validators/object.d.ts +22 -0
  69. package/dist/validators/object.mjs +105 -0
  70. package/dist/validators/object.mjs.map +6 -0
  71. package/dist/validators/optional.cjs +61 -0
  72. package/dist/validators/optional.cjs.map +6 -0
  73. package/dist/validators/optional.d.ts +21 -0
  74. package/dist/validators/optional.mjs +35 -0
  75. package/dist/validators/optional.mjs.map +6 -0
  76. package/dist/validators/string.cjs +84 -0
  77. package/dist/validators/string.cjs.map +6 -0
  78. package/dist/validators/string.d.ts +35 -0
  79. package/dist/validators/string.mjs +57 -0
  80. package/dist/validators/string.mjs.map +6 -0
  81. package/dist/validators/tuple.cjs +95 -0
  82. package/dist/validators/tuple.cjs.map +6 -0
  83. package/dist/validators/tuple.d.ts +15 -0
  84. package/dist/validators/tuple.mjs +69 -0
  85. package/dist/validators/tuple.mjs.map +6 -0
  86. package/dist/validators/union.cjs +78 -0
  87. package/dist/validators/union.cjs.map +6 -0
  88. package/dist/validators/union.d.ts +22 -0
  89. package/dist/validators/union.mjs +50 -0
  90. package/dist/validators/union.mjs.map +6 -0
  91. package/dist/validators/url.cjs +117 -0
  92. package/dist/validators/url.cjs.map +6 -0
  93. package/dist/validators/url.d.ts +57 -0
  94. package/dist/validators/url.mjs +91 -0
  95. package/dist/validators/url.mjs.map +6 -0
  96. package/package.json +33 -23
  97. package/src/dts-generator.ts +6 -21
  98. package/src/index.ts +23 -23
  99. package/src/schema.ts +11 -9
  100. package/src/types.ts +42 -26
  101. package/src/utilities.ts +9 -6
  102. package/src/validators/array.ts +6 -5
  103. package/src/validators/boolean.ts +2 -2
  104. package/src/validators/constant.ts +3 -1
  105. package/src/validators/date.ts +1 -1
  106. package/src/validators/never.ts +4 -2
  107. package/src/validators/number.ts +8 -7
  108. package/src/validators/object.ts +15 -18
  109. package/src/validators/optional.ts +5 -7
  110. package/src/validators/string.ts +8 -6
  111. package/src/validators/tuple.ts +7 -5
  112. package/src/validators/union.ts +7 -5
  113. package/src/validators/url.ts +8 -7
  114. package/dist/dts-generator.js.map +0 -6
  115. package/dist/index.js +0 -948
  116. package/dist/index.js.map +0 -6
  117. package/index.d.ts +0 -618
@@ -27,7 +27,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
27
27
  ));
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
29
 
30
- // src/dts-generator.ts
30
+ // dts-generator.ts
31
31
  var dts_generator_exports = {};
32
32
  __export(dts_generator_exports, {
33
33
  generateTypes: () => generateTypes,
@@ -35,7 +35,7 @@ __export(dts_generator_exports, {
35
35
  });
36
36
  module.exports = __toCommonJS(dts_generator_exports);
37
37
  var import_typescript = __toESM(require("typescript"));
38
- var import_index = require("./index.js");
38
+ var import_index = require("./index.cjs");
39
39
  var generators = /* @__PURE__ */ new Map();
40
40
  function registerTypeGenerator(validator, generator) {
41
41
  generators.set(validator, generator);
@@ -77,7 +77,7 @@ function generateTypeNode(validator, references) {
77
77
  return type;
78
78
  if (type === neverType)
79
79
  return undefinedType;
80
- if ((0, import_typescript.isUnionTypeNode)(type)) {
80
+ if (import_typescript.default.isUnionTypeNode(type)) {
81
81
  return import_typescript.default.factory.createUnionTypeNode([...type.types, undefinedType]);
82
82
  }
83
83
  return import_typescript.default.factory.createUnionTypeNode([type, undefinedType]);
@@ -111,15 +111,6 @@ registerTypeGenerator(import_index.BooleanValidator, () => booleanType);
111
111
  registerTypeGenerator(import_index.NeverValidator, () => neverType);
112
112
  registerTypeGenerator(import_index.DateValidator, () => import_typescript.default.factory.createTypeReferenceNode("Date"));
113
113
  registerTypeGenerator(import_index.URLValidator, () => import_typescript.default.factory.createTypeReferenceNode("URL"));
114
- registerTypeGenerator(import_index.any, () => anyType);
115
- registerTypeGenerator(import_index.array, () => anyArrayType);
116
- registerTypeGenerator(import_index.number, () => numberType);
117
- registerTypeGenerator(import_index.object, () => recordType);
118
- registerTypeGenerator(import_index.string, () => stringType);
119
- registerTypeGenerator(import_index.boolean, () => booleanType);
120
- registerTypeGenerator(import_index.never, () => neverType);
121
- registerTypeGenerator(import_index.date, () => import_typescript.default.factory.createTypeReferenceNode("Date"));
122
- registerTypeGenerator(import_index.url, () => import_typescript.default.factory.createTypeReferenceNode("URL"));
123
114
  registerTypeGenerator(import_index.ArrayValidator, (validator, references) => {
124
115
  const itemType = generateTypeNode(validator.items, references);
125
116
  return import_typescript.default.factory.createArrayTypeNode(itemType);
@@ -171,8 +162,8 @@ registerTypeGenerator(import_index.TupleValidator, (validator, references) => {
171
162
  const types = members.slice(first, next).map(({ validator: validator2 }) => generateTypeNode(validator2, references));
172
163
  const after = members.slice(next).map(({ validator: validator2 }) => generateTypeNode(validator2, references));
173
164
  const union = import_typescript.default.factory.createUnionTypeNode(types);
174
- const array2 = import_typescript.default.factory.createArrayTypeNode(union);
175
- const rest = import_typescript.default.factory.createRestTypeNode(array2);
165
+ const array = import_typescript.default.factory.createArrayTypeNode(union);
166
+ const rest = import_typescript.default.factory.createRestTypeNode(array);
176
167
  return import_typescript.default.factory.createTupleTypeNode([...before, rest, ...after]);
177
168
  });
178
169
  registerTypeGenerator(import_index.AllOfValidator, (validator, references) => {
@@ -223,4 +214,4 @@ registerTypeGenerator(import_index.ObjectValidator, (validator, references) => {
223
214
  generateTypes,
224
215
  registerTypeGenerator
225
216
  });
226
- //# sourceMappingURL=dts-generator.js.map
217
+ //# sourceMappingURL=dts-generator.cjs.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/dts-generator.ts"],
4
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAAe;AAEf,mBAqBO;AA2BP,IAAM,aAAa,oBAAI,IAA8C;AAG9D,SAAS,sBACZ,WACA,WACI;AACN,aAAW,IAAI,WAAW,SAAS;AACrC;AAGO,SAAS,cAAc,aAAiD;AAK7E,QAAM,aAAa,oBAAI,IAAuB;AAC9C,QAAM,aAAa,oBAAI,IAAuB;AAE9C,SAAO,QAAQ,WAAW,EAAE,QAAQ,CAAC,CAAE,MAAM,UAAW,MAAM;AAC5D,UAAM,gBAAY,2BAAa,UAAU;AAEzC,QAAI,CAAE,WAAW,IAAI,SAAS;AAAG,iBAAW,IAAI,WAAW,IAAI;AAC/D,eAAW,IAAI,MAAM,SAAS;AAAA,EAChC,CAAC;AAGD,QAAM,QAAmC,CAAC;AAC1C,aAAW,CAAE,MAAM,SAAU,KAAK,WAAW,QAAQ,GAAG;AAGtD,UAAM,gBAAgB,IAAI,IAAI,UAAU;AACxC,QAAI,cAAc,IAAI,SAAS,MAAM,MAAM;AACzC,oBAAc,OAAO,SAAS;AAAA,IAChC;AAGA,UAAM,OAAO,iBAAiB,WAAW,aAAa;AAGtD,UAAM,YAAY,CAAE,kBAAAA,QAAG,QAAQ,eA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, Validator } from './index';
2
+ import type { Validation, Validator } from './index';
3
3
  /** A function taking a `Validator` and producing its `TypeNode`. */
4
4
  type TypeGenerator<V extends Validator = Validator> = (validator: V, references: ReadonlyMap<Validator, string>) => ts.TypeNode;
5
5
  /** The generic constructor of a `Validator` instance. */
@@ -1,34 +1,25 @@
1
- // src/dts-generator.ts
2
- import ts, { isUnionTypeNode } from "typescript";
1
+ // dts-generator.ts
2
+ import ts from "typescript";
3
3
  import {
4
4
  AllOfValidator,
5
- any,
6
5
  AnyArrayValidator,
7
6
  AnyNumberValidator,
8
7
  AnyObjectValidator,
9
8
  AnyStringValidator,
10
9
  AnyValidator,
11
- array,
12
10
  ArrayValidator,
13
11
  assertSchema,
14
- boolean,
15
12
  BooleanValidator,
16
13
  ConstantValidator,
17
- date,
18
14
  DateValidator,
19
15
  getValidator,
20
- never,
21
16
  NeverValidator,
22
- number,
23
17
  NumberValidator,
24
- object,
25
18
  ObjectValidator,
26
19
  OneOfValidator,
27
20
  OptionalValidator,
28
- string,
29
21
  StringValidator,
30
22
  TupleValidator,
31
- url,
32
23
  URLValidator
33
24
  } from "./index.mjs";
34
25
  var generators = /* @__PURE__ */ new Map();
@@ -72,7 +63,7 @@ function generateTypeNode(validator, references) {
72
63
  return type;
73
64
  if (type === neverType)
74
65
  return undefinedType;
75
- if (isUnionTypeNode(type)) {
66
+ if (ts.isUnionTypeNode(type)) {
76
67
  return ts.factory.createUnionTypeNode([...type.types, undefinedType]);
77
68
  }
78
69
  return ts.factory.createUnionTypeNode([type, undefinedType]);
@@ -106,15 +97,6 @@ registerTypeGenerator(BooleanValidator, () => booleanType);
106
97
  registerTypeGenerator(NeverValidator, () => neverType);
107
98
  registerTypeGenerator(DateValidator, () => ts.factory.createTypeReferenceNode("Date"));
108
99
  registerTypeGenerator(URLValidator, () => ts.factory.createTypeReferenceNode("URL"));
109
- registerTypeGenerator(any, () => anyType);
110
- registerTypeGenerator(array, () => anyArrayType);
111
- registerTypeGenerator(number, () => numberType);
112
- registerTypeGenerator(object, () => recordType);
113
- registerTypeGenerator(string, () => stringType);
114
- registerTypeGenerator(boolean, () => booleanType);
115
- registerTypeGenerator(never, () => neverType);
116
- registerTypeGenerator(date, () => ts.factory.createTypeReferenceNode("Date"));
117
- registerTypeGenerator(url, () => ts.factory.createTypeReferenceNode("URL"));
118
100
  registerTypeGenerator(ArrayValidator, (validator, references) => {
119
101
  const itemType = generateTypeNode(validator.items, references);
120
102
  return ts.factory.createArrayTypeNode(itemType);
@@ -166,8 +148,8 @@ registerTypeGenerator(TupleValidator, (validator, references) => {
166
148
  const types = members.slice(first, next).map(({ validator: validator2 }) => generateTypeNode(validator2, references));
167
149
  const after = members.slice(next).map(({ validator: validator2 }) => generateTypeNode(validator2, references));
168
150
  const union = ts.factory.createUnionTypeNode(types);
169
- const array2 = ts.factory.createArrayTypeNode(union);
170
- const rest = ts.factory.createRestTypeNode(array2);
151
+ const array = ts.factory.createArrayTypeNode(union);
152
+ const rest = ts.factory.createRestTypeNode(array);
171
153
  return ts.factory.createTupleTypeNode([...before, rest, ...after]);
172
154
  });
173
155
  registerTypeGenerator(AllOfValidator, (validator, references) => {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/dts-generator.ts"],
4
- "mappings": ";AAAA,OAAO,MAAM,uBAAuB;AACpC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAGK;AAsBP,IAAM,aAAa,oBAAI,IAA8C;AAG9D,SAAS,sBACZ,WACA,WACI;AACN,aAAW,IAAI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W,eAAe;AAChE,QAAM,aAAqC,CAAC;AAE5C,aAAW,CAAE,KAAK,cAAe,KAAK,UAAU,WAAW,QAAQ,GAAG;AACpE,UAAM,OAAO,iBAAiB,gBAAgB,UAAU;AACxD,UAAM,WAAW,eAAe;AAEhC,UAAM,YAAY,GAAG,QAAQ;AAAA,MACzB;AAAA,MACA;AAAA,MACA,WAAW,kBAAkB;AAAA,MAC7B;AAAA,IAAI;AAER,eAAW,KAAK,SAAS;AAAA,EAC3B;AAEA,MAAI,UAAU,sBAAsB;AAClC,UAAM,eAAe,iBAAiB,UAAU,sBAAsB,UAAU;AAEhF,UAAM,QAAQ,GAAG,QAAQ;AAAA,MACrB;AAAA;AAAA,MACA,GAAG,QAAQ,+BAA+B,CAAC,GAAG,OAAO,UAAU;AAAA,MAC/D;AAAA;AAAA,MACA;AAAA;AAAA,MACA;AAAA;AAAA,MACA;AAAA,IAAS;AAEb,QAAI,WAAW,UAAU;AAAG,aAAO;AAEnC,UAAM,OAAO,GAAG,QAAQ,sBAAsB,UAAU;AACxD,WAAO,GAAG,QAAQ,2BAA2B,CAAE,MAAM,KAAM,CAAC;AAAA,EAC9D,OAAO;AACL,WAAO,GAAG,QAAQ,sBAAsB,UAAU;AAAA,EACpD;AACF,CAAC;",
5
+ "names": ["count", "first", "next", "types", "validator"]
6
6
  }
@@ -0,0 +1,113 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // errors.ts
21
+ var errors_exports = {};
22
+ __export(errors_exports, {
23
+ ValidationError: () => ValidationError,
24
+ ValidationErrorBuilder: () => ValidationErrorBuilder,
25
+ assertSchema: () => assertSchema,
26
+ assertValidation: () => assertValidation
27
+ });
28
+ module.exports = __toCommonJS(errors_exports);
29
+ function pathToString(path) {
30
+ return path.reduce((string, key, index) => {
31
+ if (typeof key === "number")
32
+ return `${string}[${key}]`;
33
+ return index === 0 ? key : `${string}.${key}`;
34
+ }, "");
35
+ }
36
+ var ValidationError = class extends Error {
37
+ /** An `Array` of validation errors encountered while validating */
38
+ errors;
39
+ /** Our stack, always present as we enforce it in the constructor */
40
+ stack;
41
+ constructor(builderOrCause, constructorOrPath, maybeConstructor) {
42
+ let constructor;
43
+ let errors;
44
+ if (builderOrCause instanceof ValidationErrorBuilder) {
45
+ errors = builderOrCause.errors;
46
+ constructor = builderOrCause.assert;
47
+ } else {
48
+ const path = Array.isArray(constructorOrPath) ? constructorOrPath : [];
49
+ if (builderOrCause instanceof ValidationError) {
50
+ errors = builderOrCause.errors.map(({ path: subpath, message: message2 }) => ({ path: [...path, ...subpath], message: message2 }));
51
+ } else {
52
+ errors = [{ path, message: `${builderOrCause}` }];
53
+ }
54
+ constructor = typeof maybeConstructor === "function" ? maybeConstructor : typeof constructorOrPath === "function" ? constructorOrPath : ValidationError;
55
+ }
56
+ const details = errors.map(({ path, message: message2 }) => ({ key: pathToString(path), message: message2 })).map(({ key, message: message2 }) => key ? `${key}: ${message2}` : message2).join("\n ");
57
+ const message = errors.length !== 1 ? `Found ${errors.length} validation errors` : "Found 1 validation error";
58
+ super(`${message}
59
+ ${details}`);
60
+ Error.captureStackTrace(this, constructor);
61
+ Object.defineProperty(this, "errors", { value: errors });
62
+ }
63
+ };
64
+ var ValidationErrorBuilder = class {
65
+ /** The current list of validation errors */
66
+ errors = [];
67
+ /**
68
+ * Record a validation error associated with the specified key.
69
+ *
70
+ * @param error - The error (normally a `string` or a `ValidationError`)
71
+ * to record and associate with the given key
72
+ * @param key - The key in an object, or index in an array where the
73
+ * vaildation error was encountered
74
+ */
75
+ record(error, ...key) {
76
+ const path = [...key];
77
+ if (error instanceof ValidationError) {
78
+ error.errors.forEach(({ path: subpath, message }) => {
79
+ this.errors.push({ path: [...path, ...subpath], message });
80
+ });
81
+ } else {
82
+ this.errors.push({ path, message: `${error}` });
83
+ }
84
+ return this;
85
+ }
86
+ /**
87
+ * Assert there are no validation errors and return the specified value, or
88
+ * throw a `ValidationError` combining all errors
89
+ *
90
+ * @param value - The value to return if no errors have been recorded
91
+ */
92
+ assert(value) {
93
+ if (this.errors.length > 0)
94
+ throw new ValidationError(this);
95
+ return value;
96
+ }
97
+ };
98
+ function assertValidation(what, message) {
99
+ if (!what)
100
+ throw new ValidationError(message, assertValidation);
101
+ }
102
+ function assertSchema(what, message) {
103
+ if (!what)
104
+ throw new TypeError(message);
105
+ }
106
+ // Annotate the CommonJS export names for ESM import in node:
107
+ 0 && (module.exports = {
108
+ ValidationError,
109
+ ValidationErrorBuilder,
110
+ assertSchema,
111
+ assertValidation
112
+ });
113
+ //# sourceMappingURL=errors.cjs.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/errors.ts"],
4
+ "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,SAAS,aAAa,MAAmC;AACvD,SAAO,KAAK,OAAO,CAAC,QAAgB,KAAK,UAAkB;AACzD,QAAI,OAAO,QAAQ;AAAU,aAAO,GAAG,UAAU;AACjD,WAAO,UAAU,IAAI,MAAM,GAAG,UAAU;AAAA,EAC1C,GAAG,EAAE;AACP;AAKO,IAAM,kBAAN,cAA8B,MAAM;AAAA;AAAA,EAEhC;AAAA;AAAA,EAEA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;AACnD,aAAK,OAAO,KAAK,EAAE,MAAM,CAAE,GAAG,MAAM,GAAG,OAAQ,GAAG,QAAQ,CAAC;AAAA,MAC7D,CAAC;AAAA,IACH,OAAO;AACL,WAAK,OAAO,KAAK,EAAE,MAAM,SAAS,GAAG,QAAQ,CAAC;AAAA,IAChD;AACA,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,OAAU,OAAa;AACrB,QAAI,KAAK,OAAO,SAAS;AAAG,YAAM,IAAI,gBAAgB,IAAI;AAC1D,WAAO;AAAA,EACT;AACF;AAKO,SAAS,iBAAiB,MAA2B,SAA+B;AACzF,MAAI,CAAE;AAAM,UAAM,IAAI,gBAAgB,SAAS,gBAAgB;AACjE;AAMO,SAAS,aAAa,MAA2B,SAA+B;AACrF,MAAI,CAAE;AAAM,UAAM,IAAI,UAAU,OAAO;AACzC;",
5
+ "names": ["message"]
6
+ }
@@ -0,0 +1,55 @@
1
+ export type ValidationErrors = {
2
+ path: (string | number)[];
3
+ message: string;
4
+ }[];
5
+ /**
6
+ * A `ValidationError` wraps one or more errors encountered during validation.
7
+ */
8
+ export declare class ValidationError extends Error {
9
+ /** An `Array` of validation errors encountered while validating */
10
+ readonly errors: ValidationErrors;
11
+ /** Our stack, always present as we enforce it in the constructor */
12
+ readonly stack: string;
13
+ /**
14
+ * Create a new `ValidationError` instance from a `ValidationErrorBuilder`
15
+ * or with a `cause` (a string, or another error) and optional path.
16
+ *
17
+ * The `constructor` (optional last parameter) will restrict creation of
18
+ * this instance's stack up to the specified function.
19
+ */
20
+ constructor(builder: ValidationErrorBuilder);
21
+ constructor(cause: any, constructor?: Function);
22
+ constructor(cause: any, path: (string | number)[], constructor?: Function);
23
+ }
24
+ /**
25
+ * Helper class to build a `ValidationError` associated p
26
+ */
27
+ export declare class ValidationErrorBuilder {
28
+ /** The current list of validation errors */
29
+ readonly errors: ValidationErrors;
30
+ /**
31
+ * Record a validation error associated with the specified key.
32
+ *
33
+ * @param error - The error (normally a `string` or a `ValidationError`)
34
+ * to record and associate with the given key
35
+ * @param key - The key in an object, or index in an array where the
36
+ * vaildation error was encountered
37
+ */
38
+ record(error: any, ...key: (string | number)[]): this;
39
+ /**
40
+ * Assert there are no validation errors and return the specified value, or
41
+ * throw a `ValidationError` combining all errors
42
+ *
43
+ * @param value - The value to return if no errors have been recorded
44
+ */
45
+ assert<T>(value: T): T;
46
+ }
47
+ /**
48
+ * Simple assertion function throwing `ValidationError`(s) with an empty path
49
+ */
50
+ export declare function assertValidation(what: boolean | undefined, message: string): asserts what;
51
+ /**
52
+ * Simple assertion function throwing `TypeError`(s) to be used when
53
+ * constructing a `Validator` from a `Schema` or validation constraints.
54
+ */
55
+ export declare function assertSchema(what: boolean | undefined, message: string): asserts what;
@@ -0,0 +1,85 @@
1
+ // errors.ts
2
+ function pathToString(path) {
3
+ return path.reduce((string, key, index) => {
4
+ if (typeof key === "number")
5
+ return `${string}[${key}]`;
6
+ return index === 0 ? key : `${string}.${key}`;
7
+ }, "");
8
+ }
9
+ var ValidationError = class extends Error {
10
+ /** An `Array` of validation errors encountered while validating */
11
+ errors;
12
+ /** Our stack, always present as we enforce it in the constructor */
13
+ stack;
14
+ constructor(builderOrCause, constructorOrPath, maybeConstructor) {
15
+ let constructor;
16
+ let errors;
17
+ if (builderOrCause instanceof ValidationErrorBuilder) {
18
+ errors = builderOrCause.errors;
19
+ constructor = builderOrCause.assert;
20
+ } else {
21
+ const path = Array.isArray(constructorOrPath) ? constructorOrPath : [];
22
+ if (builderOrCause instanceof ValidationError) {
23
+ errors = builderOrCause.errors.map(({ path: subpath, message: message2 }) => ({ path: [...path, ...subpath], message: message2 }));
24
+ } else {
25
+ errors = [{ path, message: `${builderOrCause}` }];
26
+ }
27
+ constructor = typeof maybeConstructor === "function" ? maybeConstructor : typeof constructorOrPath === "function" ? constructorOrPath : ValidationError;
28
+ }
29
+ const details = errors.map(({ path, message: message2 }) => ({ key: pathToString(path), message: message2 })).map(({ key, message: message2 }) => key ? `${key}: ${message2}` : message2).join("\n ");
30
+ const message = errors.length !== 1 ? `Found ${errors.length} validation errors` : "Found 1 validation error";
31
+ super(`${message}
32
+ ${details}`);
33
+ Error.captureStackTrace(this, constructor);
34
+ Object.defineProperty(this, "errors", { value: errors });
35
+ }
36
+ };
37
+ var ValidationErrorBuilder = class {
38
+ /** The current list of validation errors */
39
+ errors = [];
40
+ /**
41
+ * Record a validation error associated with the specified key.
42
+ *
43
+ * @param error - The error (normally a `string` or a `ValidationError`)
44
+ * to record and associate with the given key
45
+ * @param key - The key in an object, or index in an array where the
46
+ * vaildation error was encountered
47
+ */
48
+ record(error, ...key) {
49
+ const path = [...key];
50
+ if (error instanceof ValidationError) {
51
+ error.errors.forEach(({ path: subpath, message }) => {
52
+ this.errors.push({ path: [...path, ...subpath], message });
53
+ });
54
+ } else {
55
+ this.errors.push({ path, message: `${error}` });
56
+ }
57
+ return this;
58
+ }
59
+ /**
60
+ * Assert there are no validation errors and return the specified value, or
61
+ * throw a `ValidationError` combining all errors
62
+ *
63
+ * @param value - The value to return if no errors have been recorded
64
+ */
65
+ assert(value) {
66
+ if (this.errors.length > 0)
67
+ throw new ValidationError(this);
68
+ return value;
69
+ }
70
+ };
71
+ function assertValidation(what, message) {
72
+ if (!what)
73
+ throw new ValidationError(message, assertValidation);
74
+ }
75
+ function assertSchema(what, message) {
76
+ if (!what)
77
+ throw new TypeError(message);
78
+ }
79
+ export {
80
+ ValidationError,
81
+ ValidationErrorBuilder,
82
+ assertSchema,
83
+ assertValidation
84
+ };
85
+ //# sourceMappingURL=errors.mjs.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/errors.ts"],
4
+ "mappings": ";AAGA,SAAS,aAAa,MAAmC;AACvD,SAAO,KAAK,OAAO,CAAC,QAAgB,KAAK,UAAkB;AACzD,QAAI,OAAO,QAAQ;AAAU,aAAO,GAAG,UAAU;AACjD,WAAO,UAAU,IAAI,MAAM,GAAG,UA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GAAG,GAAI;AACtB,QAAI,iBAAiB,iBAAiB;AACpC,YAAM,OAAO,QAAQ,CAAC,EAAE,MAAM,SAAS,QAAQ,MAAM;AACnD,aAAK,OAAO,KAAK,EAAE,MAAM,CAAE,GAAG,MAAM,GAAG,OAAQ,GAAG,QAAQ,CAAC;AAAA,MAC7D,CAAC;AAAA,IACH,OAAO;AACL,WAAK,OAAO,KAAK,EAAE,MAAM,SAAS,GAAG,QAAQ,CAAC;AAAA,IAChD;AACA,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,OAAU,OAAa;AACrB,QAAI,KAAK,OAAO,SAAS;AAAG,YAAM,IAAI,gBAAgB,IAAI;AAC1D,WAAO;AAAA,EACT;AACF;AAKO,SAAS,iBAAiB,MAA2B,SAA+B;AACzF,MAAI,CAAE;AAAM,UAAM,IAAI,gBAAgB,SAAS,gBAAgB;AACjE;AAMO,SAAS,aAAa,MAA2B,SAA+B;AACrF,MAAI,CAAE;AAAM,UAAM,IAAI,UAAU,OAAO;AACzC;",
5
+ "names": ["message"]
6
+ }
package/dist/index.cjs ADDED
@@ -0,0 +1,133 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+
21
+ // index.ts
22
+ var src_exports = {};
23
+ __export(src_exports, {
24
+ AllOfValidator: () => import_union.AllOfValidator,
25
+ AnyArrayValidator: () => import_array.AnyArrayValidator,
26
+ AnyNumberValidator: () => import_number.AnyNumberValidator,
27
+ AnyObjectValidator: () => import_object.AnyObjectValidator,
28
+ AnyStringValidator: () => import_string.AnyStringValidator,
29
+ AnyValidator: () => import_any.AnyValidator,
30
+ ArrayValidator: () => import_array.ArrayValidator,
31
+ BooleanValidator: () => import_boolean.BooleanValidator,
32
+ ConstantValidator: () => import_constant.ConstantValidator,
33
+ DateValidator: () => import_date.DateValidator,
34
+ NeverValidator: () => import_never.NeverValidator,
35
+ NumberValidator: () => import_number.NumberValidator,
36
+ ObjectValidator: () => import_object.ObjectValidator,
37
+ OneOfValidator: () => import_union.OneOfValidator,
38
+ OptionalValidator: () => import_optional.OptionalValidator,
39
+ StringValidator: () => import_string.StringValidator,
40
+ TupleValidator: () => import_tuple.TupleValidator,
41
+ URLValidator: () => import_url.URLValidator,
42
+ allOf: () => import_union.allOf,
43
+ any: () => import_any.any,
44
+ array: () => import_array.array,
45
+ arrayOf: () => import_array.arrayOf,
46
+ boolean: () => import_boolean.boolean,
47
+ constant: () => import_constant.constant,
48
+ date: () => import_date.date,
49
+ never: () => import_never.never,
50
+ number: () => import_number.number,
51
+ object: () => import_object.object,
52
+ objectOf: () => import_object.objectOf,
53
+ oneOf: () => import_union.oneOf,
54
+ optional: () => import_optional.optional,
55
+ string: () => import_string.string,
56
+ strip: () => strip,
57
+ tuple: () => import_tuple.tuple,
58
+ url: () => import_url.url,
59
+ validate: () => validate
60
+ });
61
+ module.exports = __toCommonJS(src_exports);
62
+ __reExport(src_exports, require("./errors.cjs"), module.exports);
63
+ __reExport(src_exports, require("./schema.cjs"), module.exports);
64
+ __reExport(src_exports, require("./types.cjs"), module.exports);
65
+ __reExport(src_exports, require("./utilities.cjs"), module.exports);
66
+ var import_any = require("./validators/any.cjs");
67
+ var import_array = require("./validators/array.cjs");
68
+ var import_boolean = require("./validators/boolean.cjs");
69
+ var import_constant = require("./validators/constant.cjs");
70
+ var import_date = require("./validators/date.cjs");
71
+ var import_never = require("./validators/never.cjs");
72
+ var import_number = require("./validators/number.cjs");
73
+ var import_object = require("./validators/object.cjs");
74
+ var import_optional = require("./validators/optional.cjs");
75
+ var import_string = require("./validators/string.cjs");
76
+ var import_tuple = require("./validators/tuple.cjs");
77
+ var import_union = require("./validators/union.cjs");
78
+ var import_url = require("./validators/url.cjs");
79
+ var import_types = require("./types.cjs");
80
+ var import_utilities = require("./utilities.cjs");
81
+ function validate(validation, value, options) {
82
+ const opts = { ...import_types.defaultValidationOptions, ...options };
83
+ return (0, import_utilities.getValidator)(validation).validate(value, opts);
84
+ }
85
+ function strip(validation, value, options) {
86
+ const opts = {
87
+ stripAdditionalProperties: true,
88
+ stripForbiddenProperties: false,
89
+ stripOptionalNulls: true,
90
+ ...options
91
+ };
92
+ return (0, import_utilities.getValidator)(validation).validate(value, opts);
93
+ }
94
+ // Annotate the CommonJS export names for ESM import in node:
95
+ 0 && (module.exports = {
96
+ AllOfValidator,
97
+ AnyArrayValidator,
98
+ AnyNumberValidator,
99
+ AnyObjectValidator,
100
+ AnyStringValidator,
101
+ AnyValidator,
102
+ ArrayValidator,
103
+ BooleanValidator,
104
+ ConstantValidator,
105
+ DateValidator,
106
+ NeverValidator,
107
+ NumberValidator,
108
+ ObjectValidator,
109
+ OneOfValidator,
110
+ OptionalValidator,
111
+ StringValidator,
112
+ TupleValidator,
113
+ URLValidator,
114
+ allOf,
115
+ any,
116
+ array,
117
+ arrayOf,
118
+ boolean,
119
+ constant,
120
+ date,
121
+ never,
122
+ number,
123
+ object,
124
+ objectOf,
125
+ oneOf,
126
+ optional,
127
+ string,
128
+ strip,
129
+ tuple,
130
+ url,
131
+ validate
132
+ });
133
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/index.ts"],
4
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAKA,wBAAc,yBALd;AAMA,wBAAc,yBANd;AAOA,wBAAc,wBAPd;AAQA,wBAAc,4BARd;AAWA,iBAAkC;AAClC,mBAAkE;AAClE,qBAA0C;AAC1C,sBAA4C;AAC5C,kBAAoC;AACpC,mBAAsC;AACtC,oBAA4D;AAC5D,oBAAsE;AACtE,sBAA4C;AAC5C,oBAA4D;AAC5D,mBAAsC;AACtC,mBAA6D;AAC7D,iBAAkC;AAelC,mBAAyC;AACzC,uBAA6B;AAUtB,SAAS,SACZ,YACA,OACA,SACkB;AACpB,QAAM,OAA0B,EAAE,GAAG,uCAA0B,GAAG,QAAQ;AAC1E,aAAO,+BAAa,UAAU,EAAE,SAAS,OAAO,IAAI;AACtD;AAgBO,SAAS,MACZ,YACA,OACA,SACkB;AACpB,QAAM,OAA0B;AAAA,IAC9B,2BAA2B;AAAA,IAC3B,0BAA0B;AAAA,IAC1B,oBAAoB;AAAA,IACpB,GAAG;AAAA,EACL;AAEA,aAAO,+BAAa,UAAU,EAAE,SAAS,OAAO,IAAI;AACtD;",
5
+ "names": []
6
+ }
@@ -0,0 +1,47 @@
1
+ export * from './errors';
2
+ export * from './schema';
3
+ export * from './types';
4
+ export * from './utilities';
5
+ export { any, AnyValidator } from './validators/any';
6
+ export { array, arrayOf, ArrayValidator, AnyArrayValidator } from './validators/array';
7
+ export { boolean, BooleanValidator } from './validators/boolean';
8
+ export { constant, ConstantValidator } from './validators/constant';
9
+ export { date, DateValidator } from './validators/date';
10
+ export { never, NeverValidator } from './validators/never';
11
+ export { AnyNumberValidator, number, NumberValidator } from './validators/number';
12
+ export { AnyObjectValidator, object, objectOf, ObjectValidator } from './validators/object';
13
+ export { optional, OptionalValidator } from './validators/optional';
14
+ export { AnyStringValidator, string, StringValidator } from './validators/string';
15
+ export { tuple, TupleValidator } from './validators/tuple';
16
+ export { allOf, AllOfValidator, oneOf, OneOfValidator } from './validators/union';
17
+ export { url, URLValidator } from './validators/url';
18
+ export type { ArrayConstraints } from './validators/array';
19
+ export type { BooleanConstraints } from './validators/boolean';
20
+ export type { DateConstraints } from './validators/date';
21
+ export type { BrandedNumberConstraints } from './validators/number';
22
+ export type { BrandedStringConstraints, StringConstraints } from './validators/string';
23
+ export type { TupleMember } from './validators/tuple';
24
+ export type { URLConstraints } from './validators/url';
25
+ import type { InferValidation, Validation, ValidationOptions } from './types';
26
+ /**
27
+ * Validate a _value_ using the specified `Validation`.
28
+ *
29
+ * By default additional and forbidden properties will _not_ be stripped and
30
+ * reported as an error.
31
+ */
32
+ export declare function validate<V extends Validation>(validation: V, value: any, options?: ValidationOptions): InferValidation<V>;
33
+ /**
34
+ * Validate a _value_ using the specified `Validation`, automatically stripping
35
+ * additional properties and optional `null`s (but not forbidden ones).
36
+ *
37
+ * This is equivalent to:
38
+ *
39
+ * ```
40
+ * validate(validation, value, {
41
+ * stripAdditionalProperties: true,
42
+ * stripForbiddenProperties: false,
43
+ * stripOptionalNulls: true,
44
+ * })
45
+ * ```
46
+ */
47
+ export declare function strip<V extends Validation>(validation: V, value: any, options?: ValidationOptions): InferValidation<V>;