arktype 2.0.0-rc.11 → 2.0.0-rc.12

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 (43) hide show
  1. package/out/keywords/constructors/Date.d.ts +12 -12
  2. package/out/keywords/inference.d.ts +31 -84
  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/capitalize.d.ts +2 -2
  8. package/out/keywords/string/creditCard.d.ts +2 -2
  9. package/out/keywords/string/date.d.ts +4 -4
  10. package/out/keywords/string/digits.d.ts +2 -2
  11. package/out/keywords/string/email.d.ts +2 -2
  12. package/out/keywords/string/integer.d.ts +2 -2
  13. package/out/keywords/string/ip.d.ts +4 -4
  14. package/out/keywords/string/json.d.ts +2 -2
  15. package/out/keywords/string/lower.d.ts +2 -2
  16. package/out/keywords/string/normalize.d.ts +5 -5
  17. package/out/keywords/string/numeric.d.ts +2 -2
  18. package/out/keywords/string/semver.d.ts +2 -2
  19. package/out/keywords/string/string.d.ts +13 -13
  20. package/out/keywords/string/trim.d.ts +2 -2
  21. package/out/keywords/string/upper.d.ts +2 -2
  22. package/out/keywords/string/url.d.ts +2 -2
  23. package/out/keywords/string/uuid.d.ts +10 -10
  24. package/out/methods/base.d.ts +11 -10
  25. package/out/methods/object.d.ts +3 -6
  26. package/out/parser/ast/default.d.ts +2 -2
  27. package/out/parser/ast/infer.d.ts +5 -6
  28. package/out/parser/ast/validate.d.ts +5 -5
  29. package/out/parser/ast/validate.js +1 -1
  30. package/out/parser/objectLiteral.d.ts +2 -2
  31. package/out/parser/reduce/dynamic.d.ts +1 -2
  32. package/out/parser/shift/operand/unenclosed.d.ts +5 -1
  33. package/out/parser/shift/operand/unenclosed.js +5 -4
  34. package/out/parser/shift/operator/brand.d.ts +6 -0
  35. package/out/parser/shift/operator/brand.js +5 -0
  36. package/out/parser/shift/operator/default.js +4 -1
  37. package/out/parser/shift/operator/operator.d.ts +2 -1
  38. package/out/parser/shift/operator/operator.js +4 -2
  39. package/out/parser/shift/scanner.d.ts +3 -2
  40. package/out/parser/shift/scanner.js +1 -0
  41. package/out/parser/tuple.d.ts +6 -5
  42. package/out/type.d.ts +2 -2
  43. package/package.json +3 -3
@@ -1,4 +1,4 @@
1
- import type { Branded, constrain, constraint, Constraints, Default, Literal, Narrowed, normalizeLimit, Optional } from "../inference.ts";
1
+ import type { Branded, constraint, Default, Literal, Narrowed, normalizeLimit, of, Optional } 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, Branded<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 Branded<infer rule> ? branded<rule> : never;
32
32
  }
@@ -1,5 +1,5 @@
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";
@@ -16,10 +16,15 @@ export type ConstraintSet = Record<PropertyKey, 1>;
16
16
  export type Constraints = Record<string, ConstraintSet> | {
17
17
  default?: unknown;
18
18
  };
19
- export declare const constrained: " arkConstrained";
20
- export type constrained = typeof constrained;
21
- export type constrain<base, constraints extends Constraints> = base & {
22
- [constrained]: constraints;
19
+ export interface BaseAttributes {
20
+ predicate?: dict<1>;
21
+ default?: unknown;
22
+ optional?: 1;
23
+ }
24
+ export declare const attributes: " arkAttributes";
25
+ export type attributes = typeof attributes;
26
+ export type of<base, attributes> = base & {
27
+ [attributes]: [base, attributes];
23
28
  };
24
29
  export type LimitLiteral = number | DateLiteral;
25
30
  export type normalizeLimit<limit> = limit extends DateLiteral<infer source> ? source : limit extends number | string ? limit : never;
@@ -54,39 +59,12 @@ export type ExactlyLength<rule> = {
54
59
  atLeastLength: constraint<rule>;
55
60
  atMostLength: constraint<rule>;
56
61
  };
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
- ]) ? [
62
+ export type applyConstraintSchema<t, kind extends Constraint.PrimitiveKind, schema extends NodeSchema<kind>> = applyAttribute<t, schemaToConstraint<kind, schema>>;
63
+ export type applyAttribute<t, attribute> = t extends InferredMorph<infer i, infer o> ? (In: leftIfEqual<i, _applyAttribute<i, attribute>>) => o : leftIfEqual<t, _applyAttribute<t, attribute>>;
64
+ type _applyAttribute<t, attribute> = t extends null | undefined ? t : t extends of<infer base, infer attributes> ? [
63
65
  number,
64
66
  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;
67
+ ] extends [base, number] ? number.is<attribute & attributes> : [string, base] extends [base, string] ? 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] ? string.applyAttribute<attribute> : [Date, t] extends [t, Date] ? Date.applyAttribute<attribute> : of<t, conform<attribute, Constraints>>;
90
68
  export type normalizePrimitiveConstraintRoot<schema extends NodeSchema<Constraint.PrimitiveKind>> = "rule" extends keyof schema ? conform<schema["rule"], PropertyKey> : conform<schema, PropertyKey>;
91
69
  type minLengthSchemaToConstraint<schema, rule> = schema extends {
92
70
  exclusive: true;
@@ -132,29 +110,7 @@ export declare namespace distill {
132
110
  }
133
111
  }
134
112
  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;
113
+ 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> : _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;
158
114
  type distillMappable<o, opts extends distill.Options> = opts["endpoint"] extends "in" ? show<{
159
115
  [k in keyof o as k extends inferredOptionalOrDefaultKeyOf<o> ? never : k]: _distill<o[k], opts>;
160
116
  } & {
@@ -164,19 +120,18 @@ type distillMappable<o, opts extends distill.Options> = opts["endpoint"] extends
164
120
  } & {
165
121
  [k in keyof o as k extends inferredOptionalKeyOf<o> ? k : never]?: _distill<o[k], opts>;
166
122
  }>;
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>;
123
+ type distillUnbrandedIo<t extends InferredMorph, i, o extends Out, opts extends distill.Options> = t extends (InferredMorph<of<infer constrainedIn, any>, Out<of<infer constrainedOut, any>>>) ? distillIo<constrainedIn, o extends To ? To<constrainedOut> : Out<constrainedOut>, opts> : t extends InferredMorph<of<infer constrainedIn, any>> ? distillIo<constrainedIn, o, opts> : t extends InferredMorph<any, Out<of<infer constrainedOut, any>>> ? distillIo<i, o extends To ? To<constrainedOut> : Out<constrainedOut>, opts> : distillIo<i, o, opts>;
168
124
  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
125
  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;
126
+ type inOfValueExtends<v, t> = [
127
+ v
128
+ ] extends [anyOrNever] ? false : [v] extends [t] ? true : [v] extends [InferredMorph<infer i>] ? inOfValueExtends<i, t> : false;
129
+ type inferredDefaultKeyOf<o> = keyof o extends infer k ? k extends keyof o ? inOfValueExtends<o[k], InferredDefault> extends true ? k : never : never : never;
130
+ type inferredOptionalKeyOf<o> = keyof o extends infer k ? k extends keyof o ? inOfValueExtends<o[k], InferredOptional> extends true ? k : never : never : never;
176
131
  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
132
  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];
133
+ type distillNonArraykeys<originalArray extends array, distilledArray, opts extends distill.Options> = keyof originalArray extends keyof distilledArray | attributes ? distilledArray : distilledArray & _distill<{
134
+ [k in keyof originalArray as k extends (keyof distilledArray | (opts["branded"] extends true ? never : attributes)) ? never : k]: originalArray[k];
180
135
  }, opts>;
181
136
  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
137
  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 +140,30 @@ type distillPostfix<t extends array, opts extends distill.Options, postfix exten
185
140
  type BuiltinTerminalObjectKind = Exclude<keyof arkPrototypes.instances, "Array" | "Function">;
186
141
  /** Objects we don't want to expand during inference like Date or Promise */
187
142
  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>;
143
+ 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>;
144
+ export type constrainWithPredicate<t> = t extends of<unknown, infer constraints> ? applyConstraintSchema<of<t, constraints>, "predicate", any> : applyConstraintSchema<t, "predicate", any>;
190
145
  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
146
  export type inferMorphOut<morph extends Morph> = Exclude<ReturnType<morph>, ArkError | ArkErrors>;
192
147
  export type Out<o = any> = ["=>", o, boolean];
193
148
  export type To<o = any> = ["=>", o, true];
194
149
  export type InferredMorph<i = any, o extends Out = Out> = (In: i) => o;
195
150
  export type Optional = {
196
- optional?: {};
151
+ optional: {};
197
152
  };
198
- export type InferredOptional<t = unknown> = constrain<t, Optional>;
153
+ export type InferredOptional<t = unknown> = of<t, Optional>;
199
154
  export type Default<v = any> = {
200
- default?: {
155
+ default: {
201
156
  value: v;
202
157
  };
203
158
  };
204
- export type InferredDefault<t = unknown, v = any> = constrain<t, Default<v>>;
159
+ export type DefaultFor<t> = (Primitive extends t ? Primitive : t extends Primitive ? t : never) | (() => t);
160
+ export type InferredDefault<t = unknown, v = any> = of<t, Default<v>>;
205
161
  export type termOrType<t> = t | Type<t, any>;
206
162
  export type inferIntersection<l, r> = _inferIntersection<l, r, false>;
207
163
  export type inferPipe<l, r> = _inferIntersection<l, r, true>;
208
164
  type _inferIntersection<l, r, piped extends boolean> = [
209
165
  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;
166
+ ] 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
167
  interface MorphableIntersection<piped extends boolean> extends Hkt<[unknown, unknown]> {
221
168
  body: _inferIntersection<this[0], this[1], piped>;
222
169
  }
@@ -1,2 +1,2 @@
1
1
  import { noSuggest } from "@ark/util";
2
- export const constrained = noSuggest("arkConstrained");
2
+ export const attributes = noSuggest("arkAttributes");
@@ -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, Branded, constraint, Default, Narrowed, of, Optional } 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, Branded<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 Branded<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 { Branded, of } from "../inference.ts";
2
2
  declare namespace string {
3
- type alpha = constrain<string, Branded<"alpha">>;
3
+ type alpha = of<string, Branded<"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 { Branded, of } from "../inference.ts";
2
2
  declare namespace string {
3
- type alphanumeric = constrain<string, Branded<"alphanumeric">>;
3
+ type alphanumeric = of<string, Branded<"alphanumeric">>;
4
4
  }
5
5
  export declare const alphanumeric: import("@ark/schema").IntersectionNode;
6
6
  export type alphanumeric = string.alphanumeric;
@@ -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 { Branded, of, To } from "../inference.ts";
3
3
  declare namespace string {
4
- type capitalized = constrain<string, Branded<"capitalized">>;
4
+ type capitalized = of<string, Branded<"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 { Branded, 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, Branded<"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 { Branded, 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, Branded<"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, Branded<"date.epoch">>;
27
+ type iso = of<string, Branded<"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 { Branded, of } from "../inference.ts";
2
2
  declare namespace string {
3
- type digits = constrain<string, Branded<"digits">>;
3
+ type digits = of<string, Branded<"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 { Branded, of } from "../inference.ts";
2
2
  declare namespace string {
3
- type email = constrain<string, Branded<"email">>;
3
+ type email = of<string, Branded<"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 { Branded, of, 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, Branded<"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 { Branded, of } from "../inference.ts";
3
3
  declare namespace string {
4
- type ip = constrain<string, Branded<"ip">>;
4
+ type ip = of<string, Branded<"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, Branded<"ip.v4">>;
7
+ type v6 = of<string, Branded<"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 { Branded, To, of } from "../inference.ts";
3
3
  declare namespace string {
4
- type json = constrain<string, Branded<"json">>;
4
+ type json = of<string, Branded<"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 { Branded, of, To } from "../inference.ts";
3
3
  declare namespace string {
4
- type lowercase = constrain<string, Branded<"lowercase">>;
4
+ type lowercase = of<string, Branded<"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 { Branded, of, 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, Branded<"normalized.NFC">>;
7
+ type NFD = of<string, Branded<"normalized.NFD">>;
8
+ type NFKC = of<string, Branded<"normalized.NFKC">>;
9
+ type NFKD = of<string, Branded<"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 { Branded, of, To } from "../inference.ts";
3
3
  declare namespace string {
4
- type numeric = constrain<string, Branded<"numeric">>;
4
+ type numeric = of<string, Branded<"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 { Branded, of } from "../inference.ts";
2
2
  declare namespace string {
3
- type semver = constrain<string, Branded<"semver">>;
3
+ type semver = of<string, Branded<"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, Branded, Default, ExactlyLength, LessThanLength, MoreThanLength, Narrowed, Optional, 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, Branded<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 Branded<infer rule> ? branded<rule> : never;
86
86
  type module = Module<string.submodule>;
87
87
  type submodule = Submodule<$>;
88
88
  type $ = {
@@ -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 { Branded, of, To } from "../inference.ts";
3
3
  declare namespace string {
4
- type trimmed = constrain<string, Branded<"trimmed">>;
4
+ type trimmed = of<string, Branded<"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 { Branded, of, To } from "../inference.ts";
3
3
  declare namespace string {
4
- type uppercase = constrain<string, Branded<"uppercase">>;
4
+ type uppercase = of<string, Branded<"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 { Branded, of, To } from "../inference.ts";
3
3
  declare namespace string {
4
- type url = constrain<string, Branded<"url">>;
4
+ type url = of<string, Branded<"url">>;
5
5
  }
6
6
  export declare const url: url.module;
7
7
  export declare namespace url {
@@ -1,5 +1,5 @@
1
1
  import type { Module, Submodule } from "../../module.ts";
2
- import type { Branded, constrain } from "../inference.ts";
2
+ import type { Branded, of } from "../inference.ts";
3
3
  export declare const uuid: Module<{
4
4
  root: import("./string.ts").string.matching<string> | "00000000-0000-0000-0000-000000000000" | "ffffffff-ffff-ffff-ffff-ffffffffffff";
5
5
  v4: unknown;
@@ -12,16 +12,16 @@ export declare const uuid: Module<{
12
12
  v8: unknown;
13
13
  }>;
14
14
  declare namespace string {
15
- type uuid = constrain<string, Branded<"uuid">>;
15
+ type uuid = of<string, Branded<"uuid">>;
16
16
  namespace uuid {
17
- type v1 = constrain<string, Branded<"uuid.v1">>;
18
- type v2 = constrain<string, Branded<"uuid.v2">>;
19
- type v3 = constrain<string, Branded<"uuid.v3">>;
20
- type v4 = constrain<string, Branded<"uuid.v4">>;
21
- type v5 = constrain<string, Branded<"uuid.v5">>;
22
- type v6 = constrain<string, Branded<"uuid.v6">>;
23
- type v7 = constrain<string, Branded<"uuid.v7">>;
24
- type v8 = constrain<string, Branded<"uuid.v8">>;
17
+ type v1 = of<string, Branded<"uuid.v1">>;
18
+ type v2 = of<string, Branded<"uuid.v2">>;
19
+ type v3 = of<string, Branded<"uuid.v3">>;
20
+ type v4 = of<string, Branded<"uuid.v4">>;
21
+ type v5 = of<string, Branded<"uuid.v5">>;
22
+ type v6 = of<string, Branded<"uuid.v6">>;
23
+ type v7 = of<string, Branded<"uuid.v7">>;
24
+ type v8 = of<string, Branded<"uuid.v8">>;
25
25
  }
26
26
  }
27
27
  export declare namespace uuid {
@@ -1,7 +1,7 @@
1
1
  import type { ArkErrors, BaseRoot, Disjoint, JsonSchema, MetaSchema, Morph, UndeclaredKeyBehavior } from "@ark/schema";
2
2
  import type { anyOrNever, array, Callable, ErrorMessage, inferred, Json, unset } from "@ark/util";
3
3
  import type { ArkAmbient } from "../config.ts";
4
- import type { applyConstraint, Default, distill, inferIntersection, inferMorphOut, inferPipes, InferredMorph, Optional, To } from "../keywords/inference.ts";
4
+ import type { applyAttribute, Branded, Default, DefaultFor, distill, inferIntersection, inferMorphOut, inferPipes, InferredMorph, Optional, To } from "../keywords/inference.ts";
5
5
  import type { type } from "../keywords/keywords.ts";
6
6
  import type { Scope } from "../scope.ts";
7
7
  import type { ArrayType } from "./array.ts";
@@ -37,6 +37,7 @@ interface Type<out t = unknown, $ = {}> extends Callable<(data: unknown) => dist
37
37
  onDeepUndeclaredKey(behavior: UndeclaredKeyBehavior): this;
38
38
  from(literal: this["inferIn"]): this["infer"];
39
39
  as<t = unset>(...args: validateChainedAsArgs<t>): instantiateType<t, $>;
40
+ brand<const name extends string, r = applyAttribute<t, Branded<name>> extends infer r ? instantiateType<r, $> : never>(name: name): r;
40
41
  get in(): instantiateType<this["inferBrandableIn"], $>;
41
42
  get out(): instantiateType<this["inferIntrospectableOut"], $>;
42
43
  intersect<const def>(def: type.validate<def, $>): type.infer<def, $> extends infer r ? instantiateType<inferIntersection<t, r>, $> | Disjoint : never;
@@ -52,8 +53,8 @@ interface Type<out t = unknown, $ = {}> extends Callable<(data: unknown) => dist
52
53
  extract<const def>(r: type.validate<def, $>): type.infer<def, $> extends infer r ? instantiateType<Extract<t, r>, $> : never;
53
54
  exclude<const def>(r: type.validate<def, $>): type.infer<def, $> extends infer r ? instantiateType<Exclude<t, r>, $> : never;
54
55
  distribute<mapOut, reduceOut = mapOut[]>(mapBranch: (branch: Type, i: number, branches: array<Type>) => mapOut, reduceMapped?: (mappedBranches: mapOut[]) => reduceOut): NoInfer<reduceOut>;
55
- optional<r = applyConstraint<t, Optional>>(): instantiateType<r, $>;
56
- default<const value extends this["inferIn"], r = applyConstraint<t, Default<value>>>(value: value): instantiateType<r, $>;
56
+ optional<r = applyAttribute<t, Optional>>(): instantiateType<r, $>;
57
+ default<const value extends this["inferIn"], r = applyAttribute<t, Default<value>>>(value: DefaultFor<value>): NoInfer<instantiateType<r, $>> extends infer result ? result : never;
57
58
  /** @deprecated */
58
59
  apply: Function["apply"];
59
60
  /** @deprecated */
@@ -74,13 +75,13 @@ interface Type<out t = unknown, $ = {}> extends Callable<(data: unknown) => dist
74
75
  Symbol: never;
75
76
  }
76
77
  interface ChainedPipeSignature<t, $> {
77
- <a extends Morph<distill.Out<t>>, r = instantiateType<inferPipes<t, [a]>, $>>(a: a): NoInfer<r>;
78
- <a extends Morph<distill.Out<t>>, b extends Morph<inferMorphOut<a>>, r = instantiateType<inferPipes<t, [a, b]>, $>>(a: a, b: b): NoInfer<r>;
79
- <a extends Morph<distill.Out<t>>, b extends Morph<inferMorphOut<a>>, c extends Morph<inferMorphOut<b>>, r = instantiateType<inferPipes<t, [a, b, c]>, $>>(a: a, b: b, c: c): NoInfer<r>;
80
- <a extends Morph<distill.Out<t>>, b extends Morph<inferMorphOut<a>>, c extends Morph<inferMorphOut<b>>, d extends Morph<inferMorphOut<c>>, r = instantiateType<inferPipes<t, [a, b, c, d]>, $>>(a: a, b: b, c: c, d: d): NoInfer<r>;
81
- <a extends Morph<distill.Out<t>>, b extends Morph<inferMorphOut<a>>, c extends Morph<inferMorphOut<b>>, d extends Morph<inferMorphOut<c>>, e extends Morph<inferMorphOut<d>>, r = instantiateType<inferPipes<t, [a, b, c, d, e]>, $>>(a: a, b: b, c: c, d: d, e: e): NoInfer<r>;
82
- <a extends Morph<distill.Out<t>>, b extends Morph<inferMorphOut<a>>, c extends Morph<inferMorphOut<b>>, d extends Morph<inferMorphOut<c>>, e extends Morph<inferMorphOut<d>>, f extends Morph<inferMorphOut<e>>, r = instantiateType<inferPipes<t, [a, b, c, d, e, f]>, $>>(a: a, b: b, c: c, d: d, e: e, f: f): NoInfer<r>;
83
- <a extends Morph<distill.Out<t>>, b extends Morph<inferMorphOut<a>>, c extends Morph<inferMorphOut<b>>, d extends Morph<inferMorphOut<c>>, e extends Morph<inferMorphOut<d>>, f extends Morph<inferMorphOut<e>>, g extends Morph<inferMorphOut<f>>, r = instantiateType<inferPipes<t, [a, b, c, d, e, f, g]>, $>>(a: a, b: b, c: c, d: d, e: e, f: f, g: g): NoInfer<r>;
78
+ <a extends Morph<distill.Out<t>>, r = instantiateType<inferPipes<t, [a]>, $>>(a: a): NoInfer<r> extends infer result ? result : never;
79
+ <a extends Morph<distill.Out<t>>, b extends Morph<inferMorphOut<a>>, r = instantiateType<inferPipes<t, [a, b]>, $>>(a: a, b: b): NoInfer<r> extends infer result ? result : never;
80
+ <a extends Morph<distill.Out<t>>, b extends Morph<inferMorphOut<a>>, c extends Morph<inferMorphOut<b>>, r = instantiateType<inferPipes<t, [a, b, c]>, $>>(a: a, b: b, c: c): NoInfer<r> extends infer result ? result : never;
81
+ <a extends Morph<distill.Out<t>>, b extends Morph<inferMorphOut<a>>, c extends Morph<inferMorphOut<b>>, d extends Morph<inferMorphOut<c>>, r = instantiateType<inferPipes<t, [a, b, c, d]>, $>>(a: a, b: b, c: c, d: d): NoInfer<r> extends infer result ? result : never;
82
+ <a extends Morph<distill.Out<t>>, b extends Morph<inferMorphOut<a>>, c extends Morph<inferMorphOut<b>>, d extends Morph<inferMorphOut<c>>, e extends Morph<inferMorphOut<d>>, r = instantiateType<inferPipes<t, [a, b, c, d, e]>, $>>(a: a, b: b, c: c, d: d, e: e): NoInfer<r> extends infer result ? result : never;
83
+ <a extends Morph<distill.Out<t>>, b extends Morph<inferMorphOut<a>>, c extends Morph<inferMorphOut<b>>, d extends Morph<inferMorphOut<c>>, e extends Morph<inferMorphOut<d>>, f extends Morph<inferMorphOut<e>>, r = instantiateType<inferPipes<t, [a, b, c, d, e, f]>, $>>(a: a, b: b, c: c, d: d, e: e, f: f): NoInfer<r> extends infer result ? result : never;
84
+ <a extends Morph<distill.Out<t>>, b extends Morph<inferMorphOut<a>>, c extends Morph<inferMorphOut<b>>, d extends Morph<inferMorphOut<c>>, e extends Morph<inferMorphOut<d>>, f extends Morph<inferMorphOut<e>>, g extends Morph<inferMorphOut<f>>, r = instantiateType<inferPipes<t, [a, b, c, d, e, f, g]>, $>>(a: a, b: b, c: c, d: d, e: e, f: f, g: g): NoInfer<r> extends infer result ? result : never;
84
85
  }
85
86
  export interface ChainedPipes<t, $> extends ChainedPipeSignature<t, $> {
86
87
  try: ChainedPipeSignature<t, $>;
@@ -1,6 +1,6 @@
1
1
  import type { BaseMappedPropInner, OptionalMappedPropInner, Prop } from "@ark/schema";
2
2
  import type { arkGet, arkIndexableOf, arkKeyOf, array, ErrorType, inferred, intersectUnion, Json, Key, listable, merge, optionalKeyOf, show, toArkKey } from "@ark/util";
3
- import type { applyConstraint, constrain, Default, Optional, parseConstraints } from "../keywords/inference.ts";
3
+ import type { applyAttribute, Default, of, Optional } from "../keywords/inference.ts";
4
4
  import type { type } from "../keywords/keywords.ts";
5
5
  import type { ArrayType } from "./array.ts";
6
6
  import type { instantiateType } from "./instantiate.ts";
@@ -33,10 +33,7 @@ interface Type<out t extends object = object, $ = {}> extends ValidatorType<t, $
33
33
  props: array<typePropOf<t, $>>;
34
34
  }
35
35
  type typePropOf<o, $> = keyof o extends infer k ? k extends keyof o ? typeProp<o, k, $> : never : never;
36
- type typeProp<o, k extends keyof o, $, t = o[k] & ({} | null)> = parseConstraints<t> extends ([
37
- infer base,
38
- infer constraints extends Default | Optional
39
- ]) ? constraints extends Default<infer defaultValue> ? DefaultedTypeProp<k & Key, keyof constraints extends keyof Default ? base : constrain<base, Omit<constraints, keyof Default>>, defaultValue, $> : constraints extends Optional ? BaseTypeProp<"optional", k & Key, keyof constraints extends keyof Optional ? base : constrain<base, Omit<constraints, keyof Optional>>, $> : never : BaseTypeProp<k extends optionalKeyOf<o> ? "optional" : "required", k & Key, t, $>;
36
+ type typeProp<o, k extends keyof o, $, t = o[k] & ({} | null)> = t extends of<infer base, infer attributes> ? attributes extends Default<infer defaultValue> ? DefaultedTypeProp<k & Key, keyof attributes extends keyof Default ? base : of<base, Omit<attributes, keyof Default>>, defaultValue, $> : attributes extends Optional ? BaseTypeProp<"optional", k & Key, keyof attributes extends keyof Optional ? base : of<base, Omit<attributes, keyof Optional>>, $> : never : BaseTypeProp<k extends optionalKeyOf<o> ? "optional" : "required", k & Key, t, $>;
40
37
  export interface BaseTypeProp<kind extends Prop.Kind = Prop.Kind, k extends Key = Key,
41
38
  /** @ts-ignore cast variance */
42
39
  out v = unknown, $ = {}> {
@@ -73,7 +70,7 @@ type fromTypeProps<t, props extends array<MappedTypeProp>> = show<{
73
70
  [prop in props[number] as Extract<applyHomomorphicOptionality<t, prop>, {
74
71
  kind: "optional";
75
72
  default: unknown;
76
- }>["key"]]: applyConstraint<prop["value"][inferred], Default<prop["default" & keyof prop]>>;
73
+ }>["key"]]: applyAttribute<prop["value"][inferred], Default<prop["default" & keyof prop]>>;
77
74
  }>;
78
75
  type applyHomomorphicOptionality<t, prop extends MappedTypeProp> = prop["kind"] extends string ? prop : prop & {
79
76
  kind: prop["key"] extends optionalKeyOf<t> ? "optional" : "required";
@@ -2,7 +2,7 @@ import type { writeUnassignableDefaultValueMessage } from "@ark/schema";
2
2
  import type { ErrorMessage } from "@ark/util";
3
3
  import type { type } from "../../keywords/keywords.ts";
4
4
  import type { UnitLiteral } from "../shift/operator/default.ts";
5
- import type { inferAstOut } from "./infer.ts";
5
+ import type { inferAstIn } from "./infer.ts";
6
6
  import type { astToString } from "./utils.ts";
7
7
  import type { validateAst } from "./validate.ts";
8
- export type validateDefault<baseAst, unitLiteral extends UnitLiteral, $, args> = validateAst<baseAst, $, args> extends infer e extends ErrorMessage ? e : type.infer<unitLiteral> extends inferAstOut<baseAst, $, args> ? undefined : ErrorMessage<writeUnassignableDefaultValueMessage<astToString<baseAst>, unitLiteral>>;
8
+ export type validateDefault<baseAst, unitLiteral extends UnitLiteral, $, args> = validateAst<baseAst, $, args> extends infer e extends ErrorMessage ? e : type.infer<unitLiteral> extends inferAstIn<baseAst, $, args> ? undefined : ErrorMessage<writeUnassignableDefaultValueMessage<astToString<baseAst>, unitLiteral>>;
@@ -1,11 +1,12 @@
1
1
  import type { GenericAst } from "@ark/schema";
2
2
  import type { Hkt, arkKeyOf, array } from "@ark/util";
3
3
  import type { Date } from "../../keywords/constructors/Date.ts";
4
- import type { Default, LimitLiteral, Optional, applyConstraint, applyConstraintSchema, distill, inferIntersection, normalizeLimit } from "../../keywords/inference.ts";
4
+ import type { Branded, Default, LimitLiteral, Optional, applyAttribute, applyConstraintSchema, distill, inferIntersection, normalizeLimit } from "../../keywords/inference.ts";
5
5
  import type { type } from "../../keywords/keywords.ts";
6
6
  import type { UnparsedScope } from "../../scope.ts";
7
7
  import type { inferDefinition } from "../definition.ts";
8
8
  import type { Comparator, MinComparator } from "../reduce/shared.ts";
9
+ import type { Scanner } from "../shift/scanner.ts";
9
10
  export type inferAstRoot<ast, $, args> = ast extends array ? inferExpression<ast, $, args> : never;
10
11
  export type inferAstIn<ast, $, args> = distill.In<inferAstRoot<ast, $, args>>;
11
12
  export type inferAstOut<ast, $, args> = distill.Out<inferAstRoot<ast, $, args>>;
@@ -25,15 +26,13 @@ export type inferExpression<ast, $, args> = ast extends array ? ast extends Infe
25
26
  [i in keyof argAsts]: inferExpression<argAsts[i], $, args>;
26
27
  }> : inferDefinition<g["bodyDef"], resolveScope<g["$"], $>, {
27
28
  [i in keyof g["names"] & `${number}` as g["names"][i]]: inferExpression<argAsts[i & keyof argAsts], resolveScope<g["arg$"], $>, args>;
28
- }> : ast[1] extends "[]" ? inferExpression<ast[0], $, args>[] : ast[1] extends "|" ? inferExpression<ast[0], $, args> | inferExpression<ast[2], $, args> : ast[1] extends "&" ? inferIntersection<inferExpression<ast[0], $, args>, inferExpression<ast[2], $, args>> : ast[1] extends "=" ? type.infer<ast[2]> extends infer defaultValue ? applyConstraint<inferExpression<ast[0], $, args>, Default<defaultValue>> : never : ast[1] extends Comparator ? ast[0] extends LimitLiteral ? brandBound<inferExpression<ast[2], $, args>, ast[1], ast[0]> : brandBound<inferExpression<ast[0], $, args>, ast[1], ast[2] & LimitLiteral> : ast[1] extends "%" ? applyConstraintSchema<inferExpression<ast[0], $, args>, "divisor", ast[2] & number> : ast[1] extends "?" ? applyConstraint<inferExpression<ast[0], $, args>, Optional> : ast[0] extends "keyof" ? arkKeyOf<inferExpression<ast[1], $, args>> : never : never;
29
+ }> : ast[1] extends "[]" ? inferExpression<ast[0], $, args>[] : ast[1] extends "|" ? inferExpression<ast[0], $, args> | inferExpression<ast[2], $, args> : ast[1] extends "&" ? inferIntersection<inferExpression<ast[0], $, args>, inferExpression<ast[2], $, args>> : ast[1] extends "=" ? type.infer<ast[2]> extends infer defaultValue ? applyAttribute<inferExpression<ast[0], $, args>, Default<defaultValue>> : never : ast[1] extends "#" ? applyAttribute<inferExpression<ast[0], $, args>, Branded<ast[2]>> : ast[1] extends Comparator ? ast[0] extends LimitLiteral ? brandBound<inferExpression<ast[2], $, args>, ast[1], ast[0]> : brandBound<inferExpression<ast[0], $, args>, ast[1], ast[2] & LimitLiteral> : ast[1] extends "%" ? applyConstraintSchema<inferExpression<ast[0], $, args>, "divisor", ast[2] & number> : ast[1] extends "?" ? applyAttribute<inferExpression<ast[0], $, args>, Optional> : ast[0] extends "keyof" ? arkKeyOf<inferExpression<ast[1], $, args>> : never : never;
29
30
  export type brandBound<brandableIn, comparator extends Comparator, limit extends LimitLiteral> = distill.In<brandableIn> extends infer In ? comparator extends "==" ? In extends number ? limit : In extends Date ? Date.literal<normalizeLimit<limit>> : applyConstraintSchema<brandableIn, "exactLength", limit & number> : applyConstraintSchema<brandableIn, In extends number ? comparator extends MinComparator ? "min" : "max" : In extends string | array ? comparator extends MinComparator ? "minLength" : "maxLength" : comparator extends MinComparator ? "after" : "before", {
30
31
  rule: normalizeLimit<limit>;
31
32
  exclusive: comparator extends ">" | "<" ? true : false;
32
33
  }> : never;
33
34
  export type PrefixOperator = "keyof" | "instanceof" | "===" | "node";
34
35
  export type PrefixExpression<operator extends PrefixOperator = PrefixOperator, operand = unknown> = [operator, operand];
35
- export type PostfixOperator = "[]" | "?";
36
- export type PostfixExpression<operator extends PostfixOperator = PostfixOperator, operand = unknown> = readonly [operand, operator];
37
- export type InfixOperator = "|" | "&" | Comparator | "%" | ":" | "=>" | "@" | "=";
38
- export type InfixExpression<operator extends InfixOperator = InfixOperator, l = unknown, r = unknown> = [l, operator, r];
36
+ export type PostfixExpression<operator extends Scanner.PostfixToken = Scanner.PostfixToken, operand = unknown> = readonly [operand, operator];
37
+ export type InfixExpression<operator extends Scanner.InfixToken = Scanner.InfixToken, l = unknown, r = unknown> = [l, operator, r];
39
38
  export {};
@@ -1,5 +1,5 @@
1
1
  import type { arkKind, GenericParamAst, PrivateDeclaration, writeMissingSubmoduleAccessMessage, writeUnsatisfiedParameterConstraintMessage } from "@ark/schema";
2
- import type { anyOrNever, array, BigintLiteral, charsAfterFirst, Completion, ErrorMessage, NumberLiteral, typeToString, writeMalformedNumericLiteralMessage } from "@ark/util";
2
+ import type { anyOrNever, array, BigintLiteral, Completion, ErrorMessage, NumberLiteral, typeToString, writeMalformedNumericLiteralMessage } from "@ark/util";
3
3
  import type { Generic } from "../../generic.ts";
4
4
  import type { Comparator } from "../reduce/shared.ts";
5
5
  import type { writeInvalidGenericArgCountMessage } from "../shift/operand/genericArgs.ts";
@@ -11,14 +11,14 @@ import type { validateDivisor } from "./divisor.ts";
11
11
  import type { DefAst, GenericInstantiationAst, inferAstRoot, InferredAst, InfixExpression, PostfixExpression } from "./infer.ts";
12
12
  import type { validateKeyof } from "./keyof.ts";
13
13
  import type { astToString } from "./utils.ts";
14
- export type validateAst<ast, $, args> = ast extends ErrorMessage ? ast : ast extends InferredAst ? validateInferredAst<ast[0], ast[2]> : ast extends DefAst ? ast[2] extends PrivateDeclaration ? ErrorMessage<writePrefixedPrivateReferenceMessage<ast[2]>> : undefined : ast extends PostfixExpression<infer operator, infer operand> ? operator extends "[]" ? validateAst<operand, $, args> : operator extends "?" ? validateAst<operand, $, args> : never : ast extends InfixExpression<infer operator, infer l, infer r> ? operator extends "&" | "|" ? validateInfix<ast, $, args> : operator extends Comparator ? validateRange<l, operator, r, $, args> : operator extends "%" ? validateDivisor<l, $, args> : operator extends "=" ? validateDefault<l, r & UnitLiteral, $, args> : never : ast extends ["keyof", infer operand] ? validateKeyof<operand, $, args> : ast extends GenericInstantiationAst<infer g, infer argAsts> ? validateGenericArgs<g["paramsAst"], argAsts, $, args, []> : ErrorMessage<writeUnexpectedExpressionMessage<astToString<ast>>> & {
14
+ export type validateAst<ast, $, args> = ast extends ErrorMessage ? ast : ast extends InferredAst ? validateInferredAst<ast[0], ast[2]> : ast extends DefAst ? ast[2] extends PrivateDeclaration<infer name> ? ErrorMessage<writePrefixedPrivateReferenceMessage<name>> : undefined : ast extends PostfixExpression<infer operator, infer operand> ? operator extends "[]" ? validateAst<operand, $, args> : operator extends "?" ? validateAst<operand, $, args> : never : ast extends InfixExpression<infer operator, infer l, infer r> ? operator extends "&" | "|" ? validateInfix<ast, $, args> : operator extends Comparator ? validateRange<l, operator, r, $, args> : operator extends "%" ? validateDivisor<l, $, args> : operator extends "=" ? validateDefault<l, r & UnitLiteral, $, args> : operator extends "#" ? validateAst<l, $, args> : ErrorMessage<writeUnexpectedExpressionMessage<astToString<ast>>> : ast extends ["keyof", infer operand] ? validateKeyof<operand, $, args> : ast extends GenericInstantiationAst<infer g, infer argAsts> ? validateGenericArgs<g["paramsAst"], argAsts, $, args, []> : ErrorMessage<writeUnexpectedExpressionMessage<astToString<ast>>> & {
15
15
  ast: ast;
16
16
  };
17
17
  type writeUnexpectedExpressionMessage<expression extends string> = `Unexpectedly failed to parse the expression resulting from ${expression}`;
18
18
  type validateGenericArgs<params extends array<GenericParamAst>, argAsts extends array, $, args, indices extends 1[]> = argAsts extends readonly [infer arg, ...infer argsTail] ? validateAst<arg, $, args> extends infer e extends ErrorMessage ? e : inferAstRoot<arg, $, args> extends params[indices["length"]][1] ? validateGenericArgs<params, argsTail, $, args, [...indices, 1]> : ErrorMessage<writeUnsatisfiedParameterConstraintMessage<params[indices["length"]][0], typeToString<params[indices["length"]][1]>, astToString<arg>>> : undefined;
19
- export declare const writePrefixedPrivateReferenceMessage: <def extends PrivateDeclaration>(def: def) => writePrefixedPrivateReferenceMessage<def>;
20
- export type writePrefixedPrivateReferenceMessage<def extends PrivateDeclaration> = `Private type references should not include '#'. Use '${charsAfterFirst<def>}' instead.`;
21
- type validateInferredAst<inferred, def extends string> = def extends NumberLiteral ? number extends inferred ? ErrorMessage<writeMalformedNumericLiteralMessage<def, "number">> : undefined : def extends BigintLiteral ? bigint extends inferred ? ErrorMessage<writeMalformedNumericLiteralMessage<def, "bigint">> : undefined : [inferred] extends [anyOrNever] ? undefined : def extends PrivateDeclaration ? ErrorMessage<writePrefixedPrivateReferenceMessage<def>> : inferred extends Generic ? ErrorMessage<writeInvalidGenericArgCountMessage<def, inferred["names"], []>> : inferred extends {
19
+ export declare const writePrefixedPrivateReferenceMessage: <name extends string>(name: name) => writePrefixedPrivateReferenceMessage<name>;
20
+ export type writePrefixedPrivateReferenceMessage<name extends string> = `Private type references should not include '#'. Use '${name}' instead.`;
21
+ type validateInferredAst<inferred, def extends string> = def extends NumberLiteral ? number extends inferred ? ErrorMessage<writeMalformedNumericLiteralMessage<def, "number">> : undefined : def extends BigintLiteral ? bigint extends inferred ? ErrorMessage<writeMalformedNumericLiteralMessage<def, "bigint">> : undefined : [inferred] extends [anyOrNever] ? undefined : def extends PrivateDeclaration<infer name> ? ErrorMessage<writePrefixedPrivateReferenceMessage<name>> : inferred extends Generic ? ErrorMessage<writeInvalidGenericArgCountMessage<def, inferred["names"], []>> : inferred extends {
22
22
  [arkKind]: "module";
23
23
  } ? "root" extends keyof inferred ? undefined : ErrorMessage<writeMissingSubmoduleAccessMessage<def>> : def extends ErrorMessage ? def : undefined;
24
24
  export type validateString<def extends string, $, args> = validateAst<parseString<def, $, args>, $, args> extends (infer result extends ErrorMessage) ? result extends Completion<infer text> ? text : result : def;
@@ -1 +1 @@
1
- export const writePrefixedPrivateReferenceMessage = (def) => `Private type references should not include '#'. Use '${def.slice(1)}' instead.`;
1
+ export const writePrefixedPrivateReferenceMessage = (name) => `Private type references should not include '#'. Use '${name}' instead.`;
@@ -1,6 +1,6 @@
1
1
  import { type BaseParseContext, type BaseRoot, type Index, type Optional, type Required, type UndeclaredKeyBehavior, type writeInvalidPropertyKeyMessage } from "@ark/schema";
2
2
  import { type anyOrNever, type Dict, type ErrorMessage, type ErrorType, type EscapeToken, type Key, type listable, type merge, type show } from "@ark/util";
3
- import type { constrain } from "../keywords/inference.ts";
3
+ import type { of } from "../keywords/inference.ts";
4
4
  import type { astToString } from "./ast/utils.ts";
5
5
  import type { validateString } from "./ast/validate.ts";
6
6
  import type { inferDefinition, validateDefinition } from "./definition.ts";
@@ -19,7 +19,7 @@ type _inferObjectLiteral<def extends object, $, args> = {
19
19
  -readonly [k in keyof def as optionalKeyFrom<k>]?: inferDefinition<def[k], $, args>;
20
20
  };
21
21
  export type validateObjectLiteral<def, $, args> = {
22
- [k in keyof def]: k extends IndexKey<infer indexDef> ? validateString<indexDef, $, args> extends ErrorMessage<infer message> ? ErrorType<message> : inferDefinition<indexDef, $, args> extends Key | constrain<Key, {}> ? validateDefinition<def[k], $, args> : ErrorType<writeInvalidPropertyKeyMessage<indexDef>> : k extends "..." ? inferDefinition<def[k], $, args> extends object ? validateDefinition<def[k], $, args> : ErrorType<writeInvalidSpreadTypeMessage<astToString<def[k]>>> : k extends "+" ? UndeclaredKeyBehavior : validateDefinition<def[k], $, args>;
22
+ [k in keyof def]: k extends IndexKey<infer indexDef> ? validateString<indexDef, $, args> extends ErrorMessage<infer message> ? ErrorType<message> : inferDefinition<indexDef, $, args> extends Key | of<Key, {}> ? validateDefinition<def[k], $, args> : ErrorType<writeInvalidPropertyKeyMessage<indexDef>> : k extends "..." ? inferDefinition<def[k], $, args> extends object ? validateDefinition<def[k], $, args> : ErrorType<writeInvalidSpreadTypeMessage<astToString<def[k]>>> : k extends "+" ? UndeclaredKeyBehavior : validateDefinition<def[k], $, args>;
23
23
  };
24
24
  type nonOptionalKeyFrom<k, $, args> = parseKey<k> extends PreparsedKey<"required", infer inner> ? inner : parseKey<k> extends PreparsedKey<"index", infer inner> ? inferDefinition<inner, $, args> extends infer t extends Key ? t : never : never;
25
25
  type optionalKeyFrom<k> = parseKey<k> extends PreparsedKey<"optional", infer inner> ? inner : never;
@@ -1,7 +1,6 @@
1
1
  import type { BaseParseContext, BaseRoot } from "@ark/schema";
2
2
  import { type requireKeys } from "@ark/util";
3
3
  import type { LimitLiteral } from "../../keywords/inference.ts";
4
- import type { InfixOperator } from "../ast/infer.ts";
5
4
  import type { Scanner } from "../shift/scanner.ts";
6
5
  import { type Comparator, type MinComparator, type OpenLeftBound, type StringifiablePrefixOperator } from "./shared.ts";
7
6
  type BranchState = {
@@ -36,7 +35,7 @@ export declare class DynamicState {
36
35
  parseOperand(): void;
37
36
  private assertRangeUnset;
38
37
  reduceGroupOpen(): void;
39
- previousOperator(): MinComparator | StringifiablePrefixOperator | InfixOperator | undefined;
38
+ previousOperator(): MinComparator | StringifiablePrefixOperator | Scanner.InfixToken | undefined;
40
39
  shiftedByOne(): this;
41
40
  }
42
41
  export {};
@@ -3,6 +3,7 @@ import { type BigintLiteral, type NumberLiteral, type join, type lastOf } from "
3
3
  import type { ArkAmbient } from "../../../config.ts";
4
4
  import type { resolutionToAst } from "../../../scope.ts";
5
5
  import type { GenericInstantiationAst, InferredAst } from "../../ast/infer.ts";
6
+ import { writePrefixedPrivateReferenceMessage } from "../../ast/validate.ts";
6
7
  import type { DynamicState } from "../../reduce/dynamic.ts";
7
8
  import type { StaticState, state } from "../../reduce/static.ts";
8
9
  import type { BaseCompletions } from "../../string.ts";
@@ -27,7 +28,10 @@ type tryResolveSubmodule<token extends string, resolution, reference extends str
27
28
  ]> : unresolvableState<s, reference, resolution, {}, submodulePath> : state.error<writeNonSubmoduleDotMessage<lastOf<submodulePath>>>;
28
29
  /** Provide valid completions for the current token, or fallback to an
29
30
  * unresolvable error if there are none */
30
- export type unresolvableState<s extends StaticState, token extends string, resolutions, args, submodulePath extends string[]> = validReferenceFromToken<token, resolutions, args, submodulePath> extends (never) ? state.error<writeUnresolvableMessage<qualifiedReference<token, submodulePath>>> : state.completion<`${s["scanned"]}${qualifiedReference<validReferenceFromToken<token, resolutions, args, submodulePath>, submodulePath>}`>;
31
+ export type unresolvableState<s extends StaticState, token extends string, resolutions, args, submodulePath extends string[]> = [
32
+ token,
33
+ s["unscanned"]
34
+ ] extends ["", Scanner.shift<"#", infer unscanned>] ? Scanner.shiftUntilNextTerminator<unscanned> extends (Scanner.shiftResult<infer name, string>) ? state.error<writePrefixedPrivateReferenceMessage<name>> : never : validReferenceFromToken<token, resolutions, args, submodulePath> extends (never) ? state.error<writeUnresolvableMessage<qualifiedReference<token, submodulePath>>> : state.completion<`${s["scanned"]}${qualifiedReference<validReferenceFromToken<token, resolutions, args, submodulePath>, submodulePath>}`>;
31
35
  type qualifiedReference<reference extends string, submodulePath extends string[]> = join<[...submodulePath, reference], ".">;
32
36
  type validReferenceFromToken<token extends string, $, args, submodulePath extends string[]> = Extract<submodulePath["length"] extends 0 ? BaseCompletions<$, args> : resolvableReferenceIn<$>, `${token}${string}`>;
33
37
  export declare const writeMissingOperandMessage: (s: DynamicState) => string;
@@ -19,10 +19,11 @@ export const parseGenericInstantiation = (name, g, s) => {
19
19
  };
20
20
  const unenclosedToNode = (s, token) => maybeParseReference(s, token) ??
21
21
  maybeParseUnenclosedLiteral(s, token) ??
22
- s.error(token === "" ? writeMissingOperandMessage(s)
23
- : token[0] === "#" ?
24
- writePrefixedPrivateReferenceMessage(token)
25
- : writeUnresolvableMessage(token));
22
+ s.error(token === "" ?
23
+ s.scanner.lookahead === "#" ?
24
+ writePrefixedPrivateReferenceMessage(s.shiftedByOne().scanner.shiftUntilNextTerminator())
25
+ : writeMissingOperandMessage(s)
26
+ : writeUnresolvableMessage(token));
26
27
  const maybeParseReference = (s, token) => {
27
28
  if (s.ctx.args?.[token]) {
28
29
  const arg = s.ctx.args[token];
@@ -0,0 +1,6 @@
1
+ import type { emptyBrandNameMessage } from "@ark/schema";
2
+ import type { DynamicStateWithRoot } from "../../reduce/dynamic.ts";
3
+ import type { StaticState, state } from "../../reduce/static.ts";
4
+ import type { Scanner } from "../scanner.ts";
5
+ export declare const parseBrand: (s: DynamicStateWithRoot) => void;
6
+ export type parseBrand<s extends StaticState, unscanned extends string> = Scanner.shiftUntilNextTerminator<Scanner.skipWhitespace<unscanned>> extends (Scanner.shiftResult<`${infer brandName}`, infer nextUnscanned>) ? brandName extends "" ? state.error<emptyBrandNameMessage> : state.setRoot<s, [s["root"], "#", brandName], nextUnscanned> : never;
@@ -0,0 +1,5 @@
1
+ export const parseBrand = (s) => {
2
+ s.scanner.shiftUntilNonWhitespace();
3
+ const brandName = s.scanner.shiftUntilNextTerminator();
4
+ s.root = s.root.brand(brandName);
5
+ };
@@ -7,6 +7,9 @@ export const parseDefault = (s) => {
7
7
  // token from which it was parsed
8
8
  if (!defaultNode.hasKind("unit"))
9
9
  return s.error(writeNonLiteralDefaultMessage(defaultNode.expression));
10
- return baseNode.default(defaultNode.unit);
10
+ const defaultValue = defaultNode.unit instanceof Date ?
11
+ () => new Date(defaultNode.unit)
12
+ : defaultNode.unit;
13
+ return baseNode.default(defaultValue);
11
14
  };
12
15
  export const writeNonLiteralDefaultMessage = (defaultDef) => `Default value '${defaultDef}' must a literal value`;
@@ -3,9 +3,10 @@ import type { DynamicStateWithRoot } from "../../reduce/dynamic.ts";
3
3
  import type { StaticState, state } from "../../reduce/static.ts";
4
4
  import { Scanner } from "../scanner.ts";
5
5
  import { parseBound, type ComparatorStartChar } from "./bounds.ts";
6
+ import { parseBrand } from "./brand.ts";
6
7
  import { parseDivisor } from "./divisor.ts";
7
8
  export declare const parseOperator: (s: DynamicStateWithRoot) => void;
8
- export type parseOperator<s extends StaticState, $, args> = s["unscanned"] extends Scanner.shift<infer lookahead, infer unscanned> ? lookahead extends "[" ? unscanned extends Scanner.shift<"]", infer nextUnscanned> ? state.setRoot<s, [s["root"], "[]"], nextUnscanned> : state.error<incompleteArrayTokenMessage> : lookahead extends "|" | "&" ? state.reduceBranch<s, lookahead, unscanned> : lookahead extends ")" ? state.finalizeGroup<s, unscanned> : Scanner.lookaheadIsFinalizing<lookahead, unscanned> extends true ? state.finalize<state.scanTo<s, unscanned>, lookahead & Scanner.FinalizingLookahead> : lookahead extends ComparatorStartChar ? parseBound<s, lookahead, unscanned, $, args> : lookahead extends "%" ? parseDivisor<s, unscanned> : lookahead extends WhiteSpaceToken ? parseOperator<state.scanTo<s, unscanned>, $, args> : state.error<writeUnexpectedCharacterMessage<lookahead>> : state.finalize<s, "">;
9
+ export type parseOperator<s extends StaticState, $, args> = s["unscanned"] extends Scanner.shift<infer lookahead, infer unscanned> ? lookahead extends "[" ? unscanned extends Scanner.shift<"]", infer nextUnscanned> ? state.setRoot<s, [s["root"], "[]"], nextUnscanned> : state.error<incompleteArrayTokenMessage> : lookahead extends "|" | "&" ? state.reduceBranch<s, lookahead, unscanned> : lookahead extends ")" ? state.finalizeGroup<s, unscanned> : Scanner.lookaheadIsFinalizing<lookahead, unscanned> extends true ? state.finalize<state.scanTo<s, unscanned>, lookahead & Scanner.FinalizingLookahead> : lookahead extends ComparatorStartChar ? parseBound<s, lookahead, unscanned, $, args> : lookahead extends "%" ? parseDivisor<s, unscanned> : lookahead extends "#" ? parseBrand<s, unscanned> : lookahead extends WhiteSpaceToken ? parseOperator<state.scanTo<s, unscanned>, $, args> : state.error<writeUnexpectedCharacterMessage<lookahead>> : state.finalize<s, "">;
9
10
  export declare const writeUnexpectedCharacterMessage: <char extends string, shouldBe extends string>(char: char, shouldBe?: shouldBe) => writeUnexpectedCharacterMessage<char, shouldBe>;
10
11
  export type writeUnexpectedCharacterMessage<char extends string, shouldBe extends string = ""> = `'${char}' is not allowed here${shouldBe extends "" ? "" : ` (should be ${shouldBe})`}`;
11
12
  export declare const incompleteArrayTokenMessage = "Missing expected ']'";
@@ -1,6 +1,7 @@
1
1
  import { isKeyOf, whiteSpaceTokens } from "@ark/util";
2
2
  import { Scanner } from "../scanner.js";
3
3
  import { comparatorStartChars, parseBound } from "./bounds.js";
4
+ import { parseBrand } from "./brand.js";
4
5
  import { parseDivisor } from "./divisor.js";
5
6
  export const parseOperator = (s) => {
6
7
  const lookahead = s.scanner.shift();
@@ -15,8 +16,9 @@ export const parseOperator = (s) => {
15
16
  s.finalize(lookahead)
16
17
  : isKeyOf(lookahead, comparatorStartChars) ? parseBound(s, lookahead)
17
18
  : lookahead === "%" ? parseDivisor(s)
18
- : lookahead in whiteSpaceTokens ? parseOperator(s)
19
- : s.error(writeUnexpectedCharacterMessage(lookahead)));
19
+ : lookahead === "#" ? parseBrand(s)
20
+ : lookahead in whiteSpaceTokens ? parseOperator(s)
21
+ : s.error(writeUnexpectedCharacterMessage(lookahead)));
20
22
  };
21
23
  export const writeUnexpectedCharacterMessage = (char, shouldBe = "") => `'${char}' is not allowed here${shouldBe && ` (should be ${shouldBe})`}`;
22
24
  export const incompleteArrayTokenMessage = `Missing expected ']'`;
@@ -35,6 +35,7 @@ export declare class Scanner<lookahead extends string = string> {
35
35
  readonly ",": true;
36
36
  readonly ":": true;
37
37
  readonly "?": true;
38
+ readonly "#": true;
38
39
  };
39
40
  static finalizingLookaheads: {
40
41
  readonly ">": true;
@@ -56,8 +57,8 @@ export declare namespace Scanner {
56
57
  };
57
58
  type TerminatingChar = keyof typeof Scanner.terminatingChars;
58
59
  type FinalizingLookahead = keyof typeof Scanner.finalizingLookaheads;
59
- type InfixToken = Comparator | "|" | "&" | "%" | ":" | "=>";
60
- type PostfixToken = "[]";
60
+ type InfixToken = Comparator | "|" | "&" | "%" | ":" | "=>" | "#" | "@" | "=";
61
+ type PostfixToken = "[]" | "?";
61
62
  type OperatorToken = InfixToken | PostfixToken;
62
63
  type shift<lookahead extends string, unscanned extends string> = `${lookahead}${unscanned}`;
63
64
  type shiftUntil<unscanned extends string, terminator extends string, scanned extends string = ""> = unscanned extends shift<infer lookahead, infer nextUnscanned> ? lookahead extends terminator ? scanned extends `${infer base}${EscapeToken}` ? shiftUntil<nextUnscanned, terminator, `${base}${lookahead}`> : [scanned, unscanned] : shiftUntil<nextUnscanned, terminator, `${scanned}${lookahead}`> : [scanned, ""];
@@ -75,6 +75,7 @@ export class Scanner {
75
75
  ",": true,
76
76
  ":": true,
77
77
  "?": true,
78
+ "#": true,
78
79
  ...whiteSpaceTokens
79
80
  };
80
81
  static finalizingLookaheads = {
@@ -1,14 +1,15 @@
1
1
  import { type BaseParseContext, type BaseRoot, type MetaSchema, type Morph, type Predicate } from "@ark/schema";
2
2
  import { type anyOrNever, type array, type BuiltinObjectKind, type conform, type Constructor, type Domain, type ErrorMessage, type show } from "@ark/util";
3
- import type { applyConstraint, Default, distill, inferIntersection, inferMorphOut, inferPredicate, InferredOptional, Optional, Out } from "../keywords/inference.ts";
3
+ import type { applyAttribute, Default, DefaultFor, distill, inferIntersection, inferMorphOut, inferPredicate, InferredOptional, Optional, Out } from "../keywords/inference.ts";
4
4
  import type { type } from "../keywords/keywords.ts";
5
- import type { InfixOperator, PostfixExpression } from "./ast/infer.ts";
5
+ import type { PostfixExpression } from "./ast/infer.ts";
6
6
  import type { inferDefinition, validateDefinition } from "./definition.ts";
7
7
  import { writeMissingRightOperandMessage } from "./shift/operand/unenclosed.ts";
8
+ import type { Scanner } from "./shift/scanner.ts";
8
9
  import type { BaseCompletions } from "./string.ts";
9
10
  export declare const parseTuple: (def: array, ctx: BaseParseContext) => BaseRoot;
10
11
  export declare const parseTupleLiteral: (def: array, ctx: BaseParseContext) => BaseRoot;
11
- type InfixExpression = readonly [unknown, InfixOperator, ...unknown[]];
12
+ type InfixExpression = readonly [unknown, Scanner.InfixToken, ...unknown[]];
12
13
  export type validateTuple<def extends array, $, args> = def extends IndexZeroExpression ? validatePrefixExpression<def, $, args> : def extends PostfixExpression ? validatePostfixExpression<def, $, args> : def extends InfixExpression ? validateInfixExpression<def, $, args> : def extends (readonly ["", ...unknown[]] | readonly [unknown, "", ...unknown[]]) ? readonly [
13
14
  def[0] extends "" ? BaseCompletions<$, args, IndexZeroOperator | "..."> : def[0],
14
15
  def[1] extends "" ? BaseCompletions<$, args, IndexOneOperator | "..."> : def[1]
@@ -110,13 +111,13 @@ type optionalPostVariadicMessage = typeof optionalPostVariadicMessage;
110
111
  export declare const spreadOptionalMessage = "A spread element cannot be optional";
111
112
  type spreadOptionalMessage = typeof optionalPostVariadicMessage;
112
113
  export type inferTuple<def extends array, $, args> = def extends TupleExpression ? inferTupleExpression<def, $, args> : inferTupleLiteral<def, $, args>;
113
- export type inferTupleExpression<def extends TupleExpression, $, args> = def[1] extends "[]" ? inferDefinition<def[0], $, args>[] : def[1] extends "&" ? inferIntersection<inferDefinition<def[0], $, args>, inferDefinition<def[2], $, args>> : def[1] extends "|" ? inferDefinition<def[0], $, args> | inferDefinition<def[2], $, args> : def[1] extends ":" ? inferPredicate<inferDefinition<def[0], $, args>, def[2]> : def[1] extends "=>" ? parseMorph<def[0], def[2], $, args> : def[1] extends "@" ? inferDefinition<def[0], $, args> : def[1] extends "=" ? applyConstraint<inferDefinition<def[0], $, args>, Default<def[2]>> : def[1] extends "?" ? applyConstraint<inferDefinition<def[0], $, args>, Optional> : def extends readonly ["===", ...infer values] ? values[number] : def extends (readonly ["instanceof", ...infer constructors extends Constructor[]]) ? InstanceType<constructors[number]> : def[0] extends "keyof" ? inferKeyOfExpression<def[1], $, args> : never;
114
+ export type inferTupleExpression<def extends TupleExpression, $, args> = def[1] extends "[]" ? inferDefinition<def[0], $, args>[] : def[1] extends "&" ? inferIntersection<inferDefinition<def[0], $, args>, inferDefinition<def[2], $, args>> : def[1] extends "|" ? inferDefinition<def[0], $, args> | inferDefinition<def[2], $, args> : def[1] extends ":" ? inferPredicate<inferDefinition<def[0], $, args>, def[2]> : def[1] extends "=>" ? parseMorph<def[0], def[2], $, args> : def[1] extends "@" ? inferDefinition<def[0], $, args> : def[1] extends "=" ? applyAttribute<inferDefinition<def[0], $, args>, Default<def[2]>> : def[1] extends "?" ? applyAttribute<inferDefinition<def[0], $, args>, Optional> : def extends readonly ["===", ...infer values] ? values[number] : def extends (readonly ["instanceof", ...infer constructors extends Constructor[]]) ? InstanceType<constructors[number]> : def[0] extends "keyof" ? inferKeyOfExpression<def[1], $, args> : never;
114
115
  export type validatePrefixExpression<def extends IndexZeroExpression, $, args> = def["length"] extends 1 ? readonly [writeMissingRightOperandMessage<def[0]>] : def[0] extends "keyof" ? readonly [def[0], validateDefinition<def[1], $, args>] : def[0] extends "===" ? readonly [def[0], ...unknown[]] : def[0] extends "instanceof" ? readonly [def[0], ...Constructor[]] : never;
115
116
  export type validatePostfixExpression<def extends PostfixExpression, $, args> = conform<def, readonly [validateDefinition<def[0], $, args>, "[]" | "?"]>;
116
117
  export type validateInfixExpression<def extends InfixExpression, $, args> = def["length"] extends 2 ? readonly [def[0], writeMissingRightOperandMessage<def[1]>] : readonly [
117
118
  validateDefinition<def[0], $, args>,
118
119
  def[1],
119
- def[1] extends "|" ? validateDefinition<def[2], $, args> : def[1] extends "&" ? validateDefinition<def[2], $, args> : def[1] extends ":" ? Predicate<type.infer.Out<def[0], $, args>> : def[1] extends "=>" ? Morph<type.infer.Out<def[0], $, args>> : def[1] extends "@" ? MetaSchema : def[1] extends "=" ? type.infer.Out<def[0], $, args> : validateDefinition<def[2], $, args>
120
+ def[1] extends "|" ? validateDefinition<def[2], $, args> : def[1] extends "&" ? validateDefinition<def[2], $, args> : def[1] extends ":" ? Predicate<type.infer.Out<def[0], $, args>> : def[1] extends "=>" ? Morph<type.infer.Out<def[0], $, args>> : def[1] extends "@" ? MetaSchema : def[1] extends "=" ? DefaultFor<type.infer.In<def[0], $, args>> : validateDefinition<def[2], $, args>
120
121
  ];
121
122
  export type UnparsedTupleExpressionInput = {
122
123
  instanceof: Constructor;
package/out/type.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { ArkErrors, BaseRoot, type BaseParseOptions, type MetaSchema, type Morph, type Predicate, type RootSchema } from "@ark/schema";
2
2
  import { Callable, Hkt, type Constructor, type array, type conform } from "@ark/util";
3
3
  import type { Generic, GenericParser, ParameterString, baseGenericConstraints, parseValidGenericParams, validateParameterString } from "./generic.ts";
4
- import type { distill } from "./keywords/inference.ts";
4
+ import type { DefaultFor, distill } from "./keywords/inference.ts";
5
5
  import type { Ark, keywords, type } from "./keywords/keywords.ts";
6
6
  import type { BaseType } from "./methods/base.ts";
7
7
  import type { instantiateType } from "./methods/instantiate.ts";
@@ -13,7 +13,7 @@ export type TypeParserAttachments = Omit<TypeParser, never>;
13
13
  export interface TypeParser<$ = {}> extends Ark.boundTypeAttachments<$> {
14
14
  <const def, r = Type<type.infer<def, $>, $>>(def: type.validate<def, $>): r;
15
15
  <const params extends ParameterString, const def>(params: validateParameterString<params, $>, def: validateDefinition<def, $, baseGenericConstraints<parseValidGenericParams<params, $>>>): Generic<parseValidGenericParams<params, $>, def, $>;
16
- <const zero, const one, const rest extends array, r = Type<type.infer<[zero, one, ...rest], $>, $>>(_0: zero extends IndexZeroOperator ? zero : type.validate<zero, $>, _1: zero extends "keyof" ? type.validate<one, $> : zero extends "instanceof" ? conform<one, Constructor> : zero extends "===" ? conform<one, unknown> : conform<one, IndexOneOperator>, ..._2: zero extends "===" ? rest : zero extends "instanceof" ? conform<rest, readonly Constructor[]> : one extends TupleInfixOperator ? one extends ":" ? [Predicate<distill.In<type.infer<zero, $>>>] : one extends "=>" ? [Morph<distill.Out<type.infer<zero, $>>, unknown>] : one extends "@" ? [MetaSchema] : one extends "=" ? [distill.In<type.infer<NoInfer<zero>, $>>] : [type.validate<rest[0], $>] : []): r;
16
+ <const zero, const one, const rest extends array, r = Type<type.infer<[zero, one, ...rest], $>, $>>(_0: zero extends IndexZeroOperator ? zero : type.validate<zero, $>, _1: zero extends "keyof" ? type.validate<one, $> : zero extends "instanceof" ? conform<one, Constructor> : zero extends "===" ? conform<one, unknown> : conform<one, IndexOneOperator>, ..._2: zero extends "===" ? rest : zero extends "instanceof" ? conform<rest, readonly Constructor[]> : one extends TupleInfixOperator ? one extends ":" ? [Predicate<distill.In<type.infer<zero, $>>>] : one extends "=>" ? [Morph<distill.Out<type.infer<zero, $>>, unknown>] : one extends "@" ? [MetaSchema] : one extends "=" ? [DefaultFor<distill.In<type.infer<NoInfer<zero>, $>>>] : [type.validate<rest[0], $>] : []): r;
17
17
  errors: typeof ArkErrors;
18
18
  hkt: typeof Hkt;
19
19
  keywords: typeof keywords;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "arktype",
3
3
  "description": "TypeScript's 1:1 validator, optimized from editor to runtime",
4
- "version": "2.0.0-rc.11",
4
+ "version": "2.0.0-rc.12",
5
5
  "license": "MIT",
6
6
  "author": {
7
7
  "name": "David Blass",
@@ -34,8 +34,8 @@
34
34
  "out"
35
35
  ],
36
36
  "dependencies": {
37
- "@ark/util": "0.13.0",
38
- "@ark/schema": "0.13.0"
37
+ "@ark/util": "0.14.0",
38
+ "@ark/schema": "0.14.0"
39
39
  },
40
40
  "publishConfig": {
41
41
  "access": "public"