arktype 2.0.0-rc.7 → 2.0.0-rc.9

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 (98) hide show
  1. package/out/config.d.ts +1 -1
  2. package/out/generic.d.ts +9 -9
  3. package/out/generic.js +2 -2
  4. package/out/index.d.ts +1 -1
  5. package/out/index.js +1 -1
  6. package/out/keywords/constructors/Array.d.ts +1 -1
  7. package/out/keywords/constructors/Date.d.ts +1 -1
  8. package/out/keywords/constructors/FormData.d.ts +1 -1
  9. package/out/keywords/{ast.d.ts → inference.d.ts} +42 -20
  10. package/out/keywords/{ark.d.ts → keywords.d.ts} +7 -3
  11. package/out/keywords/{ark.js → keywords.js} +7 -7
  12. package/out/keywords/number/number.d.ts +1 -1
  13. package/out/keywords/string/alpha.d.ts +1 -1
  14. package/out/keywords/string/alphanumeric.d.ts +1 -1
  15. package/out/keywords/string/capitalize.d.ts +1 -1
  16. package/out/keywords/string/creditCard.d.ts +1 -1
  17. package/out/keywords/string/date.d.ts +1 -1
  18. package/out/keywords/string/date.js +6 -6
  19. package/out/keywords/string/digits.d.ts +1 -1
  20. package/out/keywords/string/email.d.ts +1 -1
  21. package/out/keywords/string/integer.d.ts +1 -1
  22. package/out/keywords/string/ip.d.ts +1 -1
  23. package/out/keywords/string/json.d.ts +2 -1
  24. package/out/keywords/string/json.js +18 -10
  25. package/out/keywords/string/lower.d.ts +1 -1
  26. package/out/keywords/string/normalize.d.ts +1 -1
  27. package/out/keywords/string/numeric.d.ts +1 -1
  28. package/out/keywords/string/semver.d.ts +1 -1
  29. package/out/keywords/string/string.d.ts +7 -7
  30. package/out/keywords/string/trim.d.ts +1 -1
  31. package/out/keywords/string/upper.d.ts +1 -1
  32. package/out/keywords/string/url.d.ts +1 -1
  33. package/out/keywords/string/uuid.d.ts +1 -1
  34. package/out/methods/array.d.ts +1 -1
  35. package/out/methods/base.d.ts +26 -23
  36. package/out/methods/date.d.ts +1 -1
  37. package/out/methods/instantiate.d.ts +5 -4
  38. package/out/methods/morph.d.ts +3 -4
  39. package/out/methods/number.d.ts +1 -1
  40. package/out/methods/object.d.ts +55 -30
  41. package/out/methods/string.d.ts +1 -1
  42. package/out/methods/validator.d.ts +1 -1
  43. package/out/parser/{semantic → ast}/bounds.d.ts +3 -3
  44. package/out/parser/{semantic → ast}/default.d.ts +2 -2
  45. package/out/parser/{semantic → ast}/infer.d.ts +6 -8
  46. package/out/parser/{semantic → ast}/utils.d.ts +1 -1
  47. package/out/parser/{semantic → ast}/validate.d.ts +5 -5
  48. package/out/parser/definition.d.ts +5 -5
  49. package/out/parser/objectLiteral.d.ts +3 -3
  50. package/out/parser/{string/reduce → reduce}/dynamic.d.ts +2 -2
  51. package/out/parser/{string/reduce → reduce}/shared.d.ts +1 -1
  52. package/out/parser/{string/reduce → reduce}/static.d.ts +1 -1
  53. package/out/parser/{string/shift → shift}/operand/date.d.ts +1 -1
  54. package/out/parser/{string/shift → shift}/operand/enclosed.d.ts +3 -3
  55. package/out/parser/{string/shift → shift}/operand/unenclosed.d.ts +3 -3
  56. package/out/parser/{string/shift → shift}/operand/unenclosed.js +1 -1
  57. package/out/parser/{string/shift → shift}/operator/bounds.d.ts +3 -3
  58. package/out/parser/{string/shift → shift}/operator/default.d.ts +1 -1
  59. package/out/parser/{string/shift → shift}/scanner.d.ts +3 -1
  60. package/out/parser/{string/shift → shift}/scanner.js +5 -3
  61. package/out/parser/{string/string.d.ts → string.d.ts} +4 -4
  62. package/out/parser/{string/string.js → string.js} +2 -0
  63. package/out/parser/tuple.d.ts +47 -36
  64. package/out/parser/tuple.js +5 -10
  65. package/out/scope.d.ts +4 -4
  66. package/out/scope.js +4 -4
  67. package/out/type.d.ts +8 -10
  68. package/out/type.js +2 -1
  69. package/package.json +3 -3
  70. package/out/intersect.d.ts +0 -26
  71. package/out/intersect.js +0 -1
  72. package/out/keys.d.ts +0 -18
  73. package/out/keys.js +0 -1
  74. /package/out/keywords/{ast.js → inference.js} +0 -0
  75. /package/out/parser/{semantic → ast}/bounds.js +0 -0
  76. /package/out/parser/{semantic → ast}/default.js +0 -0
  77. /package/out/parser/{semantic → ast}/divisor.d.ts +0 -0
  78. /package/out/parser/{semantic → ast}/divisor.js +0 -0
  79. /package/out/parser/{semantic → ast}/infer.js +0 -0
  80. /package/out/parser/{semantic → ast}/keyof.d.ts +0 -0
  81. /package/out/parser/{semantic → ast}/keyof.js +0 -0
  82. /package/out/parser/{semantic → ast}/utils.js +0 -0
  83. /package/out/parser/{semantic → ast}/validate.js +0 -0
  84. /package/out/parser/{string/reduce → reduce}/dynamic.js +0 -0
  85. /package/out/parser/{string/reduce → reduce}/shared.js +0 -0
  86. /package/out/parser/{string/reduce → reduce}/static.js +0 -0
  87. /package/out/parser/{string/shift → shift}/operand/date.js +0 -0
  88. /package/out/parser/{string/shift → shift}/operand/enclosed.js +0 -0
  89. /package/out/parser/{string/shift → shift}/operand/genericArgs.d.ts +0 -0
  90. /package/out/parser/{string/shift → shift}/operand/genericArgs.js +0 -0
  91. /package/out/parser/{string/shift → shift}/operand/operand.d.ts +0 -0
  92. /package/out/parser/{string/shift → shift}/operand/operand.js +0 -0
  93. /package/out/parser/{string/shift → shift}/operator/bounds.js +0 -0
  94. /package/out/parser/{string/shift → shift}/operator/default.js +0 -0
  95. /package/out/parser/{string/shift → shift}/operator/divisor.d.ts +0 -0
  96. /package/out/parser/{string/shift → shift}/operator/divisor.js +0 -0
  97. /package/out/parser/{string/shift → shift}/operator/operator.d.ts +0 -0
  98. /package/out/parser/{string/shift → shift}/operator/operator.js +0 -0
@@ -1,22 +1,23 @@
1
1
  import type { ArkErrors, BaseRoot, Disjoint, JsonSchema, MetaSchema, Morph, UndeclaredKeyBehavior } from "@ark/schema";
2
2
  import type { anyOrNever, array, Callable, ErrorMessage, inferred, Json, unset } from "@ark/util";
3
3
  import type { ArkAmbient } from "../config.ts";
4
- import type { inferIntersection } from "../intersect.ts";
5
- import type { type } from "../keywords/ark.ts";
6
- import type { applyConstraint, Default, distill, inferMorphOut, inferPipes, Optional } from "../keywords/ast.ts";
4
+ import type { applyConstraint, Default, distill, inferIntersection, inferMorphOut, inferPipes, Optional } from "../keywords/inference.ts";
5
+ import type { type } from "../keywords/keywords.ts";
7
6
  import type { Scope } from "../scope.ts";
8
7
  import type { ArrayType } from "./array.ts";
9
8
  import type { instantiateType } from "./instantiate.ts";
10
9
  /** @ts-ignore cast variance */
11
10
  interface Type<out t = unknown, $ = {}> extends Callable<(data: unknown) => distill.Out<t> | ArkErrors> {
12
11
  t: t;
12
+ infer: this["inferOut"];
13
13
  inferBrandableIn: distill.brandable.In<t>;
14
14
  inferBrandableOut: distill.brandable.Out<t>;
15
15
  inferIntrospectableOut: distill.introspectable.Out<t>;
16
- infer: distill.Out<t>;
16
+ inferOut: distill.Out<t>;
17
17
  inferIn: distill.In<t>;
18
18
  [inferred]: t;
19
19
  json: Json;
20
+ toJSON(): Json;
20
21
  meta: ArkAmbient.meta;
21
22
  precompilation: string | undefined;
22
23
  toJsonSchema(): JsonSchema;
@@ -26,28 +27,30 @@ interface Type<out t = unknown, $ = {}> extends Callable<(data: unknown) => dist
26
27
  $: Scope<$>;
27
28
  assert(data: unknown): this["infer"];
28
29
  allows(data: unknown): data is this["inferIn"];
29
- traverse(data: unknown): distill.Out<t> | ArkErrors;
30
+ traverse(data: unknown): this["infer"] | ArkErrors;
30
31
  configure(meta: MetaSchema): this;
31
32
  describe(description: string): this;
32
- optional<r = applyConstraint<t, Optional>>(): instantiateType<r, $>;
33
- default<value extends this["infer"], r = (In?: this["inferBrandableIn"]) => Default<value>>(value: value): instantiateType<r, $>;
34
33
  onUndeclaredKey(behavior: UndeclaredKeyBehavior): this;
35
34
  onDeepUndeclaredKey(behavior: UndeclaredKeyBehavior): this;
36
35
  from(literal: this["inferIn"]): this["infer"];
37
36
  as<t = unset>(...args: validateChainedAsArgs<t>): instantiateType<t, $>;
38
37
  get in(): instantiateType<this["inferBrandableIn"], $>;
39
38
  get out(): instantiateType<this["inferIntrospectableOut"], $>;
40
- intersect<const def, r = type.infer<def, $>>(def: type.validate<def, $>): instantiateType<inferIntersection<t, r>, $> | Disjoint;
41
- and<const def, r = type.infer<def, $>>(def: type.validate<def, $>): instantiateType<inferIntersection<t, r>, $>;
42
- or<const def, r = type.infer<def, $>>(def: type.validate<def, $>): instantiateType<t | r, $>;
39
+ intersect<const def>(def: type.validate<def, $>): type.infer<def, $> extends infer r ? instantiateType<inferIntersection<t, r>, $> | Disjoint : never;
40
+ and<const def>(def: type.validate<def, $>): type.infer<def, $> extends infer r ? instantiateType<inferIntersection<t, r>, $> : never;
41
+ or<const def>(def: type.validate<def, $>): type.infer<def, $> extends infer r ? instantiateType<t | r, $> : never;
43
42
  array(): ArrayType<t[], $>;
44
43
  pipe: ChainedPipes<t, $>;
45
- equals<def>(def: type.validate<def, $>): this is instantiateType<type.infer<def, $>, $>;
46
- extract<def>(r: type.validate<def, $>): instantiateType<Extract<t, type.infer<def, $>>, $>;
47
- exclude<def>(r: type.validate<def, $>): instantiateType<Exclude<t, type.infer<def, $>>, $>;
48
- extends<def>(other: type.validate<def, $>): this is instantiateType<type.infer<def, $>, $>;
49
- overlaps<def>(r: type.validate<def, $>): boolean;
50
- distribute<mapOut, reduceOut = mapOut[]>(mapBranch: (branch: Type, i: number, branches: array<Type>) => mapOut, reduceMapped?: (mappedBranches: mapOut[]) => reduceOut): reduceOut;
44
+ equals<const def>(def: type.validate<def, $>): boolean;
45
+ ifEquals<const def>(def: type.validate<def, $>): type.infer<def, $> extends infer r ? instantiateType<r, $> | undefined : never;
46
+ extends<const def>(other: type.validate<def, $>): boolean;
47
+ ifExtends<const def>(other: type.validate<def, $>): type.infer<def, $> extends infer r ? instantiateType<r, $> | undefined : never;
48
+ overlaps<const def>(r: type.validate<def, $>): boolean;
49
+ extract<const def>(r: type.validate<def, $>): type.infer<def, $> extends infer r ? instantiateType<Extract<t, r>, $> : never;
50
+ exclude<const def>(r: type.validate<def, $>): type.infer<def, $> extends infer r ? instantiateType<Exclude<t, r>, $> : never;
51
+ distribute<mapOut, reduceOut = mapOut[]>(mapBranch: (branch: Type, i: number, branches: array<Type>) => mapOut, reduceMapped?: (mappedBranches: mapOut[]) => reduceOut): NoInfer<reduceOut>;
52
+ optional<r = applyConstraint<t, Optional>>(): instantiateType<r, $>;
53
+ default<value extends this["infer"], r = (In?: this["inferBrandableIn"]) => Default<value>>(value: value): instantiateType<r, $>;
51
54
  /** @deprecated */
52
55
  apply: Function["apply"];
53
56
  /** @deprecated */
@@ -68,13 +71,13 @@ interface Type<out t = unknown, $ = {}> extends Callable<(data: unknown) => dist
68
71
  Symbol: never;
69
72
  }
70
73
  interface ChainedPipeSignature<t, $> {
71
- <a extends Morph<distill.Out<t>>, r = instantiateType<inferPipes<t, [a]>, $>>(a: a): r;
72
- <a extends Morph<distill.Out<t>>, b extends Morph<inferMorphOut<a>>, r = instantiateType<inferPipes<t, [a, b]>, $>>(a: a, b: b): r;
73
- <a extends Morph<distill.Out<t>>, b extends Morph<inferMorphOut<a>>, c extends Morph<inferMorphOut<b>>, r = instantiateType<inferPipes<t, [a, b, c]>, $>>(a: a, b: b, c: c): r;
74
- <a extends Morph<distill.Out<t>>, b extends Morph<inferMorphOut<a>>, c extends Morph<inferMorphOut<b>>, d extends Morph<inferMorphOut<c>>, r = instantiateType<inferPipes<t, [a, b, c, d]>, $>>(a: a, b: b, c: c, d: d): r;
75
- <a extends Morph<distill.Out<t>>, b extends Morph<inferMorphOut<a>>, c extends Morph<inferMorphOut<b>>, d extends Morph<inferMorphOut<c>>, e extends Morph<inferMorphOut<d>>, r = instantiateType<inferPipes<t, [a, b, c, d, e]>, $>>(a: a, b: b, c: c, d: d, e: e): r;
76
- <a extends Morph<distill.Out<t>>, b extends Morph<inferMorphOut<a>>, c extends Morph<inferMorphOut<b>>, d extends Morph<inferMorphOut<c>>, e extends Morph<inferMorphOut<d>>, f extends Morph<inferMorphOut<e>>, r = instantiateType<inferPipes<t, [a, b, c, d, e, f]>, $>>(a: a, b: b, c: c, d: d, e: e, f: f): r;
77
- <a extends Morph<distill.Out<t>>, b extends Morph<inferMorphOut<a>>, c extends Morph<inferMorphOut<b>>, d extends Morph<inferMorphOut<c>>, e extends Morph<inferMorphOut<d>>, f extends Morph<inferMorphOut<e>>, g extends Morph<inferMorphOut<f>>, r = instantiateType<inferPipes<t, [a, b, c, d, e, f, g]>, $>>(a: a, b: b, c: c, d: d, e: e, f: f, g: g): r;
74
+ <a extends Morph<distill.Out<t>>, r = instantiateType<inferPipes<t, [a]>, $>>(a: a): NoInfer<r>;
75
+ <a extends Morph<distill.Out<t>>, b extends Morph<inferMorphOut<a>>, r = instantiateType<inferPipes<t, [a, b]>, $>>(a: a, b: b): NoInfer<r>;
76
+ <a extends Morph<distill.Out<t>>, b extends Morph<inferMorphOut<a>>, c extends Morph<inferMorphOut<b>>, r = instantiateType<inferPipes<t, [a, b, c]>, $>>(a: a, b: b, c: c): NoInfer<r>;
77
+ <a extends Morph<distill.Out<t>>, b extends Morph<inferMorphOut<a>>, c extends Morph<inferMorphOut<b>>, d extends Morph<inferMorphOut<c>>, r = instantiateType<inferPipes<t, [a, b, c, d]>, $>>(a: a, b: b, c: c, d: d): NoInfer<r>;
78
+ <a extends Morph<distill.Out<t>>, b extends Morph<inferMorphOut<a>>, c extends Morph<inferMorphOut<b>>, d extends Morph<inferMorphOut<c>>, e extends Morph<inferMorphOut<d>>, r = instantiateType<inferPipes<t, [a, b, c, d, e]>, $>>(a: a, b: b, c: c, d: d, e: e): NoInfer<r>;
79
+ <a extends Morph<distill.Out<t>>, b extends Morph<inferMorphOut<a>>, c extends Morph<inferMorphOut<b>>, d extends Morph<inferMorphOut<c>>, e extends Morph<inferMorphOut<d>>, f extends Morph<inferMorphOut<e>>, r = instantiateType<inferPipes<t, [a, b, c, d, e, f]>, $>>(a: a, b: b, c: c, d: d, e: e, f: f): NoInfer<r>;
80
+ <a extends Morph<distill.Out<t>>, b extends Morph<inferMorphOut<a>>, c extends Morph<inferMorphOut<b>>, d extends Morph<inferMorphOut<c>>, e extends Morph<inferMorphOut<d>>, f extends Morph<inferMorphOut<e>>, g extends Morph<inferMorphOut<f>>, r = instantiateType<inferPipes<t, [a, b, c, d, e, f, g]>, $>>(a: a, b: b, c: c, d: d, e: e, f: f, g: g): NoInfer<r>;
78
81
  }
79
82
  export interface ChainedPipes<t, $> extends ChainedPipeSignature<t, $> {
80
83
  try: ChainedPipeSignature<t, $>;
@@ -1,5 +1,5 @@
1
1
  import type { ExclusiveDateRangeSchema, exclusivizeRangeSchema, InclusiveDateRangeSchema } from "@ark/schema";
2
- import type { applyConstraintSchema } from "../keywords/ast.ts";
2
+ import type { applyConstraintSchema } from "../keywords/inference.ts";
3
3
  import type { ObjectType } from "./object.ts";
4
4
  /** @ts-ignore cast variance */
5
5
  interface Type<out t extends globalThis.Date = globalThis.Date, $ = {}> extends ObjectType<t, $> {
@@ -1,6 +1,7 @@
1
1
  import type { anyOrNever, array } from "@ark/util";
2
- import type { MorphAst } from "../keywords/ast.ts";
2
+ import type { InferredMorph } from "../keywords/inference.ts";
3
3
  import type { ArrayType } from "./array.ts";
4
+ import type { BaseType } from "./base.ts";
4
5
  import type { DateType } from "./date.ts";
5
6
  import type { MorphType } from "./morph.ts";
6
7
  import type { NumberType } from "./number.ts";
@@ -8,9 +9,9 @@ import type { ObjectType } from "./object.ts";
8
9
  import type { StringType } from "./string.ts";
9
10
  import type { ValidatorType } from "./validator.ts";
10
11
  export type instantiateType<t, $> = [
11
- Extract<t, MorphAst>
12
+ Extract<t, InferredMorph>
12
13
  ] extends [anyOrNever] ? [
13
14
  t
14
- ] extends [string] ? StringType<t, $> : [t] extends [number] ? NumberType<t, $> : [t] extends [object] ? [
15
+ ] extends [anyOrNever] ? BaseType<t, $> : [t] extends [string] ? StringType<t, $> : [t] extends [number] ? NumberType<t, $> : [t] extends [object] ? [
15
16
  t
16
- ] extends [array] ? ArrayType<t, $> : [t] extends [Date] ? DateType<t, $> : ObjectType<t, $> : ValidatorType<t, $> : MorphType<t, $>;
17
+ ] extends [array] ? ArrayType<t, $> : [t] extends [Date] ? DateType<t, $> : ObjectType<t, $> : unknown extends t ? BaseType<unknown, $> : ValidatorType<t, $> : MorphType<t, $>;
@@ -1,11 +1,10 @@
1
1
  import type { Predicate, PredicateCast } from "@ark/schema";
2
- import type { inferPipe } from "../intersect.ts";
3
- import type { type } from "../keywords/ark.ts";
4
- import type { applyConstraintSchema, Out, To } from "../keywords/ast.ts";
2
+ import type { applyConstraintSchema, inferPipe, Out, To } from "../keywords/inference.ts";
3
+ import type { type } from "../keywords/keywords.ts";
5
4
  import type { BaseType } from "./base.ts";
6
5
  /** @ts-ignore cast variance */
7
6
  interface Type<out t = unknown, $ = {}> extends BaseType<t, $> {
8
- to<const def, r = type.infer<def, $>>(def: type.validate<def, $>): Type<inferPipe<t, r>, $>;
7
+ to<const def, r = type.infer<def, $>>(def: type.validate<def, $>): Type<inferPipe<t, NoInfer<r>>, $>;
9
8
  narrow<narrowed extends this["infer"] = never>(predicate: Predicate<this["infer"]> | PredicateCast<this["infer"], narrowed>): Type<([
10
9
  narrowed
11
10
  ] extends [never] ? applyConstraintSchema<this["inferBrandableOut"], "predicate", Predicate> : narrowed) extends infer o ? this["inferIntrospectableOut"] extends this["inferBrandableOut"] ? (In: this["inferBrandableIn"]) => To<o> : (In: this["inferBrandableIn"]) => Out<o> : never, $>;
@@ -1,5 +1,5 @@
1
1
  import type { Divisor, ExclusiveNumericRangeSchema, exclusivizeRangeSchema, InclusiveNumericRangeSchema } from "@ark/schema";
2
- import type { applyConstraintSchema } from "../keywords/ast.ts";
2
+ import type { applyConstraintSchema } from "../keywords/inference.ts";
3
3
  import type { ValidatorType } from "./validator.ts";
4
4
  /** @ts-ignore cast variance */
5
5
  interface Type<out t extends number = number, $ = {}> extends ValidatorType<t, $> {
@@ -1,6 +1,7 @@
1
- import type { array, ErrorType, inferred, intersectUnion, Key, listable, merge, optionalKeyOf, show } from "@ark/util";
2
- import type { arkGet, arkKeyOf, toArkKey } from "../keys.ts";
3
- import type { type } from "../keywords/ark.ts";
1
+ import type { BaseMappedPropInner, OptionalMappedPropInner, Prop } from "@ark/schema";
2
+ import type { anyOrNever, arkGet, arkIndexableOf, arkKeyOf, array, ErrorType, inferred, intersectUnion, Json, Key, listable, merge, optionalKeyOf, show, toArkKey } from "@ark/util";
3
+ import type { Default, InferredDefault, InferredOptional } from "../keywords/inference.ts";
4
+ import type { type } from "../keywords/keywords.ts";
4
5
  import type { ArrayType } from "./array.ts";
5
6
  import type { instantiateType } from "./instantiate.ts";
6
7
  import type { ValidatorType } from "./validator.ts";
@@ -12,46 +13,70 @@ interface Type<out t extends object = object, $ = {}> extends ValidatorType<t, $
12
13
  readonly [k in keyof t]: t[k];
13
14
  }, $>;
14
15
  keyof(): instantiateType<arkKeyOf<t>, $>;
15
- get<k1 extends arkKeyOf<t>, r = instantiateType<arkGet<t, k1>, $>>(k1: k1 | type.cast<k1>): r;
16
- get<k1 extends arkKeyOf<t>, k2 extends arkKeyOf<arkGet<t, k1>>, r = instantiateType<arkGet<arkGet<t, k1>, k2>, $>>(k1: k1 | type.cast<k1>, k2: k2 | type.cast<k2>): r;
17
- get<k1 extends arkKeyOf<t>, k2 extends arkKeyOf<arkGet<t, k1>>, k3 extends arkKeyOf<arkGet<arkGet<t, k1>, k2>>, r = instantiateType<arkGet<arkGet<arkGet<t, k1>, k2>, k3>, $>>(k1: k1 | type.cast<k1>, k2: k2 | type.cast<k2>, k3: k3 | type.cast<k3>): r;
16
+ get<const k1 extends arkIndexableOf<t>>(k1: k1 | type.cast<k1>): instantiateType<arkGet<t, k1>, $> extends infer r ? r : never;
17
+ get<const k1 extends arkIndexableOf<t>, const k2 extends arkIndexableOf<arkGet<t, k1>>>(k1: k1 | type.cast<k1>, k2: k2 | type.cast<k2>): instantiateType<arkGet<arkGet<t, k1>, k2>, $> extends infer r ? r : never;
18
+ get<const k1 extends arkIndexableOf<t>, const k2 extends arkIndexableOf<arkGet<t, k1>>, const k3 extends arkIndexableOf<arkGet<arkGet<t, k1>, k2>>>(k1: k1 | type.cast<k1>, k2: k2 | type.cast<k2>, k3: k3 | type.cast<k3>): instantiateType<arkGet<arkGet<arkGet<t, k1>, k2>, k3>, $> extends infer r ? r : never;
18
19
  pick<const key extends arkKeyOf<t> = never>(...keys: (key | type.cast<key>)[]): Type<{
19
20
  [k in keyof t as Extract<toArkKey<t, k>, key>]: t[k];
20
21
  }, $>;
21
22
  omit<const key extends arkKeyOf<t> = never>(...keys: (key | type.cast<key>)[]): Type<{
22
23
  [k in keyof t as Exclude<toArkKey<t, k>, key>]: t[k];
23
24
  }, $>;
24
- merge<const def, r = type.infer<def, $>>(def: type.validate<def, $> & (r extends object ? unknown : ErrorType<"Merged type must be an object", [actual: r]>)): Type<merge<t, r & object>, $>;
25
+ merge<const def, r = type.infer<def, $>>(def: type.validate<def, $> & (r extends object ? unknown : ErrorType<"Merged type must be an object", [actual: r]>)): Type<merge<t, NoInfer<r & object>>, $>;
25
26
  required(): Type<{
26
27
  [k in keyof t]-?: t[k];
27
28
  }, $>;
28
29
  partial(): Type<{
29
30
  [k in keyof t]?: t[k];
30
31
  }, $>;
31
- map<transformed extends listable<MappedTypeEntry<Key, v>>, v = unknown>(flatMapEntry: (entry: typeEntryOf<t, $>) => transformed): Type<constructMapped<t, transformed>, $>;
32
+ map<transformed extends listable<MappedTypeProp>>(flatMapEntry: (entry: typePropOf<t, $>) => transformed): Type<constructMapped<t, transformed>, $>;
33
+ props: array<typePropOf<t, $>>;
32
34
  }
33
- export type MappedTypeEntry<k extends Key = Key, v = unknown> = readonly [
34
- key: k,
35
- value: type.cast<v>,
36
- kind?: "required" | "optional"
37
- ];
38
- type TypeEntries = array<MappedTypeEntry>;
39
- type typeEntryOf<t, $> = {
40
- [k in keyof t]-?: readonly [
41
- k,
42
- instantiateType<t[k] & ({} | null), $>,
43
- k extends optionalKeyOf<t> ? "optional" : "required"
44
- ];
45
- }[keyof t] & unknown;
46
- type constructMapped<t, transformed extends listable<MappedTypeEntry>> = show<intersectUnion<fromTypeEntries<t, transformed extends TypeEntries ? transformed : [transformed]>>>;
47
- type fromTypeEntries<t, entries extends TypeEntries> = show<{
48
- [entry in entries[number] as Extract<applyHomomorphicOptionality<t, entry>, readonly [unknown, unknown, "required"]>[0]]: entry[1][inferred];
35
+ type typePropOf<o, $> = {
36
+ [k in keyof o]-?: typeProp<o, k, $>;
37
+ }[keyof o] & unknown;
38
+ type typeProp<o, k extends keyof o, $, t = o[k] & ({} | null)> = t extends InferredDefault<infer v, infer defaultValue> ? DefaultedTypeProp<k & Key, v, defaultValue, $> : BaseTypeProp<k extends optionalKeyOf<o> ? "optional" : t extends InferredOptional ? [
39
+ t
40
+ ] extends [anyOrNever] ? "required" : "optional" : "required", k & Key, t, $>;
41
+ export interface BaseTypeProp<kind extends Prop.Kind = Prop.Kind, k extends Key = Key,
42
+ /** @ts-ignore cast variance */
43
+ out v = unknown, $ = {}> {
44
+ kind: kind;
45
+ key: k;
46
+ value: instantiateType<v, $>;
47
+ meta: ArkEnv.meta;
48
+ toJSON: () => Json;
49
+ }
50
+ export interface DefaultedTypeProp<k extends Key = Key, v = unknown, defaultValue = v, $ = {}> extends BaseTypeProp<"optional", k, v, $> {
51
+ default: defaultValue;
52
+ }
53
+ type MappedTypeProp<k extends Key = Key, v = unknown> = BaseMappedTypeProp<k, v> | OptionalMappedTypeProp<k, v>;
54
+ type BaseMappedTypeProp<k extends Key, v> = merge<BaseMappedPropInner, {
55
+ key: k;
56
+ value: type.cast<v>;
57
+ }>;
58
+ type OptionalMappedTypeProp<k extends Key, v> = merge<OptionalMappedPropInner, {
59
+ key: k;
60
+ value: type.cast<v>;
61
+ default?: v;
62
+ }>;
63
+ type constructMapped<t, transformed extends listable<MappedTypeProp>> = show<intersectUnion<fromTypeProps<t, transformed extends array ? transformed : [transformed]>>>;
64
+ type fromTypeProps<t, props extends array<MappedTypeProp>> = show<{
65
+ [prop in props[number] as Extract<applyHomomorphicOptionality<t, prop>, {
66
+ kind: "required";
67
+ }>["key"]]: prop["value"][inferred];
68
+ } & {
69
+ [prop in props[number] as Extract<applyHomomorphicOptionality<t, prop>, {
70
+ kind: "optional";
71
+ default?: never;
72
+ }>["key"]]?: prop["value"][inferred];
49
73
  } & {
50
- [entry in entries[number] as Extract<applyHomomorphicOptionality<t, entry>, readonly [unknown, unknown, "optional"]>[0]]?: entry[1][inferred];
74
+ [prop in props[number] as Extract<applyHomomorphicOptionality<t, prop>, {
75
+ kind: "optional";
76
+ default: unknown;
77
+ }>["key"]]: (In?: prop["value"][inferred]) => Default<prop["default" & keyof prop]>;
51
78
  }>;
52
- type applyHomomorphicOptionality<t, entry extends MappedTypeEntry> = readonly [
53
- entry[0],
54
- entry[1],
55
- entry[2] extends string ? entry[2] : entry[0] extends optionalKeyOf<t> ? "optional" : "required"
56
- ];
79
+ type applyHomomorphicOptionality<t, prop extends MappedTypeProp> = prop["kind"] extends string ? prop : prop & {
80
+ kind: prop["key"] extends optionalKeyOf<t> ? "optional" : "required";
81
+ };
57
82
  export type { Type as ObjectType };
@@ -1,5 +1,5 @@
1
1
  import type { ExactLength, ExclusiveNumericRangeSchema, exclusivizeRangeSchema, InclusiveNumericRangeSchema, Pattern } from "@ark/schema";
2
- import type { applyConstraintSchema } from "../keywords/ast.ts";
2
+ import type { applyConstraintSchema } from "../keywords/inference.ts";
3
3
  import type { ValidatorType } from "./validator.ts";
4
4
  /** @ts-ignore cast variance */
5
5
  interface Type<out t extends string = string, $ = {}> extends ValidatorType<t, $> {
@@ -1,5 +1,5 @@
1
1
  import type { Predicate, PredicateCast } from "@ark/schema";
2
- import type { applyConstraintSchema } from "../keywords/ast.ts";
2
+ import type { applyConstraintSchema } from "../keywords/inference.ts";
3
3
  import type { BaseType } from "./base.ts";
4
4
  import type { instantiateType } from "./instantiate.ts";
5
5
  /** @ts-ignore cast variance */
@@ -1,8 +1,8 @@
1
1
  import type { writeUnboundableMessage } from "@ark/schema";
2
2
  import type { ErrorMessage, array, typeToString } from "@ark/util";
3
- import type { LimitLiteral } from "../../keywords/ast.ts";
4
- import type { Comparator } from "../string/reduce/shared.ts";
5
- import type { BoundExpressionKind, writeInvalidLimitMessage } from "../string/shift/operator/bounds.ts";
3
+ import type { LimitLiteral } from "../../keywords/inference.ts";
4
+ import type { Comparator } from "../reduce/shared.ts";
5
+ import type { BoundExpressionKind, writeInvalidLimitMessage } from "../shift/operator/bounds.ts";
6
6
  import type { inferAstIn } from "./infer.ts";
7
7
  import type { astToString } from "./utils.ts";
8
8
  import type { validateAst } from "./validate.ts";
@@ -1,7 +1,7 @@
1
1
  import type { writeUnassignableDefaultValueMessage } from "@ark/schema";
2
2
  import type { ErrorMessage } from "@ark/util";
3
- import type { type } from "../../keywords/ark.ts";
4
- import type { UnitLiteral } from "../string/shift/operator/default.ts";
3
+ import type { type } from "../../keywords/keywords.ts";
4
+ import type { UnitLiteral } from "../shift/operator/default.ts";
5
5
  import type { inferAstOut } from "./infer.ts";
6
6
  import type { astToString } from "./utils.ts";
7
7
  import type { validateAst } from "./validate.ts";
@@ -1,13 +1,11 @@
1
1
  import type { GenericAst } from "@ark/schema";
2
- import type { Hkt, array } from "@ark/util";
3
- import type { inferIntersection } from "../../intersect.ts";
4
- import type { arkKeyOf } from "../../keys.ts";
5
- import type { type } from "../../keywords/ark.ts";
6
- import type { Default, LimitLiteral, applyConstraintSchema, distill, normalizeLimit } from "../../keywords/ast.ts";
2
+ import type { Hkt, arkKeyOf, array } from "@ark/util";
7
3
  import type { Date } from "../../keywords/constructors/Date.ts";
4
+ import type { Default, LimitLiteral, Optional, applyConstraint, applyConstraintSchema, distill, inferIntersection, normalizeLimit } from "../../keywords/inference.ts";
5
+ import type { type } from "../../keywords/keywords.ts";
8
6
  import type { UnparsedScope } from "../../scope.ts";
9
7
  import type { inferDefinition } from "../definition.ts";
10
- import type { Comparator, MinComparator } from "../string/reduce/shared.ts";
8
+ import type { Comparator, MinComparator } from "../reduce/shared.ts";
11
9
  export type inferAstRoot<ast, $, args> = ast extends array ? inferExpression<ast, $, args> : never;
12
10
  export type inferAstIn<ast, $, args> = distill.In<inferAstRoot<ast, $, args>>;
13
11
  export type inferAstOut<ast, $, args> = distill.Out<inferAstRoot<ast, $, args>>;
@@ -27,14 +25,14 @@ export type inferExpression<ast, $, args> = ast extends array ? ast extends Infe
27
25
  [i in keyof argAsts]: inferExpression<argAsts[i], $, args>;
28
26
  }> : inferDefinition<g["bodyDef"], resolveScope<g["$"], $>, {
29
27
  [i in keyof g["names"] & `${number}` as g["names"][i]]: inferExpression<argAsts[i & keyof argAsts], resolveScope<g["arg$"], $>, args>;
30
- }> : ast[1] extends "[]" ? inferExpression<ast[0], $, args>[] : ast[1] extends "|" ? inferExpression<ast[0], $, args> | inferExpression<ast[2], $, args> : ast[1] extends "&" ? inferIntersection<inferExpression<ast[0], $, args>, inferExpression<ast[2], $, args>> : ast[1] extends "=" ? type.infer<ast[2]> extends infer defaultValue ? (In?: inferExpression<ast[0], $, args>) => Default<defaultValue> : never : ast[1] extends Comparator ? ast[0] extends LimitLiteral ? brandBound<inferExpression<ast[2], $, args>, ast[1], ast[0]> : brandBound<inferExpression<ast[0], $, args>, ast[1], ast[2] & LimitLiteral> : ast[1] extends "%" ? applyConstraintSchema<inferExpression<ast[0], $, args>, "divisor", ast[2] & number> : ast[0] extends "keyof" ? arkKeyOf<inferExpression<ast[1], $, args>> : never : never;
28
+ }> : ast[1] extends "[]" ? inferExpression<ast[0], $, args>[] : ast[1] extends "|" ? inferExpression<ast[0], $, args> | inferExpression<ast[2], $, args> : ast[1] extends "&" ? inferIntersection<inferExpression<ast[0], $, args>, inferExpression<ast[2], $, args>> : ast[1] extends "=" ? type.infer<ast[2]> extends infer defaultValue ? (In?: inferExpression<ast[0], $, args>) => Default<defaultValue> : never : ast[1] extends Comparator ? ast[0] extends LimitLiteral ? brandBound<inferExpression<ast[2], $, args>, ast[1], ast[0]> : brandBound<inferExpression<ast[0], $, args>, ast[1], ast[2] & LimitLiteral> : ast[1] extends "%" ? applyConstraintSchema<inferExpression<ast[0], $, args>, "divisor", ast[2] & number> : ast[1] extends "?" ? applyConstraint<inferExpression<ast[0], $, args>, Optional> : ast[0] extends "keyof" ? arkKeyOf<inferExpression<ast[1], $, args>> : never : never;
31
29
  export type brandBound<brandableIn, comparator extends Comparator, limit extends LimitLiteral> = distill.In<brandableIn> extends infer In ? comparator extends "==" ? In extends number ? limit : In extends Date ? Date.literal<normalizeLimit<limit>> : applyConstraintSchema<brandableIn, "exactLength", limit & number> : applyConstraintSchema<brandableIn, In extends number ? comparator extends MinComparator ? "min" : "max" : In extends string | array ? comparator extends MinComparator ? "minLength" : "maxLength" : comparator extends MinComparator ? "after" : "before", {
32
30
  rule: normalizeLimit<limit>;
33
31
  exclusive: comparator extends ">" | "<" ? true : false;
34
32
  }> : never;
35
33
  export type PrefixOperator = "keyof" | "instanceof" | "===" | "node";
36
34
  export type PrefixExpression<operator extends PrefixOperator = PrefixOperator, operand = unknown> = [operator, operand];
37
- export type PostfixOperator = "[]";
35
+ export type PostfixOperator = "[]" | "?";
38
36
  export type PostfixExpression<operator extends PostfixOperator = PostfixOperator, operand = unknown> = readonly [operand, operator];
39
37
  export type InfixOperator = "|" | "&" | Comparator | "%" | ":" | "=>" | "@" | "=";
40
38
  export type InfixExpression<operator extends InfixOperator = InfixOperator, l = unknown, r = unknown> = [l, operator, r];
@@ -1,4 +1,4 @@
1
1
  import type { Stringifiable } from "@ark/util";
2
- import type { Comparator } from "../string/reduce/shared.ts";
2
+ import type { Comparator } from "../reduce/shared.ts";
3
3
  import type { DefAst, InferredAst, InfixExpression, PostfixExpression } from "./infer.ts";
4
4
  export type astToString<ast> = ast extends InferredAst | DefAst ? ast[2] : ast extends PostfixExpression<infer operator, infer operand> ? operator extends "[]" ? `${astToString<operand>}[]` : never : ast extends InfixExpression<infer operator, infer l, infer r> ? operator extends "&" | "|" | "%" | Comparator ? `${astToString<l>} ${operator} ${astToString<r>}` : never : ast extends Stringifiable ? `${ast extends bigint ? `${ast}n` : ast}` : "...";
@@ -1,17 +1,17 @@
1
1
  import type { arkKind, GenericParamAst, PrivateDeclaration, writeMissingSubmoduleAccessMessage, writeUnsatisfiedParameterConstraintMessage } from "@ark/schema";
2
2
  import type { anyOrNever, array, BigintLiteral, charsAfterFirst, Completion, ErrorMessage, NumberLiteral, typeToString, writeMalformedNumericLiteralMessage } from "@ark/util";
3
3
  import type { Generic } from "../../generic.ts";
4
- import type { Comparator } from "../string/reduce/shared.ts";
5
- import type { writeInvalidGenericArgCountMessage } from "../string/shift/operand/genericArgs.ts";
6
- import type { UnitLiteral } from "../string/shift/operator/default.ts";
7
- import type { parseString } from "../string/string.ts";
4
+ import type { Comparator } from "../reduce/shared.ts";
5
+ import type { writeInvalidGenericArgCountMessage } from "../shift/operand/genericArgs.ts";
6
+ import type { UnitLiteral } from "../shift/operator/default.ts";
7
+ import type { parseString } from "../string.ts";
8
8
  import type { validateRange } from "./bounds.ts";
9
9
  import type { validateDefault } from "./default.ts";
10
10
  import type { validateDivisor } from "./divisor.ts";
11
11
  import type { DefAst, GenericInstantiationAst, inferAstRoot, InferredAst, InfixExpression, PostfixExpression } from "./infer.ts";
12
12
  import type { validateKeyof } from "./keyof.ts";
13
13
  import type { astToString } from "./utils.ts";
14
- export type validateAst<ast, $, args> = ast extends ErrorMessage ? ast : ast extends InferredAst ? validateInferredAst<ast[0], ast[2]> : ast extends DefAst ? ast[2] extends PrivateDeclaration ? ErrorMessage<writePrefixedPrivateReferenceMessage<ast[2]>> : undefined : ast extends PostfixExpression<infer operator, infer operand> ? operator extends "[]" ? validateAst<operand, $, args> : never : ast extends InfixExpression<infer operator, infer l, infer r> ? operator extends "&" | "|" ? validateInfix<ast, $, args> : operator extends Comparator ? validateRange<l, operator, r, $, args> : operator extends "%" ? validateDivisor<l, $, args> : operator extends "=" ? validateDefault<l, r & UnitLiteral, $, args> : never : ast extends ["keyof", infer operand] ? validateKeyof<operand, $, args> : ast extends GenericInstantiationAst<infer g, infer argAsts> ? validateGenericArgs<g["paramsAst"], argAsts, $, args, []> : ErrorMessage<writeUnexpectedExpressionMessage<astToString<ast>>> & {
14
+ export type validateAst<ast, $, args> = ast extends ErrorMessage ? ast : ast extends InferredAst ? validateInferredAst<ast[0], ast[2]> : ast extends DefAst ? ast[2] extends PrivateDeclaration ? ErrorMessage<writePrefixedPrivateReferenceMessage<ast[2]>> : undefined : ast extends PostfixExpression<infer operator, infer operand> ? operator extends "[]" ? validateAst<operand, $, args> : operator extends "?" ? validateAst<operand, $, args> : never : ast extends InfixExpression<infer operator, infer l, infer r> ? operator extends "&" | "|" ? validateInfix<ast, $, args> : operator extends Comparator ? validateRange<l, operator, r, $, args> : operator extends "%" ? validateDivisor<l, $, args> : operator extends "=" ? validateDefault<l, r & UnitLiteral, $, args> : never : ast extends ["keyof", infer operand] ? validateKeyof<operand, $, args> : ast extends GenericInstantiationAst<infer g, infer argAsts> ? validateGenericArgs<g["paramsAst"], argAsts, $, args, []> : ErrorMessage<writeUnexpectedExpressionMessage<astToString<ast>>> & {
15
15
  ast: ast;
16
16
  };
17
17
  type writeUnexpectedExpressionMessage<expression extends string> = `Unexpectedly failed to parse the expression resulting from ${expression}`;
@@ -1,16 +1,16 @@
1
1
  import { type BaseParseContext, type BaseRoot } from "@ark/schema";
2
2
  import { type ErrorMessage, type Fn, type Primitive, type anyOrNever, type array, type defined, type equals, type ifEmptyObjectLiteral, type objectKindOrDomainOf, type optionalKeyOf, type requiredKeyOf, type show } from "@ark/util";
3
- import type { type } from "../keywords/ark.ts";
3
+ import type { type } from "../keywords/keywords.ts";
4
4
  import type { string } from "../keywords/string/string.ts";
5
+ import type { validateString } from "./ast/validate.ts";
5
6
  import { type inferObjectLiteral, type validateObjectLiteral } from "./objectLiteral.ts";
6
- import type { validateString } from "./semantic/validate.ts";
7
- import type { BaseCompletions, inferString } from "./string/string.ts";
7
+ import type { BaseCompletions, inferString } from "./string.ts";
8
8
  import { type TupleExpression, type inferTuple, type validateTuple } from "./tuple.ts";
9
9
  export declare const parseObject: (def: object, ctx: BaseParseContext) => BaseRoot;
10
10
  export type inferDefinition<def, $, args> = [
11
11
  def
12
12
  ] extends [anyOrNever] ? def : def extends type.cast<infer t> ? ifEmptyObjectLiteral<def, object, t> : def extends ThunkCast<infer t> ? t : def extends string ? inferString<def, $, args> : def extends array ? inferTuple<def, $, args> : def extends RegExp ? string.matching<string> : def extends object ? inferObjectLiteral<def, $, args> : never;
13
- export type validateDefinition<def, $, args> = null extends undefined ? ErrorMessage<`'strict' or 'strictNullChecks' must be set to true in your tsconfig's 'compilerOptions'`> : [def] extends [Terminal] ? def : def extends string ? validateString<def, $, args> : def extends array ? validateTuple<def, $, args> : def extends BadDefinitionType ? ErrorMessage<writeBadDefinitionTypeMessage<objectKindOrDomainOf<def>>> : unknown extends def ? BaseCompletions<$, args> | {} : validateObjectLiteral<def, $, args>;
13
+ export type validateDefinition<def, $, args> = null extends undefined ? ErrorMessage<`'strict' or 'strictNullChecks' must be set to true in your tsconfig's 'compilerOptions'`> : [def] extends [Terminal] ? def : def extends string ? validateString<def, $, args> : def extends array ? validateTuple<def, $, args> : def extends BadDefinitionType ? ErrorMessage<writeBadDefinitionTypeMessage<objectKindOrDomainOf<def>>> : unknown extends def ? BaseCompletions<$, args> | {} : RegExp extends def ? def : validateObjectLiteral<def, $, args>;
14
14
  export type validateDeclared<declared, def, $, args> = def extends validateDefinition<def, $, args> ? validateInference<def, declared, $, args> : validateDefinition<def, $, args>;
15
15
  type validateInference<def, declared, $, args> = def extends RegExp | type.cast<unknown> | ThunkCast | TupleExpression ? validateShallowInference<def, declared, $, args> : def extends array ? declared extends array ? {
16
16
  [i in keyof declared]: i extends keyof def ? validateInference<def[i], declared[i], $, args> : declared[i];
@@ -24,7 +24,7 @@ type declarationMismatch<def, declared, $, args> = {
24
24
  declared: declared;
25
25
  inferred: inferDefinition<def, $, args>;
26
26
  };
27
- type Terminal = RegExp | type.cast<unknown> | Fn;
27
+ type Terminal = type.cast<unknown> | Fn;
28
28
  export type ThunkCast<t = unknown> = () => type.cast<t>;
29
29
  type BadDefinitionType = Exclude<Primitive, string>;
30
30
  export declare const writeBadDefinitionTypeMessage: <actual extends string>(actual: actual) => writeBadDefinitionTypeMessage<actual>;
@@ -1,9 +1,9 @@
1
1
  import { type BaseParseContext, type BaseRoot, type Index, type Optional, type Required, type UndeclaredKeyBehavior, type writeInvalidPropertyKeyMessage } from "@ark/schema";
2
2
  import { type anyOrNever, type Dict, type ErrorMessage, type ErrorType, type EscapeToken, type Key, type listable, type merge, type show } from "@ark/util";
3
- import type { constrain } from "../keywords/ast.ts";
3
+ import type { constrain } from "../keywords/inference.ts";
4
+ import type { astToString } from "./ast/utils.ts";
5
+ import type { validateString } from "./ast/validate.ts";
4
6
  import type { inferDefinition, validateDefinition } from "./definition.ts";
5
- import type { astToString } from "./semantic/utils.ts";
6
- import type { validateString } from "./semantic/validate.ts";
7
7
  export declare const parseObjectLiteral: (def: Dict, ctx: BaseParseContext) => BaseRoot;
8
8
  export declare const writeInvalidUndeclaredBehaviorMessage: (actual: unknown) => string;
9
9
  export declare const nonLeadingSpreadError = "Spread operator may only be used as the first key in an object";
@@ -1,7 +1,7 @@
1
1
  import type { BaseParseContext, BaseRoot } from "@ark/schema";
2
2
  import { type requireKeys } from "@ark/util";
3
- import type { LimitLiteral } from "../../../keywords/ast.ts";
4
- import type { InfixOperator } from "../../semantic/infer.ts";
3
+ import type { LimitLiteral } from "../../keywords/inference.ts";
4
+ import type { InfixOperator } from "../ast/infer.ts";
5
5
  import type { Scanner } from "../shift/scanner.ts";
6
6
  import { type Comparator, type MinComparator, type OpenLeftBound, type StringifiablePrefixOperator } from "./shared.ts";
7
7
  type BranchState = {
@@ -1,4 +1,4 @@
1
- import type { LimitLiteral } from "../../../keywords/ast.ts";
1
+ import type { LimitLiteral } from "../../keywords/inference.ts";
2
2
  export type StringifiablePrefixOperator = "keyof";
3
3
  export declare const minComparators: {
4
4
  readonly ">": true;
@@ -1,5 +1,5 @@
1
1
  import type { Completion, ErrorMessage, defined } from "@ark/util";
2
- import type { LimitLiteral } from "../../../keywords/ast.ts";
2
+ import type { LimitLiteral } from "../../keywords/inference.ts";
3
3
  import type { Scanner } from "../shift/scanner.ts";
4
4
  import type { Comparator, InvertedComparators, MaxComparator, MinComparator, OpenLeftBound, StringifiablePrefixOperator, writeMultipleLeftBoundsMessage, writeOpenRangeMessage, writeUnclosedGroupMessage, writeUnmatchedGroupCloseMessage, writeUnpairableComparatorMessage } from "./shared.ts";
5
5
  export type StaticState = {
@@ -1,4 +1,4 @@
1
- import type { DateLiteral } from "../../../../keywords/ast.ts";
1
+ import type { DateLiteral } from "../../../keywords/inference.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>;
@@ -1,6 +1,6 @@
1
- import type { string } from "../../../../keywords/ast.ts";
2
- import type { Date } from "../../../../keywords/constructors/Date.ts";
3
- import type { InferredAst } from "../../../semantic/infer.ts";
1
+ import type { Date } from "../../../keywords/constructors/Date.ts";
2
+ import type { string } from "../../../keywords/inference.ts";
3
+ import type { InferredAst } from "../../ast/infer.ts";
4
4
  import type { DynamicState } from "../../reduce/dynamic.ts";
5
5
  import type { StaticState, state } from "../../reduce/static.ts";
6
6
  import type { Scanner } from "../scanner.ts";
@@ -1,8 +1,8 @@
1
1
  import { writeUnresolvableMessage, type BaseRoot, type GenericAst, type GenericRoot, type arkKind, type genericParamNames, type resolvableReferenceIn, type writeNonSubmoduleDotMessage } from "@ark/schema";
2
2
  import { type BigintLiteral, type NumberLiteral, type join, type lastOf } from "@ark/util";
3
- import type { ArkAmbient } from "../../../../config.ts";
4
- import type { resolutionToAst } from "../../../../scope.ts";
5
- import type { GenericInstantiationAst, InferredAst } from "../../../semantic/infer.ts";
3
+ import type { ArkAmbient } from "../../../config.ts";
4
+ import type { resolutionToAst } from "../../../scope.ts";
5
+ import type { GenericInstantiationAst, InferredAst } from "../../ast/infer.ts";
6
6
  import type { DynamicState } from "../../reduce/dynamic.ts";
7
7
  import type { StaticState, state } from "../../reduce/static.ts";
8
8
  import type { BaseCompletions } from "../../string.ts";
@@ -1,6 +1,6 @@
1
1
  import { hasArkKind, writeUnresolvableMessage } from "@ark/schema";
2
2
  import { printable, throwParseError, tryParseWellFormedBigint, tryParseWellFormedNumber } from "@ark/util";
3
- import { writePrefixedPrivateReferenceMessage } from "../../../semantic/validate.js";
3
+ import { writePrefixedPrivateReferenceMessage } from "../../ast/validate.js";
4
4
  import { parseGenericArgs, writeInvalidGenericArgCountMessage } from "./genericArgs.js";
5
5
  export const parseUnenclosed = (s) => {
6
6
  const token = s.scanner.shiftUntilNextTerminator();
@@ -1,8 +1,8 @@
1
1
  import { type BaseRoot, type BoundKind } from "@ark/schema";
2
2
  import { type keySet } from "@ark/util";
3
- import type { DateLiteral } from "../../../../keywords/ast.ts";
4
- import type { InferredAst } from "../../../semantic/infer.ts";
5
- import type { astToString } from "../../../semantic/utils.ts";
3
+ import type { DateLiteral } from "../../../keywords/inference.ts";
4
+ import type { InferredAst } from "../../ast/infer.ts";
5
+ import type { astToString } from "../../ast/utils.ts";
6
6
  import type { DynamicState, DynamicStateWithRoot } from "../../reduce/dynamic.ts";
7
7
  import { writeUnpairableComparatorMessage, type Comparator, type InvertedComparators, type MaxComparator } from "../../reduce/shared.ts";
8
8
  import type { state, StaticState } from "../../reduce/static.ts";
@@ -1,6 +1,6 @@
1
1
  import type { BaseRoot } from "@ark/schema";
2
2
  import type { BigintLiteral, ErrorMessage, NumberLiteral, trim } from "@ark/util";
3
- import type { DateLiteral } from "../../../../keywords/ast.ts";
3
+ import type { DateLiteral } from "../../../keywords/inference.ts";
4
4
  import type { DynamicStateWithRoot } from "../../reduce/dynamic.ts";
5
5
  import type { StringLiteral } from "../operand/enclosed.ts";
6
6
  type UnitLiteralKeyword = "null" | "undefined" | "true" | "false";
@@ -34,19 +34,21 @@ export declare class Scanner<lookahead extends string = string> {
34
34
  readonly "%": true;
35
35
  readonly ",": true;
36
36
  readonly ":": true;
37
+ readonly "?": true;
37
38
  };
38
39
  static finalizingLookaheads: {
39
40
  readonly ">": true;
40
41
  readonly ",": true;
41
42
  readonly "": true;
42
43
  readonly "=": true;
44
+ readonly "?": true;
43
45
  };
44
46
  static lookaheadIsTerminator: Scanner.UntilCondition;
45
47
  static lookaheadIsNotWhitespace: Scanner.UntilCondition;
46
48
  static lookaheadIsFinalizing: (lookahead: string, unscanned: string) => lookahead is ">" | "," | "=";
47
49
  }
48
50
  export declare namespace Scanner {
49
- 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;
51
+ 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;
50
52
  type UntilCondition = (scanner: Scanner, shifted: string) => boolean;
51
53
  type OnInputEndFn = (scanner: Scanner, shifted: string) => string;
52
54
  type ShiftUntilOptions = {
@@ -74,13 +74,15 @@ export class Scanner {
74
74
  "%": true,
75
75
  ",": true,
76
76
  ":": true,
77
+ "?": true,
77
78
  ...whiteSpaceTokens
78
79
  };
79
80
  static finalizingLookaheads = {
80
81
  ">": true,
81
82
  ",": true,
82
83
  "": true,
83
- "=": true
84
+ "=": true,
85
+ "?": true
84
86
  };
85
87
  static lookaheadIsTerminator = (scanner) => scanner.lookahead in this.terminatingChars;
86
88
  static lookaheadIsNotWhitespace = (scanner) => !(scanner.lookahead in whiteSpaceTokens);
@@ -95,6 +97,6 @@ export class Scanner {
95
97
  // "=" is a finalizer on its own (representing a default value),
96
98
  // but not with a second "=" (an equality comparator)
97
99
  : lookahead === "=" ? unscanned[0] !== "="
98
- // ","" is unambiguously a finalizer
99
- : lookahead === ",";
100
+ // "," and "?" are unambiguously finalizers
101
+ : lookahead === "," || lookahead === "?";
100
102
  }