arktype 2.0.0-rc.15 → 2.0.0-rc.16

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 (55) hide show
  1. package/out/{keywords/inference.d.ts → attributes.d.ts} +143 -54
  2. package/out/attributes.js +2 -0
  3. package/out/keywords/constructors/Array.d.ts +1 -1
  4. package/out/keywords/constructors/Date.d.ts +23 -18
  5. package/out/keywords/constructors/FormData.d.ts +1 -1
  6. package/out/keywords/keywords.d.ts +4 -4
  7. package/out/keywords/number/epoch.d.ts +2 -1
  8. package/out/keywords/number/number.d.ts +28 -28
  9. package/out/keywords/string/alpha.d.ts +2 -2
  10. package/out/keywords/string/alphanumeric.d.ts +2 -2
  11. package/out/keywords/string/base64.d.ts +3 -3
  12. package/out/keywords/string/capitalize.d.ts +2 -2
  13. package/out/keywords/string/creditCard.d.ts +2 -2
  14. package/out/keywords/string/date.d.ts +4 -4
  15. package/out/keywords/string/digits.d.ts +2 -2
  16. package/out/keywords/string/email.d.ts +2 -2
  17. package/out/keywords/string/integer.d.ts +2 -2
  18. package/out/keywords/string/ip.d.ts +4 -4
  19. package/out/keywords/string/json.d.ts +2 -2
  20. package/out/keywords/string/lower.d.ts +2 -2
  21. package/out/keywords/string/normalize.d.ts +5 -5
  22. package/out/keywords/string/numeric.d.ts +2 -2
  23. package/out/keywords/string/semver.d.ts +2 -2
  24. package/out/keywords/string/string.d.ts +26 -7
  25. package/out/keywords/string/trim.d.ts +2 -2
  26. package/out/keywords/string/upper.d.ts +2 -2
  27. package/out/keywords/string/url.d.ts +2 -2
  28. package/out/keywords/string/uuid.d.ts +10 -10
  29. package/out/keywords/ts.d.ts +1 -1
  30. package/out/methods/array.d.ts +6 -6
  31. package/out/methods/base.d.ts +16 -27
  32. package/out/methods/date.d.ts +5 -5
  33. package/out/methods/instantiate.d.ts +1 -1
  34. package/out/methods/morph.d.ts +1 -1
  35. package/out/methods/number.d.ts +6 -6
  36. package/out/methods/object.d.ts +3 -3
  37. package/out/methods/string.d.ts +7 -7
  38. package/out/parser/ast/bounds.d.ts +1 -1
  39. package/out/parser/ast/infer.d.ts +8 -7
  40. package/out/parser/objectLiteral.d.ts +1 -1
  41. package/out/parser/reduce/dynamic.d.ts +1 -1
  42. package/out/parser/reduce/shared.d.ts +1 -1
  43. package/out/parser/reduce/static.d.ts +1 -1
  44. package/out/parser/shift/operand/date.d.ts +1 -1
  45. package/out/parser/shift/operand/enclosed.d.ts +2 -2
  46. package/out/parser/shift/operator/bounds.d.ts +1 -1
  47. package/out/parser/shift/operator/default.d.ts +1 -1
  48. package/out/parser/tuple.d.ts +4 -4
  49. package/out/scope.d.ts +6 -1
  50. package/out/scope.js +3 -1
  51. package/out/type.d.ts +1 -1
  52. package/package.json +3 -3
  53. package/out/keywords/inference.js +0 -2
  54. package/out/keywords/string/brands.d.ts +0 -17
  55. package/out/keywords/string/brands.js +0 -1
@@ -1,53 +1,95 @@
1
1
  import type { ArkError, ArkErrors, Constraint, constraintKindOf, Morph, NodeSchema } from "@ark/schema";
2
- import { type anyOrNever, type array, type conform, type dict, type equals, type Hkt, type intersectArrays, type isSafelyMappable, type leftIfEqual, type Primitive, type show } from "@ark/util";
3
- import type { Type } from "../type.ts";
4
- import type { arkPrototypes } from "./constructors/constructors.ts";
5
- import type { Date } from "./constructors/Date.ts";
6
- import type { type } from "./keywords.ts";
7
- import type { DivisibleBy, number } from "./number/number.ts";
8
- import type { brandedString, Matching, string } from "./string/string.ts";
9
- export type { arkPrototypes as object } from "./constructors/constructors.ts";
10
- export type { number } from "./number/number.ts";
11
- export type { string } from "./string/string.ts";
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";
5
+ 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
+ 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";
12
12
  export type Comparator = "<" | "<=" | ">" | ">=" | "==";
13
13
  export type RegexLiteral<source extends string = string> = `/${source}/`;
14
14
  export type DateLiteral<source extends string = string> = `d"${source}"` | `d'${source}'`;
15
- export interface BaseAttributes {
16
- predicate?: dict;
17
- default?: unknown;
18
- optional?: true;
19
- }
20
- export declare const ofKey: " of";
21
- export type ofKey = typeof ofKey;
22
- export type of<base, attributes> = base & {
23
- [ofKey]: {
15
+ export declare const attributesKey: " attributes";
16
+ export type attributesKey = typeof attributesKey;
17
+ export type of<base, attributes extends Attributes> = base & {
18
+ [attributesKey]: {
24
19
  base: base;
25
20
  attributes: attributes;
26
21
  };
27
22
  };
28
- export type brand<base, attributes> = base & {
29
- [ofKey]: {
23
+ export type brand<base, attributes extends Attributes> = base & {
24
+ [attributesKey]: {
30
25
  base: base;
31
- attributes: attributes & {
32
- brand: true;
33
- };
26
+ attributes: attributes;
27
+ brand: true;
34
28
  };
35
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;
36
58
  export type LimitLiteral = number | DateLiteral;
37
59
  export type normalizeLimit<limit> = limit extends DateLiteral<infer source> ? source : limit extends number | string ? limit : never;
38
60
  export type constraint<rule> = {
39
- [k in rule & PropertyKey]: 1;
61
+ [k in rule & PropertyKey]: true;
40
62
  };
41
- export type Literal<rule> = {
42
- literal: constraint<rule>;
63
+ export type Anonymous = Nominal<"?">;
64
+ export type Nominal<name> = {
65
+ nominal: constraint<name>;
43
66
  };
44
- export type Narrowed = {
45
- predicate: {
46
- "?": 1;
47
- };
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>;
48
75
  };
49
- export type Predicate<name> = {
50
- predicate: constraint<name>;
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>;
51
93
  };
52
94
  export type primitiveConstraintKindOf<In> = Extract<Constraint.PrimitiveKind, constraintKindOf<In>>;
53
95
  export type AtLeastLength<rule> = {
@@ -66,12 +108,52 @@ export type ExactlyLength<rule> = {
66
108
  atLeastLength: constraint<rule>;
67
109
  atMostLength: constraint<rule>;
68
110
  };
69
- export type applyConstraintSchema<t, kind extends Constraint.PrimitiveKind, schema extends NodeSchema<kind>> = applyAttribute<t, schemaToConstraint<kind, schema>>;
70
- export type applyAttribute<t, attribute> = t extends InferredMorph<infer i, infer o> ? (In: leftIfEqual<i, _applyAttribute<i, attribute>>) => o : leftIfEqual<t, _applyAttribute<t, attribute>>;
71
- type _applyAttribute<t, attribute> = t extends null | undefined ? t : t extends of<infer base, infer attributes> ? [
72
- number,
73
- base
74
- ] extends [base, number] ? number.is<attribute & attributes> : [string, base] extends [base, string] ? "brand" extends keyof attributes | keyof attribute ? brandedString.is<attribute & attributes> : string.is<attribute & attributes> : [Date, base] extends [base, Date] ? Date.is<attribute & attributes> : of<base, attributes & attribute> : [number, t] extends [t, number] ? number.applyAttribute<attribute> : [string, t] extends [t, string] ? "brand" extends keyof attribute ? brandedString.applyBrand<attribute> : string.applyAttribute<attribute> : [Date, t] extends [t, Date] ? Date.applyAttribute<attribute> : of<t, attribute>;
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"> = t extends InferredMorph<infer i, infer o> ? (In: leftIfEqual<i, _attachAttributes<i, attributes, behavior>>) => o : leftIfEqual<t, _attachAttributes<t, attributes, behavior>>;
115
+ type _attachAttributes<t, attributes extends Attributes, behavior extends AttributeInferenceBehavior> = t extends null | undefined ? t : t extends of<infer base, infer existingAttributes> ? "brand" extends keyof t[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;
75
157
  export type normalizePrimitiveConstraintRoot<schema extends NodeSchema<Constraint.PrimitiveKind>> = "rule" extends keyof schema ? conform<schema["rule"], PropertyKey> : conform<schema, PropertyKey>;
76
158
  type minLengthSchemaToConstraint<schema, rule> = schema extends {
77
159
  exclusive: true;
@@ -79,13 +161,14 @@ type minLengthSchemaToConstraint<schema, rule> = schema extends {
79
161
  type maxLengthSchemaToConstraint<schema, rule> = schema extends {
80
162
  exclusive: true;
81
163
  } ? LessThanLength<rule> : AtMostLength<rule>;
82
- 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 "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> : Narrowed : never;
164
+ export type associateAttributesFromSchema<t, kind extends Constraint.PrimitiveKind, schema extends NodeSchema<kind>> = associateAttributes<t, schemaToAttributes<kind, schema>>;
165
+ 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;
83
166
  export type distill<t, opts extends distill.Options = {}> = finalizeDistillation<t, _distill<t, opts>>;
84
167
  export declare namespace distill {
85
168
  type Endpoint = "in" | "out" | "out.introspectable";
86
169
  type Options = {
87
170
  endpoint?: Endpoint;
88
- branded?: true;
171
+ attributes?: "preserve" | "brand" | "unbrand";
89
172
  };
90
173
  type In<t> = distill<t, {
91
174
  endpoint: "in";
@@ -93,23 +176,28 @@ export declare namespace distill {
93
176
  type Out<t> = distill<t, {
94
177
  endpoint: "out";
95
178
  }>;
96
- namespace brandable {
179
+ namespace withAttributes {
97
180
  type In<t> = distill<t, {
98
181
  endpoint: "in";
99
- branded: true;
182
+ attributes: "preserve";
100
183
  }>;
101
184
  type Out<t> = distill<t, {
102
185
  endpoint: "out";
103
- branded: true;
186
+ attributes: "preserve";
104
187
  }>;
105
188
  namespace introspectable {
106
189
  type Out<t> = distill<t, {
107
190
  endpoint: "out.introspectable";
108
- branded: true;
191
+ attributes: "preserve";
109
192
  }>;
110
193
  }
111
194
  }
112
- type unbranded<t> = distill<t>;
195
+ type brand<t> = distill<t, {
196
+ attributes: "brand";
197
+ }>;
198
+ type unbrand<t> = distill<t, {
199
+ attributes: "unbrand";
200
+ }>;
113
201
  namespace introspectable {
114
202
  type Out<t> = distill<t, {
115
203
  endpoint: "out.introspectable";
@@ -117,7 +205,7 @@ export declare namespace distill {
117
205
  }
118
206
  }
119
207
  type finalizeDistillation<t, distilled> = equals<t, distilled> extends true ? t : distilled;
120
- type _distill<t, opts extends distill.Options> = t extends undefined ? t : [t] extends [anyOrNever] ? t : t extends of<infer base, infer attributes> ? opts["branded"] extends true ? of<_distill<base, opts>, attributes> : "brand" extends keyof attributes ? 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;
208
+ 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;
121
209
  type distillMappable<o, opts extends distill.Options> = opts["endpoint"] extends "in" ? show<{
122
210
  [k in keyof o as k extends inferredOptionalOrDefaultKeyOf<o> ? never : k]: _distill<o[k], opts>;
123
211
  } & {
@@ -136,8 +224,8 @@ type inferredDefaultKeyOf<o> = keyof o extends infer k ? k extends keyof o ? inE
136
224
  type inferredOptionalKeyOf<o> = keyof o extends infer k ? k extends keyof o ? inExtends<o[k], InferredOptional> extends true ? k : never : never : never;
137
225
  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>;
138
226
  type alignReadonly<result extends unknown[], original extends array> = original extends unknown[] ? result : Readonly<result>;
139
- type distillNonArraykeys<originalArray extends array, distilledArray, opts extends distill.Options> = keyof originalArray extends keyof distilledArray | ofKey ? distilledArray : distilledArray & _distill<{
140
- [k in keyof originalArray as k extends (keyof distilledArray | (opts["branded"] extends true ? never : ofKey)) ? never : k]: originalArray[k];
227
+ type distillNonArraykeys<originalArray extends array, distilledArray, opts extends distill.Options> = keyof originalArray extends keyof distilledArray | attributesKey ? distilledArray : distilledArray & _distill<{
228
+ [k in keyof originalArray as k extends (keyof distilledArray | (opts["attributes"] extends true ? never : attributesKey)) ? never : k]: originalArray[k];
141
229
  }, opts>;
142
230
  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>];
143
231
  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]> : [...{
@@ -146,19 +234,20 @@ type distillPostfix<t extends array, opts extends distill.Options, postfix exten
146
234
  type BuiltinTerminalObjectKind = Exclude<keyof arkPrototypes.instances, "Array" | "Function">;
147
235
  /** Objects we don't want to expand during inference like Date or Promise */
148
236
  type TerminallyInferredObject = arkPrototypes.instanceOf<BuiltinTerminalObjectKind> | ArkEnv.prototypes;
149
- export type inferPredicate<t, predicate> = predicate extends (data: any, ...args: any[]) => data is infer narrowed ? t extends of<unknown, infer constraints> ? applyConstraintSchema<of<narrowed, constraints>, "predicate", any> : applyConstraintSchema<narrowed, "predicate", any> : applyConstraintSchema<t, "predicate", any>;
150
- export type constrainWithPredicate<t> = t extends of<unknown, infer constraints> ? applyConstraintSchema<of<t, constraints>, "predicate", any> : applyConstraintSchema<t, "predicate", any>;
151
- 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.brandable.In<t>) => Out<out> : never, tail> : t;
237
+ 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>;
238
+ 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;
152
239
  export type inferMorphOut<morph extends Morph> = Exclude<ReturnType<morph>, ArkError | ArkErrors>;
153
240
  export type Out<o = any> = ["=>", o, boolean];
154
241
  export type To<o = any> = ["=>", o, true];
155
242
  export type InferredMorph<i = any, o extends Out = Out> = (In: i) => o;
156
243
  export type Optional = {
157
- optional: {};
244
+ optional: {
245
+ "=": true;
246
+ };
158
247
  };
159
248
  export type InferredOptional<t = unknown> = of<t, Optional>;
160
249
  export type Default<v = any> = {
161
- default: {
250
+ defaultsTo: {
162
251
  value: v;
163
252
  };
164
253
  };
@@ -0,0 +1,2 @@
1
+ import { noSuggest } from "@ark/util";
2
+ export const attributesKey = noSuggest("attributes");
@@ -1,6 +1,6 @@
1
1
  import { Hkt, liftArray, type Digit } from "@ark/util";
2
+ import type { To } from "../../attributes.ts";
2
3
  import type { Module, Submodule } from "../../module.ts";
3
- import type { To } from "../inference.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,32 +1,37 @@
1
- import type { constraint, Default, Literal, Narrowed, normalizeLimit, of, Optional, Predicate } from "../inference.ts";
2
- export type AtOrAfter<rule> = {
3
- atOrAfter: constraint<rule>;
4
- };
5
- export type AtOrBefore<rule> = {
6
- atOrBefore: constraint<rule>;
7
- };
8
- export type After<rule> = {
9
- after: constraint<rule>;
10
- };
11
- export type Before<rule> = {
12
- before: constraint<rule>;
13
- };
1
+ import type { satisfy } from "@ark/util";
2
+ import type { After, Anonymous, AtOrAfter, AtOrBefore, AttributeKind, Attributes, Before, brand, Default, Nominal, normalizeLimit, of, Optional } from "../../attributes.ts";
14
3
  export declare namespace Date {
15
4
  type atOrAfter<rule> = of<Date, AtOrAfter<rule>>;
16
5
  type after<rule> = of<Date, After<rule>>;
17
6
  type atOrBefore<rule> = of<Date, AtOrBefore<rule>>;
18
7
  type before<rule> = of<Date, Before<rule>>;
19
- type narrowed = of<Date, Narrowed>;
8
+ type anonymous = of<Date, Anonymous>;
9
+ type nominal<rule> = of<Date, Nominal<rule>>;
20
10
  type optional = of<Date, Optional>;
21
11
  type defaultsTo<rule> = of<Date, Default<rule>>;
22
- type branded<rule> = of<Date, Predicate<rule>>;
23
- type literal<rule> = of<Date, Literal<rule>>;
24
- type is<attributes> = of<Date, attributes>;
12
+ type is<attributes extends Attributes> = of<Date, attributes>;
25
13
  type afterSchemaToConstraint<schema, rule> = schema extends {
26
14
  exclusive: true;
27
15
  } ? After<normalizeLimit<rule>> : AtOrAfter<normalizeLimit<rule>>;
28
16
  type beforeSchemaToConstraint<schema, rule> = schema extends {
29
17
  exclusive: true;
30
18
  } ? Before<normalizeLimit<rule>> : AtOrBefore<normalizeLimit<rule>>;
31
- type applyAttribute<attribute> = attribute extends After<infer rule> ? after<rule> : attribute extends Before<infer rule> ? before<rule> : attribute extends AtOrAfter<infer rule> ? atOrAfter<rule> : attribute extends AtOrBefore<infer rule> ? atOrBefore<rule> : attribute extends Optional ? optional : attribute extends Default<infer rule> ? defaultsTo<rule> : attribute extends Predicate<infer rule> ? branded<rule> : never;
19
+ type AttributableKind = satisfy<AttributeKind, "after" | "atOrAfter" | "before" | "atOrBefore">;
20
+ type withSingleAttribute<kind extends AttributableKind, value extends Attributes[kind]> = raw.withSingleAttribute<kind, value>;
21
+ namespace raw {
22
+ type withSingleAttribute<kind, value> = kind extends "nominal" ? nominal<value> : kind extends "after" ? after<value> : kind extends "atOrAfter" ? atOrAfter<value> : kind extends "before" ? before<value> : kind extends "atOrBefore" ? atOrBefore<value> : kind extends "optional" ? optional : kind extends "defaultsTo" ? defaultsTo<value> : never;
23
+ }
24
+ type branded<rule> = brand<Date, Nominal<rule>>;
25
+ namespace branded {
26
+ type atOrAfter<rule> = brand<Date, AtOrAfter<rule>>;
27
+ type after<rule> = brand<Date, After<rule>>;
28
+ type atOrBefore<rule> = brand<Date, AtOrBefore<rule>>;
29
+ type before<rule> = brand<Date, Before<rule>>;
30
+ type anonymous = brand<Date, Anonymous>;
31
+ type is<attributes extends Attributes> = brand<Date, attributes>;
32
+ type withSingleAttribute<kind extends AttributableKind, value extends Attributes[kind]> = raw.withSingleAttribute<kind, value>;
33
+ namespace raw {
34
+ type withSingleAttribute<kind, value> = kind extends "nominal" ? branded<value> : kind extends "after" ? after<value> : kind extends "atOrAfter" ? atOrAfter<value> : kind extends "before" ? before<value> : kind extends "atOrBefore" ? atOrBefore<value> : never;
35
+ }
36
+ }
32
37
  }
@@ -1,5 +1,5 @@
1
+ import type { To } from "../../attributes.ts";
1
2
  import type { Module, Submodule } from "../../module.ts";
2
- import type { To } from "../inference.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,5 +1,6 @@
1
1
  import type { ArkErrors, arkKind } from "@ark/schema";
2
2
  import type { inferred } from "@ark/util";
3
+ import type { distill } 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";
@@ -8,7 +9,6 @@ import { type bindThis, type Scope } from "../scope.ts";
8
9
  import type { DeclarationParser, DefinitionParser, SchemaParser, Type, TypeParser } from "../type.ts";
9
10
  import { arkBuiltins } from "./builtins.ts";
10
11
  import { arkPrototypes } from "./constructors/constructors.ts";
11
- import type { distill } from "./inference.ts";
12
12
  import { number } from "./number/number.ts";
13
13
  import { string } from "./string/string.ts";
14
14
  import { arkTsGenerics, arkTsKeywords, object, unknown } from "./ts.ts";
@@ -45,9 +45,9 @@ export declare namespace type {
45
45
  namespace infer {
46
46
  type In<def, $ = {}, args = {}> = distill.In<inferDefinition<def, $, args>>;
47
47
  type Out<def, $ = {}, args = {}> = distill.Out<inferDefinition<def, $, args>>;
48
- namespace brandable {
49
- type In<def, $ = {}, args = {}> = distill.brandable.In<inferDefinition<def, $, args>>;
50
- type Out<def, $ = {}, args = {}> = distill.brandable.Out<inferDefinition<def, $, args>>;
48
+ namespace withAttributes {
49
+ type In<def, $ = {}, args = {}> = distill.withAttributes.In<inferDefinition<def, $, args>>;
50
+ type Out<def, $ = {}, args = {}> = distill.withAttributes.Out<inferDefinition<def, $, args>>;
51
51
  }
52
52
  namespace introspectable {
53
53
  type Out<def, $ = {}, args = {}> = distill.introspectable.Out<inferDefinition<def, $, args>>;
@@ -1,4 +1,5 @@
1
- import type { AtLeast, AtMost, DivisibleBy, number } from "./number.ts";
1
+ import type { AtLeast, AtMost, DivisibleBy } from "../../attributes.ts";
2
+ import type { number } from "./number.ts";
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.
@@ -1,49 +1,35 @@
1
+ import type { satisfy } from "@ark/util";
2
+ import type { Anonymous, AtLeast, AtMost, AttributeKind, Attributes, brand, Default, DivisibleBy, LessThan, MoreThan, Nominal, of, Optional } from "../../attributes.ts";
1
3
  import type { Module, Submodule } from "../../module.ts";
2
- import type { BaseAttributes, constraint, Default, Narrowed, of, Optional, Predicate } from "../inference.ts";
3
4
  import { epoch } from "./epoch.ts";
4
5
  import { integer } from "./integer.ts";
5
6
  export declare const number: number.module;
6
- export type AtLeast<rule> = {
7
- atLeast: constraint<rule>;
8
- };
9
- export type AtMost<rule> = {
10
- atMost: constraint<rule>;
11
- };
12
- export type MoreThan<rule> = {
13
- moreThan: constraint<rule>;
14
- };
15
- export type LessThan<rule> = {
16
- lessThan: constraint<rule>;
17
- };
18
- export type DivisibleBy<rule> = {
19
- divisibleBy: constraint<rule>;
20
- };
21
7
  export declare namespace number {
22
8
  type atLeast<rule> = of<number, AtLeast<rule>>;
23
9
  type moreThan<rule> = of<number, MoreThan<rule>>;
24
10
  type atMost<rule> = of<number, AtMost<rule>>;
25
11
  type lessThan<rule> = of<number, LessThan<rule>>;
26
12
  type divisibleBy<rule> = of<number, DivisibleBy<rule>>;
27
- type narrowed = of<number, Narrowed>;
13
+ type anonymous = of<number, Anonymous>;
28
14
  type optional = of<number, Optional>;
29
15
  type defaultsTo<rule> = of<number, Default<rule>>;
30
- type branded<rule> = of<number, Predicate<rule>>;
31
- interface ownConstraints extends AtLeast<number>, MoreThan<number>, LessThan<number>, AtMost<number>, DivisibleBy<number> {
32
- }
33
- interface Attributes extends BaseAttributes, Partial<ownConstraints> {
34
- }
35
- type NaN = branded<"NaN">;
36
- type Infinity = branded<"Infinity">;
37
- type NegativeInfinity = branded<"NegativeInfinity">;
38
- type safe = branded<"safe">;
39
- type is<attributes> = of<number, attributes>;
16
+ type nominal<rule> = of<number, Nominal<rule>>;
17
+ type NaN = nominal<"NaN">;
18
+ type Infinity = nominal<"Infinity">;
19
+ type NegativeInfinity = nominal<"NegativeInfinity">;
20
+ type safe = nominal<"safe">;
21
+ type is<attributes extends Attributes> = of<number, attributes>;
22
+ type AttributableKind = satisfy<AttributeKind, "divisibleBy" | "moreThan" | "atLeast" | "atMost" | "lessThan">;
40
23
  type minSchemaToConstraint<schema, rule> = schema extends {
41
24
  exclusive: true;
42
25
  } ? MoreThan<rule> : AtLeast<rule>;
43
26
  type maxSchemaToConstraint<schema, rule> = schema extends {
44
27
  exclusive: true;
45
28
  } ? LessThan<rule> : AtMost<rule>;
46
- type applyAttribute<attribute> = attribute extends MoreThan<infer rule> ? moreThan<rule> : attribute extends AtLeast<infer rule> ? atLeast<rule> : attribute extends AtMost<infer rule> ? atMost<rule> : attribute extends LessThan<infer rule> ? lessThan<rule> : attribute extends DivisibleBy<infer rule> ? divisibleBy<rule> : attribute extends Optional ? optional : attribute extends Default<infer rule> ? defaultsTo<rule> : attribute extends Predicate<infer rule> ? branded<rule> : never;
29
+ type withSingleAttribute<kind extends AttributableKind, value extends Attributes[kind]> = raw.withSingleAttribute<kind, value>;
30
+ namespace raw {
31
+ type withSingleAttribute<kind, value> = kind extends "nominal" ? nominal<value> : kind extends "divisibleBy" ? divisibleBy<value> : kind extends "moreThan" ? moreThan<value> : kind extends "atLeast" ? atLeast<value> : kind extends "atMost" ? atMost<value> : kind extends "lessThan" ? lessThan<value> : kind extends "optional" ? optional : kind extends "defaultsTo" ? defaultsTo<value> : never;
32
+ }
47
33
  type module = Module<submodule>;
48
34
  type submodule = Submodule<$>;
49
35
  type $ = {
@@ -55,4 +41,18 @@ export declare namespace number {
55
41
  Infinity: Infinity;
56
42
  NegativeInfinity: NegativeInfinity;
57
43
  };
44
+ type branded<rule> = brand<number, Nominal<rule>>;
45
+ namespace branded {
46
+ type atLeast<rule> = brand<number, AtLeast<rule>>;
47
+ type moreThan<rule> = brand<number, MoreThan<rule>>;
48
+ type atMost<rule> = brand<number, AtMost<rule>>;
49
+ type lessThan<rule> = brand<number, LessThan<rule>>;
50
+ type divisibleBy<rule> = brand<number, DivisibleBy<rule>>;
51
+ type is<attributes extends Attributes> = brand<number, attributes>;
52
+ type anonymous = brand<number, Anonymous>;
53
+ type withSingleAttribute<kind extends AttributableKind, value extends Attributes[kind]> = raw.withSingleAttribute<kind, value>;
54
+ namespace raw {
55
+ type withSingleAttribute<kind, value> = kind extends "nominal" ? branded<value> : kind extends "divisibleBy" ? divisibleBy<value> : kind extends "moreThan" ? moreThan<value> : kind extends "atLeast" ? atLeast<value> : kind extends "atMost" ? atMost<value> : kind extends "lessThan" ? lessThan<value> : never;
56
+ }
57
+ }
58
58
  }
@@ -1,6 +1,6 @@
1
- import type { Predicate, of } from "../inference.ts";
1
+ import type { Nominal, of } from "../../attributes.ts";
2
2
  declare namespace string {
3
- type alpha = of<string, Predicate<"alpha">>;
3
+ type alpha = of<string, Nominal<"alpha">>;
4
4
  }
5
5
  export declare const alpha: import("@ark/schema").IntersectionNode;
6
6
  export type alpha = string.alpha;
@@ -1,6 +1,6 @@
1
- import type { Predicate, of } from "../inference.ts";
1
+ import type { Nominal, of } from "../../attributes.ts";
2
2
  declare namespace string {
3
- type alphanumeric = of<string, Predicate<"alphanumeric">>;
3
+ type alphanumeric = of<string, Nominal<"alphanumeric">>;
4
4
  }
5
5
  export declare const alphanumeric: import("@ark/schema").IntersectionNode;
6
6
  export type alphanumeric = string.alphanumeric;
@@ -1,13 +1,13 @@
1
+ import type { Nominal, of } from "../../attributes.ts";
1
2
  import type { Module, Submodule } from "../../module.ts";
2
- import type { Predicate, of } from "../inference.ts";
3
3
  export declare const base64: Module<{
4
4
  root: unknown;
5
5
  url: unknown;
6
6
  }>;
7
7
  declare namespace string {
8
- type base64 = of<string, Predicate<"base64">>;
8
+ type base64 = of<string, Nominal<"base64">>;
9
9
  namespace base64 {
10
- type url = of<string, Predicate<"base64.url">>;
10
+ type url = of<string, Nominal<"base64.url">>;
11
11
  }
12
12
  }
13
13
  export declare namespace base64 {
@@ -1,7 +1,7 @@
1
+ import type { Nominal, of, To } from "../../attributes.ts";
1
2
  import type { Module, Submodule } from "../../module.ts";
2
- import type { of, Predicate, To } from "../inference.ts";
3
3
  declare namespace string {
4
- type capitalized = of<string, Predicate<"capitalized">>;
4
+ type capitalized = of<string, Nominal<"capitalized">>;
5
5
  }
6
6
  export declare const capitalize: capitalize.module;
7
7
  export declare namespace capitalize {
@@ -1,7 +1,7 @@
1
- import type { Predicate, of } from "../inference.ts";
1
+ import type { Nominal, of } from "../../attributes.ts";
2
2
  export declare const isLuhnValid: (creditCardInput: string) => boolean;
3
3
  declare namespace string {
4
- type creditCard = of<string, Predicate<"creditCard">>;
4
+ type creditCard = of<string, Nominal<"creditCard">>;
5
5
  }
6
6
  export declare const creditCard: import("@ark/schema").BaseRoot<import("@ark/schema").InternalRootDeclaration>;
7
7
  export type creditCard = string.creditCard;
@@ -1,5 +1,5 @@
1
+ import type { Nominal, To, of } from "../../attributes.ts";
1
2
  import type { Module, Submodule } from "../../module.ts";
2
- import type { Predicate, To, of } from "../inference.ts";
3
3
  type DayDelimiter = "." | "/" | "-";
4
4
  type DayPart = DayPatterns[PartKey];
5
5
  type PartKey = keyof DayPatterns;
@@ -21,10 +21,10 @@ export type DateOptions = {
21
21
  export declare const iso8601Matcher: RegExp;
22
22
  export declare const tryParseDatePattern: (data: string, opts?: DateOptions) => Date | string;
23
23
  declare namespace string {
24
- type date = of<string, Predicate<"date">>;
24
+ type date = of<string, Nominal<"date">>;
25
25
  namespace date {
26
- type epoch = of<string, Predicate<"date.epoch">>;
27
- type iso = of<string, Predicate<"date.iso">>;
26
+ type epoch = of<string, Nominal<"date.epoch">>;
27
+ type iso = of<string, Nominal<"date.iso">>;
28
28
  }
29
29
  }
30
30
  export declare const stringDate: stringDate.module;
@@ -1,6 +1,6 @@
1
- import type { Predicate, of } from "../inference.ts";
1
+ import type { Nominal, of } from "../../attributes.ts";
2
2
  declare namespace string {
3
- type digits = of<string, Predicate<"digits">>;
3
+ type digits = of<string, Nominal<"digits">>;
4
4
  }
5
5
  export declare const digits: import("@ark/schema").IntersectionNode;
6
6
  export type digits = string.digits;
@@ -1,6 +1,6 @@
1
- import type { Predicate, of } from "../inference.ts";
1
+ import type { Nominal, of } from "../../attributes.ts";
2
2
  declare namespace string {
3
- type email = of<string, Predicate<"email">>;
3
+ type email = of<string, Nominal<"email">>;
4
4
  }
5
5
  export declare const email: import("@ark/schema").IntersectionNode;
6
6
  export type email = string.email;
@@ -1,8 +1,8 @@
1
+ import type { Nominal, of, To } from "../../attributes.ts";
1
2
  import type { Module, Submodule } from "../../module.ts";
2
- import type { of, Predicate, To } from "../inference.ts";
3
3
  import type { number } from "../number/number.ts";
4
4
  declare namespace string {
5
- type integer = of<string, Predicate<"integer">>;
5
+ type integer = of<string, Nominal<"integer">>;
6
6
  }
7
7
  export declare const integer: stringInteger.module;
8
8
  export declare namespace stringInteger {
@@ -1,10 +1,10 @@
1
+ import type { Nominal, of } from "../../attributes.ts";
1
2
  import type { Module, Submodule } from "../../module.ts";
2
- import type { Predicate, of } from "../inference.ts";
3
3
  declare namespace string {
4
- type ip = of<string, Predicate<"ip">>;
4
+ type ip = of<string, Nominal<"ip">>;
5
5
  namespace ip {
6
- type v4 = of<string, Predicate<"ip.v4">>;
7
- type v6 = of<string, Predicate<"ip.v6">>;
6
+ type v4 = of<string, Nominal<"ip.v4">>;
7
+ type v6 = of<string, Nominal<"ip.v6">>;
8
8
  }
9
9
  }
10
10
  export declare const ip: ip.module;