arktype 2.0.0-rc.8 → 2.0.0

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 (159) 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 +18 -18
  5. package/out/generic.js +2 -2
  6. package/out/index.d.ts +4 -2
  7. package/out/index.js +3 -2
  8. package/out/keywords/{constructors/Array.d.ts → Array.d.ts} +2 -2
  9. package/out/keywords/{constructors/Array.js → Array.js} +2 -2
  10. package/out/keywords/{constructors/FormData.d.ts → FormData.d.ts} +2 -2
  11. package/out/keywords/{constructors/FormData.js → FormData.js} +2 -2
  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 -1
  16. package/out/keywords/{constructors/constructors.js → constructors.js} +2 -2
  17. package/out/keywords/{ark.d.ts → keywords.d.ts} +16 -15
  18. package/out/keywords/keywords.js +30 -0
  19. package/out/keywords/number.d.ts +23 -0
  20. package/out/keywords/{number/epoch.js → number.js} +22 -1
  21. package/out/keywords/string.d.ts +327 -0
  22. package/out/keywords/string.js +398 -0
  23. package/out/keywords/ts.d.ts +31 -4
  24. package/out/keywords/ts.js +21 -8
  25. package/out/methods/array.d.ts +6 -7
  26. package/out/methods/base.d.ts +461 -34
  27. package/out/methods/date.d.ts +5 -6
  28. package/out/methods/instantiate.d.ts +5 -5
  29. package/out/methods/morph.d.ts +6 -7
  30. package/out/methods/number.d.ts +8 -9
  31. package/out/methods/object.d.ts +80 -31
  32. package/out/methods/string.d.ts +9 -10
  33. package/out/parser/{semantic → ast}/bounds.d.ts +3 -3
  34. package/out/parser/{semantic → ast}/default.d.ts +4 -4
  35. package/out/parser/ast/generic.d.ts +17 -0
  36. package/out/parser/ast/infer.d.ts +25 -0
  37. package/out/parser/{semantic → ast}/utils.d.ts +1 -1
  38. package/out/parser/ast/validate.d.ts +30 -0
  39. package/out/parser/ast/validate.js +3 -0
  40. package/out/parser/definition.d.ts +18 -9
  41. package/out/parser/definition.js +38 -3
  42. package/out/parser/objectLiteral.d.ts +40 -40
  43. package/out/parser/objectLiteral.js +83 -67
  44. package/out/parser/property.d.ts +36 -0
  45. package/out/parser/property.js +16 -0
  46. package/out/parser/{string/reduce → reduce}/dynamic.d.ts +8 -9
  47. package/out/parser/{string/reduce → reduce}/shared.d.ts +1 -1
  48. package/out/parser/{string/reduce → reduce}/static.d.ts +4 -4
  49. package/out/parser/{string/shift → shift}/operand/date.d.ts +1 -1
  50. package/out/parser/{string/shift → shift}/operand/enclosed.d.ts +4 -5
  51. package/out/parser/shift/operand/operand.d.ts +9 -0
  52. package/out/parser/{string/shift → shift}/operand/operand.js +2 -2
  53. package/out/parser/{string/shift → shift}/operand/unenclosed.d.ts +15 -7
  54. package/out/parser/{string/shift → shift}/operand/unenclosed.js +6 -5
  55. package/out/parser/{string/shift → shift}/operator/bounds.d.ts +7 -7
  56. package/out/parser/{string/shift → shift}/operator/bounds.js +5 -4
  57. package/out/parser/shift/operator/brand.d.ts +6 -0
  58. package/out/parser/shift/operator/brand.js +5 -0
  59. package/out/parser/{string/shift → shift}/operator/default.d.ts +3 -2
  60. package/out/parser/{string/shift → shift}/operator/default.js +4 -1
  61. package/out/parser/{string/shift → shift}/operator/divisor.d.ts +2 -2
  62. package/out/parser/shift/operator/operator.d.ts +14 -0
  63. package/out/parser/{string/shift → shift}/operator/operator.js +7 -5
  64. package/out/parser/shift/scanner.d.ts +47 -0
  65. package/out/parser/shift/scanner.js +43 -0
  66. package/out/parser/{string/string.d.ts → string.d.ts} +7 -6
  67. package/out/parser/{string/string.js → string.js} +18 -1
  68. package/out/parser/tupleExpressions.d.ts +48 -0
  69. package/out/parser/tupleExpressions.js +67 -0
  70. package/out/parser/tupleLiteral.d.ts +95 -0
  71. package/out/parser/tupleLiteral.js +122 -0
  72. package/out/scope.d.ts +19 -14
  73. package/out/scope.js +25 -41
  74. package/out/type.d.ts +67 -9
  75. package/out/type.js +4 -3
  76. package/package.json +8 -8
  77. package/out/intersect.d.ts +0 -26
  78. package/out/keys.d.ts +0 -18
  79. package/out/keys.js +0 -1
  80. package/out/keywords/ark.js +0 -26
  81. package/out/keywords/ast.d.ts +0 -198
  82. package/out/keywords/ast.js +0 -2
  83. package/out/keywords/constructors/Date.d.ts +0 -31
  84. package/out/keywords/constructors/Date.js +0 -1
  85. package/out/keywords/number/epoch.d.ts +0 -9
  86. package/out/keywords/number/integer.d.ts +0 -3
  87. package/out/keywords/number/integer.js +0 -5
  88. package/out/keywords/number/number.d.ts +0 -53
  89. package/out/keywords/number/number.js +0 -21
  90. package/out/keywords/string/alpha.d.ts +0 -7
  91. package/out/keywords/string/alpha.js +0 -2
  92. package/out/keywords/string/alphanumeric.d.ts +0 -7
  93. package/out/keywords/string/alphanumeric.js +0 -2
  94. package/out/keywords/string/capitalize.d.ts +0 -15
  95. package/out/keywords/string/capitalize.js +0 -12
  96. package/out/keywords/string/creditCard.d.ts +0 -8
  97. package/out/keywords/string/creditCard.js +0 -37
  98. package/out/keywords/string/date.d.ts +0 -55
  99. package/out/keywords/string/date.js +0 -98
  100. package/out/keywords/string/digits.d.ts +0 -7
  101. package/out/keywords/string/digits.js +0 -2
  102. package/out/keywords/string/email.d.ts +0 -7
  103. package/out/keywords/string/email.js +0 -4
  104. package/out/keywords/string/integer.d.ts +0 -16
  105. package/out/keywords/string/integer.js +0 -16
  106. package/out/keywords/string/ip.d.ts +0 -20
  107. package/out/keywords/string/ip.js +0 -23
  108. package/out/keywords/string/json.d.ts +0 -16
  109. package/out/keywords/string/json.js +0 -53
  110. package/out/keywords/string/lower.d.ts +0 -15
  111. package/out/keywords/string/lower.js +0 -12
  112. package/out/keywords/string/normalize.d.ts +0 -88
  113. package/out/keywords/string/normalize.js +0 -43
  114. package/out/keywords/string/numeric.d.ts +0 -15
  115. package/out/keywords/string/numeric.js +0 -13
  116. package/out/keywords/string/semver.d.ts +0 -7
  117. package/out/keywords/string/semver.js +0 -4
  118. package/out/keywords/string/string.d.ts +0 -108
  119. package/out/keywords/string/string.js +0 -41
  120. package/out/keywords/string/trim.d.ts +0 -15
  121. package/out/keywords/string/trim.js +0 -14
  122. package/out/keywords/string/upper.d.ts +0 -15
  123. package/out/keywords/string/upper.js +0 -12
  124. package/out/keywords/string/url.d.ts +0 -15
  125. package/out/keywords/string/url.js +0 -37
  126. package/out/keywords/string/utils.d.ts +0 -2
  127. package/out/keywords/string/utils.js +0 -10
  128. package/out/keywords/string/uuid.d.ts +0 -42
  129. package/out/keywords/string/uuid.js +0 -19
  130. package/out/keywords/utils.d.ts +0 -1
  131. package/out/keywords/utils.js +0 -2
  132. package/out/methods/validator.d.ts +0 -11
  133. package/out/methods/validator.js +0 -1
  134. package/out/parser/semantic/infer.d.ts +0 -41
  135. package/out/parser/semantic/validate.d.ts +0 -26
  136. package/out/parser/semantic/validate.js +0 -1
  137. package/out/parser/string/shift/operand/operand.d.ts +0 -9
  138. package/out/parser/string/shift/operator/operator.d.ts +0 -13
  139. package/out/parser/string/shift/scanner.d.ts +0 -71
  140. package/out/parser/string/shift/scanner.js +0 -102
  141. package/out/parser/tuple.d.ts +0 -144
  142. package/out/parser/tuple.js +0 -164
  143. /package/out/parser/{semantic → ast}/bounds.js +0 -0
  144. /package/out/parser/{semantic → ast}/default.js +0 -0
  145. /package/out/parser/{semantic → ast}/divisor.d.ts +0 -0
  146. /package/out/parser/{semantic → ast}/divisor.js +0 -0
  147. /package/out/{intersect.js → parser/ast/generic.js} +0 -0
  148. /package/out/parser/{semantic → ast}/infer.js +0 -0
  149. /package/out/parser/{semantic → ast}/keyof.d.ts +0 -0
  150. /package/out/parser/{semantic → ast}/keyof.js +0 -0
  151. /package/out/parser/{semantic → ast}/utils.js +0 -0
  152. /package/out/parser/{string/reduce → reduce}/dynamic.js +0 -0
  153. /package/out/parser/{string/reduce → reduce}/shared.js +0 -0
  154. /package/out/parser/{string/reduce → reduce}/static.js +0 -0
  155. /package/out/parser/{string/shift → shift}/operand/date.js +0 -0
  156. /package/out/parser/{string/shift → shift}/operand/enclosed.js +0 -0
  157. /package/out/parser/{string/shift → shift}/operand/genericArgs.d.ts +0 -0
  158. /package/out/parser/{string/shift → shift}/operand/genericArgs.js +0 -0
  159. /package/out/parser/{string/shift → shift}/operator/divisor.js +0 -0
@@ -0,0 +1,94 @@
1
+ import type { ArkError, ArkErrors, Morph } from "@ark/schema";
2
+ import { type anyOrNever, type array, type Brand, type equals, type Hkt, type intersectArrays, type isSafelyMappable, type Primitive, type show } from "@ark/util";
3
+ import type { arkPrototypes } from "./keywords/constructors.ts";
4
+ import type { type } from "./keywords/keywords.ts";
5
+ import type { Type } from "./type.ts";
6
+ export type { arkPrototypes as object } from "./keywords/constructors.ts";
7
+ export type Comparator = "<" | "<=" | ">" | ">=" | "==";
8
+ export type RegexLiteral<source extends string = string> = `/${source}/`;
9
+ export type DateLiteral<source extends string = string> = `d"${source}"` | `d'${source}'`;
10
+ export type LimitLiteral = number | DateLiteral;
11
+ export type normalizeLimit<limit> = limit extends DateLiteral<infer source> ? source : limit extends number | string ? limit : never;
12
+ export type distill<t, endpoint extends distill.Endpoint> = finalizeDistillation<t, _distill<t, endpoint, never>>;
13
+ export declare namespace distill {
14
+ type Endpoint = "in" | "out" | "out.introspectable";
15
+ type In<t> = distill<t, "in">;
16
+ type Out<t> = distill<t, "out">;
17
+ namespace introspectable {
18
+ type Out<t> = distill<t, "out.introspectable">;
19
+ }
20
+ }
21
+ type finalizeDistillation<t, distilled> = equals<t, distilled> extends true ? t : distilled;
22
+ type _distill<t, endpoint extends distill.Endpoint, seen> = t extends undefined ? t : [t] extends [anyOrNever | seen] ? t : unknown extends t ? unknown : t extends Brand<infer base> ? endpoint extends "in" ? base : t : t extends TerminallyInferredObject | Primitive ? t : t extends Function ? t extends InferredMorph<infer i, infer o> ? distillIo<i, o, endpoint, seen> : t : t extends Default<infer constraint> ? _distill<constraint, endpoint, seen> : t extends array ? distillArray<t, endpoint, seen | t> : isSafelyMappable<t> extends true ? distillMappable<t, endpoint, seen | t> : t;
23
+ type distillMappable<o, endpoint extends distill.Endpoint, seen> = endpoint extends "in" ? show<{
24
+ [k in keyof o as k extends inferredDefaultKeyOf<o> ? never : k]: _distill<o[k], endpoint, seen>;
25
+ } & {
26
+ [k in inferredDefaultKeyOf<o>]?: _distill<o[k], endpoint, seen>;
27
+ }> : {
28
+ [k in keyof o]: _distill<o[k], endpoint, seen>;
29
+ };
30
+ type distillIo<i, o extends Out, endpoint extends distill.Endpoint, seen> = endpoint extends "out" ? _distill<o["t"], endpoint, seen> : endpoint extends "in" ? _distill<i, endpoint, seen> : o extends To<infer validatedOut> ? _distill<validatedOut, endpoint, seen> : unknown;
31
+ type unwrapInput<t> = t extends InferredMorph<infer i> ? t extends anyOrNever ? t : i : t;
32
+ type inferredDefaultKeyOf<o> = keyof o extends infer k ? k extends keyof o ? unwrapInput<o[k]> extends Default<infer t> ? [
33
+ t
34
+ ] extends [anyOrNever] ? never : k : never : never : never;
35
+ type distillArray<t extends array, endpoint extends distill.Endpoint, seen> = t[number][] extends t ? alignReadonly<_distill<t[number], endpoint, seen>[], t> : distillNonArraykeys<t, alignReadonly<distillArrayFromPrefix<[...t], endpoint, seen, []>, t>, endpoint, seen>;
36
+ type alignReadonly<result extends unknown[], original extends array> = original extends unknown[] ? result : Readonly<result>;
37
+ type distillNonArraykeys<originalArray extends array, distilledArray, endpoint extends distill.Endpoint, seen> = keyof originalArray extends keyof distilledArray ? distilledArray : distilledArray & _distill<{
38
+ [k in keyof originalArray as k extends keyof distilledArray ? never : k]: originalArray[k];
39
+ }, endpoint, seen>;
40
+ type distillArrayFromPrefix<t extends array, endpoint extends distill.Endpoint, seen, prefix extends array> = t extends readonly [infer head, ...infer tail] ? distillArrayFromPrefix<tail, endpoint, seen, [
41
+ ...prefix,
42
+ _distill<head, endpoint, seen>
43
+ ]> : [...prefix, ...distillArrayFromPostfix<t, endpoint, seen, []>];
44
+ type distillArrayFromPostfix<t extends array, endpoint extends distill.Endpoint, seen, postfix extends array> = t extends readonly [...infer init, infer last] ? distillArrayFromPostfix<init, endpoint, seen, [
45
+ _distill<last, endpoint, seen>,
46
+ ...postfix
47
+ ]> : [...{
48
+ [i in keyof t]: _distill<t[i], endpoint, seen>;
49
+ }, ...postfix];
50
+ type BuiltinTerminalObjectKind = Exclude<keyof arkPrototypes.instances, "Array" | "Function">;
51
+ /** Objects we don't want to expand during inference like Date or Promise */
52
+ type TerminallyInferredObject = arkPrototypes.instanceOf<BuiltinTerminalObjectKind> | ArkEnv.prototypes;
53
+ export type inferPredicate<t, predicate> = predicate extends (data: any, ...args: any[]) => data is infer narrowed ? narrowed : t;
54
+ export type inferPipes<t, pipes extends Morph[]> = pipes extends [infer head extends Morph, ...infer tail extends Morph[]] ? inferPipes<head extends type.cast<infer tPipe> ? inferPipe<t, tPipe> : inferMorphOut<head> extends infer out ? (In: distill.In<t>) => Out<out> : never, tail> : t;
55
+ export type inferMorphOut<morph extends Morph> = Exclude<ReturnType<morph>, ArkError | ArkErrors>;
56
+ declare const isMorphOutKey: " isMorphOut";
57
+ export interface Out<o = any> {
58
+ [isMorphOutKey]: true;
59
+ t: o;
60
+ introspectable: boolean;
61
+ }
62
+ export interface To<o = any> extends Out<o> {
63
+ introspectable: true;
64
+ }
65
+ export type InferredMorph<i = any, o extends Out = Out> = (In: i) => o;
66
+ declare const defaultsToKey: " defaultsTo";
67
+ export type Default<t = unknown, v = unknown> = {
68
+ [defaultsToKey]: [t, v];
69
+ };
70
+ export type withDefault<t, v, undistributed = t> = t extends InferredMorph ? addDefaultToMorph<t, v> : Default<Exclude<undistributed, InferredMorph>, v>;
71
+ type addDefaultToMorph<t extends InferredMorph, v> = [
72
+ normalizeMorphDistribution<t>
73
+ ] extends [InferredMorph<infer i, infer o>] ? (In: Default<i, v>) => o : never;
74
+ type normalizeMorphDistribution<t, undistributedIn = t extends InferredMorph<infer i> ? i : never, undistributedOut extends Out = [t] extends [InferredMorph<any, infer o>] ? [
75
+ o
76
+ ] extends [To<infer unwrappedOut>] ? To<unwrappedOut> : o : never> = (Extract<t, InferredMorph> extends anyOrNever ? never : Extract<t, InferredMorph> extends InferredMorph<infer i, infer o> ? [
77
+ undistributedOut
78
+ ] extends [o] ? (In: undistributedIn) => undistributedOut : [undistributedIn] extends [i] ? (In: undistributedIn) => undistributedOut : t : never) | Exclude<t, InferredMorph>;
79
+ export type defaultFor<t = unknown> = (Primitive extends t ? Primitive : t extends Primitive ? t : never) | (() => t);
80
+ export type termOrType<t> = t | Type<t, any>;
81
+ export type inferIntersection<l, r> = normalizeMorphDistribution<_inferIntersection<l, r, false>>;
82
+ export type inferPipe<l, r> = normalizeMorphDistribution<_inferIntersection<l, r, true>>;
83
+ type _inferIntersection<l, r, piped extends boolean> = [
84
+ l & r
85
+ ] extends [infer t extends anyOrNever] ? t : l extends InferredMorph<infer lIn, infer lOut> ? r extends InferredMorph<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 InferredMorph<infer rIn, infer rOut> ? (In: _inferIntersection<rIn, l, false>) => rOut : [l, r] extends [object, object] ? intersectObjects<l, r, piped> extends infer result ? result : never : l & r;
86
+ interface MorphableIntersection<piped extends boolean> extends Hkt<[unknown, unknown]> {
87
+ body: _inferIntersection<this[0], this[1], piped>;
88
+ }
89
+ type intersectObjects<l, r, piped extends boolean> = l extends array ? r extends array ? intersectArrays<l, r, MorphableIntersection<piped>> : // for an intersection with exactly one array operand like { name: string } & string[],
90
+ l & r : r extends array ? l & r : show<{
91
+ [k in keyof l]: k extends keyof r ? _inferIntersection<l[k], r[k], piped> : l[k];
92
+ } & {
93
+ [k in keyof r]: k extends keyof l ? _inferIntersection<l[k], r[k], piped> : r[k];
94
+ }>;
@@ -0,0 +1,3 @@
1
+ import { noSuggest } from "@ark/util";
2
+ const isMorphOutKey = noSuggest("isMorphOut");
3
+ const defaultsToKey = noSuggest("defaultsTo");
package/out/config.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { ArkSchemaRegistry } from "@ark/schema";
2
- import type { Ark } from "./keywords/ark.ts";
2
+ import type { Ark } from "./keywords/keywords.ts";
3
3
  import type { exportScope } from "./module.ts";
4
4
  export * from "@ark/schema/config";
5
5
  export interface ArkTypeRegistryContents extends ArkSchemaRegistry {
package/out/generic.d.ts CHANGED
@@ -1,12 +1,12 @@
1
1
  import { GenericRoot, type arkKind, type BaseParseContext, type GenericAst, type GenericParamAst, type GenericParamDef, type genericParamNames, type LazyGenericBody } from "@ark/schema";
2
- import { type array, type Callable, type conform, type ErrorMessage, type ErrorType, type Hkt, type Json, type WhiteSpaceToken } from "@ark/util";
3
- import type { type } from "./keywords/ark.ts";
4
- import type { inferDefinition, validateDefinition } from "./parser/definition.ts";
5
- import type { inferAstRoot } from "./parser/semantic/infer.ts";
6
- import type { validateAst } from "./parser/semantic/validate.ts";
7
- import type { state, StaticState } from "./parser/string/reduce/static.ts";
8
- import type { Scanner } from "./parser/string/shift/scanner.ts";
9
- import { parseUntilFinalizer } from "./parser/string/string.ts";
2
+ import { type array, type Callable, type conform, type ErrorMessage, type ErrorType, type Hkt, type JsonStructure, type WhitespaceChar } from "@ark/util";
3
+ import type { type } from "./keywords/keywords.ts";
4
+ import type { inferAstRoot } from "./parser/ast/infer.ts";
5
+ import type { validateAst } from "./parser/ast/validate.ts";
6
+ import type { inferDefinition } from "./parser/definition.ts";
7
+ import type { state, StaticState } from "./parser/reduce/static.ts";
8
+ import type { ArkTypeScanner } from "./parser/shift/scanner.ts";
9
+ import { parseUntilFinalizer } from "./parser/string.ts";
10
10
  import type { Scope } from "./scope.ts";
11
11
  import type { Type } from "./type.ts";
12
12
  export type ParameterString<params extends string = string> = `<${params}>`;
@@ -119,7 +119,7 @@ export interface Generic<params extends array<GenericParamAst> = array<GenericPa
119
119
  $: Scope<$>;
120
120
  arg$: Scope<arg$>;
121
121
  internal: GenericRoot;
122
- json: Json;
122
+ json: JsonStructure;
123
123
  }
124
124
  export type GenericConstructor<params extends array<GenericParamAst> = array<GenericParamAst>, bodyDef = unknown, $ = {}, arg$ = {}> = new () => Generic<params, bodyDef, $, arg$>;
125
125
  export declare const Generic: GenericConstructor;
@@ -127,19 +127,19 @@ export type GenericDeclaration<name extends string = string, params extends Para
127
127
  export type parseValidGenericParams<def extends ParameterString, $> = conform<parseGenericParams<extractParams<def>, $>, array<GenericParamAst>>;
128
128
  export declare const emptyGenericParameterMessage = "An empty string is not a valid generic parameter name";
129
129
  export type emptyGenericParameterMessage = typeof emptyGenericParameterMessage;
130
- export type parseGenericParams<def extends string, $> = parseNextNameChar<Scanner.skipWhitespace<def>, "", [
130
+ export type parseGenericParams<def extends string, $> = parseNextNameChar<ArkTypeScanner.skipWhitespace<def>, "", [
131
131
  ], $>;
132
- type ParamsTerminator = WhiteSpaceToken | ",";
133
- export declare const parseGenericParamName: (scanner: Scanner, result: GenericParamDef[], ctx: BaseParseContext) => GenericParamDef[];
134
- type parseName<unscanned extends string, result extends array<GenericParamAst>, $> = parseNextNameChar<Scanner.skipWhitespace<unscanned>, "", result, $>;
135
- type parseNextNameChar<unscanned extends string, name extends string, result extends array<GenericParamAst>, $> = unscanned extends `${infer lookahead}${infer nextUnscanned}` ? lookahead extends ParamsTerminator ? name extends "" ? ErrorMessage<emptyGenericParameterMessage> : lookahead extends "," ? parseName<nextUnscanned, [...result, [name, unknown]], $> : lookahead extends WhiteSpaceToken ? _parseOptionalConstraint<nextUnscanned, name, result, $> : never : parseNextNameChar<nextUnscanned, `${name}${lookahead}`, result, $> : name extends "" ? result : [...result, [name, unknown]];
132
+ type ParamsTerminator = WhitespaceChar | ",";
133
+ export declare const parseGenericParamName: (scanner: ArkTypeScanner, result: GenericParamDef[], ctx: BaseParseContext) => GenericParamDef[];
134
+ type parseName<unscanned extends string, result extends array<GenericParamAst>, $> = parseNextNameChar<ArkTypeScanner.skipWhitespace<unscanned>, "", result, $>;
135
+ type parseNextNameChar<unscanned extends string, name extends string, result extends array<GenericParamAst>, $> = unscanned extends `${infer lookahead}${infer nextUnscanned}` ? lookahead extends ParamsTerminator ? name extends "" ? ErrorMessage<emptyGenericParameterMessage> : lookahead extends "," ? parseName<nextUnscanned, [...result, [name, unknown]], $> : lookahead extends WhitespaceChar ? _parseOptionalConstraint<nextUnscanned, name, result, $> : never : parseNextNameChar<nextUnscanned, `${name}${lookahead}`, result, $> : name extends "" ? result : [...result, [name, unknown]];
136
136
  declare const extendsToken = "extends ";
137
137
  type extendsToken = typeof extendsToken;
138
- declare const _parseOptionalConstraint: (scanner: Scanner, name: string, result: GenericParamDef[], ctx: BaseParseContext) => GenericParamDef[];
139
- type _parseOptionalConstraint<unscanned extends string, name extends string, result extends array<GenericParamAst>, $> = Scanner.skipWhitespace<unscanned> extends (`${extendsToken}${infer nextUnscanned}`) ? parseUntilFinalizer<state.initialize<nextUnscanned>, $, {}> extends (infer finalArgState extends StaticState) ? validateAst<finalArgState["root"], $, {}> extends (infer e extends ErrorMessage) ? e : parseName<finalArgState["unscanned"], [
138
+ declare const _parseOptionalConstraint: (scanner: ArkTypeScanner, name: string, result: GenericParamDef[], ctx: BaseParseContext) => GenericParamDef[];
139
+ type _parseOptionalConstraint<unscanned extends string, name extends string, result extends array<GenericParamAst>, $> = ArkTypeScanner.skipWhitespace<unscanned> extends (`${extendsToken}${infer nextUnscanned}`) ? parseUntilFinalizer<state.initialize<nextUnscanned>, $, {}> extends (infer finalArgState extends StaticState) ? validateAst<finalArgState["root"], $, {}> extends (infer e extends ErrorMessage) ? e : parseName<finalArgState["unscanned"], [
140
140
  ...result,
141
141
  [name, inferAstRoot<finalArgState["root"], $, {}>]
142
- ], $> : never : parseName<Scanner.skipWhitespace<unscanned> extends `,${infer nextUnscanned}` ? nextUnscanned : unscanned, [
142
+ ], $> : never : parseName<ArkTypeScanner.skipWhitespace<unscanned> extends (`,${infer nextUnscanned}`) ? nextUnscanned : unscanned, [
143
143
  ...result,
144
144
  [name, unknown]
145
145
  ], $>;
@@ -153,7 +153,7 @@ export type GenericParser<$ = {}> = <const paramsDef extends array<GenericParamD
153
153
  [i in keyof paramsDef]: paramsDef[i] extends (readonly [infer name, infer def]) ? readonly [name, type.validate<def, $>] : paramsDef[i];
154
154
  }) => GenericBodyParser<genericParamDefsToAst<paramsDef, $>, $>;
155
155
  interface GenericBodyParser<params extends array<GenericParamAst>, $> {
156
- <const body>(body: validateDefinition<body, $, baseGenericConstraints<params>>): Generic<params, body, $, $>;
156
+ <const body>(body: type.validate<body, $, baseGenericConstraints<params>>): Generic<params, body, $, $>;
157
157
  <hkt extends Hkt.constructor>(instantiateDef: LazyGenericBody<baseGenericResolutions<params, $>>, hkt: hkt): Generic<params, InstanceType<hkt>, $, $>;
158
158
  }
159
159
  export {};
package/out/generic.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { GenericRoot } from "@ark/schema";
2
2
  import { throwParseError } from "@ark/util";
3
- import { DynamicState } from "./parser/string/reduce/dynamic.js";
4
- import { parseUntilFinalizer } from "./parser/string/string.js";
3
+ import { DynamicState } from "./parser/reduce/dynamic.js";
4
+ import { parseUntilFinalizer } from "./parser/string.js";
5
5
  export const Generic = GenericRoot;
6
6
  export const emptyGenericParameterMessage = "An empty string is not a valid generic parameter name";
7
7
  export const parseGenericParamName = (scanner, result, ctx) => {
package/out/index.d.ts CHANGED
@@ -1,7 +1,9 @@
1
1
  export { ArkError, ArkErrors, type ArkConfig, type ArkScopeConfig, type JsonSchema } from "@ark/schema";
2
2
  export { Hkt, inferred } from "@ark/util";
3
+ export type { distill } from "./attributes.ts";
4
+ export * from "./config.ts";
3
5
  export { Generic } from "./generic.ts";
4
- export { ambient, ark, declare, define, generic, type, type Ark } from "./keywords/ark.ts";
6
+ export { ark, declare, define, generic, keywords, type, type Ark } from "./keywords/keywords.ts";
5
7
  export { Module, type BoundModule, type Submodule } from "./module.ts";
6
- export { module, scope, type Scope } from "./scope.ts";
8
+ export { scope, type Scope } from "./scope.ts";
7
9
  export { Type } from "./type.ts";
package/out/index.js CHANGED
@@ -1,7 +1,8 @@
1
1
  export { ArkError, ArkErrors } from "@ark/schema";
2
2
  export { Hkt, inferred } from "@ark/util";
3
+ export * from "./config.js";
3
4
  export { Generic } from "./generic.js";
4
- export { ambient, ark, declare, define, generic, type } from "./keywords/ark.js";
5
+ export { ark, declare, define, generic, keywords, type } from "./keywords/keywords.js";
5
6
  export { Module } from "./module.js";
6
- export { module, scope } from "./scope.js";
7
+ export { scope } from "./scope.js";
7
8
  export { Type } from "./type.js";
@@ -1,6 +1,6 @@
1
1
  import { Hkt, liftArray, type Digit } from "@ark/util";
2
- import type { Module, Submodule } from "../../module.ts";
3
- import type { To } from "../ast.ts";
2
+ import type { To } from "../attributes.ts";
3
+ import type { Module, Submodule } from "../module.ts";
4
4
  declare class liftFromHkt extends Hkt<[element: unknown]> {
5
5
  body: liftArray<this[0]> extends infer lifted ? (In: this[0] | lifted) => To<lifted> : never;
6
6
  }
@@ -1,6 +1,6 @@
1
1
  import { genericNode, intrinsic, rootSchema } from "@ark/schema";
2
2
  import { Hkt, liftArray } from "@ark/util";
3
- import { arkModule } from "../utils.js";
3
+ import { Scope } from "../scope.js";
4
4
  class liftFromHkt extends Hkt {
5
5
  }
6
6
  const liftFrom = genericNode("element")(args => {
@@ -11,7 +11,7 @@ const liftFrom = genericNode("element")(args => {
11
11
  .pipe(liftArray)
12
12
  .distribute(branch => branch.assertHasKind("morph").declareOut(lifted), rootSchema);
13
13
  }, liftFromHkt);
14
- export const arkArray = arkModule({
14
+ export const arkArray = Scope.module({
15
15
  root: intrinsic.Array,
16
16
  readonly: "root",
17
17
  index: intrinsic.nonNegativeIntegerString,
@@ -1,5 +1,5 @@
1
- import type { Module, Submodule } from "../../module.ts";
2
- import type { To } from "../ast.ts";
1
+ import type { To } from "../attributes.ts";
2
+ import type { Module, Submodule } from "../module.ts";
3
3
  export type FormDataValue = string | File;
4
4
  export type ParsedFormData = Record<string, FormDataValue | FormDataValue[]>;
5
5
  export declare const arkFormData: arkFormData.module;
@@ -1,6 +1,6 @@
1
1
  import { rootSchema } from "@ark/schema";
2
2
  import { registry } from "@ark/util";
3
- import { arkModule } from "../utils.js";
3
+ import { Scope } from "../scope.js";
4
4
  const value = rootSchema(["string", registry.FileConstructor]);
5
5
  const parsedFormDataValue = value.rawOr(value.array());
6
6
  const parsed = rootSchema({
@@ -11,7 +11,7 @@ const parsed = rootSchema({
11
11
  value: parsedFormDataValue
12
12
  }
13
13
  });
14
- export const arkFormData = arkModule({
14
+ export const arkFormData = Scope.module({
15
15
  root: ["instanceof", FormData],
16
16
  value,
17
17
  parsed,
@@ -1,4 +1,4 @@
1
- import type { Module, Submodule } from "../../module.ts";
1
+ import type { Module, Submodule } from "../module.ts";
2
2
  export declare const TypedArray: TypedArray.module;
3
3
  export declare namespace TypedArray {
4
4
  type module = Module<TypedArray.$>;
@@ -1,5 +1,5 @@
1
- import { arkModule } from "../utils.js";
2
- export const TypedArray = arkModule({
1
+ import { Scope } from "../scope.js";
2
+ export const TypedArray = Scope.module({
3
3
  Int8: ["instanceof", Int8Array],
4
4
  Uint8: ["instanceof", Uint8Array],
5
5
  Uint8Clamped: ["instanceof", Uint8ClampedArray],
@@ -1,10 +1,10 @@
1
1
  import { genericNode, intrinsic } from "@ark/schema";
2
2
  import { Hkt } from "@ark/util";
3
- import { arkModule } from "./utils.js";
3
+ import { Scope } from "../scope.js";
4
4
  class MergeHkt extends Hkt {
5
5
  }
6
6
  const Merge = genericNode(["base", intrinsic.object], ["props", intrinsic.object])(args => args.base.merge(args.props), MergeHkt);
7
- export const arkBuiltins = arkModule({
7
+ export const arkBuiltins = Scope.module({
8
8
  Key: intrinsic.key,
9
9
  Merge
10
10
  });
@@ -1,5 +1,5 @@
1
1
  import { type EcmascriptObjects, type PlatformObjects } from "@ark/util";
2
- import type { Module, Submodule } from "../../module.ts";
2
+ import type { Module, Submodule } from "../module.ts";
3
3
  import { arkArray } from "./Array.ts";
4
4
  import { arkFormData } from "./FormData.ts";
5
5
  import { TypedArray } from "./TypedArray.ts";
@@ -1,5 +1,5 @@
1
1
  import { ecmascriptConstructors, flatMorph, platformConstructors } from "@ark/util";
2
- import { arkModule } from "../utils.js";
2
+ import { Scope } from "../scope.js";
3
3
  import { arkArray } from "./Array.js";
4
4
  import { arkFormData } from "./FormData.js";
5
5
  import { TypedArray } from "./TypedArray.js";
@@ -8,7 +8,7 @@ const omittedPrototypes = {
8
8
  Number: 1,
9
9
  String: 1
10
10
  };
11
- export const arkPrototypes = arkModule({
11
+ export const arkPrototypes = Scope.module({
12
12
  ...flatMorph({ ...ecmascriptConstructors, ...platformConstructors }, (k, v) => (k in omittedPrototypes ? [] : [k, ["instanceof", v]])),
13
13
  Array: arkArray,
14
14
  TypedArray,
@@ -1,17 +1,17 @@
1
1
  import type { ArkErrors, arkKind } from "@ark/schema";
2
- import type { inferred } from "@ark/util";
2
+ import type { Brand, inferred } from "@ark/util";
3
+ import type { distill, InferredMorph, Out, To } from "../attributes.ts";
3
4
  import type { GenericParser } from "../generic.ts";
4
5
  import type { BaseType } from "../methods/base.ts";
5
6
  import type { BoundModule, Module } from "../module.ts";
6
7
  import type { inferDefinition, validateDefinition } from "../parser/definition.ts";
7
8
  import { type bindThis, type Scope } from "../scope.ts";
8
9
  import type { DeclarationParser, DefinitionParser, SchemaParser, Type, TypeParser } from "../type.ts";
9
- import type { distill } from "./ast.ts";
10
10
  import { arkBuiltins } from "./builtins.ts";
11
- import { arkPrototypes } from "./constructors/constructors.ts";
12
- import { number } from "./number/number.ts";
13
- import { string } from "./string/string.ts";
14
- import { arkTsGenerics, arkTsKeywords, unknown } from "./ts.ts";
11
+ import { arkPrototypes } from "./constructors.ts";
12
+ import { number } from "./number.ts";
13
+ import { string } from "./string.ts";
14
+ import { arkTsGenerics, arkTsKeywords, object, unknown } from "./ts.ts";
15
15
  export interface Ark extends Omit<Ark.keywords, keyof Ark.wrapped>, Ark.wrapped {
16
16
  }
17
17
  export declare namespace Ark {
@@ -20,22 +20,26 @@ export declare namespace Ark {
20
20
  interface wrapped extends arkPrototypes.wrapped {
21
21
  string: string.submodule;
22
22
  number: number.submodule;
23
+ object: object.submodule;
23
24
  unknown: unknown.submodule;
24
25
  }
25
26
  interface typeAttachments extends arkTsKeywords.$ {
27
+ arrayIndex: arkPrototypes.$["Array"]["index"];
26
28
  Key: arkBuiltins.$["Key"];
27
29
  Record: arkTsGenerics.$["Record"];
30
+ Date: arkPrototypes.$["Date"];
31
+ Array: arkPrototypes.$["Array"]["root"];
28
32
  }
29
33
  interface boundTypeAttachments<$> extends Omit<BoundModule<typeAttachments, $>, arkKind> {
30
34
  }
31
35
  }
32
- export declare const ambient: Scope<Ark>;
33
- export declare const ark: Module<Ark>;
36
+ export declare const ark: Scope<Ark>;
37
+ export declare const keywords: Module<Ark>;
34
38
  export declare const type: TypeParser<{}>;
35
39
  export declare namespace type {
36
- type cast<t> = {
37
- [inferred]?: t;
38
- };
40
+ interface cast<to> {
41
+ [inferred]?: to;
42
+ }
39
43
  type errors = ArkErrors;
40
44
  /** @ts-ignore cast variance */
41
45
  interface Any<out t = any> extends BaseType<t, any> {
@@ -44,15 +48,12 @@ export declare namespace type {
44
48
  namespace infer {
45
49
  type In<def, $ = {}, args = {}> = distill.In<inferDefinition<def, $, args>>;
46
50
  type Out<def, $ = {}, args = {}> = distill.Out<inferDefinition<def, $, args>>;
47
- namespace brandable {
48
- type In<def, $ = {}, args = {}> = distill.brandable.In<inferDefinition<def, $, args>>;
49
- type Out<def, $ = {}, args = {}> = distill.brandable.Out<inferDefinition<def, $, args>>;
50
- }
51
51
  namespace introspectable {
52
52
  type Out<def, $ = {}, args = {}> = distill.introspectable.Out<inferDefinition<def, $, args>>;
53
53
  }
54
54
  }
55
55
  type validate<def, $ = {}, args = bindThis<def>> = validateDefinition<def, $, args>;
56
+ type brand<t, id> = t extends InferredMorph<infer i, infer o> ? o["introspectable"] extends true ? (In: i) => To<Brand<o["t"], id>> : (In: i) => Out<Brand<o["t"], id>> : Brand<t, id>;
56
57
  }
57
58
  export type type<t = unknown, $ = {}> = Type<t, $>;
58
59
  export declare const generic: GenericParser<{}>;
@@ -0,0 +1,30 @@
1
+ import { $arkTypeRegistry, scope } from "../scope.js";
2
+ import { arkBuiltins } from "./builtins.js";
3
+ import { arkPrototypes } from "./constructors.js";
4
+ import { number } from "./number.js";
5
+ import { string } from "./string.js";
6
+ import { arkTsGenerics, arkTsKeywords, object, unknown } from "./ts.js";
7
+ $arkTypeRegistry.typeAttachments = {
8
+ ...arkTsKeywords,
9
+ arrayIndex: arkPrototypes.Array.index,
10
+ Key: arkBuiltins.Key,
11
+ Record: arkTsGenerics.Record,
12
+ Array: arkPrototypes.Array.root,
13
+ Date: arkPrototypes.Date
14
+ };
15
+ export const ark = scope({
16
+ ...arkTsKeywords,
17
+ ...arkTsGenerics,
18
+ ...arkPrototypes,
19
+ ...arkBuiltins,
20
+ string,
21
+ number,
22
+ object,
23
+ unknown
24
+ }, { prereducedAliases: true, ambient: true });
25
+ export const keywords = ark.export();
26
+ export const type = ark.type;
27
+ export const generic = ark.generic;
28
+ export const schema = ark.schema;
29
+ export const define = ark.define;
30
+ export const declare = ark.declare;
@@ -0,0 +1,23 @@
1
+ import type { Module, Submodule } from "../module.ts";
2
+ /**
3
+ * As per the ECMA-262 specification:
4
+ * A time value supports a slightly smaller range of -8,640,000,000,000,000 to 8,640,000,000,000,000 milliseconds.
5
+ *
6
+ * @see https://262.ecma-international.org/15.0/index.html#sec-time-values-and-time-range
7
+ */
8
+ export declare const epoch: import("@ark/schema").BaseRoot<import("@ark/schema").InternalRootDeclaration>;
9
+ export declare const integer: import("@ark/schema").BaseRoot<import("@ark/schema").InternalRootDeclaration>;
10
+ export declare const number: number.module;
11
+ export declare namespace number {
12
+ type module = Module<submodule>;
13
+ type submodule = Submodule<$>;
14
+ type $ = {
15
+ root: number;
16
+ epoch: number;
17
+ integer: number;
18
+ safe: number;
19
+ NaN: number;
20
+ Infinity: number;
21
+ NegativeInfinity: number;
22
+ };
23
+ }
@@ -1,4 +1,5 @@
1
- import { rootSchema } from "@ark/schema";
1
+ import { intrinsic, rootSchema } from "@ark/schema";
2
+ import { Scope } from "../scope.js";
2
3
  /**
3
4
  * As per the ECMA-262 specification:
4
5
  * A time value supports a slightly smaller range of -8,640,000,000,000,000 to 8,640,000,000,000,000 milliseconds.
@@ -24,3 +25,23 @@ export const epoch = rootSchema({
24
25
  },
25
26
  meta: "an integer representing a safe Unix timestamp"
26
27
  });
28
+ export const integer = rootSchema({
29
+ domain: "number",
30
+ divisor: 1
31
+ });
32
+ export const number = Scope.module({
33
+ root: intrinsic.number,
34
+ integer,
35
+ epoch,
36
+ safe: rootSchema({
37
+ domain: {
38
+ domain: "number",
39
+ numberAllowsNaN: false
40
+ },
41
+ min: Number.MIN_SAFE_INTEGER,
42
+ max: Number.MAX_SAFE_INTEGER
43
+ }),
44
+ NaN: ["===", Number.NaN],
45
+ Infinity: ["===", Number.POSITIVE_INFINITY],
46
+ NegativeInfinity: ["===", Number.NEGATIVE_INFINITY]
47
+ });