arktype 2.0.0-rc.11 → 2.0.0-rc.13

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 (50) hide show
  1. package/out/keywords/constructors/Date.d.ts +12 -12
  2. package/out/keywords/inference.d.ts +42 -89
  3. package/out/keywords/inference.js +1 -1
  4. package/out/keywords/number/number.d.ts +16 -12
  5. package/out/keywords/string/alpha.d.ts +2 -2
  6. package/out/keywords/string/alphanumeric.d.ts +2 -2
  7. package/out/keywords/string/brands.d.ts +17 -0
  8. package/out/keywords/string/capitalize.d.ts +2 -2
  9. package/out/keywords/string/creditCard.d.ts +2 -2
  10. package/out/keywords/string/date.d.ts +4 -4
  11. package/out/keywords/string/digits.d.ts +2 -2
  12. package/out/keywords/string/email.d.ts +2 -2
  13. package/out/keywords/string/integer.d.ts +2 -2
  14. package/out/keywords/string/ip.d.ts +4 -4
  15. package/out/keywords/string/json.d.ts +2 -2
  16. package/out/keywords/string/lower.d.ts +2 -2
  17. package/out/keywords/string/normalize.d.ts +5 -5
  18. package/out/keywords/string/numeric.d.ts +2 -2
  19. package/out/keywords/string/semver.d.ts +2 -2
  20. package/out/keywords/string/string.d.ts +14 -13
  21. package/out/keywords/string/trim.d.ts +2 -2
  22. package/out/keywords/string/upper.d.ts +2 -2
  23. package/out/keywords/string/url.d.ts +2 -2
  24. package/out/keywords/string/uuid.d.ts +10 -10
  25. package/out/methods/base.d.ts +24 -21
  26. package/out/methods/instantiate.d.ts +3 -3
  27. package/out/methods/morph.d.ts +2 -6
  28. package/out/methods/number.d.ts +2 -2
  29. package/out/methods/object.d.ts +8 -11
  30. package/out/methods/string.d.ts +2 -2
  31. package/out/parser/ast/default.d.ts +2 -2
  32. package/out/parser/ast/infer.d.ts +5 -6
  33. package/out/parser/ast/validate.d.ts +5 -5
  34. package/out/parser/ast/validate.js +1 -1
  35. package/out/parser/objectLiteral.d.ts +2 -2
  36. package/out/parser/reduce/dynamic.d.ts +1 -2
  37. package/out/parser/shift/operand/unenclosed.d.ts +5 -1
  38. package/out/parser/shift/operand/unenclosed.js +5 -4
  39. package/out/parser/shift/operator/brand.d.ts +6 -0
  40. package/out/parser/shift/operator/brand.js +5 -0
  41. package/out/parser/shift/operator/default.js +4 -1
  42. package/out/parser/shift/operator/operator.d.ts +2 -1
  43. package/out/parser/shift/operator/operator.js +4 -2
  44. package/out/parser/shift/scanner.d.ts +3 -2
  45. package/out/parser/shift/scanner.js +1 -0
  46. package/out/parser/tuple.d.ts +6 -5
  47. package/out/type.d.ts +2 -2
  48. package/package.json +3 -3
  49. package/out/methods/validator.d.ts +0 -11
  50. /package/out/{methods/validator.js → keywords/string/brands.js} +0 -0
@@ -1,5 +1,5 @@
1
1
  import type { Module, Submodule } from "../../module.ts";
2
- import type { Branded, constrain } from "../inference.ts";
2
+ import type { Predicate, of } from "../inference.ts";
3
3
  export declare const uuid: Module<{
4
4
  root: import("./string.ts").string.matching<string> | "00000000-0000-0000-0000-000000000000" | "ffffffff-ffff-ffff-ffff-ffffffffffff";
5
5
  v4: unknown;
@@ -12,16 +12,16 @@ export declare const uuid: Module<{
12
12
  v8: unknown;
13
13
  }>;
14
14
  declare namespace string {
15
- type uuid = constrain<string, Branded<"uuid">>;
15
+ type uuid = of<string, Predicate<"uuid">>;
16
16
  namespace uuid {
17
- type v1 = constrain<string, Branded<"uuid.v1">>;
18
- type v2 = constrain<string, Branded<"uuid.v2">>;
19
- type v3 = constrain<string, Branded<"uuid.v3">>;
20
- type v4 = constrain<string, Branded<"uuid.v4">>;
21
- type v5 = constrain<string, Branded<"uuid.v5">>;
22
- type v6 = constrain<string, Branded<"uuid.v6">>;
23
- type v7 = constrain<string, Branded<"uuid.v7">>;
24
- type v8 = constrain<string, Branded<"uuid.v8">>;
17
+ type v1 = of<string, Predicate<"uuid.v1">>;
18
+ type v2 = of<string, Predicate<"uuid.v2">>;
19
+ type v3 = of<string, Predicate<"uuid.v3">>;
20
+ type v4 = of<string, Predicate<"uuid.v4">>;
21
+ type v5 = of<string, Predicate<"uuid.v5">>;
22
+ type v6 = of<string, Predicate<"uuid.v6">>;
23
+ type v7 = of<string, Predicate<"uuid.v7">>;
24
+ type v8 = of<string, Predicate<"uuid.v8">>;
25
25
  }
26
26
  }
27
27
  export declare namespace uuid {
@@ -1,13 +1,14 @@
1
- import type { ArkErrors, BaseRoot, Disjoint, JsonSchema, MetaSchema, Morph, UndeclaredKeyBehavior } from "@ark/schema";
1
+ import type { ArkErrors, BaseRoot, Disjoint, JsonSchema, MetaSchema, Morph, PredicateCast, Predicate as PredicateFn, 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 { applyConstraint, Default, distill, inferIntersection, inferMorphOut, inferPipes, InferredMorph, Optional, To } from "../keywords/inference.ts";
4
+ import type { applyAttribute, applyConstraintSchema, Default, DefaultFor, distill, inferIntersection, inferMorphOut, inferPipes, InferredMorph, Optional, Out, To } from "../keywords/inference.ts";
5
5
  import type { type } from "../keywords/keywords.ts";
6
6
  import type { Scope } from "../scope.ts";
7
7
  import type { ArrayType } from "./array.ts";
8
8
  import type { instantiateType } from "./instantiate.ts";
9
9
  /** @ts-ignore cast variance */
10
10
  interface Type<out t = unknown, $ = {}> extends Callable<(data: unknown) => distill.Out<t> | ArkErrors> {
11
+ [inferred]: t;
11
12
  t: t;
12
13
  infer: this["inferOut"];
13
14
  inferBrandableIn: distill.brandable.In<t>;
@@ -17,8 +18,7 @@ interface Type<out t = unknown, $ = {}> extends Callable<(data: unknown) => dist
17
18
  inferIn: distill.In<t>;
18
19
  inferredOutIsIntrospectable: t extends InferredMorph<any, infer o> ? [
19
20
  o
20
- ] extends [anyOrNever] ? true : o extends To ? true : false : true;
21
- [inferred]: t;
21
+ ] extends [anyOrNever] ? true : o extends To ? true : false : unknown extends t ? boolean : true;
22
22
  json: Json;
23
23
  toJSON(): Json;
24
24
  meta: ArkAmbient.meta;
@@ -31,6 +31,7 @@ interface Type<out t = unknown, $ = {}> extends Callable<(data: unknown) => dist
31
31
  assert(data: unknown): this["infer"];
32
32
  allows(data: unknown): data is this["inferIn"];
33
33
  traverse(data: unknown): this["infer"] | ArkErrors;
34
+ brandable(): this;
34
35
  configure(meta: MetaSchema): this;
35
36
  describe(description: string): this;
36
37
  onUndeclaredKey(behavior: UndeclaredKeyBehavior): this;
@@ -39,21 +40,23 @@ interface Type<out t = unknown, $ = {}> extends Callable<(data: unknown) => dist
39
40
  as<t = unset>(...args: validateChainedAsArgs<t>): instantiateType<t, $>;
40
41
  get in(): instantiateType<this["inferBrandableIn"], $>;
41
42
  get out(): instantiateType<this["inferIntrospectableOut"], $>;
42
- intersect<const def>(def: type.validate<def, $>): type.infer<def, $> extends infer r ? instantiateType<inferIntersection<t, r>, $> | Disjoint : never;
43
- and<const def>(def: type.validate<def, $>): type.infer<def, $> extends infer r ? instantiateType<inferIntersection<t, r>, $> : never;
44
- or<const def>(def: type.validate<def, $>): type.infer<def, $> extends infer r ? instantiateType<t | r, $> : never;
43
+ intersect<const def, r = type.infer<def, $>>(def: type.validate<def, $>): instantiateType<inferIntersection<t, r>, $> | Disjoint;
44
+ and<const def, r = type.infer<def, $>>(def: type.validate<def, $>): instantiateType<inferIntersection<t, r>, $>;
45
+ or<const def, r = type.infer<def, $>>(def: type.validate<def, $>): instantiateType<t | r, $>;
46
+ narrow<narrowed extends this["infer"] = never, r = [narrowed] extends [never] ? t extends InferredMorph<infer i, infer o> ? o extends To ? (In: i) => To<applyConstraintSchema<o[1], "predicate", PredicateFn>> : (In: i) => Out<applyConstraintSchema<o[1], "predicate", PredicateFn>> : applyConstraintSchema<t, "predicate", PredicateFn> : t extends InferredMorph<infer i, infer o> ? o extends To ? (In: i) => To<narrowed> : (In: i) => Out<narrowed> : narrowed>(predicate: PredicateFn<this["infer"]> | PredicateCast<this["infer"], narrowed>): instantiateType<r, $>;
47
+ satisfying<narrowed extends this["inferIn"] = never, r = [narrowed] extends [never] ? applyConstraintSchema<t, "predicate", PredicateFn> : t extends InferredMorph<any, infer o> ? (In: narrowed) => o : narrowed>(predicate: PredicateFn<this["inferIn"]> | PredicateCast<this["inferIn"], narrowed>): instantiateType<r, $>;
45
48
  array(): ArrayType<t[], $>;
46
49
  pipe: ChainedPipes<t, $>;
47
50
  equals<const def>(def: type.validate<def, $>): boolean;
48
- ifEquals<const def>(def: type.validate<def, $>): type.infer<def, $> extends infer r ? instantiateType<r, $> | undefined : never;
51
+ ifEquals<const def, r = type.infer<def, $>>(def: type.validate<def, $>): instantiateType<r, $> | undefined;
49
52
  extends<const def>(other: type.validate<def, $>): boolean;
50
- ifExtends<const def>(other: type.validate<def, $>): type.infer<def, $> extends infer r ? instantiateType<r, $> | undefined : never;
53
+ ifExtends<const def, r = type.infer<def, $>>(other: type.validate<def, $>): instantiateType<r, $> | undefined;
51
54
  overlaps<const def>(r: type.validate<def, $>): boolean;
52
- extract<const def>(r: type.validate<def, $>): type.infer<def, $> extends infer r ? instantiateType<Extract<t, r>, $> : never;
53
- exclude<const def>(r: type.validate<def, $>): type.infer<def, $> extends infer r ? instantiateType<Exclude<t, r>, $> : never;
54
- distribute<mapOut, reduceOut = mapOut[]>(mapBranch: (branch: Type, i: number, branches: array<Type>) => mapOut, reduceMapped?: (mappedBranches: mapOut[]) => reduceOut): NoInfer<reduceOut>;
55
- optional<r = applyConstraint<t, Optional>>(): instantiateType<r, $>;
56
- default<const value extends this["inferIn"], r = applyConstraint<t, Default<value>>>(value: value): instantiateType<r, $>;
55
+ extract<const def, r = type.infer<def, $>>(r: type.validate<def, $>): instantiateType<Extract<t, r>, $>;
56
+ exclude<const def, r = type.infer<def, $>>(r: type.validate<def, $>): instantiateType<Exclude<t, r>, $>;
57
+ distribute<mapOut, reduceOut = mapOut[]>(mapBranch: (branch: Type, i: number, branches: array<Type>) => mapOut, reduceMapped?: (mappedBranches: mapOut[]) => reduceOut): reduceOut;
58
+ optional<r = applyAttribute<t, Optional>>(): instantiateType<r, $>;
59
+ default<const value extends this["inferIn"], r = applyAttribute<t, Default<value>>>(value: DefaultFor<value>): instantiateType<r, $>;
57
60
  /** @deprecated */
58
61
  apply: Function["apply"];
59
62
  /** @deprecated */
@@ -74,13 +77,13 @@ interface Type<out t = unknown, $ = {}> extends Callable<(data: unknown) => dist
74
77
  Symbol: never;
75
78
  }
76
79
  interface ChainedPipeSignature<t, $> {
77
- <a extends Morph<distill.Out<t>>, r = instantiateType<inferPipes<t, [a]>, $>>(a: a): NoInfer<r>;
78
- <a extends Morph<distill.Out<t>>, b extends Morph<inferMorphOut<a>>, r = instantiateType<inferPipes<t, [a, b]>, $>>(a: a, b: b): NoInfer<r>;
79
- <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>;
80
- <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>;
81
- <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>;
82
- <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>;
83
- <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>;
80
+ <a extends Morph<distill.Out<t>>, r = instantiateType<inferPipes<t, [a]>, $>>(a: a): NoInfer<r> extends infer result ? result : never;
81
+ <a extends Morph<distill.Out<t>>, b extends Morph<inferMorphOut<a>>, r = instantiateType<inferPipes<t, [a, b]>, $>>(a: a, b: b): NoInfer<r> extends infer result ? result : never;
82
+ <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> extends infer result ? result : never;
83
+ <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> extends infer result ? result : never;
84
+ <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> extends infer result ? result : never;
85
+ <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> extends infer result ? result : never;
86
+ <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> extends infer result ? result : never;
84
87
  }
85
88
  export interface ChainedPipes<t, $> extends ChainedPipeSignature<t, $> {
86
89
  try: ChainedPipeSignature<t, $>;
@@ -7,11 +7,11 @@ import type { MorphType } from "./morph.ts";
7
7
  import type { NumberType } from "./number.ts";
8
8
  import type { ObjectType } from "./object.ts";
9
9
  import type { StringType } from "./string.ts";
10
- import type { ValidatorType } from "./validator.ts";
11
- export type instantiateType<t, $> = [
10
+ export type instantiateType<t, $> = NoInfer<_instantiateType<t, $>> extends infer r ? r : never;
11
+ export type _instantiateType<t, $> = [
12
12
  Extract<t, InferredMorph>
13
13
  ] extends [anyOrNever] ? [
14
14
  t
15
15
  ] extends [anyOrNever] ? BaseType<t, $> : [t] extends [string] ? StringType<t, $> : [t] extends [number] ? NumberType<t, $> : [t] extends [object] ? [
16
16
  t
17
- ] extends [array] ? ArrayType<t, $> : [t] extends [Date] ? DateType<t, $> : ObjectType<t, $> : unknown extends t ? BaseType<unknown, $> : ValidatorType<t, $> : MorphType<t, $>;
17
+ ] extends [array] ? ArrayType<t, $> : [t] extends [Date] ? DateType<t, $> : ObjectType<t, $> : BaseType<t, $> : MorphType<t, $>;
@@ -1,12 +1,8 @@
1
- import type { Predicate, PredicateCast } from "@ark/schema";
2
- import type { applyConstraintSchema, inferPipe, Out, To } from "../keywords/inference.ts";
1
+ import type { inferPipe } from "../keywords/inference.ts";
3
2
  import type { type } from "../keywords/keywords.ts";
4
3
  import type { BaseType } from "./base.ts";
5
4
  /** @ts-ignore cast variance */
6
5
  interface Type<out t = unknown, $ = {}> extends BaseType<t, $> {
7
- to<const def, r = type.infer<def, $>>(def: type.validate<def, $>): Type<inferPipe<t, NoInfer<r>>, $>;
8
- narrow<narrowed extends this["infer"] = never>(predicate: Predicate<this["infer"]> | PredicateCast<this["infer"], narrowed>): Type<([
9
- narrowed
10
- ] extends [never] ? applyConstraintSchema<this["inferBrandableOut"], "predicate", Predicate> : narrowed) extends infer o ? this["inferredOutIsIntrospectable"] extends true ? (In: this["inferBrandableIn"]) => To<o> : (In: this["inferBrandableIn"]) => Out<o> : never, $>;
6
+ to<const def, r = type.infer<def, $>>(def: type.validate<def, $>): Type<inferPipe<t, r>, $>;
11
7
  }
12
8
  export type { Type as MorphType };
@@ -1,8 +1,8 @@
1
1
  import type { Divisor, ExclusiveNumericRangeSchema, exclusivizeRangeSchema, InclusiveNumericRangeSchema } from "@ark/schema";
2
2
  import type { applyConstraintSchema } from "../keywords/inference.ts";
3
- import type { ValidatorType } from "./validator.ts";
3
+ import type { BaseType } from "./base.ts";
4
4
  /** @ts-ignore cast variance */
5
- interface Type<out t extends number = number, $ = {}> extends ValidatorType<t, $> {
5
+ interface Type<out t extends number = number, $ = {}> extends BaseType<t, $> {
6
6
  divisibleBy<const schema extends Divisor.Schema>(schema: schema): Type<applyConstraintSchema<t, "divisor", schema>, $>;
7
7
  atLeast<const schema extends InclusiveNumericRangeSchema>(schema: schema): Type<applyConstraintSchema<t, "min", schema>, $>;
8
8
  atMost<const schema extends InclusiveNumericRangeSchema>(schema: schema): Type<applyConstraintSchema<t, "max", schema>, $>;
@@ -1,28 +1,28 @@
1
1
  import type { BaseMappedPropInner, OptionalMappedPropInner, Prop } from "@ark/schema";
2
2
  import type { arkGet, arkIndexableOf, arkKeyOf, array, ErrorType, inferred, intersectUnion, Json, Key, listable, merge, optionalKeyOf, show, toArkKey } from "@ark/util";
3
- import type { applyConstraint, constrain, Default, Optional, parseConstraints } from "../keywords/inference.ts";
3
+ import type { applyAttribute, Default, of, Optional } from "../keywords/inference.ts";
4
4
  import type { type } from "../keywords/keywords.ts";
5
5
  import type { ArrayType } from "./array.ts";
6
+ import type { BaseType } from "./base.ts";
6
7
  import type { instantiateType } from "./instantiate.ts";
7
- import type { ValidatorType } from "./validator.ts";
8
8
  /** @ts-ignore cast variance */
9
- interface Type<out t extends object = object, $ = {}> extends ValidatorType<t, $> {
9
+ interface Type<out t extends object = object, $ = {}> extends BaseType<t, $> {
10
10
  readonly(): t extends array ? ArrayType<{
11
11
  readonly [i in keyof t]: t[i];
12
12
  }, $> : Type<{
13
13
  readonly [k in keyof t]: t[k];
14
14
  }, $>;
15
15
  keyof(): instantiateType<arkKeyOf<t>, $>;
16
- get<const k1 extends arkIndexableOf<t>>(k1: k1 | type.cast<k1>): instantiateType<arkGet<t, k1>, $> extends infer r ? r : never;
16
+ get<const k1 extends arkIndexableOf<t>, r = arkGet<t, k1>>(k1: k1 | type.cast<k1>): instantiateType<r, $>;
17
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
+ get<const k1 extends arkIndexableOf<t>, const k2 extends arkIndexableOf<arkGet<t, k1>>, const k3 extends arkIndexableOf<arkGet<arkGet<t, k1>, k2>>, r = arkGet<arkGet<arkGet<t, k1>, k2>, k3>>(k1: k1 | type.cast<k1>, k2: k2 | type.cast<k2>, k3: k3 | type.cast<k3>): instantiateType<r, $>;
19
19
  pick<const key extends arkKeyOf<t> = never>(...keys: (key | type.cast<key>)[]): Type<{
20
20
  [k in keyof t as Extract<toArkKey<t, k>, key>]: t[k];
21
21
  }, $>;
22
22
  omit<const key extends arkKeyOf<t> = never>(...keys: (key | type.cast<key>)[]): Type<{
23
23
  [k in keyof t as Exclude<toArkKey<t, k>, key>]: t[k];
24
24
  }, $>;
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
+ 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>, $>;
26
26
  required(): Type<{
27
27
  [k in keyof t]-?: t[k];
28
28
  }, $>;
@@ -33,10 +33,7 @@ interface Type<out t extends object = object, $ = {}> extends ValidatorType<t, $
33
33
  props: array<typePropOf<t, $>>;
34
34
  }
35
35
  type typePropOf<o, $> = keyof o extends infer k ? k extends keyof o ? typeProp<o, k, $> : never : never;
36
- type typeProp<o, k extends keyof o, $, t = o[k] & ({} | null)> = parseConstraints<t> extends ([
37
- infer base,
38
- infer constraints extends Default | Optional
39
- ]) ? constraints extends Default<infer defaultValue> ? DefaultedTypeProp<k & Key, keyof constraints extends keyof Default ? base : constrain<base, Omit<constraints, keyof Default>>, defaultValue, $> : constraints extends Optional ? BaseTypeProp<"optional", k & Key, keyof constraints extends keyof Optional ? base : constrain<base, Omit<constraints, keyof Optional>>, $> : never : BaseTypeProp<k extends optionalKeyOf<o> ? "optional" : "required", k & Key, t, $>;
36
+ type typeProp<o, k extends keyof o, $, t = o[k] & ({} | null)> = t extends of<infer base, infer attributes> ? attributes extends Default<infer defaultValue> ? DefaultedTypeProp<k & Key, keyof attributes extends keyof Default ? base : of<base, Omit<attributes, keyof Default>>, defaultValue, $> : attributes extends Optional ? BaseTypeProp<"optional", k & Key, keyof attributes extends keyof Optional ? base : of<base, Omit<attributes, keyof Optional>>, $> : never : BaseTypeProp<k extends optionalKeyOf<o> ? "optional" : "required", k & Key, t, $>;
40
37
  export interface BaseTypeProp<kind extends Prop.Kind = Prop.Kind, k extends Key = Key,
41
38
  /** @ts-ignore cast variance */
42
39
  out v = unknown, $ = {}> {
@@ -73,7 +70,7 @@ type fromTypeProps<t, props extends array<MappedTypeProp>> = show<{
73
70
  [prop in props[number] as Extract<applyHomomorphicOptionality<t, prop>, {
74
71
  kind: "optional";
75
72
  default: unknown;
76
- }>["key"]]: applyConstraint<prop["value"][inferred], Default<prop["default" & keyof prop]>>;
73
+ }>["key"]]: applyAttribute<prop["value"][inferred], Default<prop["default" & keyof prop]>>;
77
74
  }>;
78
75
  type applyHomomorphicOptionality<t, prop extends MappedTypeProp> = prop["kind"] extends string ? prop : prop & {
79
76
  kind: prop["key"] extends optionalKeyOf<t> ? "optional" : "required";
@@ -1,8 +1,8 @@
1
1
  import type { ExactLength, ExclusiveNumericRangeSchema, exclusivizeRangeSchema, InclusiveNumericRangeSchema, Pattern } from "@ark/schema";
2
2
  import type { applyConstraintSchema } from "../keywords/inference.ts";
3
- import type { ValidatorType } from "./validator.ts";
3
+ import type { BaseType } from "./base.ts";
4
4
  /** @ts-ignore cast variance */
5
- interface Type<out t extends string = string, $ = {}> extends ValidatorType<t, $> {
5
+ interface Type<out t extends string = string, $ = {}> extends BaseType<t, $> {
6
6
  matching<const schema extends Pattern.Schema>(schema: schema): Type<applyConstraintSchema<t, "pattern", schema>, $>;
7
7
  atLeastLength<const schema extends InclusiveNumericRangeSchema>(schema: schema): Type<applyConstraintSchema<t, "minLength", schema>, $>;
8
8
  atMostLength<const schema extends InclusiveNumericRangeSchema>(schema: schema): Type<applyConstraintSchema<t, "maxLength", schema>, $>;
@@ -2,7 +2,7 @@ import type { writeUnassignableDefaultValueMessage } from "@ark/schema";
2
2
  import type { ErrorMessage } from "@ark/util";
3
3
  import type { type } from "../../keywords/keywords.ts";
4
4
  import type { UnitLiteral } from "../shift/operator/default.ts";
5
- import type { inferAstOut } from "./infer.ts";
5
+ import type { inferAstIn } from "./infer.ts";
6
6
  import type { astToString } from "./utils.ts";
7
7
  import type { validateAst } from "./validate.ts";
8
- export type validateDefault<baseAst, unitLiteral extends UnitLiteral, $, args> = validateAst<baseAst, $, args> extends infer e extends ErrorMessage ? e : type.infer<unitLiteral> extends inferAstOut<baseAst, $, args> ? undefined : ErrorMessage<writeUnassignableDefaultValueMessage<astToString<baseAst>, unitLiteral>>;
8
+ export type validateDefault<baseAst, unitLiteral extends UnitLiteral, $, args> = validateAst<baseAst, $, args> extends infer e extends ErrorMessage ? e : type.infer<unitLiteral> extends inferAstIn<baseAst, $, args> ? undefined : ErrorMessage<writeUnassignableDefaultValueMessage<astToString<baseAst>, unitLiteral>>;
@@ -1,11 +1,12 @@
1
1
  import type { GenericAst } from "@ark/schema";
2
2
  import type { Hkt, arkKeyOf, array } from "@ark/util";
3
3
  import type { Date } from "../../keywords/constructors/Date.ts";
4
- import type { Default, LimitLiteral, Optional, applyConstraint, applyConstraintSchema, distill, inferIntersection, normalizeLimit } from "../../keywords/inference.ts";
4
+ import type { Default, LimitLiteral, Optional, Predicate, applyAttribute, applyConstraintSchema, distill, inferIntersection, normalizeLimit } from "../../keywords/inference.ts";
5
5
  import type { type } from "../../keywords/keywords.ts";
6
6
  import type { UnparsedScope } from "../../scope.ts";
7
7
  import type { inferDefinition } from "../definition.ts";
8
8
  import type { Comparator, MinComparator } from "../reduce/shared.ts";
9
+ import type { Scanner } from "../shift/scanner.ts";
9
10
  export type inferAstRoot<ast, $, args> = ast extends array ? inferExpression<ast, $, args> : never;
10
11
  export type inferAstIn<ast, $, args> = distill.In<inferAstRoot<ast, $, args>>;
11
12
  export type inferAstOut<ast, $, args> = distill.Out<inferAstRoot<ast, $, args>>;
@@ -25,15 +26,13 @@ export type inferExpression<ast, $, args> = ast extends array ? ast extends Infe
25
26
  [i in keyof argAsts]: inferExpression<argAsts[i], $, args>;
26
27
  }> : inferDefinition<g["bodyDef"], resolveScope<g["$"], $>, {
27
28
  [i in keyof g["names"] & `${number}` as g["names"][i]]: inferExpression<argAsts[i & keyof argAsts], resolveScope<g["arg$"], $>, args>;
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 ? applyConstraint<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;
29
+ }> : 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 ? applyAttribute<inferExpression<ast[0], $, args>, Default<defaultValue>> : never : ast[1] extends "#" ? applyAttribute<inferExpression<ast[0], $, args>, Predicate<ast[2]>> : 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 "?" ? applyAttribute<inferExpression<ast[0], $, args>, Optional> : ast[0] extends "keyof" ? arkKeyOf<inferExpression<ast[1], $, args>> : never : never;
29
30
  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", {
30
31
  rule: normalizeLimit<limit>;
31
32
  exclusive: comparator extends ">" | "<" ? true : false;
32
33
  }> : never;
33
34
  export type PrefixOperator = "keyof" | "instanceof" | "===" | "node";
34
35
  export type PrefixExpression<operator extends PrefixOperator = PrefixOperator, operand = unknown> = [operator, operand];
35
- export type PostfixOperator = "[]" | "?";
36
- export type PostfixExpression<operator extends PostfixOperator = PostfixOperator, operand = unknown> = readonly [operand, operator];
37
- export type InfixOperator = "|" | "&" | Comparator | "%" | ":" | "=>" | "@" | "=";
38
- export type InfixExpression<operator extends InfixOperator = InfixOperator, l = unknown, r = unknown> = [l, operator, r];
36
+ export type PostfixExpression<operator extends Scanner.PostfixToken = Scanner.PostfixToken, operand = unknown> = readonly [operand, operator];
37
+ export type InfixExpression<operator extends Scanner.InfixToken = Scanner.InfixToken, l = unknown, r = unknown> = [l, operator, r];
39
38
  export {};
@@ -1,5 +1,5 @@
1
1
  import type { arkKind, GenericParamAst, PrivateDeclaration, writeMissingSubmoduleAccessMessage, writeUnsatisfiedParameterConstraintMessage } from "@ark/schema";
2
- import type { anyOrNever, array, BigintLiteral, charsAfterFirst, Completion, ErrorMessage, NumberLiteral, typeToString, writeMalformedNumericLiteralMessage } from "@ark/util";
2
+ import type { anyOrNever, array, BigintLiteral, Completion, ErrorMessage, NumberLiteral, typeToString, writeMalformedNumericLiteralMessage } from "@ark/util";
3
3
  import type { Generic } from "../../generic.ts";
4
4
  import type { Comparator } from "../reduce/shared.ts";
5
5
  import type { writeInvalidGenericArgCountMessage } from "../shift/operand/genericArgs.ts";
@@ -11,14 +11,14 @@ 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> : 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<infer name> ? ErrorMessage<writePrefixedPrivateReferenceMessage<name>> : 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> : operator extends "#" ? validateAst<l, $, args> : ErrorMessage<writeUnexpectedExpressionMessage<astToString<ast>>> : 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}`;
18
18
  type validateGenericArgs<params extends array<GenericParamAst>, argAsts extends array, $, args, indices extends 1[]> = argAsts extends readonly [infer arg, ...infer argsTail] ? validateAst<arg, $, args> extends infer e extends ErrorMessage ? e : inferAstRoot<arg, $, args> extends params[indices["length"]][1] ? validateGenericArgs<params, argsTail, $, args, [...indices, 1]> : ErrorMessage<writeUnsatisfiedParameterConstraintMessage<params[indices["length"]][0], typeToString<params[indices["length"]][1]>, astToString<arg>>> : undefined;
19
- export declare const writePrefixedPrivateReferenceMessage: <def extends PrivateDeclaration>(def: def) => writePrefixedPrivateReferenceMessage<def>;
20
- export type writePrefixedPrivateReferenceMessage<def extends PrivateDeclaration> = `Private type references should not include '#'. Use '${charsAfterFirst<def>}' instead.`;
21
- type validateInferredAst<inferred, def extends string> = def extends NumberLiteral ? number extends inferred ? ErrorMessage<writeMalformedNumericLiteralMessage<def, "number">> : undefined : def extends BigintLiteral ? bigint extends inferred ? ErrorMessage<writeMalformedNumericLiteralMessage<def, "bigint">> : undefined : [inferred] extends [anyOrNever] ? undefined : def extends PrivateDeclaration ? ErrorMessage<writePrefixedPrivateReferenceMessage<def>> : inferred extends Generic ? ErrorMessage<writeInvalidGenericArgCountMessage<def, inferred["names"], []>> : inferred extends {
19
+ export declare const writePrefixedPrivateReferenceMessage: <name extends string>(name: name) => writePrefixedPrivateReferenceMessage<name>;
20
+ export type writePrefixedPrivateReferenceMessage<name extends string> = `Private type references should not include '#'. Use '${name}' instead.`;
21
+ type validateInferredAst<inferred, def extends string> = def extends NumberLiteral ? number extends inferred ? ErrorMessage<writeMalformedNumericLiteralMessage<def, "number">> : undefined : def extends BigintLiteral ? bigint extends inferred ? ErrorMessage<writeMalformedNumericLiteralMessage<def, "bigint">> : undefined : [inferred] extends [anyOrNever] ? undefined : def extends PrivateDeclaration<infer name> ? ErrorMessage<writePrefixedPrivateReferenceMessage<name>> : inferred extends Generic ? ErrorMessage<writeInvalidGenericArgCountMessage<def, inferred["names"], []>> : inferred extends {
22
22
  [arkKind]: "module";
23
23
  } ? "root" extends keyof inferred ? undefined : ErrorMessage<writeMissingSubmoduleAccessMessage<def>> : def extends ErrorMessage ? def : undefined;
24
24
  export type validateString<def extends string, $, args> = validateAst<parseString<def, $, args>, $, args> extends (infer result extends ErrorMessage) ? result extends Completion<infer text> ? text : result : def;
@@ -1 +1 @@
1
- export const writePrefixedPrivateReferenceMessage = (def) => `Private type references should not include '#'. Use '${def.slice(1)}' instead.`;
1
+ export const writePrefixedPrivateReferenceMessage = (name) => `Private type references should not include '#'. Use '${name}' instead.`;
@@ -1,6 +1,6 @@
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/inference.ts";
3
+ import type { of } from "../keywords/inference.ts";
4
4
  import type { astToString } from "./ast/utils.ts";
5
5
  import type { validateString } from "./ast/validate.ts";
6
6
  import type { inferDefinition, validateDefinition } from "./definition.ts";
@@ -19,7 +19,7 @@ type _inferObjectLiteral<def extends object, $, args> = {
19
19
  -readonly [k in keyof def as optionalKeyFrom<k>]?: inferDefinition<def[k], $, args>;
20
20
  };
21
21
  export type validateObjectLiteral<def, $, args> = {
22
- [k in keyof def]: k extends IndexKey<infer indexDef> ? validateString<indexDef, $, args> extends ErrorMessage<infer message> ? ErrorType<message> : inferDefinition<indexDef, $, args> extends Key | constrain<Key, {}> ? validateDefinition<def[k], $, args> : ErrorType<writeInvalidPropertyKeyMessage<indexDef>> : k extends "..." ? inferDefinition<def[k], $, args> extends object ? validateDefinition<def[k], $, args> : ErrorType<writeInvalidSpreadTypeMessage<astToString<def[k]>>> : k extends "+" ? UndeclaredKeyBehavior : validateDefinition<def[k], $, args>;
22
+ [k in keyof def]: k extends IndexKey<infer indexDef> ? validateString<indexDef, $, args> extends ErrorMessage<infer message> ? ErrorType<message> : inferDefinition<indexDef, $, args> extends Key | of<Key, {}> ? validateDefinition<def[k], $, args> : ErrorType<writeInvalidPropertyKeyMessage<indexDef>> : k extends "..." ? inferDefinition<def[k], $, args> extends object ? validateDefinition<def[k], $, args> : ErrorType<writeInvalidSpreadTypeMessage<astToString<def[k]>>> : k extends "+" ? UndeclaredKeyBehavior : validateDefinition<def[k], $, args>;
23
23
  };
24
24
  type nonOptionalKeyFrom<k, $, args> = parseKey<k> extends PreparsedKey<"required", infer inner> ? inner : parseKey<k> extends PreparsedKey<"index", infer inner> ? inferDefinition<inner, $, args> extends infer t extends Key ? t : never : never;
25
25
  type optionalKeyFrom<k> = parseKey<k> extends PreparsedKey<"optional", infer inner> ? inner : never;
@@ -1,7 +1,6 @@
1
1
  import type { BaseParseContext, BaseRoot } from "@ark/schema";
2
2
  import { type requireKeys } from "@ark/util";
3
3
  import type { LimitLiteral } from "../../keywords/inference.ts";
4
- import type { InfixOperator } from "../ast/infer.ts";
5
4
  import type { Scanner } from "../shift/scanner.ts";
6
5
  import { type Comparator, type MinComparator, type OpenLeftBound, type StringifiablePrefixOperator } from "./shared.ts";
7
6
  type BranchState = {
@@ -36,7 +35,7 @@ export declare class DynamicState {
36
35
  parseOperand(): void;
37
36
  private assertRangeUnset;
38
37
  reduceGroupOpen(): void;
39
- previousOperator(): MinComparator | StringifiablePrefixOperator | InfixOperator | undefined;
38
+ previousOperator(): MinComparator | StringifiablePrefixOperator | Scanner.InfixToken | undefined;
40
39
  shiftedByOne(): this;
41
40
  }
42
41
  export {};
@@ -3,6 +3,7 @@ import { type BigintLiteral, type NumberLiteral, type join, type lastOf } from "
3
3
  import type { ArkAmbient } from "../../../config.ts";
4
4
  import type { resolutionToAst } from "../../../scope.ts";
5
5
  import type { GenericInstantiationAst, InferredAst } from "../../ast/infer.ts";
6
+ import { writePrefixedPrivateReferenceMessage } from "../../ast/validate.ts";
6
7
  import type { DynamicState } from "../../reduce/dynamic.ts";
7
8
  import type { StaticState, state } from "../../reduce/static.ts";
8
9
  import type { BaseCompletions } from "../../string.ts";
@@ -27,7 +28,10 @@ type tryResolveSubmodule<token extends string, resolution, reference extends str
27
28
  ]> : unresolvableState<s, reference, resolution, {}, submodulePath> : state.error<writeNonSubmoduleDotMessage<lastOf<submodulePath>>>;
28
29
  /** Provide valid completions for the current token, or fallback to an
29
30
  * unresolvable error if there are none */
30
- export type unresolvableState<s extends StaticState, token extends string, resolutions, args, submodulePath extends string[]> = validReferenceFromToken<token, resolutions, args, submodulePath> extends (never) ? state.error<writeUnresolvableMessage<qualifiedReference<token, submodulePath>>> : state.completion<`${s["scanned"]}${qualifiedReference<validReferenceFromToken<token, resolutions, args, submodulePath>, submodulePath>}`>;
31
+ export type unresolvableState<s extends StaticState, token extends string, resolutions, args, submodulePath extends string[]> = [
32
+ token,
33
+ s["unscanned"]
34
+ ] extends ["", Scanner.shift<"#", infer unscanned>] ? Scanner.shiftUntilNextTerminator<unscanned> extends (Scanner.shiftResult<infer name, string>) ? state.error<writePrefixedPrivateReferenceMessage<name>> : never : validReferenceFromToken<token, resolutions, args, submodulePath> extends (never) ? state.error<writeUnresolvableMessage<qualifiedReference<token, submodulePath>>> : state.completion<`${s["scanned"]}${qualifiedReference<validReferenceFromToken<token, resolutions, args, submodulePath>, submodulePath>}`>;
31
35
  type qualifiedReference<reference extends string, submodulePath extends string[]> = join<[...submodulePath, reference], ".">;
32
36
  type validReferenceFromToken<token extends string, $, args, submodulePath extends string[]> = Extract<submodulePath["length"] extends 0 ? BaseCompletions<$, args> : resolvableReferenceIn<$>, `${token}${string}`>;
33
37
  export declare const writeMissingOperandMessage: (s: DynamicState) => string;
@@ -19,10 +19,11 @@ export const parseGenericInstantiation = (name, g, s) => {
19
19
  };
20
20
  const unenclosedToNode = (s, token) => maybeParseReference(s, token) ??
21
21
  maybeParseUnenclosedLiteral(s, token) ??
22
- s.error(token === "" ? writeMissingOperandMessage(s)
23
- : token[0] === "#" ?
24
- writePrefixedPrivateReferenceMessage(token)
25
- : writeUnresolvableMessage(token));
22
+ s.error(token === "" ?
23
+ s.scanner.lookahead === "#" ?
24
+ writePrefixedPrivateReferenceMessage(s.shiftedByOne().scanner.shiftUntilNextTerminator())
25
+ : writeMissingOperandMessage(s)
26
+ : writeUnresolvableMessage(token));
26
27
  const maybeParseReference = (s, token) => {
27
28
  if (s.ctx.args?.[token]) {
28
29
  const arg = s.ctx.args[token];
@@ -0,0 +1,6 @@
1
+ import type { emptyBrandNameMessage } from "@ark/schema";
2
+ import type { DynamicStateWithRoot } from "../../reduce/dynamic.ts";
3
+ import type { StaticState, state } from "../../reduce/static.ts";
4
+ import type { Scanner } from "../scanner.ts";
5
+ export declare const parseBrand: (s: DynamicStateWithRoot) => void;
6
+ export type parseBrand<s extends StaticState, unscanned extends string> = Scanner.shiftUntilNextTerminator<Scanner.skipWhitespace<unscanned>> extends (Scanner.shiftResult<`${infer brandName}`, infer nextUnscanned>) ? brandName extends "" ? state.error<emptyBrandNameMessage> : state.setRoot<s, [s["root"], "#", brandName], nextUnscanned> : never;
@@ -0,0 +1,5 @@
1
+ export const parseBrand = (s) => {
2
+ s.scanner.shiftUntilNonWhitespace();
3
+ const brandName = s.scanner.shiftUntilNextTerminator();
4
+ s.root = s.root.brand(brandName);
5
+ };
@@ -7,6 +7,9 @@ export const parseDefault = (s) => {
7
7
  // token from which it was parsed
8
8
  if (!defaultNode.hasKind("unit"))
9
9
  return s.error(writeNonLiteralDefaultMessage(defaultNode.expression));
10
- return baseNode.default(defaultNode.unit);
10
+ const defaultValue = defaultNode.unit instanceof Date ?
11
+ () => new Date(defaultNode.unit)
12
+ : defaultNode.unit;
13
+ return baseNode.default(defaultValue);
11
14
  };
12
15
  export const writeNonLiteralDefaultMessage = (defaultDef) => `Default value '${defaultDef}' must a literal value`;
@@ -3,9 +3,10 @@ import type { DynamicStateWithRoot } from "../../reduce/dynamic.ts";
3
3
  import type { StaticState, state } from "../../reduce/static.ts";
4
4
  import { Scanner } from "../scanner.ts";
5
5
  import { parseBound, type ComparatorStartChar } from "./bounds.ts";
6
+ import { parseBrand } from "./brand.ts";
6
7
  import { parseDivisor } from "./divisor.ts";
7
8
  export declare const parseOperator: (s: DynamicStateWithRoot) => void;
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
+ 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 "#" ? parseBrand<s, unscanned> : lookahead extends WhiteSpaceToken ? parseOperator<state.scanTo<s, unscanned>, $, args> : state.error<writeUnexpectedCharacterMessage<lookahead>> : state.finalize<s, "">;
9
10
  export declare const writeUnexpectedCharacterMessage: <char extends string, shouldBe extends string>(char: char, shouldBe?: shouldBe) => writeUnexpectedCharacterMessage<char, shouldBe>;
10
11
  export type writeUnexpectedCharacterMessage<char extends string, shouldBe extends string = ""> = `'${char}' is not allowed here${shouldBe extends "" ? "" : ` (should be ${shouldBe})`}`;
11
12
  export declare const incompleteArrayTokenMessage = "Missing expected ']'";
@@ -1,6 +1,7 @@
1
1
  import { isKeyOf, whiteSpaceTokens } from "@ark/util";
2
2
  import { Scanner } from "../scanner.js";
3
3
  import { comparatorStartChars, parseBound } from "./bounds.js";
4
+ import { parseBrand } from "./brand.js";
4
5
  import { parseDivisor } from "./divisor.js";
5
6
  export const parseOperator = (s) => {
6
7
  const lookahead = s.scanner.shift();
@@ -15,8 +16,9 @@ export const parseOperator = (s) => {
15
16
  s.finalize(lookahead)
16
17
  : isKeyOf(lookahead, comparatorStartChars) ? parseBound(s, lookahead)
17
18
  : lookahead === "%" ? parseDivisor(s)
18
- : lookahead in whiteSpaceTokens ? parseOperator(s)
19
- : s.error(writeUnexpectedCharacterMessage(lookahead)));
19
+ : lookahead === "#" ? parseBrand(s)
20
+ : lookahead in whiteSpaceTokens ? parseOperator(s)
21
+ : s.error(writeUnexpectedCharacterMessage(lookahead)));
20
22
  };
21
23
  export const writeUnexpectedCharacterMessage = (char, shouldBe = "") => `'${char}' is not allowed here${shouldBe && ` (should be ${shouldBe})`}`;
22
24
  export const incompleteArrayTokenMessage = `Missing expected ']'`;
@@ -35,6 +35,7 @@ export declare class Scanner<lookahead extends string = string> {
35
35
  readonly ",": true;
36
36
  readonly ":": true;
37
37
  readonly "?": true;
38
+ readonly "#": true;
38
39
  };
39
40
  static finalizingLookaheads: {
40
41
  readonly ">": true;
@@ -56,8 +57,8 @@ export declare namespace Scanner {
56
57
  };
57
58
  type TerminatingChar = keyof typeof Scanner.terminatingChars;
58
59
  type FinalizingLookahead = keyof typeof Scanner.finalizingLookaheads;
59
- type InfixToken = Comparator | "|" | "&" | "%" | ":" | "=>";
60
- type PostfixToken = "[]";
60
+ type InfixToken = Comparator | "|" | "&" | "%" | ":" | "=>" | "#" | "@" | "=";
61
+ type PostfixToken = "[]" | "?";
61
62
  type OperatorToken = InfixToken | PostfixToken;
62
63
  type shift<lookahead extends string, unscanned extends string> = `${lookahead}${unscanned}`;
63
64
  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, ""];
@@ -75,6 +75,7 @@ export class Scanner {
75
75
  ",": true,
76
76
  ":": true,
77
77
  "?": true,
78
+ "#": true,
78
79
  ...whiteSpaceTokens
79
80
  };
80
81
  static finalizingLookaheads = {
@@ -1,14 +1,15 @@
1
1
  import { type BaseParseContext, type BaseRoot, type MetaSchema, type Morph, type Predicate } from "@ark/schema";
2
2
  import { type anyOrNever, type array, type BuiltinObjectKind, type conform, type Constructor, type Domain, type ErrorMessage, type show } from "@ark/util";
3
- import type { applyConstraint, Default, distill, inferIntersection, inferMorphOut, inferPredicate, InferredOptional, Optional, Out } from "../keywords/inference.ts";
3
+ import type { applyAttribute, Default, DefaultFor, distill, inferIntersection, inferMorphOut, inferPredicate, InferredOptional, Optional, Out } from "../keywords/inference.ts";
4
4
  import type { type } from "../keywords/keywords.ts";
5
- import type { InfixOperator, PostfixExpression } from "./ast/infer.ts";
5
+ import type { PostfixExpression } from "./ast/infer.ts";
6
6
  import type { inferDefinition, validateDefinition } from "./definition.ts";
7
7
  import { writeMissingRightOperandMessage } from "./shift/operand/unenclosed.ts";
8
+ import type { Scanner } from "./shift/scanner.ts";
8
9
  import type { BaseCompletions } from "./string.ts";
9
10
  export declare const parseTuple: (def: array, ctx: BaseParseContext) => BaseRoot;
10
11
  export declare const parseTupleLiteral: (def: array, ctx: BaseParseContext) => BaseRoot;
11
- type InfixExpression = readonly [unknown, InfixOperator, ...unknown[]];
12
+ type InfixExpression = readonly [unknown, Scanner.InfixToken, ...unknown[]];
12
13
  export type validateTuple<def extends array, $, args> = def extends IndexZeroExpression ? validatePrefixExpression<def, $, args> : def extends PostfixExpression ? validatePostfixExpression<def, $, args> : def extends InfixExpression ? validateInfixExpression<def, $, args> : def extends (readonly ["", ...unknown[]] | readonly [unknown, "", ...unknown[]]) ? readonly [
13
14
  def[0] extends "" ? BaseCompletions<$, args, IndexZeroOperator | "..."> : def[0],
14
15
  def[1] extends "" ? BaseCompletions<$, args, IndexOneOperator | "..."> : def[1]
@@ -110,13 +111,13 @@ type optionalPostVariadicMessage = typeof optionalPostVariadicMessage;
110
111
  export declare const spreadOptionalMessage = "A spread element cannot be optional";
111
112
  type spreadOptionalMessage = typeof optionalPostVariadicMessage;
112
113
  export type inferTuple<def extends array, $, args> = def extends TupleExpression ? inferTupleExpression<def, $, args> : inferTupleLiteral<def, $, args>;
113
- export type inferTupleExpression<def extends TupleExpression, $, args> = def[1] extends "[]" ? inferDefinition<def[0], $, args>[] : def[1] extends "&" ? inferIntersection<inferDefinition<def[0], $, args>, inferDefinition<def[2], $, args>> : def[1] extends "|" ? inferDefinition<def[0], $, args> | inferDefinition<def[2], $, args> : def[1] extends ":" ? inferPredicate<inferDefinition<def[0], $, args>, def[2]> : def[1] extends "=>" ? parseMorph<def[0], def[2], $, args> : def[1] extends "@" ? inferDefinition<def[0], $, args> : def[1] extends "=" ? applyConstraint<inferDefinition<def[0], $, args>, Default<def[2]>> : def[1] extends "?" ? applyConstraint<inferDefinition<def[0], $, args>, Optional> : def extends readonly ["===", ...infer values] ? values[number] : def extends (readonly ["instanceof", ...infer constructors extends Constructor[]]) ? InstanceType<constructors[number]> : def[0] extends "keyof" ? inferKeyOfExpression<def[1], $, args> : never;
114
+ export type inferTupleExpression<def extends TupleExpression, $, args> = def[1] extends "[]" ? inferDefinition<def[0], $, args>[] : def[1] extends "&" ? inferIntersection<inferDefinition<def[0], $, args>, inferDefinition<def[2], $, args>> : def[1] extends "|" ? inferDefinition<def[0], $, args> | inferDefinition<def[2], $, args> : def[1] extends ":" ? inferPredicate<inferDefinition<def[0], $, args>, def[2]> : def[1] extends "=>" ? parseMorph<def[0], def[2], $, args> : def[1] extends "@" ? inferDefinition<def[0], $, args> : def[1] extends "=" ? applyAttribute<inferDefinition<def[0], $, args>, Default<def[2]>> : def[1] extends "?" ? applyAttribute<inferDefinition<def[0], $, args>, Optional> : def extends readonly ["===", ...infer values] ? values[number] : def extends (readonly ["instanceof", ...infer constructors extends Constructor[]]) ? InstanceType<constructors[number]> : def[0] extends "keyof" ? inferKeyOfExpression<def[1], $, args> : never;
114
115
  export type validatePrefixExpression<def extends IndexZeroExpression, $, args> = def["length"] extends 1 ? readonly [writeMissingRightOperandMessage<def[0]>] : def[0] extends "keyof" ? readonly [def[0], validateDefinition<def[1], $, args>] : def[0] extends "===" ? readonly [def[0], ...unknown[]] : def[0] extends "instanceof" ? readonly [def[0], ...Constructor[]] : never;
115
116
  export type validatePostfixExpression<def extends PostfixExpression, $, args> = conform<def, readonly [validateDefinition<def[0], $, args>, "[]" | "?"]>;
116
117
  export type validateInfixExpression<def extends InfixExpression, $, args> = def["length"] extends 2 ? readonly [def[0], writeMissingRightOperandMessage<def[1]>] : readonly [
117
118
  validateDefinition<def[0], $, args>,
118
119
  def[1],
119
- def[1] extends "|" ? validateDefinition<def[2], $, args> : def[1] extends "&" ? validateDefinition<def[2], $, args> : def[1] extends ":" ? Predicate<type.infer.Out<def[0], $, args>> : def[1] extends "=>" ? Morph<type.infer.Out<def[0], $, args>> : def[1] extends "@" ? MetaSchema : def[1] extends "=" ? type.infer.Out<def[0], $, args> : validateDefinition<def[2], $, args>
120
+ def[1] extends "|" ? validateDefinition<def[2], $, args> : def[1] extends "&" ? validateDefinition<def[2], $, args> : def[1] extends ":" ? Predicate<type.infer.Out<def[0], $, args>> : def[1] extends "=>" ? Morph<type.infer.Out<def[0], $, args>> : def[1] extends "@" ? MetaSchema : def[1] extends "=" ? DefaultFor<type.infer.In<def[0], $, args>> : validateDefinition<def[2], $, args>
120
121
  ];
121
122
  export type UnparsedTupleExpressionInput = {
122
123
  instanceof: Constructor;
package/out/type.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { ArkErrors, BaseRoot, type BaseParseOptions, type MetaSchema, type Morph, type Predicate, type RootSchema } from "@ark/schema";
2
2
  import { Callable, Hkt, type Constructor, type array, type conform } from "@ark/util";
3
3
  import type { Generic, GenericParser, ParameterString, baseGenericConstraints, parseValidGenericParams, validateParameterString } from "./generic.ts";
4
- import type { distill } from "./keywords/inference.ts";
4
+ import type { DefaultFor, distill } from "./keywords/inference.ts";
5
5
  import type { Ark, keywords, type } from "./keywords/keywords.ts";
6
6
  import type { BaseType } from "./methods/base.ts";
7
7
  import type { instantiateType } from "./methods/instantiate.ts";
@@ -13,7 +13,7 @@ export type TypeParserAttachments = Omit<TypeParser, never>;
13
13
  export interface TypeParser<$ = {}> extends Ark.boundTypeAttachments<$> {
14
14
  <const def, r = Type<type.infer<def, $>, $>>(def: type.validate<def, $>): r;
15
15
  <const params extends ParameterString, const def>(params: validateParameterString<params, $>, def: validateDefinition<def, $, baseGenericConstraints<parseValidGenericParams<params, $>>>): Generic<parseValidGenericParams<params, $>, def, $>;
16
- <const zero, const one, const rest extends array, r = Type<type.infer<[zero, one, ...rest], $>, $>>(_0: zero extends IndexZeroOperator ? zero : type.validate<zero, $>, _1: zero extends "keyof" ? type.validate<one, $> : zero extends "instanceof" ? conform<one, Constructor> : zero extends "===" ? conform<one, unknown> : conform<one, IndexOneOperator>, ..._2: zero extends "===" ? rest : zero extends "instanceof" ? conform<rest, readonly Constructor[]> : one extends TupleInfixOperator ? one extends ":" ? [Predicate<distill.In<type.infer<zero, $>>>] : one extends "=>" ? [Morph<distill.Out<type.infer<zero, $>>, unknown>] : one extends "@" ? [MetaSchema] : one extends "=" ? [distill.In<type.infer<NoInfer<zero>, $>>] : [type.validate<rest[0], $>] : []): r;
16
+ <const zero, const one, const rest extends array, r = Type<type.infer<[zero, one, ...rest], $>, $>>(_0: zero extends IndexZeroOperator ? zero : type.validate<zero, $>, _1: zero extends "keyof" ? type.validate<one, $> : zero extends "instanceof" ? conform<one, Constructor> : zero extends "===" ? conform<one, unknown> : conform<one, IndexOneOperator>, ..._2: zero extends "===" ? rest : zero extends "instanceof" ? conform<rest, readonly Constructor[]> : one extends TupleInfixOperator ? one extends ":" ? [Predicate<distill.In<type.infer<zero, $>>>] : one extends "=>" ? [Morph<distill.Out<type.infer<zero, $>>, unknown>] : one extends "@" ? [MetaSchema] : one extends "=" ? [DefaultFor<distill.In<type.infer<NoInfer<zero>, $>>>] : [type.validate<rest[0], $>] : []): r;
17
17
  errors: typeof ArkErrors;
18
18
  hkt: typeof Hkt;
19
19
  keywords: typeof keywords;