@jixo/cli 0.25.0 → 0.26.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/assets/bundle/google-aistudio.browser.js +562 -2433
- package/assets/bundle/google-aistudio.jixo.js +63655 -0
- package/assets/prompt.json +1 -1
- package/assets/tools.json +1 -0
- package/bundle/{acorn-CU7YmuGp.js → acorn-BJF4qA9z.js} +17 -39
- package/bundle/acorn-BJF4qA9z.js.map +1 -0
- package/bundle/{angular-BZFEnvyh.js → angular-Cu7-vCtW.js} +44 -207
- package/bundle/angular-Cu7-vCtW.js.map +1 -0
- package/bundle/{babel-BC5Ty8sN.js → babel-ZTOL0_x6.js} +109 -125
- package/bundle/babel-ZTOL0_x6.js.map +1 -0
- package/bundle/{estree-DZTSfOv_.js → estree-5JRlNokb.js} +9 -10
- package/bundle/estree-5JRlNokb.js.map +1 -0
- package/bundle/file-replacer-CQZSjZXb.js +3 -0
- package/bundle/{file-replacer-cUUAxJ6b.js → file-replacer-CZhq6MJJ.js} +1543 -1127
- package/bundle/file-replacer-CZhq6MJJ.js.map +1 -0
- package/bundle/{flow-CNTeHoxv.js → flow-Cd3L1dMY.js} +482 -680
- package/bundle/flow-Cd3L1dMY.js.map +1 -0
- package/bundle/{gen-prompt-qt1W8jAy.js → gen-prompt-3bZp8K__.js} +5610 -526
- package/bundle/gen-prompt-3bZp8K__.js.map +1 -0
- package/bundle/gen-prompt-IINGP6mf.js +4 -0
- package/bundle/{glimmer-DYkbcawC.js → glimmer-N8tyHqy2.js} +29 -47
- package/bundle/glimmer-N8tyHqy2.js.map +1 -0
- package/bundle/{graphql-fCaNVuM0.js → graphql-BsfPfzVT.js} +8 -8
- package/bundle/graphql-BsfPfzVT.js.map +1 -0
- package/bundle/{html-Bb8ztcZq.js → html-CV8zEM7F.js} +8 -10
- package/bundle/html-CV8zEM7F.js.map +1 -0
- package/bundle/index.js +16415 -7240
- package/bundle/index.js.map +1 -0
- package/bundle/{markdown-ChusAllR.js → markdown-Cq8CRcxA.js} +5 -89
- package/bundle/markdown-Cq8CRcxA.js.map +1 -0
- package/bundle/{meriyah-9NeL3We4.js → meriyah-f8qRdfjZ.js} +10 -16
- package/bundle/meriyah-f8qRdfjZ.js.map +1 -0
- package/bundle/{postcss-DXCUuMfC.js → postcss-CtnQb9ad.js} +69 -159
- package/bundle/postcss-CtnQb9ad.js.map +1 -0
- package/bundle/{typescript-C2HFEnMP.js → typescript-BQw1QTVg.js} +55 -106
- package/bundle/typescript-BQw1QTVg.js.map +1 -0
- package/bundle/{yaml-ByEZ6gmG.js → yaml-B5kqwurc.js} +55 -127
- package/bundle/yaml-B5kqwurc.js.map +1 -0
- package/dist/commands/google-aistudio.d.ts.map +1 -1
- package/dist/commands/google-aistudio.js +6 -16
- package/dist/commands/google-aistudio.js.map +1 -1
- package/dist/commands/groq.js +1 -1
- package/dist/commands/groq.js.map +1 -1
- package/dist/prompts.json +2 -14
- package/dist/runCli.js +3 -3
- package/dist/runCli.js.map +1 -1
- package/package.json +9 -8
- package/assets/bundle/groq.browser.js +0 -3714
- package/bundle/external-CS43xY0F.js +0 -285
- package/bundle/file-replacer-nbB4NnrU.js +0 -3
- package/bundle/gen-prompt-BxI7DHUD.js +0 -4
- package/dist/cli.d.ts +0 -2
- package/dist/cli.d.ts.map +0 -1
- package/dist/cli.js +0 -83
- package/dist/cli.js.map +0 -1
- package/dist/commands/daemon.d.ts +0 -5
- package/dist/commands/daemon.d.ts.map +0 -1
- package/dist/commands/daemon.js +0 -20
- package/dist/commands/daemon.js.map +0 -1
- package/dist/commands/doctor/config.d.ts +0 -3
- package/dist/commands/doctor/config.d.ts.map +0 -1
- package/dist/commands/doctor/config.js +0 -17
- package/dist/commands/doctor/config.js.map +0 -1
- package/dist/commands/doctor/doctor.d.ts +0 -3
- package/dist/commands/doctor/doctor.d.ts.map +0 -1
- package/dist/commands/doctor/doctor.js +0 -158
- package/dist/commands/doctor/doctor.js.map +0 -1
- package/dist/commands/doctor/doctor.test.d.ts +0 -2
- package/dist/commands/doctor/doctor.test.d.ts.map +0 -1
- package/dist/commands/doctor/doctor.test.js +0 -14
- package/dist/commands/doctor/doctor.test.js.map +0 -1
- package/dist/commands/doctor/index.d.ts +0 -2
- package/dist/commands/doctor/index.d.ts.map +0 -1
- package/dist/commands/doctor/index.js +0 -8
- package/dist/commands/doctor/index.js.map +0 -1
- package/dist/commands/doctor/types.d.ts +0 -45
- package/dist/commands/doctor/types.d.ts.map +0 -1
- package/dist/commands/doctor/types.js +0 -3
- package/dist/commands/doctor/types.js.map +0 -1
- package/dist/commands/init.d.ts +0 -2
- package/dist/commands/init.d.ts.map +0 -1
- package/dist/commands/init.js +0 -40
- package/dist/commands/init.js.map +0 -1
- package/dist/commands/tasks/run.d.ts +0 -10
- package/dist/commands/tasks/run.d.ts.map +0 -1
- package/dist/commands/tasks/run.js +0 -44
- package/dist/commands/tasks/run.js.map +0 -1
- package/dist/config.d.ts +0 -15
- package/dist/config.d.ts.map +0 -1
- package/dist/config.js +0 -23
- package/dist/config.js.map +0 -1
- package/dist/env.d.ts +0 -6
- package/dist/env.d.ts.map +0 -1
- package/dist/env.js +0 -16
- package/dist/env.js.map +0 -1
|
@@ -4,17 +4,33 @@ const obj_assign_props = /* @__NO_SIDE_EFFECTS__ */ (a$1, b$1) => {
|
|
|
4
4
|
return a$1;
|
|
5
5
|
};
|
|
6
6
|
const isPromiseLike = (value) => value !== null && typeof value?.then === "function";
|
|
7
|
-
const func_remember = /* @__NO_SIDE_EFFECTS__ */ (func, key) => {
|
|
7
|
+
const func_remember = /* @__NO_SIDE_EFFECTS__ */ (func, key, cacheAwaited) => {
|
|
8
8
|
let result;
|
|
9
9
|
const once_fn = function(...args) {
|
|
10
10
|
const newKey = key?.apply(this, args);
|
|
11
|
-
if (result === void 0 || newKey !== result.key)
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
if (result === void 0 || newKey !== result.key) {
|
|
12
|
+
const res = func.apply(this, args);
|
|
13
|
+
result = {
|
|
14
|
+
key: newKey,
|
|
15
|
+
res,
|
|
16
|
+
awaitedRes: void 0
|
|
17
|
+
};
|
|
18
|
+
if (cacheAwaited) if (typeof res === "object" && res && "then" in res && typeof res.then === "function") res.then((r$1) => {
|
|
19
|
+
if (result && res === result.res) result.awaitedRes = {
|
|
20
|
+
type: "resolved",
|
|
21
|
+
result: r$1
|
|
22
|
+
};
|
|
23
|
+
}, (e$1) => {
|
|
24
|
+
if (result && res === result.res) result.awaitedRes = {
|
|
25
|
+
type: "rejected",
|
|
26
|
+
error: e$1
|
|
27
|
+
};
|
|
28
|
+
});
|
|
29
|
+
else result.awaitedRes = res;
|
|
30
|
+
}
|
|
15
31
|
return result.res;
|
|
16
32
|
};
|
|
17
|
-
const once_fn_mix =
|
|
33
|
+
const once_fn_mix = /* @__PURE__ */ obj_assign_props(once_fn, {
|
|
18
34
|
get source() {
|
|
19
35
|
return func;
|
|
20
36
|
},
|
|
@@ -27,6 +43,9 @@ const func_remember = /* @__NO_SIDE_EFFECTS__ */ (func, key) => {
|
|
|
27
43
|
get returnValue() {
|
|
28
44
|
return result?.res;
|
|
29
45
|
},
|
|
46
|
+
get awaitedReturnValue() {
|
|
47
|
+
return result?.awaitedRes;
|
|
48
|
+
},
|
|
30
49
|
reset() {
|
|
31
50
|
result = void 0;
|
|
32
51
|
},
|
|
@@ -35,29 +54,6 @@ const func_remember = /* @__NO_SIDE_EFFECTS__ */ (func, key) => {
|
|
|
35
54
|
return once_fn_mix(...args);
|
|
36
55
|
}
|
|
37
56
|
});
|
|
38
|
-
Object.defineProperties(once_fn_mix, {
|
|
39
|
-
source: {
|
|
40
|
-
value: func,
|
|
41
|
-
writable: false,
|
|
42
|
-
configurable: true,
|
|
43
|
-
enumerable: true
|
|
44
|
-
},
|
|
45
|
-
key: {
|
|
46
|
-
get: () => result?.key,
|
|
47
|
-
configurable: true,
|
|
48
|
-
enumerable: true
|
|
49
|
-
},
|
|
50
|
-
runned: {
|
|
51
|
-
get: () => result != null,
|
|
52
|
-
configurable: true,
|
|
53
|
-
enumerable: true
|
|
54
|
-
},
|
|
55
|
-
returnValue: {
|
|
56
|
-
get: () => result?.res,
|
|
57
|
-
configurable: true,
|
|
58
|
-
enumerable: true
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
57
|
return once_fn_mix;
|
|
62
58
|
};
|
|
63
59
|
const wrapSuccess = (result) => {
|
|
@@ -121,7 +117,6 @@ const func_catch = /* @__PURE__ */ Object.assign((fn, errorParser) => {
|
|
|
121
117
|
wrapSuccess,
|
|
122
118
|
wrapError
|
|
123
119
|
});
|
|
124
|
-
const effect_symbol = Symbol.for("effect");
|
|
125
120
|
const timmers = {
|
|
126
121
|
timeout: (ms) => {
|
|
127
122
|
return (cb) => {
|
|
@@ -165,6 +160,19 @@ const timmers = {
|
|
|
165
160
|
return typeof ms === "number" ? ms <= 0 ? timmers.microtask : timmers.timeout(ms) : ms;
|
|
166
161
|
}
|
|
167
162
|
};
|
|
163
|
+
const abort_signal_merge = (..._signals) => {
|
|
164
|
+
const signals = _signals.filter((s$1) => s$1 != null);
|
|
165
|
+
if (signals.length === 0) return;
|
|
166
|
+
if (signals.length === 1) return signals[0];
|
|
167
|
+
const aborted_signals = signals.filter((signal) => signal.aborted);
|
|
168
|
+
if (aborted_signals.length === 1) return aborted_signals[0];
|
|
169
|
+
if (aborted_signals.length > 1) return AbortSignal.abort(new AggregateError(aborted_signals.map((signal) => signal.reason), "multi-signals are aborted"));
|
|
170
|
+
const aborter = new AbortController();
|
|
171
|
+
for (const signal of signals) signal.addEventListener("abort", (reason) => {
|
|
172
|
+
aborter.abort(reason);
|
|
173
|
+
});
|
|
174
|
+
return aborter.signal;
|
|
175
|
+
};
|
|
168
176
|
const func_throttle = (fn, wait = 0, options = {}) => {
|
|
169
177
|
const timmer = timmers.from(wait);
|
|
170
178
|
let clear;
|
|
@@ -208,139 +216,32 @@ const func_throttle = (fn, wait = 0, options = {}) => {
|
|
|
208
216
|
}
|
|
209
217
|
});
|
|
210
218
|
};
|
|
211
|
-
let
|
|
212
|
-
const
|
|
213
|
-
if (rootDirHandle) return rootDirHandle;
|
|
219
|
+
let restoredDirHandle;
|
|
220
|
+
const pickDirHandle = async () => {
|
|
214
221
|
const ti = setTimeout(() => {
|
|
215
|
-
console.log("%c等待用户动作:
|
|
222
|
+
console.log("%c等待用户动作: 请选择一个文件夹", styles.info);
|
|
216
223
|
}, 100);
|
|
217
224
|
try {
|
|
218
|
-
|
|
219
|
-
console.log(`%c✅ 根文件夹已选择: %c${rootDirHandle.name}`, styles.success, styles.code);
|
|
220
|
-
return rootDirHandle;
|
|
225
|
+
return await window.showDirectoryPicker({ mode: "readwrite" });
|
|
221
226
|
} catch (e$1) {
|
|
222
227
|
clearTimeout(ti);
|
|
223
228
|
if (e$1 instanceof Error) {
|
|
224
229
|
if (e$1.name === "SecurityError" || e$1.name === "NotAllowedError") {
|
|
225
230
|
console.log("%c请将鼠标聚焦到窗口视图中", styles.info);
|
|
226
231
|
await delay(1e3);
|
|
227
|
-
return
|
|
232
|
+
return pickDirHandle();
|
|
228
233
|
}
|
|
229
234
|
if (e$1.name === "AbortError") throw new DOMException("用户取消了文件夹选择", "AbortError");
|
|
230
235
|
}
|
|
231
236
|
throw e$1;
|
|
237
|
+
} finally {
|
|
238
|
+
clearTimeout(ti);
|
|
232
239
|
}
|
|
233
240
|
};
|
|
234
|
-
const
|
|
235
|
-
const
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
throw error;
|
|
239
|
-
}
|
|
240
|
-
const getHandle = async (path, { create = false } = {}) => {
|
|
241
|
-
let curr = dirHandle;
|
|
242
|
-
const parts = path.split("/").filter(Boolean);
|
|
243
|
-
const last = parts.at(-1);
|
|
244
|
-
for (let i$1 = 0; i$1 < parts.length - 1; i$1++) curr = await curr.getDirectoryHandle(parts[i$1], { create });
|
|
245
|
-
return {
|
|
246
|
-
parent: curr,
|
|
247
|
-
name: last,
|
|
248
|
-
async getFile() {
|
|
249
|
-
if (!last) throw new Error("No file name");
|
|
250
|
-
return curr.getFileHandle(last, { create });
|
|
251
|
-
},
|
|
252
|
-
async getDir() {
|
|
253
|
-
if (!last) return curr;
|
|
254
|
-
return curr.getDirectoryHandle(last, { create });
|
|
255
|
-
}
|
|
256
|
-
};
|
|
257
|
-
};
|
|
258
|
-
const writeFile = async (filePath, data, opts) => {
|
|
259
|
-
const { getFile } = await getHandle(filePath, { create: true });
|
|
260
|
-
const handle = await getFile();
|
|
261
|
-
const w$1 = await handle.createWritable();
|
|
262
|
-
if (!opts?.append) await w$1.truncate(0);
|
|
263
|
-
await w$1.write(data);
|
|
264
|
-
await w$1.close();
|
|
265
|
-
};
|
|
266
|
-
const createWriteStream = async (filePath) => {
|
|
267
|
-
const { getFile } = await getHandle(filePath, { create: true });
|
|
268
|
-
const handle = await getFile();
|
|
269
|
-
return handle.createWritable();
|
|
270
|
-
};
|
|
271
|
-
const readFileText = async (filePath) => {
|
|
272
|
-
const { getFile } = await getHandle(filePath);
|
|
273
|
-
const file = await (await getFile()).getFile();
|
|
274
|
-
return file.text();
|
|
275
|
-
};
|
|
276
|
-
const readFileBinary = async (filePath) => {
|
|
277
|
-
const { getFile } = await getHandle(filePath);
|
|
278
|
-
const file = await (await getFile()).getFile();
|
|
279
|
-
return file.bytes();
|
|
280
|
-
};
|
|
281
|
-
const createReadStream = async (filePath) => {
|
|
282
|
-
const { getFile } = await getHandle(filePath);
|
|
283
|
-
const file = await (await getFile()).getFile();
|
|
284
|
-
return file.stream();
|
|
285
|
-
};
|
|
286
|
-
const readdir = async (dirPath) => {
|
|
287
|
-
const { getDir } = await getHandle(dirPath);
|
|
288
|
-
const dir = await getDir();
|
|
289
|
-
return Array.fromAsync(dir.keys());
|
|
290
|
-
};
|
|
291
|
-
const mkdir = async (dirPath, opts) => {
|
|
292
|
-
const parts = dirPath.split("/").filter(Boolean);
|
|
293
|
-
let curr = dirHandle;
|
|
294
|
-
for (const segment of parts) {
|
|
295
|
-
curr = await curr.getDirectoryHandle(segment, { create: true });
|
|
296
|
-
if (!opts?.recursive) break;
|
|
297
|
-
}
|
|
298
|
-
};
|
|
299
|
-
const exists = async (path) => {
|
|
300
|
-
try {
|
|
301
|
-
await getHandle(path);
|
|
302
|
-
return true;
|
|
303
|
-
} catch {
|
|
304
|
-
return false;
|
|
305
|
-
}
|
|
306
|
-
};
|
|
307
|
-
const stat = async (path) => {
|
|
308
|
-
const { getFile, getDir } = await getHandle(path);
|
|
309
|
-
try {
|
|
310
|
-
const h$1 = await getFile();
|
|
311
|
-
const f$1 = await h$1.getFile();
|
|
312
|
-
return {
|
|
313
|
-
isFile: true,
|
|
314
|
-
size: f$1.size,
|
|
315
|
-
lastModified: f$1.lastModified
|
|
316
|
-
};
|
|
317
|
-
} catch {
|
|
318
|
-
await getDir();
|
|
319
|
-
return { isFile: false };
|
|
320
|
-
}
|
|
321
|
-
};
|
|
322
|
-
const rm = async (path, opts) => {
|
|
323
|
-
try {
|
|
324
|
-
const { parent, name } = await getHandle(path);
|
|
325
|
-
if (!name) throw new Error("Invalid path");
|
|
326
|
-
await parent.removeEntry(name, { recursive: opts?.recursive });
|
|
327
|
-
return true;
|
|
328
|
-
} catch {
|
|
329
|
-
return false;
|
|
330
|
-
}
|
|
331
|
-
};
|
|
332
|
-
return {
|
|
333
|
-
writeFile,
|
|
334
|
-
createWriteStream,
|
|
335
|
-
readFileText,
|
|
336
|
-
readFileBinary,
|
|
337
|
-
createReadStream,
|
|
338
|
-
readdir,
|
|
339
|
-
mkdir,
|
|
340
|
-
exists,
|
|
341
|
-
stat,
|
|
342
|
-
rm
|
|
343
|
-
};
|
|
241
|
+
const prepareDirHandle = /* @__PURE__ */ func_remember(async () => {
|
|
242
|
+
const rootDirHandle = restoredDirHandle ?? await pickDirHandle();
|
|
243
|
+
console.log(`%c✅ 根文件夹已选择,用来作为内容导入导出的协作目录: %c${rootDirHandle.name}`, styles.success, styles.code);
|
|
244
|
+
return rootDirHandle;
|
|
344
245
|
});
|
|
345
246
|
const styles = {
|
|
346
247
|
header: "color: #4CAF50; font-size: 18px; font-weight: bold; border-bottom: 2px solid #4CAF50; padding-bottom: 5px;",
|
|
@@ -350,66 +251,98 @@ const styles = {
|
|
|
350
251
|
code: "background-color: #f0f0f0; color: #333; padding: 2px 4px; border-radius: 3px; font-family: monospace;",
|
|
351
252
|
warn: "color: #FFC107;"
|
|
352
253
|
};
|
|
353
|
-
const arrayFromAsync = async (iter) => {
|
|
354
|
-
const arr = [];
|
|
355
|
-
for await (const item of iter) arr.push(item);
|
|
356
|
-
return arr;
|
|
357
|
-
};
|
|
358
254
|
const getTargetNamespace = () => location.pathname.split("/").at(-1);
|
|
359
|
-
const delay = (ms) => new Promise((
|
|
360
|
-
const
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
255
|
+
const delay = (ms, { signal } = {}) => new Promise((resolve, reject) => {
|
|
256
|
+
const ti = setTimeout(resolve, ms);
|
|
257
|
+
signal?.addEventListener("abort", () => {
|
|
258
|
+
clearTimeout(ti);
|
|
259
|
+
reject(signal.reason);
|
|
260
|
+
});
|
|
261
|
+
});
|
|
262
|
+
const raf = () => new Promise((cb) => requestAnimationFrame(cb));
|
|
263
|
+
const untilRaf = async (condition, { timeout = 3e3, signal } = {}) => {
|
|
264
|
+
const timeoutSignal = createTimeoutSignal(timeout, signal, `untilRaf(${condition.toString()})`);
|
|
265
|
+
while (!await condition()) {
|
|
266
|
+
await raf();
|
|
267
|
+
timeoutSignal?.throwIfAborted();
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
const $ = (selectors) => document.querySelector(selectors);
|
|
271
|
+
const createTimeoutSignal = (timeout, signal, reason) => {
|
|
272
|
+
return abort_signal_merge(signal, timeout > 0 ? (() => {
|
|
273
|
+
const abortController = new AbortController();
|
|
274
|
+
const ti = setTimeout(() => {
|
|
275
|
+
abortController.abort(new Error(reason));
|
|
276
|
+
}, timeout);
|
|
277
|
+
signal?.addEventListener("abort", () => clearTimeout(ti));
|
|
278
|
+
return abortController.signal;
|
|
279
|
+
})() : null);
|
|
280
|
+
};
|
|
281
|
+
const while$ = async (selectors, options = {}) => {
|
|
282
|
+
const { timeout = 3e3, signal } = options;
|
|
283
|
+
const timeoutSignal = createTimeoutSignal(timeout, signal, `while$(${selectors})`);
|
|
284
|
+
while (true) {
|
|
285
|
+
const ele = $(selectors);
|
|
286
|
+
if (ele != null) return ele;
|
|
287
|
+
await raf();
|
|
288
|
+
timeoutSignal?.throwIfAborted();
|
|
289
|
+
}
|
|
290
|
+
};
|
|
291
|
+
const $$ = (selectors) => document.querySelectorAll(selectors);
|
|
292
|
+
const fillFunctionCall = async (signal) => {
|
|
293
|
+
if (signal?.aborted) return;
|
|
294
|
+
const rootDirHandle = await prepareDirHandle();
|
|
364
295
|
const targetName = getTargetNamespace();
|
|
365
|
-
const keys = await arrayFromAsync(rootDirHandle
|
|
366
|
-
const callTaskname
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
top: chatContainerEle.scrollHeight - chatContainerEle.clientHeight,
|
|
376
|
-
behavior: "smooth"
|
|
377
|
-
});
|
|
378
|
-
await delay(1e3);
|
|
379
|
-
};
|
|
380
|
-
const findFunctionCallResponseTextareaEle = () => document.querySelector("textarea[placeholder=\"Enter function response\"]");
|
|
381
|
-
const waitFunctionCallResponseTextareaEle = async () => {
|
|
382
|
-
while (true) {
|
|
383
|
-
const ele = findFunctionCallResponseTextareaEle();
|
|
384
|
-
if (ele) return ele;
|
|
385
|
-
await scrollToBottom();
|
|
296
|
+
const keys = await arrayFromAsync(rootDirHandle.keys());
|
|
297
|
+
for (const callTaskname of keys.filter((key) => key.endsWith(".function_call.json") && key.startsWith(targetName))) {
|
|
298
|
+
if (signal?.aborted) return;
|
|
299
|
+
const taskFile = await (await rootDirHandle.getFileHandle(callTaskname)).getFile();
|
|
300
|
+
const taskResponse = JSON.parse(await taskFile.text());
|
|
301
|
+
if (!taskResponse.output) return;
|
|
302
|
+
const lastBtn = [...(await while$("ms-prompt-scrollbar", { signal })).querySelectorAll("button")].at(-1);
|
|
303
|
+
if (lastBtn) {
|
|
304
|
+
lastBtn.click();
|
|
305
|
+
await untilRaf(() => lastBtn.classList.contains("ms-button-active"));
|
|
386
306
|
}
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
textareaEle.dispatchEvent(new Event("input"));
|
|
392
|
-
await delay(150);
|
|
393
|
-
const findFunctionCallResponseButtonEle = () => document.querySelector(`button[mattooltip="Send response"]`);
|
|
394
|
-
const waitFunctionCallResponseButtonEle = async () => {
|
|
395
|
-
while (true) {
|
|
396
|
-
const ele = findFunctionCallResponseButtonEle();
|
|
397
|
-
if (ele) return ele;
|
|
398
|
-
await scrollToBottom();
|
|
307
|
+
const functionCallEles = [...$$("ms-function-call-chunk")];
|
|
308
|
+
if (functionCallEles.length === 0) {
|
|
309
|
+
console.error("找不到任何可以进行function-call的输入");
|
|
310
|
+
return;
|
|
399
311
|
}
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
};
|
|
405
|
-
const syncInput = async (fps = 3) => {
|
|
406
|
-
(async () => {
|
|
407
|
-
while (true) {
|
|
408
|
-
await fillFunctionCall();
|
|
409
|
-
await delay(1e3 / fps);
|
|
312
|
+
const functionCallEle = functionCallEles.find((ele) => ele.querySelector("mat-panel-title")?.textContent?.trim() === `function ${taskResponse.name}` && JSON.stringify(JSON.parse(ele.querySelector("code")?.textContent ?? "{}")) === taskResponse.parameters);
|
|
313
|
+
if (null == functionCallEle) {
|
|
314
|
+
console.warn(`找不到指定的可以进行function-call-ele: ${taskResponse.name}(${taskResponse.parameters})`);
|
|
315
|
+
return;
|
|
410
316
|
}
|
|
411
|
-
|
|
317
|
+
const responseTextEle = functionCallEle.querySelector("input[placeholder=\"Enter function response\"]");
|
|
318
|
+
if (!responseTextEle || responseTextEle.disabled) return;
|
|
319
|
+
responseTextEle.value = typeof taskResponse.output === "string" ? taskResponse.output : JSON.stringify(taskResponse.output, null, 2);
|
|
320
|
+
responseTextEle.dispatchEvent(new Event("input"));
|
|
321
|
+
const buttonEle = functionCallEle.querySelector("form button");
|
|
322
|
+
if (!buttonEle) return;
|
|
323
|
+
await untilRaf(() => buttonEle.ariaDisabled === "false");
|
|
324
|
+
buttonEle.click();
|
|
325
|
+
await rootDirHandle.removeEntry(callTaskname);
|
|
326
|
+
}
|
|
327
|
+
};
|
|
328
|
+
const syncInput = async (signal, fps = 3) => {
|
|
329
|
+
if (signal?.aborted) {
|
|
330
|
+
console.log("JIXO BROWSER: syncOutput aborted before starting.");
|
|
331
|
+
return;
|
|
332
|
+
}
|
|
333
|
+
signal?.addEventListener("abort", () => {
|
|
334
|
+
console.log("JIXO BROWSER: syncInput aborted.");
|
|
335
|
+
});
|
|
336
|
+
while (!signal?.aborted) {
|
|
337
|
+
await fillFunctionCall(signal);
|
|
338
|
+
await delay(1e3 / fps);
|
|
339
|
+
}
|
|
412
340
|
};
|
|
341
|
+
async function arrayFromAsync(iter) {
|
|
342
|
+
const arr = [];
|
|
343
|
+
for await (const i$1 of iter) arr.push(i$1);
|
|
344
|
+
return arr;
|
|
345
|
+
}
|
|
413
346
|
const t = Symbol.for("@ts-pattern/matcher"), e = Symbol.for("@ts-pattern/isVariadic"), n = "@ts-pattern/anonymous-select-key", r = (t$1) => Boolean(t$1 && "object" == typeof t$1), i = (e$1) => e$1 && !!e$1[t], o = (n$1, s$1, c$1) => {
|
|
414
347
|
if (i(n$1)) {
|
|
415
348
|
const e$1 = n$1[t](), { matched: r$1, selections: i$1 } = e$1.match(s$1);
|
|
@@ -456,13 +389,13 @@ function a(...t$1) {
|
|
|
456
389
|
}
|
|
457
390
|
function u(t$1) {
|
|
458
391
|
return Object.assign(t$1, {
|
|
459
|
-
optional: () =>
|
|
392
|
+
optional: () => l(t$1),
|
|
460
393
|
and: (e$1) => m(t$1, e$1),
|
|
461
394
|
or: (e$1) => d(t$1, e$1),
|
|
462
395
|
select: (e$1) => void 0 === e$1 ? y(t$1) : y(e$1, t$1)
|
|
463
396
|
});
|
|
464
397
|
}
|
|
465
|
-
function
|
|
398
|
+
function h(t$1) {
|
|
466
399
|
return Object.assign(((t$2) => Object.assign(t$2, { [Symbol.iterator]() {
|
|
467
400
|
let n$1 = 0;
|
|
468
401
|
const r$1 = [{
|
|
@@ -477,11 +410,11 @@ function l(t$1) {
|
|
|
477
410
|
return null != (t$3 = r$1[n$1++]) ? t$3 : r$1.at(-1);
|
|
478
411
|
} };
|
|
479
412
|
} }))(t$1), {
|
|
480
|
-
optional: () => l(
|
|
481
|
-
select: (e$1) =>
|
|
413
|
+
optional: () => h(l(t$1)),
|
|
414
|
+
select: (e$1) => h(void 0 === e$1 ? y(t$1) : y(e$1, t$1))
|
|
482
415
|
});
|
|
483
416
|
}
|
|
484
|
-
function
|
|
417
|
+
function l(e$1) {
|
|
485
418
|
return u({ [t]: () => ({
|
|
486
419
|
match: (t$1) => {
|
|
487
420
|
let n$1 = {};
|
|
@@ -618,9 +551,9 @@ const S = u(p(function(t$1) {
|
|
|
618
551
|
var N = {
|
|
619
552
|
__proto__: null,
|
|
620
553
|
matcher: t,
|
|
621
|
-
optional:
|
|
554
|
+
optional: l,
|
|
622
555
|
array: function(...e$1) {
|
|
623
|
-
return
|
|
556
|
+
return h({ [t]: () => ({
|
|
624
557
|
match: (t$1) => {
|
|
625
558
|
if (!Array.isArray(t$1)) return { matched: !1 };
|
|
626
559
|
if (0 === e$1.length) return { matched: !0 };
|
|
@@ -776,12 +709,15 @@ var I = class I {
|
|
|
776
709
|
returnType() {
|
|
777
710
|
return this;
|
|
778
711
|
}
|
|
712
|
+
narrow() {
|
|
713
|
+
return this;
|
|
714
|
+
}
|
|
779
715
|
};
|
|
780
716
|
function L(t$1) {
|
|
781
717
|
throw new W(t$1);
|
|
782
718
|
}
|
|
783
|
-
|
|
784
|
-
function $constructor(name, initializer$
|
|
719
|
+
Object.freeze({ status: "aborted" });
|
|
720
|
+
function $constructor(name, initializer$1, params) {
|
|
785
721
|
function init(inst, def) {
|
|
786
722
|
var _a;
|
|
787
723
|
Object.defineProperty(inst, "_zod", {
|
|
@@ -790,7 +726,7 @@ function $constructor(name, initializer$2, params) {
|
|
|
790
726
|
});
|
|
791
727
|
(_a = inst._zod).traits ?? (_a.traits = /* @__PURE__ */ new Set());
|
|
792
728
|
inst._zod.traits.add(name);
|
|
793
|
-
initializer$
|
|
729
|
+
initializer$1(inst, def);
|
|
794
730
|
for (const k$1 in _$1.prototype) if (!(k$1 in inst)) Object.defineProperty(inst, k$1, { value: _$1.prototype[k$1].bind(inst) });
|
|
795
731
|
inst._zod.constr = _$1;
|
|
796
732
|
inst._zod.def = def;
|
|
@@ -814,7 +750,6 @@ function $constructor(name, initializer$2, params) {
|
|
|
814
750
|
Object.defineProperty(_$1, "name", { value: name });
|
|
815
751
|
return _$1;
|
|
816
752
|
}
|
|
817
|
-
const $brand = Symbol("zod_brand");
|
|
818
753
|
var $ZodAsyncError = class extends Error {
|
|
819
754
|
constructor() {
|
|
820
755
|
super(`Encountered Promise during synchronous parse. Use .parseAsync() instead.`);
|
|
@@ -825,42 +760,36 @@ function config(newConfig) {
|
|
|
825
760
|
if (newConfig) Object.assign(globalConfig, newConfig);
|
|
826
761
|
return globalConfig;
|
|
827
762
|
}
|
|
828
|
-
function getEnumValues(entries) {
|
|
829
|
-
const numericValues = Object.values(entries).filter((v$1) => typeof v$1 === "number");
|
|
830
|
-
const values = Object.entries(entries).filter(([k$1, _$1]) => numericValues.indexOf(+k$1) === -1).map(([_$1, v$1]) => v$1);
|
|
831
|
-
return values;
|
|
832
|
-
}
|
|
833
763
|
function jsonStringifyReplacer(_$1, value) {
|
|
834
764
|
if (typeof value === "bigint") return value.toString();
|
|
835
765
|
return value;
|
|
836
766
|
}
|
|
837
767
|
function cached(getter) {
|
|
838
|
-
const set = false;
|
|
839
768
|
return { get value() {
|
|
840
769
|
{
|
|
841
770
|
const value = getter();
|
|
842
771
|
Object.defineProperty(this, "value", { value });
|
|
843
772
|
return value;
|
|
844
773
|
}
|
|
774
|
+
throw new Error("cached value already set");
|
|
845
775
|
} };
|
|
846
776
|
}
|
|
847
|
-
function nullish(input) {
|
|
848
|
-
return input === null || input === void 0;
|
|
849
|
-
}
|
|
850
777
|
function cleanRegex(source) {
|
|
851
778
|
const start = source.startsWith("^") ? 1 : 0;
|
|
852
779
|
const end = source.endsWith("$") ? source.length - 1 : source.length;
|
|
853
780
|
return source.slice(start, end);
|
|
854
781
|
}
|
|
782
|
+
const EVALUATING = Symbol("evaluating");
|
|
855
783
|
function defineLazy(object$1, key, getter) {
|
|
856
|
-
|
|
784
|
+
let value = void 0;
|
|
857
785
|
Object.defineProperty(object$1, key, {
|
|
858
786
|
get() {
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
787
|
+
if (value === EVALUATING) return;
|
|
788
|
+
if (value === void 0) {
|
|
789
|
+
value = EVALUATING;
|
|
790
|
+
value = getter();
|
|
863
791
|
}
|
|
792
|
+
return value;
|
|
864
793
|
},
|
|
865
794
|
set(v$1) {
|
|
866
795
|
Object.defineProperty(object$1, key, { value: v$1 });
|
|
@@ -876,48 +805,19 @@ function assignProp(target, prop, value) {
|
|
|
876
805
|
configurable: true
|
|
877
806
|
});
|
|
878
807
|
}
|
|
879
|
-
function mergeDefs(...defs) {
|
|
880
|
-
const mergedDescriptors = {};
|
|
881
|
-
for (const def of defs) {
|
|
882
|
-
const descriptors = Object.getOwnPropertyDescriptors(def);
|
|
883
|
-
Object.assign(mergedDescriptors, descriptors);
|
|
884
|
-
}
|
|
885
|
-
return Object.defineProperties({}, mergedDescriptors);
|
|
886
|
-
}
|
|
887
|
-
function esc(str) {
|
|
888
|
-
return JSON.stringify(str);
|
|
889
|
-
}
|
|
890
808
|
const captureStackTrace = "captureStackTrace" in Error ? Error.captureStackTrace : (..._args) => {};
|
|
891
809
|
function isObject(data) {
|
|
892
810
|
return typeof data === "object" && data !== null && !Array.isArray(data);
|
|
893
811
|
}
|
|
894
|
-
|
|
812
|
+
cached(() => {
|
|
895
813
|
if (typeof navigator !== "undefined" && navigator?.userAgent?.includes("Cloudflare")) return false;
|
|
896
814
|
try {
|
|
897
|
-
|
|
898
|
-
new F("");
|
|
815
|
+
new Function("");
|
|
899
816
|
return true;
|
|
900
817
|
} catch (_$1) {
|
|
901
818
|
return false;
|
|
902
819
|
}
|
|
903
820
|
});
|
|
904
|
-
function isPlainObject(o$1) {
|
|
905
|
-
if (isObject(o$1) === false) return false;
|
|
906
|
-
const ctor = o$1.constructor;
|
|
907
|
-
if (ctor === void 0) return true;
|
|
908
|
-
const prot = ctor.prototype;
|
|
909
|
-
if (isObject(prot) === false) return false;
|
|
910
|
-
if (Object.prototype.hasOwnProperty.call(prot, "isPrototypeOf") === false) return false;
|
|
911
|
-
return true;
|
|
912
|
-
}
|
|
913
|
-
const propertyKeyTypes = new Set([
|
|
914
|
-
"string",
|
|
915
|
-
"number",
|
|
916
|
-
"symbol"
|
|
917
|
-
]);
|
|
918
|
-
function escapeRegex(str) {
|
|
919
|
-
return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
920
|
-
}
|
|
921
821
|
function clone(inst, def, params) {
|
|
922
822
|
const cl = new inst._zod.constr(def ?? inst._zod.def);
|
|
923
823
|
if (!def || params?.parent) cl._zod.parent = inst;
|
|
@@ -943,128 +843,9 @@ function optionalKeys(shape) {
|
|
|
943
843
|
return shape[k$1]._zod.optin === "optional" && shape[k$1]._zod.optout === "optional";
|
|
944
844
|
});
|
|
945
845
|
}
|
|
946
|
-
|
|
947
|
-
safeint: [Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER],
|
|
948
|
-
int32: [-2147483648, 2147483647],
|
|
949
|
-
uint32: [0, 4294967295],
|
|
950
|
-
float32: [-34028234663852886e22, 34028234663852886e22],
|
|
951
|
-
float64: [-Number.MAX_VALUE, Number.MAX_VALUE]
|
|
952
|
-
};
|
|
953
|
-
function pick(schema, mask) {
|
|
954
|
-
const currDef = schema._zod.def;
|
|
955
|
-
const def = mergeDefs(schema._zod.def, {
|
|
956
|
-
get shape() {
|
|
957
|
-
const newShape = {};
|
|
958
|
-
for (const key in mask) {
|
|
959
|
-
if (!(key in currDef.shape)) throw new Error(`Unrecognized key: "${key}"`);
|
|
960
|
-
if (!mask[key]) continue;
|
|
961
|
-
newShape[key] = currDef.shape[key];
|
|
962
|
-
}
|
|
963
|
-
assignProp(this, "shape", newShape);
|
|
964
|
-
return newShape;
|
|
965
|
-
},
|
|
966
|
-
checks: []
|
|
967
|
-
});
|
|
968
|
-
return clone(schema, def);
|
|
969
|
-
}
|
|
970
|
-
function omit(schema, mask) {
|
|
971
|
-
const currDef = schema._zod.def;
|
|
972
|
-
const def = mergeDefs(schema._zod.def, {
|
|
973
|
-
get shape() {
|
|
974
|
-
const newShape = { ...schema._zod.def.shape };
|
|
975
|
-
for (const key in mask) {
|
|
976
|
-
if (!(key in currDef.shape)) throw new Error(`Unrecognized key: "${key}"`);
|
|
977
|
-
if (!mask[key]) continue;
|
|
978
|
-
delete newShape[key];
|
|
979
|
-
}
|
|
980
|
-
assignProp(this, "shape", newShape);
|
|
981
|
-
return newShape;
|
|
982
|
-
},
|
|
983
|
-
checks: []
|
|
984
|
-
});
|
|
985
|
-
return clone(schema, def);
|
|
986
|
-
}
|
|
987
|
-
function extend(schema, shape) {
|
|
988
|
-
if (!isPlainObject(shape)) throw new Error("Invalid input to extend: expected a plain object");
|
|
989
|
-
const def = mergeDefs(schema._zod.def, {
|
|
990
|
-
get shape() {
|
|
991
|
-
const _shape = {
|
|
992
|
-
...schema._zod.def.shape,
|
|
993
|
-
...shape
|
|
994
|
-
};
|
|
995
|
-
assignProp(this, "shape", _shape);
|
|
996
|
-
return _shape;
|
|
997
|
-
},
|
|
998
|
-
checks: []
|
|
999
|
-
});
|
|
1000
|
-
return clone(schema, def);
|
|
1001
|
-
}
|
|
1002
|
-
function merge(a$1, b$1) {
|
|
1003
|
-
const def = mergeDefs(a$1._zod.def, {
|
|
1004
|
-
get shape() {
|
|
1005
|
-
const _shape = {
|
|
1006
|
-
...a$1._zod.def.shape,
|
|
1007
|
-
...b$1._zod.def.shape
|
|
1008
|
-
};
|
|
1009
|
-
assignProp(this, "shape", _shape);
|
|
1010
|
-
return _shape;
|
|
1011
|
-
},
|
|
1012
|
-
get catchall() {
|
|
1013
|
-
return b$1._zod.def.catchall;
|
|
1014
|
-
},
|
|
1015
|
-
checks: []
|
|
1016
|
-
});
|
|
1017
|
-
return clone(a$1, def);
|
|
1018
|
-
}
|
|
1019
|
-
function partial(Class, schema, mask) {
|
|
1020
|
-
const def = mergeDefs(schema._zod.def, {
|
|
1021
|
-
get shape() {
|
|
1022
|
-
const oldShape = schema._zod.def.shape;
|
|
1023
|
-
const shape = { ...oldShape };
|
|
1024
|
-
if (mask) for (const key in mask) {
|
|
1025
|
-
if (!(key in oldShape)) throw new Error(`Unrecognized key: "${key}"`);
|
|
1026
|
-
if (!mask[key]) continue;
|
|
1027
|
-
shape[key] = Class ? new Class({
|
|
1028
|
-
type: "optional",
|
|
1029
|
-
innerType: oldShape[key]
|
|
1030
|
-
}) : oldShape[key];
|
|
1031
|
-
}
|
|
1032
|
-
else for (const key in oldShape) shape[key] = Class ? new Class({
|
|
1033
|
-
type: "optional",
|
|
1034
|
-
innerType: oldShape[key]
|
|
1035
|
-
}) : oldShape[key];
|
|
1036
|
-
assignProp(this, "shape", shape);
|
|
1037
|
-
return shape;
|
|
1038
|
-
},
|
|
1039
|
-
checks: []
|
|
1040
|
-
});
|
|
1041
|
-
return clone(schema, def);
|
|
1042
|
-
}
|
|
1043
|
-
function required(Class, schema, mask) {
|
|
1044
|
-
const def = mergeDefs(schema._zod.def, {
|
|
1045
|
-
get shape() {
|
|
1046
|
-
const oldShape = schema._zod.def.shape;
|
|
1047
|
-
const shape = { ...oldShape };
|
|
1048
|
-
if (mask) for (const key in mask) {
|
|
1049
|
-
if (!(key in shape)) throw new Error(`Unrecognized key: "${key}"`);
|
|
1050
|
-
if (!mask[key]) continue;
|
|
1051
|
-
shape[key] = new Class({
|
|
1052
|
-
type: "nonoptional",
|
|
1053
|
-
innerType: oldShape[key]
|
|
1054
|
-
});
|
|
1055
|
-
}
|
|
1056
|
-
else for (const key in oldShape) shape[key] = new Class({
|
|
1057
|
-
type: "nonoptional",
|
|
1058
|
-
innerType: oldShape[key]
|
|
1059
|
-
});
|
|
1060
|
-
assignProp(this, "shape", shape);
|
|
1061
|
-
return shape;
|
|
1062
|
-
},
|
|
1063
|
-
checks: []
|
|
1064
|
-
});
|
|
1065
|
-
return clone(schema, def);
|
|
1066
|
-
}
|
|
846
|
+
Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER, -Number.MAX_VALUE, Number.MAX_VALUE;
|
|
1067
847
|
function aborted(x$1, startIndex = 0) {
|
|
848
|
+
if (x$1.aborted === true) return true;
|
|
1068
849
|
for (let i$1 = startIndex; i$1 < x$1.issues.length; i$1++) if (x$1.issues[i$1]?.continue !== true) return true;
|
|
1069
850
|
return false;
|
|
1070
851
|
}
|
|
@@ -1084,31 +865,13 @@ function finalizeIssue(iss, ctx, config$1) {
|
|
|
1084
865
|
...iss,
|
|
1085
866
|
path: iss.path ?? []
|
|
1086
867
|
};
|
|
1087
|
-
if (!iss.message)
|
|
1088
|
-
const message = unwrapMessage(iss.inst?._zod.def?.error?.(iss)) ?? unwrapMessage(ctx?.error?.(iss)) ?? unwrapMessage(config$1.customError?.(iss)) ?? unwrapMessage(config$1.localeError?.(iss)) ?? "Invalid input";
|
|
1089
|
-
full.message = message;
|
|
1090
|
-
}
|
|
868
|
+
if (!iss.message) full.message = unwrapMessage(iss.inst?._zod.def?.error?.(iss)) ?? unwrapMessage(ctx?.error?.(iss)) ?? unwrapMessage(config$1.customError?.(iss)) ?? unwrapMessage(config$1.localeError?.(iss)) ?? "Invalid input";
|
|
1091
869
|
delete full.inst;
|
|
1092
870
|
delete full.continue;
|
|
1093
871
|
if (!ctx?.reportInput) delete full.input;
|
|
1094
872
|
return full;
|
|
1095
873
|
}
|
|
1096
|
-
|
|
1097
|
-
if (Array.isArray(input)) return "array";
|
|
1098
|
-
if (typeof input === "string") return "string";
|
|
1099
|
-
return "unknown";
|
|
1100
|
-
}
|
|
1101
|
-
function issue(...args) {
|
|
1102
|
-
const [iss, input, inst] = args;
|
|
1103
|
-
if (typeof iss === "string") return {
|
|
1104
|
-
message: iss,
|
|
1105
|
-
code: "custom",
|
|
1106
|
-
input,
|
|
1107
|
-
inst
|
|
1108
|
-
};
|
|
1109
|
-
return { ...iss };
|
|
1110
|
-
}
|
|
1111
|
-
const initializer$1 = (inst, def) => {
|
|
874
|
+
const initializer = (inst, def) => {
|
|
1112
875
|
inst.name = "$ZodError";
|
|
1113
876
|
Object.defineProperty(inst, "_zod", {
|
|
1114
877
|
value: inst._zod,
|
|
@@ -1124,49 +887,8 @@ const initializer$1 = (inst, def) => {
|
|
|
1124
887
|
enumerable: false
|
|
1125
888
|
});
|
|
1126
889
|
};
|
|
1127
|
-
const $ZodError = $constructor("$ZodError", initializer
|
|
1128
|
-
const $ZodRealError = $constructor("$ZodError", initializer
|
|
1129
|
-
function flattenError(error, mapper = (issue$1) => issue$1.message) {
|
|
1130
|
-
const fieldErrors = {};
|
|
1131
|
-
const formErrors = [];
|
|
1132
|
-
for (const sub of error.issues) if (sub.path.length > 0) {
|
|
1133
|
-
fieldErrors[sub.path[0]] = fieldErrors[sub.path[0]] || [];
|
|
1134
|
-
fieldErrors[sub.path[0]].push(mapper(sub));
|
|
1135
|
-
} else formErrors.push(mapper(sub));
|
|
1136
|
-
return {
|
|
1137
|
-
formErrors,
|
|
1138
|
-
fieldErrors
|
|
1139
|
-
};
|
|
1140
|
-
}
|
|
1141
|
-
function formatError(error, _mapper) {
|
|
1142
|
-
const mapper = _mapper || function(issue$1) {
|
|
1143
|
-
return issue$1.message;
|
|
1144
|
-
};
|
|
1145
|
-
const fieldErrors = { _errors: [] };
|
|
1146
|
-
const processError = (error$1) => {
|
|
1147
|
-
for (const issue$1 of error$1.issues) if (issue$1.code === "invalid_union" && issue$1.errors.length) issue$1.errors.map((issues) => processError({ issues }));
|
|
1148
|
-
else if (issue$1.code === "invalid_key") processError({ issues: issue$1.issues });
|
|
1149
|
-
else if (issue$1.code === "invalid_element") processError({ issues: issue$1.issues });
|
|
1150
|
-
else if (issue$1.path.length === 0) fieldErrors._errors.push(mapper(issue$1));
|
|
1151
|
-
else {
|
|
1152
|
-
let curr = fieldErrors;
|
|
1153
|
-
let i$1 = 0;
|
|
1154
|
-
while (i$1 < issue$1.path.length) {
|
|
1155
|
-
const el = issue$1.path[i$1];
|
|
1156
|
-
const terminal = i$1 === issue$1.path.length - 1;
|
|
1157
|
-
if (!terminal) curr[el] = curr[el] || { _errors: [] };
|
|
1158
|
-
else {
|
|
1159
|
-
curr[el] = curr[el] || { _errors: [] };
|
|
1160
|
-
curr[el]._errors.push(mapper(issue$1));
|
|
1161
|
-
}
|
|
1162
|
-
curr = curr[el];
|
|
1163
|
-
i$1++;
|
|
1164
|
-
}
|
|
1165
|
-
}
|
|
1166
|
-
};
|
|
1167
|
-
processError(error);
|
|
1168
|
-
return fieldErrors;
|
|
1169
|
-
}
|
|
890
|
+
const $ZodError = $constructor("$ZodError", initializer);
|
|
891
|
+
const $ZodRealError = $constructor("$ZodError", initializer, { Parent: Error });
|
|
1170
892
|
const _parse = (_Err) => (schema, value, _ctx, _params) => {
|
|
1171
893
|
const ctx = _ctx ? Object.assign(_ctx, { async: false }) : { async: false };
|
|
1172
894
|
const result = schema._zod.run({
|
|
@@ -1181,7 +903,7 @@ const _parse = (_Err) => (schema, value, _ctx, _params) => {
|
|
|
1181
903
|
}
|
|
1182
904
|
return result.value;
|
|
1183
905
|
};
|
|
1184
|
-
const parse
|
|
906
|
+
const parse = /* @__PURE__ */ _parse($ZodRealError);
|
|
1185
907
|
const _parseAsync = (_Err) => async (schema, value, _ctx, params) => {
|
|
1186
908
|
const ctx = _ctx ? Object.assign(_ctx, { async: true }) : { async: true };
|
|
1187
909
|
let result = schema._zod.run({
|
|
@@ -1196,7 +918,7 @@ const _parseAsync = (_Err) => async (schema, value, _ctx, params) => {
|
|
|
1196
918
|
}
|
|
1197
919
|
return result.value;
|
|
1198
920
|
};
|
|
1199
|
-
const parseAsync
|
|
921
|
+
const parseAsync = /* @__PURE__ */ _parseAsync($ZodRealError);
|
|
1200
922
|
const _safeParse = (_Err) => (schema, value, _ctx) => {
|
|
1201
923
|
const ctx = _ctx ? {
|
|
1202
924
|
..._ctx,
|
|
@@ -1215,7 +937,7 @@ const _safeParse = (_Err) => (schema, value, _ctx) => {
|
|
|
1215
937
|
data: result.value
|
|
1216
938
|
};
|
|
1217
939
|
};
|
|
1218
|
-
const safeParse
|
|
940
|
+
const safeParse = /* @__PURE__ */ _safeParse($ZodRealError);
|
|
1219
941
|
const _safeParseAsync = (_Err) => async (schema, value, _ctx) => {
|
|
1220
942
|
const ctx = _ctx ? Object.assign(_ctx, { async: true }) : { async: true };
|
|
1221
943
|
let result = schema._zod.run({
|
|
@@ -1231,310 +953,15 @@ const _safeParseAsync = (_Err) => async (schema, value, _ctx) => {
|
|
|
1231
953
|
data: result.value
|
|
1232
954
|
};
|
|
1233
955
|
};
|
|
1234
|
-
const safeParseAsync
|
|
1235
|
-
const cuid = /^[cC][^\s-]{8,}$/;
|
|
1236
|
-
const cuid2 = /^[0-9a-z]+$/;
|
|
1237
|
-
const ulid = /^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/;
|
|
1238
|
-
const xid = /^[0-9a-vA-V]{20}$/;
|
|
1239
|
-
const ksuid = /^[A-Za-z0-9]{27}$/;
|
|
1240
|
-
const nanoid = /^[a-zA-Z0-9_-]{21}$/;
|
|
1241
|
-
const duration$1 = /^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/;
|
|
1242
|
-
const guid = /^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/;
|
|
1243
|
-
const uuid = (version$1) => {
|
|
1244
|
-
if (!version$1) return /^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000)$/;
|
|
1245
|
-
return /* @__PURE__ */ new RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${version$1}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`);
|
|
1246
|
-
};
|
|
1247
|
-
const email = /^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/;
|
|
1248
|
-
const _emoji$1 = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
|
|
1249
|
-
function emoji() {
|
|
1250
|
-
return new RegExp(_emoji$1, "u");
|
|
1251
|
-
}
|
|
1252
|
-
const ipv4 = /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/;
|
|
1253
|
-
const ipv6 = /^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})$/;
|
|
1254
|
-
const cidrv4 = /^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/([0-9]|[1-2][0-9]|3[0-2])$/;
|
|
1255
|
-
const cidrv6 = /^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/;
|
|
1256
|
-
const base64 = /^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/;
|
|
1257
|
-
const base64url = /^[A-Za-z0-9_-]*$/;
|
|
1258
|
-
const hostname = /^([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+$/;
|
|
1259
|
-
const e164 = /^\+(?:[0-9]){6,14}[0-9]$/;
|
|
1260
|
-
const dateSource = `(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))`;
|
|
1261
|
-
const date$1 = /* @__PURE__ */ new RegExp(`^${dateSource}$`);
|
|
1262
|
-
function timeSource(args) {
|
|
1263
|
-
const hhmm = `(?:[01]\\d|2[0-3]):[0-5]\\d`;
|
|
1264
|
-
const regex = typeof args.precision === "number" ? args.precision === -1 ? `${hhmm}` : args.precision === 0 ? `${hhmm}:[0-5]\\d` : `${hhmm}:[0-5]\\d\\.\\d{${args.precision}}` : `${hhmm}(?::[0-5]\\d(?:\\.\\d+)?)?`;
|
|
1265
|
-
return regex;
|
|
1266
|
-
}
|
|
1267
|
-
function time$1(args) {
|
|
1268
|
-
return /* @__PURE__ */ new RegExp(`^${timeSource(args)}$`);
|
|
1269
|
-
}
|
|
1270
|
-
function datetime$1(args) {
|
|
1271
|
-
const time$2 = timeSource({ precision: args.precision });
|
|
1272
|
-
const opts = ["Z"];
|
|
1273
|
-
if (args.local) opts.push("");
|
|
1274
|
-
if (args.offset) opts.push(`([+-]\\d{2}:\\d{2})`);
|
|
1275
|
-
const timeRegex = `${time$2}(?:${opts.join("|")})`;
|
|
1276
|
-
return /* @__PURE__ */ new RegExp(`^${dateSource}T(?:${timeRegex})$`);
|
|
1277
|
-
}
|
|
956
|
+
const safeParseAsync = /* @__PURE__ */ _safeParseAsync($ZodRealError);
|
|
1278
957
|
const string$1 = (params) => {
|
|
1279
958
|
const regex = params ? `[\\s\\S]{${params?.minimum ?? 0},${params?.maximum ?? ""}}` : `[\\s\\S]*`;
|
|
1280
959
|
return /* @__PURE__ */ new RegExp(`^${regex}$`);
|
|
1281
960
|
};
|
|
1282
|
-
const lowercase = /^[^A-Z]*$/;
|
|
1283
|
-
const uppercase = /^[^a-z]*$/;
|
|
1284
|
-
const $ZodCheck = /* @__PURE__ */ $constructor("$ZodCheck", (inst, def) => {
|
|
1285
|
-
var _a;
|
|
1286
|
-
inst._zod ?? (inst._zod = {});
|
|
1287
|
-
inst._zod.def = def;
|
|
1288
|
-
(_a = inst._zod).onattach ?? (_a.onattach = []);
|
|
1289
|
-
});
|
|
1290
|
-
const $ZodCheckMaxLength = /* @__PURE__ */ $constructor("$ZodCheckMaxLength", (inst, def) => {
|
|
1291
|
-
var _a;
|
|
1292
|
-
$ZodCheck.init(inst, def);
|
|
1293
|
-
(_a = inst._zod.def).when ?? (_a.when = (payload) => {
|
|
1294
|
-
const val = payload.value;
|
|
1295
|
-
return !nullish(val) && val.length !== void 0;
|
|
1296
|
-
});
|
|
1297
|
-
inst._zod.onattach.push((inst$1) => {
|
|
1298
|
-
const curr = inst$1._zod.bag.maximum ?? Number.POSITIVE_INFINITY;
|
|
1299
|
-
if (def.maximum < curr) inst$1._zod.bag.maximum = def.maximum;
|
|
1300
|
-
});
|
|
1301
|
-
inst._zod.check = (payload) => {
|
|
1302
|
-
const input = payload.value;
|
|
1303
|
-
const length = input.length;
|
|
1304
|
-
if (length <= def.maximum) return;
|
|
1305
|
-
const origin = getLengthableOrigin(input);
|
|
1306
|
-
payload.issues.push({
|
|
1307
|
-
origin,
|
|
1308
|
-
code: "too_big",
|
|
1309
|
-
maximum: def.maximum,
|
|
1310
|
-
inclusive: true,
|
|
1311
|
-
input,
|
|
1312
|
-
inst,
|
|
1313
|
-
continue: !def.abort
|
|
1314
|
-
});
|
|
1315
|
-
};
|
|
1316
|
-
});
|
|
1317
|
-
const $ZodCheckMinLength = /* @__PURE__ */ $constructor("$ZodCheckMinLength", (inst, def) => {
|
|
1318
|
-
var _a;
|
|
1319
|
-
$ZodCheck.init(inst, def);
|
|
1320
|
-
(_a = inst._zod.def).when ?? (_a.when = (payload) => {
|
|
1321
|
-
const val = payload.value;
|
|
1322
|
-
return !nullish(val) && val.length !== void 0;
|
|
1323
|
-
});
|
|
1324
|
-
inst._zod.onattach.push((inst$1) => {
|
|
1325
|
-
const curr = inst$1._zod.bag.minimum ?? Number.NEGATIVE_INFINITY;
|
|
1326
|
-
if (def.minimum > curr) inst$1._zod.bag.minimum = def.minimum;
|
|
1327
|
-
});
|
|
1328
|
-
inst._zod.check = (payload) => {
|
|
1329
|
-
const input = payload.value;
|
|
1330
|
-
const length = input.length;
|
|
1331
|
-
if (length >= def.minimum) return;
|
|
1332
|
-
const origin = getLengthableOrigin(input);
|
|
1333
|
-
payload.issues.push({
|
|
1334
|
-
origin,
|
|
1335
|
-
code: "too_small",
|
|
1336
|
-
minimum: def.minimum,
|
|
1337
|
-
inclusive: true,
|
|
1338
|
-
input,
|
|
1339
|
-
inst,
|
|
1340
|
-
continue: !def.abort
|
|
1341
|
-
});
|
|
1342
|
-
};
|
|
1343
|
-
});
|
|
1344
|
-
const $ZodCheckLengthEquals = /* @__PURE__ */ $constructor("$ZodCheckLengthEquals", (inst, def) => {
|
|
1345
|
-
var _a;
|
|
1346
|
-
$ZodCheck.init(inst, def);
|
|
1347
|
-
(_a = inst._zod.def).when ?? (_a.when = (payload) => {
|
|
1348
|
-
const val = payload.value;
|
|
1349
|
-
return !nullish(val) && val.length !== void 0;
|
|
1350
|
-
});
|
|
1351
|
-
inst._zod.onattach.push((inst$1) => {
|
|
1352
|
-
const bag = inst$1._zod.bag;
|
|
1353
|
-
bag.minimum = def.length;
|
|
1354
|
-
bag.maximum = def.length;
|
|
1355
|
-
bag.length = def.length;
|
|
1356
|
-
});
|
|
1357
|
-
inst._zod.check = (payload) => {
|
|
1358
|
-
const input = payload.value;
|
|
1359
|
-
const length = input.length;
|
|
1360
|
-
if (length === def.length) return;
|
|
1361
|
-
const origin = getLengthableOrigin(input);
|
|
1362
|
-
const tooBig = length > def.length;
|
|
1363
|
-
payload.issues.push({
|
|
1364
|
-
origin,
|
|
1365
|
-
...tooBig ? {
|
|
1366
|
-
code: "too_big",
|
|
1367
|
-
maximum: def.length
|
|
1368
|
-
} : {
|
|
1369
|
-
code: "too_small",
|
|
1370
|
-
minimum: def.length
|
|
1371
|
-
},
|
|
1372
|
-
inclusive: true,
|
|
1373
|
-
exact: true,
|
|
1374
|
-
input: payload.value,
|
|
1375
|
-
inst,
|
|
1376
|
-
continue: !def.abort
|
|
1377
|
-
});
|
|
1378
|
-
};
|
|
1379
|
-
});
|
|
1380
|
-
const $ZodCheckStringFormat = /* @__PURE__ */ $constructor("$ZodCheckStringFormat", (inst, def) => {
|
|
1381
|
-
var _a, _b;
|
|
1382
|
-
$ZodCheck.init(inst, def);
|
|
1383
|
-
inst._zod.onattach.push((inst$1) => {
|
|
1384
|
-
const bag = inst$1._zod.bag;
|
|
1385
|
-
bag.format = def.format;
|
|
1386
|
-
if (def.pattern) {
|
|
1387
|
-
bag.patterns ?? (bag.patterns = /* @__PURE__ */ new Set());
|
|
1388
|
-
bag.patterns.add(def.pattern);
|
|
1389
|
-
}
|
|
1390
|
-
});
|
|
1391
|
-
if (def.pattern) (_a = inst._zod).check ?? (_a.check = (payload) => {
|
|
1392
|
-
def.pattern.lastIndex = 0;
|
|
1393
|
-
if (def.pattern.test(payload.value)) return;
|
|
1394
|
-
payload.issues.push({
|
|
1395
|
-
origin: "string",
|
|
1396
|
-
code: "invalid_format",
|
|
1397
|
-
format: def.format,
|
|
1398
|
-
input: payload.value,
|
|
1399
|
-
...def.pattern ? { pattern: def.pattern.toString() } : {},
|
|
1400
|
-
inst,
|
|
1401
|
-
continue: !def.abort
|
|
1402
|
-
});
|
|
1403
|
-
});
|
|
1404
|
-
else (_b = inst._zod).check ?? (_b.check = () => {});
|
|
1405
|
-
});
|
|
1406
|
-
const $ZodCheckRegex = /* @__PURE__ */ $constructor("$ZodCheckRegex", (inst, def) => {
|
|
1407
|
-
$ZodCheckStringFormat.init(inst, def);
|
|
1408
|
-
inst._zod.check = (payload) => {
|
|
1409
|
-
def.pattern.lastIndex = 0;
|
|
1410
|
-
if (def.pattern.test(payload.value)) return;
|
|
1411
|
-
payload.issues.push({
|
|
1412
|
-
origin: "string",
|
|
1413
|
-
code: "invalid_format",
|
|
1414
|
-
format: "regex",
|
|
1415
|
-
input: payload.value,
|
|
1416
|
-
pattern: def.pattern.toString(),
|
|
1417
|
-
inst,
|
|
1418
|
-
continue: !def.abort
|
|
1419
|
-
});
|
|
1420
|
-
};
|
|
1421
|
-
});
|
|
1422
|
-
const $ZodCheckLowerCase = /* @__PURE__ */ $constructor("$ZodCheckLowerCase", (inst, def) => {
|
|
1423
|
-
def.pattern ?? (def.pattern = lowercase);
|
|
1424
|
-
$ZodCheckStringFormat.init(inst, def);
|
|
1425
|
-
});
|
|
1426
|
-
const $ZodCheckUpperCase = /* @__PURE__ */ $constructor("$ZodCheckUpperCase", (inst, def) => {
|
|
1427
|
-
def.pattern ?? (def.pattern = uppercase);
|
|
1428
|
-
$ZodCheckStringFormat.init(inst, def);
|
|
1429
|
-
});
|
|
1430
|
-
const $ZodCheckIncludes = /* @__PURE__ */ $constructor("$ZodCheckIncludes", (inst, def) => {
|
|
1431
|
-
$ZodCheck.init(inst, def);
|
|
1432
|
-
const escapedRegex = escapeRegex(def.includes);
|
|
1433
|
-
const pattern = new RegExp(typeof def.position === "number" ? `^.{${def.position}}${escapedRegex}` : escapedRegex);
|
|
1434
|
-
def.pattern = pattern;
|
|
1435
|
-
inst._zod.onattach.push((inst$1) => {
|
|
1436
|
-
const bag = inst$1._zod.bag;
|
|
1437
|
-
bag.patterns ?? (bag.patterns = /* @__PURE__ */ new Set());
|
|
1438
|
-
bag.patterns.add(pattern);
|
|
1439
|
-
});
|
|
1440
|
-
inst._zod.check = (payload) => {
|
|
1441
|
-
if (payload.value.includes(def.includes, def.position)) return;
|
|
1442
|
-
payload.issues.push({
|
|
1443
|
-
origin: "string",
|
|
1444
|
-
code: "invalid_format",
|
|
1445
|
-
format: "includes",
|
|
1446
|
-
includes: def.includes,
|
|
1447
|
-
input: payload.value,
|
|
1448
|
-
inst,
|
|
1449
|
-
continue: !def.abort
|
|
1450
|
-
});
|
|
1451
|
-
};
|
|
1452
|
-
});
|
|
1453
|
-
const $ZodCheckStartsWith = /* @__PURE__ */ $constructor("$ZodCheckStartsWith", (inst, def) => {
|
|
1454
|
-
$ZodCheck.init(inst, def);
|
|
1455
|
-
const pattern = /* @__PURE__ */ new RegExp(`^${escapeRegex(def.prefix)}.*`);
|
|
1456
|
-
def.pattern ?? (def.pattern = pattern);
|
|
1457
|
-
inst._zod.onattach.push((inst$1) => {
|
|
1458
|
-
const bag = inst$1._zod.bag;
|
|
1459
|
-
bag.patterns ?? (bag.patterns = /* @__PURE__ */ new Set());
|
|
1460
|
-
bag.patterns.add(pattern);
|
|
1461
|
-
});
|
|
1462
|
-
inst._zod.check = (payload) => {
|
|
1463
|
-
if (payload.value.startsWith(def.prefix)) return;
|
|
1464
|
-
payload.issues.push({
|
|
1465
|
-
origin: "string",
|
|
1466
|
-
code: "invalid_format",
|
|
1467
|
-
format: "starts_with",
|
|
1468
|
-
prefix: def.prefix,
|
|
1469
|
-
input: payload.value,
|
|
1470
|
-
inst,
|
|
1471
|
-
continue: !def.abort
|
|
1472
|
-
});
|
|
1473
|
-
};
|
|
1474
|
-
});
|
|
1475
|
-
const $ZodCheckEndsWith = /* @__PURE__ */ $constructor("$ZodCheckEndsWith", (inst, def) => {
|
|
1476
|
-
$ZodCheck.init(inst, def);
|
|
1477
|
-
const pattern = /* @__PURE__ */ new RegExp(`.*${escapeRegex(def.suffix)}$`);
|
|
1478
|
-
def.pattern ?? (def.pattern = pattern);
|
|
1479
|
-
inst._zod.onattach.push((inst$1) => {
|
|
1480
|
-
const bag = inst$1._zod.bag;
|
|
1481
|
-
bag.patterns ?? (bag.patterns = /* @__PURE__ */ new Set());
|
|
1482
|
-
bag.patterns.add(pattern);
|
|
1483
|
-
});
|
|
1484
|
-
inst._zod.check = (payload) => {
|
|
1485
|
-
if (payload.value.endsWith(def.suffix)) return;
|
|
1486
|
-
payload.issues.push({
|
|
1487
|
-
origin: "string",
|
|
1488
|
-
code: "invalid_format",
|
|
1489
|
-
format: "ends_with",
|
|
1490
|
-
suffix: def.suffix,
|
|
1491
|
-
input: payload.value,
|
|
1492
|
-
inst,
|
|
1493
|
-
continue: !def.abort
|
|
1494
|
-
});
|
|
1495
|
-
};
|
|
1496
|
-
});
|
|
1497
|
-
const $ZodCheckOverwrite = /* @__PURE__ */ $constructor("$ZodCheckOverwrite", (inst, def) => {
|
|
1498
|
-
$ZodCheck.init(inst, def);
|
|
1499
|
-
inst._zod.check = (payload) => {
|
|
1500
|
-
payload.value = def.tx(payload.value);
|
|
1501
|
-
};
|
|
1502
|
-
});
|
|
1503
|
-
var Doc = class {
|
|
1504
|
-
constructor(args = []) {
|
|
1505
|
-
this.content = [];
|
|
1506
|
-
this.indent = 0;
|
|
1507
|
-
if (this) this.args = args;
|
|
1508
|
-
}
|
|
1509
|
-
indented(fn) {
|
|
1510
|
-
this.indent += 1;
|
|
1511
|
-
fn(this);
|
|
1512
|
-
this.indent -= 1;
|
|
1513
|
-
}
|
|
1514
|
-
write(arg) {
|
|
1515
|
-
if (typeof arg === "function") {
|
|
1516
|
-
arg(this, { execution: "sync" });
|
|
1517
|
-
arg(this, { execution: "async" });
|
|
1518
|
-
return;
|
|
1519
|
-
}
|
|
1520
|
-
const content = arg;
|
|
1521
|
-
const lines = content.split("\n").filter((x$1) => x$1);
|
|
1522
|
-
const minIndent = Math.min(...lines.map((x$1) => x$1.length - x$1.trimStart().length));
|
|
1523
|
-
const dedented = lines.map((x$1) => x$1.slice(minIndent)).map((x$1) => " ".repeat(this.indent * 2) + x$1);
|
|
1524
|
-
for (const line of dedented) this.content.push(line);
|
|
1525
|
-
}
|
|
1526
|
-
compile() {
|
|
1527
|
-
const F = Function;
|
|
1528
|
-
const args = this?.args;
|
|
1529
|
-
const content = this?.content ?? [``];
|
|
1530
|
-
const lines = [...content.map((x$1) => ` ${x$1}`)];
|
|
1531
|
-
return new F(...args, lines.join("\n"));
|
|
1532
|
-
}
|
|
1533
|
-
};
|
|
1534
961
|
const version = {
|
|
1535
962
|
major: 4,
|
|
1536
|
-
minor:
|
|
1537
|
-
patch:
|
|
963
|
+
minor: 1,
|
|
964
|
+
patch: 5
|
|
1538
965
|
};
|
|
1539
966
|
const $ZodType = /* @__PURE__ */ $constructor("$ZodType", (inst, def) => {
|
|
1540
967
|
var _a;
|
|
@@ -1556,21 +983,18 @@ const $ZodType = /* @__PURE__ */ $constructor("$ZodType", (inst, def) => {
|
|
|
1556
983
|
let asyncResult;
|
|
1557
984
|
for (const ch of checks$1) {
|
|
1558
985
|
if (ch._zod.def.when) {
|
|
1559
|
-
|
|
1560
|
-
if (!shouldRun) continue;
|
|
986
|
+
if (!ch._zod.def.when(payload)) continue;
|
|
1561
987
|
} else if (isAborted) continue;
|
|
1562
988
|
const currLen = payload.issues.length;
|
|
1563
989
|
const _$1 = ch._zod.check(payload);
|
|
1564
990
|
if (_$1 instanceof Promise && ctx?.async === false) throw new $ZodAsyncError();
|
|
1565
991
|
if (asyncResult || _$1 instanceof Promise) asyncResult = (asyncResult ?? Promise.resolve()).then(async () => {
|
|
1566
992
|
await _$1;
|
|
1567
|
-
|
|
1568
|
-
if (nextLen === currLen) return;
|
|
993
|
+
if (payload.issues.length === currLen) return;
|
|
1569
994
|
if (!isAborted) isAborted = aborted(payload, currLen);
|
|
1570
995
|
});
|
|
1571
996
|
else {
|
|
1572
|
-
|
|
1573
|
-
if (nextLen === currLen) continue;
|
|
997
|
+
if (payload.issues.length === currLen) continue;
|
|
1574
998
|
if (!isAborted) isAborted = aborted(payload, currLen);
|
|
1575
999
|
}
|
|
1576
1000
|
}
|
|
@@ -1579,7 +1003,33 @@ const $ZodType = /* @__PURE__ */ $constructor("$ZodType", (inst, def) => {
|
|
|
1579
1003
|
});
|
|
1580
1004
|
return payload;
|
|
1581
1005
|
};
|
|
1006
|
+
const handleCanaryResult = (canary, payload, ctx) => {
|
|
1007
|
+
if (aborted(canary)) {
|
|
1008
|
+
canary.aborted = true;
|
|
1009
|
+
return canary;
|
|
1010
|
+
}
|
|
1011
|
+
const checkResult = runChecks(payload, checks, ctx);
|
|
1012
|
+
if (checkResult instanceof Promise) {
|
|
1013
|
+
if (ctx.async === false) throw new $ZodAsyncError();
|
|
1014
|
+
return checkResult.then((checkResult$1) => inst._zod.parse(checkResult$1, ctx));
|
|
1015
|
+
}
|
|
1016
|
+
return inst._zod.parse(checkResult, ctx);
|
|
1017
|
+
};
|
|
1582
1018
|
inst._zod.run = (payload, ctx) => {
|
|
1019
|
+
if (ctx.skipChecks) return inst._zod.parse(payload, ctx);
|
|
1020
|
+
if (ctx.direction === "backward") {
|
|
1021
|
+
const canary = inst._zod.parse({
|
|
1022
|
+
value: payload.value,
|
|
1023
|
+
issues: []
|
|
1024
|
+
}, {
|
|
1025
|
+
...ctx,
|
|
1026
|
+
skipChecks: true
|
|
1027
|
+
});
|
|
1028
|
+
if (canary instanceof Promise) return canary.then((canary$1) => {
|
|
1029
|
+
return handleCanaryResult(canary$1, payload, ctx);
|
|
1030
|
+
});
|
|
1031
|
+
return handleCanaryResult(canary, payload, ctx);
|
|
1032
|
+
}
|
|
1583
1033
|
const result = inst._zod.parse(payload, ctx);
|
|
1584
1034
|
if (result instanceof Promise) {
|
|
1585
1035
|
if (ctx.async === false) throw new $ZodAsyncError();
|
|
@@ -1591,10 +1041,10 @@ const $ZodType = /* @__PURE__ */ $constructor("$ZodType", (inst, def) => {
|
|
|
1591
1041
|
inst["~standard"] = {
|
|
1592
1042
|
validate: (value) => {
|
|
1593
1043
|
try {
|
|
1594
|
-
const r$1 = safeParse
|
|
1044
|
+
const r$1 = safeParse(inst, value);
|
|
1595
1045
|
return r$1.success ? { value: r$1.data } : { issues: r$1.error?.issues };
|
|
1596
1046
|
} catch (_$1) {
|
|
1597
|
-
return safeParseAsync
|
|
1047
|
+
return safeParseAsync(inst, value).then((r$1) => r$1.success ? { value: r$1.data } : { issues: r$1.error?.issues });
|
|
1598
1048
|
}
|
|
1599
1049
|
},
|
|
1600
1050
|
vendor: "zod",
|
|
@@ -1618,311 +1068,40 @@ const $ZodString = /* @__PURE__ */ $constructor("$ZodString", (inst, def) => {
|
|
|
1618
1068
|
return payload;
|
|
1619
1069
|
};
|
|
1620
1070
|
});
|
|
1621
|
-
const $
|
|
1622
|
-
$
|
|
1623
|
-
|
|
1624
|
-
});
|
|
1625
|
-
const $ZodGUID = /* @__PURE__ */ $constructor("$ZodGUID", (inst, def) => {
|
|
1626
|
-
def.pattern ?? (def.pattern = guid);
|
|
1627
|
-
$ZodStringFormat.init(inst, def);
|
|
1628
|
-
});
|
|
1629
|
-
const $ZodUUID = /* @__PURE__ */ $constructor("$ZodUUID", (inst, def) => {
|
|
1630
|
-
if (def.version) {
|
|
1631
|
-
const versionMap = {
|
|
1632
|
-
v1: 1,
|
|
1633
|
-
v2: 2,
|
|
1634
|
-
v3: 3,
|
|
1635
|
-
v4: 4,
|
|
1636
|
-
v5: 5,
|
|
1637
|
-
v6: 6,
|
|
1638
|
-
v7: 7,
|
|
1639
|
-
v8: 8
|
|
1640
|
-
};
|
|
1641
|
-
const v$1 = versionMap[def.version];
|
|
1642
|
-
if (v$1 === void 0) throw new Error(`Invalid UUID version: "${def.version}"`);
|
|
1643
|
-
def.pattern ?? (def.pattern = uuid(v$1));
|
|
1644
|
-
} else def.pattern ?? (def.pattern = uuid());
|
|
1645
|
-
$ZodStringFormat.init(inst, def);
|
|
1646
|
-
});
|
|
1647
|
-
const $ZodEmail = /* @__PURE__ */ $constructor("$ZodEmail", (inst, def) => {
|
|
1648
|
-
def.pattern ?? (def.pattern = email);
|
|
1649
|
-
$ZodStringFormat.init(inst, def);
|
|
1071
|
+
const $ZodAny = /* @__PURE__ */ $constructor("$ZodAny", (inst, def) => {
|
|
1072
|
+
$ZodType.init(inst, def);
|
|
1073
|
+
inst._zod.parse = (payload) => payload;
|
|
1650
1074
|
});
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
code: "invalid_format",
|
|
1661
|
-
format: "url",
|
|
1662
|
-
note: "Invalid hostname",
|
|
1663
|
-
pattern: hostname.source,
|
|
1664
|
-
input: payload.value,
|
|
1665
|
-
inst,
|
|
1666
|
-
continue: !def.abort
|
|
1667
|
-
});
|
|
1668
|
-
}
|
|
1669
|
-
if (def.protocol) {
|
|
1670
|
-
def.protocol.lastIndex = 0;
|
|
1671
|
-
if (!def.protocol.test(url.protocol.endsWith(":") ? url.protocol.slice(0, -1) : url.protocol)) payload.issues.push({
|
|
1672
|
-
code: "invalid_format",
|
|
1673
|
-
format: "url",
|
|
1674
|
-
note: "Invalid protocol",
|
|
1675
|
-
pattern: def.protocol.source,
|
|
1676
|
-
input: payload.value,
|
|
1677
|
-
inst,
|
|
1678
|
-
continue: !def.abort
|
|
1679
|
-
});
|
|
1680
|
-
}
|
|
1681
|
-
if (def.normalize) payload.value = url.href;
|
|
1682
|
-
else payload.value = trimmed;
|
|
1683
|
-
return;
|
|
1684
|
-
} catch (_$1) {
|
|
1075
|
+
function handleArrayResult(result, final, index) {
|
|
1076
|
+
if (result.issues.length) final.issues.push(...prefixIssues(index, result.issues));
|
|
1077
|
+
final.value[index] = result.value;
|
|
1078
|
+
}
|
|
1079
|
+
const $ZodArray = /* @__PURE__ */ $constructor("$ZodArray", (inst, def) => {
|
|
1080
|
+
$ZodType.init(inst, def);
|
|
1081
|
+
inst._zod.parse = (payload, ctx) => {
|
|
1082
|
+
const input = payload.value;
|
|
1083
|
+
if (!Array.isArray(input)) {
|
|
1685
1084
|
payload.issues.push({
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
input
|
|
1689
|
-
inst
|
|
1690
|
-
continue: !def.abort
|
|
1085
|
+
expected: "array",
|
|
1086
|
+
code: "invalid_type",
|
|
1087
|
+
input,
|
|
1088
|
+
inst
|
|
1691
1089
|
});
|
|
1090
|
+
return payload;
|
|
1091
|
+
}
|
|
1092
|
+
payload.value = Array(input.length);
|
|
1093
|
+
const proms = [];
|
|
1094
|
+
for (let i$1 = 0; i$1 < input.length; i$1++) {
|
|
1095
|
+
const item = input[i$1];
|
|
1096
|
+
const result = def.element._zod.run({
|
|
1097
|
+
value: item,
|
|
1098
|
+
issues: []
|
|
1099
|
+
}, ctx);
|
|
1100
|
+
if (result instanceof Promise) proms.push(result.then((result$1) => handleArrayResult(result$1, payload, i$1)));
|
|
1101
|
+
else handleArrayResult(result, payload, i$1);
|
|
1692
1102
|
}
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
const $ZodEmoji = /* @__PURE__ */ $constructor("$ZodEmoji", (inst, def) => {
|
|
1696
|
-
def.pattern ?? (def.pattern = emoji());
|
|
1697
|
-
$ZodStringFormat.init(inst, def);
|
|
1698
|
-
});
|
|
1699
|
-
const $ZodNanoID = /* @__PURE__ */ $constructor("$ZodNanoID", (inst, def) => {
|
|
1700
|
-
def.pattern ?? (def.pattern = nanoid);
|
|
1701
|
-
$ZodStringFormat.init(inst, def);
|
|
1702
|
-
});
|
|
1703
|
-
const $ZodCUID = /* @__PURE__ */ $constructor("$ZodCUID", (inst, def) => {
|
|
1704
|
-
def.pattern ?? (def.pattern = cuid);
|
|
1705
|
-
$ZodStringFormat.init(inst, def);
|
|
1706
|
-
});
|
|
1707
|
-
const $ZodCUID2 = /* @__PURE__ */ $constructor("$ZodCUID2", (inst, def) => {
|
|
1708
|
-
def.pattern ?? (def.pattern = cuid2);
|
|
1709
|
-
$ZodStringFormat.init(inst, def);
|
|
1710
|
-
});
|
|
1711
|
-
const $ZodULID = /* @__PURE__ */ $constructor("$ZodULID", (inst, def) => {
|
|
1712
|
-
def.pattern ?? (def.pattern = ulid);
|
|
1713
|
-
$ZodStringFormat.init(inst, def);
|
|
1714
|
-
});
|
|
1715
|
-
const $ZodXID = /* @__PURE__ */ $constructor("$ZodXID", (inst, def) => {
|
|
1716
|
-
def.pattern ?? (def.pattern = xid);
|
|
1717
|
-
$ZodStringFormat.init(inst, def);
|
|
1718
|
-
});
|
|
1719
|
-
const $ZodKSUID = /* @__PURE__ */ $constructor("$ZodKSUID", (inst, def) => {
|
|
1720
|
-
def.pattern ?? (def.pattern = ksuid);
|
|
1721
|
-
$ZodStringFormat.init(inst, def);
|
|
1722
|
-
});
|
|
1723
|
-
const $ZodISODateTime = /* @__PURE__ */ $constructor("$ZodISODateTime", (inst, def) => {
|
|
1724
|
-
def.pattern ?? (def.pattern = datetime$1(def));
|
|
1725
|
-
$ZodStringFormat.init(inst, def);
|
|
1726
|
-
});
|
|
1727
|
-
const $ZodISODate = /* @__PURE__ */ $constructor("$ZodISODate", (inst, def) => {
|
|
1728
|
-
def.pattern ?? (def.pattern = date$1);
|
|
1729
|
-
$ZodStringFormat.init(inst, def);
|
|
1730
|
-
});
|
|
1731
|
-
const $ZodISOTime = /* @__PURE__ */ $constructor("$ZodISOTime", (inst, def) => {
|
|
1732
|
-
def.pattern ?? (def.pattern = time$1(def));
|
|
1733
|
-
$ZodStringFormat.init(inst, def);
|
|
1734
|
-
});
|
|
1735
|
-
const $ZodISODuration = /* @__PURE__ */ $constructor("$ZodISODuration", (inst, def) => {
|
|
1736
|
-
def.pattern ?? (def.pattern = duration$1);
|
|
1737
|
-
$ZodStringFormat.init(inst, def);
|
|
1738
|
-
});
|
|
1739
|
-
const $ZodIPv4 = /* @__PURE__ */ $constructor("$ZodIPv4", (inst, def) => {
|
|
1740
|
-
def.pattern ?? (def.pattern = ipv4);
|
|
1741
|
-
$ZodStringFormat.init(inst, def);
|
|
1742
|
-
inst._zod.onattach.push((inst$1) => {
|
|
1743
|
-
const bag = inst$1._zod.bag;
|
|
1744
|
-
bag.format = `ipv4`;
|
|
1745
|
-
});
|
|
1746
|
-
});
|
|
1747
|
-
const $ZodIPv6 = /* @__PURE__ */ $constructor("$ZodIPv6", (inst, def) => {
|
|
1748
|
-
def.pattern ?? (def.pattern = ipv6);
|
|
1749
|
-
$ZodStringFormat.init(inst, def);
|
|
1750
|
-
inst._zod.onattach.push((inst$1) => {
|
|
1751
|
-
const bag = inst$1._zod.bag;
|
|
1752
|
-
bag.format = `ipv6`;
|
|
1753
|
-
});
|
|
1754
|
-
inst._zod.check = (payload) => {
|
|
1755
|
-
try {
|
|
1756
|
-
new URL(`http://[${payload.value}]`);
|
|
1757
|
-
} catch {
|
|
1758
|
-
payload.issues.push({
|
|
1759
|
-
code: "invalid_format",
|
|
1760
|
-
format: "ipv6",
|
|
1761
|
-
input: payload.value,
|
|
1762
|
-
inst,
|
|
1763
|
-
continue: !def.abort
|
|
1764
|
-
});
|
|
1765
|
-
}
|
|
1766
|
-
};
|
|
1767
|
-
});
|
|
1768
|
-
const $ZodCIDRv4 = /* @__PURE__ */ $constructor("$ZodCIDRv4", (inst, def) => {
|
|
1769
|
-
def.pattern ?? (def.pattern = cidrv4);
|
|
1770
|
-
$ZodStringFormat.init(inst, def);
|
|
1771
|
-
});
|
|
1772
|
-
const $ZodCIDRv6 = /* @__PURE__ */ $constructor("$ZodCIDRv6", (inst, def) => {
|
|
1773
|
-
def.pattern ?? (def.pattern = cidrv6);
|
|
1774
|
-
$ZodStringFormat.init(inst, def);
|
|
1775
|
-
inst._zod.check = (payload) => {
|
|
1776
|
-
const [address, prefix] = payload.value.split("/");
|
|
1777
|
-
try {
|
|
1778
|
-
if (!prefix) throw new Error();
|
|
1779
|
-
const prefixNum = Number(prefix);
|
|
1780
|
-
if (`${prefixNum}` !== prefix) throw new Error();
|
|
1781
|
-
if (prefixNum < 0 || prefixNum > 128) throw new Error();
|
|
1782
|
-
new URL(`http://[${address}]`);
|
|
1783
|
-
} catch {
|
|
1784
|
-
payload.issues.push({
|
|
1785
|
-
code: "invalid_format",
|
|
1786
|
-
format: "cidrv6",
|
|
1787
|
-
input: payload.value,
|
|
1788
|
-
inst,
|
|
1789
|
-
continue: !def.abort
|
|
1790
|
-
});
|
|
1791
|
-
}
|
|
1792
|
-
};
|
|
1793
|
-
});
|
|
1794
|
-
function isValidBase64(data) {
|
|
1795
|
-
if (data === "") return true;
|
|
1796
|
-
if (data.length % 4 !== 0) return false;
|
|
1797
|
-
try {
|
|
1798
|
-
atob(data);
|
|
1799
|
-
return true;
|
|
1800
|
-
} catch {
|
|
1801
|
-
return false;
|
|
1802
|
-
}
|
|
1803
|
-
}
|
|
1804
|
-
const $ZodBase64 = /* @__PURE__ */ $constructor("$ZodBase64", (inst, def) => {
|
|
1805
|
-
def.pattern ?? (def.pattern = base64);
|
|
1806
|
-
$ZodStringFormat.init(inst, def);
|
|
1807
|
-
inst._zod.onattach.push((inst$1) => {
|
|
1808
|
-
inst$1._zod.bag.contentEncoding = "base64";
|
|
1809
|
-
});
|
|
1810
|
-
inst._zod.check = (payload) => {
|
|
1811
|
-
if (isValidBase64(payload.value)) return;
|
|
1812
|
-
payload.issues.push({
|
|
1813
|
-
code: "invalid_format",
|
|
1814
|
-
format: "base64",
|
|
1815
|
-
input: payload.value,
|
|
1816
|
-
inst,
|
|
1817
|
-
continue: !def.abort
|
|
1818
|
-
});
|
|
1819
|
-
};
|
|
1820
|
-
});
|
|
1821
|
-
function isValidBase64URL(data) {
|
|
1822
|
-
if (!base64url.test(data)) return false;
|
|
1823
|
-
const base64$1 = data.replace(/[-_]/g, (c$1) => c$1 === "-" ? "+" : "/");
|
|
1824
|
-
const padded = base64$1.padEnd(Math.ceil(base64$1.length / 4) * 4, "=");
|
|
1825
|
-
return isValidBase64(padded);
|
|
1826
|
-
}
|
|
1827
|
-
const $ZodBase64URL = /* @__PURE__ */ $constructor("$ZodBase64URL", (inst, def) => {
|
|
1828
|
-
def.pattern ?? (def.pattern = base64url);
|
|
1829
|
-
$ZodStringFormat.init(inst, def);
|
|
1830
|
-
inst._zod.onattach.push((inst$1) => {
|
|
1831
|
-
inst$1._zod.bag.contentEncoding = "base64url";
|
|
1832
|
-
});
|
|
1833
|
-
inst._zod.check = (payload) => {
|
|
1834
|
-
if (isValidBase64URL(payload.value)) return;
|
|
1835
|
-
payload.issues.push({
|
|
1836
|
-
code: "invalid_format",
|
|
1837
|
-
format: "base64url",
|
|
1838
|
-
input: payload.value,
|
|
1839
|
-
inst,
|
|
1840
|
-
continue: !def.abort
|
|
1841
|
-
});
|
|
1842
|
-
};
|
|
1843
|
-
});
|
|
1844
|
-
const $ZodE164 = /* @__PURE__ */ $constructor("$ZodE164", (inst, def) => {
|
|
1845
|
-
def.pattern ?? (def.pattern = e164);
|
|
1846
|
-
$ZodStringFormat.init(inst, def);
|
|
1847
|
-
});
|
|
1848
|
-
function isValidJWT(token, algorithm = null) {
|
|
1849
|
-
try {
|
|
1850
|
-
const tokensParts = token.split(".");
|
|
1851
|
-
if (tokensParts.length !== 3) return false;
|
|
1852
|
-
const [header] = tokensParts;
|
|
1853
|
-
if (!header) return false;
|
|
1854
|
-
const parsedHeader = JSON.parse(atob(header));
|
|
1855
|
-
if ("typ" in parsedHeader && parsedHeader?.typ !== "JWT") return false;
|
|
1856
|
-
if (!parsedHeader.alg) return false;
|
|
1857
|
-
if (algorithm && (!("alg" in parsedHeader) || parsedHeader.alg !== algorithm)) return false;
|
|
1858
|
-
return true;
|
|
1859
|
-
} catch {
|
|
1860
|
-
return false;
|
|
1861
|
-
}
|
|
1862
|
-
}
|
|
1863
|
-
const $ZodJWT = /* @__PURE__ */ $constructor("$ZodJWT", (inst, def) => {
|
|
1864
|
-
$ZodStringFormat.init(inst, def);
|
|
1865
|
-
inst._zod.check = (payload) => {
|
|
1866
|
-
if (isValidJWT(payload.value, def.alg)) return;
|
|
1867
|
-
payload.issues.push({
|
|
1868
|
-
code: "invalid_format",
|
|
1869
|
-
format: "jwt",
|
|
1870
|
-
input: payload.value,
|
|
1871
|
-
inst,
|
|
1872
|
-
continue: !def.abort
|
|
1873
|
-
});
|
|
1874
|
-
};
|
|
1875
|
-
});
|
|
1876
|
-
const $ZodAny = /* @__PURE__ */ $constructor("$ZodAny", (inst, def) => {
|
|
1877
|
-
$ZodType.init(inst, def);
|
|
1878
|
-
inst._zod.parse = (payload) => payload;
|
|
1879
|
-
});
|
|
1880
|
-
const $ZodUnknown = /* @__PURE__ */ $constructor("$ZodUnknown", (inst, def) => {
|
|
1881
|
-
$ZodType.init(inst, def);
|
|
1882
|
-
inst._zod.parse = (payload) => payload;
|
|
1883
|
-
});
|
|
1884
|
-
const $ZodNever = /* @__PURE__ */ $constructor("$ZodNever", (inst, def) => {
|
|
1885
|
-
$ZodType.init(inst, def);
|
|
1886
|
-
inst._zod.parse = (payload, _ctx) => {
|
|
1887
|
-
payload.issues.push({
|
|
1888
|
-
expected: "never",
|
|
1889
|
-
code: "invalid_type",
|
|
1890
|
-
input: payload.value,
|
|
1891
|
-
inst
|
|
1892
|
-
});
|
|
1893
|
-
return payload;
|
|
1894
|
-
};
|
|
1895
|
-
});
|
|
1896
|
-
function handleArrayResult(result, final, index) {
|
|
1897
|
-
if (result.issues.length) final.issues.push(...prefixIssues(index, result.issues));
|
|
1898
|
-
final.value[index] = result.value;
|
|
1899
|
-
}
|
|
1900
|
-
const $ZodArray = /* @__PURE__ */ $constructor("$ZodArray", (inst, def) => {
|
|
1901
|
-
$ZodType.init(inst, def);
|
|
1902
|
-
inst._zod.parse = (payload, ctx) => {
|
|
1903
|
-
const input = payload.value;
|
|
1904
|
-
if (!Array.isArray(input)) {
|
|
1905
|
-
payload.issues.push({
|
|
1906
|
-
expected: "array",
|
|
1907
|
-
code: "invalid_type",
|
|
1908
|
-
input,
|
|
1909
|
-
inst
|
|
1910
|
-
});
|
|
1911
|
-
return payload;
|
|
1912
|
-
}
|
|
1913
|
-
payload.value = Array(input.length);
|
|
1914
|
-
const proms = [];
|
|
1915
|
-
for (let i$1 = 0; i$1 < input.length; i$1++) {
|
|
1916
|
-
const item = input[i$1];
|
|
1917
|
-
const result = def.element._zod.run({
|
|
1918
|
-
value: item,
|
|
1919
|
-
issues: []
|
|
1920
|
-
}, ctx);
|
|
1921
|
-
if (result instanceof Promise) proms.push(result.then((result$1) => handleArrayResult(result$1, payload, i$1)));
|
|
1922
|
-
else handleArrayResult(result, payload, i$1);
|
|
1923
|
-
}
|
|
1924
|
-
if (proms.length) return Promise.all(proms).then(() => payload);
|
|
1925
|
-
return payload;
|
|
1103
|
+
if (proms.length) return Promise.all(proms).then(() => payload);
|
|
1104
|
+
return payload;
|
|
1926
1105
|
};
|
|
1927
1106
|
});
|
|
1928
1107
|
function handlePropertyResult(result, final, key, input) {
|
|
@@ -1931,20 +1110,50 @@ function handlePropertyResult(result, final, key, input) {
|
|
|
1931
1110
|
if (key in input) final.value[key] = void 0;
|
|
1932
1111
|
} else final.value[key] = result.value;
|
|
1933
1112
|
}
|
|
1113
|
+
function normalizeDef(def) {
|
|
1114
|
+
const keys = Object.keys(def.shape);
|
|
1115
|
+
for (const k$1 of keys) if (!def.shape[k$1]._zod.traits.has("$ZodType")) throw new Error(`Invalid element at key "${k$1}": expected a Zod schema`);
|
|
1116
|
+
const okeys = optionalKeys(def.shape);
|
|
1117
|
+
return {
|
|
1118
|
+
...def,
|
|
1119
|
+
keys,
|
|
1120
|
+
keySet: new Set(keys),
|
|
1121
|
+
numKeys: keys.length,
|
|
1122
|
+
optionalKeys: new Set(okeys)
|
|
1123
|
+
};
|
|
1124
|
+
}
|
|
1125
|
+
function handleCatchall(proms, input, payload, ctx, def, inst) {
|
|
1126
|
+
const unrecognized = [];
|
|
1127
|
+
const keySet = def.keySet;
|
|
1128
|
+
const _catchall = def.catchall._zod;
|
|
1129
|
+
const t$1 = _catchall.def.type;
|
|
1130
|
+
for (const key of Object.keys(input)) {
|
|
1131
|
+
if (keySet.has(key)) continue;
|
|
1132
|
+
if (t$1 === "never") {
|
|
1133
|
+
unrecognized.push(key);
|
|
1134
|
+
continue;
|
|
1135
|
+
}
|
|
1136
|
+
const r$1 = _catchall.run({
|
|
1137
|
+
value: input[key],
|
|
1138
|
+
issues: []
|
|
1139
|
+
}, ctx);
|
|
1140
|
+
if (r$1 instanceof Promise) proms.push(r$1.then((r$2) => handlePropertyResult(r$2, payload, key, input)));
|
|
1141
|
+
else handlePropertyResult(r$1, payload, key, input);
|
|
1142
|
+
}
|
|
1143
|
+
if (unrecognized.length) payload.issues.push({
|
|
1144
|
+
code: "unrecognized_keys",
|
|
1145
|
+
keys: unrecognized,
|
|
1146
|
+
input,
|
|
1147
|
+
inst
|
|
1148
|
+
});
|
|
1149
|
+
if (!proms.length) return payload;
|
|
1150
|
+
return Promise.all(proms).then(() => {
|
|
1151
|
+
return payload;
|
|
1152
|
+
});
|
|
1153
|
+
}
|
|
1934
1154
|
const $ZodObject = /* @__PURE__ */ $constructor("$ZodObject", (inst, def) => {
|
|
1935
1155
|
$ZodType.init(inst, def);
|
|
1936
|
-
const _normalized = cached(() =>
|
|
1937
|
-
const keys = Object.keys(def.shape);
|
|
1938
|
-
for (const k$1 of keys) if (!(def.shape[k$1] instanceof $ZodType)) throw new Error(`Invalid element at key "${k$1}": expected a Zod schema`);
|
|
1939
|
-
const okeys = optionalKeys(def.shape);
|
|
1940
|
-
return {
|
|
1941
|
-
shape: def.shape,
|
|
1942
|
-
keys,
|
|
1943
|
-
keySet: new Set(keys),
|
|
1944
|
-
numKeys: keys.length,
|
|
1945
|
-
optionalKeys: new Set(okeys)
|
|
1946
|
-
};
|
|
1947
|
-
});
|
|
1156
|
+
const _normalized = cached(() => normalizeDef(def));
|
|
1948
1157
|
defineLazy(inst._zod, "propValues", () => {
|
|
1949
1158
|
const shape = def.shape;
|
|
1950
1159
|
const propValues = {};
|
|
@@ -1957,53 +1166,7 @@ const $ZodObject = /* @__PURE__ */ $constructor("$ZodObject", (inst, def) => {
|
|
|
1957
1166
|
}
|
|
1958
1167
|
return propValues;
|
|
1959
1168
|
});
|
|
1960
|
-
const generateFastpass = (shape) => {
|
|
1961
|
-
const doc = new Doc([
|
|
1962
|
-
"shape",
|
|
1963
|
-
"payload",
|
|
1964
|
-
"ctx"
|
|
1965
|
-
]);
|
|
1966
|
-
const normalized = _normalized.value;
|
|
1967
|
-
const parseStr = (key) => {
|
|
1968
|
-
const k$1 = esc(key);
|
|
1969
|
-
return `shape[${k$1}]._zod.run({ value: input[${k$1}], issues: [] }, ctx)`;
|
|
1970
|
-
};
|
|
1971
|
-
doc.write(`const input = payload.value;`);
|
|
1972
|
-
const ids = Object.create(null);
|
|
1973
|
-
let counter = 0;
|
|
1974
|
-
for (const key of normalized.keys) ids[key] = `key_${counter++}`;
|
|
1975
|
-
doc.write(`const newResult = {}`);
|
|
1976
|
-
for (const key of normalized.keys) {
|
|
1977
|
-
const id = ids[key];
|
|
1978
|
-
const k$1 = esc(key);
|
|
1979
|
-
doc.write(`const ${id} = ${parseStr(key)};`);
|
|
1980
|
-
doc.write(`
|
|
1981
|
-
if (${id}.issues.length) {
|
|
1982
|
-
payload.issues = payload.issues.concat(${id}.issues.map(iss => ({
|
|
1983
|
-
...iss,
|
|
1984
|
-
path: iss.path ? [${k$1}, ...iss.path] : [${k$1}]
|
|
1985
|
-
})));
|
|
1986
|
-
}
|
|
1987
|
-
|
|
1988
|
-
if (${id}.value === undefined) {
|
|
1989
|
-
if (${k$1} in input) {
|
|
1990
|
-
newResult[${k$1}] = undefined;
|
|
1991
|
-
}
|
|
1992
|
-
} else {
|
|
1993
|
-
newResult[${k$1}] = ${id}.value;
|
|
1994
|
-
}
|
|
1995
|
-
`);
|
|
1996
|
-
}
|
|
1997
|
-
doc.write(`payload.value = newResult;`);
|
|
1998
|
-
doc.write(`return payload;`);
|
|
1999
|
-
const fn = doc.compile();
|
|
2000
|
-
return (payload, ctx) => fn(shape, payload, ctx);
|
|
2001
|
-
};
|
|
2002
|
-
let fastpass;
|
|
2003
1169
|
const isObject$1 = isObject;
|
|
2004
|
-
const jit = !globalConfig.jitless;
|
|
2005
|
-
const allowsEval$1 = allowsEval;
|
|
2006
|
-
const fastEnabled = jit && allowsEval$1.value;
|
|
2007
1170
|
const catchall = def.catchall;
|
|
2008
1171
|
let value;
|
|
2009
1172
|
inst._zod.parse = (payload, ctx) => {
|
|
@@ -2018,51 +1181,19 @@ const $ZodObject = /* @__PURE__ */ $constructor("$ZodObject", (inst, def) => {
|
|
|
2018
1181
|
});
|
|
2019
1182
|
return payload;
|
|
2020
1183
|
}
|
|
1184
|
+
payload.value = {};
|
|
2021
1185
|
const proms = [];
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
} else {
|
|
2026
|
-
payload.value = {};
|
|
2027
|
-
const shape = value.shape;
|
|
2028
|
-
for (const key of value.keys) {
|
|
2029
|
-
const el = shape[key];
|
|
2030
|
-
const r$1 = el._zod.run({
|
|
2031
|
-
value: input[key],
|
|
2032
|
-
issues: []
|
|
2033
|
-
}, ctx);
|
|
2034
|
-
if (r$1 instanceof Promise) proms.push(r$1.then((r$2) => handlePropertyResult(r$2, payload, key, input)));
|
|
2035
|
-
else handlePropertyResult(r$1, payload, key, input);
|
|
2036
|
-
}
|
|
2037
|
-
}
|
|
2038
|
-
if (!catchall) return proms.length ? Promise.all(proms).then(() => payload) : payload;
|
|
2039
|
-
const unrecognized = [];
|
|
2040
|
-
const keySet = value.keySet;
|
|
2041
|
-
const _catchall = catchall._zod;
|
|
2042
|
-
const t$1 = _catchall.def.type;
|
|
2043
|
-
for (const key of Object.keys(input)) {
|
|
2044
|
-
if (keySet.has(key)) continue;
|
|
2045
|
-
if (t$1 === "never") {
|
|
2046
|
-
unrecognized.push(key);
|
|
2047
|
-
continue;
|
|
2048
|
-
}
|
|
2049
|
-
const r$1 = _catchall.run({
|
|
1186
|
+
const shape = value.shape;
|
|
1187
|
+
for (const key of value.keys) {
|
|
1188
|
+
const r$1 = shape[key]._zod.run({
|
|
2050
1189
|
value: input[key],
|
|
2051
1190
|
issues: []
|
|
2052
1191
|
}, ctx);
|
|
2053
1192
|
if (r$1 instanceof Promise) proms.push(r$1.then((r$2) => handlePropertyResult(r$2, payload, key, input)));
|
|
2054
1193
|
else handlePropertyResult(r$1, payload, key, input);
|
|
2055
1194
|
}
|
|
2056
|
-
if (
|
|
2057
|
-
|
|
2058
|
-
keys: unrecognized,
|
|
2059
|
-
input,
|
|
2060
|
-
inst
|
|
2061
|
-
});
|
|
2062
|
-
if (!proms.length) return payload;
|
|
2063
|
-
return Promise.all(proms).then(() => {
|
|
2064
|
-
return payload;
|
|
2065
|
-
});
|
|
1195
|
+
if (!catchall) return proms.length ? Promise.all(proms).then(() => payload) : payload;
|
|
1196
|
+
return handleCatchall(proms, input, payload, ctx, _normalized.value, inst);
|
|
2066
1197
|
};
|
|
2067
1198
|
});
|
|
2068
1199
|
function handleUnionResults(results, final, inst, ctx) {
|
|
@@ -2078,801 +1209,95 @@ function handleUnionResults(results, final, inst, ctx) {
|
|
|
2078
1209
|
final.issues.push({
|
|
2079
1210
|
code: "invalid_union",
|
|
2080
1211
|
input: final.value,
|
|
2081
|
-
inst,
|
|
2082
|
-
errors: results.map((result) => result.issues.map((iss) => finalizeIssue(iss, ctx, config())))
|
|
2083
|
-
});
|
|
2084
|
-
return final;
|
|
2085
|
-
}
|
|
2086
|
-
const $ZodUnion = /* @__PURE__ */ $constructor("$ZodUnion", (inst, def) => {
|
|
2087
|
-
$ZodType.init(inst, def);
|
|
2088
|
-
defineLazy(inst._zod, "optin", () => def.options.some((o$1) => o$1._zod.optin === "optional") ? "optional" : void 0);
|
|
2089
|
-
defineLazy(inst._zod, "optout", () => def.options.some((o$1) => o$1._zod.optout === "optional") ? "optional" : void 0);
|
|
2090
|
-
defineLazy(inst._zod, "values", () => {
|
|
2091
|
-
if (def.options.every((o$1) => o$1._zod.values)) return new Set(def.options.flatMap((option) => Array.from(option._zod.values)));
|
|
2092
|
-
return void 0;
|
|
2093
|
-
});
|
|
2094
|
-
defineLazy(inst._zod, "pattern", () => {
|
|
2095
|
-
if (def.options.every((o$1) => o$1._zod.pattern)) {
|
|
2096
|
-
const patterns = def.options.map((o$1) => o$1._zod.pattern);
|
|
2097
|
-
return /* @__PURE__ */ new RegExp(`^(${patterns.map((p$1) => cleanRegex(p$1.source)).join("|")})$`);
|
|
2098
|
-
}
|
|
2099
|
-
return void 0;
|
|
2100
|
-
});
|
|
2101
|
-
inst._zod.parse = (payload, ctx) => {
|
|
2102
|
-
let async = false;
|
|
2103
|
-
const results = [];
|
|
2104
|
-
for (const option of def.options) {
|
|
2105
|
-
const result = option._zod.run({
|
|
2106
|
-
value: payload.value,
|
|
2107
|
-
issues: []
|
|
2108
|
-
}, ctx);
|
|
2109
|
-
if (result instanceof Promise) {
|
|
2110
|
-
results.push(result);
|
|
2111
|
-
async = true;
|
|
2112
|
-
} else {
|
|
2113
|
-
if (result.issues.length === 0) return result;
|
|
2114
|
-
results.push(result);
|
|
2115
|
-
}
|
|
2116
|
-
}
|
|
2117
|
-
if (!async) return handleUnionResults(results, payload, inst, ctx);
|
|
2118
|
-
return Promise.all(results).then((results$1) => {
|
|
2119
|
-
return handleUnionResults(results$1, payload, inst, ctx);
|
|
2120
|
-
});
|
|
2121
|
-
};
|
|
2122
|
-
});
|
|
2123
|
-
const $ZodIntersection = /* @__PURE__ */ $constructor("$ZodIntersection", (inst, def) => {
|
|
2124
|
-
$ZodType.init(inst, def);
|
|
2125
|
-
inst._zod.parse = (payload, ctx) => {
|
|
2126
|
-
const input = payload.value;
|
|
2127
|
-
const left = def.left._zod.run({
|
|
2128
|
-
value: input,
|
|
2129
|
-
issues: []
|
|
2130
|
-
}, ctx);
|
|
2131
|
-
const right = def.right._zod.run({
|
|
2132
|
-
value: input,
|
|
2133
|
-
issues: []
|
|
2134
|
-
}, ctx);
|
|
2135
|
-
const async = left instanceof Promise || right instanceof Promise;
|
|
2136
|
-
if (async) return Promise.all([left, right]).then(([left$1, right$1]) => {
|
|
2137
|
-
return handleIntersectionResults(payload, left$1, right$1);
|
|
2138
|
-
});
|
|
2139
|
-
return handleIntersectionResults(payload, left, right);
|
|
2140
|
-
};
|
|
2141
|
-
});
|
|
2142
|
-
function mergeValues(a$1, b$1) {
|
|
2143
|
-
if (a$1 === b$1) return {
|
|
2144
|
-
valid: true,
|
|
2145
|
-
data: a$1
|
|
2146
|
-
};
|
|
2147
|
-
if (a$1 instanceof Date && b$1 instanceof Date && +a$1 === +b$1) return {
|
|
2148
|
-
valid: true,
|
|
2149
|
-
data: a$1
|
|
2150
|
-
};
|
|
2151
|
-
if (isPlainObject(a$1) && isPlainObject(b$1)) {
|
|
2152
|
-
const bKeys = Object.keys(b$1);
|
|
2153
|
-
const sharedKeys = Object.keys(a$1).filter((key) => bKeys.indexOf(key) !== -1);
|
|
2154
|
-
const newObj = {
|
|
2155
|
-
...a$1,
|
|
2156
|
-
...b$1
|
|
2157
|
-
};
|
|
2158
|
-
for (const key of sharedKeys) {
|
|
2159
|
-
const sharedValue = mergeValues(a$1[key], b$1[key]);
|
|
2160
|
-
if (!sharedValue.valid) return {
|
|
2161
|
-
valid: false,
|
|
2162
|
-
mergeErrorPath: [key, ...sharedValue.mergeErrorPath]
|
|
2163
|
-
};
|
|
2164
|
-
newObj[key] = sharedValue.data;
|
|
2165
|
-
}
|
|
2166
|
-
return {
|
|
2167
|
-
valid: true,
|
|
2168
|
-
data: newObj
|
|
2169
|
-
};
|
|
2170
|
-
}
|
|
2171
|
-
if (Array.isArray(a$1) && Array.isArray(b$1)) {
|
|
2172
|
-
if (a$1.length !== b$1.length) return {
|
|
2173
|
-
valid: false,
|
|
2174
|
-
mergeErrorPath: []
|
|
2175
|
-
};
|
|
2176
|
-
const newArray = [];
|
|
2177
|
-
for (let index = 0; index < a$1.length; index++) {
|
|
2178
|
-
const itemA = a$1[index];
|
|
2179
|
-
const itemB = b$1[index];
|
|
2180
|
-
const sharedValue = mergeValues(itemA, itemB);
|
|
2181
|
-
if (!sharedValue.valid) return {
|
|
2182
|
-
valid: false,
|
|
2183
|
-
mergeErrorPath: [index, ...sharedValue.mergeErrorPath]
|
|
2184
|
-
};
|
|
2185
|
-
newArray.push(sharedValue.data);
|
|
2186
|
-
}
|
|
2187
|
-
return {
|
|
2188
|
-
valid: true,
|
|
2189
|
-
data: newArray
|
|
2190
|
-
};
|
|
2191
|
-
}
|
|
2192
|
-
return {
|
|
2193
|
-
valid: false,
|
|
2194
|
-
mergeErrorPath: []
|
|
2195
|
-
};
|
|
2196
|
-
}
|
|
2197
|
-
function handleIntersectionResults(result, left, right) {
|
|
2198
|
-
if (left.issues.length) result.issues.push(...left.issues);
|
|
2199
|
-
if (right.issues.length) result.issues.push(...right.issues);
|
|
2200
|
-
if (aborted(result)) return result;
|
|
2201
|
-
const merged = mergeValues(left.value, right.value);
|
|
2202
|
-
if (!merged.valid) throw new Error(`Unmergable intersection. Error path: ${JSON.stringify(merged.mergeErrorPath)}`);
|
|
2203
|
-
result.value = merged.data;
|
|
2204
|
-
return result;
|
|
2205
|
-
}
|
|
2206
|
-
const $ZodEnum = /* @__PURE__ */ $constructor("$ZodEnum", (inst, def) => {
|
|
2207
|
-
$ZodType.init(inst, def);
|
|
2208
|
-
const values = getEnumValues(def.entries);
|
|
2209
|
-
const valuesSet = new Set(values);
|
|
2210
|
-
inst._zod.values = valuesSet;
|
|
2211
|
-
inst._zod.pattern = /* @__PURE__ */ new RegExp(`^(${values.filter((k$1) => propertyKeyTypes.has(typeof k$1)).map((o$1) => typeof o$1 === "string" ? escapeRegex(o$1) : o$1.toString()).join("|")})$`);
|
|
2212
|
-
inst._zod.parse = (payload, _ctx) => {
|
|
2213
|
-
const input = payload.value;
|
|
2214
|
-
if (valuesSet.has(input)) return payload;
|
|
2215
|
-
payload.issues.push({
|
|
2216
|
-
code: "invalid_value",
|
|
2217
|
-
values,
|
|
2218
|
-
input,
|
|
2219
|
-
inst
|
|
2220
|
-
});
|
|
2221
|
-
return payload;
|
|
2222
|
-
};
|
|
2223
|
-
});
|
|
2224
|
-
const $ZodTransform = /* @__PURE__ */ $constructor("$ZodTransform", (inst, def) => {
|
|
2225
|
-
$ZodType.init(inst, def);
|
|
2226
|
-
inst._zod.parse = (payload, _ctx) => {
|
|
2227
|
-
const _out = def.transform(payload.value, payload);
|
|
2228
|
-
if (_ctx.async) {
|
|
2229
|
-
const output = _out instanceof Promise ? _out : Promise.resolve(_out);
|
|
2230
|
-
return output.then((output$1) => {
|
|
2231
|
-
payload.value = output$1;
|
|
2232
|
-
return payload;
|
|
2233
|
-
});
|
|
2234
|
-
}
|
|
2235
|
-
if (_out instanceof Promise) throw new $ZodAsyncError();
|
|
2236
|
-
payload.value = _out;
|
|
2237
|
-
return payload;
|
|
2238
|
-
};
|
|
2239
|
-
});
|
|
2240
|
-
const $ZodOptional = /* @__PURE__ */ $constructor("$ZodOptional", (inst, def) => {
|
|
2241
|
-
$ZodType.init(inst, def);
|
|
2242
|
-
inst._zod.optin = "optional";
|
|
2243
|
-
inst._zod.optout = "optional";
|
|
2244
|
-
defineLazy(inst._zod, "values", () => {
|
|
2245
|
-
return def.innerType._zod.values ? new Set([...def.innerType._zod.values, void 0]) : void 0;
|
|
2246
|
-
});
|
|
2247
|
-
defineLazy(inst._zod, "pattern", () => {
|
|
2248
|
-
const pattern = def.innerType._zod.pattern;
|
|
2249
|
-
return pattern ? /* @__PURE__ */ new RegExp(`^(${cleanRegex(pattern.source)})?$`) : void 0;
|
|
2250
|
-
});
|
|
2251
|
-
inst._zod.parse = (payload, ctx) => {
|
|
2252
|
-
if (def.innerType._zod.optin === "optional") return def.innerType._zod.run(payload, ctx);
|
|
2253
|
-
if (payload.value === void 0) return payload;
|
|
2254
|
-
return def.innerType._zod.run(payload, ctx);
|
|
2255
|
-
};
|
|
2256
|
-
});
|
|
2257
|
-
const $ZodNullable = /* @__PURE__ */ $constructor("$ZodNullable", (inst, def) => {
|
|
2258
|
-
$ZodType.init(inst, def);
|
|
2259
|
-
defineLazy(inst._zod, "optin", () => def.innerType._zod.optin);
|
|
2260
|
-
defineLazy(inst._zod, "optout", () => def.innerType._zod.optout);
|
|
2261
|
-
defineLazy(inst._zod, "pattern", () => {
|
|
2262
|
-
const pattern = def.innerType._zod.pattern;
|
|
2263
|
-
return pattern ? /* @__PURE__ */ new RegExp(`^(${cleanRegex(pattern.source)}|null)$`) : void 0;
|
|
2264
|
-
});
|
|
2265
|
-
defineLazy(inst._zod, "values", () => {
|
|
2266
|
-
return def.innerType._zod.values ? new Set([...def.innerType._zod.values, null]) : void 0;
|
|
2267
|
-
});
|
|
2268
|
-
inst._zod.parse = (payload, ctx) => {
|
|
2269
|
-
if (payload.value === null) return payload;
|
|
2270
|
-
return def.innerType._zod.run(payload, ctx);
|
|
2271
|
-
};
|
|
2272
|
-
});
|
|
2273
|
-
const $ZodDefault = /* @__PURE__ */ $constructor("$ZodDefault", (inst, def) => {
|
|
2274
|
-
$ZodType.init(inst, def);
|
|
2275
|
-
inst._zod.optin = "optional";
|
|
2276
|
-
defineLazy(inst._zod, "values", () => def.innerType._zod.values);
|
|
2277
|
-
inst._zod.parse = (payload, ctx) => {
|
|
2278
|
-
if (payload.value === void 0) {
|
|
2279
|
-
payload.value = def.defaultValue;
|
|
2280
|
-
return payload;
|
|
2281
|
-
}
|
|
2282
|
-
const result = def.innerType._zod.run(payload, ctx);
|
|
2283
|
-
if (result instanceof Promise) return result.then((result$1) => handleDefaultResult(result$1, def));
|
|
2284
|
-
return handleDefaultResult(result, def);
|
|
2285
|
-
};
|
|
2286
|
-
});
|
|
2287
|
-
function handleDefaultResult(payload, def) {
|
|
2288
|
-
if (payload.value === void 0) payload.value = def.defaultValue;
|
|
2289
|
-
return payload;
|
|
2290
|
-
}
|
|
2291
|
-
const $ZodPrefault = /* @__PURE__ */ $constructor("$ZodPrefault", (inst, def) => {
|
|
2292
|
-
$ZodType.init(inst, def);
|
|
2293
|
-
inst._zod.optin = "optional";
|
|
2294
|
-
defineLazy(inst._zod, "values", () => def.innerType._zod.values);
|
|
2295
|
-
inst._zod.parse = (payload, ctx) => {
|
|
2296
|
-
if (payload.value === void 0) payload.value = def.defaultValue;
|
|
2297
|
-
return def.innerType._zod.run(payload, ctx);
|
|
2298
|
-
};
|
|
2299
|
-
});
|
|
2300
|
-
const $ZodNonOptional = /* @__PURE__ */ $constructor("$ZodNonOptional", (inst, def) => {
|
|
2301
|
-
$ZodType.init(inst, def);
|
|
2302
|
-
defineLazy(inst._zod, "values", () => {
|
|
2303
|
-
const v$1 = def.innerType._zod.values;
|
|
2304
|
-
return v$1 ? new Set([...v$1].filter((x$1) => x$1 !== void 0)) : void 0;
|
|
2305
|
-
});
|
|
2306
|
-
inst._zod.parse = (payload, ctx) => {
|
|
2307
|
-
const result = def.innerType._zod.run(payload, ctx);
|
|
2308
|
-
if (result instanceof Promise) return result.then((result$1) => handleNonOptionalResult(result$1, inst));
|
|
2309
|
-
return handleNonOptionalResult(result, inst);
|
|
2310
|
-
};
|
|
2311
|
-
});
|
|
2312
|
-
function handleNonOptionalResult(payload, inst) {
|
|
2313
|
-
if (!payload.issues.length && payload.value === void 0) payload.issues.push({
|
|
2314
|
-
code: "invalid_type",
|
|
2315
|
-
expected: "nonoptional",
|
|
2316
|
-
input: payload.value,
|
|
2317
|
-
inst
|
|
2318
|
-
});
|
|
2319
|
-
return payload;
|
|
2320
|
-
}
|
|
2321
|
-
const $ZodCatch = /* @__PURE__ */ $constructor("$ZodCatch", (inst, def) => {
|
|
2322
|
-
$ZodType.init(inst, def);
|
|
2323
|
-
defineLazy(inst._zod, "optin", () => def.innerType._zod.optin);
|
|
2324
|
-
defineLazy(inst._zod, "optout", () => def.innerType._zod.optout);
|
|
2325
|
-
defineLazy(inst._zod, "values", () => def.innerType._zod.values);
|
|
2326
|
-
inst._zod.parse = (payload, ctx) => {
|
|
2327
|
-
const result = def.innerType._zod.run(payload, ctx);
|
|
2328
|
-
if (result instanceof Promise) return result.then((result$1) => {
|
|
2329
|
-
payload.value = result$1.value;
|
|
2330
|
-
if (result$1.issues.length) {
|
|
2331
|
-
payload.value = def.catchValue({
|
|
2332
|
-
...payload,
|
|
2333
|
-
error: { issues: result$1.issues.map((iss) => finalizeIssue(iss, ctx, config())) },
|
|
2334
|
-
input: payload.value
|
|
2335
|
-
});
|
|
2336
|
-
payload.issues = [];
|
|
2337
|
-
}
|
|
2338
|
-
return payload;
|
|
2339
|
-
});
|
|
2340
|
-
payload.value = result.value;
|
|
2341
|
-
if (result.issues.length) {
|
|
2342
|
-
payload.value = def.catchValue({
|
|
2343
|
-
...payload,
|
|
2344
|
-
error: { issues: result.issues.map((iss) => finalizeIssue(iss, ctx, config())) },
|
|
2345
|
-
input: payload.value
|
|
2346
|
-
});
|
|
2347
|
-
payload.issues = [];
|
|
2348
|
-
}
|
|
2349
|
-
return payload;
|
|
2350
|
-
};
|
|
2351
|
-
});
|
|
2352
|
-
const $ZodPipe = /* @__PURE__ */ $constructor("$ZodPipe", (inst, def) => {
|
|
2353
|
-
$ZodType.init(inst, def);
|
|
2354
|
-
defineLazy(inst._zod, "values", () => def.in._zod.values);
|
|
2355
|
-
defineLazy(inst._zod, "optin", () => def.in._zod.optin);
|
|
2356
|
-
defineLazy(inst._zod, "optout", () => def.out._zod.optout);
|
|
2357
|
-
defineLazy(inst._zod, "propValues", () => def.in._zod.propValues);
|
|
2358
|
-
inst._zod.parse = (payload, ctx) => {
|
|
2359
|
-
const left = def.in._zod.run(payload, ctx);
|
|
2360
|
-
if (left instanceof Promise) return left.then((left$1) => handlePipeResult(left$1, def, ctx));
|
|
2361
|
-
return handlePipeResult(left, def, ctx);
|
|
2362
|
-
};
|
|
2363
|
-
});
|
|
2364
|
-
function handlePipeResult(left, def, ctx) {
|
|
2365
|
-
if (left.issues.length) return left;
|
|
2366
|
-
return def.out._zod.run({
|
|
2367
|
-
value: left.value,
|
|
2368
|
-
issues: left.issues
|
|
2369
|
-
}, ctx);
|
|
2370
|
-
}
|
|
2371
|
-
const $ZodReadonly = /* @__PURE__ */ $constructor("$ZodReadonly", (inst, def) => {
|
|
2372
|
-
$ZodType.init(inst, def);
|
|
2373
|
-
defineLazy(inst._zod, "propValues", () => def.innerType._zod.propValues);
|
|
2374
|
-
defineLazy(inst._zod, "values", () => def.innerType._zod.values);
|
|
2375
|
-
defineLazy(inst._zod, "optin", () => def.innerType._zod.optin);
|
|
2376
|
-
defineLazy(inst._zod, "optout", () => def.innerType._zod.optout);
|
|
2377
|
-
inst._zod.parse = (payload, ctx) => {
|
|
2378
|
-
const result = def.innerType._zod.run(payload, ctx);
|
|
2379
|
-
if (result instanceof Promise) return result.then(handleReadonlyResult);
|
|
2380
|
-
return handleReadonlyResult(result);
|
|
2381
|
-
};
|
|
2382
|
-
});
|
|
2383
|
-
function handleReadonlyResult(payload) {
|
|
2384
|
-
payload.value = Object.freeze(payload.value);
|
|
2385
|
-
return payload;
|
|
2386
|
-
}
|
|
2387
|
-
const $ZodCustom = /* @__PURE__ */ $constructor("$ZodCustom", (inst, def) => {
|
|
2388
|
-
$ZodCheck.init(inst, def);
|
|
2389
|
-
$ZodType.init(inst, def);
|
|
2390
|
-
inst._zod.parse = (payload, _$1) => {
|
|
2391
|
-
return payload;
|
|
2392
|
-
};
|
|
2393
|
-
inst._zod.check = (payload) => {
|
|
2394
|
-
const input = payload.value;
|
|
2395
|
-
const r$1 = def.fn(input);
|
|
2396
|
-
if (r$1 instanceof Promise) return r$1.then((r$2) => handleRefineResult(r$2, payload, input, inst));
|
|
2397
|
-
handleRefineResult(r$1, payload, input, inst);
|
|
2398
|
-
return;
|
|
2399
|
-
};
|
|
2400
|
-
});
|
|
2401
|
-
function handleRefineResult(result, payload, input, inst) {
|
|
2402
|
-
if (!result) {
|
|
2403
|
-
const _iss = {
|
|
2404
|
-
code: "custom",
|
|
2405
|
-
input,
|
|
2406
|
-
inst,
|
|
2407
|
-
path: [...inst._zod.def.path ?? []],
|
|
2408
|
-
continue: !inst._zod.def.abort
|
|
2409
|
-
};
|
|
2410
|
-
if (inst._zod.def.params) _iss.params = inst._zod.def.params;
|
|
2411
|
-
payload.issues.push(issue(_iss));
|
|
2412
|
-
}
|
|
2413
|
-
}
|
|
2414
|
-
const $output = Symbol("ZodOutput");
|
|
2415
|
-
const $input = Symbol("ZodInput");
|
|
2416
|
-
var $ZodRegistry = class {
|
|
2417
|
-
constructor() {
|
|
2418
|
-
this._map = /* @__PURE__ */ new Map();
|
|
2419
|
-
this._idmap = /* @__PURE__ */ new Map();
|
|
2420
|
-
}
|
|
2421
|
-
add(schema, ..._meta) {
|
|
2422
|
-
const meta = _meta[0];
|
|
2423
|
-
this._map.set(schema, meta);
|
|
2424
|
-
if (meta && typeof meta === "object" && "id" in meta) {
|
|
2425
|
-
if (this._idmap.has(meta.id)) throw new Error(`ID ${meta.id} already exists in the registry`);
|
|
2426
|
-
this._idmap.set(meta.id, schema);
|
|
2427
|
-
}
|
|
2428
|
-
return this;
|
|
2429
|
-
}
|
|
2430
|
-
clear() {
|
|
2431
|
-
this._map = /* @__PURE__ */ new Map();
|
|
2432
|
-
this._idmap = /* @__PURE__ */ new Map();
|
|
2433
|
-
return this;
|
|
2434
|
-
}
|
|
2435
|
-
remove(schema) {
|
|
2436
|
-
const meta = this._map.get(schema);
|
|
2437
|
-
if (meta && typeof meta === "object" && "id" in meta) this._idmap.delete(meta.id);
|
|
2438
|
-
this._map.delete(schema);
|
|
2439
|
-
return this;
|
|
2440
|
-
}
|
|
2441
|
-
get(schema) {
|
|
2442
|
-
const p$1 = schema._zod.parent;
|
|
2443
|
-
if (p$1) {
|
|
2444
|
-
const pm = { ...this.get(p$1) ?? {} };
|
|
2445
|
-
delete pm.id;
|
|
2446
|
-
const f$1 = {
|
|
2447
|
-
...pm,
|
|
2448
|
-
...this._map.get(schema)
|
|
2449
|
-
};
|
|
2450
|
-
return Object.keys(f$1).length ? f$1 : void 0;
|
|
2451
|
-
}
|
|
2452
|
-
return this._map.get(schema);
|
|
2453
|
-
}
|
|
2454
|
-
has(schema) {
|
|
2455
|
-
return this._map.has(schema);
|
|
2456
|
-
}
|
|
2457
|
-
};
|
|
2458
|
-
function registry() {
|
|
2459
|
-
return new $ZodRegistry();
|
|
2460
|
-
}
|
|
2461
|
-
const globalRegistry = /* @__PURE__ */ registry();
|
|
2462
|
-
function _string(Class, params) {
|
|
2463
|
-
return new Class({
|
|
2464
|
-
type: "string",
|
|
2465
|
-
...normalizeParams(params)
|
|
2466
|
-
});
|
|
2467
|
-
}
|
|
2468
|
-
function _email(Class, params) {
|
|
2469
|
-
return new Class({
|
|
2470
|
-
type: "string",
|
|
2471
|
-
format: "email",
|
|
2472
|
-
check: "string_format",
|
|
2473
|
-
abort: false,
|
|
2474
|
-
...normalizeParams(params)
|
|
2475
|
-
});
|
|
2476
|
-
}
|
|
2477
|
-
function _guid(Class, params) {
|
|
2478
|
-
return new Class({
|
|
2479
|
-
type: "string",
|
|
2480
|
-
format: "guid",
|
|
2481
|
-
check: "string_format",
|
|
2482
|
-
abort: false,
|
|
2483
|
-
...normalizeParams(params)
|
|
2484
|
-
});
|
|
2485
|
-
}
|
|
2486
|
-
function _uuid(Class, params) {
|
|
2487
|
-
return new Class({
|
|
2488
|
-
type: "string",
|
|
2489
|
-
format: "uuid",
|
|
2490
|
-
check: "string_format",
|
|
2491
|
-
abort: false,
|
|
2492
|
-
...normalizeParams(params)
|
|
2493
|
-
});
|
|
2494
|
-
}
|
|
2495
|
-
function _uuidv4(Class, params) {
|
|
2496
|
-
return new Class({
|
|
2497
|
-
type: "string",
|
|
2498
|
-
format: "uuid",
|
|
2499
|
-
check: "string_format",
|
|
2500
|
-
abort: false,
|
|
2501
|
-
version: "v4",
|
|
2502
|
-
...normalizeParams(params)
|
|
2503
|
-
});
|
|
2504
|
-
}
|
|
2505
|
-
function _uuidv6(Class, params) {
|
|
2506
|
-
return new Class({
|
|
2507
|
-
type: "string",
|
|
2508
|
-
format: "uuid",
|
|
2509
|
-
check: "string_format",
|
|
2510
|
-
abort: false,
|
|
2511
|
-
version: "v6",
|
|
2512
|
-
...normalizeParams(params)
|
|
2513
|
-
});
|
|
2514
|
-
}
|
|
2515
|
-
function _uuidv7(Class, params) {
|
|
2516
|
-
return new Class({
|
|
2517
|
-
type: "string",
|
|
2518
|
-
format: "uuid",
|
|
2519
|
-
check: "string_format",
|
|
2520
|
-
abort: false,
|
|
2521
|
-
version: "v7",
|
|
2522
|
-
...normalizeParams(params)
|
|
2523
|
-
});
|
|
2524
|
-
}
|
|
2525
|
-
function _url(Class, params) {
|
|
2526
|
-
return new Class({
|
|
2527
|
-
type: "string",
|
|
2528
|
-
format: "url",
|
|
2529
|
-
check: "string_format",
|
|
2530
|
-
abort: false,
|
|
2531
|
-
...normalizeParams(params)
|
|
2532
|
-
});
|
|
2533
|
-
}
|
|
2534
|
-
function _emoji(Class, params) {
|
|
2535
|
-
return new Class({
|
|
2536
|
-
type: "string",
|
|
2537
|
-
format: "emoji",
|
|
2538
|
-
check: "string_format",
|
|
2539
|
-
abort: false,
|
|
2540
|
-
...normalizeParams(params)
|
|
2541
|
-
});
|
|
2542
|
-
}
|
|
2543
|
-
function _nanoid(Class, params) {
|
|
2544
|
-
return new Class({
|
|
2545
|
-
type: "string",
|
|
2546
|
-
format: "nanoid",
|
|
2547
|
-
check: "string_format",
|
|
2548
|
-
abort: false,
|
|
2549
|
-
...normalizeParams(params)
|
|
2550
|
-
});
|
|
2551
|
-
}
|
|
2552
|
-
function _cuid(Class, params) {
|
|
2553
|
-
return new Class({
|
|
2554
|
-
type: "string",
|
|
2555
|
-
format: "cuid",
|
|
2556
|
-
check: "string_format",
|
|
2557
|
-
abort: false,
|
|
2558
|
-
...normalizeParams(params)
|
|
2559
|
-
});
|
|
2560
|
-
}
|
|
2561
|
-
function _cuid2(Class, params) {
|
|
2562
|
-
return new Class({
|
|
2563
|
-
type: "string",
|
|
2564
|
-
format: "cuid2",
|
|
2565
|
-
check: "string_format",
|
|
2566
|
-
abort: false,
|
|
2567
|
-
...normalizeParams(params)
|
|
2568
|
-
});
|
|
2569
|
-
}
|
|
2570
|
-
function _ulid(Class, params) {
|
|
2571
|
-
return new Class({
|
|
2572
|
-
type: "string",
|
|
2573
|
-
format: "ulid",
|
|
2574
|
-
check: "string_format",
|
|
2575
|
-
abort: false,
|
|
2576
|
-
...normalizeParams(params)
|
|
2577
|
-
});
|
|
2578
|
-
}
|
|
2579
|
-
function _xid(Class, params) {
|
|
2580
|
-
return new Class({
|
|
2581
|
-
type: "string",
|
|
2582
|
-
format: "xid",
|
|
2583
|
-
check: "string_format",
|
|
2584
|
-
abort: false,
|
|
2585
|
-
...normalizeParams(params)
|
|
2586
|
-
});
|
|
2587
|
-
}
|
|
2588
|
-
function _ksuid(Class, params) {
|
|
2589
|
-
return new Class({
|
|
2590
|
-
type: "string",
|
|
2591
|
-
format: "ksuid",
|
|
2592
|
-
check: "string_format",
|
|
2593
|
-
abort: false,
|
|
2594
|
-
...normalizeParams(params)
|
|
2595
|
-
});
|
|
2596
|
-
}
|
|
2597
|
-
function _ipv4(Class, params) {
|
|
2598
|
-
return new Class({
|
|
2599
|
-
type: "string",
|
|
2600
|
-
format: "ipv4",
|
|
2601
|
-
check: "string_format",
|
|
2602
|
-
abort: false,
|
|
2603
|
-
...normalizeParams(params)
|
|
2604
|
-
});
|
|
2605
|
-
}
|
|
2606
|
-
function _ipv6(Class, params) {
|
|
2607
|
-
return new Class({
|
|
2608
|
-
type: "string",
|
|
2609
|
-
format: "ipv6",
|
|
2610
|
-
check: "string_format",
|
|
2611
|
-
abort: false,
|
|
2612
|
-
...normalizeParams(params)
|
|
2613
|
-
});
|
|
2614
|
-
}
|
|
2615
|
-
function _cidrv4(Class, params) {
|
|
2616
|
-
return new Class({
|
|
2617
|
-
type: "string",
|
|
2618
|
-
format: "cidrv4",
|
|
2619
|
-
check: "string_format",
|
|
2620
|
-
abort: false,
|
|
2621
|
-
...normalizeParams(params)
|
|
2622
|
-
});
|
|
2623
|
-
}
|
|
2624
|
-
function _cidrv6(Class, params) {
|
|
2625
|
-
return new Class({
|
|
2626
|
-
type: "string",
|
|
2627
|
-
format: "cidrv6",
|
|
2628
|
-
check: "string_format",
|
|
2629
|
-
abort: false,
|
|
2630
|
-
...normalizeParams(params)
|
|
2631
|
-
});
|
|
2632
|
-
}
|
|
2633
|
-
function _base64(Class, params) {
|
|
2634
|
-
return new Class({
|
|
2635
|
-
type: "string",
|
|
2636
|
-
format: "base64",
|
|
2637
|
-
check: "string_format",
|
|
2638
|
-
abort: false,
|
|
2639
|
-
...normalizeParams(params)
|
|
2640
|
-
});
|
|
2641
|
-
}
|
|
2642
|
-
function _base64url(Class, params) {
|
|
2643
|
-
return new Class({
|
|
2644
|
-
type: "string",
|
|
2645
|
-
format: "base64url",
|
|
2646
|
-
check: "string_format",
|
|
2647
|
-
abort: false,
|
|
2648
|
-
...normalizeParams(params)
|
|
2649
|
-
});
|
|
2650
|
-
}
|
|
2651
|
-
function _e164(Class, params) {
|
|
2652
|
-
return new Class({
|
|
2653
|
-
type: "string",
|
|
2654
|
-
format: "e164",
|
|
2655
|
-
check: "string_format",
|
|
2656
|
-
abort: false,
|
|
2657
|
-
...normalizeParams(params)
|
|
2658
|
-
});
|
|
2659
|
-
}
|
|
2660
|
-
function _jwt(Class, params) {
|
|
2661
|
-
return new Class({
|
|
2662
|
-
type: "string",
|
|
2663
|
-
format: "jwt",
|
|
2664
|
-
check: "string_format",
|
|
2665
|
-
abort: false,
|
|
2666
|
-
...normalizeParams(params)
|
|
2667
|
-
});
|
|
2668
|
-
}
|
|
2669
|
-
function _isoDateTime(Class, params) {
|
|
2670
|
-
return new Class({
|
|
2671
|
-
type: "string",
|
|
2672
|
-
format: "datetime",
|
|
2673
|
-
check: "string_format",
|
|
2674
|
-
offset: false,
|
|
2675
|
-
local: false,
|
|
2676
|
-
precision: null,
|
|
2677
|
-
...normalizeParams(params)
|
|
1212
|
+
inst,
|
|
1213
|
+
errors: results.map((result) => result.issues.map((iss) => finalizeIssue(iss, ctx, config())))
|
|
2678
1214
|
});
|
|
1215
|
+
return final;
|
|
2679
1216
|
}
|
|
2680
|
-
|
|
2681
|
-
|
|
2682
|
-
|
|
2683
|
-
|
|
2684
|
-
|
|
2685
|
-
|
|
1217
|
+
const $ZodUnion = /* @__PURE__ */ $constructor("$ZodUnion", (inst, def) => {
|
|
1218
|
+
$ZodType.init(inst, def);
|
|
1219
|
+
defineLazy(inst._zod, "optin", () => def.options.some((o$1) => o$1._zod.optin === "optional") ? "optional" : void 0);
|
|
1220
|
+
defineLazy(inst._zod, "optout", () => def.options.some((o$1) => o$1._zod.optout === "optional") ? "optional" : void 0);
|
|
1221
|
+
defineLazy(inst._zod, "values", () => {
|
|
1222
|
+
if (def.options.every((o$1) => o$1._zod.values)) return new Set(def.options.flatMap((option) => Array.from(option._zod.values)));
|
|
2686
1223
|
});
|
|
2687
|
-
|
|
2688
|
-
|
|
2689
|
-
|
|
2690
|
-
|
|
2691
|
-
|
|
2692
|
-
check: "string_format",
|
|
2693
|
-
precision: null,
|
|
2694
|
-
...normalizeParams(params)
|
|
1224
|
+
defineLazy(inst._zod, "pattern", () => {
|
|
1225
|
+
if (def.options.every((o$1) => o$1._zod.pattern)) {
|
|
1226
|
+
const patterns = def.options.map((o$1) => o$1._zod.pattern);
|
|
1227
|
+
return /* @__PURE__ */ new RegExp(`^(${patterns.map((p$1) => cleanRegex(p$1.source)).join("|")})$`);
|
|
1228
|
+
}
|
|
2695
1229
|
});
|
|
1230
|
+
const single = def.options.length === 1;
|
|
1231
|
+
const first = def.options[0]._zod.run;
|
|
1232
|
+
inst._zod.parse = (payload, ctx) => {
|
|
1233
|
+
if (single) return first(payload, ctx);
|
|
1234
|
+
let async = false;
|
|
1235
|
+
const results = [];
|
|
1236
|
+
for (const option of def.options) {
|
|
1237
|
+
const result = option._zod.run({
|
|
1238
|
+
value: payload.value,
|
|
1239
|
+
issues: []
|
|
1240
|
+
}, ctx);
|
|
1241
|
+
if (result instanceof Promise) {
|
|
1242
|
+
results.push(result);
|
|
1243
|
+
async = true;
|
|
1244
|
+
} else {
|
|
1245
|
+
if (result.issues.length === 0) return result;
|
|
1246
|
+
results.push(result);
|
|
1247
|
+
}
|
|
1248
|
+
}
|
|
1249
|
+
if (!async) return handleUnionResults(results, payload, inst, ctx);
|
|
1250
|
+
return Promise.all(results).then((results$1) => {
|
|
1251
|
+
return handleUnionResults(results$1, payload, inst, ctx);
|
|
1252
|
+
});
|
|
1253
|
+
};
|
|
1254
|
+
});
|
|
1255
|
+
function handleOptionalResult(result, input) {
|
|
1256
|
+
if (result.issues.length && input === void 0) return {
|
|
1257
|
+
issues: [],
|
|
1258
|
+
value: void 0
|
|
1259
|
+
};
|
|
1260
|
+
return result;
|
|
2696
1261
|
}
|
|
2697
|
-
|
|
1262
|
+
const $ZodOptional = /* @__PURE__ */ $constructor("$ZodOptional", (inst, def) => {
|
|
1263
|
+
$ZodType.init(inst, def);
|
|
1264
|
+
inst._zod.optin = "optional";
|
|
1265
|
+
inst._zod.optout = "optional";
|
|
1266
|
+
defineLazy(inst._zod, "values", () => {
|
|
1267
|
+
return def.innerType._zod.values ? new Set([...def.innerType._zod.values, void 0]) : void 0;
|
|
1268
|
+
});
|
|
1269
|
+
defineLazy(inst._zod, "pattern", () => {
|
|
1270
|
+
const pattern = def.innerType._zod.pattern;
|
|
1271
|
+
return pattern ? /* @__PURE__ */ new RegExp(`^(${cleanRegex(pattern.source)})?$`) : void 0;
|
|
1272
|
+
});
|
|
1273
|
+
inst._zod.parse = (payload, ctx) => {
|
|
1274
|
+
if (def.innerType._zod.optin === "optional") {
|
|
1275
|
+
const result = def.innerType._zod.run(payload, ctx);
|
|
1276
|
+
if (result instanceof Promise) return result.then((r$1) => handleOptionalResult(r$1, payload.value));
|
|
1277
|
+
return handleOptionalResult(result, payload.value);
|
|
1278
|
+
}
|
|
1279
|
+
if (payload.value === void 0) return payload;
|
|
1280
|
+
return def.innerType._zod.run(payload, ctx);
|
|
1281
|
+
};
|
|
1282
|
+
});
|
|
1283
|
+
function _string(Class, params) {
|
|
2698
1284
|
return new Class({
|
|
2699
1285
|
type: "string",
|
|
2700
|
-
format: "duration",
|
|
2701
|
-
check: "string_format",
|
|
2702
1286
|
...normalizeParams(params)
|
|
2703
1287
|
});
|
|
2704
1288
|
}
|
|
2705
1289
|
function _any(Class) {
|
|
2706
1290
|
return new Class({ type: "any" });
|
|
2707
1291
|
}
|
|
2708
|
-
|
|
2709
|
-
|
|
2710
|
-
}
|
|
2711
|
-
function _never(Class, params) {
|
|
2712
|
-
return new Class({
|
|
2713
|
-
type: "never",
|
|
2714
|
-
...normalizeParams(params)
|
|
2715
|
-
});
|
|
2716
|
-
}
|
|
2717
|
-
function _maxLength(maximum, params) {
|
|
2718
|
-
const ch = new $ZodCheckMaxLength({
|
|
2719
|
-
check: "max_length",
|
|
2720
|
-
...normalizeParams(params),
|
|
2721
|
-
maximum
|
|
2722
|
-
});
|
|
2723
|
-
return ch;
|
|
2724
|
-
}
|
|
2725
|
-
function _minLength(minimum, params) {
|
|
2726
|
-
return new $ZodCheckMinLength({
|
|
2727
|
-
check: "min_length",
|
|
2728
|
-
...normalizeParams(params),
|
|
2729
|
-
minimum
|
|
2730
|
-
});
|
|
2731
|
-
}
|
|
2732
|
-
function _length(length, params) {
|
|
2733
|
-
return new $ZodCheckLengthEquals({
|
|
2734
|
-
check: "length_equals",
|
|
2735
|
-
...normalizeParams(params),
|
|
2736
|
-
length
|
|
2737
|
-
});
|
|
2738
|
-
}
|
|
2739
|
-
function _regex(pattern, params) {
|
|
2740
|
-
return new $ZodCheckRegex({
|
|
2741
|
-
check: "string_format",
|
|
2742
|
-
format: "regex",
|
|
2743
|
-
...normalizeParams(params),
|
|
2744
|
-
pattern
|
|
2745
|
-
});
|
|
2746
|
-
}
|
|
2747
|
-
function _lowercase(params) {
|
|
2748
|
-
return new $ZodCheckLowerCase({
|
|
2749
|
-
check: "string_format",
|
|
2750
|
-
format: "lowercase",
|
|
2751
|
-
...normalizeParams(params)
|
|
2752
|
-
});
|
|
2753
|
-
}
|
|
2754
|
-
function _uppercase(params) {
|
|
2755
|
-
return new $ZodCheckUpperCase({
|
|
2756
|
-
check: "string_format",
|
|
2757
|
-
format: "uppercase",
|
|
2758
|
-
...normalizeParams(params)
|
|
2759
|
-
});
|
|
2760
|
-
}
|
|
2761
|
-
function _includes(includes, params) {
|
|
2762
|
-
return new $ZodCheckIncludes({
|
|
2763
|
-
check: "string_format",
|
|
2764
|
-
format: "includes",
|
|
2765
|
-
...normalizeParams(params),
|
|
2766
|
-
includes
|
|
2767
|
-
});
|
|
2768
|
-
}
|
|
2769
|
-
function _startsWith(prefix, params) {
|
|
2770
|
-
return new $ZodCheckStartsWith({
|
|
2771
|
-
check: "string_format",
|
|
2772
|
-
format: "starts_with",
|
|
2773
|
-
...normalizeParams(params),
|
|
2774
|
-
prefix
|
|
2775
|
-
});
|
|
2776
|
-
}
|
|
2777
|
-
function _endsWith(suffix, params) {
|
|
2778
|
-
return new $ZodCheckEndsWith({
|
|
2779
|
-
check: "string_format",
|
|
2780
|
-
format: "ends_with",
|
|
2781
|
-
...normalizeParams(params),
|
|
2782
|
-
suffix
|
|
2783
|
-
});
|
|
2784
|
-
}
|
|
2785
|
-
function _overwrite(tx) {
|
|
2786
|
-
return new $ZodCheckOverwrite({
|
|
2787
|
-
check: "overwrite",
|
|
2788
|
-
tx
|
|
2789
|
-
});
|
|
2790
|
-
}
|
|
2791
|
-
function _normalize(form) {
|
|
2792
|
-
return _overwrite((input) => input.normalize(form));
|
|
2793
|
-
}
|
|
2794
|
-
function _trim() {
|
|
2795
|
-
return _overwrite((input) => input.trim());
|
|
2796
|
-
}
|
|
2797
|
-
function _toLowerCase() {
|
|
2798
|
-
return _overwrite((input) => input.toLowerCase());
|
|
2799
|
-
}
|
|
2800
|
-
function _toUpperCase() {
|
|
2801
|
-
return _overwrite((input) => input.toUpperCase());
|
|
2802
|
-
}
|
|
2803
|
-
function _array(Class, element, params) {
|
|
2804
|
-
return new Class({
|
|
2805
|
-
type: "array",
|
|
2806
|
-
element,
|
|
2807
|
-
...normalizeParams(params)
|
|
2808
|
-
});
|
|
2809
|
-
}
|
|
2810
|
-
function _refine(Class, fn, _params) {
|
|
2811
|
-
const schema = new Class({
|
|
2812
|
-
type: "custom",
|
|
2813
|
-
check: "custom",
|
|
2814
|
-
fn,
|
|
2815
|
-
...normalizeParams(_params)
|
|
2816
|
-
});
|
|
2817
|
-
return schema;
|
|
2818
|
-
}
|
|
2819
|
-
const ZodISODateTime = /* @__PURE__ */ $constructor("ZodISODateTime", (inst, def) => {
|
|
2820
|
-
$ZodISODateTime.init(inst, def);
|
|
2821
|
-
ZodStringFormat.init(inst, def);
|
|
2822
|
-
});
|
|
2823
|
-
function datetime(params) {
|
|
2824
|
-
return _isoDateTime(ZodISODateTime, params);
|
|
2825
|
-
}
|
|
2826
|
-
const ZodISODate = /* @__PURE__ */ $constructor("ZodISODate", (inst, def) => {
|
|
2827
|
-
$ZodISODate.init(inst, def);
|
|
2828
|
-
ZodStringFormat.init(inst, def);
|
|
2829
|
-
});
|
|
2830
|
-
function date(params) {
|
|
2831
|
-
return _isoDate(ZodISODate, params);
|
|
2832
|
-
}
|
|
2833
|
-
const ZodISOTime = /* @__PURE__ */ $constructor("ZodISOTime", (inst, def) => {
|
|
2834
|
-
$ZodISOTime.init(inst, def);
|
|
2835
|
-
ZodStringFormat.init(inst, def);
|
|
2836
|
-
});
|
|
2837
|
-
function time(params) {
|
|
2838
|
-
return _isoTime(ZodISOTime, params);
|
|
2839
|
-
}
|
|
2840
|
-
const ZodISODuration = /* @__PURE__ */ $constructor("ZodISODuration", (inst, def) => {
|
|
2841
|
-
$ZodISODuration.init(inst, def);
|
|
2842
|
-
ZodStringFormat.init(inst, def);
|
|
2843
|
-
});
|
|
2844
|
-
function duration(params) {
|
|
2845
|
-
return _isoDuration(ZodISODuration, params);
|
|
2846
|
-
}
|
|
2847
|
-
const initializer = (inst, issues) => {
|
|
2848
|
-
$ZodError.init(inst, issues);
|
|
2849
|
-
inst.name = "ZodError";
|
|
2850
|
-
Object.defineProperties(inst, {
|
|
2851
|
-
format: { value: (mapper) => formatError(inst, mapper) },
|
|
2852
|
-
flatten: { value: (mapper) => flattenError(inst, mapper) },
|
|
2853
|
-
addIssue: { value: (issue$1) => {
|
|
2854
|
-
inst.issues.push(issue$1);
|
|
2855
|
-
inst.message = JSON.stringify(inst.issues, jsonStringifyReplacer, 2);
|
|
2856
|
-
} },
|
|
2857
|
-
addIssues: { value: (issues$1) => {
|
|
2858
|
-
inst.issues.push(...issues$1);
|
|
2859
|
-
inst.message = JSON.stringify(inst.issues, jsonStringifyReplacer, 2);
|
|
2860
|
-
} },
|
|
2861
|
-
isEmpty: { get() {
|
|
2862
|
-
return inst.issues.length === 0;
|
|
2863
|
-
} }
|
|
2864
|
-
});
|
|
2865
|
-
};
|
|
2866
|
-
const ZodError = $constructor("ZodError", initializer);
|
|
2867
|
-
const ZodRealError = $constructor("ZodError", initializer, { Parent: Error });
|
|
2868
|
-
const parse = /* @__PURE__ */ _parse(ZodRealError);
|
|
2869
|
-
const parseAsync = /* @__PURE__ */ _parseAsync(ZodRealError);
|
|
2870
|
-
const safeParse = /* @__PURE__ */ _safeParse(ZodRealError);
|
|
2871
|
-
const safeParseAsync = /* @__PURE__ */ _safeParseAsync(ZodRealError);
|
|
2872
|
-
const ZodType = /* @__PURE__ */ $constructor("ZodType", (inst, def) => {
|
|
1292
|
+
const ZodMiniType = /* @__PURE__ */ $constructor("ZodMiniType", (inst, def) => {
|
|
1293
|
+
if (!inst._zod) throw new Error("Uninitialized schema in ZodMiniType.");
|
|
2873
1294
|
$ZodType.init(inst, def);
|
|
2874
1295
|
inst.def = def;
|
|
2875
|
-
|
|
1296
|
+
inst.type = def.type;
|
|
1297
|
+
inst.parse = (data, params) => parse(inst, data, params, { callee: inst.parse });
|
|
1298
|
+
inst.safeParse = (data, params) => safeParse(inst, data, params);
|
|
1299
|
+
inst.parseAsync = async (data, params) => parseAsync(inst, data, params, { callee: inst.parseAsync });
|
|
1300
|
+
inst.safeParseAsync = async (data, params) => safeParseAsync(inst, data, params);
|
|
2876
1301
|
inst.check = (...checks) => {
|
|
2877
1302
|
return inst.clone({
|
|
2878
1303
|
...def,
|
|
@@ -2883,257 +1308,42 @@ const ZodType = /* @__PURE__ */ $constructor("ZodType", (inst, def) => {
|
|
|
2883
1308
|
} } : ch)]
|
|
2884
1309
|
});
|
|
2885
1310
|
};
|
|
2886
|
-
inst.clone = (
|
|
1311
|
+
inst.clone = (_def, params) => clone(inst, _def, params);
|
|
2887
1312
|
inst.brand = () => inst;
|
|
2888
1313
|
inst.register = ((reg, meta) => {
|
|
2889
1314
|
reg.add(inst, meta);
|
|
2890
1315
|
return inst;
|
|
2891
1316
|
});
|
|
2892
|
-
inst.parse = (data, params) => parse(inst, data, params, { callee: inst.parse });
|
|
2893
|
-
inst.safeParse = (data, params) => safeParse(inst, data, params);
|
|
2894
|
-
inst.parseAsync = async (data, params) => parseAsync(inst, data, params, { callee: inst.parseAsync });
|
|
2895
|
-
inst.safeParseAsync = async (data, params) => safeParseAsync(inst, data, params);
|
|
2896
|
-
inst.spa = inst.safeParseAsync;
|
|
2897
|
-
inst.refine = (check$1, params) => inst.check(refine(check$1, params));
|
|
2898
|
-
inst.superRefine = (refinement) => inst.check(superRefine(refinement));
|
|
2899
|
-
inst.overwrite = (fn) => inst.check(_overwrite(fn));
|
|
2900
|
-
inst.optional = () => optional(inst);
|
|
2901
|
-
inst.nullable = () => nullable(inst);
|
|
2902
|
-
inst.nullish = () => optional(nullable(inst));
|
|
2903
|
-
inst.nonoptional = (params) => nonoptional(inst, params);
|
|
2904
|
-
inst.array = () => array(inst);
|
|
2905
|
-
inst.or = (arg) => union([inst, arg]);
|
|
2906
|
-
inst.and = (arg) => intersection(inst, arg);
|
|
2907
|
-
inst.transform = (tx) => pipe(inst, transform(tx));
|
|
2908
|
-
inst.default = (def$1) => _default(inst, def$1);
|
|
2909
|
-
inst.prefault = (def$1) => prefault(inst, def$1);
|
|
2910
|
-
inst.catch = (params) => _catch(inst, params);
|
|
2911
|
-
inst.pipe = (target) => pipe(inst, target);
|
|
2912
|
-
inst.readonly = () => readonly(inst);
|
|
2913
|
-
inst.describe = (description) => {
|
|
2914
|
-
const cl = inst.clone();
|
|
2915
|
-
globalRegistry.add(cl, { description });
|
|
2916
|
-
return cl;
|
|
2917
|
-
};
|
|
2918
|
-
Object.defineProperty(inst, "description", {
|
|
2919
|
-
get() {
|
|
2920
|
-
return globalRegistry.get(inst)?.description;
|
|
2921
|
-
},
|
|
2922
|
-
configurable: true
|
|
2923
|
-
});
|
|
2924
|
-
inst.meta = (...args) => {
|
|
2925
|
-
if (args.length === 0) return globalRegistry.get(inst);
|
|
2926
|
-
const cl = inst.clone();
|
|
2927
|
-
globalRegistry.add(cl, args[0]);
|
|
2928
|
-
return cl;
|
|
2929
|
-
};
|
|
2930
|
-
inst.isOptional = () => inst.safeParse(void 0).success;
|
|
2931
|
-
inst.isNullable = () => inst.safeParse(null).success;
|
|
2932
|
-
return inst;
|
|
2933
|
-
});
|
|
2934
|
-
const _ZodString = /* @__PURE__ */ $constructor("_ZodString", (inst, def) => {
|
|
2935
|
-
$ZodString.init(inst, def);
|
|
2936
|
-
ZodType.init(inst, def);
|
|
2937
|
-
const bag = inst._zod.bag;
|
|
2938
|
-
inst.format = bag.format ?? null;
|
|
2939
|
-
inst.minLength = bag.minimum ?? null;
|
|
2940
|
-
inst.maxLength = bag.maximum ?? null;
|
|
2941
|
-
inst.regex = (...args) => inst.check(_regex(...args));
|
|
2942
|
-
inst.includes = (...args) => inst.check(_includes(...args));
|
|
2943
|
-
inst.startsWith = (...args) => inst.check(_startsWith(...args));
|
|
2944
|
-
inst.endsWith = (...args) => inst.check(_endsWith(...args));
|
|
2945
|
-
inst.min = (...args) => inst.check(_minLength(...args));
|
|
2946
|
-
inst.max = (...args) => inst.check(_maxLength(...args));
|
|
2947
|
-
inst.length = (...args) => inst.check(_length(...args));
|
|
2948
|
-
inst.nonempty = (...args) => inst.check(_minLength(1, ...args));
|
|
2949
|
-
inst.lowercase = (params) => inst.check(_lowercase(params));
|
|
2950
|
-
inst.uppercase = (params) => inst.check(_uppercase(params));
|
|
2951
|
-
inst.trim = () => inst.check(_trim());
|
|
2952
|
-
inst.normalize = (...args) => inst.check(_normalize(...args));
|
|
2953
|
-
inst.toLowerCase = () => inst.check(_toLowerCase());
|
|
2954
|
-
inst.toUpperCase = () => inst.check(_toUpperCase());
|
|
2955
1317
|
});
|
|
2956
|
-
const
|
|
1318
|
+
const ZodMiniString = /* @__PURE__ */ $constructor("ZodMiniString", (inst, def) => {
|
|
2957
1319
|
$ZodString.init(inst, def);
|
|
2958
|
-
|
|
2959
|
-
inst.email = (params) => inst.check(_email(ZodEmail, params));
|
|
2960
|
-
inst.url = (params) => inst.check(_url(ZodURL, params));
|
|
2961
|
-
inst.jwt = (params) => inst.check(_jwt(ZodJWT, params));
|
|
2962
|
-
inst.emoji = (params) => inst.check(_emoji(ZodEmoji, params));
|
|
2963
|
-
inst.guid = (params) => inst.check(_guid(ZodGUID, params));
|
|
2964
|
-
inst.uuid = (params) => inst.check(_uuid(ZodUUID, params));
|
|
2965
|
-
inst.uuidv4 = (params) => inst.check(_uuidv4(ZodUUID, params));
|
|
2966
|
-
inst.uuidv6 = (params) => inst.check(_uuidv6(ZodUUID, params));
|
|
2967
|
-
inst.uuidv7 = (params) => inst.check(_uuidv7(ZodUUID, params));
|
|
2968
|
-
inst.nanoid = (params) => inst.check(_nanoid(ZodNanoID, params));
|
|
2969
|
-
inst.guid = (params) => inst.check(_guid(ZodGUID, params));
|
|
2970
|
-
inst.cuid = (params) => inst.check(_cuid(ZodCUID, params));
|
|
2971
|
-
inst.cuid2 = (params) => inst.check(_cuid2(ZodCUID2, params));
|
|
2972
|
-
inst.ulid = (params) => inst.check(_ulid(ZodULID, params));
|
|
2973
|
-
inst.base64 = (params) => inst.check(_base64(ZodBase64, params));
|
|
2974
|
-
inst.base64url = (params) => inst.check(_base64url(ZodBase64URL, params));
|
|
2975
|
-
inst.xid = (params) => inst.check(_xid(ZodXID, params));
|
|
2976
|
-
inst.ksuid = (params) => inst.check(_ksuid(ZodKSUID, params));
|
|
2977
|
-
inst.ipv4 = (params) => inst.check(_ipv4(ZodIPv4, params));
|
|
2978
|
-
inst.ipv6 = (params) => inst.check(_ipv6(ZodIPv6, params));
|
|
2979
|
-
inst.cidrv4 = (params) => inst.check(_cidrv4(ZodCIDRv4, params));
|
|
2980
|
-
inst.cidrv6 = (params) => inst.check(_cidrv6(ZodCIDRv6, params));
|
|
2981
|
-
inst.e164 = (params) => inst.check(_e164(ZodE164, params));
|
|
2982
|
-
inst.datetime = (params) => inst.check(datetime(params));
|
|
2983
|
-
inst.date = (params) => inst.check(date(params));
|
|
2984
|
-
inst.time = (params) => inst.check(time(params));
|
|
2985
|
-
inst.duration = (params) => inst.check(duration(params));
|
|
1320
|
+
ZodMiniType.init(inst, def);
|
|
2986
1321
|
});
|
|
2987
1322
|
function string(params) {
|
|
2988
|
-
return _string(
|
|
1323
|
+
return _string(ZodMiniString, params);
|
|
2989
1324
|
}
|
|
2990
|
-
const
|
|
2991
|
-
$ZodStringFormat.init(inst, def);
|
|
2992
|
-
_ZodString.init(inst, def);
|
|
2993
|
-
});
|
|
2994
|
-
const ZodEmail = /* @__PURE__ */ $constructor("ZodEmail", (inst, def) => {
|
|
2995
|
-
$ZodEmail.init(inst, def);
|
|
2996
|
-
ZodStringFormat.init(inst, def);
|
|
2997
|
-
});
|
|
2998
|
-
const ZodGUID = /* @__PURE__ */ $constructor("ZodGUID", (inst, def) => {
|
|
2999
|
-
$ZodGUID.init(inst, def);
|
|
3000
|
-
ZodStringFormat.init(inst, def);
|
|
3001
|
-
});
|
|
3002
|
-
const ZodUUID = /* @__PURE__ */ $constructor("ZodUUID", (inst, def) => {
|
|
3003
|
-
$ZodUUID.init(inst, def);
|
|
3004
|
-
ZodStringFormat.init(inst, def);
|
|
3005
|
-
});
|
|
3006
|
-
const ZodURL = /* @__PURE__ */ $constructor("ZodURL", (inst, def) => {
|
|
3007
|
-
$ZodURL.init(inst, def);
|
|
3008
|
-
ZodStringFormat.init(inst, def);
|
|
3009
|
-
});
|
|
3010
|
-
const ZodEmoji = /* @__PURE__ */ $constructor("ZodEmoji", (inst, def) => {
|
|
3011
|
-
$ZodEmoji.init(inst, def);
|
|
3012
|
-
ZodStringFormat.init(inst, def);
|
|
3013
|
-
});
|
|
3014
|
-
const ZodNanoID = /* @__PURE__ */ $constructor("ZodNanoID", (inst, def) => {
|
|
3015
|
-
$ZodNanoID.init(inst, def);
|
|
3016
|
-
ZodStringFormat.init(inst, def);
|
|
3017
|
-
});
|
|
3018
|
-
const ZodCUID = /* @__PURE__ */ $constructor("ZodCUID", (inst, def) => {
|
|
3019
|
-
$ZodCUID.init(inst, def);
|
|
3020
|
-
ZodStringFormat.init(inst, def);
|
|
3021
|
-
});
|
|
3022
|
-
const ZodCUID2 = /* @__PURE__ */ $constructor("ZodCUID2", (inst, def) => {
|
|
3023
|
-
$ZodCUID2.init(inst, def);
|
|
3024
|
-
ZodStringFormat.init(inst, def);
|
|
3025
|
-
});
|
|
3026
|
-
const ZodULID = /* @__PURE__ */ $constructor("ZodULID", (inst, def) => {
|
|
3027
|
-
$ZodULID.init(inst, def);
|
|
3028
|
-
ZodStringFormat.init(inst, def);
|
|
3029
|
-
});
|
|
3030
|
-
const ZodXID = /* @__PURE__ */ $constructor("ZodXID", (inst, def) => {
|
|
3031
|
-
$ZodXID.init(inst, def);
|
|
3032
|
-
ZodStringFormat.init(inst, def);
|
|
3033
|
-
});
|
|
3034
|
-
const ZodKSUID = /* @__PURE__ */ $constructor("ZodKSUID", (inst, def) => {
|
|
3035
|
-
$ZodKSUID.init(inst, def);
|
|
3036
|
-
ZodStringFormat.init(inst, def);
|
|
3037
|
-
});
|
|
3038
|
-
const ZodIPv4 = /* @__PURE__ */ $constructor("ZodIPv4", (inst, def) => {
|
|
3039
|
-
$ZodIPv4.init(inst, def);
|
|
3040
|
-
ZodStringFormat.init(inst, def);
|
|
3041
|
-
});
|
|
3042
|
-
const ZodIPv6 = /* @__PURE__ */ $constructor("ZodIPv6", (inst, def) => {
|
|
3043
|
-
$ZodIPv6.init(inst, def);
|
|
3044
|
-
ZodStringFormat.init(inst, def);
|
|
3045
|
-
});
|
|
3046
|
-
const ZodCIDRv4 = /* @__PURE__ */ $constructor("ZodCIDRv4", (inst, def) => {
|
|
3047
|
-
$ZodCIDRv4.init(inst, def);
|
|
3048
|
-
ZodStringFormat.init(inst, def);
|
|
3049
|
-
});
|
|
3050
|
-
const ZodCIDRv6 = /* @__PURE__ */ $constructor("ZodCIDRv6", (inst, def) => {
|
|
3051
|
-
$ZodCIDRv6.init(inst, def);
|
|
3052
|
-
ZodStringFormat.init(inst, def);
|
|
3053
|
-
});
|
|
3054
|
-
const ZodBase64 = /* @__PURE__ */ $constructor("ZodBase64", (inst, def) => {
|
|
3055
|
-
$ZodBase64.init(inst, def);
|
|
3056
|
-
ZodStringFormat.init(inst, def);
|
|
3057
|
-
});
|
|
3058
|
-
const ZodBase64URL = /* @__PURE__ */ $constructor("ZodBase64URL", (inst, def) => {
|
|
3059
|
-
$ZodBase64URL.init(inst, def);
|
|
3060
|
-
ZodStringFormat.init(inst, def);
|
|
3061
|
-
});
|
|
3062
|
-
const ZodE164 = /* @__PURE__ */ $constructor("ZodE164", (inst, def) => {
|
|
3063
|
-
$ZodE164.init(inst, def);
|
|
3064
|
-
ZodStringFormat.init(inst, def);
|
|
3065
|
-
});
|
|
3066
|
-
const ZodJWT = /* @__PURE__ */ $constructor("ZodJWT", (inst, def) => {
|
|
3067
|
-
$ZodJWT.init(inst, def);
|
|
3068
|
-
ZodStringFormat.init(inst, def);
|
|
3069
|
-
});
|
|
3070
|
-
const ZodAny = /* @__PURE__ */ $constructor("ZodAny", (inst, def) => {
|
|
1325
|
+
const ZodMiniAny = /* @__PURE__ */ $constructor("ZodMiniAny", (inst, def) => {
|
|
3071
1326
|
$ZodAny.init(inst, def);
|
|
3072
|
-
|
|
1327
|
+
ZodMiniType.init(inst, def);
|
|
3073
1328
|
});
|
|
3074
1329
|
function any() {
|
|
3075
|
-
return _any(
|
|
3076
|
-
}
|
|
3077
|
-
const ZodUnknown = /* @__PURE__ */ $constructor("ZodUnknown", (inst, def) => {
|
|
3078
|
-
$ZodUnknown.init(inst, def);
|
|
3079
|
-
ZodType.init(inst, def);
|
|
3080
|
-
});
|
|
3081
|
-
function unknown() {
|
|
3082
|
-
return _unknown(ZodUnknown);
|
|
3083
|
-
}
|
|
3084
|
-
const ZodNever = /* @__PURE__ */ $constructor("ZodNever", (inst, def) => {
|
|
3085
|
-
$ZodNever.init(inst, def);
|
|
3086
|
-
ZodType.init(inst, def);
|
|
3087
|
-
});
|
|
3088
|
-
function never(params) {
|
|
3089
|
-
return _never(ZodNever, params);
|
|
1330
|
+
return _any(ZodMiniAny);
|
|
3090
1331
|
}
|
|
3091
|
-
const
|
|
1332
|
+
const ZodMiniArray = /* @__PURE__ */ $constructor("ZodMiniArray", (inst, def) => {
|
|
3092
1333
|
$ZodArray.init(inst, def);
|
|
3093
|
-
|
|
3094
|
-
inst.element = def.element;
|
|
3095
|
-
inst.min = (minLength, params) => inst.check(_minLength(minLength, params));
|
|
3096
|
-
inst.nonempty = (params) => inst.check(_minLength(1, params));
|
|
3097
|
-
inst.max = (maxLength, params) => inst.check(_maxLength(maxLength, params));
|
|
3098
|
-
inst.length = (len, params) => inst.check(_length(len, params));
|
|
3099
|
-
inst.unwrap = () => inst.element;
|
|
1334
|
+
ZodMiniType.init(inst, def);
|
|
3100
1335
|
});
|
|
3101
1336
|
function array(element, params) {
|
|
3102
|
-
return
|
|
1337
|
+
return new ZodMiniArray({
|
|
1338
|
+
type: "array",
|
|
1339
|
+
element,
|
|
1340
|
+
...normalizeParams(params)
|
|
1341
|
+
});
|
|
3103
1342
|
}
|
|
3104
|
-
const
|
|
1343
|
+
const ZodMiniObject = /* @__PURE__ */ $constructor("ZodMiniObject", (inst, def) => {
|
|
3105
1344
|
$ZodObject.init(inst, def);
|
|
3106
|
-
|
|
1345
|
+
ZodMiniType.init(inst, def);
|
|
3107
1346
|
defineLazy(inst, "shape", () => def.shape);
|
|
3108
|
-
inst.keyof = () => _enum(Object.keys(inst._zod.def.shape));
|
|
3109
|
-
inst.catchall = (catchall) => inst.clone({
|
|
3110
|
-
...inst._zod.def,
|
|
3111
|
-
catchall
|
|
3112
|
-
});
|
|
3113
|
-
inst.passthrough = () => inst.clone({
|
|
3114
|
-
...inst._zod.def,
|
|
3115
|
-
catchall: unknown()
|
|
3116
|
-
});
|
|
3117
|
-
inst.loose = () => inst.clone({
|
|
3118
|
-
...inst._zod.def,
|
|
3119
|
-
catchall: unknown()
|
|
3120
|
-
});
|
|
3121
|
-
inst.strict = () => inst.clone({
|
|
3122
|
-
...inst._zod.def,
|
|
3123
|
-
catchall: never()
|
|
3124
|
-
});
|
|
3125
|
-
inst.strip = () => inst.clone({
|
|
3126
|
-
...inst._zod.def,
|
|
3127
|
-
catchall: void 0
|
|
3128
|
-
});
|
|
3129
|
-
inst.extend = (incoming) => {
|
|
3130
|
-
return extend(inst, incoming);
|
|
3131
|
-
};
|
|
3132
|
-
inst.merge = (other) => merge(inst, other);
|
|
3133
|
-
inst.pick = (mask) => pick(inst, mask);
|
|
3134
|
-
inst.omit = (mask) => omit(inst, mask);
|
|
3135
|
-
inst.partial = (...args) => partial(ZodOptional, inst, args[0]);
|
|
3136
|
-
inst.required = (...args) => required(ZodNonOptional, inst, args[0]);
|
|
3137
1347
|
});
|
|
3138
1348
|
function object(shape, params) {
|
|
3139
1349
|
const def = {
|
|
@@ -3144,248 +1354,138 @@ function object(shape, params) {
|
|
|
3144
1354
|
},
|
|
3145
1355
|
...normalizeParams(params)
|
|
3146
1356
|
};
|
|
3147
|
-
return new
|
|
1357
|
+
return new ZodMiniObject(def);
|
|
3148
1358
|
}
|
|
3149
|
-
const
|
|
1359
|
+
const ZodMiniUnion = /* @__PURE__ */ $constructor("ZodMiniUnion", (inst, def) => {
|
|
3150
1360
|
$ZodUnion.init(inst, def);
|
|
3151
|
-
|
|
3152
|
-
inst.options = def.options;
|
|
1361
|
+
ZodMiniType.init(inst, def);
|
|
3153
1362
|
});
|
|
3154
1363
|
function union(options, params) {
|
|
3155
|
-
return new
|
|
1364
|
+
return new ZodMiniUnion({
|
|
3156
1365
|
type: "union",
|
|
3157
1366
|
options,
|
|
3158
1367
|
...normalizeParams(params)
|
|
3159
1368
|
});
|
|
3160
1369
|
}
|
|
3161
|
-
const
|
|
3162
|
-
$ZodIntersection.init(inst, def);
|
|
3163
|
-
ZodType.init(inst, def);
|
|
3164
|
-
});
|
|
3165
|
-
function intersection(left, right) {
|
|
3166
|
-
return new ZodIntersection({
|
|
3167
|
-
type: "intersection",
|
|
3168
|
-
left,
|
|
3169
|
-
right
|
|
3170
|
-
});
|
|
3171
|
-
}
|
|
3172
|
-
const ZodEnum = /* @__PURE__ */ $constructor("ZodEnum", (inst, def) => {
|
|
3173
|
-
$ZodEnum.init(inst, def);
|
|
3174
|
-
ZodType.init(inst, def);
|
|
3175
|
-
inst.enum = def.entries;
|
|
3176
|
-
inst.options = Object.values(def.entries);
|
|
3177
|
-
const keys = new Set(Object.keys(def.entries));
|
|
3178
|
-
inst.extract = (values, params) => {
|
|
3179
|
-
const newEntries = {};
|
|
3180
|
-
for (const value of values) if (keys.has(value)) newEntries[value] = def.entries[value];
|
|
3181
|
-
else throw new Error(`Key ${value} not found in enum`);
|
|
3182
|
-
return new ZodEnum({
|
|
3183
|
-
...def,
|
|
3184
|
-
checks: [],
|
|
3185
|
-
...normalizeParams(params),
|
|
3186
|
-
entries: newEntries
|
|
3187
|
-
});
|
|
3188
|
-
};
|
|
3189
|
-
inst.exclude = (values, params) => {
|
|
3190
|
-
const newEntries = { ...def.entries };
|
|
3191
|
-
for (const value of values) if (keys.has(value)) delete newEntries[value];
|
|
3192
|
-
else throw new Error(`Key ${value} not found in enum`);
|
|
3193
|
-
return new ZodEnum({
|
|
3194
|
-
...def,
|
|
3195
|
-
checks: [],
|
|
3196
|
-
...normalizeParams(params),
|
|
3197
|
-
entries: newEntries
|
|
3198
|
-
});
|
|
3199
|
-
};
|
|
3200
|
-
});
|
|
3201
|
-
function _enum(values, params) {
|
|
3202
|
-
const entries = Array.isArray(values) ? Object.fromEntries(values.map((v$1) => [v$1, v$1])) : values;
|
|
3203
|
-
return new ZodEnum({
|
|
3204
|
-
type: "enum",
|
|
3205
|
-
entries,
|
|
3206
|
-
...normalizeParams(params)
|
|
3207
|
-
});
|
|
3208
|
-
}
|
|
3209
|
-
const ZodTransform = /* @__PURE__ */ $constructor("ZodTransform", (inst, def) => {
|
|
3210
|
-
$ZodTransform.init(inst, def);
|
|
3211
|
-
ZodType.init(inst, def);
|
|
3212
|
-
inst._zod.parse = (payload, _ctx) => {
|
|
3213
|
-
payload.addIssue = (issue$1) => {
|
|
3214
|
-
if (typeof issue$1 === "string") payload.issues.push(issue(issue$1, payload.value, def));
|
|
3215
|
-
else {
|
|
3216
|
-
const _issue = issue$1;
|
|
3217
|
-
if (_issue.fatal) _issue.continue = false;
|
|
3218
|
-
_issue.code ?? (_issue.code = "custom");
|
|
3219
|
-
_issue.input ?? (_issue.input = payload.value);
|
|
3220
|
-
_issue.inst ?? (_issue.inst = inst);
|
|
3221
|
-
payload.issues.push(issue(_issue));
|
|
3222
|
-
}
|
|
3223
|
-
};
|
|
3224
|
-
const output = def.transform(payload.value, payload);
|
|
3225
|
-
if (output instanceof Promise) return output.then((output$1) => {
|
|
3226
|
-
payload.value = output$1;
|
|
3227
|
-
return payload;
|
|
3228
|
-
});
|
|
3229
|
-
payload.value = output;
|
|
3230
|
-
return payload;
|
|
3231
|
-
};
|
|
3232
|
-
});
|
|
3233
|
-
function transform(fn) {
|
|
3234
|
-
return new ZodTransform({
|
|
3235
|
-
type: "transform",
|
|
3236
|
-
transform: fn
|
|
3237
|
-
});
|
|
3238
|
-
}
|
|
3239
|
-
const ZodOptional = /* @__PURE__ */ $constructor("ZodOptional", (inst, def) => {
|
|
1370
|
+
const ZodMiniOptional = /* @__PURE__ */ $constructor("ZodMiniOptional", (inst, def) => {
|
|
3240
1371
|
$ZodOptional.init(inst, def);
|
|
3241
|
-
|
|
3242
|
-
inst.unwrap = () => inst._zod.def.innerType;
|
|
1372
|
+
ZodMiniType.init(inst, def);
|
|
3243
1373
|
});
|
|
3244
1374
|
function optional(innerType) {
|
|
3245
|
-
return new
|
|
1375
|
+
return new ZodMiniOptional({
|
|
3246
1376
|
type: "optional",
|
|
3247
1377
|
innerType
|
|
3248
1378
|
});
|
|
3249
1379
|
}
|
|
3250
|
-
|
|
3251
|
-
|
|
3252
|
-
|
|
3253
|
-
|
|
3254
|
-
|
|
3255
|
-
|
|
3256
|
-
|
|
3257
|
-
|
|
3258
|
-
|
|
3259
|
-
|
|
3260
|
-
|
|
3261
|
-
const
|
|
3262
|
-
|
|
3263
|
-
|
|
3264
|
-
|
|
3265
|
-
|
|
3266
|
-
|
|
3267
|
-
|
|
3268
|
-
|
|
3269
|
-
|
|
3270
|
-
innerType,
|
|
3271
|
-
get defaultValue() {
|
|
3272
|
-
return typeof defaultValue === "function" ? defaultValue() : defaultValue;
|
|
1380
|
+
let __TYPE_KEY = "__TYPE_KEY__";
|
|
1381
|
+
let __CONTENT_KEY = "__CONTENT_KEY__";
|
|
1382
|
+
let __BLOB_URL_KEY = "__BLOB_URL_KEY__";
|
|
1383
|
+
let __IMAGE_CONTENT_KEY = "__IMAGE_CONTENT_KEY__";
|
|
1384
|
+
let __IMAGE_INLINE_CONTENT_KEY = "__IMAGE_INLINE_CONTENT_KEY__";
|
|
1385
|
+
let __FILE_CONTENT_KEY = "__FILE_CONTENT_KEY__";
|
|
1386
|
+
let __FC_RESPONSE_KEY = "__FC_RESPONSE_KEY__";
|
|
1387
|
+
let sm = [];
|
|
1388
|
+
const KEYS = {
|
|
1389
|
+
get TYPE_KEY() {
|
|
1390
|
+
if (__TYPE_KEY === "__TYPE_KEY__") {
|
|
1391
|
+
const msg = sm.at(-1);
|
|
1392
|
+
for (const key in msg) {
|
|
1393
|
+
if (/^(role|text|grounding|id|isJson|parts|tokenCount)$/.test(key)) continue;
|
|
1394
|
+
const val = msg[key];
|
|
1395
|
+
if (/^(text|image|function_call|file)$/.test(val)) {
|
|
1396
|
+
__TYPE_KEY = key;
|
|
1397
|
+
break;
|
|
1398
|
+
}
|
|
1399
|
+
}
|
|
3273
1400
|
}
|
|
3274
|
-
|
|
3275
|
-
}
|
|
3276
|
-
|
|
3277
|
-
|
|
3278
|
-
|
|
3279
|
-
|
|
3280
|
-
|
|
3281
|
-
|
|
3282
|
-
|
|
3283
|
-
|
|
3284
|
-
|
|
3285
|
-
|
|
3286
|
-
|
|
1401
|
+
return __TYPE_KEY;
|
|
1402
|
+
},
|
|
1403
|
+
get CONTENT_KEY() {
|
|
1404
|
+
if (__CONTENT_KEY === "__CONTENT_KEY__") msgLabel: for (const msg of sm) {
|
|
1405
|
+
const parts = msg.parts;
|
|
1406
|
+
if (Array.isArray(parts) && parts.length > 0) {
|
|
1407
|
+
const part = parts[0];
|
|
1408
|
+
for (const key in part) {
|
|
1409
|
+
const val = part[key];
|
|
1410
|
+
if (Array.isArray(val)) {
|
|
1411
|
+
__CONTENT_KEY = key;
|
|
1412
|
+
break msgLabel;
|
|
1413
|
+
}
|
|
1414
|
+
break;
|
|
1415
|
+
}
|
|
1416
|
+
}
|
|
3287
1417
|
}
|
|
3288
|
-
|
|
3289
|
-
}
|
|
3290
|
-
|
|
3291
|
-
|
|
3292
|
-
|
|
3293
|
-
|
|
3294
|
-
|
|
3295
|
-
|
|
3296
|
-
|
|
3297
|
-
|
|
3298
|
-
|
|
3299
|
-
|
|
3300
|
-
|
|
3301
|
-
}
|
|
3302
|
-
|
|
3303
|
-
|
|
3304
|
-
|
|
3305
|
-
|
|
3306
|
-
|
|
3307
|
-
|
|
3308
|
-
function _catch(innerType, catchValue) {
|
|
3309
|
-
return new ZodCatch({
|
|
3310
|
-
type: "catch",
|
|
3311
|
-
innerType,
|
|
3312
|
-
catchValue: typeof catchValue === "function" ? catchValue : () => catchValue
|
|
3313
|
-
});
|
|
3314
|
-
}
|
|
3315
|
-
const ZodPipe = /* @__PURE__ */ $constructor("ZodPipe", (inst, def) => {
|
|
3316
|
-
$ZodPipe.init(inst, def);
|
|
3317
|
-
ZodType.init(inst, def);
|
|
3318
|
-
inst.in = def.in;
|
|
3319
|
-
inst.out = def.out;
|
|
3320
|
-
});
|
|
3321
|
-
function pipe(in_, out) {
|
|
3322
|
-
return new ZodPipe({
|
|
3323
|
-
type: "pipe",
|
|
3324
|
-
in: in_,
|
|
3325
|
-
out
|
|
3326
|
-
});
|
|
3327
|
-
}
|
|
3328
|
-
const ZodReadonly = /* @__PURE__ */ $constructor("ZodReadonly", (inst, def) => {
|
|
3329
|
-
$ZodReadonly.init(inst, def);
|
|
3330
|
-
ZodType.init(inst, def);
|
|
3331
|
-
inst.unwrap = () => inst._zod.def.innerType;
|
|
3332
|
-
});
|
|
3333
|
-
function readonly(innerType) {
|
|
3334
|
-
return new ZodReadonly({
|
|
3335
|
-
type: "readonly",
|
|
3336
|
-
innerType
|
|
3337
|
-
});
|
|
3338
|
-
}
|
|
3339
|
-
const ZodCustom = /* @__PURE__ */ $constructor("ZodCustom", (inst, def) => {
|
|
3340
|
-
$ZodCustom.init(inst, def);
|
|
3341
|
-
ZodType.init(inst, def);
|
|
3342
|
-
});
|
|
3343
|
-
function check(fn) {
|
|
3344
|
-
const ch = new $ZodCheck({ check: "custom" });
|
|
3345
|
-
ch._zod.check = fn;
|
|
3346
|
-
return ch;
|
|
3347
|
-
}
|
|
3348
|
-
function refine(fn, _params = {}) {
|
|
3349
|
-
return _refine(ZodCustom, fn, _params);
|
|
3350
|
-
}
|
|
3351
|
-
function superRefine(fn) {
|
|
3352
|
-
const ch = check((payload) => {
|
|
3353
|
-
payload.addIssue = (issue$1) => {
|
|
3354
|
-
if (typeof issue$1 === "string") payload.issues.push(issue(issue$1, payload.value, ch._zod.def));
|
|
3355
|
-
else {
|
|
3356
|
-
const _issue = issue$1;
|
|
3357
|
-
if (_issue.fatal) _issue.continue = false;
|
|
3358
|
-
_issue.code ?? (_issue.code = "custom");
|
|
3359
|
-
_issue.input ?? (_issue.input = payload.value);
|
|
3360
|
-
_issue.inst ?? (_issue.inst = ch);
|
|
3361
|
-
_issue.continue ?? (_issue.continue = !ch._zod.def.abort);
|
|
3362
|
-
payload.issues.push(issue(_issue));
|
|
1418
|
+
return __CONTENT_KEY;
|
|
1419
|
+
},
|
|
1420
|
+
get BLOB_URL_KEY() {
|
|
1421
|
+
prepareImageKeys();
|
|
1422
|
+
return __BLOB_URL_KEY;
|
|
1423
|
+
},
|
|
1424
|
+
get IMAGE_CONTENT_KEY() {
|
|
1425
|
+
prepareImageKeys();
|
|
1426
|
+
return __IMAGE_CONTENT_KEY;
|
|
1427
|
+
},
|
|
1428
|
+
get IMAGE_INLINE_CONTENT_KEY() {
|
|
1429
|
+
prepareImageKeys();
|
|
1430
|
+
return __IMAGE_INLINE_CONTENT_KEY;
|
|
1431
|
+
},
|
|
1432
|
+
get FILE_CONTENT_KEY() {
|
|
1433
|
+
if (__FILE_CONTENT_KEY === "__FILE_CONTENT_KEY__") {
|
|
1434
|
+
for (const msg of sm) if ("file" === msg[KEYS.TYPE_KEY]) for (const key in msg) {
|
|
1435
|
+
if (/^(role|text|grounding|id|isJson|parts|tokenCount)$/.test(key)) continue;
|
|
1436
|
+
const val = msg[key];
|
|
1437
|
+
if (typeof val === "object" && val && "mimeType" in val) __FILE_CONTENT_KEY = key;
|
|
3363
1438
|
}
|
|
3364
|
-
}
|
|
3365
|
-
return
|
|
3366
|
-
}
|
|
3367
|
-
|
|
3368
|
-
|
|
1439
|
+
}
|
|
1440
|
+
return __FILE_CONTENT_KEY;
|
|
1441
|
+
},
|
|
1442
|
+
get FC_RESPONSE_KEY() {
|
|
1443
|
+
if (__FC_RESPONSE_KEY === "__FC_RESPONSE_KEY__") {
|
|
1444
|
+
for (const msg of sm) if ("function_call" === msg[KEYS.TYPE_KEY]) for (const key in msg) {
|
|
1445
|
+
if (/^(role|text|grounding|id|isJson|parts|tokenCount)$/.test(key)) continue;
|
|
1446
|
+
const val = msg[key];
|
|
1447
|
+
if (typeof val === "object" && val && "response" in val) __FC_RESPONSE_KEY = key;
|
|
1448
|
+
}
|
|
1449
|
+
}
|
|
1450
|
+
return __FC_RESPONSE_KEY;
|
|
1451
|
+
}
|
|
1452
|
+
};
|
|
1453
|
+
const prepareImageKeys = () => {
|
|
1454
|
+
if (__BLOB_URL_KEY === "__BLOB_URL_KEY__" || __IMAGE_CONTENT_KEY === "__IMAGE_CONTENT_KEY__" || __IMAGE_INLINE_CONTENT_KEY === "__IMAGE_INLINE_CONTENT_KEY__") {
|
|
1455
|
+
for (const msg of sm) if ("image" === msg[KEYS.TYPE_KEY]) for (const key in msg) {
|
|
1456
|
+
if (/^(role|text|grounding|id|isJson|parts|tokenCount)$/.test(key)) continue;
|
|
1457
|
+
const val = msg[key];
|
|
1458
|
+
if (typeof val === "object" && val && "mimeType" in val) if ("id" in val) __IMAGE_CONTENT_KEY = key;
|
|
1459
|
+
else __IMAGE_INLINE_CONTENT_KEY = key;
|
|
1460
|
+
else if (typeof val === "string" && val.startsWith("blob:")) __BLOB_URL_KEY = key;
|
|
1461
|
+
}
|
|
1462
|
+
}
|
|
1463
|
+
};
|
|
1464
|
+
const prepareKey = (sourceMessages) => {
|
|
1465
|
+
if (sourceMessages.length === 0) return;
|
|
1466
|
+
sm = sourceMessages;
|
|
1467
|
+
};
|
|
3369
1468
|
const TargetPartSchema = union([
|
|
3370
1469
|
object({ text: string() }),
|
|
3371
1470
|
object({ inlineData: object({
|
|
3372
1471
|
mimeType: string(),
|
|
3373
1472
|
data: string()
|
|
3374
1473
|
}) }),
|
|
3375
|
-
object({
|
|
1474
|
+
object({ functionCall: object({
|
|
3376
1475
|
name: string(),
|
|
3377
|
-
|
|
1476
|
+
parameters: any()
|
|
3378
1477
|
}) }),
|
|
3379
|
-
object({
|
|
1478
|
+
object({ functionResponse: object({
|
|
3380
1479
|
name: string(),
|
|
3381
1480
|
response: any()
|
|
3382
1481
|
}) })
|
|
3383
1482
|
]);
|
|
3384
1483
|
const TargetMessageSchema = object({
|
|
1484
|
+
id: optional(string()),
|
|
3385
1485
|
role: string(),
|
|
3386
1486
|
parts: array(TargetPartSchema)
|
|
3387
1487
|
});
|
|
3388
|
-
|
|
1488
|
+
array(TargetMessageSchema);
|
|
3389
1489
|
const blobUrlToBase64 = (blobUrl) => {
|
|
3390
1490
|
return new Promise(async (resolve, reject) => {
|
|
3391
1491
|
try {
|
|
@@ -3406,27 +1506,25 @@ const blobUrlToBase64 = (blobUrl) => {
|
|
|
3406
1506
|
}
|
|
3407
1507
|
});
|
|
3408
1508
|
};
|
|
3409
|
-
let normalizeNcMapToCanonicalArray;
|
|
3410
1509
|
const normalizeNcValue = (ncWrapper) => {
|
|
3411
|
-
const ncArray = ncWrapper.
|
|
1510
|
+
const ncArray = ncWrapper[KEYS.CONTENT_KEY];
|
|
3412
1511
|
return z(ncArray).with([
|
|
3413
1512
|
N.any,
|
|
3414
1513
|
N.any,
|
|
3415
1514
|
N.any,
|
|
3416
1515
|
N.any,
|
|
3417
|
-
{
|
|
1516
|
+
{ [KEYS.CONTENT_KEY]: [N.select(N.instanceOf(Map))] }
|
|
3418
1517
|
], (innerMap) => {
|
|
3419
|
-
const processedMapArray = normalizeNcMapToCanonicalArray(innerMap);
|
|
3420
1518
|
return [
|
|
3421
1519
|
null,
|
|
3422
1520
|
null,
|
|
3423
1521
|
null,
|
|
3424
1522
|
null,
|
|
3425
|
-
[
|
|
1523
|
+
[normalizeNcMapToCanonicalArray(innerMap)]
|
|
3426
1524
|
];
|
|
3427
1525
|
}).otherwise(() => ncArray);
|
|
3428
1526
|
};
|
|
3429
|
-
normalizeNcMapToCanonicalArray = (map) => {
|
|
1527
|
+
const normalizeNcMapToCanonicalArray = (map) => {
|
|
3430
1528
|
return Array.from(map.entries()).map(([key, valueWrapper]) => {
|
|
3431
1529
|
const canonicalValueArray = normalizeNcValue(valueWrapper);
|
|
3432
1530
|
return [key, canonicalValueArray];
|
|
@@ -3436,10 +1534,10 @@ const getCanonicalFunctionCall = (msg) => {
|
|
|
3436
1534
|
return z(msg.parts[0]).with(N.array(), (part) => ({
|
|
3437
1535
|
name: part[10][0],
|
|
3438
1536
|
argsArray: part[10][1][0]
|
|
3439
|
-
})).with({
|
|
3440
|
-
const functionCallData = part.
|
|
1537
|
+
})).with({ [KEYS.CONTENT_KEY]: N.array() }, (part) => {
|
|
1538
|
+
const functionCallData = part[KEYS.CONTENT_KEY][10][KEYS.CONTENT_KEY];
|
|
3441
1539
|
const name = functionCallData[0];
|
|
3442
|
-
const argsMap = functionCallData[1].
|
|
1540
|
+
const argsMap = functionCallData[1][KEYS.CONTENT_KEY][0];
|
|
3443
1541
|
return {
|
|
3444
1542
|
name,
|
|
3445
1543
|
argsArray: normalizeNcMapToCanonicalArray(argsMap)
|
|
@@ -3449,8 +1547,32 @@ const getCanonicalFunctionCall = (msg) => {
|
|
|
3449
1547
|
});
|
|
3450
1548
|
};
|
|
3451
1549
|
const parseArgValue = (arg) => {
|
|
3452
|
-
if (!Array.isArray(arg))
|
|
1550
|
+
if (!Array.isArray(arg)) {
|
|
1551
|
+
if (typeof arg === "object" && arg !== null && KEYS.CONTENT_KEY in arg) return parseArgValue(arg[KEYS.CONTENT_KEY]);
|
|
1552
|
+
return arg;
|
|
1553
|
+
}
|
|
3453
1554
|
return z(arg).with([
|
|
1555
|
+
N.any,
|
|
1556
|
+
N.any,
|
|
1557
|
+
N.any,
|
|
1558
|
+
N.any,
|
|
1559
|
+
N.any,
|
|
1560
|
+
{ [KEYS.CONTENT_KEY]: [N.select()] }
|
|
1561
|
+
], (val) => {
|
|
1562
|
+
if (Array.isArray(val)) return val.map(parseArgValue);
|
|
1563
|
+
console.warn("unknown struct 1", val);
|
|
1564
|
+
return null;
|
|
1565
|
+
}).with([
|
|
1566
|
+
N.any,
|
|
1567
|
+
N.any,
|
|
1568
|
+
N.any,
|
|
1569
|
+
N.any,
|
|
1570
|
+
{ [KEYS.CONTENT_KEY]: [N.select(N.instanceOf(Map))] }
|
|
1571
|
+
], (map) => {
|
|
1572
|
+
return Object.fromEntries([...map.entries()].map(([key, valueWrapper]) => {
|
|
1573
|
+
return [key, parseArgValue(valueWrapper)];
|
|
1574
|
+
}));
|
|
1575
|
+
}).with([
|
|
3454
1576
|
N.any,
|
|
3455
1577
|
N.any,
|
|
3456
1578
|
N.any,
|
|
@@ -3470,17 +1592,21 @@ const parseArgValue = (arg) => {
|
|
|
3470
1592
|
N.any,
|
|
3471
1593
|
N.any,
|
|
3472
1594
|
N.select(N.string)
|
|
3473
|
-
], (val) => val).with([N.any, N.select(N.number)], (val) => val).otherwise(() =>
|
|
1595
|
+
], (val) => val).with([N.any, N.select(N.number)], (val) => val).otherwise(() => {
|
|
1596
|
+
console.warn("unknown struct 0", arg);
|
|
1597
|
+
return null;
|
|
1598
|
+
});
|
|
3474
1599
|
};
|
|
3475
1600
|
const parseFunctionArgs = (argList) => {
|
|
3476
1601
|
if (!Array.isArray(argList)) return {};
|
|
3477
1602
|
return Object.fromEntries(argList.map(([key, value]) => [key, parseArgValue(value)]));
|
|
3478
1603
|
};
|
|
3479
1604
|
const convertMessages = async (sourceMessages) => {
|
|
1605
|
+
prepareKey(sourceMessages);
|
|
3480
1606
|
const groupedMessages = sourceMessages.reduce((acc, msg) => {
|
|
3481
1607
|
const lastGroup = acc[acc.length - 1];
|
|
3482
1608
|
const prevMessage = lastGroup?.items[lastGroup.items.length - 1];
|
|
3483
|
-
if (lastGroup && lastGroup.role === msg.role && prevMessage?.
|
|
1609
|
+
if (lastGroup && lastGroup.role === msg.role && prevMessage?.[KEYS.TYPE_KEY] !== "function_call") lastGroup.items.push(msg);
|
|
3484
1610
|
else acc.push({
|
|
3485
1611
|
role: msg.role,
|
|
3486
1612
|
items: [msg]
|
|
@@ -3492,44 +1618,44 @@ const convertMessages = async (sourceMessages) => {
|
|
|
3492
1618
|
let functionResponseData = null;
|
|
3493
1619
|
const partsPromises = group.items.map(async (item) => {
|
|
3494
1620
|
return z(item).with({
|
|
3495
|
-
|
|
1621
|
+
[KEYS.TYPE_KEY]: "text",
|
|
3496
1622
|
text: N.string
|
|
3497
1623
|
}, (msg) => {
|
|
3498
1624
|
return msg.text.length > 0 ? { text: msg.text } : null;
|
|
3499
|
-
}).with({
|
|
3500
|
-
|
|
3501
|
-
|
|
3502
|
-
}, (wd) => {
|
|
3503
|
-
return { inlineData: {
|
|
3504
|
-
mimeType: wd.mimeType,
|
|
3505
|
-
data: wd.Dc
|
|
3506
|
-
} };
|
|
3507
|
-
}).with({
|
|
3508
|
-
Ua: "image",
|
|
3509
|
-
Ta: N.not(void 0).select("ta"),
|
|
3510
|
-
zd: N.not(void 0).select("zd")
|
|
3511
|
-
}, async ({ ta, zd }) => {
|
|
3512
|
-
try {
|
|
3513
|
-
const data = await blobUrlToBase64(zd);
|
|
1625
|
+
}).with({ [KEYS.TYPE_KEY]: "image" }, async (img) => {
|
|
1626
|
+
if (KEYS.IMAGE_INLINE_CONTENT_KEY in img) {
|
|
1627
|
+
const inlineContent = img[KEYS.IMAGE_INLINE_CONTENT_KEY];
|
|
3514
1628
|
return { inlineData: {
|
|
3515
|
-
mimeType:
|
|
3516
|
-
data
|
|
1629
|
+
mimeType: inlineContent.mimeType,
|
|
1630
|
+
data: inlineContent.Dc
|
|
3517
1631
|
} };
|
|
3518
|
-
} catch (error) {
|
|
3519
|
-
console.error(`Failed to process blob URL ${zd}:`, error);
|
|
3520
|
-
return null;
|
|
3521
1632
|
}
|
|
3522
|
-
|
|
1633
|
+
if (KEYS.BLOB_URL_KEY in img && KEYS.IMAGE_CONTENT_KEY in img) {
|
|
1634
|
+
const imageConent = img[KEYS.IMAGE_CONTENT_KEY];
|
|
1635
|
+
const blobUrl = img[KEYS.BLOB_URL_KEY];
|
|
1636
|
+
try {
|
|
1637
|
+
const data = await blobUrlToBase64(blobUrl);
|
|
1638
|
+
return { inlineData: {
|
|
1639
|
+
mimeType: imageConent.mimeType,
|
|
1640
|
+
data
|
|
1641
|
+
} };
|
|
1642
|
+
} catch (error) {
|
|
1643
|
+
console.error(`Failed to process blob URL ${blobUrl}:`, error);
|
|
1644
|
+
return null;
|
|
1645
|
+
}
|
|
1646
|
+
}
|
|
1647
|
+
return null;
|
|
1648
|
+
}).with({ [KEYS.TYPE_KEY]: "function_call" }, (msg) => {
|
|
3523
1649
|
try {
|
|
3524
1650
|
const { name, argsArray } = getCanonicalFunctionCall(msg);
|
|
3525
1651
|
const args = parseFunctionArgs(argsArray);
|
|
3526
|
-
if (msg.
|
|
1652
|
+
if (typeof msg[KEYS.FC_RESPONSE_KEY]?.response === "string") functionResponseData = {
|
|
3527
1653
|
name,
|
|
3528
|
-
response: msg.
|
|
1654
|
+
response: msg[KEYS.FC_RESPONSE_KEY].response
|
|
3529
1655
|
};
|
|
3530
|
-
return {
|
|
1656
|
+
return { functionCall: {
|
|
3531
1657
|
name,
|
|
3532
|
-
args
|
|
1658
|
+
parameters: JSON.stringify(args)
|
|
3533
1659
|
} };
|
|
3534
1660
|
} catch (error) {
|
|
3535
1661
|
console.error("Failed to parse function call:", error, item);
|
|
@@ -3539,14 +1665,16 @@ const convertMessages = async (sourceMessages) => {
|
|
|
3539
1665
|
});
|
|
3540
1666
|
const parts = (await Promise.all(partsPromises)).filter((p$1) => p$1 !== null);
|
|
3541
1667
|
if (parts.length > 0) finalMessages.push({
|
|
1668
|
+
id: group.id,
|
|
3542
1669
|
role: group.role,
|
|
3543
1670
|
parts
|
|
3544
1671
|
});
|
|
3545
1672
|
if (functionResponseData) finalMessages.push({
|
|
1673
|
+
id: group.id,
|
|
3546
1674
|
role: "user",
|
|
3547
|
-
parts: [{
|
|
1675
|
+
parts: [{ functionResponse: {
|
|
3548
1676
|
name: functionResponseData.name,
|
|
3549
|
-
response:
|
|
1677
|
+
response: functionResponseData.response
|
|
3550
1678
|
} }]
|
|
3551
1679
|
});
|
|
3552
1680
|
}
|
|
@@ -3556,9 +1684,25 @@ const convertMessages = async (sourceMessages) => {
|
|
|
3556
1684
|
});
|
|
3557
1685
|
return finalMessages;
|
|
3558
1686
|
};
|
|
3559
|
-
const syncOutput = async () => {
|
|
1687
|
+
const syncOutput = async (signal) => {
|
|
1688
|
+
if (signal?.aborted) {
|
|
1689
|
+
console.log("JIXO BROWSER: syncOutput aborted before starting.");
|
|
1690
|
+
return;
|
|
1691
|
+
}
|
|
1692
|
+
const abortController = new AbortController();
|
|
1693
|
+
const internalSignal = abortController.signal;
|
|
1694
|
+
signal?.addEventListener("abort", () => {
|
|
1695
|
+
console.log("JIXO BROWSER: syncOutput aborted.");
|
|
1696
|
+
abortController.abort();
|
|
1697
|
+
}, { once: true });
|
|
1698
|
+
let preRaw = "";
|
|
3560
1699
|
const onChange = func_throttle(async (raw) => {
|
|
3561
|
-
|
|
1700
|
+
if (internalSignal.aborted) return;
|
|
1701
|
+
const newRaw = JSON.stringify(raw);
|
|
1702
|
+
if (preRaw !== newRaw) {
|
|
1703
|
+
preRaw = newRaw;
|
|
1704
|
+
await runFileCreation(await convertMessages(raw));
|
|
1705
|
+
}
|
|
3562
1706
|
}, 200, {
|
|
3563
1707
|
before: true,
|
|
3564
1708
|
waitPromise: true
|
|
@@ -3570,52 +1714,37 @@ const syncOutput = async () => {
|
|
|
3570
1714
|
let isMatched = false;
|
|
3571
1715
|
if (this.length > 1 && a$1 && Object.getPrototypeOf(a$1) === Object.prototype && a$1.role && a$1.id && typeof a$1.text === "string") isMatched = true;
|
|
3572
1716
|
const res = arr_push.apply(this, args);
|
|
3573
|
-
if (isMatched) try {
|
|
1717
|
+
if (isMatched && !internalSignal.aborted) try {
|
|
3574
1718
|
onChange(structuredClone(this));
|
|
3575
1719
|
} catch {}
|
|
3576
1720
|
return res;
|
|
3577
1721
|
};
|
|
3578
1722
|
const findInput = () => $(`textarea[aria-label="Start typing a prompt"]`);
|
|
3579
|
-
while (!
|
|
1723
|
+
while (!internalSignal.aborted) {
|
|
3580
1724
|
const input = findInput();
|
|
3581
|
-
if (input)
|
|
3582
|
-
input.dispatchEvent(new Event("input"));
|
|
3583
|
-
started = true;
|
|
3584
|
-
}
|
|
1725
|
+
if (input) input.dispatchEvent(new Event("input"));
|
|
3585
1726
|
await delay(300);
|
|
3586
1727
|
}
|
|
3587
1728
|
};
|
|
3588
|
-
let started = false;
|
|
3589
|
-
let writting = false;
|
|
3590
1729
|
async function runFileCreation(b$1, targetFilename = getTargetNamespace() + ".contents.json") {
|
|
3591
|
-
started = true;
|
|
3592
|
-
if (writting) return;
|
|
3593
|
-
writting = true;
|
|
3594
1730
|
try {
|
|
3595
|
-
const
|
|
3596
|
-
if (!rootDirHandle$1) return;
|
|
3597
|
-
const fileHandle = await rootDirHandle$1.getFileHandle(targetFilename, { create: true });
|
|
3598
|
-
const writable = await fileHandle.createWritable();
|
|
3599
|
-
console.log("%c - 创建可写流成功。", styles.info);
|
|
1731
|
+
const writable = await (await (await prepareDirHandle()).getFileHandle(targetFilename, { create: true })).createWritable();
|
|
3600
1732
|
await writable.write(JSON.stringify(b$1));
|
|
3601
|
-
console.log("%c - 数据写入中...", styles.info);
|
|
3602
1733
|
await writable.close();
|
|
3603
|
-
console.log(`%c - ✅
|
|
1734
|
+
console.log(`%c - ✅ File written: %c${targetFilename}`, styles.success, styles.code);
|
|
3604
1735
|
} catch (error) {
|
|
3605
|
-
if (error instanceof Error && error.name === "AbortError") console.warn("%c⚠️
|
|
3606
|
-
else console.error("%c❌
|
|
3607
|
-
} finally {
|
|
3608
|
-
writting = false;
|
|
1736
|
+
if (error instanceof Error && error.name === "AbortError") console.warn("%c⚠️ User cancelled folder selection.", styles.warn);
|
|
1737
|
+
else console.error("%c❌ Error writing file:", styles.error, error);
|
|
3609
1738
|
}
|
|
3610
1739
|
}
|
|
3611
1740
|
(async () => {
|
|
3612
|
-
|
|
1741
|
+
if (await prepareDirHandle().then(() => false, (e$1) => {
|
|
3613
1742
|
if (e$1 instanceof Error && e$1.name === "AbortError") return true;
|
|
3614
|
-
})
|
|
3615
|
-
if (aborted$1) {
|
|
1743
|
+
})) {
|
|
3616
1744
|
console.warn("用户取消了脚本运行");
|
|
3617
1745
|
return;
|
|
3618
1746
|
}
|
|
3619
1747
|
syncOutput();
|
|
3620
1748
|
syncInput();
|
|
3621
1749
|
})();
|
|
1750
|
+
export {};
|