flavor-code 1.3.22 → 1.4.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 +437 -434
- package/README.zh-CN.md +434 -431
- package/dist/{app-MWGRT3BJ.js → app-C5ZQUOKJ.js} +37 -63
- package/dist/astgraph/grammars.mjs +68 -68
- package/dist/astgraph/vendor/tree-sitter.js +3980 -3980
- package/dist/astgraph/vendor/zod/LICENSE +21 -21
- package/dist/astgraph/vendor/zod/index.js +4 -4
- package/dist/astgraph/vendor/zod/locales/index.js +1 -1
- package/dist/astgraph/vendor/zod/locales/package.json +7 -7
- package/dist/astgraph/vendor/zod/package.json +135 -135
- package/dist/astgraph/vendor/zod/v4/classic/checks.js +1 -1
- package/dist/astgraph/vendor/zod/v4/classic/coerce.js +17 -17
- package/dist/astgraph/vendor/zod/v4/classic/compat.js +31 -31
- package/dist/astgraph/vendor/zod/v4/classic/errors.js +48 -48
- package/dist/astgraph/vendor/zod/v4/classic/external.js +20 -20
- package/dist/astgraph/vendor/zod/v4/classic/from-json-schema.js +599 -599
- package/dist/astgraph/vendor/zod/v4/classic/index.js +4 -4
- package/dist/astgraph/vendor/zod/v4/classic/iso.js +30 -30
- package/dist/astgraph/vendor/zod/v4/classic/package.json +7 -7
- package/dist/astgraph/vendor/zod/v4/classic/parse.js +15 -15
- package/dist/astgraph/vendor/zod/v4/classic/schemas.js +1395 -1395
- package/dist/astgraph/vendor/zod/v4/core/api.js +1087 -1087
- package/dist/astgraph/vendor/zod/v4/core/checks.js +575 -575
- package/dist/astgraph/vendor/zod/v4/core/core.js +78 -78
- package/dist/astgraph/vendor/zod/v4/core/doc.js +35 -35
- package/dist/astgraph/vendor/zod/v4/core/errors.js +185 -185
- package/dist/astgraph/vendor/zod/v4/core/index.js +16 -16
- package/dist/astgraph/vendor/zod/v4/core/json-schema-generator.js +95 -95
- package/dist/astgraph/vendor/zod/v4/core/json-schema-processors.js +601 -601
- package/dist/astgraph/vendor/zod/v4/core/json-schema.js +1 -1
- package/dist/astgraph/vendor/zod/v4/core/package.json +7 -7
- package/dist/astgraph/vendor/zod/v4/core/parse.js +93 -93
- package/dist/astgraph/vendor/zod/v4/core/regexes.js +139 -139
- package/dist/astgraph/vendor/zod/v4/core/registries.js +51 -51
- package/dist/astgraph/vendor/zod/v4/core/schemas.js +2239 -2239
- package/dist/astgraph/vendor/zod/v4/core/standard-schema.js +1 -1
- package/dist/astgraph/vendor/zod/v4/core/to-json-schema.js +448 -448
- package/dist/astgraph/vendor/zod/v4/core/util.js +674 -674
- package/dist/astgraph/vendor/zod/v4/core/versions.js +5 -5
- package/dist/astgraph/vendor/zod/v4/index.js +3 -3
- package/dist/astgraph/vendor/zod/v4/locales/ar.js +106 -106
- package/dist/astgraph/vendor/zod/v4/locales/az.js +105 -105
- package/dist/astgraph/vendor/zod/v4/locales/be.js +156 -156
- package/dist/astgraph/vendor/zod/v4/locales/bg.js +120 -120
- package/dist/astgraph/vendor/zod/v4/locales/ca.js +107 -107
- package/dist/astgraph/vendor/zod/v4/locales/cs.js +111 -111
- package/dist/astgraph/vendor/zod/v4/locales/da.js +115 -115
- package/dist/astgraph/vendor/zod/v4/locales/de.js +108 -108
- package/dist/astgraph/vendor/zod/v4/locales/el.js +109 -109
- package/dist/astgraph/vendor/zod/v4/locales/en.js +113 -113
- package/dist/astgraph/vendor/zod/v4/locales/eo.js +109 -109
- package/dist/astgraph/vendor/zod/v4/locales/es.js +132 -132
- package/dist/astgraph/vendor/zod/v4/locales/fa.js +114 -114
- package/dist/astgraph/vendor/zod/v4/locales/fi.js +112 -112
- package/dist/astgraph/vendor/zod/v4/locales/fr-CA.js +107 -107
- package/dist/astgraph/vendor/zod/v4/locales/fr.js +125 -125
- package/dist/astgraph/vendor/zod/v4/locales/he.js +214 -214
- package/dist/astgraph/vendor/zod/v4/locales/hr.js +122 -122
- package/dist/astgraph/vendor/zod/v4/locales/hu.js +108 -108
- package/dist/astgraph/vendor/zod/v4/locales/hy.js +147 -147
- package/dist/astgraph/vendor/zod/v4/locales/id.js +106 -106
- package/dist/astgraph/vendor/zod/v4/locales/index.js +52 -52
- package/dist/astgraph/vendor/zod/v4/locales/is.js +109 -109
- package/dist/astgraph/vendor/zod/v4/locales/it.js +108 -108
- package/dist/astgraph/vendor/zod/v4/locales/ja.js +107 -107
- package/dist/astgraph/vendor/zod/v4/locales/ka.js +112 -112
- package/dist/astgraph/vendor/zod/v4/locales/kh.js +5 -5
- package/dist/astgraph/vendor/zod/v4/locales/km.js +110 -110
- package/dist/astgraph/vendor/zod/v4/locales/ko.js +111 -111
- package/dist/astgraph/vendor/zod/v4/locales/lt.js +203 -203
- package/dist/astgraph/vendor/zod/v4/locales/mk.js +109 -109
- package/dist/astgraph/vendor/zod/v4/locales/ms.js +107 -107
- package/dist/astgraph/vendor/zod/v4/locales/nl.js +110 -110
- package/dist/astgraph/vendor/zod/v4/locales/no.js +108 -108
- package/dist/astgraph/vendor/zod/v4/locales/ota.js +109 -109
- package/dist/astgraph/vendor/zod/v4/locales/package.json +7 -7
- package/dist/astgraph/vendor/zod/v4/locales/pl.js +109 -109
- package/dist/astgraph/vendor/zod/v4/locales/ps.js +114 -114
- package/dist/astgraph/vendor/zod/v4/locales/pt.js +108 -108
- package/dist/astgraph/vendor/zod/v4/locales/ro.js +119 -119
- package/dist/astgraph/vendor/zod/v4/locales/ru.js +156 -156
- package/dist/astgraph/vendor/zod/v4/locales/sl.js +109 -109
- package/dist/astgraph/vendor/zod/v4/locales/sv.js +110 -110
- package/dist/astgraph/vendor/zod/v4/locales/ta.js +110 -110
- package/dist/astgraph/vendor/zod/v4/locales/th.js +110 -110
- package/dist/astgraph/vendor/zod/v4/locales/tr.js +105 -105
- package/dist/astgraph/vendor/zod/v4/locales/ua.js +5 -5
- package/dist/astgraph/vendor/zod/v4/locales/uk.js +108 -108
- package/dist/astgraph/vendor/zod/v4/locales/ur.js +110 -110
- package/dist/astgraph/vendor/zod/v4/locales/uz.js +110 -110
- package/dist/astgraph/vendor/zod/v4/locales/vi.js +108 -108
- package/dist/astgraph/vendor/zod/v4/locales/yo.js +107 -107
- package/dist/astgraph/vendor/zod/v4/locales/zh-CN.js +109 -109
- package/dist/astgraph/vendor/zod/v4/locales/zh-TW.js +107 -107
- package/dist/astgraph/vendor/zod/v4/mini/checks.js +1 -1
- package/dist/astgraph/vendor/zod/v4/mini/coerce.js +22 -22
- package/dist/astgraph/vendor/zod/v4/mini/external.js +14 -14
- package/dist/astgraph/vendor/zod/v4/mini/index.js +3 -3
- package/dist/astgraph/vendor/zod/v4/mini/iso.js +34 -34
- package/dist/astgraph/vendor/zod/v4/mini/package.json +7 -7
- package/dist/astgraph/vendor/zod/v4/mini/parse.js +1 -1
- package/dist/astgraph/vendor/zod/v4/mini/schemas.js +961 -961
- package/dist/astgraph/vendor/zod/v4/package.json +7 -7
- package/dist/{chunk-7OICVL2M.js → chunk-2BF7CVWZ.js} +0 -42
- package/dist/{chunk-RQTYHUMK.js → chunk-3WCDZ6ZL.js} +15 -0
- package/dist/{chunk-Z62P4LL7.js → chunk-6MNOZ2TX.js} +8962 -8422
- package/dist/{chunk-VEUSROUQ.js → chunk-FOTMP4ZS.js} +1 -1
- package/dist/{chunk-SUSLIHXO.js → chunk-ODRWR4KK.js} +1 -1
- package/dist/{chunk-RPFWB45Y.js → chunk-URUVFECH.js} +1 -1
- package/dist/{claude-ink-6CEG2XZZ.js → claude-ink-LP32NSX5.js} +2 -3
- package/dist/cli-main.js +27 -11
- package/dist/config/load.d.ts +2 -0
- package/dist/desktop/main.js +1092 -541
- package/dist/desktop-renderer/assets/index-Bk6FYhyh.css +1 -0
- package/dist/desktop-renderer/assets/{index-D75ozXnZ.js → index-CqRIr-hz.js} +3 -3
- package/dist/desktop-renderer/assets/{interactive-terminal-CTFo4fK9.js → interactive-terminal-C4o7MNPO.js} +1 -1
- package/dist/desktop-renderer/index.html +2 -2
- package/dist/doctor.d.ts +38 -0
- package/dist/execution/docker.d.ts +5 -1
- package/dist/execution/types.d.ts +11 -0
- package/dist/jobs/registry.d.ts +1 -0
- package/dist/{load-4FWNXE6F.js → load-V2UIYYQI.js} +1 -1
- package/dist/sdk/index.js +4 -4
- package/dist/tools/shell.d.ts +17 -12
- package/dist/tools/types.d.ts +1 -0
- package/dist/ui/commands.d.ts +1 -1
- package/dist/ui/session.d.ts +1 -0
- package/dist/update/check.d.ts +20 -0
- package/dist/utils/semver.d.ts +3 -0
- package/dist/utils/spawn-executable.d.ts +2 -0
- package/package.json +1 -1
- package//346/212/200/346/234/257/346/226/271/346/241/210/346/212/245/345/221/212.md +5848 -5848
- package/dist/chunk-OTYFL4AG.js +0 -16
- package/dist/desktop-renderer/assets/index-ZZsUx916.css +0 -1
|
@@ -1,78 +1,78 @@
|
|
|
1
|
-
var _a;
|
|
2
|
-
/** A special constant with type `never` */
|
|
3
|
-
export const NEVER = /*@__PURE__*/ Object.freeze({
|
|
4
|
-
status: "aborted",
|
|
5
|
-
});
|
|
6
|
-
export /*@__NO_SIDE_EFFECTS__*/ function $constructor(name, initializer, params) {
|
|
7
|
-
function init(inst, def) {
|
|
8
|
-
if (!inst._zod) {
|
|
9
|
-
Object.defineProperty(inst, "_zod", {
|
|
10
|
-
value: {
|
|
11
|
-
def,
|
|
12
|
-
constr: _,
|
|
13
|
-
traits: new Set(),
|
|
14
|
-
},
|
|
15
|
-
enumerable: false,
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
if (inst._zod.traits.has(name)) {
|
|
19
|
-
return;
|
|
20
|
-
}
|
|
21
|
-
inst._zod.traits.add(name);
|
|
22
|
-
initializer(inst, def);
|
|
23
|
-
// support prototype modifications
|
|
24
|
-
const proto = _.prototype;
|
|
25
|
-
const keys = Object.keys(proto);
|
|
26
|
-
for (let i = 0; i < keys.length; i++) {
|
|
27
|
-
const k = keys[i];
|
|
28
|
-
if (!(k in inst)) {
|
|
29
|
-
inst[k] = proto[k].bind(inst);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
// doesn't work if Parent has a constructor with arguments
|
|
34
|
-
const Parent = params?.Parent ?? Object;
|
|
35
|
-
class Definition extends Parent {
|
|
36
|
-
}
|
|
37
|
-
Object.defineProperty(Definition, "name", { value: name });
|
|
38
|
-
function _(def) {
|
|
39
|
-
var _a;
|
|
40
|
-
const inst = params?.Parent ? new Definition() : this;
|
|
41
|
-
init(inst, def);
|
|
42
|
-
(_a = inst._zod).deferred ?? (_a.deferred = []);
|
|
43
|
-
for (const fn of inst._zod.deferred) {
|
|
44
|
-
fn();
|
|
45
|
-
}
|
|
46
|
-
return inst;
|
|
47
|
-
}
|
|
48
|
-
Object.defineProperty(_, "init", { value: init });
|
|
49
|
-
Object.defineProperty(_, Symbol.hasInstance, {
|
|
50
|
-
value: (inst) => {
|
|
51
|
-
if (params?.Parent && inst instanceof params.Parent)
|
|
52
|
-
return true;
|
|
53
|
-
return inst?._zod?.traits?.has(name);
|
|
54
|
-
},
|
|
55
|
-
});
|
|
56
|
-
Object.defineProperty(_, "name", { value: name });
|
|
57
|
-
return _;
|
|
58
|
-
}
|
|
59
|
-
////////////////////////////// UTILITIES ///////////////////////////////////////
|
|
60
|
-
export const $brand = Symbol("zod_brand");
|
|
61
|
-
export class $ZodAsyncError extends Error {
|
|
62
|
-
constructor() {
|
|
63
|
-
super(`Encountered Promise during synchronous parse. Use .parseAsync() instead.`);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
export class $ZodEncodeError extends Error {
|
|
67
|
-
constructor(name) {
|
|
68
|
-
super(`Encountered unidirectional transform during encode: ${name}`);
|
|
69
|
-
this.name = "ZodEncodeError";
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
(_a = globalThis).__zod_globalConfig ?? (_a.__zod_globalConfig = {});
|
|
73
|
-
export const globalConfig = globalThis.__zod_globalConfig;
|
|
74
|
-
export function config(newConfig) {
|
|
75
|
-
if (newConfig)
|
|
76
|
-
Object.assign(globalConfig, newConfig);
|
|
77
|
-
return globalConfig;
|
|
78
|
-
}
|
|
1
|
+
var _a;
|
|
2
|
+
/** A special constant with type `never` */
|
|
3
|
+
export const NEVER = /*@__PURE__*/ Object.freeze({
|
|
4
|
+
status: "aborted",
|
|
5
|
+
});
|
|
6
|
+
export /*@__NO_SIDE_EFFECTS__*/ function $constructor(name, initializer, params) {
|
|
7
|
+
function init(inst, def) {
|
|
8
|
+
if (!inst._zod) {
|
|
9
|
+
Object.defineProperty(inst, "_zod", {
|
|
10
|
+
value: {
|
|
11
|
+
def,
|
|
12
|
+
constr: _,
|
|
13
|
+
traits: new Set(),
|
|
14
|
+
},
|
|
15
|
+
enumerable: false,
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
if (inst._zod.traits.has(name)) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
inst._zod.traits.add(name);
|
|
22
|
+
initializer(inst, def);
|
|
23
|
+
// support prototype modifications
|
|
24
|
+
const proto = _.prototype;
|
|
25
|
+
const keys = Object.keys(proto);
|
|
26
|
+
for (let i = 0; i < keys.length; i++) {
|
|
27
|
+
const k = keys[i];
|
|
28
|
+
if (!(k in inst)) {
|
|
29
|
+
inst[k] = proto[k].bind(inst);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
// doesn't work if Parent has a constructor with arguments
|
|
34
|
+
const Parent = params?.Parent ?? Object;
|
|
35
|
+
class Definition extends Parent {
|
|
36
|
+
}
|
|
37
|
+
Object.defineProperty(Definition, "name", { value: name });
|
|
38
|
+
function _(def) {
|
|
39
|
+
var _a;
|
|
40
|
+
const inst = params?.Parent ? new Definition() : this;
|
|
41
|
+
init(inst, def);
|
|
42
|
+
(_a = inst._zod).deferred ?? (_a.deferred = []);
|
|
43
|
+
for (const fn of inst._zod.deferred) {
|
|
44
|
+
fn();
|
|
45
|
+
}
|
|
46
|
+
return inst;
|
|
47
|
+
}
|
|
48
|
+
Object.defineProperty(_, "init", { value: init });
|
|
49
|
+
Object.defineProperty(_, Symbol.hasInstance, {
|
|
50
|
+
value: (inst) => {
|
|
51
|
+
if (params?.Parent && inst instanceof params.Parent)
|
|
52
|
+
return true;
|
|
53
|
+
return inst?._zod?.traits?.has(name);
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
Object.defineProperty(_, "name", { value: name });
|
|
57
|
+
return _;
|
|
58
|
+
}
|
|
59
|
+
////////////////////////////// UTILITIES ///////////////////////////////////////
|
|
60
|
+
export const $brand = Symbol("zod_brand");
|
|
61
|
+
export class $ZodAsyncError extends Error {
|
|
62
|
+
constructor() {
|
|
63
|
+
super(`Encountered Promise during synchronous parse. Use .parseAsync() instead.`);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
export class $ZodEncodeError extends Error {
|
|
67
|
+
constructor(name) {
|
|
68
|
+
super(`Encountered unidirectional transform during encode: ${name}`);
|
|
69
|
+
this.name = "ZodEncodeError";
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
(_a = globalThis).__zod_globalConfig ?? (_a.__zod_globalConfig = {});
|
|
73
|
+
export const globalConfig = globalThis.__zod_globalConfig;
|
|
74
|
+
export function config(newConfig) {
|
|
75
|
+
if (newConfig)
|
|
76
|
+
Object.assign(globalConfig, newConfig);
|
|
77
|
+
return globalConfig;
|
|
78
|
+
}
|
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
export class Doc {
|
|
2
|
-
constructor(args = []) {
|
|
3
|
-
this.content = [];
|
|
4
|
-
this.indent = 0;
|
|
5
|
-
if (this)
|
|
6
|
-
this.args = args;
|
|
7
|
-
}
|
|
8
|
-
indented(fn) {
|
|
9
|
-
this.indent += 1;
|
|
10
|
-
fn(this);
|
|
11
|
-
this.indent -= 1;
|
|
12
|
-
}
|
|
13
|
-
write(arg) {
|
|
14
|
-
if (typeof arg === "function") {
|
|
15
|
-
arg(this, { execution: "sync" });
|
|
16
|
-
arg(this, { execution: "async" });
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
const content = arg;
|
|
20
|
-
const lines = content.split("\n").filter((x) => x);
|
|
21
|
-
const minIndent = Math.min(...lines.map((x) => x.length - x.trimStart().length));
|
|
22
|
-
const dedented = lines.map((x) => x.slice(minIndent)).map((x) => " ".repeat(this.indent * 2) + x);
|
|
23
|
-
for (const line of dedented) {
|
|
24
|
-
this.content.push(line);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
compile() {
|
|
28
|
-
const F = Function;
|
|
29
|
-
const args = this?.args;
|
|
30
|
-
const content = this?.content ?? [``];
|
|
31
|
-
const lines = [...content.map((x) => ` ${x}`)];
|
|
32
|
-
// console.log(lines.join("\n"));
|
|
33
|
-
return new F(...args, lines.join("\n"));
|
|
34
|
-
}
|
|
35
|
-
}
|
|
1
|
+
export class Doc {
|
|
2
|
+
constructor(args = []) {
|
|
3
|
+
this.content = [];
|
|
4
|
+
this.indent = 0;
|
|
5
|
+
if (this)
|
|
6
|
+
this.args = args;
|
|
7
|
+
}
|
|
8
|
+
indented(fn) {
|
|
9
|
+
this.indent += 1;
|
|
10
|
+
fn(this);
|
|
11
|
+
this.indent -= 1;
|
|
12
|
+
}
|
|
13
|
+
write(arg) {
|
|
14
|
+
if (typeof arg === "function") {
|
|
15
|
+
arg(this, { execution: "sync" });
|
|
16
|
+
arg(this, { execution: "async" });
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
const content = arg;
|
|
20
|
+
const lines = content.split("\n").filter((x) => x);
|
|
21
|
+
const minIndent = Math.min(...lines.map((x) => x.length - x.trimStart().length));
|
|
22
|
+
const dedented = lines.map((x) => x.slice(minIndent)).map((x) => " ".repeat(this.indent * 2) + x);
|
|
23
|
+
for (const line of dedented) {
|
|
24
|
+
this.content.push(line);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
compile() {
|
|
28
|
+
const F = Function;
|
|
29
|
+
const args = this?.args;
|
|
30
|
+
const content = this?.content ?? [``];
|
|
31
|
+
const lines = [...content.map((x) => ` ${x}`)];
|
|
32
|
+
// console.log(lines.join("\n"));
|
|
33
|
+
return new F(...args, lines.join("\n"));
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -1,185 +1,185 @@
|
|
|
1
|
-
import { $constructor } from "./core.js";
|
|
2
|
-
import * as util from "./util.js";
|
|
3
|
-
const initializer = (inst, def) => {
|
|
4
|
-
inst.name = "$ZodError";
|
|
5
|
-
Object.defineProperty(inst, "_zod", {
|
|
6
|
-
value: inst._zod,
|
|
7
|
-
enumerable: false,
|
|
8
|
-
});
|
|
9
|
-
Object.defineProperty(inst, "issues", {
|
|
10
|
-
value: def,
|
|
11
|
-
enumerable: false,
|
|
12
|
-
});
|
|
13
|
-
inst.message = JSON.stringify(def, util.jsonStringifyReplacer, 2);
|
|
14
|
-
Object.defineProperty(inst, "toString", {
|
|
15
|
-
value: () => inst.message,
|
|
16
|
-
enumerable: false,
|
|
17
|
-
});
|
|
18
|
-
};
|
|
19
|
-
export const $ZodError = $constructor("$ZodError", initializer);
|
|
20
|
-
export const $ZodRealError = $constructor("$ZodError", initializer, { Parent: Error });
|
|
21
|
-
export function flattenError(error, mapper = (issue) => issue.message) {
|
|
22
|
-
const fieldErrors = {};
|
|
23
|
-
const formErrors = [];
|
|
24
|
-
for (const sub of error.issues) {
|
|
25
|
-
if (sub.path.length > 0) {
|
|
26
|
-
fieldErrors[sub.path[0]] = fieldErrors[sub.path[0]] || [];
|
|
27
|
-
fieldErrors[sub.path[0]].push(mapper(sub));
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
30
|
-
formErrors.push(mapper(sub));
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
return { formErrors, fieldErrors };
|
|
34
|
-
}
|
|
35
|
-
export function formatError(error, mapper = (issue) => issue.message) {
|
|
36
|
-
const fieldErrors = { _errors: [] };
|
|
37
|
-
const processError = (error, path = []) => {
|
|
38
|
-
for (const issue of error.issues) {
|
|
39
|
-
if (issue.code === "invalid_union" && issue.errors.length) {
|
|
40
|
-
issue.errors.map((issues) => processError({ issues }, [...path, ...issue.path]));
|
|
41
|
-
}
|
|
42
|
-
else if (issue.code === "invalid_key") {
|
|
43
|
-
processError({ issues: issue.issues }, [...path, ...issue.path]);
|
|
44
|
-
}
|
|
45
|
-
else if (issue.code === "invalid_element") {
|
|
46
|
-
processError({ issues: issue.issues }, [...path, ...issue.path]);
|
|
47
|
-
}
|
|
48
|
-
else {
|
|
49
|
-
const fullpath = [...path, ...issue.path];
|
|
50
|
-
if (fullpath.length === 0) {
|
|
51
|
-
fieldErrors._errors.push(mapper(issue));
|
|
52
|
-
}
|
|
53
|
-
else {
|
|
54
|
-
let curr = fieldErrors;
|
|
55
|
-
let i = 0;
|
|
56
|
-
while (i < fullpath.length) {
|
|
57
|
-
const el = fullpath[i];
|
|
58
|
-
const terminal = i === fullpath.length - 1;
|
|
59
|
-
if (!terminal) {
|
|
60
|
-
curr[el] = curr[el] || { _errors: [] };
|
|
61
|
-
}
|
|
62
|
-
else {
|
|
63
|
-
curr[el] = curr[el] || { _errors: [] };
|
|
64
|
-
curr[el]._errors.push(mapper(issue));
|
|
65
|
-
}
|
|
66
|
-
curr = curr[el];
|
|
67
|
-
i++;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
processError(error);
|
|
74
|
-
return fieldErrors;
|
|
75
|
-
}
|
|
76
|
-
export function treeifyError(error, mapper = (issue) => issue.message) {
|
|
77
|
-
const result = { errors: [] };
|
|
78
|
-
const processError = (error, path = []) => {
|
|
79
|
-
var _a, _b;
|
|
80
|
-
for (const issue of error.issues) {
|
|
81
|
-
if (issue.code === "invalid_union" && issue.errors.length) {
|
|
82
|
-
// regular union error
|
|
83
|
-
issue.errors.map((issues) => processError({ issues }, [...path, ...issue.path]));
|
|
84
|
-
}
|
|
85
|
-
else if (issue.code === "invalid_key") {
|
|
86
|
-
processError({ issues: issue.issues }, [...path, ...issue.path]);
|
|
87
|
-
}
|
|
88
|
-
else if (issue.code === "invalid_element") {
|
|
89
|
-
processError({ issues: issue.issues }, [...path, ...issue.path]);
|
|
90
|
-
}
|
|
91
|
-
else {
|
|
92
|
-
const fullpath = [...path, ...issue.path];
|
|
93
|
-
if (fullpath.length === 0) {
|
|
94
|
-
result.errors.push(mapper(issue));
|
|
95
|
-
continue;
|
|
96
|
-
}
|
|
97
|
-
let curr = result;
|
|
98
|
-
let i = 0;
|
|
99
|
-
while (i < fullpath.length) {
|
|
100
|
-
const el = fullpath[i];
|
|
101
|
-
const terminal = i === fullpath.length - 1;
|
|
102
|
-
if (typeof el === "string") {
|
|
103
|
-
curr.properties ?? (curr.properties = {});
|
|
104
|
-
(_a = curr.properties)[el] ?? (_a[el] = { errors: [] });
|
|
105
|
-
curr = curr.properties[el];
|
|
106
|
-
}
|
|
107
|
-
else {
|
|
108
|
-
curr.items ?? (curr.items = []);
|
|
109
|
-
(_b = curr.items)[el] ?? (_b[el] = { errors: [] });
|
|
110
|
-
curr = curr.items[el];
|
|
111
|
-
}
|
|
112
|
-
if (terminal) {
|
|
113
|
-
curr.errors.push(mapper(issue));
|
|
114
|
-
}
|
|
115
|
-
i++;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
};
|
|
120
|
-
processError(error);
|
|
121
|
-
return result;
|
|
122
|
-
}
|
|
123
|
-
/** Format a ZodError as a human-readable string in the following form.
|
|
124
|
-
*
|
|
125
|
-
* From
|
|
126
|
-
*
|
|
127
|
-
* ```ts
|
|
128
|
-
* ZodError {
|
|
129
|
-
* issues: [
|
|
130
|
-
* {
|
|
131
|
-
* expected: 'string',
|
|
132
|
-
* code: 'invalid_type',
|
|
133
|
-
* path: [ 'username' ],
|
|
134
|
-
* message: 'Invalid input: expected string'
|
|
135
|
-
* },
|
|
136
|
-
* {
|
|
137
|
-
* expected: 'number',
|
|
138
|
-
* code: 'invalid_type',
|
|
139
|
-
* path: [ 'favoriteNumbers', 1 ],
|
|
140
|
-
* message: 'Invalid input: expected number'
|
|
141
|
-
* }
|
|
142
|
-
* ];
|
|
143
|
-
* }
|
|
144
|
-
* ```
|
|
145
|
-
*
|
|
146
|
-
* to
|
|
147
|
-
*
|
|
148
|
-
* ```
|
|
149
|
-
* username
|
|
150
|
-
* ✖ Expected number, received string at "username
|
|
151
|
-
* favoriteNumbers[0]
|
|
152
|
-
* ✖ Invalid input: expected number
|
|
153
|
-
* ```
|
|
154
|
-
*/
|
|
155
|
-
export function toDotPath(_path) {
|
|
156
|
-
const segs = [];
|
|
157
|
-
const path = _path.map((seg) => (typeof seg === "object" ? seg.key : seg));
|
|
158
|
-
for (const seg of path) {
|
|
159
|
-
if (typeof seg === "number")
|
|
160
|
-
segs.push(`[${seg}]`);
|
|
161
|
-
else if (typeof seg === "symbol")
|
|
162
|
-
segs.push(`[${JSON.stringify(String(seg))}]`);
|
|
163
|
-
else if (/[^\w$]/.test(seg))
|
|
164
|
-
segs.push(`[${JSON.stringify(seg)}]`);
|
|
165
|
-
else {
|
|
166
|
-
if (segs.length)
|
|
167
|
-
segs.push(".");
|
|
168
|
-
segs.push(seg);
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
return segs.join("");
|
|
172
|
-
}
|
|
173
|
-
export function prettifyError(error) {
|
|
174
|
-
const lines = [];
|
|
175
|
-
// sort by path length
|
|
176
|
-
const issues = [...error.issues].sort((a, b) => (a.path ?? []).length - (b.path ?? []).length);
|
|
177
|
-
// Process each issue
|
|
178
|
-
for (const issue of issues) {
|
|
179
|
-
lines.push(`✖ ${issue.message}`);
|
|
180
|
-
if (issue.path?.length)
|
|
181
|
-
lines.push(` → at ${toDotPath(issue.path)}`);
|
|
182
|
-
}
|
|
183
|
-
// Convert Map to formatted string
|
|
184
|
-
return lines.join("\n");
|
|
185
|
-
}
|
|
1
|
+
import { $constructor } from "./core.js";
|
|
2
|
+
import * as util from "./util.js";
|
|
3
|
+
const initializer = (inst, def) => {
|
|
4
|
+
inst.name = "$ZodError";
|
|
5
|
+
Object.defineProperty(inst, "_zod", {
|
|
6
|
+
value: inst._zod,
|
|
7
|
+
enumerable: false,
|
|
8
|
+
});
|
|
9
|
+
Object.defineProperty(inst, "issues", {
|
|
10
|
+
value: def,
|
|
11
|
+
enumerable: false,
|
|
12
|
+
});
|
|
13
|
+
inst.message = JSON.stringify(def, util.jsonStringifyReplacer, 2);
|
|
14
|
+
Object.defineProperty(inst, "toString", {
|
|
15
|
+
value: () => inst.message,
|
|
16
|
+
enumerable: false,
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
export const $ZodError = $constructor("$ZodError", initializer);
|
|
20
|
+
export const $ZodRealError = $constructor("$ZodError", initializer, { Parent: Error });
|
|
21
|
+
export function flattenError(error, mapper = (issue) => issue.message) {
|
|
22
|
+
const fieldErrors = {};
|
|
23
|
+
const formErrors = [];
|
|
24
|
+
for (const sub of error.issues) {
|
|
25
|
+
if (sub.path.length > 0) {
|
|
26
|
+
fieldErrors[sub.path[0]] = fieldErrors[sub.path[0]] || [];
|
|
27
|
+
fieldErrors[sub.path[0]].push(mapper(sub));
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
formErrors.push(mapper(sub));
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return { formErrors, fieldErrors };
|
|
34
|
+
}
|
|
35
|
+
export function formatError(error, mapper = (issue) => issue.message) {
|
|
36
|
+
const fieldErrors = { _errors: [] };
|
|
37
|
+
const processError = (error, path = []) => {
|
|
38
|
+
for (const issue of error.issues) {
|
|
39
|
+
if (issue.code === "invalid_union" && issue.errors.length) {
|
|
40
|
+
issue.errors.map((issues) => processError({ issues }, [...path, ...issue.path]));
|
|
41
|
+
}
|
|
42
|
+
else if (issue.code === "invalid_key") {
|
|
43
|
+
processError({ issues: issue.issues }, [...path, ...issue.path]);
|
|
44
|
+
}
|
|
45
|
+
else if (issue.code === "invalid_element") {
|
|
46
|
+
processError({ issues: issue.issues }, [...path, ...issue.path]);
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
const fullpath = [...path, ...issue.path];
|
|
50
|
+
if (fullpath.length === 0) {
|
|
51
|
+
fieldErrors._errors.push(mapper(issue));
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
let curr = fieldErrors;
|
|
55
|
+
let i = 0;
|
|
56
|
+
while (i < fullpath.length) {
|
|
57
|
+
const el = fullpath[i];
|
|
58
|
+
const terminal = i === fullpath.length - 1;
|
|
59
|
+
if (!terminal) {
|
|
60
|
+
curr[el] = curr[el] || { _errors: [] };
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
curr[el] = curr[el] || { _errors: [] };
|
|
64
|
+
curr[el]._errors.push(mapper(issue));
|
|
65
|
+
}
|
|
66
|
+
curr = curr[el];
|
|
67
|
+
i++;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
processError(error);
|
|
74
|
+
return fieldErrors;
|
|
75
|
+
}
|
|
76
|
+
export function treeifyError(error, mapper = (issue) => issue.message) {
|
|
77
|
+
const result = { errors: [] };
|
|
78
|
+
const processError = (error, path = []) => {
|
|
79
|
+
var _a, _b;
|
|
80
|
+
for (const issue of error.issues) {
|
|
81
|
+
if (issue.code === "invalid_union" && issue.errors.length) {
|
|
82
|
+
// regular union error
|
|
83
|
+
issue.errors.map((issues) => processError({ issues }, [...path, ...issue.path]));
|
|
84
|
+
}
|
|
85
|
+
else if (issue.code === "invalid_key") {
|
|
86
|
+
processError({ issues: issue.issues }, [...path, ...issue.path]);
|
|
87
|
+
}
|
|
88
|
+
else if (issue.code === "invalid_element") {
|
|
89
|
+
processError({ issues: issue.issues }, [...path, ...issue.path]);
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
const fullpath = [...path, ...issue.path];
|
|
93
|
+
if (fullpath.length === 0) {
|
|
94
|
+
result.errors.push(mapper(issue));
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
let curr = result;
|
|
98
|
+
let i = 0;
|
|
99
|
+
while (i < fullpath.length) {
|
|
100
|
+
const el = fullpath[i];
|
|
101
|
+
const terminal = i === fullpath.length - 1;
|
|
102
|
+
if (typeof el === "string") {
|
|
103
|
+
curr.properties ?? (curr.properties = {});
|
|
104
|
+
(_a = curr.properties)[el] ?? (_a[el] = { errors: [] });
|
|
105
|
+
curr = curr.properties[el];
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
curr.items ?? (curr.items = []);
|
|
109
|
+
(_b = curr.items)[el] ?? (_b[el] = { errors: [] });
|
|
110
|
+
curr = curr.items[el];
|
|
111
|
+
}
|
|
112
|
+
if (terminal) {
|
|
113
|
+
curr.errors.push(mapper(issue));
|
|
114
|
+
}
|
|
115
|
+
i++;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
processError(error);
|
|
121
|
+
return result;
|
|
122
|
+
}
|
|
123
|
+
/** Format a ZodError as a human-readable string in the following form.
|
|
124
|
+
*
|
|
125
|
+
* From
|
|
126
|
+
*
|
|
127
|
+
* ```ts
|
|
128
|
+
* ZodError {
|
|
129
|
+
* issues: [
|
|
130
|
+
* {
|
|
131
|
+
* expected: 'string',
|
|
132
|
+
* code: 'invalid_type',
|
|
133
|
+
* path: [ 'username' ],
|
|
134
|
+
* message: 'Invalid input: expected string'
|
|
135
|
+
* },
|
|
136
|
+
* {
|
|
137
|
+
* expected: 'number',
|
|
138
|
+
* code: 'invalid_type',
|
|
139
|
+
* path: [ 'favoriteNumbers', 1 ],
|
|
140
|
+
* message: 'Invalid input: expected number'
|
|
141
|
+
* }
|
|
142
|
+
* ];
|
|
143
|
+
* }
|
|
144
|
+
* ```
|
|
145
|
+
*
|
|
146
|
+
* to
|
|
147
|
+
*
|
|
148
|
+
* ```
|
|
149
|
+
* username
|
|
150
|
+
* ✖ Expected number, received string at "username
|
|
151
|
+
* favoriteNumbers[0]
|
|
152
|
+
* ✖ Invalid input: expected number
|
|
153
|
+
* ```
|
|
154
|
+
*/
|
|
155
|
+
export function toDotPath(_path) {
|
|
156
|
+
const segs = [];
|
|
157
|
+
const path = _path.map((seg) => (typeof seg === "object" ? seg.key : seg));
|
|
158
|
+
for (const seg of path) {
|
|
159
|
+
if (typeof seg === "number")
|
|
160
|
+
segs.push(`[${seg}]`);
|
|
161
|
+
else if (typeof seg === "symbol")
|
|
162
|
+
segs.push(`[${JSON.stringify(String(seg))}]`);
|
|
163
|
+
else if (/[^\w$]/.test(seg))
|
|
164
|
+
segs.push(`[${JSON.stringify(seg)}]`);
|
|
165
|
+
else {
|
|
166
|
+
if (segs.length)
|
|
167
|
+
segs.push(".");
|
|
168
|
+
segs.push(seg);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
return segs.join("");
|
|
172
|
+
}
|
|
173
|
+
export function prettifyError(error) {
|
|
174
|
+
const lines = [];
|
|
175
|
+
// sort by path length
|
|
176
|
+
const issues = [...error.issues].sort((a, b) => (a.path ?? []).length - (b.path ?? []).length);
|
|
177
|
+
// Process each issue
|
|
178
|
+
for (const issue of issues) {
|
|
179
|
+
lines.push(`✖ ${issue.message}`);
|
|
180
|
+
if (issue.path?.length)
|
|
181
|
+
lines.push(` → at ${toDotPath(issue.path)}`);
|
|
182
|
+
}
|
|
183
|
+
// Convert Map to formatted string
|
|
184
|
+
return lines.join("\n");
|
|
185
|
+
}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
export * from "./core.js";
|
|
2
|
-
export * from "./parse.js";
|
|
3
|
-
export * from "./errors.js";
|
|
4
|
-
export * from "./schemas.js";
|
|
5
|
-
export * from "./checks.js";
|
|
6
|
-
export * from "./versions.js";
|
|
7
|
-
export * as util from "./util.js";
|
|
8
|
-
export * as regexes from "./regexes.js";
|
|
9
|
-
export * as locales from "../locales/index.js";
|
|
10
|
-
export * from "./registries.js";
|
|
11
|
-
export * from "./doc.js";
|
|
12
|
-
export * from "./api.js";
|
|
13
|
-
export * from "./to-json-schema.js";
|
|
14
|
-
export { toJSONSchema } from "./json-schema-processors.js";
|
|
15
|
-
export { JSONSchemaGenerator } from "./json-schema-generator.js";
|
|
16
|
-
export * as JSONSchema from "./json-schema.js";
|
|
1
|
+
export * from "./core.js";
|
|
2
|
+
export * from "./parse.js";
|
|
3
|
+
export * from "./errors.js";
|
|
4
|
+
export * from "./schemas.js";
|
|
5
|
+
export * from "./checks.js";
|
|
6
|
+
export * from "./versions.js";
|
|
7
|
+
export * as util from "./util.js";
|
|
8
|
+
export * as regexes from "./regexes.js";
|
|
9
|
+
export * as locales from "../locales/index.js";
|
|
10
|
+
export * from "./registries.js";
|
|
11
|
+
export * from "./doc.js";
|
|
12
|
+
export * from "./api.js";
|
|
13
|
+
export * from "./to-json-schema.js";
|
|
14
|
+
export { toJSONSchema } from "./json-schema-processors.js";
|
|
15
|
+
export { JSONSchemaGenerator } from "./json-schema-generator.js";
|
|
16
|
+
export * as JSONSchema from "./json-schema.js";
|