arktype 2.2.10 → 3.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +181 -15
- package/out/attributes.d.ts +50 -14
- package/out/checkers.d.ts +172 -0
- package/out/chunk-2U2AWCI3.js +626 -0
- package/out/chunk-4CUA5XIP.js +7 -0
- package/out/chunk-5U2ZMDNI.js +1566 -0
- package/out/chunk-DLWCO4RV.js +18 -0
- package/out/chunk-E3DZXEZK.js +72 -0
- package/out/chunk-EVCML554.js +47 -0
- package/out/chunk-G45P2CLE.js +63 -0
- package/out/chunk-GPNK5353.js +2529 -0
- package/out/chunk-MLKGABMK.js +9 -0
- package/out/chunk-NRIGTMPM.js +7 -0
- package/out/chunk-PRTMQCHS.js +3 -0
- package/out/chunk-R5G57XC7.js +7 -0
- package/out/chunk-RAZ3TXOE.js +313 -0
- package/out/chunk-SWOOCAHN.js +4 -0
- package/out/chunk-TAHPKDNM.js +3 -0
- package/out/chunk-UETB6YE2.js +14 -0
- package/out/chunk-UK5UGFOX.js +254 -0
- package/out/chunk-VV6YDN2D.js +6118 -0
- package/out/codecs.d.ts +21 -0
- package/out/codecs.js +7 -0
- package/out/config.d.ts +8 -3
- package/out/config.js +2 -3
- package/out/declare.d.ts +17 -3
- package/out/deferred.d.ts +10 -0
- package/out/errors.d.ts +1 -0
- package/out/errors.js +2 -0
- package/out/fn.d.ts +1 -1
- package/out/generic.d.ts +3 -3
- package/out/i18n.d.ts +2 -0
- package/out/i18n.js +2 -0
- package/out/index.d.ts +5 -4
- package/out/index.js +8 -9
- package/out/internal.d.ts +70 -0
- package/out/internal.js +17 -0
- package/out/island.d.ts +2 -0
- package/out/island.js +6 -0
- package/out/islandDependency.d.ts +2 -0
- package/out/islandDependency.js +18 -0
- package/out/keywords/Array.d.ts +2 -2
- package/out/keywords/builtins.d.ts +5 -3
- package/out/keywords/constructors.d.ts +9 -1
- package/out/keywords/functions.d.ts +254 -0
- package/out/keywords/keywords.d.ts +8 -9
- package/out/keywords/number.d.ts +2 -8
- package/out/keywords/phrases.d.ts +245 -0
- package/out/keywords/string.d.ts +14 -113
- package/out/keywords/ts.d.ts +35 -33
- package/out/keywords/ts.js +4 -82
- package/out/locale.d.ts +19 -0
- package/out/locales/de.d.ts +2 -0
- package/out/locales/de.js +2 -0
- package/out/locales/en.d.ts +4 -0
- package/out/locales/en.js +5 -0
- package/out/match.d.ts +6 -6
- package/out/module.d.ts +1 -1
- package/out/mutatesInput.js +3 -0
- package/out/parser/ast/generic.d.ts +6 -3
- package/out/parser/ast/infer.d.ts +1 -1
- package/out/parser/ast/validate.d.ts +11 -6
- package/out/parser/definition.d.ts +68 -7
- package/out/parser/objectLiteral.d.ts +40 -12
- package/out/parser/property.d.ts +3 -5
- package/out/parser/reduce/dynamic.d.ts +16 -7
- package/out/parser/reduce/shared.d.ts +4 -0
- package/out/parser/reduce/static.d.ts +13 -13
- package/out/parser/shift/operand/date.d.ts +0 -5
- package/out/parser/shift/operand/operand.d.ts +2 -1
- package/out/parser/shift/operand/unenclosed.d.ts +9 -6
- package/out/parser/shift/operand/unresolvable.d.ts +68 -0
- package/out/parser/shift/operator/bounds.d.ts +9 -4
- package/out/parser/shift/operator/brand.d.ts +2 -2
- package/out/parser/shift/operator/default.d.ts +2 -2
- package/out/parser/shift/operator/divisor.d.ts +2 -2
- package/out/parser/shift/operator/operator.d.ts +1 -1
- package/out/parser/shift/tokens.d.ts +9 -2
- package/out/parser/string.d.ts +61 -7
- package/out/parser/tupleExpressions.d.ts +7 -3
- package/out/precompiled.d.ts +1 -0
- package/out/precompiled.js +2 -0
- package/out/runtime.d.ts +181 -0
- package/out/runtime.js +4 -0
- package/out/runtimeDevelopment.d.ts +1 -0
- package/out/runtimeDevelopment.js +133 -0
- package/out/runtimeExports.d.ts +1 -0
- package/out/scope.d.ts +40 -11
- package/out/standalone/artifact.d.ts +265 -0
- package/out/standalone/baking.d.ts +201 -0
- package/out/standalone/combinators.d.ts +13 -0
- package/out/standalone/compilers.d.ts +23 -0
- package/out/standalone/creators.d.ts +41 -0
- package/out/standalone/fallbacks.d.ts +48 -0
- package/out/standalone/keys.d.ts +31 -0
- package/out/standalone/modules.d.ts +26 -0
- package/out/standalone/sites.d.ts +52 -0
- package/out/standalone/units.d.ts +31 -0
- package/out/standalone/values.d.ts +60 -0
- package/out/standalone.d.ts +16 -0
- package/out/type.d.ts +45 -6
- package/out/variants/array.d.ts +1 -1
- package/out/variants/base.d.ts +47 -27
- package/out/variants/date.d.ts +1 -1
- package/out/variants/instantiate.d.ts +4 -2
- package/out/variants/number.d.ts +1 -1
- package/out/variants/object.d.ts +17 -12
- package/out/variants/string.d.ts +1 -1
- package/package.json +169 -8
- package/skills/arktype/SKILL.md +278 -43
- package/skills/arktype/references/migrating.md +1296 -0
- package/skills/arktype/references/precompile.md +191 -0
- package/out/attributes.js +0 -3
- package/out/fn.js +0 -58
- package/out/generic.js +0 -37
- package/out/keywords/Array.js +0 -21
- package/out/keywords/FormData.js +0 -40
- package/out/keywords/TypedArray.js +0 -16
- package/out/keywords/builtins.js +0 -11
- package/out/keywords/constructors.js +0 -16
- package/out/keywords/keywords.js +0 -48
- package/out/keywords/number.js +0 -49
- package/out/keywords/string.js +0 -467
- package/out/match.js +0 -95
- package/out/module.js +0 -3
- package/out/nary.js +0 -1
- package/out/parser/ast/bounds.js +0 -1
- package/out/parser/ast/default.js +0 -1
- package/out/parser/ast/divisor.js +0 -1
- package/out/parser/ast/generic.js +0 -1
- package/out/parser/ast/infer.js +0 -1
- package/out/parser/ast/keyof.js +0 -1
- package/out/parser/ast/utils.js +0 -1
- package/out/parser/ast/validate.js +0 -3
- package/out/parser/definition.js +0 -78
- package/out/parser/objectLiteral.js +0 -113
- package/out/parser/property.js +0 -16
- package/out/parser/reduce/dynamic.js +0 -153
- package/out/parser/reduce/shared.js +0 -25
- package/out/parser/reduce/static.js +0 -1
- package/out/parser/shift/operand/date.js +0 -23
- package/out/parser/shift/operand/enclosed.js +0 -82
- package/out/parser/shift/operand/genericArgs.js +0 -16
- package/out/parser/shift/operand/operand.js +0 -16
- package/out/parser/shift/operand/unenclosed.js +0 -59
- package/out/parser/shift/operator/bounds.js +0 -91
- package/out/parser/shift/operator/brand.js +0 -6
- package/out/parser/shift/operator/default.js +0 -29
- package/out/parser/shift/operator/divisor.js +0 -13
- package/out/parser/shift/operator/operator.js +0 -28
- package/out/parser/shift/tokens.js +0 -37
- package/out/parser/string.js +0 -42
- package/out/parser/tupleExpressions.js +0 -75
- package/out/parser/tupleLiteral.js +0 -128
- package/out/scope.js +0 -106
- package/out/type.js +0 -55
- package/out/variants/array.js +0 -1
- package/out/variants/base.js +0 -1
- package/out/variants/date.js +0 -1
- package/out/variants/instantiate.js +0 -1
- package/out/variants/number.js +0 -1
- package/out/variants/object.js +0 -1
- package/out/variants/string.js +0 -1
- /package/out/{declare.js → mutatesInput.d.ts} +0 -0
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { BaseRoot } from "@ark/schema";
|
|
2
|
-
import { type BigintLiteral, type ErrorMessage, type NumberLiteral, type Scanner, type trim } from "@ark/util";
|
|
2
|
+
import { type BigintLiteral, type ErrorMessage, type NonFiniteNumberLiteral, type NumberLiteral, type Scanner, type trim } from "@ark/util";
|
|
3
3
|
import type { type } from "../../../keywords/keywords.ts";
|
|
4
4
|
import type { DateLiteral } from "../../../attributes.ts";
|
|
5
5
|
import type { RootedRuntimeState } from "../../reduce/dynamic.ts";
|
|
6
6
|
import type { EnclosingLiteralStartToken, EnclosingLiteralTokens, StringLiteral } from "../operand/enclosed.ts";
|
|
7
7
|
type UnitLiteralKeyword = "null" | "undefined" | "true" | "false";
|
|
8
8
|
export type UnitLiteral = UnenclosedUnitLiteral | EnclosedUnitLiteral;
|
|
9
|
-
export type UnenclosedUnitLiteral = BigintLiteral | NumberLiteral | UnitLiteralKeyword;
|
|
9
|
+
export type UnenclosedUnitLiteral = BigintLiteral | NumberLiteral | NonFiniteNumberLiteral | UnitLiteralKeyword;
|
|
10
10
|
export type EnclosedUnitLiteral = StringLiteral | DateLiteral;
|
|
11
11
|
/**
|
|
12
12
|
* Unlike a unit literal, an empty collection can't be reused across traversals
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { type Scanner } from "@ark/util";
|
|
2
2
|
import type { RootedRuntimeState } from "../../reduce/dynamic.ts";
|
|
3
3
|
import type { StaticState, s } from "../../reduce/static.ts";
|
|
4
|
-
import {
|
|
4
|
+
import { shiftUntilTerminator } from "../tokens.ts";
|
|
5
5
|
export declare const parseDivisor: (s: RootedRuntimeState) => void;
|
|
6
|
-
export type parseDivisor<s extends StaticState, unscanned extends string> =
|
|
6
|
+
export type parseDivisor<s extends StaticState, unscanned extends string> = shiftUntilTerminator<Scanner.skipWhitespace<unscanned>> extends (Scanner.shiftResult<infer scanned, infer nextUnscanned>) ? scanned extends `${infer divisor extends number}` ? divisor extends 0 ? s.error<writeInvalidDivisorMessage<0>> : s.setRoot<s, [s["root"], "%", divisor], nextUnscanned> : s.error<writeInvalidDivisorMessage<scanned>> : never;
|
|
7
7
|
export declare const writeInvalidDivisorMessage: <divisor extends string | number>(divisor: divisor) => writeInvalidDivisorMessage<divisor>;
|
|
8
8
|
export type writeInvalidDivisorMessage<divisor extends string | number> = `% operator must be followed by a non-zero integer literal (was ${divisor})`;
|
|
@@ -6,7 +6,7 @@ import { parseBound, type ComparatorStartChar } from "./bounds.ts";
|
|
|
6
6
|
import { parseBrand } from "./brand.ts";
|
|
7
7
|
import { parseDivisor } from "./divisor.ts";
|
|
8
8
|
export declare const parseOperator: (s: RootedRuntimeState) => void;
|
|
9
|
-
export type parseOperator<s extends StaticState, $, args> = s["unscanned"] extends Scanner.shift<infer
|
|
9
|
+
export type parseOperator<s extends StaticState, $, args> = s["unscanned"] extends Scanner.shift<infer peek, infer unscanned> ? peek extends "[" ? unscanned extends Scanner.shift<"]", infer nextUnscanned> ? s.setRoot<s, [s["root"], "[]"], nextUnscanned> : s.error<incompleteArrayTokenMessage> : peek extends "|" ? unscanned extends Scanner.shift<">", infer nextUnscanned> ? s.reduceBranch<s, "|>", nextUnscanned> : s.reduceBranch<s, peek, unscanned> : peek extends "&" ? s.reduceBranch<s, peek, unscanned> : peek extends ")" ? s.finalizeGroup<s, unscanned> : lookaheadIsFinalizing<peek, unscanned> extends true ? s.finalize<s.scanTo<s, unscanned>, peek & FinalizingLookahead> : peek extends ComparatorStartChar ? parseBound<s, peek, unscanned, $, args> : peek extends "%" ? parseDivisor<s, unscanned> : peek extends "#" ? parseBrand<s, unscanned> : peek extends WhitespaceChar ? parseOperator<s.scanTo<s, unscanned>, $, args> : s.error<writeUnexpectedCharacterMessage<peek>> : s.finalize<s, "">;
|
|
10
10
|
export declare const writeUnexpectedCharacterMessage: <char extends string, shouldBe extends string>(char: char, shouldBe?: shouldBe) => writeUnexpectedCharacterMessage<char, shouldBe>;
|
|
11
11
|
export type writeUnexpectedCharacterMessage<char extends string, shouldBe extends string = ""> = `'${char}' is not allowed here${shouldBe extends "" ? "" : ` (should be ${shouldBe})`}`;
|
|
12
12
|
export declare const incompleteArrayTokenMessage = "Missing expected ']'";
|
|
@@ -18,6 +18,12 @@ export declare const terminatingChars: {
|
|
|
18
18
|
readonly "#": 1;
|
|
19
19
|
};
|
|
20
20
|
export type TerminatingChar = keyof typeof terminatingChars;
|
|
21
|
+
export declare const shiftUntilTerminator: (sc: Scanner) => string;
|
|
22
|
+
export type shiftUntilTerminator<unscanned extends string> = unscanned extends `${string}!=${string}` ? shiftComparatorBang<Scanner.shiftUntil<unscanned, TerminatingChar>> : Scanner.shiftUntil<unscanned, TerminatingChar>;
|
|
23
|
+
type shiftComparatorBang<result extends [string, string]> = result[1] extends `=${string}` ? result[0] extends `${infer name}!` ? [
|
|
24
|
+
name,
|
|
25
|
+
`!${result[1]}`
|
|
26
|
+
] : result : result;
|
|
21
27
|
export declare const finalizingLookaheads: {
|
|
22
28
|
readonly ">": 1;
|
|
23
29
|
readonly ",": 1;
|
|
@@ -26,8 +32,9 @@ export declare const finalizingLookaheads: {
|
|
|
26
32
|
readonly "?": 1;
|
|
27
33
|
};
|
|
28
34
|
export type FinalizingLookahead = keyof typeof finalizingLookaheads;
|
|
29
|
-
export declare const lookaheadIsFinalizing: (
|
|
30
|
-
export type lookaheadIsFinalizing<
|
|
35
|
+
export declare const lookaheadIsFinalizing: (peek: string, sc: Scanner) => peek is ">" | "," | "=" | "?";
|
|
36
|
+
export type lookaheadIsFinalizing<peek extends string, unscanned extends string> = peek extends ">" ? unscanned extends `=${infer nextUnscanned}` ? nextUnscanned extends `=${string}` ? true : false : Scanner.skipWhitespace<unscanned> extends ("" | `${TerminatingChar}${string}` | `!=${string}`) ? true : false : peek extends "=" ? unscanned extends `=${string}` ? false : true : peek extends "," | "?" ? true : false;
|
|
31
37
|
export type InfixToken = Comparator | "|" | "&" | "%" | ":" | "=>" | "|>" | "#" | "@" | "=";
|
|
32
38
|
export type PostfixToken = "[]" | "?";
|
|
33
39
|
export type OperatorToken = InfixToken | PostfixToken;
|
|
40
|
+
export {};
|
package/out/parser/string.d.ts
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
import type { BaseParseContext, resolvableReferenceIn } from "@ark/schema";
|
|
2
|
-
import { type ErrorMessage } from "@ark/util";
|
|
1
|
+
import type { arkKind, BaseParseContext, GenericAst, resolvableReferenceIn } from "@ark/schema";
|
|
2
|
+
import { type anyOrNever, type Backslash, type BigintLiteral, type ErrorMessage, type NumberLiteral, type WhitespaceChar } from "@ark/util";
|
|
3
|
+
import type { DateLiteral } from "../attributes.ts";
|
|
3
4
|
import type { ArkAmbient } from "../config.ts";
|
|
4
5
|
import type { InnerParseResult, resolutionToAst } from "../scope.ts";
|
|
5
|
-
import type { inferAstRoot } from "./ast/infer.ts";
|
|
6
|
+
import type { InferredAst, inferAstRoot } from "./ast/infer.ts";
|
|
6
7
|
import { RuntimeState, type RootedRuntimeState } from "./reduce/dynamic.ts";
|
|
7
|
-
import type { StringifiablePrefixOperator } from "./reduce/shared.ts";
|
|
8
|
+
import type { Comparator, InvertedComparators, MaxComparator, StringifiablePrefixOperator } from "./reduce/shared.ts";
|
|
8
9
|
import type { s, StaticState } from "./reduce/static.ts";
|
|
10
|
+
import type { EnclosingQuote } from "./shift/operand/enclosed.ts";
|
|
11
|
+
import type { writeInvalidGenericArgCountMessage } from "./shift/operand/genericArgs.ts";
|
|
9
12
|
import type { parseOperand } from "./shift/operand/operand.ts";
|
|
10
13
|
import { parseDefault } from "./shift/operator/default.ts";
|
|
11
14
|
import { writeUnexpectedCharacterMessage, type parseOperator } from "./shift/operator/operator.ts";
|
|
@@ -14,10 +17,61 @@ export declare const parseString: (def: string, ctx: BaseParseContext) => InnerP
|
|
|
14
17
|
* Try to parse the definition from right to left using the most common syntax.
|
|
15
18
|
* This can be much more efficient for simple definitions.
|
|
16
19
|
*/
|
|
17
|
-
export type parseString<def extends string, $, args> = def extends keyof $ ?
|
|
18
|
-
|
|
19
|
-
|
|
20
|
+
export type parseString<def extends string, $, args> = def extends keyof $ ? $[def] extends GenericAst ? [
|
|
21
|
+
$[def]
|
|
22
|
+
] extends [anyOrNever] ? resolutionToAst<def, $[def]> : ErrorMessage<writeInvalidGenericArgCountMessage<def, $[def]["names"], []>> : resolutionToAst<def, $[def]> : def extends `${string}[]` ? def extends `${infer child}[]` ? child extends keyof $ ? [resolutionToAst<child, $[child]>, "[]"] : resolveAmbient<child, $> extends [unknown] ? parseAmbientReference<def, child, resolveAmbient<child, $>[0], $, args> : parseNonReference<def, $, args> : never : resolveAmbient<def, $> extends [unknown] ? parseAmbientReference<def, def, resolveAmbient<def, $>[0], $, args> : parseNonReference<def, $, args>;
|
|
23
|
+
type parseNonReference<def extends string, $, args> = def extends `${EnclosingQuote}${string}` ? parseQuotedToken<def> extends infer ast ? null extends ast ? parseExpression<def, $, args> : ast : never : def extends `${string}${" " | "|"}${string}` ? parseExpression<def, $, args> : def extends NumberLiteral | BigintLiteral ? parseOperandToken<def, $, args> extends infer ast ? null extends ast ? fullStringParse<s.initialize<def>, $, args> : ast : never : fullStringParse<s.initialize<def>, $, args>;
|
|
24
|
+
type parseExpression<def extends string, $, args> = def extends `${string}${"(" | "|>"}${string}` | `/${string}` ? fullStringParse<s.initialize<def>, $, args> : def extends `${string} = ${string}` ? parseDefaultExpression<def, $, args> : def extends `${string} | ${string}` ? parseSpacedUnion<def, def, $, args> : def extends `${string}|${string}` ? parseOperandUnion<def, def, $, args> : parseBoundedOperand<def, $, args>;
|
|
25
|
+
type parseDefaultExpression<def extends string, $, args> = def extends `${infer base} = ${infer value}` ? parseString<base, $, args> extends (ErrorMessage | readonly [unknown, "?" | "="] | readonly [unknown, "=", unknown]) ? fullStringParse<s.initialize<def>, $, args> : parseDefault<parseString<base, $, args>, ` ${value}`> : never;
|
|
26
|
+
type resolveAmbient<reference, $> = [
|
|
27
|
+
reference
|
|
28
|
+
] extends [keyof ArkAmbient.$] ? [ArkAmbient.$[reference]] : reference extends `${string}.${string}` ? reference extends `${infer submodule}.${infer name}` ? [
|
|
29
|
+
submodule
|
|
30
|
+
] extends [keyof $] ? null : [submodule] extends [keyof ArkAmbient.$] ? resolveSubmodule<ArkAmbient.$[submodule], name> : null : null : null;
|
|
31
|
+
type resolveSubmodule<submodule, reference> = submodule extends {
|
|
32
|
+
[arkKind]: "module";
|
|
33
|
+
} ? [
|
|
34
|
+
reference
|
|
35
|
+
] extends [keyof submodule] ? [submodule[reference]] : reference extends `${infer nested}.${infer name}` ? [
|
|
36
|
+
nested
|
|
37
|
+
] extends [keyof submodule] ? resolveSubmodule<submodule[nested], name> : null : null : null;
|
|
38
|
+
type parseAmbientReference<def extends string, reference extends string, resolution, $, args> = [
|
|
39
|
+
reference
|
|
40
|
+
] extends [keyof args] ? fullStringParse<s.initialize<def>, $, args> : [resolution] extends [GenericAst] ? fullStringParse<s.initialize<def>, $, args> : def extends reference ? resolutionToAst<reference, resolution> : [resolutionToAst<reference, resolution>, "[]"];
|
|
41
|
+
type parseOperandUnion<def extends string, unscanned extends string, $, args, union = undefined> = unscanned extends `${infer head}|${infer tail}` ? parseOperandToken<trimSpaces<head>, $, args> extends infer ast ? null extends ast ? fullStringParse<s.initialize<def>, $, args> : parseOperandUnion<def, tail, $, args, [
|
|
42
|
+
union
|
|
43
|
+
] extends [undefined] ? ast : [union, "|", ast]> : never : parseOperandToken<trimSpaces<unscanned>, $, args> extends infer ast ? null extends ast ? fullStringParse<s.initialize<def>, $, args> : [union, "|", ast] : never;
|
|
44
|
+
type parseSpacedUnion<def extends string, unscanned extends string, $, args, union = undefined> = unscanned extends `${infer head} | ${infer tail}` ? parseOperandToken<head, $, args> extends infer ast ? null extends ast ? fullStringParse<s.initialize<def>, $, args> : parseSpacedUnion<def, tail, $, args, [
|
|
45
|
+
union
|
|
46
|
+
] extends [undefined] ? ast : [union, "|", ast]> : never : parseOperandToken<unscanned, $, args> extends infer ast ? null extends ast ? fullStringParse<s.initialize<def>, $, args> : [union, "|", ast] : never;
|
|
47
|
+
type parseOperandToken<token extends string, $, args> = token extends `${string}[]` ? token extends `${infer child}[]` ? parseOperandToken<child, $, args> extends infer ast ? null extends ast ? null : [ast, "[]"] : never : never : token extends `${EnclosingQuote}${string}` ? parseQuotedToken<token> : [token] extends [keyof args] ? null : token extends keyof $ ? referenceToAst<token, $[token]> : resolveAmbient<token, $> extends [unknown] ? referenceToAst<token, resolveAmbient<token, $>[0]> : `#${token}` extends keyof $ ? null : token extends `${string}${WhitespaceChar}${string}` ? null : token extends NumberLiteral<infer n> ? InferredAst<n, token> : token extends BigintLiteral<infer b> ? InferredAst<b, token> : null;
|
|
48
|
+
type parseQuotedToken<token extends string> = token extends `'${infer content}'` ? content extends `${string}${"'" | Backslash}${string}` ? null : InferredAst<content, token> : token extends `"${infer content}"` ? content extends `${string}${'"' | Backslash}${string}` ? null : InferredAst<content, token> : null;
|
|
49
|
+
type parseBoundedOperand<def extends string, $, args> = def extends `${infer l} ${infer comparator extends Comparator} ${infer r}` ? parseOperandToken<l, $, args> extends (InferredAst<Date | number, `${infer min extends number | DateLiteral}`>) ? [
|
|
50
|
+
comparator,
|
|
51
|
+
r
|
|
52
|
+
] extends ([
|
|
53
|
+
"<" | "<=",
|
|
54
|
+
`${infer operand} ${infer maxComparator extends MaxComparator} ${infer max}`
|
|
55
|
+
]) ? parseRightBound<operand, max, $, args> extends ([
|
|
56
|
+
infer ast,
|
|
57
|
+
infer maxLimit
|
|
58
|
+
]) ? [
|
|
59
|
+
min,
|
|
60
|
+
InvertedComparators[comparator],
|
|
61
|
+
[ast, maxComparator, maxLimit]
|
|
62
|
+
] : fullStringParse<s.initialize<def>, $, args> : fullStringParse<s.initialize<def>, $, args> : parseRightBound<l, r, $, args> extends [infer ast, infer limit] ? [
|
|
63
|
+
ast,
|
|
64
|
+
comparator,
|
|
65
|
+
limit
|
|
20
66
|
] : fullStringParse<s.initialize<def>, $, args> : fullStringParse<s.initialize<def>, $, args>;
|
|
67
|
+
type parseRightBound<operand extends string, limit extends string, $, args> = parseOperandToken<operand, $, args> extends infer ast ? null extends ast ? null : [
|
|
68
|
+
ast
|
|
69
|
+
] extends [InferredAst<Date | number, `${number}`>] ? null : parseOperandToken<limit, $, args> extends (InferredAst<unknown, `${infer value extends number | DateLiteral}`>) ? [
|
|
70
|
+
ast,
|
|
71
|
+
value
|
|
72
|
+
] : null : never;
|
|
73
|
+
type referenceToAst<reference extends string, resolution> = resolutionToAst<reference, resolution> extends infer ast ? ast extends GenericAst ? null : ast : never;
|
|
74
|
+
type trimSpaces<token extends string> = token extends ` ${infer rest}` ? trimSpaces<rest> : token extends `${infer rest} ` ? trimSpaces<rest> : token;
|
|
21
75
|
export type inferString<def extends string, $, args> = inferAstRoot<parseString<def, $, args>, $, args>;
|
|
22
76
|
export type BaseCompletions<$, args, otherSuggestions extends string = never> = resolvableReferenceIn<$> | resolvableReferenceIn<ArkAmbient.$> | (keyof args & string) | StringifiablePrefixOperator | otherSuggestions;
|
|
23
77
|
export declare const fullStringParse: (s: RuntimeState) => InnerParseResult;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type BaseParseContext, type BaseRoot, type Morph, type NodeSelector, type Predicate, type TypeMeta, type unwrapDefault } from "@ark/schema";
|
|
2
|
-
import { type array, type BuiltinObjectKind, type Constructor, type Domain, type show } from "@ark/util";
|
|
3
|
-
import type { defaultFor, distill, inferIntersection, inferMorphOut, inferPipe, inferPredicate, Out, withDefault } from "../attributes.ts";
|
|
2
|
+
import { type anyOrNever, type array, type BuiltinObjectKind, type Constructor, type Domain, type ErrorMessage, type show } from "@ark/util";
|
|
3
|
+
import type { defaultFor, distill, inferIntersection, inferMorphOut, inferPipe, inferPredicate, InferredMorph, Out, withDefault } from "../attributes.ts";
|
|
4
4
|
import type { type } from "../keywords/keywords.ts";
|
|
5
5
|
import type { inferDefinition, validateDefinition } from "./definition.ts";
|
|
6
6
|
import { writeMissingRightOperandMessage } from "./shift/operand/unenclosed.ts";
|
|
@@ -16,7 +16,7 @@ export type validatePrefixExpression<def extends IndexZeroExpression, $, args> =
|
|
|
16
16
|
export type validateIndexOneExpression<def extends IndexOneExpression, $, args> = def[1] extends TuplePostfixOperator ? readonly [validateDefinition<def[0], $, args>, def[1]] : readonly [
|
|
17
17
|
validateDefinition<def[0], $, args>,
|
|
18
18
|
def["length"] extends 2 ? writeMissingRightOperandMessage<def[1]> : def[1],
|
|
19
|
-
def[1] extends "|" ? validateDefinition<def[2], $, args> : def[1] extends "&" ? validateDefinition<def[2], $, args> : def[1] extends ":" ?
|
|
19
|
+
def[1] extends "|" ? validateDefinition<def[2], $, args> : def[1] extends "&" ? validateDefinition<def[2], $, args> : def[1] extends ":" ? validatePredicate<inferDefinition<def[0], $, args>, type.infer.Out<def[0], $, args>> : def[1] extends "=>" ? Morph<type.infer.Out<def[0], $, args>> : def[1] extends "|>" ? validateDefinition<def[2], $, args> : def[1] extends "=" ? defaultFor<type.infer.In<def[0], $, args>> : def[1] extends "@" ? TypeMeta.MappableInput : validateDefinition<def[2], $, args>,
|
|
20
20
|
...(def[1] extends "@" ? [NodeSelector?] : [])
|
|
21
21
|
];
|
|
22
22
|
export type UnparsedTupleExpressionInput = {
|
|
@@ -33,6 +33,10 @@ export declare const parseMorphTuple: IndexOneParser<"=>">;
|
|
|
33
33
|
export declare const writeMalformedFunctionalExpressionMessage: (operator: ":" | "=>", value: unknown) => string;
|
|
34
34
|
export type parseTo<inDef, outDef, $, args> = inferPipe<inferDefinition<inDef, $, args>, inferDefinition<outDef, $, args>>;
|
|
35
35
|
export type parseMorph<inDef, morph, $, args> = morph extends Morph ? inferMorphOut<morph> extends infer out ? (In: distill.In<inferDefinition<inDef, $, args>>) => Out<out> : never : never;
|
|
36
|
+
export type validatePredicate<operand, data> = [
|
|
37
|
+
operand
|
|
38
|
+
] extends [anyOrNever] ? Predicate<data> : [operand] extends [InferredMorph] ? ErrorMessage<narrowedMorphMessage> : Predicate<data>;
|
|
39
|
+
export type narrowedMorphMessage = "Predicate operand must be unknown (was a morph)";
|
|
36
40
|
export declare const parseNarrowTuple: IndexOneParser<":">;
|
|
37
41
|
export type IndexOneExpression<token extends string = IndexOneOperator> = readonly [unknown, token, ...unknown[]];
|
|
38
42
|
type IndexOneParser<token extends string> = (def: IndexOneExpression<token>, ctx: BaseParseContext) => BaseRoot;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { registerPrecompiledUnits } from "@ark/schema";
|
package/out/runtime.d.ts
ADDED
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import type { JsonSchema, RootApply, StandardJSONSchemaV1, StandardSchemaV1 } from "@ark/schema";
|
|
2
|
+
import { ArkErrors, type ArkErrorCode, type ArkIssue, type CompactApply, type UnionIssueOf, type FailHandler, type FailureContext, type FailureSite, type InternalTraversal, type IssuesClass, type SiteContext, type Traversal } from "@ark/schema/runtime";
|
|
3
|
+
import { type Fn, type inferred, type JsonStructure } from "@ark/util";
|
|
4
|
+
import { InternalTypedFn } from "./fn.ts";
|
|
5
|
+
import type { introspectionMembers } from "./standalone.ts";
|
|
6
|
+
import type { ArrayType } from "./variants/array.ts";
|
|
7
|
+
import type { DateType } from "./variants/date.ts";
|
|
8
|
+
import type { NumberType } from "./variants/number.ts";
|
|
9
|
+
import type { ObjectType } from "./variants/object.ts";
|
|
10
|
+
import type { StringType } from "./variants/string.ts";
|
|
11
|
+
export { addErrors, addMorphErrs, aliasVisits, allowsAcyclic, allowsInBranch, allowsInBranchBy, allowsInContext, allowsUntracked, appliesValues, applyCyclic, applyIssues, applyRejected, ArkErrors, arrayIndexMatcher, callMorph, codedIssue, computeDefaultValueMorph, configure, configuredFallbackOf, configuredWriterOf, copyDeclared, copyOf, alikeIssue, describeCollapsibleDate, describePredicate, disallowed, discriminatesBooleans, enInfo, enterApplied, enterResolution, execMorph, exitResolution, exitApplied, failsInBranches, failsKey, failsKeySite, failsSite, FirstIssues, FirstIssueTraversal, fixConfig, foundErrors, fixConfigured, holdsOnlyIndices, keepOwn, InternalTraversal, listedIssue, matchesRepeated, mergeTransformed, missingTextOf, pipe, pipeApplied, pipeChecked, pipeTransformed, printKind, rejected, rejects, runtimeConfig, runtimeScope, silentCtx, throwIssues, throwOnDefault, TransformErrors, transformed, transformedInApply, transformIfAllowed, transformResolution, transformsBranches, transformsValid, Traversal, TraversalError, tryMorph, writeDomainActual, writeLengthActual, writeMessage, writeNotEqualActual, writeProtoActual, writeNullableJsonSchema, writeUnionJsonSchema, writeUnitActual, writeUnitMessage, type ArkError } from "@ark/schema/runtime";
|
|
12
|
+
export { baseNameOf, functionNameOf, isIpv4, isIpv6, isIso8601, isNumericString, isPlainObjectOrArray, isUuid, isValidDate, isWellFormedInteger, jsTypeOfDescriptions, liftArray, ParseError, printable, throwParseError, timeOf } from "@ark/util";
|
|
13
|
+
export * from "./checkers.ts";
|
|
14
|
+
export * from "./keywords/functions.ts";
|
|
15
|
+
export interface ValidatorAttributes {
|
|
16
|
+
meta: ArkEnv.meta;
|
|
17
|
+
expression?: string;
|
|
18
|
+
description?: string;
|
|
19
|
+
json?: JsonStructure;
|
|
20
|
+
toJSON?: () => JsonStructure;
|
|
21
|
+
toJsonSchema?: () => JsonSchema;
|
|
22
|
+
"~standard"?: Pick<StandardJSONSchemaV1.Props, "jsonSchema">;
|
|
23
|
+
}
|
|
24
|
+
export type IntrospectionMember = (typeof introspectionMembers)[number];
|
|
25
|
+
export declare const precompiledForArktype_3_0_0_beta_1 = true;
|
|
26
|
+
export declare const assign: {
|
|
27
|
+
<T extends {}, U>(target: T, source: U): T & U;
|
|
28
|
+
<T extends {}, U, V>(target: T, source1: U, source2: V): T & U & V;
|
|
29
|
+
<T extends {}, U, V, W>(target: T, source1: U, source2: V, source3: W): T & U & V & W;
|
|
30
|
+
(target: object, ...sources: any[]): any;
|
|
31
|
+
};
|
|
32
|
+
export declare const is: (value1: any, value2: any) => boolean;
|
|
33
|
+
export declare const freeze: {
|
|
34
|
+
<T extends Function>(f: T): T;
|
|
35
|
+
<T extends {
|
|
36
|
+
[idx: string]: U | null | undefined | object;
|
|
37
|
+
}, U extends string | bigint | number | boolean | symbol>(o: T): Readonly<T>;
|
|
38
|
+
<T>(o: T): Readonly<T>;
|
|
39
|
+
};
|
|
40
|
+
export declare const setPrototypeOf: (o: any, proto: object | null) => any;
|
|
41
|
+
/**
|
|
42
|
+
* #### a Type precompiled to validate without arktype, frozen with what it holds
|
|
43
|
+
*/
|
|
44
|
+
export interface Validator {
|
|
45
|
+
(data: unknown, pipedFromCtx?: Traversal, onFail?: ArkErrors.Handler | null): unknown;
|
|
46
|
+
}
|
|
47
|
+
export declare class Validator {
|
|
48
|
+
meta: ArkEnv.meta;
|
|
49
|
+
allows: (data: unknown) => boolean;
|
|
50
|
+
assert: (data: unknown, pipedFromCtx?: Traversal) => unknown;
|
|
51
|
+
"~standard": StandardSchemaV1.Props;
|
|
52
|
+
expression: string;
|
|
53
|
+
description: string;
|
|
54
|
+
json: JsonStructure;
|
|
55
|
+
toJSON: () => JsonStructure;
|
|
56
|
+
toJsonSchema: () => JsonSchema;
|
|
57
|
+
traverse(data: unknown, pipedFromCtx?: Traversal): ArkErrors | {} | null | undefined;
|
|
58
|
+
from(input: unknown): unknown;
|
|
59
|
+
toString(): string;
|
|
60
|
+
}
|
|
61
|
+
export declare const own: <t extends object>(validator: t, attributes: object) => t;
|
|
62
|
+
export declare const bakeInto: <t>(validator: t, { "~standard": standard, ...attributes }: Omit<ValidatorAttributes, "meta">) => t;
|
|
63
|
+
export declare const standardResultOf: (out: unknown) => StandardSchemaV1.Result<unknown>;
|
|
64
|
+
export declare const siteOf: (code: ArkErrorCode, description?: string, message?: string) => SiteContext;
|
|
65
|
+
export declare const requiredSiteOf: (description?: string) => FailureSite;
|
|
66
|
+
export declare const keySiteOf: (code: ArkErrorCode, description?: string, missing?: any) => FailureSite;
|
|
67
|
+
export declare const createValidator: (rootApply: RootApply, allows: (data: unknown) => boolean, attributes: ValidatorAttributes, id: string, holes?: readonly unknown[]) => Validator;
|
|
68
|
+
export declare const createValidatorWith: (make: (parts: readonly Fn[], onFail: FailHandler | null) => Fn, parts: readonly Fn[], id: string, attributes?: ValidatorAttributes, holes?: readonly unknown[]) => Validator;
|
|
69
|
+
type ValidatorArgs = [
|
|
70
|
+
pipedFromCtx?: Traversal | undefined,
|
|
71
|
+
onFail?: FailHandler | null | undefined
|
|
72
|
+
];
|
|
73
|
+
export declare const pipedIntoUndetailed: (pipedFromCtx: Traversal, out: unknown) => unknown;
|
|
74
|
+
export declare const callingRootApply: ([, rootApply]: readonly Fn[], configuredOnFail: FailHandler | null) => Fn;
|
|
75
|
+
export declare const deferred: (load: () => readonly Fn[]) => readonly Fn[];
|
|
76
|
+
export declare const once: <t>(load: () => t) => (() => t);
|
|
77
|
+
export declare const callingDeferredRootApply: (parts: Fn[], configuredOnFail: FailHandler | null) => Fn;
|
|
78
|
+
type ValidatorParts = [
|
|
79
|
+
rootApply: RootApply,
|
|
80
|
+
allows: (data: unknown) => boolean,
|
|
81
|
+
attributes: ValidatorAttributes,
|
|
82
|
+
id: string
|
|
83
|
+
];
|
|
84
|
+
export declare const rekeyed: (parts: ValidatorParts, holes: readonly unknown[]) => Validator;
|
|
85
|
+
type TypeOnlyMember = typeof inferred | "t" | "infer" | "inferIn" | "inferOut" | "inferIntrospectableOut" | "Symbol";
|
|
86
|
+
export type UnavailableMember = Exclude<keyof (ArrayType & DateType & NumberType & ObjectType & StringType), keyof Validator | keyof Function | TypeOnlyMember | IntrospectionMember>;
|
|
87
|
+
export declare const bakedJsonSchema: (write: () => JsonSchema, byTarget: readonly ((() => JsonSchema) | 0)[], ignoresFallback?: 1) => ((opts?: {
|
|
88
|
+
target?: unknown;
|
|
89
|
+
}) => JsonSchema);
|
|
90
|
+
type FallBack = (code: string, ctx: object, configured?: Fn) => unknown;
|
|
91
|
+
interface JsonSchemaOptions {
|
|
92
|
+
target?: unknown;
|
|
93
|
+
fallback?: unknown;
|
|
94
|
+
}
|
|
95
|
+
export declare const replayedJsonSchema: (write: () => JsonSchema, byTarget: readonly ((() => JsonSchema) | 0)[], replays: readonly (((fallBack: FallBack) => JsonSchema) | 0)[]) => ((opts?: JsonSchemaOptions) => JsonSchema);
|
|
96
|
+
type JsonSchemaWritersByTarget = readonly (() => JsonSchema)[];
|
|
97
|
+
export declare const bakedStandardJsonSchema: (input: JsonSchemaWritersByTarget, output: JsonSchemaWritersByTarget) => StandardJSONSchemaV1.Converter;
|
|
98
|
+
export declare const throwJsonSchemaError: (code: string, message: string, context: object) => never;
|
|
99
|
+
export declare const fallbackThrower: (code: string, header: string) => (ctx: object) => never;
|
|
100
|
+
export declare const throwUnbaked: (reason: string) => never;
|
|
101
|
+
export declare const typedFn: (raw: Fn, params: Validator, returns: Validator) => InternalTypedFn;
|
|
102
|
+
export declare const type: {
|
|
103
|
+
errors: typeof ArkErrors;
|
|
104
|
+
};
|
|
105
|
+
export declare const canParseUrl: (s: string) => boolean;
|
|
106
|
+
export declare const codeSiteOf: (code: ArkErrorCode, description: string | undefined, message: string) => SiteContext;
|
|
107
|
+
type Writer = string | Fn | undefined;
|
|
108
|
+
export declare const writtenSiteOf: (code: ArkErrorCode, description: string | undefined, context: Record<string, unknown>, writers: readonly Writer[], keeps?: any) => SiteContext;
|
|
109
|
+
export declare const raisingTraversalOf: (Base: typeof Traversal, writtenByCode: Record<string, [writers: readonly Writer[], keeps: number]>) => typeof Traversal;
|
|
110
|
+
export declare const failsAt: (ctx: FailureContext | undefined, site: FailureSite, data: unknown) => boolean | undefined;
|
|
111
|
+
export declare const failsWith: (ctx: FailureContext | undefined, data: unknown, code: ArkErrorCode, expected?: string | undefined, message?: string | undefined, text?: ((issue: ArkIssue) => unknown) | undefined) => boolean | undefined;
|
|
112
|
+
export declare const failsKeyWith: (ctx: FailureContext | undefined, data: unknown, key: PropertyKey, code: ArkErrorCode, expected?: string | undefined, missing?: string | undefined) => boolean | undefined;
|
|
113
|
+
export declare const failsAtKey: (ctx: FailureContext | undefined, site: FailureSite, data: unknown, key: PropertyKey) => boolean | undefined;
|
|
114
|
+
export declare const failsAtPath: (ctx: FailureContext | undefined, site: FailureSite, data: unknown, [k, ...deeper]: PropertyKey[]) => boolean | undefined;
|
|
115
|
+
export declare const failsIn: (ctx: FailureContext | undefined, apply: CompactApply, data: unknown, key: PropertyKey, expected?: string | undefined, message?: string | undefined, text?: ((issue: ArkIssue) => unknown) | undefined) => boolean | undefined;
|
|
116
|
+
export declare const ownIssue: (site: FailureSite) => UnionIssueOf;
|
|
117
|
+
export declare const failsListed: (ctx: any, firsts: readonly ArkIssue[], data: unknown, issueOf: UnionIssueOf) => boolean | undefined;
|
|
118
|
+
export declare const failsBranches: (ctx: any, branches: readonly CompactApply[], data: unknown, issueOf: UnionIssueOf) => boolean | undefined;
|
|
119
|
+
export declare const applyErrors: (apply: CompactApply, data: unknown, config: unknown, onFail: ArkErrors.Handler | null, Ctx: new (data: unknown, config: unknown) => ArkErrors | InternalTraversal) => unknown;
|
|
120
|
+
export declare const applyNodeErrors: (node: {
|
|
121
|
+
tApply: CompactApply;
|
|
122
|
+
}, data: unknown, config: unknown, onFail: ArkErrors.Handler | null, Ctx: new (data: unknown, config: unknown) => ArkErrors | InternalTraversal) => unknown;
|
|
123
|
+
export declare const applyElements: (allows: (data: unknown) => boolean, apply: CompactApply, i: number, data: readonly unknown[], args: ValidatorArgs, onFail: ArkErrors.Handler | null, Ctx: new (data: unknown, config: unknown) => ArkErrors | InternalTraversal) => unknown;
|
|
124
|
+
export declare const applyCallErrors: (apply: CompactApply, data: unknown, args: ValidatorArgs, onFail: ArkErrors.Handler | null, Ctx: new (data: unknown, config: unknown) => ArkErrors | InternalTraversal) => unknown;
|
|
125
|
+
export declare const unreadErrors: (apply: CompactApply, data: unknown, onFail: ArkErrors.Handler | null, Ctx?: IssuesClass) => unknown;
|
|
126
|
+
export declare const unreadCallErrors: (apply: CompactApply, data: unknown, args: ValidatorArgs, onFail?: ArkErrors.Handler | null, Ctx?: IssuesClass) => unknown;
|
|
127
|
+
export declare const emptyMeta: ArkEnv.meta;
|
|
128
|
+
type WrittenIssue = ArkErrors["issues"][number];
|
|
129
|
+
/**
|
|
130
|
+
* The first of `errors.issues`. Errors finding their issues once read find
|
|
131
|
+
* only it, walking their data until it fails.
|
|
132
|
+
*/
|
|
133
|
+
export declare const firstIssue: (errors: ArkErrors) => WrittenIssue;
|
|
134
|
+
export declare const InvalidErrors: new (data: unknown) => ArkErrors;
|
|
135
|
+
export declare const unreadElements: (allows: (data: unknown) => boolean, apply: CompactApply, i: number, data: readonly unknown[], args: ValidatorArgs, onFail?: ArkErrors.Handler | null, Ctx?: IssuesClass) => unknown;
|
|
136
|
+
export type HoleKind = "function" | "class" | "symbol";
|
|
137
|
+
type HoleFact = string | number;
|
|
138
|
+
export declare const factOfHole: (hole: unknown, kind?: HoleKind, classes?: Record<string, unknown>) => HoleFact;
|
|
139
|
+
export declare const describeShape: (value: unknown) => string;
|
|
140
|
+
/**
|
|
141
|
+
* What a plain object or array of primitives holds, as 53 bits: what kind it
|
|
142
|
+
* is, then each own key and its value as Object.is tells it from another. A
|
|
143
|
+
* build writes it for what a site read whole, like an enum's values, in place
|
|
144
|
+
* of each key and value, which would name them all again
|
|
145
|
+
*/
|
|
146
|
+
export declare const digestOf: (value: object) => string;
|
|
147
|
+
export declare const writeDigestMismatchMessage: <label extends string>(label: label) => `${label} holds other keys or values than it was precompiled with`;
|
|
148
|
+
export declare const checkDigest: (value: unknown, expected: string, label?: string) => void;
|
|
149
|
+
export declare const checkFacts: (actual: HoleFact, expected: HoleFact, label?: string) => void;
|
|
150
|
+
export declare const checkArity: (value: unknown, expected: number, label?: string) => void;
|
|
151
|
+
export declare const checkIdentity: (value: unknown, expected: unknown, label?: string, expectedLabel?: string) => void;
|
|
152
|
+
type DefaultKey = [id: string, holes: readonly unknown[]];
|
|
153
|
+
export declare const checkDefault: (validator: Validator, value: unknown, key: PropertyKey | null, defaultKey: DefaultKey) => void;
|
|
154
|
+
export declare const checkInput: (value: unknown, expected: unknown, label?: string) => void;
|
|
155
|
+
export declare const checkProgress: (progress: number | undefined, at: number, name: string) => void;
|
|
156
|
+
export declare const checkFunction: (value: unknown, label?: string) => void;
|
|
157
|
+
export declare const checkHeld: (value: unknown, label?: string, kind?: "Type" | "Module" | "Scope" | "Generic") => void;
|
|
158
|
+
export declare const holdHoles: <value extends object>(value: value, id?: string, holes?: readonly unknown[]) => value;
|
|
159
|
+
export declare const holesOf: (holder: unknown, id: string, label?: string, kind?: "Type" | "Module" | "Scope" | "Generic") => readonly unknown[];
|
|
160
|
+
export declare const receiverOf: (id: string, label?: string, kind?: "Module" | "Scope" | "Generic") => (holder: unknown) => readonly unknown[];
|
|
161
|
+
declare class InternTable {
|
|
162
|
+
value: unknown;
|
|
163
|
+
private readonly tablesByObject;
|
|
164
|
+
private readonly tablesByValue;
|
|
165
|
+
next(hole: unknown): InternTable;
|
|
166
|
+
}
|
|
167
|
+
export declare const internTable: () => InternTable;
|
|
168
|
+
export declare const internedTable: (key: string) => InternTable;
|
|
169
|
+
export declare const intern: <value>(table: InternTable, holes: readonly unknown[], create: () => value, defaults?: readonly DefaultKey[]) => value;
|
|
170
|
+
export declare const internIn: <value>(holder: object, holes: readonly unknown[], create: () => value, defaults?: readonly DefaultKey[]) => value;
|
|
171
|
+
export declare const interned: <value, args extends unknown[]>(key: string, create: (...args: args) => value, ...args: args) => value;
|
|
172
|
+
export declare const checkHelper: (helper: unknown, file: string, name: string, label: string) => void;
|
|
173
|
+
export declare const writeCreationMismatchMessage: <label extends string, actual extends string, expected extends string>(label: label, actual: actual, expected: expected) => writeCreationMismatchMessage<label, actual, expected>;
|
|
174
|
+
export type writeCreationMismatchMessage<label extends string, actual extends string, expected extends string> = `${label} is ${actual}, but was precompiled as ${expected}`;
|
|
175
|
+
export declare const writeIdentityMismatchMessage: <label extends string, expectedLabel extends string>(label: label, expectedLabel: expectedLabel) => writeIdentityMismatchMessage<label, expectedLabel>;
|
|
176
|
+
export type writeIdentityMismatchMessage<label extends string, expectedLabel extends string> = `${label} is not ${expectedLabel}, which it was at build`;
|
|
177
|
+
export declare const bakedJsonSchemaOptionsMessage = "A standalone validator's JSON Schema takes only a target it was built with, and a fallback only where it was built to apply one; set members[\"toJsonSchema\"] true, or build with runtime: \"arktype\"";
|
|
178
|
+
export type bakedJsonSchemaOptionsMessage = typeof bakedJsonSchemaOptionsMessage;
|
|
179
|
+
export declare const writeUnbakedMessage: <reason extends string>(reason: reason) => writeUnbakedMessage<reason>;
|
|
180
|
+
export type writeUnbakedMessage<reason extends string> = `${reason}. Build with runtime: "arktype" to write it where it's read.`;
|
|
181
|
+
export declare const deepFreeze: <t>(value: t) => t;
|
package/out/runtime.js
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { ArkErrors, FirstIssueTraversal, FirstIssues, InternalTraversal, InvalidErrors, ParseError, TransformErrors, Traversal, TraversalError, Validator, addErrors, addMorphErrs, aliasVisits, aliasedMember, aliasedValue, alikeIssue, allowsAcyclic, allowsInBranch, allowsInBranchBy, allowsInContext, allowsOf, allowsReadingCtx, allowsUntracked, appliesValues, applyCallErrors, applyCyclic, applyElements, applyErrors, applyIssues, applyNodeErrors, applyRejected, arrayCheck, arrayIndexMatcher, arrayOf, assign, bakeInto, bakedJsonSchema, bakedJsonSchemaOptionsMessage, bakedStandardJsonSchema, baseNameOf, booleanChecker, callMorph, callingDeferredRootApply, callingRootApply, canParseUrl, check, checkArity, checkDefault, checkDigest, checkFacts, checkFunction, checkHeld, checkHelper, checkIdentity, checkInput, checkProgress, checkerNode, closedProps, codeSiteOf, codedIssue, compiled, computeDefaultValueMorph, configure, configuredFallbackOf, configuredWriterOf, copyDeclared, copyOf, createValidator, createValidatorWith, ctxNode, deepFreeze, deferred, deletingProps, describeCollapsibleDate, describeDomains, describePredicate, describeShape, describeValues, digestOf, disallowed, discriminate, discriminateOr, discriminatesBooleans, divisor, domains, elementsOf, emptyMeta, enInfo, enterApplied, enterResolution, exactLength, execMorph, exitApplied, exitResolution, factOfHole, failingArrayOf, failingBranches, failingClosedProps, failingDeletingProps, failingElementsOf, failingProps, failsAt, failsAtKey, failsAtPath, failsBranches, failsIn, failsInBranches, failsKey, failsKeySite, failsKeyWith, failsListed, failsSite, failsWith, fallbackThrower, firstIssue, fixConfig, fixConfigured, foundErrors, freeze, functionNameOf, holdHoles, holdingAlias, holdsOnlyIndices, holesOf, indexed, integerCheck, integerRange, intern, internIn, internTable, interned, internedTable, intersection, is, isIpv4, isIpv6, isIso8601, isNumericString, isPlainObjectOrArray, isUuid, isValidDate, isWellFormedInteger, jsTypeOfDescriptions, keepOwn, keySiteOf, lessThan, liftArray, listedIssue, matchesRepeated, max, maxLength, mergeTransformed, min, minLength, missingTextOf, moreThan, morphing, narrowed, narrowedAfter, narrowedBy, narrowedByEach, narrowedInCtx, narrowedRejecting, narrowedWithCtx, nullable, nullableDescriptionOf, nullableObject, numberCheck, objectCheck, once, optional, own, ownIssue, pattern, pipe, pipeApplied, pipeChecked, pipeTransformed, piped, pipedIntoUndetailed, precompiledForArktype_3_0_0_beta_1, printKind, printable, props, raisingTraversalOf, readingCtx, readingCtxNode, receiverOf, recordOf, rejected, rejecting, rejects, rejectsWith, rekeyed, replacingUndefined, replayedJsonSchema, required, requiredSiteOf, runtimeConfig, runtimeScope, saying, sayingMissing, setPrototypeOf, silentCtx, siteOf, sited, sitedProps, standardResultOf, stringCheck, stringRange, throwIssues, throwJsonSchemaError, throwOnDefault, throwParseError, throwUnbaked, timeOf, transformIfAllowed, transformOf, transformResolution, transformed, transformedInApply, transformingClosedProps, transformingElementsOf, transformingNarrowedAfter, transformingProps, transformsBranches, transformsValid, tryMorph, type, typedFn, union, unit, units, unnamed, unreadCallErrors, unreadElements, unreadErrors, writeCreationMismatchMessage, writeDigestMismatchMessage, writeDomainActual, writeIdentityMismatchMessage, writeLengthActual, writeMessage, writeNotEqualActual, writeNullableJsonSchema, writeProtoActual, writeUnbakedMessage, writeUnionJsonSchema, writeUnitActual, writeUnitMessage, writtenBy, writtenSiteOf } from "./chunk-5U2ZMDNI.js";
|
|
2
|
+
import "./chunk-G45P2CLE.js";
|
|
3
|
+
export { capitalizeString, emptyCollectionDefaults, epochDescriptions, isEpochString, isJsonString, isLuhnValid, isParsableDate, isParsableUrl, isRegexPattern, keepFormatted, lowercaseString, maxEpoch, normalizationsByForm, parseDate, parseEpoch, parseFormData, parseInteger, parseIsoDate, parseJson, parseNumeric, parseUrl, parsesFinite, raisedErrorPhrases, stringifyJson, trimString, uppercaseString, writeEpoch, writeIsoDate, writeJsonSyntaxErrorMessage, writeUrl } from "./chunk-UK5UGFOX.js";
|
|
4
|
+
import "./chunk-MLKGABMK.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./runtime.ts";
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { ArkErrors, Validator } from "./runtime.js";
|
|
2
|
+
// as @ark/schema's kinds.ts prints the errors arktype returns
|
|
3
|
+
Object.defineProperty(ArkErrors.prototype, Symbol.for("nodejs.util.inspect.custom"), {
|
|
4
|
+
value(depth, options, inspect) {
|
|
5
|
+
const shown = { summary: this.summary, issues: this.issues };
|
|
6
|
+
if (typeof inspect !== "function")
|
|
7
|
+
return shown;
|
|
8
|
+
if (depth !== null && depth < 0)
|
|
9
|
+
return "[ArkErrors]";
|
|
10
|
+
// one level more, so an issue prints as deep as it did in a bare array
|
|
11
|
+
return `ArkErrors ${inspect(shown, { ...options, depth: depth === null ? null : depth + 1 })}`;
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
// a Type's members a validator never has, which a library may read, e.g. `schema.in.toJsonSchema()`
|
|
15
|
+
for (const member of [
|
|
16
|
+
"in",
|
|
17
|
+
"out",
|
|
18
|
+
"encode",
|
|
19
|
+
"and",
|
|
20
|
+
"or",
|
|
21
|
+
"intersect",
|
|
22
|
+
"merge",
|
|
23
|
+
"pipe",
|
|
24
|
+
"to",
|
|
25
|
+
"narrow",
|
|
26
|
+
"filter",
|
|
27
|
+
"array",
|
|
28
|
+
"as",
|
|
29
|
+
"brand",
|
|
30
|
+
"configure",
|
|
31
|
+
"describe",
|
|
32
|
+
"onUndeclaredKey",
|
|
33
|
+
"onDeepUndeclaredKey",
|
|
34
|
+
"keyof",
|
|
35
|
+
"get",
|
|
36
|
+
"map",
|
|
37
|
+
"omit",
|
|
38
|
+
"pick",
|
|
39
|
+
"partial",
|
|
40
|
+
"required",
|
|
41
|
+
"readonly",
|
|
42
|
+
"extract",
|
|
43
|
+
"exclude",
|
|
44
|
+
"atLeastLength",
|
|
45
|
+
"atMostLength",
|
|
46
|
+
"moreThanLength",
|
|
47
|
+
"lessThanLength",
|
|
48
|
+
"exactlyLength",
|
|
49
|
+
"matching",
|
|
50
|
+
"atLeast",
|
|
51
|
+
"atMost",
|
|
52
|
+
"moreThan",
|
|
53
|
+
"lessThan",
|
|
54
|
+
"divisibleBy",
|
|
55
|
+
"atOrAfter",
|
|
56
|
+
"atOrBefore",
|
|
57
|
+
"laterThan",
|
|
58
|
+
"earlierThan",
|
|
59
|
+
"optional",
|
|
60
|
+
"default",
|
|
61
|
+
"ifEquals",
|
|
62
|
+
"ifExtends",
|
|
63
|
+
"equals",
|
|
64
|
+
"extends",
|
|
65
|
+
"overlaps",
|
|
66
|
+
"distribute",
|
|
67
|
+
"select",
|
|
68
|
+
"props",
|
|
69
|
+
"internal",
|
|
70
|
+
"$"
|
|
71
|
+
]) {
|
|
72
|
+
Object.defineProperty(Validator.prototype, member, {
|
|
73
|
+
get: () => {
|
|
74
|
+
throw new Error(`${member} is a Type's, which this standalone validator lacks. Put // @ark-runtime before the definition it's read off, so arktype defines it, or build with runtime: "arktype".`);
|
|
75
|
+
},
|
|
76
|
+
configurable: true
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
// a member a build didn't bake, which reads undefined in production
|
|
80
|
+
const lacks = (member) => new Error(`${member} isn't precompiled: set members["${member}"] true in the precompile options`);
|
|
81
|
+
// one a build bakes is the validator's own, defined over these
|
|
82
|
+
for (const member of [
|
|
83
|
+
"expression",
|
|
84
|
+
"description",
|
|
85
|
+
"json",
|
|
86
|
+
"toJSON",
|
|
87
|
+
"toJsonSchema"
|
|
88
|
+
]) {
|
|
89
|
+
Object.defineProperty(Validator.prototype, member, {
|
|
90
|
+
get: () => {
|
|
91
|
+
throw lacks(member);
|
|
92
|
+
},
|
|
93
|
+
configurable: true
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
// what prints a validator reads its expression, and one without prints as it
|
|
97
|
+
// does in production
|
|
98
|
+
const { toString } = Validator.prototype;
|
|
99
|
+
Validator.prototype.toString = function () {
|
|
100
|
+
try {
|
|
101
|
+
return toString.call(this);
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
return "Type";
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
// a validator is assigned its `~standard` as it's created, which this
|
|
108
|
+
// receives: one with no jsonSchema baked is held as a copy whose jsonSchema
|
|
109
|
+
// throws, frozen if what was assigned is
|
|
110
|
+
Object.defineProperty(Validator.prototype, "~standard", {
|
|
111
|
+
set(standard) {
|
|
112
|
+
let held = standard;
|
|
113
|
+
if (!("jsonSchema" in standard)) {
|
|
114
|
+
held = Object.defineProperty({ ...standard }, "jsonSchema", {
|
|
115
|
+
get: () => {
|
|
116
|
+
throw lacks("~standard.jsonSchema");
|
|
117
|
+
},
|
|
118
|
+
enumerable: true,
|
|
119
|
+
configurable: true
|
|
120
|
+
});
|
|
121
|
+
if (Object.isFrozen(standard))
|
|
122
|
+
Object.freeze(held);
|
|
123
|
+
}
|
|
124
|
+
Object.defineProperty(this, "~standard", {
|
|
125
|
+
value: held,
|
|
126
|
+
writable: true,
|
|
127
|
+
enumerable: true,
|
|
128
|
+
configurable: true
|
|
129
|
+
});
|
|
130
|
+
},
|
|
131
|
+
configurable: true
|
|
132
|
+
});
|
|
133
|
+
export * from "./runtime.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./runtime.ts";
|