@wirecat/mail-cli 0.0.0-stage → 0.1.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/CHANGELOG.md +50 -0
- package/LICENSE +204 -0
- package/README.md +141 -2
- package/dist/bin/mail.d.ts +3 -0
- package/dist/bin/mail.d.ts.map +1 -0
- package/dist/bin/mail.js +36 -0
- package/dist/bin/mail.js.map +1 -0
- package/dist/bundle/all-profiles-TKMBELRZ.js +286 -0
- package/dist/bundle/anthropic-7LMUAEIZ.js +72 -0
- package/dist/bundle/app-server-JGMIJDD4.js +229 -0
- package/dist/bundle/bun-XRO6XJHQ.js +169 -0
- package/dist/bundle/bun-sqlite-Z54LEHVM.js +71 -0
- package/dist/bundle/chunk-2LLNPNMB.js +24 -0
- package/dist/bundle/chunk-3E3WA2L6.js +1932 -0
- package/dist/bundle/chunk-3KEVLSNN.js +138 -0
- package/dist/bundle/chunk-3KOA73LS.js +3416 -0
- package/dist/bundle/chunk-4E7BN3TC.js +122 -0
- package/dist/bundle/chunk-4FEMINO2.js +409 -0
- package/dist/bundle/chunk-5BVIWP3S.js +71 -0
- package/dist/bundle/chunk-5D4AEUVA.js +24783 -0
- package/dist/bundle/chunk-5NYMNSSO.js +264 -0
- package/dist/bundle/chunk-5WGEUDE4.js +27 -0
- package/dist/bundle/chunk-6MAZWSC3.js +132 -0
- package/dist/bundle/chunk-75CWWETH.js +379 -0
- package/dist/bundle/chunk-7SXGLT6T.js +444 -0
- package/dist/bundle/chunk-BTQX2ZSZ.js +288 -0
- package/dist/bundle/chunk-CEW6KIFA.js +1193 -0
- package/dist/bundle/chunk-CH6RXYAX.js +82 -0
- package/dist/bundle/chunk-D72URWJE.js +532 -0
- package/dist/bundle/chunk-DFDN6AUB.js +21 -0
- package/dist/bundle/chunk-EOEDICIE.js +6848 -0
- package/dist/bundle/chunk-F6D6PJ34.js +100 -0
- package/dist/bundle/chunk-FDCGTODC.js +78 -0
- package/dist/bundle/chunk-FZ5FXIG6.js +18 -0
- package/dist/bundle/chunk-GAH7N7HO.js +8181 -0
- package/dist/bundle/chunk-GK4M2SUP.js +195 -0
- package/dist/bundle/chunk-GN62YOT5.js +161 -0
- package/dist/bundle/chunk-GQQJOH7A.js +7050 -0
- package/dist/bundle/chunk-GWDCKUBI.js +781 -0
- package/dist/bundle/chunk-HTQTIKWP.js +928 -0
- package/dist/bundle/chunk-IK5TH3O7.js +217 -0
- package/dist/bundle/chunk-J3QXTBD2.js +2742 -0
- package/dist/bundle/chunk-J6MSJLIW.js +45 -0
- package/dist/bundle/chunk-JBBZCTTF.js +76 -0
- package/dist/bundle/chunk-JVMVLITS.js +260 -0
- package/dist/bundle/chunk-K4FVKPDQ.js +525 -0
- package/dist/bundle/chunk-KHTO2Q6E.js +886 -0
- package/dist/bundle/chunk-KM7Q67Z3.js +63 -0
- package/dist/bundle/chunk-LQ37ALDJ.js +2416 -0
- package/dist/bundle/chunk-MNOIRJEO.js +2315 -0
- package/dist/bundle/chunk-MS53RALV.js +168 -0
- package/dist/bundle/chunk-NK7EB63L.js +36225 -0
- package/dist/bundle/chunk-NPGVOZVK.js +2 -0
- package/dist/bundle/chunk-OTUOZ33L.js +82 -0
- package/dist/bundle/chunk-P7P5MNAU.js +46 -0
- package/dist/bundle/chunk-QLEUNU6G.js +537 -0
- package/dist/bundle/chunk-QQB7WT7R.js +216 -0
- package/dist/bundle/chunk-QX7RCLRS.js +23 -0
- package/dist/bundle/chunk-T6464KYA.js +35130 -0
- package/dist/bundle/chunk-TE5U5OAM.js +73 -0
- package/dist/bundle/chunk-TI6VBZKJ.js +166 -0
- package/dist/bundle/chunk-TQFCPUIM.js +53 -0
- package/dist/bundle/chunk-TVREDYX4.js +3574 -0
- package/dist/bundle/chunk-TWPDVUBR.js +106 -0
- package/dist/bundle/chunk-TWTATDM7.js +461 -0
- package/dist/bundle/chunk-UH4DDRHA.js +2989 -0
- package/dist/bundle/chunk-VEIZZRQ5.js +630 -0
- package/dist/bundle/chunk-WLFLBWNH.js +54 -0
- package/dist/bundle/chunk-WXAXYJJ7.js +486 -0
- package/dist/bundle/chunk-XQUUANA2.js +24600 -0
- package/dist/bundle/chunk-Y5E2WNWB.js +35 -0
- package/dist/bundle/chunk-YO4CUH5E.js +33 -0
- package/dist/bundle/chunk-YPQQ5J4X.js +849 -0
- package/dist/bundle/chunk-Z34ICZA3.js +1028 -0
- package/dist/bundle/chunk-ZANYM66S.js +58 -0
- package/dist/bundle/chunk-ZD3WUGR2.js +142 -0
- package/dist/bundle/chunk-ZVVMGPBJ.js +50 -0
- package/dist/bundle/command-contract-WU434ZUL.js +34 -0
- package/dist/bundle/decode-YB3ZDTES.js +162 -0
- package/dist/bundle/dispatch-EUKKT3PD.js +411 -0
- package/dist/bundle/dist-A6GKSKFC.js +2072 -0
- package/dist/bundle/dist-X36THCOF.js +7577 -0
- package/dist/bundle/echarts-YNGCOYHW.js +42501 -0
- package/dist/bundle/embed-LWNHIRBQ.js +37 -0
- package/dist/bundle/embedder-2LYD3U37.js +110 -0
- package/dist/bundle/failure-OAIC5VAP.js +24 -0
- package/dist/bundle/first-run-N3HJKGU7.js +27 -0
- package/dist/bundle/first-screen-4U2DMV3G.js +32 -0
- package/dist/bundle/instructions-GJHHFV64.js +11 -0
- package/dist/bundle/mail.js +166 -0
- package/dist/bundle/mcp-L7SRVDRN.js +167 -0
- package/dist/bundle/node-GFOH6FKP.js +176 -0
- package/dist/bundle/node-KM3CUABH.js +2340 -0
- package/dist/bundle/node-TLZSIHIJ.js +21 -0
- package/dist/bundle/node-sqlite-NBXQXBIU.js +63 -0
- package/dist/bundle/oauth-56EFO5AQ.js +19 -0
- package/dist/bundle/open-2V7QZQJP.js +21 -0
- package/dist/bundle/openai-V3SVACVL.js +251 -0
- package/dist/bundle/process-XVDX4SPD.js +91 -0
- package/dist/bundle/program-ILID6EAT.js +35542 -0
- package/dist/bundle/prompt-YKWAI222.js +14 -0
- package/dist/bundle/recognize-PAR66KVM.js +25 -0
- package/dist/bundle/remote-CE43TKXC.js +28 -0
- package/dist/bundle/rerank-M7S7P2TW.js +51 -0
- package/dist/bundle/serve-ENPMIV6J.js +197 -0
- package/dist/bundle/server-JRTHUCVY.js +63 -0
- package/dist/bundle/server-MBEZLVKZ.js +189 -0
- package/dist/bundle/sqlite-runtime-HVGDHBJJ.js +18 -0
- package/dist/bundle/state-QZSOSKBD.js +35 -0
- package/dist/bundle/store-2BUX6LVX.js +124 -0
- package/dist/bundle/store-UJ7SNKXI.js +141 -0
- package/dist/bundle/store-maintenance-command-I7V5C44K.js +52 -0
- package/dist/commands/account.d.ts +3 -0
- package/dist/commands/account.d.ts.map +1 -0
- package/dist/commands/account.js +47 -0
- package/dist/commands/account.js.map +1 -0
- package/dist/commands/context.d.ts +41 -0
- package/dist/commands/context.d.ts.map +1 -0
- package/dist/commands/context.js +52 -0
- package/dist/commands/context.js.map +1 -0
- package/dist/commands/doctor.d.ts +77 -0
- package/dist/commands/doctor.d.ts.map +1 -0
- package/dist/commands/doctor.js +74 -0
- package/dist/commands/doctor.js.map +1 -0
- package/dist/commands/folders.d.ts +3 -0
- package/dist/commands/folders.d.ts.map +1 -0
- package/dist/commands/folders.js +36 -0
- package/dist/commands/folders.js.map +1 -0
- package/dist/commands/login.d.ts +5 -0
- package/dist/commands/login.d.ts.map +1 -0
- package/dist/commands/login.js +21 -0
- package/dist/commands/login.js.map +1 -0
- package/dist/commands/mailbox.d.ts +16 -0
- package/dist/commands/mailbox.d.ts.map +1 -0
- package/dist/commands/mailbox.js +54 -0
- package/dist/commands/mailbox.js.map +1 -0
- package/dist/commands/mcp.d.ts +3 -0
- package/dist/commands/mcp.d.ts.map +1 -0
- package/dist/commands/mcp.js +97 -0
- package/dist/commands/mcp.js.map +1 -0
- package/dist/commands/session.d.ts +3 -0
- package/dist/commands/session.d.ts.map +1 -0
- package/dist/commands/session.js +211 -0
- package/dist/commands/session.js.map +1 -0
- package/dist/commands/setup.d.ts +3 -0
- package/dist/commands/setup.d.ts.map +1 -0
- package/dist/commands/setup.js +156 -0
- package/dist/commands/setup.js.map +1 -0
- package/dist/commands/status.d.ts +3 -0
- package/dist/commands/status.d.ts.map +1 -0
- package/dist/commands/status.js +89 -0
- package/dist/commands/status.js.map +1 -0
- package/dist/commands/sync.d.ts +3 -0
- package/dist/commands/sync.d.ts.map +1 -0
- package/dist/commands/sync.js +190 -0
- package/dist/commands/sync.js.map +1 -0
- package/dist/config.d.ts +190 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +46 -0
- package/dist/config.js.map +1 -0
- package/dist/discovery.d.ts +42 -0
- package/dist/discovery.d.ts.map +1 -0
- package/dist/discovery.js +179 -0
- package/dist/discovery.js.map +1 -0
- package/dist/identity.d.ts +5 -0
- package/dist/identity.d.ts.map +1 -0
- package/dist/identity.js +16 -0
- package/dist/identity.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/mail/imap-errors.d.ts +4 -0
- package/dist/mail/imap-errors.d.ts.map +1 -0
- package/dist/mail/imap-errors.js +41 -0
- package/dist/mail/imap-errors.js.map +1 -0
- package/dist/mail/imap-messages.d.ts +18 -0
- package/dist/mail/imap-messages.d.ts.map +1 -0
- package/dist/mail/imap-messages.js +66 -0
- package/dist/mail/imap-messages.js.map +1 -0
- package/dist/mail/imap.d.ts +67 -0
- package/dist/mail/imap.d.ts.map +1 -0
- package/dist/mail/imap.js +348 -0
- package/dist/mail/imap.js.map +1 -0
- package/dist/mail/parse.d.ts +18 -0
- package/dist/mail/parse.d.ts.map +1 -0
- package/dist/mail/parse.js +31 -0
- package/dist/mail/parse.js.map +1 -0
- package/dist/mail/port.d.ts +50 -0
- package/dist/mail/port.d.ts.map +1 -0
- package/dist/mail/port.js +4 -0
- package/dist/mail/port.js.map +1 -0
- package/dist/mcp.d.ts +29 -0
- package/dist/mcp.d.ts.map +1 -0
- package/dist/mcp.js +98 -0
- package/dist/mcp.js.map +1 -0
- package/dist/profile.d.ts +16 -0
- package/dist/profile.d.ts.map +1 -0
- package/dist/profile.js +31 -0
- package/dist/profile.js.map +1 -0
- package/dist/program.d.ts +6 -0
- package/dist/program.d.ts.map +1 -0
- package/dist/program.js +52 -0
- package/dist/program.js.map +1 -0
- package/dist/providers.d.ts +53 -0
- package/dist/providers.d.ts.map +1 -0
- package/dist/providers.js +106 -0
- package/dist/providers.js.map +1 -0
- package/dist/secret.d.ts +30 -0
- package/dist/secret.d.ts.map +1 -0
- package/dist/secret.js +68 -0
- package/dist/secret.js.map +1 -0
- package/dist/store.d.ts +12 -0
- package/dist/store.d.ts.map +1 -0
- package/dist/store.js +25 -0
- package/dist/store.js.map +1 -0
- package/dist/sync.d.ts +26 -0
- package/dist/sync.d.ts.map +1 -0
- package/dist/sync.js +75 -0
- package/dist/sync.js.map +1 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +2 -0
- package/dist/version.js.map +1 -0
- package/package.json +83 -4
- package/skills/mail-cli/SKILL.md +27 -0
|
@@ -0,0 +1,2416 @@
|
|
|
1
|
+
import { createRequire as __bundleRequire } from "node:module";
|
|
2
|
+
const require = __bundleRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
errorCodes,
|
|
5
|
+
isCliError,
|
|
6
|
+
visibleControls
|
|
7
|
+
} from "./chunk-5BVIWP3S.js";
|
|
8
|
+
import {
|
|
9
|
+
__name
|
|
10
|
+
} from "./chunk-ZVVMGPBJ.js";
|
|
11
|
+
|
|
12
|
+
// node_modules/.pnpm/@wirecat+cli-base@0.68.1_commander@15.0.0_esbuild@0.28.2_typescript@7.0.2_vitest@5.0.5/node_modules/@wirecat/cli-base/dist/exit-codes.js
|
|
13
|
+
var EXIT_CODES = {
|
|
14
|
+
validation_error: 2,
|
|
15
|
+
configuration_error: 3,
|
|
16
|
+
authentication_error: 4,
|
|
17
|
+
permission_error: 5,
|
|
18
|
+
not_found: 6,
|
|
19
|
+
confirmation_required: 7,
|
|
20
|
+
rate_limited: 8,
|
|
21
|
+
timeout: 9,
|
|
22
|
+
network_error: 10,
|
|
23
|
+
provider_error: 11,
|
|
24
|
+
provider_unavailable: 12,
|
|
25
|
+
invalid_response: 13,
|
|
26
|
+
outcome_unknown: 14,
|
|
27
|
+
cancelled: 130
|
|
28
|
+
};
|
|
29
|
+
var exitCodeFor = /* @__PURE__ */ __name((code) => EXIT_CODES[code], "exitCodeFor");
|
|
30
|
+
var GENERIC_FAILURE = 1;
|
|
31
|
+
|
|
32
|
+
// node_modules/.pnpm/valibot@1.5.0_typescript@7.0.2/node_modules/valibot/dist/index.mjs
|
|
33
|
+
var store$4;
|
|
34
|
+
var DEFAULT_CONFIG = {
|
|
35
|
+
lang: void 0,
|
|
36
|
+
message: void 0,
|
|
37
|
+
abortEarly: void 0,
|
|
38
|
+
abortPipeEarly: void 0
|
|
39
|
+
};
|
|
40
|
+
// @__NO_SIDE_EFFECTS__
|
|
41
|
+
function getGlobalConfig(config$1) {
|
|
42
|
+
if (!config$1 && !store$4) return DEFAULT_CONFIG;
|
|
43
|
+
return {
|
|
44
|
+
lang: config$1?.lang ?? store$4?.lang,
|
|
45
|
+
message: config$1?.message,
|
|
46
|
+
abortEarly: config$1?.abortEarly ?? store$4?.abortEarly,
|
|
47
|
+
abortPipeEarly: config$1?.abortPipeEarly ?? store$4?.abortPipeEarly
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
__name(getGlobalConfig, "getGlobalConfig");
|
|
51
|
+
var store$3;
|
|
52
|
+
// @__NO_SIDE_EFFECTS__
|
|
53
|
+
function getGlobalMessage(lang) {
|
|
54
|
+
return store$3?.get(lang);
|
|
55
|
+
}
|
|
56
|
+
__name(getGlobalMessage, "getGlobalMessage");
|
|
57
|
+
var store$2;
|
|
58
|
+
// @__NO_SIDE_EFFECTS__
|
|
59
|
+
function getSchemaMessage(lang) {
|
|
60
|
+
return store$2?.get(lang);
|
|
61
|
+
}
|
|
62
|
+
__name(getSchemaMessage, "getSchemaMessage");
|
|
63
|
+
var store$1;
|
|
64
|
+
// @__NO_SIDE_EFFECTS__
|
|
65
|
+
function getSpecificMessage(reference2, lang) {
|
|
66
|
+
return store$1?.get(reference2)?.get(lang);
|
|
67
|
+
}
|
|
68
|
+
__name(getSpecificMessage, "getSpecificMessage");
|
|
69
|
+
// @__NO_SIDE_EFFECTS__
|
|
70
|
+
function _stringify(input) {
|
|
71
|
+
const type = typeof input;
|
|
72
|
+
if (type === "string") return `"${input}"`;
|
|
73
|
+
if (type === "number" || type === "bigint" || type === "boolean") return `${input}`;
|
|
74
|
+
if (type === "object" || type === "function") return (input && Object.getPrototypeOf(input)?.constructor?.name) ?? "null";
|
|
75
|
+
return type;
|
|
76
|
+
}
|
|
77
|
+
__name(_stringify, "_stringify");
|
|
78
|
+
function _addIssue(context, label, dataset, config$1, other) {
|
|
79
|
+
const input = other && "input" in other ? other.input : dataset.value;
|
|
80
|
+
const expected = other?.expected ?? context.expects ?? null;
|
|
81
|
+
const received = other?.received ?? /* @__PURE__ */ _stringify(input);
|
|
82
|
+
const issue = {
|
|
83
|
+
kind: context.kind,
|
|
84
|
+
type: context.type,
|
|
85
|
+
input,
|
|
86
|
+
expected,
|
|
87
|
+
received,
|
|
88
|
+
message: `Invalid ${label}: ${expected ? `Expected ${expected} but r` : "R"}eceived ${received}`,
|
|
89
|
+
requirement: context.requirement,
|
|
90
|
+
path: other?.path,
|
|
91
|
+
issues: other?.issues,
|
|
92
|
+
lang: config$1.lang,
|
|
93
|
+
abortEarly: config$1.abortEarly,
|
|
94
|
+
abortPipeEarly: config$1.abortPipeEarly
|
|
95
|
+
};
|
|
96
|
+
const isSchema = context.kind === "schema";
|
|
97
|
+
const message$1 = other?.message ?? context.message ?? /* @__PURE__ */ getSpecificMessage(context.reference, issue.lang) ?? (isSchema ? /* @__PURE__ */ getSchemaMessage(issue.lang) : null) ?? config$1.message ?? /* @__PURE__ */ getGlobalMessage(issue.lang);
|
|
98
|
+
if (message$1 !== void 0) issue.message = typeof message$1 === "function" ? message$1(issue) : message$1;
|
|
99
|
+
if (isSchema) dataset.typed = false;
|
|
100
|
+
if (dataset.issues) dataset.issues.push(issue);
|
|
101
|
+
else dataset.issues = [issue];
|
|
102
|
+
}
|
|
103
|
+
__name(_addIssue, "_addIssue");
|
|
104
|
+
// @__NO_SIDE_EFFECTS__
|
|
105
|
+
function _isSameValueZero(value1, value2) {
|
|
106
|
+
return value1 === value2 || Number.isNaN(value1) && Number.isNaN(value2);
|
|
107
|
+
}
|
|
108
|
+
__name(_isSameValueZero, "_isSameValueZero");
|
|
109
|
+
// @__NO_SIDE_EFFECTS__
|
|
110
|
+
function _isValidObjectKey(object$1, key) {
|
|
111
|
+
return Object.prototype.hasOwnProperty.call(object$1, key) && key !== "__proto__" && key !== "prototype" && key !== "constructor";
|
|
112
|
+
}
|
|
113
|
+
__name(_isValidObjectKey, "_isValidObjectKey");
|
|
114
|
+
// @__NO_SIDE_EFFECTS__
|
|
115
|
+
function _joinExpects(values$1, separator) {
|
|
116
|
+
const list = [...new Set(values$1)];
|
|
117
|
+
if (list.length > 1) return `(${list.join(` ${separator} `)})`;
|
|
118
|
+
return list[0] ?? "never";
|
|
119
|
+
}
|
|
120
|
+
__name(_joinExpects, "_joinExpects");
|
|
121
|
+
function _standardSchema(schema) {
|
|
122
|
+
schema["~standard"] = {
|
|
123
|
+
version: 1,
|
|
124
|
+
vendor: "valibot",
|
|
125
|
+
validate: /* @__PURE__ */ __name((value$1) => schema["~run"]({ value: value$1 }, /* @__PURE__ */ getGlobalConfig()), "validate")
|
|
126
|
+
};
|
|
127
|
+
return schema;
|
|
128
|
+
}
|
|
129
|
+
__name(_standardSchema, "_standardSchema");
|
|
130
|
+
// @__NO_SIDE_EFFECTS__
|
|
131
|
+
function getDotPath(issue) {
|
|
132
|
+
if (issue.path) {
|
|
133
|
+
let key = "";
|
|
134
|
+
for (const item of issue.path) if (typeof item.key === "string" || typeof item.key === "number") if (key) key += `.${item.key}`;
|
|
135
|
+
else key += item.key;
|
|
136
|
+
else return null;
|
|
137
|
+
return key;
|
|
138
|
+
}
|
|
139
|
+
return null;
|
|
140
|
+
}
|
|
141
|
+
__name(getDotPath, "getDotPath");
|
|
142
|
+
var ValiError = class extends Error {
|
|
143
|
+
static {
|
|
144
|
+
__name(this, "ValiError");
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Creates a Valibot error with useful information.
|
|
148
|
+
*
|
|
149
|
+
* @param issues The error issues.
|
|
150
|
+
*/
|
|
151
|
+
constructor(issues) {
|
|
152
|
+
super(issues[0].message);
|
|
153
|
+
this.name = "ValiError";
|
|
154
|
+
this.issues = issues;
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
var EMOJI_REGEX = new RegExp("^(?:[\\u{1F1E6}-\\u{1F1FF}]{2}|\\u{1F3F4}[\\u{E0061}-\\u{E007A}]{2}[\\u{E0030}-\\u{E0039}\\u{E0061}-\\u{E007A}]{1,3}\\u{E007F}|(?:\\p{Emoji}\\uFE0F\\u20E3?|\\p{Emoji_Modifier_Base}\\p{Emoji_Modifier}?|(?![\\p{Emoji_Modifier_Base}\\u{1F1E6}-\\u{1F1FF}])\\p{Emoji_Presentation})(?:\\u200D(?:\\p{Emoji}\\uFE0F\\u20E3?|\\p{Emoji_Modifier_Base}\\p{Emoji_Modifier}?|(?![\\p{Emoji_Modifier_Base}\\u{1F1E6}-\\u{1F1FF}])\\p{Emoji_Presentation}))*)+$", "u");
|
|
158
|
+
var ISO_DATE_REGEX = /^\d{4}-(?:0[1-9]|1[0-2])-(?:[12]\d|0[1-9]|3[01])$/u;
|
|
159
|
+
var ISO_TIMESTAMP_REGEX = /^\d{4}-(?:0[1-9]|1[0-2])-(?:[12]\d|0[1-9]|3[01])[T ](?:0\d|1\d|2[0-3])(?::[0-5]\d){2}(?:\.\d{1,9})?(?:Z| ?[+-](?:0\d|1\d|2[0-3])(?::?[0-5]\d)?)$/u;
|
|
160
|
+
// @__NO_SIDE_EFFECTS__
|
|
161
|
+
function check(requirement, message$1) {
|
|
162
|
+
return {
|
|
163
|
+
kind: "validation",
|
|
164
|
+
type: "check",
|
|
165
|
+
reference: check,
|
|
166
|
+
async: false,
|
|
167
|
+
expects: null,
|
|
168
|
+
requirement,
|
|
169
|
+
message: message$1,
|
|
170
|
+
"~run"(dataset, config$1) {
|
|
171
|
+
if (dataset.typed && !this.requirement(dataset.value)) _addIssue(this, "input", dataset, config$1);
|
|
172
|
+
return dataset;
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
__name(check, "check");
|
|
177
|
+
// @__NO_SIDE_EFFECTS__
|
|
178
|
+
function description(description_) {
|
|
179
|
+
return {
|
|
180
|
+
kind: "metadata",
|
|
181
|
+
type: "description",
|
|
182
|
+
reference: description,
|
|
183
|
+
description: description_
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
__name(description, "description");
|
|
187
|
+
// @__NO_SIDE_EFFECTS__
|
|
188
|
+
function endsWith(requirement, message$1) {
|
|
189
|
+
return {
|
|
190
|
+
kind: "validation",
|
|
191
|
+
type: "ends_with",
|
|
192
|
+
reference: endsWith,
|
|
193
|
+
async: false,
|
|
194
|
+
expects: `"${requirement}"`,
|
|
195
|
+
requirement,
|
|
196
|
+
message: message$1,
|
|
197
|
+
"~run"(dataset, config$1) {
|
|
198
|
+
if (dataset.typed && !dataset.value.endsWith(this.requirement)) _addIssue(this, "end", dataset, config$1, { received: `"${dataset.value.slice(-this.requirement.length)}"` });
|
|
199
|
+
return dataset;
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
__name(endsWith, "endsWith");
|
|
204
|
+
// @__NO_SIDE_EFFECTS__
|
|
205
|
+
function finite(message$1) {
|
|
206
|
+
return {
|
|
207
|
+
kind: "validation",
|
|
208
|
+
type: "finite",
|
|
209
|
+
reference: finite,
|
|
210
|
+
async: false,
|
|
211
|
+
expects: null,
|
|
212
|
+
requirement: Number.isFinite,
|
|
213
|
+
message: message$1,
|
|
214
|
+
"~run"(dataset, config$1) {
|
|
215
|
+
if (dataset.typed && !this.requirement(dataset.value)) _addIssue(this, "finite", dataset, config$1);
|
|
216
|
+
return dataset;
|
|
217
|
+
}
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
__name(finite, "finite");
|
|
221
|
+
// @__NO_SIDE_EFFECTS__
|
|
222
|
+
function integer(message$1) {
|
|
223
|
+
return {
|
|
224
|
+
kind: "validation",
|
|
225
|
+
type: "integer",
|
|
226
|
+
reference: integer,
|
|
227
|
+
async: false,
|
|
228
|
+
expects: null,
|
|
229
|
+
requirement: Number.isInteger,
|
|
230
|
+
message: message$1,
|
|
231
|
+
"~run"(dataset, config$1) {
|
|
232
|
+
if (dataset.typed && !this.requirement(dataset.value)) _addIssue(this, "integer", dataset, config$1);
|
|
233
|
+
return dataset;
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
__name(integer, "integer");
|
|
238
|
+
// @__NO_SIDE_EFFECTS__
|
|
239
|
+
function isoDate(message$1) {
|
|
240
|
+
return {
|
|
241
|
+
kind: "validation",
|
|
242
|
+
type: "iso_date",
|
|
243
|
+
reference: isoDate,
|
|
244
|
+
async: false,
|
|
245
|
+
expects: null,
|
|
246
|
+
requirement: ISO_DATE_REGEX,
|
|
247
|
+
message: message$1,
|
|
248
|
+
"~run"(dataset, config$1) {
|
|
249
|
+
if (dataset.typed && !this.requirement.test(dataset.value)) _addIssue(this, "date", dataset, config$1);
|
|
250
|
+
return dataset;
|
|
251
|
+
}
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
__name(isoDate, "isoDate");
|
|
255
|
+
// @__NO_SIDE_EFFECTS__
|
|
256
|
+
function isoTimestamp(message$1) {
|
|
257
|
+
return {
|
|
258
|
+
kind: "validation",
|
|
259
|
+
type: "iso_timestamp",
|
|
260
|
+
reference: isoTimestamp,
|
|
261
|
+
async: false,
|
|
262
|
+
expects: null,
|
|
263
|
+
requirement: ISO_TIMESTAMP_REGEX,
|
|
264
|
+
message: message$1,
|
|
265
|
+
"~run"(dataset, config$1) {
|
|
266
|
+
if (dataset.typed && !this.requirement.test(dataset.value)) _addIssue(this, "timestamp", dataset, config$1);
|
|
267
|
+
return dataset;
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
__name(isoTimestamp, "isoTimestamp");
|
|
272
|
+
// @__NO_SIDE_EFFECTS__
|
|
273
|
+
function maxLength(requirement, message$1) {
|
|
274
|
+
return {
|
|
275
|
+
kind: "validation",
|
|
276
|
+
type: "max_length",
|
|
277
|
+
reference: maxLength,
|
|
278
|
+
async: false,
|
|
279
|
+
expects: `<=${requirement}`,
|
|
280
|
+
requirement,
|
|
281
|
+
message: message$1,
|
|
282
|
+
"~run"(dataset, config$1) {
|
|
283
|
+
if (dataset.typed && dataset.value.length > this.requirement) _addIssue(this, "length", dataset, config$1, { received: `${dataset.value.length}` });
|
|
284
|
+
return dataset;
|
|
285
|
+
}
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
__name(maxLength, "maxLength");
|
|
289
|
+
// @__NO_SIDE_EFFECTS__
|
|
290
|
+
function maxValue(requirement, message$1) {
|
|
291
|
+
return {
|
|
292
|
+
kind: "validation",
|
|
293
|
+
type: "max_value",
|
|
294
|
+
reference: maxValue,
|
|
295
|
+
async: false,
|
|
296
|
+
expects: `<=${requirement instanceof Date ? requirement.toJSON() : /* @__PURE__ */ _stringify(requirement)}`,
|
|
297
|
+
requirement,
|
|
298
|
+
message: message$1,
|
|
299
|
+
"~run"(dataset, config$1) {
|
|
300
|
+
if (dataset.typed && !(dataset.value <= this.requirement)) _addIssue(this, "value", dataset, config$1, { received: dataset.value instanceof Date ? dataset.value.toJSON() : /* @__PURE__ */ _stringify(dataset.value) });
|
|
301
|
+
return dataset;
|
|
302
|
+
}
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
__name(maxValue, "maxValue");
|
|
306
|
+
// @__NO_SIDE_EFFECTS__
|
|
307
|
+
function minLength(requirement, message$1) {
|
|
308
|
+
return {
|
|
309
|
+
kind: "validation",
|
|
310
|
+
type: "min_length",
|
|
311
|
+
reference: minLength,
|
|
312
|
+
async: false,
|
|
313
|
+
expects: `>=${requirement}`,
|
|
314
|
+
requirement,
|
|
315
|
+
message: message$1,
|
|
316
|
+
"~run"(dataset, config$1) {
|
|
317
|
+
if (dataset.typed && dataset.value.length < this.requirement) _addIssue(this, "length", dataset, config$1, { received: `${dataset.value.length}` });
|
|
318
|
+
return dataset;
|
|
319
|
+
}
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
__name(minLength, "minLength");
|
|
323
|
+
// @__NO_SIDE_EFFECTS__
|
|
324
|
+
function minValue(requirement, message$1) {
|
|
325
|
+
return {
|
|
326
|
+
kind: "validation",
|
|
327
|
+
type: "min_value",
|
|
328
|
+
reference: minValue,
|
|
329
|
+
async: false,
|
|
330
|
+
expects: `>=${requirement instanceof Date ? requirement.toJSON() : /* @__PURE__ */ _stringify(requirement)}`,
|
|
331
|
+
requirement,
|
|
332
|
+
message: message$1,
|
|
333
|
+
"~run"(dataset, config$1) {
|
|
334
|
+
if (dataset.typed && !(dataset.value >= this.requirement)) _addIssue(this, "value", dataset, config$1, { received: dataset.value instanceof Date ? dataset.value.toJSON() : /* @__PURE__ */ _stringify(dataset.value) });
|
|
335
|
+
return dataset;
|
|
336
|
+
}
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
__name(minValue, "minValue");
|
|
340
|
+
// @__NO_SIDE_EFFECTS__
|
|
341
|
+
function nonEmpty(message$1) {
|
|
342
|
+
return {
|
|
343
|
+
kind: "validation",
|
|
344
|
+
type: "non_empty",
|
|
345
|
+
reference: nonEmpty,
|
|
346
|
+
async: false,
|
|
347
|
+
expects: "!0",
|
|
348
|
+
message: message$1,
|
|
349
|
+
"~run"(dataset, config$1) {
|
|
350
|
+
if (dataset.typed && dataset.value.length === 0) _addIssue(this, "length", dataset, config$1, { received: "0" });
|
|
351
|
+
return dataset;
|
|
352
|
+
}
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
__name(nonEmpty, "nonEmpty");
|
|
356
|
+
// @__NO_SIDE_EFFECTS__
|
|
357
|
+
function regex(requirement, message$1) {
|
|
358
|
+
return {
|
|
359
|
+
kind: "validation",
|
|
360
|
+
type: "regex",
|
|
361
|
+
reference: regex,
|
|
362
|
+
async: false,
|
|
363
|
+
expects: `${requirement}`,
|
|
364
|
+
requirement,
|
|
365
|
+
message: message$1,
|
|
366
|
+
"~run"(dataset, config$1) {
|
|
367
|
+
if (dataset.typed && !this.requirement.test(dataset.value)) _addIssue(this, "format", dataset, config$1);
|
|
368
|
+
return dataset;
|
|
369
|
+
}
|
|
370
|
+
};
|
|
371
|
+
}
|
|
372
|
+
__name(regex, "regex");
|
|
373
|
+
// @__NO_SIDE_EFFECTS__
|
|
374
|
+
function safeInteger(message$1) {
|
|
375
|
+
return {
|
|
376
|
+
kind: "validation",
|
|
377
|
+
type: "safe_integer",
|
|
378
|
+
reference: safeInteger,
|
|
379
|
+
async: false,
|
|
380
|
+
expects: null,
|
|
381
|
+
requirement: Number.isSafeInteger,
|
|
382
|
+
message: message$1,
|
|
383
|
+
"~run"(dataset, config$1) {
|
|
384
|
+
if (dataset.typed && !this.requirement(dataset.value)) _addIssue(this, "safe integer", dataset, config$1);
|
|
385
|
+
return dataset;
|
|
386
|
+
}
|
|
387
|
+
};
|
|
388
|
+
}
|
|
389
|
+
__name(safeInteger, "safeInteger");
|
|
390
|
+
// @__NO_SIDE_EFFECTS__
|
|
391
|
+
function transform(operation) {
|
|
392
|
+
return {
|
|
393
|
+
kind: "transformation",
|
|
394
|
+
type: "transform",
|
|
395
|
+
reference: transform,
|
|
396
|
+
async: false,
|
|
397
|
+
operation,
|
|
398
|
+
"~run"(dataset) {
|
|
399
|
+
dataset.value = this.operation(dataset.value);
|
|
400
|
+
return dataset;
|
|
401
|
+
}
|
|
402
|
+
};
|
|
403
|
+
}
|
|
404
|
+
__name(transform, "transform");
|
|
405
|
+
// @__NO_SIDE_EFFECTS__
|
|
406
|
+
function trim() {
|
|
407
|
+
return {
|
|
408
|
+
kind: "transformation",
|
|
409
|
+
type: "trim",
|
|
410
|
+
reference: trim,
|
|
411
|
+
async: false,
|
|
412
|
+
"~run"(dataset) {
|
|
413
|
+
dataset.value = dataset.value.trim();
|
|
414
|
+
return dataset;
|
|
415
|
+
}
|
|
416
|
+
};
|
|
417
|
+
}
|
|
418
|
+
__name(trim, "trim");
|
|
419
|
+
var ABORT_EARLY_CONFIG = { abortEarly: true };
|
|
420
|
+
// @__NO_SIDE_EFFECTS__
|
|
421
|
+
function getFallback(schema, dataset, config$1) {
|
|
422
|
+
return typeof schema.fallback === "function" ? schema.fallback(dataset, config$1) : schema.fallback;
|
|
423
|
+
}
|
|
424
|
+
__name(getFallback, "getFallback");
|
|
425
|
+
// @__NO_SIDE_EFFECTS__
|
|
426
|
+
function forward(action, path) {
|
|
427
|
+
return {
|
|
428
|
+
...action,
|
|
429
|
+
"~run"(dataset, config$1) {
|
|
430
|
+
const prevIssues = dataset.issues && [...dataset.issues];
|
|
431
|
+
dataset = action["~run"](dataset, config$1);
|
|
432
|
+
if (dataset.issues) {
|
|
433
|
+
for (const issue of dataset.issues) if (!prevIssues?.includes(issue)) {
|
|
434
|
+
let pathInput = dataset.value;
|
|
435
|
+
for (const key of path) {
|
|
436
|
+
const pathValue = pathInput[key];
|
|
437
|
+
const pathItem = {
|
|
438
|
+
type: "unknown",
|
|
439
|
+
origin: "value",
|
|
440
|
+
input: pathInput,
|
|
441
|
+
key,
|
|
442
|
+
value: pathValue
|
|
443
|
+
};
|
|
444
|
+
if (issue.path) issue.path.push(pathItem);
|
|
445
|
+
else issue.path = [pathItem];
|
|
446
|
+
if (!pathValue) break;
|
|
447
|
+
pathInput = pathValue;
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
return dataset;
|
|
452
|
+
}
|
|
453
|
+
};
|
|
454
|
+
}
|
|
455
|
+
__name(forward, "forward");
|
|
456
|
+
// @__NO_SIDE_EFFECTS__
|
|
457
|
+
function getDefault(schema, dataset, config$1) {
|
|
458
|
+
return typeof schema.default === "function" ? schema.default(dataset, config$1) : schema.default;
|
|
459
|
+
}
|
|
460
|
+
__name(getDefault, "getDefault");
|
|
461
|
+
// @__NO_SIDE_EFFECTS__
|
|
462
|
+
function array(item, message$1) {
|
|
463
|
+
return _standardSchema({
|
|
464
|
+
kind: "schema",
|
|
465
|
+
type: "array",
|
|
466
|
+
reference: array,
|
|
467
|
+
expects: "Array",
|
|
468
|
+
async: false,
|
|
469
|
+
item,
|
|
470
|
+
message: message$1,
|
|
471
|
+
"~run"(dataset, config$1) {
|
|
472
|
+
const input = dataset.value;
|
|
473
|
+
if (Array.isArray(input)) {
|
|
474
|
+
dataset.typed = true;
|
|
475
|
+
dataset.value = [];
|
|
476
|
+
for (let key = 0; key < input.length; key++) {
|
|
477
|
+
const value$1 = input[key];
|
|
478
|
+
const itemDataset = this.item["~run"]({ value: value$1 }, config$1);
|
|
479
|
+
if (itemDataset.issues) {
|
|
480
|
+
const pathItem = {
|
|
481
|
+
type: "array",
|
|
482
|
+
origin: "value",
|
|
483
|
+
input,
|
|
484
|
+
key,
|
|
485
|
+
value: value$1
|
|
486
|
+
};
|
|
487
|
+
for (const issue of itemDataset.issues) {
|
|
488
|
+
if (issue.path) issue.path.unshift(pathItem);
|
|
489
|
+
else issue.path = [pathItem];
|
|
490
|
+
dataset.issues?.push(issue);
|
|
491
|
+
}
|
|
492
|
+
if (!dataset.issues) dataset.issues = itemDataset.issues;
|
|
493
|
+
if (config$1.abortEarly) {
|
|
494
|
+
dataset.typed = false;
|
|
495
|
+
break;
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
if (!itemDataset.typed) dataset.typed = false;
|
|
499
|
+
dataset.value.push(itemDataset.value);
|
|
500
|
+
}
|
|
501
|
+
} else _addIssue(this, "type", dataset, config$1);
|
|
502
|
+
return dataset;
|
|
503
|
+
}
|
|
504
|
+
});
|
|
505
|
+
}
|
|
506
|
+
__name(array, "array");
|
|
507
|
+
// @__NO_SIDE_EFFECTS__
|
|
508
|
+
function boolean(message$1) {
|
|
509
|
+
return _standardSchema({
|
|
510
|
+
kind: "schema",
|
|
511
|
+
type: "boolean",
|
|
512
|
+
reference: boolean,
|
|
513
|
+
expects: "boolean",
|
|
514
|
+
async: false,
|
|
515
|
+
message: message$1,
|
|
516
|
+
"~run"(dataset, config$1) {
|
|
517
|
+
if (typeof dataset.value === "boolean") dataset.typed = true;
|
|
518
|
+
else _addIssue(this, "type", dataset, config$1);
|
|
519
|
+
return dataset;
|
|
520
|
+
}
|
|
521
|
+
});
|
|
522
|
+
}
|
|
523
|
+
__name(boolean, "boolean");
|
|
524
|
+
// @__NO_SIDE_EFFECTS__
|
|
525
|
+
function lazy(getter) {
|
|
526
|
+
return _standardSchema({
|
|
527
|
+
kind: "schema",
|
|
528
|
+
type: "lazy",
|
|
529
|
+
reference: lazy,
|
|
530
|
+
expects: "unknown",
|
|
531
|
+
async: false,
|
|
532
|
+
getter,
|
|
533
|
+
"~run"(dataset, config$1) {
|
|
534
|
+
return this.getter(dataset.value)["~run"](dataset, config$1);
|
|
535
|
+
}
|
|
536
|
+
});
|
|
537
|
+
}
|
|
538
|
+
__name(lazy, "lazy");
|
|
539
|
+
// @__NO_SIDE_EFFECTS__
|
|
540
|
+
function literal(literal_, message$1) {
|
|
541
|
+
return _standardSchema({
|
|
542
|
+
kind: "schema",
|
|
543
|
+
type: "literal",
|
|
544
|
+
reference: literal,
|
|
545
|
+
expects: /* @__PURE__ */ _stringify(literal_),
|
|
546
|
+
async: false,
|
|
547
|
+
literal: literal_,
|
|
548
|
+
message: message$1,
|
|
549
|
+
"~run"(dataset, config$1) {
|
|
550
|
+
if (/* @__PURE__ */ _isSameValueZero(dataset.value, this.literal)) dataset.typed = true;
|
|
551
|
+
else _addIssue(this, "type", dataset, config$1);
|
|
552
|
+
return dataset;
|
|
553
|
+
}
|
|
554
|
+
});
|
|
555
|
+
}
|
|
556
|
+
__name(literal, "literal");
|
|
557
|
+
// @__NO_SIDE_EFFECTS__
|
|
558
|
+
function looseObject(entries$1, message$1) {
|
|
559
|
+
return _standardSchema({
|
|
560
|
+
kind: "schema",
|
|
561
|
+
type: "loose_object",
|
|
562
|
+
reference: looseObject,
|
|
563
|
+
expects: "Object",
|
|
564
|
+
async: false,
|
|
565
|
+
entries: entries$1,
|
|
566
|
+
message: message$1,
|
|
567
|
+
"~run"(dataset, config$1) {
|
|
568
|
+
const input = dataset.value;
|
|
569
|
+
if (input && typeof input === "object") {
|
|
570
|
+
dataset.typed = true;
|
|
571
|
+
dataset.value = {};
|
|
572
|
+
for (const key in this.entries) {
|
|
573
|
+
const valueSchema = this.entries[key];
|
|
574
|
+
if (key in input || (valueSchema.type === "exact_optional" || valueSchema.type === "optional" || valueSchema.type === "nullish") && valueSchema.default !== void 0) {
|
|
575
|
+
const value$1 = key in input ? input[key] : /* @__PURE__ */ getDefault(valueSchema);
|
|
576
|
+
const valueDataset = valueSchema["~run"]({ value: value$1 }, config$1);
|
|
577
|
+
if (valueDataset.issues) {
|
|
578
|
+
const pathItem = {
|
|
579
|
+
type: "object",
|
|
580
|
+
origin: "value",
|
|
581
|
+
input,
|
|
582
|
+
key,
|
|
583
|
+
value: value$1
|
|
584
|
+
};
|
|
585
|
+
for (const issue of valueDataset.issues) {
|
|
586
|
+
if (issue.path) issue.path.unshift(pathItem);
|
|
587
|
+
else issue.path = [pathItem];
|
|
588
|
+
dataset.issues?.push(issue);
|
|
589
|
+
}
|
|
590
|
+
if (!dataset.issues) dataset.issues = valueDataset.issues;
|
|
591
|
+
if (config$1.abortEarly) {
|
|
592
|
+
dataset.typed = false;
|
|
593
|
+
break;
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
if (!valueDataset.typed) dataset.typed = false;
|
|
597
|
+
dataset.value[key] = valueDataset.value;
|
|
598
|
+
} else if (valueSchema.fallback !== void 0) dataset.value[key] = /* @__PURE__ */ getFallback(valueSchema);
|
|
599
|
+
else if (valueSchema.type !== "exact_optional" && valueSchema.type !== "optional" && valueSchema.type !== "nullish") {
|
|
600
|
+
_addIssue(this, "key", dataset, config$1, {
|
|
601
|
+
input: void 0,
|
|
602
|
+
expected: `"${key}"`,
|
|
603
|
+
path: [{
|
|
604
|
+
type: "object",
|
|
605
|
+
origin: "key",
|
|
606
|
+
input,
|
|
607
|
+
key,
|
|
608
|
+
value: input[key]
|
|
609
|
+
}]
|
|
610
|
+
});
|
|
611
|
+
if (config$1.abortEarly) break;
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
if (!dataset.issues || !config$1.abortEarly) {
|
|
615
|
+
for (const key in input) if (/* @__PURE__ */ _isValidObjectKey(input, key) && !Object.prototype.hasOwnProperty.call(this.entries, key)) dataset.value[key] = input[key];
|
|
616
|
+
}
|
|
617
|
+
} else _addIssue(this, "type", dataset, config$1);
|
|
618
|
+
return dataset;
|
|
619
|
+
}
|
|
620
|
+
});
|
|
621
|
+
}
|
|
622
|
+
__name(looseObject, "looseObject");
|
|
623
|
+
// @__NO_SIDE_EFFECTS__
|
|
624
|
+
function null_(message$1) {
|
|
625
|
+
return _standardSchema({
|
|
626
|
+
kind: "schema",
|
|
627
|
+
type: "null",
|
|
628
|
+
reference: null_,
|
|
629
|
+
expects: "null",
|
|
630
|
+
async: false,
|
|
631
|
+
message: message$1,
|
|
632
|
+
"~run"(dataset, config$1) {
|
|
633
|
+
if (dataset.value === null) dataset.typed = true;
|
|
634
|
+
else _addIssue(this, "type", dataset, config$1);
|
|
635
|
+
return dataset;
|
|
636
|
+
}
|
|
637
|
+
});
|
|
638
|
+
}
|
|
639
|
+
__name(null_, "null_");
|
|
640
|
+
// @__NO_SIDE_EFFECTS__
|
|
641
|
+
function nullable(wrapped, default_) {
|
|
642
|
+
return _standardSchema({
|
|
643
|
+
kind: "schema",
|
|
644
|
+
type: "nullable",
|
|
645
|
+
reference: nullable,
|
|
646
|
+
expects: `(${wrapped.expects} | null)`,
|
|
647
|
+
async: false,
|
|
648
|
+
wrapped,
|
|
649
|
+
default: default_,
|
|
650
|
+
"~run"(dataset, config$1) {
|
|
651
|
+
if (dataset.value === null) {
|
|
652
|
+
if (this.default !== void 0) dataset.value = /* @__PURE__ */ getDefault(this, dataset, config$1);
|
|
653
|
+
if (dataset.value === null) {
|
|
654
|
+
dataset.typed = true;
|
|
655
|
+
return dataset;
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
return this.wrapped["~run"](dataset, config$1);
|
|
659
|
+
}
|
|
660
|
+
});
|
|
661
|
+
}
|
|
662
|
+
__name(nullable, "nullable");
|
|
663
|
+
// @__NO_SIDE_EFFECTS__
|
|
664
|
+
function number(message$1) {
|
|
665
|
+
return _standardSchema({
|
|
666
|
+
kind: "schema",
|
|
667
|
+
type: "number",
|
|
668
|
+
reference: number,
|
|
669
|
+
expects: "number",
|
|
670
|
+
async: false,
|
|
671
|
+
message: message$1,
|
|
672
|
+
"~run"(dataset, config$1) {
|
|
673
|
+
if (typeof dataset.value === "number" && !isNaN(dataset.value)) dataset.typed = true;
|
|
674
|
+
else _addIssue(this, "type", dataset, config$1);
|
|
675
|
+
return dataset;
|
|
676
|
+
}
|
|
677
|
+
});
|
|
678
|
+
}
|
|
679
|
+
__name(number, "number");
|
|
680
|
+
// @__NO_SIDE_EFFECTS__
|
|
681
|
+
function object(entries$1, message$1) {
|
|
682
|
+
return _standardSchema({
|
|
683
|
+
kind: "schema",
|
|
684
|
+
type: "object",
|
|
685
|
+
reference: object,
|
|
686
|
+
expects: "Object",
|
|
687
|
+
async: false,
|
|
688
|
+
entries: entries$1,
|
|
689
|
+
message: message$1,
|
|
690
|
+
"~run"(dataset, config$1) {
|
|
691
|
+
const input = dataset.value;
|
|
692
|
+
if (input && typeof input === "object") {
|
|
693
|
+
dataset.typed = true;
|
|
694
|
+
dataset.value = {};
|
|
695
|
+
for (const key in this.entries) {
|
|
696
|
+
const valueSchema = this.entries[key];
|
|
697
|
+
if (key in input || (valueSchema.type === "exact_optional" || valueSchema.type === "optional" || valueSchema.type === "nullish") && valueSchema.default !== void 0) {
|
|
698
|
+
const value$1 = key in input ? input[key] : /* @__PURE__ */ getDefault(valueSchema);
|
|
699
|
+
const valueDataset = valueSchema["~run"]({ value: value$1 }, config$1);
|
|
700
|
+
if (valueDataset.issues) {
|
|
701
|
+
const pathItem = {
|
|
702
|
+
type: "object",
|
|
703
|
+
origin: "value",
|
|
704
|
+
input,
|
|
705
|
+
key,
|
|
706
|
+
value: value$1
|
|
707
|
+
};
|
|
708
|
+
for (const issue of valueDataset.issues) {
|
|
709
|
+
if (issue.path) issue.path.unshift(pathItem);
|
|
710
|
+
else issue.path = [pathItem];
|
|
711
|
+
dataset.issues?.push(issue);
|
|
712
|
+
}
|
|
713
|
+
if (!dataset.issues) dataset.issues = valueDataset.issues;
|
|
714
|
+
if (config$1.abortEarly) {
|
|
715
|
+
dataset.typed = false;
|
|
716
|
+
break;
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
if (!valueDataset.typed) dataset.typed = false;
|
|
720
|
+
dataset.value[key] = valueDataset.value;
|
|
721
|
+
} else if (valueSchema.fallback !== void 0) dataset.value[key] = /* @__PURE__ */ getFallback(valueSchema);
|
|
722
|
+
else if (valueSchema.type !== "exact_optional" && valueSchema.type !== "optional" && valueSchema.type !== "nullish") {
|
|
723
|
+
_addIssue(this, "key", dataset, config$1, {
|
|
724
|
+
input: void 0,
|
|
725
|
+
expected: `"${key}"`,
|
|
726
|
+
path: [{
|
|
727
|
+
type: "object",
|
|
728
|
+
origin: "key",
|
|
729
|
+
input,
|
|
730
|
+
key,
|
|
731
|
+
value: input[key]
|
|
732
|
+
}]
|
|
733
|
+
});
|
|
734
|
+
if (config$1.abortEarly) break;
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
} else _addIssue(this, "type", dataset, config$1);
|
|
738
|
+
return dataset;
|
|
739
|
+
}
|
|
740
|
+
});
|
|
741
|
+
}
|
|
742
|
+
__name(object, "object");
|
|
743
|
+
// @__NO_SIDE_EFFECTS__
|
|
744
|
+
function objectWithRest(entries$1, rest, message$1) {
|
|
745
|
+
return _standardSchema({
|
|
746
|
+
kind: "schema",
|
|
747
|
+
type: "object_with_rest",
|
|
748
|
+
reference: objectWithRest,
|
|
749
|
+
expects: "Object",
|
|
750
|
+
async: false,
|
|
751
|
+
entries: entries$1,
|
|
752
|
+
rest,
|
|
753
|
+
message: message$1,
|
|
754
|
+
"~run"(dataset, config$1) {
|
|
755
|
+
const input = dataset.value;
|
|
756
|
+
if (input && typeof input === "object") {
|
|
757
|
+
dataset.typed = true;
|
|
758
|
+
dataset.value = {};
|
|
759
|
+
for (const key in this.entries) {
|
|
760
|
+
const valueSchema = this.entries[key];
|
|
761
|
+
if (key in input || (valueSchema.type === "exact_optional" || valueSchema.type === "optional" || valueSchema.type === "nullish") && valueSchema.default !== void 0) {
|
|
762
|
+
const value$1 = key in input ? input[key] : /* @__PURE__ */ getDefault(valueSchema);
|
|
763
|
+
const valueDataset = valueSchema["~run"]({ value: value$1 }, config$1);
|
|
764
|
+
if (valueDataset.issues) {
|
|
765
|
+
const pathItem = {
|
|
766
|
+
type: "object",
|
|
767
|
+
origin: "value",
|
|
768
|
+
input,
|
|
769
|
+
key,
|
|
770
|
+
value: value$1
|
|
771
|
+
};
|
|
772
|
+
for (const issue of valueDataset.issues) {
|
|
773
|
+
if (issue.path) issue.path.unshift(pathItem);
|
|
774
|
+
else issue.path = [pathItem];
|
|
775
|
+
dataset.issues?.push(issue);
|
|
776
|
+
}
|
|
777
|
+
if (!dataset.issues) dataset.issues = valueDataset.issues;
|
|
778
|
+
if (config$1.abortEarly) {
|
|
779
|
+
dataset.typed = false;
|
|
780
|
+
break;
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
if (!valueDataset.typed) dataset.typed = false;
|
|
784
|
+
dataset.value[key] = valueDataset.value;
|
|
785
|
+
} else if (valueSchema.fallback !== void 0) dataset.value[key] = /* @__PURE__ */ getFallback(valueSchema);
|
|
786
|
+
else if (valueSchema.type !== "exact_optional" && valueSchema.type !== "optional" && valueSchema.type !== "nullish") {
|
|
787
|
+
_addIssue(this, "key", dataset, config$1, {
|
|
788
|
+
input: void 0,
|
|
789
|
+
expected: `"${key}"`,
|
|
790
|
+
path: [{
|
|
791
|
+
type: "object",
|
|
792
|
+
origin: "key",
|
|
793
|
+
input,
|
|
794
|
+
key,
|
|
795
|
+
value: input[key]
|
|
796
|
+
}]
|
|
797
|
+
});
|
|
798
|
+
if (config$1.abortEarly) break;
|
|
799
|
+
}
|
|
800
|
+
}
|
|
801
|
+
if (!dataset.issues || !config$1.abortEarly) {
|
|
802
|
+
for (const key in input) if (/* @__PURE__ */ _isValidObjectKey(input, key) && !Object.prototype.hasOwnProperty.call(this.entries, key)) {
|
|
803
|
+
const valueDataset = this.rest["~run"]({ value: input[key] }, config$1);
|
|
804
|
+
if (valueDataset.issues) {
|
|
805
|
+
const pathItem = {
|
|
806
|
+
type: "object",
|
|
807
|
+
origin: "value",
|
|
808
|
+
input,
|
|
809
|
+
key,
|
|
810
|
+
value: input[key]
|
|
811
|
+
};
|
|
812
|
+
for (const issue of valueDataset.issues) {
|
|
813
|
+
if (issue.path) issue.path.unshift(pathItem);
|
|
814
|
+
else issue.path = [pathItem];
|
|
815
|
+
dataset.issues?.push(issue);
|
|
816
|
+
}
|
|
817
|
+
if (!dataset.issues) dataset.issues = valueDataset.issues;
|
|
818
|
+
if (config$1.abortEarly) {
|
|
819
|
+
dataset.typed = false;
|
|
820
|
+
break;
|
|
821
|
+
}
|
|
822
|
+
}
|
|
823
|
+
if (!valueDataset.typed) dataset.typed = false;
|
|
824
|
+
dataset.value[key] = valueDataset.value;
|
|
825
|
+
}
|
|
826
|
+
}
|
|
827
|
+
} else _addIssue(this, "type", dataset, config$1);
|
|
828
|
+
return dataset;
|
|
829
|
+
}
|
|
830
|
+
});
|
|
831
|
+
}
|
|
832
|
+
__name(objectWithRest, "objectWithRest");
|
|
833
|
+
// @__NO_SIDE_EFFECTS__
|
|
834
|
+
function optional(wrapped, default_) {
|
|
835
|
+
return _standardSchema({
|
|
836
|
+
kind: "schema",
|
|
837
|
+
type: "optional",
|
|
838
|
+
reference: optional,
|
|
839
|
+
expects: `(${wrapped.expects} | undefined)`,
|
|
840
|
+
async: false,
|
|
841
|
+
wrapped,
|
|
842
|
+
default: default_,
|
|
843
|
+
"~run"(dataset, config$1) {
|
|
844
|
+
if (dataset.value === void 0) {
|
|
845
|
+
if (this.default !== void 0) dataset.value = /* @__PURE__ */ getDefault(this, dataset, config$1);
|
|
846
|
+
if (dataset.value === void 0) {
|
|
847
|
+
dataset.typed = true;
|
|
848
|
+
return dataset;
|
|
849
|
+
}
|
|
850
|
+
}
|
|
851
|
+
return this.wrapped["~run"](dataset, config$1);
|
|
852
|
+
}
|
|
853
|
+
});
|
|
854
|
+
}
|
|
855
|
+
__name(optional, "optional");
|
|
856
|
+
// @__NO_SIDE_EFFECTS__
|
|
857
|
+
function picklist(options, message$1) {
|
|
858
|
+
return _standardSchema({
|
|
859
|
+
kind: "schema",
|
|
860
|
+
type: "picklist",
|
|
861
|
+
reference: picklist,
|
|
862
|
+
expects: /* @__PURE__ */ _joinExpects(options.map(_stringify), "|"),
|
|
863
|
+
async: false,
|
|
864
|
+
options,
|
|
865
|
+
message: message$1,
|
|
866
|
+
"~run"(dataset, config$1) {
|
|
867
|
+
if (this.options.includes(dataset.value)) dataset.typed = true;
|
|
868
|
+
else _addIssue(this, "type", dataset, config$1);
|
|
869
|
+
return dataset;
|
|
870
|
+
}
|
|
871
|
+
});
|
|
872
|
+
}
|
|
873
|
+
__name(picklist, "picklist");
|
|
874
|
+
// @__NO_SIDE_EFFECTS__
|
|
875
|
+
function record(key, value$1, message$1) {
|
|
876
|
+
return _standardSchema({
|
|
877
|
+
kind: "schema",
|
|
878
|
+
type: "record",
|
|
879
|
+
reference: record,
|
|
880
|
+
expects: "Object",
|
|
881
|
+
async: false,
|
|
882
|
+
key,
|
|
883
|
+
value: value$1,
|
|
884
|
+
message: message$1,
|
|
885
|
+
"~run"(dataset, config$1) {
|
|
886
|
+
const input = dataset.value;
|
|
887
|
+
if (input && typeof input === "object") {
|
|
888
|
+
dataset.typed = true;
|
|
889
|
+
dataset.value = {};
|
|
890
|
+
for (const entryKey in input) if (/* @__PURE__ */ _isValidObjectKey(input, entryKey)) {
|
|
891
|
+
const entryValue = input[entryKey];
|
|
892
|
+
const keyDataset = this.key["~run"]({ value: entryKey }, config$1);
|
|
893
|
+
if (keyDataset.issues) {
|
|
894
|
+
const pathItem = {
|
|
895
|
+
type: "object",
|
|
896
|
+
origin: "key",
|
|
897
|
+
input,
|
|
898
|
+
key: entryKey,
|
|
899
|
+
value: entryValue
|
|
900
|
+
};
|
|
901
|
+
for (const issue of keyDataset.issues) {
|
|
902
|
+
issue.path = [pathItem];
|
|
903
|
+
dataset.issues?.push(issue);
|
|
904
|
+
}
|
|
905
|
+
if (!dataset.issues) dataset.issues = keyDataset.issues;
|
|
906
|
+
if (config$1.abortEarly) {
|
|
907
|
+
dataset.typed = false;
|
|
908
|
+
break;
|
|
909
|
+
}
|
|
910
|
+
}
|
|
911
|
+
const valueDataset = this.value["~run"]({ value: entryValue }, config$1);
|
|
912
|
+
if (valueDataset.issues) {
|
|
913
|
+
const pathItem = {
|
|
914
|
+
type: "object",
|
|
915
|
+
origin: "value",
|
|
916
|
+
input,
|
|
917
|
+
key: entryKey,
|
|
918
|
+
value: entryValue
|
|
919
|
+
};
|
|
920
|
+
for (const issue of valueDataset.issues) {
|
|
921
|
+
if (issue.path) issue.path.unshift(pathItem);
|
|
922
|
+
else issue.path = [pathItem];
|
|
923
|
+
dataset.issues?.push(issue);
|
|
924
|
+
}
|
|
925
|
+
if (!dataset.issues) dataset.issues = valueDataset.issues;
|
|
926
|
+
if (config$1.abortEarly) {
|
|
927
|
+
dataset.typed = false;
|
|
928
|
+
break;
|
|
929
|
+
}
|
|
930
|
+
}
|
|
931
|
+
if (!keyDataset.typed || !valueDataset.typed) dataset.typed = false;
|
|
932
|
+
if (keyDataset.typed) dataset.value[keyDataset.value] = valueDataset.value;
|
|
933
|
+
}
|
|
934
|
+
} else _addIssue(this, "type", dataset, config$1);
|
|
935
|
+
return dataset;
|
|
936
|
+
}
|
|
937
|
+
});
|
|
938
|
+
}
|
|
939
|
+
__name(record, "record");
|
|
940
|
+
// @__NO_SIDE_EFFECTS__
|
|
941
|
+
function strictObject(entries$1, message$1) {
|
|
942
|
+
return _standardSchema({
|
|
943
|
+
kind: "schema",
|
|
944
|
+
type: "strict_object",
|
|
945
|
+
reference: strictObject,
|
|
946
|
+
expects: "Object",
|
|
947
|
+
async: false,
|
|
948
|
+
entries: entries$1,
|
|
949
|
+
message: message$1,
|
|
950
|
+
"~run"(dataset, config$1) {
|
|
951
|
+
const input = dataset.value;
|
|
952
|
+
if (input && typeof input === "object") {
|
|
953
|
+
dataset.typed = true;
|
|
954
|
+
dataset.value = {};
|
|
955
|
+
for (const key in this.entries) {
|
|
956
|
+
const valueSchema = this.entries[key];
|
|
957
|
+
if (key in input || (valueSchema.type === "exact_optional" || valueSchema.type === "optional" || valueSchema.type === "nullish") && valueSchema.default !== void 0) {
|
|
958
|
+
const value$1 = key in input ? input[key] : /* @__PURE__ */ getDefault(valueSchema);
|
|
959
|
+
const valueDataset = valueSchema["~run"]({ value: value$1 }, config$1);
|
|
960
|
+
if (valueDataset.issues) {
|
|
961
|
+
const pathItem = {
|
|
962
|
+
type: "object",
|
|
963
|
+
origin: "value",
|
|
964
|
+
input,
|
|
965
|
+
key,
|
|
966
|
+
value: value$1
|
|
967
|
+
};
|
|
968
|
+
for (const issue of valueDataset.issues) {
|
|
969
|
+
if (issue.path) issue.path.unshift(pathItem);
|
|
970
|
+
else issue.path = [pathItem];
|
|
971
|
+
dataset.issues?.push(issue);
|
|
972
|
+
}
|
|
973
|
+
if (!dataset.issues) dataset.issues = valueDataset.issues;
|
|
974
|
+
if (config$1.abortEarly) {
|
|
975
|
+
dataset.typed = false;
|
|
976
|
+
break;
|
|
977
|
+
}
|
|
978
|
+
}
|
|
979
|
+
if (!valueDataset.typed) dataset.typed = false;
|
|
980
|
+
dataset.value[key] = valueDataset.value;
|
|
981
|
+
} else if (valueSchema.fallback !== void 0) dataset.value[key] = /* @__PURE__ */ getFallback(valueSchema);
|
|
982
|
+
else if (valueSchema.type !== "exact_optional" && valueSchema.type !== "optional" && valueSchema.type !== "nullish") {
|
|
983
|
+
_addIssue(this, "key", dataset, config$1, {
|
|
984
|
+
input: void 0,
|
|
985
|
+
expected: `"${key}"`,
|
|
986
|
+
path: [{
|
|
987
|
+
type: "object",
|
|
988
|
+
origin: "key",
|
|
989
|
+
input,
|
|
990
|
+
key,
|
|
991
|
+
value: input[key]
|
|
992
|
+
}]
|
|
993
|
+
});
|
|
994
|
+
if (config$1.abortEarly) break;
|
|
995
|
+
}
|
|
996
|
+
}
|
|
997
|
+
if (!dataset.issues || !config$1.abortEarly) {
|
|
998
|
+
for (const key in input) if (!Object.prototype.hasOwnProperty.call(this.entries, key)) {
|
|
999
|
+
_addIssue(this, "key", dataset, config$1, {
|
|
1000
|
+
input: key,
|
|
1001
|
+
expected: "never",
|
|
1002
|
+
path: [{
|
|
1003
|
+
type: "object",
|
|
1004
|
+
origin: "key",
|
|
1005
|
+
input,
|
|
1006
|
+
key,
|
|
1007
|
+
value: input[key]
|
|
1008
|
+
}]
|
|
1009
|
+
});
|
|
1010
|
+
break;
|
|
1011
|
+
}
|
|
1012
|
+
}
|
|
1013
|
+
} else _addIssue(this, "type", dataset, config$1);
|
|
1014
|
+
return dataset;
|
|
1015
|
+
}
|
|
1016
|
+
});
|
|
1017
|
+
}
|
|
1018
|
+
__name(strictObject, "strictObject");
|
|
1019
|
+
// @__NO_SIDE_EFFECTS__
|
|
1020
|
+
function string(message$1) {
|
|
1021
|
+
return _standardSchema({
|
|
1022
|
+
kind: "schema",
|
|
1023
|
+
type: "string",
|
|
1024
|
+
reference: string,
|
|
1025
|
+
expects: "string",
|
|
1026
|
+
async: false,
|
|
1027
|
+
message: message$1,
|
|
1028
|
+
"~run"(dataset, config$1) {
|
|
1029
|
+
if (typeof dataset.value === "string") dataset.typed = true;
|
|
1030
|
+
else _addIssue(this, "type", dataset, config$1);
|
|
1031
|
+
return dataset;
|
|
1032
|
+
}
|
|
1033
|
+
});
|
|
1034
|
+
}
|
|
1035
|
+
__name(string, "string");
|
|
1036
|
+
// @__NO_SIDE_EFFECTS__
|
|
1037
|
+
function _subIssues(datasets) {
|
|
1038
|
+
let issues;
|
|
1039
|
+
if (datasets) for (const dataset of datasets) if (issues) for (const issue of dataset.issues) issues.push(issue);
|
|
1040
|
+
else issues = dataset.issues;
|
|
1041
|
+
return issues;
|
|
1042
|
+
}
|
|
1043
|
+
__name(_subIssues, "_subIssues");
|
|
1044
|
+
// @__NO_SIDE_EFFECTS__
|
|
1045
|
+
function union(options, message$1) {
|
|
1046
|
+
return _standardSchema({
|
|
1047
|
+
kind: "schema",
|
|
1048
|
+
type: "union",
|
|
1049
|
+
reference: union,
|
|
1050
|
+
expects: /* @__PURE__ */ _joinExpects(options.map((option) => option.expects), "|"),
|
|
1051
|
+
async: false,
|
|
1052
|
+
options,
|
|
1053
|
+
message: message$1,
|
|
1054
|
+
"~run"(dataset, config$1) {
|
|
1055
|
+
let validDataset;
|
|
1056
|
+
let typedDatasets;
|
|
1057
|
+
let untypedDatasets;
|
|
1058
|
+
for (const schema of this.options) {
|
|
1059
|
+
const optionDataset = schema["~run"]({ value: dataset.value }, config$1);
|
|
1060
|
+
if (optionDataset.typed) if (optionDataset.issues) if (typedDatasets) typedDatasets.push(optionDataset);
|
|
1061
|
+
else typedDatasets = [optionDataset];
|
|
1062
|
+
else {
|
|
1063
|
+
validDataset = optionDataset;
|
|
1064
|
+
break;
|
|
1065
|
+
}
|
|
1066
|
+
else if (untypedDatasets) untypedDatasets.push(optionDataset);
|
|
1067
|
+
else untypedDatasets = [optionDataset];
|
|
1068
|
+
}
|
|
1069
|
+
if (validDataset) return validDataset;
|
|
1070
|
+
if (typedDatasets) {
|
|
1071
|
+
if (typedDatasets.length === 1) return typedDatasets[0];
|
|
1072
|
+
_addIssue(this, "type", dataset, config$1, { issues: /* @__PURE__ */ _subIssues(typedDatasets) });
|
|
1073
|
+
dataset.typed = true;
|
|
1074
|
+
} else if (untypedDatasets?.length === 1) return untypedDatasets[0];
|
|
1075
|
+
else _addIssue(this, "type", dataset, config$1, { issues: /* @__PURE__ */ _subIssues(untypedDatasets) });
|
|
1076
|
+
return dataset;
|
|
1077
|
+
}
|
|
1078
|
+
});
|
|
1079
|
+
}
|
|
1080
|
+
__name(union, "union");
|
|
1081
|
+
// @__NO_SIDE_EFFECTS__
|
|
1082
|
+
function unknown() {
|
|
1083
|
+
return _standardSchema({
|
|
1084
|
+
kind: "schema",
|
|
1085
|
+
type: "unknown",
|
|
1086
|
+
reference: unknown,
|
|
1087
|
+
expects: "unknown",
|
|
1088
|
+
async: false,
|
|
1089
|
+
"~run"(dataset) {
|
|
1090
|
+
dataset.typed = true;
|
|
1091
|
+
return dataset;
|
|
1092
|
+
}
|
|
1093
|
+
});
|
|
1094
|
+
}
|
|
1095
|
+
__name(unknown, "unknown");
|
|
1096
|
+
// @__NO_SIDE_EFFECTS__
|
|
1097
|
+
function variant(key, options, message$1) {
|
|
1098
|
+
return _standardSchema({
|
|
1099
|
+
kind: "schema",
|
|
1100
|
+
type: "variant",
|
|
1101
|
+
reference: variant,
|
|
1102
|
+
expects: "Object",
|
|
1103
|
+
async: false,
|
|
1104
|
+
key,
|
|
1105
|
+
options,
|
|
1106
|
+
message: message$1,
|
|
1107
|
+
"~run"(dataset, config$1) {
|
|
1108
|
+
const input = dataset.value;
|
|
1109
|
+
if (input && typeof input === "object") {
|
|
1110
|
+
let outputDataset;
|
|
1111
|
+
let maxDiscriminatorPriority = 0;
|
|
1112
|
+
let invalidDiscriminatorKey = this.key;
|
|
1113
|
+
let expectedDiscriminators = [];
|
|
1114
|
+
const parseOptions = /* @__PURE__ */ __name((variant$1, allKeys) => {
|
|
1115
|
+
for (const schema of variant$1.options) {
|
|
1116
|
+
if (schema.type === "variant") parseOptions(schema, new Set(allKeys).add(schema.key));
|
|
1117
|
+
else {
|
|
1118
|
+
let keysAreValid = true;
|
|
1119
|
+
let currentPriority = 0;
|
|
1120
|
+
for (const currentKey of allKeys) {
|
|
1121
|
+
const discriminatorSchema = schema.entries[currentKey];
|
|
1122
|
+
if (currentKey in input ? discriminatorSchema["~run"]({
|
|
1123
|
+
typed: false,
|
|
1124
|
+
value: input[currentKey]
|
|
1125
|
+
}, ABORT_EARLY_CONFIG).issues : discriminatorSchema.type !== "exact_optional" && discriminatorSchema.type !== "optional" && discriminatorSchema.type !== "nullish") {
|
|
1126
|
+
keysAreValid = false;
|
|
1127
|
+
if (invalidDiscriminatorKey !== currentKey && (maxDiscriminatorPriority < currentPriority || maxDiscriminatorPriority === currentPriority && currentKey in input && !(invalidDiscriminatorKey in input))) {
|
|
1128
|
+
maxDiscriminatorPriority = currentPriority;
|
|
1129
|
+
invalidDiscriminatorKey = currentKey;
|
|
1130
|
+
expectedDiscriminators = [];
|
|
1131
|
+
}
|
|
1132
|
+
if (invalidDiscriminatorKey === currentKey) expectedDiscriminators.push(schema.entries[currentKey].expects);
|
|
1133
|
+
break;
|
|
1134
|
+
}
|
|
1135
|
+
currentPriority++;
|
|
1136
|
+
}
|
|
1137
|
+
if (keysAreValid) {
|
|
1138
|
+
const optionDataset = schema["~run"]({ value: input }, config$1);
|
|
1139
|
+
if (!outputDataset || !outputDataset.typed && optionDataset.typed) outputDataset = optionDataset;
|
|
1140
|
+
}
|
|
1141
|
+
}
|
|
1142
|
+
if (outputDataset && !outputDataset.issues) break;
|
|
1143
|
+
}
|
|
1144
|
+
}, "parseOptions");
|
|
1145
|
+
parseOptions(this, /* @__PURE__ */ new Set([this.key]));
|
|
1146
|
+
if (outputDataset) return outputDataset;
|
|
1147
|
+
_addIssue(this, "type", dataset, config$1, {
|
|
1148
|
+
input: input[invalidDiscriminatorKey],
|
|
1149
|
+
expected: /* @__PURE__ */ _joinExpects(expectedDiscriminators, "|"),
|
|
1150
|
+
path: [{
|
|
1151
|
+
type: "object",
|
|
1152
|
+
origin: "value",
|
|
1153
|
+
input,
|
|
1154
|
+
key: invalidDiscriminatorKey,
|
|
1155
|
+
value: input[invalidDiscriminatorKey]
|
|
1156
|
+
}]
|
|
1157
|
+
});
|
|
1158
|
+
} else _addIssue(this, "type", dataset, config$1);
|
|
1159
|
+
return dataset;
|
|
1160
|
+
}
|
|
1161
|
+
});
|
|
1162
|
+
}
|
|
1163
|
+
__name(variant, "variant");
|
|
1164
|
+
// @__NO_SIDE_EFFECTS__
|
|
1165
|
+
function omit(schema, keys) {
|
|
1166
|
+
const entries$1 = { ...schema.entries };
|
|
1167
|
+
for (const key of keys) delete entries$1[key];
|
|
1168
|
+
return _standardSchema({
|
|
1169
|
+
...schema,
|
|
1170
|
+
entries: entries$1
|
|
1171
|
+
});
|
|
1172
|
+
}
|
|
1173
|
+
__name(omit, "omit");
|
|
1174
|
+
function parse(schema, input, config$1) {
|
|
1175
|
+
const dataset = schema["~run"]({ value: input }, /* @__PURE__ */ getGlobalConfig(config$1));
|
|
1176
|
+
if (dataset.issues) throw new ValiError(dataset.issues);
|
|
1177
|
+
return dataset.value;
|
|
1178
|
+
}
|
|
1179
|
+
__name(parse, "parse");
|
|
1180
|
+
// @__NO_SIDE_EFFECTS__
|
|
1181
|
+
function partial(schema, keys) {
|
|
1182
|
+
const entries$1 = {};
|
|
1183
|
+
for (const key in schema.entries) entries$1[key] = !keys || keys.includes(key) ? /* @__PURE__ */ optional(schema.entries[key]) : schema.entries[key];
|
|
1184
|
+
return _standardSchema({
|
|
1185
|
+
...schema,
|
|
1186
|
+
entries: entries$1
|
|
1187
|
+
});
|
|
1188
|
+
}
|
|
1189
|
+
__name(partial, "partial");
|
|
1190
|
+
// @__NO_SIDE_EFFECTS__
|
|
1191
|
+
function pick(schema, keys) {
|
|
1192
|
+
const entries$1 = {};
|
|
1193
|
+
for (const key of keys) entries$1[key] = schema.entries[key];
|
|
1194
|
+
return _standardSchema({
|
|
1195
|
+
...schema,
|
|
1196
|
+
entries: entries$1
|
|
1197
|
+
});
|
|
1198
|
+
}
|
|
1199
|
+
__name(pick, "pick");
|
|
1200
|
+
// @__NO_SIDE_EFFECTS__
|
|
1201
|
+
function pipe(...pipe$1) {
|
|
1202
|
+
return _standardSchema({
|
|
1203
|
+
...pipe$1[0],
|
|
1204
|
+
pipe: pipe$1,
|
|
1205
|
+
"~run"(dataset, config$1) {
|
|
1206
|
+
for (const item of pipe$1) if (item.kind !== "metadata") {
|
|
1207
|
+
if (dataset.issues && (item.kind === "schema" || item.kind === "transformation")) {
|
|
1208
|
+
dataset.typed = false;
|
|
1209
|
+
break;
|
|
1210
|
+
}
|
|
1211
|
+
if (!dataset.issues || !config$1.abortEarly && !config$1.abortPipeEarly) dataset = item["~run"](dataset, config$1);
|
|
1212
|
+
}
|
|
1213
|
+
return dataset;
|
|
1214
|
+
}
|
|
1215
|
+
});
|
|
1216
|
+
}
|
|
1217
|
+
__name(pipe, "pipe");
|
|
1218
|
+
// @__NO_SIDE_EFFECTS__
|
|
1219
|
+
function safeParse(schema, input, config$1) {
|
|
1220
|
+
const dataset = schema["~run"]({ value: input }, /* @__PURE__ */ getGlobalConfig(config$1));
|
|
1221
|
+
return {
|
|
1222
|
+
typed: dataset.typed,
|
|
1223
|
+
success: !dataset.issues,
|
|
1224
|
+
output: dataset.value,
|
|
1225
|
+
issues: dataset.issues
|
|
1226
|
+
};
|
|
1227
|
+
}
|
|
1228
|
+
__name(safeParse, "safeParse");
|
|
1229
|
+
// @__NO_SIDE_EFFECTS__
|
|
1230
|
+
function summarize(issues) {
|
|
1231
|
+
let summary = "";
|
|
1232
|
+
for (const issue of issues) {
|
|
1233
|
+
if (summary) summary += "\n";
|
|
1234
|
+
summary += `\xD7 ${issue.message}`;
|
|
1235
|
+
const dotPath = /* @__PURE__ */ getDotPath(issue);
|
|
1236
|
+
if (dotPath) summary += `
|
|
1237
|
+
\u2192 at ${dotPath}`;
|
|
1238
|
+
}
|
|
1239
|
+
return summary;
|
|
1240
|
+
}
|
|
1241
|
+
__name(summarize, "summarize");
|
|
1242
|
+
// @__NO_SIDE_EFFECTS__
|
|
1243
|
+
function unwrap(schema) {
|
|
1244
|
+
return schema.wrapped;
|
|
1245
|
+
}
|
|
1246
|
+
__name(unwrap, "unwrap");
|
|
1247
|
+
|
|
1248
|
+
// node_modules/.pnpm/@wirecat+cli-base@0.68.1_commander@15.0.0_esbuild@0.28.2_typescript@7.0.2_vitest@5.0.5/node_modules/@wirecat/cli-base/dist/standards/effects.js
|
|
1249
|
+
var EFFECT_LEVELS = ["none", "read", "write"];
|
|
1250
|
+
var effectsSchema = strictObject({
|
|
1251
|
+
remote: picklist(EFFECT_LEVELS),
|
|
1252
|
+
local: picklist(EFFECT_LEVELS)
|
|
1253
|
+
});
|
|
1254
|
+
var writes = /* @__PURE__ */ __name((effects) => effects === void 0 || effects.remote === "write" || effects.local === "write", "writes");
|
|
1255
|
+
|
|
1256
|
+
// node_modules/.pnpm/@valibot+to-json-schema@1.8.0_valibot@1.5.0_typescript@7.0.2_/node_modules/@valibot/to-json-schema/dist/index.mjs
|
|
1257
|
+
function addError(errors, message) {
|
|
1258
|
+
if (errors) {
|
|
1259
|
+
errors.push(message);
|
|
1260
|
+
return errors;
|
|
1261
|
+
}
|
|
1262
|
+
return [message];
|
|
1263
|
+
}
|
|
1264
|
+
__name(addError, "addError");
|
|
1265
|
+
var ESCAPE_REGEX = /[.*+?^${}()|[\]\\]/g;
|
|
1266
|
+
function escapeRegExp(string2) {
|
|
1267
|
+
return string2.replace(ESCAPE_REGEX, "\\$&");
|
|
1268
|
+
}
|
|
1269
|
+
__name(escapeRegExp, "escapeRegExp");
|
|
1270
|
+
function handleError(message, config) {
|
|
1271
|
+
switch (config?.errorMode) {
|
|
1272
|
+
case "ignore":
|
|
1273
|
+
break;
|
|
1274
|
+
case "warn":
|
|
1275
|
+
console.warn(message);
|
|
1276
|
+
break;
|
|
1277
|
+
default:
|
|
1278
|
+
throw new Error(message);
|
|
1279
|
+
}
|
|
1280
|
+
}
|
|
1281
|
+
__name(handleError, "handleError");
|
|
1282
|
+
function isJsonConstValue(value) {
|
|
1283
|
+
return typeof value === "boolean" || typeof value === "number" && Number.isFinite(value) || typeof value === "string";
|
|
1284
|
+
}
|
|
1285
|
+
__name(isJsonConstValue, "isJsonConstValue");
|
|
1286
|
+
function isJsonEnumValues(values) {
|
|
1287
|
+
return values.every(isJsonConstValue);
|
|
1288
|
+
}
|
|
1289
|
+
__name(isJsonEnumValues, "isJsonEnumValues");
|
|
1290
|
+
var ReferenceMap = class extends Map {
|
|
1291
|
+
static {
|
|
1292
|
+
__name(this, "ReferenceMap");
|
|
1293
|
+
}
|
|
1294
|
+
/**
|
|
1295
|
+
* Creates an empty schema reference map.
|
|
1296
|
+
*/
|
|
1297
|
+
constructor() {
|
|
1298
|
+
super();
|
|
1299
|
+
this.count = 0;
|
|
1300
|
+
this.usedIds = /* @__PURE__ */ new Set();
|
|
1301
|
+
}
|
|
1302
|
+
/**
|
|
1303
|
+
* Adds a schema reference and reserves its ID.
|
|
1304
|
+
*
|
|
1305
|
+
* @param schema The Valibot schema.
|
|
1306
|
+
* @param referenceId The reference ID.
|
|
1307
|
+
*
|
|
1308
|
+
* @returns The reference map.
|
|
1309
|
+
*/
|
|
1310
|
+
set(schema, referenceId) {
|
|
1311
|
+
this.usedIds.add(referenceId);
|
|
1312
|
+
return super.set(schema, referenceId);
|
|
1313
|
+
}
|
|
1314
|
+
/**
|
|
1315
|
+
* Creates a reference ID that is not yet used.
|
|
1316
|
+
*
|
|
1317
|
+
* @param definitions The JSON Schema definitions.
|
|
1318
|
+
*
|
|
1319
|
+
* @returns The unused reference ID.
|
|
1320
|
+
*/
|
|
1321
|
+
createId(definitions) {
|
|
1322
|
+
while (this.usedIds.has(`${this.count}`) || `${this.count}` in definitions) this.count++;
|
|
1323
|
+
return `${this.count++}`;
|
|
1324
|
+
}
|
|
1325
|
+
};
|
|
1326
|
+
function getLowerBound(current, value) {
|
|
1327
|
+
if (typeof current !== "number" || !Number.isFinite(current) || value > current) return value;
|
|
1328
|
+
return current;
|
|
1329
|
+
}
|
|
1330
|
+
__name(getLowerBound, "getLowerBound");
|
|
1331
|
+
function getUpperBound(current, value) {
|
|
1332
|
+
if (typeof current !== "number" || !Number.isFinite(current) || value < current) return value;
|
|
1333
|
+
return current;
|
|
1334
|
+
}
|
|
1335
|
+
__name(getUpperBound, "getUpperBound");
|
|
1336
|
+
// @__NO_SIDE_EFFECTS__
|
|
1337
|
+
function getNotRestriction(current, value) {
|
|
1338
|
+
return current !== void 0 ? { anyOf: [current, value] } : value;
|
|
1339
|
+
}
|
|
1340
|
+
__name(getNotRestriction, "getNotRestriction");
|
|
1341
|
+
function intersectEnum(jsonSchema, values) {
|
|
1342
|
+
let enumValues = jsonSchema.enum ?? values;
|
|
1343
|
+
if (jsonSchema.enum) {
|
|
1344
|
+
const valueSet = new Set(values);
|
|
1345
|
+
enumValues = enumValues.filter((value) => valueSet.has(value));
|
|
1346
|
+
}
|
|
1347
|
+
if (enumValues.length) jsonSchema.enum = [...new Set(enumValues)];
|
|
1348
|
+
else {
|
|
1349
|
+
delete jsonSchema.enum;
|
|
1350
|
+
jsonSchema.not = /* @__PURE__ */ getNotRestriction(jsonSchema.not, {});
|
|
1351
|
+
}
|
|
1352
|
+
}
|
|
1353
|
+
__name(intersectEnum, "intersectEnum");
|
|
1354
|
+
function convertAction(jsonSchema, valibotAction, config) {
|
|
1355
|
+
if (config?.ignoreActions?.includes(valibotAction.type)) return jsonSchema;
|
|
1356
|
+
let errors;
|
|
1357
|
+
switch (valibotAction.type) {
|
|
1358
|
+
case "base64":
|
|
1359
|
+
jsonSchema.contentEncoding = "base64";
|
|
1360
|
+
break;
|
|
1361
|
+
case "bic":
|
|
1362
|
+
case "cuid2":
|
|
1363
|
+
case "decimal":
|
|
1364
|
+
case "digits":
|
|
1365
|
+
case "domain":
|
|
1366
|
+
case "emoji":
|
|
1367
|
+
case "hash":
|
|
1368
|
+
case "hexadecimal":
|
|
1369
|
+
case "hex_color":
|
|
1370
|
+
case "isrc":
|
|
1371
|
+
case "iso_time_second":
|
|
1372
|
+
case "iso_week":
|
|
1373
|
+
case "ksuid":
|
|
1374
|
+
case "mac":
|
|
1375
|
+
case "mac48":
|
|
1376
|
+
case "mac64":
|
|
1377
|
+
case "nanoid":
|
|
1378
|
+
case "octal":
|
|
1379
|
+
case "slug":
|
|
1380
|
+
case "ulid":
|
|
1381
|
+
if (jsonSchema.pattern) errors = addError(errors, `The "${valibotAction.type}" action is not supported in combination with another regex action.`);
|
|
1382
|
+
else jsonSchema.pattern = valibotAction.requirement.source;
|
|
1383
|
+
break;
|
|
1384
|
+
case "description":
|
|
1385
|
+
jsonSchema.description = valibotAction.description;
|
|
1386
|
+
break;
|
|
1387
|
+
case "email":
|
|
1388
|
+
case "rfc_email":
|
|
1389
|
+
jsonSchema.format = "email";
|
|
1390
|
+
break;
|
|
1391
|
+
case "ends_with":
|
|
1392
|
+
if (jsonSchema.pattern) errors = addError(errors, `The "${valibotAction.type}" action is not supported in combination with another regex action.`);
|
|
1393
|
+
else jsonSchema.pattern = `${escapeRegExp(valibotAction.requirement)}$`;
|
|
1394
|
+
break;
|
|
1395
|
+
case "empty":
|
|
1396
|
+
if (jsonSchema.type === "array") jsonSchema.maxItems = 0;
|
|
1397
|
+
else {
|
|
1398
|
+
if (jsonSchema.type !== "string") errors = addError(errors, `The "${valibotAction.type}" action is not supported on type "${jsonSchema.type}".`);
|
|
1399
|
+
jsonSchema.maxLength = 0;
|
|
1400
|
+
}
|
|
1401
|
+
break;
|
|
1402
|
+
case "entries":
|
|
1403
|
+
if (!Number.isInteger(valibotAction.requirement) || valibotAction.requirement < 0) {
|
|
1404
|
+
errors = addError(errors, 'The requirement of the "entries" action must be a non-negative integer.');
|
|
1405
|
+
break;
|
|
1406
|
+
}
|
|
1407
|
+
jsonSchema.minProperties = getLowerBound(jsonSchema.minProperties, valibotAction.requirement);
|
|
1408
|
+
jsonSchema.maxProperties = getUpperBound(jsonSchema.maxProperties, valibotAction.requirement);
|
|
1409
|
+
break;
|
|
1410
|
+
case "examples":
|
|
1411
|
+
if (Array.isArray(jsonSchema.examples)) jsonSchema.examples = [...jsonSchema.examples, ...valibotAction.examples];
|
|
1412
|
+
else jsonSchema.examples = valibotAction.examples;
|
|
1413
|
+
break;
|
|
1414
|
+
case "gt_value":
|
|
1415
|
+
if (jsonSchema.type !== "number" && jsonSchema.type !== "integer") {
|
|
1416
|
+
errors = addError(errors, `The "gt_value" action is not supported on type "${jsonSchema.type}".`);
|
|
1417
|
+
break;
|
|
1418
|
+
}
|
|
1419
|
+
if (!Number.isFinite(valibotAction.requirement)) {
|
|
1420
|
+
errors = addError(errors, 'The requirement of the "gt_value" action is not JSON compatible.');
|
|
1421
|
+
break;
|
|
1422
|
+
}
|
|
1423
|
+
if (config?.target === "openapi-3.0") {
|
|
1424
|
+
errors = addError(errors, 'The "gt_value" action is not supported for OpenAPI 3.0.');
|
|
1425
|
+
break;
|
|
1426
|
+
}
|
|
1427
|
+
jsonSchema.exclusiveMinimum = getLowerBound(jsonSchema.exclusiveMinimum, valibotAction.requirement);
|
|
1428
|
+
break;
|
|
1429
|
+
case "includes":
|
|
1430
|
+
if (jsonSchema.pattern) errors = addError(errors, `The "${valibotAction.type}" action is not supported in combination with another regex action.`);
|
|
1431
|
+
else jsonSchema.pattern = escapeRegExp(valibotAction.requirement);
|
|
1432
|
+
break;
|
|
1433
|
+
case "integer":
|
|
1434
|
+
jsonSchema.type = "integer";
|
|
1435
|
+
break;
|
|
1436
|
+
case "ipv4":
|
|
1437
|
+
jsonSchema.format = "ipv4";
|
|
1438
|
+
break;
|
|
1439
|
+
case "ipv6":
|
|
1440
|
+
jsonSchema.format = "ipv6";
|
|
1441
|
+
break;
|
|
1442
|
+
case "iso_date":
|
|
1443
|
+
jsonSchema.format = "date";
|
|
1444
|
+
break;
|
|
1445
|
+
case "iso_date_time":
|
|
1446
|
+
case "iso_timestamp":
|
|
1447
|
+
jsonSchema.format = "date-time";
|
|
1448
|
+
break;
|
|
1449
|
+
case "iso_time":
|
|
1450
|
+
jsonSchema.format = "time";
|
|
1451
|
+
break;
|
|
1452
|
+
case "jws_compact":
|
|
1453
|
+
if (jsonSchema.pattern) errors = addError(errors, `The "${valibotAction.type}" action is not supported in combination with another regex action.`);
|
|
1454
|
+
else jsonSchema.pattern = valibotAction.requirement.source;
|
|
1455
|
+
break;
|
|
1456
|
+
case "length":
|
|
1457
|
+
if (!Number.isInteger(valibotAction.requirement) || valibotAction.requirement < 0) {
|
|
1458
|
+
errors = addError(errors, 'The requirement of the "length" action must be a non-negative integer.');
|
|
1459
|
+
break;
|
|
1460
|
+
}
|
|
1461
|
+
if (jsonSchema.type === "array") {
|
|
1462
|
+
jsonSchema.minItems = getLowerBound(jsonSchema.minItems, valibotAction.requirement);
|
|
1463
|
+
jsonSchema.maxItems = getUpperBound(jsonSchema.maxItems, valibotAction.requirement);
|
|
1464
|
+
} else {
|
|
1465
|
+
if (jsonSchema.type !== "string") errors = addError(errors, `The "${valibotAction.type}" action is not supported on type "${jsonSchema.type}".`);
|
|
1466
|
+
jsonSchema.minLength = getLowerBound(jsonSchema.minLength, valibotAction.requirement);
|
|
1467
|
+
jsonSchema.maxLength = getUpperBound(jsonSchema.maxLength, valibotAction.requirement);
|
|
1468
|
+
}
|
|
1469
|
+
break;
|
|
1470
|
+
case "lt_value":
|
|
1471
|
+
if (jsonSchema.type !== "number" && jsonSchema.type !== "integer") {
|
|
1472
|
+
errors = addError(errors, `The "lt_value" action is not supported on type "${jsonSchema.type}".`);
|
|
1473
|
+
break;
|
|
1474
|
+
}
|
|
1475
|
+
if (!Number.isFinite(valibotAction.requirement)) {
|
|
1476
|
+
errors = addError(errors, 'The requirement of the "lt_value" action is not JSON compatible.');
|
|
1477
|
+
break;
|
|
1478
|
+
}
|
|
1479
|
+
if (config?.target === "openapi-3.0") {
|
|
1480
|
+
errors = addError(errors, 'The "lt_value" action is not supported for OpenAPI 3.0.');
|
|
1481
|
+
break;
|
|
1482
|
+
}
|
|
1483
|
+
jsonSchema.exclusiveMaximum = getUpperBound(jsonSchema.exclusiveMaximum, valibotAction.requirement);
|
|
1484
|
+
break;
|
|
1485
|
+
case "max_entries":
|
|
1486
|
+
if (!Number.isInteger(valibotAction.requirement) || valibotAction.requirement < 0) {
|
|
1487
|
+
errors = addError(errors, 'The requirement of the "max_entries" action must be a non-negative integer.');
|
|
1488
|
+
break;
|
|
1489
|
+
}
|
|
1490
|
+
jsonSchema.maxProperties = getUpperBound(jsonSchema.maxProperties, valibotAction.requirement);
|
|
1491
|
+
break;
|
|
1492
|
+
case "max_length":
|
|
1493
|
+
if (!Number.isInteger(valibotAction.requirement) || valibotAction.requirement < 0) {
|
|
1494
|
+
errors = addError(errors, 'The requirement of the "max_length" action must be a non-negative integer.');
|
|
1495
|
+
break;
|
|
1496
|
+
}
|
|
1497
|
+
if (jsonSchema.type === "array") jsonSchema.maxItems = getUpperBound(jsonSchema.maxItems, valibotAction.requirement);
|
|
1498
|
+
else {
|
|
1499
|
+
if (jsonSchema.type !== "string") errors = addError(errors, `The "${valibotAction.type}" action is not supported on type "${jsonSchema.type}".`);
|
|
1500
|
+
jsonSchema.maxLength = getUpperBound(jsonSchema.maxLength, valibotAction.requirement);
|
|
1501
|
+
}
|
|
1502
|
+
break;
|
|
1503
|
+
case "max_value":
|
|
1504
|
+
if (jsonSchema.type !== "number" && jsonSchema.type !== "integer") {
|
|
1505
|
+
errors = addError(errors, `The "max_value" action is not supported on type "${jsonSchema.type}".`);
|
|
1506
|
+
break;
|
|
1507
|
+
}
|
|
1508
|
+
if (!Number.isFinite(valibotAction.requirement)) {
|
|
1509
|
+
errors = addError(errors, 'The requirement of the "max_value" action is not JSON compatible.');
|
|
1510
|
+
break;
|
|
1511
|
+
}
|
|
1512
|
+
jsonSchema.maximum = getUpperBound(jsonSchema.maximum, valibotAction.requirement);
|
|
1513
|
+
break;
|
|
1514
|
+
case "metadata":
|
|
1515
|
+
if (typeof valibotAction.metadata.title === "string") jsonSchema.title = valibotAction.metadata.title;
|
|
1516
|
+
if (typeof valibotAction.metadata.description === "string") jsonSchema.description = valibotAction.metadata.description;
|
|
1517
|
+
if (Array.isArray(valibotAction.metadata.examples)) if (Array.isArray(jsonSchema.examples)) jsonSchema.examples = [...jsonSchema.examples, ...valibotAction.metadata.examples];
|
|
1518
|
+
else jsonSchema.examples = valibotAction.metadata.examples;
|
|
1519
|
+
for (const key of Object.keys(valibotAction.metadata)) if (key !== "title" && key !== "description" && key !== "examples" && key !== "__proto__") jsonSchema[key] = valibotAction.metadata[key];
|
|
1520
|
+
break;
|
|
1521
|
+
case "min_entries":
|
|
1522
|
+
if (!Number.isInteger(valibotAction.requirement) || valibotAction.requirement < 0) {
|
|
1523
|
+
errors = addError(errors, 'The requirement of the "min_entries" action must be a non-negative integer.');
|
|
1524
|
+
break;
|
|
1525
|
+
}
|
|
1526
|
+
jsonSchema.minProperties = getLowerBound(jsonSchema.minProperties, valibotAction.requirement);
|
|
1527
|
+
break;
|
|
1528
|
+
case "min_length":
|
|
1529
|
+
if (!Number.isInteger(valibotAction.requirement) || valibotAction.requirement < 0) {
|
|
1530
|
+
errors = addError(errors, 'The requirement of the "min_length" action must be a non-negative integer.');
|
|
1531
|
+
break;
|
|
1532
|
+
}
|
|
1533
|
+
if (jsonSchema.type === "array") jsonSchema.minItems = getLowerBound(jsonSchema.minItems, valibotAction.requirement);
|
|
1534
|
+
else {
|
|
1535
|
+
if (jsonSchema.type !== "string") errors = addError(errors, `The "${valibotAction.type}" action is not supported on type "${jsonSchema.type}".`);
|
|
1536
|
+
jsonSchema.minLength = getLowerBound(jsonSchema.minLength, valibotAction.requirement);
|
|
1537
|
+
}
|
|
1538
|
+
break;
|
|
1539
|
+
case "min_value":
|
|
1540
|
+
if (jsonSchema.type !== "number" && jsonSchema.type !== "integer") {
|
|
1541
|
+
errors = addError(errors, `The "min_value" action is not supported on type "${jsonSchema.type}".`);
|
|
1542
|
+
break;
|
|
1543
|
+
}
|
|
1544
|
+
if (!Number.isFinite(valibotAction.requirement)) {
|
|
1545
|
+
errors = addError(errors, 'The requirement of the "min_value" action is not JSON compatible.');
|
|
1546
|
+
break;
|
|
1547
|
+
}
|
|
1548
|
+
jsonSchema.minimum = getLowerBound(jsonSchema.minimum, valibotAction.requirement);
|
|
1549
|
+
break;
|
|
1550
|
+
case "multiple_of":
|
|
1551
|
+
jsonSchema.multipleOf = valibotAction.requirement;
|
|
1552
|
+
break;
|
|
1553
|
+
case "non_empty":
|
|
1554
|
+
if (jsonSchema.type === "array") jsonSchema.minItems = getLowerBound(jsonSchema.minItems, 1);
|
|
1555
|
+
else {
|
|
1556
|
+
if (jsonSchema.type !== "string") errors = addError(errors, `The "${valibotAction.type}" action is not supported on type "${jsonSchema.type}".`);
|
|
1557
|
+
jsonSchema.minLength = getLowerBound(jsonSchema.minLength, 1);
|
|
1558
|
+
}
|
|
1559
|
+
break;
|
|
1560
|
+
case "not_value":
|
|
1561
|
+
if (!isJsonConstValue(valibotAction.requirement)) {
|
|
1562
|
+
errors = addError(errors, 'The requirement of the "not_value" action is not JSON compatible.');
|
|
1563
|
+
break;
|
|
1564
|
+
}
|
|
1565
|
+
jsonSchema.not = /* @__PURE__ */ getNotRestriction(jsonSchema.not, config?.target === "openapi-3.0" ? { enum: [valibotAction.requirement] } : { const: valibotAction.requirement });
|
|
1566
|
+
break;
|
|
1567
|
+
case "not_values":
|
|
1568
|
+
if (!isJsonEnumValues(valibotAction.requirement)) {
|
|
1569
|
+
errors = addError(errors, 'A requirement of the "not_values" action is not JSON compatible.');
|
|
1570
|
+
break;
|
|
1571
|
+
}
|
|
1572
|
+
if (valibotAction.requirement.length) jsonSchema.not = /* @__PURE__ */ getNotRestriction(jsonSchema.not, { enum: [...new Set(valibotAction.requirement)] });
|
|
1573
|
+
break;
|
|
1574
|
+
case "regex":
|
|
1575
|
+
if (valibotAction.requirement.flags) errors = addError(errors, "RegExp flags are not supported by JSON Schema.");
|
|
1576
|
+
if (jsonSchema.pattern) errors = addError(errors, `The "${valibotAction.type}" action is not supported in combination with another regex action.`);
|
|
1577
|
+
else jsonSchema.pattern = valibotAction.requirement.source;
|
|
1578
|
+
break;
|
|
1579
|
+
case "safe_integer":
|
|
1580
|
+
jsonSchema.type = "integer";
|
|
1581
|
+
jsonSchema.minimum = getLowerBound(jsonSchema.minimum, Number.MIN_SAFE_INTEGER);
|
|
1582
|
+
jsonSchema.maximum = getUpperBound(jsonSchema.maximum, Number.MAX_SAFE_INTEGER);
|
|
1583
|
+
break;
|
|
1584
|
+
case "starts_with":
|
|
1585
|
+
if (jsonSchema.pattern) errors = addError(errors, `The "${valibotAction.type}" action is not supported in combination with another regex action.`);
|
|
1586
|
+
else jsonSchema.pattern = `^${escapeRegExp(valibotAction.requirement)}`;
|
|
1587
|
+
break;
|
|
1588
|
+
case "title":
|
|
1589
|
+
jsonSchema.title = valibotAction.title;
|
|
1590
|
+
break;
|
|
1591
|
+
case "url":
|
|
1592
|
+
jsonSchema.format = "uri";
|
|
1593
|
+
break;
|
|
1594
|
+
case "uuid":
|
|
1595
|
+
jsonSchema.format = "uuid";
|
|
1596
|
+
break;
|
|
1597
|
+
case "value":
|
|
1598
|
+
if (!isJsonConstValue(valibotAction.requirement)) {
|
|
1599
|
+
errors = addError(errors, 'The requirement of the "value" action is not JSON compatible.');
|
|
1600
|
+
break;
|
|
1601
|
+
}
|
|
1602
|
+
if (config?.target === "openapi-3.0") intersectEnum(jsonSchema, [valibotAction.requirement]);
|
|
1603
|
+
else if ("const" in jsonSchema && jsonSchema.const !== valibotAction.requirement) errors = addError(errors, `The "${valibotAction.type}" action is not supported in combination with a different "const" restriction.`);
|
|
1604
|
+
else jsonSchema.const = valibotAction.requirement;
|
|
1605
|
+
break;
|
|
1606
|
+
case "values":
|
|
1607
|
+
if (!isJsonEnumValues(valibotAction.requirement)) {
|
|
1608
|
+
errors = addError(errors, 'A requirement of the "values" action is not JSON compatible.');
|
|
1609
|
+
break;
|
|
1610
|
+
}
|
|
1611
|
+
intersectEnum(jsonSchema, valibotAction.requirement);
|
|
1612
|
+
break;
|
|
1613
|
+
default:
|
|
1614
|
+
errors = addError(errors, `The "${valibotAction.type}" action cannot be converted to JSON Schema.`);
|
|
1615
|
+
}
|
|
1616
|
+
if (config?.overrideAction) {
|
|
1617
|
+
const actionOverride = config.overrideAction({
|
|
1618
|
+
valibotAction,
|
|
1619
|
+
jsonSchema,
|
|
1620
|
+
errors
|
|
1621
|
+
});
|
|
1622
|
+
if (actionOverride) return { ...actionOverride };
|
|
1623
|
+
}
|
|
1624
|
+
if (errors) for (const message of errors) handleError(message, config);
|
|
1625
|
+
return jsonSchema;
|
|
1626
|
+
}
|
|
1627
|
+
__name(convertAction, "convertAction");
|
|
1628
|
+
function flattenPipe(pipe2) {
|
|
1629
|
+
return pipe2.flatMap((item) => "pipe" in item ? flattenPipe(item.pipe) : item);
|
|
1630
|
+
}
|
|
1631
|
+
__name(flattenPipe, "flattenPipe");
|
|
1632
|
+
function getDefinitionRef(referenceId) {
|
|
1633
|
+
return `#/$defs/${referenceId.replaceAll("~", "~0").replaceAll("/", "~1")}`;
|
|
1634
|
+
}
|
|
1635
|
+
__name(getDefinitionRef, "getDefinitionRef");
|
|
1636
|
+
function convertSchema(jsonSchema, valibotSchema, config, context, skipRef = false) {
|
|
1637
|
+
if (!skipRef) {
|
|
1638
|
+
const referenceId = context.referenceMap.get(valibotSchema);
|
|
1639
|
+
if (referenceId) {
|
|
1640
|
+
jsonSchema.$ref = getDefinitionRef(referenceId);
|
|
1641
|
+
if (config?.overrideRef) {
|
|
1642
|
+
const refOverride = config.overrideRef({
|
|
1643
|
+
...context,
|
|
1644
|
+
referenceId,
|
|
1645
|
+
valibotSchema,
|
|
1646
|
+
jsonSchema
|
|
1647
|
+
});
|
|
1648
|
+
if (refOverride) jsonSchema.$ref = refOverride;
|
|
1649
|
+
}
|
|
1650
|
+
return jsonSchema;
|
|
1651
|
+
}
|
|
1652
|
+
}
|
|
1653
|
+
if ("pipe" in valibotSchema) {
|
|
1654
|
+
const flatPipe = flattenPipe(valibotSchema.pipe);
|
|
1655
|
+
let startIndex = 0;
|
|
1656
|
+
let stopIndex = flatPipe.length - 1;
|
|
1657
|
+
if (config?.typeMode === "input") {
|
|
1658
|
+
const inputStopIndex = flatPipe.slice(1).findIndex((item) => item.kind === "schema" || item.kind === "transformation" && (item.type === "find_item" || item.type === "parse_json" || item.type === "raw_transform" || item.type === "reduce_items" || item.type === "stringify_json" || item.type === "to_bigint" || item.type === "to_boolean" || item.type === "to_date" || item.type === "to_number" || item.type === "to_string" || item.type === "transform"));
|
|
1659
|
+
if (inputStopIndex !== -1) stopIndex = inputStopIndex;
|
|
1660
|
+
} else if (config?.typeMode === "output") {
|
|
1661
|
+
const outputStartIndex = flatPipe.findLastIndex((item) => item.kind === "schema");
|
|
1662
|
+
if (outputStartIndex !== -1) startIndex = outputStartIndex;
|
|
1663
|
+
}
|
|
1664
|
+
for (let index = startIndex; index <= stopIndex; index++) {
|
|
1665
|
+
const valibotPipeItem = flatPipe[index];
|
|
1666
|
+
if (valibotPipeItem.kind === "schema") {
|
|
1667
|
+
if (index > startIndex) handleError('Set the "typeMode" config to "input" or "output" to convert pipelines with multiple schemas.', config);
|
|
1668
|
+
jsonSchema = convertSchema(jsonSchema, valibotPipeItem, config, context, true);
|
|
1669
|
+
} else jsonSchema = convertAction(jsonSchema, valibotPipeItem, config);
|
|
1670
|
+
}
|
|
1671
|
+
return jsonSchema;
|
|
1672
|
+
}
|
|
1673
|
+
let errors;
|
|
1674
|
+
switch (valibotSchema.type) {
|
|
1675
|
+
case "boolean":
|
|
1676
|
+
jsonSchema.type = "boolean";
|
|
1677
|
+
break;
|
|
1678
|
+
case "null":
|
|
1679
|
+
if (config?.target === "openapi-3.0") jsonSchema.enum = [null];
|
|
1680
|
+
else jsonSchema.type = "null";
|
|
1681
|
+
break;
|
|
1682
|
+
case "number":
|
|
1683
|
+
jsonSchema.type = "number";
|
|
1684
|
+
break;
|
|
1685
|
+
case "string":
|
|
1686
|
+
jsonSchema.type = "string";
|
|
1687
|
+
break;
|
|
1688
|
+
case "array":
|
|
1689
|
+
jsonSchema.type = "array";
|
|
1690
|
+
jsonSchema.items = convertSchema({}, valibotSchema.item, config, context);
|
|
1691
|
+
break;
|
|
1692
|
+
case "tuple":
|
|
1693
|
+
case "tuple_with_rest":
|
|
1694
|
+
case "loose_tuple":
|
|
1695
|
+
case "strict_tuple":
|
|
1696
|
+
jsonSchema.type = "array";
|
|
1697
|
+
if (config?.target === "openapi-3.0") {
|
|
1698
|
+
jsonSchema.items = { anyOf: [] };
|
|
1699
|
+
jsonSchema.minItems = valibotSchema.items.length;
|
|
1700
|
+
for (const item of valibotSchema.items) jsonSchema.items.anyOf.push(convertSchema({}, item, config, context));
|
|
1701
|
+
if (valibotSchema.type === "tuple_with_rest") jsonSchema.items.anyOf.push(convertSchema({}, valibotSchema.rest, config, context));
|
|
1702
|
+
else if (valibotSchema.type === "strict_tuple" || valibotSchema.type === "tuple") jsonSchema.maxItems = valibotSchema.items.length;
|
|
1703
|
+
} else if (config?.target === "draft-2020-12") {
|
|
1704
|
+
jsonSchema.prefixItems = [];
|
|
1705
|
+
jsonSchema.minItems = valibotSchema.items.length;
|
|
1706
|
+
for (const item of valibotSchema.items) jsonSchema.prefixItems.push(convertSchema({}, item, config, context));
|
|
1707
|
+
if (valibotSchema.type === "tuple_with_rest") jsonSchema.items = convertSchema({}, valibotSchema.rest, config, context);
|
|
1708
|
+
else if (valibotSchema.type === "strict_tuple") jsonSchema.items = false;
|
|
1709
|
+
} else {
|
|
1710
|
+
jsonSchema.items = [];
|
|
1711
|
+
jsonSchema.minItems = valibotSchema.items.length;
|
|
1712
|
+
for (const item of valibotSchema.items) jsonSchema.items.push(convertSchema({}, item, config, context));
|
|
1713
|
+
if (valibotSchema.type === "tuple_with_rest") jsonSchema.additionalItems = convertSchema({}, valibotSchema.rest, config, context);
|
|
1714
|
+
else if (valibotSchema.type === "strict_tuple") jsonSchema.additionalItems = false;
|
|
1715
|
+
}
|
|
1716
|
+
break;
|
|
1717
|
+
case "object":
|
|
1718
|
+
case "object_with_rest":
|
|
1719
|
+
case "loose_object":
|
|
1720
|
+
case "strict_object":
|
|
1721
|
+
jsonSchema.type = "object";
|
|
1722
|
+
jsonSchema.properties = {};
|
|
1723
|
+
jsonSchema.required = [];
|
|
1724
|
+
for (const key in valibotSchema.entries) {
|
|
1725
|
+
const entry = valibotSchema.entries[key];
|
|
1726
|
+
jsonSchema.properties[key] = convertSchema({}, entry, config, context);
|
|
1727
|
+
if (entry.type !== "exact_optional" && entry.type !== "nullish" && entry.type !== "optional") jsonSchema.required.push(key);
|
|
1728
|
+
}
|
|
1729
|
+
if (valibotSchema.type === "object_with_rest") jsonSchema.additionalProperties = convertSchema({}, valibotSchema.rest, config, context);
|
|
1730
|
+
else if (valibotSchema.type === "strict_object") jsonSchema.additionalProperties = false;
|
|
1731
|
+
break;
|
|
1732
|
+
case "record":
|
|
1733
|
+
if (config?.target === "openapi-3.0" && "pipe" in valibotSchema.key) errors = addError(errors, 'The "record" schema with a schema for the key that contains a "pipe" cannot be converted to JSON Schema.');
|
|
1734
|
+
if (valibotSchema.key.type !== "string") errors = addError(errors, `The "record" schema with the "${valibotSchema.key.type}" schema for the key cannot be converted to JSON Schema.`);
|
|
1735
|
+
jsonSchema.type = "object";
|
|
1736
|
+
if (config?.target !== "openapi-3.0") jsonSchema.propertyNames = convertSchema({}, valibotSchema.key, config, context);
|
|
1737
|
+
jsonSchema.additionalProperties = convertSchema({}, valibotSchema.value, config, context);
|
|
1738
|
+
break;
|
|
1739
|
+
case "any":
|
|
1740
|
+
case "unknown":
|
|
1741
|
+
break;
|
|
1742
|
+
case "never":
|
|
1743
|
+
jsonSchema.not = {};
|
|
1744
|
+
break;
|
|
1745
|
+
case "nullable":
|
|
1746
|
+
case "nullish":
|
|
1747
|
+
if (config?.target === "openapi-3.0") {
|
|
1748
|
+
const innerSchema = convertSchema({}, valibotSchema.wrapped, config, context);
|
|
1749
|
+
Object.assign(jsonSchema, innerSchema);
|
|
1750
|
+
jsonSchema.nullable = true;
|
|
1751
|
+
} else jsonSchema.anyOf = [convertSchema({}, valibotSchema.wrapped, config, context), { type: "null" }];
|
|
1752
|
+
if (valibotSchema.default !== void 0) jsonSchema.default = typeof valibotSchema.default === "function" ? valibotSchema.default() : valibotSchema.default;
|
|
1753
|
+
break;
|
|
1754
|
+
case "exact_optional":
|
|
1755
|
+
case "optional":
|
|
1756
|
+
case "undefinedable":
|
|
1757
|
+
jsonSchema = convertSchema(jsonSchema, valibotSchema.wrapped, config, context);
|
|
1758
|
+
if (valibotSchema.default !== void 0) jsonSchema.default = typeof valibotSchema.default === "function" ? valibotSchema.default() : valibotSchema.default;
|
|
1759
|
+
break;
|
|
1760
|
+
case "literal":
|
|
1761
|
+
if (!isJsonConstValue(valibotSchema.literal)) {
|
|
1762
|
+
errors = addError(errors, 'The value of the "literal" schema is not JSON compatible.');
|
|
1763
|
+
break;
|
|
1764
|
+
}
|
|
1765
|
+
if (config?.target === "openapi-3.0") jsonSchema.enum = [valibotSchema.literal];
|
|
1766
|
+
else jsonSchema.const = valibotSchema.literal;
|
|
1767
|
+
break;
|
|
1768
|
+
case "enum":
|
|
1769
|
+
case "picklist": {
|
|
1770
|
+
const options = valibotSchema.options;
|
|
1771
|
+
if (!options.every((option) => typeof option === "string" || typeof option === "number" && Number.isFinite(option))) {
|
|
1772
|
+
errors = addError(errors, `An option of the "${valibotSchema.type}" schema is not JSON compatible.`);
|
|
1773
|
+
break;
|
|
1774
|
+
}
|
|
1775
|
+
jsonSchema.enum = options;
|
|
1776
|
+
if (options.every((option) => typeof option === "string")) jsonSchema.type = "string";
|
|
1777
|
+
else if (options.every((option) => typeof option === "number")) jsonSchema.type = "number";
|
|
1778
|
+
else if (config?.target !== "openapi-3.0") jsonSchema.type = ["string", "number"];
|
|
1779
|
+
break;
|
|
1780
|
+
}
|
|
1781
|
+
case "union":
|
|
1782
|
+
jsonSchema.anyOf = valibotSchema.options.map((option) => convertSchema({}, option, config, context));
|
|
1783
|
+
break;
|
|
1784
|
+
case "variant":
|
|
1785
|
+
jsonSchema.oneOf = valibotSchema.options.map((option) => convertSchema({}, option, config, context));
|
|
1786
|
+
break;
|
|
1787
|
+
case "intersect":
|
|
1788
|
+
jsonSchema.allOf = valibotSchema.options.map((option) => convertSchema({}, option, config, context));
|
|
1789
|
+
break;
|
|
1790
|
+
case "lazy": {
|
|
1791
|
+
let wrappedValibotSchema = context.getterMap.get(valibotSchema.getter);
|
|
1792
|
+
if (!wrappedValibotSchema) {
|
|
1793
|
+
wrappedValibotSchema = valibotSchema.getter(void 0);
|
|
1794
|
+
context.getterMap.set(valibotSchema.getter, wrappedValibotSchema);
|
|
1795
|
+
}
|
|
1796
|
+
let referenceId = context.referenceMap.get(wrappedValibotSchema);
|
|
1797
|
+
if (!referenceId) {
|
|
1798
|
+
referenceId = context.referenceMap.createId(context.definitions);
|
|
1799
|
+
context.referenceMap.set(wrappedValibotSchema, referenceId);
|
|
1800
|
+
context.definitions[referenceId] = convertSchema({}, wrappedValibotSchema, config, context, true);
|
|
1801
|
+
}
|
|
1802
|
+
jsonSchema.$ref = getDefinitionRef(referenceId);
|
|
1803
|
+
if (config?.overrideRef) {
|
|
1804
|
+
const refOverride = config.overrideRef({
|
|
1805
|
+
...context,
|
|
1806
|
+
referenceId,
|
|
1807
|
+
valibotSchema: wrappedValibotSchema,
|
|
1808
|
+
jsonSchema
|
|
1809
|
+
});
|
|
1810
|
+
if (refOverride) jsonSchema.$ref = refOverride;
|
|
1811
|
+
}
|
|
1812
|
+
break;
|
|
1813
|
+
}
|
|
1814
|
+
default:
|
|
1815
|
+
errors = addError(errors, `The "${valibotSchema.type}" schema cannot be converted to JSON Schema.`);
|
|
1816
|
+
}
|
|
1817
|
+
if (config?.overrideSchema) {
|
|
1818
|
+
const schemaOverride = config.overrideSchema({
|
|
1819
|
+
...context,
|
|
1820
|
+
referenceId: context.referenceMap.get(valibotSchema),
|
|
1821
|
+
valibotSchema,
|
|
1822
|
+
jsonSchema,
|
|
1823
|
+
errors
|
|
1824
|
+
});
|
|
1825
|
+
if (schemaOverride) return { ...schemaOverride };
|
|
1826
|
+
}
|
|
1827
|
+
if (errors) for (const message of errors) handleError(message, config);
|
|
1828
|
+
return jsonSchema;
|
|
1829
|
+
}
|
|
1830
|
+
__name(convertSchema, "convertSchema");
|
|
1831
|
+
var store;
|
|
1832
|
+
function getGlobalDefs() {
|
|
1833
|
+
return store;
|
|
1834
|
+
}
|
|
1835
|
+
__name(getGlobalDefs, "getGlobalDefs");
|
|
1836
|
+
function toJsonSchema(schema, config) {
|
|
1837
|
+
const context = {
|
|
1838
|
+
definitions: {},
|
|
1839
|
+
referenceMap: new ReferenceMap(),
|
|
1840
|
+
getterMap: /* @__PURE__ */ new Map()
|
|
1841
|
+
};
|
|
1842
|
+
const definitions = config?.definitions ?? getGlobalDefs();
|
|
1843
|
+
if (definitions) {
|
|
1844
|
+
for (const key in definitions) context.referenceMap.set(definitions[key], key);
|
|
1845
|
+
for (const key in definitions) context.definitions[key] = convertSchema({}, definitions[key], config, context, true);
|
|
1846
|
+
}
|
|
1847
|
+
const jsonSchema = convertSchema({}, schema, config, context);
|
|
1848
|
+
const target = config?.target ?? "draft-07";
|
|
1849
|
+
if (target === "draft-2020-12") jsonSchema.$schema = "https://json-schema.org/draft/2020-12/schema";
|
|
1850
|
+
else if (target === "draft-07") jsonSchema.$schema = "http://json-schema.org/draft-07/schema#";
|
|
1851
|
+
if (context.referenceMap.size) jsonSchema.$defs = context.definitions;
|
|
1852
|
+
return jsonSchema;
|
|
1853
|
+
}
|
|
1854
|
+
__name(toJsonSchema, "toJsonSchema");
|
|
1855
|
+
var SUPPORTED_TARGETS = [
|
|
1856
|
+
"draft-07",
|
|
1857
|
+
"draft-2020-12",
|
|
1858
|
+
"openapi-3.0"
|
|
1859
|
+
];
|
|
1860
|
+
function toStandardJsonSchema(schema) {
|
|
1861
|
+
return { "~standard": {
|
|
1862
|
+
...schema["~standard"],
|
|
1863
|
+
jsonSchema: {
|
|
1864
|
+
input(options) {
|
|
1865
|
+
if (SUPPORTED_TARGETS.includes(options.target)) return toJsonSchema(schema, {
|
|
1866
|
+
typeMode: "input",
|
|
1867
|
+
target: options.target,
|
|
1868
|
+
...options.libraryOptions
|
|
1869
|
+
});
|
|
1870
|
+
throw new Error(`Unsupported target: ${options.target}`);
|
|
1871
|
+
},
|
|
1872
|
+
output(options) {
|
|
1873
|
+
if (SUPPORTED_TARGETS.includes(options.target)) return toJsonSchema(schema, {
|
|
1874
|
+
typeMode: "output",
|
|
1875
|
+
target: options.target,
|
|
1876
|
+
...options.libraryOptions
|
|
1877
|
+
});
|
|
1878
|
+
throw new Error(`Unsupported target: ${options.target}`);
|
|
1879
|
+
}
|
|
1880
|
+
}
|
|
1881
|
+
} };
|
|
1882
|
+
}
|
|
1883
|
+
__name(toStandardJsonSchema, "toStandardJsonSchema");
|
|
1884
|
+
|
|
1885
|
+
// node_modules/.pnpm/@wirecat+cli-base@0.68.1_commander@15.0.0_esbuild@0.28.2_typescript@7.0.2_vitest@5.0.5/node_modules/@wirecat/cli-base/dist/standards/registry.js
|
|
1886
|
+
var word = pipe(string(), regex(/^[a-z][a-z0-9]*(-[a-z0-9]+)*$/, "a lower-case word, words joined by -"));
|
|
1887
|
+
var SNAKE_CASE = /^[a-z][a-z0-9]*(_[a-z0-9]+)*$/;
|
|
1888
|
+
var text = pipe(string(), regex(/\S/, "must not be empty"));
|
|
1889
|
+
var dottedId = pipe(string(), regex(/^[a-z][a-z0-9-]*(\.[a-z][a-z0-9-]*)+$/, "dotted lower-case words, such as `page.next`"));
|
|
1890
|
+
var RegistryError = class extends Error {
|
|
1891
|
+
static {
|
|
1892
|
+
__name(this, "RegistryError");
|
|
1893
|
+
}
|
|
1894
|
+
registry;
|
|
1895
|
+
problems;
|
|
1896
|
+
constructor(registry, problems) {
|
|
1897
|
+
super(`${registry} registry: ${problems.join("; ")}`);
|
|
1898
|
+
this.registry = registry;
|
|
1899
|
+
this.problems = problems;
|
|
1900
|
+
this.name = "RegistryError";
|
|
1901
|
+
}
|
|
1902
|
+
};
|
|
1903
|
+
var issuesOf = /* @__PURE__ */ __name((issues) => issues.map((issue) => {
|
|
1904
|
+
const path = getDotPath(issue);
|
|
1905
|
+
return path ? `${path}: ${issue.message}` : issue.message;
|
|
1906
|
+
}), "issuesOf");
|
|
1907
|
+
var parseRegistry = /* @__PURE__ */ __name((registry, schema, input, check2 = () => []) => {
|
|
1908
|
+
const parsed = safeParse(schema, input);
|
|
1909
|
+
if (!parsed.success)
|
|
1910
|
+
throw new RegistryError(registry, issuesOf(parsed.issues));
|
|
1911
|
+
const problems = check2(parsed.output);
|
|
1912
|
+
if (problems.length > 0)
|
|
1913
|
+
throw new RegistryError(registry, problems);
|
|
1914
|
+
return parsed.output;
|
|
1915
|
+
}, "parseRegistry");
|
|
1916
|
+
var duplicates = /* @__PURE__ */ __name((values) => [...new Set(values.filter((value, index) => values.indexOf(value) !== index))].sort(), "duplicates");
|
|
1917
|
+
var jsonSchemaOf = /* @__PURE__ */ __name((schema, definitions) => toJsonSchema(schema, { target: "draft-2020-12", ...definitions ? { definitions } : {} }), "jsonSchemaOf");
|
|
1918
|
+
var PLACEHOLDER = /\{([a-z][a-z0-9]*(?:_[a-z0-9]+)*)\}/g;
|
|
1919
|
+
var placeholders = /* @__PURE__ */ __name((template) => [...template.matchAll(PLACEHOLDER)].map((match) => match[1] ?? ""), "placeholders");
|
|
1920
|
+
var fill = /* @__PURE__ */ __name((template, values) => template.replace(PLACEHOLDER, (_, name) => {
|
|
1921
|
+
const value = values[name];
|
|
1922
|
+
if (value === void 0)
|
|
1923
|
+
throw new Error(`no value for {${name}} in "${template}"`);
|
|
1924
|
+
return String(value);
|
|
1925
|
+
}), "fill");
|
|
1926
|
+
|
|
1927
|
+
// node_modules/.pnpm/@wirecat+cli-base@0.68.1_commander@15.0.0_esbuild@0.28.2_typescript@7.0.2_vitest@5.0.5/node_modules/@wirecat/cli-base/dist/standards/output.js
|
|
1928
|
+
var MAX_NEXT_STEPS = 2;
|
|
1929
|
+
var isoTime = pipe(string(), isoTimestamp("an ISO 8601 time in UTC"), endsWith("Z", "an ISO 8601 time in UTC, ending in `Z`"));
|
|
1930
|
+
var reference = pipe(string(), regex(/^[a-z]+:\S+$/, "a reference such as `note:42`"));
|
|
1931
|
+
var nextStepSchema = variant("kind", [
|
|
1932
|
+
strictObject({
|
|
1933
|
+
kind: literal("command"),
|
|
1934
|
+
step: dottedId,
|
|
1935
|
+
/** The command path as one string, `messages list` — what the MCP router tools take as `command`. */
|
|
1936
|
+
command: text,
|
|
1937
|
+
args: record(string(), unknown()),
|
|
1938
|
+
/**
|
|
1939
|
+
* The whole line to type, with the tool and the profile it ran with: `tg personal mcp config`. Only the CLI
|
|
1940
|
+
* knows the profile, so it fills this; MCP answers leave it out.
|
|
1941
|
+
*/
|
|
1942
|
+
line: optional(text),
|
|
1943
|
+
why: text,
|
|
1944
|
+
/** True only when the target command is known to write nothing, here or at the provider. */
|
|
1945
|
+
safe_to_auto_execute: boolean()
|
|
1946
|
+
}),
|
|
1947
|
+
/** Something only the person can do — sign in on the phone, approve a device. */
|
|
1948
|
+
strictObject({
|
|
1949
|
+
kind: literal("user_action"),
|
|
1950
|
+
step: dottedId,
|
|
1951
|
+
why: text,
|
|
1952
|
+
safe_to_auto_execute: literal(false)
|
|
1953
|
+
})
|
|
1954
|
+
]);
|
|
1955
|
+
var missingSchema = strictObject({
|
|
1956
|
+
field: text,
|
|
1957
|
+
why: text,
|
|
1958
|
+
/** Left out when there is nothing to run that would fill the field. */
|
|
1959
|
+
step: optional(dottedId)
|
|
1960
|
+
});
|
|
1961
|
+
var limit = pipe(number(), integer(), minValue(1));
|
|
1962
|
+
var totalSchema = strictObject({
|
|
1963
|
+
value: pipe(number(), integer(), minValue(0)),
|
|
1964
|
+
relation: picklist(["eq", "gte"])
|
|
1965
|
+
});
|
|
1966
|
+
var pageSchema = variant("mode", [
|
|
1967
|
+
strictObject({
|
|
1968
|
+
mode: literal("page"),
|
|
1969
|
+
limit,
|
|
1970
|
+
has_more: boolean(),
|
|
1971
|
+
next_page: optional(pipe(number(), integer(), minValue(2))),
|
|
1972
|
+
total: optional(totalSchema)
|
|
1973
|
+
}),
|
|
1974
|
+
strictObject({
|
|
1975
|
+
mode: literal("cursor"),
|
|
1976
|
+
limit,
|
|
1977
|
+
has_more: boolean(),
|
|
1978
|
+
next_cursor: optional(text),
|
|
1979
|
+
total: optional(totalSchema)
|
|
1980
|
+
})
|
|
1981
|
+
]);
|
|
1982
|
+
var issueSchema = strictObject({
|
|
1983
|
+
code: picklist(errorCodes),
|
|
1984
|
+
reason: optional(dottedId),
|
|
1985
|
+
/** The account, provider or source that is missing from the answer. */
|
|
1986
|
+
source: text
|
|
1987
|
+
});
|
|
1988
|
+
var metaSchema = strictObject({
|
|
1989
|
+
run_id: text,
|
|
1990
|
+
duration_ms: pipe(number(), integer(), minValue(0)),
|
|
1991
|
+
accounts: optional(array(text)),
|
|
1992
|
+
complete: boolean(),
|
|
1993
|
+
issues: optional(array(issueSchema)),
|
|
1994
|
+
truncated: optional(boolean()),
|
|
1995
|
+
timezone: optional(text),
|
|
1996
|
+
window: optional(strictObject({ since: optional(isoTime), until: optional(isoTime) }))
|
|
1997
|
+
});
|
|
1998
|
+
var nextSteps = optional(pipe(array(nextStepSchema), maxLength(MAX_NEXT_STEPS)));
|
|
1999
|
+
var listEnvelopeSchema = /* @__PURE__ */ __name((item) => strictObject({
|
|
2000
|
+
items: array(item),
|
|
2001
|
+
page: pageSchema,
|
|
2002
|
+
next: nextSteps,
|
|
2003
|
+
missing: optional(array(missingSchema)),
|
|
2004
|
+
meta: metaSchema
|
|
2005
|
+
}), "listEnvelopeSchema");
|
|
2006
|
+
var itemEnvelopeSchema = /* @__PURE__ */ __name((item) => strictObject({
|
|
2007
|
+
item,
|
|
2008
|
+
next: nextSteps,
|
|
2009
|
+
missing: optional(array(missingSchema)),
|
|
2010
|
+
meta: metaSchema
|
|
2011
|
+
}), "itemEnvelopeSchema");
|
|
2012
|
+
var jsonlEndSchema = strictObject({
|
|
2013
|
+
type: literal("end"),
|
|
2014
|
+
complete: boolean(),
|
|
2015
|
+
issues: optional(array(issueSchema)),
|
|
2016
|
+
page: pageSchema
|
|
2017
|
+
});
|
|
2018
|
+
var jsonlOf = /* @__PURE__ */ __name(({ items, page, meta }) => [
|
|
2019
|
+
...items.map((data) => JSON.stringify({ type: "item", data })),
|
|
2020
|
+
JSON.stringify({ type: "end", complete: meta.complete, ...meta.issues ? { issues: meta.issues } : {}, page })
|
|
2021
|
+
].join("\n"), "jsonlOf");
|
|
2022
|
+
|
|
2023
|
+
// node_modules/.pnpm/@wirecat+cli-base@0.68.1_commander@15.0.0_esbuild@0.28.2_typescript@7.0.2_vitest@5.0.5/node_modules/@wirecat/cli-base/dist/standards/errors.js
|
|
2024
|
+
var CRASH_CODE = "internal_error";
|
|
2025
|
+
var CRASH_REASON = "command.crashed";
|
|
2026
|
+
var errorObjectSchema = strictObject({
|
|
2027
|
+
error: strictObject({
|
|
2028
|
+
code: picklist([...errorCodes, CRASH_CODE]),
|
|
2029
|
+
reason: dottedId,
|
|
2030
|
+
message: text,
|
|
2031
|
+
/** The option or argument at fault. */
|
|
2032
|
+
param: optional(text),
|
|
2033
|
+
details: optional(record(string(), unknown())),
|
|
2034
|
+
next: optional(pipe(array(nextStepSchema), maxLength(MAX_NEXT_STEPS))),
|
|
2035
|
+
/** Whether running the same command again may work and cannot do harm; never for a write that may have landed. */
|
|
2036
|
+
retry: strictObject({
|
|
2037
|
+
safe: boolean(),
|
|
2038
|
+
after_ms: optional(pipe(number(), integer(), minValue(0)))
|
|
2039
|
+
}),
|
|
2040
|
+
/** Optional until every CLI keeps a run for each failure. */
|
|
2041
|
+
run_id: optional(text)
|
|
2042
|
+
})
|
|
2043
|
+
});
|
|
2044
|
+
var reasonSchema = strictObject({
|
|
2045
|
+
reason: dottedId,
|
|
2046
|
+
code: picklist([...errorCodes, CRASH_CODE]),
|
|
2047
|
+
/** `{name}` placeholders, each one of `details`. */
|
|
2048
|
+
message: pipe(text, maxLength(120)),
|
|
2049
|
+
details: array(pipe(string(), regex(SNAKE_CASE, "a snake_case key"))),
|
|
2050
|
+
step: optional(dottedId)
|
|
2051
|
+
});
|
|
2052
|
+
var defineReasons = /* @__PURE__ */ __name((input) => parseRegistry("error reasons", array(reasonSchema), input, (reasons) => [
|
|
2053
|
+
...duplicates(reasons.map((entry) => entry.reason)).map((reason) => `"${reason}" is listed twice`),
|
|
2054
|
+
...reasons.flatMap((entry) => placeholders(entry.message).filter((name) => !entry.details.includes(name)).map((name) => `${entry.reason}: the message names {${name}}, which is not one of its details`))
|
|
2055
|
+
]), "defineReasons");
|
|
2056
|
+
var COMMON_DETAILS = ["attempts", "status", "request_id", "operation", "operation_id"];
|
|
2057
|
+
var BASE_REASONS = defineReasons([
|
|
2058
|
+
{ reason: "input.invalid", code: "validation_error", message: "the input is not valid", details: [] },
|
|
2059
|
+
{
|
|
2060
|
+
reason: "batch.read-budget",
|
|
2061
|
+
code: "validation_error",
|
|
2062
|
+
message: "batch stored-text read budget exhausted",
|
|
2063
|
+
details: []
|
|
2064
|
+
},
|
|
2065
|
+
{ reason: "batch.output-budget", code: "validation_error", message: "batch output budget exhausted", details: [] },
|
|
2066
|
+
{ reason: "config.invalid", code: "configuration_error", message: "the configuration is not valid", details: [] },
|
|
2067
|
+
{ reason: "auth.failed", code: "authentication_error", message: "the sign-in did not work", details: [] },
|
|
2068
|
+
{ reason: "access.denied", code: "permission_error", message: "this account may not do that", details: [] },
|
|
2069
|
+
{ reason: "item.not-found", code: "not_found", message: "nothing found by that name", details: [] },
|
|
2070
|
+
{
|
|
2071
|
+
reason: "tool.not-installed",
|
|
2072
|
+
code: "not_found",
|
|
2073
|
+
message: "no wcat-<name> program by that name is on PATH",
|
|
2074
|
+
details: ["tool", "installed"]
|
|
2075
|
+
},
|
|
2076
|
+
{
|
|
2077
|
+
reason: "confirmation.required",
|
|
2078
|
+
code: "confirmation_required",
|
|
2079
|
+
message: "this changes something; confirm it",
|
|
2080
|
+
details: []
|
|
2081
|
+
},
|
|
2082
|
+
{ reason: "provider.rate-limited", code: "rate_limited", message: "too many requests; wait", details: [] },
|
|
2083
|
+
{ reason: "command.timed-out", code: "timeout", message: "the command took too long", details: ["timeout_ms"] },
|
|
2084
|
+
{ reason: "network.failed", code: "network_error", message: "the network did not answer", details: [] },
|
|
2085
|
+
{ reason: "provider.refused", code: "provider_error", message: "the provider refused", details: [] },
|
|
2086
|
+
{ reason: "provider.unavailable", code: "provider_unavailable", message: "the provider is down", details: [] },
|
|
2087
|
+
{
|
|
2088
|
+
reason: "provider.invalid-response",
|
|
2089
|
+
code: "invalid_response",
|
|
2090
|
+
message: "the answer could not be read",
|
|
2091
|
+
details: []
|
|
2092
|
+
},
|
|
2093
|
+
{
|
|
2094
|
+
reason: "output.too-large",
|
|
2095
|
+
code: "invalid_response",
|
|
2096
|
+
message: "the output is over {max_bytes} bytes",
|
|
2097
|
+
details: ["max_bytes", "buffered_bytes", "partial_output"]
|
|
2098
|
+
},
|
|
2099
|
+
{
|
|
2100
|
+
reason: "output.fields-unavailable",
|
|
2101
|
+
code: "invalid_response",
|
|
2102
|
+
message: "fields can be picked only from whole JSON values",
|
|
2103
|
+
details: []
|
|
2104
|
+
},
|
|
2105
|
+
{ reason: "outcome.unknown", code: "outcome_unknown", message: "it is not known whether it worked", details: [] },
|
|
2106
|
+
{ reason: "command.cancelled", code: "cancelled", message: "the command was cancelled", details: [] },
|
|
2107
|
+
{ reason: CRASH_REASON, code: CRASH_CODE, message: "the command failed; this is a bug", details: [] }
|
|
2108
|
+
]);
|
|
2109
|
+
|
|
2110
|
+
// node_modules/.pnpm/@wirecat+cli-base@0.68.1_commander@15.0.0_esbuild@0.28.2_typescript@7.0.2_vitest@5.0.5/node_modules/@wirecat/cli-base/dist/standards/steps.js
|
|
2111
|
+
var SAME_COMMAND = "*";
|
|
2112
|
+
var commandPath = pipe(string(), regex(/^[a-z][a-z0-9-]*( [a-z][a-z0-9-]*)*$/, "a command path such as `messages sync`"));
|
|
2113
|
+
var stepSchema = union([
|
|
2114
|
+
strictObject({
|
|
2115
|
+
id: dottedId,
|
|
2116
|
+
kind: optional(literal("command"), "command"),
|
|
2117
|
+
command: union([literal(SAME_COMMAND), commandPath]),
|
|
2118
|
+
args: array(strictObject({
|
|
2119
|
+
name: pipe(string(), regex(SNAKE_CASE, "an argument or option name in snake_case")),
|
|
2120
|
+
required: boolean()
|
|
2121
|
+
})),
|
|
2122
|
+
why: pipe(text, maxLength(120))
|
|
2123
|
+
}),
|
|
2124
|
+
strictObject({ id: dottedId, kind: literal("user_action"), why: pipe(text, maxLength(120)) })
|
|
2125
|
+
]);
|
|
2126
|
+
var argsOf = /* @__PURE__ */ __name((step) => step.kind === "command" ? step.args : [], "argsOf");
|
|
2127
|
+
var defineSteps = /* @__PURE__ */ __name((input) => parseRegistry("steps", array(stepSchema), input, (steps) => [
|
|
2128
|
+
...duplicates(steps.map((step) => step.id)).map((id) => `"${id}" is listed twice`),
|
|
2129
|
+
...steps.flatMap((step) => duplicates(argsOf(step).map((arg) => arg.name)).map((name) => `${step.id}: argument "${name}" is listed twice`))
|
|
2130
|
+
]), "defineSteps");
|
|
2131
|
+
var BINDS = /^[^\p{Cc}\u2028\u2029]*$/u;
|
|
2132
|
+
var binds = /* @__PURE__ */ __name((value) => typeof value === "number" || typeof value === "boolean" || typeof value === "string" && BINDS.test(value), "binds");
|
|
2133
|
+
var stepOf = /* @__PURE__ */ __name((definition, input = {}) => {
|
|
2134
|
+
const args = input.args ?? {};
|
|
2135
|
+
if (definition.kind === "user_action")
|
|
2136
|
+
return {
|
|
2137
|
+
kind: "user_action",
|
|
2138
|
+
step: definition.id,
|
|
2139
|
+
why: fill(definition.why, { ...input.values }),
|
|
2140
|
+
safe_to_auto_execute: false
|
|
2141
|
+
};
|
|
2142
|
+
const command = definition.command === SAME_COMMAND ? input.command : definition.command;
|
|
2143
|
+
if (!command)
|
|
2144
|
+
throw new Error(`${definition.id}: the step runs the same command, so pass the command`);
|
|
2145
|
+
const known = new Set(definition.args.map((arg) => arg.name));
|
|
2146
|
+
if (definition.command !== SAME_COMMAND) {
|
|
2147
|
+
for (const name of Object.keys(args))
|
|
2148
|
+
if (!known.has(name))
|
|
2149
|
+
throw new Error(`${definition.id}: no argument "${name}"`);
|
|
2150
|
+
}
|
|
2151
|
+
for (const arg of definition.args)
|
|
2152
|
+
if (arg.required && args[arg.name] === void 0)
|
|
2153
|
+
throw new Error(`${definition.id}: argument "${arg.name}" is required`);
|
|
2154
|
+
for (const [name, value] of Object.entries(args))
|
|
2155
|
+
if (!(Array.isArray(value) ? value.every(binds) : binds(value)))
|
|
2156
|
+
throw new Error(`${definition.id}: "${name}" is not a value an option takes`);
|
|
2157
|
+
const target = input.targets?.(command);
|
|
2158
|
+
if (input.targets && !target)
|
|
2159
|
+
throw new Error(`${definition.id}: no command "${command}"`);
|
|
2160
|
+
const names = new Set(target?.names ?? []);
|
|
2161
|
+
if (target) {
|
|
2162
|
+
for (const name of Object.keys(args))
|
|
2163
|
+
if (!names.has(name))
|
|
2164
|
+
throw new Error(`${definition.id}: "${command}" takes no "${name}"`);
|
|
2165
|
+
}
|
|
2166
|
+
const scalars = Object.fromEntries(Object.entries(args).filter((entry) => ["string", "number"].includes(typeof entry[1])));
|
|
2167
|
+
return {
|
|
2168
|
+
kind: "command",
|
|
2169
|
+
step: definition.id,
|
|
2170
|
+
command,
|
|
2171
|
+
args: { ...args },
|
|
2172
|
+
why: fill(definition.why, { ...scalars, ...input.values }),
|
|
2173
|
+
safe_to_auto_execute: target?.effects !== void 0 && !writes(target.effects)
|
|
2174
|
+
};
|
|
2175
|
+
}, "stepOf");
|
|
2176
|
+
var STEPS = defineSteps([
|
|
2177
|
+
{
|
|
2178
|
+
id: "page.next",
|
|
2179
|
+
command: SAME_COMMAND,
|
|
2180
|
+
args: [
|
|
2181
|
+
{ name: "cursor", required: false },
|
|
2182
|
+
{ name: "page", required: false },
|
|
2183
|
+
{ name: "limit", required: false }
|
|
2184
|
+
],
|
|
2185
|
+
why: "{shown} shown, more exist"
|
|
2186
|
+
}
|
|
2187
|
+
]);
|
|
2188
|
+
|
|
2189
|
+
// node_modules/.pnpm/@wirecat+cli-base@0.68.1_commander@15.0.0_esbuild@0.28.2_typescript@7.0.2_vitest@5.0.5/node_modules/@wirecat/cli-base/dist/failure.js
|
|
2190
|
+
var recognise = /* @__PURE__ */ __name((failure) => {
|
|
2191
|
+
if (isCliError(failure))
|
|
2192
|
+
return failure;
|
|
2193
|
+
if (!(failure instanceof Error) || failure.name !== "CliError")
|
|
2194
|
+
return void 0;
|
|
2195
|
+
const { code, details } = failure;
|
|
2196
|
+
if (!errorCodes.includes(code))
|
|
2197
|
+
return void 0;
|
|
2198
|
+
return {
|
|
2199
|
+
code,
|
|
2200
|
+
message: failure.message,
|
|
2201
|
+
details: typeof details === "object" && details !== null ? details : {}
|
|
2202
|
+
};
|
|
2203
|
+
}, "recognise");
|
|
2204
|
+
var reasonFor = /* @__PURE__ */ __name((code, named, reasons) => reasons.find((entry) => entry.reason === named && entry.code === code) ?? BASE_REASONS.find((entry) => entry.reason === named && entry.code === code) ?? // The first base reason for each code is its fallback.
|
|
2205
|
+
BASE_REASONS.find((entry) => entry.code === code), "reasonFor");
|
|
2206
|
+
var nextFor = /* @__PURE__ */ __name((reason, details, context) => {
|
|
2207
|
+
const definition = reason.step ? context.steps?.find((step) => step.id === reason.step) : void 0;
|
|
2208
|
+
if (!definition)
|
|
2209
|
+
return [];
|
|
2210
|
+
const known = new Set(definition.kind === "command" ? definition.args.map((arg) => arg.name) : []);
|
|
2211
|
+
const args = Object.fromEntries(Object.entries(details).filter(([key, value]) => known.has(key) && value !== void 0));
|
|
2212
|
+
try {
|
|
2213
|
+
return [stepOf(definition, { args, ...context.targets ? { targets: context.targets } : {} })];
|
|
2214
|
+
} catch {
|
|
2215
|
+
return [];
|
|
2216
|
+
}
|
|
2217
|
+
}, "nextFor");
|
|
2218
|
+
var TRANSIENT = [
|
|
2219
|
+
"rate_limited",
|
|
2220
|
+
"timeout",
|
|
2221
|
+
"network_error",
|
|
2222
|
+
"provider_unavailable"
|
|
2223
|
+
];
|
|
2224
|
+
var retryOf = /* @__PURE__ */ __name((code, details, effects) => {
|
|
2225
|
+
const transient = details.retryable !== false && (TRANSIENT.includes(code) || code === "provider_error" && details.retryable === true);
|
|
2226
|
+
const safe = code !== "outcome_unknown" && transient && (!writes(effects) || details.sent === false);
|
|
2227
|
+
const after = details.retry_after_ms;
|
|
2228
|
+
return safe && typeof after === "number" && Number.isInteger(after) && after >= 0 ? { safe, after_ms: after } : { safe };
|
|
2229
|
+
}, "retryOf");
|
|
2230
|
+
var errorObjectOf = /* @__PURE__ */ __name((failure, context = {}) => {
|
|
2231
|
+
const reasons = context.reasons ?? [];
|
|
2232
|
+
const recognised = recognise(failure);
|
|
2233
|
+
if (!recognised) {
|
|
2234
|
+
const reason2 = reasonFor(CRASH_CODE, CRASH_REASON, reasons);
|
|
2235
|
+
return {
|
|
2236
|
+
error: {
|
|
2237
|
+
code: CRASH_CODE,
|
|
2238
|
+
reason: reason2.reason,
|
|
2239
|
+
message: reason2.message,
|
|
2240
|
+
retry: { safe: false },
|
|
2241
|
+
...context.runId ? { run_id: context.runId } : {}
|
|
2242
|
+
}
|
|
2243
|
+
};
|
|
2244
|
+
}
|
|
2245
|
+
const { code, message, details } = recognised;
|
|
2246
|
+
const reason = reasonFor(code, details.reason, reasons);
|
|
2247
|
+
const allowed = /* @__PURE__ */ new Set([...COMMON_DETAILS, ...context.details ?? [], ...reason.details]);
|
|
2248
|
+
allowed.delete("cause");
|
|
2249
|
+
const kept = Object.fromEntries(Object.entries(details).filter(([key, value]) => allowed.has(key) && value !== void 0));
|
|
2250
|
+
const next = nextFor(reason, details, context);
|
|
2251
|
+
const runId = context.runId ?? (typeof details.run_id === "string" ? details.run_id : void 0);
|
|
2252
|
+
return {
|
|
2253
|
+
error: {
|
|
2254
|
+
code,
|
|
2255
|
+
reason: reason.reason,
|
|
2256
|
+
message,
|
|
2257
|
+
...typeof details.param === "string" ? { param: details.param } : {},
|
|
2258
|
+
...Object.keys(kept).length > 0 ? { details: kept } : {},
|
|
2259
|
+
...next.length > 0 ? { next } : {},
|
|
2260
|
+
retry: retryOf(code, details, context.effects),
|
|
2261
|
+
...runId ? { run_id: runId } : {}
|
|
2262
|
+
}
|
|
2263
|
+
};
|
|
2264
|
+
}, "errorObjectOf");
|
|
2265
|
+
var exitCodeOfError = /* @__PURE__ */ __name(({ error }) => error.code === CRASH_CODE ? GENERIC_FAILURE : EXIT_CODES[error.code], "exitCodeOfError");
|
|
2266
|
+
var exitCodeOfAnswer = /* @__PURE__ */ __name((meta, partial2 = false) => {
|
|
2267
|
+
if (meta.complete || partial2)
|
|
2268
|
+
return 0;
|
|
2269
|
+
const code = meta.issues?.[0]?.code;
|
|
2270
|
+
return code === void 0 ? GENERIC_FAILURE : EXIT_CODES[code];
|
|
2271
|
+
}, "exitCodeOfAnswer");
|
|
2272
|
+
var kebab = /* @__PURE__ */ __name((name) => name.replaceAll("_", "-"), "kebab");
|
|
2273
|
+
var commandLine = /* @__PURE__ */ __name((cli, step) => [
|
|
2274
|
+
cli,
|
|
2275
|
+
step.command,
|
|
2276
|
+
...Object.entries(step.args).map(([name, value]) => value === true ? `--${kebab(name)}` : `--${kebab(name)} ${JSON.stringify(value)}`)
|
|
2277
|
+
].join(" "), "commandLine");
|
|
2278
|
+
var STACK_FRAMES = 10;
|
|
2279
|
+
var errorRecordOf = /* @__PURE__ */ __name((failure, object2, options) => {
|
|
2280
|
+
const thrown = failure instanceof Error ? failure : void 0;
|
|
2281
|
+
const { cause, ...details } = recognise(failure)?.details ?? {};
|
|
2282
|
+
const stack = thrown?.stack?.split("\n").slice(1, STACK_FRAMES + 1).map((line) => visibleControls(line.trim()));
|
|
2283
|
+
const reason = thrown?.cause ?? cause;
|
|
2284
|
+
return {
|
|
2285
|
+
time: (options.time ?? /* @__PURE__ */ new Date()).toISOString(),
|
|
2286
|
+
severity: "error",
|
|
2287
|
+
body: "command.failed",
|
|
2288
|
+
...object2.error.run_id ? { run_id: object2.error.run_id } : {},
|
|
2289
|
+
command: options.command,
|
|
2290
|
+
attributes: {
|
|
2291
|
+
code: object2.error.code,
|
|
2292
|
+
reason: object2.error.reason,
|
|
2293
|
+
message: object2.error.message,
|
|
2294
|
+
...Object.keys(details).length > 0 ? { details } : {},
|
|
2295
|
+
...thrown ? { name: thrown.name, thrown_message: visibleControls(thrown.message) } : { thrown: String(failure) },
|
|
2296
|
+
...reason === void 0 ? {} : { cause: visibleControls(reason instanceof Error ? reason.message : String(reason)) },
|
|
2297
|
+
...stack && stack.length > 0 ? { stack } : {}
|
|
2298
|
+
},
|
|
2299
|
+
resource: { service: options.service, version: options.version }
|
|
2300
|
+
};
|
|
2301
|
+
}, "errorRecordOf");
|
|
2302
|
+
var renderError = /* @__PURE__ */ __name((object2, options) => {
|
|
2303
|
+
if (!options.interactive)
|
|
2304
|
+
return [JSON.stringify(object2), ...options.record ? [JSON.stringify(options.record)] : []].join("\n");
|
|
2305
|
+
const { message, next, run_id: runId } = object2.error;
|
|
2306
|
+
const step = next?.[0];
|
|
2307
|
+
return [
|
|
2308
|
+
`\u2717 ${visibleControls(message)}`,
|
|
2309
|
+
...step?.kind === "command" ? [`\u2192 ${visibleControls(step.why)}: ${visibleControls(step.line ?? commandLine(options.cli, step))}`] : step ? [`\u2192 ${visibleControls(step.why)}`] : [],
|
|
2310
|
+
...options.record ? [JSON.stringify(options.record, null, 2)] : runId ? [`details: ${options.cli} runs show ${runId}`] : []
|
|
2311
|
+
].join("\n");
|
|
2312
|
+
}, "renderError");
|
|
2313
|
+
var mcpErrorResult = /* @__PURE__ */ __name((object2) => ({
|
|
2314
|
+
content: [{ type: "text", text: JSON.stringify(object2) }],
|
|
2315
|
+
structuredContent: object2,
|
|
2316
|
+
isError: true
|
|
2317
|
+
}), "mcpErrorResult");
|
|
2318
|
+
var catchCrashes = /* @__PURE__ */ __name((options) => {
|
|
2319
|
+
const target = options.target ?? process;
|
|
2320
|
+
const write = options.write ?? ((text2) => process.stderr.write(`${text2}
|
|
2321
|
+
`));
|
|
2322
|
+
const exit = options.exit ?? ((code) => process.exit(code));
|
|
2323
|
+
const crashed = /* @__PURE__ */ __name((failure) => {
|
|
2324
|
+
const object2 = errorObjectOf(failure, options);
|
|
2325
|
+
write(renderError(object2, { cli: options.cli, interactive: options.interactive }));
|
|
2326
|
+
exit(exitCodeOfError(object2));
|
|
2327
|
+
}, "crashed");
|
|
2328
|
+
target.on("uncaughtException", crashed);
|
|
2329
|
+
target.on("unhandledRejection", crashed);
|
|
2330
|
+
return () => {
|
|
2331
|
+
target.off("uncaughtException", crashed);
|
|
2332
|
+
target.off("unhandledRejection", crashed);
|
|
2333
|
+
};
|
|
2334
|
+
}, "catchCrashes");
|
|
2335
|
+
|
|
2336
|
+
export {
|
|
2337
|
+
EXIT_CODES,
|
|
2338
|
+
exitCodeFor,
|
|
2339
|
+
GENERIC_FAILURE,
|
|
2340
|
+
getDotPath,
|
|
2341
|
+
check,
|
|
2342
|
+
description,
|
|
2343
|
+
finite,
|
|
2344
|
+
integer,
|
|
2345
|
+
isoDate,
|
|
2346
|
+
isoTimestamp,
|
|
2347
|
+
maxLength,
|
|
2348
|
+
maxValue,
|
|
2349
|
+
minLength,
|
|
2350
|
+
minValue,
|
|
2351
|
+
nonEmpty,
|
|
2352
|
+
regex,
|
|
2353
|
+
safeInteger,
|
|
2354
|
+
transform,
|
|
2355
|
+
trim,
|
|
2356
|
+
forward,
|
|
2357
|
+
array,
|
|
2358
|
+
boolean,
|
|
2359
|
+
lazy,
|
|
2360
|
+
literal,
|
|
2361
|
+
looseObject,
|
|
2362
|
+
null_,
|
|
2363
|
+
nullable,
|
|
2364
|
+
number,
|
|
2365
|
+
object,
|
|
2366
|
+
objectWithRest,
|
|
2367
|
+
optional,
|
|
2368
|
+
picklist,
|
|
2369
|
+
record,
|
|
2370
|
+
strictObject,
|
|
2371
|
+
string,
|
|
2372
|
+
union,
|
|
2373
|
+
unknown,
|
|
2374
|
+
variant,
|
|
2375
|
+
omit,
|
|
2376
|
+
parse,
|
|
2377
|
+
partial,
|
|
2378
|
+
pick,
|
|
2379
|
+
pipe,
|
|
2380
|
+
safeParse,
|
|
2381
|
+
summarize,
|
|
2382
|
+
unwrap,
|
|
2383
|
+
effectsSchema,
|
|
2384
|
+
writes,
|
|
2385
|
+
toJsonSchema,
|
|
2386
|
+
toStandardJsonSchema,
|
|
2387
|
+
word,
|
|
2388
|
+
SNAKE_CASE,
|
|
2389
|
+
text,
|
|
2390
|
+
dottedId,
|
|
2391
|
+
RegistryError,
|
|
2392
|
+
parseRegistry,
|
|
2393
|
+
duplicates,
|
|
2394
|
+
jsonSchemaOf,
|
|
2395
|
+
MAX_NEXT_STEPS,
|
|
2396
|
+
isoTime,
|
|
2397
|
+
reference,
|
|
2398
|
+
pageSchema,
|
|
2399
|
+
listEnvelopeSchema,
|
|
2400
|
+
itemEnvelopeSchema,
|
|
2401
|
+
jsonlOf,
|
|
2402
|
+
CRASH_CODE,
|
|
2403
|
+
errorObjectSchema,
|
|
2404
|
+
defineReasons,
|
|
2405
|
+
defineSteps,
|
|
2406
|
+
stepOf,
|
|
2407
|
+
STEPS,
|
|
2408
|
+
retryOf,
|
|
2409
|
+
errorObjectOf,
|
|
2410
|
+
exitCodeOfError,
|
|
2411
|
+
exitCodeOfAnswer,
|
|
2412
|
+
errorRecordOf,
|
|
2413
|
+
renderError,
|
|
2414
|
+
mcpErrorResult,
|
|
2415
|
+
catchCrashes
|
|
2416
|
+
};
|