arktype 2.0.0-rc.1 → 2.0.0-rc.11

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 (141) hide show
  1. package/out/config.d.ts +1 -1
  2. package/out/generic.d.ts +47 -48
  3. package/out/generic.js +6 -8
  4. package/out/index.d.ts +4 -4
  5. package/out/index.js +2 -2
  6. package/out/keywords/builtins.js +2 -2
  7. package/out/keywords/constructors/Array.d.ts +2 -2
  8. package/out/keywords/constructors/Array.js +7 -7
  9. package/out/keywords/constructors/Date.d.ts +32 -0
  10. package/out/keywords/constructors/FormData.d.ts +2 -2
  11. package/out/keywords/constructors/FormData.js +8 -8
  12. package/out/keywords/constructors/TypedArray.js +2 -2
  13. package/out/keywords/constructors/constructors.d.ts +0 -1
  14. package/out/keywords/constructors/constructors.js +2 -2
  15. package/out/keywords/inference.d.ts +228 -0
  16. package/out/keywords/keywords.d.ts +62 -0
  17. package/out/keywords/{ark.js → keywords.js} +11 -8
  18. package/out/keywords/number/epoch.d.ts +1 -2
  19. package/out/keywords/number/epoch.js +2 -2
  20. package/out/keywords/number/integer.js +2 -2
  21. package/out/keywords/number/number.d.ts +32 -6
  22. package/out/keywords/number/number.js +17 -5
  23. package/out/keywords/string/alpha.d.ts +1 -1
  24. package/out/keywords/string/alphanumeric.d.ts +1 -1
  25. package/out/keywords/string/capitalize.d.ts +2 -2
  26. package/out/keywords/string/capitalize.js +4 -4
  27. package/out/keywords/string/creditCard.d.ts +1 -1
  28. package/out/keywords/string/creditCard.js +2 -2
  29. package/out/keywords/string/date.d.ts +4 -8
  30. package/out/keywords/string/date.js +16 -16
  31. package/out/keywords/string/digits.d.ts +1 -1
  32. package/out/keywords/string/email.d.ts +1 -1
  33. package/out/keywords/string/integer.d.ts +2 -2
  34. package/out/keywords/string/integer.js +7 -7
  35. package/out/keywords/string/ip.d.ts +2 -2
  36. package/out/keywords/string/ip.js +5 -5
  37. package/out/keywords/string/json.d.ts +3 -2
  38. package/out/keywords/string/json.js +24 -16
  39. package/out/keywords/string/lower.d.ts +2 -2
  40. package/out/keywords/string/lower.js +4 -4
  41. package/out/keywords/string/normalize.d.ts +23 -27
  42. package/out/keywords/string/normalize.js +14 -14
  43. package/out/keywords/string/numeric.d.ts +2 -2
  44. package/out/keywords/string/numeric.js +7 -7
  45. package/out/keywords/string/semver.d.ts +1 -1
  46. package/out/keywords/string/string.d.ts +39 -42
  47. package/out/keywords/string/string.js +3 -3
  48. package/out/keywords/string/trim.d.ts +2 -2
  49. package/out/keywords/string/trim.js +4 -4
  50. package/out/keywords/string/upper.d.ts +2 -2
  51. package/out/keywords/string/upper.js +4 -4
  52. package/out/keywords/string/url.d.ts +2 -2
  53. package/out/keywords/string/url.js +8 -8
  54. package/out/keywords/string/uuid.d.ts +11 -11
  55. package/out/keywords/string/uuid.js +3 -3
  56. package/out/keywords/ts.d.ts +38 -1
  57. package/out/keywords/ts.js +20 -4
  58. package/out/keywords/utils.d.ts +1 -1
  59. package/out/keywords/utils.js +1 -1
  60. package/out/{subtypes → methods}/array.d.ts +6 -6
  61. package/out/methods/base.d.ts +96 -0
  62. package/out/{subtypes → methods}/date.d.ts +5 -5
  63. package/out/{subtypes → methods}/instantiate.d.ts +5 -4
  64. package/out/methods/morph.d.ts +12 -0
  65. package/out/{subtypes → methods}/number.d.ts +6 -6
  66. package/out/methods/object.d.ts +81 -0
  67. package/out/{subtypes → methods}/string.d.ts +7 -7
  68. package/out/{subtypes → methods}/validator.d.ts +2 -2
  69. package/out/module.d.ts +2 -2
  70. package/out/parser/{semantic → ast}/bounds.d.ts +3 -3
  71. package/out/parser/ast/default.d.ts +8 -0
  72. package/out/parser/{semantic → ast}/infer.d.ts +11 -11
  73. package/out/parser/{semantic → ast}/utils.d.ts +1 -1
  74. package/out/parser/{semantic → ast}/validate.d.ts +6 -6
  75. package/out/parser/definition.d.ts +8 -9
  76. package/out/parser/objectLiteral.d.ts +11 -37
  77. package/out/parser/objectLiteral.js +6 -24
  78. package/out/parser/{string/reduce → reduce}/dynamic.d.ts +5 -7
  79. package/out/parser/{string/reduce → reduce}/dynamic.js +5 -6
  80. package/out/parser/{string/reduce → reduce}/shared.d.ts +1 -1
  81. package/out/parser/{string/reduce → reduce}/static.d.ts +1 -1
  82. package/out/parser/{string/shift → shift}/operand/date.d.ts +3 -1
  83. package/out/parser/{string/shift → shift}/operand/enclosed.d.ts +3 -2
  84. package/out/parser/{string/shift → shift}/operand/enclosed.js +7 -3
  85. package/out/parser/{string/shift → shift}/operand/unenclosed.d.ts +3 -3
  86. package/out/parser/{string/shift → shift}/operand/unenclosed.js +7 -3
  87. package/out/parser/{string/shift → shift}/operator/bounds.d.ts +3 -3
  88. package/out/parser/{string/shift → shift}/operator/default.d.ts +3 -6
  89. package/out/parser/{string/shift → shift}/operator/default.js +1 -6
  90. package/out/parser/{string/shift → shift}/scanner.d.ts +3 -1
  91. package/out/parser/{string/shift → shift}/scanner.js +5 -3
  92. package/out/parser/{string/string.d.ts → string.d.ts} +6 -7
  93. package/out/parser/{string/string.js → string.js} +2 -0
  94. package/out/parser/tuple.d.ts +54 -43
  95. package/out/parser/tuple.js +36 -30
  96. package/out/scope.d.ts +32 -39
  97. package/out/scope.js +43 -35
  98. package/out/type.d.ts +24 -21
  99. package/out/type.js +14 -10
  100. package/package.json +3 -3
  101. package/out/intersect.d.ts +0 -28
  102. package/out/keys.d.ts +0 -16
  103. package/out/keywords/ark.d.ts +0 -39
  104. package/out/keywords/ast.d.ts +0 -193
  105. package/out/parser/semantic/default.d.ts +0 -9
  106. package/out/parser/semantic/default.js +0 -1
  107. package/out/subtypes/base.d.ts +0 -85
  108. package/out/subtypes/morph.d.ts +0 -13
  109. package/out/subtypes/object.d.ts +0 -33
  110. /package/out/{intersect.js → keywords/constructors/Date.js} +0 -0
  111. /package/out/keywords/{ast.js → inference.js} +0 -0
  112. /package/out/{subtypes → methods}/array.js +0 -0
  113. /package/out/{subtypes → methods}/base.js +0 -0
  114. /package/out/{subtypes → methods}/date.js +0 -0
  115. /package/out/{subtypes → methods}/instantiate.js +0 -0
  116. /package/out/{subtypes → methods}/morph.js +0 -0
  117. /package/out/{subtypes → methods}/number.js +0 -0
  118. /package/out/{subtypes → methods}/object.js +0 -0
  119. /package/out/{subtypes → methods}/string.js +0 -0
  120. /package/out/{subtypes → methods}/validator.js +0 -0
  121. /package/out/parser/{semantic → ast}/bounds.js +0 -0
  122. /package/out/{keys.js → parser/ast/default.js} +0 -0
  123. /package/out/parser/{semantic → ast}/divisor.d.ts +0 -0
  124. /package/out/parser/{semantic → ast}/divisor.js +0 -0
  125. /package/out/parser/{semantic → ast}/infer.js +0 -0
  126. /package/out/parser/{semantic → ast}/keyof.d.ts +0 -0
  127. /package/out/parser/{semantic → ast}/keyof.js +0 -0
  128. /package/out/parser/{semantic → ast}/utils.js +0 -0
  129. /package/out/parser/{semantic → ast}/validate.js +0 -0
  130. /package/out/parser/{string/reduce → reduce}/shared.js +0 -0
  131. /package/out/parser/{string/reduce → reduce}/static.js +0 -0
  132. /package/out/parser/{string/shift → shift}/operand/date.js +0 -0
  133. /package/out/parser/{string/shift → shift}/operand/genericArgs.d.ts +0 -0
  134. /package/out/parser/{string/shift → shift}/operand/genericArgs.js +0 -0
  135. /package/out/parser/{string/shift → shift}/operand/operand.d.ts +0 -0
  136. /package/out/parser/{string/shift → shift}/operand/operand.js +0 -0
  137. /package/out/parser/{string/shift → shift}/operator/bounds.js +0 -0
  138. /package/out/parser/{string/shift → shift}/operator/divisor.d.ts +0 -0
  139. /package/out/parser/{string/shift → shift}/operator/divisor.js +0 -0
  140. /package/out/parser/{string/shift → shift}/operator/operator.d.ts +0 -0
  141. /package/out/parser/{string/shift → shift}/operator/operator.js +0 -0
@@ -1,18 +1,17 @@
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 } from "@ark/util";
3
+ import type { applyConstraint, Default, distill, inferIntersection, inferMorphOut, inferPredicate, InferredOptional, Optional, Out } from "../keywords/inference.ts";
4
+ import type { type } from "../keywords/keywords.ts";
5
+ import type { InfixOperator, 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;
7
+ import { writeMissingRightOperandMessage } from "./shift/operand/unenclosed.ts";
8
+ import type { BaseCompletions } from "./string.ts";
9
+ export declare const parseTuple: (def: array, ctx: BaseParseContext) => BaseRoot;
10
+ export declare const parseTupleLiteral: (def: array, ctx: BaseParseContext) => BaseRoot;
12
11
  type InfixExpression = readonly [unknown, InfixOperator, ...unknown[]];
13
12
  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
13
  def[0] extends "" ? BaseCompletions<$, args, IndexZeroOperator | "..."> : def[0],
15
- def[1] extends "" ? BaseCompletions<$, args, IndexOneOperator | "..." | "?"> : def[1]
14
+ def[1] extends "" ? BaseCompletions<$, args, IndexOneOperator | "..."> : def[1]
16
15
  ] : validateTupleLiteral<def, $, args>;
17
16
  export type validateTupleLiteral<def extends array, $, args> = parseSequence<def, $, args> extends infer s extends SequenceParseState ? Readonly<s["validated"]> : never;
18
17
  type inferTupleLiteral<def extends array, $, args> = parseSequence<def, $, args> extends infer s extends SequenceParseState ? s["inferred"] : never;
@@ -20,55 +19,75 @@ type SequenceParseState = {
20
19
  unscanned: array;
21
20
  inferred: array;
22
21
  validated: array;
22
+ includesOptional: boolean;
23
23
  };
24
24
  type parseSequence<def extends array, $, args> = parseNextElement<{
25
25
  unscanned: def;
26
26
  inferred: [];
27
27
  validated: [];
28
+ includesOptional: false;
28
29
  }, $, args>;
29
30
  type PreparsedElement = {
30
31
  head: unknown;
31
32
  tail: array;
33
+ inferred: unknown;
32
34
  optional: boolean;
33
35
  spread: boolean;
34
36
  };
35
37
  declare namespace PreparsedElement {
36
38
  type from<result extends PreparsedElement> = result;
37
39
  }
38
- type preparseNextElement<s extends SequenceParseState> = s["unscanned"] extends readonly ["...", infer head, ...infer tail] ? tail extends readonly ["?", ...infer postOptionalTail] ? PreparsedElement.from<{
40
+ type preparseNextElement<s extends SequenceParseState, $, args> = s["unscanned"] extends readonly ["...", infer head, ...infer tail] ? inferDefinition<head, $, args> extends infer t ? [
41
+ t
42
+ ] extends [anyOrNever] ? PreparsedElement.from<{
39
43
  head: head;
40
- tail: postOptionalTail;
44
+ tail: tail;
45
+ inferred: t;
46
+ optional: false;
47
+ spread: true;
48
+ }> : [t] extends [InferredOptional<infer base>] ? PreparsedElement.from<{
49
+ head: head;
50
+ tail: tail;
51
+ inferred: base;
41
52
  optional: true;
42
53
  spread: true;
43
54
  }> : PreparsedElement.from<{
44
55
  head: head;
45
56
  tail: tail;
57
+ inferred: t;
46
58
  optional: false;
47
59
  spread: true;
48
- }> : s["unscanned"] extends readonly [infer head, "?", ...infer tail] ? PreparsedElement.from<{
60
+ }> : never : s["unscanned"] extends readonly [infer head, ...infer tail] ? inferDefinition<head, $, args> extends infer t ? [
61
+ t
62
+ ] extends [anyOrNever] ? PreparsedElement.from<{
49
63
  head: head;
50
64
  tail: tail;
65
+ inferred: t;
66
+ optional: false;
67
+ spread: false;
68
+ }> : [t] extends [InferredOptional<infer base>] ? PreparsedElement.from<{
69
+ head: head;
70
+ tail: tail;
71
+ inferred: base;
51
72
  optional: true;
52
73
  spread: false;
53
- }> : s["unscanned"] extends readonly [infer head, ...infer tail] ? PreparsedElement.from<{
74
+ }> : PreparsedElement.from<{
54
75
  head: head;
55
76
  tail: tail;
77
+ inferred: t;
56
78
  optional: false;
57
79
  spread: false;
58
- }> : null;
59
- type parseNextElement<s extends SequenceParseState, $, args> = preparseNextElement<s> extends infer next extends PreparsedElement ? parseNextElement<{
80
+ }> : never : null;
81
+ type parseNextElement<s extends SequenceParseState, $, args> = preparseNextElement<s, $, args> extends infer next extends PreparsedElement ? parseNextElement<{
60
82
  unscanned: next["tail"];
61
83
  inferred: next["spread"] extends true ? [
62
84
  ...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>];
85
+ ...conform<next["inferred"], array>
86
+ ] : next["optional"] extends true ? [...s["inferred"], next["inferred"]?] : [...s["inferred"], next["inferred"]];
68
87
  validated: [
69
88
  ...s["validated"],
70
89
  ...(next["spread"] extends true ? [
71
- inferDefinition<next["head"], $, args> extends (infer spreadOperand extends array) ? [
90
+ next["inferred"] extends infer spreadOperand extends array ? [
72
91
  number,
73
92
  number
74
93
  ] extends ([
@@ -76,17 +95,9 @@ type parseNextElement<s extends SequenceParseState, $, args> = preparseNextEleme
76
95
  spreadOperand["length"]
77
96
  ]) ? ErrorMessage<multipleVariadicMessage> : "..." : ErrorMessage<writeNonArraySpreadMessage<next["head"]>>
78
97
  ] : []),
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
- ] : [])
98
+ 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
99
  ];
100
+ includesOptional: s["includesOptional"] | next["optional"] extends (false) ? false : true;
90
101
  }, $, args> : s;
91
102
  export declare const writeNonArraySpreadMessage: <operand extends string>(operand: operand) => writeNonArraySpreadMessage<operand>;
92
103
  type writeNonArraySpreadMessage<operand> = `Spread element must be an array${operand extends string ? ` (was ${operand})` : ""}`;
@@ -99,13 +110,13 @@ type optionalPostVariadicMessage = typeof optionalPostVariadicMessage;
99
110
  export declare const spreadOptionalMessage = "A spread element cannot be optional";
100
111
  type spreadOptionalMessage = typeof optionalPostVariadicMessage;
101
112
  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;
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;
103
114
  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>, "[]"]>;
115
+ export type validatePostfixExpression<def extends PostfixExpression, $, args> = conform<def, readonly [validateDefinition<def[0], $, args>, "[]" | "?"]>;
105
116
  export type validateInfixExpression<def extends InfixExpression, $, args> = def["length"] extends 2 ? readonly [def[0], writeMissingRightOperandMessage<def[1]>] : readonly [
106
117
  validateDefinition<def[0], $, args>,
107
118
  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>
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>
109
120
  ];
110
121
  export type UnparsedTupleExpressionInput = {
111
122
  instanceof: Constructor;
@@ -114,18 +125,18 @@ export type UnparsedTupleExpressionInput = {
114
125
  export type UnparsedTupleOperator = show<keyof UnparsedTupleExpressionInput>;
115
126
  export declare const parseKeyOfTuple: PrefixParser<"keyof">;
116
127
  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;
128
+ export type IndexOneParser<token extends IndexOneOperator> = (def: IndexOneExpression<token>, ctx: BaseParseContext) => BaseRoot;
129
+ export type PrefixParser<token extends IndexZeroOperator> = (def: IndexZeroExpression<token>, ctx: BaseParseContext) => BaseRoot;
119
130
  export type TupleExpression = IndexZeroExpression | IndexOneExpression;
120
131
  export type TupleExpressionOperator = IndexZeroOperator | IndexOneOperator;
121
132
  export type IndexOneOperator = TuplePostfixOperator | TupleInfixOperator;
122
- export type TuplePostfixOperator = "[]";
123
- export type TupleInfixOperator = "&" | "|" | "=>" | ":" | "@";
133
+ export type TuplePostfixOperator = "[]" | "?";
134
+ export type TupleInfixOperator = "&" | "|" | "=>" | ":" | "@" | "=";
124
135
  export type IndexOneExpression<token extends IndexOneOperator = IndexOneOperator> = readonly [unknown, token, ...unknown[]];
125
- export declare const parseMorphTuple: PostfixParser<"=>">;
136
+ export declare const parseMorphTuple: IndexOneParser<"=>">;
126
137
  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<":">;
138
+ export type parseMorph<inDef, morph, $, args> = morph extends Morph ? inferMorphOut<morph> extends infer out ? (In: distill.brandable.In<inferDefinition<inDef, $, args>>) => Out<out> : never : never;
139
+ export declare const parseNarrowTuple: IndexOneParser<":">;
129
140
  export type IndexZeroOperator = "keyof" | "instanceof" | "===";
130
141
  export type IndexZeroExpression<token extends IndexZeroOperator = IndexZeroOperator> = readonly [token, ...unknown[]];
131
142
  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,19 @@
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 SchemaParser, type TypeParser, type UnitTypeParser } from "./type.ts";
10
+ export type ScopeParser = <const def>(def: scope.validate<def>, config?: ArkScopeConfig) => Scope<scope.infer<def>>;
11
+ export type ModuleParser = <const def>(def: scope.validate<def>, config?: ArkScopeConfig) => scope.infer<def> extends infer $ ? Module<{
13
12
  [k in exportedNameOf<$>]: $[k];
14
13
  }> : 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;
14
+ export type bindThis<def> = {
15
+ this: Def<def>;
17
16
  };
18
- export type inferScope<def> = inferBootstrapped<bootstrapAliases<def>>;
19
- export type bindThis<def> = {};
20
17
  /** nominal type for an unparsed definition used during scope bootstrapping */
21
18
  type Def<def = {}> = nominal<def, "unparsed">;
22
19
  /** sentinel indicating a scope that will be associated with a generic has not yet been parsed */
@@ -26,9 +23,9 @@ type PreparsedResolution = PreparsedNodeResolution;
26
23
  type bootstrapAliases<def> = {
27
24
  [k in Exclude<keyof def, GenericDeclaration>]: def[k] extends (PreparsedResolution) ? def[k] extends {
28
25
  t: infer g extends GenericAst;
29
- } ? g : def[k] extends Module<infer $> ? Submodule<$> : def[k] : def[k] extends (() => infer thunkReturn extends PreparsedResolution) ? thunkReturn extends {
26
+ } ? g : def[k] extends Module<infer $> | BoundModule<infer $, any> ? Submodule<$> : def[k] : def[k] extends (() => infer thunkReturn extends PreparsedResolution) ? thunkReturn extends {
30
27
  t: infer g extends GenericAst;
31
- } ? g : thunkReturn extends Module<infer $> ? Submodule<$> : thunkReturn : Def<def[k]>;
28
+ } ? g : thunkReturn extends Module<infer $> | BoundModule<infer $, any> ? Submodule<$> : thunkReturn : Def<def[k]>;
32
29
  } & {
33
30
  [k in keyof def & GenericDeclaration as extractGenericName<k>]: GenericAst<parseValidGenericParams<extractGenericParameters<k>, bootstrapAliases<def>>, def[k], UnparsedScope>;
34
31
  };
@@ -40,18 +37,12 @@ type inferBootstrapped<$> = {
40
37
  export type bindGenericToScope<g extends GenericAst, $> = GenericAst<g["paramsAst"], g["bodyDef"], g["$"] extends UnparsedScope ? $ : g["$"], $>;
41
38
  type extractGenericName<k> = k extends GenericDeclaration<infer name> ? name : never;
42
39
  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
40
  export type resolutionToAst<alias extends string, resolution> = [
45
41
  resolution
46
42
  ] extends [anyOrNever] ? InferredAst<resolution, alias> : resolution extends Def<infer def> ? DefAst<def, alias> : resolution extends {
47
43
  [arkKind]: "module";
48
- $root: infer root;
44
+ root: infer root;
49
45
  } ? 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
46
  export type moduleKeyOf<$> = {
56
47
  [k in keyof $]: $[k] extends {
57
48
  [arkKind]: "module";
@@ -59,30 +50,25 @@ export type moduleKeyOf<$> = {
59
50
  $[k]
60
51
  ] extends [anyOrNever] ? never : k & string : never;
61
52
  }[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
53
  export interface ArkTypeRegistry extends ArkSchemaRegistry {
65
54
  typeAttachments?: Ark.boundTypeAttachments<any>;
66
55
  }
67
56
  export declare const $arkTypeRegistry: ArkTypeRegistry;
68
- export interface ParseContext extends TypeParseOptions {
69
- $: InternalScope;
70
- }
71
- export interface TypeParseOptions {
72
- args?: GenericArgResolutions;
73
- }
74
57
  export interface InternalScope {
75
58
  constructor: typeof InternalScope;
76
59
  }
77
60
  export declare class InternalScope<$ extends {} = {}> extends BaseScope<$> {
78
61
  private parseCache;
79
- preparseAlias(k: string, v: unknown): AliasDefEntry;
80
62
  protected cacheGetter<name extends keyof this>(name: name, value: this[name]): this[name];
81
- preparseRoot(def: unknown): unknown;
82
63
  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;
64
+ protected preparseOwnAliasEntry(k: string, v: unknown): AliasDefEntry;
65
+ parseGenericParams(def: string, opts: BaseParseOptions): array<GenericParamDef>;
66
+ protected normalizeRootScopeValue(resolution: unknown): unknown;
67
+ protected preparseOwnDefinitionFormat(def: unknown, opts: BaseParseOptions): BaseRoot | BaseParseContextInput;
68
+ parseOwnDefinitionFormat(def: unknown, ctx: BaseParseContext): BaseRoot;
69
+ parseString(def: string, ctx: BaseParseContext): BaseRoot;
70
+ unit: UnitTypeParser<$>;
71
+ enumerated: EnumeratedTypeParser<$>;
86
72
  type: InternalTypeParser;
87
73
  declare: () => {
88
74
  type: InternalTypeParser;
@@ -92,6 +78,12 @@ export declare class InternalScope<$ extends {} = {}> extends BaseScope<$> {
92
78
  static module: ModuleParser;
93
79
  }
94
80
  export declare const scope: ScopeParser;
81
+ export declare namespace scope {
82
+ type validate<def> = {
83
+ [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;
84
+ };
85
+ type infer<def> = inferBootstrapped<bootstrapAliases<def>>;
86
+ }
95
87
  export declare const module: ModuleParser;
96
88
  export interface Scope<$ = {}> {
97
89
  t: $;
@@ -105,12 +97,14 @@ export interface Scope<$ = {}> {
105
97
  aliases: Record<string, unknown>;
106
98
  internal: toInternalScope<$>;
107
99
  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>>>;
100
+ node<kinds extends NodeKind | array<RootKind>>(kinds: kinds, schema: NodeSchema<flattenListable<kinds>>, opts?: BaseParseOptions): nodeOfKind<reducibleKindOf<flattenListable<kinds>>>;
101
+ unit: UnitTypeParser<$>;
102
+ enumerated: EnumeratedTypeParser<$>;
110
103
  type: TypeParser<$>;
111
104
  declare: DeclarationParser<$>;
112
105
  define: DefinitionParser<$>;
113
106
  generic: GenericParser<$>;
107
+ schema: SchemaParser<$>;
114
108
  import(): Module<{
115
109
  [k in exportedNameOf<$> as PrivateDeclaration<k>]: $[k];
116
110
  }>;
@@ -131,7 +125,6 @@ export interface ScopeConstructor {
131
125
  module: ModuleParser;
132
126
  }
133
127
  export declare const Scope: ScopeConstructor;
134
- export declare const writeShallowCycleErrorMessage: (name: string, seen: string[]) => string;
135
128
  export type parseScopeKey<k, def> = k extends `${infer name}<${infer params}>` ? parseGenericScopeKey<name, params, def> : {
136
129
  name: k;
137
130
  params: [];
package/out/scope.js CHANGED
@@ -1,16 +1,28 @@
1
1
  import { $ark, BaseScope, hasArkKind, parseGeneric } from "@ark/schema";
2
2
  import { domainOf, flatMorph, hasDomain, isThunk, throwParseError } from "@ark/util";
3
- import { parseGenericParams } from "./generic.js";
3
+ import { parseGenericParamName } from "./generic.js";
4
4
  import { parseObject, writeBadDefinitionTypeMessage } from "./parser/definition.js";
5
- import { DynamicState } from "./parser/string/reduce/dynamic.js";
6
- import { writeUnexpectedCharacterMessage } from "./parser/string/shift/operator/operator.js";
7
- import { Scanner } from "./parser/string/shift/scanner.js";
8
- import { fullStringParse } from "./parser/string/string.js";
5
+ import { DynamicState } from "./parser/reduce/dynamic.js";
6
+ import { writeUnexpectedCharacterMessage } from "./parser/shift/operator/operator.js";
7
+ import { Scanner } from "./parser/shift/scanner.js";
8
+ import { fullStringParse } from "./parser/string.js";
9
9
  import { InternalTypeParser } from "./type.js";
10
10
  export const $arkTypeRegistry = $ark;
11
11
  export class InternalScope extends BaseScope {
12
12
  parseCache = {};
13
- preparseAlias(k, v) {
13
+ cacheGetter(name, value) {
14
+ Object.defineProperty(this, name, { value });
15
+ return value;
16
+ }
17
+ get ambientAttachments() {
18
+ if (!$arkTypeRegistry.typeAttachments)
19
+ return;
20
+ return this.cacheGetter("ambientAttachments", flatMorph($arkTypeRegistry.typeAttachments, (k, v) => [
21
+ k,
22
+ this.bindReference(v)
23
+ ]));
24
+ }
25
+ preparseOwnAliasEntry(k, v) {
14
26
  const firstParamIndex = k.indexOf("<");
15
27
  if (firstParamIndex === -1)
16
28
  return [k, v];
@@ -24,47 +36,46 @@ export class InternalScope extends BaseScope {
24
36
  // use a thunk definition for the generic so that we can parse
25
37
  // constraints within the current scope
26
38
  () => {
27
- const params = parseGenericParams(paramString, {
28
- $: this,
29
- args: {}
30
- });
39
+ const params = this.parseGenericParams(paramString, { alias: name });
31
40
  const generic = parseGeneric(params, v, this);
32
41
  return generic;
33
42
  }
34
43
  ];
35
44
  }
36
- cacheGetter(name, value) {
37
- Object.defineProperty(this, name, { value });
38
- return value;
45
+ parseGenericParams(def, opts) {
46
+ return parseGenericParamName(new Scanner(def), [], this.createParseContext({ ...opts, def, prefix: "generic" }));
39
47
  }
40
- preparseRoot(def) {
41
- if (isThunk(def) && !hasArkKind(def, "generic"))
42
- return def();
43
- return def;
48
+ normalizeRootScopeValue(resolution) {
49
+ if (isThunk(resolution) && !hasArkKind(resolution, "generic"))
50
+ return resolution();
51
+ return resolution;
44
52
  }
45
- get ambientAttachments() {
46
- if (!$arkTypeRegistry.typeAttachments)
47
- return;
48
- return this.cacheGetter("ambientAttachments", flatMorph($arkTypeRegistry.typeAttachments, (k, v) => [
49
- k,
50
- v.bindScope(this)
51
- ]));
53
+ preparseOwnDefinitionFormat(def, opts) {
54
+ return {
55
+ ...opts,
56
+ def,
57
+ prefix: opts.alias ?? "type"
58
+ };
52
59
  }
53
- parse(def, ctx, defaultable = false) {
60
+ parseOwnDefinitionFormat(def, ctx) {
61
+ const isScopeAlias = ctx.alias && ctx.alias in this.aliases;
62
+ // if the definition being parsed is not a scope alias and is not a
63
+ // generic instantiation (i.e. opts don't include args), add this as a resolution.
64
+ if (!isScopeAlias && !ctx.args)
65
+ ctx.args = { this: ctx.id };
54
66
  if (typeof def === "string") {
55
67
  if (ctx.args && Object.keys(ctx.args).some(k => def.includes(k))) {
56
68
  // we can only rely on the cache if there are no contextual
57
69
  // resolutions like "this" or generic args
58
- return this.parseString(def, ctx, defaultable);
70
+ return this.parseString(def, ctx);
59
71
  }
60
- const contextKey = `${def}${defaultable}`;
61
- return (this.parseCache[contextKey] ??= this.parseString(def, ctx, defaultable));
72
+ return (this.parseCache[def] ??= this.parseString(def, ctx));
62
73
  }
63
74
  return hasDomain(def, "object") ?
64
75
  parseObject(def, ctx)
65
76
  : throwParseError(writeBadDefinitionTypeMessage(domainOf(def)));
66
77
  }
67
- parseString(def, ctx, defaultable) {
78
+ parseString(def, ctx) {
68
79
  const aliasResolution = this.maybeResolveRoot(def);
69
80
  if (aliasResolution)
70
81
  return aliasResolution;
@@ -73,16 +84,14 @@ export class InternalScope extends BaseScope {
73
84
  : undefined;
74
85
  if (aliasArrayResolution)
75
86
  return aliasArrayResolution;
76
- const s = new DynamicState(new Scanner(def), ctx, defaultable);
87
+ const s = new DynamicState(new Scanner(def), ctx);
77
88
  const node = fullStringParse(s);
78
89
  if (s.finalizer === ">")
79
90
  throwParseError(writeUnexpectedCharacterMessage(">"));
80
91
  return node;
81
92
  }
82
- parseRoot = (def, opts = {}) => {
83
- const node = this.parse(def, Object.assign(this.finalizeRootArgs(opts, () => node), { $: this })).bindScope(this);
84
- return node;
85
- };
93
+ unit = value => this.units([value]);
94
+ enumerated = (...values) => this.units(values);
86
95
  type = new InternalTypeParser(this);
87
96
  declare = () => ({
88
97
  type: this.type
@@ -94,4 +103,3 @@ export class InternalScope extends BaseScope {
94
103
  export const scope = InternalScope.scope;
95
104
  export const module = InternalScope.module;
96
105
  export const Scope = InternalScope;
97
- export const writeShallowCycleErrorMessage = (name, seen) => `Alias '${name}' has a shallow resolution cycle: ${[...seen, name].join(":")}`;