arktype 2.0.0-beta.3 → 2.0.0-beta.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/out/ast.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { ArkError, ArkErrors, constraintKindOf, Morph, NodeSchema, PrimitiveConstraintKind } from "@ark/schema";
1
+ import type { ArkError, ArkErrors, Constraint, constraintKindOf, Morph, NodeSchema } from "@ark/schema";
2
2
  import { type anyOrNever, type array, type BuiltinObjectKind, type BuiltinObjects, type conform, type equals, type leftIfEqual, type Primitive, type propValueOf, type show } from "@ark/util";
3
3
  import type { type } from "./ark.js";
4
4
  import type { inferPipe } from "./intersect.js";
@@ -52,7 +52,7 @@ export type Narrowed = {
52
52
  [k in anonymous]: 1;
53
53
  };
54
54
  };
55
- export type primitiveConstraintKindOf<In> = Extract<PrimitiveConstraintKind, constraintKindOf<In>>;
55
+ export type primitiveConstraintKindOf<In> = Extract<Constraint.PrimitiveKind, constraintKindOf<In>>;
56
56
  export declare namespace number {
57
57
  type atLeast<rule> = constrain<number, AtLeast<rule>>;
58
58
  type moreThan<rule> = constrain<number, MoreThan<rule>>;
@@ -61,7 +61,7 @@ export declare namespace number {
61
61
  type divisibleBy<rule> = constrain<number, DivisibleBy<rule>>;
62
62
  type narrowed = constrain<number, Narrowed>;
63
63
  type is<constraints extends Constraints> = constrain<number, constraints>;
64
- type parseConstraint<kind extends PrimitiveConstraintKind, schema extends NodeSchema<kind>> = normalizePrimitiveConstraintRoot<schema> extends infer rule ? kind extends "min" ? schema extends {
64
+ type parseConstraint<kind extends Constraint.PrimitiveKind, schema extends NodeSchema<kind>> = normalizePrimitiveConstraintRoot<schema> extends infer rule ? kind extends "min" ? schema extends {
65
65
  exclusive: true;
66
66
  } ? moreThan<rule> : atLeast<rule> : kind extends "max" ? schema extends {
67
67
  exclusive: true;
@@ -92,7 +92,7 @@ export declare namespace string {
92
92
  type matching<rule> = constrain<string, Matching<rule>>;
93
93
  type narrowed = constrain<string, Narrowed>;
94
94
  type is<constraints extends Constraints> = constrain<string, constraints>;
95
- type parseConstraint<kind extends PrimitiveConstraintKind, schema extends NodeSchema<kind>> = normalizePrimitiveConstraintRoot<schema> extends infer rule ? kind extends "minLength" ? schema extends {
95
+ type parseConstraint<kind extends Constraint.PrimitiveKind, schema extends NodeSchema<kind>> = normalizePrimitiveConstraintRoot<schema> extends infer rule ? kind extends "minLength" ? schema extends {
96
96
  exclusive: true;
97
97
  } ? moreThanLength<rule> : atLeastLength<rule> : kind extends "maxLength" ? schema extends {
98
98
  exclusive: true;
@@ -118,14 +118,14 @@ export declare namespace Date {
118
118
  type narrowed = constrain<Date, Narrowed>;
119
119
  type literal<rule> = constrain<Date, Literal<rule>>;
120
120
  type is<constraints extends Constraints> = constrain<Date, constraints>;
121
- type parseConstraint<kind extends PrimitiveConstraintKind, schema extends NodeSchema<kind>> = normalizePrimitiveConstraintRoot<schema> extends infer rule ? kind extends "after" ? schema extends {
121
+ type parseConstraint<kind extends Constraint.PrimitiveKind, schema extends NodeSchema<kind>> = normalizePrimitiveConstraintRoot<schema> extends infer rule ? kind extends "after" ? schema extends {
122
122
  exclusive: true;
123
123
  } ? after<normalizeLimit<rule>> : atOrAfter<normalizeLimit<rule>> : kind extends "before" ? schema extends {
124
124
  exclusive: true;
125
125
  } ? before<normalizeLimit<rule>> : atOrBefore<normalizeLimit<rule>> : narrowed : never;
126
126
  }
127
- export type applyConstraint<t, kind extends PrimitiveConstraintKind, schema extends NodeSchema<kind>> = t extends MorphAst<infer i, infer o> ? (In: leftIfEqual<i, _applyConstraint<i, kind, schema>>) => Out<o> : leftIfEqual<t, _applyConstraint<t, kind, schema>>;
128
- type _applyConstraint<t, kind extends PrimitiveConstraintKind, schema extends NodeSchema<kind>> = schemaToConstraint<kind, schema> extends infer constraint ? parseConstraints<t> extends ([
127
+ export type applyConstraint<t, kind extends Constraint.PrimitiveKind, schema extends NodeSchema<kind>> = t extends MorphAst<infer i, infer o> ? (In: leftIfEqual<i, _applyConstraint<i, kind, schema>>) => o : leftIfEqual<t, _applyConstraint<t, kind, schema>>;
128
+ type _applyConstraint<t, kind extends Constraint.PrimitiveKind, schema extends NodeSchema<kind>> = schemaToConstraint<kind, schema> extends infer constraint ? parseConstraints<t> extends ([
129
129
  infer base,
130
130
  infer constraints extends Constraints
131
131
  ]) ? [
@@ -148,8 +148,8 @@ export type parseConstraints<t> = t extends constrain<infer base, infer constrai
148
148
  Date,
149
149
  constraints
150
150
  ] : [base, constraints] : null;
151
- export type normalizePrimitiveConstraintRoot<schema extends NodeSchema<PrimitiveConstraintKind>> = "rule" extends keyof schema ? conform<schema["rule"], PropertyKey> : conform<schema, PropertyKey>;
152
- export type schemaToConstraint<kind extends PrimitiveConstraintKind, schema extends NodeSchema<kind>> = normalizePrimitiveConstraintRoot<schema> extends infer rule ? kind extends "pattern" ? Matching<rule> : kind extends "divisor" ? DivisibleBy<rule> : kind extends "exactLength" ? Length<rule> : kind extends "min" ? schema extends {
151
+ export type normalizePrimitiveConstraintRoot<schema extends NodeSchema<Constraint.PrimitiveKind>> = "rule" extends keyof schema ? conform<schema["rule"], PropertyKey> : conform<schema, PropertyKey>;
152
+ export type schemaToConstraint<kind extends Constraint.PrimitiveKind, schema extends NodeSchema<kind>> = normalizePrimitiveConstraintRoot<schema> extends infer rule ? kind extends "pattern" ? Matching<rule> : kind extends "divisor" ? DivisibleBy<rule> : kind extends "exactLength" ? Length<rule> : kind extends "min" ? schema extends {
153
153
  exclusive: true;
154
154
  } ? MoreThan<rule> : AtLeast<rule> : kind extends "max" ? schema extends {
155
155
  exclusive: true;
@@ -166,6 +166,7 @@ export type distillIn<t> = finalizeDistillation<t, _distill<t, "in", "base">>;
166
166
  export type distillOut<t> = finalizeDistillation<t, _distill<t, "out", "base">>;
167
167
  export type distillConstrainableIn<t> = finalizeDistillation<t, _distill<t, "in", "constrainable">>;
168
168
  export type distillConstrainableOut<t> = finalizeDistillation<t, _distill<t, "out", "constrainable">>;
169
+ export type distillValidatedOut<t> = finalizeDistillation<t, _distill<t, "validatedOut", "constrainable">>;
169
170
  type finalizeDistillation<t, distilled> = equals<t, distilled> extends true ? t : distilled;
170
171
  export type includesMorphs<t> = [
171
172
  _distill<t, "in", "constrainable">,
@@ -174,10 +175,12 @@ export type includesMorphs<t> = [
174
175
  _distill<t, "out", "constrainable">,
175
176
  _distill<t, "in", "constrainable">
176
177
  ]) ? false : true;
177
- type _distill<t, io extends "in" | "out", distilledKind extends "base" | "constrainable"> = t extends undefined ? t : [t] extends [anyOrNever] ? t : parseConstraints<t> extends ([
178
+ type IoKind = "in" | "out" | "validatedOut";
179
+ type DistilledKind = "base" | "constrainable";
180
+ type _distill<t, io extends IoKind, distilledKind extends DistilledKind> = t extends undefined ? t : [t] extends [anyOrNever] ? t : parseConstraints<t> extends ([
178
181
  infer base,
179
182
  infer constraints extends Constraints
180
- ]) ? distilledKind extends "base" ? _distill<base, io, distilledKind> : constrain<_distill<base, io, distilledKind>, constraints> : t extends TerminallyInferredObjectKind | Primitive ? t : unknown extends t ? unknown : t extends MorphAst<infer i, infer o> ? io extends "in" ? _distill<i, io, distilledKind> : _distill<o, io, distilledKind> : t extends DefaultableAst<infer t> ? _distill<t, io, distilledKind> : t extends array ? distillArray<t, io, distilledKind, []> : t extends Function ? t : {
183
+ ]) ? distilledKind extends "base" ? _distill<base, io, distilledKind> : constrain<_distill<base, io, distilledKind>, constraints> : t extends TerminallyInferredObjectKind | Primitive ? t : unknown extends t ? unknown : t extends MorphAst<infer i, infer o> ? io extends "in" ? _distill<i, io, distilledKind> : io extends "validatedOut" ? o extends To<infer validatedOut> ? _distill<validatedOut, io, distilledKind> : unknown : _distill<o[1], io, distilledKind> : t extends DefaultableAst<infer t> ? _distill<t, io, distilledKind> : t extends array ? distillArray<t, io, distilledKind, []> : t extends Function ? t : {
181
184
  [k in keyof t]: t[k];
182
185
  } extends t ? io extends "in" ? show<{
183
186
  [k in keyof t as k extends defaultableKeyOf<t> ? never : k]: _distill<t[k], io, distilledKind>;
@@ -189,11 +192,11 @@ type _distill<t, io extends "in" | "out", distilledKind extends "base" | "constr
189
192
  export type defaultableKeyOf<t> = {
190
193
  [k in keyof t]: [t[k]] extends [anyOrNever] ? never : t[k] extends DefaultableAst ? k : never;
191
194
  }[keyof t];
192
- type distillArray<t extends array, io extends "in" | "out", constraints extends "base" | "constrainable", prefix extends array> = t extends readonly [infer head, ...infer tail] ? distillArray<tail, io, constraints, [
195
+ type distillArray<t extends array, io extends IoKind, constraints extends DistilledKind, prefix extends array> = t extends readonly [infer head, ...infer tail] ? distillArray<tail, io, constraints, [
193
196
  ...prefix,
194
197
  _distill<head, io, constraints>
195
198
  ]> : [...prefix, ...distillPostfix<t, io, constraints>];
196
- type distillPostfix<t extends array, io extends "in" | "out", constraints extends "base" | "constrainable", postfix extends array = []> = t extends readonly [...infer init, infer last] ? distillPostfix<init, io, constraints, [
199
+ type distillPostfix<t extends array, io extends IoKind, constraints extends DistilledKind, postfix extends array = []> = t extends readonly [...infer init, infer last] ? distillPostfix<init, io, constraints, [
197
200
  _distill<last, io, constraints>,
198
201
  ...postfix
199
202
  ]> : [...{
@@ -205,8 +208,9 @@ export type inferPredicate<t, predicate> = predicate extends (data: any, ...args
205
208
  export type constrainWithPredicate<t> = t extends constrain<unknown, infer constraints> ? applyConstraint<constrain<t, constraints>, "predicate", any> : applyConstraint<t, "predicate", any>;
206
209
  export type inferPipes<t, pipes extends Morph[]> = pipes extends [infer head extends Morph, ...infer tail extends Morph[]] ? inferPipes<pipes[0] extends type.cast<infer tPipe> ? inferPipe<t, tPipe> : inferMorphOut<head> extends infer out ? (In: distillConstrainableIn<t>) => Out<out> : never, tail> : t;
207
210
  export type inferMorphOut<morph extends Morph> = Exclude<ReturnType<morph>, ArkError | ArkErrors>;
208
- export type Out<o = any> = ["=>", o];
209
- export type MorphAst<i = any, o = any> = (In: i) => Out<o>;
211
+ export type Out<o = any> = ["=>", o, boolean];
212
+ export type To<o = any> = ["=>", o, true];
213
+ export type MorphAst<i = any, o extends Out = Out> = (In: i) => o;
210
214
  export type Default<v = any> = ["=", v];
211
215
  export type DefaultableAst<t = any, v = any> = (In?: t) => Default<v>;
212
216
  export type termOrType<t> = t | Type<t, any>;
package/out/config.d.ts CHANGED
@@ -1,13 +1,12 @@
1
- import type { ArkSchemaRegistryContents } from "@ark/schema";
1
+ import type { ArkSchemaRegistry } from "@ark/schema";
2
2
  import type { Ark } from "./ark.js";
3
3
  import type { exportScope } from "./module.js";
4
4
  export * from "@ark/schema/config";
5
- export interface ArkTypeRegistryContents extends ArkSchemaRegistryContents {
5
+ export interface ArkTypeRegistryContents extends ArkSchemaRegistry {
6
6
  ambient: exportScope<Ark>;
7
7
  }
8
8
  declare global {
9
9
  export interface ArkEnv {
10
- registry(): ArkTypeRegistryContents;
11
10
  }
12
11
  export namespace ArkEnv {
13
12
  }
package/out/generic.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import type { arkKind, GenericAst, GenericHkt, GenericParamAst, GenericParamDef, genericParamNames, GenericRoot, LazyGenericBody } from "@ark/schema";
2
- import { type array, type Callable, type conform, type ErrorMessage, type ErrorType, type WhiteSpaceToken } from "@ark/util";
1
+ import type { arkKind, GenericAst, GenericParamAst, GenericParamDef, genericParamNames, GenericRoot, LazyGenericBody } from "@ark/schema";
2
+ import { type array, type Callable, type conform, type ErrorMessage, type ErrorType, type Hkt, type WhiteSpaceToken } from "@ark/util";
3
3
  import type { inferDefinition } from "./parser/definition.js";
4
4
  import type { inferAstRoot } from "./parser/semantic/infer.js";
5
5
  import type { validateAst } from "./parser/semantic/validate.js";
@@ -92,7 +92,7 @@ export type GenericInstantiator<params extends array<GenericParamAst>, def, $, a
92
92
  } : (error: ErrorMessage<`You may not define more than 7 positional generic parameters`>) => never;
93
93
  type instantiateGeneric<def, params extends array<GenericParamAst>, args, $, args$> = Type<[
94
94
  def
95
- ] extends [GenericHkt] ? GenericHkt.instantiate<def, {
95
+ ] extends [Hkt] ? Hkt.apply<def, {
96
96
  [i in keyof args]: inferTypeRoot<args[i], args$>;
97
97
  }> : inferDefinition<def, $, bindGenericArgs<params, args$, args>>, args$>;
98
98
  type bindGenericArgs<params extends array<GenericParamAst>, $, args> = {
@@ -156,5 +156,5 @@ export type genericParamDefsToAst<defs extends array<GenericParamDef>, $> = [
156
156
  [i in keyof defs]: genericParamDefToAst<defs[i], $>;
157
157
  }
158
158
  ];
159
- export type GenericHktParser<$ = {}> = <const paramsDef extends array<GenericParamDef>>(...params: paramsDef) => <hkt extends abstract new () => GenericHkt, params extends Array<GenericParamAst> = genericParamDefsToAst<paramsDef, $>>(instantiateDef: LazyGenericBody<baseGenericResolutions<params, $>>, hkt: hkt) => Generic<params, InstanceType<hkt>, $, $>;
159
+ export type GenericHktParser<$ = {}> = <const paramsDef extends array<GenericParamDef>>(...params: paramsDef) => <hkt extends Hkt.constructor, params extends Array<GenericParamAst> = genericParamDefsToAst<paramsDef, $>>(instantiateDef: LazyGenericBody<baseGenericResolutions<params, $>>, hkt: hkt) => Generic<params, InstanceType<hkt>, $, $>;
160
160
  export {};
package/out/index.d.ts CHANGED
@@ -1,7 +1,8 @@
1
- export { ArkError, ArkErrors, GenericHkt } from "@ark/schema";
1
+ export { ArkError, ArkErrors } from "@ark/schema";
2
2
  export type { ArkConfig, ArkScopeConfig } from "@ark/schema";
3
+ export { Hkt } from "@ark/util";
3
4
  export { ambient, ark, declare, define, generic, type } from "./ark.js";
4
5
  export type { Generic } from "./generic.js";
5
- export { Module, type Submodule } from "./module.js";
6
+ export { Module, type Submodule, type BoundModule } from "./module.js";
6
7
  export { scope, type Scope, type inferScope, type validateScope } from "./scope.js";
7
8
  export { Type, type inferAmbient, type inferTypeRoot, type validateAmbient, type validateTypeRoot } from "./type.js";
package/out/index.js CHANGED
@@ -1,4 +1,5 @@
1
- export { ArkError, ArkErrors, GenericHkt } from "@ark/schema";
1
+ export { ArkError, ArkErrors } from "@ark/schema";
2
+ export { Hkt } from "@ark/util";
2
3
  export { ambient, ark, declare, define, generic, type } from "./ark.js";
3
4
  export { Module } from "./module.js";
4
5
  export { scope } from "./scope.js";
@@ -1,10 +1,10 @@
1
- import type { anyOrNever, array, conform, Hkt, intersectArrays, show } from "@ark/util";
2
- import type { constrain, Constraints, MorphAst, Out, parseConstraints } from "./ast.js";
1
+ import type { anyOrNever, array, Hkt, intersectArrays, show } from "@ark/util";
2
+ import type { constrain, Constraints, MorphAst, parseConstraints, To } from "./ast.js";
3
3
  export type inferIntersection<l, r> = _inferIntersection<l, r, false>;
4
4
  export type inferPipe<l, r> = _inferIntersection<l, r, true>;
5
5
  type _inferIntersection<l, r, piped extends boolean> = [
6
6
  l & r
7
- ] extends [infer t extends anyOrNever] ? t : l extends MorphAst<infer lIn, infer lOut> ? r extends MorphAst<any, infer rOut> ? piped extends true ? (In: lIn) => Out<rOut> : never : piped extends true ? (In: lIn) => Out<r> : (In: _inferIntersection<lIn, r, false>) => Out<lOut> : r extends MorphAst<infer rIn, infer rOut> ? (In: _inferIntersection<rIn, l, false>) => Out<rOut> : parseConstraints<l> extends ([
7
+ ] extends [infer t extends anyOrNever] ? t : l extends MorphAst<infer lIn, infer lOut> ? r extends MorphAst<any, infer rOut> ? piped extends true ? (In: lIn) => rOut : never : piped extends true ? (In: lIn) => To<r> : (In: _inferIntersection<lIn, r, false>) => lOut : r extends MorphAst<infer rIn, infer rOut> ? (In: _inferIntersection<rIn, l, false>) => rOut : parseConstraints<l> extends ([
8
8
  infer lBase,
9
9
  infer lConstraints extends Constraints
10
10
  ]) ? parseConstraints<r> extends ([
@@ -14,8 +14,8 @@ type _inferIntersection<l, r, piped extends boolean> = [
14
14
  infer rBase,
15
15
  infer rConstraints extends Constraints
16
16
  ]) ? constrain<_inferIntersection<l, rBase, piped>, rConstraints> : [l, r] extends [object, object] ? intersectObjects<l, r, piped> extends infer result ? result : never : l & r;
17
- declare class MorphableIntersection<piped extends boolean> extends Hkt.Kind {
18
- hkt: (In: conform<this[Hkt.args], [l: unknown, r: unknown]>) => _inferIntersection<(typeof In)[0], (typeof In)[1], piped>;
17
+ interface MorphableIntersection<piped extends boolean> extends Hkt<[unknown, unknown]> {
18
+ body: _inferIntersection<this[0], this[1], piped>;
19
19
  }
20
20
  type intersectObjects<l, r, piped extends boolean> = [
21
21
  l,
@@ -1,15 +1,17 @@
1
+ import * as util from "@ark/util";
2
+ import { Hkt } from "@ark/util";
1
3
  import type { Out } from "../ast.js";
2
4
  import type { Module } from "../module.js";
3
5
  import { type inferScope } from "../scope.js";
6
+ declare class liftArrayHkt extends Hkt<[element: unknown]> {
7
+ body: util.liftArray<this[0]> extends infer lifted ? (In: this[0] | lifted) => Out<lifted> : never;
8
+ }
9
+ declare class mergeHkt extends Hkt<[base: object, props: object]> {
10
+ body: util.merge<this[0], this[1]>;
11
+ }
4
12
  declare const arkGenericsExports: {
5
- liftArray: import("@ark/schema").GenericRoot<readonly [["element", unknown]], {
6
- hkt: (args: [unknown]) => (In: unknown) => Out<unknown[]>;
7
- readonly args: import("@ark/util").array;
8
- }>;
9
- merge: import("@ark/schema").GenericRoot<readonly [["base", object], ["props", object]], {
10
- hkt: (args: [object, object]) => object;
11
- readonly args: import("@ark/util").array;
12
- }>;
13
+ liftArray: import("@ark/schema").GenericRoot<readonly [["element", unknown]], liftArrayHkt>;
14
+ merge: import("@ark/schema").GenericRoot<readonly [["base", object], ["props", object]], mergeHkt>;
13
15
  };
14
16
  export type arkGenericsExports = inferScope<typeof arkGenericsExports>;
15
17
  export type arkGenerics = Module<arkGenericsExports>;
@@ -1,14 +1,17 @@
1
- import { GenericHkt, genericNode } from "@ark/schema";
2
- import { liftArray } from "@ark/util";
1
+ import { genericNode } from "@ark/schema";
2
+ import * as util from "@ark/util";
3
+ import { Hkt } from "@ark/util";
3
4
  import { scope } from "../scope.js";
4
5
  import { tsKeywords } from "./tsKeywords.js";
5
- const ArkLiftArray = genericNode("element")(args => args.element.or(args.element.array()).pipe(liftArray), class liftArrayHkt extends GenericHkt {
6
- });
7
- const ArkMerge = genericNode(["base", tsKeywords.object], ["props", tsKeywords.object])(args => args.base.merge(args.props), class mergeHkt extends GenericHkt {
8
- });
6
+ class liftArrayHkt extends Hkt {
7
+ }
8
+ const liftArray = genericNode("element")(args => args.element.or(args.element.array()).pipe(util.liftArray), liftArrayHkt);
9
+ class mergeHkt extends Hkt {
10
+ }
11
+ const merge = genericNode(["base", tsKeywords.object], ["props", tsKeywords.object])(args => args.base.merge(args.props), mergeHkt);
9
12
  const arkGenericsExports = {
10
- liftArray: ArkLiftArray,
11
- merge: ArkMerge
13
+ liftArray,
14
+ merge
12
15
  };
13
16
  const $ = scope(arkGenericsExports, {
14
17
  prereducedAliases: true
@@ -5,7 +5,6 @@ export type formattingExports = {
5
5
  uppercase: (In: string) => Out<string>;
6
6
  lowercase: (In: string) => Out<string>;
7
7
  capitalize: (In: string) => Out<string>;
8
- wellFormed: (In: string) => Out<string>;
9
8
  normalize: (In: string) => Out<string>;
10
9
  };
11
10
  export type formatting = Module<formattingExports>;
@@ -16,10 +16,6 @@ const capitalize = rootNode({
16
16
  in: "string",
17
17
  morphs: (s) => s.charAt(0).toUpperCase() + s.slice(1)
18
18
  });
19
- const wellFormed = rootNode({
20
- in: "string",
21
- morphs: (s) => s.toWellFormed()
22
- });
23
19
  const normalize = rootNode({
24
20
  in: "string",
25
21
  morphs: (s) => s.normalize()
@@ -29,7 +25,6 @@ export const formatting = scope({
29
25
  uppercase,
30
26
  lowercase,
31
27
  capitalize,
32
- wellFormed,
33
28
  normalize
34
29
  }, {
35
30
  prereducedAliases: true
@@ -1,35 +1,35 @@
1
- import type { Key } from "@ark/util";
1
+ import { Hkt, type Key, type omit, type pick, type show } from "@ark/util";
2
2
  import type { Module } from "../module.js";
3
3
  import { type inferScope } from "../scope.js";
4
+ declare class RecordHkt extends Hkt<[Key, unknown]> {
5
+ body: Record<this[0], this[1]>;
6
+ }
7
+ declare class PickHkt extends Hkt<[object, Key]> {
8
+ body: pick<this[0], this[1] & keyof this[0]>;
9
+ }
10
+ declare class OmitHkt extends Hkt<[object, Key]> {
11
+ body: omit<this[0], this[1] & keyof this[0]>;
12
+ }
13
+ declare class PartialHkt extends Hkt<[object]> {
14
+ body: show<Partial<this[0]>>;
15
+ }
16
+ declare class RequiredHkt extends Hkt<[object]> {
17
+ body: show<Required<this[0]>>;
18
+ }
19
+ declare class ExcludeHkt extends Hkt<[unknown, unknown]> {
20
+ body: Exclude<this[0], this[1]>;
21
+ }
22
+ declare class ExtractHkt extends Hkt<[unknown, unknown]> {
23
+ body: Extract<this[0], this[1]>;
24
+ }
4
25
  declare const tsGenericsExports: {
5
- Record: import("@ark/schema").GenericRoot<readonly [["K", Key], ["V", unknown]], {
6
- hkt: (args: [Key, unknown]) => Record<Key, unknown>;
7
- readonly args: import("@ark/util").array;
8
- }>;
9
- Pick: import("@ark/schema").GenericRoot<readonly [["T", object], ["K", Key]], {
10
- hkt: (args: [object, Key]) => object;
11
- readonly args: import("@ark/util").array;
12
- }>;
13
- Omit: import("@ark/schema").GenericRoot<readonly [["T", object], ["K", Key]], {
14
- hkt: (args: [object, Key]) => object;
15
- readonly args: import("@ark/util").array;
16
- }>;
17
- Exclude: import("@ark/schema").GenericRoot<readonly [["T", unknown], ["U", unknown]], {
18
- hkt: (args: [unknown, unknown]) => never;
19
- readonly args: import("@ark/util").array;
20
- }>;
21
- Extract: import("@ark/schema").GenericRoot<readonly [["T", unknown], ["U", unknown]], {
22
- hkt: (args: [unknown, unknown]) => unknown;
23
- readonly args: import("@ark/util").array;
24
- }>;
25
- Partial: import("@ark/schema").GenericRoot<readonly [["T", object]], {
26
- hkt: (args: [object]) => object;
27
- readonly args: import("@ark/util").array;
28
- }>;
29
- Required: import("@ark/schema").GenericRoot<readonly [["T", object]], {
30
- hkt: (args: [object]) => object;
31
- readonly args: import("@ark/util").array;
32
- }>;
26
+ Record: import("@ark/schema").GenericRoot<readonly [["K", Key], ["V", unknown]], RecordHkt>;
27
+ Pick: import("@ark/schema").GenericRoot<readonly [["T", object], ["K", Key]], PickHkt>;
28
+ Omit: import("@ark/schema").GenericRoot<readonly [["T", object], ["K", Key]], OmitHkt>;
29
+ Exclude: import("@ark/schema").GenericRoot<readonly [["T", unknown], ["U", unknown]], ExcludeHkt>;
30
+ Extract: import("@ark/schema").GenericRoot<readonly [["T", unknown], ["U", unknown]], ExtractHkt>;
31
+ Partial: import("@ark/schema").GenericRoot<readonly [["T", object]], PartialHkt>;
32
+ Required: import("@ark/schema").GenericRoot<readonly [["T", object]], RequiredHkt>;
33
33
  };
34
34
  export type tsGenericsExports = inferScope<typeof tsGenericsExports>;
35
35
  export type tsGenerics = Module<tsGenericsExports>;
@@ -1,27 +1,35 @@
1
- import { GenericHkt, genericNode } from "@ark/schema";
1
+ import { genericNode } from "@ark/schema";
2
+ import { Hkt } from "@ark/util";
2
3
  import { scope } from "../scope.js";
3
4
  import { internal } from "./internal.js";
4
5
  import { tsKeywords } from "./tsKeywords.js";
6
+ class RecordHkt extends Hkt {
7
+ }
5
8
  const Record = genericNode(["K", internal.key], "V")(args => ({
6
9
  domain: "object",
7
10
  index: {
8
11
  signature: args.K,
9
12
  value: args.V
10
13
  }
11
- }), class RecordHkt extends GenericHkt {
12
- });
13
- const Pick = genericNode(["T", tsKeywords.object], ["K", internal.key])(args => args.T.pick(args.K), class PickHkt extends GenericHkt {
14
- });
15
- const Omit = genericNode(["T", tsKeywords.object], ["K", internal.key])(args => args.T.omit(args.K), class OmitHkt extends GenericHkt {
16
- });
17
- const Partial = genericNode(["T", tsKeywords.object])(args => args.T.partial(), class PartialHkt extends GenericHkt {
18
- });
19
- const Required = genericNode(["T", tsKeywords.object])(args => args.T.required(), class RequiredHkt extends GenericHkt {
20
- });
21
- const Exclude = genericNode("T", "U")(args => args.T.exclude(args.U), class ExcludeHkt extends GenericHkt {
22
- });
23
- const Extract = genericNode("T", "U")(args => args.T.extract(args.U), class ExtractHkt extends GenericHkt {
24
- });
14
+ }), RecordHkt);
15
+ class PickHkt extends Hkt {
16
+ }
17
+ const Pick = genericNode(["T", tsKeywords.object], ["K", internal.key])(args => args.T.pick(args.K), PickHkt);
18
+ class OmitHkt extends Hkt {
19
+ }
20
+ const Omit = genericNode(["T", tsKeywords.object], ["K", internal.key])(args => args.T.omit(args.K), OmitHkt);
21
+ class PartialHkt extends Hkt {
22
+ }
23
+ const Partial = genericNode(["T", tsKeywords.object])(args => args.T.partial(), PartialHkt);
24
+ class RequiredHkt extends Hkt {
25
+ }
26
+ const Required = genericNode(["T", tsKeywords.object])(args => args.T.required(), RequiredHkt);
27
+ class ExcludeHkt extends Hkt {
28
+ }
29
+ const Exclude = genericNode("T", "U")(args => args.T.exclude(args.U), ExcludeHkt);
30
+ class ExtractHkt extends Hkt {
31
+ }
32
+ const Extract = genericNode("T", "U")(args => args.T.extract(args.U), ExtractHkt);
25
33
  const tsGenericsExports = {
26
34
  Record,
27
35
  Pick,
@@ -1,2 +1,2 @@
1
- import { type IntersectionNode } from "@ark/schema";
2
- export declare const regexStringNode: (regex: RegExp, description: string) => IntersectionNode;
1
+ import { type Intersection } from "@ark/schema";
2
+ export declare const regexStringNode: (regex: RegExp, description: string) => Intersection.Node;
@@ -4,6 +4,6 @@ export const regexStringNode = (regex, description) => node("intersection", {
4
4
  pattern: {
5
5
  rule: regex.source,
6
6
  flags: regex.flags,
7
- description
7
+ meta: description
8
8
  }
9
9
  });
@@ -7,6 +7,7 @@ import { regexStringNode } from "./utils/regex.js";
7
7
  const url = rootNode({
8
8
  domain: "string",
9
9
  predicate: {
10
+ meta: "a valid URL",
10
11
  predicate: (s) => {
11
12
  try {
12
13
  new URL(s);
@@ -15,8 +16,7 @@ const url = rootNode({
15
16
  return false;
16
17
  }
17
18
  return true;
18
- },
19
- description: "a valid URL"
19
+ }
20
20
  }
21
21
  });
22
22
  // https://www.regular-expressions.info/email.html
@@ -31,12 +31,12 @@ const semver = regexStringNode(semverMatcher, "a valid semantic version (see htt
31
31
  const creditCard = rootNode({
32
32
  domain: "string",
33
33
  pattern: {
34
- rule: creditCardMatcher.source,
35
- description: "a valid credit card number"
34
+ meta: "a valid credit card number",
35
+ rule: creditCardMatcher.source
36
36
  },
37
37
  predicate: {
38
- predicate: isLuhnValid,
39
- description: "a valid credit card number"
38
+ meta: "a valid credit card number",
39
+ predicate: isLuhnValid
40
40
  }
41
41
  });
42
42
  /**
@@ -48,21 +48,21 @@ const creditCard = rootNode({
48
48
  const unixTimestamp = rootNode({
49
49
  domain: {
50
50
  domain: "number",
51
- description: "a number representing a Unix timestamp"
51
+ meta: "a number representing a Unix timestamp"
52
52
  },
53
53
  divisor: {
54
54
  rule: 1,
55
- description: `an integer representing a Unix timestamp`
55
+ meta: `an integer representing a Unix timestamp`
56
56
  },
57
57
  min: {
58
58
  rule: -8640000000000000,
59
- description: `a Unix timestamp after -8640000000000000`
59
+ meta: `a Unix timestamp after -8640000000000000`
60
60
  },
61
61
  max: {
62
62
  rule: 8640000000000000,
63
- description: "a Unix timestamp before 8640000000000000"
63
+ meta: "a Unix timestamp before 8640000000000000"
64
64
  },
65
- description: "an integer representing a safe Unix timestamp"
65
+ meta: "an integer representing a safe Unix timestamp"
66
66
  });
67
67
  export const validation = scope({
68
68
  alpha: regexStringNode(/^[A-Za-z]*$/, "only letters"),
@@ -1,4 +1,4 @@
1
- import { type BaseRoot, type IndexNode, type OptionalNode, type RequiredNode, type UndeclaredKeyBehavior, type writeInvalidPropertyKeyMessage } from "@ark/schema";
1
+ import { type BaseRoot, type Index, type Optional, type Required, type UndeclaredKeyBehavior, type writeInvalidPropertyKeyMessage } from "@ark/schema";
2
2
  import { type anyOrNever, type conform, type Dict, type ErrorMessage, type ErrorType, type EscapeToken, type Key, type listable, type merge, type show } from "@ark/util";
3
3
  import type { constrain, Default } from "../ast.js";
4
4
  import type { ParseContext } from "../scope.js";
@@ -43,7 +43,7 @@ declare namespace PreparsedKey {
43
43
  type ParsedKeyKind = "required" | "optional" | "index" | MetaKey;
44
44
  export type MetaKey = "..." | "+";
45
45
  export type IndexKey<def extends string = string> = `[${def}]`;
46
- export type ParsedEntry = ParsedUndeclaredEntry | ParsedSpreadEntry | RequiredNode | OptionalNode | IndexNode;
46
+ export type ParsedEntry = ParsedUndeclaredEntry | ParsedSpreadEntry | Required.Node | Optional.Node | Index.Node;
47
47
  export type ParsedUndeclaredEntry = {
48
48
  kind: "undeclared";
49
49
  behavior: UndeclaredKeyBehavior;
@@ -1,5 +1,5 @@
1
- import type { GenericAst, GenericHkt } from "@ark/schema";
2
- import type { BigintLiteral, array } from "@ark/util";
1
+ import type { GenericAst } from "@ark/schema";
2
+ import type { BigintLiteral, Hkt, array } from "@ark/util";
3
3
  import type { Ark } from "../../ark.js";
4
4
  import type { Date, DateLiteral, Default, LimitLiteral, RegexLiteral, applyConstraint, distillIn, distillOut, normalizeLimit, string } from "../../ast.js";
5
5
  import type { inferIntersection } from "../../intersect.js";
@@ -13,7 +13,7 @@ export type inferAstOut<ast, $, args> = distillOut<inferAstRoot<ast, $, args>>;
13
13
  export type inferConstrainableAst<ast, $, args> = ast extends array ? inferExpression<ast, $, args> : ast extends string ? inferTerminal<ast, $, args> : never;
14
14
  export type GenericInstantiationAst<generic extends GenericAst = GenericAst, argAsts extends unknown[] = unknown[]> = [generic, "<>", argAsts];
15
15
  type resolveScope<g$, $> = g$ extends UnparsedScope ? $ : g$;
16
- export type inferExpression<ast extends array, $, args> = ast extends GenericInstantiationAst<infer g, infer argAsts> ? g["bodyDef"] extends GenericHkt ? GenericHkt.instantiate<g["bodyDef"], {
16
+ export type inferExpression<ast extends array, $, args> = ast extends GenericInstantiationAst<infer g, infer argAsts> ? g["bodyDef"] extends Hkt ? Hkt.apply<g["bodyDef"], {
17
17
  [i in keyof argAsts]: inferConstrainableAst<argAsts[i], $, args>;
18
18
  }> : inferDefinition<g["bodyDef"], resolveScope<g["$"], $>, {
19
19
  [i in keyof g["names"] & `${number}` as g["names"][i]]: inferConstrainableAst<argAsts[i & keyof argAsts], resolveScope<g["arg$"], $>, args>;
@@ -2,8 +2,10 @@ import type { DateLiteral } from "../../../../ast.js";
2
2
  export declare const isDateLiteral: (value: unknown) => value is DateLiteral;
3
3
  export declare const isValidDate: (d: Date) => boolean;
4
4
  export declare const extractDateLiteralSource: <literal extends DateLiteral>(literal: literal) => extractDateLiteralSource<literal>;
5
+ type extractDateLiteralSource<literal extends DateLiteral> = literal extends DateLiteral<infer source> ? source : never;
5
6
  export declare const writeInvalidDateMessage: <source extends string>(source: source) => writeInvalidDateMessage<source>;
6
7
  export type writeInvalidDateMessage<source extends string> = `'${source}' could not be parsed by the Date constructor`;
7
8
  export type DateInput = ConstructorParameters<typeof Date>[0];
8
9
  export type DateParseResult<errorOnFail extends boolean | string = boolean | string> = Date | (errorOnFail extends true | string ? never : undefined);
9
10
  export declare const tryParseDate: <errorOnFail extends boolean | string>(source: string, errorOnFail?: errorOnFail) => DateParseResult<errorOnFail>;
11
+ export {};
@@ -18,7 +18,7 @@ export const parseEnclosed = (s, enclosing) => {
18
18
  s.root = s.ctx.$.node("unit", { unit: enclosed });
19
19
  else {
20
20
  const date = tryParseDate(enclosed, writeInvalidDateMessage(enclosed));
21
- s.root = s.ctx.$.node("unit", { unit: date, description: enclosed });
21
+ s.root = s.ctx.$.node("unit", { meta: enclosed, unit: date });
22
22
  }
23
23
  };
24
24
  export const enclosingQuote = {
@@ -1,5 +1,5 @@
1
- import { writeUnboundableMessage } from "@ark/schema";
2
- import { $ark, isKeyOf, throwParseError } from "@ark/util";
1
+ import { $ark, writeUnboundableMessage } from "@ark/schema";
2
+ import { isKeyOf, throwParseError } from "@ark/util";
3
3
  import { invertedComparators, maxComparators, writeUnpairableComparatorMessage } from "../../reduce/shared.js";
4
4
  import { extractDateLiteralSource, isDateLiteral } from "../operand/date.js";
5
5
  export const parseBound = (s, start) => {
@@ -1,4 +1,4 @@
1
- import { type BaseMeta, type BaseRoot, type Morph, type Predicate } from "@ark/schema";
1
+ import { type BaseRoot, type MetaSchema, type Morph, type Predicate } from "@ark/schema";
2
2
  import { type array, type BuiltinObjectKind, type conform, type Constructor, type Domain, type ErrorMessage, type show } from "@ark/util";
3
3
  import type { distillConstrainableIn, distillOut, inferMorphOut, inferPredicate, Out } from "../ast.js";
4
4
  import type { inferIntersection } from "../intersect.js";
@@ -105,7 +105,7 @@ export type validatePostfixExpression<def extends PostfixExpression, $, args> =
105
105
  export type validateInfixExpression<def extends InfixExpression, $, args> = def["length"] extends 2 ? readonly [def[0], writeMissingRightOperandMessage<def[1]>] : readonly [
106
106
  validateDefinition<def[0], $, args>,
107
107
  def[1],
108
- def[1] extends "|" ? validateDefinition<def[2], $, args> : def[1] extends "&" ? validateDefinition<def[2], $, args> : def[1] extends ":" ? Predicate<distillOut<inferDefinition<def[0], $, args>>> : def[1] extends "=>" ? Morph<distillOut<inferDefinition<def[0], $, args>>, unknown> : def[1] extends "@" ? BaseMeta | string : validateDefinition<def[2], $, args>
108
+ def[1] extends "|" ? validateDefinition<def[2], $, args> : def[1] extends "&" ? validateDefinition<def[2], $, args> : def[1] extends ":" ? Predicate<distillOut<inferDefinition<def[0], $, args>>> : def[1] extends "=>" ? Morph<distillOut<inferDefinition<def[0], $, args>>, unknown> : def[1] extends "@" ? MetaSchema : validateDefinition<def[2], $, args>
109
109
  ];
110
110
  export type UnparsedTupleExpressionInput = {
111
111
  instanceof: Constructor;
@@ -1,5 +1,5 @@
1
- import { makeRootAndArrayPropertiesMutable } from "@ark/schema";
2
- import { $ark, append, objectKindOrDomainOf, throwParseError } from "@ark/util";
1
+ import { $ark, makeRootAndArrayPropertiesMutable } from "@ark/schema";
2
+ import { append, objectKindOrDomainOf, throwParseError } from "@ark/util";
3
3
  import { writeMissingRightOperandMessage } from "./string/shift/operand/unenclosed.js";
4
4
  export const parseTuple = (def, ctx) => maybeParseTupleExpression(def, ctx) ?? parseTupleLiteral(def, ctx);
5
5
  export const parseTupleLiteral = (def, ctx) => {
package/out/scope.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { BaseScope, type AliasDefEntry, type ArkScopeConfig, type BaseNode, type BaseRoot, type GenericArgResolutions, type GenericAst, type GenericParamAst, type InternalResolutions, type Node, type NodeKind, type NodeParseOptions, type NodeSchema, type PreparsedNodeResolution, type PrivateDeclaration, type RootKind, type RootSchema, type arkKind, type destructuredExportContext, type destructuredImportContext, type exportedNameOf, type reducibleKindOf, type toInternalScope, type writeDuplicateAliasError } from "@ark/schema";
1
+ import { BaseScope, type AliasDefEntry, type ArkScopeConfig, type BaseNode, type BaseRoot, type GenericArgResolutions, type GenericAst, type GenericParamAst, type InternalResolutions, type NodeKind, type NodeParseOptions, type NodeSchema, type PreparsedNodeResolution, type PrivateDeclaration, type RootKind, type RootSchema, type arkKind, type destructuredExportContext, type destructuredImportContext, type exportedNameOf, type nodeOfKind, type reducibleKindOf, type toInternalScope, type writeDuplicateAliasError } from "@ark/schema";
2
2
  import { type ErrorType, type Json, type anyOrNever, type array, type flattenListable, type nominal, type show } from "@ark/util";
3
3
  import type { Ark } from "./ark.js";
4
4
  import { parseGenericParams, type GenericDeclaration, type GenericHktParser, type ParameterString, type baseGenericConstraints, type parseValidGenericParams } from "./generic.js";
@@ -80,7 +80,7 @@ export interface Scope<$ = {}> {
80
80
  internal: toInternalScope<$>;
81
81
  defineSchema<const def extends RootSchema>(schema: def): def;
82
82
  schema(schema: RootSchema, opts?: NodeParseOptions): BaseRoot;
83
- node<kinds extends NodeKind | array<RootKind>>(kinds: kinds, schema: NodeSchema<flattenListable<kinds>>, opts?: NodeParseOptions): Node<reducibleKindOf<flattenListable<kinds>>>;
83
+ node<kinds extends NodeKind | array<RootKind>>(kinds: kinds, schema: NodeSchema<flattenListable<kinds>>, opts?: NodeParseOptions): nodeOfKind<reducibleKindOf<flattenListable<kinds>>>;
84
84
  type: TypeParser<$>;
85
85
  declare: DeclarationParser<$>;
86
86
  define: DefinitionParser<$>;
@@ -1,4 +1,4 @@
1
- import type { ExactLengthSchema, ExclusiveNumericRangeSchema, exclusivizeRangeSchema, InclusiveNumericRangeSchema } from "@ark/schema";
1
+ import type { ExactLength, ExclusiveNumericRangeSchema, exclusivizeRangeSchema, InclusiveNumericRangeSchema } from "@ark/schema";
2
2
  import type { applyConstraint } from "../ast.js";
3
3
  import type { ObjectType } from "./object.js";
4
4
  interface Type<
@@ -8,6 +8,6 @@ out t extends readonly unknown[] = readonly unknown[], $ = {}> extends ObjectTyp
8
8
  atMostLength<const schema extends InclusiveNumericRangeSchema>(schema: schema): Type<applyConstraint<t, "maxLength", schema>, $>;
9
9
  moreThanLength<const schema extends ExclusiveNumericRangeSchema>(schema: schema): Type<applyConstraint<t, "minLength", exclusivizeRangeSchema<schema>>, $>;
10
10
  lessThanLength<const schema extends ExclusiveNumericRangeSchema>(schema: schema): Type<applyConstraint<t, "maxLength", exclusivizeRangeSchema<schema>>, $>;
11
- exactlyLength<const schema extends ExactLengthSchema>(schema: schema): Type<applyConstraint<t, "exactLength", schema>, $>;
11
+ exactlyLength<const schema extends ExactLength.Schema>(schema: schema): Type<applyConstraint<t, "exactLength", schema>, $>;
12
12
  }
13
13
  export type { Type as ArrayType };
@@ -1,6 +1,6 @@
1
- import type { ArkErrors, BaseMeta, BaseRoot, Disjoint, Morph, UndeclaredKeyBehavior } from "@ark/schema";
1
+ import type { ArkErrors, BaseRoot, Disjoint, MetaSchema, Morph, UndeclaredKeyBehavior } from "@ark/schema";
2
2
  import type { anyOrNever, Callable, ErrorMessage, Json, unset } from "@ark/util";
3
- import type { distillConstrainableIn, distillConstrainableOut, distillIn, distillOut, inferMorphOut, inferPipes, inferred } from "../ast.js";
3
+ import type { distillConstrainableIn, distillConstrainableOut, distillIn, distillOut, distillValidatedOut, inferMorphOut, inferPipes, inferred } from "../ast.js";
4
4
  import type { inferIntersection } from "../intersect.js";
5
5
  import type { Scope } from "../scope.js";
6
6
  import type { inferTypeRoot, validateTypeRoot } from "../type.js";
@@ -11,6 +11,7 @@ interface Type<out t = unknown, $ = {}> extends Callable<(data: unknown) => dist
11
11
  t: t;
12
12
  tIn: distillConstrainableIn<t>;
13
13
  tOut: distillConstrainableOut<t>;
14
+ tValidatedOut: distillValidatedOut<t>;
14
15
  infer: distillOut<t>;
15
16
  inferIn: distillIn<t>;
16
17
  [inferred]: t;
@@ -22,25 +23,19 @@ interface Type<out t = unknown, $ = {}> extends Callable<(data: unknown) => dist
22
23
  assert(data: unknown): this["infer"];
23
24
  allows(data: unknown): data is this["inferIn"];
24
25
  traverse(data: unknown): distillOut<t> | ArkErrors;
25
- configure(configOrDescription: BaseMeta | string): this;
26
+ configure(meta: MetaSchema): this;
26
27
  describe(description: string): this;
27
28
  onUndeclaredKey(behavior: UndeclaredKeyBehavior): this;
28
29
  onDeepUndeclaredKey(behavior: UndeclaredKeyBehavior): this;
29
30
  from(literal: this["inferIn"]): this["infer"];
30
31
  as<t = unset>(...args: validateChainedAsArgs<t>): instantiateType<t, $>;
31
32
  get in(): instantiateType<this["tIn"], $>;
32
- get out(): instantiateType<this["tOut"], $>;
33
+ get out(): instantiateType<this["tValidatedOut"], $>;
33
34
  intersect<const def, r = inferTypeRoot<def, $>>(def: validateTypeRoot<def, $>): instantiateType<inferIntersection<t, r>, $> | Disjoint;
34
35
  and<const def, r = inferTypeRoot<def, $>>(def: validateTypeRoot<def, $>): instantiateType<inferIntersection<t, r>, $>;
35
36
  or<const def, r = inferTypeRoot<def, $>>(def: validateTypeRoot<def, $>): instantiateType<t | r, $>;
36
37
  array(): ArrayType<t[], $>;
37
- pipe<a extends Morph<this["infer"]>, r = instantiateType<inferPipes<t, [a]>, $>>(a: a): r;
38
- pipe<a extends Morph<this["infer"]>, b extends Morph<inferMorphOut<a>>, r = instantiateType<inferPipes<t, [a, b]>, $>>(a: a, b: b): r;
39
- pipe<a extends Morph<this["infer"]>, b extends Morph<inferMorphOut<a>>, c extends Morph<inferMorphOut<b>>, r = instantiateType<inferPipes<t, [a, b, c]>, $>>(a: a, b: b, c: c): r;
40
- pipe<a extends Morph<this["infer"]>, 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): r;
41
- pipe<a extends Morph<this["infer"]>, 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): r;
42
- pipe<a extends Morph<this["infer"]>, 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): r;
43
- pipe<a extends Morph<this["infer"]>, 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): r;
38
+ pipe: ChainedPipes<t, $>;
44
39
  equals<def>(def: validateTypeRoot<def, $>): this is instantiateType<inferTypeRoot<def, $>, $>;
45
40
  extract<def>(r: validateTypeRoot<def, $>): instantiateType<Extract<t, inferTypeRoot<def, $>>, $>;
46
41
  exclude<def>(r: validateTypeRoot<def, $>): instantiateType<Exclude<t, inferTypeRoot<def, $>>, $>;
@@ -65,6 +60,18 @@ interface Type<out t = unknown, $ = {}> extends Callable<(data: unknown) => dist
65
60
  /** @deprecated */
66
61
  Symbol: never;
67
62
  }
63
+ interface ChainedPipeSignature<t, $> {
64
+ <a extends Morph<distillOut<t>>, r = instantiateType<inferPipes<t, [a]>, $>>(a: a): r;
65
+ <a extends Morph<distillOut<t>>, b extends Morph<inferMorphOut<a>>, r = instantiateType<inferPipes<t, [a, b]>, $>>(a: a, b: b): r;
66
+ <a extends Morph<distillOut<t>>, b extends Morph<inferMorphOut<a>>, c extends Morph<inferMorphOut<b>>, r = instantiateType<inferPipes<t, [a, b, c]>, $>>(a: a, b: b, c: c): r;
67
+ <a extends Morph<distillOut<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): r;
68
+ <a extends Morph<distillOut<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): r;
69
+ <a extends Morph<distillOut<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): r;
70
+ <a extends Morph<distillOut<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): r;
71
+ }
72
+ export interface ChainedPipes<t, $> extends ChainedPipeSignature<t, $> {
73
+ try: ChainedPipeSignature<t, $>;
74
+ }
68
75
  type validateChainedAsArgs<t> = [
69
76
  t
70
77
  ] extends [unset] ? [
@@ -1,10 +1,13 @@
1
1
  import type { Predicate, PredicateCast } from "@ark/schema";
2
- import type { applyConstraint, Out } from "../ast.js";
2
+ import type { applyConstraint, Out, To } from "../ast.js";
3
+ import type { inferPipe } from "../intersect.js";
4
+ import type { inferTypeRoot, validateTypeRoot } from "../type.js";
3
5
  import type { BaseType } from "./base.js";
4
6
  /** @ts-ignore cast variance */
5
7
  interface Type<out t = unknown, $ = {}> extends BaseType<t, $> {
6
- narrow<narrowed extends this["infer"] = never>(predicate: Predicate<this["infer"]> | PredicateCast<this["infer"], narrowed>): Type<(In: this["tIn"]) => Out<[
8
+ to<const def, r = inferTypeRoot<def, $>>(def: validateTypeRoot<def, $>): Type<inferPipe<t, r>, $>;
9
+ narrow<narrowed extends this["infer"] = never>(predicate: Predicate<this["infer"]> | PredicateCast<this["infer"], narrowed>): Type<([
7
10
  narrowed
8
- ] extends [never] ? applyConstraint<this["tOut"], "predicate", Predicate> : narrowed>, $>;
11
+ ] extends [never] ? applyConstraint<this["tOut"], "predicate", Predicate> : narrowed) extends infer o ? this["tValidatedOut"] extends this["tOut"] ? (In: this["tIn"]) => To<o> : (In: this["tIn"]) => Out<o> : never, $>;
9
12
  }
10
13
  export type { Type as MorphType };
@@ -1,9 +1,9 @@
1
- import type { DivisorSchema, ExclusiveNumericRangeSchema, exclusivizeRangeSchema, InclusiveNumericRangeSchema } from "@ark/schema";
1
+ import type { Divisor, ExclusiveNumericRangeSchema, exclusivizeRangeSchema, InclusiveNumericRangeSchema } from "@ark/schema";
2
2
  import type { applyConstraint } from "../ast.js";
3
3
  import type { ValidatorType } from "./validator.js";
4
4
  /** @ts-ignore cast variance */
5
5
  interface Type<out t extends number = number, $ = {}> extends ValidatorType<t, $> {
6
- divisibleBy<const schema extends DivisorSchema>(schema: schema): Type<applyConstraint<t, "divisor", schema>, $>;
6
+ divisibleBy<const schema extends Divisor.Schema>(schema: schema): Type<applyConstraint<t, "divisor", schema>, $>;
7
7
  atLeast<const schema extends InclusiveNumericRangeSchema>(schema: schema): Type<applyConstraint<t, "min", schema>, $>;
8
8
  atMost<const schema extends InclusiveNumericRangeSchema>(schema: schema): Type<applyConstraint<t, "max", schema>, $>;
9
9
  moreThan<const schema extends ExclusiveNumericRangeSchema>(schema: schema): Type<applyConstraint<t, "min", exclusivizeRangeSchema<schema>>, $>;
@@ -1,13 +1,13 @@
1
- import type { ExactLengthSchema, ExclusiveNumericRangeSchema, exclusivizeRangeSchema, InclusiveNumericRangeSchema, PatternSchema } from "@ark/schema";
1
+ import type { ExactLength, ExclusiveNumericRangeSchema, exclusivizeRangeSchema, InclusiveNumericRangeSchema, Pattern } from "@ark/schema";
2
2
  import type { applyConstraint } from "../ast.js";
3
3
  import type { ValidatorType } from "./validator.js";
4
4
  /** @ts-ignore cast variance */
5
5
  interface Type<out t extends string = string, $ = {}> extends ValidatorType<t, $> {
6
- matching<const schema extends PatternSchema>(schema: schema): Type<applyConstraint<t, "pattern", schema>, $>;
6
+ matching<const schema extends Pattern.Schema>(schema: schema): Type<applyConstraint<t, "pattern", schema>, $>;
7
7
  atLeastLength<const schema extends InclusiveNumericRangeSchema>(schema: schema): Type<applyConstraint<t, "minLength", schema>, $>;
8
8
  atMostLength<const schema extends InclusiveNumericRangeSchema>(schema: schema): Type<applyConstraint<t, "maxLength", schema>, $>;
9
9
  moreThanLength<const schema extends ExclusiveNumericRangeSchema>(schema: schema): Type<applyConstraint<t, "minLength", exclusivizeRangeSchema<schema>>, $>;
10
10
  lessThanLength<const schema extends ExclusiveNumericRangeSchema>(schema: schema): Type<applyConstraint<t, "maxLength", exclusivizeRangeSchema<schema>>, $>;
11
- exactlyLength<const schema extends ExactLengthSchema>(schema: schema): Type<applyConstraint<t, "exactLength", schema>, $>;
11
+ exactlyLength<const schema extends ExactLength.Schema>(schema: schema): Type<applyConstraint<t, "exactLength", schema>, $>;
12
12
  }
13
13
  export type { Type as StringType };
package/out/type.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ArkErrors, BaseRoot, type BaseMeta, type Morph, type Predicate } from "@ark/schema";
1
+ import { ArkErrors, BaseRoot, type MetaSchema, type Morph, type Predicate } from "@ark/schema";
2
2
  import { Callable, type Constructor, type array, type conform } from "@ark/util";
3
3
  import type { distillIn, distillOut } from "./ast.js";
4
4
  import { type Generic, type ParameterString, type baseGenericConstraints, type parseValidGenericParams, type validateParameterString } from "./generic.js";
@@ -12,7 +12,7 @@ export type TypeParserAttachments = Omit<TypeParser, never>;
12
12
  export interface TypeParser<$ = {}> {
13
13
  <const def, r = Type<inferTypeRoot<def, $>, $>>(def: validateTypeRoot<def, $>): r;
14
14
  <params extends ParameterString, const def>(params: validateParameterString<params, $>, def: validateDefinition<def, $, baseGenericConstraints<parseValidGenericParams<params, $>>>): Generic<parseValidGenericParams<params, $>, def, $>;
15
- <const zero, const one, const rest extends array, r = Type<inferTypeRoot<[zero, one, ...rest], $>, $>>(_0: zero extends IndexZeroOperator ? zero : validateTypeRoot<zero, $>, _1: zero extends "keyof" ? validateTypeRoot<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<distillIn<inferTypeRoot<zero, $>>>] : one extends "=>" ? [Morph<distillOut<inferTypeRoot<zero, $>>, unknown>] : one extends "@" ? [string | BaseMeta] : [validateTypeRoot<rest[0], $>] : []): r;
15
+ <const zero, const one, const rest extends array, r = Type<inferTypeRoot<[zero, one, ...rest], $>, $>>(_0: zero extends IndexZeroOperator ? zero : validateTypeRoot<zero, $>, _1: zero extends "keyof" ? validateTypeRoot<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<distillIn<inferTypeRoot<zero, $>>>] : one extends "=>" ? [Morph<distillOut<inferTypeRoot<zero, $>>, unknown>] : one extends "@" ? [MetaSchema] : [validateTypeRoot<rest[0], $>] : []): r;
16
16
  raw(def: unknown): BaseType<any, $>;
17
17
  errors: typeof ArkErrors;
18
18
  }
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-beta.3",
4
+ "version": "2.0.0-beta.4",
5
5
  "license": "MIT",
6
6
  "author": {
7
7
  "name": "David Blass",
@@ -25,8 +25,8 @@
25
25
  "out"
26
26
  ],
27
27
  "dependencies": {
28
- "@ark/util": "0.2.0",
29
- "@ark/schema": "0.3.0"
28
+ "@ark/util": "0.2.1",
29
+ "@ark/schema": "0.3.1"
30
30
  },
31
31
  "publishConfig": {
32
32
  "access": "public"