arktype 2.0.0-rc.26 → 2.0.0-rc.28

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 (99) hide show
  1. package/out/attributes.d.ts +61 -241
  2. package/out/attributes.js +2 -1
  3. package/out/generic.d.ts +4 -4
  4. package/out/keywords/{constructors/Array.d.ts → Array.d.ts} +2 -2
  5. package/out/keywords/{constructors/Array.js → Array.js} +1 -1
  6. package/out/keywords/{constructors/FormData.d.ts → FormData.d.ts} +2 -2
  7. package/out/keywords/{constructors/FormData.js → FormData.js} +1 -1
  8. package/out/keywords/{constructors/TypedArray.d.ts → TypedArray.d.ts} +1 -1
  9. package/out/keywords/{constructors/TypedArray.js → TypedArray.js} +1 -1
  10. package/out/keywords/{constructors/constructors.d.ts → constructors.d.ts} +1 -1
  11. package/out/keywords/{constructors/constructors.js → constructors.js} +1 -1
  12. package/out/keywords/keywords.d.ts +6 -9
  13. package/out/keywords/keywords.js +3 -3
  14. package/out/keywords/number.d.ts +23 -0
  15. package/out/keywords/{number/epoch.js → number.js} +23 -1
  16. package/out/keywords/string.d.ts +327 -0
  17. package/out/keywords/string.js +398 -0
  18. package/out/methods/array.d.ts +6 -7
  19. package/out/methods/base.d.ts +10 -14
  20. package/out/methods/date.d.ts +5 -6
  21. package/out/methods/number.d.ts +6 -7
  22. package/out/methods/object.d.ts +5 -5
  23. package/out/methods/string.d.ts +7 -8
  24. package/out/parser/ast/generic.d.ts +17 -0
  25. package/out/parser/ast/infer.d.ts +4 -18
  26. package/out/parser/ast/validate.d.ts +10 -6
  27. package/out/parser/ast/validate.js +2 -0
  28. package/out/parser/definition.d.ts +17 -8
  29. package/out/parser/definition.js +20 -2
  30. package/out/parser/objectLiteral.d.ts +39 -39
  31. package/out/parser/objectLiteral.js +75 -49
  32. package/out/parser/property.d.ts +37 -0
  33. package/out/parser/property.js +16 -0
  34. package/out/parser/reduce/dynamic.d.ts +1 -1
  35. package/out/parser/shift/operand/enclosed.d.ts +1 -3
  36. package/out/parser/shift/operand/unenclosed.d.ts +2 -1
  37. package/out/parser/shift/operator/default.d.ts +2 -1
  38. package/out/parser/shift/operator/default.js +1 -1
  39. package/out/parser/string.d.ts +5 -4
  40. package/out/parser/string.js +18 -1
  41. package/out/parser/tupleExpressions.d.ts +47 -0
  42. package/out/parser/tupleExpressions.js +67 -0
  43. package/out/parser/tupleLiteral.d.ts +80 -0
  44. package/out/parser/tupleLiteral.js +119 -0
  45. package/out/scope.d.ts +8 -7
  46. package/out/scope.js +12 -32
  47. package/out/type.d.ts +5 -5
  48. package/package.json +3 -3
  49. package/out/keywords/constructors/Date.d.ts +0 -37
  50. package/out/keywords/number/epoch.d.ts +0 -10
  51. package/out/keywords/number/integer.d.ts +0 -3
  52. package/out/keywords/number/integer.js +0 -5
  53. package/out/keywords/number/number.d.ts +0 -58
  54. package/out/keywords/number/number.js +0 -21
  55. package/out/keywords/string/alpha.d.ts +0 -7
  56. package/out/keywords/string/alpha.js +0 -2
  57. package/out/keywords/string/alphanumeric.d.ts +0 -7
  58. package/out/keywords/string/alphanumeric.js +0 -2
  59. package/out/keywords/string/base64.d.ts +0 -21
  60. package/out/keywords/string/base64.js +0 -6
  61. package/out/keywords/string/capitalize.d.ts +0 -15
  62. package/out/keywords/string/capitalize.js +0 -12
  63. package/out/keywords/string/creditCard.d.ts +0 -8
  64. package/out/keywords/string/creditCard.js +0 -37
  65. package/out/keywords/string/date.d.ts +0 -55
  66. package/out/keywords/string/date.js +0 -98
  67. package/out/keywords/string/digits.d.ts +0 -7
  68. package/out/keywords/string/digits.js +0 -2
  69. package/out/keywords/string/email.d.ts +0 -7
  70. package/out/keywords/string/email.js +0 -4
  71. package/out/keywords/string/integer.d.ts +0 -16
  72. package/out/keywords/string/integer.js +0 -16
  73. package/out/keywords/string/ip.d.ts +0 -20
  74. package/out/keywords/string/ip.js +0 -23
  75. package/out/keywords/string/json.d.ts +0 -16
  76. package/out/keywords/string/json.js +0 -54
  77. package/out/keywords/string/lower.d.ts +0 -15
  78. package/out/keywords/string/lower.js +0 -12
  79. package/out/keywords/string/normalize.d.ts +0 -88
  80. package/out/keywords/string/normalize.js +0 -43
  81. package/out/keywords/string/numeric.d.ts +0 -15
  82. package/out/keywords/string/numeric.js +0 -13
  83. package/out/keywords/string/semver.d.ts +0 -7
  84. package/out/keywords/string/semver.js +0 -4
  85. package/out/keywords/string/string.d.ts +0 -135
  86. package/out/keywords/string/string.js +0 -43
  87. package/out/keywords/string/trim.d.ts +0 -15
  88. package/out/keywords/string/trim.js +0 -14
  89. package/out/keywords/string/upper.d.ts +0 -15
  90. package/out/keywords/string/upper.js +0 -12
  91. package/out/keywords/string/url.d.ts +0 -15
  92. package/out/keywords/string/url.js +0 -37
  93. package/out/keywords/string/utils.d.ts +0 -2
  94. package/out/keywords/string/utils.js +0 -10
  95. package/out/keywords/string/uuid.d.ts +0 -42
  96. package/out/keywords/string/uuid.js +0 -19
  97. package/out/parser/tuple.d.ts +0 -148
  98. package/out/parser/tuple.js +0 -164
  99. /package/out/{keywords/constructors/Date.js → parser/ast/generic.js} +0 -0
@@ -1,268 +1,88 @@
1
- import type { ArkError, ArkErrors, Constraint, constraintKindOf, Morph, NodeSchema } from "@ark/schema";
2
- import { type anyOrNever, type array, type conform, type equals, type Hkt, type intersectArrays, type isSafelyMappable, type leftIfEqual, type Primitive, type show } from "@ark/util";
3
- import type { arkPrototypes } from "./keywords/constructors/constructors.ts";
4
- import type { Date } from "./keywords/constructors/Date.ts";
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";
5
4
  import type { type } from "./keywords/keywords.ts";
6
- import type { number } from "./keywords/number/number.ts";
7
- import type { Matching, string } from "./keywords/string/string.ts";
8
5
  import type { Type } from "./type.ts";
9
- export type { arkPrototypes as object } from "./keywords/constructors/constructors.ts";
10
- export type { number } from "./keywords/number/number.ts";
11
- export type { string } from "./keywords/string/string.ts";
6
+ export type { arkPrototypes as object } from "./keywords/constructors.ts";
12
7
  export type Comparator = "<" | "<=" | ">" | ">=" | "==";
13
8
  export type RegexLiteral<source extends string = string> = `/${source}/`;
14
9
  export type DateLiteral<source extends string = string> = `d"${source}"` | `d'${source}'`;
15
- export declare const attributesKey: " attributes";
16
- export type attributesKey = typeof attributesKey;
17
- export type of<base, attributes extends Attributes> = base & {
18
- [attributesKey]: {
19
- base: base;
20
- attributes: attributes;
21
- };
22
- };
23
- export type brand<base, attributes extends Attributes> = base & {
24
- [attributesKey]: {
25
- base: base;
26
- attributes: attributes;
27
- brand: true;
28
- };
29
- };
30
- export interface ConstrainingAttributeValuesByKind {
31
- divisibleBy: number;
32
- moreThan: number;
33
- atLeast: number;
34
- atMost: number;
35
- lessThan: number;
36
- matching: string;
37
- moreThanLength: number;
38
- atLeastLength: number;
39
- atMostLength: number;
40
- lessThanLength: number;
41
- atOrAfter: string;
42
- after: string;
43
- atOrBefore: string;
44
- before: string;
45
- nominal: string;
46
- }
47
- export type ConstrainingAttributeKind = keyof ConstrainingAttributeValuesByKind;
48
- export type ConstrainingAttributesByKind = {
49
- [k in ConstrainingAttributeKind]?: Record<ConstrainingAttributeValuesByKind[k], true>;
50
- };
51
- export interface MetaAttributeValuesByKind extends Optional, Default {
52
- }
53
- export type MetaAttributeKind = keyof MetaAttributeValuesByKind;
54
- export type MetaAttributesByKind = Partial<MetaAttributeValuesByKind>;
55
- export interface Attributes extends ConstrainingAttributesByKind, MetaAttributesByKind {
56
- }
57
- export type AttributeKind = keyof Attributes;
58
10
  export type LimitLiteral = number | DateLiteral;
59
11
  export type normalizeLimit<limit> = limit extends DateLiteral<infer source> ? source : limit extends number | string ? limit : never;
60
- export type constraint<rule> = {
61
- [k in rule & PropertyKey]: true;
62
- };
63
- export type Anonymous = Nominal<"?">;
64
- export type Nominal<name> = {
65
- nominal: constraint<name>;
66
- };
67
- export type AtLeast<rule> = {
68
- atLeast: constraint<rule>;
69
- };
70
- export type AtMost<rule> = {
71
- atMost: constraint<rule>;
72
- };
73
- export type MoreThan<rule> = {
74
- moreThan: constraint<rule>;
75
- };
76
- export type LessThan<rule> = {
77
- lessThan: constraint<rule>;
78
- };
79
- export type DivisibleBy<rule> = {
80
- divisibleBy: constraint<rule>;
81
- };
82
- export type AtOrAfter<rule> = {
83
- atOrAfter: constraint<rule>;
84
- };
85
- export type AtOrBefore<rule> = {
86
- atOrBefore: constraint<rule>;
87
- };
88
- export type After<rule> = {
89
- after: constraint<rule>;
90
- };
91
- export type Before<rule> = {
92
- before: constraint<rule>;
93
- };
94
- export type primitiveConstraintKindOf<In> = Extract<Constraint.PrimitiveKind, constraintKindOf<In>>;
95
- export type AtLeastLength<rule> = {
96
- atLeastLength: constraint<rule>;
97
- };
98
- export type AtMostLength<rule> = {
99
- atMostLength: constraint<rule>;
100
- };
101
- export type MoreThanLength<rule> = {
102
- moreThanLength: constraint<rule>;
103
- };
104
- export type LessThanLength<rule> = {
105
- lessThanLength: constraint<rule>;
106
- };
107
- export type ExactlyLength<rule> = {
108
- atLeastLength: constraint<rule>;
109
- atMostLength: constraint<rule>;
110
- };
111
- export type AttributeInferenceBehavior = "brand" | "associate";
112
- export type associateAttributes<t, attributes extends Attributes> = attachAttributes<t, attributes, "associate">;
113
- export type brandAttributes<t, attributes extends Attributes> = attachAttributes<t, attributes, "brand">;
114
- type attachAttributes<t, attributes extends Attributes, behavior extends AttributeInferenceBehavior = "associate", unmorphedT = Exclude<t, InferredMorph>> = t extends InferredMorph<infer i, infer o> ? (In: leftIfEqual<i, _attachAttributes<i, attributes, behavior>>) => o : leftIfEqual<unmorphedT, _attachAttributes<unmorphedT, attributes, behavior>>;
115
- type _attachAttributes<t, attributes extends Attributes, behavior extends AttributeInferenceBehavior, distributed = t> = distributed extends null | undefined ? distributed : distributed extends of<infer base, infer existingAttributes> ? "brand" extends keyof distributed[attributesKey] | behavior ? brandMultiple<base, existingAttributes & attributes> : associateMultiple<base, existingAttributes & attributes> : extractIfSingleAttributeEntry<attributes> extends (AttributeEntry<infer kind, infer value>) ? "brand" extends behavior ? brandSingle<t, attributes, kind, value> : associateSingle<t, attributes, kind, value> : "brand" extends behavior ? brandMultiple<t, attributes> : associateMultiple<t, attributes>;
116
- type associateMultiple<t, attributes extends Attributes> = [
117
- t,
118
- string
119
- ] extends [string, t] ? string.is<attributes> : [t, number] extends [number, t] ? number.is<attributes> : [t, Date] extends [Date, t] ? Date.is<attributes> : of<t, attributes>;
120
- type brandMultiple<t, attributes extends Attributes> = [
121
- t,
122
- string
123
- ] extends [string, t] ? string.branded.is<attributes> : [t, number] extends [number, t] ? number.branded.is<attributes> : [t, Date] extends [Date, t] ? Date.branded.is<attributes> : brand<t, attributes>;
124
- type associateSingle<t, attributes extends Attributes, kind extends AttributeKind, value> = [
125
- t,
126
- string
127
- ] extends [string, t] ? string.raw.withSingleAttribute<kind, value> : [t, number] extends [number, t] ? number.raw.withSingleAttribute<kind, value> : [t, Date] extends [Date, t] ? Date.raw.withSingleAttribute<kind, value> : of<t, attributes>;
128
- type brandSingle<t, attributes extends Attributes, kind extends AttributeKind, value> = [
129
- t,
130
- string
131
- ] extends [string, t] ? string.branded.raw.withSingleAttribute<kind, value> : [t, number] extends [number, t] ? number.branded.raw.withSingleAttribute<kind, value> : [t, Date] extends [Date, t] ? Date.branded.raw.withSingleAttribute<kind, value> : brand<t, attributes>;
132
- type AttributeEntry<kind extends AttributeKind, value> = [kind, value];
133
- /**
134
- * Check if attributes is a single attribute kind + value that can be collapsed
135
- * for display purposes, e.g.:
136
- *
137
- * // has multiple attribute kinds
138
- * { divisibleBy: { 2: true }, moreThan: { 3: true } } => null
139
- *
140
- * // has multiple attribute values of a single kind
141
- * { divisibleBy: { 2: true, 3: true } } => null
142
- *
143
- * // has a single attribute kind + value, can be collapsed
144
- * { divisibleBy: { 2: true } } => ["divisibleBy", 2]
145
- */
146
- type extractIfSingleAttributeEntry<attributes extends Attributes> = extractIfSingleEntry<attributes> extends (AttributeEntry<infer kind, infer attributesValue>) ? extractIfSingleEntry<attributesValue> extends [infer key, infer value] ? AttributeEntry<kind, kind extends MetaAttributeKind ? value : key> : null : null;
147
- type extractIfSingleEntry<o> = {
148
- [k in keyof o]: keyof o extends k ? [key: k, value: o[k]] : null;
149
- }[keyof o];
150
- export interface LengthAttributeValuesByKind {
151
- moreThanLength: number;
152
- atLeastLength: number;
153
- atMostLength: number;
154
- lessThanLength: number;
155
- }
156
- export type LengthAttributeKind = keyof LengthAttributeValuesByKind;
157
- export type normalizePrimitiveConstraintRoot<schema extends NodeSchema<Constraint.PrimitiveKind>> = "rule" extends keyof schema ? conform<schema["rule"], PropertyKey> : conform<schema, PropertyKey>;
158
- type minLengthSchemaToConstraint<schema, rule> = schema extends {
159
- exclusive: true;
160
- } ? MoreThanLength<rule> : AtLeastLength<rule>;
161
- type maxLengthSchemaToConstraint<schema, rule> = schema extends {
162
- exclusive: true;
163
- } ? LessThanLength<rule> : AtMostLength<rule>;
164
- export type associateAttributesFromSchema<t, kind extends Constraint.PrimitiveKind, schema extends NodeSchema<kind>> = associateAttributes<t, schemaToAttributes<kind, schema>>;
165
- export type associateAttributesFromStringSchema<t extends string, kind extends Constraint.PrimitiveKind, schema extends NodeSchema<kind>> = conform<associateAttributes<t, schemaToAttributes<kind, schema>>, string>;
166
- export type associateAttributesFromNumberSchema<t extends number, kind extends Constraint.PrimitiveKind, schema extends NodeSchema<kind>> = conform<associateAttributes<t, schemaToAttributes<kind, schema>>, number>;
167
- export type associateAttributesFromDateSchema<t extends Date, kind extends Constraint.PrimitiveKind, schema extends NodeSchema<kind>> = conform<associateAttributes<t, schemaToAttributes<kind, schema>>, Date>;
168
- export type associateAttributesFromArraySchema<t extends readonly unknown[], kind extends Constraint.PrimitiveKind, schema extends NodeSchema<kind>> = conform<associateAttributes<t, schemaToAttributes<kind, schema>>, readonly unknown[]>;
169
- export type schemaToAttributes<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 "min" ? number.minSchemaToConstraint<schema, rule> : kind extends "max" ? number.maxSchemaToConstraint<schema, rule> : kind extends "minLength" ? minLengthSchemaToConstraint<schema, rule> : kind extends "maxLength" ? maxLengthSchemaToConstraint<schema, rule> : kind extends "exactLength" ? ExactlyLength<rule> : kind extends "after" ? Date.afterSchemaToConstraint<schema, rule> : kind extends "before" ? Date.beforeSchemaToConstraint<schema, rule> : Anonymous : never;
170
- export type distill<t, opts extends distill.Options = {}> = finalizeDistillation<t, _distill<t, opts>>;
12
+ export type distill<t, endpoint extends distill.Endpoint> = finalizeDistillation<t, _distill<t, endpoint, never>>;
171
13
  export declare namespace distill {
172
14
  type Endpoint = "in" | "out" | "out.introspectable";
173
- type Options = {
174
- endpoint?: Endpoint;
175
- attributes?: "preserve" | "brand" | "unbrand";
176
- };
177
- type In<t> = distill<t, {
178
- endpoint: "in";
179
- }>;
180
- type Out<t> = distill<t, {
181
- endpoint: "out";
182
- }>;
183
- namespace withAttributes {
184
- type In<t> = distill<t, {
185
- endpoint: "in";
186
- attributes: "preserve";
187
- }>;
188
- type Out<t> = distill<t, {
189
- endpoint: "out";
190
- attributes: "preserve";
191
- }>;
192
- namespace introspectable {
193
- type Out<t> = distill<t, {
194
- endpoint: "out.introspectable";
195
- attributes: "preserve";
196
- }>;
197
- }
198
- }
199
- type brand<t> = distill<t, {
200
- attributes: "brand";
201
- }>;
202
- type unbrand<t> = distill<t, {
203
- attributes: "unbrand";
204
- }>;
15
+ type In<t> = distill<t, "in">;
16
+ type Out<t> = distill<t, "out">;
205
17
  namespace introspectable {
206
- type Out<t> = distill<t, {
207
- endpoint: "out.introspectable";
208
- }>;
18
+ type Out<t> = distill<t, "out.introspectable">;
209
19
  }
210
20
  }
211
21
  type finalizeDistillation<t, distilled> = equals<t, distilled> extends true ? t : distilled;
212
- type _distill<t, opts extends distill.Options> = t extends undefined ? t : [t] extends [anyOrNever] ? t : t extends of<infer base, infer attributes> ? opts["attributes"] extends "preserve" ? associateAttributes<_distill<base, opts>, attributes> : opts["attributes"] extends "unbrand" ? associateAttributes<_distill<base, opts>, attributes> : opts["attributes"] extends "brand" ? brand<_distill<base, opts>, attributes> : "brand" extends keyof t[attributesKey] ? brand<_distill<base, opts>, attributes> : _distill<base, opts> : unknown extends t ? unknown : t extends TerminallyInferredObject | Primitive ? t : t extends InferredMorph<infer i, infer o> ? distillIo<i, o, opts> : t extends array ? distillArray<t, opts> : t extends Function ? t : isSafelyMappable<t> extends true ? distillMappable<t, opts> : t;
213
- type distillMappable<o, opts extends distill.Options> = opts["endpoint"] extends "in" ? show<{
214
- [k in keyof o as k extends inferredOptionalOrDefaultKeyOf<o> ? never : k]: _distill<o[k], opts>;
215
- } & {
216
- [k in inferredOptionalOrDefaultKeyOf<o>]?: _distill<o[k], opts>;
217
- }> : show<{
218
- [k in keyof o as k extends inferredOptionalKeyOf<o> ? never : k]: _distill<o[k], opts>;
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>;
219
25
  } & {
220
- [k in keyof o as k extends inferredOptionalKeyOf<o> ? k : never]?: _distill<o[k], opts>;
221
- }>;
222
- type distillIo<i, o extends Out, opts extends distill.Options> = opts["endpoint"] extends "in" ? _distill<i, opts> : opts["endpoint"] extends "out.introspectable" ? o extends To<infer validatedOut> ? _distill<validatedOut, opts> : unknown : opts["endpoint"] extends "out" ? _distill<o[1], opts> : _distill<o[1], opts> extends infer r ? o extends To ? (In: i) => To<r> : (In: i) => Out<r> : never;
223
- export type inferredOptionalOrDefaultKeyOf<o> = inferredDefaultKeyOf<o> | inferredOptionalKeyOf<o>;
224
- type inExtends<v, t> = [
225
- v
226
- ] extends [anyOrNever] ? false : [v] extends [t] ? true : [v] extends [InferredMorph<infer i>] ? inExtends<i, t> : false;
227
- type inferredDefaultKeyOf<o> = keyof o extends infer k ? k extends keyof o ? inExtends<o[k], InferredDefault> extends true ? k : never : never : never;
228
- type inferredOptionalKeyOf<o> = keyof o extends infer k ? k extends keyof o ? inExtends<o[k], InferredOptional> extends true ? k : never : never : never;
229
- type distillArray<t extends array, opts extends distill.Options> = t[number][] extends t ? alignReadonly<_distill<t[number], opts>[], t> : distillNonArraykeys<t, alignReadonly<_distillArray<[...t], opts, []>, t>, opts>;
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>;
230
36
  type alignReadonly<result extends unknown[], original extends array> = original extends unknown[] ? result : Readonly<result>;
231
- type distillNonArraykeys<originalArray extends array, distilledArray, opts extends distill.Options> = keyof originalArray extends keyof distilledArray | attributesKey ? distilledArray : distilledArray & _distill<{
232
- [k in keyof originalArray as k extends (keyof distilledArray | (opts["attributes"] extends true ? never : attributesKey)) ? never : k]: originalArray[k];
233
- }, opts>;
234
- type _distillArray<t extends array, opts extends distill.Options, prefix extends array> = t extends readonly [infer head, ...infer tail] ? _distillArray<tail, opts, [...prefix, _distill<head, opts>]> : [...prefix, ...distillPostfix<t, opts>];
235
- type distillPostfix<t extends array, opts extends distill.Options, postfix extends array = []> = t extends readonly [...infer init, infer last] ? distillPostfix<init, opts, [_distill<last, opts>, ...postfix]> : [...{
236
- [i in keyof t]: _distill<t[i], opts>;
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>;
237
49
  }, ...postfix];
238
50
  type BuiltinTerminalObjectKind = Exclude<keyof arkPrototypes.instances, "Array" | "Function">;
239
51
  /** Objects we don't want to expand during inference like Date or Promise */
240
52
  type TerminallyInferredObject = arkPrototypes.instanceOf<BuiltinTerminalObjectKind> | ArkEnv.prototypes;
241
- export type inferPredicate<t, predicate> = predicate extends (data: any, ...args: any[]) => data is infer narrowed ? t extends of<unknown, infer constraints> ? "brand" extends keyof t[attributesKey] ? brand<narrowed, constraints> : of<narrowed, constraints> : narrowed : associateAttributes<t, Anonymous>;
242
- 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: distill.withAttributes.In<t>) => Out<out> : never, tail> : t;
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;
243
55
  export type inferMorphOut<morph extends Morph> = Exclude<ReturnType<morph>, ArkError | ArkErrors>;
244
- export type Out<o = any> = ["=>", o, boolean];
245
- export type To<o = any> = ["=>", o, true];
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
+ }
246
65
  export type InferredMorph<i = any, o extends Out = Out> = (In: i) => o;
247
- export type Optional = {
248
- optional: {
249
- "=": true;
250
- };
251
- };
252
- export type InferredOptional<t = unknown> = of<t, Optional>;
253
- export type Default<v = any> = {
254
- defaultsTo: {
255
- value: v;
256
- };
257
- };
258
- export type DefaultFor<t> = (Primitive extends t ? Primitive : t extends Primitive ? t : never) | (() => t);
259
- export type InferredDefault<t = unknown, v = any> = of<t, Default<v>>;
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);
260
80
  export type termOrType<t> = t | Type<t, any>;
261
- export type inferIntersection<l, r> = _inferIntersection<l, r, false>;
262
- export type inferPipe<l, r> = _inferIntersection<l, r, true>;
81
+ export type inferIntersection<l, r> = normalizeMorphDistribution<_inferIntersection<l, r, false>>;
82
+ export type inferPipe<l, r> = normalizeMorphDistribution<_inferIntersection<l, r, true>>;
263
83
  type _inferIntersection<l, r, piped extends boolean> = [
264
84
  l & r
265
- ] 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 extends of<infer lBase, infer lAttributes> ? r extends of<infer rBase, infer rAttributes> ? of<_inferIntersection<lBase, rBase, piped>, lAttributes & rAttributes> : of<_inferIntersection<lBase, r, piped>, lAttributes> : r extends of<infer rBase, infer rAttributes> ? of<_inferIntersection<rBase, l, piped>, rAttributes> : [l, r] extends [object, object] ? intersectObjects<l, r, piped> extends infer result ? result : never : 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;
266
86
  interface MorphableIntersection<piped extends boolean> extends Hkt<[unknown, unknown]> {
267
87
  body: _inferIntersection<this[0], this[1], piped>;
268
88
  }
package/out/attributes.js CHANGED
@@ -1,2 +1,3 @@
1
1
  import { noSuggest } from "@ark/util";
2
- export const attributesKey = noSuggest("attributes");
2
+ const isMorphOutKey = noSuggest("isMorphOut");
3
+ const defaultsToKey = noSuggest("defaultsTo");
package/out/generic.d.ts CHANGED
@@ -1,9 +1,9 @@
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 WhitespaceChar } from "@ark/util";
2
+ import { type array, type Callable, type conform, type ErrorMessage, type ErrorType, type Hkt, type JsonStructure, type WhitespaceChar } from "@ark/util";
3
3
  import type { type } from "./keywords/keywords.ts";
4
4
  import type { inferAstRoot } from "./parser/ast/infer.ts";
5
5
  import type { validateAst } from "./parser/ast/validate.ts";
6
- import type { inferDefinition, validateDefinition } from "./parser/definition.ts";
6
+ import type { inferDefinition } from "./parser/definition.ts";
7
7
  import type { state, StaticState } from "./parser/reduce/static.ts";
8
8
  import type { ArkTypeScanner } from "./parser/shift/scanner.ts";
9
9
  import { parseUntilFinalizer } from "./parser/string.ts";
@@ -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;
@@ -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 {};
@@ -1,6 +1,6 @@
1
1
  import { Hkt, liftArray, type Digit } from "@ark/util";
2
- import type { To } from "../../attributes.ts";
3
- import type { Module, Submodule } from "../../module.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 { arkModule } from "./utils.js";
4
4
  class liftFromHkt extends Hkt {
5
5
  }
6
6
  const liftFrom = genericNode("element")(args => {
@@ -1,5 +1,5 @@
1
- import type { To } from "../../attributes.ts";
2
- import type { Module, Submodule } from "../../module.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 { arkModule } from "./utils.js";
4
4
  const value = rootSchema(["string", registry.FileConstructor]);
5
5
  const parsedFormDataValue = value.rawOr(value.array());
6
6
  const parsed = rootSchema({
@@ -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,4 +1,4 @@
1
- import { arkModule } from "../utils.js";
1
+ import { arkModule } from "./utils.js";
2
2
  export const TypedArray = arkModule({
3
3
  Int8: ["instanceof", Int8Array],
4
4
  Uint8: ["instanceof", Uint8Array],
@@ -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,8 +1,8 @@
1
1
  import { ecmascriptConstructors, flatMorph, platformConstructors } from "@ark/util";
2
- import { arkModule } from "../utils.js";
3
2
  import { arkArray } from "./Array.js";
4
3
  import { arkFormData } from "./FormData.js";
5
4
  import { TypedArray } from "./TypedArray.js";
5
+ import { arkModule } from "./utils.js";
6
6
  const omittedPrototypes = {
7
7
  Boolean: 1,
8
8
  Number: 1,
@@ -1,6 +1,6 @@
1
1
  import type { ArkErrors, arkKind } from "@ark/schema";
2
- import type { inferred } from "@ark/util";
3
- import type { distill } from "../attributes.ts";
2
+ import type { Brand, inferred } from "@ark/util";
3
+ import type { distill, InferredMorph, Out, To } from "../attributes.ts";
4
4
  import type { GenericParser } from "../generic.ts";
5
5
  import type { BaseType } from "../methods/base.ts";
6
6
  import type { BoundModule, Module } from "../module.ts";
@@ -8,9 +8,9 @@ import type { inferDefinition, validateDefinition } from "../parser/definition.t
8
8
  import { type bindThis, type Scope } from "../scope.ts";
9
9
  import type { DeclarationParser, DefinitionParser, SchemaParser, Type, TypeParser } from "../type.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";
11
+ import { arkPrototypes } from "./constructors.ts";
12
+ import { number } from "./number.ts";
13
+ import { string } from "./string.ts";
14
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
  }
@@ -47,15 +47,12 @@ export declare namespace type {
47
47
  namespace infer {
48
48
  type In<def, $ = {}, args = {}> = distill.In<inferDefinition<def, $, args>>;
49
49
  type Out<def, $ = {}, args = {}> = distill.Out<inferDefinition<def, $, args>>;
50
- namespace withAttributes {
51
- type In<def, $ = {}, args = {}> = distill.withAttributes.In<inferDefinition<def, $, args>>;
52
- type Out<def, $ = {}, args = {}> = distill.withAttributes.Out<inferDefinition<def, $, args>>;
53
- }
54
50
  namespace introspectable {
55
51
  type Out<def, $ = {}, args = {}> = distill.introspectable.Out<inferDefinition<def, $, args>>;
56
52
  }
57
53
  }
58
54
  type validate<def, $ = {}, args = bindThis<def>> = validateDefinition<def, $, args>;
55
+ 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>;
59
56
  }
60
57
  export type type<t = unknown, $ = {}> = Type<t, $>;
61
58
  export declare const generic: GenericParser<{}>;
@@ -1,8 +1,8 @@
1
1
  import { $arkTypeRegistry, scope } from "../scope.js";
2
2
  import { arkBuiltins } from "./builtins.js";
3
- import { arkPrototypes } from "./constructors/constructors.js";
4
- import { number } from "./number/number.js";
5
- import { string } from "./string/string.js";
3
+ import { arkPrototypes } from "./constructors.js";
4
+ import { number } from "./number.js";
5
+ import { string } from "./string.js";
6
6
  import { arkTsGenerics, arkTsKeywords, object, unknown } from "./ts.js";
7
7
  $arkTypeRegistry.typeAttachments = {
8
8
  ...arkTsKeywords,
@@ -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 { arkModule } from "./utils.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,24 @@ 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 = arkModule({
33
+ root: intrinsic.number,
34
+ integer,
35
+ epoch,
36
+ safe: rootSchema({
37
+ domain: "number",
38
+ min: Number.MIN_SAFE_INTEGER,
39
+ max: Number.MAX_SAFE_INTEGER,
40
+ predicate: {
41
+ predicate: n => !Number.isNaN(n),
42
+ meta: "a safe number"
43
+ }
44
+ }),
45
+ NaN: ["===", Number.NaN],
46
+ Infinity: ["===", Number.POSITIVE_INFINITY],
47
+ NegativeInfinity: ["===", Number.NEGATIVE_INFINITY]
48
+ });