Socket
Socket
Sign inDemoInstall

arktype

Package Overview
Dependencies
Maintainers
1
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.5 to 2.0.0-rc.6

70

out/generic.d.ts
import { GenericRoot, type arkKind, type GenericAst, type GenericParamAst, type GenericParamDef, type genericParamNames, type LazyGenericBody } from "@ark/schema";
import { type array, type Callable, type conform, type ErrorMessage, type ErrorType, type Hkt, type Json, type WhiteSpaceToken } from "@ark/util";
import type { type } from "./keywords/ark.ts";
import type { inferDefinition, validateDefinition } from "./parser/definition.ts";

@@ -10,11 +11,11 @@ import type { inferAstRoot } from "./parser/semantic/infer.ts";

import type { ParseContext, Scope } from "./scope.ts";
import type { inferTypeRoot, Type, validateTypeRoot } from "./type.ts";
import type { Type } from "./type.ts";
export type ParameterString<params extends string = string> = `<${params}>`;
export type extractParams<s extends ParameterString> = s extends ParameterString<infer params> ? params : never;
export type validateParameterString<s extends ParameterString, $> = parseGenericParams<extractParams<s>, $> extends infer e extends ErrorMessage ? e : s;
export type validateGenericArg<arg, param extends GenericParamAst, $> = inferTypeRoot<arg, $> extends param[1] ? unknown : ErrorType<`Invalid argument for ${param[0]}`, [expected: param[1]]>;
export type validateGenericArg<arg, param extends GenericParamAst, $> = type.infer<arg, $> extends param[1] ? unknown : ErrorType<`Invalid argument for ${param[0]}`, [expected: param[1]]>;
export type GenericInstantiator<params extends array<GenericParamAst>, def, $, args$> = params["length"] extends 1 ? {
<const a, r = instantiateGeneric<def, params, [a], $, args$>>(a: validateTypeRoot<a, args$> & validateGenericArg<a, params[0], args$>): r;
<const a, r = instantiateGeneric<def, params, [a], $, args$>>(a: type.validate<a, args$> & validateGenericArg<a, params[0], args$>): r;
} : params["length"] extends 2 ? {
<const a, const b, r = instantiateGeneric<def, params, [a, b], $, args$>>(...args: [validateTypeRoot<a, args$>, validateTypeRoot<b, args$>] & [
<const a, const b, r = instantiateGeneric<def, params, [a, b], $, args$>>(...args: [type.validate<a, args$>, type.validate<b, args$>] & [
validateGenericArg<a, params[0], args$>,

@@ -25,5 +26,5 @@ validateGenericArg<b, params[1], args$>

<const a, const b, const c, r = instantiateGeneric<def, params, [a, b, c], $, args$>>(...args: [
validateTypeRoot<a, args$>,
validateTypeRoot<b, args$>,
validateTypeRoot<c, args$>
type.validate<a, args$>,
type.validate<b, args$>,
type.validate<c, args$>
] & [

@@ -36,6 +37,6 @@ validateGenericArg<a, params[0], args$>,

<const a, const b, const c, const d, r = instantiateGeneric<def, params, [a, b, c, d], $, args$>>(...args: [
validateTypeRoot<a, args$>,
validateTypeRoot<b, args$>,
validateTypeRoot<c, args$>,
validateTypeRoot<d, args$>
type.validate<a, args$>,
type.validate<b, args$>,
type.validate<c, args$>,
type.validate<d, args$>
] & [

@@ -49,7 +50,7 @@ validateGenericArg<a, params[0], args$>,

<const a, const b, const c, const d, const e, r = instantiateGeneric<def, params, [a, b, c, d, e], $, args$>>(...args: [
validateTypeRoot<a, args$>,
validateTypeRoot<b, args$>,
validateTypeRoot<c, args$>,
validateTypeRoot<d, args$>,
validateTypeRoot<e, args$>
type.validate<a, args$>,
type.validate<b, args$>,
type.validate<c, args$>,
type.validate<d, args$>,
type.validate<e, args$>
] & [

@@ -64,8 +65,8 @@ validateGenericArg<a, params[0], args$>,

<const a, const b, const c, const d, const e, const f, r = instantiateGeneric<def, params, [a, b, c, d, e, f], $, args$>>(...args: [
validateTypeRoot<a, args$>,
validateTypeRoot<b, args$>,
validateTypeRoot<c, args$>,
validateTypeRoot<d, args$>,
validateTypeRoot<e, args$>,
validateTypeRoot<f, args$>
type.validate<a, args$>,
type.validate<b, args$>,
type.validate<c, args$>,
type.validate<d, args$>,
type.validate<e, args$>,
type.validate<f, args$>
] & [

@@ -81,9 +82,9 @@ validateGenericArg<a, params[0], args$>,

<const a, const b, const c, const d, const e, const f, const g, r = instantiateGeneric<def, params, [a, b, c, d, e, f, g], $, args$>>(...args: [
validateTypeRoot<a, args$>,
validateTypeRoot<b, args$>,
validateTypeRoot<c, args$>,
validateTypeRoot<d, args$>,
validateTypeRoot<e, args$>,
validateTypeRoot<f, args$>,
validateTypeRoot<g, args$>
type.validate<a, args$>,
type.validate<b, args$>,
type.validate<c, args$>,
type.validate<d, args$>,
type.validate<e, args$>,
type.validate<f, args$>,
type.validate<g, args$>
] & [

@@ -102,6 +103,6 @@ validateGenericArg<a, params[0], args$>,

] extends [Hkt] ? Hkt.apply<def, {
[i in keyof args]: inferTypeRoot<args[i], args$>;
[i in keyof args]: type.infer<args[i], args$>;
}> : inferDefinition<def, $, bindGenericArgs<params, args$, args>>, args$>;
type bindGenericArgs<params extends array<GenericParamAst>, $, args> = {
[i in keyof params & `${number}` as params[i][0]]: inferTypeRoot<args[i & keyof args], $>;
[i in keyof params & `${number}` as params[i][0]]: type.infer<args[i & keyof args], $>;
};

@@ -153,6 +154,3 @@ type baseGenericResolutions<params extends array<GenericParamAst>, $> = baseGenericConstraints<params> extends infer baseConstraints ? {

], $>;
type genericParamDefToAst<schema extends GenericParamDef, $> = schema extends string ? [schema, unknown] : schema extends readonly [infer name, infer def] ? [
name,
inferTypeRoot<def, $>
] : never;
type genericParamDefToAst<schema extends GenericParamDef, $> = schema extends string ? [schema, unknown] : schema extends readonly [infer name, infer def] ? [name, type.infer<def, $>] : never;
export type genericParamDefsToAst<defs extends array<GenericParamDef>, $> = [

@@ -164,3 +162,3 @@ ...{

export type GenericParser<$ = {}> = <const paramsDef extends array<GenericParamDef>>(...params: {
[i in keyof paramsDef]: paramsDef[i] extends (readonly [infer name, infer def]) ? readonly [name, validateTypeRoot<def, $>] : paramsDef[i];
[i in keyof paramsDef]: paramsDef[i] extends (readonly [infer name, infer def]) ? readonly [name, type.validate<def, $>] : paramsDef[i];
}) => GenericBodyParser<genericParamDefsToAst<paramsDef, $>, $>;

@@ -167,0 +165,0 @@ interface GenericBodyParser<params extends array<GenericParamAst>, $> {

@@ -7,2 +7,2 @@ export { ArkError, ArkErrors, type ArkConfig, type ArkScopeConfig, type JsonSchema } from "@ark/schema";

export { module, scope, type Scope, type inferScope, type validateScope } from "./scope.ts";
export { Type, type inferAmbient, type inferTypeRoot, type validateAmbient, type validateTypeRoot } from "./type.ts";
export { Type } from "./type.ts";

@@ -20,6 +20,4 @@ import type { anyOrNever, array, Hkt, intersectArrays, show } from "@ark/util";

}
type intersectObjects<l, r, piped extends boolean> = [
l,
r
] extends [infer lList extends array, infer rList extends array] ? intersectArrays<lList, rList, MorphableIntersection<piped>> : show<{
type intersectObjects<l, r, piped extends boolean> = l extends array ? r extends array ? intersectArrays<l, r, MorphableIntersection<piped>> : // for an intersection with exactly one array operand like { name: string } & string[],
l & r : r extends array ? l & r : show<{
[k in keyof l]: k extends keyof r ? _inferIntersection<l[k], r[k], piped> : l[k];

@@ -26,0 +24,0 @@ } & {

@@ -5,5 +5,5 @@ import type { ArkErrors, arkKind } from "@ark/schema";

import type { BoundModule, Module } from "../module.ts";
import type { inferDefinition } from "../parser/definition.ts";
import { type Scope } from "../scope.ts";
import type { DeclarationParser, DefinitionParser, Type, TypeParser, validateTypeRoot } from "../type.ts";
import type { inferDefinition, validateDefinition } from "../parser/definition.ts";
import { type bindThis, type Scope } from "../scope.ts";
import type { DeclarationParser, DefinitionParser, Type, TypeParser } from "../type.ts";
import type { distill } from "./ast.ts";

@@ -14,3 +14,3 @@ import { arkBuiltins } from "./builtins.ts";

import { string } from "./string/string.ts";
import { arkTsGenerics, arkTsKeywords } from "./ts.ts";
import { arkTsGenerics, arkTsKeywords, unknown } from "./ts.ts";
export interface Ark extends Omit<Ark.keywords, keyof Ark.wrapped>, Ark.wrapped {

@@ -24,2 +24,3 @@ }

number: number.submodule;
unknown: unknown.submodule;
}

@@ -41,3 +42,3 @@ interface typeAttachments extends arkTsKeywords.$ {

type errors = ArkErrors;
type infer<def, $ = {}, args = {}> = inferDefinition<def, $, args>;
type infer<def, $ = {}, args = bindThis<def>> = inferDefinition<def, $, args>;
namespace infer {

@@ -54,3 +55,3 @@ type In<def, $ = {}, args = {}> = distill.In<inferDefinition<def, $, args>>;

}
type validate<def, $ = {}> = validateTypeRoot<def, $>;
type validate<def, $ = {}, args = bindThis<def>> = validateDefinition<def, $, args>;
}

@@ -57,0 +58,0 @@ export type type<t = unknown, $ = {}> = Type<t, $>;

@@ -6,3 +6,3 @@ import { $arkTypeRegistry, scope } from "../scope.js";

import { string } from "./string/string.js";
import { arkTsGenerics, arkTsKeywords } from "./ts.js";
import { arkTsGenerics, arkTsKeywords, unknown } from "./ts.js";
$arkTypeRegistry.typeAttachments = {

@@ -19,3 +19,4 @@ ...arkTsKeywords,

string,
number
number,
unknown
}, { prereducedAliases: true, ambient: true });

@@ -22,0 +23,0 @@ export const ark = ambient.export();

@@ -150,19 +150,21 @@ import type { ArkError, ArkErrors, Constraint, constraintKindOf, Morph, NodeSchema } from "@ark/schema";

} extends t ? opts["endpoint"] extends "in" ? show<{
[k in keyof t as k extends defaultedKeyOf<t> | metaOptionalKey<t> ? never : k]: _distill<t[k], opts>;
[k in keyof t as k extends optionalInputKeyOf<t> ? never : k]: _distill<t[k], opts>;
} & {
[k in defaultedKeyOf<t> | metaOptionalKey<t>]?: _distill<t[k], opts>;
[k in optionalInputKeyOf<t>]?: _distill<t[k], opts>;
}> : show<{
[k in keyof t as k extends metaOptionalKey<t> ? never : k]: _distill<t[k], opts>;
[k in keyof t as k extends metaOptionalKeyOf<t> ? never : k]: _distill<t[k], opts>;
} & {
[k in keyof t as k extends metaOptionalKey<t> ? k : never]?: _distill<t[k], opts>;
[k in keyof t as k extends metaOptionalKeyOf<t> ? k : never]?: _distill<t[k], opts>;
}> : t;
type defaultedKeyOf<t> = {
[k in keyof t]: [t[k]] extends [anyOrNever] ? never : t[k] extends DefaultedAst ? k : never;
}[keyof t];
type metaOptionalKey<o> = {
[k in keyof o]: o[k] extends OptionalAst ? [
o[k]
] extends [anyOrNever] ? never : k : never;
type optionalInputKeyOf<o> = metaDefaultedKeyOf<o> | metaOptionalKeyOf<o>;
type metaDefaultedKeyOf<o> = {
[k in keyof o]: [o[k]] extends [anyOrNever] ? never : o[k] extends DefaultedAst ? k : never;
}[keyof o];
type distillArray<t extends array, opts extends distill.Options, prefix extends array> = _distillArray<t, opts, prefix> extends infer result ? t extends unknown[] ? result : Readonly<t> : never;
type metaOptionalKeyOf<o> = {
[k in keyof o]: [o[k]] extends [anyOrNever] ? never : o[k] extends OptionalAst ? k : never;
}[keyof o];
type distillArray<t extends array, opts extends distill.Options, prefix extends array> = _distillArray<t, opts, prefix> extends infer result ? (t extends unknown[] ? result : Readonly<t>) & // re-intersect non-array props for a type like `{ name: string } & string[]`
_distill<{
[k in keyof t as k extends keyof unknown[] ? never : k]: t[k];
}, opts> : never;
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>];

@@ -169,0 +171,0 @@ 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]> : [...{

import { genericNode, intrinsic } from "@ark/schema";
import { Hkt } from "@ark/util";
import { submodule } from "./utils.js";
import { arkModule } from "./utils.js";
class MergeHkt extends Hkt {
}
const Merge = genericNode(["base", intrinsic.object], ["props", intrinsic.object])(args => args.base.merge(args.props), MergeHkt);
export const arkBuiltins = submodule({
export const arkBuiltins = arkModule({
Key: intrinsic.key,
Merge
});
import { genericNode, intrinsic, rootNode } from "@ark/schema";
import { Hkt, liftArray } from "@ark/util";
import { submodule } from "../utils.js";
import { arkModule } from "../utils.js";
class liftFromHkt extends Hkt {

@@ -14,3 +14,3 @@ }

}, liftFromHkt);
export const arkArray = submodule({
export const arkArray = arkModule({
root: intrinsic.Array,

@@ -17,0 +17,0 @@ readonly: "root",

import { ecmascriptConstructors, flatMorph, platformConstructors } from "@ark/util";
import { submodule } from "../utils.js";
import { arkModule } from "../utils.js";
import { arkArray } from "./Array.js";

@@ -11,3 +11,3 @@ import { arkFormData } from "./FormData.js";

};
export const arkPrototypes = submodule({
export const arkPrototypes = arkModule({
...flatMorph({ ...ecmascriptConstructors, ...platformConstructors }, (k, v) => (k in omittedPrototypes ? [] : [k, ["instanceof", v]])),

@@ -14,0 +14,0 @@ Array: arkArray,

import { rootNode } from "@ark/schema";
import { registry } from "@ark/util";
import { submodule } from "../utils.js";
import { arkModule } from "../utils.js";
const value = rootNode(["string", registry.FileConstructor]);

@@ -14,3 +14,3 @@ const parsedFormDataValue = value.or(value.array());

});
export const arkFormData = submodule({
export const arkFormData = arkModule({
root: ["instanceof", FormData],

@@ -17,0 +17,0 @@ value,

@@ -1,3 +0,3 @@

import { submodule } from "../utils.js";
export const TypedArray = submodule({
import { arkModule } from "../utils.js";
export const TypedArray = arkModule({
Int8: ["instanceof", Int8Array],

@@ -4,0 +4,0 @@ Uint8: ["instanceof", Uint8Array],

@@ -30,2 +30,6 @@ import type { Module, Submodule } from "../../module.ts";

type branded<rule> = constrain<number, Branded<rule>>;
type NaN = branded<"NaN">;
type Infinity = branded<"Infinity">;
type NegativeInfinity = branded<"NegativeInfinity">;
type safe = branded<"safe">;
type is<constraints extends Constraints> = constrain<number, constraints>;

@@ -45,3 +49,7 @@ type minSchemaToConstraint<schema, rule> = schema extends {

integer: integer;
safe: safe;
NaN: NaN;
Infinity: Infinity;
NegativeInfinity: NegativeInfinity;
};
}

@@ -1,9 +0,21 @@

import { intrinsic } from "@ark/schema";
import { submodule } from "../utils.js";
import { intrinsic, rootNode } from "@ark/schema";
import { arkModule } from "../utils.js";
import { epoch } from "./epoch.js";
import { integer } from "./integer.js";
export const number = submodule({
export const number = arkModule({
root: intrinsic.number,
integer,
epoch
epoch,
safe: rootNode({
domain: "number",
min: Number.MIN_SAFE_INTEGER,
max: Number.MAX_SAFE_INTEGER,
predicate: {
predicate: n => !Number.isNaN(n),
meta: "a safe number"
}
}),
NaN: ["===", Number.NaN],
Infinity: ["===", Number.POSITIVE_INFINITY],
NegativeInfinity: ["===", Number.NEGATIVE_INFINITY]
});
import { rootNode } from "@ark/schema";
import { submodule } from "../utils.js";
import { arkModule } from "../utils.js";
import { regexStringNode } from "./utils.js";
const preformatted = regexStringNode(/^[A-Z].*$/, "capitalized");
export const capitalize = submodule({
export const capitalize = arkModule({
root: rootNode({

@@ -7,0 +7,0 @@ in: "string",

import type { Module, Submodule } from "../../module.ts";
import type { type } from "../ark.ts";
import type { Branded, To, constrain } from "../ast.ts";

@@ -41,5 +40,2 @@ type DayDelimiter = "." | "/" | "-";

};
type shallowResolutions = {
[k in keyof $ as `string.date.${k}`]: $[k] extends type.cast<infer t> ? t : $[k];
};
namespace iso {

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

import { ArkErrors, intrinsic, rootNode } from "@ark/schema";
import { number } from "../number/number.js";
import { submodule } from "../utils.js";
import { arkModule } from "../utils.js";
import { integer } from "./integer.js";

@@ -66,3 +66,3 @@ import { regexStringNode } from "./utils.js";

.assertHasKind("intersection");
const epoch = submodule({
const epoch = arkModule({
root: epochroot,

@@ -76,3 +76,3 @@ parse: rootNode({

const isoroot = regexStringNode(iso8601Matcher, "an ISO 8601 (YYYY-MM-DDTHH:mm:ss.sssZ) date").internal.assertHasKind("intersection");
const iso = submodule({
const iso = arkModule({
root: isoroot,

@@ -85,3 +85,3 @@ parse: rootNode({

});
export const stringDate = submodule({
export const stringDate = arkModule({
root: parsableDate,

@@ -88,0 +88,0 @@ parse: rootNode({

import { intrinsic, rootNode } from "@ark/schema";
import { wellFormedIntegerMatcher } from "@ark/util";
import { submodule } from "../utils.js";
import { arkModule } from "../utils.js";
import { regexStringNode } from "./utils.js";
const root = regexStringNode(wellFormedIntegerMatcher, "a well-formed integer string");
export const integer = submodule({
export const integer = arkModule({
root,

@@ -8,0 +8,0 @@ parse: rootNode({

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

import { submodule } from "../utils.js";
import { arkModule } from "../utils.js";
import { regexStringNode } from "./utils.js";

@@ -19,3 +19,3 @@ // Based on https://github.com/validatorjs/validator.js/blob/master/src/lib/isIP.js

// Based on https://github.com/validatorjs/validator.js/blob/master/src/lib/isUUID.js
export const ip = submodule({
export const ip = arkModule({
root: ["v4 | v6", "@", "an IP address"],

@@ -22,0 +22,0 @@ v4: regexStringNode(ipv4Matcher, "an IPv4 address"),

import { intrinsic, rootNode } from "@ark/schema";
import { submodule } from "../utils.js";
import { arkModule } from "../utils.js";
const jsonStringDescription = "a JSON string";

@@ -20,3 +20,3 @@ const isParsableJson = (s) => {

});
export const json = submodule({
export const json = arkModule({
root,

@@ -23,0 +23,0 @@ parse: rootNode({

import { rootNode } from "@ark/schema";
import { submodule } from "../utils.js";
import { arkModule } from "../utils.js";
import { regexStringNode } from "./utils.js";
const preformatted = regexStringNode(/^[a-z]*$/, "only lowercase letters");
export const lower = submodule({
export const lower = arkModule({
root: rootNode({

@@ -7,0 +7,0 @@ in: "string",

import type { Module, Submodule } from "../../module.ts";
import type { type } from "../ark.ts";
import type { Branded, constrain, To } from "../ast.ts";

@@ -60,5 +59,2 @@ declare namespace string {

};
type shallowResolutions = {
[k in keyof $ as `string.normalize.${k}`]: $[k] extends type.cast<infer t> ? t : $[k];
};
namespace NFC {

@@ -65,0 +61,0 @@ type submodule = Submodule<$>;

import { rootNode } from "@ark/schema";
import { flatMorph } from "@ark/util";
import { submodule } from "../utils.js";
import { arkModule } from "../utils.js";
export const normalizedForms = ["NFC", "NFD", "NFKC", "NFKD"];

@@ -21,19 +21,19 @@ const preformattedNodes = flatMorph(normalizedForms, (i, form) => [

]);
export const NFC = submodule({
export const NFC = arkModule({
root: normalizeNodes.NFC,
preformatted: preformattedNodes.NFC
});
export const NFD = submodule({
export const NFD = arkModule({
root: normalizeNodes.NFD,
preformatted: preformattedNodes.NFD
});
export const NFKC = submodule({
export const NFKC = arkModule({
root: normalizeNodes.NFKC,
preformatted: preformattedNodes.NFKC
});
export const NFKD = submodule({
export const NFKD = arkModule({
root: normalizeNodes.NFKD,
preformatted: preformattedNodes.NFKD
});
export const normalize = submodule({
export const normalize = arkModule({
root: "NFC",

@@ -40,0 +40,0 @@ NFC,

import { intrinsic, rootNode } from "@ark/schema";
import { wellFormedNumberMatcher } from "@ark/util";
import { submodule } from "../utils.js";
import { arkModule } from "../utils.js";
import { regexStringNode } from "./utils.js";
const root = regexStringNode(wellFormedNumberMatcher, "a well-formed numeric string");
export const numeric = submodule({
export const numeric = arkModule({
root,

@@ -8,0 +8,0 @@ parse: rootNode({

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

@@ -102,2 +101,3 @@ import { alpha } from "./alpha.ts";

date: stringDate.submodule;
url: url.submodule;
trim: trim.submodule;

@@ -109,5 +109,2 @@ normalize: normalize.submodule;

};
type shallowResolutions = {
[k in keyof $ as `string.${k}`]: $[k] extends type.cast<infer t> ? t : $[k];
};
}
import { intrinsic } from "@ark/schema";
import { submodule } from "../utils.js";
import { arkModule } from "../utils.js";
import { alpha } from "./alpha.js";

@@ -21,3 +21,3 @@ import { alphanumeric } from "./alphanumeric.js";

import { uuid } from "./uuid.js";
export const string = submodule({
export const string = arkModule({
root: intrinsic.string,

@@ -24,0 +24,0 @@ numeric,

import { rootNode } from "@ark/schema";
import { submodule } from "../utils.js";
import { arkModule } from "../utils.js";
import { regexStringNode } from "./utils.js";

@@ -7,3 +7,3 @@ const preformatted = regexStringNode(

/^\S.*\S$|^\S?$/, "trimmed");
export const trim = submodule({
export const trim = arkModule({
root: rootNode({

@@ -10,0 +10,0 @@ in: "string",

import { rootNode } from "@ark/schema";
import { submodule } from "../utils.js";
import { arkModule } from "../utils.js";
import { regexStringNode } from "./utils.js";
const preformatted = regexStringNode(/^[A-Z]*$/, "only uppercase letters");
export const upper = submodule({
export const upper = arkModule({
root: rootNode({

@@ -7,0 +7,0 @@ in: "string",

import { rootNode } from "@ark/schema";
import { submodule } from "../utils.js";
import { arkModule } from "../utils.js";
const isParsableUrl = (s) => {

@@ -22,3 +22,3 @@ if (URL.canParse)

});
export const url = submodule({
export const url = arkModule({
root,

@@ -25,0 +25,0 @@ parse: rootNode({

@@ -1,5 +0,5 @@

import { submodule } from "../utils.js";
import { arkModule } from "../utils.js";
import { regexStringNode } from "./utils.js";
// Based on https://github.com/validatorjs/validator.js/blob/master/src/lib/isUUID.js
export const uuid = submodule({
export const uuid = arkModule({
// the meta tuple expression ensures the error message does not delegate

@@ -6,0 +6,0 @@ // to the individual branches, which are too detailed

@@ -22,2 +22,13 @@ import { Hkt, type Key, type omit, type pick, type show } from "@ark/util";

}
export declare const unknown: Module<{
root: unknown;
any: unknown;
}>;
export declare namespace unknown {
type submodule = Submodule<$>;
type $ = {
root: unknown;
any: any;
};
}
declare class RecordHkt extends Hkt<[Key, unknown]> {

@@ -24,0 +35,0 @@ body: Record<this[0], this[1]>;

import { genericNode, intrinsic } from "@ark/schema";
import { Hkt } from "@ark/util";
import { submodule } from "./utils.js";
export const arkTsKeywords = submodule({
import { arkModule } from "./utils.js";
export const arkTsKeywords = arkModule({
bigint: intrinsic.bigint,

@@ -18,2 +18,6 @@ boolean: intrinsic.boolean,

});
export const unknown = arkModule({
root: intrinsic.unknown,
any: intrinsic.unknown
});
class RecordHkt extends Hkt {

@@ -46,3 +50,3 @@ }

const Extract = genericNode("T", "U")(args => args.T.extract(args.U), ExtractHkt);
export const arkTsGenerics = submodule({
export const arkTsGenerics = arkModule({
Record,

@@ -49,0 +53,0 @@ Pick,

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

export declare const submodule: import("../scope.ts").ModuleParser;
export declare const arkModule: import("../scope.ts").ModuleParser;
import { module } from "../scope.js";
export const submodule = module;
export const arkModule = module;
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 { inferIntersection } from "../intersect.ts";
import type { type } from "../keywords/ark.ts";
import type { applyConstraint, Default, distill, inferMorphOut, inferPipes, Optional } from "../keywords/ast.ts";
import type { Scope } from "../scope.ts";
import type { inferTypeRoot, validateTypeRoot } from "../type.ts";
import type { ArrayType } from "./array.ts";

@@ -12,5 +12,5 @@ import type { instantiateType } from "./instantiate.ts";

t: t;
tIn: distill.brandable.In<t>;
tOut: distill.brandable.Out<t>;
tValidatedOut: distill.introspectable.Out<t>;
inferBrandableIn: distill.brandable.In<t>;
inferBrandableOut: distill.brandable.Out<t>;
inferIntrospectableOut: distill.introspectable.Out<t>;
infer: distill.Out<t>;

@@ -31,3 +31,3 @@ inferIn: distill.In<t>;

optional<r = applyConstraint<t, Optional>>(): instantiateType<r, $>;
default<value extends this["infer"], r = (In?: this["tIn"]) => Default<value>>(value: value): instantiateType<r, $>;
default<value extends this["infer"], r = (In?: this["inferBrandableIn"]) => Default<value>>(value: value): instantiateType<r, $>;
onUndeclaredKey(behavior: UndeclaredKeyBehavior): this;

@@ -37,14 +37,14 @@ onDeepUndeclaredKey(behavior: UndeclaredKeyBehavior): this;

as<t = unset>(...args: validateChainedAsArgs<t>): instantiateType<t, $>;
get in(): instantiateType<this["tIn"], $>;
get out(): instantiateType<this["tValidatedOut"], $>;
intersect<const def, r = inferTypeRoot<def, $>>(def: validateTypeRoot<def, $>): instantiateType<inferIntersection<t, r>, $> | Disjoint;
and<const def, r = inferTypeRoot<def, $>>(def: validateTypeRoot<def, $>): instantiateType<inferIntersection<t, r>, $>;
or<const def, r = inferTypeRoot<def, $>>(def: validateTypeRoot<def, $>): instantiateType<t | r, $>;
get in(): instantiateType<this["inferBrandableIn"], $>;
get out(): instantiateType<this["inferIntrospectableOut"], $>;
intersect<const def, r = type.infer<def, $>>(def: type.validate<def, $>): instantiateType<inferIntersection<t, r>, $> | Disjoint;
and<const def, r = type.infer<def, $>>(def: type.validate<def, $>): instantiateType<inferIntersection<t, r>, $>;
or<const def, r = type.infer<def, $>>(def: type.validate<def, $>): instantiateType<t | r, $>;
array(): ArrayType<t[], $>;
pipe: ChainedPipes<t, $>;
equals<def>(def: validateTypeRoot<def, $>): this is instantiateType<inferTypeRoot<def, $>, $>;
extract<def>(r: validateTypeRoot<def, $>): instantiateType<Extract<t, inferTypeRoot<def, $>>, $>;
exclude<def>(r: validateTypeRoot<def, $>): instantiateType<Exclude<t, inferTypeRoot<def, $>>, $>;
extends<def>(other: validateTypeRoot<def, $>): this is instantiateType<inferTypeRoot<def, $>, $>;
overlaps<def>(r: validateTypeRoot<def, $>): boolean;
equals<def>(def: type.validate<def, $>): this is instantiateType<type.infer<def, $>, $>;
extract<def>(r: type.validate<def, $>): instantiateType<Extract<t, type.infer<def, $>>, $>;
exclude<def>(r: type.validate<def, $>): instantiateType<Exclude<t, type.infer<def, $>>, $>;
extends<def>(other: type.validate<def, $>): this is instantiateType<type.infer<def, $>, $>;
overlaps<def>(r: type.validate<def, $>): boolean;
distribute<mapOut, reduceOut = mapOut[]>(mapBranch: (branch: Type, i: number, branches: array<Type>) => mapOut, reduceMapped?: (mappedBranches: mapOut[]) => reduceOut): reduceOut;

@@ -51,0 +51,0 @@ /** @deprecated */

import type { Predicate, PredicateCast } from "@ark/schema";
import type { inferPipe } from "../intersect.ts";
import type { type } from "../keywords/ark.ts";
import type { applyConstraintSchema, Out, To } from "../keywords/ast.ts";
import type { inferTypeRoot, validateTypeRoot } from "../type.ts";
import type { BaseType } from "./base.ts";
/** @ts-ignore cast variance */
interface Type<out t = unknown, $ = {}> extends BaseType<t, $> {
to<const def, r = inferTypeRoot<def, $>>(def: validateTypeRoot<def, $>): Type<inferPipe<t, r>, $>;
to<const def, r = type.infer<def, $>>(def: type.validate<def, $>): Type<inferPipe<t, r>, $>;
narrow<narrowed extends this["infer"] = never>(predicate: Predicate<this["infer"]> | PredicateCast<this["infer"], narrowed>): Type<([
narrowed
] extends [never] ? applyConstraintSchema<this["tOut"], "predicate", Predicate> : narrowed) extends infer o ? this["tValidatedOut"] extends this["tOut"] ? (In: this["tIn"]) => To<o> : (In: this["tIn"]) => Out<o> : never, $>;
] 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, $>;
}
export type { Type as MorphType };
import type { array, ErrorType, merge } from "@ark/util";
import type { arkKeyOf, getArkKey, toArkKey } from "../keys.ts";
import type { type } from "../keywords/ark.ts";
import type { inferTypeRoot, validateTypeRoot } from "../type.ts";
import type { ArrayType } from "./array.ts";

@@ -25,3 +24,3 @@ import type { instantiateType } from "./instantiate.ts";

}, $>;
merge<const def, r = inferTypeRoot<def, $>>(def: validateTypeRoot<def, $> & (r extends object ? unknown : ErrorType<"Merged type must be an object", [actual: r]>)): Type<merge<t, r & object>, $>;
merge<const def, r = type.infer<def, $>>(def: type.validate<def, $> & (r extends object ? unknown : ErrorType<"Merged type must be an object", [actual: r]>)): Type<merge<t, r & object>, $>;
required(): Type<{

@@ -28,0 +27,0 @@ [k in keyof t]-?: t[k];

import type { writeUnassignableDefaultValueMessage } from "@ark/schema";
import type { ErrorMessage } from "@ark/util";
import type { inferAmbient } from "../../type.ts";
import type { type } from "../../keywords/ark.ts";
import type { UnitLiteral } from "../string/shift/operator/default.ts";

@@ -8,2 +8,2 @@ import type { inferAstOut } from "./infer.ts";

import type { validateAst } from "./validate.ts";
export type validateDefault<baseAst, unitLiteral extends UnitLiteral, $, args> = validateAst<baseAst, $, args> extends infer e extends ErrorMessage ? e : inferAmbient<unitLiteral> extends inferAstOut<baseAst, $, args> ? undefined : ErrorMessage<writeUnassignableDefaultValueMessage<astToString<baseAst>, unitLiteral>>;
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>>;
import type { GenericAst } from "@ark/schema";
import type { Hkt, array } from "@ark/util";
import type { inferIntersection } from "../../intersect.ts";
import type { type } from "../../keywords/ark.ts";
import type { Default, LimitLiteral, applyConstraintSchema, distill, normalizeLimit } from "../../keywords/ast.ts";
import type { Date } from "../../keywords/constructors/Date.ts";
import type { UnparsedScope } from "../../scope.ts";
import type { inferAmbient } from "../../type.ts";
import type { inferDefinition } from "../definition.ts";

@@ -29,3 +29,3 @@ import type { Comparator, MinComparator } from "../string/reduce/shared.ts";

[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 "=" ? inferAmbient<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[0] extends "keyof" ? keyof 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 ? (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[0] extends "keyof" ? keyof 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", {

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

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

import { isKeyOf } from "@ark/util";
import { isKeyOf, throwParseError } from "@ark/util";
import { tryParseDate, writeInvalidDateMessage } from "./date.js";

@@ -10,4 +10,8 @@ export const parseEnclosed = (s, enclosing) => {

if (enclosing === "/") {
// fail parsing if the regex is invalid
new RegExp(enclosed);
try {
new RegExp(enclosed);
}
catch (e) {
throwParseError(String(e));
}
s.root = s.ctx.$.node("intersection", {

@@ -14,0 +18,0 @@ domain: "string",

import { $ark, makeRootAndArrayPropertiesMutable } from "@ark/schema";
import { append, objectKindOrDomainOf, throwParseError } from "@ark/util";
import { append, isEmptyObject, objectKindOrDomainOf, throwParseError } from "@ark/util";
import { writeMissingRightOperandMessage } from "./string/shift/operand/unenclosed.js";

@@ -37,6 +37,11 @@ export const parseTuple = (def, ctx) => maybeParseTupleExpression(def, ctx) ?? parseTupleLiteral(def, ctx);

}
return ctx.$.internal.rootNode(sequences.map(sequence => ({
proto: Array,
sequence
})));
return ctx.$.internal.rootNode(sequences.map(sequence => isEmptyObject(sequence) ?
{
proto: Array,
exactLength: 0
}
: {
proto: Array,
sequence
}));
};

@@ -43,0 +48,0 @@ const appendElement = (base, kind, element) => {

@@ -75,2 +75,3 @@ import { BaseScope, type AliasDefEntry, type ArkScopeConfig, type BaseNode, type BaseRoot, type GenericArgResolutions, type GenericAst, type GenericParamAst, type NodeKind, type NodeParseOptions, type NodeSchema, type PreparsedNodeResolution, type PrivateDeclaration, type RootKind, type RootSchema, type arkKind, type exportedNameOf, type nodeOfKind, type reducibleKindOf, type toInternalScope, type writeDuplicateAliasError } from "@ark/schema";

parse(def: unknown, ctx: ParseContext): BaseRoot;
private _parse;
parseString(def: string, ctx: ParseContext): BaseRoot;

@@ -77,0 +78,0 @@ parseRoot: (def: unknown, opts?: TypeParseOptions) => BaseRoot;

@@ -50,6 +50,9 @@ import { $ark, BaseScope, hasArkKind, parseGeneric } from "@ark/schema";

k,
v.bindScope(this)
this.bindReference(v)
]));
}
parse(def, ctx) {
return this.bindReference(this._parse(def, ctx));
}
_parse(def, ctx) {
if (typeof def === "string") {

@@ -83,3 +86,3 @@ if (ctx.args && Object.keys(ctx.args).some(k => def.includes(k))) {

parseRoot = (def, opts = {}) => {
const node = this.parse(def, Object.assign(this.finalizeRootArgs(opts, () => node), { $: this })).bindScope(this);
const node = this.parse(def, Object.assign(this.finalizeRootArgs(opts, () => node), { $: this }));
return node;

@@ -86,0 +89,0 @@ };

import { ArkErrors, BaseRoot, type MetaSchema, type Morph, type Predicate } from "@ark/schema";
import { Callable, type Constructor, type array, type conform } from "@ark/util";
import { type Generic, type GenericParser, type ParameterString, type baseGenericConstraints, type parseValidGenericParams, type validateParameterString } from "./generic.ts";
import type { Ark, ark } from "./keywords/ark.ts";
import type { Ark, ark, type } from "./keywords/ark.ts";
import type { distill } from "./keywords/ast.ts";
import type { BaseType } from "./methods/base.ts";
import type { instantiateType } from "./methods/instantiate.ts";
import type { inferDefinition, validateDeclared, validateDefinition } from "./parser/definition.ts";
import type { validateDeclared, validateDefinition } from "./parser/definition.ts";
import type { IndexOneOperator, IndexZeroOperator, TupleInfixOperator } from "./parser/tuple.ts";

@@ -14,5 +14,6 @@ import type { InternalScope, ModuleParser, Scope, ScopeParser, bindThis } from "./scope.ts";

export interface TypeParser<$ = {}> extends Ark.boundTypeAttachments<$> {
<const def, r = Type<inferTypeRoot<def, $>, $>>(def: validateTypeRoot<def, $>): r;
<const def, r = Type<type.infer<def, $>, $>>(def: type.validate<def, $>): r;
<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<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<distill.In<inferTypeRoot<zero, $>>>] : one extends "=>" ? [Morph<distill.Out<inferTypeRoot<zero, $>>, unknown>] : one extends "@" ? [MetaSchema] : [validateTypeRoot<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] : [type.validate<rest[0], $>] : []): r;
$: Scope<$>;
raw(def: unknown): BaseType<any, $>;

@@ -35,7 +36,3 @@ errors: typeof ArkErrors;

export type EnumeratedTypeParser<$> = <const values extends readonly unknown[]>(...values: values) => Type<values[number], $>;
export type DefinitionParser<$> = <def>(def: validateTypeRoot<def, $>) => def;
export type validateTypeRoot<def, $ = {}> = validateDefinition<def, $, bindThis<def>>;
export type inferTypeRoot<def, $> = inferDefinition<def, $, bindThis<def>>;
export type validateAmbient<def> = validateTypeRoot<def, {}>;
export type inferAmbient<def> = inferTypeRoot<def, {}>;
export type DefinitionParser<$> = <def>(def: type.validate<def, $>) => def;
export type Type<t = unknown, $ = {}> = instantiateType<t, $>;

@@ -42,0 +39,0 @@ export declare namespace Type {

@@ -8,2 +8,3 @@ import { ArkErrors, BaseRoot, GenericRoot } from "@ark/schema";

errors: ArkErrors,
$: $,
raw: $.parseRoot,

@@ -10,0 +11,0 @@ module: $.constructor.module,

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

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

"dependencies": {
"@ark/schema": "0.7.0",
"@ark/util": "0.7.0"
"@ark/util": "0.8.0",
"@ark/schema": "0.8.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