🚀. Socket Launch Week Day 3:Socket Firewall Now Blocks Malicious VS Code and Open VSX Extensions.Learn more
Sign In

arktype

Package Overview
Dependencies
Maintainers
1
Versions
151
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.1.27
to
2.1.28
+11
-6
out/declare.d.ts

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

import type { anyOrNever, array, defined, equals, ErrorMessage, ErrorType, optionalKeyOf, requiredKeyOf, show, unset } from "@ark/util";
import type { anyOrNever, array, equals, ErrorMessage, ErrorType, optionalKeyOf, requiredKeyOf, show, unset } from "@ark/util";
import type { distill } from "./attributes.ts";
import type { type } from "./keywords/keywords.ts";
import type { inferDefinition, ThunkCast } from "./parser/definition.ts";
import type { inferDefinition, TerminalObjectDefinition, ThunkCast } from "./parser/definition.ts";
import type { OptionalPropertyDefinition } from "./parser/property.ts";
import type { TupleExpression } from "./parser/tupleExpressions.ts";

@@ -18,9 +19,13 @@ import type { bindThis } from "./scope.ts";

export type validateDeclared<declared, def, $, ctx extends DeclareContext> = def extends type.validate<def, $> ? validateInference<def, declared, $, bindThis<def>, ctx> : type.validate<def, $>;
type validateInference<def, declared, $, args, ctx extends DeclareContext> = def extends RegExp | type.cast<unknown> | ThunkCast | TupleExpression ? validateShallowInference<inferDefinition<def, $, args>, declared, ctx> : def extends array ? declared extends array ? {
type validateInference<def, declared, $, args, ctx extends DeclareContext> = def extends TerminalObjectDefinition | ThunkCast | TupleExpression ? keyof def extends never ? validateObjectInference<def, declared, $, args, ctx> : validateShallowInference<inferDefinition<def, $, args>, declared, ctx> : def extends array ? validateArrayInference<def, declared, $, args, ctx> : def extends object ? validateObjectInference<def, declared, $, args, ctx> : validateShallowInference<inferDefinition<def, $, args>, declared, ctx>;
type validateArrayInference<def extends array, declared, $, args, ctx extends DeclareContext> = declared extends array ? {
[i in keyof declared]: i extends keyof def ? validateInference<def[i], declared[i], $, args, ctx> : declared[i];
} : show<declarationMismatch<inferDefinition<def, $, args>, declared>> : def extends object ? show<{
} : show<declarationMismatch<inferDefinition<def, $, args>, declared>>;
type validateObjectInference<def extends object, declared, $, args, ctx extends DeclareContext> = show<{
[k in requiredKeyOf<declared>]: k extends keyof def ? validateInference<def[k], declared[k], $, args, ctx> : declared[k];
} & {
[k in optionalKeyOf<declared> & string as `${k}?`]: `${k}?` extends (keyof def) ? validateInference<def[`${k}?`], defined<declared[k]>, $, args, ctx> : declared[k];
}> : validateShallowInference<inferDefinition<def, $, args>, declared, ctx>;
[k in optionalKeyOf<declared> & string as declaredOptionalKeySuggestion<k, def>]: declaredOptionalValueSuggestion<def, k, declared, $, args, ctx>;
}>;
type declaredOptionalKeySuggestion<k extends string, def> = k extends keyof def ? def[k] extends OptionalPropertyDefinition ? k : `${k}?` : `${k}?`;
type declaredOptionalValueSuggestion<def, k extends keyof declared & string, declared, $, args, ctx extends DeclareContext> = k extends keyof def ? def[k] extends OptionalPropertyDefinition ? validateInference<def[k], Required<declared>[k], $, args, ctx> : declared[k] : `${k}?` extends keyof def ? validateInference<def[`${k}?`], Required<declared>[k], $, args, ctx> : declared[k];
type validateShallowInference<t, declared, ctx extends DeclareContext, inferred = ctx["side"] extends distill.Side ? distill<t, ctx["side"]> : t> = equals<inferred, declared> extends true ? unknown : show<declarationMismatch<inferred, declared>>;

@@ -27,0 +32,0 @@ type declarationMismatch<inferred, declared> = ErrorType<{

@@ -9,6 +9,6 @@ import type { BaseRoot, IntersectionNode } from "@ark/schema";

import type { Type } from "./type.ts";
export interface FnParser<$ = {}> {
<const args extends readonly unknown[], paramsT extends readonly unknown[] = inferTupleLiteral<args extends readonly [...infer params, ":", unknown] ? params : args, $, {}>, returnT = args extends readonly [...unknown[], ":", infer returnDef] ? type.infer<returnDef, $> : unknown>(...args: {
[i in keyof args]: conform<args[i], get<validateFnArgs<args, $>, i>>;
}): <internalSignature extends (...args: distill.Out<paramsT>) => distill.In<returnT>, externalSignature extends Fn = (...args: applyElementLabels<distill.In<paramsT>, Parameters<internalSignature>>) => args extends readonly [...unknown[], ":", unknown] ? distill.Out<returnT> : ReturnType<internalSignature>>(implementation: internalSignature) => TypedFn<externalSignature, $, args extends readonly [...unknown[], ":", unknown] ? Return.introspectable : {}>;
export type BaseFnParser<$ = {}> = <const args extends readonly unknown[], paramsT extends readonly unknown[] = inferTupleLiteral<args extends readonly [...infer params, ":", unknown] ? params : args, $, {}>, returnT = args extends readonly [...unknown[], ":", infer returnDef] ? type.infer<returnDef, $> : unknown>(...args: {
[i in keyof args]: conform<args[i], get<validateFnArgs<args, $>, i>>;
}) => <internalSignature extends (...args: distill.Out<paramsT>) => distill.In<returnT>, externalSignature extends Fn = (...args: applyElementLabels<distill.In<paramsT>, Parameters<internalSignature>>) => args extends readonly [...unknown[], ":", unknown] ? distill.Out<returnT> : ReturnType<internalSignature>>(implementation: internalSignature) => TypedFn<externalSignature, $, args extends readonly [...unknown[], ":", unknown] ? Return.introspectable : {}>;
export interface FnParser<$ = {}> extends BaseFnParser<$> {
/**

@@ -15,0 +15,0 @@ * The {@link Scope} in which definitions passed to this function will be parsed.

export { ArkError, ArkErrors, Traversal, TraversalError, type ArkSchemaConfig, type ArkSchemaScopeConfig, type JsonSchema } from "@ark/schema";
export { Hkt, ParseError, inferred } from "@ark/util";
export { Hkt, inferred, ParseError } from "@ark/util";
export { regex } from "arkregex";
export type { Out, distill } from "./attributes.ts";
export type { distill, Out } from "./attributes.ts";
export * from "./config.ts";
export { Generic } from "./generic.ts";
export { ark, declare, define, generic, keywords, match, type, type Ark } from "./keywords/keywords.ts";
export { ark, declare, define, fn, generic, keywords, match, type, type Ark } from "./keywords/keywords.ts";
export { Module, type BoundModule, type Submodule } from "./module.ts";
export type { inferDefinition, validateDefinition } from "./parser/definition.ts";
export { scope, type Scope, type bindThis } from "./scope.ts";
export { scope, type bindThis, type Scope } from "./scope.ts";
export { Type } from "./type.ts";
export type { BaseType } from "./variants/base.ts";
export { ArkError, ArkErrors, Traversal, TraversalError } from "@ark/schema";
export { Hkt, ParseError, inferred } from "@ark/util";
export { Hkt, inferred, ParseError } from "@ark/util";
export { regex } from "arkregex";
export * from "./config.js";
export { Generic } from "./generic.js";
export { ark, declare, define, generic, keywords, match, type } from "./keywords/keywords.js";
export { ark, declare, define, fn, generic, keywords, match, type } from "./keywords/keywords.js";
export { Module } from "./module.js";
export { scope } from "./scope.js";
export { Type } from "./type.js";

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

import { type BaseParseContext, type BaseRoot } from "@ark/schema";
import { type BaseParseContext, type BaseRoot, type StandardSchemaV1 } from "@ark/schema";
import { type anyOrNever, type array, type ErrorMessage, type Fn, type ifEmptyObjectLiteral, type objectKindOrDomainOf, type Primitive } from "@ark/util";
import type { Out } from "../attributes.ts";
import type { type } from "../keywords/keywords.ts";

@@ -15,11 +16,12 @@ import type { InnerParseResult } from "../scope.ts";

def
] extends [anyOrNever] ? def : def extends type.cast<infer t> ? ifEmptyObjectLiteral<def, object, t> : def extends ThunkCast<infer t> ? t : def extends string ? inferString<def, $, args> : def extends array ? inferTuple<def, $, args> : def extends RegExp ? string : def extends object ? inferObjectLiteral<def, $, args> : never;
] extends [anyOrNever] ? def : def extends type.cast<infer t> ? ifEmptyObjectLiteral<def, object, t> : def extends ThunkCast<infer t> ? t : def extends string ? inferString<def, $, args> : def extends array ? inferTuple<def, $, args> : def extends RegExp ? string : def extends StandardSchemaV1 ? inferStandardSchema<def> : def extends object ? inferObjectLiteral<def, $, args> : never;
type inferStandardSchema<schema extends StandardSchemaV1, i = StandardSchemaV1.InferInput<schema>, o = StandardSchemaV1.InferOutput<schema>> = [i, o] extends [o, i] ? i : (In: i) => Out<o>;
export type validateDefinition<def, $, args> = null extends undefined ? ErrorMessage<`'strict' or 'strictNullChecks' must be set to true in your tsconfig's 'compilerOptions'`> : [def] extends [anyOrNever] ? def : def extends OptionalPropertyDefinition ? ErrorMessage<shallowOptionalMessage> : isDefaultable<def, $, args> extends true ? ErrorMessage<shallowDefaultableMessage> : validateInnerDefinition<def, $, args>;
export type validateInnerDefinition<def, $, args> = [
def
] extends [Terminal] ? def : def extends string ? validateString<def, $, args> : unknown extends def ? BaseCompletions<$, args> | {} : def extends readonly unknown[] ? validateTuple<def, $, args> : def extends BadDefinitionType ? ErrorMessage<writeBadDefinitionTypeMessage<objectKindOrDomainOf<def>>> : validateObjectLiteral<def, $, args>;
] extends [TerminalObjectDefinition] ? def : def extends string ? validateString<def, $, args> : unknown extends def ? BaseCompletions<$, args> | {} : def extends readonly unknown[] ? validateTuple<def, $, args> : def extends BadDefinitionType ? ErrorMessage<writeBadDefinitionTypeMessage<objectKindOrDomainOf<def>>> : validateObjectLiteral<def, $, args>;
export declare const parseTuple: (def: array, ctx: BaseParseContext) => BaseRoot;
export type validateTuple<def extends array, $, args> = maybeValidateTupleExpression<def, $, args> extends infer result ? result extends null ? validateTupleLiteral<def, $, args> : result : never;
export type inferTuple<def extends array, $, args> = def extends TupleExpression ? inferTupleExpression<def, $, args> : inferTupleLiteral<def, $, args>;
type Terminal = type.cast<unknown> | Fn | RegExp;
export type TerminalObjectDefinition = type.cast<unknown> | Fn | RegExp | StandardSchemaV1;
export type ThunkCast<t = unknown> = () => type.cast<t>;

@@ -26,0 +28,0 @@ type BadDefinitionType = Exclude<Primitive, string>;

import { hasArkKind } from "@ark/schema";
import { domainOf, hasDomain, isThunk, objectKindOf, printable, throwParseError } from "@ark/util";
import { domainOf, hasDomain, isThunk, objectKindOf, printable, throwParseError, uncapitalize } from "@ark/util";
import { parseObjectLiteral } from "./objectLiteral.js";

@@ -28,2 +28,4 @@ import { parseString } from "./string.js";

return def;
if ("~standard" in def)
return parseStandardSchema(def, ctx);
return parseObjectLiteral(def, ctx);

@@ -47,3 +49,28 @@ case "Array":

};
const parseStandardSchema = (def, ctx) => ctx.$.intrinsic.unknown.pipe((v, ctx) => {
const result = def["~standard"].validate(v);
if (!result.issues)
return result.value;
for (const { message, path } of result.issues) {
if (path) {
if (path.length) {
ctx.error({
problem: uncapitalize(message),
relativePath: path.map(k => (typeof k === "object" ? k.key : k))
});
}
else {
ctx.error({
message
});
}
}
else {
ctx.error({
message
});
}
}
});
export const parseTuple = (def, ctx) => maybeParseTupleExpression(def, ctx) ?? parseTupleLiteral(def, ctx);
export const writeBadDefinitionTypeMessage = (actual) => `Type definitions must be strings or objects (was ${actual})`;

@@ -40,4 +40,4 @@ import type { BaseParseContext, BaseRoot } from "@ark/schema";

previousOperator(): MinComparator | StringifiablePrefixOperator | InfixToken | undefined;
shiftedByOne(): this;
shiftedBy(count: number): this;
}
export {};

@@ -149,6 +149,6 @@ import { isKeyOf, throwInternalError, throwParseError, writeUnclosedGroupMessage, writeUnmatchedGroupCloseMessage } from "@ark/util";

}
shiftedByOne() {
this.scanner.shift();
shiftedBy(count) {
this.scanner.jumpForward(count);
return this;
}
}

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

import { type Scanner } from "@ark/util";
import type { regex } from "arkregex";
import { type ErrorMessage, type Scanner } from "@ark/util";
import type { Regex, regex } from "arkregex";
import type { Out } from "../../../attributes.ts";
import type { InferredAst } from "../../ast/infer.ts";

@@ -10,3 +11,4 @@ import type { RuntimeState } from "../../reduce/dynamic.ts";

export declare const parseEnclosed: (s: RuntimeState, enclosing: EnclosingStartToken) => void;
export type parseEnclosed<s extends StaticState, enclosingStart extends EnclosingStartToken, unscanned extends string> = Scanner.shiftUntilEscapable<unscanned, EnclosingTokens[enclosingStart], ""> extends Scanner.shiftResult<infer scanned, infer nextUnscanned> ? nextUnscanned extends "" ? s.error<writeUnterminatedEnclosedMessage<scanned, enclosingStart>> : s.setRoot<s, InferredAst<enclosingStart extends EnclosingQuote ? scanned : enclosingStart extends "/" ? regex.infer<scanned> : Date, `${enclosingStart}${scanned}${EnclosingTokens[enclosingStart]}`>, nextUnscanned extends Scanner.shift<string, infer unscanned> ? unscanned : ""> : never;
export type parseEnclosed<s extends StaticState, enclosingStart extends EnclosingStartToken, unscanned extends string> = Scanner.shiftUntilEscapable<unscanned, EnclosingTokens[enclosingStart], ""> extends Scanner.shiftResult<infer scanned, infer nextUnscanned> ? _parseEnclosed<s, enclosingStart, scanned, nextUnscanned> : never;
type _parseEnclosed<s extends StaticState, enclosingStart extends EnclosingStartToken, scanned extends string, nextUnscanned extends string, def extends string = `${enclosingStart}${scanned}${EnclosingTokens[enclosingStart]}`> = nextUnscanned extends "" ? s.error<writeUnterminatedEnclosedMessage<scanned, enclosingStart>> : enclosingStart extends EnclosingQuote ? s.setRoot<s, InferredAst<scanned, def>, nextUnscanned extends Scanner.shift<string, infer unscanned> ? unscanned : ""> : enclosingStart extends EnclosingRegexToken ? regex.parse<scanned> extends infer r ? r extends Regex ? s.setRoot<s, InferredAst<enclosingStart extends "/" ? r["infer"] : (In: r["infer"]) => Out<r["inferExecArray"]>, def>, nextUnscanned extends Scanner.shift<string, infer unscanned> ? unscanned : ""> : r extends ErrorMessage<infer e> ? s.error<e> : never : never : s.setRoot<s, InferredAst<Date, def>, nextUnscanned extends Scanner.shift<string, infer unscanned> ? unscanned : "">;
export declare const enclosingQuote: {

@@ -30,4 +32,11 @@ readonly "'": 1;

export type EnclosingLiteralStartToken = keyof EnclosingLiteralTokens;
export declare const enclosingRegexTokens: {
readonly "/": "/";
readonly "x/": "/";
};
export type EnclosingRegexTokens = typeof enclosingRegexTokens;
export type EnclosingRegexToken = keyof EnclosingRegexTokens;
export declare const enclosingTokens: {
readonly "/": "/";
readonly "x/": "/";
readonly "d'": "'";

@@ -34,0 +43,0 @@ readonly 'd"': "\"";

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

import { rootSchema } from "@ark/schema";
import { isKeyOf, throwParseError } from "@ark/util";
import { tryParseDate, writeInvalidDateMessage } from "./date.js";
const regexExecArray = rootSchema({
proto: "Array",
sequence: "string",
required: {
key: "groups",
value: ["object", { unit: undefined }]
}
});
export const parseEnclosed = (s, enclosing) => {

@@ -9,5 +18,6 @@ const enclosed = s.scanner.shiftUntilEscapable(untilLookaheadIsClosing[enclosingTokens[enclosing]]);

s.scanner.shift();
if (enclosing === "/") {
if (enclosing in enclosingRegexTokens) {
let regex;
try {
new RegExp(enclosed);
regex = new RegExp(enclosed);
}

@@ -21,2 +31,9 @@ catch (e) {

}, { prereduced: true });
if (enclosing === "x/") {
s.root = s.ctx.$.node("morph", {
in: s.root,
morphs: (s) => regex.exec(s),
declaredOut: regexExecArray
});
}
}

@@ -45,5 +62,9 @@ else if (isKeyOf(enclosing, enclosingQuote))

};
export const enclosingRegexTokens = {
"/": "/",
"x/": "/"
};
export const enclosingTokens = {
...enclosingLiteralTokens,
"/": "/"
...enclosingRegexTokens
};

@@ -50,0 +71,0 @@ export const untilLookaheadIsClosing = {

@@ -8,2 +8,2 @@ import { type Scanner, type WhitespaceChar } from "@ark/util";

export declare const parseOperand: (s: RuntimeState) => void;
export type parseOperand<s extends StaticState, $, args> = s["unscanned"] extends Scanner.shift<infer lookahead, infer unscanned> ? lookahead extends "(" ? s.reduceGroupOpen<s, unscanned> : lookahead extends EnclosingStartToken ? parseEnclosed<s, lookahead, unscanned> : lookahead extends WhitespaceChar ? parseOperand<s.scanTo<s, unscanned>, $, args> : lookahead extends "d" ? unscanned extends (Scanner.shift<infer enclosing extends EnclosingQuote, infer nextUnscanned>) ? parseEnclosed<s, `d${enclosing}`, nextUnscanned> : parseUnenclosed<s, $, args> : parseUnenclosed<s, $, args> : s.completion<`${s["scanned"]}${BaseCompletions<$, args>}`>;
export type parseOperand<s extends StaticState, $, args> = s["unscanned"] extends Scanner.shift<infer lookahead, infer unscanned> ? lookahead extends "(" ? s.reduceGroupOpen<s, unscanned> : lookahead extends EnclosingStartToken ? parseEnclosed<s, lookahead, unscanned> : lookahead extends WhitespaceChar ? parseOperand<s.scanTo<s, unscanned>, $, args> : lookahead extends "d" ? unscanned extends (Scanner.shift<infer enclosing extends EnclosingQuote, infer nextUnscanned>) ? parseEnclosed<s, `d${enclosing}`, nextUnscanned> : parseUnenclosed<s, $, args> : lookahead extends "x" ? unscanned extends Scanner.shift<"/", infer nextUnscanned> ? parseEnclosed<s, "x/", nextUnscanned> : parseUnenclosed<s, $, args> : parseUnenclosed<s, $, args> : s.completion<`${s["scanned"]}${BaseCompletions<$, args>}`>;

@@ -5,5 +5,5 @@ import { whitespaceChars } from "@ark/util";

export const parseOperand = (s) => s.scanner.lookahead === "" ? s.error(writeMissingOperandMessage(s))
: s.scanner.lookahead === "(" ? s.shiftedByOne().reduceGroupOpen()
: s.scanner.lookahead === "(" ? s.shiftedBy(1).reduceGroupOpen()
: s.scanner.lookaheadIsIn(enclosingChar) ? parseEnclosed(s, s.scanner.shift())
: s.scanner.lookaheadIsIn(whitespaceChars) ? parseOperand(s.shiftedByOne())
: s.scanner.lookaheadIsIn(whitespaceChars) ? parseOperand(s.shiftedBy(1))
: s.scanner.lookahead === "d" ?

@@ -13,2 +13,6 @@ s.scanner.nextLookahead in enclosingQuote ?

: parseUnenclosed(s)
: parseUnenclosed(s);
: s.scanner.lookahead === "x" ?
s.scanner.nextLookahead === "/" ?
s.shiftedBy(2) && parseEnclosed(s, "x/")
: parseUnenclosed(s)
: parseUnenclosed(s);

@@ -25,3 +25,3 @@ import { hasArkKind, writeUnresolvableMessage } from "@ark/schema";

s.scanner.lookahead === "#" ?
writePrefixedPrivateReferenceMessage(s.shiftedByOne().scanner.shiftUntilLookahead(terminatingChars))
writePrefixedPrivateReferenceMessage(s.shiftedBy(1).scanner.shiftUntilLookahead(terminatingChars))
: writeMissingOperandMessage(s)

@@ -28,0 +28,0 @@ : writeUnresolvableMessage(token));

@@ -15,3 +15,3 @@ import { isKeyOf, whitespaceChars } from "@ark/util";

s.scanner.lookahead === ">" ?
s.shiftedByOne().pushRootToBranch("|>")
s.shiftedBy(1).pushRootToBranch("|>")
: s.pushRootToBranch(lookahead)

@@ -18,0 +18,0 @@ : lookahead === "&" ? s.pushRootToBranch(lookahead)

@@ -104,4 +104,4 @@ import { $ark, BaseScope, hasArkKind, parseGeneric } from "@ark/schema";

export const scope = Object.assign(InternalScope.scope, {
define: def => def
define: (def) => def
});
export const Scope = InternalScope;
{
"name": "arktype",
"description": "TypeScript's 1:1 validator, optimized from editor to runtime",
"version": "2.1.27",
"version": "2.1.28",
"license": "MIT",

@@ -41,5 +41,5 @@ "repository": {

"dependencies": {
"@ark/util": "0.55.0",
"arkregex": "0.0.3",
"@ark/schema": "0.55.0"
"@ark/util": "0.56.0",
"arkregex": "0.0.4",
"@ark/schema": "0.56.0"
},

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

@@ -6,3 +6,3 @@ <h1 align="center">ArkType</h1>

It can be used to check external data like JSON payloads or forms at the boundaries of your code (similar to Zod or Yup).
It can be used to check external data like JSON payloads or forms at the boundaries of your code (similar to Zod).

@@ -9,0 +9,0 @@ <video