arktype 2.0.0-dev.18 → 2.0.0-dev.19

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.
@@ -25,7 +25,7 @@ type validatePossibleDefaultValue<def, k extends keyof def, $, args> = def[k] ex
25
25
  "=",
26
26
  inferDefinition<defaultDef, $, args>
27
27
  ] : ErrorMessage<invalidDefaultKeyKindMessage> : validateDefinition<def[k], $, args>;
28
- 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 ? (t extends of<any, any> ? string : Key) & t : never : never;
28
+ 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 ? (t extends of<infer inner, any> ? Extract<inner, string> : Key) & t : never : never;
29
29
  type optionalKeyFrom<k> = parseKey<k> extends PreparsedKey<"optional", infer inner> ? inner : never;
30
30
  type PreparsedKey<kind extends ParsedKeyKind = ParsedKeyKind, inner extends Key = Key> = {
31
31
  kind: kind;
@@ -1,4 +1,4 @@
1
- import { type BaseMeta, type BaseRoot, type Morph, type Out, type Predicate, type distillConstrainableIn, type distillConstrainableOut, type inferIntersection, type inferMorphOut, type inferNarrow } from "@arktype/schema";
1
+ import { type BaseMeta, type BaseRoot, type Morph, type Out, type Predicate, type distillConstrainableIn, type distillConstrainableOut, type inferIntersection, type inferMorphOut, type inferPredicate } from "@arktype/schema";
2
2
  import { type Constructor, type Domain, type ErrorMessage, type array, type conform, type show } from "@arktype/util";
3
3
  import type { ParseContext } from "../scope.js";
4
4
  import type { inferDefinition, validateDefinition } from "./definition.js";
@@ -97,7 +97,7 @@ type optionalPostVariadicMessage = typeof optionalPostVariadicMessage;
97
97
  export declare const spreadOptionalMessage = "A spread element cannot be optional";
98
98
  type spreadOptionalMessage = typeof optionalPostVariadicMessage;
99
99
  export type inferTuple<def extends array, $, args> = def extends TupleExpression ? inferTupleExpression<def, $, args> : inferTupleLiteral<def, $, args>;
100
- 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 ":" ? inferNarrow<inferDefinition<def[0], $, args>, def[2]> : def[1] extends "=>" ? parseMorph<def[0], def[2], $, args> : def[1] extends "@" ? inferDefinition<def[0], $, args> : 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;
100
+ 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 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;
101
101
  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;
102
102
  export type validatePostfixExpression<def extends PostfixExpression, $, args> = conform<def, readonly [validateDefinition<def[0], $, args>, "[]"]>;
103
103
  export type validateInfixExpression<def extends InfixExpression, $, args> = def["length"] extends 2 ? readonly [def[0], writeMissingRightOperandMessage<def[1]>] : readonly [
package/out/type.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { ArkErrors, BaseRoot, type BaseMeta, type Disjoint, type InnerRoot, type Morph, type NodeSchema, type Out, type Predicate, type PrimitiveConstraintKind, type Root, type ambient, type constrain, type constraintKindOf, type distillIn, type distillOut, type includesMorphs, type inferIntersection, type inferMorphOut, type inferNarrow, type inferPipes, type internalImplementationOf } from "@arktype/schema";
2
- import { Callable, type Constructor, type array, type conform } from "@arktype/util";
1
+ import { ArkErrors, BaseRoot, type BaseMeta, type ConstraintKind, type Disjoint, type DivisorSchema, type ExactLengthSchema, type ExclusiveDateRangeSchema, type ExclusiveNumericRangeSchema, type InclusiveDateRangeSchema, type InclusiveNumericRangeSchema, type InnerRoot, type Morph, type MorphAst, type NodeSchema, type Out, type Predicate, type Prerequisite, type PrimitiveConstraintKind, type RegexSchema, type Root, type ambient, type constrain, type constraintKindOf, type distillIn, type distillOut, type exclusivizeRangeSchema, type inferIntersection, type inferMorphOut, type inferPipes, type inferPredicate, type writeInvalidOperandMessage } from "@arktype/schema";
2
+ import { Callable, type Constructor, type ErrorMessage, type array, type conform } from "@arktype/util";
3
3
  import { Generic, type validateParameterString } from "./generic.js";
4
4
  import type { inferDefinition, validateDeclared, validateDefinition } from "./parser/definition.js";
5
5
  import { parseGenericParams } from "./parser/generic.js";
@@ -21,7 +21,10 @@ export declare class RawTypeParser extends Callable<(...args: unknown[]) => Base
21
21
  export type DeclarationParser<$> = <preinferred>() => {
22
22
  type: <def>(def: validateDeclared<preinferred, def, $ & ambient, bindThis<def>>) => Type<preinferred, $>;
23
23
  };
24
- declare class _Type<t = unknown, $ = any> extends InnerRoot<t, $> implements internalImplementationOf<Root> {
24
+ type validateChainedConstraint<kind extends ConstraintKind, t extends {
25
+ inferIn: unknown;
26
+ }> = t["inferIn"] extends Prerequisite<kind> ? t : ErrorMessage<writeInvalidOperandMessage<kind, Root<t["inferIn"]>>>;
27
+ declare class _Type<t = unknown, $ = any> extends InnerRoot<t, $> {
25
28
  $: Scope<$>;
26
29
  get in(): Type<this["tIn"], $>;
27
30
  get out(): Type<this["tOut"], $>;
@@ -37,12 +40,28 @@ declare class _Type<t = unknown, $ = any> extends InnerRoot<t, $> implements int
37
40
  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>>>(a: a, b: b, c: c, d: d, e: e): Type<inferPipes<t, [a, b, c, d, e]>, $>;
38
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>>, f extends Morph<inferMorphOut<e>>>(a: a, b: b, c: c, d: d, e: e, f: f): Type<inferPipes<t, [a, b, c, d, e, f]>, $>;
39
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>>, g extends Morph<inferMorphOut<f>>>(a: a, b: b, c: c, d: d, e: e, f: f, g: g): Type<inferPipes<t, [a, b, c, d, e, f, g]>, $>;
40
- narrow<def extends Predicate<distillOut<t>>>(def: def): Type<includesMorphs<t> extends true ? (In: this["tIn"]) => Out<inferNarrow<this["tOut"], def>> : inferNarrow<t, def>, $>;
43
+ narrow<const predicate extends Predicate<distillOut<t>>>(predicate: predicate): Type<t extends MorphAst ? (In: this["tIn"]) => Out<inferPredicate<this["tOut"], predicate>> : inferPredicate<t, predicate>, $>;
41
44
  equals<def>(def: validateTypeRoot<def, $>): this is Type<inferTypeRoot<def>, $>;
42
45
  extract<def>(r: validateTypeRoot<def, $>): Type<t, $>;
43
46
  exclude<def>(r: validateTypeRoot<def, $>): Type<t, $>;
44
47
  extends<def>(other: validateTypeRoot<def, $>): this is Type<inferTypeRoot<def>, $>;
45
48
  constrain<kind extends PrimitiveConstraintKind, const def extends NodeSchema<kind>>(kind: conform<kind, constraintKindOf<this["inferIn"]>>, def: def): Type<constrain<t, kind, def>, $>;
49
+ satisfying<predicate extends Predicate<distillIn<t>>>(predicate: predicate): Type<t extends MorphAst ? (In: inferPredicate<this["tIn"], predicate>) => Out<this["tOut"]> : inferPredicate<t, predicate>, $>;
50
+ divisibleBy<const schema extends DivisorSchema>(this: validateChainedConstraint<"divisor", this>, schema: schema): Type<constrain<t, "divisor", schema>, $>;
51
+ matching<const schema extends RegexSchema>(this: validateChainedConstraint<"regex", this>, schema: schema): Type<constrain<t, "regex", schema>, $>;
52
+ atLeast<const schema extends InclusiveNumericRangeSchema>(this: validateChainedConstraint<"min", this>, schema: schema): Type<constrain<t, "min", schema>, $>;
53
+ atMost<const schema extends InclusiveNumericRangeSchema>(this: validateChainedConstraint<"max", this>, schema: schema): Type<constrain<t, "max", schema>, $>;
54
+ moreThan<const schema extends ExclusiveNumericRangeSchema>(this: validateChainedConstraint<"min", this>, schema: schema): Type<constrain<t, "min", exclusivizeRangeSchema<schema>>, $>;
55
+ lessThan<const schema extends ExclusiveNumericRangeSchema>(this: validateChainedConstraint<"max", this>, schema: schema): Type<constrain<t, "max", exclusivizeRangeSchema<schema>>, $>;
56
+ atLeastLength<const schema extends InclusiveNumericRangeSchema>(this: validateChainedConstraint<"minLength", this>, schema: schema): Type<constrain<t, "minLength", schema>, $>;
57
+ atMostLength<const schema extends InclusiveNumericRangeSchema>(this: validateChainedConstraint<"maxLength", this>, schema: schema): Type<constrain<t, "maxLength", schema>, $>;
58
+ moreThanLength<const schema extends ExclusiveNumericRangeSchema>(this: validateChainedConstraint<"minLength", this>, schema: schema): Type<constrain<t, "minLength", exclusivizeRangeSchema<schema>>, $>;
59
+ lessThanLength<const schema extends ExclusiveNumericRangeSchema>(this: validateChainedConstraint<"maxLength", this>, schema: schema): Type<constrain<t, "maxLength", exclusivizeRangeSchema<schema>>, $>;
60
+ exactlyLength<const schema extends ExactLengthSchema>(this: validateChainedConstraint<"exactLength", this>, schema: schema): Type<constrain<t, "exactLength", schema>, $>;
61
+ atOrAfter<const schema extends InclusiveDateRangeSchema>(this: validateChainedConstraint<"after", this>, schema: schema): Type<constrain<t, "after", schema>, $>;
62
+ atOrBefore<const schema extends InclusiveDateRangeSchema>(this: validateChainedConstraint<"before", this>, schema: schema): Type<constrain<t, "before", schema>, $>;
63
+ laterThan<const schema extends ExclusiveDateRangeSchema>(this: validateChainedConstraint<"after", this>, schema: schema): Type<constrain<t, "after", exclusivizeRangeSchema<schema>>, $>;
64
+ earlierThan<const schema extends ExclusiveDateRangeSchema>(this: validateChainedConstraint<"before", this>, schema: schema): Type<constrain<t, "before", exclusivizeRangeSchema<schema>>, $>;
46
65
  }
47
66
  export interface Type<
48
67
  /** @ts-expect-error allow instantiation assignment to the base type */
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-dev.18",
4
+ "version": "2.0.0-dev.19",
5
5
  "license": "MIT",
6
6
  "author": {
7
7
  "name": "David Blass",
@@ -24,8 +24,8 @@
24
24
  "out"
25
25
  ],
26
26
  "dependencies": {
27
- "@arktype/util": "0.0.46",
28
- "@arktype/schema": "0.1.10"
27
+ "@arktype/schema": "0.1.11",
28
+ "@arktype/util": "0.0.47"
29
29
  },
30
30
  "scripts": {
31
31
  "build": "tsx ../repo/build.ts",