arktype 3.0.0-beta.2 → 3.0.0-rc.0
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 +55 -20
- package/out/_internal/regex/quantify.d.ts +17 -1
- package/out/_internal/schema/refinements/range.d.ts +2 -1
- package/out/_internal/schema/roots/domain.d.ts +1 -0
- package/out/_internal/schema/roots/root.d.ts +3 -1
- package/out/_internal/schema/roots/union.d.ts +8 -3
- package/out/_internal/schema/shared/compile.d.ts +2 -0
- package/out/_internal/schema/shared/declare.d.ts +9 -6
- package/out/_internal/schema/shared/errors.d.ts +3 -0
- package/out/_internal/schema/shared/issues.d.ts +5 -1
- package/out/_internal/schema/shared/issuesLean.d.ts +4 -0
- package/out/_internal/schema/shared/issuesNone.d.ts +1 -0
- package/out/_internal/schema/shared/issuesNoneLean.d.ts +1 -0
- package/out/_internal/schema/shared/standardFailure.d.ts +1 -0
- package/out/_internal/schema/shared/toJsonSchema.d.ts +16 -3
- package/out/_internal/schema/shared/transform.d.ts +1 -0
- package/out/_internal/sets/constraint.d.ts +2 -0
- package/out/_internal/sets/fromJsonSchema.d.ts +3 -1
- package/out/_internal/util/registry.d.ts +1 -1
- package/out/attributes.d.ts +12 -8
- package/out/{chunk-QBX4MEQR.js → chunk-3HZC67MT.js} +15 -15
- package/out/{chunk-5TN5JRP7.js → chunk-3KBOPH3J.js} +63 -41
- package/out/{chunk-NIZDOWFU.js → chunk-46PLKNON.js} +2 -2
- package/out/{chunk-7JXN4WJX.js → chunk-4FTHWK63.js} +1 -1
- package/out/{chunk-EA2DNEDI.js → chunk-4HREHNIV.js} +12 -12
- package/out/{chunk-J7CKAEDX.js → chunk-4NZCLVBD.js} +1 -1
- package/out/{chunk-7N3JEHA4.js → chunk-6FMBO47M.js} +1 -1
- package/out/{chunk-W77ROLOT.js → chunk-7TALAWYX.js} +1 -1
- package/out/{chunk-YMYPW3L5.js → chunk-BCYKO54Z.js} +3 -3
- package/out/{chunk-7SVIUP6X.js → chunk-C2JOL5M2.js} +2 -2
- package/out/{chunk-GPNWBJL3.js → chunk-C2V6QPE3.js} +17 -11
- package/out/{chunk-XMEK4I7J.js → chunk-C3B4IFQL.js} +887 -266
- package/out/{chunk-FY4M7GE7.js → chunk-FWRSDUJ2.js} +4 -4
- package/out/chunk-GID3FSQA.js +161 -0
- package/out/{chunk-CGWRW4JZ.js → chunk-K7SLP5D2.js} +4 -4
- package/out/{chunk-KDMHK4KP.js → chunk-KQPSKGUI.js} +2 -2
- package/out/{chunk-KVQCLBJR.js → chunk-KXOC3JEX.js} +241 -66
- package/out/{chunk-CQU7WIIR.js → chunk-KXOSUYRA.js} +6 -6
- package/out/{chunk-5WRZ25AB.js → chunk-MTWKGAGO.js} +4 -4
- package/out/{chunk-OA5Q2JLI.js → chunk-NU73GNCX.js} +8 -4
- package/out/{chunk-ZFB6DQWY.js → chunk-P5W67FQH.js} +6 -11
- package/out/{chunk-A7A6FDBS.js → chunk-PDLTEX6Z.js} +50 -44
- package/out/{chunk-RAM6G3F6.js → chunk-QUS4IAXJ.js} +26 -25
- package/out/{chunk-HA3POWOU.js → chunk-R7WXIH5P.js} +6 -5
- package/out/{chunk-YN3XRJ7H.js → chunk-UJJGG4VQ.js} +1 -1
- package/out/{chunk-NIYAI7AF.js → chunk-US6BWOGJ.js} +3 -3
- package/out/{chunk-JZ4KBCMM.js → chunk-VMMMOO4R.js} +21 -13
- package/out/{chunk-PIFOURNM.js → chunk-VYMXHSFR.js} +11 -4
- package/out/{chunk-57LF5Y5P.js → chunk-W2XOI5DY.js} +1 -1
- package/out/{chunk-SGFGLENC.js → chunk-WC5L5YRP.js} +3 -3
- package/out/{chunk-V4TZHFNK.js → chunk-WKOSL2G6.js} +1 -1
- package/out/{chunk-UH6XKS3C.js → chunk-XNUAQSJ4.js} +30 -9
- package/out/{chunk-C5JGK6GT.js → chunk-ZRYEHGSG.js} +20 -3
- package/out/cli.d.ts +5 -1
- package/out/cli.js +301 -49
- package/out/codecs.d.ts +4 -3
- package/out/codecs.js +18 -18
- package/out/config.js +8 -8
- package/out/declare.d.ts +2 -4
- package/out/errors.js +8 -8
- package/out/fn.d.ts +2 -2
- package/out/fromJsonSchema.d.ts +1 -1
- package/out/generic.d.ts +7 -4
- package/out/i18n.js +5 -5
- package/out/index.js +19 -19
- package/out/internal.js +32 -32
- package/out/island.js +18 -18
- package/out/islandDependency.js +33 -33
- package/out/jsonSchema/infer.d.ts +16 -6
- package/out/jsonSchema/validate.d.ts +16 -4
- package/out/keywords/functions.d.ts +4 -169
- package/out/keywords/keywords.d.ts +1 -1
- package/out/keywords/phrases.d.ts +3 -168
- package/out/keywords/ts.js +14 -14
- package/out/locales/de.js +6 -6
- package/out/locales/en.js +15 -15
- package/out/match.d.ts +12 -9
- package/out/mutatesInput.js +14 -14
- package/out/nary.d.ts +219 -193
- package/out/parser/definition.d.ts +2 -2
- package/out/parser/shift/operator/default.d.ts +2 -2
- package/out/parser/tupleExpressions.d.ts +2 -0
- package/out/precompiled.js +11 -11
- package/out/runtime.d.ts +1 -1
- package/out/runtime.js +5 -5
- package/out/schema.js +11 -11
- package/out/schemaInternal.js +29 -17
- package/out/schemaRuntime.js +4 -4
- package/out/schemaRuntimeLean.js +60 -36
- package/out/schemaRuntimeNone.js +52 -31
- package/out/schemaRuntimeNoneLean.js +52 -31
- package/out/type.d.ts +3 -3
- package/out/util.js +14 -11
- package/out/variants/base.d.ts +9 -8
- package/out/variants/object.d.ts +14 -6
- package/package.json +4 -4
- package/skills/arktype/SKILL.md +17 -17
- package/skills/arktype/references/migrating.md +13 -13
- package/skills/arktype/references/precompile.md +4 -4
- package/out/chunk-CSVAPWDE.js +0 -83
package/README.md
CHANGED
|
@@ -1,10 +1,35 @@
|
|
|
1
|
-
<
|
|
2
|
-
<
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="https://arktype.io">
|
|
3
|
+
<img
|
|
4
|
+
src="https://arktype.io/3/image/og.png"
|
|
5
|
+
width="720"
|
|
6
|
+
alt="ArkType — TypeScript's smallest, fastest validator. One prompt away."
|
|
7
|
+
/>
|
|
8
|
+
</a>
|
|
9
|
+
</p>
|
|
3
10
|
|
|
4
11
|
<p align="center">
|
|
5
|
-
<a href="https://arktype.io
|
|
12
|
+
<a href="https://arktype.io/docs/intro/setup"><strong>Docs</strong></a>
|
|
13
|
+
·
|
|
14
|
+
<a href="https://arktype.io/#board">Benchmarks</a>
|
|
15
|
+
·
|
|
16
|
+
<a href="https://arktype.io/docs/precompile">Precompile</a>
|
|
17
|
+
·
|
|
18
|
+
<a href="https://arktype.io/docs/migrating">Migrate from Zod</a>
|
|
19
|
+
·
|
|
20
|
+
<a href="https://arktype.io/playground">Playground</a>
|
|
21
|
+
·
|
|
22
|
+
<a href="https://arktype.io/discord">Discord</a>
|
|
6
23
|
</p>
|
|
7
24
|
|
|
25
|
+
## Quick start
|
|
26
|
+
|
|
27
|
+
```sh
|
|
28
|
+
npm install arktype
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Write definitions in TypeScript's own syntax — inferred 1:1 and validated at runtime. Works with anything that takes [Standard Schema](https://standardschema.dev) (tRPC, Hono, React Hook Form, Drizzle, AI SDK, MCP SDK, and more).
|
|
32
|
+
|
|
8
33
|
```ts
|
|
9
34
|
import { type } from "arktype"
|
|
10
35
|
|
|
@@ -29,30 +54,40 @@ if (out instanceof type.errors) {
|
|
|
29
54
|
}
|
|
30
55
|
```
|
|
31
56
|
|
|
32
|
-
```sh
|
|
33
|
-
npm install arktype
|
|
34
|
-
```
|
|
35
|
-
|
|
36
57
|
## Migrate with one prompt
|
|
37
58
|
|
|
38
|
-
Add the
|
|
59
|
+
1. Add the ArkType [agent skill](https://arktype.io/docs/agents):
|
|
39
60
|
|
|
40
|
-
```sh
|
|
41
|
-
npx skills add arktypeio/arktype
|
|
42
|
-
```
|
|
61
|
+
```sh
|
|
62
|
+
npx skills add arktypeio/arktype
|
|
63
|
+
```
|
|
43
64
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
```
|
|
65
|
+
2. Ask your coding agent:
|
|
66
|
+
|
|
67
|
+
```text
|
|
68
|
+
Migrate this project from Zod to ArkType.
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
See the [migration guide](https://arktype.io/docs/migrating) for Zod, Valibot, TypeBox, Yup, Joi, Effect Schema, and JSON Schema.
|
|
47
72
|
|
|
48
73
|
## Docs
|
|
49
74
|
|
|
50
|
-
- [Get started](https://arktype.io/docs/intro/setup)
|
|
51
|
-
- [
|
|
52
|
-
- [
|
|
53
|
-
- [Migration guide](https://arktype.io/docs/migrating)
|
|
54
|
-
- [With agents](https://arktype.io/docs/agents)
|
|
55
|
-
- [What's new in 3.0](https://arktype.io/docs/blog/3.0) and [upgrading from 2.x](https://arktype.io/docs/upgrading)
|
|
75
|
+
- **[Get started](https://arktype.io/docs/intro/setup)** — installation, editor setup, and your first type
|
|
76
|
+
- **[Precompile](https://arktype.io/docs/precompile)** — compile Types at build time with `@ark/aot`
|
|
77
|
+
- **[Benchmarks](https://arktype.io/#board)** — speed, startup, and bundle size, with methods and rerun commands
|
|
78
|
+
- **[Migration guide](https://arktype.io/docs/migrating)** — from Zod, Valibot, TypeBox, Yup, Joi, Effect Schema, and JSON Schema
|
|
79
|
+
- **[With agents](https://arktype.io/docs/agents)** — the skill and Markdown docs at [arktype.io/llms.txt](https://arktype.io/llms.txt)
|
|
80
|
+
- **[What's new in 3.0](https://arktype.io/docs/blog/3.0)** — release notes and [upgrading from 2.x](https://arktype.io/docs/upgrading)
|
|
81
|
+
|
|
82
|
+
## CLI
|
|
83
|
+
|
|
84
|
+
`arktype` ships the `ark` binary (`init`, `migrate`, `skill`, and `check` / `emit` / `declare` via `@ark/aot`). Inside an installed project, run `pnpm exec ark` (or `npx arktype` everywhere — `ark` on npm is an unrelated package):
|
|
85
|
+
|
|
86
|
+
```sh
|
|
87
|
+
npx arktype init # create ark.json and install the bundled skill
|
|
88
|
+
npx arktype migrate # install the skill and print a migration prompt
|
|
89
|
+
npx arktype check # run @ark/aot --check
|
|
90
|
+
```
|
|
56
91
|
|
|
57
92
|
## Contributions
|
|
58
93
|
|
|
@@ -24,11 +24,25 @@ type parsePossibleRangeString<unscanned extends string> = unscanned extends (`${
|
|
|
24
24
|
max: parseNonNegativeInteger<l>;
|
|
25
25
|
unscanned: skipPossibleQuestionMark<next>;
|
|
26
26
|
}> : null;
|
|
27
|
+
type GreaterDigits = {
|
|
28
|
+
"0": never;
|
|
29
|
+
"1": "0";
|
|
30
|
+
"2": "0" | "1";
|
|
31
|
+
"3": "0" | "1" | "2";
|
|
32
|
+
"4": "0" | "1" | "2" | "3";
|
|
33
|
+
"5": "0" | "1" | "2" | "3" | "4";
|
|
34
|
+
"6": "0" | "1" | "2" | "3" | "4" | "5";
|
|
35
|
+
"7": "0" | "1" | "2" | "3" | "4" | "5" | "6";
|
|
36
|
+
"8": "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7";
|
|
37
|
+
"9": "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8";
|
|
38
|
+
};
|
|
39
|
+
type isGreaterNaturalString<l extends string, r extends string, decided extends boolean | null = null> = l extends `${infer ld extends keyof GreaterDigits}${infer lRest}` ? r extends `${infer rd extends keyof GreaterDigits}${infer rRest}` ? isGreaterNaturalString<lRest, rRest, decided extends boolean ? decided : ld extends rd ? null : rd extends GreaterDigits[ld] ? true : false> : true : r extends "" ? decided extends true ? true : false : false;
|
|
40
|
+
type exceedsMax<min extends number, max extends number | null> = max extends number ? min extends 0 | max ? false : isGreaterNaturalString<`${min}`, `${max}`> : false;
|
|
27
41
|
type parseQuantifier<unscanned extends string, parsed extends ParsedRange> = unscanned extends `${infer range}${parsed["unscanned"]}` ? `{${range}` : never;
|
|
28
42
|
export type parsePossibleRange<s extends State, unscanned extends string, parsed extends ParsedRange | null = parsePossibleRangeString<unscanned>> = parsed extends ParsedRange ? s["root"] extends "" ? s.error<writeUnmatchedQuantifierError<parseQuantifier<unscanned, parsed>>> : [parsed["min"], parsed["max"]] extends ([
|
|
29
43
|
never,
|
|
30
44
|
unknown
|
|
31
|
-
] | [unknown, never]) ? s.error<writeUnnaturalNumberQuantifierError<parseQuantifier<unscanned, parsed>>> :
|
|
45
|
+
] | [unknown, never]) ? s.error<writeUnnaturalNumberQuantifierError<parseQuantifier<unscanned, parsed>>> : exceedsMax<parsed["min"], parsed["max"]> extends true ? s.error<writeMinExceedsMaxQuantifierError<parseQuantifier<unscanned, parsed>>> : s.pushQuantifier<s, parsed["min"], parsed["max"], parsed["unscanned"]> : s.shiftQuantifiable<s, "{", unscanned>;
|
|
32
46
|
export type quantify<pattern extends string, min extends number, max extends number | null> = tryFastPath<pattern, min, max>;
|
|
33
47
|
type tryFastPath<pattern extends string, min extends number, max extends number | null> = max extends 0 ? "" : string extends pattern ? string : [pattern, `${number}`] extends [`${number}`, pattern] ? max extends null ? string : min extends 0 ? "" | `${number}` : `${number}` : min extends 0 ? max extends 1 ? "" | pattern : max extends number ? loopFromZero<pattern, max, "", []> : // max is null, all we can do is append ${string}
|
|
34
48
|
"" | `${pattern}${string}` : loopUntilMin<pattern, min, max, "", []>;
|
|
@@ -40,4 +54,6 @@ export declare const writeUnmatchedQuantifierError: <quantifier extends string>(
|
|
|
40
54
|
export type writeUnmatchedQuantifierError<quantifier extends string> = `Quantifier ${quantifier} requires a preceding token`;
|
|
41
55
|
export declare const writeUnnaturalNumberQuantifierError: <quantifier extends string>(quantifier: quantifier) => writeUnnaturalNumberQuantifierError<quantifier>;
|
|
42
56
|
export type writeUnnaturalNumberQuantifierError<quantifier extends string> = `Quantifier ${quantifier} must use natural numbers`;
|
|
57
|
+
export declare const writeMinExceedsMaxQuantifierError: <quantifier extends string>(quantifier: quantifier) => writeMinExceedsMaxQuantifierError<quantifier>;
|
|
58
|
+
export type writeMinExceedsMaxQuantifierError<quantifier extends string> = `Quantifier ${quantifier} min cannot exceed max`;
|
|
43
59
|
export {};
|
|
@@ -10,6 +10,7 @@ export interface BaseRangeDeclaration extends BaseNodeDeclaration {
|
|
|
10
10
|
}
|
|
11
11
|
export declare abstract class BaseRange<d extends BaseRangeDeclaration> extends InternalPrimitiveConstraint<d> {
|
|
12
12
|
readonly exclusive?: true;
|
|
13
|
+
readonly expression: string;
|
|
13
14
|
constructor(...args: ConstructorParameters<typeof InternalPrimitiveConstraint>);
|
|
14
15
|
sameInner(r: BaseRange<d>): boolean | undefined;
|
|
15
16
|
/** the kind of data its bound applies to: a value, a length or a date */
|
|
@@ -17,7 +18,6 @@ export declare abstract class BaseRange<d extends BaseRangeDeclaration> extends
|
|
|
17
18
|
get comparator(): RelativeComparator;
|
|
18
19
|
/** its rule as a number, a Date's time where it's a Date */
|
|
19
20
|
get numRule(): number;
|
|
20
|
-
readonly expression: string;
|
|
21
21
|
get limitKind(): LimitKind;
|
|
22
22
|
jsCond(js: NodeCompiler, data: string): string;
|
|
23
23
|
get stringLimit(): string;
|
|
@@ -81,6 +81,7 @@ export type NumericallyBoundable = string | number | array;
|
|
|
81
81
|
export type Boundable = NumericallyBoundable | Date;
|
|
82
82
|
export type LengthBoundKind = "minLength" | "maxLength" | "exactLength" | "notEqualLength";
|
|
83
83
|
export declare const writeInvalidLengthBoundMessage: (kind: LengthBoundKind, limit: number) => string;
|
|
84
|
+
export declare const writeInvalidRangeRuleMessage: (kind: RangeKind, limit: unknown) => string;
|
|
84
85
|
export declare const assertLengthRule: (kind: LengthBoundKind, rule: number) => void;
|
|
85
86
|
type OperandKindsByBoundKind = satisfy<Record<RangeKind, BoundOperandKind>, {
|
|
86
87
|
min: "value";
|
|
@@ -39,6 +39,7 @@ export declare class DomainNode extends InternalBasis<Domain.Declaration> {
|
|
|
39
39
|
export declare const Domain: {
|
|
40
40
|
impl: nodeImplementationOf<Domain.Declaration>;
|
|
41
41
|
Node: typeof DomainNode;
|
|
42
|
+
writeInvalidDomainMessage: (actual: unknown) => string;
|
|
42
43
|
writeBadAllowNanMessage: (actual: Exclude<Domain.NonEnumerable, "number">) => string;
|
|
43
44
|
writeBadAllowInfinityMessage: (actual: Exclude<Domain.NonEnumerable, "number">) => string;
|
|
44
45
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { arkKind, inferred, type array } from "../../util/index.js";
|
|
2
2
|
import { type Constraint } from "../constraint.ts";
|
|
3
3
|
import type { nodeOfKind, reducibleKindOf } from "../kinds.ts";
|
|
4
|
-
import { BaseNode, type GettableKeyOrNode, type KeyOrKeyNode, type NodeSelector } from "../node.ts";
|
|
4
|
+
import { BaseNode, type DeepNodeTransformContext, type DeepNodeTransformation, type GettableKeyOrNode, type KeyOrKeyNode, type NodeSelector } from "../node.ts";
|
|
5
5
|
import type { Predicate } from "../predicate.ts";
|
|
6
6
|
import type { Divisor } from "../refinements/divisor.ts";
|
|
7
7
|
import type { ExactLength } from "../refinements/exactLength.ts";
|
|
@@ -69,6 +69,8 @@ out d extends InternalRootDeclaration = InternalRootDeclaration> extends BaseNod
|
|
|
69
69
|
rawArray(): BaseRoot;
|
|
70
70
|
overlaps(r: unknown): boolean;
|
|
71
71
|
extends(r: unknown): boolean;
|
|
72
|
+
/** transforms this root inside an enclosing transform, sharing its cycle state */
|
|
73
|
+
transformWithin(mapper: DeepNodeTransformation, ctx: DeepNodeTransformContext): BaseRoot | null;
|
|
72
74
|
ifExtends(r: unknown): BaseRoot | undefined;
|
|
73
75
|
subsumes(r: unknown): boolean;
|
|
74
76
|
configure(meta: TypeMeta.MappableInput, selector?: NodeSelector): this;
|
|
@@ -84,10 +84,15 @@ export declare class UnionNode extends BaseRoot<Union.Declaration> {
|
|
|
84
84
|
get topMorphs(): array<Morph>;
|
|
85
85
|
get brief(): string;
|
|
86
86
|
/**
|
|
87
|
-
*
|
|
88
|
-
*
|
|
87
|
+
* the discriminant an uncompiled check reads. A Type compiled later checks
|
|
88
|
+
* its first data through its branches, sparing that call discriminating
|
|
89
|
+
* every union on the data's path. A predicate reading ctx is only called for
|
|
90
|
+
* the branch compiled code picks, and a node never compiled checks as
|
|
91
|
+
* compiled code would. This reads no cache: whether something else had
|
|
92
|
+
* already discriminated the union (a binding sizing its references by id,
|
|
93
|
+
* a describe of a miss) would decide which branches' predicates are called
|
|
89
94
|
*/
|
|
90
|
-
private get
|
|
95
|
+
private get uncompiledDisc();
|
|
91
96
|
tAllows(data: unknown, ctx: InternalTraversal | AliasDepth): boolean;
|
|
92
97
|
tApply(data: unknown, ctx: InternalTraversal): void;
|
|
93
98
|
applyMiss(data: unknown, ctx: InternalTraversal, value: unknown): boolean;
|
|
@@ -111,6 +111,8 @@ export declare abstract class NodeCompiler extends CompiledFunction<Fn, [
|
|
|
111
111
|
nameOf(id: NodeId): string;
|
|
112
112
|
prop(key: PropertyKey, optional?: boolean): string;
|
|
113
113
|
serialize(value: unknown): string;
|
|
114
|
+
/** validates that a numeric literal interpolated into generated JS is a number */
|
|
115
|
+
num(n: number): string;
|
|
114
116
|
ref(value: object | symbol): string;
|
|
115
117
|
site(node: BaseNode): string;
|
|
116
118
|
error(node: BaseNode, key?: string, data?: string): string;
|
|
@@ -6,9 +6,6 @@ import type { ArkErrorCode, ArkErrors } from "./errors.ts";
|
|
|
6
6
|
import type { NarrowedAttachments, NodeKind } from "./implement.ts";
|
|
7
7
|
import type { JsonSchema } from "./jsonSchema.ts";
|
|
8
8
|
export interface DefaultArkEnv {
|
|
9
|
-
meta(): {};
|
|
10
|
-
context(): {};
|
|
11
|
-
onFail(errors: ArkErrors): ArkErrors;
|
|
12
9
|
/** the scope strings resolve against, where unknown is arktype's keywords */
|
|
13
10
|
$(): unknown;
|
|
14
11
|
}
|
|
@@ -38,10 +35,16 @@ export interface ArkEnv extends DefaultArkEnv {
|
|
|
38
35
|
prototypes(): never;
|
|
39
36
|
}
|
|
40
37
|
export declare namespace ArkEnv {
|
|
41
|
-
type meta = show<NodeMeta &
|
|
42
|
-
|
|
38
|
+
type meta = show<NodeMeta & (ArkEnv extends {
|
|
39
|
+
meta(...args: never): infer meta;
|
|
40
|
+
} ? meta : {})>;
|
|
41
|
+
type onFail = ArkEnv extends {
|
|
42
|
+
onFail(...args: never): infer result;
|
|
43
|
+
} ? result : ArkErrors;
|
|
43
44
|
/** what a call passes for its narrows and morphs to read as `ctx.context` */
|
|
44
|
-
type context =
|
|
45
|
+
type context = ArkEnv extends {
|
|
46
|
+
context(...args: never): infer context;
|
|
47
|
+
} ? context : {};
|
|
45
48
|
/** classes `.infer` leaves opaque */
|
|
46
49
|
type prototypes = ReturnType<ArkEnv["prototypes"]>;
|
|
47
50
|
}
|
|
@@ -174,7 +174,10 @@ export declare const registerLocaleRenderer: (registered: LocaleRenderer) => voi
|
|
|
174
174
|
/** the default config, once one has resolved */
|
|
175
175
|
export declare let defaultConfig: ResolvedConfig;
|
|
176
176
|
export declare const configureLocale: (locale: ArkSchemaConfig["locale"], base: ResolvedConfig) => Locale.Resolved;
|
|
177
|
+
export declare const writeInvalidLocaleObjectMessage: (locale: unknown) => string;
|
|
177
178
|
export declare const unwrittenError: (error: ArkError, prefix?: array<PropertyKey>, config?: ResolvedConfig) => ArkError;
|
|
179
|
+
/** @internal attaches non-enumerable toJSON to an errors' issues array */
|
|
180
|
+
export declare const serializableErrors: (issues: ArkError[]) => readonly ArkError[];
|
|
178
181
|
/**
|
|
179
182
|
* The first of `errors.issues`, its text written without the rest's.
|
|
180
183
|
*/
|
|
@@ -157,6 +157,10 @@ interface Issues extends ReadIssues {
|
|
|
157
157
|
* A human-readable summary of all errors.
|
|
158
158
|
*/
|
|
159
159
|
readonly summary: string;
|
|
160
|
+
/**
|
|
161
|
+
* The summary in `locale`, or as configured without one.
|
|
162
|
+
*/
|
|
163
|
+
summaryIn(locale?: unknown): string;
|
|
160
164
|
/**
|
|
161
165
|
* Throw a TraversalError based on these errors.
|
|
162
166
|
*/
|
|
@@ -181,7 +185,7 @@ interface Issues extends ReadIssues {
|
|
|
181
185
|
export interface IssueJson {
|
|
182
186
|
code: ArkErrorCode;
|
|
183
187
|
path: (string | number)[];
|
|
184
|
-
expected
|
|
188
|
+
expected?: string;
|
|
185
189
|
message: string;
|
|
186
190
|
errors?: IssueJson[];
|
|
187
191
|
}
|
|
@@ -32,6 +32,10 @@ interface Issues extends ReadIssues {
|
|
|
32
32
|
* A human-readable summary of all errors.
|
|
33
33
|
*/
|
|
34
34
|
readonly summary: string;
|
|
35
|
+
/**
|
|
36
|
+
* The summary in `locale`, or as configured without one.
|
|
37
|
+
*/
|
|
38
|
+
summaryIn(locale?: unknown): string;
|
|
35
39
|
/**
|
|
36
40
|
* Throw a TraversalError based on these errors.
|
|
37
41
|
*/
|
|
@@ -3,6 +3,7 @@ import type { StandardSchemaV1 } from "./standardSchema.ts";
|
|
|
3
3
|
export type SummarizedErrors = {
|
|
4
4
|
readonly issues: StandardSchemaV1.FailureResult["issues"];
|
|
5
5
|
readonly summary: string;
|
|
6
|
+
toJSON?: () => readonly unknown[];
|
|
6
7
|
};
|
|
7
8
|
/**
|
|
8
9
|
* @internal a Standard Schema failure of errors: their issues, and their
|
|
@@ -206,11 +206,24 @@ export declare namespace ToJsonSchema {
|
|
|
206
206
|
* @default true for "openapi-3.0" and "openapi-3.1", otherwise false
|
|
207
207
|
*/
|
|
208
208
|
discriminator?: boolean;
|
|
209
|
+
/**
|
|
210
|
+
* Which side of a morph, defaulted key, `"+": "delete"` object, or
|
|
211
|
+
* `undefined`-allowing property to convert:
|
|
212
|
+
* - omitted (default): converts the Type as written (morphs and
|
|
213
|
+
* required `undefined` branches invoke `fallback`, defaults are
|
|
214
|
+
* written as `default`, and `"+": "delete"` omits `additionalProperties`)
|
|
215
|
+
* - `"in"`: the accepted JSON input (drops `undefined` union branches,
|
|
216
|
+
* converts morphs as their input, keeps defaults, allows keys
|
|
217
|
+
* `"+": "delete"` removes)
|
|
218
|
+
* - `"out"`: the serialized output (converts morphs as their output,
|
|
219
|
+
* applies defaults, writes `additionalProperties: false` for
|
|
220
|
+
* `"+": "delete"`, and drops `undefined` from object property/index
|
|
221
|
+
* values and `required`)
|
|
222
|
+
*/
|
|
223
|
+
io?: "in" | "out";
|
|
209
224
|
fallback?: FallbackOption;
|
|
210
225
|
}
|
|
211
|
-
interface Context extends Required<Omit<Options, "discriminator">>, Pick<Options, "discriminator"> {
|
|
226
|
+
interface Context extends Required<Omit<Options, "discriminator" | "io">>, Pick<Options, "discriminator" | "io"> {
|
|
212
227
|
fallback: HandlerByCode;
|
|
213
|
-
/** set by ~standard.jsonSchema.input to write a Type as it's accepted */
|
|
214
|
-
io?: "in";
|
|
215
228
|
}
|
|
216
229
|
}
|
|
@@ -24,6 +24,7 @@ export declare namespace TransformErrors {
|
|
|
24
24
|
}
|
|
25
25
|
export declare const holdsOnlyIndices: (data: unknown[]) => boolean;
|
|
26
26
|
export declare const copyOf: (data: object) => object;
|
|
27
|
+
export declare const setOwnValue: (out: object, k: PropertyKey, value: unknown) => void;
|
|
27
28
|
export declare const keepOwn: (out: object, data: object, k: Key) => void;
|
|
28
29
|
/**
|
|
29
30
|
* what deleting undeclared keys makes of data other than a plain object, a copy
|
|
@@ -7,6 +7,8 @@ interface ConstraintIntersectionState<kind extends ConstraintGroupKind = Constra
|
|
|
7
7
|
l: BaseConstraint[];
|
|
8
8
|
r: BaseConstraint[];
|
|
9
9
|
roots: BaseRoot[];
|
|
10
|
+
derivedL?: Set<BaseConstraint>;
|
|
11
|
+
derivedR?: Set<BaseConstraint>;
|
|
10
12
|
ctx: IntersectionContext;
|
|
11
13
|
}
|
|
12
14
|
export declare const intersectConstraints: <kind extends ConstraintGroupKind>(s: ConstraintIntersectionState<kind>) => nodeOfKind<RootKind | Extract<kind, "structure">> | Disjoint;
|
|
@@ -9,5 +9,7 @@ export declare const writeInvalidKeywordMessage: (pointer: string, expected: str
|
|
|
9
9
|
export declare const writeUnsupportedKeywordMessage: (pointer: string) => string;
|
|
10
10
|
export declare const writeUnsupportedRefMessage: (ref: string, pointer: string) => string;
|
|
11
11
|
export declare const writeUnresolvableRefMessage: (ref: string) => string;
|
|
12
|
-
export declare const writeNullableWithoutTypeMessage: (pointer: string) => string;
|
|
13
12
|
export declare const writeNonNullableNullMessage: (pointer: string) => string;
|
|
13
|
+
export declare const writeShallowCycleMessage: (ref: string, pointer: string) => string;
|
|
14
|
+
export declare const writeCircularSchemaMessage: (pointer: string) => string;
|
|
15
|
+
export declare const writeMaxDepthMessage: (pointer: string, maxDepth?: number) => string;
|
package/out/attributes.d.ts
CHANGED
|
@@ -12,6 +12,10 @@ export type normalizeLimit<limit> = limit extends DateLiteral<infer source> ? so
|
|
|
12
12
|
export type distill<t, side extends distill.Side> = [
|
|
13
13
|
distilledSidesOf<t>
|
|
14
14
|
] extends [undistilledOn<side>] ? t : _distill<t, side>;
|
|
15
|
+
export type distillEncoded<t> = [
|
|
16
|
+
distilledSidesOf<t>
|
|
17
|
+
] extends [undistilledOn<"in">] ? t : _distill<t, "encoded">;
|
|
18
|
+
type DistillSide = distill.Side | "encoded";
|
|
15
19
|
export declare namespace distill {
|
|
16
20
|
type Side = "in" | "out" | "knownOut";
|
|
17
21
|
type In<t> = distill<t, "in">;
|
|
@@ -34,17 +38,17 @@ type ArrayKey = keyof unknown[] | `${number}`;
|
|
|
34
38
|
type undistilledOn<side extends distill.Side> = Exclude<distill.Side, side> | {
|
|
35
39
|
readonly [k: PropertyKey]: undistilledOn<side>;
|
|
36
40
|
};
|
|
37
|
-
type _distill<t, side extends
|
|
41
|
+
type _distill<t, side extends DistillSide> = t extends undefined ? t : [t] extends [anyOrNever] ? t : unknown extends t ? unknown : t extends {
|
|
38
42
|
readonly [brand]: [infer base, unknown];
|
|
39
|
-
} ? side extends "in" ? base : t : t extends TerminallyInferredObject | Primitive ? t : t extends Function ? t extends (...args: never) => anyOrNever ? t : t extends InferredMorph<infer i, infer o> ? distillIo<i, o, side> : t : t extends Default<infer constraint> ? _distill<constraint, side> : t extends array ? distillArray<t, side> : isSafelyMappable<t> extends true ? distillMappable<t, side> : t;
|
|
40
|
-
type distillMappable<o, side extends
|
|
43
|
+
} ? side extends "in" | "encoded" ? base : t : t extends TerminallyInferredObject | Primitive ? t : t extends Function ? t extends (...args: never) => anyOrNever ? t : t extends InferredMorph<infer i, infer o> ? distillIo<i, o, side> : t : t extends Default<infer constraint> ? _distill<constraint, side> : t extends array ? distillArray<t, side> : isSafelyMappable<t> extends true ? distillMappable<t, side> : t;
|
|
44
|
+
type distillMappable<o, side extends DistillSide> = side extends "in" ? show<{
|
|
41
45
|
[k in keyof o as k extends inferredDefaultKeyOf<o> ? never : k]: _distill<o[k], side>;
|
|
42
46
|
} & {
|
|
43
47
|
[k in inferredDefaultKeyOf<o>]?: _distill<o[k], side>;
|
|
44
48
|
}> : {
|
|
45
49
|
[k in keyof o]: _distill<o[k], side>;
|
|
46
50
|
};
|
|
47
|
-
type distillIo<i, o extends Out, side extends
|
|
51
|
+
type distillIo<i, o extends Out, side extends DistillSide> = side extends "out" ? _distill<o["t"], side> : side extends "in" | "encoded" ? _distill<i, side> : o extends To<infer validatedOut> ? _distill<validatedOut, side> : unknown;
|
|
48
52
|
type unwrapInput<t> = t extends InferredMorph<infer i> ? t extends anyOrNever ? t : i : t;
|
|
49
53
|
type inferredDefaultKeyOf<o> = string extends keyof o ? keyof indexedDefaults<o> : symbol extends keyof o ? keyof indexedDefaults<o> : keyof o extends infer k ? k extends keyof o ? isInferredDefault<o[k]> extends true ? k : never : never : never;
|
|
50
54
|
type indexedDefaults<o> = {
|
|
@@ -53,16 +57,16 @@ type indexedDefaults<o> = {
|
|
|
53
57
|
type isInferredDefault<v> = unwrapInput<v> extends Default<infer t> ? [
|
|
54
58
|
t
|
|
55
59
|
] extends [anyOrNever] ? false : true : false;
|
|
56
|
-
type distillArray<t extends array, side extends
|
|
60
|
+
type distillArray<t extends array, side extends DistillSide> = t[number][] extends t ? alignReadonly<_distill<t[number], side>[], t> : distillNonArraykeys<t, alignReadonly<distillArrayFromPrefix<[...t], side, []>, t>, side>;
|
|
57
61
|
type alignReadonly<result extends unknown[], original extends array> = original extends unknown[] ? result : Readonly<result>;
|
|
58
|
-
type distillNonArraykeys<originalArray extends array, distilledArray, side extends
|
|
62
|
+
type distillNonArraykeys<originalArray extends array, distilledArray, side extends DistillSide> = keyof originalArray extends keyof distilledArray ? distilledArray : distilledArray & _distill<{
|
|
59
63
|
[k in keyof originalArray as k extends keyof distilledArray ? never : k]: originalArray[k];
|
|
60
64
|
}, side>;
|
|
61
|
-
type distillArrayFromPrefix<t extends array, side extends
|
|
65
|
+
type distillArrayFromPrefix<t extends array, side extends DistillSide, prefix extends array> = t extends readonly [infer head, ...infer tail] ? distillArrayFromPrefix<tail, side, [
|
|
62
66
|
side,
|
|
63
67
|
head
|
|
64
68
|
] extends ["in", Default] ? [...prefix, _distill<head, side>?] : [...prefix, _distill<head, side>]> : [...prefix, ...distillArrayFromPostfix<t, side, []>];
|
|
65
|
-
type distillArrayFromPostfix<t extends array, side extends
|
|
69
|
+
type distillArrayFromPostfix<t extends array, side extends DistillSide, postfix extends array> = t extends readonly [...infer init, infer last] ? distillArrayFromPostfix<init, side, [_distill<last, side>, ...postfix]> : [...{
|
|
66
70
|
[i in keyof t]: _distill<t[i], side>;
|
|
67
71
|
}, ...postfix];
|
|
68
72
|
/** Objects we don't want to expand during inference like Date or Promise */
|
|
@@ -188,7 +188,7 @@ var numericStringMatcher = (
|
|
|
188
188
|
// "-0" is excluded by requiring a nonzero digit after "-", not a lookahead,
|
|
189
189
|
// since it's a JSON Schema pattern, which RE2 (e.g. LLM structured outputs)
|
|
190
190
|
// can't read with one
|
|
191
|
-
/^(?:(?:0|[1-9]\d*)(?:\.\d+)?|\.\d+|-(?:[1-9]\d*(?:\.\d+)?|0
|
|
191
|
+
/^(?:(?:0|[1-9]\d*)(?:\.\d+)?|\.\d+|-(?:[1-9]\d*(?:\.\d+)?|0?\.\d*[1-9]\d*))(?:[Ee][+-]?\d+)?$/
|
|
192
192
|
);
|
|
193
193
|
var isDigitCode = (code) => code >= 48 && code <= 57;
|
|
194
194
|
var isNumericString = (s) => {
|
|
@@ -205,7 +205,7 @@ var isNumericString = (s) => {
|
|
|
205
205
|
do
|
|
206
206
|
code = s.charCodeAt(++i);
|
|
207
207
|
while (isDigitCode(code));
|
|
208
|
-
} else if (
|
|
208
|
+
} else if (code !== 46)
|
|
209
209
|
return false;
|
|
210
210
|
if (code === 46) {
|
|
211
211
|
code = s.charCodeAt(++i);
|
|
@@ -366,12 +366,9 @@ var splitByKeys = (o, leftKeys) => {
|
|
|
366
366
|
const l = {};
|
|
367
367
|
const r = {};
|
|
368
368
|
let k;
|
|
369
|
-
for (k in o)
|
|
370
|
-
if (k
|
|
371
|
-
l
|
|
372
|
-
else
|
|
373
|
-
r[k] = o[k];
|
|
374
|
-
}
|
|
369
|
+
for (k in o)
|
|
370
|
+
if (hasOwn(o, k))
|
|
371
|
+
defineValue(hasOwn(leftKeys, k) ? l : r, k, o[k]);
|
|
375
372
|
return [l, r];
|
|
376
373
|
};
|
|
377
374
|
var pick = (o, keys) => splitByKeys(o, keys)[0];
|
|
@@ -400,7 +397,7 @@ var withAlphabetizedKeys = (o) => {
|
|
|
400
397
|
const keys = Object.keys(o).sort();
|
|
401
398
|
const result = {};
|
|
402
399
|
for (let i = 0; i < keys.length; i++)
|
|
403
|
-
result
|
|
400
|
+
defineValue(result, keys[i], o[keys[i]]);
|
|
404
401
|
return result;
|
|
405
402
|
};
|
|
406
403
|
var invert = (t) => flatMorph(t, (k, v) => [v, k]);
|
|
@@ -475,7 +472,7 @@ var objectKindOf = (data) => {
|
|
|
475
472
|
if (prototype === Object.prototype)
|
|
476
473
|
return void 0;
|
|
477
474
|
const constructors = builtinsOf();
|
|
478
|
-
while (prototype?.constructor && (!
|
|
475
|
+
while (prototype?.constructor && (!hasOwn(constructors, prototype.constructor.name) || constructors[prototype.constructor.name]?.prototype !== prototype))
|
|
479
476
|
prototype = Object.getPrototypeOf(prototype);
|
|
480
477
|
const name = prototype?.constructor?.name;
|
|
481
478
|
if (name === void 0 || name === "Object")
|
|
@@ -567,7 +564,7 @@ var typedArrayDescriptions = {
|
|
|
567
564
|
var objectKindDescriptions = /* @__PURE__ */ Object.assign({}, ecmascriptDescriptions, platformDescriptions, typedArrayDescriptions);
|
|
568
565
|
var getBuiltinNameOfConstructor = (ctor) => {
|
|
569
566
|
const constructorName = functionNameOf(Object(ctor)) ?? null;
|
|
570
|
-
return constructorName &&
|
|
567
|
+
return constructorName && hasOwn(builtinConstructors, constructorName) && builtinConstructors[constructorName] === ctor ? constructorName : null;
|
|
571
568
|
};
|
|
572
569
|
var ancestorsOf = (o) => {
|
|
573
570
|
let proto = Object.getPrototypeOf(o);
|
|
@@ -707,9 +704,9 @@ var _serialize = (data, opts, seen) => {
|
|
|
707
704
|
if (toJson)
|
|
708
705
|
return Reflect.apply(toJson, o, []);
|
|
709
706
|
if (typeof o === "function")
|
|
710
|
-
return printableOpts.onFunction(o);
|
|
707
|
+
return opts.onFunction?.(o) ?? printableOpts.onFunction(o);
|
|
711
708
|
if (seen.includes(o))
|
|
712
|
-
return "(cycle)";
|
|
709
|
+
return opts.onCycle?.(o) ?? "(cycle)";
|
|
713
710
|
const nextSeen = [...seen, o];
|
|
714
711
|
if (isArray(o))
|
|
715
712
|
return o.map((item) => _serialize(item, opts, nextSeen));
|
|
@@ -717,12 +714,13 @@ var _serialize = (data, opts, seen) => {
|
|
|
717
714
|
return o.toDateString();
|
|
718
715
|
const result = {};
|
|
719
716
|
for (const [k, v] of ownEntriesOf(o, opts)) {
|
|
720
|
-
|
|
717
|
+
const key = typeof k === "symbol" ? opts.onSymbol?.(k) ?? k.toString() : k;
|
|
718
|
+
defineValue(result, key, _serialize(v, opts, nextSeen));
|
|
721
719
|
}
|
|
722
720
|
return result;
|
|
723
721
|
}
|
|
724
722
|
case "symbol":
|
|
725
|
-
return printableOpts.onSymbol(data);
|
|
723
|
+
return opts.onSymbol?.(data) ?? printableOpts.onSymbol(data);
|
|
726
724
|
case "bigint":
|
|
727
725
|
return opts.onBigInt?.(data) ?? `${data}n`;
|
|
728
726
|
case "undefined":
|
|
@@ -734,6 +732,8 @@ var _serialize = (data, opts, seen) => {
|
|
|
734
732
|
}
|
|
735
733
|
};
|
|
736
734
|
var describeCollapsibleDate = (date) => {
|
|
735
|
+
if (!isValidDate(date))
|
|
736
|
+
return "Invalid Date";
|
|
737
737
|
const year = date.getUTCFullYear();
|
|
738
738
|
const month = date.getUTCMonth();
|
|
739
739
|
const dayOfMonth = date.getUTCDate();
|