arktype 2.0.0-beta.2 → 2.0.0-beta.4

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 (89) hide show
  1. package/out/ark.d.ts +18 -4
  2. package/out/ark.js +22 -3
  3. package/out/ast.d.ts +217 -0
  4. package/out/ast.js +3 -0
  5. package/out/config.d.ts +12 -0
  6. package/out/generic.d.ts +106 -20
  7. package/out/index.d.ts +6 -5
  8. package/out/index.js +3 -2
  9. package/out/intersect.d.ts +28 -0
  10. package/out/intersect.js +1 -0
  11. package/out/keys.d.ts +16 -0
  12. package/out/keys.js +1 -0
  13. package/out/keywords/arkGenerics.d.ts +19 -0
  14. package/out/keywords/arkGenerics.js +19 -0
  15. package/out/keywords/format.d.ts +11 -0
  16. package/out/keywords/format.js +31 -0
  17. package/out/keywords/internal.d.ts +11 -0
  18. package/out/keywords/internal.js +25 -0
  19. package/out/keywords/jsObjects.d.ts +15 -0
  20. package/out/keywords/jsObjects.js +13 -0
  21. package/out/keywords/parsing.d.ts +16 -0
  22. package/out/keywords/parsing.js +77 -0
  23. package/out/keywords/platformObjects.d.ts +13 -0
  24. package/out/keywords/platformObjects.js +12 -0
  25. package/out/keywords/tsGenerics.d.ts +37 -0
  26. package/out/keywords/tsGenerics.js +45 -0
  27. package/out/keywords/tsKeywords.d.ts +18 -0
  28. package/out/keywords/tsKeywords.js +17 -0
  29. package/out/keywords/typedArray.d.ts +16 -0
  30. package/out/keywords/typedArray.js +14 -0
  31. package/out/keywords/utils/creditCard.d.ts +2 -0
  32. package/out/keywords/utils/creditCard.js +25 -0
  33. package/out/keywords/utils/date.d.ts +20 -0
  34. package/out/keywords/utils/date.js +36 -0
  35. package/out/keywords/utils/ip.d.ts +3 -0
  36. package/out/keywords/utils/ip.js +20 -0
  37. package/out/keywords/utils/regex.d.ts +2 -0
  38. package/out/keywords/utils/regex.js +9 -0
  39. package/out/keywords/validation.d.ts +19 -0
  40. package/out/keywords/validation.js +84 -0
  41. package/out/module.d.ts +19 -11
  42. package/out/module.js +1 -0
  43. package/out/parser/definition.d.ts +5 -4
  44. package/out/parser/objectLiteral.d.ts +7 -6
  45. package/out/parser/objectLiteral.js +2 -2
  46. package/out/parser/semantic/bounds.d.ts +2 -1
  47. package/out/parser/semantic/divisor.d.ts +2 -2
  48. package/out/parser/semantic/infer.d.ts +14 -9
  49. package/out/parser/semantic/keyof.d.ts +7 -0
  50. package/out/parser/semantic/keyof.js +1 -0
  51. package/out/parser/semantic/validate.d.ts +4 -5
  52. package/out/parser/semantic/validate.js +0 -1
  53. package/out/parser/string/reduce/dynamic.d.ts +2 -1
  54. package/out/parser/string/reduce/shared.d.ts +1 -1
  55. package/out/parser/string/reduce/static.d.ts +1 -1
  56. package/out/parser/string/shift/operand/date.d.ts +3 -1
  57. package/out/parser/string/shift/operand/enclosed.js +1 -1
  58. package/out/parser/string/shift/operand/genericArgs.d.ts +4 -4
  59. package/out/parser/string/shift/operand/unenclosed.d.ts +13 -8
  60. package/out/parser/string/shift/operator/bounds.d.ts +2 -1
  61. package/out/parser/string/shift/operator/bounds.js +4 -4
  62. package/out/parser/string/shift/operator/default.d.ts +2 -1
  63. package/out/parser/string/string.d.ts +2 -1
  64. package/out/parser/tuple.d.ts +5 -3
  65. package/out/parser/tuple.js +5 -5
  66. package/out/scope.d.ts +47 -26
  67. package/out/scope.js +2 -7
  68. package/out/subtypes/array.d.ts +13 -0
  69. package/out/subtypes/array.js +1 -0
  70. package/out/subtypes/base.d.ts +83 -0
  71. package/out/subtypes/base.js +1 -0
  72. package/out/subtypes/date.d.ts +11 -0
  73. package/out/subtypes/date.js +1 -0
  74. package/out/subtypes/instantiate.d.ts +16 -0
  75. package/out/subtypes/instantiate.js +1 -0
  76. package/out/subtypes/morph.d.ts +13 -0
  77. package/out/subtypes/morph.js +1 -0
  78. package/out/subtypes/number.d.ts +12 -0
  79. package/out/subtypes/number.js +1 -0
  80. package/out/subtypes/object.d.ts +27 -0
  81. package/out/subtypes/object.js +1 -0
  82. package/out/subtypes/string.d.ts +13 -0
  83. package/out/subtypes/string.js +1 -0
  84. package/out/subtypes/validator.d.ts +11 -0
  85. package/out/subtypes/validator.js +1 -0
  86. package/out/type.d.ts +17 -71
  87. package/package.json +3 -3
  88. package/out/match.d.ts +0 -71
  89. package/out/match.js +0 -50
package/out/ark.d.ts CHANGED
@@ -1,9 +1,24 @@
1
- import { type Ark, type ArkErrors, type inferred } from "@ark/schema";
1
+ import type { ArkErrors } from "@ark/schema";
2
+ import type { inferred } from "./ast.js";
2
3
  import type { GenericHktParser } from "./generic.js";
3
- import type { MatchParser } from "./match.js";
4
- import type { Module } from "./module.js";
4
+ import { type arkGenericsExports } from "./keywords/arkGenerics.js";
5
+ import { type formattingExports } from "./keywords/format.js";
6
+ import { type internalExports } from "./keywords/internal.js";
7
+ import { type jsObjectExports } from "./keywords/jsObjects.js";
8
+ import { type parsingExports } from "./keywords/parsing.js";
9
+ import { type platformObjectExports } from "./keywords/platformObjects.js";
10
+ import { type tsGenericsExports } from "./keywords/tsGenerics.js";
11
+ import { type tsKeywordExports } from "./keywords/tsKeywords.js";
12
+ import { type typedArrayExports } from "./keywords/typedArray.js";
13
+ import { type validationExports } from "./keywords/validation.js";
14
+ import type { Module, Submodule } from "./module.js";
5
15
  import { type Scope } from "./scope.js";
6
16
  import type { DeclarationParser, DefinitionParser, TypeParser } from "./type.js";
17
+ export interface Ark extends tsKeywordExports, jsObjectExports, platformObjectExports, validationExports, tsGenericsExports, arkGenericsExports, internalExports {
18
+ TypedArray: Submodule<typedArrayExports>;
19
+ parse: Submodule<parsingExports>;
20
+ format: Submodule<formattingExports>;
21
+ }
7
22
  export declare const ambient: Scope<Ark>;
8
23
  export declare const ark: Module<Ark>;
9
24
  export declare const type: TypeParser<{}>;
@@ -14,6 +29,5 @@ export declare namespace type {
14
29
  type errors = ArkErrors;
15
30
  }
16
31
  export declare const generic: GenericHktParser<{}>;
17
- export declare const match: MatchParser<{}>;
18
32
  export declare const define: DefinitionParser<{}>;
19
33
  export declare const declare: DeclarationParser<{}>;
package/out/ark.js CHANGED
@@ -1,9 +1,28 @@
1
- import { keywordNodes } from "@ark/schema";
1
+ import { arkGenerics } from "./keywords/arkGenerics.js";
2
+ import { formatting } from "./keywords/format.js";
3
+ import { internal } from "./keywords/internal.js";
4
+ import { jsObjects } from "./keywords/jsObjects.js";
5
+ import { parsing } from "./keywords/parsing.js";
6
+ import { platformObjects } from "./keywords/platformObjects.js";
7
+ import { tsGenerics } from "./keywords/tsGenerics.js";
8
+ import { tsKeywords } from "./keywords/tsKeywords.js";
9
+ import { typedArray } from "./keywords/typedArray.js";
10
+ import { validation } from "./keywords/validation.js";
2
11
  import { scope } from "./scope.js";
3
- export const ambient = scope(keywordNodes);
12
+ export const ambient = scope({
13
+ ...tsKeywords,
14
+ ...jsObjects,
15
+ ...platformObjects,
16
+ ...validation,
17
+ ...internal,
18
+ ...tsGenerics,
19
+ ...arkGenerics,
20
+ TypedArray: typedArray,
21
+ parse: parsing,
22
+ format: formatting
23
+ }, { prereducedAliases: true, ambient: true });
4
24
  export const ark = ambient.export();
5
25
  export const type = ambient.type;
6
26
  export const generic = ambient.generic;
7
- export const match = ambient.match;
8
27
  export const define = ambient.define;
9
28
  export const declare = ambient.declare;
package/out/ast.d.ts ADDED
@@ -0,0 +1,217 @@
1
+ import type { ArkError, ArkErrors, Constraint, constraintKindOf, Morph, NodeSchema } from "@ark/schema";
2
+ import { type anyOrNever, type array, type BuiltinObjectKind, type BuiltinObjects, type conform, type equals, type leftIfEqual, type Primitive, type propValueOf, type show } from "@ark/util";
3
+ import type { type } from "./ark.js";
4
+ import type { inferPipe } from "./intersect.js";
5
+ import type { platformObjectExports } from "./keywords/platformObjects.js";
6
+ import type { typedArrayExports } from "./keywords/typedArray.js";
7
+ import type { Type } from "./type.js";
8
+ export declare const inferred: " arkInferred";
9
+ export type inferred = typeof inferred;
10
+ export type Comparator = "<" | "<=" | ">" | ">=" | "==";
11
+ export type RegexLiteral<source extends string = string> = `/${source}/`;
12
+ export type DateLiteral<source extends string = string> = `d"${source}"` | `d'${source}'`;
13
+ export type ConstraintSet = Record<PropertyKey, 1>;
14
+ export type Constraints = Record<string, ConstraintSet>;
15
+ export declare const constrained: " arkConstrained";
16
+ export type constrained = typeof constrained;
17
+ export type constrain<base, constraints extends Constraints> = base & {
18
+ [constrained]: constraints;
19
+ };
20
+ export type LimitLiteral = number | DateLiteral;
21
+ export type normalizeLimit<limit> = limit extends DateLiteral<infer source> ? source : limit extends number | string ? limit : never;
22
+ type constraint<rule> = {
23
+ [k in rule & PropertyKey]: 1;
24
+ };
25
+ export type AtLeast<rule> = {
26
+ atLeast: constraint<rule>;
27
+ };
28
+ export type AtMost<rule> = {
29
+ atMost: constraint<rule>;
30
+ };
31
+ export type MoreThan<rule> = {
32
+ moreThan: constraint<rule>;
33
+ };
34
+ export type LessThan<rule> = {
35
+ lessThan: constraint<rule>;
36
+ };
37
+ export type Literal<rule> = {
38
+ literal: constraint<rule>;
39
+ };
40
+ export type DivisibleBy<rule> = {
41
+ divisibleBy: constraint<rule>;
42
+ };
43
+ export type Length<rule> = {
44
+ length: constraint<rule>;
45
+ };
46
+ export type Matching<rule> = {
47
+ matching: constraint<rule>;
48
+ };
49
+ export type anonymous = "?";
50
+ export type Narrowed = {
51
+ predicate: {
52
+ [k in anonymous]: 1;
53
+ };
54
+ };
55
+ export type primitiveConstraintKindOf<In> = Extract<Constraint.PrimitiveKind, constraintKindOf<In>>;
56
+ export declare namespace number {
57
+ type atLeast<rule> = constrain<number, AtLeast<rule>>;
58
+ type moreThan<rule> = constrain<number, MoreThan<rule>>;
59
+ type atMost<rule> = constrain<number, AtMost<rule>>;
60
+ type lessThan<rule> = constrain<number, LessThan<rule>>;
61
+ type divisibleBy<rule> = constrain<number, DivisibleBy<rule>>;
62
+ type narrowed = constrain<number, Narrowed>;
63
+ type is<constraints extends Constraints> = constrain<number, constraints>;
64
+ type parseConstraint<kind extends Constraint.PrimitiveKind, schema extends NodeSchema<kind>> = normalizePrimitiveConstraintRoot<schema> extends infer rule ? kind extends "min" ? schema extends {
65
+ exclusive: true;
66
+ } ? moreThan<rule> : atLeast<rule> : kind extends "max" ? schema extends {
67
+ exclusive: true;
68
+ } ? lessThan<rule> : atMost<rule> : kind extends "divisor" ? divisibleBy<rule> : narrowed : never;
69
+ }
70
+ export type AtLeastLength<rule> = {
71
+ atLeastLength: constraint<rule>;
72
+ };
73
+ export type AtMostLength<rule> = {
74
+ atMostLength: constraint<rule>;
75
+ };
76
+ export type MoreThanLength<rule> = {
77
+ moreThanLength: constraint<rule>;
78
+ };
79
+ export type LessThanLength<rule> = {
80
+ lessThanLength: constraint<rule>;
81
+ };
82
+ export type ExactlyLength<rule> = {
83
+ atLeastLength: constraint<rule>;
84
+ atMostLength: constraint<rule>;
85
+ };
86
+ export declare namespace string {
87
+ type atLeastLength<rule> = constrain<string, AtLeastLength<rule>>;
88
+ type moreThanLength<rule> = constrain<string, MoreThanLength<rule>>;
89
+ type atMostLength<rule> = constrain<string, AtMostLength<rule>>;
90
+ type lessThanLength<rule> = constrain<string, LessThanLength<rule>>;
91
+ type exactlyLength<rule> = constrain<string, ExactlyLength<rule>>;
92
+ type matching<rule> = constrain<string, Matching<rule>>;
93
+ type narrowed = constrain<string, Narrowed>;
94
+ type is<constraints extends Constraints> = constrain<string, constraints>;
95
+ type parseConstraint<kind extends Constraint.PrimitiveKind, schema extends NodeSchema<kind>> = normalizePrimitiveConstraintRoot<schema> extends infer rule ? kind extends "minLength" ? schema extends {
96
+ exclusive: true;
97
+ } ? moreThanLength<rule> : atLeastLength<rule> : kind extends "maxLength" ? schema extends {
98
+ exclusive: true;
99
+ } ? lessThanLength<rule> : atMostLength<rule> : kind extends "pattern" ? matching<rule & string> : kind extends "exactLength" ? exactlyLength<rule> : narrowed : never;
100
+ }
101
+ export type AtOrAfter<rule> = {
102
+ atOrAfter: constraint<rule>;
103
+ };
104
+ export type AtOrBefore<rule> = {
105
+ atOrBefore: constraint<rule>;
106
+ };
107
+ export type After<rule> = {
108
+ after: constraint<rule>;
109
+ };
110
+ export type Before<rule> = {
111
+ before: constraint<rule>;
112
+ };
113
+ export declare namespace Date {
114
+ type atOrAfter<rule> = constrain<Date, AtOrAfter<rule>>;
115
+ type after<rule> = constrain<Date, After<rule>>;
116
+ type atOrBefore<rule> = constrain<Date, AtOrBefore<rule>>;
117
+ type before<rule> = constrain<Date, Before<rule>>;
118
+ type narrowed = constrain<Date, Narrowed>;
119
+ type literal<rule> = constrain<Date, Literal<rule>>;
120
+ type is<constraints extends Constraints> = constrain<Date, constraints>;
121
+ type parseConstraint<kind extends Constraint.PrimitiveKind, schema extends NodeSchema<kind>> = normalizePrimitiveConstraintRoot<schema> extends infer rule ? kind extends "after" ? schema extends {
122
+ exclusive: true;
123
+ } ? after<normalizeLimit<rule>> : atOrAfter<normalizeLimit<rule>> : kind extends "before" ? schema extends {
124
+ exclusive: true;
125
+ } ? before<normalizeLimit<rule>> : atOrBefore<normalizeLimit<rule>> : narrowed : never;
126
+ }
127
+ export type applyConstraint<t, kind extends Constraint.PrimitiveKind, schema extends NodeSchema<kind>> = t extends MorphAst<infer i, infer o> ? (In: leftIfEqual<i, _applyConstraint<i, kind, schema>>) => o : leftIfEqual<t, _applyConstraint<t, kind, schema>>;
128
+ type _applyConstraint<t, kind extends Constraint.PrimitiveKind, schema extends NodeSchema<kind>> = schemaToConstraint<kind, schema> extends infer constraint ? parseConstraints<t> extends ([
129
+ infer base,
130
+ infer constraints extends Constraints
131
+ ]) ? [
132
+ number,
133
+ base
134
+ ] extends [base, number] ? number.is<constraint & constraints> : [string, base] extends [base, string] ? string.is<constraint & constraints> : [Date, base] extends [base, Date] ? Date.is<constraint & constraints> : constrain<base, constraints & constraint> : [number, t] extends [t, number] ? number.parseConstraint<kind, schema> : [string, t] extends [t, string] ? string.parseConstraint<kind, schema> : [Date, t] extends [t, Date] ? Date.parseConstraint<kind, schema> : constrain<t, conform<constraint, Constraints>> : never;
135
+ export type parseConstraints<t> = t extends constrain<infer base, infer constraints> ? equals<t, number & {
136
+ [constrained]: constraints;
137
+ }> extends true ? [
138
+ number,
139
+ constraints
140
+ ] : equals<t, string & {
141
+ [constrained]: constraints;
142
+ }> extends true ? [
143
+ string,
144
+ constraints
145
+ ] : equals<t, Date & {
146
+ [constrained]: constraints;
147
+ }> extends true ? [
148
+ Date,
149
+ constraints
150
+ ] : [base, constraints] : null;
151
+ export type normalizePrimitiveConstraintRoot<schema extends NodeSchema<Constraint.PrimitiveKind>> = "rule" extends keyof schema ? conform<schema["rule"], PropertyKey> : conform<schema, PropertyKey>;
152
+ export type schemaToConstraint<kind extends Constraint.PrimitiveKind, schema extends NodeSchema<kind>> = normalizePrimitiveConstraintRoot<schema> extends infer rule ? kind extends "pattern" ? Matching<rule> : kind extends "divisor" ? DivisibleBy<rule> : kind extends "exactLength" ? Length<rule> : kind extends "min" ? schema extends {
153
+ exclusive: true;
154
+ } ? MoreThan<rule> : AtLeast<rule> : kind extends "max" ? schema extends {
155
+ exclusive: true;
156
+ } ? LessThan<rule> : AtMost<rule> : kind extends "minLength" ? schema extends {
157
+ exclusive: true;
158
+ } ? MoreThanLength<rule> : AtLeastLength<rule> : kind extends "maxLength" ? schema extends {
159
+ exclusive: true;
160
+ } ? LessThanLength<rule> : AtMostLength<rule> : kind extends "exactLength" ? ExactlyLength<rule> : kind extends "after" ? schema extends {
161
+ exclusive: true;
162
+ } ? After<normalizeLimit<rule>> : AtOrAfter<normalizeLimit<rule>> : kind extends "before" ? schema extends {
163
+ exclusive: true;
164
+ } ? Before<normalizeLimit<rule>> : AtOrBefore<normalizeLimit<rule>> : Narrowed : never;
165
+ export type distillIn<t> = finalizeDistillation<t, _distill<t, "in", "base">>;
166
+ export type distillOut<t> = finalizeDistillation<t, _distill<t, "out", "base">>;
167
+ export type distillConstrainableIn<t> = finalizeDistillation<t, _distill<t, "in", "constrainable">>;
168
+ export type distillConstrainableOut<t> = finalizeDistillation<t, _distill<t, "out", "constrainable">>;
169
+ export type distillValidatedOut<t> = finalizeDistillation<t, _distill<t, "validatedOut", "constrainable">>;
170
+ type finalizeDistillation<t, distilled> = equals<t, distilled> extends true ? t : distilled;
171
+ export type includesMorphs<t> = [
172
+ _distill<t, "in", "constrainable">,
173
+ _distill<t, "out", "constrainable">
174
+ ] extends ([
175
+ _distill<t, "out", "constrainable">,
176
+ _distill<t, "in", "constrainable">
177
+ ]) ? false : true;
178
+ type IoKind = "in" | "out" | "validatedOut";
179
+ type DistilledKind = "base" | "constrainable";
180
+ type _distill<t, io extends IoKind, distilledKind extends DistilledKind> = t extends undefined ? t : [t] extends [anyOrNever] ? t : parseConstraints<t> extends ([
181
+ infer base,
182
+ infer constraints extends Constraints
183
+ ]) ? distilledKind extends "base" ? _distill<base, io, distilledKind> : constrain<_distill<base, io, distilledKind>, constraints> : t extends TerminallyInferredObjectKind | Primitive ? t : unknown extends t ? unknown : t extends MorphAst<infer i, infer o> ? io extends "in" ? _distill<i, io, distilledKind> : io extends "validatedOut" ? o extends To<infer validatedOut> ? _distill<validatedOut, io, distilledKind> : unknown : _distill<o[1], io, distilledKind> : t extends DefaultableAst<infer t> ? _distill<t, io, distilledKind> : t extends array ? distillArray<t, io, distilledKind, []> : t extends Function ? t : {
184
+ [k in keyof t]: t[k];
185
+ } extends t ? io extends "in" ? show<{
186
+ [k in keyof t as k extends defaultableKeyOf<t> ? never : k]: _distill<t[k], io, distilledKind>;
187
+ } & {
188
+ [k in defaultableKeyOf<t>]?: _distill<t[k], io, distilledKind>;
189
+ }> : {
190
+ [k in keyof t]: _distill<t[k], io, distilledKind>;
191
+ } : t;
192
+ export type defaultableKeyOf<t> = {
193
+ [k in keyof t]: [t[k]] extends [anyOrNever] ? never : t[k] extends DefaultableAst ? k : never;
194
+ }[keyof t];
195
+ type distillArray<t extends array, io extends IoKind, constraints extends DistilledKind, prefix extends array> = t extends readonly [infer head, ...infer tail] ? distillArray<tail, io, constraints, [
196
+ ...prefix,
197
+ _distill<head, io, constraints>
198
+ ]> : [...prefix, ...distillPostfix<t, io, constraints>];
199
+ type distillPostfix<t extends array, io extends IoKind, constraints extends DistilledKind, postfix extends array = []> = t extends readonly [...infer init, infer last] ? distillPostfix<init, io, constraints, [
200
+ _distill<last, io, constraints>,
201
+ ...postfix
202
+ ]> : [...{
203
+ [i in keyof t]: _distill<t[i], io, constraints>;
204
+ }, ...postfix];
205
+ /** Objects we don't want to expand during inference like Date or Promise */
206
+ type TerminallyInferredObjectKind = ArkEnv.prototypes | BuiltinObjects[Exclude<BuiltinObjectKind, "Array" | "Function">] | propValueOf<platformObjectExports> | propValueOf<typedArrayExports>;
207
+ export type inferPredicate<t, predicate> = predicate extends (data: any, ...args: any[]) => data is infer narrowed ? t extends constrain<unknown, infer constraints> ? applyConstraint<constrain<narrowed, constraints>, "predicate", any> : applyConstraint<narrowed, "predicate", any> : applyConstraint<t, "predicate", any>;
208
+ export type constrainWithPredicate<t> = t extends constrain<unknown, infer constraints> ? applyConstraint<constrain<t, constraints>, "predicate", any> : applyConstraint<t, "predicate", any>;
209
+ export type inferPipes<t, pipes extends Morph[]> = pipes extends [infer head extends Morph, ...infer tail extends Morph[]] ? inferPipes<pipes[0] extends type.cast<infer tPipe> ? inferPipe<t, tPipe> : inferMorphOut<head> extends infer out ? (In: distillConstrainableIn<t>) => Out<out> : never, tail> : t;
210
+ export type inferMorphOut<morph extends Morph> = Exclude<ReturnType<morph>, ArkError | ArkErrors>;
211
+ export type Out<o = any> = ["=>", o, boolean];
212
+ export type To<o = any> = ["=>", o, true];
213
+ export type MorphAst<i = any, o extends Out = Out> = (In: i) => o;
214
+ export type Default<v = any> = ["=", v];
215
+ export type DefaultableAst<t = any, v = any> = (In?: t) => Default<v>;
216
+ export type termOrType<t> = t | Type<t, any>;
217
+ export {};
package/out/ast.js ADDED
@@ -0,0 +1,3 @@
1
+ import { noSuggest } from "@ark/util";
2
+ export const inferred = noSuggest("arkInferred");
3
+ export const constrained = noSuggest("arkConstrained");
package/out/config.d.ts CHANGED
@@ -1 +1,13 @@
1
+ import type { ArkSchemaRegistry } from "@ark/schema";
2
+ import type { Ark } from "./ark.js";
3
+ import type { exportScope } from "./module.js";
1
4
  export * from "@ark/schema/config";
5
+ export interface ArkTypeRegistryContents extends ArkSchemaRegistry {
6
+ ambient: exportScope<Ark>;
7
+ }
8
+ declare global {
9
+ export interface ArkEnv {
10
+ }
11
+ export namespace ArkEnv {
12
+ }
13
+ }
package/out/generic.d.ts CHANGED
@@ -1,26 +1,100 @@
1
- import type { ConstrainedGenericParamDef, GenericHkt, GenericParamAst, GenericParamDef, GenericProps, GenericRoot, LazyGenericBody } from "@ark/schema";
2
- import { type array, type Callable, type conform, type ErrorMessage, type ErrorType, type WhiteSpaceToken } from "@ark/util";
1
+ import type { arkKind, GenericAst, GenericParamAst, GenericParamDef, genericParamNames, GenericRoot, LazyGenericBody } from "@ark/schema";
2
+ import { type array, type Callable, type conform, type ErrorMessage, type ErrorType, type Hkt, type WhiteSpaceToken } from "@ark/util";
3
3
  import type { inferDefinition } from "./parser/definition.js";
4
4
  import type { inferAstRoot } from "./parser/semantic/infer.js";
5
5
  import type { validateAst } from "./parser/semantic/validate.js";
6
6
  import type { state, StaticState } from "./parser/string/reduce/static.js";
7
7
  import { Scanner } from "./parser/string/shift/scanner.js";
8
8
  import { parseUntilFinalizer } from "./parser/string/string.js";
9
- import type { ParseContext } from "./scope.js";
9
+ import type { ParseContext, Scope } from "./scope.js";
10
10
  import type { inferTypeRoot, Type, validateTypeRoot } from "./type.js";
11
11
  export type ParameterString<params extends string = string> = `<${params}>`;
12
12
  export type extractParams<s extends ParameterString> = s extends ParameterString<infer params> ? params : never;
13
13
  export type validateParameterString<s extends ParameterString, $> = parseGenericParams<extractParams<s>, $> extends infer e extends ErrorMessage ? e : s;
14
- export type validateGenericArg<arg, param extends GenericParamAst, $> = inferTypeRoot<arg, $> extends param[1] ? arg : ErrorType<`Invalid argument for ${param[0]}`, [expected: param[1]]>;
15
- export type GenericInstantiator<params extends array<GenericParamAst>, def, $, args$> = <const args extends {
16
- [i in keyof params]: validateTypeRoot<args[i & keyof args], args$>;
17
- }>(
18
- /** @ts-expect-error treat as array */
19
- ...args: {
20
- [i in keyof args]: validateGenericArg<args[i], params[i & keyof params & `${number}`], args$>;
21
- }) => Type<def extends GenericHkt ? GenericHkt.instantiate<def, {
14
+ type validateGenericArg<arg, param extends GenericParamAst, $> = inferTypeRoot<arg, $> extends param[1] ? arg : ErrorType<`Invalid argument for ${param[0]}`, [expected: param[1]]>;
15
+ export type GenericInstantiator<params extends array<GenericParamAst>, def, $, args$> = params["length"] extends 1 ? {
16
+ <const a, r = instantiateGeneric<def, params, [a], $, args$>>(a: validateTypeRoot<a, args$> & validateGenericArg<a, params[0], args$>): r;
17
+ } : params["length"] extends 2 ? {
18
+ <const a, const b, r = instantiateGeneric<def, params, [a, b], $, args$>>(...args: [validateTypeRoot<a, args$>, validateTypeRoot<b, args$>] & [
19
+ validateGenericArg<a, params[0], args$>,
20
+ validateGenericArg<b, params[1], args$>
21
+ ]): r;
22
+ } : params["length"] extends 3 ? {
23
+ <const a, const b, const c, r = instantiateGeneric<def, params, [a, b, c], $, args$>>(...args: [
24
+ validateTypeRoot<a, args$>,
25
+ validateTypeRoot<b, args$>,
26
+ validateTypeRoot<c, args$>
27
+ ] & [
28
+ validateGenericArg<a, params[0], args$>,
29
+ validateGenericArg<b, params[1], args$>,
30
+ validateGenericArg<c, params[2], args$>
31
+ ]): r;
32
+ } : params["length"] extends 4 ? {
33
+ <const a, const b, const c, const d, r = instantiateGeneric<def, params, [a, b, c, d], $, args$>>(...args: [
34
+ validateTypeRoot<a, args$>,
35
+ validateTypeRoot<b, args$>,
36
+ validateTypeRoot<c, args$>,
37
+ validateTypeRoot<d, args$>
38
+ ] & [
39
+ validateGenericArg<a, params[0], args$>,
40
+ validateGenericArg<b, params[1], args$>,
41
+ validateGenericArg<c, params[2], args$>,
42
+ validateGenericArg<d, params[3], args$>
43
+ ]): r;
44
+ } : params["length"] extends 4 ? {
45
+ <const a, const b, const c, const d, const e, r = instantiateGeneric<def, params, [a, b, c, d, e], $, args$>>(...args: [
46
+ validateTypeRoot<a, args$>,
47
+ validateTypeRoot<b, args$>,
48
+ validateTypeRoot<c, args$>,
49
+ validateTypeRoot<d, args$>,
50
+ validateTypeRoot<e, args$>
51
+ ] & [
52
+ validateGenericArg<a, params[0], args$>,
53
+ validateGenericArg<b, params[1], args$>,
54
+ validateGenericArg<c, params[2], args$>,
55
+ validateGenericArg<d, params[3], args$>,
56
+ validateGenericArg<e, params[4], args$>
57
+ ]): r;
58
+ } : params["length"] extends 5 ? {
59
+ <const a, const b, const c, const d, const e, const f, r = instantiateGeneric<def, params, [a, b, c, d, e, f], $, args$>>(...args: [
60
+ validateTypeRoot<a, args$>,
61
+ validateTypeRoot<b, args$>,
62
+ validateTypeRoot<c, args$>,
63
+ validateTypeRoot<d, args$>,
64
+ validateTypeRoot<e, args$>,
65
+ validateTypeRoot<f, args$>
66
+ ] & [
67
+ validateGenericArg<a, params[0], args$>,
68
+ validateGenericArg<b, params[1], args$>,
69
+ validateGenericArg<c, params[2], args$>,
70
+ validateGenericArg<d, params[3], args$>,
71
+ validateGenericArg<e, params[4], args$>,
72
+ validateGenericArg<f, params[5], args$>
73
+ ]): r;
74
+ } : params["length"] extends 6 ? {
75
+ <const a, const b, const c, const d, const e, const f, const g, r = instantiateGeneric<def, params, [a, b, c, d, e, f, g], $, args$>>(...args: [
76
+ validateTypeRoot<a, args$>,
77
+ validateTypeRoot<b, args$>,
78
+ validateTypeRoot<c, args$>,
79
+ validateTypeRoot<d, args$>,
80
+ validateTypeRoot<e, args$>,
81
+ validateTypeRoot<f, args$>,
82
+ validateTypeRoot<g, args$>
83
+ ] & [
84
+ validateGenericArg<a, params[0], args$>,
85
+ validateGenericArg<b, params[1], args$>,
86
+ validateGenericArg<c, params[2], args$>,
87
+ validateGenericArg<d, params[3], args$>,
88
+ validateGenericArg<e, params[4], args$>,
89
+ validateGenericArg<f, params[5], args$>,
90
+ validateGenericArg<g, params[6], args$>
91
+ ]): r;
92
+ } : (error: ErrorMessage<`You may not define more than 7 positional generic parameters`>) => never;
93
+ type instantiateGeneric<def, params extends array<GenericParamAst>, args, $, args$> = Type<[
94
+ def
95
+ ] extends [Hkt] ? Hkt.apply<def, {
22
96
  [i in keyof args]: inferTypeRoot<args[i], args$>;
23
- }> : inferDefinition<def, $, bindGenericArgs<params, args$, args>>, $>;
97
+ }> : inferDefinition<def, $, bindGenericArgs<params, args$, args>>, args$>;
24
98
  type bindGenericArgs<params extends array<GenericParamAst>, $, args> = {
25
99
  [i in keyof params & `${number}` as params[i][0]]: inferTypeRoot<args[i & keyof args], $>;
26
100
  };
@@ -30,8 +104,20 @@ type baseGenericResolutions<params extends array<GenericParamAst>, $> = baseGene
30
104
  export type baseGenericConstraints<params extends array<GenericParamAst>> = {
31
105
  [i in keyof params & `${number}` as params[i][0]]: params[i][1];
32
106
  };
33
- export interface Generic<params extends array<GenericParamAst> = array<GenericParamAst>, bodyDef = unknown, $ = {}, args$ = $> extends Callable<GenericInstantiator<params, bodyDef, $, args$>>, GenericProps<params, bodyDef, $> {
34
- internal: GenericRoot<params, bodyDef, $>;
107
+ export interface Generic<params extends array<GenericParamAst> = array<GenericParamAst>, bodyDef = unknown, $ = {}, arg$ = $> extends Callable<GenericInstantiator<params, bodyDef, $, arg$>> {
108
+ [arkKind]: "generic";
109
+ t: GenericAst<params, bodyDef, $, arg$>;
110
+ bodyDef: bodyDef;
111
+ params: {
112
+ [i in keyof params]: [params[i][0], Type<params[i][1], $>];
113
+ };
114
+ names: genericParamNames<params>;
115
+ constraints: {
116
+ [i in keyof params]: Type<params[i][1], $>;
117
+ };
118
+ $: Scope<$>;
119
+ arg$: Scope<arg$>;
120
+ internal: GenericRoot;
35
121
  }
36
122
  export type GenericDeclaration<name extends string = string, params extends ParameterString = ParameterString> = `${name}${params}`;
37
123
  export type parseValidGenericParams<def extends ParameterString, $> = conform<parseGenericParams<extractParams<def>, $>, array<GenericParamAst>>;
@@ -61,14 +147,14 @@ type _parseOptionalConstraint<unscanned extends string, name extends string, res
61
147
  ...result,
62
148
  [name, unknown]
63
149
  ], $>;
64
- type genericParamDefToAst<schema extends GenericParamDef, $> = schema extends string ? [schema, unknown] : schema extends ConstrainedGenericParamDef ? [
65
- schema[0],
66
- inferTypeRoot<schema[1], $>
150
+ type genericParamDefToAst<schema extends GenericParamDef, $> = schema extends string ? [schema, unknown] : schema extends readonly [infer name, infer def] ? [
151
+ name,
152
+ inferTypeRoot<def, $>
67
153
  ] : never;
68
- export type genericParamDefsToAst<schemas extends array<GenericParamDef>, $> = [
154
+ export type genericParamDefsToAst<defs extends array<GenericParamDef>, $> = [
69
155
  ...{
70
- [i in keyof schemas]: genericParamDefToAst<schemas[i], $>;
156
+ [i in keyof defs]: genericParamDefToAst<defs[i], $>;
71
157
  }
72
158
  ];
73
- export type GenericHktParser<$ = {}> = <const paramsDef extends array<GenericParamDef>>(...params: paramsDef) => <hkt extends abstract new () => GenericHkt, params extends Array<GenericParamAst> = genericParamDefsToAst<paramsDef, $>>(instantiateDef: LazyGenericBody<baseGenericResolutions<params, $>>, hkt: hkt) => Generic<params, InstanceType<hkt>, $, $>;
159
+ export type GenericHktParser<$ = {}> = <const paramsDef extends array<GenericParamDef>>(...params: paramsDef) => <hkt extends Hkt.constructor, params extends Array<GenericParamAst> = genericParamDefsToAst<paramsDef, $>>(instantiateDef: LazyGenericBody<baseGenericResolutions<params, $>>, hkt: hkt) => Generic<params, InstanceType<hkt>, $, $>;
74
160
  export {};
package/out/index.d.ts CHANGED
@@ -1,7 +1,8 @@
1
- export { ArkError, ArkErrors, GenericHkt } from "@ark/schema";
2
- export type { Ark, ArkConfig, Out, constrained, inferred } from "@ark/schema";
3
- export { ambient, ark, declare, define, generic, match, type } from "./ark.js";
1
+ export { ArkError, ArkErrors } from "@ark/schema";
2
+ export type { ArkConfig, ArkScopeConfig } from "@ark/schema";
3
+ export { Hkt } from "@ark/util";
4
+ export { ambient, ark, declare, define, generic, type } from "./ark.js";
4
5
  export type { Generic } from "./generic.js";
5
- export { Module } from "./module.js";
6
+ export { Module, type Submodule, type BoundModule } from "./module.js";
6
7
  export { scope, type Scope, type inferScope, type validateScope } from "./scope.js";
7
- export { Type, type AnyType, type inferTypeRoot, type validateTypeRoot } from "./type.js";
8
+ export { Type, type inferAmbient, type inferTypeRoot, type validateAmbient, type validateTypeRoot } from "./type.js";
package/out/index.js CHANGED
@@ -1,5 +1,6 @@
1
- export { ArkError, ArkErrors, GenericHkt } from "@ark/schema";
2
- export { ambient, ark, declare, define, generic, match, type } from "./ark.js";
1
+ export { ArkError, ArkErrors } from "@ark/schema";
2
+ export { Hkt } from "@ark/util";
3
+ export { ambient, ark, declare, define, generic, type } from "./ark.js";
3
4
  export { Module } from "./module.js";
4
5
  export { scope } from "./scope.js";
5
6
  export { Type } from "./type.js";
@@ -0,0 +1,28 @@
1
+ import type { anyOrNever, array, Hkt, intersectArrays, show } from "@ark/util";
2
+ import type { constrain, Constraints, MorphAst, parseConstraints, To } from "./ast.js";
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 {};
@@ -0,0 +1 @@
1
+ export {};
package/out/keys.d.ts ADDED
@@ -0,0 +1,16 @@
1
+ import type { array, join, Key, NonNegativeIntegerLiteral, typeToString } from "@ark/util";
2
+ import type { type } from "./ark.js";
3
+ import type { termOrType } from "./ast.js";
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}`;
package/out/keys.js ADDED
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,19 @@
1
+ import * as util from "@ark/util";
2
+ import { Hkt } from "@ark/util";
3
+ import type { Out } from "../ast.js";
4
+ import type { Module } from "../module.js";
5
+ import { type inferScope } from "../scope.js";
6
+ declare class liftArrayHkt extends Hkt<[element: unknown]> {
7
+ body: util.liftArray<this[0]> extends infer lifted ? (In: this[0] | lifted) => Out<lifted> : never;
8
+ }
9
+ declare class mergeHkt extends Hkt<[base: object, props: object]> {
10
+ body: util.merge<this[0], this[1]>;
11
+ }
12
+ declare const arkGenericsExports: {
13
+ liftArray: import("@ark/schema").GenericRoot<readonly [["element", unknown]], liftArrayHkt>;
14
+ merge: import("@ark/schema").GenericRoot<readonly [["base", object], ["props", object]], mergeHkt>;
15
+ };
16
+ export type arkGenericsExports = inferScope<typeof arkGenericsExports>;
17
+ export type arkGenerics = Module<arkGenericsExports>;
18
+ export declare const arkGenerics: arkGenerics;
19
+ export {};
@@ -0,0 +1,19 @@
1
+ import { genericNode } from "@ark/schema";
2
+ import * as util from "@ark/util";
3
+ import { Hkt } from "@ark/util";
4
+ import { scope } from "../scope.js";
5
+ import { tsKeywords } from "./tsKeywords.js";
6
+ class liftArrayHkt extends Hkt {
7
+ }
8
+ const liftArray = genericNode("element")(args => args.element.or(args.element.array()).pipe(util.liftArray), liftArrayHkt);
9
+ class mergeHkt extends Hkt {
10
+ }
11
+ const merge = genericNode(["base", tsKeywords.object], ["props", tsKeywords.object])(args => args.base.merge(args.props), mergeHkt);
12
+ const arkGenericsExports = {
13
+ liftArray,
14
+ merge
15
+ };
16
+ const $ = scope(arkGenericsExports, {
17
+ prereducedAliases: true
18
+ });
19
+ export const arkGenerics = $.export();
@@ -0,0 +1,11 @@
1
+ import type { Out } from "../ast.js";
2
+ import type { Module } from "../module.js";
3
+ export type formattingExports = {
4
+ trim: (In: string) => Out<string>;
5
+ uppercase: (In: string) => Out<string>;
6
+ lowercase: (In: string) => Out<string>;
7
+ capitalize: (In: string) => Out<string>;
8
+ normalize: (In: string) => Out<string>;
9
+ };
10
+ export type formatting = Module<formattingExports>;
11
+ export declare const formatting: formatting;
@@ -0,0 +1,31 @@
1
+ import { rootNode } from "@ark/schema";
2
+ import { scope } from "../scope.js";
3
+ const trim = rootNode({
4
+ in: "string",
5
+ morphs: (s) => s.trim()
6
+ });
7
+ const uppercase = rootNode({
8
+ in: "string",
9
+ morphs: (s) => s.toUpperCase()
10
+ });
11
+ const lowercase = rootNode({
12
+ in: "string",
13
+ morphs: (s) => s.toLowerCase()
14
+ });
15
+ const capitalize = rootNode({
16
+ in: "string",
17
+ morphs: (s) => s.charAt(0).toUpperCase() + s.slice(1)
18
+ });
19
+ const normalize = rootNode({
20
+ in: "string",
21
+ morphs: (s) => s.normalize()
22
+ });
23
+ export const formatting = scope({
24
+ trim,
25
+ uppercase,
26
+ lowercase,
27
+ capitalize,
28
+ normalize
29
+ }, {
30
+ prereducedAliases: true
31
+ }).export();
@@ -0,0 +1,11 @@
1
+ import type { array, Digit, Key } from "@ark/util";
2
+ import type { Module } from "../module.js";
3
+ import "./tsKeywords.js";
4
+ export type NonNegativeIntegerString = `${Digit}` | (`${Exclude<Digit, 0>}${string}` & `${bigint}`);
5
+ export interface internalExports {
6
+ lengthBoundable: string | array;
7
+ key: Key;
8
+ nonNegativeIntegerString: NonNegativeIntegerString;
9
+ }
10
+ export type internal = Module<internalExports>;
11
+ export declare const internal: internal;