arktype 3.0.0-beta.0 → 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 +162 -10
- package/out/attributes.d.ts +4 -2
- package/out/checkers.d.ts +37 -2
- package/out/{chunk-Z4F45ZTE.js → chunk-2U2AWCI3.js} +3 -3
- package/out/{chunk-5NJWD7CO.js → chunk-5U2ZMDNI.js} +215 -140
- package/out/{chunk-KJ3C5GTL.js → chunk-DLWCO4RV.js} +1 -1
- package/out/{chunk-H4VRNKMB.js → chunk-E3DZXEZK.js} +1 -1
- package/out/{chunk-EJZJUYPI.js → chunk-EVCML554.js} +2 -2
- package/out/{chunk-KI2MOYNT.js → chunk-GPNK5353.js} +184 -32
- package/out/{chunk-LUXERINN.js → chunk-RAZ3TXOE.js} +40 -38
- package/out/chunk-SWOOCAHN.js +4 -0
- package/out/{chunk-ARTS74PX.js → chunk-UETB6YE2.js} +1 -1
- package/out/{chunk-JHDPSG5Y.js → chunk-UK5UGFOX.js} +6 -6
- package/out/{chunk-WEPQK3AY.js → chunk-VV6YDN2D.js} +441 -145
- package/out/codecs.js +5 -5
- package/out/config.d.ts +6 -3
- package/out/i18n.d.ts +1 -1
- package/out/i18n.js +1 -1
- package/out/index.d.ts +1 -1
- package/out/index.js +5 -5
- package/out/internal.d.ts +1 -0
- package/out/internal.js +11 -11
- package/out/island.js +2 -2
- package/out/islandDependency.js +11 -11
- package/out/keywords/functions.d.ts +24 -24
- package/out/keywords/keywords.d.ts +2 -2
- package/out/keywords/phrases.d.ts +23 -23
- package/out/keywords/ts.js +2 -2
- package/out/locale.d.ts +1 -1
- package/out/locales/de.js +1 -1
- package/out/locales/en.js +3 -3
- package/out/match.d.ts +5 -3
- package/out/mutatesInput.js +2 -2
- package/out/parser/definition.d.ts +54 -3
- package/out/parser/shift/operand/unenclosed.d.ts +3 -1
- package/out/parser/shift/operand/unresolvable.d.ts +68 -0
- package/out/parser/shift/operator/bounds.d.ts +4 -1
- package/out/runtime.d.ts +34 -25
- package/out/runtime.js +2 -2
- package/out/runtimeDevelopment.js +63 -4
- package/out/scope.d.ts +4 -4
- package/out/standalone/artifact.d.ts +4 -0
- package/out/standalone/baking.d.ts +8 -1
- package/out/standalone/sites.d.ts +6 -3
- package/out/standalone/values.d.ts +2 -0
- package/out/type.d.ts +42 -5
- package/package.json +49 -6
- package/skills/arktype/SKILL.md +211 -92
- package/skills/arktype/references/migrating.md +990 -255
- package/skills/arktype/references/precompile.md +8 -5
- package/out/chunk-EDEN5UWG.js +0 -4
package/out/locales/de.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { de } from "../chunk-
|
|
1
|
+
export { de } from "../chunk-RAZ3TXOE.js";
|
|
2
2
|
import "../chunk-MLKGABMK.js";
|
package/out/locales/en.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { en } from "../chunk-4CUA5XIP.js";
|
|
2
|
-
import "../chunk-
|
|
3
|
-
import "../chunk-
|
|
4
|
-
import "../chunk-
|
|
2
|
+
import "../chunk-E3DZXEZK.js";
|
|
3
|
+
import "../chunk-SWOOCAHN.js";
|
|
4
|
+
import "../chunk-UK5UGFOX.js";
|
|
5
5
|
import "../chunk-MLKGABMK.js";
|
package/out/match.d.ts
CHANGED
|
@@ -2,8 +2,9 @@ import { type ArkErrors, type BaseRoot, type Morph } from "@ark/schema";
|
|
|
2
2
|
import { Callable, type conform, type ErrorMessage, type ErrorType, type isDisjoint, type Key, type numericStringKeyOf, type propValueOf, type show, type unionToTuple } from "@ark/util";
|
|
3
3
|
import type { distill, Out } from "./attributes.ts";
|
|
4
4
|
import type { type } from "./keywords/keywords.ts";
|
|
5
|
+
import type { validateDefinition } from "./parser/definition.ts";
|
|
5
6
|
import type { BaseCompletions } from "./parser/string.ts";
|
|
6
|
-
import type { InternalScope } from "./scope.ts";
|
|
7
|
+
import type { bindThis, InternalScope } from "./scope.ts";
|
|
7
8
|
import type { Inferred } from "./variants/base.ts";
|
|
8
9
|
type MatchParserContext<input = unknown> = {
|
|
9
10
|
cases: Morph[];
|
|
@@ -102,11 +103,12 @@ interface ChainableMatchParser<ctx extends MatchParserContext> {
|
|
|
102
103
|
export type DefaultCaseKeyword = "never" | "assert" | "reject";
|
|
103
104
|
type DefaultCase<ctx extends MatchParserContext = MatchParserContext<any>> = DefaultCaseKeyword | Morph<ctx["input"]>;
|
|
104
105
|
type DefaultMethod<ctx extends MatchParserContext> = <const def extends DefaultCase<ctx>>(def: def) => finalizeMatchParser<ctx, def>;
|
|
106
|
+
type validateCase<def, ctx extends MatchParserContext> = validateDefinition<def, ctx["$"], bindThis<def>>;
|
|
105
107
|
type validateCases<cases, ctx extends MatchParserContext> = {
|
|
106
|
-
[def in keyof cases]?: def extends "default" ? DefaultCase<ctx> : def extends number ? (In: inferCaseArg<`${def}`, ctx, "out">) => unknown : def extends
|
|
108
|
+
[def in keyof cases]?: def extends "default" ? DefaultCase<ctx> : def extends number ? (In: inferCaseArg<`${def}`, ctx, "out">) => unknown : def extends validateCase<def, ctx> ? (In: inferCaseArg<def, ctx, "out">) => unknown : validateCase<def, ctx>;
|
|
107
109
|
};
|
|
108
110
|
type errorCases<cases, ctx extends MatchParserContext> = {
|
|
109
|
-
[def in keyof cases]?: def extends "default" ? DefaultCase<ctx> : def extends number ? (In: inferCaseArg<`${def}`, ctx, "out">) => unknown : def extends
|
|
111
|
+
[def in keyof cases]?: def extends "default" ? DefaultCase<ctx> : def extends number ? (In: inferCaseArg<`${def}`, ctx, "out">) => unknown : def extends validateCase<def, ctx> ? (In: inferCaseArg<def, ctx, "out">) => unknown : ErrorType<validateCase<def, ctx>>;
|
|
110
112
|
} & {
|
|
111
113
|
[k in BaseCompletions<ctx["$"], {}>]?: (In: inferCaseArg<k, ctx, "out">) => unknown;
|
|
112
114
|
} & {
|
package/out/mutatesInput.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import "./chunk-
|
|
2
|
-
import "./chunk-
|
|
1
|
+
import "./chunk-DLWCO4RV.js";
|
|
2
|
+
import "./chunk-UK5UGFOX.js";
|
|
3
3
|
import "./chunk-MLKGABMK.js";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BaseRoot, type BaseParseContext, type StandardSchemaV1 } from "@ark/schema";
|
|
2
|
-
import { type anyOrNever, type array, type ErrorMessage, type Fn, type ifEmptyObjectLiteral, type inferred, type objectKindOrDomainOf, type Primitive } from "@ark/util";
|
|
2
|
+
import { type anyOrNever, type array, type Constructor, type ErrorMessage, type Fn, type ifEmptyObjectLiteral, type inferred, type objectKindOrDomainOf, type Primitive } from "@ark/util";
|
|
3
3
|
import type { Out } from "../attributes.ts";
|
|
4
4
|
import type { type } from "../keywords/keywords.ts";
|
|
5
5
|
import type { InnerParseResult } from "../scope.ts";
|
|
@@ -28,13 +28,64 @@ type isSingleDefinition<def, original = def> = def extends unknown ? [
|
|
|
28
28
|
] extends [def] ? true : false : never;
|
|
29
29
|
type inferStandardSchema<schema extends StandardSchemaV1, i = StandardSchemaV1.InferInput<schema>, o = StandardSchemaV1.InferOutput<schema>> = [i, o] extends [o, i] ? i : (In: i) => Out<o>;
|
|
30
30
|
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>;
|
|
31
|
-
|
|
31
|
+
/**
|
|
32
|
+
* {@link validateDefinition} as the type of a parameter (`type.validate`),
|
|
33
|
+
* written so that completing a string passed directly to `type()` stays fast.
|
|
34
|
+
* Once `def` is resolved it is exactly `validateDefinition<def, $, args>`.
|
|
35
|
+
*
|
|
36
|
+
* To complete a string argument, TypeScript first resolves the call with
|
|
37
|
+
* inference blocked from that string, which it does by inferring from the
|
|
38
|
+
* parameter's type to itself. Wherever that meets the same alias on both sides
|
|
39
|
+
* with `def` among its arguments, it asks for the alias's variance, and the
|
|
40
|
+
* variance of a conditional type is measured by comparing instantiations of it,
|
|
41
|
+
* which recurses into every alias the validator can reach. An editor rebuilds
|
|
42
|
+
* the checker on each edit, so that was paid on every keystroke: 650ms a
|
|
43
|
+
* completion on TypeScript 6 and 200ms on 7, for a call that checks in a few.
|
|
44
|
+
* `completions.test.ts` bounds the instantiations a completion costs. TypeScript
|
|
45
|
+
* 5.1 has no such pass, so nothing changes there.
|
|
46
|
+
*
|
|
47
|
+
* Each part of this is there for that pass:
|
|
48
|
+
*
|
|
49
|
+
* - Two references to one interface are inferred through their type arguments,
|
|
50
|
+
* and variance annotated `in out` is read rather than measured, so nothing
|
|
51
|
+
* behind {@link DefinitionArgument} is visited. Without the annotations a
|
|
52
|
+
* completion still takes 300ms.
|
|
53
|
+
* - The index is deferred while `def` is generic and is `"validated"` once
|
|
54
|
+
* it's resolved. Indexed by the literal, the interface would be replaced by
|
|
55
|
+
* its property where this alias is declared.
|
|
56
|
+
* - That hides the validator from ordinary inference too, which needs two
|
|
57
|
+
* things from it, so they are the false branch, which is never the result:
|
|
58
|
+
* `def` itself, and a mapped type over `keyof def`, through which TypeScript
|
|
59
|
+
* infers what it can of a definition containing a function it has yet to
|
|
60
|
+
* contextually type, like the morph of `["string", "=>", s => s.length]`.
|
|
61
|
+
* - The first check is resolved where this alias is declared, so its
|
|
62
|
+
* instantiations aren't recorded as this alias's. If they were, its own
|
|
63
|
+
* variance would be measured, which compares the validator after all.
|
|
64
|
+
*/
|
|
65
|
+
export type validateDefinitionArgument<def, $, args> = null extends undefined ? validateDefinition<def, $, args> : [def] extends [unknown] ? DefinitionArgument<def, $, args>[def extends unknown ? "validated" : never] : [def] extends [anyOrNever] ? def : {
|
|
66
|
+
[k in keyof def]: validateDefinitionArgument<def[k], $, args>;
|
|
67
|
+
};
|
|
68
|
+
export interface DefinitionArgument<in out def, in out $, in out args> {
|
|
69
|
+
validated: validateDefinition<def, $, args>;
|
|
70
|
+
}
|
|
71
|
+
export type validateInnerDefinition<def, $, args> = def extends TerminalObjectDefinition ? validateTerminalObject<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>>> : def extends Constructor ? ErrorMessage<writeBadDefinitionTypeMessage<"Function">> : validateObjectLiteral<def, $, args>;
|
|
32
72
|
export declare const parseTuple: (def: array, ctx: BaseParseContext) => BaseRoot;
|
|
33
73
|
export type validateTuple<def extends array, $, args> = maybeValidateTupleExpression<def, $, args> extends infer result ? result extends null ? validateTupleLiteral<def, $, args> : result : never;
|
|
34
74
|
export type inferTuple<def extends array, $, args> = def extends TupleExpression ? inferTupleExpression<def, $, args> : inferTupleLiteral<def, $, args>;
|
|
35
75
|
export type TerminalObjectDefinition = type.cast<unknown> | Fn | RegExp | StandardSchemaV1;
|
|
76
|
+
type validateTerminalObject<def> = def extends Constructor ? def extends StandardSchemaV1 ? def : ErrorMessage<writeBadDefinitionTypeMessage<"Function">> : def;
|
|
36
77
|
export type ThunkCast<t = unknown> = () => type.cast<t>;
|
|
37
78
|
type BadDefinitionType = Exclude<Primitive, string>;
|
|
38
79
|
export declare const writeBadDefinitionTypeMessage: <actual extends string>(actual: actual) => writeBadDefinitionTypeMessage<actual>;
|
|
39
|
-
type writeBadDefinitionTypeMessage<actual extends string> = `Type definitions must be strings or objects (was ${actual})`;
|
|
80
|
+
type writeBadDefinitionTypeMessage<actual extends string> = `Type definitions must be strings or objects (was ${actual})${actual extends (keyof badDefinitionHints) ? badDefinitionHints[actual] : ""}`;
|
|
81
|
+
declare const badDefinitionHints: {
|
|
82
|
+
readonly Function: ". Write a class as type.instanceOf(MyClass) or a keyword like Date, and a predicate as .narrow(fn)";
|
|
83
|
+
readonly number: ". Write a literal value in a string, or pass it to type.unit()";
|
|
84
|
+
readonly bigint: ". Write a literal value in a string, or pass it to type.unit()";
|
|
85
|
+
readonly boolean: ". Write a literal value in a string, or pass it to type.unit()";
|
|
86
|
+
readonly null: ". Write a literal value in a string, or pass it to type.unit()";
|
|
87
|
+
readonly undefined: ". Write a literal value in a string, or pass it to type.unit()";
|
|
88
|
+
readonly symbol: ". Write a literal value in a string, or pass it to type.unit()";
|
|
89
|
+
};
|
|
90
|
+
type badDefinitionHints = typeof badDefinitionHints;
|
|
40
91
|
export {};
|
|
@@ -10,6 +10,7 @@ import type { StaticState, s } from "../../reduce/static.ts";
|
|
|
10
10
|
import type { BaseCompletions } from "../../string.ts";
|
|
11
11
|
import { shiftUntilTerminator } from "../tokens.ts";
|
|
12
12
|
import { parseGenericArgs, writeInvalidGenericArgCountMessage, type ParsedArgs } from "./genericArgs.ts";
|
|
13
|
+
import { writeUnresolvableHint } from "./unresolvable.ts";
|
|
13
14
|
export declare const parseUnenclosed: (s: RuntimeState) => void;
|
|
14
15
|
export declare const limitOf: (s: RuntimeState, token: string) => number | undefined;
|
|
15
16
|
export type parseUnenclosed<s extends StaticState, $, args> = shiftUntilTerminator<s["unscanned"]> extends (Scanner.shiftResult<infer token, infer unscanned>) ? tryResolve<s, unscanned, token, $, args> extends s.from<infer s> ? s : never : never;
|
|
@@ -33,7 +34,8 @@ type tryResolveSubmodule<token extends string, resolution, reference extends str
|
|
|
33
34
|
export type unresolvableState<s extends StaticState, token extends string, res, args, submodulePath extends string[]> = [
|
|
34
35
|
token,
|
|
35
36
|
s["unscanned"]
|
|
36
|
-
] extends ["", Scanner.shift<"#", infer unscanned>] ? shiftUntilTerminator<unscanned> extends (Scanner.shiftResult<infer name, string>) ? s.error<writePrefixedPrivateReferenceMessage<name>> : never : validReferenceFromToken<token, res, args, submodulePath> extends never ? s.error<
|
|
37
|
+
] extends ["", Scanner.shift<"#", infer unscanned>] ? shiftUntilTerminator<unscanned> extends (Scanner.shiftResult<infer name, string>) ? s.error<writePrefixedPrivateReferenceMessage<name>> : never : validReferenceFromToken<token, res, args, submodulePath> extends never ? s.error<writeUnresolvableWithHint<qualifiedReference<token, submodulePath>>> : s.completion<`${s["scanned"]}${qualifiedReference<validReferenceFromToken<token, res, args, submodulePath>, submodulePath>}`>;
|
|
38
|
+
type writeUnresolvableWithHint<name extends string> = `${writeUnresolvableMessage<name>}${writeUnresolvableHint<name>}`;
|
|
37
39
|
type qualifiedReference<reference extends string, submodulePath extends string[]> = join<[...submodulePath, reference], ".">;
|
|
38
40
|
type validReferenceFromToken<token extends string, $, args, submodulePath extends string[]> = Extract<submodulePath["length"] extends 0 ? BaseCompletions<$, args> : resolvableReferenceIn<$>, `${token}${string}`>;
|
|
39
41
|
export declare const writeMissingOperandMessage: (s: RuntimeState) => string;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { type BaseScope } from "@ark/schema";
|
|
2
|
+
import { type Dict } from "@ark/util";
|
|
3
|
+
/**
|
|
4
|
+
* What a name from Zod, TypeScript or JSON Schema is written as here. Every key
|
|
5
|
+
* is unresolvable in the default scope, and every value parses in it
|
|
6
|
+
*/
|
|
7
|
+
export declare const foreignAliases: {
|
|
8
|
+
readonly any: "unknown.any";
|
|
9
|
+
readonly void: "undefined";
|
|
10
|
+
readonly String: "string";
|
|
11
|
+
readonly Number: "number";
|
|
12
|
+
readonly Boolean: "boolean";
|
|
13
|
+
readonly BigInt: "bigint";
|
|
14
|
+
readonly Symbol: "symbol";
|
|
15
|
+
readonly Object: "object";
|
|
16
|
+
readonly function: "Function";
|
|
17
|
+
readonly array: "unknown[]";
|
|
18
|
+
readonly str: "string";
|
|
19
|
+
readonly bool: "boolean";
|
|
20
|
+
readonly num: "number";
|
|
21
|
+
readonly int: "number.integer";
|
|
22
|
+
readonly integer: "number.integer";
|
|
23
|
+
readonly float: "number";
|
|
24
|
+
readonly double: "number";
|
|
25
|
+
readonly decimal: "number";
|
|
26
|
+
readonly "number.int": "number.integer";
|
|
27
|
+
readonly "number.float": "number";
|
|
28
|
+
readonly "number.positive": "number > 0";
|
|
29
|
+
readonly "number.negative": "number < 0";
|
|
30
|
+
readonly "number.nonnegative": "number >= 0";
|
|
31
|
+
readonly "string.nonempty": "string > 0";
|
|
32
|
+
readonly date: "Date";
|
|
33
|
+
readonly datetime: "string.date.iso";
|
|
34
|
+
readonly "string.datetime": "string.date.iso";
|
|
35
|
+
readonly timestamp: "number.epoch";
|
|
36
|
+
readonly email: "string.email";
|
|
37
|
+
readonly uuid: "string.uuid";
|
|
38
|
+
readonly guid: "string.uuid";
|
|
39
|
+
readonly "string.guid": "string.uuid";
|
|
40
|
+
readonly url: "string.url";
|
|
41
|
+
readonly uri: "string.url";
|
|
42
|
+
readonly "string.uri": "string.url";
|
|
43
|
+
readonly ip: "string.ip";
|
|
44
|
+
readonly ipv4: "string.ip.v4";
|
|
45
|
+
readonly ipv6: "string.ip.v6";
|
|
46
|
+
readonly "string.ipv4": "string.ip.v4";
|
|
47
|
+
readonly "string.ipv6": "string.ip.v6";
|
|
48
|
+
readonly json: "string.json";
|
|
49
|
+
readonly base64: "string.base64";
|
|
50
|
+
readonly hex: "string.hex";
|
|
51
|
+
readonly regex: "RegExp";
|
|
52
|
+
readonly regexp: "RegExp";
|
|
53
|
+
readonly nan: "number.NaN";
|
|
54
|
+
};
|
|
55
|
+
export type foreignAliases = typeof foreignAliases;
|
|
56
|
+
/**
|
|
57
|
+
* What follows `'name' is unresolvable` in a type error. A name from another
|
|
58
|
+
* library is all it suggests: a lookup costs nothing until a definition fails,
|
|
59
|
+
* and the nearest alias, which the thrown error also suggests, would cost a
|
|
60
|
+
* comparison with every alias in scope
|
|
61
|
+
*/
|
|
62
|
+
export type writeUnresolvableHint<name extends string> = name extends keyof foreignAliases ? `. Did you mean '${foreignAliases[name]}'?` : "";
|
|
63
|
+
/**
|
|
64
|
+
* What follows `'name' is unresolvable` in the thrown error: the definition a
|
|
65
|
+
* name from another library means, else the aliases nearest to it, else the
|
|
66
|
+
* names of the submodule it was read from
|
|
67
|
+
*/
|
|
68
|
+
export declare const writeUnresolvableHint: (name: string, $: BaseScope, args: Dict | undefined) => string;
|
|
@@ -18,8 +18,11 @@ type shiftComparator<start extends ComparatorStartChar, unscanned extends string
|
|
|
18
18
|
export declare const writeIncompatibleRangeMessage: (l: BoundKind, r: BoundKind) => string;
|
|
19
19
|
export declare const getBoundKinds: (comparator: Comparator, limit: number | DateLiteral, root: BaseRoot, boundKind: BoundExpressionKind) => BoundKind[];
|
|
20
20
|
export declare const parseRightBound: (s: RootedRuntimeState, comparator: Comparator) => void;
|
|
21
|
-
export type parseRightBound<s extends StaticState, comparator extends Comparator, $, args> = Scanner.skipWhitespace<s["unscanned"]> extends "" ? s.error<writeMissingRightOperandMessage<comparator>> : parseOperand<s, $, args> extends infer nextState extends StaticState ? nextState["root"] extends (InferredAst<unknown, `${infer limit extends number | DateLiteral}`>) ? s["branches"]["lBound"] extends {} ? comparator extends MaxComparator ? s.reduceRange<s, s["branches"]["lBound"]["limit"], s["branches"]["lBound"]["comparator"], comparator, limit, nextState["unscanned"]> : s.error<writeUnpairableComparatorMessage<comparator>> : s.reduceSingleBound<s, comparator, limit, nextState["unscanned"]> : s.error
|
|
21
|
+
export type parseRightBound<s extends StaticState, comparator extends Comparator, $, args> = Scanner.skipWhitespace<s["unscanned"]> extends "" ? s.error<writeMissingRightOperandMessage<comparator>> : parseOperand<s, $, args> extends infer nextState extends StaticState ? nextState["root"] extends (InferredAst<unknown, `${infer limit extends number | DateLiteral}`>) ? s["branches"]["lBound"] extends {} ? comparator extends MaxComparator ? s.reduceRange<s, s["branches"]["lBound"]["limit"], s["branches"]["lBound"]["comparator"], comparator, limit, nextState["unscanned"]> : s.error<writeUnpairableComparatorMessage<comparator>> : s.reduceSingleBound<s, comparator, limit, nextState["unscanned"]> : s.error<`${writeInvalidLimitMessage<comparator, scannedToken<s["unscanned"], nextState["unscanned"]>, "right">}${[comparator, s["root"]] extends ["<", InferredAst<unknown, "Array">] ? arrayIsNotGenericHint : ""}`> : never;
|
|
22
22
|
type scannedToken<unscanned extends string, nextUnscanned extends string> = Scanner.skipWhitespace<unscanned> extends `${infer token}${nextUnscanned}` ? token : never;
|
|
23
|
+
/** what follows a limit's message where it reads as TypeScript's `Array<T>` */
|
|
24
|
+
export declare const arrayIsNotGenericHint = ". Array isn't generic here: write an array of strings as string[]";
|
|
25
|
+
export type arrayIsNotGenericHint = typeof arrayIsNotGenericHint;
|
|
23
26
|
export declare const writeInvalidLimitMessage: <comparator extends Comparator, limit extends string | number, boundKind extends BoundExpressionKind>(comparator: comparator, limit: limit, boundKind: boundKind) => writeInvalidLimitMessage<comparator, limit, boundKind>;
|
|
24
27
|
export type writeInvalidLimitMessage<comparator extends Comparator, limit extends string | number, boundKind extends BoundExpressionKind> = `Comparator ${boundKind extends "left" ? InvertedComparators[comparator] : comparator} must be ${boundKind extends "left" ? "preceded" : "followed"} by a corresponding literal (was ${limit})`;
|
|
25
28
|
export type BoundExpressionKind = "left" | "right";
|
package/out/runtime.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
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 SiteContext, type Traversal } from "@ark/schema/runtime";
|
|
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
3
|
import { type Fn, type inferred, type JsonStructure } from "@ark/util";
|
|
4
4
|
import { InternalTypedFn } from "./fn.ts";
|
|
5
5
|
import type { introspectionMembers } from "./standalone.ts";
|
|
@@ -8,7 +8,7 @@ import type { DateType } from "./variants/date.ts";
|
|
|
8
8
|
import type { NumberType } from "./variants/number.ts";
|
|
9
9
|
import type { ObjectType } from "./variants/object.ts";
|
|
10
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, computeDefaultValueMorph, configure, configuredFallbackOf, configuredWriterOf, copyDeclared, copyOf, alikeIssue, describeCollapsibleDate, describePredicate, disallowed, discriminatesBooleans, enInfo, enterApplied, enterResolution, execMorph, exitResolution, exitApplied, failsInBranches, FirstIssues, FirstIssueTraversal, fixConfig, foundErrors, fixConfigured, holdsOnlyIndices, keepOwn, InternalTraversal, listedIssue, matchesRepeated, mergeTransformed, pipe, pipeApplied, pipeChecked, pipeTransformed, printKind, rejected, rejects, runtimeConfig, runtimeScope, silentCtx, throwIssues, throwOnDefault, TransformErrors, transformed, transformedInApply, transformIfAllowed, transformResolution, transformsBranches, transformsValid, Traversal, TraversalError, tryMorph, writeDomainActual, writeLengthActual,
|
|
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
12
|
export { baseNameOf, functionNameOf, isIpv4, isIpv6, isIso8601, isNumericString, isPlainObjectOrArray, isUuid, isValidDate, isWellFormedInteger, jsTypeOfDescriptions, liftArray, ParseError, printable, throwParseError, timeOf } from "@ark/util";
|
|
13
13
|
export * from "./checkers.ts";
|
|
14
14
|
export * from "./keywords/functions.ts";
|
|
@@ -22,7 +22,7 @@ export interface ValidatorAttributes {
|
|
|
22
22
|
"~standard"?: Pick<StandardJSONSchemaV1.Props, "jsonSchema">;
|
|
23
23
|
}
|
|
24
24
|
export type IntrospectionMember = (typeof introspectionMembers)[number];
|
|
25
|
-
export declare const
|
|
25
|
+
export declare const precompiledForArktype_3_0_0_beta_1 = true;
|
|
26
26
|
export declare const assign: {
|
|
27
27
|
<T extends {}, U>(target: T, source: U): T & U;
|
|
28
28
|
<T extends {}, U, V>(target: T, source1: U, source2: V): T & U & V;
|
|
@@ -49,16 +49,15 @@ export declare class Validator {
|
|
|
49
49
|
allows: (data: unknown) => boolean;
|
|
50
50
|
assert: (data: unknown, pipedFromCtx?: Traversal) => unknown;
|
|
51
51
|
"~standard": StandardSchemaV1.Props;
|
|
52
|
+
expression: string;
|
|
53
|
+
description: string;
|
|
54
|
+
json: JsonStructure;
|
|
55
|
+
toJSON: () => JsonStructure;
|
|
56
|
+
toJsonSchema: () => JsonSchema;
|
|
52
57
|
traverse(data: unknown, pipedFromCtx?: Traversal): ArkErrors | {} | null | undefined;
|
|
53
58
|
from(input: unknown): unknown;
|
|
54
59
|
toString(): string;
|
|
55
|
-
get expression(): string;
|
|
56
|
-
get description(): string;
|
|
57
|
-
get json(): JsonStructure;
|
|
58
|
-
get toJSON(): () => JsonStructure;
|
|
59
|
-
get toJsonSchema(): () => JsonSchema;
|
|
60
60
|
}
|
|
61
|
-
export declare const lacks: (member: IntrospectionMember) => Error;
|
|
62
61
|
export declare const own: <t extends object>(validator: t, attributes: object) => t;
|
|
63
62
|
export declare const bakeInto: <t>(validator: t, { "~standard": standard, ...attributes }: Omit<ValidatorAttributes, "meta">) => t;
|
|
64
63
|
export declare const standardResultOf: (out: unknown) => StandardSchemaV1.Result<unknown>;
|
|
@@ -104,13 +103,16 @@ export declare const type: {
|
|
|
104
103
|
errors: typeof ArkErrors;
|
|
105
104
|
};
|
|
106
105
|
export declare const canParseUrl: (s: string) => boolean;
|
|
107
|
-
export declare const
|
|
106
|
+
export declare const codeSiteOf: (code: ArkErrorCode, description: string | undefined, message: string) => SiteContext;
|
|
108
107
|
type Writer = string | Fn | undefined;
|
|
109
108
|
export declare const writtenSiteOf: (code: ArkErrorCode, description: string | undefined, context: Record<string, unknown>, writers: readonly Writer[], keeps?: any) => SiteContext;
|
|
110
109
|
export declare const raisingTraversalOf: (Base: typeof Traversal, writtenByCode: Record<string, [writers: readonly Writer[], keeps: number]>) => typeof Traversal;
|
|
111
|
-
export declare const failsAt: (ctx: FailureContext | undefined, site: FailureSite, data: unknown
|
|
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;
|
|
112
114
|
export declare const failsAtPath: (ctx: FailureContext | undefined, site: FailureSite, data: unknown, [k, ...deeper]: PropertyKey[]) => boolean | undefined;
|
|
113
|
-
export declare const failsIn: (ctx: FailureContext | undefined, apply: CompactApply, data: unknown, key: PropertyKey,
|
|
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;
|
|
114
116
|
export declare const ownIssue: (site: FailureSite) => UnionIssueOf;
|
|
115
117
|
export declare const failsListed: (ctx: any, firsts: readonly ArkIssue[], data: unknown, issueOf: UnionIssueOf) => boolean | undefined;
|
|
116
118
|
export declare const failsBranches: (ctx: any, branches: readonly CompactApply[], data: unknown, issueOf: UnionIssueOf) => boolean | undefined;
|
|
@@ -120,13 +122,9 @@ export declare const applyNodeErrors: (node: {
|
|
|
120
122
|
}, data: unknown, config: unknown, onFail: ArkErrors.Handler | null, Ctx: new (data: unknown, config: unknown) => ArkErrors | InternalTraversal) => unknown;
|
|
121
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;
|
|
122
124
|
export declare const applyCallErrors: (apply: CompactApply, data: unknown, args: ValidatorArgs, onFail: ArkErrors.Handler | null, Ctx: new (data: unknown, config: unknown) => ArkErrors | InternalTraversal) => unknown;
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
export declare const UnreadArkErrors: UnreadErrorsOf;
|
|
126
|
-
export declare const unreadErrors: (apply: CompactApply, data: unknown, onFail: ArkErrors.Handler | null, Ctx: UnreadErrorsOf) => unknown;
|
|
127
|
-
export declare const unreadCallErrors: (apply: CompactApply, data: unknown, args: ValidatorArgs, onFail: ArkErrors.Handler | null, Ctx: UnreadErrorsOf) => 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;
|
|
128
127
|
export declare const emptyMeta: ArkEnv.meta;
|
|
129
|
-
export declare const UnreadFirstIssues: UnreadErrorsOf;
|
|
130
128
|
type WrittenIssue = ArkErrors["issues"][number];
|
|
131
129
|
/**
|
|
132
130
|
* The first of `errors.issues`. Errors finding their issues once read find
|
|
@@ -134,22 +132,32 @@ type WrittenIssue = ArkErrors["issues"][number];
|
|
|
134
132
|
*/
|
|
135
133
|
export declare const firstIssue: (errors: ArkErrors) => WrittenIssue;
|
|
136
134
|
export declare const InvalidErrors: new (data: unknown) => ArkErrors;
|
|
137
|
-
export declare const unreadElements: (allows: (data: unknown) => boolean, apply: CompactApply, i: number, data: readonly unknown[], args: ValidatorArgs, onFail
|
|
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;
|
|
138
136
|
export type HoleKind = "function" | "class" | "symbol";
|
|
139
137
|
type HoleFact = string | number;
|
|
140
138
|
export declare const factOfHole: (hole: unknown, kind?: HoleKind, classes?: Record<string, unknown>) => HoleFact;
|
|
141
139
|
export declare const describeShape: (value: unknown) => string;
|
|
142
|
-
|
|
143
|
-
|
|
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;
|
|
144
152
|
type DefaultKey = [id: string, holes: readonly unknown[]];
|
|
145
153
|
export declare const checkDefault: (validator: Validator, value: unknown, key: PropertyKey | null, defaultKey: DefaultKey) => void;
|
|
146
|
-
export declare const checkInput: (value: unknown, expected: unknown, label
|
|
154
|
+
export declare const checkInput: (value: unknown, expected: unknown, label?: string) => void;
|
|
147
155
|
export declare const checkProgress: (progress: number | undefined, at: number, name: string) => void;
|
|
148
|
-
export declare const checkFunction: (value: unknown, label
|
|
156
|
+
export declare const checkFunction: (value: unknown, label?: string) => void;
|
|
149
157
|
export declare const checkHeld: (value: unknown, label?: string, kind?: "Type" | "Module" | "Scope" | "Generic") => void;
|
|
150
158
|
export declare const holdHoles: <value extends object>(value: value, id?: string, holes?: readonly unknown[]) => value;
|
|
151
|
-
export declare const holesOf: (holder: unknown, id: string, label
|
|
152
|
-
export declare const receiverOf: (id: string, label
|
|
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[];
|
|
153
161
|
declare class InternTable {
|
|
154
162
|
value: unknown;
|
|
155
163
|
private readonly tablesByObject;
|
|
@@ -159,6 +167,7 @@ declare class InternTable {
|
|
|
159
167
|
export declare const internTable: () => InternTable;
|
|
160
168
|
export declare const internedTable: (key: string) => InternTable;
|
|
161
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;
|
|
162
171
|
export declare const interned: <value, args extends unknown[]>(key: string, create: (...args: args) => value, ...args: args) => value;
|
|
163
172
|
export declare const checkHelper: (helper: unknown, file: string, name: string, label: string) => void;
|
|
164
173
|
export declare const writeCreationMismatchMessage: <label extends string, actual extends string, expected extends string>(label: label, actual: actual, expected: expected) => writeCreationMismatchMessage<label, actual, expected>;
|
package/out/runtime.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { ArkErrors, FirstIssueTraversal, FirstIssues, InternalTraversal, InvalidErrors, ParseError, TransformErrors, Traversal, TraversalError,
|
|
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
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,
|
|
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
4
|
import "./chunk-MLKGABMK.js";
|
|
@@ -1,9 +1,14 @@
|
|
|
1
|
-
// arktype/runtime under the "development" condition: Node prints issues, and a
|
|
2
|
-
// Type's member a validator never has throws where read
|
|
3
1
|
import { ArkErrors, Validator } from "./runtime.js";
|
|
2
|
+
// as @ark/schema's kinds.ts prints the errors arktype returns
|
|
4
3
|
Object.defineProperty(ArkErrors.prototype, Symbol.for("nodejs.util.inspect.custom"), {
|
|
5
|
-
value() {
|
|
6
|
-
|
|
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 })}`;
|
|
7
12
|
}
|
|
8
13
|
});
|
|
9
14
|
// a Type's members a validator never has, which a library may read, e.g. `schema.in.toJsonSchema()`
|
|
@@ -71,4 +76,58 @@ for (const member of [
|
|
|
71
76
|
configurable: true
|
|
72
77
|
});
|
|
73
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
|
+
});
|
|
74
133
|
export * from "./runtime.js";
|
package/out/scope.d.ts
CHANGED
|
@@ -4,13 +4,13 @@ import type { InferredMorph } from "./attributes.ts";
|
|
|
4
4
|
import type { DeclarationParser } from "./declare.ts";
|
|
5
5
|
import { InternalFnParser, type FnParser } from "./fn.ts";
|
|
6
6
|
import { type Generic, type GenericDeclaration, type GenericParser, type ParameterString, type baseGenericConstraints, type parseGenericParams, type parseValidGenericParams } from "./generic.ts";
|
|
7
|
-
import type { Ark
|
|
7
|
+
import type { Ark } from "./keywords/keywords.ts";
|
|
8
8
|
import { InternalMatchParser, type MatchParser } from "./match.ts";
|
|
9
9
|
import type { BoundModule, Module, Submodule, exportScope, instantiateExport } from "./module.ts";
|
|
10
10
|
import type { NaryIntersectionParser, NaryMergeParser, NaryPipeParser, NaryUnionParser } from "./nary.ts";
|
|
11
11
|
import type { GenericInstantiationAst } from "./parser/ast/generic.ts";
|
|
12
12
|
import type { DefAst, InferredAst } from "./parser/ast/infer.ts";
|
|
13
|
-
import { type inferDefinition } from "./parser/definition.ts";
|
|
13
|
+
import { type inferDefinition, type validateDefinition } from "./parser/definition.ts";
|
|
14
14
|
import type { ParsedOptionalProperty } from "./parser/property.ts";
|
|
15
15
|
import type { BranchOperator } from "./parser/reduce/shared.ts";
|
|
16
16
|
import type { ParsedDefaultableProperty } from "./parser/shift/operator/default.ts";
|
|
@@ -111,11 +111,11 @@ type InferredDefinition = {
|
|
|
111
111
|
};
|
|
112
112
|
export declare namespace scope {
|
|
113
113
|
type validate<def> = {
|
|
114
|
-
[k in keyof def]: k extends noSuggest ? unknown : parseScopeKey<k, def>["params"] extends infer params ? params extends array<GenericParamAst> ? params["length"] extends 0 ? def[k] extends InferredDefinition | PreparsedResolution ? def[k] : k extends (PrivateDeclaration<infer name extends keyof def & string>) ? ErrorType<writeDuplicateAliasError<name>> : validateAlias<k, def[k], bootstrapAliases<def>> : def[k] extends Generic ? ErrorType<writeParameterizedGenericKeyMessage<parseScopeKey<k, def>["name"] & string>> :
|
|
114
|
+
[k in keyof def]: k extends noSuggest ? unknown : parseScopeKey<k, def>["params"] extends infer params ? params extends array<GenericParamAst> ? params["length"] extends 0 ? def[k] extends InferredDefinition | PreparsedResolution ? def[k] : k extends (PrivateDeclaration<infer name extends keyof def & string>) ? ErrorType<writeDuplicateAliasError<name>> : validateAlias<k, def[k], bootstrapAliases<def>> : def[k] extends Generic ? ErrorType<writeParameterizedGenericKeyMessage<parseScopeKey<k, def>["name"] & string>> : validateDefinition<def[k], bootstrapAliases<def>, baseGenericConstraints<params>> : params : never;
|
|
115
115
|
};
|
|
116
116
|
type infer<def> = inferBootstrapped<bootstrapAliases<def>>;
|
|
117
117
|
}
|
|
118
|
-
type validateAlias<k, def, $> = shallowCycleMessageOf<k, def, $> extends infer message extends string ? ErrorMessage<message> :
|
|
118
|
+
type validateAlias<k, def, $> = shallowCycleMessageOf<k, def, $> extends infer message extends string ? ErrorMessage<message> : validateDefinition<def, $, {}>;
|
|
119
119
|
type shallowCycleMessageOf<k, def, $> = def extends string ? aliasNameOf<k> extends infer name extends string ? name extends (shallowClosure<shallowReferencesOf<parseString<def, $, {}>, $>, $>) ? shallowCycleOf<name, parseString<def, $, {}>, $, [name]> extends (infer cycle extends string[]) ? writeShallowCycleErrorMessage<name, cycle> : never : undefined : never : undefined;
|
|
120
120
|
type aliasNameOf<k> = k extends PrivateDeclaration<infer name> ? name : k;
|
|
121
121
|
type aliasAstOf<name, $> = name extends string ? (name extends keyof $ ? $[name] : $[PrivateDeclaration<name> & keyof $]) extends Def<infer def extends string> ? parseString<def, $, {}> : undefined : never;
|
|
@@ -122,6 +122,7 @@ export declare class StandaloneArtifact {
|
|
|
122
122
|
checkFacts(checked: CheckedHole[]): void;
|
|
123
123
|
refuseNameDependence(): void;
|
|
124
124
|
holeNamed(name: string, read?: (fn: Function) => string): unknown;
|
|
125
|
+
labelArg(label: string | undefined, after?: string): string;
|
|
125
126
|
receiveHole(hole: unknown, expression: string, label: string): boolean;
|
|
126
127
|
heldFrom(expression: string): string;
|
|
127
128
|
receiverOf(value: Foldable, id: string, label: string): string;
|
|
@@ -146,6 +147,7 @@ export declare class StandaloneArtifact {
|
|
|
146
147
|
writeFactory(index: number, configured: Configured): string;
|
|
147
148
|
private writeBakedAfter;
|
|
148
149
|
private internTableOf;
|
|
150
|
+
get internsByHolder(): boolean;
|
|
149
151
|
get internsAcrossModules(): boolean;
|
|
150
152
|
private internNameOf;
|
|
151
153
|
private internKeyOf;
|
|
@@ -169,6 +171,7 @@ export declare class StandaloneArtifact {
|
|
|
169
171
|
writeFlatUnit(writing: SharedUnit, refs: string[], links: string[]): string[];
|
|
170
172
|
writeScopedUnit(writing: SharedUnit, refs: string[], links: string[]): [declarations: string[], scope: UnitScope | undefined];
|
|
171
173
|
writeUnitNodes(writing: SharedUnit): string[];
|
|
174
|
+
writeCtxNode(root: BaseRoot, unit: RootUnit): string;
|
|
172
175
|
get writesCheckerNodes(): boolean;
|
|
173
176
|
isCheckerNode(root: BaseRoot, unit: RootUnit): boolean;
|
|
174
177
|
writeTemplateCall(unit: RootUnit, prologue: string[], returned: string[]): string | undefined;
|
|
@@ -239,6 +242,7 @@ export declare class StandaloneArtifact {
|
|
|
239
242
|
readByRuntime(root: BaseRoot): string | undefined;
|
|
240
243
|
declareConst(value: unknown, role: DeclarationRole, expression: string): string;
|
|
241
244
|
shapeOf(node: BaseRoot): string;
|
|
245
|
+
writeFilledShape(node: BaseRoot, shape: string, unit: RootUnit, traversals: string[]): string;
|
|
242
246
|
writeShapeFlags(node: BaseRoot, unit: RootUnit): string;
|
|
243
247
|
writeShape(node: BaseRoot, shape: string, unit: RootUnit, traversals: string[]): string;
|
|
244
248
|
emitRef(value: unknown): string;
|
|
@@ -87,6 +87,7 @@ export interface StandaloneOptions {
|
|
|
87
87
|
holdsIds?: boolean | undefined;
|
|
88
88
|
mutatesInput?: MutatesInput | undefined;
|
|
89
89
|
optimize?: Optimization | undefined;
|
|
90
|
+
strategy?: string | undefined;
|
|
90
91
|
jsonInput?: boolean | undefined;
|
|
91
92
|
hoisted?: boolean | undefined;
|
|
92
93
|
values?: boolean | undefined;
|
|
@@ -95,6 +96,7 @@ export interface StandaloneOptions {
|
|
|
95
96
|
combines?: boolean | undefined;
|
|
96
97
|
shapes?: boolean | undefined;
|
|
97
98
|
called?: boolean | undefined;
|
|
99
|
+
defersIssues?: boolean | undefined;
|
|
98
100
|
/** @internal the chars a site's baked introspection may total */
|
|
99
101
|
bakedLimit?: number | undefined;
|
|
100
102
|
readsAllows?: boolean | undefined;
|
|
@@ -133,6 +135,7 @@ export interface Baking extends ValidatorReads {
|
|
|
133
135
|
jsonInput: boolean;
|
|
134
136
|
hoisted: boolean;
|
|
135
137
|
shortest: boolean;
|
|
138
|
+
strategy: string;
|
|
136
139
|
defers: boolean;
|
|
137
140
|
flattens: boolean;
|
|
138
141
|
combines: boolean;
|
|
@@ -150,6 +153,7 @@ export declare const writeFunction: (baking: Baking, name: string, params: strin
|
|
|
150
153
|
export declare const holdsOnlyMeta: (members: ReadonlySet<ValidatorMember>) => boolean;
|
|
151
154
|
export declare const isCreatedByRuntime: (members: ReadonlySet<ValidatorMember>, baking: Baking) => boolean;
|
|
152
155
|
export declare const writeLazyRead: (name: string, initial: string) => string;
|
|
156
|
+
export declare const internsByHolder: (baking: Baking) => boolean;
|
|
153
157
|
export declare const writeValue: (hoisted: boolean, name: string, expression: string, isPure?: boolean) => string;
|
|
154
158
|
export declare const invalidErrorsOf: (defersIssues: boolean) => string;
|
|
155
159
|
export declare const appliedSignature = "(data, onFail) => ";
|
|
@@ -169,16 +173,19 @@ export interface IssueFeatures {
|
|
|
169
173
|
reportsIndices: boolean;
|
|
170
174
|
bracketsKeys: boolean;
|
|
171
175
|
writesText: boolean;
|
|
176
|
+
callsSiteText: boolean;
|
|
172
177
|
listsUnions: boolean;
|
|
173
178
|
rewritesUnions: boolean;
|
|
174
179
|
traversesUnions: boolean;
|
|
175
|
-
readsKeySites: boolean;
|
|
176
180
|
appliesValues: boolean;
|
|
177
181
|
transformsBranches: boolean;
|
|
178
182
|
failsInBranches: boolean;
|
|
179
183
|
discriminatesBooleans: boolean;
|
|
180
184
|
readsSummary: boolean;
|
|
181
185
|
readsErrors: boolean;
|
|
186
|
+
holdsExpression: boolean;
|
|
187
|
+
namesTraversalError: boolean;
|
|
188
|
+
findsOnRead: boolean;
|
|
182
189
|
}
|
|
183
190
|
export declare const noIssueFeatures: IssueFeatures;
|
|
184
191
|
export interface StandaloneModules {
|