arktype 2.0.0-rc.11 → 2.0.0-rc.13

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 (50) hide show
  1. package/out/keywords/constructors/Date.d.ts +12 -12
  2. package/out/keywords/inference.d.ts +42 -89
  3. package/out/keywords/inference.js +1 -1
  4. package/out/keywords/number/number.d.ts +16 -12
  5. package/out/keywords/string/alpha.d.ts +2 -2
  6. package/out/keywords/string/alphanumeric.d.ts +2 -2
  7. package/out/keywords/string/brands.d.ts +17 -0
  8. package/out/keywords/string/capitalize.d.ts +2 -2
  9. package/out/keywords/string/creditCard.d.ts +2 -2
  10. package/out/keywords/string/date.d.ts +4 -4
  11. package/out/keywords/string/digits.d.ts +2 -2
  12. package/out/keywords/string/email.d.ts +2 -2
  13. package/out/keywords/string/integer.d.ts +2 -2
  14. package/out/keywords/string/ip.d.ts +4 -4
  15. package/out/keywords/string/json.d.ts +2 -2
  16. package/out/keywords/string/lower.d.ts +2 -2
  17. package/out/keywords/string/normalize.d.ts +5 -5
  18. package/out/keywords/string/numeric.d.ts +2 -2
  19. package/out/keywords/string/semver.d.ts +2 -2
  20. package/out/keywords/string/string.d.ts +14 -13
  21. package/out/keywords/string/trim.d.ts +2 -2
  22. package/out/keywords/string/upper.d.ts +2 -2
  23. package/out/keywords/string/url.d.ts +2 -2
  24. package/out/keywords/string/uuid.d.ts +10 -10
  25. package/out/methods/base.d.ts +24 -21
  26. package/out/methods/instantiate.d.ts +3 -3
  27. package/out/methods/morph.d.ts +2 -6
  28. package/out/methods/number.d.ts +2 -2
  29. package/out/methods/object.d.ts +8 -11
  30. package/out/methods/string.d.ts +2 -2
  31. package/out/parser/ast/default.d.ts +2 -2
  32. package/out/parser/ast/infer.d.ts +5 -6
  33. package/out/parser/ast/validate.d.ts +5 -5
  34. package/out/parser/ast/validate.js +1 -1
  35. package/out/parser/objectLiteral.d.ts +2 -2
  36. package/out/parser/reduce/dynamic.d.ts +1 -2
  37. package/out/parser/shift/operand/unenclosed.d.ts +5 -1
  38. package/out/parser/shift/operand/unenclosed.js +5 -4
  39. package/out/parser/shift/operator/brand.d.ts +6 -0
  40. package/out/parser/shift/operator/brand.js +5 -0
  41. package/out/parser/shift/operator/default.js +4 -1
  42. package/out/parser/shift/operator/operator.d.ts +2 -1
  43. package/out/parser/shift/operator/operator.js +4 -2
  44. package/out/parser/shift/scanner.d.ts +3 -2
  45. package/out/parser/shift/scanner.js +1 -0
  46. package/out/parser/tuple.d.ts +6 -5
  47. package/out/type.d.ts +2 -2
  48. package/package.json +3 -3
  49. package/out/methods/validator.d.ts +0 -11
  50. /package/out/{methods/validator.js → keywords/string/brands.js} +0 -0
@@ -1,4 +1,4 @@
1
- import type { Branded, constrain, constraint, Constraints, Default, Literal, Narrowed, normalizeLimit, Optional } from "../inference.ts";
1
+ import type { constraint, Default, Literal, Narrowed, normalizeLimit, of, Optional, Predicate } from "../inference.ts";
2
2
  export type AtOrAfter<rule> = {
3
3
  atOrAfter: constraint<rule>;
4
4
  };
@@ -12,21 +12,21 @@ export type Before<rule> = {
12
12
  before: constraint<rule>;
13
13
  };
14
14
  export declare namespace Date {
15
- type atOrAfter<rule> = constrain<Date, AtOrAfter<rule>>;
16
- type after<rule> = constrain<Date, After<rule>>;
17
- type atOrBefore<rule> = constrain<Date, AtOrBefore<rule>>;
18
- type before<rule> = constrain<Date, Before<rule>>;
19
- type narrowed = constrain<Date, Narrowed>;
20
- type optional = constrain<Date, Optional>;
21
- type defaultsTo<rule> = constrain<Date, Default<rule>>;
22
- type branded<rule> = constrain<Date, Branded<rule>>;
23
- type literal<rule> = constrain<Date, Literal<rule>>;
24
- type is<constraints extends Constraints> = constrain<Date, constraints>;
15
+ type atOrAfter<rule> = of<Date, AtOrAfter<rule>>;
16
+ type after<rule> = of<Date, After<rule>>;
17
+ type atOrBefore<rule> = of<Date, AtOrBefore<rule>>;
18
+ type before<rule> = of<Date, Before<rule>>;
19
+ type narrowed = of<Date, Narrowed>;
20
+ type optional = of<Date, Optional>;
21
+ 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>;
25
25
  type afterSchemaToConstraint<schema, rule> = schema extends {
26
26
  exclusive: true;
27
27
  } ? After<normalizeLimit<rule>> : AtOrAfter<normalizeLimit<rule>>;
28
28
  type beforeSchemaToConstraint<schema, rule> = schema extends {
29
29
  exclusive: true;
30
30
  } ? Before<normalizeLimit<rule>> : AtOrBefore<normalizeLimit<rule>>;
31
- type withConstraint<constraint> = constraint extends After<infer rule> ? after<rule> : constraint extends Before<infer rule> ? before<rule> : constraint extends AtOrAfter<infer rule> ? atOrAfter<rule> : constraint extends AtOrBefore<infer rule> ? atOrBefore<rule> : constraint extends Optional ? optional : constraint extends Default<infer rule> ? defaultsTo<rule> : constraint extends Narrowed ? narrowed : never;
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;
32
32
  }
@@ -1,25 +1,37 @@
1
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 objectKindOf, type Primitive, type show } from "@ark/util";
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
3
  import type { Type } from "../type.ts";
4
4
  import type { arkPrototypes } from "./constructors/constructors.ts";
5
5
  import type { Date } from "./constructors/Date.ts";
6
6
  import type { type } from "./keywords.ts";
7
7
  import type { DivisibleBy, number } from "./number/number.ts";
8
- import type { Matching, string } from "./string/string.ts";
8
+ import type { brandedString, Matching, string } from "./string/string.ts";
9
9
  export type { arkPrototypes as object } from "./constructors/constructors.ts";
10
10
  export type { number } from "./number/number.ts";
11
11
  export type { string } from "./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 type ConstraintSet = Record<PropertyKey, 1>;
16
- export type Constraints = Record<string, ConstraintSet> | {
15
+ export interface BaseAttributes {
16
+ predicate?: dict;
17
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]: {
24
+ base: base;
25
+ attributes: attributes;
26
+ };
18
27
  };
19
- export declare const constrained: " arkConstrained";
20
- export type constrained = typeof constrained;
21
- export type constrain<base, constraints extends Constraints> = base & {
22
- [constrained]: constraints;
28
+ export type brand<base, attributes> = base & {
29
+ [ofKey]: {
30
+ base: base;
31
+ attributes: attributes & {
32
+ brand: true;
33
+ };
34
+ };
23
35
  };
24
36
  export type LimitLiteral = number | DateLiteral;
25
37
  export type normalizeLimit<limit> = limit extends DateLiteral<infer source> ? source : limit extends number | string ? limit : never;
@@ -34,8 +46,8 @@ export type Narrowed = {
34
46
  "?": 1;
35
47
  };
36
48
  };
37
- export type Branded<rule> = {
38
- predicate: constraint<rule>;
49
+ export type Predicate<name> = {
50
+ predicate: constraint<name>;
39
51
  };
40
52
  export type primitiveConstraintKindOf<In> = Extract<Constraint.PrimitiveKind, constraintKindOf<In>>;
41
53
  export type AtLeastLength<rule> = {
@@ -54,39 +66,12 @@ export type ExactlyLength<rule> = {
54
66
  atLeastLength: constraint<rule>;
55
67
  atMostLength: constraint<rule>;
56
68
  };
57
- export type applyConstraintSchema<t, kind extends Constraint.PrimitiveKind, schema extends NodeSchema<kind>> = applyConstraint<t, schemaToConstraint<kind, schema>>;
58
- export type applyConstraint<t, constraint> = t extends InferredMorph<infer i, infer o> ? (In: leftIfEqual<i, _applyConstraint<i, constraint>>) => o : leftIfEqual<t, _applyConstraint<t, constraint>>;
59
- type _applyConstraint<t, constraint> = parseConstraints<t> extends ([
60
- infer base,
61
- infer constraints extends Constraints
62
- ]) ? [
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> ? [
63
72
  number,
64
73
  base
65
- ] 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.withConstraint<constraint> : [string, t] extends [t, string] ? string.withConstraint<constraint> : [Date, t] extends [t, Date] ? Date.withConstraint<constraint> : constrain<t, conform<constraint, Constraints>>;
66
- export type parseConstraints<t> = t extends constrain<infer base, infer constraints> ? equals<t, number & {
67
- [constrained]: constraints;
68
- }> extends true ? [
69
- number,
70
- constraints
71
- ] : equals<t, string & {
72
- [constrained]: constraints;
73
- }> extends true ? [
74
- string,
75
- constraints
76
- ] : equals<t, bigint & {
77
- [constrained]: constraints;
78
- }> extends true ? [
79
- bigint,
80
- constraints
81
- ] : equals<t, symbol & {
82
- [constrained]: constraints;
83
- }> extends true ? [
84
- symbol,
85
- constraints
86
- ] : objectKindOf<t> extends infer kind ? kind extends BuiltinTerminalObjectKind ? [
87
- arkPrototypes.instanceOf<kind>,
88
- constraints
89
- ] : kind extends "Array" ? null : kind extends undefined ? [Omit<base, constrained>, constraints] : [base, constraints] : never : null;
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>;
90
75
  export type normalizePrimitiveConstraintRoot<schema extends NodeSchema<Constraint.PrimitiveKind>> = "rule" extends keyof schema ? conform<schema["rule"], PropertyKey> : conform<schema, PropertyKey>;
91
76
  type minLengthSchemaToConstraint<schema, rule> = schema extends {
92
77
  exclusive: true;
@@ -132,29 +117,7 @@ export declare namespace distill {
132
117
  }
133
118
  }
134
119
  type finalizeDistillation<t, distilled> = equals<t, distilled> extends true ? t : distilled;
135
- export type includesMorphs<t> = [
136
- _distill<t, {
137
- endpoint: "in";
138
- branded: true;
139
- }>,
140
- _distill<t, {
141
- endpoint: "out";
142
- branded: true;
143
- }>
144
- ] extends ([
145
- _distill<t, {
146
- endpoint: "out";
147
- branded: true;
148
- }>,
149
- _distill<t, {
150
- endpoint: "in";
151
- branded: true;
152
- }>
153
- ]) ? false : true;
154
- type _distill<t, opts extends distill.Options> = t extends undefined ? t : [t] extends [anyOrNever] ? t : parseConstraints<t> extends ([
155
- infer base,
156
- infer constraints extends Constraints
157
- ]) ? opts["branded"] extends true ? constrain<_distill<base, opts>, constraints> : _distill<base, opts> : unknown extends t ? unknown : t extends TerminallyInferredObject | Primitive ? t : t extends InferredMorph<infer i, infer o> ? opts["branded"] extends true ? distillIo<i, o, opts> : distillUnbrandedIo<t, i, o, opts> : t extends array ? distillArray<t, opts> : t extends Function ? t : isSafelyMappable<t> extends true ? distillMappable<t, opts> : t;
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;
158
121
  type distillMappable<o, opts extends distill.Options> = opts["endpoint"] extends "in" ? show<{
159
122
  [k in keyof o as k extends inferredOptionalOrDefaultKeyOf<o> ? never : k]: _distill<o[k], opts>;
160
123
  } & {
@@ -164,19 +127,17 @@ type distillMappable<o, opts extends distill.Options> = opts["endpoint"] extends
164
127
  } & {
165
128
  [k in keyof o as k extends inferredOptionalKeyOf<o> ? k : never]?: _distill<o[k], opts>;
166
129
  }>;
167
- type distillUnbrandedIo<t extends InferredMorph, i, o extends Out, opts extends distill.Options> = t extends (InferredMorph<constrain<infer constrainedIn, any>, Out<constrain<infer constrainedOut, any>>>) ? distillIo<constrainedIn, o extends To ? To<constrainedOut> : Out<constrainedOut>, opts> : t extends InferredMorph<constrain<infer constrainedIn, any>> ? distillIo<constrainedIn, o, opts> : t extends InferredMorph<any, Out<constrain<infer constrainedOut, any>>> ? distillIo<i, o extends To ? To<constrainedOut> : Out<constrainedOut>, opts> : distillIo<i, o, opts>;
168
130
  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;
169
131
  type inferredOptionalOrDefaultKeyOf<o> = inferredDefaultKeyOf<o> | inferredOptionalKeyOf<o>;
170
- type inferredDefaultKeyOf<o> = keyof o extends infer k ? k extends keyof o ? [
171
- o[k]
172
- ] extends [anyOrNever] ? never : o[k] extends InferredDefault ? k : never : never : never;
173
- type inferredOptionalKeyOf<o> = keyof o extends infer k ? k extends keyof o ? [
174
- o[k]
175
- ] extends [anyOrNever] ? never : o[k] extends InferredOptional ? k : never : never : never;
132
+ type inExtends<v, t> = [
133
+ v
134
+ ] extends [anyOrNever] ? false : [v] extends [t] ? true : [v] extends [InferredMorph<infer i>] ? inExtends<i, t> : false;
135
+ type inferredDefaultKeyOf<o> = keyof o extends infer k ? k extends keyof o ? inExtends<o[k], InferredDefault> extends true ? k : never : never : never;
136
+ type inferredOptionalKeyOf<o> = keyof o extends infer k ? k extends keyof o ? inExtends<o[k], InferredOptional> extends true ? k : never : never : never;
176
137
  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>;
177
138
  type alignReadonly<result extends unknown[], original extends array> = original extends unknown[] ? result : Readonly<result>;
178
- type distillNonArraykeys<originalArray extends array, distilledArray, opts extends distill.Options> = keyof originalArray extends keyof distilledArray | constrained ? distilledArray : distilledArray & _distill<{
179
- [k in keyof originalArray as k extends (keyof distilledArray | (opts["branded"] extends true ? never : constrained)) ? never : k]: originalArray[k];
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];
180
141
  }, opts>;
181
142
  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>];
182
143
  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]> : [...{
@@ -185,38 +146,30 @@ type distillPostfix<t extends array, opts extends distill.Options, postfix exten
185
146
  type BuiltinTerminalObjectKind = Exclude<keyof arkPrototypes.instances, "Array" | "Function">;
186
147
  /** Objects we don't want to expand during inference like Date or Promise */
187
148
  type TerminallyInferredObject = arkPrototypes.instanceOf<BuiltinTerminalObjectKind> | ArkEnv.prototypes;
188
- export type inferPredicate<t, predicate> = predicate extends (data: any, ...args: any[]) => data is infer narrowed ? t extends constrain<unknown, infer constraints> ? applyConstraintSchema<constrain<narrowed, constraints>, "predicate", any> : applyConstraintSchema<narrowed, "predicate", any> : applyConstraintSchema<t, "predicate", any>;
189
- export type constrainWithPredicate<t> = t extends constrain<unknown, infer constraints> ? applyConstraintSchema<constrain<t, constraints>, "predicate", any> : applyConstraintSchema<t, "predicate", any>;
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>;
190
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;
191
152
  export type inferMorphOut<morph extends Morph> = Exclude<ReturnType<morph>, ArkError | ArkErrors>;
192
153
  export type Out<o = any> = ["=>", o, boolean];
193
154
  export type To<o = any> = ["=>", o, true];
194
155
  export type InferredMorph<i = any, o extends Out = Out> = (In: i) => o;
195
156
  export type Optional = {
196
- optional?: {};
157
+ optional: {};
197
158
  };
198
- export type InferredOptional<t = unknown> = constrain<t, Optional>;
159
+ export type InferredOptional<t = unknown> = of<t, Optional>;
199
160
  export type Default<v = any> = {
200
- default?: {
161
+ default: {
201
162
  value: v;
202
163
  };
203
164
  };
204
- export type InferredDefault<t = unknown, v = any> = constrain<t, Default<v>>;
165
+ export type DefaultFor<t> = (Primitive extends t ? Primitive : t extends Primitive ? t : never) | (() => t);
166
+ export type InferredDefault<t = unknown, v = any> = of<t, Default<v>>;
205
167
  export type termOrType<t> = t | Type<t, any>;
206
168
  export type inferIntersection<l, r> = _inferIntersection<l, r, false>;
207
169
  export type inferPipe<l, r> = _inferIntersection<l, r, true>;
208
170
  type _inferIntersection<l, r, piped extends boolean> = [
209
171
  l & r
210
- ] 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 : parseConstraints<l> extends ([
211
- infer lBase,
212
- infer lConstraints extends Constraints
213
- ]) ? parseConstraints<r> extends ([
214
- infer rBase,
215
- infer rConstraints extends Constraints
216
- ]) ? constrain<_inferIntersection<lBase, rBase, piped>, lConstraints & rConstraints> : constrain<_inferIntersection<lBase, r, piped>, lConstraints> : parseConstraints<r> extends ([
217
- infer rBase,
218
- infer rConstraints extends Constraints
219
- ]) ? constrain<_inferIntersection<l, rBase, piped>, rConstraints> : [l, r] extends [object, object] ? intersectObjects<l, r, piped> extends infer result ? result : never : l & r;
172
+ ] 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;
220
173
  interface MorphableIntersection<piped extends boolean> extends Hkt<[unknown, unknown]> {
221
174
  body: _inferIntersection<this[0], this[1], piped>;
222
175
  }
@@ -1,2 +1,2 @@
1
1
  import { noSuggest } from "@ark/util";
2
- export const constrained = noSuggest("arkConstrained");
2
+ export const ofKey = noSuggest("of");
@@ -1,5 +1,5 @@
1
1
  import type { Module, Submodule } from "../../module.ts";
2
- import type { Branded, constrain, constraint, Constraints, Default, Narrowed, Optional } from "../inference.ts";
2
+ import type { BaseAttributes, constraint, Default, Narrowed, of, Optional, Predicate } from "../inference.ts";
3
3
  import { epoch } from "./epoch.ts";
4
4
  import { integer } from "./integer.ts";
5
5
  export declare const number: number.module;
@@ -19,27 +19,31 @@ export type DivisibleBy<rule> = {
19
19
  divisibleBy: constraint<rule>;
20
20
  };
21
21
  export declare namespace number {
22
- type atLeast<rule> = constrain<number, AtLeast<rule>>;
23
- type moreThan<rule> = constrain<number, MoreThan<rule>>;
24
- type atMost<rule> = constrain<number, AtMost<rule>>;
25
- type lessThan<rule> = constrain<number, LessThan<rule>>;
26
- type divisibleBy<rule> = constrain<number, DivisibleBy<rule>>;
27
- type narrowed = constrain<number, Narrowed>;
28
- type optional = constrain<number, Optional>;
29
- type defaultsTo<rule> = constrain<number, Default<rule>>;
30
- type branded<rule> = constrain<number, Branded<rule>>;
22
+ type atLeast<rule> = of<number, AtLeast<rule>>;
23
+ type moreThan<rule> = of<number, MoreThan<rule>>;
24
+ type atMost<rule> = of<number, AtMost<rule>>;
25
+ type lessThan<rule> = of<number, LessThan<rule>>;
26
+ type divisibleBy<rule> = of<number, DivisibleBy<rule>>;
27
+ type narrowed = of<number, Narrowed>;
28
+ type optional = of<number, Optional>;
29
+ 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
+ }
31
35
  type NaN = branded<"NaN">;
32
36
  type Infinity = branded<"Infinity">;
33
37
  type NegativeInfinity = branded<"NegativeInfinity">;
34
38
  type safe = branded<"safe">;
35
- type is<constraints extends Constraints> = constrain<number, constraints>;
39
+ type is<attributes> = of<number, attributes>;
36
40
  type minSchemaToConstraint<schema, rule> = schema extends {
37
41
  exclusive: true;
38
42
  } ? MoreThan<rule> : AtLeast<rule>;
39
43
  type maxSchemaToConstraint<schema, rule> = schema extends {
40
44
  exclusive: true;
41
45
  } ? LessThan<rule> : AtMost<rule>;
42
- type withConstraint<constraint> = constraint extends MoreThan<infer rule> ? moreThan<rule> : constraint extends AtLeast<infer rule> ? atLeast<rule> : constraint extends AtMost<infer rule> ? atMost<rule> : constraint extends LessThan<infer rule> ? lessThan<rule> : constraint extends DivisibleBy<infer rule> ? divisibleBy<rule> : constraint extends Optional ? optional : constraint extends Default<infer rule> ? defaultsTo<rule> : constraint extends Narrowed ? narrowed : never;
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;
43
47
  type module = Module<submodule>;
44
48
  type submodule = Submodule<$>;
45
49
  type $ = {
@@ -1,6 +1,6 @@
1
- import type { Branded, constrain } from "../inference.ts";
1
+ import type { Predicate, of } from "../inference.ts";
2
2
  declare namespace string {
3
- type alpha = constrain<string, Branded<"alpha">>;
3
+ type alpha = of<string, Predicate<"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 { Branded, constrain } from "../inference.ts";
1
+ import type { Predicate, of } from "../inference.ts";
2
2
  declare namespace string {
3
- type alphanumeric = constrain<string, Branded<"alphanumeric">>;
3
+ type alphanumeric = of<string, Predicate<"alphanumeric">>;
4
4
  }
5
5
  export declare const alphanumeric: import("@ark/schema").IntersectionNode;
6
6
  export type alphanumeric = string.alphanumeric;
@@ -0,0 +1,17 @@
1
+ import type { AtLeastLength, AtMostLength, Default, ExactlyLength, LessThanLength, MoreThanLength, Narrowed, Optional, Predicate, brand } from "../inference.ts";
2
+ import type { Matching } from "./string.ts";
3
+ declare namespace string {
4
+ type atLeastLength<rule> = brand<string, AtLeastLength<rule>>;
5
+ type moreThanLength<rule> = brand<string, MoreThanLength<rule>>;
6
+ type atMostLength<rule> = brand<string, AtMostLength<rule>>;
7
+ type lessThanLength<rule> = brand<string, LessThanLength<rule>>;
8
+ type exactlyLength<rule> = brand<string, ExactlyLength<rule>>;
9
+ type matching<rule> = brand<string, Matching<rule>>;
10
+ type narrowed = brand<string, Narrowed>;
11
+ type optional = brand<string, Optional>;
12
+ type defaultsTo<rule> = brand<string, Default<rule>>;
13
+ type branded<rule> = brand<string, Predicate<rule>>;
14
+ type is<attributes> = brand<string, attributes>;
15
+ type applyBrand<attribute> = attribute extends ExactlyLength<infer rule> ? exactlyLength<rule> : attribute extends MoreThanLength<infer rule> ? moreThanLength<rule> : attribute extends AtLeastLength<infer rule> ? atLeastLength<rule> : attribute extends AtMostLength<infer rule> ? atMostLength<rule> : attribute extends LessThanLength<infer rule> ? lessThanLength<rule> : attribute extends Matching<infer rule> ? matching<rule> : attribute extends Optional ? optional : attribute extends Default<infer rule> ? defaultsTo<rule> : attribute extends Predicate<infer rule> ? branded<rule> : never;
16
+ }
17
+ export type { string as brandedString };
@@ -1,7 +1,7 @@
1
1
  import type { Module, Submodule } from "../../module.ts";
2
- import type { Branded, constrain, To } from "../inference.ts";
2
+ import type { of, Predicate, To } from "../inference.ts";
3
3
  declare namespace string {
4
- type capitalized = constrain<string, Branded<"capitalized">>;
4
+ type capitalized = of<string, Predicate<"capitalized">>;
5
5
  }
6
6
  export declare const capitalize: capitalize.module;
7
7
  export declare namespace capitalize {
@@ -1,7 +1,7 @@
1
- import type { Branded, constrain } from "../inference.ts";
1
+ import type { Predicate, of } from "../inference.ts";
2
2
  export declare const isLuhnValid: (creditCardInput: string) => boolean;
3
3
  declare namespace string {
4
- type creditCard = constrain<string, Branded<"creditCard">>;
4
+ type creditCard = of<string, Predicate<"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
1
  import type { Module, Submodule } from "../../module.ts";
2
- import type { Branded, To, constrain } from "../inference.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 = constrain<string, Branded<"date">>;
24
+ type date = of<string, Predicate<"date">>;
25
25
  namespace date {
26
- type epoch = constrain<string, Branded<"date.epoch">>;
27
- type iso = constrain<string, Branded<"date.iso">>;
26
+ type epoch = of<string, Predicate<"date.epoch">>;
27
+ type iso = of<string, Predicate<"date.iso">>;
28
28
  }
29
29
  }
30
30
  export declare const stringDate: stringDate.module;
@@ -1,6 +1,6 @@
1
- import type { Branded, constrain } from "../inference.ts";
1
+ import type { Predicate, of } from "../inference.ts";
2
2
  declare namespace string {
3
- type digits = constrain<string, Branded<"digits">>;
3
+ type digits = of<string, Predicate<"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 { Branded, constrain } from "../inference.ts";
1
+ import type { Predicate, of } from "../inference.ts";
2
2
  declare namespace string {
3
- type email = constrain<string, Branded<"email">>;
3
+ type email = of<string, Predicate<"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
1
  import type { Module, Submodule } from "../../module.ts";
2
- import type { Branded, constrain, To } from "../inference.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 = constrain<string, Branded<"integer">>;
5
+ type integer = of<string, Predicate<"integer">>;
6
6
  }
7
7
  export declare const integer: stringInteger.module;
8
8
  export declare namespace stringInteger {
@@ -1,10 +1,10 @@
1
1
  import type { Module, Submodule } from "../../module.ts";
2
- import type { Branded, constrain } from "../inference.ts";
2
+ import type { Predicate, of } from "../inference.ts";
3
3
  declare namespace string {
4
- type ip = constrain<string, Branded<"ip">>;
4
+ type ip = of<string, Predicate<"ip">>;
5
5
  namespace ip {
6
- type v4 = constrain<string, Branded<"ip.v4">>;
7
- type v6 = constrain<string, Branded<"ip.v6">>;
6
+ type v4 = of<string, Predicate<"ip.v4">>;
7
+ type v6 = of<string, Predicate<"ip.v6">>;
8
8
  }
9
9
  }
10
10
  export declare const ip: ip.module;
@@ -1,7 +1,7 @@
1
1
  import type { Module, Submodule } from "../../module.ts";
2
- import type { Branded, To, constrain } from "../inference.ts";
2
+ import type { Predicate, To, of } from "../inference.ts";
3
3
  declare namespace string {
4
- type json = constrain<string, Branded<"json">>;
4
+ type json = of<string, Predicate<"json">>;
5
5
  }
6
6
  export declare const writeJsonSyntaxErrorProblem: (error: unknown) => string;
7
7
  export declare const json: stringJson.module;
@@ -1,7 +1,7 @@
1
1
  import type { Module, Submodule } from "../../module.ts";
2
- import type { Branded, constrain, To } from "../inference.ts";
2
+ import type { of, Predicate, To } from "../inference.ts";
3
3
  declare namespace string {
4
- type lowercase = constrain<string, Branded<"lowercase">>;
4
+ type lowercase = of<string, Predicate<"lowercase">>;
5
5
  }
6
6
  export declare const lower: lower.module;
7
7
  export declare namespace lower {
@@ -1,12 +1,12 @@
1
1
  import type { Module, Submodule } from "../../module.ts";
2
- import type { Branded, constrain, To } from "../inference.ts";
2
+ import type { of, Predicate, To } from "../inference.ts";
3
3
  declare namespace string {
4
4
  type normalized = normalized.NFC;
5
5
  namespace normalized {
6
- type NFC = constrain<string, Branded<"normalized.NFC">>;
7
- type NFD = constrain<string, Branded<"normalized.NFD">>;
8
- type NFKC = constrain<string, Branded<"normalized.NFKC">>;
9
- type NFKD = constrain<string, Branded<"normalized.NFKD">>;
6
+ type NFC = of<string, Predicate<"normalized.NFC">>;
7
+ type NFD = of<string, Predicate<"normalized.NFD">>;
8
+ type NFKC = of<string, Predicate<"normalized.NFKC">>;
9
+ type NFKD = of<string, Predicate<"normalized.NFKD">>;
10
10
  }
11
11
  }
12
12
  export declare const normalizedForms: readonly ["NFC", "NFD", "NFKC", "NFKD"];
@@ -1,7 +1,7 @@
1
1
  import type { Module, Submodule } from "../../module.ts";
2
- import type { Branded, constrain, To } from "../inference.ts";
2
+ import type { of, Predicate, To } from "../inference.ts";
3
3
  declare namespace string {
4
- type numeric = constrain<string, Branded<"numeric">>;
4
+ type numeric = of<string, Predicate<"numeric">>;
5
5
  }
6
6
  export declare const numeric: stringNumeric.module;
7
7
  export declare namespace stringNumeric {
@@ -1,6 +1,6 @@
1
- import type { Branded, constrain } from "../inference.ts";
1
+ import type { Predicate, of } from "../inference.ts";
2
2
  declare namespace string {
3
- type semver = constrain<string, Branded<"semver">>;
3
+ type semver = of<string, Predicate<"semver">>;
4
4
  }
5
5
  export declare const semver: import("@ark/schema").IntersectionNode;
6
6
  export type semver = string.semver;
@@ -1,5 +1,5 @@
1
1
  import type { Module, Submodule } from "../../module.ts";
2
- import type { AtLeastLength, AtMostLength, Branded, Constraints, Default, ExactlyLength, LessThanLength, MoreThanLength, Narrowed, Optional, constrain, constraint } from "../inference.ts";
2
+ import type { AtLeastLength, AtMostLength, Default, ExactlyLength, LessThanLength, MoreThanLength, Narrowed, Optional, Predicate, constraint, of } from "../inference.ts";
3
3
  import { alpha } from "./alpha.ts";
4
4
  import { alphanumeric } from "./alphanumeric.ts";
5
5
  import { capitalize } from "./capitalize.ts";
@@ -71,18 +71,18 @@ export type Matching<rule> = {
71
71
  matching: constraint<rule>;
72
72
  };
73
73
  export declare namespace string {
74
- type atLeastLength<rule> = constrain<string, AtLeastLength<rule>>;
75
- type moreThanLength<rule> = constrain<string, MoreThanLength<rule>>;
76
- type atMostLength<rule> = constrain<string, AtMostLength<rule>>;
77
- type lessThanLength<rule> = constrain<string, LessThanLength<rule>>;
78
- type exactlyLength<rule> = constrain<string, ExactlyLength<rule>>;
79
- type matching<rule> = constrain<string, Matching<rule>>;
80
- type narrowed = constrain<string, Narrowed>;
81
- type optional = constrain<string, Optional>;
82
- type defaultsTo<rule> = constrain<string, Default<rule>>;
83
- type branded<rule> = constrain<string, Branded<rule>>;
84
- type is<constraints extends Constraints> = constrain<string, constraints>;
85
- type withConstraint<constraint> = constraint extends ExactlyLength<infer rule> ? exactlyLength<rule> : constraint extends MoreThanLength<infer rule> ? moreThanLength<rule> : constraint extends AtLeastLength<infer rule> ? atLeastLength<rule> : constraint extends AtMostLength<infer rule> ? atMostLength<rule> : constraint extends LessThanLength<infer rule> ? lessThanLength<rule> : constraint extends Matching<infer rule> ? matching<rule> : constraint extends Optional ? optional : constraint extends Default<infer rule> ? defaultsTo<rule> : constraint extends Narrowed ? narrowed : never;
74
+ type atLeastLength<rule> = of<string, AtLeastLength<rule>>;
75
+ type moreThanLength<rule> = of<string, MoreThanLength<rule>>;
76
+ type atMostLength<rule> = of<string, AtMostLength<rule>>;
77
+ type lessThanLength<rule> = of<string, LessThanLength<rule>>;
78
+ type exactlyLength<rule> = of<string, ExactlyLength<rule>>;
79
+ type matching<rule> = of<string, Matching<rule>>;
80
+ type narrowed = of<string, Narrowed>;
81
+ type optional = of<string, Optional>;
82
+ type defaultsTo<rule> = of<string, Default<rule>>;
83
+ type branded<rule> = of<string, Predicate<rule>>;
84
+ type is<attributes> = of<string, attributes>;
85
+ type applyAttribute<attribute> = attribute extends ExactlyLength<infer rule> ? exactlyLength<rule> : attribute extends MoreThanLength<infer rule> ? moreThanLength<rule> : attribute extends AtLeastLength<infer rule> ? atLeastLength<rule> : attribute extends AtMostLength<infer rule> ? atMostLength<rule> : attribute extends LessThanLength<infer rule> ? lessThanLength<rule> : attribute extends Matching<infer rule> ? matching<rule> : attribute extends Optional ? optional : attribute extends Default<infer rule> ? defaultsTo<rule> : attribute extends Predicate<infer rule> ? branded<rule> : never;
86
86
  type module = Module<string.submodule>;
87
87
  type submodule = Submodule<$>;
88
88
  type $ = {
@@ -107,3 +107,4 @@ export declare namespace string {
107
107
  upper: upper.submodule;
108
108
  };
109
109
  }
110
+ export type { brandedString } from "./brands.ts";
@@ -1,7 +1,7 @@
1
1
  import type { Module, Submodule } from "../../module.ts";
2
- import type { Branded, constrain, To } from "../inference.ts";
2
+ import type { of, Predicate, To } from "../inference.ts";
3
3
  declare namespace string {
4
- type trimmed = constrain<string, Branded<"trimmed">>;
4
+ type trimmed = of<string, Predicate<"trimmed">>;
5
5
  }
6
6
  export declare const trim: trim.module;
7
7
  export declare namespace trim {
@@ -1,7 +1,7 @@
1
1
  import type { Module, Submodule } from "../../module.ts";
2
- import type { Branded, constrain, To } from "../inference.ts";
2
+ import type { of, Predicate, To } from "../inference.ts";
3
3
  declare namespace string {
4
- type uppercase = constrain<string, Branded<"uppercase">>;
4
+ type uppercase = of<string, Predicate<"uppercase">>;
5
5
  }
6
6
  export declare const upper: upper.module;
7
7
  export declare namespace upper {
@@ -1,7 +1,7 @@
1
1
  import type { Module, Submodule } from "../../module.ts";
2
- import type { Branded, constrain, To } from "../inference.ts";
2
+ import type { of, Predicate, To } from "../inference.ts";
3
3
  declare namespace string {
4
- type url = constrain<string, Branded<"url">>;
4
+ type url = of<string, Predicate<"url">>;
5
5
  }
6
6
  export declare const url: url.module;
7
7
  export declare namespace url {