arktype 2.0.0-rc.3 → 2.0.0-rc.30

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 (176) hide show
  1. package/out/attributes.d.ts +94 -0
  2. package/out/attributes.js +3 -0
  3. package/out/config.d.ts +1 -1
  4. package/out/generic.d.ts +55 -58
  5. package/out/generic.js +6 -8
  6. package/out/index.d.ts +6 -4
  7. package/out/index.js +4 -3
  8. package/out/keywords/{constructors/Array.d.ts → Array.d.ts} +3 -3
  9. package/out/keywords/{constructors/Array.js → Array.js} +7 -7
  10. package/out/keywords/{constructors/FormData.d.ts → FormData.d.ts} +3 -3
  11. package/out/keywords/{constructors/FormData.js → FormData.js} +8 -8
  12. package/out/keywords/{constructors/TypedArray.d.ts → TypedArray.d.ts} +1 -1
  13. package/out/keywords/{constructors/TypedArray.js → TypedArray.js} +2 -2
  14. package/out/keywords/builtins.js +2 -2
  15. package/out/keywords/{constructors/constructors.d.ts → constructors.d.ts} +1 -2
  16. package/out/keywords/{constructors/constructors.js → constructors.js} +2 -2
  17. package/out/keywords/keywords.d.ts +61 -0
  18. package/out/keywords/keywords.js +29 -0
  19. package/out/keywords/number.d.ts +23 -0
  20. package/out/keywords/{number/epoch.js → number.js} +24 -2
  21. package/out/keywords/string.d.ts +327 -0
  22. package/out/keywords/string.js +398 -0
  23. package/out/keywords/ts.d.ts +42 -4
  24. package/out/keywords/ts.js +24 -7
  25. package/out/methods/array.d.ts +12 -0
  26. package/out/methods/base.d.ts +178 -0
  27. package/out/methods/date.d.ts +10 -0
  28. package/out/methods/instantiate.d.ts +17 -0
  29. package/out/methods/morph.d.ts +12 -0
  30. package/out/methods/number.d.ts +11 -0
  31. package/out/methods/object.d.ts +106 -0
  32. package/out/methods/string.d.ts +12 -0
  33. package/out/module.d.ts +2 -2
  34. package/out/parser/{semantic → ast}/bounds.d.ts +3 -3
  35. package/out/parser/ast/default.d.ts +8 -0
  36. package/out/parser/ast/generic.d.ts +17 -0
  37. package/out/parser/ast/infer.d.ts +25 -0
  38. package/out/parser/{semantic → ast}/utils.d.ts +1 -1
  39. package/out/parser/ast/validate.d.ts +30 -0
  40. package/out/parser/ast/validate.js +3 -0
  41. package/out/parser/definition.d.ts +21 -13
  42. package/out/parser/definition.js +20 -2
  43. package/out/parser/objectLiteral.d.ts +41 -67
  44. package/out/parser/objectLiteral.js +79 -71
  45. package/out/parser/property.d.ts +36 -0
  46. package/out/parser/property.js +16 -0
  47. package/out/parser/{string/reduce → reduce}/dynamic.d.ts +10 -13
  48. package/out/parser/{string/reduce → reduce}/dynamic.js +5 -6
  49. package/out/parser/{string/reduce → reduce}/shared.d.ts +1 -1
  50. package/out/parser/{string/reduce → reduce}/static.d.ts +4 -4
  51. package/out/parser/{string/shift → shift}/operand/date.d.ts +3 -1
  52. package/out/parser/{string/shift → shift}/operand/enclosed.d.ts +4 -4
  53. package/out/parser/{string/shift → shift}/operand/enclosed.js +7 -3
  54. package/out/parser/shift/operand/operand.d.ts +9 -0
  55. package/out/parser/{string/shift → shift}/operand/operand.js +2 -2
  56. package/out/parser/{string/shift → shift}/operand/unenclosed.d.ts +15 -7
  57. package/out/parser/{string/shift → shift}/operand/unenclosed.js +12 -7
  58. package/out/parser/{string/shift → shift}/operator/bounds.d.ts +7 -7
  59. package/out/parser/{string/shift → shift}/operator/bounds.js +5 -4
  60. package/out/parser/shift/operator/brand.d.ts +6 -0
  61. package/out/parser/shift/operator/brand.js +5 -0
  62. package/out/parser/{string/shift → shift}/operator/default.d.ts +4 -6
  63. package/out/parser/{string/shift → shift}/operator/default.js +4 -6
  64. package/out/parser/{string/shift → shift}/operator/divisor.d.ts +2 -2
  65. package/out/parser/shift/operator/operator.d.ts +14 -0
  66. package/out/parser/{string/shift → shift}/operator/operator.js +7 -5
  67. package/out/parser/shift/scanner.d.ts +47 -0
  68. package/out/parser/shift/scanner.js +43 -0
  69. package/out/parser/{string/string.d.ts → string.d.ts} +9 -9
  70. package/out/parser/{string/string.js → string.js} +19 -0
  71. package/out/parser/tupleExpressions.d.ts +47 -0
  72. package/out/parser/tupleExpressions.js +67 -0
  73. package/out/parser/tupleLiteral.d.ts +95 -0
  74. package/out/parser/tupleLiteral.js +122 -0
  75. package/out/scope.d.ts +41 -34
  76. package/out/scope.js +54 -62
  77. package/out/type.d.ts +46 -22
  78. package/out/type.js +15 -11
  79. package/package.json +3 -3
  80. package/out/intersect.d.ts +0 -28
  81. package/out/keys.d.ts +0 -16
  82. package/out/keywords/ark.d.ts +0 -39
  83. package/out/keywords/ark.js +0 -24
  84. package/out/keywords/ast.d.ts +0 -193
  85. package/out/keywords/ast.js +0 -2
  86. package/out/keywords/number/epoch.d.ts +0 -10
  87. package/out/keywords/number/integer.d.ts +0 -3
  88. package/out/keywords/number/integer.js +0 -5
  89. package/out/keywords/number/number.d.ts +0 -28
  90. package/out/keywords/number/number.js +0 -9
  91. package/out/keywords/string/alpha.d.ts +0 -7
  92. package/out/keywords/string/alpha.js +0 -2
  93. package/out/keywords/string/alphanumeric.d.ts +0 -7
  94. package/out/keywords/string/alphanumeric.js +0 -2
  95. package/out/keywords/string/capitalize.d.ts +0 -15
  96. package/out/keywords/string/capitalize.js +0 -12
  97. package/out/keywords/string/creditCard.d.ts +0 -8
  98. package/out/keywords/string/creditCard.js +0 -37
  99. package/out/keywords/string/date.d.ts +0 -59
  100. package/out/keywords/string/date.js +0 -98
  101. package/out/keywords/string/digits.d.ts +0 -7
  102. package/out/keywords/string/digits.js +0 -2
  103. package/out/keywords/string/email.d.ts +0 -7
  104. package/out/keywords/string/email.js +0 -4
  105. package/out/keywords/string/integer.d.ts +0 -16
  106. package/out/keywords/string/integer.js +0 -16
  107. package/out/keywords/string/ip.d.ts +0 -20
  108. package/out/keywords/string/ip.js +0 -23
  109. package/out/keywords/string/json.d.ts +0 -15
  110. package/out/keywords/string/json.js +0 -45
  111. package/out/keywords/string/lower.d.ts +0 -15
  112. package/out/keywords/string/lower.js +0 -12
  113. package/out/keywords/string/normalize.d.ts +0 -92
  114. package/out/keywords/string/normalize.js +0 -43
  115. package/out/keywords/string/numeric.d.ts +0 -15
  116. package/out/keywords/string/numeric.js +0 -13
  117. package/out/keywords/string/semver.d.ts +0 -7
  118. package/out/keywords/string/semver.js +0 -4
  119. package/out/keywords/string/string.d.ts +0 -112
  120. package/out/keywords/string/string.js +0 -41
  121. package/out/keywords/string/trim.d.ts +0 -15
  122. package/out/keywords/string/trim.js +0 -14
  123. package/out/keywords/string/upper.d.ts +0 -15
  124. package/out/keywords/string/upper.js +0 -12
  125. package/out/keywords/string/url.d.ts +0 -15
  126. package/out/keywords/string/url.js +0 -37
  127. package/out/keywords/string/utils.d.ts +0 -2
  128. package/out/keywords/string/utils.js +0 -10
  129. package/out/keywords/string/uuid.d.ts +0 -42
  130. package/out/keywords/string/uuid.js +0 -19
  131. package/out/keywords/utils.d.ts +0 -1
  132. package/out/keywords/utils.js +0 -2
  133. package/out/parser/semantic/default.d.ts +0 -9
  134. package/out/parser/semantic/default.js +0 -1
  135. package/out/parser/semantic/infer.d.ts +0 -39
  136. package/out/parser/semantic/validate.d.ts +0 -26
  137. package/out/parser/semantic/validate.js +0 -1
  138. package/out/parser/string/shift/operand/operand.d.ts +0 -9
  139. package/out/parser/string/shift/operator/operator.d.ts +0 -13
  140. package/out/parser/string/shift/scanner.d.ts +0 -69
  141. package/out/parser/string/shift/scanner.js +0 -100
  142. package/out/parser/tuple.d.ts +0 -132
  143. package/out/parser/tuple.js +0 -158
  144. package/out/subtypes/array.d.ts +0 -13
  145. package/out/subtypes/base.d.ts +0 -85
  146. package/out/subtypes/date.d.ts +0 -11
  147. package/out/subtypes/instantiate.d.ts +0 -16
  148. package/out/subtypes/morph.d.ts +0 -13
  149. package/out/subtypes/number.d.ts +0 -12
  150. package/out/subtypes/object.d.ts +0 -33
  151. package/out/subtypes/string.d.ts +0 -13
  152. package/out/subtypes/validator.d.ts +0 -11
  153. package/out/subtypes/validator.js +0 -1
  154. /package/out/{subtypes → methods}/array.js +0 -0
  155. /package/out/{subtypes → methods}/base.js +0 -0
  156. /package/out/{subtypes → methods}/date.js +0 -0
  157. /package/out/{subtypes → methods}/instantiate.js +0 -0
  158. /package/out/{subtypes → methods}/morph.js +0 -0
  159. /package/out/{subtypes → methods}/number.js +0 -0
  160. /package/out/{subtypes → methods}/object.js +0 -0
  161. /package/out/{subtypes → methods}/string.js +0 -0
  162. /package/out/parser/{semantic → ast}/bounds.js +0 -0
  163. /package/out/{intersect.js → parser/ast/default.js} +0 -0
  164. /package/out/parser/{semantic → ast}/divisor.d.ts +0 -0
  165. /package/out/parser/{semantic → ast}/divisor.js +0 -0
  166. /package/out/{keys.js → parser/ast/generic.js} +0 -0
  167. /package/out/parser/{semantic → ast}/infer.js +0 -0
  168. /package/out/parser/{semantic → ast}/keyof.d.ts +0 -0
  169. /package/out/parser/{semantic → ast}/keyof.js +0 -0
  170. /package/out/parser/{semantic → ast}/utils.js +0 -0
  171. /package/out/parser/{string/reduce → reduce}/shared.js +0 -0
  172. /package/out/parser/{string/reduce → reduce}/static.js +0 -0
  173. /package/out/parser/{string/shift → shift}/operand/date.js +0 -0
  174. /package/out/parser/{string/shift → shift}/operand/genericArgs.d.ts +0 -0
  175. /package/out/parser/{string/shift → shift}/operand/genericArgs.js +0 -0
  176. /package/out/parser/{string/shift → shift}/operator/divisor.js +0 -0
@@ -0,0 +1,122 @@
1
+ import { $ark, makeRootAndArrayPropertiesMutable, postfixAfterOptionalOrDefaultableMessage } from "@ark/schema";
2
+ import { append, isArray, isEmptyObject, throwParseError } from "@ark/util";
3
+ import { parseProperty } from "./property.js";
4
+ export const parseTupleLiteral = (def, ctx) => {
5
+ let sequences = [{}];
6
+ let i = 0;
7
+ while (i < def.length) {
8
+ let spread = false;
9
+ if (def[i] === "..." && i < def.length - 1) {
10
+ spread = true;
11
+ i++;
12
+ }
13
+ const parsedProperty = parseProperty(def[i], ctx);
14
+ const [valueNode, operator, possibleDefaultValue] = !isArray(parsedProperty) ? [parsedProperty] : parsedProperty;
15
+ i++;
16
+ if (spread) {
17
+ if (!valueNode.extends($ark.intrinsic.Array))
18
+ return throwParseError(writeNonArraySpreadMessage(valueNode.expression));
19
+ // a spread must be distributed over branches e.g.:
20
+ // def: [string, ...(number[] | [true, false])]
21
+ // nodes: [string, ...number[]] | [string, true, false]
22
+ sequences = sequences.flatMap(base =>
23
+ // since appendElement mutates base, we have to shallow-ish clone it for each branch
24
+ valueNode.distribute(branch => appendSpreadBranch(makeRootAndArrayPropertiesMutable(base), branch)));
25
+ }
26
+ else {
27
+ sequences = sequences.map(base => {
28
+ if (operator === "?")
29
+ return appendOptionalElement(base, valueNode);
30
+ if (operator === "=")
31
+ return appendDefaultableElement(base, valueNode, possibleDefaultValue);
32
+ return appendRequiredElement(base, valueNode);
33
+ });
34
+ }
35
+ }
36
+ return ctx.$.parseSchema(sequences.map(sequence => isEmptyObject(sequence) ?
37
+ {
38
+ proto: Array,
39
+ exactLength: 0
40
+ }
41
+ : {
42
+ proto: Array,
43
+ sequence
44
+ }));
45
+ };
46
+ const appendRequiredElement = (base, element) => {
47
+ if (base.defaultables || base.optionals) {
48
+ return throwParseError(base.variadic ?
49
+ // e.g. [boolean = true, ...string[], number]
50
+ postfixAfterOptionalOrDefaultableMessage
51
+ // e.g. [string?, number]
52
+ : requiredPostOptionalMessage);
53
+ }
54
+ if (base.variadic) {
55
+ // e.g. [...string[], number]
56
+ base.postfix = append(base.postfix, element);
57
+ }
58
+ else {
59
+ // e.g. [string, number]
60
+ base.prefix = append(base.prefix, element);
61
+ }
62
+ return base;
63
+ };
64
+ const appendOptionalElement = (base, element) => {
65
+ if (base.variadic)
66
+ // e.g. [...string[], number?]
67
+ return throwParseError(optionalOrDefaultableAfterVariadicMessage);
68
+ // e.g. [string, number?]
69
+ base.optionals = append(base.optionals, element);
70
+ return base;
71
+ };
72
+ const appendDefaultableElement = (base, element, value) => {
73
+ if (base.variadic)
74
+ // e.g. [...string[], number = 0]
75
+ return throwParseError(optionalOrDefaultableAfterVariadicMessage);
76
+ if (base.optionals)
77
+ // e.g. [string?, number = 0]
78
+ return throwParseError(defaultablePostOptionalMessage);
79
+ // value's assignability to element will be checked when the
80
+ // sequence is instantiated by @ark/schema
81
+ // e.g. [string, number = 0]
82
+ base.defaultables = append(base.defaultables, [[element, value]]);
83
+ return base;
84
+ };
85
+ const appendVariadicElement = (base, element) => {
86
+ // e.g. [...string[], number, ...string[]]
87
+ if (base.postfix)
88
+ throwParseError(multipleVariadicMesage);
89
+ if (base.variadic) {
90
+ if (!base.variadic.equals(element)) {
91
+ // e.g. [...string[], ...number[]]
92
+ throwParseError(multipleVariadicMesage);
93
+ }
94
+ // e.g. [...string[], ...string[]]
95
+ // do nothing, second spread doesn't change the type
96
+ }
97
+ else {
98
+ // e.g. [string, ...number[]]
99
+ base.variadic = element.internal;
100
+ }
101
+ return base;
102
+ };
103
+ const appendSpreadBranch = (base, branch) => {
104
+ const spread = branch.firstReferenceOfKind("sequence");
105
+ if (!spread) {
106
+ // the only array with no sequence reference is unknown[]
107
+ return appendVariadicElement(base, $ark.intrinsic.unknown);
108
+ }
109
+ spread.prefix?.forEach(node => appendRequiredElement(base, node));
110
+ spread.optionals?.forEach(node => appendOptionalElement(base, node));
111
+ if (spread.variadic)
112
+ appendVariadicElement(base, spread.variadic);
113
+ spread.postfix?.forEach(node => appendRequiredElement(base, node));
114
+ return base;
115
+ };
116
+ export const writeNonArraySpreadMessage = (operand) => `Spread element must be an array (was ${operand})`;
117
+ export const multipleVariadicMesage = "A tuple may have at most one variadic element";
118
+ export const requiredPostOptionalMessage = "A required element may not follow an optional element";
119
+ export const optionalOrDefaultableAfterVariadicMessage = "An optional element may not follow a variadic element";
120
+ export const spreadOptionalMessage = "A spread element cannot be optional";
121
+ export const spreadDefaultableMessage = "A spread element cannot have a default";
122
+ export const defaultablePostOptionalMessage = "A defaultable element may not follow an optional element without a default";
package/out/scope.d.ts CHANGED
@@ -1,24 +1,28 @@
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 noSuggest, type nominal } from "@ark/util";
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 Brand, type ErrorType, type JsonStructure, type anyOrNever, type array, type flattenListable, type noSuggest } from "@ark/util";
3
3
  import type { ArkSchemaRegistry } from "./config.ts";
4
- import { parseGenericParams, type GenericDeclaration, type GenericParser, type ParameterString, type baseGenericConstraints, type parseValidGenericParams } from "./generic.ts";
5
- import type { Ark } from "./keywords/ark.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 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<{
7
+ import type { DefAst, InferredAst } from "./parser/ast/infer.ts";
8
+ import { type inferDefinition } from "./parser/definition.ts";
9
+ import type { ParsedOptionalProperty } from "./parser/property.ts";
10
+ import type { ParsedDefaultableProperty } from "./parser/shift/operator/default.ts";
11
+ import { InternalTypeParser, type DeclarationParser, type DefinitionParser, type EnumeratedTypeParser, type InstanceOfTypeParser, type SchemaParser, type TypeParser, type UnitTypeParser } from "./type.ts";
12
+ /** The convenience properties attached to `scope` */
13
+ export type ScopeParserAttachments = Omit<ScopeParser, never>;
14
+ export interface ScopeParser {
15
+ <const def>(def: scope.validate<def>, config?: ArkScopeConfig): Scope<scope.infer<def>>;
16
+ define: <const def>(def: scope.validate<def>) => def;
17
+ }
18
+ export type ModuleParser = <const def>(def: scope.validate<def>, config?: ArkScopeConfig) => scope.infer<def> extends infer $ ? Module<{
13
19
  [k in exportedNameOf<$>]: $[k];
14
20
  }> : 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;
21
+ export type bindThis<def> = {
22
+ this: Def<def>;
17
23
  };
18
- export type inferScope<def> = inferBootstrapped<bootstrapAliases<def>>;
19
- export type bindThis<def> = {};
20
24
  /** nominal type for an unparsed definition used during scope bootstrapping */
21
- type Def<def = {}> = nominal<def, "unparsed">;
25
+ type Def<def = {}> = Brand<def, "unparsed">;
22
26
  /** sentinel indicating a scope that will be associated with a generic has not yet been parsed */
23
27
  export type UnparsedScope = "$";
24
28
  /** These are legal as values of a scope but not as definitions in other contexts */
@@ -44,7 +48,7 @@ export type resolutionToAst<alias extends string, resolution> = [
44
48
  resolution
45
49
  ] extends [anyOrNever] ? InferredAst<resolution, alias> : resolution extends Def<infer def> ? DefAst<def, alias> : resolution extends {
46
50
  [arkKind]: "module";
47
- $root: infer root;
51
+ root: infer root;
48
52
  } ? InferredAst<root, alias> : resolution extends GenericAst ? resolution : InferredAst<resolution, alias>;
49
53
  export type moduleKeyOf<$> = {
50
54
  [k in keyof $]: $[k] extends {
@@ -57,52 +61,55 @@ export interface ArkTypeRegistry extends ArkSchemaRegistry {
57
61
  typeAttachments?: Ark.boundTypeAttachments<any>;
58
62
  }
59
63
  export declare const $arkTypeRegistry: ArkTypeRegistry;
60
- export interface ParseContext extends TypeParseOptions {
61
- $: InternalScope;
62
- }
63
- export interface TypeParseOptions {
64
- args?: GenericArgResolutions;
65
- }
66
64
  export interface InternalScope {
67
65
  constructor: typeof InternalScope;
68
66
  }
69
67
  export declare class InternalScope<$ extends {} = {}> extends BaseScope<$> {
70
- private parseCache;
71
- preparseAlias(k: string, v: unknown): AliasDefEntry;
72
68
  protected cacheGetter<name extends keyof this>(name: name, value: this[name]): this[name];
73
- preparseRoot(def: unknown): unknown;
74
69
  get ambientAttachments(): Ark.boundTypeAttachments<$> | undefined;
75
- parse<defaultable extends boolean = false>(def: unknown, ctx: ParseContext, defaultable?: defaultable): BaseRoot | (defaultable extends false ? never : ParsedDefault);
76
- parseString<defaultable extends boolean>(def: string, ctx: ParseContext, defaultable: defaultable): BaseRoot | (defaultable extends false ? never : ParsedDefault);
77
- parseRoot: (def: unknown, opts?: TypeParseOptions) => BaseRoot;
70
+ protected preparseOwnAliasEntry(k: string, v: unknown): AliasDefEntry;
71
+ parseGenericParams(def: string, opts: BaseParseOptions): array<GenericParamDef>;
72
+ protected normalizeRootScopeValue(resolution: unknown): unknown;
73
+ protected preparseOwnDefinitionFormat(def: unknown, opts: BaseParseOptions): BaseRoot | BaseParseContextInput;
74
+ parseOwnDefinitionFormat(def: unknown, ctx: BaseParseContext): BaseRoot;
75
+ unit: UnitTypeParser<$>;
76
+ enumerated: EnumeratedTypeParser<$>;
77
+ instanceOf: InstanceOfTypeParser<$>;
78
78
  type: InternalTypeParser;
79
79
  declare: () => {
80
80
  type: InternalTypeParser;
81
81
  };
82
- define: (def: unknown) => unknown;
82
+ define<def>(def: def): def;
83
83
  static scope: ScopeParser;
84
84
  static module: ModuleParser;
85
85
  }
86
86
  export declare const scope: ScopeParser;
87
- export declare const module: ModuleParser;
87
+ export declare namespace scope {
88
+ type validate<def> = {
89
+ [k in keyof def]: k extends noSuggest ? unknown : parseScopeKey<k, def>["params"] extends infer params ? params extends array<GenericParamAst> ? params["length"] extends 0 ? def[k] extends type.Any | PreparsedResolution ? def[k] : k extends (PrivateDeclaration<infer name extends keyof def & string>) ? ErrorType<writeDuplicateAliasError<name>> : type.validate<def[k], bootstrapAliases<def>, {}> : type.validate<def[k], bootstrapAliases<def>, baseGenericConstraints<params>> : params : never;
90
+ };
91
+ type infer<def> = inferBootstrapped<bootstrapAliases<def>>;
92
+ }
88
93
  export interface Scope<$ = {}> {
89
94
  t: $;
90
95
  [arkKind]: "scope";
91
96
  config: ArkScopeConfig;
92
97
  references: readonly BaseNode[];
93
- json: Json;
98
+ json: JsonStructure;
94
99
  exportedNames: array<exportedNameOf<$>>;
95
100
  /** The set of names defined at the root-level of the scope mapped to their
96
101
  * corresponding definitions.**/
97
102
  aliases: Record<string, unknown>;
98
103
  internal: toInternalScope<$>;
99
104
  defineSchema<const def extends RootSchema>(schema: def): def;
100
- schema(schema: RootSchema, opts?: NodeParseOptions): BaseRoot;
101
- node<kinds extends NodeKind | array<RootKind>>(kinds: kinds, schema: NodeSchema<flattenListable<kinds>>, opts?: NodeParseOptions): nodeOfKind<reducibleKindOf<flattenListable<kinds>>>;
105
+ node<kinds extends NodeKind | array<RootKind>>(kinds: kinds, schema: NodeSchema<flattenListable<kinds>>, opts?: BaseParseOptions): nodeOfKind<reducibleKindOf<flattenListable<kinds>>>;
106
+ unit: UnitTypeParser<$>;
107
+ enumerated: EnumeratedTypeParser<$>;
102
108
  type: TypeParser<$>;
103
109
  declare: DeclarationParser<$>;
104
110
  define: DefinitionParser<$>;
105
111
  generic: GenericParser<$>;
112
+ schema: SchemaParser<$>;
106
113
  import(): Module<{
107
114
  [k in exportedNameOf<$> as PrivateDeclaration<k>]: $[k];
108
115
  }>;
@@ -123,7 +130,6 @@ export interface ScopeConstructor {
123
130
  module: ModuleParser;
124
131
  }
125
132
  export declare const Scope: ScopeConstructor;
126
- export declare const writeShallowCycleErrorMessage: (name: string, seen: string[]) => string;
127
133
  export type parseScopeKey<k, def> = k extends `${infer name}<${infer params}>` ? parseGenericScopeKey<name, params, def> : {
128
134
  name: k;
129
135
  params: [];
@@ -132,4 +138,5 @@ type parseGenericScopeKey<name extends string, params extends string, def> = {
132
138
  name: name;
133
139
  params: parseGenericParams<params, bootstrapAliases<def>>;
134
140
  };
141
+ export type InnerParseResult = BaseRoot | ParsedOptionalProperty | ParsedDefaultableProperty;
135
142
  export {};
package/out/scope.js CHANGED
@@ -1,16 +1,25 @@
1
1
  import { $ark, BaseScope, hasArkKind, parseGeneric } from "@ark/schema";
2
- import { domainOf, flatMorph, hasDomain, isThunk, throwParseError } from "@ark/util";
3
- import { parseGenericParams } from "./generic.js";
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";
2
+ import { flatMorph, isArray, isThunk, throwParseError } from "@ark/util";
3
+ import { parseGenericParamName } from "./generic.js";
4
+ import { shallowDefaultableMessage, shallowOptionalMessage } from "./parser/ast/validate.js";
5
+ import { parseInnerDefinition } from "./parser/definition.js";
6
+ import { ArkTypeScanner } from "./parser/shift/scanner.js";
9
7
  import { InternalTypeParser } from "./type.js";
10
8
  export const $arkTypeRegistry = $ark;
11
9
  export class InternalScope extends BaseScope {
12
- parseCache = {};
13
- preparseAlias(k, v) {
10
+ cacheGetter(name, value) {
11
+ Object.defineProperty(this, name, { value });
12
+ return value;
13
+ }
14
+ get ambientAttachments() {
15
+ if (!$arkTypeRegistry.typeAttachments)
16
+ return;
17
+ return this.cacheGetter("ambientAttachments", flatMorph($arkTypeRegistry.typeAttachments, (k, v) => [
18
+ k,
19
+ this.bindReference(v)
20
+ ]));
21
+ }
22
+ preparseOwnAliasEntry(k, v) {
14
23
  const firstParamIndex = k.indexOf("<");
15
24
  if (firstParamIndex === -1)
16
25
  return [k, v];
@@ -24,74 +33,57 @@ export class InternalScope extends BaseScope {
24
33
  // use a thunk definition for the generic so that we can parse
25
34
  // constraints within the current scope
26
35
  () => {
27
- const params = parseGenericParams(paramString, {
28
- $: this,
29
- args: {}
30
- });
36
+ const params = this.parseGenericParams(paramString, { alias: name });
31
37
  const generic = parseGeneric(params, v, this);
32
38
  return generic;
33
39
  }
34
40
  ];
35
41
  }
36
- cacheGetter(name, value) {
37
- Object.defineProperty(this, name, { value });
38
- return value;
42
+ parseGenericParams(def, opts) {
43
+ return parseGenericParamName(new ArkTypeScanner(def), [], this.createParseContext({ ...opts, def, prefix: "generic" }));
39
44
  }
40
- preparseRoot(def) {
41
- if (isThunk(def) && !hasArkKind(def, "generic"))
42
- return def();
43
- return def;
45
+ normalizeRootScopeValue(resolution) {
46
+ if (isThunk(resolution) && !hasArkKind(resolution, "generic"))
47
+ return resolution();
48
+ return resolution;
44
49
  }
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
- ]));
50
+ preparseOwnDefinitionFormat(def, opts) {
51
+ return {
52
+ ...opts,
53
+ def,
54
+ prefix: opts.alias ?? "type"
55
+ };
52
56
  }
53
- parse(def, ctx, defaultable = false) {
54
- if (typeof def === "string") {
55
- if (ctx.args && Object.keys(ctx.args).some(k => def.includes(k))) {
56
- // we can only rely on the cache if there are no contextual
57
- // resolutions like "this" or generic args
58
- return this.parseString(def, ctx, defaultable);
59
- }
60
- const contextKey = `${def}${defaultable}`;
61
- return (this.parseCache[contextKey] ??= this.parseString(def, ctx, defaultable));
57
+ parseOwnDefinitionFormat(def, ctx) {
58
+ const isScopeAlias = ctx.alias && ctx.alias in this.aliases;
59
+ // if the definition being parsed is not a scope alias and is not a
60
+ // generic instantiation (i.e. opts don't include args), add `this` as a resolution.
61
+ // if we're parsing a nested string, ctx.args will have already been set
62
+ if (!isScopeAlias && !ctx.args)
63
+ ctx.args = { this: ctx.id };
64
+ const result = parseInnerDefinition(def, ctx);
65
+ if (isArray(result)) {
66
+ if (result[1] === "=")
67
+ return throwParseError(shallowDefaultableMessage);
68
+ if (result[1] === "?")
69
+ return throwParseError(shallowOptionalMessage);
62
70
  }
63
- return hasDomain(def, "object") ?
64
- parseObject(def, ctx)
65
- : throwParseError(writeBadDefinitionTypeMessage(domainOf(def)));
71
+ return result;
66
72
  }
67
- parseString(def, ctx, defaultable) {
68
- const aliasResolution = this.maybeResolveRoot(def);
69
- if (aliasResolution)
70
- return aliasResolution;
71
- const aliasArrayResolution = def.endsWith("[]") ?
72
- this.maybeResolveRoot(def.slice(0, -2))?.array()
73
- : undefined;
74
- if (aliasArrayResolution)
75
- return aliasArrayResolution;
76
- const s = new DynamicState(new Scanner(def), ctx, defaultable);
77
- const node = fullStringParse(s);
78
- if (s.finalizer === ">")
79
- throwParseError(writeUnexpectedCharacterMessage(">"));
80
- return node;
81
- }
82
- parseRoot = (def, opts = {}) => {
83
- const node = this.parse(def, Object.assign(this.finalizeRootArgs(opts, () => node), { $: this })).bindScope(this);
84
- return node;
85
- };
73
+ unit = value => this.units([value]);
74
+ enumerated = (...values) => this.units(values);
75
+ instanceOf = ctor => this.node("proto", { proto: ctor }, { prereduced: true });
86
76
  type = new InternalTypeParser(this);
87
77
  declare = () => ({
88
78
  type: this.type
89
79
  });
90
- define = ((def) => def).bind(this);
80
+ define(def) {
81
+ return def;
82
+ }
91
83
  static scope = ((def, config = {}) => new InternalScope(def, config));
92
84
  static module = ((def, config = {}) => this.scope(def, config).export());
93
85
  }
94
- export const scope = InternalScope.scope;
95
- export const module = InternalScope.module;
86
+ export const scope = Object.assign(InternalScope.scope, {
87
+ define: def => def
88
+ });
96
89
  export const Scope = InternalScope;
97
- export const writeShallowCycleErrorMessage = (name, seen) => `Alias '${name}' has a shallow resolution cycle: ${[...seen, name].join(":")}`;
package/out/type.d.ts CHANGED
@@ -1,25 +1,52 @@
1
- import { ArkErrors, BaseRoot, type MetaSchema, type Morph, type Predicate } from "@ark/schema";
2
- import { Callable, type Constructor, type array, type conform } from "@ark/util";
3
- import { type Generic, type GenericParser, type ParameterString, type baseGenericConstraints, type parseValidGenericParams, type validateParameterString } from "./generic.ts";
4
- import type { Ark, ark } from "./keywords/ark.ts";
5
- import type { distillIn, distillOut } from "./keywords/ast.ts";
6
- import type { inferDefinition, validateDeclared, validateDefinition } from "./parser/definition.ts";
7
- import type { IndexOneOperator, IndexZeroOperator, TupleInfixOperator } from "./parser/tuple.ts";
1
+ import { ArkErrors, BaseRoot, type BaseParseOptions, type MetaSchema, type Morph, type Predicate, type RootSchema } from "@ark/schema";
2
+ import { Callable, Hkt, type Constructor, type array, type conform } from "@ark/util";
3
+ import type { distill } from "./attributes.ts";
4
+ import type { Generic, GenericParser, ParameterString, baseGenericConstraints, parseValidGenericParams, validateParameterString } from "./generic.ts";
5
+ import type { Ark, keywords, type } from "./keywords/keywords.ts";
6
+ import type { BaseType } from "./methods/base.ts";
7
+ import type { instantiateType } from "./methods/instantiate.ts";
8
+ import type { validateDeclared } from "./parser/definition.ts";
9
+ import type { IndexOneOperator, IndexZeroOperator, TupleInfixOperator } from "./parser/tupleExpressions.ts";
8
10
  import type { InternalScope, ModuleParser, Scope, ScopeParser, bindThis } from "./scope.ts";
9
- import type { BaseType } from "./subtypes/base.ts";
10
- import type { instantiateType } from "./subtypes/instantiate.ts";
11
11
  /** The convenience properties attached to `type` */
12
12
  export type TypeParserAttachments = Omit<TypeParser, never>;
13
13
  export interface TypeParser<$ = {}> extends Ark.boundTypeAttachments<$> {
14
- <const def, r = Type<inferTypeRoot<def, $>, $>>(def: validateTypeRoot<def, $>): r;
15
- <params extends ParameterString, const def>(params: validateParameterString<params, $>, def: validateDefinition<def, $, baseGenericConstraints<parseValidGenericParams<params, $>>>): Generic<parseValidGenericParams<params, $>, def, $>;
16
- <const zero, const one, const rest extends array, r = Type<inferTypeRoot<[zero, one, ...rest], $>, $>>(_0: zero extends IndexZeroOperator ? zero : validateTypeRoot<zero, $>, _1: zero extends "keyof" ? validateTypeRoot<one, $> : zero extends "instanceof" ? conform<one, Constructor> : zero extends "===" ? conform<one, unknown> : conform<one, IndexOneOperator>, ..._2: zero extends "===" ? rest : zero extends "instanceof" ? conform<rest, readonly Constructor[]> : one extends TupleInfixOperator ? one extends ":" ? [Predicate<distillIn<inferTypeRoot<zero, $>>>] : one extends "=>" ? [Morph<distillOut<inferTypeRoot<zero, $>>, unknown>] : one extends "@" ? [MetaSchema] : [validateTypeRoot<rest[0], $>] : []): r;
17
- raw(def: unknown): BaseType<any, $>;
14
+ <const def, r = Type<type.infer<def, $>, $>>(def: type.validate<def, $>): r;
15
+ <const params extends ParameterString, const def>(params: validateParameterString<params, $>, def: type.validate<def, $, baseGenericConstraints<parseValidGenericParams<params, $>>>): Generic<parseValidGenericParams<params, $>, def, $>;
16
+ <const zero, const one, const rest extends array, r = Type<type.infer<[zero, one, ...rest], $>, $>>(_0: zero extends IndexZeroOperator ? zero : type.validate<zero, $>, _1: zero extends "keyof" ? type.validate<one, $> : zero extends "instanceof" ? conform<one, Constructor> : zero extends "===" ? conform<one, unknown> : conform<one, IndexOneOperator>, ..._2: zero extends "===" ? rest : zero extends "instanceof" ? conform<rest, readonly Constructor[]> : one extends TupleInfixOperator ? one extends ":" ? [Predicate<distill.In<type.infer<zero, $>>>] : one extends "=>" ? [Morph<distill.Out<type.infer<zero, $>>, unknown>] : one extends "@" ? [MetaSchema] : [type.validate<rest[0], $>] : []): r;
17
+ /**
18
+ * Error class for validation errors
19
+ * Calling type instance returns an instance of this class on failure
20
+ * @example if ( T(data) instanceof type.errors ) { ... }
21
+ */
18
22
  errors: typeof ArkErrors;
23
+ hkt: typeof Hkt;
24
+ keywords: typeof keywords;
25
+ $: Scope<$>;
26
+ raw(def: unknown): BaseType<any, $>;
19
27
  module: ModuleParser;
20
28
  scope: ScopeParser;
29
+ define: DefinitionParser<$>;
21
30
  generic: GenericParser<$>;
22
- ark: typeof ark;
31
+ schema: SchemaParser<$>;
32
+ /**
33
+ * Create a `Type` that is satisfied only by a value strictly equal (`===`) to the argument passed to this function.
34
+ * @example const foo = type.unit('foo') // Type<'foo'>
35
+ * @example const sym: unique symbol = Symbol(); type.unit(sym) // Type<typeof sym>
36
+ */
37
+ unit: UnitTypeParser<$>;
38
+ /**
39
+ * Create a `Type` that is satisfied only by a value strictly equal (`===`) to one of the arguments passed to this function.
40
+ * @example const enum = type.enumerated('foo', 'bar', obj) // obj is a by-reference object
41
+ * @example const tupleForm = type(['===', 'foo', 'bar', obj])
42
+ * @example const argsForm = type('===', 'foo', 'bar', obj)
43
+ */
44
+ enumerated: EnumeratedTypeParser<$>;
45
+ /**
46
+ * Create a `Type` that is satisfied only by a value of a specific class.
47
+ * @example const array = type.instanceOf(Array)
48
+ */
49
+ instanceOf: InstanceOfTypeParser<$>;
23
50
  }
24
51
  export declare class InternalTypeParser extends Callable<(...args: unknown[]) => BaseRoot | Generic, TypeParserAttachments> {
25
52
  constructor($: InternalScope);
@@ -27,14 +54,11 @@ export declare class InternalTypeParser extends Callable<(...args: unknown[]) =>
27
54
  export type DeclarationParser<$> = <preinferred>() => {
28
55
  type: <const def>(def: validateDeclared<preinferred, def, $, bindThis<def>>) => Type<preinferred, $>;
29
56
  };
30
- export type DefinitionParser<$> = <def>(def: validateTypeRoot<def, $>) => def;
31
- export type validateTypeRoot<def, $ = {}> = validateDefinition<def, $, bindThis<def>>;
32
- export type inferTypeRoot<def, $> = inferDefinition<def, $, bindThis<def>>;
33
- export type validateAmbient<def> = validateTypeRoot<def, {}>;
34
- export type inferAmbient<def> = inferTypeRoot<def, {}>;
57
+ export type UnitTypeParser<$> = <const t>(value: t) => Type<t, $>;
58
+ export type InstanceOfTypeParser<$> = <const t extends object>(ctor: Constructor<t>) => Type<t, $>;
59
+ export type EnumeratedTypeParser<$> = <const values extends readonly unknown[]>(...values: values) => Type<values[number], $>;
60
+ export type DefinitionParser<$> = <const def>(def: type.validate<def, $>) => def;
61
+ export type SchemaParser<$> = (schema: RootSchema, opts?: BaseParseOptions) => Type<unknown, $>;
35
62
  export type Type<t = unknown, $ = {}> = instantiateType<t, $>;
36
- export declare namespace Type {
37
- type Any<t = any> = BaseType<t, any>;
38
- }
39
63
  export type TypeConstructor<t = unknown, $ = {}> = new (def: unknown, $: Scope<$>) => Type<t, $>;
40
64
  export declare const Type: TypeConstructor;
package/out/type.js CHANGED
@@ -1,23 +1,29 @@
1
1
  import { ArkErrors, BaseRoot, GenericRoot } from "@ark/schema";
2
- import { Callable } from "@ark/util";
3
- import { parseGenericParams } from "./generic.js";
2
+ import { Callable, Hkt } from "@ark/util";
4
3
  export class InternalTypeParser extends Callable {
5
4
  constructor($) {
6
5
  const attach = Object.assign({
7
6
  errors: ArkErrors,
8
- raw: $.parseRoot,
7
+ hkt: Hkt,
8
+ $: $,
9
+ raw: $.parse,
9
10
  module: $.constructor.module,
10
11
  scope: $.constructor.scope,
12
+ define: $.define,
11
13
  generic: $.generic,
14
+ schema: $.schema,
12
15
  // this won't be defined during bootstrapping, but externally always will be
13
- ark: $.ambient
16
+ keywords: $.ambient,
17
+ unit: $.unit,
18
+ enumerated: $.enumerated,
19
+ instanceOf: $.instanceOf
14
20
  },
15
21
  // also won't be defined during bootstrapping
16
22
  $.ambientAttachments);
17
23
  super((...args) => {
18
24
  if (args.length === 1) {
19
25
  // treat as a simple definition
20
- return $.parseRoot(args[0]);
26
+ return $.parse(args[0]);
21
27
  }
22
28
  if (args.length === 2 &&
23
29
  typeof args[0] === "string" &&
@@ -25,16 +31,14 @@ export class InternalTypeParser extends Callable {
25
31
  args[0].at(-1) === ">") {
26
32
  // if there are exactly two args, the first of which looks like <${string}>,
27
33
  // treat as a generic
28
- const params = parseGenericParams(args[0].slice(1, -1), {
29
- $,
30
- args: {}
31
- });
32
- return new GenericRoot(params, args[1], $, $);
34
+ const paramString = args[0].slice(1, -1);
35
+ const params = $.parseGenericParams(paramString, {});
36
+ return new GenericRoot(params, args[1], $, $, null);
33
37
  }
34
38
  // otherwise, treat as a tuple expression. technically, this also allows
35
39
  // non-expression tuple definitions to be parsed, but it's not a supported
36
40
  // part of the API as specified by the associated types
37
- return $.parseRoot(args);
41
+ return $.parse(args);
38
42
  }, {
39
43
  bind: $,
40
44
  attach
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "arktype",
3
3
  "description": "TypeScript's 1:1 validator, optimized from editor to runtime",
4
- "version": "2.0.0-rc.3",
4
+ "version": "2.0.0-rc.30",
5
5
  "license": "MIT",
6
6
  "author": {
7
7
  "name": "David Blass",
@@ -34,8 +34,8 @@
34
34
  "out"
35
35
  ],
36
36
  "dependencies": {
37
- "@ark/util": "0.5.0",
38
- "@ark/schema": "0.5.0"
37
+ "@ark/util": "0.30.0",
38
+ "@ark/schema": "0.30.0"
39
39
  },
40
40
  "publishConfig": {
41
41
  "access": "public"
@@ -1,28 +0,0 @@
1
- import type { anyOrNever, array, Hkt, intersectArrays, show } from "@ark/util";
2
- import type { constrain, Constraints, MorphAst, parseConstraints, To } from "./keywords/ast.ts";
3
- export type inferIntersection<l, r> = _inferIntersection<l, r, false>;
4
- export type inferPipe<l, r> = _inferIntersection<l, r, true>;
5
- type _inferIntersection<l, r, piped extends boolean> = [
6
- l & r
7
- ] extends [infer t extends anyOrNever] ? t : l extends MorphAst<infer lIn, infer lOut> ? r extends MorphAst<any, infer rOut> ? piped extends true ? (In: lIn) => rOut : never : piped extends true ? (In: lIn) => To<r> : (In: _inferIntersection<lIn, r, false>) => lOut : r extends MorphAst<infer rIn, infer rOut> ? (In: _inferIntersection<rIn, l, false>) => rOut : parseConstraints<l> extends ([
8
- infer lBase,
9
- infer lConstraints extends Constraints
10
- ]) ? parseConstraints<r> extends ([
11
- infer rBase,
12
- infer rConstraints extends Constraints
13
- ]) ? constrain<_inferIntersection<lBase, rBase, piped>, lConstraints & rConstraints> : constrain<_inferIntersection<lBase, r, piped>, lConstraints> : parseConstraints<r> extends ([
14
- infer rBase,
15
- infer rConstraints extends Constraints
16
- ]) ? constrain<_inferIntersection<l, rBase, piped>, rConstraints> : [l, r] extends [object, object] ? intersectObjects<l, r, piped> extends infer result ? result : never : l & r;
17
- interface MorphableIntersection<piped extends boolean> extends Hkt<[unknown, unknown]> {
18
- body: _inferIntersection<this[0], this[1], piped>;
19
- }
20
- type intersectObjects<l, r, piped extends boolean> = [
21
- l,
22
- r
23
- ] extends [infer lList extends array, infer rList extends array] ? intersectArrays<lList, rList, MorphableIntersection<piped>> : show<{
24
- [k in keyof l]: k extends keyof r ? _inferIntersection<l[k], r[k], piped> : l[k];
25
- } & {
26
- [k in keyof r]: k extends keyof l ? _inferIntersection<l[k], r[k], piped> : r[k];
27
- }>;
28
- export {};
package/out/keys.d.ts DELETED
@@ -1,16 +0,0 @@
1
- import type { array, join, Key, NonNegativeIntegerLiteral, typeToString } from "@ark/util";
2
- import type { type } from "./keywords/ark.ts";
3
- import type { termOrType } from "./keywords/ast.ts";
4
- export type toArkKey<o, k extends keyof o> = k extends number ? [
5
- o,
6
- number
7
- ] extends [array, k] ? NonNegativeIntegerLiteral : `${k}` : k;
8
- export type arkKeyOf<o> = o extends array ? (number extends o["length"] ? NonNegativeIntegerLiteral : never) | {
9
- [k in keyof o]-?: k extends `${infer index extends number}` ? index | k : never;
10
- }[keyof o & `${number}`] : {
11
- [k in keyof o]: k extends number ? k | `${k}` : k;
12
- }[keyof o];
13
- export type getArkKey<o, k extends arkKeyOf<o>> = o[Extract<k extends NonNegativeIntegerLiteral ? number : k, keyof o>];
14
- export type TypeKey = termOrType<Key>;
15
- export type typeKeyToString<k extends TypeKey> = typeToString<k extends type.cast<infer t> ? t : k>;
16
- export type writeInvalidKeysMessage<o extends string, keys extends array<string>> = `Key${keys["length"] extends 1 ? "" : "s"} ${join<keys, ", ">} ${keys["length"] extends 1 ? "does" : "do"} not exist on ${o}`;