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

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 (42) hide show
  1. package/LICENSE +7 -0
  2. package/out/api.d.ts +1 -1
  3. package/out/api.js +5 -19
  4. package/out/ark.js +10 -13
  5. package/out/config.js +1 -17
  6. package/out/generic.d.ts +1 -1
  7. package/out/generic.js +4 -8
  8. package/out/match.js +50 -56
  9. package/out/module.js +2 -5
  10. package/out/parser/definition.d.ts +1 -1
  11. package/out/parser/definition.js +14 -19
  12. package/out/parser/generic.js +7 -11
  13. package/out/parser/objectLiteral.d.ts +31 -18
  14. package/out/parser/objectLiteral.js +72 -43
  15. package/out/parser/semantic/bounds.js +1 -5
  16. package/out/parser/semantic/divisor.js +1 -2
  17. package/out/parser/semantic/infer.js +1 -2
  18. package/out/parser/semantic/utils.js +1 -2
  19. package/out/parser/semantic/validate.js +2 -7
  20. package/out/parser/string/reduce/dynamic.js +20 -24
  21. package/out/parser/string/reduce/shared.js +9 -17
  22. package/out/parser/string/reduce/static.js +1 -2
  23. package/out/parser/string/shift/operand/date.js +10 -18
  24. package/out/parser/string/shift/operand/enclosed.js +12 -17
  25. package/out/parser/string/shift/operand/genericArgs.js +5 -10
  26. package/out/parser/string/shift/operand/operand.d.ts +1 -1
  27. package/out/parser/string/shift/operand/operand.js +11 -15
  28. package/out/parser/string/shift/operand/unenclosed.js +22 -30
  29. package/out/parser/string/shift/operator/bounds.js +27 -35
  30. package/out/parser/string/shift/operator/divisor.js +6 -11
  31. package/out/parser/string/shift/operator/operator.js +13 -18
  32. package/out/parser/string/shift/scanner.d.ts +6 -5
  33. package/out/parser/string/shift/scanner.js +7 -8
  34. package/out/parser/string/string.js +7 -12
  35. package/out/parser/tuple.js +35 -58
  36. package/out/scope.d.ts +1 -2
  37. package/out/scope.js +24 -30
  38. package/out/type.js +9 -13
  39. package/package.json +33 -33
  40. package/out/main.d.ts +0 -6
  41. package/out/main.js +0 -5
  42. package/out/package.json +0 -3
@@ -1,13 +1,10 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DynamicState = void 0;
4
- const util_1 = require("@arktype/util");
5
- const operand_js_1 = require("../shift/operand/operand.js");
6
- const operator_js_1 = require("../shift/operator/operator.js");
7
- const scanner_js_1 = require("../shift/scanner.js");
8
- const string_js_1 = require("../string.js");
9
- const shared_js_1 = require("./shared.js");
10
- class DynamicState {
1
+ import { isKeyOf, throwInternalError, throwParseError } from "@arktype/util";
2
+ import { parseOperand } from "../shift/operand/operand.js";
3
+ import { parseOperator } from "../shift/operator/operator.js";
4
+ import { Scanner } from "../shift/scanner.js";
5
+ import { parseUntilFinalizer } from "../string.js";
6
+ import { invertedComparators, minComparators, writeMultipleLeftBoundsMessage, writeOpenRangeMessage, writeUnclosedGroupMessage, writeUnmatchedGroupCloseMessage, writeUnpairableComparatorMessage } from "./shared.js";
7
+ export class DynamicState {
11
8
  ctx;
12
9
  scanner;
13
10
  // set root type to `any` so that all constraints can be applied
@@ -22,10 +19,10 @@ class DynamicState {
22
19
  groups = [];
23
20
  constructor(def, ctx) {
24
21
  this.ctx = ctx;
25
- this.scanner = new scanner_js_1.Scanner(def);
22
+ this.scanner = new Scanner(def);
26
23
  }
27
24
  error(message) {
28
- return (0, util_1.throwParseError)(message);
25
+ return throwParseError(message);
29
26
  }
30
27
  hasRoot() {
31
28
  return this.root !== undefined;
@@ -43,16 +40,16 @@ class DynamicState {
43
40
  }
44
41
  finalize(finalizer) {
45
42
  if (this.groups.length)
46
- return this.error((0, shared_js_1.writeUnclosedGroupMessage)(")"));
43
+ return this.error(writeUnclosedGroupMessage(")"));
47
44
  this.finalizeBranches();
48
45
  this.finalizer = finalizer;
49
46
  }
50
47
  reduceLeftBound(limit, comparator) {
51
- const invertedComparator = shared_js_1.invertedComparators[comparator];
52
- if (!(0, util_1.isKeyOf)(invertedComparator, shared_js_1.minComparators))
53
- return this.error((0, shared_js_1.writeUnpairableComparatorMessage)(comparator));
48
+ const invertedComparator = invertedComparators[comparator];
49
+ if (!isKeyOf(invertedComparator, minComparators))
50
+ return this.error(writeUnpairableComparatorMessage(comparator));
54
51
  if (this.branches.leftBound) {
55
- return this.error((0, shared_js_1.writeMultipleLeftBoundsMessage)(this.branches.leftBound.limit, this.branches.leftBound.comparator, limit, invertedComparator));
52
+ return this.error(writeMultipleLeftBoundsMessage(this.branches.leftBound.limit, this.branches.leftBound.comparator, limit, invertedComparator));
56
53
  }
57
54
  this.branches.leftBound = {
58
55
  comparator: invertedComparator,
@@ -76,7 +73,7 @@ class DynamicState {
76
73
  this.finalizeBranches();
77
74
  const topBranchState = this.groups.pop();
78
75
  if (!topBranchState)
79
- return this.error((0, shared_js_1.writeUnmatchedGroupCloseMessage)(this.scanner.unscanned));
76
+ return this.error(writeUnmatchedGroupCloseMessage(this.scanner.unscanned));
80
77
  this.branches = topBranchState;
81
78
  }
82
79
  addPrefix(prefix) {
@@ -88,7 +85,7 @@ class DynamicState {
88
85
  this.root =
89
86
  lastPrefix === "keyof" ?
90
87
  this.root.keyof()
91
- : (0, util_1.throwInternalError)(`Unexpected prefix '${lastPrefix}'`);
88
+ : throwInternalError(`Unexpected prefix '${lastPrefix}'`);
92
89
  }
93
90
  }
94
91
  pushRootToBranch(token) {
@@ -105,17 +102,17 @@ class DynamicState {
105
102
  this.root = undefined;
106
103
  }
107
104
  parseUntilFinalizer() {
108
- return (0, string_js_1.parseUntilFinalizer)(new DynamicState(this.scanner.unscanned, this.ctx));
105
+ return parseUntilFinalizer(new DynamicState(this.scanner.unscanned, this.ctx));
109
106
  }
110
107
  parseOperator() {
111
- return (0, operator_js_1.parseOperator)(this);
108
+ return parseOperator(this);
112
109
  }
113
110
  parseOperand() {
114
- return (0, operand_js_1.parseOperand)(this);
111
+ return parseOperand(this);
115
112
  }
116
113
  assertRangeUnset() {
117
114
  if (this.branches.leftBound) {
118
- return this.error((0, shared_js_1.writeOpenRangeMessage)(this.branches.leftBound.limit, this.branches.leftBound.comparator));
115
+ return this.error(writeOpenRangeMessage(this.branches.leftBound.limit, this.branches.leftBound.comparator));
119
116
  }
120
117
  }
121
118
  reduceGroupOpen() {
@@ -139,4 +136,3 @@ class DynamicState {
139
136
  return this;
140
137
  }
141
138
  }
142
- exports.DynamicState = DynamicState;
@@ -1,35 +1,27 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.writeMultipleLeftBoundsMessage = exports.writeUnpairableComparatorMessage = exports.writeOpenRangeMessage = exports.writeUnclosedGroupMessage = exports.writeUnmatchedGroupCloseMessage = exports.invertedComparators = exports.comparators = exports.maxComparators = exports.minComparators = void 0;
4
- exports.minComparators = {
1
+ export const minComparators = {
5
2
  ">": true,
6
3
  ">=": true
7
4
  };
8
- exports.maxComparators = {
5
+ export const maxComparators = {
9
6
  "<": true,
10
7
  "<=": true
11
8
  };
12
- exports.comparators = {
9
+ export const comparators = {
13
10
  ">": true,
14
11
  ">=": true,
15
12
  "<": true,
16
13
  "<=": true,
17
14
  "==": true
18
15
  };
19
- exports.invertedComparators = {
16
+ export const invertedComparators = {
20
17
  "<": ">",
21
18
  ">": "<",
22
19
  "<=": ">=",
23
20
  ">=": "<=",
24
21
  "==": "=="
25
22
  };
26
- const writeUnmatchedGroupCloseMessage = (unscanned) => `Unmatched )${(unscanned === "" ? "" : ` before ${unscanned}`)}`;
27
- exports.writeUnmatchedGroupCloseMessage = writeUnmatchedGroupCloseMessage;
28
- const writeUnclosedGroupMessage = (missingChar) => `Missing ${missingChar}`;
29
- exports.writeUnclosedGroupMessage = writeUnclosedGroupMessage;
30
- const writeOpenRangeMessage = (min, comparator) => `Left bounds are only valid when paired with right bounds (try ...${comparator}${min})`;
31
- exports.writeOpenRangeMessage = writeOpenRangeMessage;
32
- const writeUnpairableComparatorMessage = (comparator) => `Left-bounded expressions must specify their limits using < or <= (was ${comparator})`;
33
- exports.writeUnpairableComparatorMessage = writeUnpairableComparatorMessage;
34
- const writeMultipleLeftBoundsMessage = (openLimit, openComparator, limit, comparator) => `An expression may have at most one left bound (parsed ${openLimit}${exports.invertedComparators[openComparator]}, ${limit}${exports.invertedComparators[comparator]})`;
35
- exports.writeMultipleLeftBoundsMessage = writeMultipleLeftBoundsMessage;
23
+ export const writeUnmatchedGroupCloseMessage = (unscanned) => `Unmatched )${(unscanned === "" ? "" : ` before ${unscanned}`)}`;
24
+ export const writeUnclosedGroupMessage = (missingChar) => `Missing ${missingChar}`;
25
+ export const writeOpenRangeMessage = (min, comparator) => `Left bounds are only valid when paired with right bounds (try ...${comparator}${min})`;
26
+ export const writeUnpairableComparatorMessage = (comparator) => `Left-bounded expressions must specify their limits using < or <= (was ${comparator})`;
27
+ export const writeMultipleLeftBoundsMessage = (openLimit, openComparator, limit, comparator) => `An expression may have at most one left bound (parsed ${openLimit}${invertedComparators[openComparator]}, ${limit}${invertedComparators[comparator]})`;
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -1,31 +1,23 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.tryParseDate = exports.writeInvalidDateMessage = exports.extractDateLiteralSource = exports.isValidDate = exports.isDateLiteral = void 0;
4
- const util_1 = require("@arktype/util");
5
- const isDateLiteral = (value) => typeof value === "string" &&
1
+ import { throwParseError, tryParseNumber } from "@arktype/util";
2
+ export const isDateLiteral = (value) => typeof value === "string" &&
6
3
  value[0] === "d" &&
7
4
  (value[1] === "'" || value[1] === '"') &&
8
5
  value.at(-1) === value[1];
9
- exports.isDateLiteral = isDateLiteral;
10
- const isValidDate = (d) => d.toString() !== "Invalid Date";
11
- exports.isValidDate = isValidDate;
12
- const extractDateLiteralSource = (literal) => literal.slice(2, -1);
13
- exports.extractDateLiteralSource = extractDateLiteralSource;
14
- const writeInvalidDateMessage = (source) => `'${source}' could not be parsed by the Date constructor`;
15
- exports.writeInvalidDateMessage = writeInvalidDateMessage;
16
- const tryParseDate = (source, errorOnFail) => maybeParseDate(source, errorOnFail);
17
- exports.tryParseDate = tryParseDate;
6
+ export const isValidDate = (d) => d.toString() !== "Invalid Date";
7
+ export const extractDateLiteralSource = (literal) => literal.slice(2, -1);
8
+ export const writeInvalidDateMessage = (source) => `'${source}' could not be parsed by the Date constructor`;
9
+ export const tryParseDate = (source, errorOnFail) => maybeParseDate(source, errorOnFail);
18
10
  const maybeParseDate = (source, errorOnFail) => {
19
11
  const stringParsedDate = new Date(source);
20
- if ((0, exports.isValidDate)(stringParsedDate))
12
+ if (isValidDate(stringParsedDate))
21
13
  return stringParsedDate;
22
- const epochMillis = (0, util_1.tryParseNumber)(source);
14
+ const epochMillis = tryParseNumber(source);
23
15
  if (epochMillis !== undefined) {
24
16
  const numberParsedDate = new Date(epochMillis);
25
- if ((0, exports.isValidDate)(numberParsedDate))
17
+ if (isValidDate(numberParsedDate))
26
18
  return numberParsedDate;
27
19
  }
28
20
  return errorOnFail ?
29
- (0, util_1.throwParseError)(errorOnFail === true ? (0, exports.writeInvalidDateMessage)(source) : errorOnFail)
21
+ throwParseError(errorOnFail === true ? writeInvalidDateMessage(source) : errorOnFail)
30
22
  : undefined;
31
23
  };
@@ -1,12 +1,9 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.writeUnterminatedEnclosedMessage = exports.untilLookaheadIsClosing = exports.enclosingTokens = exports.enclosingChar = exports.enclosingQuote = exports.parseEnclosed = void 0;
4
- const util_1 = require("@arktype/util");
5
- const date_js_1 = require("./date.js");
6
- const parseEnclosed = (s, enclosing) => {
7
- const enclosed = s.scanner.shiftUntil(exports.untilLookaheadIsClosing[exports.enclosingTokens[enclosing]]);
1
+ import { isKeyOf } from "@arktype/util";
2
+ import { tryParseDate, writeInvalidDateMessage } from "./date.js";
3
+ export const parseEnclosed = (s, enclosing) => {
4
+ const enclosed = s.scanner.shiftUntil(untilLookaheadIsClosing[enclosingTokens[enclosing]]);
8
5
  if (s.scanner.lookahead === "")
9
- return s.error((0, exports.writeUnterminatedEnclosedMessage)(enclosed, enclosing));
6
+ return s.error(writeUnterminatedEnclosedMessage(enclosed, enclosing));
10
7
  // Shift the scanner one additional time for the second enclosing token
11
8
  s.scanner.shift();
12
9
  if (enclosing === "/") {
@@ -17,31 +14,30 @@ const parseEnclosed = (s, enclosing) => {
17
14
  regex: enclosed
18
15
  }, { prereduced: true });
19
16
  }
20
- else if ((0, util_1.isKeyOf)(enclosing, exports.enclosingQuote))
17
+ else if (isKeyOf(enclosing, enclosingQuote))
21
18
  s.root = s.ctx.$.node("unit", { unit: enclosed });
22
19
  else {
23
- const date = (0, date_js_1.tryParseDate)(enclosed, (0, date_js_1.writeInvalidDateMessage)(enclosed));
20
+ const date = tryParseDate(enclosed, writeInvalidDateMessage(enclosed));
24
21
  s.root = s.ctx.$.node("unit", { unit: date, description: enclosed });
25
22
  }
26
23
  };
27
- exports.parseEnclosed = parseEnclosed;
28
- exports.enclosingQuote = {
24
+ export const enclosingQuote = {
29
25
  "'": 1,
30
26
  '"': 1
31
27
  };
32
- exports.enclosingChar = {
28
+ export const enclosingChar = {
33
29
  "/": 1,
34
30
  "'": 1,
35
31
  '"': 1
36
32
  };
37
- exports.enclosingTokens = {
33
+ export const enclosingTokens = {
38
34
  "d'": "'",
39
35
  'd"': '"',
40
36
  "'": "'",
41
37
  '"': '"',
42
38
  "/": "/"
43
39
  };
44
- exports.untilLookaheadIsClosing = {
40
+ export const untilLookaheadIsClosing = {
45
41
  "'": scanner => scanner.lookahead === `'`,
46
42
  '"': scanner => scanner.lookahead === `"`,
47
43
  "/": scanner => scanner.lookahead === `/`
@@ -51,5 +47,4 @@ const enclosingCharDescriptions = {
51
47
  "'": "single-quote",
52
48
  "/": "forward slash"
53
49
  };
54
- const writeUnterminatedEnclosedMessage = (fragment, enclosingStart) => `${enclosingStart}${fragment} requires a closing ${enclosingCharDescriptions[exports.enclosingTokens[enclosingStart]]}`;
55
- exports.writeUnterminatedEnclosedMessage = writeUnterminatedEnclosedMessage;
50
+ export const writeUnterminatedEnclosedMessage = (fragment, enclosingStart) => `${enclosingStart}${fragment} requires a closing ${enclosingCharDescriptions[enclosingTokens[enclosingStart]]}`;
@@ -1,9 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.writeInvalidGenericArgsMessage = exports.parseGenericArgs = void 0;
4
- const shared_js_1 = require("../../reduce/shared.js");
5
- const parseGenericArgs = (name, params, s) => _parseGenericArgs(name, params, s, [], []);
6
- exports.parseGenericArgs = parseGenericArgs;
1
+ import { writeUnclosedGroupMessage } from "../../reduce/shared.js";
2
+ export const parseGenericArgs = (name, params, s) => _parseGenericArgs(name, params, s, [], []);
7
3
  const _parseGenericArgs = (name, params, s, argDefs, argNodes) => {
8
4
  const argState = s.parseUntilFinalizer();
9
5
  // remove the finalizing token from the argDef
@@ -16,11 +12,10 @@ const _parseGenericArgs = (name, params, s, argDefs, argNodes) => {
16
12
  unscanned: argState.scanner.unscanned
17
13
  };
18
14
  }
19
- return argState.error((0, exports.writeInvalidGenericArgsMessage)(name, params, argDefs));
15
+ return argState.error(writeInvalidGenericArgsMessage(name, params, argDefs));
20
16
  }
21
17
  if (argState.finalizer === ",")
22
18
  return _parseGenericArgs(name, params, s, argDefs, argNodes);
23
- return argState.error((0, shared_js_1.writeUnclosedGroupMessage)(">"));
19
+ return argState.error(writeUnclosedGroupMessage(">"));
24
20
  };
25
- const writeInvalidGenericArgsMessage = (name, params, argDefs) => `${name}<${params.join(", ")}> requires exactly ${params.length} args (got ${argDefs.length}${argDefs.length === 0 ? "" : `: ${argDefs.join(", ")}`})`;
26
- exports.writeInvalidGenericArgsMessage = writeInvalidGenericArgsMessage;
21
+ export const writeInvalidGenericArgsMessage = (name, params, argDefs) => `${name}<${params.join(", ")}> requires exactly ${params.length} args (got ${argDefs.length}${argDefs.length === 0 ? "" : `: ${argDefs.join(", ")}`})`;
@@ -2,7 +2,7 @@ import type { DynamicState } from "../../reduce/dynamic.js";
2
2
  import type { StaticState, state } from "../../reduce/static.js";
3
3
  import type { BaseCompletions } from "../../string.js";
4
4
  import { Scanner } from "../scanner.js";
5
- import { type EnclosingQuote, type EnclosingStartToken, parseEnclosed } from "./enclosed.js";
5
+ import { parseEnclosed, type EnclosingQuote, type EnclosingStartToken } from "./enclosed.js";
6
6
  import { parseUnenclosed } from "./unenclosed.js";
7
7
  export declare const parseOperand: (s: DynamicState) => void;
8
8
  export type parseOperand<s extends StaticState, $, args> = s["unscanned"] extends Scanner.shift<infer lookahead, infer unscanned> ? lookahead extends "(" ? state.reduceGroupOpen<s, unscanned> : lookahead extends EnclosingStartToken ? parseEnclosed<s, lookahead, unscanned> : lookahead extends Scanner.WhiteSpaceToken ? parseOperand<state.scanTo<s, unscanned>, $, args> : lookahead extends "d" ? unscanned extends (Scanner.shift<infer enclosing extends EnclosingQuote, infer nextUnscanned>) ? parseEnclosed<s, `d${enclosing}`, nextUnscanned> : parseUnenclosed<s, $, args> : parseUnenclosed<s, $, args> : state.completion<`${s["scanned"]}${BaseCompletions<$, args>}`>;
@@ -1,17 +1,13 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseOperand = void 0;
4
- const scanner_js_1 = require("../scanner.js");
5
- const enclosed_js_1 = require("./enclosed.js");
6
- const unenclosed_js_1 = require("./unenclosed.js");
7
- const parseOperand = (s) => s.scanner.lookahead === "" ? s.error((0, unenclosed_js_1.writeMissingOperandMessage)(s))
1
+ import { Scanner } from "../scanner.js";
2
+ import { enclosingChar, enclosingQuote, parseEnclosed } from "./enclosed.js";
3
+ import { parseUnenclosed, writeMissingOperandMessage } from "./unenclosed.js";
4
+ export const parseOperand = (s) => s.scanner.lookahead === "" ? s.error(writeMissingOperandMessage(s))
8
5
  : s.scanner.lookahead === "(" ? s.shiftedByOne().reduceGroupOpen()
9
- : s.scanner.lookaheadIsIn(enclosed_js_1.enclosingChar) ? (0, enclosed_js_1.parseEnclosed)(s, s.scanner.shift())
10
- : s.scanner.lookaheadIsIn(scanner_js_1.Scanner.whiteSpaceTokens) ?
11
- (0, exports.parseOperand)(s.shiftedByOne())
6
+ : s.scanner.lookaheadIsIn(enclosingChar) ? parseEnclosed(s, s.scanner.shift())
7
+ : s.scanner.lookaheadIsIn(Scanner.whiteSpaceTokens) ?
8
+ parseOperand(s.shiftedByOne())
12
9
  : s.scanner.lookahead === "d" ?
13
- s.shiftedByOne().scanner.lookaheadIsIn(enclosed_js_1.enclosingChar) ?
14
- (0, enclosed_js_1.parseEnclosed)(s, `d${s.scanner.shift()}`)
15
- : (0, unenclosed_js_1.parseUnenclosed)(s)
16
- : (0, unenclosed_js_1.parseUnenclosed)(s);
17
- exports.parseOperand = parseOperand;
10
+ s.scanner.nextLookahead in enclosingQuote ?
11
+ parseEnclosed(s, `${s.scanner.shift()}${s.scanner.shift()}`)
12
+ : parseUnenclosed(s)
13
+ : parseUnenclosed(s);
@@ -1,64 +1,56 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.writeExpressionExpectedMessage = exports.writeMissingRightOperandMessage = exports.writeMissingOperandMessage = exports.parseGenericInstantiation = exports.parseUnenclosed = void 0;
4
- const schema_1 = require("@arktype/schema");
5
- const util_1 = require("@arktype/util");
6
- const validate_js_1 = require("../../../semantic/validate.js");
7
- const genericArgs_js_1 = require("./genericArgs.js");
8
- const parseUnenclosed = (s) => {
1
+ import { BaseRoot, hasArkKind, writeUnresolvableMessage } from "@arktype/schema";
2
+ import { printable, throwParseError, tryParseNumber, tryParseWellFormedBigint } from "@arktype/util";
3
+ import { writePrefixedPrivateReferenceMessage } from "../../../semantic/validate.js";
4
+ import { parseGenericArgs, writeInvalidGenericArgsMessage } from "./genericArgs.js";
5
+ export const parseUnenclosed = (s) => {
9
6
  const token = s.scanner.shiftUntilNextTerminator();
10
7
  if (token === "keyof")
11
8
  s.addPrefix("keyof");
12
9
  else
13
10
  s.root = unenclosedToNode(s, token);
14
11
  };
15
- exports.parseUnenclosed = parseUnenclosed;
16
- const parseGenericInstantiation = (name, g, s) => {
12
+ export const parseGenericInstantiation = (name, g, s) => {
17
13
  s.scanner.shiftUntilNonWhitespace();
18
14
  const lookahead = s.scanner.shift();
19
15
  if (lookahead !== "<")
20
- return s.error((0, genericArgs_js_1.writeInvalidGenericArgsMessage)(name, g.params, []));
21
- const parsedArgs = (0, genericArgs_js_1.parseGenericArgs)(name, g.params, s);
16
+ return s.error(writeInvalidGenericArgsMessage(name, g.params, []));
17
+ const parsedArgs = parseGenericArgs(name, g.params, s);
22
18
  const remainingChars = parsedArgs.unscanned.length;
23
19
  // set the scanner position to where the args scanner left off
24
20
  s.scanner.jumpToIndex(remainingChars === 0 ? s.scanner.length : -remainingChars);
25
21
  return g(...parsedArgs.result);
26
22
  };
27
- exports.parseGenericInstantiation = parseGenericInstantiation;
28
23
  const unenclosedToNode = (s, token) => maybeParseReference(s, token) ??
29
24
  maybeParseUnenclosedLiteral(s, token) ??
30
- s.error(token === "" ? (0, exports.writeMissingOperandMessage)(s)
25
+ s.error(token === "" ? writeMissingOperandMessage(s)
31
26
  : token[0] === "#" ?
32
- (0, validate_js_1.writePrefixedPrivateReferenceMessage)(token)
33
- : (0, schema_1.writeUnresolvableMessage)(token));
27
+ writePrefixedPrivateReferenceMessage(token)
28
+ : writeUnresolvableMessage(token));
34
29
  const maybeParseReference = (s, token) => {
35
30
  if (s.ctx.args?.[token])
36
31
  return s.ctx.args[token].raw;
37
32
  const resolution = s.ctx.$.maybeResolve(token);
38
- if (resolution instanceof schema_1.BaseRoot)
33
+ if (resolution instanceof BaseRoot)
39
34
  return resolution;
40
35
  if (resolution === undefined)
41
36
  return;
42
- if ((0, schema_1.hasArkKind)(resolution, "generic"))
43
- return (0, exports.parseGenericInstantiation)(token, resolution, s);
44
- return (0, util_1.throwParseError)(`Unexpected resolution ${(0, util_1.printable)(resolution)}`);
37
+ if (hasArkKind(resolution, "generic"))
38
+ return parseGenericInstantiation(token, resolution, s);
39
+ return throwParseError(`Unexpected resolution ${printable(resolution)}`);
45
40
  };
46
41
  const maybeParseUnenclosedLiteral = (s, token) => {
47
- const maybeNumber = (0, util_1.tryParseNumber)(token, { strict: true });
42
+ const maybeNumber = tryParseNumber(token, { strict: true });
48
43
  if (maybeNumber !== undefined)
49
44
  return s.ctx.$.node("unit", { unit: maybeNumber });
50
- const maybeBigint = (0, util_1.tryParseWellFormedBigint)(token);
45
+ const maybeBigint = tryParseWellFormedBigint(token);
51
46
  if (maybeBigint !== undefined)
52
47
  return s.ctx.$.node("unit", { unit: maybeBigint });
53
48
  };
54
- const writeMissingOperandMessage = (s) => {
49
+ export const writeMissingOperandMessage = (s) => {
55
50
  const operator = s.previousOperator();
56
51
  return operator ?
57
- (0, exports.writeMissingRightOperandMessage)(operator, s.scanner.unscanned)
58
- : (0, exports.writeExpressionExpectedMessage)(s.scanner.unscanned);
52
+ writeMissingRightOperandMessage(operator, s.scanner.unscanned)
53
+ : writeExpressionExpectedMessage(s.scanner.unscanned);
59
54
  };
60
- exports.writeMissingOperandMessage = writeMissingOperandMessage;
61
- const writeMissingRightOperandMessage = (token, unscanned = "") => `Token '${token}' requires a right operand${unscanned ? ` before '${unscanned}'` : ""}`;
62
- exports.writeMissingRightOperandMessage = writeMissingRightOperandMessage;
63
- const writeExpressionExpectedMessage = (unscanned) => `Expected an expression${unscanned ? ` before '${unscanned}'` : ""}`;
64
- exports.writeExpressionExpectedMessage = writeExpressionExpectedMessage;
55
+ export const writeMissingRightOperandMessage = (token, unscanned = "") => `Token '${token}' requires a right operand${unscanned ? ` before '${unscanned}'` : ""}`;
56
+ export const writeExpressionExpectedMessage = (unscanned) => `Expected an expression${unscanned ? ` before '${unscanned}'` : ""}`;
@@ -1,11 +1,8 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.writeInvalidLimitMessage = exports.parseRightBound = exports.singleEqualsMessage = exports.getBoundKinds = exports.writeIncompatibleRangeMessage = exports.comparatorStartChars = exports.parseBound = void 0;
4
- const schema_1 = require("@arktype/schema");
5
- const util_1 = require("@arktype/util");
6
- const shared_js_1 = require("../../reduce/shared.js");
7
- const date_js_1 = require("../operand/date.js");
8
- const parseBound = (s, start) => {
1
+ import { internalKeywords, jsObjects, tsKeywords, writeUnboundableMessage } from "@arktype/schema";
2
+ import { isKeyOf, throwParseError } from "@arktype/util";
3
+ import { invertedComparators, maxComparators, writeUnpairableComparatorMessage } from "../../reduce/shared.js";
4
+ import { extractDateLiteralSource, isDateLiteral } from "../operand/date.js";
5
+ export const parseBound = (s, start) => {
9
6
  const comparator = shiftComparator(s, start);
10
7
  if (s.root.hasKind("unit")) {
11
8
  if (typeof s.root.unit === "number") {
@@ -20,57 +17,54 @@ const parseBound = (s, start) => {
20
17
  return;
21
18
  }
22
19
  }
23
- return (0, exports.parseRightBound)(s, comparator);
20
+ return parseRightBound(s, comparator);
24
21
  };
25
- exports.parseBound = parseBound;
26
22
  const oneCharComparators = {
27
23
  "<": true,
28
24
  ">": true
29
25
  };
30
- exports.comparatorStartChars = {
26
+ export const comparatorStartChars = {
31
27
  "<": 1,
32
28
  ">": 1,
33
29
  "=": 1
34
30
  };
35
31
  const shiftComparator = (s, start) => s.scanner.lookaheadIs("=") ? `${start}${s.scanner.shift()}`
36
- : (0, util_1.isKeyOf)(start, oneCharComparators) ? start
37
- : s.error(exports.singleEqualsMessage);
38
- const writeIncompatibleRangeMessage = (l, r) => `Bound kinds ${l} and ${r} are incompatible`;
39
- exports.writeIncompatibleRangeMessage = writeIncompatibleRangeMessage;
40
- const getBoundKinds = (comparator, limit, root, boundKind) => {
41
- if (root.extends(schema_1.tsKeywords.number)) {
32
+ : isKeyOf(start, oneCharComparators) ? start
33
+ : s.error(singleEqualsMessage);
34
+ export const writeIncompatibleRangeMessage = (l, r) => `Bound kinds ${l} and ${r} are incompatible`;
35
+ export const getBoundKinds = (comparator, limit, root, boundKind) => {
36
+ if (root.extends(tsKeywords.number)) {
42
37
  if (typeof limit !== "number") {
43
- return (0, util_1.throwParseError)((0, exports.writeInvalidLimitMessage)(comparator, limit, boundKind));
38
+ return throwParseError(writeInvalidLimitMessage(comparator, limit, boundKind));
44
39
  }
45
40
  return (comparator === "==" ? ["min", "max"]
46
41
  : comparator[0] === ">" ? ["min"]
47
42
  : ["max"]);
48
43
  }
49
- if (root.extends(schema_1.internalKeywords.lengthBoundable)) {
44
+ if (root.extends(internalKeywords.lengthBoundable)) {
50
45
  if (typeof limit !== "number") {
51
- return (0, util_1.throwParseError)((0, exports.writeInvalidLimitMessage)(comparator, limit, boundKind));
46
+ return throwParseError(writeInvalidLimitMessage(comparator, limit, boundKind));
52
47
  }
53
48
  return (comparator === "==" ? ["minLength", "maxLength"]
54
49
  : comparator[0] === ">" ? ["minLength"]
55
50
  : ["maxLength"]);
56
51
  }
57
- if (root.extends(schema_1.jsObjects.Date)) {
52
+ if (root.extends(jsObjects.Date)) {
58
53
  // allow either numeric or date limits
59
54
  return (comparator === "==" ? ["after", "before"]
60
55
  : comparator[0] === ">" ? ["after"]
61
56
  : ["before"]);
62
57
  }
63
- return (0, util_1.throwParseError)((0, schema_1.writeUnboundableMessage)(root.expression));
58
+ return throwParseError(writeUnboundableMessage(root.expression));
64
59
  };
65
- exports.getBoundKinds = getBoundKinds;
66
- exports.singleEqualsMessage = "= is not a valid comparator. Use == to check for equality";
60
+ export const singleEqualsMessage = "= is not a valid comparator. Use == to check for equality";
67
61
  const openLeftBoundToRoot = (leftBound) => ({
68
- rule: (0, date_js_1.isDateLiteral)(leftBound.limit) ?
69
- (0, date_js_1.extractDateLiteralSource)(leftBound.limit)
62
+ rule: isDateLiteral(leftBound.limit) ?
63
+ extractDateLiteralSource(leftBound.limit)
70
64
  : leftBound.limit,
71
65
  exclusive: leftBound.comparator.length === 1
72
66
  });
73
- const parseRightBound = (s, comparator) => {
67
+ export const parseRightBound = (s, comparator) => {
74
68
  // store the node that will be bounded
75
69
  const previousRoot = s.unsetRoot();
76
70
  const previousScannerIndex = s.scanner.location;
@@ -82,22 +76,20 @@ const parseRightBound = (s, comparator) => {
82
76
  s.root = previousRoot;
83
77
  if (!limitNode.hasKind("unit") ||
84
78
  (typeof limitNode.unit !== "number" && !(limitNode.unit instanceof Date)))
85
- return s.error((0, exports.writeInvalidLimitMessage)(comparator, limitToken, "right"));
79
+ return s.error(writeInvalidLimitMessage(comparator, limitToken, "right"));
86
80
  const limit = limitNode.unit;
87
81
  // apply the newly-parsed right bound
88
82
  const exclusive = comparator.length === 1;
89
83
  // if the comparator is ==, both the min and max of that pair will be applied
90
- for (const kind of (0, exports.getBoundKinds)(comparator, typeof limit === "number" ? limit : limitToken, previousRoot, "right"))
84
+ for (const kind of getBoundKinds(comparator, typeof limit === "number" ? limit : limitToken, previousRoot, "right"))
91
85
  s.constrainRoot(kind, { rule: limit, exclusive });
92
86
  if (!s.branches.leftBound)
93
87
  return;
94
88
  // if there's an open left bound, perform additional validation and apply it
95
- if (!(0, util_1.isKeyOf)(comparator, shared_js_1.maxComparators))
96
- return s.error((0, shared_js_1.writeUnpairableComparatorMessage)(comparator));
97
- const lowerBoundKind = (0, exports.getBoundKinds)(s.branches.leftBound.comparator, s.branches.leftBound.limit, previousRoot, "left");
89
+ if (!isKeyOf(comparator, maxComparators))
90
+ return s.error(writeUnpairableComparatorMessage(comparator));
91
+ const lowerBoundKind = getBoundKinds(s.branches.leftBound.comparator, s.branches.leftBound.limit, previousRoot, "left");
98
92
  s.constrainRoot(lowerBoundKind[0], openLeftBoundToRoot(s.branches.leftBound));
99
93
  s.branches.leftBound = null;
100
94
  };
101
- exports.parseRightBound = parseRightBound;
102
- const writeInvalidLimitMessage = (comparator, limit, boundKind) => `Comparator ${boundKind === "left" ? shared_js_1.invertedComparators[comparator] : comparator} must be ${boundKind === "left" ? "preceded" : "followed"} by a corresponding literal (was ${limit})`;
103
- exports.writeInvalidLimitMessage = writeInvalidLimitMessage;
95
+ export const writeInvalidLimitMessage = (comparator, limit, boundKind) => `Comparator ${boundKind === "left" ? invertedComparators[comparator] : comparator} must be ${boundKind === "left" ? "preceded" : "followed"} by a corresponding literal (was ${limit})`;
@@ -1,16 +1,11 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.writeInvalidDivisorMessage = exports.parseDivisor = void 0;
4
- const util_1 = require("@arktype/util");
5
- const parseDivisor = (s) => {
1
+ import { tryParseInteger } from "@arktype/util";
2
+ export const parseDivisor = (s) => {
6
3
  const divisorToken = s.scanner.shiftUntilNextTerminator();
7
- const divisor = (0, util_1.tryParseInteger)(divisorToken, {
8
- errorOnFail: (0, exports.writeInvalidDivisorMessage)(divisorToken)
4
+ const divisor = tryParseInteger(divisorToken, {
5
+ errorOnFail: writeInvalidDivisorMessage(divisorToken)
9
6
  });
10
7
  if (divisor === 0)
11
- s.error((0, exports.writeInvalidDivisorMessage)(0));
8
+ s.error(writeInvalidDivisorMessage(0));
12
9
  s.root = s.root.constrain("divisor", divisor);
13
10
  };
14
- exports.parseDivisor = parseDivisor;
15
- const writeInvalidDivisorMessage = (divisor) => `% operator must be followed by a non-zero integer literal (was ${divisor})`;
16
- exports.writeInvalidDivisorMessage = writeInvalidDivisorMessage;
11
+ export const writeInvalidDivisorMessage = (divisor) => `% operator must be followed by a non-zero integer literal (was ${divisor})`;
@@ -1,27 +1,22 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.incompleteArrayTokenMessage = exports.writeUnexpectedCharacterMessage = exports.parseOperator = void 0;
4
- const util_1 = require("@arktype/util");
5
- const scanner_js_1 = require("../scanner.js");
6
- const bounds_js_1 = require("./bounds.js");
7
- const divisor_js_1 = require("./divisor.js");
8
- const parseOperator = (s) => {
1
+ import { isKeyOf } from "@arktype/util";
2
+ import { Scanner } from "../scanner.js";
3
+ import { comparatorStartChars, parseBound } from "./bounds.js";
4
+ import { parseDivisor } from "./divisor.js";
5
+ export const parseOperator = (s) => {
9
6
  const lookahead = s.scanner.shift();
10
7
  return (lookahead === "" ? s.finalize("")
11
8
  : lookahead === "[" ?
12
9
  s.scanner.shift() === "]" ?
13
10
  s.setRoot(s.root.array())
14
- : s.error(exports.incompleteArrayTokenMessage)
11
+ : s.error(incompleteArrayTokenMessage)
15
12
  : lookahead === "|" || lookahead === "&" ? s.pushRootToBranch(lookahead)
16
13
  : lookahead === ")" ? s.finalizeGroup()
17
- : scanner_js_1.Scanner.lookaheadIsFinalizing(lookahead, s.scanner.unscanned) ?
14
+ : Scanner.lookaheadIsFinalizing(lookahead, s.scanner.unscanned) ?
18
15
  s.finalize(lookahead)
19
- : (0, util_1.isKeyOf)(lookahead, bounds_js_1.comparatorStartChars) ? (0, bounds_js_1.parseBound)(s, lookahead)
20
- : lookahead === "%" ? (0, divisor_js_1.parseDivisor)(s)
21
- : lookahead === " " ? (0, exports.parseOperator)(s)
22
- : s.error((0, exports.writeUnexpectedCharacterMessage)(lookahead)));
16
+ : isKeyOf(lookahead, comparatorStartChars) ? parseBound(s, lookahead)
17
+ : lookahead === "%" ? parseDivisor(s)
18
+ : lookahead === " " ? parseOperator(s)
19
+ : s.error(writeUnexpectedCharacterMessage(lookahead)));
23
20
  };
24
- exports.parseOperator = parseOperator;
25
- const writeUnexpectedCharacterMessage = (char, shouldBe = "") => `'${char}' is not allowed here${shouldBe && ` (should be ${shouldBe})`}`;
26
- exports.writeUnexpectedCharacterMessage = writeUnexpectedCharacterMessage;
27
- exports.incompleteArrayTokenMessage = `Missing expected ']'`;
21
+ export const writeUnexpectedCharacterMessage = (char, shouldBe = "") => `'${char}' is not allowed here${shouldBe && ` (should be ${shouldBe})`}`;
22
+ export const incompleteArrayTokenMessage = `Missing expected ']'`;