arktype 2.0.0-dev.11 → 2.0.0-dev.12-cjs

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 (36) hide show
  1. package/out/api.d.ts +1 -1
  2. package/out/api.js +19 -5
  3. package/out/ark.js +13 -10
  4. package/out/config.js +17 -1
  5. package/out/generic.js +8 -4
  6. package/out/match.js +5 -1
  7. package/out/module.d.ts +4 -5
  8. package/out/module.js +5 -3
  9. package/out/package.json +3 -0
  10. package/out/parser/definition.d.ts +1 -1
  11. package/out/parser/definition.js +19 -14
  12. package/out/parser/generic.js +11 -7
  13. package/out/parser/objectLiteral.js +23 -17
  14. package/out/parser/semantic/bounds.js +5 -1
  15. package/out/parser/semantic/divisor.js +2 -1
  16. package/out/parser/semantic/infer.js +2 -1
  17. package/out/parser/semantic/utils.js +2 -1
  18. package/out/parser/semantic/validate.js +7 -2
  19. package/out/parser/string/reduce/dynamic.js +24 -20
  20. package/out/parser/string/reduce/shared.js +17 -9
  21. package/out/parser/string/reduce/static.js +2 -1
  22. package/out/parser/string/shift/operand/date.js +18 -10
  23. package/out/parser/string/shift/operand/enclosed.js +17 -12
  24. package/out/parser/string/shift/operand/genericArgs.js +10 -5
  25. package/out/parser/string/shift/operand/operand.js +15 -11
  26. package/out/parser/string/shift/operand/unenclosed.d.ts +2 -2
  27. package/out/parser/string/shift/operand/unenclosed.js +30 -22
  28. package/out/parser/string/shift/operator/bounds.js +35 -27
  29. package/out/parser/string/shift/operator/divisor.js +11 -6
  30. package/out/parser/string/shift/operator/operator.js +18 -13
  31. package/out/parser/string/shift/scanner.js +8 -4
  32. package/out/parser/string/string.js +12 -7
  33. package/out/parser/tuple.js +46 -35
  34. package/out/scope.js +30 -24
  35. package/out/type.js +13 -9
  36. package/package.json +6 -14
@@ -1,8 +1,12 @@
1
- import { jsObjects, makeRootAndArrayPropertiesMutable, tsKeywords } from "@arktype/schema";
2
- import { append, objectKindOrDomainOf, throwParseError } from "@arktype/util";
3
- import { writeMissingRightOperandMessage } from "./string/shift/operand/unenclosed.js";
4
- export const parseTuple = (def, ctx) => maybeParseTupleExpression(def, ctx) ?? parseTupleLiteral(def, ctx);
5
- export const parseTupleLiteral = (def, ctx) => {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.writeInvalidConstructorMessage = exports.parseNarrowTuple = exports.writeMalformedFunctionalExpressionMessage = exports.parseMorphTuple = exports.parseKeyOfTuple = exports.spreadOptionalMessage = exports.optionalPostVariadicMessage = exports.requiredPostOptionalMessage = exports.multipleVariadicMesage = exports.writeNonArraySpreadMessage = exports.parseTupleLiteral = exports.parseTuple = void 0;
4
+ const schema_1 = require("@arktype/schema");
5
+ const util_1 = require("@arktype/util");
6
+ const unenclosed_js_1 = require("./string/shift/operand/unenclosed.js");
7
+ const parseTuple = (def, ctx) => maybeParseTupleExpression(def, ctx) ?? (0, exports.parseTupleLiteral)(def, ctx);
8
+ exports.parseTuple = parseTuple;
9
+ const parseTupleLiteral = (def, ctx) => {
6
10
  let sequences = [{}];
7
11
  let i = 0;
8
12
  while (i < def.length) {
@@ -16,19 +20,19 @@ export const parseTupleLiteral = (def, ctx) => {
16
20
  i++;
17
21
  if (def[i] === "?") {
18
22
  if (spread)
19
- return throwParseError(spreadOptionalMessage);
23
+ return (0, util_1.throwParseError)(exports.spreadOptionalMessage);
20
24
  optional = true;
21
25
  i++;
22
26
  }
23
27
  if (spread) {
24
- if (!element.extends(jsObjects.Array))
25
- return throwParseError(writeNonArraySpreadMessage(element.expression));
28
+ if (!element.extends(schema_1.jsObjects.Array))
29
+ return (0, util_1.throwParseError)((0, exports.writeNonArraySpreadMessage)(element.expression));
26
30
  // a spread must be distributed over branches e.g.:
27
31
  // def: [string, ...(number[] | [true, false])]
28
32
  // nodes: [string, ...number[]] | [string, true, false]
29
33
  sequences = sequences.flatMap(base =>
30
34
  // since appendElement mutates base, we have to shallow-ish clone it for each branch
31
- element.branches.map(branch => appendSpreadBranch(makeRootAndArrayPropertiesMutable(base), branch)));
35
+ element.branches.map(branch => appendSpreadBranch((0, schema_1.makeRootAndArrayPropertiesMutable)(base), branch)));
32
36
  }
33
37
  else {
34
38
  sequences = sequences.map(base => appendElement(base, optional ? "optional" : "required", element));
@@ -39,36 +43,37 @@ export const parseTupleLiteral = (def, ctx) => {
39
43
  sequence
40
44
  })));
41
45
  };
46
+ exports.parseTupleLiteral = parseTupleLiteral;
42
47
  const appendElement = (base, kind, element) => {
43
48
  switch (kind) {
44
49
  case "required":
45
50
  if (base.optionals)
46
51
  // e.g. [string?, number]
47
- return throwParseError(requiredPostOptionalMessage);
52
+ return (0, util_1.throwParseError)(exports.requiredPostOptionalMessage);
48
53
  if (base.variadic) {
49
54
  // e.g. [...string[], number]
50
- base.postfix = append(base.postfix, element);
55
+ base.postfix = (0, util_1.append)(base.postfix, element);
51
56
  }
52
57
  else {
53
58
  // e.g. [string, number]
54
- base.prefix = append(base.prefix, element);
59
+ base.prefix = (0, util_1.append)(base.prefix, element);
55
60
  }
56
61
  return base;
57
62
  case "optional":
58
63
  if (base.variadic)
59
64
  // e.g. [...string[], number?]
60
- return throwParseError(optionalPostVariadicMessage);
65
+ return (0, util_1.throwParseError)(exports.optionalPostVariadicMessage);
61
66
  // e.g. [string, number?]
62
- base.optionals = append(base.optionals, element);
67
+ base.optionals = (0, util_1.append)(base.optionals, element);
63
68
  return base;
64
69
  case "variadic":
65
70
  // e.g. [...string[], number, ...string[]]
66
71
  if (base.postfix)
67
- throwParseError(multipleVariadicMesage);
72
+ (0, util_1.throwParseError)(exports.multipleVariadicMesage);
68
73
  if (base.variadic) {
69
74
  if (!base.variadic.equals(element)) {
70
75
  // e.g. [...string[], ...number[]]
71
- throwParseError(multipleVariadicMesage);
76
+ (0, util_1.throwParseError)(exports.multipleVariadicMesage);
72
77
  }
73
78
  // e.g. [...string[], ...string[]]
74
79
  // do nothing, second spread doesn't change the type
@@ -84,7 +89,7 @@ const appendSpreadBranch = (base, branch) => {
84
89
  const spread = branch.firstReferenceOfKind("sequence");
85
90
  if (!spread) {
86
91
  // the only array with no sequence reference is unknown[]
87
- return appendElement(base, "variadic", tsKeywords.unknown);
92
+ return appendElement(base, "variadic", schema_1.tsKeywords.unknown);
88
93
  }
89
94
  spread.prefix.forEach(node => appendElement(base, "required", node));
90
95
  spread.optionals.forEach(node => appendElement(base, "optional", node));
@@ -110,55 +115,60 @@ const maybeParseTupleExpression = (def, ctx) => {
110
115
  // )
111
116
  // : tupleExpressionResult
112
117
  };
113
- export const writeNonArraySpreadMessage = (operand) => `Spread element must be an array (was ${operand})`;
114
- export const multipleVariadicMesage = "A tuple may have at most one variadic element";
115
- export const requiredPostOptionalMessage = "A required element may not follow an optional element";
116
- export const optionalPostVariadicMessage = "An optional element may not follow a variadic element";
117
- export const spreadOptionalMessage = "A spread element cannot be optional";
118
- export const parseKeyOfTuple = (def, ctx) => ctx.$.parse(def[1], ctx).keyof();
118
+ const writeNonArraySpreadMessage = (operand) => `Spread element must be an array (was ${operand})`;
119
+ exports.writeNonArraySpreadMessage = writeNonArraySpreadMessage;
120
+ exports.multipleVariadicMesage = "A tuple may have at most one variadic element";
121
+ exports.requiredPostOptionalMessage = "A required element may not follow an optional element";
122
+ exports.optionalPostVariadicMessage = "An optional element may not follow a variadic element";
123
+ exports.spreadOptionalMessage = "A spread element cannot be optional";
124
+ const parseKeyOfTuple = (def, ctx) => ctx.$.parse(def[1], ctx).keyof();
125
+ exports.parseKeyOfTuple = parseKeyOfTuple;
119
126
  const parseBranchTuple = (def, ctx) => {
120
127
  if (def[2] === undefined)
121
- return throwParseError(writeMissingRightOperandMessage(def[1], ""));
128
+ return (0, util_1.throwParseError)((0, unenclosed_js_1.writeMissingRightOperandMessage)(def[1], ""));
122
129
  const l = ctx.$.parse(def[0], ctx);
123
130
  const r = ctx.$.parse(def[2], ctx);
124
131
  return def[1] === "&" ? l.and(r) : l.or(r);
125
132
  };
126
133
  const parseArrayTuple = (def, ctx) => ctx.$.parse(def[0], ctx).array();
127
134
  const isIndexOneExpression = (def) => indexOneParsers[def[1]] !== undefined;
128
- export const parseMorphTuple = (def, ctx) => {
135
+ const parseMorphTuple = (def, ctx) => {
129
136
  if (typeof def[2] !== "function") {
130
- return throwParseError(writeMalformedFunctionalExpressionMessage("=>", def[2]));
137
+ return (0, util_1.throwParseError)((0, exports.writeMalformedFunctionalExpressionMessage)("=>", def[2]));
131
138
  }
132
139
  // TODO: nested morphs?
133
140
  return ctx.$.parse(def[0], ctx).pipe(def[2]);
134
141
  };
135
- export const writeMalformedFunctionalExpressionMessage = (operator, value) => `${operator === ":" ? "Narrow" : "Morph"} expression requires a function following '${operator}' (was ${typeof value})`;
136
- export const parseNarrowTuple = (def, ctx) => {
142
+ exports.parseMorphTuple = parseMorphTuple;
143
+ const writeMalformedFunctionalExpressionMessage = (operator, value) => `${operator === ":" ? "Narrow" : "Morph"} expression requires a function following '${operator}' (was ${typeof value})`;
144
+ exports.writeMalformedFunctionalExpressionMessage = writeMalformedFunctionalExpressionMessage;
145
+ const parseNarrowTuple = (def, ctx) => {
137
146
  if (typeof def[2] !== "function") {
138
- return throwParseError(writeMalformedFunctionalExpressionMessage(":", def[2]));
147
+ return (0, util_1.throwParseError)((0, exports.writeMalformedFunctionalExpressionMessage)(":", def[2]));
139
148
  }
140
149
  return ctx.$.parse(def[0], ctx).constrain("predicate", def[2]);
141
150
  };
151
+ exports.parseNarrowTuple = parseNarrowTuple;
142
152
  const parseAttributeTuple = (def, ctx) => ctx.$.parse(def[0], ctx).configureShallowDescendants(def[2]);
143
153
  const indexOneParsers = {
144
154
  "|": parseBranchTuple,
145
155
  "&": parseBranchTuple,
146
156
  "[]": parseArrayTuple,
147
- ":": parseNarrowTuple,
148
- "=>": parseMorphTuple,
157
+ ":": exports.parseNarrowTuple,
158
+ "=>": exports.parseMorphTuple,
149
159
  "@": parseAttributeTuple
150
160
  };
151
161
  const prefixParsers = {
152
- keyof: parseKeyOfTuple,
162
+ keyof: exports.parseKeyOfTuple,
153
163
  instanceof: (def, ctx) => {
154
164
  if (typeof def[1] !== "function") {
155
- return throwParseError(writeInvalidConstructorMessage(objectKindOrDomainOf(def[1])));
165
+ return (0, util_1.throwParseError)((0, exports.writeInvalidConstructorMessage)((0, util_1.objectKindOrDomainOf)(def[1])));
156
166
  }
157
167
  const branches = def
158
168
  .slice(1)
159
169
  .map(ctor => typeof ctor === "function" ?
160
170
  ctx.$.node("proto", { proto: ctor })
161
- : throwParseError(writeInvalidConstructorMessage(objectKindOrDomainOf(ctor))));
171
+ : (0, util_1.throwParseError)((0, exports.writeInvalidConstructorMessage)((0, util_1.objectKindOrDomainOf)(ctor))));
162
172
  return branches.length === 1 ?
163
173
  branches[0]
164
174
  : ctx.$.node("union", { branches });
@@ -166,4 +176,5 @@ const prefixParsers = {
166
176
  "===": (def, ctx) => ctx.$.units(def.slice(1))
167
177
  };
168
178
  const isIndexZeroExpression = (def) => prefixParsers[def[0]] !== undefined;
169
- export const writeInvalidConstructorMessage = (actual) => `Expected a constructor following 'instanceof' operator (was ${actual})`;
179
+ const writeInvalidConstructorMessage = (actual) => `Expected a constructor following 'instanceof' operator (was ${actual})`;
180
+ exports.writeInvalidConstructorMessage = writeInvalidConstructorMessage;
package/out/scope.js CHANGED
@@ -1,35 +1,38 @@
1
- import { RawRootScope, hasArkKind } from "@arktype/schema";
2
- import { domainOf, hasDomain, isThunk, throwParseError } from "@arktype/util";
3
- import { Generic } from "./generic.js";
4
- import { createMatchParser } from "./match.js";
5
- import { parseObject, writeBadDefinitionTypeMessage } from "./parser/definition.js";
6
- import { parseGenericParams } from "./parser/generic.js";
7
- import { DynamicState } from "./parser/string/reduce/dynamic.js";
8
- import { fullStringParse } from "./parser/string/string.js";
9
- import { RawTypeParser } from "./type.js";
10
- export const scope = ((def, config = {}) => new RawScope(def, config));
11
- export class RawScope extends RawRootScope {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseScopeKey = exports.writeShallowCycleErrorMessage = exports.RawScope = exports.scope = void 0;
4
+ const schema_1 = require("@arktype/schema");
5
+ const util_1 = require("@arktype/util");
6
+ const generic_js_1 = require("./generic.js");
7
+ const match_js_1 = require("./match.js");
8
+ const definition_js_1 = require("./parser/definition.js");
9
+ const generic_js_2 = require("./parser/generic.js");
10
+ const dynamic_js_1 = require("./parser/string/reduce/dynamic.js");
11
+ const string_js_1 = require("./parser/string/string.js");
12
+ const type_js_1 = require("./type.js");
13
+ exports.scope = ((def, config = {}) => new RawScope(def, config));
14
+ class RawScope extends schema_1.RawRootScope {
12
15
  parseCache = {};
13
16
  constructor(def, config) {
14
17
  const aliases = {};
15
18
  for (const k in def) {
16
- const parsedKey = parseScopeKey(k);
19
+ const parsedKey = (0, exports.parseScopeKey)(k);
17
20
  aliases[parsedKey.name] =
18
21
  parsedKey.params.length ?
19
22
  // TODO: this
20
- new Generic(parsedKey.params, def[k], {})
23
+ new generic_js_1.Generic(parsedKey.params, def[k], {})
21
24
  : def[k];
22
25
  }
23
26
  super(aliases, config);
24
27
  }
25
- type = new RawTypeParser(this);
26
- match = createMatchParser(this);
28
+ type = new type_js_1.RawTypeParser(this);
29
+ match = (0, match_js_1.createMatchParser)(this);
27
30
  declare = (() => ({
28
31
  type: this.type
29
32
  })).bind(this);
30
33
  define = ((def) => def).bind(this);
31
34
  preparseRoot(def) {
32
- if (isThunk(def) && !hasArkKind(def, "generic"))
35
+ if ((0, util_1.isThunk)(def) && !(0, schema_1.hasArkKind)(def, "generic"))
33
36
  return def();
34
37
  return def;
35
38
  }
@@ -53,19 +56,21 @@ export class RawScope extends RawRootScope {
53
56
  this.parseCache[def] = this.parseString(def, ctx);
54
57
  return this.parseCache[def];
55
58
  }
56
- return hasDomain(def, "object") ?
57
- parseObject(def, ctx)
58
- : throwParseError(writeBadDefinitionTypeMessage(domainOf(def)));
59
+ return (0, util_1.hasDomain)(def, "object") ?
60
+ (0, definition_js_1.parseObject)(def, ctx)
61
+ : (0, util_1.throwParseError)((0, definition_js_1.writeBadDefinitionTypeMessage)((0, util_1.domainOf)(def)));
59
62
  }
60
63
  parseString(def, ctx) {
61
64
  return (this.maybeResolveRoot(def) ??
62
65
  ((def.endsWith("[]") &&
63
66
  this.maybeResolveRoot(def.slice(0, -2))?.array()) ||
64
- fullStringParse(new DynamicState(def, ctx))));
67
+ (0, string_js_1.fullStringParse)(new dynamic_js_1.DynamicState(def, ctx))));
65
68
  }
66
69
  }
67
- export const writeShallowCycleErrorMessage = (name, seen) => `Alias '${name}' has a shallow resolution cycle: ${[...seen, name].join(":")}`;
68
- export const parseScopeKey = (k) => {
70
+ exports.RawScope = RawScope;
71
+ const writeShallowCycleErrorMessage = (name, seen) => `Alias '${name}' has a shallow resolution cycle: ${[...seen, name].join(":")}`;
72
+ exports.writeShallowCycleErrorMessage = writeShallowCycleErrorMessage;
73
+ const parseScopeKey = (k) => {
69
74
  const firstParamIndex = k.indexOf("<");
70
75
  if (firstParamIndex === -1) {
71
76
  return {
@@ -74,10 +79,11 @@ export const parseScopeKey = (k) => {
74
79
  };
75
80
  }
76
81
  if (k.at(-1) !== ">") {
77
- throwParseError(`'>' must be the last character of a generic declaration in a scope`);
82
+ (0, util_1.throwParseError)(`'>' must be the last character of a generic declaration in a scope`);
78
83
  }
79
84
  return {
80
85
  name: k.slice(0, firstParamIndex),
81
- params: parseGenericParams(k.slice(firstParamIndex + 1, -1))
86
+ params: (0, generic_js_2.parseGenericParams)(k.slice(firstParamIndex + 1, -1))
82
87
  };
83
88
  };
89
+ exports.parseScopeKey = parseScopeKey;
package/out/type.js CHANGED
@@ -1,11 +1,14 @@
1
- import { ArkErrors, BaseRoot } from "@arktype/schema";
2
- import { Callable } from "@arktype/util";
3
- import { Generic } from "./generic.js";
4
- import { parseGenericParams } from "./parser/generic.js";
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Type = exports.RawTypeParser = void 0;
4
+ const schema_1 = require("@arktype/schema");
5
+ const util_1 = require("@arktype/util");
6
+ const generic_js_1 = require("./generic.js");
7
+ const generic_js_2 = require("./parser/generic.js");
5
8
  const typeParserAttachments = Object.freeze({
6
- errors: ArkErrors
9
+ errors: schema_1.ArkErrors
7
10
  });
8
- export class RawTypeParser extends Callable {
11
+ class RawTypeParser extends util_1.Callable {
9
12
  constructor($) {
10
13
  super((...args) => {
11
14
  if (args.length === 1) {
@@ -18,10 +21,10 @@ export class RawTypeParser extends Callable {
18
21
  args[0].at(-1) === ">") {
19
22
  // if there are exactly two args, the first of which looks like <${string}>,
20
23
  // treat as a generic
21
- const params = parseGenericParams(args[0].slice(1, -1));
24
+ const params = (0, generic_js_2.parseGenericParams)(args[0].slice(1, -1));
22
25
  const def = args[1];
23
26
  // TODO: validateUninstantiatedGeneric, remove this cast
24
- return new Generic(params, def, $);
27
+ return new generic_js_1.Generic(params, def, $);
25
28
  }
26
29
  // otherwise, treat as a tuple expression. technically, this also allows
27
30
  // non-expression tuple definitions to be parsed, but it's not a supported
@@ -30,4 +33,5 @@ export class RawTypeParser extends Callable {
30
33
  }, { bind: $, attach: typeParserAttachments });
31
34
  }
32
35
  }
33
- export const Type = BaseRoot;
36
+ exports.RawTypeParser = RawTypeParser;
37
+ exports.Type = schema_1.BaseRoot;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "arktype",
3
3
  "description": "TypeScript's 1:1 validator, optimized from editor to runtime",
4
- "version": "2.0.0-dev.11",
4
+ "version": "2.0.0-dev.12-cjs",
5
5
  "license": "MIT",
6
6
  "author": {
7
7
  "name": "David Blass",
@@ -16,17 +16,9 @@
16
16
  "main": "./out/api.js",
17
17
  "types": "./out/api.d.ts",
18
18
  "exports": {
19
- ".": {
20
- "types": "./out/api.d.ts",
21
- "default": "./out/api.js"
22
- },
23
- "./config": {
24
- "types": "./out/config.d.ts",
25
- "default": "./out/config.js"
26
- },
27
- "./internal/*": {
28
- "default": "./out/*"
29
- }
19
+ ".": "./out/api.js",
20
+ "./config": "./out/config.js",
21
+ "./internal/*": "./out/*"
30
22
  },
31
23
  "files": [
32
24
  "out"
@@ -36,7 +28,7 @@
36
28
  "test": "tsx ../repo/testPackage.ts"
37
29
  },
38
30
  "dependencies": {
39
- "@arktype/util": "0.0.38",
40
- "@arktype/schema": "0.1.2"
31
+ "@arktype/util": "0.0.41-cjs",
32
+ "@arktype/schema": "0.1.4-cjs"
41
33
  }
42
34
  }