arktype 2.0.0-rc.2 → 2.0.0-rc.21

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 (151) hide show
  1. package/out/attributes.d.ts +274 -0
  2. package/out/attributes.js +2 -0
  3. package/out/config.d.ts +1 -1
  4. package/out/generic.d.ts +45 -48
  5. package/out/generic.js +6 -8
  6. package/out/index.d.ts +4 -4
  7. package/out/index.js +2 -2
  8. package/out/keywords/builtins.js +2 -2
  9. package/out/keywords/constructors/Array.d.ts +2 -2
  10. package/out/keywords/constructors/Array.js +7 -7
  11. package/out/keywords/constructors/Date.d.ts +37 -0
  12. package/out/keywords/constructors/FormData.d.ts +2 -2
  13. package/out/keywords/constructors/FormData.js +8 -8
  14. package/out/keywords/constructors/TypedArray.js +2 -2
  15. package/out/keywords/constructors/constructors.d.ts +0 -1
  16. package/out/keywords/constructors/constructors.js +2 -2
  17. package/out/keywords/keywords.d.ts +64 -0
  18. package/out/keywords/{ark.js → keywords.js} +14 -9
  19. package/out/keywords/number/epoch.d.ts +1 -1
  20. package/out/keywords/number/epoch.js +2 -2
  21. package/out/keywords/number/integer.js +2 -2
  22. package/out/keywords/number/number.d.ts +44 -14
  23. package/out/keywords/number/number.js +17 -5
  24. package/out/keywords/string/alpha.d.ts +2 -2
  25. package/out/keywords/string/alphanumeric.d.ts +2 -2
  26. package/out/keywords/string/base64.d.ts +21 -0
  27. package/out/keywords/string/base64.js +6 -0
  28. package/out/keywords/string/capitalize.d.ts +3 -3
  29. package/out/keywords/string/capitalize.js +4 -4
  30. package/out/keywords/string/creditCard.d.ts +2 -2
  31. package/out/keywords/string/creditCard.js +2 -2
  32. package/out/keywords/string/date.d.ts +7 -11
  33. package/out/keywords/string/date.js +16 -16
  34. package/out/keywords/string/digits.d.ts +2 -2
  35. package/out/keywords/string/email.d.ts +2 -2
  36. package/out/keywords/string/integer.d.ts +3 -3
  37. package/out/keywords/string/integer.js +7 -7
  38. package/out/keywords/string/ip.d.ts +5 -5
  39. package/out/keywords/string/ip.js +5 -5
  40. package/out/keywords/string/json.d.ts +4 -3
  41. package/out/keywords/string/json.js +39 -30
  42. package/out/keywords/string/lower.d.ts +3 -3
  43. package/out/keywords/string/lower.js +4 -4
  44. package/out/keywords/string/normalize.d.ts +27 -31
  45. package/out/keywords/string/normalize.js +14 -14
  46. package/out/keywords/string/numeric.d.ts +3 -3
  47. package/out/keywords/string/numeric.js +7 -7
  48. package/out/keywords/string/semver.d.ts +2 -2
  49. package/out/keywords/string/string.d.ts +74 -51
  50. package/out/keywords/string/string.js +5 -3
  51. package/out/keywords/string/trim.d.ts +3 -3
  52. package/out/keywords/string/trim.js +4 -4
  53. package/out/keywords/string/upper.d.ts +3 -3
  54. package/out/keywords/string/upper.js +4 -4
  55. package/out/keywords/string/url.d.ts +3 -3
  56. package/out/keywords/string/url.js +8 -8
  57. package/out/keywords/string/uuid.d.ts +20 -20
  58. package/out/keywords/string/uuid.js +3 -3
  59. package/out/keywords/ts.d.ts +38 -1
  60. package/out/keywords/ts.js +20 -4
  61. package/out/keywords/utils.d.ts +1 -1
  62. package/out/keywords/utils.js +1 -1
  63. package/out/{subtypes → methods}/array.d.ts +6 -6
  64. package/out/methods/base.d.ts +183 -0
  65. package/out/{subtypes → methods}/date.d.ts +5 -5
  66. package/out/methods/instantiate.d.ts +17 -0
  67. package/out/methods/morph.d.ts +12 -0
  68. package/out/methods/number.d.ts +12 -0
  69. package/out/methods/object.d.ts +106 -0
  70. package/out/methods/string.d.ts +13 -0
  71. package/out/module.d.ts +2 -2
  72. package/out/parser/{semantic → ast}/bounds.d.ts +3 -3
  73. package/out/parser/ast/default.d.ts +8 -0
  74. package/out/parser/ast/infer.d.ts +39 -0
  75. package/out/parser/{semantic → ast}/utils.d.ts +1 -1
  76. package/out/parser/{semantic → ast}/validate.d.ts +10 -10
  77. package/out/parser/ast/validate.js +1 -0
  78. package/out/parser/definition.d.ts +8 -9
  79. package/out/parser/objectLiteral.d.ts +11 -37
  80. package/out/parser/objectLiteral.js +6 -24
  81. package/out/parser/{string/reduce → reduce}/dynamic.d.ts +5 -8
  82. package/out/parser/{string/reduce → reduce}/dynamic.js +5 -6
  83. package/out/parser/{string/reduce → reduce}/shared.d.ts +1 -1
  84. package/out/parser/{string/reduce → reduce}/static.d.ts +1 -1
  85. package/out/parser/{string/shift → shift}/operand/date.d.ts +3 -1
  86. package/out/parser/{string/shift → shift}/operand/enclosed.d.ts +4 -3
  87. package/out/parser/{string/shift → shift}/operand/enclosed.js +7 -3
  88. package/out/parser/{string/shift → shift}/operand/unenclosed.d.ts +8 -4
  89. package/out/parser/{string/shift → shift}/operand/unenclosed.js +12 -7
  90. package/out/parser/{string/shift → shift}/operator/bounds.d.ts +3 -3
  91. package/out/parser/shift/operator/brand.d.ts +6 -0
  92. package/out/parser/shift/operator/brand.js +5 -0
  93. package/out/parser/{string/shift → shift}/operator/default.d.ts +3 -6
  94. package/out/parser/{string/shift → shift}/operator/default.js +4 -6
  95. package/out/parser/{string/shift → shift}/operator/operator.d.ts +2 -1
  96. package/out/parser/{string/shift → shift}/operator/operator.js +4 -2
  97. package/out/parser/{string/shift → shift}/scanner.d.ts +6 -3
  98. package/out/parser/{string/shift → shift}/scanner.js +6 -3
  99. package/out/parser/{string/string.d.ts → string.d.ts} +6 -7
  100. package/out/parser/{string/string.js → string.js} +2 -0
  101. package/out/parser/tuple.d.ts +56 -44
  102. package/out/parser/tuple.js +36 -30
  103. package/out/scope.d.ts +38 -39
  104. package/out/scope.js +47 -36
  105. package/out/type.d.ts +45 -21
  106. package/out/type.js +14 -10
  107. package/package.json +3 -3
  108. package/out/intersect.d.ts +0 -28
  109. package/out/keys.d.ts +0 -16
  110. package/out/keywords/ark.d.ts +0 -39
  111. package/out/keywords/ast.d.ts +0 -193
  112. package/out/keywords/ast.js +0 -2
  113. package/out/parser/semantic/default.d.ts +0 -9
  114. package/out/parser/semantic/default.js +0 -1
  115. package/out/parser/semantic/infer.d.ts +0 -39
  116. package/out/parser/semantic/validate.js +0 -1
  117. package/out/subtypes/base.d.ts +0 -85
  118. package/out/subtypes/instantiate.d.ts +0 -16
  119. package/out/subtypes/morph.d.ts +0 -13
  120. package/out/subtypes/number.d.ts +0 -12
  121. package/out/subtypes/object.d.ts +0 -33
  122. package/out/subtypes/string.d.ts +0 -13
  123. package/out/subtypes/validator.d.ts +0 -11
  124. package/out/subtypes/validator.js +0 -1
  125. /package/out/{intersect.js → keywords/constructors/Date.js} +0 -0
  126. /package/out/{subtypes → methods}/array.js +0 -0
  127. /package/out/{subtypes → methods}/base.js +0 -0
  128. /package/out/{subtypes → methods}/date.js +0 -0
  129. /package/out/{subtypes → methods}/instantiate.js +0 -0
  130. /package/out/{subtypes → methods}/morph.js +0 -0
  131. /package/out/{subtypes → methods}/number.js +0 -0
  132. /package/out/{subtypes → methods}/object.js +0 -0
  133. /package/out/{subtypes → methods}/string.js +0 -0
  134. /package/out/parser/{semantic → ast}/bounds.js +0 -0
  135. /package/out/{keys.js → parser/ast/default.js} +0 -0
  136. /package/out/parser/{semantic → ast}/divisor.d.ts +0 -0
  137. /package/out/parser/{semantic → ast}/divisor.js +0 -0
  138. /package/out/parser/{semantic → ast}/infer.js +0 -0
  139. /package/out/parser/{semantic → ast}/keyof.d.ts +0 -0
  140. /package/out/parser/{semantic → ast}/keyof.js +0 -0
  141. /package/out/parser/{semantic → ast}/utils.js +0 -0
  142. /package/out/parser/{string/reduce → reduce}/shared.js +0 -0
  143. /package/out/parser/{string/reduce → reduce}/static.js +0 -0
  144. /package/out/parser/{string/shift → shift}/operand/date.js +0 -0
  145. /package/out/parser/{string/shift → shift}/operand/genericArgs.d.ts +0 -0
  146. /package/out/parser/{string/shift → shift}/operand/genericArgs.js +0 -0
  147. /package/out/parser/{string/shift → shift}/operand/operand.d.ts +0 -0
  148. /package/out/parser/{string/shift → shift}/operand/operand.js +0 -0
  149. /package/out/parser/{string/shift → shift}/operator/bounds.js +0 -0
  150. /package/out/parser/{string/shift → shift}/operator/divisor.d.ts +0 -0
  151. /package/out/parser/{string/shift → shift}/operator/divisor.js +0 -0
@@ -34,19 +34,22 @@ export declare class Scanner<lookahead extends string = string> {
34
34
  readonly "%": true;
35
35
  readonly ",": true;
36
36
  readonly ":": true;
37
+ readonly "?": true;
38
+ readonly "#": true;
37
39
  };
38
40
  static finalizingLookaheads: {
39
41
  readonly ">": true;
40
42
  readonly ",": true;
41
43
  readonly "": true;
42
44
  readonly "=": true;
45
+ readonly "?": true;
43
46
  };
44
47
  static lookaheadIsTerminator: Scanner.UntilCondition;
45
48
  static lookaheadIsNotWhitespace: Scanner.UntilCondition;
46
49
  static lookaheadIsFinalizing: (lookahead: string, unscanned: string) => lookahead is ">" | "," | "=";
47
50
  }
48
51
  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;
52
+ 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
53
  type UntilCondition = (scanner: Scanner, shifted: string) => boolean;
51
54
  type OnInputEndFn = (scanner: Scanner, shifted: string) => string;
52
55
  type ShiftUntilOptions = {
@@ -54,8 +57,8 @@ export declare namespace Scanner {
54
57
  };
55
58
  type TerminatingChar = keyof typeof Scanner.terminatingChars;
56
59
  type FinalizingLookahead = keyof typeof Scanner.finalizingLookaheads;
57
- type InfixToken = Comparator | "|" | "&" | "%" | ":" | "=>";
58
- type PostfixToken = "[]";
60
+ type InfixToken = Comparator | "|" | "&" | "%" | ":" | "=>" | "#" | "@" | "=";
61
+ type PostfixToken = "[]" | "?";
59
62
  type OperatorToken = InfixToken | PostfixToken;
60
63
  type shift<lookahead extends string, unscanned extends string> = `${lookahead}${unscanned}`;
61
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, ""];
@@ -74,13 +74,16 @@ export class Scanner {
74
74
  "%": true,
75
75
  ",": true,
76
76
  ":": true,
77
+ "?": true,
78
+ "#": true,
77
79
  ...whiteSpaceTokens
78
80
  };
79
81
  static finalizingLookaheads = {
80
82
  ">": true,
81
83
  ",": true,
82
84
  "": true,
83
- "=": true
85
+ "=": true,
86
+ "?": true
84
87
  };
85
88
  static lookaheadIsTerminator = (scanner) => scanner.lookahead in this.terminatingChars;
86
89
  static lookaheadIsNotWhitespace = (scanner) => !(scanner.lookahead in whiteSpaceTokens);
@@ -95,6 +98,6 @@ export class Scanner {
95
98
  // "=" is a finalizer on its own (representing a default value),
96
99
  // but not with a second "=" (an equality comparator)
97
100
  : lookahead === "=" ? unscanned[0] !== "="
98
- // ","" is unambiguously a finalizer
99
- : lookahead === ",";
101
+ // "," and "?" are unambiguously finalizers
102
+ : lookahead === "," || lookahead === "?";
100
103
  }
@@ -1,13 +1,13 @@
1
1
  import type { BaseRoot, resolvableReferenceIn } from "@ark/schema";
2
2
  import { type ErrorMessage } from "@ark/util";
3
- import type { ArkAmbient } from "../../config.ts";
4
- import type { resolutionToAst } from "../../scope.ts";
5
- import type { inferAstRoot } from "../semantic/infer.ts";
3
+ import type { ArkAmbient } from "../config.ts";
4
+ import type { resolutionToAst } from "../scope.ts";
5
+ import type { inferAstRoot } from "./ast/infer.ts";
6
6
  import type { DynamicState, DynamicStateWithRoot } from "./reduce/dynamic.ts";
7
7
  import type { StringifiablePrefixOperator } from "./reduce/shared.ts";
8
8
  import type { state, StaticState } from "./reduce/static.ts";
9
9
  import type { parseOperand } from "./shift/operand/operand.ts";
10
- import { parseDefault, type ParsedDefault } from "./shift/operator/default.ts";
10
+ import { parseDefault } from "./shift/operator/default.ts";
11
11
  import { writeUnexpectedCharacterMessage, type parseOperator } from "./shift/operator/operator.ts";
12
12
  /**
13
13
  * Try to parse the definition from right to left using the most common syntax.
@@ -19,12 +19,11 @@ export type parseString<def extends string, $, args> = def extends keyof $ ? res
19
19
  ] : fullStringParse<state.initialize<def>, $, args> : fullStringParse<state.initialize<def>, $, args>;
20
20
  export type inferString<def extends string, $, args> = inferAstRoot<parseString<def, $, args>, $, args>;
21
21
  export type BaseCompletions<$, args, otherSuggestions extends string = never> = resolvableReferenceIn<$> | resolvableReferenceIn<ArkAmbient.$> | (keyof args & string) | StringifiablePrefixOperator | otherSuggestions;
22
- export type StringParseResult = BaseRoot | ParsedDefault;
23
- export declare const fullStringParse: (s: DynamicState) => StringParseResult;
22
+ export declare const fullStringParse: (s: DynamicState) => BaseRoot;
24
23
  type fullStringParse<s extends StaticState, $, args> = extractFinalizedResult<parseUntilFinalizer<s, $, args>>;
25
24
  export declare const parseUntilFinalizer: (s: DynamicState) => DynamicStateWithRoot;
26
25
  export type parseUntilFinalizer<s extends StaticState, $, args> = s["finalizer"] extends undefined ? parseUntilFinalizer<next<s, $, args>, $, args> : s;
27
26
  declare const next: (s: DynamicState) => void;
28
27
  type next<s extends StaticState, $, args> = s["root"] extends undefined ? parseOperand<s, $, args> : parseOperator<s, $, args>;
29
- export type extractFinalizedResult<s extends StaticState> = s["finalizer"] extends "" ? s["root"] : s["finalizer"] extends ErrorMessage ? s["finalizer"] : s["finalizer"] extends "=" ? parseDefault<s["root"], s["unscanned"]> : state.error<writeUnexpectedCharacterMessage<`${s["finalizer"]}`>>;
28
+ export type extractFinalizedResult<s extends StaticState> = s["finalizer"] extends "" ? s["root"] : s["finalizer"] extends ErrorMessage ? s["finalizer"] : s["finalizer"] extends "?" ? [s["root"], "?"] : s["finalizer"] extends "=" ? parseDefault<s["root"], s["unscanned"]> : state.error<writeUnexpectedCharacterMessage<`${s["finalizer"]}`>>;
30
29
  export {};
@@ -9,6 +9,8 @@ export const fullStringParse = (s) => {
9
9
  }
10
10
  if (s.finalizer === "=")
11
11
  result = parseDefault(s);
12
+ else if (s.finalizer === "?")
13
+ result = result.optional();
12
14
  s.scanner.shiftUntilNonWhitespace();
13
15
  if (s.scanner.lookahead) {
14
16
  // throw a parse error if non-whitespace characters made it here without being parsed
@@ -1,18 +1,18 @@
1
- import { type BaseRoot, type MetaSchema, type Morph, type Predicate } from "@ark/schema";
2
- import { type array, type BuiltinObjectKind, type conform, type Constructor, type Domain, type ErrorMessage, type show } from "@ark/util";
3
- import type { inferIntersection } from "../intersect.ts";
4
- import type { distillConstrainableIn, distillOut, inferMorphOut, inferPredicate, Out } from "../keywords/ast.ts";
5
- import type { ParseContext } from "../scope.ts";
1
+ import { type BaseParseContext, type BaseRoot, type MetaSchema, type Morph, type Predicate } from "@ark/schema";
2
+ import { type anyOrNever, type array, type BuiltinObjectKind, type conform, type Constructor, type Domain, type ErrorMessage, type show, type Thunk } from "@ark/util";
3
+ import type { associateAttributes, Default, DefaultFor, distill, inferIntersection, inferMorphOut, inferPredicate, InferredOptional, Optional, Out } from "../attributes.ts";
4
+ import type { type } from "../keywords/keywords.ts";
5
+ import type { PostfixExpression } from "./ast/infer.ts";
6
6
  import type { inferDefinition, validateDefinition } from "./definition.ts";
7
- import type { InfixOperator, PostfixExpression } from "./semantic/infer.ts";
8
- import { writeMissingRightOperandMessage } from "./string/shift/operand/unenclosed.ts";
9
- import type { BaseCompletions } from "./string/string.ts";
10
- export declare const parseTuple: (def: array, ctx: ParseContext) => BaseRoot;
11
- export declare const parseTupleLiteral: (def: array, ctx: ParseContext) => BaseRoot;
12
- type InfixExpression = readonly [unknown, InfixOperator, ...unknown[]];
7
+ import { writeMissingRightOperandMessage } from "./shift/operand/unenclosed.ts";
8
+ import type { Scanner } from "./shift/scanner.ts";
9
+ import type { BaseCompletions } from "./string.ts";
10
+ export declare const parseTuple: (def: array, ctx: BaseParseContext) => BaseRoot;
11
+ export declare const parseTupleLiteral: (def: array, ctx: BaseParseContext) => BaseRoot;
12
+ type InfixExpression = readonly [unknown, Scanner.InfixToken, ...unknown[]];
13
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 [
14
14
  def[0] extends "" ? BaseCompletions<$, args, IndexZeroOperator | "..."> : def[0],
15
- def[1] extends "" ? BaseCompletions<$, args, IndexOneOperator | "..." | "?"> : def[1]
15
+ def[1] extends "" ? BaseCompletions<$, args, IndexOneOperator | "..."> : def[1]
16
16
  ] : validateTupleLiteral<def, $, args>;
17
17
  export type validateTupleLiteral<def extends array, $, args> = parseSequence<def, $, args> extends infer s extends SequenceParseState ? Readonly<s["validated"]> : never;
18
18
  type inferTupleLiteral<def extends array, $, args> = parseSequence<def, $, args> extends infer s extends SequenceParseState ? s["inferred"] : never;
@@ -20,55 +20,75 @@ type SequenceParseState = {
20
20
  unscanned: array;
21
21
  inferred: array;
22
22
  validated: array;
23
+ includesOptional: boolean;
23
24
  };
24
25
  type parseSequence<def extends array, $, args> = parseNextElement<{
25
26
  unscanned: def;
26
27
  inferred: [];
27
28
  validated: [];
29
+ includesOptional: false;
28
30
  }, $, args>;
29
31
  type PreparsedElement = {
30
32
  head: unknown;
31
33
  tail: array;
34
+ inferred: unknown;
32
35
  optional: boolean;
33
36
  spread: boolean;
34
37
  };
35
38
  declare namespace PreparsedElement {
36
39
  type from<result extends PreparsedElement> = result;
37
40
  }
38
- type preparseNextElement<s extends SequenceParseState> = s["unscanned"] extends readonly ["...", infer head, ...infer tail] ? tail extends readonly ["?", ...infer postOptionalTail] ? PreparsedElement.from<{
41
+ type preparseNextElement<s extends SequenceParseState, $, args> = s["unscanned"] extends readonly ["...", infer head, ...infer tail] ? inferDefinition<head, $, args> extends infer t ? [
42
+ t
43
+ ] extends [anyOrNever] ? PreparsedElement.from<{
39
44
  head: head;
40
- tail: postOptionalTail;
45
+ tail: tail;
46
+ inferred: t;
47
+ optional: false;
48
+ spread: true;
49
+ }> : [t] extends [InferredOptional<infer base>] ? PreparsedElement.from<{
50
+ head: head;
51
+ tail: tail;
52
+ inferred: base;
41
53
  optional: true;
42
54
  spread: true;
43
55
  }> : PreparsedElement.from<{
44
56
  head: head;
45
57
  tail: tail;
58
+ inferred: t;
46
59
  optional: false;
47
60
  spread: true;
48
- }> : s["unscanned"] extends readonly [infer head, "?", ...infer tail] ? PreparsedElement.from<{
61
+ }> : never : s["unscanned"] extends readonly [infer head, ...infer tail] ? inferDefinition<head, $, args> extends infer t ? [
62
+ t
63
+ ] extends [anyOrNever] ? PreparsedElement.from<{
49
64
  head: head;
50
65
  tail: tail;
66
+ inferred: t;
67
+ optional: false;
68
+ spread: false;
69
+ }> : [t] extends [InferredOptional<infer base>] ? PreparsedElement.from<{
70
+ head: head;
71
+ tail: tail;
72
+ inferred: base;
51
73
  optional: true;
52
74
  spread: false;
53
- }> : s["unscanned"] extends readonly [infer head, ...infer tail] ? PreparsedElement.from<{
75
+ }> : PreparsedElement.from<{
54
76
  head: head;
55
77
  tail: tail;
78
+ inferred: t;
56
79
  optional: false;
57
80
  spread: false;
58
- }> : null;
59
- type parseNextElement<s extends SequenceParseState, $, args> = preparseNextElement<s> extends infer next extends PreparsedElement ? parseNextElement<{
81
+ }> : never : null;
82
+ type parseNextElement<s extends SequenceParseState, $, args> = preparseNextElement<s, $, args> extends infer next extends PreparsedElement ? parseNextElement<{
60
83
  unscanned: next["tail"];
61
84
  inferred: next["spread"] extends true ? [
62
85
  ...s["inferred"],
63
- ...conform<inferDefinition<next["head"], $, args>, array>
64
- ] : next["optional"] extends true ? [
65
- ...s["inferred"],
66
- inferDefinition<next["head"], $, args>?
67
- ] : [...s["inferred"], inferDefinition<next["head"], $, args>];
86
+ ...conform<next["inferred"], array>
87
+ ] : next["optional"] extends true ? [...s["inferred"], next["inferred"]?] : [...s["inferred"], next["inferred"]];
68
88
  validated: [
69
89
  ...s["validated"],
70
90
  ...(next["spread"] extends true ? [
71
- inferDefinition<next["head"], $, args> extends (infer spreadOperand extends array) ? [
91
+ next["inferred"] extends infer spreadOperand extends array ? [
72
92
  number,
73
93
  number
74
94
  ] extends ([
@@ -76,17 +96,9 @@ type parseNextElement<s extends SequenceParseState, $, args> = preparseNextEleme
76
96
  spreadOperand["length"]
77
97
  ]) ? ErrorMessage<multipleVariadicMessage> : "..." : ErrorMessage<writeNonArraySpreadMessage<next["head"]>>
78
98
  ] : []),
79
- [
80
- next["optional"] | next["spread"],
81
- "?"
82
- ] extends ([
83
- false,
84
- s["validated"][number]
85
- ]) ? ErrorMessage<requiredPostOptionalMessage> : validateDefinition<next["head"], $, args>,
86
- ...(next["optional"] extends true ? [
87
- next["spread"] extends true ? ErrorMessage<spreadOptionalMessage> : number extends s["inferred"]["length"] ? ErrorMessage<optionalPostVariadicMessage> : "?"
88
- ] : [])
99
+ next["optional"] extends true ? next["spread"] extends true ? ErrorMessage<spreadOptionalMessage> : number extends s["inferred"]["length"] ? ErrorMessage<optionalPostVariadicMessage> : validateDefinition<next["head"], $, args> : [s["includesOptional"], next["spread"]] extends [true, false] ? ErrorMessage<requiredPostOptionalMessage> : validateDefinition<next["head"], $, args>
89
100
  ];
101
+ includesOptional: s["includesOptional"] | next["optional"] extends (false) ? false : true;
90
102
  }, $, args> : s;
91
103
  export declare const writeNonArraySpreadMessage: <operand extends string>(operand: operand) => writeNonArraySpreadMessage<operand>;
92
104
  type writeNonArraySpreadMessage<operand> = `Spread element must be an array${operand extends string ? ` (was ${operand})` : ""}`;
@@ -99,13 +111,13 @@ type optionalPostVariadicMessage = typeof optionalPostVariadicMessage;
99
111
  export declare const spreadOptionalMessage = "A spread element cannot be optional";
100
112
  type spreadOptionalMessage = typeof optionalPostVariadicMessage;
101
113
  export type inferTuple<def extends array, $, args> = def extends TupleExpression ? inferTupleExpression<def, $, args> : inferTupleLiteral<def, $, args>;
102
- 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 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 "=" ? associateAttributes<inferDefinition<def[0], $, args>, Default<def[2] extends Thunk<infer returnValue> ? returnValue : def[2]>> : def[1] extends "?" ? associateAttributes<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;
103
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;
104
- export type validatePostfixExpression<def extends PostfixExpression, $, args> = conform<def, readonly [validateDefinition<def[0], $, args>, "[]"]>;
116
+ export type validatePostfixExpression<def extends PostfixExpression, $, args> = conform<def, readonly [validateDefinition<def[0], $, args>, "[]" | "?"]>;
105
117
  export type validateInfixExpression<def extends InfixExpression, $, args> = def["length"] extends 2 ? readonly [def[0], writeMissingRightOperandMessage<def[1]>] : readonly [
106
118
  validateDefinition<def[0], $, args>,
107
119
  def[1],
108
- def[1] extends "|" ? validateDefinition<def[2], $, args> : def[1] extends "&" ? validateDefinition<def[2], $, args> : def[1] extends ":" ? Predicate<distillOut<inferDefinition<def[0], $, args>>> : def[1] extends "=>" ? Morph<distillOut<inferDefinition<def[0], $, args>>, unknown> : def[1] extends "@" ? MetaSchema : 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>
109
121
  ];
110
122
  export type UnparsedTupleExpressionInput = {
111
123
  instanceof: Constructor;
@@ -114,18 +126,18 @@ export type UnparsedTupleExpressionInput = {
114
126
  export type UnparsedTupleOperator = show<keyof UnparsedTupleExpressionInput>;
115
127
  export declare const parseKeyOfTuple: PrefixParser<"keyof">;
116
128
  export type inferKeyOfExpression<operandDef, $, args> = show<keyof inferDefinition<operandDef, $, args>>;
117
- export type PostfixParser<token extends IndexOneOperator> = (def: IndexOneExpression<token>, ctx: ParseContext) => BaseRoot;
118
- export type PrefixParser<token extends IndexZeroOperator> = (def: IndexZeroExpression<token>, ctx: ParseContext) => BaseRoot;
129
+ export type IndexOneParser<token extends IndexOneOperator> = (def: IndexOneExpression<token>, ctx: BaseParseContext) => BaseRoot;
130
+ export type PrefixParser<token extends IndexZeroOperator> = (def: IndexZeroExpression<token>, ctx: BaseParseContext) => BaseRoot;
119
131
  export type TupleExpression = IndexZeroExpression | IndexOneExpression;
120
132
  export type TupleExpressionOperator = IndexZeroOperator | IndexOneOperator;
121
133
  export type IndexOneOperator = TuplePostfixOperator | TupleInfixOperator;
122
- export type TuplePostfixOperator = "[]";
123
- export type TupleInfixOperator = "&" | "|" | "=>" | ":" | "@";
134
+ export type TuplePostfixOperator = "[]" | "?";
135
+ export type TupleInfixOperator = "&" | "|" | "=>" | ":" | "@" | "=";
124
136
  export type IndexOneExpression<token extends IndexOneOperator = IndexOneOperator> = readonly [unknown, token, ...unknown[]];
125
- export declare const parseMorphTuple: PostfixParser<"=>">;
137
+ export declare const parseMorphTuple: IndexOneParser<"=>">;
126
138
  export declare const writeMalformedFunctionalExpressionMessage: (operator: ":" | "=>", value: unknown) => string;
127
- export type parseMorph<inDef, morph, $, args> = morph extends Morph ? inferMorphOut<morph> extends infer out ? (In: distillConstrainableIn<inferDefinition<inDef, $, args>>) => Out<out> : never : never;
128
- export declare const parseNarrowTuple: PostfixParser<":">;
139
+ export type parseMorph<inDef, morph, $, args> = morph extends Morph ? inferMorphOut<morph> extends infer out ? (In: distill.withAttributes.In<inferDefinition<inDef, $, args>>) => Out<out> : never : never;
140
+ export declare const parseNarrowTuple: IndexOneParser<":">;
129
141
  export type IndexZeroOperator = "keyof" | "instanceof" | "===";
130
142
  export type IndexZeroExpression<token extends IndexZeroOperator = IndexZeroOperator> = readonly [token, ...unknown[]];
131
143
  export declare const writeInvalidConstructorMessage: <actual extends Domain | BuiltinObjectKind>(actual: actual) => string;
@@ -1,25 +1,18 @@
1
- import { $ark, makeRootAndArrayPropertiesMutable } from "@ark/schema";
2
- import { append, objectKindOrDomainOf, throwParseError } from "@ark/util";
3
- import { writeMissingRightOperandMessage } from "./string/shift/operand/unenclosed.js";
1
+ import { $ark, Disjoint, intersectNodesRoot, makeRootAndArrayPropertiesMutable } from "@ark/schema";
2
+ import { append, isEmptyObject, objectKindOrDomainOf, throwParseError } from "@ark/util";
3
+ import { writeMissingRightOperandMessage } from "./shift/operand/unenclosed.js";
4
4
  export const parseTuple = (def, ctx) => maybeParseTupleExpression(def, ctx) ?? parseTupleLiteral(def, ctx);
5
5
  export const parseTupleLiteral = (def, ctx) => {
6
6
  let sequences = [{}];
7
7
  let i = 0;
8
8
  while (i < def.length) {
9
9
  let spread = false;
10
- let optional = false;
11
10
  if (def[i] === "..." && i < def.length - 1) {
12
11
  spread = true;
13
12
  i++;
14
13
  }
15
- const element = ctx.$.parse(def[i], ctx);
14
+ const element = ctx.$.parseOwnDefinitionFormat(def[i], ctx);
16
15
  i++;
17
- if (def[i] === "?") {
18
- if (spread)
19
- return throwParseError(spreadOptionalMessage);
20
- optional = true;
21
- i++;
22
- }
23
16
  if (spread) {
24
17
  if (!element.extends($ark.intrinsic.Array))
25
18
  return throwParseError(writeNonArraySpreadMessage(element.expression));
@@ -31,13 +24,18 @@ export const parseTupleLiteral = (def, ctx) => {
31
24
  element.distribute(branch => appendSpreadBranch(makeRootAndArrayPropertiesMutable(base), branch)));
32
25
  }
33
26
  else {
34
- sequences = sequences.map(base => appendElement(base, optional ? "optional" : "required", element));
27
+ sequences = sequences.map(base => appendElement(base, element.meta.optional ? "optional" : "required", element));
35
28
  }
36
29
  }
37
- return ctx.$.internal.rootNode(sequences.map(sequence => ({
38
- proto: Array,
39
- sequence
40
- })));
30
+ return ctx.$.parseSchema(sequences.map(sequence => isEmptyObject(sequence) ?
31
+ {
32
+ proto: Array,
33
+ exactLength: 0
34
+ }
35
+ : {
36
+ proto: Array,
37
+ sequence
38
+ }));
41
39
  };
42
40
  const appendElement = (base, kind, element) => {
43
41
  switch (kind) {
@@ -86,11 +84,11 @@ const appendSpreadBranch = (base, branch) => {
86
84
  // the only array with no sequence reference is unknown[]
87
85
  return appendElement(base, "variadic", $ark.intrinsic.unknown);
88
86
  }
89
- spread.prefix.forEach(node => appendElement(base, "required", node));
90
- spread.optionals.forEach(node => appendElement(base, "optional", node));
87
+ spread.prefix?.forEach(node => appendElement(base, "required", node));
88
+ spread.optionals?.forEach(node => appendElement(base, "optional", node));
91
89
  if (spread.variadic)
92
90
  appendElement(base, "variadic", spread.variadic);
93
- spread.postfix.forEach(node => appendElement(base, "required", node));
91
+ spread.postfix?.forEach(node => appendElement(base, "required", node));
94
92
  return base;
95
93
  };
96
94
  const maybeParseTupleExpression = (def, ctx) => {
@@ -104,38 +102,46 @@ export const multipleVariadicMesage = "A tuple may have at most one variadic ele
104
102
  export const requiredPostOptionalMessage = "A required element may not follow an optional element";
105
103
  export const optionalPostVariadicMessage = "An optional element may not follow a variadic element";
106
104
  export const spreadOptionalMessage = "A spread element cannot be optional";
107
- export const parseKeyOfTuple = (def, ctx) => ctx.$.parse(def[1], ctx).keyof();
105
+ export const parseKeyOfTuple = (def, ctx) => ctx.$.parseOwnDefinitionFormat(def[1], ctx).keyof();
108
106
  const parseBranchTuple = (def, ctx) => {
109
107
  if (def[2] === undefined)
110
108
  return throwParseError(writeMissingRightOperandMessage(def[1], ""));
111
- const l = ctx.$.parse(def[0], ctx);
112
- const r = ctx.$.parse(def[2], ctx);
113
- return def[1] === "&" ? l.and(r) : l.or(r);
109
+ const l = ctx.$.parseOwnDefinitionFormat(def[0], ctx);
110
+ const r = ctx.$.parseOwnDefinitionFormat(def[2], ctx);
111
+ if (def[1] === "|")
112
+ return ctx.$.node("union", { branches: [l, r] });
113
+ const result = intersectNodesRoot(l, r, ctx.$);
114
+ if (result instanceof Disjoint)
115
+ return result.throw();
116
+ return result;
114
117
  };
115
- const parseArrayTuple = (def, ctx) => ctx.$.parse(def[0], ctx).array();
118
+ const parseArrayTuple = (def, ctx) => ctx.$.parseOwnDefinitionFormat(def[0], ctx).array();
116
119
  const isIndexOneExpression = (def) => indexOneParsers[def[1]] !== undefined;
117
120
  export const parseMorphTuple = (def, ctx) => {
118
121
  if (typeof def[2] !== "function") {
119
122
  return throwParseError(writeMalformedFunctionalExpressionMessage("=>", def[2]));
120
123
  }
121
- // TODO: nested morphs?
122
- return ctx.$.parse(def[0], ctx).pipe(def[2]);
124
+ return ctx.$.parseOwnDefinitionFormat(def[0], ctx).pipe(def[2]);
123
125
  };
124
126
  export const writeMalformedFunctionalExpressionMessage = (operator, value) => `${operator === ":" ? "Narrow" : "Morph"} expression requires a function following '${operator}' (was ${typeof value})`;
125
127
  export const parseNarrowTuple = (def, ctx) => {
126
128
  if (typeof def[2] !== "function") {
127
129
  return throwParseError(writeMalformedFunctionalExpressionMessage(":", def[2]));
128
130
  }
129
- return ctx.$.parse(def[0], ctx).constrain("predicate", def[2]);
131
+ return ctx.$.parseOwnDefinitionFormat(def[0], ctx).constrain("predicate", def[2]);
130
132
  };
131
- const parseAttributeTuple = (def, ctx) => ctx.$.parse(def[0], ctx).configureShallowDescendants(def[2]);
133
+ const parseAttributeTuple = (def, ctx) => ctx.$.parseOwnDefinitionFormat(def[0], ctx).configureShallowDescendants(def[2]);
134
+ const parseDefaultTuple = (def, ctx) => ctx.$.parseOwnDefinitionFormat(def[0], ctx).default(def[2]);
135
+ const parseOptionalTuple = (def, ctx) => ctx.$.parseOwnDefinitionFormat(def[0], ctx).optional();
132
136
  const indexOneParsers = {
137
+ "[]": parseArrayTuple,
138
+ "?": parseOptionalTuple,
133
139
  "|": parseBranchTuple,
134
140
  "&": parseBranchTuple,
135
- "[]": parseArrayTuple,
136
141
  ":": parseNarrowTuple,
137
142
  "=>": parseMorphTuple,
138
- "@": parseAttributeTuple
143
+ "@": parseAttributeTuple,
144
+ "=": parseDefaultTuple
139
145
  };
140
146
  const prefixParsers = {
141
147
  keyof: parseKeyOfTuple,
package/out/scope.d.ts CHANGED
@@ -1,22 +1,24 @@
1
- import { BaseScope, type AliasDefEntry, type ArkScopeConfig, type BaseNode, type BaseRoot, type GenericArgResolutions, type GenericAst, type GenericParamAst, type NodeKind, type NodeParseOptions, type NodeSchema, type PreparsedNodeResolution, type PrivateDeclaration, type RootKind, type RootSchema, type arkKind, type exportedNameOf, type nodeOfKind, type reducibleKindOf, type toInternalScope, type writeDuplicateAliasError } from "@ark/schema";
2
- import { type ErrorType, type Json, type anyOrNever, type array, type flattenListable, type inferred, type noSuggest, type nominal } from "@ark/util";
3
- import type { ArkAmbient, ArkSchemaRegistry } from "./config.ts";
4
- import { parseGenericParams, type GenericDeclaration, type GenericParser, type ParameterString, type baseGenericConstraints, type parseValidGenericParams } from "./generic.ts";
5
- import type { Ark, type } from "./keywords/ark.ts";
1
+ import { BaseScope, type AliasDefEntry, type ArkScopeConfig, type BaseNode, type BaseParseContext, type BaseParseContextInput, type BaseParseOptions, type BaseRoot, type GenericAst, type GenericParamAst, type GenericParamDef, type NodeKind, type NodeSchema, type PreparsedNodeResolution, type PrivateDeclaration, type RootKind, type RootSchema, type arkKind, type exportedNameOf, type nodeOfKind, type reducibleKindOf, type toInternalScope, type writeDuplicateAliasError } from "@ark/schema";
2
+ import { type ErrorType, type Json, type anyOrNever, type array, type flattenListable, type noSuggest, type nominal } from "@ark/util";
3
+ import type { ArkSchemaRegistry } from "./config.ts";
4
+ import { type GenericDeclaration, type GenericParser, type ParameterString, type baseGenericConstraints, type parseGenericParams, type parseValidGenericParams } from "./generic.ts";
5
+ import type { Ark, type } from "./keywords/keywords.ts";
6
6
  import type { BoundModule, Module, Submodule, instantiateExport } from "./module.ts";
7
+ import type { DefAst, InferredAst } from "./parser/ast/infer.ts";
7
8
  import { type inferDefinition, type validateDefinition } from "./parser/definition.ts";
8
- import type { DefAst, InferredAst } from "./parser/semantic/infer.ts";
9
- import type { ParsedDefault } from "./parser/string/shift/operator/default.ts";
10
- import { InternalTypeParser, type DeclarationParser, type DefinitionParser, type Type, type TypeParser } from "./type.ts";
11
- export type ScopeParser = <const def>(def: validateScope<def>, config?: ArkScopeConfig) => Scope<inferScope<def>>;
12
- export type ModuleParser = <const def>(def: validateScope<def>, config?: ArkScopeConfig) => inferScope<def> extends infer $ ? Module<{
9
+ import { InternalTypeParser, type DeclarationParser, type DefinitionParser, type EnumeratedTypeParser, type InstanceOfTypeParser, type SchemaParser, type TypeParser, type UnitTypeParser } from "./type.ts";
10
+ /** The convenience properties attached to `scope` */
11
+ export type ScopeParserAttachments = Omit<ScopeParser, never>;
12
+ export interface ScopeParser {
13
+ <const def>(def: scope.validate<def>, config?: ArkScopeConfig): Scope<scope.infer<def>>;
14
+ define: <const def>(def: scope.validate<def>) => def;
15
+ }
16
+ export type ModuleParser = <const def>(def: scope.validate<def>, config?: ArkScopeConfig) => scope.infer<def> extends infer $ ? Module<{
13
17
  [k in exportedNameOf<$>]: $[k];
14
18
  }> : never;
15
- export type validateScope<def> = {
16
- [k in keyof def]: k extends noSuggest ? unknown : parseScopeKey<k, def>["params"] extends infer params ? params extends array<GenericParamAst> ? params["length"] extends 0 ? def[k] extends Type.Any | PreparsedResolution ? def[k] : k extends PrivateDeclaration<infer name extends keyof def & string> ? ErrorType<writeDuplicateAliasError<name>> : validateDefinition<def[k], bootstrapAliases<def>, {}> : validateDefinition<def[k], bootstrapAliases<def>, baseGenericConstraints<params>> : params : never;
19
+ export type bindThis<def> = {
20
+ this: Def<def>;
17
21
  };
18
- export type inferScope<def> = inferBootstrapped<bootstrapAliases<def>>;
19
- export type bindThis<def> = {};
20
22
  /** nominal type for an unparsed definition used during scope bootstrapping */
21
23
  type Def<def = {}> = nominal<def, "unparsed">;
22
24
  /** sentinel indicating a scope that will be associated with a generic has not yet been parsed */
@@ -26,9 +28,9 @@ type PreparsedResolution = PreparsedNodeResolution;
26
28
  type bootstrapAliases<def> = {
27
29
  [k in Exclude<keyof def, GenericDeclaration>]: def[k] extends (PreparsedResolution) ? def[k] extends {
28
30
  t: infer g extends GenericAst;
29
- } ? g : def[k] extends Module<infer $> ? Submodule<$> : def[k] : def[k] extends (() => infer thunkReturn extends PreparsedResolution) ? thunkReturn extends {
31
+ } ? g : def[k] extends Module<infer $> | BoundModule<infer $, any> ? Submodule<$> : def[k] : def[k] extends (() => infer thunkReturn extends PreparsedResolution) ? thunkReturn extends {
30
32
  t: infer g extends GenericAst;
31
- } ? g : thunkReturn extends Module<infer $> ? Submodule<$> : thunkReturn : Def<def[k]>;
33
+ } ? g : thunkReturn extends Module<infer $> | BoundModule<infer $, any> ? Submodule<$> : thunkReturn : Def<def[k]>;
32
34
  } & {
33
35
  [k in keyof def & GenericDeclaration as extractGenericName<k>]: GenericAst<parseValidGenericParams<extractGenericParameters<k>, bootstrapAliases<def>>, def[k], UnparsedScope>;
34
36
  };
@@ -40,18 +42,12 @@ type inferBootstrapped<$> = {
40
42
  export type bindGenericToScope<g extends GenericAst, $> = GenericAst<g["paramsAst"], g["bodyDef"], g["$"] extends UnparsedScope ? $ : g["$"], $>;
41
43
  type extractGenericName<k> = k extends GenericDeclaration<infer name> ? name : never;
42
44
  type extractGenericParameters<k> = k extends `${string}<${infer params}>` ? ParameterString<params> : never;
43
- export type resolve<reference extends keyof $ | keyof args, $, args> = inferResolution<reference extends keyof args ? args[reference] : $[reference & keyof $], $, args>;
44
45
  export type resolutionToAst<alias extends string, resolution> = [
45
46
  resolution
46
47
  ] extends [anyOrNever] ? InferredAst<resolution, alias> : resolution extends Def<infer def> ? DefAst<def, alias> : resolution extends {
47
48
  [arkKind]: "module";
48
- $root: infer root;
49
+ root: infer root;
49
50
  } ? InferredAst<root, alias> : resolution extends GenericAst ? resolution : InferredAst<resolution, alias>;
50
- export type inferResolution<resolution, $, args> = [
51
- resolution
52
- ] extends [anyOrNever] ? resolution : resolution extends {
53
- [inferred]: infer t;
54
- } ? t : resolution extends Def<infer def> ? inferDefinition<def, $, args> : resolution;
55
51
  export type moduleKeyOf<$> = {
56
52
  [k in keyof $]: $[k] extends {
57
53
  [arkKind]: "module";
@@ -59,30 +55,26 @@ export type moduleKeyOf<$> = {
59
55
  $[k]
60
56
  ] extends [anyOrNever] ? never : k & string : never;
61
57
  }[keyof $];
62
- type unwrapPreinferred<t> = t extends type.cast<infer inferred> ? inferred : t;
63
- export type tryInferSubmoduleReference<$, token> = token extends `${infer submodule extends moduleKeyOf<$>}.${infer subalias}` ? subalias extends keyof $[submodule] ? unwrapPreinferred<$[submodule][subalias]> : tryInferSubmoduleReference<$[submodule], subalias> : token extends (`${infer submodule extends moduleKeyOf<ArkAmbient.$>}.${infer subalias}`) ? subalias extends keyof ArkAmbient.$[submodule] ? unwrapPreinferred<ArkAmbient.$[submodule][subalias]> : tryInferSubmoduleReference<ArkAmbient.$[submodule], subalias> : never;
64
58
  export interface ArkTypeRegistry extends ArkSchemaRegistry {
65
59
  typeAttachments?: Ark.boundTypeAttachments<any>;
66
60
  }
67
61
  export declare const $arkTypeRegistry: ArkTypeRegistry;
68
- export interface ParseContext extends TypeParseOptions {
69
- $: InternalScope;
70
- }
71
- export interface TypeParseOptions {
72
- args?: GenericArgResolutions;
73
- }
74
62
  export interface InternalScope {
75
63
  constructor: typeof InternalScope;
76
64
  }
77
65
  export declare class InternalScope<$ extends {} = {}> extends BaseScope<$> {
78
66
  private parseCache;
79
- preparseAlias(k: string, v: unknown): AliasDefEntry;
80
67
  protected cacheGetter<name extends keyof this>(name: name, value: this[name]): this[name];
81
- preparseRoot(def: unknown): unknown;
82
68
  get ambientAttachments(): Ark.boundTypeAttachments<$> | undefined;
83
- parse<defaultable extends boolean = false>(def: unknown, ctx: ParseContext, defaultable?: defaultable): BaseRoot | (defaultable extends false ? never : ParsedDefault);
84
- parseString<defaultable extends boolean>(def: string, ctx: ParseContext, defaultable: defaultable): BaseRoot | (defaultable extends false ? never : ParsedDefault);
85
- parseRoot: (def: unknown, opts?: TypeParseOptions) => BaseRoot;
69
+ protected preparseOwnAliasEntry(k: string, v: unknown): AliasDefEntry;
70
+ parseGenericParams(def: string, opts: BaseParseOptions): array<GenericParamDef>;
71
+ protected normalizeRootScopeValue(resolution: unknown): unknown;
72
+ protected preparseOwnDefinitionFormat(def: unknown, opts: BaseParseOptions): BaseRoot | BaseParseContextInput;
73
+ parseOwnDefinitionFormat(def: unknown, ctx: BaseParseContext): BaseRoot;
74
+ parseString(def: string, ctx: BaseParseContext): BaseRoot;
75
+ unit: UnitTypeParser<$>;
76
+ enumerated: EnumeratedTypeParser<$>;
77
+ instanceOf: InstanceOfTypeParser<$>;
86
78
  type: InternalTypeParser;
87
79
  declare: () => {
88
80
  type: InternalTypeParser;
@@ -92,6 +84,12 @@ export declare class InternalScope<$ extends {} = {}> extends BaseScope<$> {
92
84
  static module: ModuleParser;
93
85
  }
94
86
  export declare const scope: ScopeParser;
87
+ export declare namespace scope {
88
+ type validate<def> = {
89
+ [k in keyof def]: k extends noSuggest ? unknown : parseScopeKey<k, def>["params"] extends infer params ? params extends array<GenericParamAst> ? params["length"] extends 0 ? def[k] extends type.Any | PreparsedResolution ? def[k] : k extends (PrivateDeclaration<infer name extends keyof def & string>) ? ErrorType<writeDuplicateAliasError<name>> : validateDefinition<def[k], bootstrapAliases<def>, {}> : validateDefinition<def[k], bootstrapAliases<def>, baseGenericConstraints<params>> : params : never;
90
+ };
91
+ type infer<def> = inferBootstrapped<bootstrapAliases<def>>;
92
+ }
95
93
  export declare const module: ModuleParser;
96
94
  export interface Scope<$ = {}> {
97
95
  t: $;
@@ -105,12 +103,14 @@ export interface Scope<$ = {}> {
105
103
  aliases: Record<string, unknown>;
106
104
  internal: toInternalScope<$>;
107
105
  defineSchema<const def extends RootSchema>(schema: def): def;
108
- schema(schema: RootSchema, opts?: NodeParseOptions): BaseRoot;
109
- node<kinds extends NodeKind | array<RootKind>>(kinds: kinds, schema: NodeSchema<flattenListable<kinds>>, opts?: NodeParseOptions): nodeOfKind<reducibleKindOf<flattenListable<kinds>>>;
106
+ node<kinds extends NodeKind | array<RootKind>>(kinds: kinds, schema: NodeSchema<flattenListable<kinds>>, opts?: BaseParseOptions): nodeOfKind<reducibleKindOf<flattenListable<kinds>>>;
107
+ unit: UnitTypeParser<$>;
108
+ enumerated: EnumeratedTypeParser<$>;
110
109
  type: TypeParser<$>;
111
110
  declare: DeclarationParser<$>;
112
111
  define: DefinitionParser<$>;
113
112
  generic: GenericParser<$>;
113
+ schema: SchemaParser<$>;
114
114
  import(): Module<{
115
115
  [k in exportedNameOf<$> as PrivateDeclaration<k>]: $[k];
116
116
  }>;
@@ -131,7 +131,6 @@ export interface ScopeConstructor {
131
131
  module: ModuleParser;
132
132
  }
133
133
  export declare const Scope: ScopeConstructor;
134
- export declare const writeShallowCycleErrorMessage: (name: string, seen: string[]) => string;
135
134
  export type parseScopeKey<k, def> = k extends `${infer name}<${infer params}>` ? parseGenericScopeKey<name, params, def> : {
136
135
  name: k;
137
136
  params: [];