Socket
Socket
Sign inDemoInstall

arktype

Package Overview
Dependencies
Maintainers
0
Versions
100
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

arktype - npm Package Compare versions

Comparing version 2.0.0-rc.9 to 2.0.0-rc.10

5

out/keywords/constructors/Date.d.ts

@@ -1,2 +0,2 @@

import type { Branded, constrain, constraint, Constraints, Literal, Narrowed, normalizeLimit, Optional } from "../inference.ts";
import type { Branded, constrain, constraint, Constraints, Default, Literal, Narrowed, normalizeLimit, Optional } from "../inference.ts";
export type AtOrAfter<rule> = {

@@ -21,2 +21,3 @@ atOrAfter: constraint<rule>;

type optional = constrain<Date, Optional>;
type defaultsTo<rule> = constrain<Date, Default<rule>>;
type branded<rule> = constrain<Date, Branded<rule>>;

@@ -31,3 +32,3 @@ type literal<rule> = constrain<Date, Literal<rule>>;

} ? Before<normalizeLimit<rule>> : AtOrBefore<normalizeLimit<rule>>;
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 Narrowed ? narrowed : never;
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;
}

19

out/keywords/inference.d.ts

@@ -16,3 +16,5 @@ import type { ArkError, ArkErrors, Constraint, constraintKindOf, Morph, NodeSchema } from "@ark/schema";

export type ConstraintSet = Record<PropertyKey, 1>;
export type Constraints = Record<string, ConstraintSet>;
export type Constraints = Record<string, ConstraintSet> | {
default?: unknown;
};
export declare const constrained: " arkConstrained";

@@ -56,4 +58,5 @@ export type constrained = typeof constrained;

};
export type applyConstraintSchema<t, kind extends Constraint.PrimitiveKind, schema extends NodeSchema<kind>> = t extends InferredMorph<infer i, infer o> ? (In: leftIfEqual<i, applyConstraint<i, schemaToConstraint<kind, schema>>>) => o : leftIfEqual<t, applyConstraint<t, schemaToConstraint<kind, schema>>>;
export type applyConstraint<t, constraint> = parseConstraints<t> extends ([
export type applyConstraintSchema<t, kind extends Constraint.PrimitiveKind, schema extends NodeSchema<kind>> = applyConstraint<t, schemaToConstraint<kind, schema>>;
export type applyConstraint<t, constraint> = t extends InferredMorph<infer i, infer o> ? (In: leftIfEqual<i, _applyConstraint<i, constraint>>) => o : leftIfEqual<t, _applyConstraint<t, constraint>>;
type _applyConstraint<t, constraint> = parseConstraints<t> extends ([
infer base,

@@ -156,3 +159,3 @@ infer constraints extends Constraints

infer constraints extends Constraints
]) ? 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 InferredDefault<infer t> ? _distill<t, opts> : t extends Function ? t : isSafelyMappable<t> extends true ? distillMappable<t, opts> : t;
]) ? 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;
type distillMappable<o, opts extends distill.Options> = opts["endpoint"] extends "in" ? show<{

@@ -198,4 +201,8 @@ [k in keyof o as k extends inferredOptionalOrDefaultKeyOf<o> ? never : k]: _distill<o[k], opts>;

export type InferredOptional<t = unknown> = constrain<t, Optional>;
export type Default<v = any> = ["=", v];
export type InferredDefault<t = any, v = any> = (In?: t) => Default<v>;
export type Default<v = any> = {
default?: {
value: v;
};
};
export type InferredDefault<t = unknown, v = any> = constrain<t, Default<v>>;
export type termOrType<t> = t | Type<t, any>;

@@ -202,0 +209,0 @@ export type inferIntersection<l, r> = _inferIntersection<l, r, false>;

import type { Module, Submodule } from "../../module.ts";
import type { Branded, constrain, constraint, Constraints, Narrowed, Optional } from "../inference.ts";
import type { Branded, constrain, constraint, Constraints, Default, Narrowed, Optional } from "../inference.ts";
import { epoch } from "./epoch.ts";

@@ -29,2 +29,3 @@ import { integer } from "./integer.ts";

type optional = constrain<number, Optional>;
type defaultsTo<rule> = constrain<number, Default<rule>>;
type branded<rule> = constrain<number, Branded<rule>>;

@@ -42,3 +43,3 @@ type NaN = branded<"NaN">;

} ? LessThan<rule> : AtMost<rule>;
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 Narrowed ? narrowed : never;
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;
type module = Module<submodule>;

@@ -45,0 +46,0 @@ type submodule = Submodule<$>;

import type { Module, Submodule } from "../../module.ts";
import type { AtLeastLength, AtMostLength, Branded, Constraints, ExactlyLength, LessThanLength, MoreThanLength, Narrowed, Optional, constrain, constraint } from "../inference.ts";
import type { AtLeastLength, AtMostLength, Branded, Constraints, Default, ExactlyLength, LessThanLength, MoreThanLength, Narrowed, Optional, constrain, constraint } from "../inference.ts";
import { alpha } from "./alpha.ts";

@@ -82,5 +82,6 @@ import { alphanumeric } from "./alphanumeric.ts";

type optional = constrain<string, Optional>;
type defaultsTo<rule> = constrain<string, Default<rule>>;
type branded<rule> = constrain<string, Branded<rule>>;
type is<constraints extends Constraints> = constrain<string, constraints>;
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 Narrowed ? narrowed : never;
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;
type module = Module<string.submodule>;

@@ -87,0 +88,0 @@ type submodule = Submodule<$>;

import type { ArkErrors, BaseRoot, Disjoint, JsonSchema, MetaSchema, Morph, UndeclaredKeyBehavior } from "@ark/schema";
import type { anyOrNever, array, Callable, ErrorMessage, inferred, Json, unset } from "@ark/util";
import type { ArkAmbient } from "../config.ts";
import type { applyConstraint, Default, distill, inferIntersection, inferMorphOut, inferPipes, Optional } from "../keywords/inference.ts";
import type { applyConstraint, Default, distill, inferIntersection, inferMorphOut, inferPipes, InferredMorph, Optional, To } from "../keywords/inference.ts";
import type { type } from "../keywords/keywords.ts";

@@ -18,2 +18,5 @@ import type { Scope } from "../scope.ts";

inferIn: distill.In<t>;
inferredOutIsIntrospectable: t extends InferredMorph<any, infer o> ? [
o
] extends [anyOrNever] ? true : o extends To ? true : false : true;
[inferred]: t;

@@ -54,3 +57,3 @@ json: Json;

optional<r = applyConstraint<t, Optional>>(): instantiateType<r, $>;
default<value extends this["infer"], r = (In?: this["inferBrandableIn"]) => Default<value>>(value: value): instantiateType<r, $>;
default<const value extends this["inferIn"], r = applyConstraint<t, Default<value>>>(value: value): instantiateType<r, $>;
/** @deprecated */

@@ -57,0 +60,0 @@ apply: Function["apply"];

@@ -10,4 +10,4 @@ import type { Predicate, PredicateCast } from "@ark/schema";

narrowed
] extends [never] ? applyConstraintSchema<this["inferBrandableOut"], "predicate", Predicate> : narrowed) extends infer o ? this["inferIntrospectableOut"] extends this["inferBrandableOut"] ? (In: this["inferBrandableIn"]) => To<o> : (In: this["inferBrandableIn"]) => Out<o> : never, $>;
] extends [never] ? applyConstraintSchema<this["inferBrandableOut"], "predicate", Predicate> : narrowed) extends infer o ? this["inferredOutIsIntrospectable"] extends true ? (In: this["inferBrandableIn"]) => To<o> : (In: this["inferBrandableIn"]) => Out<o> : never, $>;
}
export type { Type as MorphType };
import type { BaseMappedPropInner, OptionalMappedPropInner, Prop } from "@ark/schema";
import type { anyOrNever, arkGet, arkIndexableOf, arkKeyOf, array, ErrorType, inferred, intersectUnion, Json, Key, listable, merge, optionalKeyOf, show, toArkKey } from "@ark/util";
import type { Default, InferredDefault, InferredOptional } from "../keywords/inference.ts";
import type { arkGet, arkIndexableOf, arkKeyOf, array, ErrorType, inferred, intersectUnion, Json, Key, listable, merge, optionalKeyOf, show, toArkKey } from "@ark/util";
import type { applyConstraint, constrain, Default, Optional, parseConstraints } from "../keywords/inference.ts";
import type { type } from "../keywords/keywords.ts";

@@ -35,8 +35,7 @@ import type { ArrayType } from "./array.ts";

}
type typePropOf<o, $> = {
[k in keyof o]-?: typeProp<o, k, $>;
}[keyof o] & unknown;
type typeProp<o, k extends keyof o, $, t = o[k] & ({} | null)> = t extends InferredDefault<infer v, infer defaultValue> ? DefaultedTypeProp<k & Key, v, defaultValue, $> : BaseTypeProp<k extends optionalKeyOf<o> ? "optional" : t extends InferredOptional ? [
t
] extends [anyOrNever] ? "required" : "optional" : "required", k & Key, t, $>;
type typePropOf<o, $> = keyof o extends infer k ? k extends keyof o ? typeProp<o, k, $> : never : never;
type typeProp<o, k extends keyof o, $, t = o[k] & ({} | null)> = parseConstraints<t> extends ([
infer base,
infer constraints extends Default | Optional
]) ? 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, $>;
export interface BaseTypeProp<kind extends Prop.Kind = Prop.Kind, k extends Key = Key,

@@ -78,3 +77,3 @@ /** @ts-ignore cast variance */

default: unknown;
}>["key"]]: (In?: prop["value"][inferred]) => Default<prop["default" & keyof prop]>;
}>["key"]]: applyConstraint<prop["value"][inferred], Default<prop["default" & keyof prop]>>;
}>;

@@ -81,0 +80,0 @@ type applyHomomorphicOptionality<t, prop extends MappedTypeProp> = prop["kind"] extends string ? prop : prop & {

@@ -28,3 +28,3 @@ import type { GenericAst } from "@ark/schema";

[i in keyof g["names"] & `${number}` as g["names"][i]]: inferExpression<argAsts[i & keyof argAsts], resolveScope<g["arg$"], $>, args>;
}> : 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 ? (In?: 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;
}> : 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;
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", {

@@ -31,0 +31,0 @@ rule: normalizeLimit<limit>;

@@ -57,17 +57,2 @@ import { normalizeIndex } from "@ark/schema";

}
if (parsedValue.meta) {
if ("default" in parsedValue.meta) {
return ctx.$.node("optional", {
key: parsedKey.key,
value: parsedValue,
default: parsedValue.meta.default
});
}
if (parsedValue.meta.optional) {
return ctx.$.node("optional", {
key: parsedKey.key,
value: parsedValue
});
}
}
return ctx.$.node(parsedKey.kind, {

@@ -74,0 +59,0 @@ key: parsedKey.key,

@@ -113,3 +113,3 @@ import { type BaseParseContext, type BaseRoot, type MetaSchema, type Morph, type Predicate } from "@ark/schema";

export type inferTuple<def extends array, $, args> = def extends TupleExpression ? inferTupleExpression<def, $, args> : inferTupleLiteral<def, $, args>;
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 "=" ? (In?: 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;
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;
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;

@@ -116,0 +116,0 @@ export type validatePostfixExpression<def extends PostfixExpression, $, args> = conform<def, readonly [validateDefinition<def[0], $, args>, "[]" | "?"]>;

@@ -16,3 +16,3 @@ import { ArkErrors, BaseRoot, type BaseParseOptions, type MetaSchema, type Morph, type Predicate, type RootSchema } from "@ark/schema";

<const params extends ParameterString, const def>(params: validateParameterString<params, $>, def: validateDefinition<def, $, baseGenericConstraints<parseValidGenericParams<params, $>>>): Generic<parseValidGenericParams<params, $>, def, $>;
<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] : [type.validate<rest[0], $>] : []): r;
<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;
errors: typeof ArkErrors;

@@ -19,0 +19,0 @@ hkt: typeof Hkt;

{
"name": "arktype",
"description": "TypeScript's 1:1 validator, optimized from editor to runtime",
"version": "2.0.0-rc.9",
"version": "2.0.0-rc.10",
"license": "MIT",

@@ -37,4 +37,4 @@ "author": {

"dependencies": {
"@ark/schema": "0.11.0",
"@ark/util": "0.11.0"
"@ark/util": "0.12.0",
"@ark/schema": "0.12.0"
},

@@ -41,0 +41,0 @@ "publishConfig": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc