arktype 2.2.10 → 3.0.0-beta.1

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 (164) hide show
  1. package/README.md +181 -15
  2. package/out/attributes.d.ts +50 -14
  3. package/out/checkers.d.ts +172 -0
  4. package/out/chunk-2U2AWCI3.js +626 -0
  5. package/out/chunk-4CUA5XIP.js +7 -0
  6. package/out/chunk-5U2ZMDNI.js +1566 -0
  7. package/out/chunk-DLWCO4RV.js +18 -0
  8. package/out/chunk-E3DZXEZK.js +72 -0
  9. package/out/chunk-EVCML554.js +47 -0
  10. package/out/chunk-G45P2CLE.js +63 -0
  11. package/out/chunk-GPNK5353.js +2529 -0
  12. package/out/chunk-MLKGABMK.js +9 -0
  13. package/out/chunk-NRIGTMPM.js +7 -0
  14. package/out/chunk-PRTMQCHS.js +3 -0
  15. package/out/chunk-R5G57XC7.js +7 -0
  16. package/out/chunk-RAZ3TXOE.js +313 -0
  17. package/out/chunk-SWOOCAHN.js +4 -0
  18. package/out/chunk-TAHPKDNM.js +3 -0
  19. package/out/chunk-UETB6YE2.js +14 -0
  20. package/out/chunk-UK5UGFOX.js +254 -0
  21. package/out/chunk-VV6YDN2D.js +6118 -0
  22. package/out/codecs.d.ts +21 -0
  23. package/out/codecs.js +7 -0
  24. package/out/config.d.ts +8 -3
  25. package/out/config.js +2 -3
  26. package/out/declare.d.ts +17 -3
  27. package/out/deferred.d.ts +10 -0
  28. package/out/errors.d.ts +1 -0
  29. package/out/errors.js +2 -0
  30. package/out/fn.d.ts +1 -1
  31. package/out/generic.d.ts +3 -3
  32. package/out/i18n.d.ts +2 -0
  33. package/out/i18n.js +2 -0
  34. package/out/index.d.ts +5 -4
  35. package/out/index.js +8 -9
  36. package/out/internal.d.ts +70 -0
  37. package/out/internal.js +17 -0
  38. package/out/island.d.ts +2 -0
  39. package/out/island.js +6 -0
  40. package/out/islandDependency.d.ts +2 -0
  41. package/out/islandDependency.js +18 -0
  42. package/out/keywords/Array.d.ts +2 -2
  43. package/out/keywords/builtins.d.ts +5 -3
  44. package/out/keywords/constructors.d.ts +9 -1
  45. package/out/keywords/functions.d.ts +254 -0
  46. package/out/keywords/keywords.d.ts +8 -9
  47. package/out/keywords/number.d.ts +2 -8
  48. package/out/keywords/phrases.d.ts +245 -0
  49. package/out/keywords/string.d.ts +14 -113
  50. package/out/keywords/ts.d.ts +35 -33
  51. package/out/keywords/ts.js +4 -82
  52. package/out/locale.d.ts +19 -0
  53. package/out/locales/de.d.ts +2 -0
  54. package/out/locales/de.js +2 -0
  55. package/out/locales/en.d.ts +4 -0
  56. package/out/locales/en.js +5 -0
  57. package/out/match.d.ts +6 -6
  58. package/out/module.d.ts +1 -1
  59. package/out/mutatesInput.js +3 -0
  60. package/out/parser/ast/generic.d.ts +6 -3
  61. package/out/parser/ast/infer.d.ts +1 -1
  62. package/out/parser/ast/validate.d.ts +11 -6
  63. package/out/parser/definition.d.ts +68 -7
  64. package/out/parser/objectLiteral.d.ts +40 -12
  65. package/out/parser/property.d.ts +3 -5
  66. package/out/parser/reduce/dynamic.d.ts +16 -7
  67. package/out/parser/reduce/shared.d.ts +4 -0
  68. package/out/parser/reduce/static.d.ts +13 -13
  69. package/out/parser/shift/operand/date.d.ts +0 -5
  70. package/out/parser/shift/operand/operand.d.ts +2 -1
  71. package/out/parser/shift/operand/unenclosed.d.ts +9 -6
  72. package/out/parser/shift/operand/unresolvable.d.ts +68 -0
  73. package/out/parser/shift/operator/bounds.d.ts +9 -4
  74. package/out/parser/shift/operator/brand.d.ts +2 -2
  75. package/out/parser/shift/operator/default.d.ts +2 -2
  76. package/out/parser/shift/operator/divisor.d.ts +2 -2
  77. package/out/parser/shift/operator/operator.d.ts +1 -1
  78. package/out/parser/shift/tokens.d.ts +9 -2
  79. package/out/parser/string.d.ts +61 -7
  80. package/out/parser/tupleExpressions.d.ts +7 -3
  81. package/out/precompiled.d.ts +1 -0
  82. package/out/precompiled.js +2 -0
  83. package/out/runtime.d.ts +181 -0
  84. package/out/runtime.js +4 -0
  85. package/out/runtimeDevelopment.d.ts +1 -0
  86. package/out/runtimeDevelopment.js +133 -0
  87. package/out/runtimeExports.d.ts +1 -0
  88. package/out/scope.d.ts +40 -11
  89. package/out/standalone/artifact.d.ts +265 -0
  90. package/out/standalone/baking.d.ts +201 -0
  91. package/out/standalone/combinators.d.ts +13 -0
  92. package/out/standalone/compilers.d.ts +23 -0
  93. package/out/standalone/creators.d.ts +41 -0
  94. package/out/standalone/fallbacks.d.ts +48 -0
  95. package/out/standalone/keys.d.ts +31 -0
  96. package/out/standalone/modules.d.ts +26 -0
  97. package/out/standalone/sites.d.ts +52 -0
  98. package/out/standalone/units.d.ts +31 -0
  99. package/out/standalone/values.d.ts +60 -0
  100. package/out/standalone.d.ts +16 -0
  101. package/out/type.d.ts +45 -6
  102. package/out/variants/array.d.ts +1 -1
  103. package/out/variants/base.d.ts +47 -27
  104. package/out/variants/date.d.ts +1 -1
  105. package/out/variants/instantiate.d.ts +4 -2
  106. package/out/variants/number.d.ts +1 -1
  107. package/out/variants/object.d.ts +17 -12
  108. package/out/variants/string.d.ts +1 -1
  109. package/package.json +169 -8
  110. package/skills/arktype/SKILL.md +278 -43
  111. package/skills/arktype/references/migrating.md +1296 -0
  112. package/skills/arktype/references/precompile.md +191 -0
  113. package/out/attributes.js +0 -3
  114. package/out/fn.js +0 -58
  115. package/out/generic.js +0 -37
  116. package/out/keywords/Array.js +0 -21
  117. package/out/keywords/FormData.js +0 -40
  118. package/out/keywords/TypedArray.js +0 -16
  119. package/out/keywords/builtins.js +0 -11
  120. package/out/keywords/constructors.js +0 -16
  121. package/out/keywords/keywords.js +0 -48
  122. package/out/keywords/number.js +0 -49
  123. package/out/keywords/string.js +0 -467
  124. package/out/match.js +0 -95
  125. package/out/module.js +0 -3
  126. package/out/nary.js +0 -1
  127. package/out/parser/ast/bounds.js +0 -1
  128. package/out/parser/ast/default.js +0 -1
  129. package/out/parser/ast/divisor.js +0 -1
  130. package/out/parser/ast/generic.js +0 -1
  131. package/out/parser/ast/infer.js +0 -1
  132. package/out/parser/ast/keyof.js +0 -1
  133. package/out/parser/ast/utils.js +0 -1
  134. package/out/parser/ast/validate.js +0 -3
  135. package/out/parser/definition.js +0 -78
  136. package/out/parser/objectLiteral.js +0 -113
  137. package/out/parser/property.js +0 -16
  138. package/out/parser/reduce/dynamic.js +0 -153
  139. package/out/parser/reduce/shared.js +0 -25
  140. package/out/parser/reduce/static.js +0 -1
  141. package/out/parser/shift/operand/date.js +0 -23
  142. package/out/parser/shift/operand/enclosed.js +0 -82
  143. package/out/parser/shift/operand/genericArgs.js +0 -16
  144. package/out/parser/shift/operand/operand.js +0 -16
  145. package/out/parser/shift/operand/unenclosed.js +0 -59
  146. package/out/parser/shift/operator/bounds.js +0 -91
  147. package/out/parser/shift/operator/brand.js +0 -6
  148. package/out/parser/shift/operator/default.js +0 -29
  149. package/out/parser/shift/operator/divisor.js +0 -13
  150. package/out/parser/shift/operator/operator.js +0 -28
  151. package/out/parser/shift/tokens.js +0 -37
  152. package/out/parser/string.js +0 -42
  153. package/out/parser/tupleExpressions.js +0 -75
  154. package/out/parser/tupleLiteral.js +0 -128
  155. package/out/scope.js +0 -106
  156. package/out/type.js +0 -55
  157. package/out/variants/array.js +0 -1
  158. package/out/variants/base.js +0 -1
  159. package/out/variants/date.js +0 -1
  160. package/out/variants/instantiate.js +0 -1
  161. package/out/variants/number.js +0 -1
  162. package/out/variants/object.js +0 -1
  163. package/out/variants/string.js +0 -1
  164. /package/out/{declare.js → mutatesInput.d.ts} +0 -0
@@ -1,8 +1,10 @@
1
- import { type BaseParseContext, type BaseRoot, type StandardSchemaV1 } from "@ark/schema";
2
- import { type anyOrNever, type array, type ErrorMessage, type Fn, type ifEmptyObjectLiteral, type objectKindOrDomainOf, type Primitive } from "@ark/util";
1
+ import { BaseRoot, type BaseParseContext, type StandardSchemaV1 } from "@ark/schema";
2
+ import { type anyOrNever, type array, type Constructor, type ErrorMessage, type Fn, type ifEmptyObjectLiteral, type inferred, type objectKindOrDomainOf, type Primitive } from "@ark/util";
3
3
  import type { Out } from "../attributes.ts";
4
4
  import type { type } from "../keywords/keywords.ts";
5
5
  import type { InnerParseResult } from "../scope.ts";
6
+ import type { instantiateType } from "../variants/instantiate.ts";
7
+ import type { ObjectType } from "../variants/object.ts";
6
8
  import type { shallowDefaultableMessage, shallowOptionalMessage, validateString } from "./ast/validate.ts";
7
9
  import { type inferObjectLiteral, type validateObjectLiteral } from "./objectLiteral.ts";
8
10
  import type { isDefaultable, OptionalPropertyDefinition } from "./property.ts";
@@ -11,20 +13,79 @@ import { type inferTupleExpression, type maybeValidateTupleExpression, type Tupl
11
13
  import { type inferTupleLiteral, type validateTupleLiteral } from "./tupleLiteral.ts";
12
14
  export declare const parseInnerDefinition: (def: unknown, ctx: BaseParseContext) => InnerParseResult;
13
15
  export declare const parseObject: (def: object, ctx: BaseParseContext) => BaseRoot;
16
+ export declare const writeAsyncStandardSchemaMessage: (vendor: string) => string;
14
17
  export type inferDefinition<def, $, args> = [
15
18
  def
16
- ] extends [anyOrNever] ? def : def extends type.cast<infer t> ? ifEmptyObjectLiteral<def, object, t> : def extends ThunkCast<infer t> ? t : def extends string ? inferString<def, $, args> : def extends array ? inferTuple<def, $, args> : def extends RegExp ? string : def extends StandardSchemaV1 ? inferStandardSchema<def> : def extends object ? inferObjectLiteral<def, $, args> : never;
19
+ ] extends [anyOrNever] ? def : def extends type.cast<infer t> ? def extends {
20
+ [inferred]: infer t;
21
+ } ? t : unknown extends t ? ifEmptyObjectLiteral<def, object, t> : t : def extends ThunkCast<infer t> ? t : def extends string ? inferString<def, $, args> : def extends array ? inferTuple<def, $, args> : def extends RegExp ? string : def extends StandardSchemaV1 ? inferStandardSchema<def> : def extends object ? inferObjectLiteral<def, $, args> : never;
22
+ export type instantiateDefinition<def, $, args> = [
23
+ def
24
+ ] extends [anyOrNever | string | NonLiteralObjectDefinition] ? instantiateType<inferDefinition<def, $, args>, $> : [def] extends [object] ? "..." extends keyof def ? instantiateType<inferDefinition<def, $, args>, $> : isSingleDefinition<def> extends true ? ObjectType<inferObjectLiteral<def, $, args>, $> : instantiateType<inferDefinition<def, $, args>, $> : instantiateType<inferDefinition<def, $, args>, $>;
25
+ type NonLiteralObjectDefinition = type.cast<unknown> | ThunkCast | array | RegExp | StandardSchemaV1;
26
+ type isSingleDefinition<def, original = def> = def extends unknown ? [
27
+ original
28
+ ] extends [def] ? true : false : never;
17
29
  type inferStandardSchema<schema extends StandardSchemaV1, i = StandardSchemaV1.InferInput<schema>, o = StandardSchemaV1.InferOutput<schema>> = [i, o] extends [o, i] ? i : (In: i) => Out<o>;
18
30
  export type validateDefinition<def, $, args> = null extends undefined ? ErrorMessage<`'strict' or 'strictNullChecks' must be set to true in your tsconfig's 'compilerOptions'`> : [def] extends [anyOrNever] ? def : def extends OptionalPropertyDefinition ? ErrorMessage<shallowOptionalMessage> : isDefaultable<def, $, args> extends true ? ErrorMessage<shallowDefaultableMessage> : validateInnerDefinition<def, $, args>;
19
- export type validateInnerDefinition<def, $, args> = [
20
- def
21
- ] extends [TerminalObjectDefinition] ? def : def extends string ? validateString<def, $, args> : unknown extends def ? BaseCompletions<$, args> | {} : def extends readonly unknown[] ? validateTuple<def, $, args> : def extends BadDefinitionType ? ErrorMessage<writeBadDefinitionTypeMessage<objectKindOrDomainOf<def>>> : validateObjectLiteral<def, $, args>;
31
+ /**
32
+ * {@link validateDefinition} as the type of a parameter (`type.validate`),
33
+ * written so that completing a string passed directly to `type()` stays fast.
34
+ * Once `def` is resolved it is exactly `validateDefinition<def, $, args>`.
35
+ *
36
+ * To complete a string argument, TypeScript first resolves the call with
37
+ * inference blocked from that string, which it does by inferring from the
38
+ * parameter's type to itself. Wherever that meets the same alias on both sides
39
+ * with `def` among its arguments, it asks for the alias's variance, and the
40
+ * variance of a conditional type is measured by comparing instantiations of it,
41
+ * which recurses into every alias the validator can reach. An editor rebuilds
42
+ * the checker on each edit, so that was paid on every keystroke: 650ms a
43
+ * completion on TypeScript 6 and 200ms on 7, for a call that checks in a few.
44
+ * `completions.test.ts` bounds the instantiations a completion costs. TypeScript
45
+ * 5.1 has no such pass, so nothing changes there.
46
+ *
47
+ * Each part of this is there for that pass:
48
+ *
49
+ * - Two references to one interface are inferred through their type arguments,
50
+ * and variance annotated `in out` is read rather than measured, so nothing
51
+ * behind {@link DefinitionArgument} is visited. Without the annotations a
52
+ * completion still takes 300ms.
53
+ * - The index is deferred while `def` is generic and is `"validated"` once
54
+ * it's resolved. Indexed by the literal, the interface would be replaced by
55
+ * its property where this alias is declared.
56
+ * - That hides the validator from ordinary inference too, which needs two
57
+ * things from it, so they are the false branch, which is never the result:
58
+ * `def` itself, and a mapped type over `keyof def`, through which TypeScript
59
+ * infers what it can of a definition containing a function it has yet to
60
+ * contextually type, like the morph of `["string", "=>", s => s.length]`.
61
+ * - The first check is resolved where this alias is declared, so its
62
+ * instantiations aren't recorded as this alias's. If they were, its own
63
+ * variance would be measured, which compares the validator after all.
64
+ */
65
+ export type validateDefinitionArgument<def, $, args> = null extends undefined ? validateDefinition<def, $, args> : [def] extends [unknown] ? DefinitionArgument<def, $, args>[def extends unknown ? "validated" : never] : [def] extends [anyOrNever] ? def : {
66
+ [k in keyof def]: validateDefinitionArgument<def[k], $, args>;
67
+ };
68
+ export interface DefinitionArgument<in out def, in out $, in out args> {
69
+ validated: validateDefinition<def, $, args>;
70
+ }
71
+ export type validateInnerDefinition<def, $, args> = def extends TerminalObjectDefinition ? validateTerminalObject<def> : def extends string ? validateString<def, $, args> : unknown extends def ? BaseCompletions<$, args> | {} : def extends readonly unknown[] ? validateTuple<def, $, args> : def extends BadDefinitionType ? ErrorMessage<writeBadDefinitionTypeMessage<objectKindOrDomainOf<def>>> : def extends Constructor ? ErrorMessage<writeBadDefinitionTypeMessage<"Function">> : validateObjectLiteral<def, $, args>;
22
72
  export declare const parseTuple: (def: array, ctx: BaseParseContext) => BaseRoot;
23
73
  export type validateTuple<def extends array, $, args> = maybeValidateTupleExpression<def, $, args> extends infer result ? result extends null ? validateTupleLiteral<def, $, args> : result : never;
24
74
  export type inferTuple<def extends array, $, args> = def extends TupleExpression ? inferTupleExpression<def, $, args> : inferTupleLiteral<def, $, args>;
25
75
  export type TerminalObjectDefinition = type.cast<unknown> | Fn | RegExp | StandardSchemaV1;
76
+ type validateTerminalObject<def> = def extends Constructor ? def extends StandardSchemaV1 ? def : ErrorMessage<writeBadDefinitionTypeMessage<"Function">> : def;
26
77
  export type ThunkCast<t = unknown> = () => type.cast<t>;
27
78
  type BadDefinitionType = Exclude<Primitive, string>;
28
79
  export declare const writeBadDefinitionTypeMessage: <actual extends string>(actual: actual) => writeBadDefinitionTypeMessage<actual>;
29
- type writeBadDefinitionTypeMessage<actual extends string> = `Type definitions must be strings or objects (was ${actual})`;
80
+ type writeBadDefinitionTypeMessage<actual extends string> = `Type definitions must be strings or objects (was ${actual})${actual extends (keyof badDefinitionHints) ? badDefinitionHints[actual] : ""}`;
81
+ declare const badDefinitionHints: {
82
+ readonly Function: ". Write a class as type.instanceOf(MyClass) or a keyword like Date, and a predicate as .narrow(fn)";
83
+ readonly number: ". Write a literal value in a string, or pass it to type.unit()";
84
+ readonly bigint: ". Write a literal value in a string, or pass it to type.unit()";
85
+ readonly boolean: ". Write a literal value in a string, or pass it to type.unit()";
86
+ readonly null: ". Write a literal value in a string, or pass it to type.unit()";
87
+ readonly undefined: ". Write a literal value in a string, or pass it to type.unit()";
88
+ readonly symbol: ". Write a literal value in a string, or pass it to type.unit()";
89
+ };
90
+ type badDefinitionHints = typeof badDefinitionHints;
30
91
  export {};
@@ -2,27 +2,43 @@ import { type BaseParseContext, type BaseRoot, type writeInvalidPropertyKeyMessa
2
2
  import { Backslash, type anyOrNever, type Dict, type ErrorMessage, type ErrorType, type Key, type merge, type show } from "@ark/util";
3
3
  import type { validateString } from "./ast/validate.ts";
4
4
  import type { inferDefinition } from "./definition.ts";
5
- import { type OptionalPropertyDefinition, type validateProperty } from "./property.ts";
5
+ import { type OptionalPropertyDefinition, type OptionalPropertyString, type validateProperty } from "./property.ts";
6
6
  export declare const parseObjectLiteral: (def: Dict, ctx: BaseParseContext) => BaseRoot;
7
- export type inferObjectLiteral<def extends object, $, args> = show<"..." extends keyof def ? merge<inferDefinition<def["..."], $, args>, _inferObjectLiteral<def, $, args>> : _inferObjectLiteral<def, $, args>>;
8
- /**
9
- * Infers the contents of an object literal, ignoring a spread definition
10
- */
11
- type _inferObjectLiteral<def extends object, $, args> = {
7
+ export type inferObjectLiteral<def extends object, $, args> = "..." extends keyof def ? show<merge<inferDefinition<def["..."], $, args>, inferKeyedObjectLiteral<def, $, args>>> : [keyof def & PreparsedKeyPattern] extends [never] ? inferUnparsedKeys<def, optionalKeyOf<def>, $, args> : show<inferKeyedObjectLiteral<def, $, args>>;
8
+ type PreparsedKeyPattern = number | MetaKey | IndexKey | `${string}${Backslash}${string}`;
9
+ type optionalKeyOf<def> = {
10
+ [k in keyof def]: k extends OptionalPropertyString ? k : def[k] extends OptionalPropertyDefinition ? [
11
+ def[k]
12
+ ] extends [anyOrNever] ? never : k : never;
13
+ }[keyof def];
14
+ type inferUnparsedKeys<def, optionalKey, $, args> = [
15
+ optionalKey
16
+ ] extends [never] ? {
17
+ -readonly [k in keyof def]: inferDefinition<def[k], $, args>;
18
+ } : show<inferUnparsedProps<def, optionalKey, $, args>>;
19
+ type inferUnparsedProps<def, optionalKey, $, args> = {
20
+ -readonly [k in keyof def as k extends optionalKey ? never : k]: inferDefinition<def[k], $, args>;
21
+ } & {
22
+ -readonly [k in keyof def as k extends optionalKey ? optionalKeyFromEntry<k, def[k]> : never]?: def[k] extends OptionalPropertyDefinition<infer baseDef> ? inferDefinition<baseDef, $, args> : inferDefinition<def[k], $, args>;
23
+ };
24
+ type inferKeyedObjectLiteral<def extends object, $, args> = {
12
25
  -readonly [k in keyof def as nonOptionalKeyFromEntry<k, def[k], $, args>]: inferDefinition<def[k], $, args>;
13
26
  } & {
14
27
  -readonly [k in keyof def as optionalKeyFromEntry<k, def[k]>]?: def[k] extends OptionalPropertyDefinition<infer baseDef> ? inferDefinition<baseDef, $, args> : inferDefinition<def[k], $, args>;
15
28
  };
16
29
  export type validateObjectLiteral<def, $, args> = {
17
- [k in keyof def]: preparseKey<k> extends (infer parsedKey extends PreparsedKey) ? parsedKey extends PreparsedEntryKey<"index"> ? validateString<parsedKey["normalized"], $, args> extends (ErrorMessage<infer message>) ? ErrorType<message> : inferDefinition<parsedKey["normalized"], $, args> extends Key ? validateProperty<def[k], parsedKey["kind"], $, args> : ErrorMessage<writeInvalidPropertyKeyMessage<parsedKey["normalized"]>> : validateProperty<def[k], parsedKey["kind"], $, args> : never;
30
+ [k in keyof def]: k extends PreparsedKeyPattern ? validatePreparsedEntry<k, def[k], $, args> : k extends OptionalPropertyString ? k extends `${infer indexKey extends IndexKey}?` ? ErrorMessage<writeOptionalIndexKeyMessage<indexKey>> : validateProperty<def[k], "optional", $, args> : validateProperty<def[k], "required", $, args>;
18
31
  };
32
+ type validatePreparsedEntry<k, v, $, args> = preparseKey<k> extends infer parsedKey extends PreparsedKey ? parsedKey extends PreparsedEntryKey<"index"> ? validateString<parsedKey["normalized"], $, args> extends (ErrorMessage<infer message>) ? ErrorType<message> : inferDefinition<parsedKey["normalized"], $, args> extends Key ? validateProperty<v, parsedKey["kind"], $, args> : ErrorMessage<writeInvalidPropertyKeyMessage<parsedKey["normalized"]>> : validateProperty<v, parsedKey["kind"], $, args> : never;
19
33
  type nonOptionalKeyFromEntry<k extends PropertyKey, v, $, args> = preparseKey<k> extends infer parsedKey ? parsedKey extends PreparsedEntryKey<"required"> ? [
20
34
  v
21
35
  ] extends [OptionalPropertyDefinition] ? [
22
36
  v
23
37
  ] extends [anyOrNever] ? parsedKey["normalized"] : never : parsedKey["normalized"] : parsedKey extends PreparsedEntryKey<"index"> ? inferDefinition<parsedKey["normalized"], $, args> & Key : never : never;
24
- type optionalKeyFromEntry<k extends PropertyKey, v> = preparseKey<k> extends infer parsedKey ? parsedKey extends PreparsedEntryKey<"optional"> ? parsedKey["normalized"] : v extends OptionalPropertyDefinition ? k : never : never;
38
+ type optionalKeyFromEntry<k extends PropertyKey, v> = preparseKey<k> extends infer parsedKey ? parsedKey extends PreparsedEntryKey<"optional"> ? parsedKey["normalized"] : parsedKey extends PreparsedEntryKey<"required"> ? v extends OptionalPropertyDefinition ? parsedKey["normalized"] : never : never : never;
25
39
  export declare const writeInvalidUndeclaredBehaviorMessage: (actual: unknown) => string;
40
+ export declare const writeOptionalIndexKeyMessage: <key extends IndexKey>(key: key) => writeOptionalIndexKeyMessage<key>;
41
+ export type writeOptionalIndexKeyMessage<key extends IndexKey> = `Index signature ${key} can't be optional. Escape its '[' with a backslash for an optional key named '${key}'`;
26
42
  export declare const nonLeadingSpreadError = "Spread operator may only be used as the first key in an object";
27
43
  export type PreparsedKey = PreparsedEntryKey | PreparsedSpecialKey;
28
44
  type normalizedKeyKind<kind extends EntryKeyKind> = kind extends "index" ? string : Key;
@@ -38,23 +54,35 @@ declare namespace PreparsedKey {
38
54
  }
39
55
  export type ParsedKeyKind = EntryKeyKind | SpecialKeyKind;
40
56
  export type EntryKeyKind = "required" | "optional" | "index";
41
- export type SpecialKeyKind = "spread" | "undeclared";
42
- export type MetaKey = "..." | "+";
57
+ export type SpecialKeyKind = "spread" | "undeclared" | "meta";
58
+ export type MetaKey = "..." | "+" | "@";
43
59
  export type IndexKey<def extends string = string> = `[${def}]`;
44
60
  export declare const preparseKey: (key: Key) => PreparsedKey;
45
61
  export type preparseKey<k> = k extends symbol ? PreparsedKey.from<{
46
62
  kind: "required";
47
63
  normalized: k;
48
- }> : k extends `${infer inner}?` ? inner extends `${infer baseName}${Backslash}` ? PreparsedKey.from<{
64
+ }> : k extends `${infer inner}?` ? inner extends `${string}${Backslash}${string}` ? inner extends `${infer baseName}${Backslash}` ? PreparsedKey.from<{
49
65
  kind: "required";
50
66
  normalized: `${baseName}?`;
67
+ }> : inner extends `${Backslash}${infer escapedIndexKey extends IndexKey}` ? PreparsedKey.from<{
68
+ kind: "optional";
69
+ normalized: escapedIndexKey;
70
+ }> : PreparsedKey.from<{
71
+ kind: "optional";
72
+ normalized: inner;
51
73
  }> : PreparsedKey.from<{
52
74
  kind: "optional";
53
75
  normalized: inner;
54
- }> : k extends "+" ? {
76
+ }> : k extends `${"+" | "." | "@" | Backslash | "["}${string}` ? preparseSpecialKey<k> : PreparsedKey.from<{
77
+ kind: "required";
78
+ normalized: k extends Key ? k : `${k & number}`;
79
+ }>;
80
+ type preparseSpecialKey<k> = k extends "+" ? {
55
81
  kind: "undeclared";
56
82
  } : k extends "..." ? {
57
83
  kind: "spread";
84
+ } : k extends "@" ? {
85
+ kind: "meta";
58
86
  } : k extends `${Backslash}${infer escapedMeta extends MetaKey}` ? PreparsedKey.from<{
59
87
  kind: "required";
60
88
  normalized: escapedMeta;
@@ -1,4 +1,4 @@
1
- import type { BaseParseContext, BaseRoot, UndeclaredKeyBehavior } from "@ark/schema";
1
+ import type { BaseParseContext, BaseRoot, TypeMeta, UndeclaredKeyBehavior } from "@ark/schema";
2
2
  import { type anyOrNever, type ErrorMessage, type ErrorType, type typeToString } from "@ark/util";
3
3
  import { type inferDefinition, type validateInnerDefinition } from "./definition.ts";
4
4
  import type { ParsedKeyKind, writeInvalidSpreadTypeMessage } from "./objectLiteral.ts";
@@ -9,9 +9,7 @@ export type ParsedProperty = ParsedRequiredProperty | ParsedOptionalProperty | P
9
9
  export type ParsedRequiredProperty = BaseRoot;
10
10
  export type ParsedOptionalProperty = readonly [BaseRoot, "?"];
11
11
  export declare const parseProperty: (def: unknown, ctx: BaseParseContext) => ParsedProperty;
12
- export type validateProperty<def, keyKind extends ParsedKeyKind, $, args> = [
13
- def
14
- ] extends [anyOrNever] ?
12
+ export type validateProperty<def, keyKind extends ParsedKeyKind, $, args> = keyKind extends "required" ? validateInnerDefinition<def, $, args> : [def] extends [anyOrNever] ?
15
13
  /** this extra [anyOrNever] check is required to ensure that nested `type` invocations
16
14
  * like the following are not prematurely validated by the outer call:
17
15
  *
@@ -21,7 +19,7 @@ export type validateProperty<def, keyKind extends ParsedKeyKind, $, args> = [
21
19
  * })
22
20
  * ```
23
21
  */
24
- def : keyKind extends "spread" ? def extends validateInnerDefinition<def, $, args> ? inferDefinition<def, $, args> extends object ? def : ErrorType<writeInvalidSpreadTypeMessage<typeToString<inferDefinition<def, $, args>>>> : validateInnerDefinition<def, $, args> : keyKind extends "undeclared" ? UndeclaredKeyBehavior : keyKind extends "required" ? validateInnerDefinition<def, $, args> : def extends OptionalPropertyDefinition ? ErrorMessage<invalidOptionalKeyKindMessage> : isDefaultable<def, $, args> extends true ? ErrorMessage<invalidDefaultableKeyKindMessage> : validateInnerDefinition<def, $, args>;
22
+ def : keyKind extends "spread" ? def extends validateInnerDefinition<def, $, args> ? inferDefinition<def, $, args> extends object ? def : ErrorType<writeInvalidSpreadTypeMessage<typeToString<inferDefinition<def, $, args>>>> : validateInnerDefinition<def, $, args> : keyKind extends "undeclared" ? UndeclaredKeyBehavior : keyKind extends "meta" ? TypeMeta.Collapsible : def extends OptionalPropertyDefinition ? ErrorMessage<invalidOptionalKeyKindMessage> : isDefaultable<def, $, args> extends true ? ErrorMessage<invalidDefaultableKeyKindMessage> : validateInnerDefinition<def, $, args>;
25
23
  export type isDefaultable<def, $, args> = def extends DefaultablePropertyTuple ? true : def extends PossibleDefaultableStringDefinition ? parseString<def, $, args> extends DefaultablePropertyTuple ? true : false : false;
26
24
  export type OptionalPropertyDefinition<baseDef = unknown> = OptionalPropertyTuple<baseDef> | OptionalPropertyString<baseDef & string>;
27
25
  export type OptionalPropertyString<baseDef extends string = string> = `${baseDef}?`;
@@ -2,12 +2,15 @@ import type { BaseParseContext, BaseRoot } from "@ark/schema";
2
2
  import { type requireKeys, type Scanner } from "@ark/util";
3
3
  import type { LimitLiteral } from "../../attributes.ts";
4
4
  import type { FinalizingLookahead, InfixToken } from "../shift/tokens.ts";
5
- import { type BranchOperator, type Comparator, type MinComparator, type OpenLeftBound, type StringifiablePrefixOperator } from "./shared.ts";
5
+ import { type BranchOperator, type Comparator, type MaxComparator, type OpenLeftBound, type StringifiablePrefixOperator } from "./shared.ts";
6
6
  type BranchState = {
7
7
  prefixes: StringifiablePrefixOperator[];
8
- leftBound: OpenLeftBound | null;
8
+ /** the bound before the operand, like `5 <` in `5 < n`, until its right side is parsed */
9
+ lBound: OpenLeftBound | null;
9
10
  intersection: BaseRoot | null;
10
11
  union: BaseRoot | null;
12
+ /** the units a union starts with, built together as their union only sorts and dedupes them */
13
+ units: BaseRoot[] | null;
11
14
  pipe: BaseRoot | null;
12
15
  };
13
16
  export type RootedRuntimeState = requireKeys<RuntimeState, "root">;
@@ -16,27 +19,33 @@ export declare class RuntimeState {
16
19
  branches: BranchState;
17
20
  finalizer: FinalizingLookahead | undefined;
18
21
  groups: BranchState[];
19
- scanner: Scanner;
22
+ rightBounded: {
23
+ root: BaseRoot;
24
+ operand: BaseRoot;
25
+ } | undefined;
26
+ /** what it's parsing, scanned up to its next token */
27
+ sc: Scanner;
20
28
  ctx: BaseParseContext;
21
- constructor(scanner: Scanner, ctx: BaseParseContext);
29
+ constructor(sc: Scanner, ctx: BaseParseContext);
22
30
  error(message: string): never;
23
31
  hasRoot(): this is RootedRuntimeState;
24
32
  setRoot(root: BaseRoot): void;
25
33
  unsetRoot(): this["root"];
26
- constrainRoot(...args: Parameters<BaseRoot<any>["constrain"]>): void;
34
+ constrainRoot(...args: Parameters<BaseRoot<any>["rawConstrain"]>): void;
27
35
  finalize(finalizer: FinalizingLookahead): void;
28
36
  reduceLeftBound(limit: LimitLiteral, comparator: Comparator): void;
29
37
  finalizeBranches(): void;
30
38
  finalizeGroup(): void;
31
39
  addPrefix(prefix: StringifiablePrefixOperator): void;
32
40
  applyPrefixes(): void;
33
- pushRootToBranch(token: BranchOperator): void;
41
+ private unionUnits;
42
+ pushRootBranch(token: BranchOperator): void;
34
43
  parseUntilFinalizer(): RootedRuntimeState;
35
44
  parseOperator(this: RootedRuntimeState): void;
36
45
  parseOperand(): void;
37
46
  private assertRangeUnset;
38
47
  reduceGroupOpen(): void;
39
- previousOperator(): MinComparator | StringifiablePrefixOperator | InfixToken | undefined;
48
+ previousOperator(): MaxComparator | StringifiablePrefixOperator | InfixToken | undefined;
40
49
  shiftedBy(count: number): this;
41
50
  }
42
51
  export {};
@@ -1,3 +1,4 @@
1
+ import { type BaseRoot } from "@ark/schema";
1
2
  import type { LimitLiteral } from "../../attributes.ts";
2
3
  export type StringifiablePrefixOperator = "keyof";
3
4
  export declare const minComparators: {
@@ -16,6 +17,7 @@ export declare const comparators: {
16
17
  "<": boolean;
17
18
  "<=": boolean;
18
19
  "==": boolean;
20
+ "!=": boolean;
19
21
  };
20
22
  export type Comparator = keyof typeof comparators;
21
23
  export declare const invertedComparators: InvertedComparators;
@@ -25,8 +27,10 @@ export type InvertedComparators = {
25
27
  "<=": ">=";
26
28
  ">=": "<=";
27
29
  "==": "==";
30
+ "!=": "!=";
28
31
  };
29
32
  export type BranchOperator = "&" | "|" | "|>";
33
+ export declare const checkWrittenIntersection: (result: BaseRoot, l: BaseRoot, r: BaseRoot) => void;
30
34
  export type OpenLeftBound = {
31
35
  limit: LimitLiteral;
32
36
  comparator: MinComparator;
@@ -12,7 +12,7 @@ export type StaticState = {
12
12
  };
13
13
  type BranchState = {
14
14
  prefixes: StringifiablePrefixOperator[];
15
- leftBound: OpenLeftBound | undefined;
15
+ lBound: OpenLeftBound | undefined;
16
16
  intersection: unknown;
17
17
  pipe: unknown;
18
18
  union: unknown;
@@ -45,7 +45,7 @@ export declare namespace s {
45
45
  }>;
46
46
  type initialBranches = branchesFrom<{
47
47
  prefixes: [];
48
- leftBound: undefined;
48
+ lBound: undefined;
49
49
  intersection: undefined;
50
50
  pipe: undefined;
51
51
  union: undefined;
@@ -63,7 +63,7 @@ export declare namespace s {
63
63
  root: s["root"];
64
64
  branches: {
65
65
  prefixes: [...s["branches"]["prefixes"], prefix];
66
- leftBound: s["branches"]["leftBound"];
66
+ lBound: s["branches"]["lBound"];
67
67
  intersection: s["branches"]["intersection"];
68
68
  pipe: s["branches"]["pipe"];
69
69
  union: s["branches"]["union"];
@@ -73,11 +73,11 @@ export declare namespace s {
73
73
  scanned: updateScanned<s["scanned"], s["unscanned"], unscanned>;
74
74
  unscanned: unscanned;
75
75
  }>;
76
- type reduceBranch<s extends StaticState, token extends BranchOperator, unscanned extends string> = s["branches"]["leftBound"] extends {} ? openRangeError<s["branches"]["leftBound"]> : from<{
76
+ type reduceBranch<s extends StaticState, token extends BranchOperator, unscanned extends string> = s["branches"]["lBound"] extends {} ? openRangeError<s["branches"]["lBound"]> : from<{
77
77
  root: undefined;
78
78
  branches: {
79
79
  prefixes: [];
80
- leftBound: undefined;
80
+ lBound: undefined;
81
81
  intersection: token extends "&" ? mergeToIntersection<s> : undefined;
82
82
  union: token extends "|" ? mergeToUnion<s> : token extends "|>" ? undefined : s["branches"]["union"];
83
83
  pipe: token extends "|>" ? mergeToPipe<s> : s["branches"]["pipe"];
@@ -87,11 +87,11 @@ export declare namespace s {
87
87
  scanned: updateScanned<s["scanned"], s["unscanned"], unscanned>;
88
88
  unscanned: unscanned;
89
89
  }>;
90
- type reduceLeftBound<s extends StaticState, limit extends LimitLiteral, comparator extends Comparator, unscanned extends string> = comparator extends "<" | "<=" ? s["branches"]["leftBound"] extends {} ? s.error<writeMultipleLeftBoundsMessage<s["branches"]["leftBound"]["limit"], s["branches"]["leftBound"]["comparator"], limit, InvertedComparators[comparator]>> : from<{
90
+ type reduceLeftBound<s extends StaticState, limit extends LimitLiteral, comparator extends Comparator, unscanned extends string> = comparator extends "<" | "<=" ? s["branches"]["lBound"] extends {} ? s.error<writeMultipleLeftBoundsMessage<s["branches"]["lBound"]["limit"], s["branches"]["lBound"]["comparator"], limit, InvertedComparators[comparator]>> : from<{
91
91
  root: undefined;
92
92
  branches: {
93
93
  prefixes: s["branches"]["prefixes"];
94
- leftBound: {
94
+ lBound: {
95
95
  limit: limit;
96
96
  comparator: InvertedComparators[comparator];
97
97
  };
@@ -108,7 +108,7 @@ export declare namespace s {
108
108
  root: [minLimit, minComparator, [s["root"], maxComparator, maxLimit]];
109
109
  branches: {
110
110
  prefixes: s["branches"]["prefixes"];
111
- leftBound: undefined;
111
+ lBound: undefined;
112
112
  intersection: s["branches"]["intersection"];
113
113
  pipe: s["branches"]["pipe"];
114
114
  union: s["branches"]["union"];
@@ -122,7 +122,7 @@ export declare namespace s {
122
122
  root: [s["root"], comparator, limit];
123
123
  branches: {
124
124
  prefixes: s["branches"]["prefixes"];
125
- leftBound: undefined;
125
+ lBound: undefined;
126
126
  intersection: s["branches"]["intersection"];
127
127
  pipe: s["branches"]["pipe"];
128
128
  union: s["branches"]["union"];
@@ -143,7 +143,7 @@ export declare namespace s {
143
143
  ...stack,
144
144
  top
145
145
  ];
146
- type finalizeGroup<s extends StaticState, unscanned extends string> = s["branches"]["leftBound"] extends {} ? openRangeError<s["branches"]["leftBound"]> : s["groups"] extends popGroup<infer stack, infer top> ? from<{
146
+ type finalizeGroup<s extends StaticState, unscanned extends string> = s["branches"]["lBound"] extends {} ? openRangeError<s["branches"]["lBound"]> : s["groups"] extends popGroup<infer stack, infer top> ? from<{
147
147
  groups: stack;
148
148
  branches: top;
149
149
  root: mergeToPipe<s>;
@@ -159,7 +159,7 @@ export declare namespace s {
159
159
  scanned: updateScanned<s["scanned"], s["unscanned"], unscanned>;
160
160
  unscanned: unscanned;
161
161
  }>;
162
- type finalize<s extends StaticState, finalizer extends FinalizingLookahead> = s["groups"] extends [] ? s["branches"]["leftBound"] extends {} ? openRangeError<s["branches"]["leftBound"]> : from<{
162
+ type finalize<s extends StaticState, finalizer extends FinalizingLookahead> = s["groups"] extends [] ? s["branches"]["lBound"] extends {} ? openRangeError<s["branches"]["lBound"]> : from<{
163
163
  root: mergeToPipe<s>;
164
164
  groups: s["groups"];
165
165
  branches: initialBranches;
@@ -167,8 +167,8 @@ export declare namespace s {
167
167
  scanned: s["scanned"];
168
168
  unscanned: s["unscanned"];
169
169
  }> : s.error<writeUnclosedGroupMessage<")">>;
170
- type openRangeError<range extends defined<BranchState["leftBound"]>> = s.error<writeOpenRangeMessage<range["limit"], range["comparator"]>>;
171
- type previousOperator<s extends StaticState> = s["branches"]["leftBound"] extends {} ? s["branches"]["leftBound"]["comparator"] : s["branches"]["prefixes"] extends ([
170
+ type openRangeError<range extends defined<BranchState["lBound"]>> = s.error<writeOpenRangeMessage<range["limit"], range["comparator"]>>;
171
+ type previousOperator<s extends StaticState> = s["branches"]["lBound"] extends {} ? InvertedComparators[s["branches"]["lBound"]["comparator"]] : s["branches"]["prefixes"] extends ([
172
172
  ...unknown[],
173
173
  infer tail extends string
174
174
  ]) ? tail : s["branches"]["intersection"] extends {} ? "&" : s["branches"]["union"] extends {} ? "|" : undefined;
@@ -1,11 +1,6 @@
1
1
  import type { DateLiteral } from "../../../attributes.ts";
2
2
  export declare const isDateLiteral: (value: unknown) => value is DateLiteral;
3
- export declare const isValidDate: (d: Date) => boolean;
4
3
  export declare const extractDateLiteralSource: <literal extends DateLiteral>(literal: literal) => extractDateLiteralSource<literal>;
5
4
  type extractDateLiteralSource<literal extends DateLiteral> = literal extends DateLiteral<infer source> ? source : never;
6
- export declare const writeInvalidDateMessage: <source extends string>(source: source) => writeInvalidDateMessage<source>;
7
- export type writeInvalidDateMessage<source extends string> = `'${source}' could not be parsed by the Date constructor`;
8
5
  export type DateInput = ConstructorParameters<typeof Date>[0];
9
- export type DateParseResult<errorOnFail extends boolean | string = boolean | string> = Date | (errorOnFail extends true | string ? never : undefined);
10
- export declare const tryParseDate: <errorOnFail extends boolean | string>(source: string, errorOnFail?: errorOnFail) => DateParseResult<errorOnFail>;
11
6
  export {};
@@ -1,8 +1,9 @@
1
1
  import { type Scanner, type WhitespaceChar } from "@ark/util";
2
+ import type { InferredAst } from "../../ast/infer.ts";
2
3
  import type { RuntimeState } from "../../reduce/dynamic.ts";
3
4
  import type { StaticState, s } from "../../reduce/static.ts";
4
5
  import type { BaseCompletions } from "../../string.ts";
5
6
  import { parseEnclosed, type EnclosingQuote, type EnclosingStartToken } from "./enclosed.ts";
6
7
  import { parseUnenclosed } from "./unenclosed.ts";
7
8
  export declare const parseOperand: (s: RuntimeState) => void;
8
- export type parseOperand<s extends StaticState, $, args> = s["unscanned"] extends Scanner.shift<infer lookahead, infer unscanned> ? lookahead extends "(" ? s.reduceGroupOpen<s, unscanned> : lookahead extends EnclosingStartToken ? parseEnclosed<s, lookahead, unscanned> : lookahead extends WhitespaceChar ? parseOperand<s.scanTo<s, unscanned>, $, args> : lookahead extends "d" ? unscanned extends (Scanner.shift<infer enclosing extends EnclosingQuote, infer nextUnscanned>) ? parseEnclosed<s, `d${enclosing}`, nextUnscanned> : parseUnenclosed<s, $, args> : lookahead extends "x" ? unscanned extends Scanner.shift<"/", infer nextUnscanned> ? parseEnclosed<s, "x/", nextUnscanned> : parseUnenclosed<s, $, args> : parseUnenclosed<s, $, args> : s.completion<`${s["scanned"]}${BaseCompletions<$, args>}`>;
9
+ export type parseOperand<s extends StaticState, $, args> = s["unscanned"] extends Scanner.shift<infer peek, infer unscanned> ? peek extends "(" ? s.reduceGroupOpen<s, unscanned> : peek extends EnclosingStartToken ? parseEnclosed<s, peek, unscanned> : peek extends WhitespaceChar ? parseOperand<s.scanTo<s, unscanned>, $, args> : peek extends "[" ? unscanned extends Scanner.shift<"]", infer nextUnscanned> ? s.setRoot<s, InferredAst<[], "[]">, nextUnscanned> : parseUnenclosed<s, $, args> : peek extends "d" ? unscanned extends (Scanner.shift<infer enclosing extends EnclosingQuote, infer nextUnscanned>) ? parseEnclosed<s, `d${enclosing}`, nextUnscanned> : parseUnenclosed<s, $, args> : peek extends "x" ? unscanned extends Scanner.shift<"/", infer nextUnscanned> ? parseEnclosed<s, "x/", nextUnscanned> : parseUnenclosed<s, $, args> : parseUnenclosed<s, $, args> : s.completion<`${s["scanned"]}${BaseCompletions<$, args>}`>;
@@ -1,5 +1,5 @@
1
1
  import { writeUnresolvableMessage, type BaseRoot, type GenericAst, type GenericRoot, type arkKind, type genericParamNames, type resolvableReferenceIn, type writeNonSubmoduleDotMessage } from "@ark/schema";
2
- import { type BigintLiteral, type NumberLiteral, type Scanner, type join, type lastOf } from "@ark/util";
2
+ import { type BigintLiteral, type NonFiniteNumberLiteral, type NumberLiteral, type Scanner, type join, type lastOf } from "@ark/util";
3
3
  import type { ArkAmbient } from "../../../config.ts";
4
4
  import type { resolutionToAst } from "../../../scope.ts";
5
5
  import type { GenericInstantiationAst } from "../../ast/generic.ts";
@@ -8,15 +8,17 @@ import { writePrefixedPrivateReferenceMessage } from "../../ast/validate.ts";
8
8
  import type { RuntimeState } from "../../reduce/dynamic.ts";
9
9
  import type { StaticState, s } from "../../reduce/static.ts";
10
10
  import type { BaseCompletions } from "../../string.ts";
11
- import { type TerminatingChar } from "../tokens.ts";
11
+ import { shiftUntilTerminator } from "../tokens.ts";
12
12
  import { parseGenericArgs, writeInvalidGenericArgCountMessage, type ParsedArgs } from "./genericArgs.ts";
13
+ import { writeUnresolvableHint } from "./unresolvable.ts";
13
14
  export declare const parseUnenclosed: (s: RuntimeState) => void;
14
- export type parseUnenclosed<s extends StaticState, $, args> = Scanner.shiftUntil<s["unscanned"], TerminatingChar> extends (Scanner.shiftResult<infer token, infer unscanned>) ? tryResolve<s, unscanned, token, $, args> extends s.from<infer s> ? s : never : never;
15
+ export declare const limitOf: (s: RuntimeState, token: string) => number | undefined;
16
+ export type parseUnenclosed<s extends StaticState, $, args> = shiftUntilTerminator<s["unscanned"]> extends (Scanner.shiftResult<infer token, infer unscanned>) ? tryResolve<s, unscanned, token, $, args> extends s.from<infer s> ? s : never : never;
15
17
  type parseResolution<s extends StaticState, unscanned extends string, alias extends string, resolution, $, args> = resolutionToAst<alias, resolution> extends infer ast ? ast extends GenericAst ? parseGenericInstantiation<alias, ast, s.scanTo<s, unscanned>, $, args> : s.setRoot<s, ast, unscanned> : never;
16
18
  export declare const parseGenericInstantiation: (name: string, g: GenericRoot, s: RuntimeState) => BaseRoot;
17
19
  export type parseGenericInstantiation<name extends string, g extends GenericAst, s extends StaticState, $, args> = Scanner.skipWhitespace<s["unscanned"]> extends `<${infer unscanned}` ? parseGenericArgs<name, g, unscanned, $, args> extends infer result ? result extends ParsedArgs<infer argAsts, infer nextUnscanned> ? s.setRoot<s, GenericInstantiationAst<g, argAsts>, nextUnscanned> : result : never : s.error<writeInvalidGenericArgCountMessage<name, genericParamNames<g["paramsAst"]>, [
18
20
  ]>>;
19
- type tryResolve<s extends StaticState, unscanned extends string, token extends string, $, args> = token extends keyof args ? parseResolution<s, unscanned, token, args[token], $, args> : token extends keyof $ ? parseResolution<s, unscanned, token, $[token], $, args> : token extends keyof ArkAmbient.$ ? parseResolution<s, unscanned, token, ArkAmbient.$[token], $, args> : `#${token}` extends keyof $ ? parseResolution<s, unscanned, token, $[`#${token}`], $, args> : token extends NumberLiteral<infer n> ? s.setRoot<s, InferredAst<n, token>, unscanned> : token extends (`${infer submodule extends keyof $ & string}.${infer reference}`) ? tryResolveSubmodule<token, $[submodule], reference, s, unscanned, $, args, [
21
+ type tryResolve<s extends StaticState, unscanned extends string, token extends string, $, args> = token extends keyof args ? parseResolution<s, unscanned, token, args[token], $, args> : token extends keyof $ ? parseResolution<s, unscanned, token, $[token], $, args> : token extends keyof ArkAmbient.$ ? parseResolution<s, unscanned, token, ArkAmbient.$[token], $, args> : `#${token}` extends keyof $ ? parseResolution<s, unscanned, token, $[`#${token}`], $, args> : token extends NumberLiteral<infer n> ? s.setRoot<s, InferredAst<n, token>, unscanned> : token extends NonFiniteNumberLiteral ? s.setRoot<s, InferredAst<number, token>, unscanned> : token extends (`${infer submodule extends keyof $ & string}.${infer reference}`) ? tryResolveSubmodule<token, $[submodule], reference, s, unscanned, $, args, [
20
22
  submodule
21
23
  ]> : token extends (`${infer submodule extends keyof ArkAmbient.$ & string}.${infer reference}`) ? tryResolveSubmodule<token, ArkAmbient.$[submodule], reference, s, unscanned, $, args, [
22
24
  submodule
@@ -29,10 +31,11 @@ type tryResolveSubmodule<token extends string, resolution, reference extends str
29
31
  ]> : unresolvableState<s, reference, resolution, {}, submodulePath> : s.error<writeNonSubmoduleDotMessage<lastOf<submodulePath>>>;
30
32
  /** Provide valid completions for the current token, or fallback to an
31
33
  * unresolvable error if there are none */
32
- export type unresolvableState<s extends StaticState, token extends string, resolutions, args, submodulePath extends string[]> = [
34
+ export type unresolvableState<s extends StaticState, token extends string, res, args, submodulePath extends string[]> = [
33
35
  token,
34
36
  s["unscanned"]
35
- ] extends ["", Scanner.shift<"#", infer unscanned>] ? Scanner.shiftUntil<unscanned, TerminatingChar> extends (Scanner.shiftResult<infer name, string>) ? s.error<writePrefixedPrivateReferenceMessage<name>> : never : validReferenceFromToken<token, resolutions, args, submodulePath> extends (never) ? s.error<writeUnresolvableMessage<qualifiedReference<token, submodulePath>>> : s.completion<`${s["scanned"]}${qualifiedReference<validReferenceFromToken<token, resolutions, args, submodulePath>, submodulePath>}`>;
37
+ ] extends ["", Scanner.shift<"#", infer unscanned>] ? shiftUntilTerminator<unscanned> extends (Scanner.shiftResult<infer name, string>) ? s.error<writePrefixedPrivateReferenceMessage<name>> : never : validReferenceFromToken<token, res, args, submodulePath> extends never ? s.error<writeUnresolvableWithHint<qualifiedReference<token, submodulePath>>> : s.completion<`${s["scanned"]}${qualifiedReference<validReferenceFromToken<token, res, args, submodulePath>, submodulePath>}`>;
38
+ type writeUnresolvableWithHint<name extends string> = `${writeUnresolvableMessage<name>}${writeUnresolvableHint<name>}`;
36
39
  type qualifiedReference<reference extends string, submodulePath extends string[]> = join<[...submodulePath, reference], ".">;
37
40
  type validReferenceFromToken<token extends string, $, args, submodulePath extends string[]> = Extract<submodulePath["length"] extends 0 ? BaseCompletions<$, args> : resolvableReferenceIn<$>, `${token}${string}`>;
38
41
  export declare const writeMissingOperandMessage: (s: RuntimeState) => string;
@@ -0,0 +1,68 @@
1
+ import { type BaseScope } from "@ark/schema";
2
+ import { type Dict } from "@ark/util";
3
+ /**
4
+ * What a name from Zod, TypeScript or JSON Schema is written as here. Every key
5
+ * is unresolvable in the default scope, and every value parses in it
6
+ */
7
+ export declare const foreignAliases: {
8
+ readonly any: "unknown.any";
9
+ readonly void: "undefined";
10
+ readonly String: "string";
11
+ readonly Number: "number";
12
+ readonly Boolean: "boolean";
13
+ readonly BigInt: "bigint";
14
+ readonly Symbol: "symbol";
15
+ readonly Object: "object";
16
+ readonly function: "Function";
17
+ readonly array: "unknown[]";
18
+ readonly str: "string";
19
+ readonly bool: "boolean";
20
+ readonly num: "number";
21
+ readonly int: "number.integer";
22
+ readonly integer: "number.integer";
23
+ readonly float: "number";
24
+ readonly double: "number";
25
+ readonly decimal: "number";
26
+ readonly "number.int": "number.integer";
27
+ readonly "number.float": "number";
28
+ readonly "number.positive": "number > 0";
29
+ readonly "number.negative": "number < 0";
30
+ readonly "number.nonnegative": "number >= 0";
31
+ readonly "string.nonempty": "string > 0";
32
+ readonly date: "Date";
33
+ readonly datetime: "string.date.iso";
34
+ readonly "string.datetime": "string.date.iso";
35
+ readonly timestamp: "number.epoch";
36
+ readonly email: "string.email";
37
+ readonly uuid: "string.uuid";
38
+ readonly guid: "string.uuid";
39
+ readonly "string.guid": "string.uuid";
40
+ readonly url: "string.url";
41
+ readonly uri: "string.url";
42
+ readonly "string.uri": "string.url";
43
+ readonly ip: "string.ip";
44
+ readonly ipv4: "string.ip.v4";
45
+ readonly ipv6: "string.ip.v6";
46
+ readonly "string.ipv4": "string.ip.v4";
47
+ readonly "string.ipv6": "string.ip.v6";
48
+ readonly json: "string.json";
49
+ readonly base64: "string.base64";
50
+ readonly hex: "string.hex";
51
+ readonly regex: "RegExp";
52
+ readonly regexp: "RegExp";
53
+ readonly nan: "number.NaN";
54
+ };
55
+ export type foreignAliases = typeof foreignAliases;
56
+ /**
57
+ * What follows `'name' is unresolvable` in a type error. A name from another
58
+ * library is all it suggests: a lookup costs nothing until a definition fails,
59
+ * and the nearest alias, which the thrown error also suggests, would cost a
60
+ * comparison with every alias in scope
61
+ */
62
+ export type writeUnresolvableHint<name extends string> = name extends keyof foreignAliases ? `. Did you mean '${foreignAliases[name]}'?` : "";
63
+ /**
64
+ * What follows `'name' is unresolvable` in the thrown error: the definition a
65
+ * name from another library means, else the aliases nearest to it, else the
66
+ * names of the submodule it was read from
67
+ */
68
+ export declare const writeUnresolvableHint: (name: string, $: BaseScope, args: Dict | undefined) => string;
@@ -2,22 +2,27 @@ import { type BaseRoot, type BoundKind } from "@ark/schema";
2
2
  import { type KeySet, type Scanner } from "@ark/util";
3
3
  import type { DateLiteral } from "../../../attributes.ts";
4
4
  import type { InferredAst } from "../../ast/infer.ts";
5
- import type { astToString } from "../../ast/utils.ts";
6
5
  import type { RootedRuntimeState, RuntimeState } from "../../reduce/dynamic.ts";
7
6
  import { writeUnpairableComparatorMessage, type Comparator, type InvertedComparators, type MaxComparator } from "../../reduce/shared.ts";
8
7
  import type { s, StaticState } from "../../reduce/static.ts";
9
8
  import type { parseOperand } from "../operand/operand.ts";
9
+ import { writeMissingRightOperandMessage } from "../operand/unenclosed.ts";
10
+ import { writeUnexpectedCharacterMessage } from "./operator.ts";
10
11
  export declare const parseBound: (s: RootedRuntimeState, start: ComparatorStartChar) => void;
11
12
  export type parseBound<s extends StaticState, start extends ComparatorStartChar, unscanned extends string, $, args> = shiftComparator<start, unscanned> extends infer shiftResultOrError ? shiftResultOrError extends (Scanner.shiftResult<infer comparator extends Comparator, infer nextUnscanned>) ? s["root"] extends (InferredAst<Date | number, `${infer limit extends number | DateLiteral}`>) ? s.reduceLeftBound<s, limit, comparator, nextUnscanned> : parseRightBound<s.scanTo<s, nextUnscanned>, comparator, $, args> : shiftResultOrError : never;
12
13
  type OneCharComparator = ">" | "<";
13
14
  export type ComparatorStartChar = Comparator extends `${infer char}${string}` ? char : never;
14
15
  export declare const comparatorStartChars: KeySet<ComparatorStartChar>;
15
- declare const shiftComparator: (s: RuntimeState, start: ComparatorStartChar) => Comparator;
16
- type shiftComparator<start extends ComparatorStartChar, unscanned extends string> = unscanned extends `=${infer nextUnscanned}` ? [`${start}=`, nextUnscanned] : [start & OneCharComparator, unscanned];
16
+ export declare const shiftComparator: (s: RuntimeState, start: ComparatorStartChar) => Comparator;
17
+ type shiftComparator<start extends ComparatorStartChar, unscanned extends string> = unscanned extends `=${infer nextUnscanned}` ? [`${start}=`, nextUnscanned] : start extends OneCharComparator ? [start, unscanned] : s.error<writeUnexpectedCharacterMessage<start>>;
17
18
  export declare const writeIncompatibleRangeMessage: (l: BoundKind, r: BoundKind) => string;
18
19
  export declare const getBoundKinds: (comparator: Comparator, limit: number | DateLiteral, root: BaseRoot, boundKind: BoundExpressionKind) => BoundKind[];
19
20
  export declare const parseRightBound: (s: RootedRuntimeState, comparator: Comparator) => void;
20
- export type parseRightBound<s extends StaticState, comparator extends Comparator, $, args> = parseOperand<s, $, args> extends infer nextState extends StaticState ? nextState["root"] extends (InferredAst<unknown, `${infer limit extends number | DateLiteral}`>) ? s["branches"]["leftBound"] extends {} ? comparator extends MaxComparator ? s.reduceRange<s, s["branches"]["leftBound"]["limit"], s["branches"]["leftBound"]["comparator"], comparator, limit, nextState["unscanned"]> : s.error<writeUnpairableComparatorMessage<comparator>> : s.reduceSingleBound<s, comparator, limit, nextState["unscanned"]> : s.error<writeInvalidLimitMessage<comparator, astToString<nextState["root"]>, "right">> : never;
21
+ export type parseRightBound<s extends StaticState, comparator extends Comparator, $, args> = Scanner.skipWhitespace<s["unscanned"]> extends "" ? s.error<writeMissingRightOperandMessage<comparator>> : parseOperand<s, $, args> extends infer nextState extends StaticState ? nextState["root"] extends (InferredAst<unknown, `${infer limit extends number | DateLiteral}`>) ? s["branches"]["lBound"] extends {} ? comparator extends MaxComparator ? s.reduceRange<s, s["branches"]["lBound"]["limit"], s["branches"]["lBound"]["comparator"], comparator, limit, nextState["unscanned"]> : s.error<writeUnpairableComparatorMessage<comparator>> : s.reduceSingleBound<s, comparator, limit, nextState["unscanned"]> : s.error<`${writeInvalidLimitMessage<comparator, scannedToken<s["unscanned"], nextState["unscanned"]>, "right">}${[comparator, s["root"]] extends ["<", InferredAst<unknown, "Array">] ? arrayIsNotGenericHint : ""}`> : never;
22
+ type scannedToken<unscanned extends string, nextUnscanned extends string> = Scanner.skipWhitespace<unscanned> extends `${infer token}${nextUnscanned}` ? token : never;
23
+ /** what follows a limit's message where it reads as TypeScript's `Array<T>` */
24
+ export declare const arrayIsNotGenericHint = ". Array isn't generic here: write an array of strings as string[]";
25
+ export type arrayIsNotGenericHint = typeof arrayIsNotGenericHint;
21
26
  export declare const writeInvalidLimitMessage: <comparator extends Comparator, limit extends string | number, boundKind extends BoundExpressionKind>(comparator: comparator, limit: limit, boundKind: boundKind) => writeInvalidLimitMessage<comparator, limit, boundKind>;
22
27
  export type writeInvalidLimitMessage<comparator extends Comparator, limit extends string | number, boundKind extends BoundExpressionKind> = `Comparator ${boundKind extends "left" ? InvertedComparators[comparator] : comparator} must be ${boundKind extends "left" ? "preceded" : "followed"} by a corresponding literal (was ${limit})`;
23
28
  export type BoundExpressionKind = "left" | "right";
@@ -2,6 +2,6 @@ import type { emptyBrandNameMessage } from "@ark/schema";
2
2
  import type { Scanner } from "@ark/util";
3
3
  import type { RootedRuntimeState } from "../../reduce/dynamic.ts";
4
4
  import type { StaticState, s } from "../../reduce/static.ts";
5
- import { type TerminatingChar } from "../tokens.ts";
5
+ import { shiftUntilTerminator } from "../tokens.ts";
6
6
  export declare const parseBrand: (s: RootedRuntimeState) => void;
7
- export type parseBrand<s extends StaticState, unscanned extends string> = Scanner.shiftUntil<Scanner.skipWhitespace<unscanned>, TerminatingChar> extends Scanner.shiftResult<`${infer brandName}`, infer nextUnscanned> ? brandName extends "" ? s.error<emptyBrandNameMessage> : s.setRoot<s, [s["root"], "#", brandName], nextUnscanned> : never;
7
+ export type parseBrand<s extends StaticState, unscanned extends string> = shiftUntilTerminator<Scanner.skipWhitespace<unscanned>> extends (Scanner.shiftResult<`${infer brandName}`, infer nextUnscanned>) ? brandName extends "" ? s.error<emptyBrandNameMessage> : s.setRoot<s, [s["root"], "#", brandName], nextUnscanned> : never;