arktype 2.0.0-beta.4 → 2.0.0-beta.6

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 (95) hide show
  1. package/out/ast.d.ts +7 -10
  2. package/out/ast.js +0 -1
  3. package/out/config.d.ts +17 -2
  4. package/out/generic.d.ts +9 -16
  5. package/out/generic.js +1 -2
  6. package/out/index.d.ts +6 -7
  7. package/out/index.js +1 -1
  8. package/out/intersect.d.ts +1 -1
  9. package/out/keys.d.ts +2 -2
  10. package/out/keywords/ark.d.ts +40 -0
  11. package/out/keywords/ark.js +28 -0
  12. package/out/keywords/builtin.d.ts +26 -0
  13. package/out/keywords/builtin.js +21 -0
  14. package/out/keywords/format.d.ts +13 -10
  15. package/out/keywords/format.js +4 -1
  16. package/out/keywords/js.d.ts +18 -0
  17. package/out/keywords/{jsObjects.js → js.js} +4 -1
  18. package/out/keywords/number.d.ts +23 -0
  19. package/out/keywords/number.js +44 -0
  20. package/out/keywords/parse.d.ts +19 -0
  21. package/out/keywords/{parsing.js → parse.js} +9 -4
  22. package/out/keywords/platform.d.ts +16 -0
  23. package/out/keywords/{platformObjects.js → platform.js} +4 -1
  24. package/out/keywords/string.d.ts +31 -0
  25. package/out/keywords/string.js +89 -0
  26. package/out/keywords/ts.d.ts +58 -0
  27. package/out/keywords/ts.js +55 -0
  28. package/out/keywords/typedArray.d.ts +18 -15
  29. package/out/keywords/typedArray.js +4 -1
  30. package/out/keywords/utils/date.d.ts +1 -0
  31. package/out/keywords/utils/date.js +1 -1
  32. package/out/keywords/utils/ip.d.ts +16 -3
  33. package/out/keywords/utils/ip.js +10 -4
  34. package/out/keywords/utils/regex.d.ts +3 -2
  35. package/out/keywords/utils/uuid.d.ts +30 -0
  36. package/out/keywords/utils/uuid.js +22 -0
  37. package/out/module.d.ts +2 -2
  38. package/out/parser/definition.d.ts +9 -9
  39. package/out/parser/objectLiteral.d.ts +8 -6
  40. package/out/parser/semantic/bounds.d.ts +6 -6
  41. package/out/parser/semantic/default.d.ts +4 -4
  42. package/out/parser/semantic/divisor.d.ts +2 -2
  43. package/out/parser/semantic/infer.d.ts +8 -8
  44. package/out/parser/semantic/keyof.d.ts +2 -2
  45. package/out/parser/semantic/utils.d.ts +2 -2
  46. package/out/parser/semantic/validate.d.ts +12 -12
  47. package/out/parser/string/reduce/dynamic.d.ts +8 -8
  48. package/out/parser/string/reduce/dynamic.js +3 -3
  49. package/out/parser/string/reduce/shared.d.ts +1 -1
  50. package/out/parser/string/reduce/static.d.ts +19 -20
  51. package/out/parser/string/shift/operand/date.d.ts +1 -3
  52. package/out/parser/string/shift/operand/enclosed.d.ts +3 -3
  53. package/out/parser/string/shift/operand/genericArgs.d.ts +4 -4
  54. package/out/parser/string/shift/operand/operand.d.ts +6 -6
  55. package/out/parser/string/shift/operand/unenclosed.d.ts +12 -10
  56. package/out/parser/string/shift/operand/unenclosed.js +2 -2
  57. package/out/parser/string/shift/operator/bounds.d.ts +8 -12
  58. package/out/parser/string/shift/operator/bounds.js +0 -4
  59. package/out/parser/string/shift/operator/default.d.ts +4 -10
  60. package/out/parser/string/shift/operator/default.js +0 -6
  61. package/out/parser/string/shift/operator/divisor.d.ts +3 -3
  62. package/out/parser/string/shift/operator/operator.d.ts +5 -5
  63. package/out/parser/string/shift/scanner.d.ts +16 -16
  64. package/out/parser/string/shift/scanner.js +6 -8
  65. package/out/parser/string/string.d.ts +9 -9
  66. package/out/parser/tuple.d.ts +7 -7
  67. package/out/parser/tuple.js +2 -1
  68. package/out/scope.d.ts +24 -19
  69. package/out/scope.js +65 -111
  70. package/out/subtypes/array.d.ts +2 -2
  71. package/out/subtypes/base.d.ts +9 -8
  72. package/out/subtypes/date.d.ts +2 -2
  73. package/out/subtypes/instantiate.d.ts +8 -8
  74. package/out/subtypes/morph.d.ts +4 -4
  75. package/out/subtypes/number.d.ts +2 -2
  76. package/out/subtypes/object.d.ts +12 -6
  77. package/out/subtypes/string.d.ts +2 -2
  78. package/out/subtypes/validator.d.ts +3 -3
  79. package/out/type.d.ts +7 -7
  80. package/package.json +17 -8
  81. package/out/ark.d.ts +0 -33
  82. package/out/ark.js +0 -28
  83. package/out/keywords/arkGenerics.d.ts +0 -19
  84. package/out/keywords/arkGenerics.js +0 -19
  85. package/out/keywords/internal.d.ts +0 -11
  86. package/out/keywords/internal.js +0 -25
  87. package/out/keywords/jsObjects.d.ts +0 -15
  88. package/out/keywords/parsing.d.ts +0 -16
  89. package/out/keywords/platformObjects.d.ts +0 -13
  90. package/out/keywords/tsGenerics.d.ts +0 -37
  91. package/out/keywords/tsGenerics.js +0 -45
  92. package/out/keywords/tsKeywords.d.ts +0 -18
  93. package/out/keywords/tsKeywords.js +0 -17
  94. package/out/keywords/validation.d.ts +0 -19
  95. package/out/keywords/validation.js +0 -84
@@ -1,7 +1,7 @@
1
1
  import type { Completion, ErrorMessage, defined } from "@ark/util";
2
- import type { LimitLiteral } from "../../../ast.js";
3
- import type { Scanner } from "../shift/scanner.js";
4
- import type { Comparator, InvertedComparators, MaxComparator, MinComparator, OpenLeftBound, StringifiablePrefixOperator, writeMultipleLeftBoundsMessage, writeOpenRangeMessage, writeUnclosedGroupMessage, writeUnmatchedGroupCloseMessage, writeUnpairableComparatorMessage } from "./shared.js";
2
+ import type { LimitLiteral } from "../../../ast.ts";
3
+ import type { Scanner } from "../shift/scanner.ts";
4
+ import type { Comparator, InvertedComparators, MaxComparator, MinComparator, OpenLeftBound, StringifiablePrefixOperator, writeMultipleLeftBoundsMessage, writeOpenRangeMessage, writeUnclosedGroupMessage, writeUnmatchedGroupCloseMessage, writeUnpairableComparatorMessage } from "./shared.ts";
5
5
  export type StaticState = {
6
6
  root: unknown;
7
7
  branches: BranchState;
@@ -18,7 +18,7 @@ type BranchState = {
18
18
  };
19
19
  export type AutocompletePrefix = `${StringifiablePrefixOperator} `;
20
20
  export declare namespace state {
21
- export type initialize<def extends string> = from<{
21
+ type initialize<def extends string> = from<{
22
22
  root: undefined;
23
23
  branches: initialBranches;
24
24
  groups: [];
@@ -26,7 +26,7 @@ export declare namespace state {
26
26
  scanned: "";
27
27
  unscanned: def;
28
28
  }>;
29
- export type error<message extends string> = from<{
29
+ type error<message extends string> = from<{
30
30
  root: ErrorMessage<message>;
31
31
  branches: initialBranches;
32
32
  groups: [];
@@ -34,7 +34,7 @@ export declare namespace state {
34
34
  scanned: "";
35
35
  unscanned: "";
36
36
  }>;
37
- export type completion<text extends string> = from<{
37
+ type completion<text extends string> = from<{
38
38
  root: Completion<text>;
39
39
  branches: initialBranches;
40
40
  groups: [];
@@ -49,7 +49,7 @@ export declare namespace state {
49
49
  union: undefined;
50
50
  }>;
51
51
  type updateScanned<previousScanned extends string, previousUnscanned extends string, updatedUnscanned extends string> = previousUnscanned extends `${infer justScanned}${updatedUnscanned}` ? `${previousScanned}${justScanned}` : previousScanned;
52
- export type setRoot<s extends StaticState, root, unscanned extends string> = from<{
52
+ type setRoot<s extends StaticState, root, unscanned extends string> = from<{
53
53
  root: root;
54
54
  branches: s["branches"];
55
55
  groups: s["groups"];
@@ -57,7 +57,7 @@ export declare namespace state {
57
57
  scanned: updateScanned<s["scanned"], s["unscanned"], unscanned>;
58
58
  unscanned: unscanned;
59
59
  }>;
60
- export type addPrefix<s extends StaticState, prefix extends StringifiablePrefixOperator, unscanned extends string> = from<{
60
+ type addPrefix<s extends StaticState, prefix extends StringifiablePrefixOperator, unscanned extends string> = from<{
61
61
  root: s["root"];
62
62
  branches: {
63
63
  prefixes: [...s["branches"]["prefixes"], prefix];
@@ -70,7 +70,7 @@ export declare namespace state {
70
70
  scanned: updateScanned<s["scanned"], s["unscanned"], unscanned>;
71
71
  unscanned: unscanned;
72
72
  }>;
73
- export type reduceBranch<s extends StaticState, token extends "|" | "&", unscanned extends string> = s["branches"]["leftBound"] extends {} ? openRangeError<s["branches"]["leftBound"]> : from<{
73
+ type reduceBranch<s extends StaticState, token extends "|" | "&", unscanned extends string> = s["branches"]["leftBound"] extends {} ? openRangeError<s["branches"]["leftBound"]> : from<{
74
74
  root: undefined;
75
75
  branches: {
76
76
  prefixes: [];
@@ -83,7 +83,7 @@ export declare namespace state {
83
83
  scanned: updateScanned<s["scanned"], s["unscanned"], unscanned>;
84
84
  unscanned: unscanned;
85
85
  }>;
86
- export type reduceLeftBound<s extends StaticState, limit extends LimitLiteral, comparator extends Comparator, unscanned extends string> = comparator extends "<" | "<=" ? s["branches"]["leftBound"] extends {} ? state.error<writeMultipleLeftBoundsMessage<s["branches"]["leftBound"]["limit"], s["branches"]["leftBound"]["comparator"], limit, InvertedComparators[comparator]>> : from<{
86
+ type reduceLeftBound<s extends StaticState, limit extends LimitLiteral, comparator extends Comparator, unscanned extends string> = comparator extends "<" | "<=" ? s["branches"]["leftBound"] extends {} ? state.error<writeMultipleLeftBoundsMessage<s["branches"]["leftBound"]["limit"], s["branches"]["leftBound"]["comparator"], limit, InvertedComparators[comparator]>> : from<{
87
87
  root: undefined;
88
88
  branches: {
89
89
  prefixes: s["branches"]["prefixes"];
@@ -99,7 +99,7 @@ export declare namespace state {
99
99
  scanned: updateScanned<s["scanned"], s["unscanned"], unscanned>;
100
100
  unscanned: unscanned;
101
101
  }> : state.error<writeUnpairableComparatorMessage<comparator>>;
102
- export type reduceRange<s extends StaticState, minLimit extends LimitLiteral, minComparator extends MinComparator, maxComparator extends MaxComparator, maxLimit extends LimitLiteral, unscanned extends string> = state.from<{
102
+ type reduceRange<s extends StaticState, minLimit extends LimitLiteral, minComparator extends MinComparator, maxComparator extends MaxComparator, maxLimit extends LimitLiteral, unscanned extends string> = state.from<{
103
103
  root: [minLimit, minComparator, [s["root"], maxComparator, maxLimit]];
104
104
  branches: {
105
105
  prefixes: s["branches"]["prefixes"];
@@ -112,7 +112,7 @@ export declare namespace state {
112
112
  scanned: updateScanned<s["scanned"], s["unscanned"], unscanned>;
113
113
  unscanned: unscanned;
114
114
  }>;
115
- export type reduceSingleBound<s extends StaticState, comparator extends Comparator, limit extends number | string, unscanned extends string> = state.from<{
115
+ type reduceSingleBound<s extends StaticState, comparator extends Comparator, limit extends number | string, unscanned extends string> = state.from<{
116
116
  root: [s["root"], comparator, limit];
117
117
  branches: {
118
118
  prefixes: s["branches"]["prefixes"];
@@ -135,7 +135,7 @@ export declare namespace state {
135
135
  ...stack,
136
136
  top
137
137
  ];
138
- export type finalizeGroup<s extends StaticState, unscanned extends string> = s["branches"]["leftBound"] extends {} ? openRangeError<s["branches"]["leftBound"]> : s["groups"] extends popGroup<infer stack, infer top> ? from<{
138
+ type finalizeGroup<s extends StaticState, unscanned extends string> = s["branches"]["leftBound"] extends {} ? openRangeError<s["branches"]["leftBound"]> : s["groups"] extends popGroup<infer stack, infer top> ? from<{
139
139
  groups: stack;
140
140
  branches: top;
141
141
  root: mergeToUnion<s>;
@@ -143,7 +143,7 @@ export declare namespace state {
143
143
  scanned: updateScanned<s["scanned"], s["unscanned"], unscanned>;
144
144
  unscanned: unscanned;
145
145
  }> : state.error<writeUnmatchedGroupCloseMessage<unscanned>>;
146
- export type reduceGroupOpen<s extends StaticState, unscanned extends string> = from<{
146
+ type reduceGroupOpen<s extends StaticState, unscanned extends string> = from<{
147
147
  groups: [...s["groups"], s["branches"]];
148
148
  branches: initialBranches;
149
149
  root: undefined;
@@ -151,7 +151,7 @@ export declare namespace state {
151
151
  scanned: updateScanned<s["scanned"], s["unscanned"], unscanned>;
152
152
  unscanned: unscanned;
153
153
  }>;
154
- export type finalize<s extends StaticState, finalizer extends Scanner.FinalizingLookahead> = s["groups"] extends [] ? s["branches"]["leftBound"] extends {} ? openRangeError<s["branches"]["leftBound"]> : from<{
154
+ type finalize<s extends StaticState, finalizer extends Scanner.FinalizingLookahead> = s["groups"] extends [] ? s["branches"]["leftBound"] extends {} ? openRangeError<s["branches"]["leftBound"]> : from<{
155
155
  root: mergeToUnion<s>;
156
156
  groups: s["groups"];
157
157
  branches: initialBranches;
@@ -160,11 +160,11 @@ export declare namespace state {
160
160
  unscanned: s["unscanned"];
161
161
  }> : state.error<writeUnclosedGroupMessage<")">>;
162
162
  type openRangeError<range extends defined<BranchState["leftBound"]>> = state.error<writeOpenRangeMessage<range["limit"], range["comparator"]>>;
163
- export type previousOperator<s extends StaticState> = s["branches"]["leftBound"] extends {} ? s["branches"]["leftBound"]["comparator"] : s["branches"]["prefixes"] extends ([
163
+ type previousOperator<s extends StaticState> = s["branches"]["leftBound"] extends {} ? s["branches"]["leftBound"]["comparator"] : s["branches"]["prefixes"] extends ([
164
164
  ...unknown[],
165
165
  infer tail extends string
166
166
  ]) ? tail : s["branches"]["intersection"] extends {} ? "&" : s["branches"]["union"] extends {} ? "|" : undefined;
167
- export type scanTo<s extends StaticState, unscanned extends string> = from<{
167
+ type scanTo<s extends StaticState, unscanned extends string> = from<{
168
168
  root: s["root"];
169
169
  branches: s["branches"];
170
170
  groups: s["groups"];
@@ -172,8 +172,7 @@ export declare namespace state {
172
172
  scanned: updateScanned<s["scanned"], s["unscanned"], unscanned>;
173
173
  unscanned: unscanned;
174
174
  }>;
175
- export type from<s extends StaticState> = s;
176
- export type branchesFrom<b extends BranchState> = b;
177
- export {};
175
+ type from<s extends StaticState> = s;
176
+ type branchesFrom<b extends BranchState> = b;
178
177
  }
179
178
  export {};
@@ -1,11 +1,9 @@
1
- import type { DateLiteral } from "../../../../ast.js";
1
+ import type { DateLiteral } from "../../../../ast.ts";
2
2
  export declare const isDateLiteral: (value: unknown) => value is DateLiteral;
3
3
  export declare const isValidDate: (d: Date) => boolean;
4
4
  export declare const extractDateLiteralSource: <literal extends DateLiteral>(literal: literal) => extractDateLiteralSource<literal>;
5
- type extractDateLiteralSource<literal extends DateLiteral> = literal extends DateLiteral<infer source> ? source : never;
6
5
  export declare const writeInvalidDateMessage: <source extends string>(source: source) => writeInvalidDateMessage<source>;
7
6
  export type writeInvalidDateMessage<source extends string> = `'${source}' could not be parsed by the Date constructor`;
8
7
  export type DateInput = ConstructorParameters<typeof Date>[0];
9
8
  export type DateParseResult<errorOnFail extends boolean | string = boolean | string> = Date | (errorOnFail extends true | string ? never : undefined);
10
9
  export declare const tryParseDate: <errorOnFail extends boolean | string>(source: string, errorOnFail?: errorOnFail) => DateParseResult<errorOnFail>;
11
- export {};
@@ -1,6 +1,6 @@
1
- import type { DynamicState } from "../../reduce/dynamic.js";
2
- import type { StaticState, state } from "../../reduce/static.js";
3
- import type { Scanner } from "../scanner.js";
1
+ import type { DynamicState } from "../../reduce/dynamic.ts";
2
+ import type { StaticState, state } from "../../reduce/static.ts";
3
+ import type { Scanner } from "../scanner.ts";
4
4
  export type StringLiteral<Text extends string = string> = DoubleQuotedStringLiteral<Text> | SingleQuotedStringLiteral<Text>;
5
5
  export type DoubleQuotedStringLiteral<Text extends string = string> = `"${Text}"`;
6
6
  export type SingleQuotedStringLiteral<Text extends string = string> = `'${Text}'`;
@@ -1,9 +1,9 @@
1
1
  import type { BaseRoot, GenericAst, genericParamNames, GenericRoot } from "@ark/schema";
2
2
  import type { array, ErrorMessage, join } from "@ark/util";
3
- import type { DynamicState } from "../../reduce/dynamic.js";
4
- import { writeUnclosedGroupMessage } from "../../reduce/shared.js";
5
- import type { state, StaticState } from "../../reduce/static.js";
6
- import type { parseUntilFinalizer } from "../../string.js";
3
+ import type { DynamicState } from "../../reduce/dynamic.ts";
4
+ import { writeUnclosedGroupMessage } from "../../reduce/shared.ts";
5
+ import type { state, StaticState } from "../../reduce/static.ts";
6
+ import type { parseUntilFinalizer } from "../../string.ts";
7
7
  export declare const parseGenericArgs: (name: string, g: GenericRoot, s: DynamicState) => BaseRoot[];
8
8
  export type parseGenericArgs<name extends string, g extends GenericAst, unscanned extends string, $, args> = _parseGenericArgs<name, g, unscanned, $, args, [], []>;
9
9
  declare const _parseGenericArgs: (name: string, g: GenericRoot, s: DynamicState, argNodes: BaseRoot[]) => BaseRoot[];
@@ -1,9 +1,9 @@
1
1
  import { type WhiteSpaceToken } from "@ark/util";
2
- import type { DynamicState } from "../../reduce/dynamic.js";
3
- import type { StaticState, state } from "../../reduce/static.js";
4
- import type { BaseCompletions } from "../../string.js";
5
- import type { Scanner } from "../scanner.js";
6
- import { parseEnclosed, type EnclosingQuote, type EnclosingStartToken } from "./enclosed.js";
7
- import { parseUnenclosed } from "./unenclosed.js";
2
+ import type { DynamicState } from "../../reduce/dynamic.ts";
3
+ import type { StaticState, state } from "../../reduce/static.ts";
4
+ import type { BaseCompletions } from "../../string.ts";
5
+ import type { Scanner } from "../scanner.ts";
6
+ import { parseEnclosed, type EnclosingQuote, type EnclosingStartToken } from "./enclosed.ts";
7
+ import { parseUnenclosed } from "./unenclosed.ts";
8
8
  export declare const parseOperand: (s: DynamicState) => void;
9
9
  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 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,21 +1,23 @@
1
- import { BaseRoot, writeUnresolvableMessage, type GenericAst, type GenericRoot, type arkKind, type genericParamNames, type resolvableReferenceIn, type resolveReference, type writeNonSubmoduleDotMessage } from "@ark/schema";
1
+ import { writeUnresolvableMessage, type BaseRoot, type GenericAst, type GenericRoot, type arkKind, type genericParamNames, type resolvableReferenceIn, type resolveReference, type writeNonSubmoduleDotMessage } from "@ark/schema";
2
2
  import { type BigintLiteral, type Completion, type ErrorMessage, type anyOrNever, type join } from "@ark/util";
3
- import type { Ark } from "../../../../ark.js";
4
- import type { GenericInstantiationAst } from "../../../semantic/infer.js";
5
- import type { DynamicState } from "../../reduce/dynamic.js";
6
- import type { StaticState, state } from "../../reduce/static.js";
7
- import type { BaseCompletions } from "../../string.js";
8
- import type { Scanner } from "../scanner.js";
9
- import { parseGenericArgs, writeInvalidGenericArgCountMessage, type ParsedArgs } from "./genericArgs.js";
3
+ import type { ArkAmbient } from "arktype/config";
4
+ import type { GenericInstantiationAst } from "../../../semantic/infer.ts";
5
+ import type { DynamicState } from "../../reduce/dynamic.ts";
6
+ import type { StaticState, state } from "../../reduce/static.ts";
7
+ import type { BaseCompletions } from "../../string.ts";
8
+ import type { Scanner } from "../scanner.ts";
9
+ import { parseGenericArgs, writeInvalidGenericArgCountMessage, type ParsedArgs } from "./genericArgs.ts";
10
10
  export declare const parseUnenclosed: (s: DynamicState) => void;
11
- export type parseUnenclosed<s extends StaticState, $, args> = Scanner.shiftUntilNextTerminator<s["unscanned"]> extends (Scanner.shiftResult<infer token, infer unscanned>) ? token extends "keyof" ? state.addPrefix<s, "keyof", unscanned> : tryResolve<s, token, $, args> extends infer result ? result extends ErrorMessage<infer message> ? state.error<message> : result extends resolvableReferenceIn<$> ? parseResolution<s, unscanned, result, resolveReference<result, $>, $, args> : result extends resolvableReferenceIn<Ark> ? parseResolution<s, unscanned, result, resolveReference<result, Ark>, $, args> : state.setRoot<s, result, unscanned> : never : never;
11
+ export type parseUnenclosed<s extends StaticState, $, args> = Scanner.shiftUntilNextTerminator<s["unscanned"]> extends (Scanner.shiftResult<infer token, infer unscanned>) ? token extends "keyof" ? state.addPrefix<s, "keyof", unscanned> : tryResolve<s, token, $, args> extends infer result ? result extends ErrorMessage<infer message> ? state.error<message> : result extends resolvableReferenceIn<$> ? parseResolution<s, unscanned, result, resolveReference<result, $>, $, args> : result extends resolvableReferenceIn<ArkAmbient.$> ? parseResolution<s, unscanned, result, resolveReference<result, ArkAmbient.$>, $, args> : state.setRoot<s, result, unscanned> : never : never;
12
12
  type parseResolution<s extends StaticState, unscanned extends string, alias extends string, resolution, $, args> = [
13
13
  resolution
14
14
  ] extends [anyOrNever] ? state.setRoot<s, alias, unscanned> : resolution extends GenericAst ? parseGenericInstantiation<alias, resolution, state.scanTo<s, unscanned>, $, args> : state.setRoot<s, alias, unscanned>;
15
15
  export declare const parseGenericInstantiation: (name: string, g: GenericRoot, s: DynamicState) => BaseRoot;
16
16
  export type parseGenericInstantiation<name extends string, g extends GenericAst, s extends StaticState, $, args> = Scanner.skipWhitespace<s["unscanned"]> extends `<${infer unscanned}` ? parseGenericArgs<name, g, unscanned, $, args> extends infer result ? result extends ParsedArgs<infer argAsts, infer nextUnscanned> ? state.setRoot<s, GenericInstantiationAst<g, argAsts>, nextUnscanned> : result : never : state.error<writeInvalidGenericArgCountMessage<name, genericParamNames<g["paramsAst"]>, [
17
17
  ]>>;
18
- type tryResolve<s extends StaticState, token extends string, $, args> = token extends keyof Ark ? token : token extends keyof $ ? token : `#${token}` extends keyof $ ? token : token extends keyof args ? token : token extends `${number}` ? token : token extends BigintLiteral ? token : token extends (`${infer submodule extends (keyof $ | keyof Ark) & string}.${infer reference}`) ? tryResolveSubmodule<token, submodule, reference, s, $ & Ark, [submodule]> : unresolvableError<s, token, $, args, []>;
18
+ type tryResolve<s extends StaticState, token extends string, $, args> = token extends keyof ArkAmbient.$ ? token : token extends keyof $ ? token : `#${token}` extends keyof $ ? token : token extends keyof args ? token : token extends `${number}` ? token : token extends BigintLiteral ? token : token extends (`${infer submodule extends (keyof $ | keyof ArkAmbient.$) & string}.${infer reference}`) ? tryResolveSubmodule<token, submodule, reference, s, $ & ArkAmbient.$, [
19
+ submodule
20
+ ]> : unresolvableError<s, token, $, args, []>;
19
21
  type tryResolveSubmodule<token, submodule extends keyof $ & string, reference extends string, s extends StaticState, $, submodulePath extends string[]> = $[submodule] extends {
20
22
  [arkKind]: "module";
21
23
  } ? reference extends keyof $[submodule] ? token : reference extends (`${infer nestedSubmodule extends keyof $[submodule] & string}.${infer nestedReference}`) ? tryResolveSubmodule<token, nestedSubmodule, nestedReference, s, $[submodule], [
@@ -1,4 +1,4 @@
1
- import { BaseRoot, hasArkKind, writeUnresolvableMessage } from "@ark/schema";
1
+ import { hasArkKind, writeUnresolvableMessage } from "@ark/schema";
2
2
  import { printable, throwParseError, tryParseWellFormedBigint, tryParseWellFormedNumber } from "@ark/util";
3
3
  import { writePrefixedPrivateReferenceMessage } from "../../../semantic/validate.js";
4
4
  import { parseGenericArgs, writeInvalidGenericArgCountMessage } from "./genericArgs.js";
@@ -27,7 +27,7 @@ const maybeParseReference = (s, token) => {
27
27
  if (s.ctx.args?.[token])
28
28
  return s.ctx.args[token].internal;
29
29
  const resolution = s.ctx.$.maybeResolve(token);
30
- if (resolution instanceof BaseRoot)
30
+ if (hasArkKind(resolution, "root"))
31
31
  return resolution;
32
32
  if (resolution === undefined)
33
33
  return;
@@ -1,19 +1,15 @@
1
1
  import { type BaseRoot, type BoundKind } from "@ark/schema";
2
2
  import { type keySet } from "@ark/util";
3
- import type { LimitLiteral } from "../../../../ast.js";
4
- import type { astToString } from "../../../semantic/utils.js";
5
- import type { DynamicState, DynamicStateWithRoot } from "../../reduce/dynamic.js";
6
- import { writeUnpairableComparatorMessage, type Comparator, type InvertedComparators, type MaxComparator } from "../../reduce/shared.js";
7
- import type { StaticState, state } from "../../reduce/static.js";
8
- import type { parseOperand } from "../operand/operand.js";
9
- import type { Scanner } from "../scanner.js";
3
+ import type { LimitLiteral } from "../../../../ast.ts";
4
+ import type { astToString } from "../../../semantic/utils.ts";
5
+ import type { DynamicState, DynamicStateWithRoot } from "../../reduce/dynamic.ts";
6
+ import { writeUnpairableComparatorMessage, type Comparator, type InvertedComparators, type MaxComparator } from "../../reduce/shared.ts";
7
+ import type { StaticState, state } from "../../reduce/static.ts";
8
+ import type { parseOperand } from "../operand/operand.ts";
9
+ import type { Scanner } from "../scanner.ts";
10
10
  export declare const parseBound: (s: DynamicStateWithRoot, start: ComparatorStartChar) => void;
11
11
  export type parseBound<s extends StaticState, start extends ComparatorStartChar, unscanned extends string, $, args> = shiftComparator<start, unscanned> extends infer shiftResultOrError ? shiftResultOrError extends (Scanner.shiftResult<infer comparator extends Comparator, infer nextUnscanned>) ? s["root"] extends `${infer limit extends LimitLiteral}` ? state.reduceLeftBound<s, limit, comparator, nextUnscanned> : parseRightBound<state.scanTo<s, nextUnscanned>, comparator, $, args> : shiftResultOrError : never;
12
- declare const oneCharComparators: {
13
- readonly "<": true;
14
- readonly ">": true;
15
- };
16
- type OneCharComparator = keyof typeof oneCharComparators;
12
+ type OneCharComparator = ">" | "<";
17
13
  export type ComparatorStartChar = Comparator extends `${infer char}${string}` ? char : never;
18
14
  export declare const comparatorStartChars: keySet<ComparatorStartChar>;
19
15
  declare const shiftComparator: (s: DynamicState, start: ComparatorStartChar) => Comparator;
@@ -19,10 +19,6 @@ export const parseBound = (s, start) => {
19
19
  }
20
20
  return parseRightBound(s, comparator);
21
21
  };
22
- const oneCharComparators = {
23
- "<": true,
24
- ">": true
25
- };
26
22
  export const comparatorStartChars = {
27
23
  "<": 1,
28
24
  ">": 1,
@@ -1,15 +1,9 @@
1
1
  import type { BaseRoot } from "@ark/schema";
2
2
  import { type BigintLiteral, type ErrorMessage, type NumberLiteral, type trim } from "@ark/util";
3
- import type { DateLiteral } from "../../../../ast.js";
4
- import type { DynamicStateWithRoot } from "../../reduce/dynamic.js";
5
- import type { StringLiteral } from "../operand/enclosed.js";
6
- declare const unitLiteralKeywords: {
7
- readonly null: null;
8
- readonly undefined: undefined;
9
- readonly true: true;
10
- readonly false: false;
11
- };
12
- type UnitLiteralKeyword = keyof typeof unitLiteralKeywords;
3
+ import type { DateLiteral } from "../../../../ast.ts";
4
+ import type { DynamicStateWithRoot } from "../../reduce/dynamic.ts";
5
+ import type { StringLiteral } from "../operand/enclosed.ts";
6
+ type UnitLiteralKeyword = "null" | "undefined" | "true" | "false";
13
7
  export type UnitLiteral = StringLiteral | BigintLiteral | NumberLiteral | DateLiteral | UnitLiteralKeyword;
14
8
  export type ParsedDefault = [BaseRoot, "=", unknown];
15
9
  export declare const parseDefault: (s: DynamicStateWithRoot) => ParsedDefault;
@@ -1,10 +1,4 @@
1
1
  import { throwParseError } from "@ark/util";
2
- const unitLiteralKeywords = {
3
- null: null,
4
- undefined,
5
- true: true,
6
- false: false
7
- };
8
2
  export const parseDefault = (s) => {
9
3
  if (!s.defaultable)
10
4
  return throwParseError(shallowDefaultMessage);
@@ -1,6 +1,6 @@
1
- import type { DynamicStateWithRoot } from "../../reduce/dynamic.js";
2
- import type { StaticState, state } from "../../reduce/static.js";
3
- import type { Scanner } from "../scanner.js";
1
+ import type { DynamicStateWithRoot } from "../../reduce/dynamic.ts";
2
+ import type { StaticState, state } from "../../reduce/static.ts";
3
+ import type { Scanner } from "../scanner.ts";
4
4
  export declare const parseDivisor: (s: DynamicStateWithRoot) => void;
5
5
  export type parseDivisor<s extends StaticState, unscanned extends string> = Scanner.shiftUntilNextTerminator<Scanner.skipWhitespace<unscanned>> extends (Scanner.shiftResult<infer scanned, infer nextUnscanned>) ? scanned extends `${infer divisor extends number}` ? divisor extends 0 ? state.error<writeInvalidDivisorMessage<0>> : state.setRoot<s, [s["root"], "%", divisor], nextUnscanned> : state.error<writeInvalidDivisorMessage<scanned>> : never;
6
6
  export declare const writeInvalidDivisorMessage: <divisor extends string | number>(divisor: divisor) => writeInvalidDivisorMessage<divisor>;
@@ -1,9 +1,9 @@
1
1
  import { type WhiteSpaceToken } from "@ark/util";
2
- import type { DynamicStateWithRoot } from "../../reduce/dynamic.js";
3
- import type { StaticState, state } from "../../reduce/static.js";
4
- import { Scanner } from "../scanner.js";
5
- import { parseBound, type ComparatorStartChar } from "./bounds.js";
6
- import { parseDivisor } from "./divisor.js";
2
+ import type { DynamicStateWithRoot } from "../../reduce/dynamic.ts";
3
+ import type { StaticState, state } from "../../reduce/static.ts";
4
+ import { Scanner } from "../scanner.ts";
5
+ import { parseBound, type ComparatorStartChar } from "./bounds.ts";
6
+ import { parseDivisor } from "./divisor.ts";
7
7
  export declare const parseOperator: (s: DynamicStateWithRoot) => void;
8
8
  export type parseOperator<s extends StaticState, $, args> = s["unscanned"] extends Scanner.shift<infer lookahead, infer unscanned> ? lookahead extends "[" ? unscanned extends Scanner.shift<"]", infer nextUnscanned> ? state.setRoot<s, [s["root"], "[]"], nextUnscanned> : state.error<incompleteArrayTokenMessage> : lookahead extends "|" | "&" ? state.reduceBranch<s, lookahead, unscanned> : lookahead extends ")" ? state.finalizeGroup<s, unscanned> : Scanner.lookaheadIsFinalizing<lookahead, unscanned> extends true ? state.finalize<state.scanTo<s, unscanned>, lookahead & Scanner.FinalizingLookahead> : lookahead extends ComparatorStartChar ? parseBound<s, lookahead, unscanned, $, args> : lookahead extends "%" ? parseDivisor<s, unscanned> : lookahead extends WhiteSpaceToken ? parseOperator<state.scanTo<s, unscanned>, $, args> : state.error<writeUnexpectedCharacterMessage<lookahead>> : state.finalize<s, "">;
9
9
  export declare const writeUnexpectedCharacterMessage: <char extends string, shouldBe extends string>(char: char, shouldBe?: shouldBe) => writeUnexpectedCharacterMessage<char, shouldBe>;
@@ -1,5 +1,5 @@
1
1
  import { type Dict, type EscapeToken, type WhiteSpaceToken } from "@ark/util";
2
- import type { Comparator } from "../reduce/shared.js";
2
+ import type { Comparator } from "../reduce/shared.ts";
3
3
  export declare class Scanner<lookahead extends string = string> {
4
4
  private chars;
5
5
  private i;
@@ -20,16 +20,7 @@ export declare class Scanner<lookahead extends string = string> {
20
20
  sliceChars(start: number, end?: number): string;
21
21
  lookaheadIs<char extends lookahead>(char: char): this is Scanner<char>;
22
22
  lookaheadIsIn<tokens extends Dict>(tokens: tokens): this is Scanner<Extract<keyof tokens, string>>;
23
- }
24
- export declare namespace Scanner {
25
- type UntilCondition = (scanner: Scanner, shifted: string) => boolean;
26
- type OnInputEndFn = (scanner: Scanner, shifted: string) => string;
27
- type ShiftUntilOptions = {
28
- onInputEnd?: OnInputEndFn;
29
- };
30
- const lookaheadIsTerminator: UntilCondition;
31
- const lookaheadIsNotWhitespace: UntilCondition;
32
- const terminatingChars: {
23
+ static terminatingChars: {
33
24
  readonly "<": true;
34
25
  readonly ">": true;
35
26
  readonly "=": true;
@@ -42,19 +33,28 @@ export declare namespace Scanner {
42
33
  readonly ",": true;
43
34
  readonly ":": true;
44
35
  };
45
- type TerminatingChar = keyof typeof terminatingChars;
46
- const finalizingLookaheads: {
36
+ static finalizingLookaheads: {
47
37
  readonly ">": true;
48
38
  readonly ",": true;
49
39
  readonly "": true;
50
40
  readonly "=": true;
51
41
  };
52
- type FinalizingLookahead = keyof typeof finalizingLookaheads;
42
+ static lookaheadIsTerminator: Scanner.UntilCondition;
43
+ static lookaheadIsNotWhitespace: Scanner.UntilCondition;
44
+ static lookaheadIsFinalizing: (lookahead: string, unscanned: string) => lookahead is ">" | "," | "=";
45
+ }
46
+ export declare namespace Scanner {
47
+ type lookaheadIsFinalizing<lookahead extends string, unscanned extends string> = lookahead extends ">" ? unscanned extends `=${infer nextUnscanned}` ? nextUnscanned extends `=${string}` ? true : false : Scanner.skipWhitespace<unscanned> extends ("" | `${TerminatingChar}${string}`) ? true : false : lookahead extends "=" ? unscanned extends `=${string}` ? false : true : lookahead extends "," ? true : false;
48
+ type UntilCondition = (scanner: Scanner, shifted: string) => boolean;
49
+ type OnInputEndFn = (scanner: Scanner, shifted: string) => string;
50
+ type ShiftUntilOptions = {
51
+ onInputEnd?: OnInputEndFn;
52
+ };
53
+ type TerminatingChar = keyof typeof Scanner.terminatingChars;
54
+ type FinalizingLookahead = keyof typeof Scanner.finalizingLookaheads;
53
55
  type InfixToken = Comparator | "|" | "&" | "%" | ":" | "=>";
54
56
  type PostfixToken = "[]";
55
57
  type OperatorToken = InfixToken | PostfixToken;
56
- const lookaheadIsFinalizing: (lookahead: string, unscanned: string) => lookahead is ">" | "," | "=";
57
- type lookaheadIsFinalizing<lookahead extends string, unscanned extends string> = lookahead extends ">" ? unscanned extends `=${infer nextUnscanned}` ? nextUnscanned extends `=${string}` ? true : false : Scanner.skipWhitespace<unscanned> extends ("" | `${TerminatingChar}${string}`) ? true : false : lookahead extends "=" ? unscanned extends `=${string}` ? false : true : lookahead extends "," ? true : false;
58
58
  type shift<lookahead extends string, unscanned extends string> = `${lookahead}${unscanned}`;
59
59
  type shiftUntil<unscanned extends string, terminator extends string, scanned extends string = ""> = unscanned extends shift<infer lookahead, infer nextUnscanned> ? lookahead extends terminator ? scanned extends `${infer base}${EscapeToken}` ? shiftUntil<nextUnscanned, terminator, `${base}${lookahead}`> : [scanned, unscanned] : shiftUntil<nextUnscanned, terminator, `${scanned}${lookahead}`> : [scanned, ""];
60
60
  type shiftUntilNot<unscanned extends string, nonTerminator extends string, scanned extends string = ""> = unscanned extends shift<infer lookahead, infer nextUnscanned> ? lookahead extends nonTerminator ? shiftUntilNot<nextUnscanned, nonTerminator, `${scanned}${lookahead}`> : [scanned, unscanned] : [scanned, ""];
@@ -63,11 +63,7 @@ export class Scanner {
63
63
  lookaheadIsIn(tokens) {
64
64
  return this.lookahead in tokens;
65
65
  }
66
- }
67
- (function (Scanner) {
68
- Scanner.lookaheadIsTerminator = (scanner) => scanner.lookahead in Scanner.terminatingChars;
69
- Scanner.lookaheadIsNotWhitespace = (scanner) => !(scanner.lookahead in whiteSpaceTokens);
70
- Scanner.terminatingChars = {
66
+ static terminatingChars = {
71
67
  "<": true,
72
68
  ">": true,
73
69
  "=": true,
@@ -80,13 +76,15 @@ export class Scanner {
80
76
  ",": true,
81
77
  ":": true
82
78
  };
83
- Scanner.finalizingLookaheads = {
79
+ static finalizingLookaheads = {
84
80
  ">": true,
85
81
  ",": true,
86
82
  "": true,
87
83
  "=": true
88
84
  };
89
- Scanner.lookaheadIsFinalizing = (lookahead, unscanned) => lookahead === ">" ?
85
+ static lookaheadIsTerminator = (scanner) => scanner.lookahead in this.terminatingChars;
86
+ static lookaheadIsNotWhitespace = (scanner) => !(scanner.lookahead in whiteSpaceTokens);
87
+ static lookaheadIsFinalizing = (lookahead, unscanned) => lookahead === ">" ?
90
88
  unscanned[0] === "=" ?
91
89
  // >== would only occur in an expression like Array<number>==5
92
90
  // otherwise, >= would only occur as part of a bound like number>=5
@@ -99,4 +97,4 @@ export class Scanner {
99
97
  : lookahead === "=" ? unscanned[0] !== "="
100
98
  // ","" is unambiguously a finalizer
101
99
  : lookahead === ",";
102
- })(Scanner || (Scanner = {}));
100
+ }
@@ -1,13 +1,13 @@
1
1
  import type { BaseRoot, resolvableReferenceIn } from "@ark/schema";
2
2
  import { type ErrorMessage } from "@ark/util";
3
- import type { Ark } from "../../ark.js";
4
- import type { inferAstRoot } from "../semantic/infer.js";
5
- import type { DynamicState, DynamicStateWithRoot } from "./reduce/dynamic.js";
6
- import type { StringifiablePrefixOperator } from "./reduce/shared.js";
7
- import type { state, StaticState } from "./reduce/static.js";
8
- import type { parseOperand } from "./shift/operand/operand.js";
9
- import { parseDefault, type ParsedDefault } from "./shift/operator/default.js";
10
- import { writeUnexpectedCharacterMessage, type parseOperator } from "./shift/operator/operator.js";
3
+ import type { ArkAmbient } from "arktype/config";
4
+ import type { inferAstRoot } from "../semantic/infer.ts";
5
+ import type { DynamicState, DynamicStateWithRoot } from "./reduce/dynamic.ts";
6
+ import type { StringifiablePrefixOperator } from "./reduce/shared.ts";
7
+ import type { state, StaticState } from "./reduce/static.ts";
8
+ import type { parseOperand } from "./shift/operand/operand.ts";
9
+ import { parseDefault, type ParsedDefault } from "./shift/operator/default.ts";
10
+ import { writeUnexpectedCharacterMessage, type parseOperator } from "./shift/operator/operator.ts";
11
11
  /**
12
12
  * Try to parse the definition from right to left using the most common syntax.
13
13
  * This can be much more efficient for simple definitions.
@@ -17,7 +17,7 @@ export type parseString<def extends string, $, args> = def extends keyof $ ? def
17
17
  "[]"
18
18
  ] : fullStringParse<state.initialize<def>, $, args> : fullStringParse<state.initialize<def>, $, args>;
19
19
  export type inferString<def extends string, $, args> = inferAstRoot<parseString<def, $, args>, $, args>;
20
- export type BaseCompletions<$, args, otherSuggestions extends string = never> = resolvableReferenceIn<$> | resolvableReferenceIn<Ark> | (keyof args & string) | StringifiablePrefixOperator | otherSuggestions;
20
+ export type BaseCompletions<$, args, otherSuggestions extends string = never> = resolvableReferenceIn<$> | resolvableReferenceIn<ArkAmbient.$> | (keyof args & string) | StringifiablePrefixOperator | otherSuggestions;
21
21
  export type StringParseResult = BaseRoot | ParsedDefault;
22
22
  export declare const fullStringParse: (s: DynamicState) => StringParseResult;
23
23
  type fullStringParse<s extends StaticState, $, args> = extractFinalizedResult<parseUntilFinalizer<s, $, args>>;
@@ -1,12 +1,12 @@
1
1
  import { type BaseRoot, type MetaSchema, type Morph, type Predicate } from "@ark/schema";
2
2
  import { type array, type BuiltinObjectKind, type conform, type Constructor, type Domain, type ErrorMessage, type show } from "@ark/util";
3
- import type { distillConstrainableIn, distillOut, inferMorphOut, inferPredicate, Out } from "../ast.js";
4
- import type { inferIntersection } from "../intersect.js";
5
- import type { ParseContext } from "../scope.js";
6
- import type { inferDefinition, validateDefinition } from "./definition.js";
7
- import type { InfixOperator, PostfixExpression } from "./semantic/infer.js";
8
- import { writeMissingRightOperandMessage } from "./string/shift/operand/unenclosed.js";
9
- import type { BaseCompletions } from "./string/string.js";
3
+ import type { distillConstrainableIn, distillOut, inferMorphOut, inferPredicate, Out } from "../ast.ts";
4
+ import type { inferIntersection } from "../intersect.ts";
5
+ import type { ParseContext } from "../scope.ts";
6
+ import type { inferDefinition, validateDefinition } from "./definition.ts";
7
+ import type { InfixOperator, PostfixExpression } from "./semantic/infer.ts";
8
+ import { writeMissingRightOperandMessage } from "./string/shift/operand/unenclosed.ts";
9
+ import type { BaseCompletions } from "./string/string.ts";
10
10
  export declare const parseTuple: (def: array, ctx: ParseContext) => BaseRoot;
11
11
  export declare const parseTupleLiteral: (def: array, ctx: ParseContext) => BaseRoot;
12
12
  type InfixExpression = readonly [unknown, InfixOperator, ...unknown[]];
@@ -88,7 +88,8 @@ const appendSpreadBranch = (base, branch) => {
88
88
  }
89
89
  spread.prefix.forEach(node => appendElement(base, "required", node));
90
90
  spread.optionals.forEach(node => appendElement(base, "optional", node));
91
- spread.variadic && appendElement(base, "variadic", spread.variadic);
91
+ if (spread.variadic)
92
+ appendElement(base, "variadic", spread.variadic);
92
93
  spread.postfix.forEach(node => appendElement(base, "required", node));
93
94
  return base;
94
95
  };