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-beta.0 to 2.0.0-beta.1

11

out/ark.d.ts
import { type Ark, type ArkErrors, type inferred } from "@ark/schema";
import type { CastableBase } from "@ark/util";
import type { GenericHktParser } from "./generic.js";
import type { MatchParser } from "./match.js";
import type { Module } from "./module.js";
import { type Scope } from "./scope.js";
import type { DeclarationParser, DefinitionParser, Type, TypeParser } from "./type.js";
import type { DeclarationParser, DefinitionParser, TypeParser } from "./type.js";
export declare const ambient: Scope<Ark>;

@@ -15,11 +15,6 @@ export declare const ark: Module<Ark>;

type errors = ArkErrors;
interface of<t, $ = {}> extends Type<t, $> {
}
interface infer<t extends Type<object>> extends CastableBase<t["infer"]> {
}
interface inferIn<t extends Type<object>> extends CastableBase<t["inferIn"]> {
}
}
export declare const generic: GenericHktParser<{}>;
export declare const match: MatchParser<{}>;
export declare const define: DefinitionParser<{}>;
export declare const declare: DeclarationParser<{}>;

@@ -6,4 +6,5 @@ import { keywordNodes } from "@ark/schema";

export const type = ambient.type;
export const generic = ambient.generic;
export const match = ambient.match;
export const define = ambient.define;
export const declare = ambient.declare;

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

import type { GenericParamAst, GenericParamDef, GenericRoot, writeUnsatisfiedParameterConstraintMessage } from "@ark/schema";
import { type array, type Callable, type conform, type ErrorMessage, type keyError, type typeToString, type WhiteSpaceToken } from "@ark/util";
import type { GenericParamAst, GenericParamDef, genericParamSchemasToAst, GenericProps, GenericRoot, LazyGenericBody } from "@ark/schema";
import { type array, type Callable, type conform, type ErrorMessage, type Hkt, type keyError, type WhiteSpaceToken } from "@ark/util";
import type { inferDefinition } from "./parser/definition.js";

@@ -14,6 +14,12 @@ import type { inferAstRoot } from "./parser/semantic/infer.js";

export type validateParameterString<s extends ParameterString, $> = parseGenericParams<extractParams<s>, $> extends keyError<infer message> ? ErrorMessage<message> : s;
export type validateGenericArg<param extends GenericParamAst, def, $> = validateTypeRoot<def, $> extends infer result ? result extends ErrorMessage ? result : inferTypeRoot<def, $> extends param[1] ? def : ErrorMessage<writeUnsatisfiedParameterConstraintMessage<param[0], typeToString<param[1]>, "">> : never;
export type GenericInstantiation<params extends array<GenericParamAst> = array<GenericParamAst>, def = any, $ = any> = <const args>(...args: conform<args, {
[i in keyof params]: validateGenericArg<params[i], args[i & keyof args], $>;
}>) => Type<inferDefinition<def, $, bindGenericArgs<params, $, args>>, $>;
export type validateGenericArg<arg, param extends GenericParamAst, $> = inferTypeRoot<arg, $> extends param[1] ? arg : Type<param[1]>;
export type GenericInstantiator<params extends array<GenericParamAst>, def, $, args$> = <const args extends {
[i in keyof params]: validateTypeRoot<args[i & keyof args], args$>;
}>(
/** @ts-expect-error treat as array */
...args: {
[i in keyof args]: validateGenericArg<args[i], params[i & keyof params & `${number}`], args$>;
}) => Type<def extends Hkt.Kind ? Hkt.apply<def, {
[i in keyof args]: inferTypeRoot<args[i], args$>;
}> : inferDefinition<def, $, bindGenericArgs<params, args$, args>>, $>;
type bindGenericArgs<params extends array<GenericParamAst>, $, args> = {

@@ -25,3 +31,4 @@ [i in keyof params & `${number}` as params[i][0]]: inferTypeRoot<args[i & keyof args], $>;

};
export interface Generic<params extends array<GenericParamAst> = array<GenericParamAst>, bodyDef = unknown, $ = {}> extends Callable<GenericInstantiation<params, bodyDef, $>>, GenericRoot<params, bodyDef, $> {
export interface Generic<params extends array<GenericParamAst> = array<GenericParamAst>, bodyDef = unknown, $ = {}, args$ = $> extends Callable<GenericInstantiator<params, bodyDef, $, args$>>, GenericProps<params, bodyDef, $> {
internal: GenericRoot<params, bodyDef, $>;
}

@@ -56,2 +63,6 @@ export type GenericDeclaration<name extends string = string, params extends ParameterString = ParameterString> = `${name}${params}`;

], $>;
export type GenericHktParser<$ = {}> = <const paramsDef extends array<GenericParamDef>>(...params: paramsDef) => (instantiateDef: LazyGenericBody<genericParamSchemasToAst<paramsDef, $>>) => GenericHktSubclass<genericParamSchemasToAst<paramsDef, $>, $>;
export type GenericHktSubclass<params extends array<GenericParamAst>, $> = abstract new () => GenericHkt<genericParamSchemasToAst<params, $>, Hkt.Kind, $, $>;
export interface GenericHkt<params extends array<GenericParamAst>, hkt extends Hkt.Kind, $, args$> extends Generic<params, hkt, $, args$>, Hkt.Kind {
}
export {};
export { ArkError, ArkErrors as ArkErrors } from "@ark/schema";
export type { Ark, ArkConfig, Out, constrained, inferred } from "@ark/schema";
export { ambient, ark, declare, define, match, type } from "./ark.js";
export { ambient, ark, declare, define, generic, match, type } from "./ark.js";
export { Module } from "./module.js";
export { scope, type Scope, type inferScope, type validateScope } from "./scope.js";
export { Type, type AnyType, type inferTypeRoot, type validateTypeRoot } from "./type.js";
export { ArkError, ArkErrors as ArkErrors } from "@ark/schema";
export { ambient, ark, declare, define, match, type } from "./ark.js";
export { ambient, ark, declare, define, generic, match, type } from "./ark.js";
export { Module } from "./module.js";
export { scope } from "./scope.js";
export { Type } from "./type.js";

@@ -67,3 +67,3 @@ import type { Narrowed, distillOut, inferIntersection } from "@ark/schema";

};
export type MatchInvocation<ctx extends MatchInvocationContext> = <data extends ctx["initialInputs"]>(data: data) => {
export type MatchInvocation<ctx extends MatchInvocationContext> = <const data extends ctx["initialInputs"]>(data: data) => {
[i in numericStringKeyOf<ctx["thens"]>]: isDisjoint<data, Parameters<ctx["thens"][i]>[0]> extends true ? never : ReturnType<ctx["thens"][i]>;

@@ -70,0 +70,0 @@ }[numericStringKeyOf<ctx["thens"]>];

@@ -1,8 +0,11 @@

import { RootModule, type PreparsedNodeResolution } from "@ark/schema";
import type { anyOrNever } from "@ark/util";
import { RootModule, type arkKind, type GenericProps } from "@ark/schema";
import type { anyOrNever, Hkt } from "@ark/util";
import type { Generic, GenericHkt } from "./generic.js";
import type { Type } from "./type.js";
type exportScope<$> = {
[k in keyof $]: $[k] extends PreparsedNodeResolution ? [
[k in keyof $]: $[k] extends {
[arkKind]: "module";
} ? [
$[k]
] extends [anyOrNever] ? Type<$[k], $> : $[k] : Type<$[k], $>;
] extends [anyOrNever] ? Type<$[k], $> : $[k] : $[k] extends GenericProps<infer params, infer bodyDef, infer args$> ? $[k] extends Hkt.Kind ? GenericHkt<params, $[k], $, args$> : Generic<params, bodyDef, $, args$> : Type<$[k], $>;
};

@@ -9,0 +12,0 @@ export declare const Module: new <$ = {}>(types: exportScope<$>) => Module<$>;

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

import type { Root, writeIndivisibleMessage } from "@ark/schema";
import type { SchemaRoot, writeIndivisibleMessage } from "@ark/schema";
import type { ErrorMessage } from "@ark/util";

@@ -7,2 +7,2 @@ import type { inferAstIn } from "./infer.js";

data
] extends [number] ? validateAst<l, $, args> : ErrorMessage<writeIndivisibleMessage<Root<data>>> : never;
] extends [number] ? validateAst<l, $, args> : ErrorMessage<writeIndivisibleMessage<SchemaRoot<data>>> : never;
import type { Date, DateLiteral, Default, GenericProps, LimitLiteral, RegexLiteral, constrain, distillIn, distillOut, inferIntersection, normalizeLimit, string } from "@ark/schema";
import type { BigintLiteral, array } from "@ark/util";
import type { BigintLiteral, Hkt, array } from "@ark/util";
import type { UnparsedScope, resolve, tryInferSubmoduleReference } from "../../scope.js";

@@ -12,3 +12,5 @@ import type { inferDefinition } from "../definition.js";

export type GenericInstantiationAst<generic extends GenericProps = GenericProps, argAsts extends unknown[] = unknown[]> = [generic, "<>", argAsts];
export type inferExpression<ast extends array, $, args> = ast extends GenericInstantiationAst<infer generic, infer argAsts> ? inferDefinition<generic["bodyDef"], generic["$"]["t"] extends UnparsedScope ? $ : generic["$"]["t"], {
export type inferExpression<ast extends array, $, args> = ast extends GenericInstantiationAst<infer generic, infer argAsts> ? generic extends Hkt.Kind ? Hkt.apply<generic, {
[i in keyof argAsts]: inferConstrainableAst<argAsts[i], $, args>;
}> : inferDefinition<generic["bodyDef"], generic["$"]["t"] extends UnparsedScope ? $ : generic["$"]["t"], {
[i in keyof generic["params"] & `${number}` as generic["names"][i & keyof generic["names"]]]: inferConstrainableAst<argAsts[i & keyof argAsts], $, args>;

@@ -15,0 +17,0 @@ }> : ast[1] extends "[]" ? inferConstrainableAst<ast[0], $, args>[] : ast[1] extends "|" ? inferConstrainableAst<ast[0], $, args> | inferConstrainableAst<ast[2], $, args> : ast[1] extends "&" ? inferIntersection<inferConstrainableAst<ast[0], $, args>, inferConstrainableAst<ast[2], $, args>> : ast[1] extends "=" ? inferTerminal<ast[2] & string, $, args> extends infer defaultValue ? (In?: inferConstrainableAst<ast[0], $, args>) => Default<defaultValue> : never : ast[1] extends Comparator ? ast[0] extends LimitLiteral ? constrainBound<inferConstrainableAst<ast[2], $, args>, ast[1], ast[0]> : constrainBound<inferConstrainableAst<ast[0], $, args>, ast[1], ast[2]> : ast[1] extends "%" ? constrain<inferConstrainableAst<ast[0], $, args>, "divisor", ast[2] & number> : ast[0] extends "keyof" ? keyof inferConstrainableAst<ast[1], $, args> : never;

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

import { RawRootScope, type AliasDefEntry, type ArkConfig, type BaseRoot, type GenericArgResolutions, type GenericParamAst, type GenericParamDef, type GenericProps, type PreparsedNodeResolution, type PrivateDeclaration, type RawRootResolutions, type RootScope, type arkKind, type destructuredExportContext, type destructuredImportContext, type exportedNameOf, type writeDuplicateAliasError } from "@ark/schema";
import { InternalBaseScope, type AliasDefEntry, type ArkConfig, type BaseRoot, type BaseScope, type GenericArgResolutions, type GenericParamAst, type GenericParamDef, type GenericProps, type InternalResolutions, type PreparsedNodeResolution, type PrivateDeclaration, type arkKind, type destructuredExportContext, type destructuredImportContext, type exportedNameOf, type writeDuplicateAliasError } from "@ark/schema";
import { type anyOrNever, type array, type keyError, type nominal, type show } from "@ark/util";
import { parseGenericParams, type Generic, type GenericDeclaration, type ParameterString, type baseGenericArgs, type parseValidGenericParams } from "./generic.js";
import { parseGenericParams, type Generic, type GenericDeclaration, type GenericHktParser, type ParameterString, type baseGenericArgs, type parseValidGenericParams } from "./generic.js";
import { type MatchParser } from "./match.js";

@@ -8,3 +8,3 @@ import type { Module } from "./module.js";

import type { ParsedDefault } from "./parser/string/shift/operator/default.js";
import { RawTypeParser, type DeclarationParser, type DefinitionParser, type Type, type TypeParser } from "./type.js";
import { InternalTypeParser, type DeclarationParser, type DefinitionParser, type Type, type TypeParser } from "./type.js";
export type ScopeParser = <const def>(def: validateScope<def>, config?: ArkConfig) => Scope<inferScope<def>>;

@@ -44,3 +44,3 @@ export type validateScope<def> = {

export interface ParseContext extends TypeParseOptions {
$: RawScope;
$: InternalScope;
}

@@ -51,17 +51,9 @@ export interface TypeParseOptions {

export declare const scope: ScopeParser;
export interface Scope<$ = any> extends RootScope<$> {
type: TypeParser<$>;
match: MatchParser<$>;
declare: DeclarationParser<$>;
define: DefinitionParser<$>;
import<names extends exportedNameOf<$>[]>(...names: names): Module<show<destructuredImportContext<$, names>>>;
export<names extends exportedNameOf<$>[]>(...names: names): Module<show<destructuredExportContext<$, names>>>;
}
export declare class RawScope<$ extends RawRootResolutions = RawRootResolutions> extends RawRootScope<$> {
export declare class InternalScope<$ extends InternalResolutions = InternalResolutions> extends InternalBaseScope<$> {
private parseCache;
constructor(def: Record<string, unknown>, config?: ArkConfig);
type: RawTypeParser;
type: InternalTypeParser;
match: MatchParser<$>;
declare: () => {
type: RawTypeParser;
type: InternalTypeParser;
};

@@ -75,2 +67,12 @@ define: (def: unknown) => unknown;

}
export interface Scope<$ = any> extends BaseScope<$> {
type: TypeParser<$>;
match: MatchParser<$>;
declare: DeclarationParser<$>;
define: DefinitionParser<$>;
generic: GenericHktParser<$>;
import<names extends exportedNameOf<$>[]>(...names: names): Module<show<destructuredImportContext<$, names>>>;
export<names extends exportedNameOf<$>[]>(...names: names): Module<show<destructuredExportContext<$, names>>>;
}
export declare const Scope: new <$ = any>() => Scope<$>;
export declare const writeShallowCycleErrorMessage: (name: string, seen: string[]) => string;

@@ -77,0 +79,0 @@ export type ParsedScopeKey = {

@@ -35,3 +35,3 @@ var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {

};
import { RawRootScope, hasArkKind, parseGeneric } from "@ark/schema";
import { InternalBaseScope, hasArkKind, parseGeneric } from "@ark/schema";
import { bound, domainOf, hasDomain, isThunk, throwParseError } from "@ark/util";

@@ -45,9 +45,9 @@ import { parseGenericParams } from "./generic.js";

import { fullStringParse } from "./parser/string/string.js";
import { RawTypeParser } from "./type.js";
export const scope = ((def, config = {}) => new RawScope(def, config));
let RawScope = (() => {
let _classSuper = RawRootScope;
import { InternalTypeParser } from "./type.js";
export const scope = ((def, config = {}) => new InternalScope(def, config));
let InternalScope = (() => {
let _classSuper = InternalBaseScope;
let _instanceExtraInitializers = [];
let _parseRoot_decorators;
return class RawScope extends _classSuper {
return class InternalScope extends _classSuper {
static {

@@ -63,3 +63,3 @@ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;

}
type = new RawTypeParser(this);
type = new InternalTypeParser(this);
match = createMatchParser(this);

@@ -133,3 +133,4 @@ declare = (() => ({

})();
export { RawScope };
export { InternalScope };
export const Scope = InternalScope;
export const writeShallowCycleErrorMessage = (name, seen) => `Alias '${name}' has a shallow resolution cycle: ${[...seen, name].join(":")}`;

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

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 PatternSchema, type Predicate, type Prerequisite, type PrimitiveConstraintKind, type Root, type constrain, type constraintKindOf, type distillIn, type distillOut, type exclusivizeRangeSchema, type indexInto, type indexOf, type inferIntersection, type inferMorphOut, type inferPipes, type inferPredicate, type writeInvalidOperandMessage } from "@ark/schema";
import { Callable, type Constructor, type ErrorMessage, type array, type conform } from "@ark/util";
import { ArkErrors, BaseRoot, type BaseMeta, type Disjoint, type DivisorSchema, type ExactLengthSchema, type ExclusiveDateRangeSchema, type ExclusiveNumericRangeSchema, type InclusiveDateRangeSchema, type InclusiveNumericRangeSchema, type Morph, type MorphAst, type NodeSchema, type Out, type PatternSchema, type Predicate, type PrimitiveConstraintKind, type Root, type arkKeyOf, type constrain, type constraintKindOf, type distillIn, type distillOut, type exclusivizeRangeSchema, type getArkKey, type inferIntersection, type inferMorphOut, type inferPipes, type inferPredicate, type toArkKey, type validateChainedAsArgs, type validateChainedConstraint, type validateStructuralOperand } from "@ark/schema";
import { Callable, type Constructor, type array, type conform, type unset } from "@ark/util";
import type { type } from "./ark.js";

@@ -7,3 +7,3 @@ import { type Generic, type ParameterString, type baseGenericArgs, type parseValidGenericParams, type validateParameterString } from "./generic.js";

import type { IndexOneOperator, IndexZeroOperator, TupleInfixOperator } from "./parser/tuple.js";
import type { RawScope, Scope, bindThis } from "./scope.js";
import type { InternalScope, Scope, bindThis } from "./scope.js";
/** The convenience properties attached to `type` */

@@ -18,4 +18,4 @@ export type TypeParserAttachments = Omit<TypeParser, never>;

}
export declare class RawTypeParser extends Callable<(...args: unknown[]) => BaseRoot | Generic, TypeParserAttachments> {
constructor($: RawScope);
export declare class InternalTypeParser extends Callable<(...args: unknown[]) => BaseRoot | Generic, TypeParserAttachments> {
constructor($: InternalScope);
}

@@ -25,7 +25,5 @@ export type DeclarationParser<$> = <preinferred>() => {

};
type validateChainedConstraint<kind extends ConstraintKind, t extends {
inferIn: unknown;
}> = t["inferIn"] extends Prerequisite<kind> ? t : ErrorMessage<writeInvalidOperandMessage<kind, Root<t["inferIn"]>>>;
declare class _Type<t = unknown, $ = any> extends InnerRoot<t, $> {
declare class _Type<t = unknown, $ = any> extends Root<t, $> {
$: Scope<$>;
as<t = unset>(...args: validateChainedAsArgs<t>): Type<t, $>;
get in(): Type<this["tIn"], $>;

@@ -47,9 +45,15 @@ get out(): Type<this["tOut"], $>;

equals<def>(def: validateTypeRoot<def, $>): this is Type<inferTypeRoot<def>, $>;
extract<def>(r: validateTypeRoot<def, $>): Type<t, $>;
exclude<def>(r: validateTypeRoot<def, $>): Type<t, $>;
extract<def>(r: validateTypeRoot<def, $>): Type<Extract<t, inferTypeRoot<def, $>>, $>;
exclude<def>(r: validateTypeRoot<def, $>): Type<Exclude<t, inferTypeRoot<def, $>>, $>;
extends<def>(other: validateTypeRoot<def, $>): this is Type<inferTypeRoot<def>, $>;
overlaps<def>(r: validateTypeRoot<def, $>): boolean;
get<k1 extends indexOf<t>>(k1: k1 | type.cast<k1>): Type<indexInto<t, k1>, $>;
get<k1 extends indexOf<t>, k2 extends indexOf<indexInto<t, k1>>>(k1: k1 | type.cast<k1>, k2: k2 | type.cast<k2>): Type<indexInto<indexInto<t, k1>, k2>, $>;
get<k1 extends indexOf<t>, k2 extends indexOf<indexInto<t, k1>>, k3 extends indexOf<indexInto<indexInto<t, k1>, k2>>>(k1: k1 | type.cast<k1>, k2: k2 | type.cast<k2>, k3: k3 | type.cast<k3>): Type<indexInto<indexInto<indexInto<t, k1>, k2>, k3>, $>;
omit<const key extends arkKeyOf<t> = never>(this: validateStructuralOperand<"omit", this>, ...keys: array<key | type.cast<key>>): Type<{
[k in keyof t as Exclude<toArkKey<t, k>, key>]: t[k];
}, $>;
pick<const key extends arkKeyOf<t> = never>(this: validateStructuralOperand<"pick", this>, ...keys: array<key | type.cast<key>>): Type<{
[k in keyof t as Extract<toArkKey<t, k>, key>]: t[k];
}, $>;
get<k1 extends arkKeyOf<t>>(k1: k1 | type.cast<k1>): Type<getArkKey<t, k1>, $>;
get<k1 extends arkKeyOf<t>, k2 extends arkKeyOf<getArkKey<t, k1>>>(k1: k1 | type.cast<k1>, k2: k2 | type.cast<k2>): Type<getArkKey<getArkKey<t, k1>, k2>, $>;
get<k1 extends arkKeyOf<t>, k2 extends arkKeyOf<getArkKey<t, k1>>, k3 extends arkKeyOf<getArkKey<getArkKey<t, k1>, k2>>>(k1: k1 | type.cast<k1>, k2: k2 | type.cast<k2>, k3: k3 | type.cast<k3>): Type<getArkKey<getArkKey<getArkKey<t, k1>, k2>, k3>, $>;
constrain<kind extends PrimitiveConstraintKind, const def extends NodeSchema<kind>>(kind: conform<kind, constraintKindOf<this["inferIn"]>>, def: def): Type<constrain<t, kind, def>, $>;

@@ -56,0 +60,0 @@ satisfying<predicate extends Predicate<distillIn<t>>>(predicate: predicate): Type<t extends MorphAst ? (In: inferPredicate<this["tIn"], predicate>) => Out<this["tOut"]> : inferPredicate<t, predicate>, $>;

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

import { ArkErrors, BaseRoot } from "@ark/schema";
import { ArkErrors, BaseRoot, GenericRoot } from "@ark/schema";
import { Callable } from "@ark/util";
import { parseGenericParams } from "./generic.js";
export class RawTypeParser extends Callable {
export class InternalTypeParser extends Callable {
constructor($) {

@@ -21,4 +21,3 @@ super((...args) => {

});
const def = args[1];
return $.generic(params, def);
return new GenericRoot(params, args[1], $, $);
}

@@ -25,0 +24,0 @@ // otherwise, treat as a tuple expression. technically, this also allows

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

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

"dependencies": {
"@ark/util": "0.1.0",
"@ark/schema": "0.2.0"
"@ark/util": "0.1.1",
"@ark/schema": "0.2.1"
},

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

Sorry, the diff of this file is not supported yet

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