@commandgarden/cli 1.1.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/main.js +379 -4376
- package/node_modules/@commandgarden/app/dist/client/assets/index-58UrF1aG.js +197 -0
- package/node_modules/@commandgarden/app/dist/client/assets/index-DErcb2Kp.css +1 -0
- package/node_modules/@commandgarden/app/dist/client/index.html +19 -0
- package/node_modules/@commandgarden/app/dist/server/daemon-client.js +61 -0
- package/node_modules/@commandgarden/app/dist/server/main.js +63 -0
- package/node_modules/@commandgarden/app/dist/server/routes/audit.js +20 -0
- package/node_modules/@commandgarden/app/dist/server/routes/config.js +13 -0
- package/node_modules/@commandgarden/app/dist/server/routes/connectors.js +35 -0
- package/node_modules/@commandgarden/app/dist/server/routes/index.js +14 -0
- package/node_modules/@commandgarden/app/dist/server/routes/preferences.js +32 -0
- package/node_modules/@commandgarden/app/dist/server/routes/run.js +46 -0
- package/node_modules/@commandgarden/app/dist/server/routes/status.js +11 -0
- package/node_modules/@commandgarden/app/dist/server/store.js +55 -0
- package/node_modules/@commandgarden/app/package.json +42 -0
- package/node_modules/@commandgarden/daemon/dist/audit-store.d.ts +18 -0
- package/node_modules/@commandgarden/daemon/dist/audit-store.d.ts.map +1 -0
- package/node_modules/@commandgarden/daemon/dist/audit-store.js +97 -0
- package/node_modules/@commandgarden/daemon/dist/audit-store.js.map +1 -0
- package/node_modules/@commandgarden/daemon/dist/auth.d.ts +5 -0
- package/node_modules/@commandgarden/daemon/dist/auth.d.ts.map +1 -0
- package/node_modules/@commandgarden/daemon/dist/auth.js +27 -0
- package/node_modules/@commandgarden/daemon/dist/auth.js.map +1 -0
- package/node_modules/@commandgarden/daemon/dist/config.d.ts +109 -0
- package/node_modules/@commandgarden/daemon/dist/config.d.ts.map +1 -0
- package/node_modules/@commandgarden/daemon/dist/config.js +45 -0
- package/node_modules/@commandgarden/daemon/dist/config.js.map +1 -0
- package/node_modules/@commandgarden/daemon/dist/main.d.ts +2 -0
- package/node_modules/@commandgarden/daemon/dist/main.d.ts.map +1 -0
- package/node_modules/@commandgarden/daemon/dist/main.js +58 -0
- package/node_modules/@commandgarden/daemon/dist/main.js.map +1 -0
- package/node_modules/@commandgarden/daemon/dist/registry.d.ts +21 -0
- package/node_modules/@commandgarden/daemon/dist/registry.d.ts.map +1 -0
- package/node_modules/@commandgarden/daemon/dist/registry.js +70 -0
- package/node_modules/@commandgarden/daemon/dist/registry.js.map +1 -0
- package/node_modules/@commandgarden/daemon/dist/server.d.ts +15 -0
- package/node_modules/@commandgarden/daemon/dist/server.d.ts.map +1 -0
- package/node_modules/@commandgarden/daemon/dist/server.js +336 -0
- package/node_modules/@commandgarden/daemon/dist/server.js.map +1 -0
- package/node_modules/@commandgarden/daemon/dist/sse-manager.d.ts +10 -0
- package/node_modules/@commandgarden/daemon/dist/sse-manager.d.ts.map +1 -0
- package/node_modules/@commandgarden/daemon/dist/sse-manager.js +37 -0
- package/node_modules/@commandgarden/daemon/dist/sse-manager.js.map +1 -0
- package/node_modules/@commandgarden/daemon/dist/validator.d.ts +10 -0
- package/node_modules/@commandgarden/daemon/dist/validator.d.ts.map +1 -0
- package/node_modules/@commandgarden/daemon/dist/validator.js +19 -0
- package/node_modules/@commandgarden/daemon/dist/validator.js.map +1 -0
- package/node_modules/@commandgarden/daemon/dist/ws-relay.d.ts +30 -0
- package/node_modules/@commandgarden/daemon/dist/ws-relay.d.ts.map +1 -0
- package/node_modules/@commandgarden/daemon/dist/ws-relay.js +111 -0
- package/node_modules/@commandgarden/daemon/dist/ws-relay.js.map +1 -0
- package/node_modules/@commandgarden/daemon/package.json +30 -0
- package/node_modules/@commandgarden/shared/dist/capabilities.d.ts +7 -0
- package/node_modules/@commandgarden/shared/dist/capabilities.d.ts.map +1 -0
- package/node_modules/@commandgarden/shared/dist/capabilities.js +23 -0
- package/node_modules/@commandgarden/shared/dist/capabilities.js.map +1 -0
- package/node_modules/@commandgarden/shared/dist/connector.d.ts +377 -0
- package/node_modules/@commandgarden/shared/dist/connector.d.ts.map +1 -0
- package/node_modules/@commandgarden/shared/dist/connector.js +29 -0
- package/node_modules/@commandgarden/shared/dist/connector.js.map +1 -0
- package/node_modules/@commandgarden/shared/dist/events.d.ts +33 -0
- package/node_modules/@commandgarden/shared/dist/events.d.ts.map +1 -0
- package/node_modules/@commandgarden/shared/dist/events.js +34 -0
- package/node_modules/@commandgarden/shared/dist/events.js.map +1 -0
- package/node_modules/@commandgarden/shared/dist/expression/evaluator.d.ts +8 -0
- package/node_modules/@commandgarden/shared/dist/expression/evaluator.d.ts.map +1 -0
- package/node_modules/@commandgarden/shared/dist/expression/evaluator.js +49 -0
- package/node_modules/@commandgarden/shared/dist/expression/evaluator.js.map +1 -0
- package/node_modules/@commandgarden/shared/dist/expression/filters.d.ts +3 -0
- package/node_modules/@commandgarden/shared/dist/expression/filters.d.ts.map +1 -0
- package/node_modules/@commandgarden/shared/dist/expression/filters.js +8 -0
- package/node_modules/@commandgarden/shared/dist/expression/filters.js.map +1 -0
- package/node_modules/@commandgarden/shared/dist/expression/index.d.ts +5 -0
- package/node_modules/@commandgarden/shared/dist/expression/index.d.ts.map +1 -0
- package/node_modules/@commandgarden/shared/dist/expression/index.js +5 -0
- package/node_modules/@commandgarden/shared/dist/expression/index.js.map +1 -0
- package/node_modules/@commandgarden/shared/dist/expression/parser.d.ts +22 -0
- package/node_modules/@commandgarden/shared/dist/expression/parser.d.ts.map +1 -0
- package/node_modules/@commandgarden/shared/dist/expression/parser.js +85 -0
- package/node_modules/@commandgarden/shared/dist/expression/parser.js.map +1 -0
- package/node_modules/@commandgarden/shared/dist/expression/tokenizer.d.ts +7 -0
- package/node_modules/@commandgarden/shared/dist/expression/tokenizer.d.ts.map +1 -0
- package/node_modules/@commandgarden/shared/dist/expression/tokenizer.js +76 -0
- package/node_modules/@commandgarden/shared/dist/expression/tokenizer.js.map +1 -0
- package/node_modules/@commandgarden/shared/dist/index.d.ts +8 -0
- package/node_modules/@commandgarden/shared/dist/index.d.ts.map +1 -0
- package/node_modules/@commandgarden/shared/dist/index.js +15 -0
- package/node_modules/@commandgarden/shared/dist/index.js.map +1 -0
- package/node_modules/@commandgarden/shared/dist/loader.d.ts +17 -0
- package/node_modules/@commandgarden/shared/dist/loader.d.ts.map +1 -0
- package/node_modules/@commandgarden/shared/dist/loader.js +76 -0
- package/node_modules/@commandgarden/shared/dist/loader.js.map +1 -0
- package/node_modules/@commandgarden/shared/dist/pipeline.d.ts +339 -0
- package/node_modules/@commandgarden/shared/dist/pipeline.d.ts.map +1 -0
- package/node_modules/@commandgarden/shared/dist/pipeline.js +97 -0
- package/node_modules/@commandgarden/shared/dist/pipeline.js.map +1 -0
- package/node_modules/@commandgarden/shared/dist/protocol.d.ts +58 -0
- package/node_modules/@commandgarden/shared/dist/protocol.d.ts.map +1 -0
- package/node_modules/@commandgarden/shared/dist/protocol.js +26 -0
- package/node_modules/@commandgarden/shared/dist/protocol.js.map +1 -0
- package/node_modules/@commandgarden/shared/package.json +32 -0
- package/package.json +55 -42
package/dist/main.js
CHANGED
|
@@ -1,15 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __export = (target, all) => {
|
|
4
|
-
for (var name in all)
|
|
5
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
6
|
-
};
|
|
7
2
|
|
|
8
3
|
// src/main.ts
|
|
9
4
|
import { Command } from "commander";
|
|
10
|
-
import { join as
|
|
11
|
-
import {
|
|
12
|
-
import { createRequire } from "module";
|
|
5
|
+
import { join as join4, dirname as dirname2, resolve } from "path";
|
|
6
|
+
import { readFileSync as readFileSync7 } from "fs";
|
|
13
7
|
import { homedir } from "os";
|
|
14
8
|
import { fileURLToPath } from "url";
|
|
15
9
|
|
|
@@ -113,6 +107,64 @@ var DaemonClient = class {
|
|
|
113
107
|
}
|
|
114
108
|
};
|
|
115
109
|
|
|
110
|
+
// src/resolve-script.ts
|
|
111
|
+
import { join, dirname } from "path";
|
|
112
|
+
import { existsSync, readFileSync as readFileSync2 } from "fs";
|
|
113
|
+
import { createRequire } from "module";
|
|
114
|
+
import { pathToFileURL } from "url";
|
|
115
|
+
function resolveScript(baseDir, relativePath, packageName, entryPoint) {
|
|
116
|
+
const looked = [];
|
|
117
|
+
const relative = join(baseDir, relativePath);
|
|
118
|
+
if (existsSync(relative)) return relative;
|
|
119
|
+
looked.push(` - ${relative} (relative \u2014 not found)`);
|
|
120
|
+
try {
|
|
121
|
+
const req = createRequire(pathToFileURL(join(baseDir, "_")).href);
|
|
122
|
+
const pkgJsonPath = req.resolve(`${packageName}/package.json`);
|
|
123
|
+
const resolved = join(dirname(pkgJsonPath), entryPoint);
|
|
124
|
+
if (existsSync(resolved)) return resolved;
|
|
125
|
+
looked.push(` - ${resolved} (package found, entry point not built)`);
|
|
126
|
+
} catch {
|
|
127
|
+
looked.push(` - ${packageName} (package not resolvable via require)`);
|
|
128
|
+
}
|
|
129
|
+
const monorepoRoot = findMonorepoRoot(baseDir);
|
|
130
|
+
console.error(`Cannot find ${packageName} entry point.`);
|
|
131
|
+
console.error("");
|
|
132
|
+
console.error("Looked at:");
|
|
133
|
+
for (const line of looked) console.error(line);
|
|
134
|
+
console.error("");
|
|
135
|
+
if (monorepoRoot) {
|
|
136
|
+
console.error("To fix this, run from the monorepo root:");
|
|
137
|
+
console.error(` cd ${monorepoRoot} && npm install && npm run build`);
|
|
138
|
+
console.error("");
|
|
139
|
+
console.error("Then re-link the CLI globally:");
|
|
140
|
+
console.error(` cd ${join(monorepoRoot, "cli")} && npm link`);
|
|
141
|
+
} else {
|
|
142
|
+
console.error("To fix this, run from the monorepo root:");
|
|
143
|
+
console.error(" cd <monorepo>/commandGarden && npm install && npm run build");
|
|
144
|
+
console.error("");
|
|
145
|
+
console.error("Then re-link the CLI globally:");
|
|
146
|
+
console.error(" cd <monorepo>/commandGarden/cli && npm link");
|
|
147
|
+
}
|
|
148
|
+
process.exit(1);
|
|
149
|
+
}
|
|
150
|
+
function findMonorepoRoot(startDir) {
|
|
151
|
+
let dir = startDir;
|
|
152
|
+
for (let i = 0; i < 10; i++) {
|
|
153
|
+
const pkgPath = join(dir, "package.json");
|
|
154
|
+
if (existsSync(pkgPath)) {
|
|
155
|
+
try {
|
|
156
|
+
const content = JSON.parse(readFileSync2(pkgPath, "utf-8"));
|
|
157
|
+
if (Array.isArray(content.workspaces)) return dir;
|
|
158
|
+
} catch {
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
const parent = dirname(dir);
|
|
162
|
+
if (parent === dir) break;
|
|
163
|
+
dir = parent;
|
|
164
|
+
}
|
|
165
|
+
return null;
|
|
166
|
+
}
|
|
167
|
+
|
|
116
168
|
// src/duration.ts
|
|
117
169
|
var UNITS = {
|
|
118
170
|
m: 6e4,
|
|
@@ -175,4274 +227,234 @@ function parseConnectorArgs(rawArgs) {
|
|
|
175
227
|
const result = {};
|
|
176
228
|
let i = 0;
|
|
177
229
|
while (i < rawArgs.length) {
|
|
178
|
-
const arg = rawArgs[i];
|
|
179
|
-
if (arg.startsWith("--")) {
|
|
180
|
-
const eqIdx = arg.indexOf("=");
|
|
181
|
-
if (eqIdx !== -1) {
|
|
182
|
-
result[arg.slice(2, eqIdx)] = arg.slice(eqIdx + 1);
|
|
183
|
-
} else if (i + 1 < rawArgs.length && !rawArgs[i + 1].startsWith("--")) {
|
|
184
|
-
result[arg.slice(2)] = rawArgs[i + 1];
|
|
185
|
-
i++;
|
|
186
|
-
} else {
|
|
187
|
-
result[arg.slice(2)] = "true";
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
i++;
|
|
191
|
-
}
|
|
192
|
-
return result;
|
|
193
|
-
}
|
|
194
|
-
function promptApproval(request) {
|
|
195
|
-
const rl = createInterface({ input: process.stdin, output: process.stderr });
|
|
196
|
-
let cancelled = false;
|
|
197
|
-
const cancel = () => {
|
|
198
|
-
cancelled = true;
|
|
199
|
-
rl.close();
|
|
200
|
-
};
|
|
201
|
-
const prompt = `
|
|
202
|
-
\u26A0 Step ${request.stepIndex + 1} [${request.stepType}] in ${request.connectorKey} requires approval.
|
|
203
|
-
Capability: ${request.capability}
|
|
204
|
-
${request.description}
|
|
205
|
-
Approve? (y/n): `;
|
|
206
|
-
const promise = new Promise((resolve) => {
|
|
207
|
-
rl.question(prompt, (answer) => {
|
|
208
|
-
rl.close();
|
|
209
|
-
if (cancelled) return;
|
|
210
|
-
resolve(answer.trim().toLowerCase() === "y" || answer.trim().toLowerCase() === "yes");
|
|
211
|
-
});
|
|
212
|
-
rl.on("close", () => {
|
|
213
|
-
if (cancelled) resolve(true);
|
|
214
|
-
});
|
|
215
|
-
});
|
|
216
|
-
return { promise, cancel };
|
|
217
|
-
}
|
|
218
|
-
async function executeRun(client, connector, args, outputFormat) {
|
|
219
|
-
try {
|
|
220
|
-
const resp = await client.post("/api/run", {
|
|
221
|
-
connector,
|
|
222
|
-
args,
|
|
223
|
-
format: outputFormat
|
|
224
|
-
});
|
|
225
|
-
if (!resp.requiresApproval) {
|
|
226
|
-
if (!resp.ok) {
|
|
227
|
-
return `Error: ${resp.error ?? "Unknown error from extension"} (${resp.durationMs}ms)`;
|
|
228
|
-
}
|
|
229
|
-
return format(resp.data, resp.columns, connector, outputFormat);
|
|
230
|
-
}
|
|
231
|
-
const requestId = resp.requestId;
|
|
232
|
-
process.stderr.write(`Pipeline requires approval. Waiting for steps...
|
|
233
|
-
`);
|
|
234
|
-
return new Promise((resolve) => {
|
|
235
|
-
const abortController = new AbortController();
|
|
236
|
-
let activePrompt = null;
|
|
237
|
-
client.connectSSE(
|
|
238
|
-
`/api/run/events/${requestId}`,
|
|
239
|
-
(event, data) => {
|
|
240
|
-
if (event === "approval") {
|
|
241
|
-
const approvalReq = data;
|
|
242
|
-
activePrompt = promptApproval(approvalReq);
|
|
243
|
-
activePrompt.promise.then(async (approved) => {
|
|
244
|
-
activePrompt = null;
|
|
245
|
-
try {
|
|
246
|
-
await client.post("/api/approval", {
|
|
247
|
-
approvalId: approvalReq.approvalId,
|
|
248
|
-
approved
|
|
249
|
-
});
|
|
250
|
-
} catch {
|
|
251
|
-
}
|
|
252
|
-
if (!approved) {
|
|
253
|
-
abortController.abort();
|
|
254
|
-
resolve(`Aborted: Step ${approvalReq.stepIndex + 1} [${approvalReq.stepType}] was rejected.`);
|
|
255
|
-
}
|
|
256
|
-
});
|
|
257
|
-
} else if (event === "result") {
|
|
258
|
-
if (activePrompt) {
|
|
259
|
-
activePrompt.cancel();
|
|
260
|
-
activePrompt = null;
|
|
261
|
-
process.stderr.write("\n (approved via extension)\n");
|
|
262
|
-
}
|
|
263
|
-
abortController.abort();
|
|
264
|
-
const result = data;
|
|
265
|
-
if (!result.ok) {
|
|
266
|
-
resolve(`Error: ${result.error ?? "Unknown error"} (${result.durationMs}ms)`);
|
|
267
|
-
} else {
|
|
268
|
-
resolve(format(result.data, result.columns ?? [], connector, outputFormat));
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
},
|
|
272
|
-
abortController.signal
|
|
273
|
-
).catch(() => {
|
|
274
|
-
});
|
|
275
|
-
});
|
|
276
|
-
} catch (err) {
|
|
277
|
-
return `Error: ${err instanceof Error ? err.message : String(err)}`;
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
// src/commands/list.ts
|
|
282
|
-
import Table2 from "cli-table3";
|
|
283
|
-
async function executeList(client) {
|
|
284
|
-
try {
|
|
285
|
-
const resp = await client.get("/api/connectors");
|
|
286
|
-
if (resp.connectors.length === 0) return "No connectors installed.";
|
|
287
|
-
const table = new Table2({
|
|
288
|
-
head: ["Connector", "Description", "Access", "Domains", "Capabilities"],
|
|
289
|
-
style: { head: ["cyan"] }
|
|
290
|
-
});
|
|
291
|
-
for (const c of resp.connectors) {
|
|
292
|
-
table.push([
|
|
293
|
-
c.key,
|
|
294
|
-
c.description ?? "",
|
|
295
|
-
c.access,
|
|
296
|
-
c.domains.join(", "),
|
|
297
|
-
c.capabilities.join(", ")
|
|
298
|
-
]);
|
|
299
|
-
}
|
|
300
|
-
return table.toString();
|
|
301
|
-
} catch (err) {
|
|
302
|
-
return `Error: ${err instanceof Error ? err.message : String(err)}`;
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
// src/commands/inspect.ts
|
|
307
|
-
async function executeInspect(client, connectorKey) {
|
|
308
|
-
if (!connectorKey.includes("/")) {
|
|
309
|
-
return "Invalid connector key. Use format: <site>/<command> (e.g., timetracking/report)";
|
|
310
|
-
}
|
|
311
|
-
try {
|
|
312
|
-
const resp = await client.get(
|
|
313
|
-
`/api/connectors/${connectorKey}`
|
|
314
|
-
);
|
|
315
|
-
return renderConnector(resp.connector);
|
|
316
|
-
} catch (err) {
|
|
317
|
-
return `Error: ${err instanceof Error ? err.message : String(err)}`;
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
function renderConnector(c) {
|
|
321
|
-
const lines = [];
|
|
322
|
-
lines.push(`Connector: ${c.site}/${c.name}`);
|
|
323
|
-
lines.push(`Version: ${c.version}`);
|
|
324
|
-
if (c.description) lines.push(`Desc: ${c.description}`);
|
|
325
|
-
lines.push(`Access: ${c.access}`);
|
|
326
|
-
lines.push(`Domains: ${c.domains.join(", ")}`);
|
|
327
|
-
lines.push(`Caps: ${c.capabilities.join(", ")}`);
|
|
328
|
-
if (c.args && c.args.length > 0) {
|
|
329
|
-
lines.push("");
|
|
330
|
-
lines.push("Arguments:");
|
|
331
|
-
for (const a of c.args) {
|
|
332
|
-
const req = a.required ? "(required)" : `(default: ${a.default ?? "none"})`;
|
|
333
|
-
lines.push(` --${a.name} ${a.type} ${req}${a.help ? " " + a.help : ""}`);
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
if (c.columns && c.columns.length > 0) {
|
|
337
|
-
lines.push("");
|
|
338
|
-
lines.push("Output columns:");
|
|
339
|
-
for (const col of c.columns) {
|
|
340
|
-
lines.push(` ${col.name} (${col.type})`);
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
lines.push("");
|
|
344
|
-
lines.push(`Pipeline: ${c.pipeline.length} step(s)`);
|
|
345
|
-
for (let i = 0; i < c.pipeline.length; i++) {
|
|
346
|
-
const s = c.pipeline[i];
|
|
347
|
-
lines.push(` ${i + 1}. ${s.step}${stepSummary(s)}`);
|
|
348
|
-
}
|
|
349
|
-
return lines.join("\n");
|
|
350
|
-
}
|
|
351
|
-
function stepSummary(step) {
|
|
352
|
-
switch (step.step) {
|
|
353
|
-
case "navigate":
|
|
354
|
-
return ` \u2192 ${step.url}`;
|
|
355
|
-
case "wait":
|
|
356
|
-
return ` \u2192 ${step.selector ?? "delay"}${step.timeout ? ` (${step.timeout}ms)` : ""}`;
|
|
357
|
-
case "extract":
|
|
358
|
-
return ` \u2192 ${step.selector}`;
|
|
359
|
-
case "click":
|
|
360
|
-
return ` \u2192 ${step.selector}`;
|
|
361
|
-
case "type":
|
|
362
|
-
return ` \u2192 ${step.selector}`;
|
|
363
|
-
case "set":
|
|
364
|
-
return ` \u2192 ${step.name} = ${step.value}`;
|
|
365
|
-
case "filter":
|
|
366
|
-
return ` \u2192 ${step.field} ${step.operator} ${step.value}`;
|
|
367
|
-
case "map":
|
|
368
|
-
return ` \u2192 ${Object.keys(step.fields).join(", ")}`;
|
|
369
|
-
case "cookie":
|
|
370
|
-
return ` \u2192 ${step.domain}`;
|
|
371
|
-
case "fetch":
|
|
372
|
-
return ` \u2192 ${step.url}`;
|
|
373
|
-
case "intercept":
|
|
374
|
-
return ` \u2192 ${step.urlPattern}`;
|
|
375
|
-
default:
|
|
376
|
-
return "";
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
// src/commands/validate.ts
|
|
381
|
-
import { readFileSync as readFileSync2 } from "fs";
|
|
382
|
-
|
|
383
|
-
// ../shared/dist/capabilities.js
|
|
384
|
-
var CAPABILITIES = [
|
|
385
|
-
"navigate",
|
|
386
|
-
"cookie_read",
|
|
387
|
-
"cookie_write",
|
|
388
|
-
"dom_read",
|
|
389
|
-
"dom_write",
|
|
390
|
-
"intercept_response",
|
|
391
|
-
"js_evaluate"
|
|
392
|
-
];
|
|
393
|
-
var CAPABILITY_RISK = {
|
|
394
|
-
navigate: "low",
|
|
395
|
-
cookie_read: "medium",
|
|
396
|
-
cookie_write: "high",
|
|
397
|
-
dom_read: "low",
|
|
398
|
-
dom_write: "medium",
|
|
399
|
-
intercept_response: "medium",
|
|
400
|
-
js_evaluate: "high"
|
|
401
|
-
};
|
|
402
|
-
var HIGH_RISK_CAPABILITIES = CAPABILITIES.filter((c) => CAPABILITY_RISK[c] === "high");
|
|
403
|
-
|
|
404
|
-
// ../node_modules/zod/v3/external.js
|
|
405
|
-
var external_exports = {};
|
|
406
|
-
__export(external_exports, {
|
|
407
|
-
BRAND: () => BRAND,
|
|
408
|
-
DIRTY: () => DIRTY,
|
|
409
|
-
EMPTY_PATH: () => EMPTY_PATH,
|
|
410
|
-
INVALID: () => INVALID,
|
|
411
|
-
NEVER: () => NEVER,
|
|
412
|
-
OK: () => OK,
|
|
413
|
-
ParseStatus: () => ParseStatus,
|
|
414
|
-
Schema: () => ZodType,
|
|
415
|
-
ZodAny: () => ZodAny,
|
|
416
|
-
ZodArray: () => ZodArray,
|
|
417
|
-
ZodBigInt: () => ZodBigInt,
|
|
418
|
-
ZodBoolean: () => ZodBoolean,
|
|
419
|
-
ZodBranded: () => ZodBranded,
|
|
420
|
-
ZodCatch: () => ZodCatch,
|
|
421
|
-
ZodDate: () => ZodDate,
|
|
422
|
-
ZodDefault: () => ZodDefault,
|
|
423
|
-
ZodDiscriminatedUnion: () => ZodDiscriminatedUnion,
|
|
424
|
-
ZodEffects: () => ZodEffects,
|
|
425
|
-
ZodEnum: () => ZodEnum,
|
|
426
|
-
ZodError: () => ZodError,
|
|
427
|
-
ZodFirstPartyTypeKind: () => ZodFirstPartyTypeKind,
|
|
428
|
-
ZodFunction: () => ZodFunction,
|
|
429
|
-
ZodIntersection: () => ZodIntersection,
|
|
430
|
-
ZodIssueCode: () => ZodIssueCode,
|
|
431
|
-
ZodLazy: () => ZodLazy,
|
|
432
|
-
ZodLiteral: () => ZodLiteral,
|
|
433
|
-
ZodMap: () => ZodMap,
|
|
434
|
-
ZodNaN: () => ZodNaN,
|
|
435
|
-
ZodNativeEnum: () => ZodNativeEnum,
|
|
436
|
-
ZodNever: () => ZodNever,
|
|
437
|
-
ZodNull: () => ZodNull,
|
|
438
|
-
ZodNullable: () => ZodNullable,
|
|
439
|
-
ZodNumber: () => ZodNumber,
|
|
440
|
-
ZodObject: () => ZodObject,
|
|
441
|
-
ZodOptional: () => ZodOptional,
|
|
442
|
-
ZodParsedType: () => ZodParsedType,
|
|
443
|
-
ZodPipeline: () => ZodPipeline,
|
|
444
|
-
ZodPromise: () => ZodPromise,
|
|
445
|
-
ZodReadonly: () => ZodReadonly,
|
|
446
|
-
ZodRecord: () => ZodRecord,
|
|
447
|
-
ZodSchema: () => ZodType,
|
|
448
|
-
ZodSet: () => ZodSet,
|
|
449
|
-
ZodString: () => ZodString,
|
|
450
|
-
ZodSymbol: () => ZodSymbol,
|
|
451
|
-
ZodTransformer: () => ZodEffects,
|
|
452
|
-
ZodTuple: () => ZodTuple,
|
|
453
|
-
ZodType: () => ZodType,
|
|
454
|
-
ZodUndefined: () => ZodUndefined,
|
|
455
|
-
ZodUnion: () => ZodUnion,
|
|
456
|
-
ZodUnknown: () => ZodUnknown,
|
|
457
|
-
ZodVoid: () => ZodVoid,
|
|
458
|
-
addIssueToContext: () => addIssueToContext,
|
|
459
|
-
any: () => anyType,
|
|
460
|
-
array: () => arrayType,
|
|
461
|
-
bigint: () => bigIntType,
|
|
462
|
-
boolean: () => booleanType,
|
|
463
|
-
coerce: () => coerce,
|
|
464
|
-
custom: () => custom,
|
|
465
|
-
date: () => dateType,
|
|
466
|
-
datetimeRegex: () => datetimeRegex,
|
|
467
|
-
defaultErrorMap: () => en_default,
|
|
468
|
-
discriminatedUnion: () => discriminatedUnionType,
|
|
469
|
-
effect: () => effectsType,
|
|
470
|
-
enum: () => enumType,
|
|
471
|
-
function: () => functionType,
|
|
472
|
-
getErrorMap: () => getErrorMap,
|
|
473
|
-
getParsedType: () => getParsedType,
|
|
474
|
-
instanceof: () => instanceOfType,
|
|
475
|
-
intersection: () => intersectionType,
|
|
476
|
-
isAborted: () => isAborted,
|
|
477
|
-
isAsync: () => isAsync,
|
|
478
|
-
isDirty: () => isDirty,
|
|
479
|
-
isValid: () => isValid,
|
|
480
|
-
late: () => late,
|
|
481
|
-
lazy: () => lazyType,
|
|
482
|
-
literal: () => literalType,
|
|
483
|
-
makeIssue: () => makeIssue,
|
|
484
|
-
map: () => mapType,
|
|
485
|
-
nan: () => nanType,
|
|
486
|
-
nativeEnum: () => nativeEnumType,
|
|
487
|
-
never: () => neverType,
|
|
488
|
-
null: () => nullType,
|
|
489
|
-
nullable: () => nullableType,
|
|
490
|
-
number: () => numberType,
|
|
491
|
-
object: () => objectType,
|
|
492
|
-
objectUtil: () => objectUtil,
|
|
493
|
-
oboolean: () => oboolean,
|
|
494
|
-
onumber: () => onumber,
|
|
495
|
-
optional: () => optionalType,
|
|
496
|
-
ostring: () => ostring,
|
|
497
|
-
pipeline: () => pipelineType,
|
|
498
|
-
preprocess: () => preprocessType,
|
|
499
|
-
promise: () => promiseType,
|
|
500
|
-
quotelessJson: () => quotelessJson,
|
|
501
|
-
record: () => recordType,
|
|
502
|
-
set: () => setType,
|
|
503
|
-
setErrorMap: () => setErrorMap,
|
|
504
|
-
strictObject: () => strictObjectType,
|
|
505
|
-
string: () => stringType,
|
|
506
|
-
symbol: () => symbolType,
|
|
507
|
-
transformer: () => effectsType,
|
|
508
|
-
tuple: () => tupleType,
|
|
509
|
-
undefined: () => undefinedType,
|
|
510
|
-
union: () => unionType,
|
|
511
|
-
unknown: () => unknownType,
|
|
512
|
-
util: () => util,
|
|
513
|
-
void: () => voidType
|
|
514
|
-
});
|
|
515
|
-
|
|
516
|
-
// ../node_modules/zod/v3/helpers/util.js
|
|
517
|
-
var util;
|
|
518
|
-
(function(util2) {
|
|
519
|
-
util2.assertEqual = (_) => {
|
|
520
|
-
};
|
|
521
|
-
function assertIs(_arg) {
|
|
522
|
-
}
|
|
523
|
-
util2.assertIs = assertIs;
|
|
524
|
-
function assertNever(_x) {
|
|
525
|
-
throw new Error();
|
|
526
|
-
}
|
|
527
|
-
util2.assertNever = assertNever;
|
|
528
|
-
util2.arrayToEnum = (items) => {
|
|
529
|
-
const obj = {};
|
|
530
|
-
for (const item of items) {
|
|
531
|
-
obj[item] = item;
|
|
532
|
-
}
|
|
533
|
-
return obj;
|
|
534
|
-
};
|
|
535
|
-
util2.getValidEnumValues = (obj) => {
|
|
536
|
-
const validKeys = util2.objectKeys(obj).filter((k) => typeof obj[obj[k]] !== "number");
|
|
537
|
-
const filtered = {};
|
|
538
|
-
for (const k of validKeys) {
|
|
539
|
-
filtered[k] = obj[k];
|
|
540
|
-
}
|
|
541
|
-
return util2.objectValues(filtered);
|
|
542
|
-
};
|
|
543
|
-
util2.objectValues = (obj) => {
|
|
544
|
-
return util2.objectKeys(obj).map(function(e) {
|
|
545
|
-
return obj[e];
|
|
546
|
-
});
|
|
547
|
-
};
|
|
548
|
-
util2.objectKeys = typeof Object.keys === "function" ? (obj) => Object.keys(obj) : (object) => {
|
|
549
|
-
const keys = [];
|
|
550
|
-
for (const key in object) {
|
|
551
|
-
if (Object.prototype.hasOwnProperty.call(object, key)) {
|
|
552
|
-
keys.push(key);
|
|
553
|
-
}
|
|
554
|
-
}
|
|
555
|
-
return keys;
|
|
556
|
-
};
|
|
557
|
-
util2.find = (arr, checker) => {
|
|
558
|
-
for (const item of arr) {
|
|
559
|
-
if (checker(item))
|
|
560
|
-
return item;
|
|
561
|
-
}
|
|
562
|
-
return void 0;
|
|
563
|
-
};
|
|
564
|
-
util2.isInteger = typeof Number.isInteger === "function" ? (val) => Number.isInteger(val) : (val) => typeof val === "number" && Number.isFinite(val) && Math.floor(val) === val;
|
|
565
|
-
function joinValues(array, separator = " | ") {
|
|
566
|
-
return array.map((val) => typeof val === "string" ? `'${val}'` : val).join(separator);
|
|
567
|
-
}
|
|
568
|
-
util2.joinValues = joinValues;
|
|
569
|
-
util2.jsonStringifyReplacer = (_, value) => {
|
|
570
|
-
if (typeof value === "bigint") {
|
|
571
|
-
return value.toString();
|
|
572
|
-
}
|
|
573
|
-
return value;
|
|
574
|
-
};
|
|
575
|
-
})(util || (util = {}));
|
|
576
|
-
var objectUtil;
|
|
577
|
-
(function(objectUtil2) {
|
|
578
|
-
objectUtil2.mergeShapes = (first, second) => {
|
|
579
|
-
return {
|
|
580
|
-
...first,
|
|
581
|
-
...second
|
|
582
|
-
// second overwrites first
|
|
583
|
-
};
|
|
584
|
-
};
|
|
585
|
-
})(objectUtil || (objectUtil = {}));
|
|
586
|
-
var ZodParsedType = util.arrayToEnum([
|
|
587
|
-
"string",
|
|
588
|
-
"nan",
|
|
589
|
-
"number",
|
|
590
|
-
"integer",
|
|
591
|
-
"float",
|
|
592
|
-
"boolean",
|
|
593
|
-
"date",
|
|
594
|
-
"bigint",
|
|
595
|
-
"symbol",
|
|
596
|
-
"function",
|
|
597
|
-
"undefined",
|
|
598
|
-
"null",
|
|
599
|
-
"array",
|
|
600
|
-
"object",
|
|
601
|
-
"unknown",
|
|
602
|
-
"promise",
|
|
603
|
-
"void",
|
|
604
|
-
"never",
|
|
605
|
-
"map",
|
|
606
|
-
"set"
|
|
607
|
-
]);
|
|
608
|
-
var getParsedType = (data) => {
|
|
609
|
-
const t = typeof data;
|
|
610
|
-
switch (t) {
|
|
611
|
-
case "undefined":
|
|
612
|
-
return ZodParsedType.undefined;
|
|
613
|
-
case "string":
|
|
614
|
-
return ZodParsedType.string;
|
|
615
|
-
case "number":
|
|
616
|
-
return Number.isNaN(data) ? ZodParsedType.nan : ZodParsedType.number;
|
|
617
|
-
case "boolean":
|
|
618
|
-
return ZodParsedType.boolean;
|
|
619
|
-
case "function":
|
|
620
|
-
return ZodParsedType.function;
|
|
621
|
-
case "bigint":
|
|
622
|
-
return ZodParsedType.bigint;
|
|
623
|
-
case "symbol":
|
|
624
|
-
return ZodParsedType.symbol;
|
|
625
|
-
case "object":
|
|
626
|
-
if (Array.isArray(data)) {
|
|
627
|
-
return ZodParsedType.array;
|
|
628
|
-
}
|
|
629
|
-
if (data === null) {
|
|
630
|
-
return ZodParsedType.null;
|
|
631
|
-
}
|
|
632
|
-
if (data.then && typeof data.then === "function" && data.catch && typeof data.catch === "function") {
|
|
633
|
-
return ZodParsedType.promise;
|
|
634
|
-
}
|
|
635
|
-
if (typeof Map !== "undefined" && data instanceof Map) {
|
|
636
|
-
return ZodParsedType.map;
|
|
637
|
-
}
|
|
638
|
-
if (typeof Set !== "undefined" && data instanceof Set) {
|
|
639
|
-
return ZodParsedType.set;
|
|
640
|
-
}
|
|
641
|
-
if (typeof Date !== "undefined" && data instanceof Date) {
|
|
642
|
-
return ZodParsedType.date;
|
|
643
|
-
}
|
|
644
|
-
return ZodParsedType.object;
|
|
645
|
-
default:
|
|
646
|
-
return ZodParsedType.unknown;
|
|
647
|
-
}
|
|
648
|
-
};
|
|
649
|
-
|
|
650
|
-
// ../node_modules/zod/v3/ZodError.js
|
|
651
|
-
var ZodIssueCode = util.arrayToEnum([
|
|
652
|
-
"invalid_type",
|
|
653
|
-
"invalid_literal",
|
|
654
|
-
"custom",
|
|
655
|
-
"invalid_union",
|
|
656
|
-
"invalid_union_discriminator",
|
|
657
|
-
"invalid_enum_value",
|
|
658
|
-
"unrecognized_keys",
|
|
659
|
-
"invalid_arguments",
|
|
660
|
-
"invalid_return_type",
|
|
661
|
-
"invalid_date",
|
|
662
|
-
"invalid_string",
|
|
663
|
-
"too_small",
|
|
664
|
-
"too_big",
|
|
665
|
-
"invalid_intersection_types",
|
|
666
|
-
"not_multiple_of",
|
|
667
|
-
"not_finite"
|
|
668
|
-
]);
|
|
669
|
-
var quotelessJson = (obj) => {
|
|
670
|
-
const json = JSON.stringify(obj, null, 2);
|
|
671
|
-
return json.replace(/"([^"]+)":/g, "$1:");
|
|
672
|
-
};
|
|
673
|
-
var ZodError = class _ZodError extends Error {
|
|
674
|
-
get errors() {
|
|
675
|
-
return this.issues;
|
|
676
|
-
}
|
|
677
|
-
constructor(issues) {
|
|
678
|
-
super();
|
|
679
|
-
this.issues = [];
|
|
680
|
-
this.addIssue = (sub) => {
|
|
681
|
-
this.issues = [...this.issues, sub];
|
|
682
|
-
};
|
|
683
|
-
this.addIssues = (subs = []) => {
|
|
684
|
-
this.issues = [...this.issues, ...subs];
|
|
685
|
-
};
|
|
686
|
-
const actualProto = new.target.prototype;
|
|
687
|
-
if (Object.setPrototypeOf) {
|
|
688
|
-
Object.setPrototypeOf(this, actualProto);
|
|
689
|
-
} else {
|
|
690
|
-
this.__proto__ = actualProto;
|
|
691
|
-
}
|
|
692
|
-
this.name = "ZodError";
|
|
693
|
-
this.issues = issues;
|
|
694
|
-
}
|
|
695
|
-
format(_mapper) {
|
|
696
|
-
const mapper = _mapper || function(issue) {
|
|
697
|
-
return issue.message;
|
|
698
|
-
};
|
|
699
|
-
const fieldErrors = { _errors: [] };
|
|
700
|
-
const processError = (error) => {
|
|
701
|
-
for (const issue of error.issues) {
|
|
702
|
-
if (issue.code === "invalid_union") {
|
|
703
|
-
issue.unionErrors.map(processError);
|
|
704
|
-
} else if (issue.code === "invalid_return_type") {
|
|
705
|
-
processError(issue.returnTypeError);
|
|
706
|
-
} else if (issue.code === "invalid_arguments") {
|
|
707
|
-
processError(issue.argumentsError);
|
|
708
|
-
} else if (issue.path.length === 0) {
|
|
709
|
-
fieldErrors._errors.push(mapper(issue));
|
|
710
|
-
} else {
|
|
711
|
-
let curr = fieldErrors;
|
|
712
|
-
let i = 0;
|
|
713
|
-
while (i < issue.path.length) {
|
|
714
|
-
const el = issue.path[i];
|
|
715
|
-
const terminal = i === issue.path.length - 1;
|
|
716
|
-
if (!terminal) {
|
|
717
|
-
curr[el] = curr[el] || { _errors: [] };
|
|
718
|
-
} else {
|
|
719
|
-
curr[el] = curr[el] || { _errors: [] };
|
|
720
|
-
curr[el]._errors.push(mapper(issue));
|
|
721
|
-
}
|
|
722
|
-
curr = curr[el];
|
|
723
|
-
i++;
|
|
724
|
-
}
|
|
725
|
-
}
|
|
726
|
-
}
|
|
727
|
-
};
|
|
728
|
-
processError(this);
|
|
729
|
-
return fieldErrors;
|
|
730
|
-
}
|
|
731
|
-
static assert(value) {
|
|
732
|
-
if (!(value instanceof _ZodError)) {
|
|
733
|
-
throw new Error(`Not a ZodError: ${value}`);
|
|
734
|
-
}
|
|
735
|
-
}
|
|
736
|
-
toString() {
|
|
737
|
-
return this.message;
|
|
738
|
-
}
|
|
739
|
-
get message() {
|
|
740
|
-
return JSON.stringify(this.issues, util.jsonStringifyReplacer, 2);
|
|
741
|
-
}
|
|
742
|
-
get isEmpty() {
|
|
743
|
-
return this.issues.length === 0;
|
|
744
|
-
}
|
|
745
|
-
flatten(mapper = (issue) => issue.message) {
|
|
746
|
-
const fieldErrors = {};
|
|
747
|
-
const formErrors = [];
|
|
748
|
-
for (const sub of this.issues) {
|
|
749
|
-
if (sub.path.length > 0) {
|
|
750
|
-
const firstEl = sub.path[0];
|
|
751
|
-
fieldErrors[firstEl] = fieldErrors[firstEl] || [];
|
|
752
|
-
fieldErrors[firstEl].push(mapper(sub));
|
|
753
|
-
} else {
|
|
754
|
-
formErrors.push(mapper(sub));
|
|
755
|
-
}
|
|
756
|
-
}
|
|
757
|
-
return { formErrors, fieldErrors };
|
|
758
|
-
}
|
|
759
|
-
get formErrors() {
|
|
760
|
-
return this.flatten();
|
|
761
|
-
}
|
|
762
|
-
};
|
|
763
|
-
ZodError.create = (issues) => {
|
|
764
|
-
const error = new ZodError(issues);
|
|
765
|
-
return error;
|
|
766
|
-
};
|
|
767
|
-
|
|
768
|
-
// ../node_modules/zod/v3/locales/en.js
|
|
769
|
-
var errorMap = (issue, _ctx) => {
|
|
770
|
-
let message;
|
|
771
|
-
switch (issue.code) {
|
|
772
|
-
case ZodIssueCode.invalid_type:
|
|
773
|
-
if (issue.received === ZodParsedType.undefined) {
|
|
774
|
-
message = "Required";
|
|
775
|
-
} else {
|
|
776
|
-
message = `Expected ${issue.expected}, received ${issue.received}`;
|
|
777
|
-
}
|
|
778
|
-
break;
|
|
779
|
-
case ZodIssueCode.invalid_literal:
|
|
780
|
-
message = `Invalid literal value, expected ${JSON.stringify(issue.expected, util.jsonStringifyReplacer)}`;
|
|
781
|
-
break;
|
|
782
|
-
case ZodIssueCode.unrecognized_keys:
|
|
783
|
-
message = `Unrecognized key(s) in object: ${util.joinValues(issue.keys, ", ")}`;
|
|
784
|
-
break;
|
|
785
|
-
case ZodIssueCode.invalid_union:
|
|
786
|
-
message = `Invalid input`;
|
|
787
|
-
break;
|
|
788
|
-
case ZodIssueCode.invalid_union_discriminator:
|
|
789
|
-
message = `Invalid discriminator value. Expected ${util.joinValues(issue.options)}`;
|
|
790
|
-
break;
|
|
791
|
-
case ZodIssueCode.invalid_enum_value:
|
|
792
|
-
message = `Invalid enum value. Expected ${util.joinValues(issue.options)}, received '${issue.received}'`;
|
|
793
|
-
break;
|
|
794
|
-
case ZodIssueCode.invalid_arguments:
|
|
795
|
-
message = `Invalid function arguments`;
|
|
796
|
-
break;
|
|
797
|
-
case ZodIssueCode.invalid_return_type:
|
|
798
|
-
message = `Invalid function return type`;
|
|
799
|
-
break;
|
|
800
|
-
case ZodIssueCode.invalid_date:
|
|
801
|
-
message = `Invalid date`;
|
|
802
|
-
break;
|
|
803
|
-
case ZodIssueCode.invalid_string:
|
|
804
|
-
if (typeof issue.validation === "object") {
|
|
805
|
-
if ("includes" in issue.validation) {
|
|
806
|
-
message = `Invalid input: must include "${issue.validation.includes}"`;
|
|
807
|
-
if (typeof issue.validation.position === "number") {
|
|
808
|
-
message = `${message} at one or more positions greater than or equal to ${issue.validation.position}`;
|
|
809
|
-
}
|
|
810
|
-
} else if ("startsWith" in issue.validation) {
|
|
811
|
-
message = `Invalid input: must start with "${issue.validation.startsWith}"`;
|
|
812
|
-
} else if ("endsWith" in issue.validation) {
|
|
813
|
-
message = `Invalid input: must end with "${issue.validation.endsWith}"`;
|
|
814
|
-
} else {
|
|
815
|
-
util.assertNever(issue.validation);
|
|
816
|
-
}
|
|
817
|
-
} else if (issue.validation !== "regex") {
|
|
818
|
-
message = `Invalid ${issue.validation}`;
|
|
819
|
-
} else {
|
|
820
|
-
message = "Invalid";
|
|
821
|
-
}
|
|
822
|
-
break;
|
|
823
|
-
case ZodIssueCode.too_small:
|
|
824
|
-
if (issue.type === "array")
|
|
825
|
-
message = `Array must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `more than`} ${issue.minimum} element(s)`;
|
|
826
|
-
else if (issue.type === "string")
|
|
827
|
-
message = `String must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `over`} ${issue.minimum} character(s)`;
|
|
828
|
-
else if (issue.type === "number")
|
|
829
|
-
message = `Number must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${issue.minimum}`;
|
|
830
|
-
else if (issue.type === "bigint")
|
|
831
|
-
message = `Number must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${issue.minimum}`;
|
|
832
|
-
else if (issue.type === "date")
|
|
833
|
-
message = `Date must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${new Date(Number(issue.minimum))}`;
|
|
834
|
-
else
|
|
835
|
-
message = "Invalid input";
|
|
836
|
-
break;
|
|
837
|
-
case ZodIssueCode.too_big:
|
|
838
|
-
if (issue.type === "array")
|
|
839
|
-
message = `Array must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `less than`} ${issue.maximum} element(s)`;
|
|
840
|
-
else if (issue.type === "string")
|
|
841
|
-
message = `String must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `under`} ${issue.maximum} character(s)`;
|
|
842
|
-
else if (issue.type === "number")
|
|
843
|
-
message = `Number must be ${issue.exact ? `exactly` : issue.inclusive ? `less than or equal to` : `less than`} ${issue.maximum}`;
|
|
844
|
-
else if (issue.type === "bigint")
|
|
845
|
-
message = `BigInt must be ${issue.exact ? `exactly` : issue.inclusive ? `less than or equal to` : `less than`} ${issue.maximum}`;
|
|
846
|
-
else if (issue.type === "date")
|
|
847
|
-
message = `Date must be ${issue.exact ? `exactly` : issue.inclusive ? `smaller than or equal to` : `smaller than`} ${new Date(Number(issue.maximum))}`;
|
|
848
|
-
else
|
|
849
|
-
message = "Invalid input";
|
|
850
|
-
break;
|
|
851
|
-
case ZodIssueCode.custom:
|
|
852
|
-
message = `Invalid input`;
|
|
853
|
-
break;
|
|
854
|
-
case ZodIssueCode.invalid_intersection_types:
|
|
855
|
-
message = `Intersection results could not be merged`;
|
|
856
|
-
break;
|
|
857
|
-
case ZodIssueCode.not_multiple_of:
|
|
858
|
-
message = `Number must be a multiple of ${issue.multipleOf}`;
|
|
859
|
-
break;
|
|
860
|
-
case ZodIssueCode.not_finite:
|
|
861
|
-
message = "Number must be finite";
|
|
862
|
-
break;
|
|
863
|
-
default:
|
|
864
|
-
message = _ctx.defaultError;
|
|
865
|
-
util.assertNever(issue);
|
|
866
|
-
}
|
|
867
|
-
return { message };
|
|
868
|
-
};
|
|
869
|
-
var en_default = errorMap;
|
|
870
|
-
|
|
871
|
-
// ../node_modules/zod/v3/errors.js
|
|
872
|
-
var overrideErrorMap = en_default;
|
|
873
|
-
function setErrorMap(map) {
|
|
874
|
-
overrideErrorMap = map;
|
|
875
|
-
}
|
|
876
|
-
function getErrorMap() {
|
|
877
|
-
return overrideErrorMap;
|
|
878
|
-
}
|
|
879
|
-
|
|
880
|
-
// ../node_modules/zod/v3/helpers/parseUtil.js
|
|
881
|
-
var makeIssue = (params) => {
|
|
882
|
-
const { data, path, errorMaps, issueData } = params;
|
|
883
|
-
const fullPath = [...path, ...issueData.path || []];
|
|
884
|
-
const fullIssue = {
|
|
885
|
-
...issueData,
|
|
886
|
-
path: fullPath
|
|
887
|
-
};
|
|
888
|
-
if (issueData.message !== void 0) {
|
|
889
|
-
return {
|
|
890
|
-
...issueData,
|
|
891
|
-
path: fullPath,
|
|
892
|
-
message: issueData.message
|
|
893
|
-
};
|
|
894
|
-
}
|
|
895
|
-
let errorMessage = "";
|
|
896
|
-
const maps = errorMaps.filter((m) => !!m).slice().reverse();
|
|
897
|
-
for (const map of maps) {
|
|
898
|
-
errorMessage = map(fullIssue, { data, defaultError: errorMessage }).message;
|
|
899
|
-
}
|
|
900
|
-
return {
|
|
901
|
-
...issueData,
|
|
902
|
-
path: fullPath,
|
|
903
|
-
message: errorMessage
|
|
904
|
-
};
|
|
905
|
-
};
|
|
906
|
-
var EMPTY_PATH = [];
|
|
907
|
-
function addIssueToContext(ctx, issueData) {
|
|
908
|
-
const overrideMap = getErrorMap();
|
|
909
|
-
const issue = makeIssue({
|
|
910
|
-
issueData,
|
|
911
|
-
data: ctx.data,
|
|
912
|
-
path: ctx.path,
|
|
913
|
-
errorMaps: [
|
|
914
|
-
ctx.common.contextualErrorMap,
|
|
915
|
-
// contextual error map is first priority
|
|
916
|
-
ctx.schemaErrorMap,
|
|
917
|
-
// then schema-bound map if available
|
|
918
|
-
overrideMap,
|
|
919
|
-
// then global override map
|
|
920
|
-
overrideMap === en_default ? void 0 : en_default
|
|
921
|
-
// then global default map
|
|
922
|
-
].filter((x) => !!x)
|
|
923
|
-
});
|
|
924
|
-
ctx.common.issues.push(issue);
|
|
925
|
-
}
|
|
926
|
-
var ParseStatus = class _ParseStatus {
|
|
927
|
-
constructor() {
|
|
928
|
-
this.value = "valid";
|
|
929
|
-
}
|
|
930
|
-
dirty() {
|
|
931
|
-
if (this.value === "valid")
|
|
932
|
-
this.value = "dirty";
|
|
933
|
-
}
|
|
934
|
-
abort() {
|
|
935
|
-
if (this.value !== "aborted")
|
|
936
|
-
this.value = "aborted";
|
|
937
|
-
}
|
|
938
|
-
static mergeArray(status, results) {
|
|
939
|
-
const arrayValue = [];
|
|
940
|
-
for (const s of results) {
|
|
941
|
-
if (s.status === "aborted")
|
|
942
|
-
return INVALID;
|
|
943
|
-
if (s.status === "dirty")
|
|
944
|
-
status.dirty();
|
|
945
|
-
arrayValue.push(s.value);
|
|
946
|
-
}
|
|
947
|
-
return { status: status.value, value: arrayValue };
|
|
948
|
-
}
|
|
949
|
-
static async mergeObjectAsync(status, pairs) {
|
|
950
|
-
const syncPairs = [];
|
|
951
|
-
for (const pair of pairs) {
|
|
952
|
-
const key = await pair.key;
|
|
953
|
-
const value = await pair.value;
|
|
954
|
-
syncPairs.push({
|
|
955
|
-
key,
|
|
956
|
-
value
|
|
957
|
-
});
|
|
958
|
-
}
|
|
959
|
-
return _ParseStatus.mergeObjectSync(status, syncPairs);
|
|
960
|
-
}
|
|
961
|
-
static mergeObjectSync(status, pairs) {
|
|
962
|
-
const finalObject = {};
|
|
963
|
-
for (const pair of pairs) {
|
|
964
|
-
const { key, value } = pair;
|
|
965
|
-
if (key.status === "aborted")
|
|
966
|
-
return INVALID;
|
|
967
|
-
if (value.status === "aborted")
|
|
968
|
-
return INVALID;
|
|
969
|
-
if (key.status === "dirty")
|
|
970
|
-
status.dirty();
|
|
971
|
-
if (value.status === "dirty")
|
|
972
|
-
status.dirty();
|
|
973
|
-
if (key.value !== "__proto__" && (typeof value.value !== "undefined" || pair.alwaysSet)) {
|
|
974
|
-
finalObject[key.value] = value.value;
|
|
975
|
-
}
|
|
976
|
-
}
|
|
977
|
-
return { status: status.value, value: finalObject };
|
|
978
|
-
}
|
|
979
|
-
};
|
|
980
|
-
var INVALID = Object.freeze({
|
|
981
|
-
status: "aborted"
|
|
982
|
-
});
|
|
983
|
-
var DIRTY = (value) => ({ status: "dirty", value });
|
|
984
|
-
var OK = (value) => ({ status: "valid", value });
|
|
985
|
-
var isAborted = (x) => x.status === "aborted";
|
|
986
|
-
var isDirty = (x) => x.status === "dirty";
|
|
987
|
-
var isValid = (x) => x.status === "valid";
|
|
988
|
-
var isAsync = (x) => typeof Promise !== "undefined" && x instanceof Promise;
|
|
989
|
-
|
|
990
|
-
// ../node_modules/zod/v3/helpers/errorUtil.js
|
|
991
|
-
var errorUtil;
|
|
992
|
-
(function(errorUtil2) {
|
|
993
|
-
errorUtil2.errToObj = (message) => typeof message === "string" ? { message } : message || {};
|
|
994
|
-
errorUtil2.toString = (message) => typeof message === "string" ? message : message?.message;
|
|
995
|
-
})(errorUtil || (errorUtil = {}));
|
|
996
|
-
|
|
997
|
-
// ../node_modules/zod/v3/types.js
|
|
998
|
-
var ParseInputLazyPath = class {
|
|
999
|
-
constructor(parent, value, path, key) {
|
|
1000
|
-
this._cachedPath = [];
|
|
1001
|
-
this.parent = parent;
|
|
1002
|
-
this.data = value;
|
|
1003
|
-
this._path = path;
|
|
1004
|
-
this._key = key;
|
|
1005
|
-
}
|
|
1006
|
-
get path() {
|
|
1007
|
-
if (!this._cachedPath.length) {
|
|
1008
|
-
if (Array.isArray(this._key)) {
|
|
1009
|
-
this._cachedPath.push(...this._path, ...this._key);
|
|
1010
|
-
} else {
|
|
1011
|
-
this._cachedPath.push(...this._path, this._key);
|
|
1012
|
-
}
|
|
1013
|
-
}
|
|
1014
|
-
return this._cachedPath;
|
|
1015
|
-
}
|
|
1016
|
-
};
|
|
1017
|
-
var handleResult = (ctx, result) => {
|
|
1018
|
-
if (isValid(result)) {
|
|
1019
|
-
return { success: true, data: result.value };
|
|
1020
|
-
} else {
|
|
1021
|
-
if (!ctx.common.issues.length) {
|
|
1022
|
-
throw new Error("Validation failed but no issues detected.");
|
|
1023
|
-
}
|
|
1024
|
-
return {
|
|
1025
|
-
success: false,
|
|
1026
|
-
get error() {
|
|
1027
|
-
if (this._error)
|
|
1028
|
-
return this._error;
|
|
1029
|
-
const error = new ZodError(ctx.common.issues);
|
|
1030
|
-
this._error = error;
|
|
1031
|
-
return this._error;
|
|
1032
|
-
}
|
|
1033
|
-
};
|
|
1034
|
-
}
|
|
1035
|
-
};
|
|
1036
|
-
function processCreateParams(params) {
|
|
1037
|
-
if (!params)
|
|
1038
|
-
return {};
|
|
1039
|
-
const { errorMap: errorMap2, invalid_type_error, required_error, description } = params;
|
|
1040
|
-
if (errorMap2 && (invalid_type_error || required_error)) {
|
|
1041
|
-
throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);
|
|
1042
|
-
}
|
|
1043
|
-
if (errorMap2)
|
|
1044
|
-
return { errorMap: errorMap2, description };
|
|
1045
|
-
const customMap = (iss, ctx) => {
|
|
1046
|
-
const { message } = params;
|
|
1047
|
-
if (iss.code === "invalid_enum_value") {
|
|
1048
|
-
return { message: message ?? ctx.defaultError };
|
|
1049
|
-
}
|
|
1050
|
-
if (typeof ctx.data === "undefined") {
|
|
1051
|
-
return { message: message ?? required_error ?? ctx.defaultError };
|
|
1052
|
-
}
|
|
1053
|
-
if (iss.code !== "invalid_type")
|
|
1054
|
-
return { message: ctx.defaultError };
|
|
1055
|
-
return { message: message ?? invalid_type_error ?? ctx.defaultError };
|
|
1056
|
-
};
|
|
1057
|
-
return { errorMap: customMap, description };
|
|
1058
|
-
}
|
|
1059
|
-
var ZodType = class {
|
|
1060
|
-
get description() {
|
|
1061
|
-
return this._def.description;
|
|
1062
|
-
}
|
|
1063
|
-
_getType(input) {
|
|
1064
|
-
return getParsedType(input.data);
|
|
1065
|
-
}
|
|
1066
|
-
_getOrReturnCtx(input, ctx) {
|
|
1067
|
-
return ctx || {
|
|
1068
|
-
common: input.parent.common,
|
|
1069
|
-
data: input.data,
|
|
1070
|
-
parsedType: getParsedType(input.data),
|
|
1071
|
-
schemaErrorMap: this._def.errorMap,
|
|
1072
|
-
path: input.path,
|
|
1073
|
-
parent: input.parent
|
|
1074
|
-
};
|
|
1075
|
-
}
|
|
1076
|
-
_processInputParams(input) {
|
|
1077
|
-
return {
|
|
1078
|
-
status: new ParseStatus(),
|
|
1079
|
-
ctx: {
|
|
1080
|
-
common: input.parent.common,
|
|
1081
|
-
data: input.data,
|
|
1082
|
-
parsedType: getParsedType(input.data),
|
|
1083
|
-
schemaErrorMap: this._def.errorMap,
|
|
1084
|
-
path: input.path,
|
|
1085
|
-
parent: input.parent
|
|
1086
|
-
}
|
|
1087
|
-
};
|
|
1088
|
-
}
|
|
1089
|
-
_parseSync(input) {
|
|
1090
|
-
const result = this._parse(input);
|
|
1091
|
-
if (isAsync(result)) {
|
|
1092
|
-
throw new Error("Synchronous parse encountered promise.");
|
|
1093
|
-
}
|
|
1094
|
-
return result;
|
|
1095
|
-
}
|
|
1096
|
-
_parseAsync(input) {
|
|
1097
|
-
const result = this._parse(input);
|
|
1098
|
-
return Promise.resolve(result);
|
|
1099
|
-
}
|
|
1100
|
-
parse(data, params) {
|
|
1101
|
-
const result = this.safeParse(data, params);
|
|
1102
|
-
if (result.success)
|
|
1103
|
-
return result.data;
|
|
1104
|
-
throw result.error;
|
|
1105
|
-
}
|
|
1106
|
-
safeParse(data, params) {
|
|
1107
|
-
const ctx = {
|
|
1108
|
-
common: {
|
|
1109
|
-
issues: [],
|
|
1110
|
-
async: params?.async ?? false,
|
|
1111
|
-
contextualErrorMap: params?.errorMap
|
|
1112
|
-
},
|
|
1113
|
-
path: params?.path || [],
|
|
1114
|
-
schemaErrorMap: this._def.errorMap,
|
|
1115
|
-
parent: null,
|
|
1116
|
-
data,
|
|
1117
|
-
parsedType: getParsedType(data)
|
|
1118
|
-
};
|
|
1119
|
-
const result = this._parseSync({ data, path: ctx.path, parent: ctx });
|
|
1120
|
-
return handleResult(ctx, result);
|
|
1121
|
-
}
|
|
1122
|
-
"~validate"(data) {
|
|
1123
|
-
const ctx = {
|
|
1124
|
-
common: {
|
|
1125
|
-
issues: [],
|
|
1126
|
-
async: !!this["~standard"].async
|
|
1127
|
-
},
|
|
1128
|
-
path: [],
|
|
1129
|
-
schemaErrorMap: this._def.errorMap,
|
|
1130
|
-
parent: null,
|
|
1131
|
-
data,
|
|
1132
|
-
parsedType: getParsedType(data)
|
|
1133
|
-
};
|
|
1134
|
-
if (!this["~standard"].async) {
|
|
1135
|
-
try {
|
|
1136
|
-
const result = this._parseSync({ data, path: [], parent: ctx });
|
|
1137
|
-
return isValid(result) ? {
|
|
1138
|
-
value: result.value
|
|
1139
|
-
} : {
|
|
1140
|
-
issues: ctx.common.issues
|
|
1141
|
-
};
|
|
1142
|
-
} catch (err) {
|
|
1143
|
-
if (err?.message?.toLowerCase()?.includes("encountered")) {
|
|
1144
|
-
this["~standard"].async = true;
|
|
1145
|
-
}
|
|
1146
|
-
ctx.common = {
|
|
1147
|
-
issues: [],
|
|
1148
|
-
async: true
|
|
1149
|
-
};
|
|
1150
|
-
}
|
|
1151
|
-
}
|
|
1152
|
-
return this._parseAsync({ data, path: [], parent: ctx }).then((result) => isValid(result) ? {
|
|
1153
|
-
value: result.value
|
|
1154
|
-
} : {
|
|
1155
|
-
issues: ctx.common.issues
|
|
1156
|
-
});
|
|
1157
|
-
}
|
|
1158
|
-
async parseAsync(data, params) {
|
|
1159
|
-
const result = await this.safeParseAsync(data, params);
|
|
1160
|
-
if (result.success)
|
|
1161
|
-
return result.data;
|
|
1162
|
-
throw result.error;
|
|
1163
|
-
}
|
|
1164
|
-
async safeParseAsync(data, params) {
|
|
1165
|
-
const ctx = {
|
|
1166
|
-
common: {
|
|
1167
|
-
issues: [],
|
|
1168
|
-
contextualErrorMap: params?.errorMap,
|
|
1169
|
-
async: true
|
|
1170
|
-
},
|
|
1171
|
-
path: params?.path || [],
|
|
1172
|
-
schemaErrorMap: this._def.errorMap,
|
|
1173
|
-
parent: null,
|
|
1174
|
-
data,
|
|
1175
|
-
parsedType: getParsedType(data)
|
|
1176
|
-
};
|
|
1177
|
-
const maybeAsyncResult = this._parse({ data, path: ctx.path, parent: ctx });
|
|
1178
|
-
const result = await (isAsync(maybeAsyncResult) ? maybeAsyncResult : Promise.resolve(maybeAsyncResult));
|
|
1179
|
-
return handleResult(ctx, result);
|
|
1180
|
-
}
|
|
1181
|
-
refine(check, message) {
|
|
1182
|
-
const getIssueProperties = (val) => {
|
|
1183
|
-
if (typeof message === "string" || typeof message === "undefined") {
|
|
1184
|
-
return { message };
|
|
1185
|
-
} else if (typeof message === "function") {
|
|
1186
|
-
return message(val);
|
|
1187
|
-
} else {
|
|
1188
|
-
return message;
|
|
1189
|
-
}
|
|
1190
|
-
};
|
|
1191
|
-
return this._refinement((val, ctx) => {
|
|
1192
|
-
const result = check(val);
|
|
1193
|
-
const setError = () => ctx.addIssue({
|
|
1194
|
-
code: ZodIssueCode.custom,
|
|
1195
|
-
...getIssueProperties(val)
|
|
1196
|
-
});
|
|
1197
|
-
if (typeof Promise !== "undefined" && result instanceof Promise) {
|
|
1198
|
-
return result.then((data) => {
|
|
1199
|
-
if (!data) {
|
|
1200
|
-
setError();
|
|
1201
|
-
return false;
|
|
1202
|
-
} else {
|
|
1203
|
-
return true;
|
|
1204
|
-
}
|
|
1205
|
-
});
|
|
1206
|
-
}
|
|
1207
|
-
if (!result) {
|
|
1208
|
-
setError();
|
|
1209
|
-
return false;
|
|
1210
|
-
} else {
|
|
1211
|
-
return true;
|
|
1212
|
-
}
|
|
1213
|
-
});
|
|
1214
|
-
}
|
|
1215
|
-
refinement(check, refinementData) {
|
|
1216
|
-
return this._refinement((val, ctx) => {
|
|
1217
|
-
if (!check(val)) {
|
|
1218
|
-
ctx.addIssue(typeof refinementData === "function" ? refinementData(val, ctx) : refinementData);
|
|
1219
|
-
return false;
|
|
1220
|
-
} else {
|
|
1221
|
-
return true;
|
|
1222
|
-
}
|
|
1223
|
-
});
|
|
1224
|
-
}
|
|
1225
|
-
_refinement(refinement) {
|
|
1226
|
-
return new ZodEffects({
|
|
1227
|
-
schema: this,
|
|
1228
|
-
typeName: ZodFirstPartyTypeKind.ZodEffects,
|
|
1229
|
-
effect: { type: "refinement", refinement }
|
|
1230
|
-
});
|
|
1231
|
-
}
|
|
1232
|
-
superRefine(refinement) {
|
|
1233
|
-
return this._refinement(refinement);
|
|
1234
|
-
}
|
|
1235
|
-
constructor(def) {
|
|
1236
|
-
this.spa = this.safeParseAsync;
|
|
1237
|
-
this._def = def;
|
|
1238
|
-
this.parse = this.parse.bind(this);
|
|
1239
|
-
this.safeParse = this.safeParse.bind(this);
|
|
1240
|
-
this.parseAsync = this.parseAsync.bind(this);
|
|
1241
|
-
this.safeParseAsync = this.safeParseAsync.bind(this);
|
|
1242
|
-
this.spa = this.spa.bind(this);
|
|
1243
|
-
this.refine = this.refine.bind(this);
|
|
1244
|
-
this.refinement = this.refinement.bind(this);
|
|
1245
|
-
this.superRefine = this.superRefine.bind(this);
|
|
1246
|
-
this.optional = this.optional.bind(this);
|
|
1247
|
-
this.nullable = this.nullable.bind(this);
|
|
1248
|
-
this.nullish = this.nullish.bind(this);
|
|
1249
|
-
this.array = this.array.bind(this);
|
|
1250
|
-
this.promise = this.promise.bind(this);
|
|
1251
|
-
this.or = this.or.bind(this);
|
|
1252
|
-
this.and = this.and.bind(this);
|
|
1253
|
-
this.transform = this.transform.bind(this);
|
|
1254
|
-
this.brand = this.brand.bind(this);
|
|
1255
|
-
this.default = this.default.bind(this);
|
|
1256
|
-
this.catch = this.catch.bind(this);
|
|
1257
|
-
this.describe = this.describe.bind(this);
|
|
1258
|
-
this.pipe = this.pipe.bind(this);
|
|
1259
|
-
this.readonly = this.readonly.bind(this);
|
|
1260
|
-
this.isNullable = this.isNullable.bind(this);
|
|
1261
|
-
this.isOptional = this.isOptional.bind(this);
|
|
1262
|
-
this["~standard"] = {
|
|
1263
|
-
version: 1,
|
|
1264
|
-
vendor: "zod",
|
|
1265
|
-
validate: (data) => this["~validate"](data)
|
|
1266
|
-
};
|
|
1267
|
-
}
|
|
1268
|
-
optional() {
|
|
1269
|
-
return ZodOptional.create(this, this._def);
|
|
1270
|
-
}
|
|
1271
|
-
nullable() {
|
|
1272
|
-
return ZodNullable.create(this, this._def);
|
|
1273
|
-
}
|
|
1274
|
-
nullish() {
|
|
1275
|
-
return this.nullable().optional();
|
|
1276
|
-
}
|
|
1277
|
-
array() {
|
|
1278
|
-
return ZodArray.create(this);
|
|
1279
|
-
}
|
|
1280
|
-
promise() {
|
|
1281
|
-
return ZodPromise.create(this, this._def);
|
|
1282
|
-
}
|
|
1283
|
-
or(option) {
|
|
1284
|
-
return ZodUnion.create([this, option], this._def);
|
|
1285
|
-
}
|
|
1286
|
-
and(incoming) {
|
|
1287
|
-
return ZodIntersection.create(this, incoming, this._def);
|
|
1288
|
-
}
|
|
1289
|
-
transform(transform) {
|
|
1290
|
-
return new ZodEffects({
|
|
1291
|
-
...processCreateParams(this._def),
|
|
1292
|
-
schema: this,
|
|
1293
|
-
typeName: ZodFirstPartyTypeKind.ZodEffects,
|
|
1294
|
-
effect: { type: "transform", transform }
|
|
1295
|
-
});
|
|
1296
|
-
}
|
|
1297
|
-
default(def) {
|
|
1298
|
-
const defaultValueFunc = typeof def === "function" ? def : () => def;
|
|
1299
|
-
return new ZodDefault({
|
|
1300
|
-
...processCreateParams(this._def),
|
|
1301
|
-
innerType: this,
|
|
1302
|
-
defaultValue: defaultValueFunc,
|
|
1303
|
-
typeName: ZodFirstPartyTypeKind.ZodDefault
|
|
1304
|
-
});
|
|
1305
|
-
}
|
|
1306
|
-
brand() {
|
|
1307
|
-
return new ZodBranded({
|
|
1308
|
-
typeName: ZodFirstPartyTypeKind.ZodBranded,
|
|
1309
|
-
type: this,
|
|
1310
|
-
...processCreateParams(this._def)
|
|
1311
|
-
});
|
|
1312
|
-
}
|
|
1313
|
-
catch(def) {
|
|
1314
|
-
const catchValueFunc = typeof def === "function" ? def : () => def;
|
|
1315
|
-
return new ZodCatch({
|
|
1316
|
-
...processCreateParams(this._def),
|
|
1317
|
-
innerType: this,
|
|
1318
|
-
catchValue: catchValueFunc,
|
|
1319
|
-
typeName: ZodFirstPartyTypeKind.ZodCatch
|
|
1320
|
-
});
|
|
1321
|
-
}
|
|
1322
|
-
describe(description) {
|
|
1323
|
-
const This = this.constructor;
|
|
1324
|
-
return new This({
|
|
1325
|
-
...this._def,
|
|
1326
|
-
description
|
|
1327
|
-
});
|
|
1328
|
-
}
|
|
1329
|
-
pipe(target) {
|
|
1330
|
-
return ZodPipeline.create(this, target);
|
|
1331
|
-
}
|
|
1332
|
-
readonly() {
|
|
1333
|
-
return ZodReadonly.create(this);
|
|
1334
|
-
}
|
|
1335
|
-
isOptional() {
|
|
1336
|
-
return this.safeParse(void 0).success;
|
|
1337
|
-
}
|
|
1338
|
-
isNullable() {
|
|
1339
|
-
return this.safeParse(null).success;
|
|
1340
|
-
}
|
|
1341
|
-
};
|
|
1342
|
-
var cuidRegex = /^c[^\s-]{8,}$/i;
|
|
1343
|
-
var cuid2Regex = /^[0-9a-z]+$/;
|
|
1344
|
-
var ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}$/i;
|
|
1345
|
-
var uuidRegex = /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i;
|
|
1346
|
-
var nanoidRegex = /^[a-z0-9_-]{21}$/i;
|
|
1347
|
-
var jwtRegex = /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/;
|
|
1348
|
-
var durationRegex = /^[-+]?P(?!$)(?:(?:[-+]?\d+Y)|(?:[-+]?\d+[.,]\d+Y$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:(?:[-+]?\d+W)|(?:[-+]?\d+[.,]\d+W$))?(?:(?:[-+]?\d+D)|(?:[-+]?\d+[.,]\d+D$))?(?:T(?=[\d+-])(?:(?:[-+]?\d+H)|(?:[-+]?\d+[.,]\d+H$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:[-+]?\d+(?:[.,]\d+)?S)?)??$/;
|
|
1349
|
-
var emailRegex = /^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;
|
|
1350
|
-
var _emojiRegex = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
|
|
1351
|
-
var emojiRegex;
|
|
1352
|
-
var ipv4Regex = /^(?:(?: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])$/;
|
|
1353
|
-
var ipv4CidrRegex = /^(?:(?: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])\/(3[0-2]|[12]?[0-9])$/;
|
|
1354
|
-
var ipv6Regex = /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/;
|
|
1355
|
-
var ipv6CidrRegex = /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/;
|
|
1356
|
-
var base64Regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/;
|
|
1357
|
-
var base64urlRegex = /^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/;
|
|
1358
|
-
var dateRegexSource = `((\\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])))`;
|
|
1359
|
-
var dateRegex = new RegExp(`^${dateRegexSource}$`);
|
|
1360
|
-
function timeRegexSource(args) {
|
|
1361
|
-
let secondsRegexSource = `[0-5]\\d`;
|
|
1362
|
-
if (args.precision) {
|
|
1363
|
-
secondsRegexSource = `${secondsRegexSource}\\.\\d{${args.precision}}`;
|
|
1364
|
-
} else if (args.precision == null) {
|
|
1365
|
-
secondsRegexSource = `${secondsRegexSource}(\\.\\d+)?`;
|
|
1366
|
-
}
|
|
1367
|
-
const secondsQuantifier = args.precision ? "+" : "?";
|
|
1368
|
-
return `([01]\\d|2[0-3]):[0-5]\\d(:${secondsRegexSource})${secondsQuantifier}`;
|
|
1369
|
-
}
|
|
1370
|
-
function timeRegex(args) {
|
|
1371
|
-
return new RegExp(`^${timeRegexSource(args)}$`);
|
|
1372
|
-
}
|
|
1373
|
-
function datetimeRegex(args) {
|
|
1374
|
-
let regex = `${dateRegexSource}T${timeRegexSource(args)}`;
|
|
1375
|
-
const opts = [];
|
|
1376
|
-
opts.push(args.local ? `Z?` : `Z`);
|
|
1377
|
-
if (args.offset)
|
|
1378
|
-
opts.push(`([+-]\\d{2}:?\\d{2})`);
|
|
1379
|
-
regex = `${regex}(${opts.join("|")})`;
|
|
1380
|
-
return new RegExp(`^${regex}$`);
|
|
1381
|
-
}
|
|
1382
|
-
function isValidIP(ip, version) {
|
|
1383
|
-
if ((version === "v4" || !version) && ipv4Regex.test(ip)) {
|
|
1384
|
-
return true;
|
|
1385
|
-
}
|
|
1386
|
-
if ((version === "v6" || !version) && ipv6Regex.test(ip)) {
|
|
1387
|
-
return true;
|
|
1388
|
-
}
|
|
1389
|
-
return false;
|
|
1390
|
-
}
|
|
1391
|
-
function isValidJWT(jwt, alg) {
|
|
1392
|
-
if (!jwtRegex.test(jwt))
|
|
1393
|
-
return false;
|
|
1394
|
-
try {
|
|
1395
|
-
const [header] = jwt.split(".");
|
|
1396
|
-
if (!header)
|
|
1397
|
-
return false;
|
|
1398
|
-
const base64 = header.replace(/-/g, "+").replace(/_/g, "/").padEnd(header.length + (4 - header.length % 4) % 4, "=");
|
|
1399
|
-
const decoded = JSON.parse(atob(base64));
|
|
1400
|
-
if (typeof decoded !== "object" || decoded === null)
|
|
1401
|
-
return false;
|
|
1402
|
-
if ("typ" in decoded && decoded?.typ !== "JWT")
|
|
1403
|
-
return false;
|
|
1404
|
-
if (!decoded.alg)
|
|
1405
|
-
return false;
|
|
1406
|
-
if (alg && decoded.alg !== alg)
|
|
1407
|
-
return false;
|
|
1408
|
-
return true;
|
|
1409
|
-
} catch {
|
|
1410
|
-
return false;
|
|
1411
|
-
}
|
|
1412
|
-
}
|
|
1413
|
-
function isValidCidr(ip, version) {
|
|
1414
|
-
if ((version === "v4" || !version) && ipv4CidrRegex.test(ip)) {
|
|
1415
|
-
return true;
|
|
1416
|
-
}
|
|
1417
|
-
if ((version === "v6" || !version) && ipv6CidrRegex.test(ip)) {
|
|
1418
|
-
return true;
|
|
1419
|
-
}
|
|
1420
|
-
return false;
|
|
1421
|
-
}
|
|
1422
|
-
var ZodString = class _ZodString extends ZodType {
|
|
1423
|
-
_parse(input) {
|
|
1424
|
-
if (this._def.coerce) {
|
|
1425
|
-
input.data = String(input.data);
|
|
1426
|
-
}
|
|
1427
|
-
const parsedType = this._getType(input);
|
|
1428
|
-
if (parsedType !== ZodParsedType.string) {
|
|
1429
|
-
const ctx2 = this._getOrReturnCtx(input);
|
|
1430
|
-
addIssueToContext(ctx2, {
|
|
1431
|
-
code: ZodIssueCode.invalid_type,
|
|
1432
|
-
expected: ZodParsedType.string,
|
|
1433
|
-
received: ctx2.parsedType
|
|
1434
|
-
});
|
|
1435
|
-
return INVALID;
|
|
1436
|
-
}
|
|
1437
|
-
const status = new ParseStatus();
|
|
1438
|
-
let ctx = void 0;
|
|
1439
|
-
for (const check of this._def.checks) {
|
|
1440
|
-
if (check.kind === "min") {
|
|
1441
|
-
if (input.data.length < check.value) {
|
|
1442
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1443
|
-
addIssueToContext(ctx, {
|
|
1444
|
-
code: ZodIssueCode.too_small,
|
|
1445
|
-
minimum: check.value,
|
|
1446
|
-
type: "string",
|
|
1447
|
-
inclusive: true,
|
|
1448
|
-
exact: false,
|
|
1449
|
-
message: check.message
|
|
1450
|
-
});
|
|
1451
|
-
status.dirty();
|
|
1452
|
-
}
|
|
1453
|
-
} else if (check.kind === "max") {
|
|
1454
|
-
if (input.data.length > check.value) {
|
|
1455
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1456
|
-
addIssueToContext(ctx, {
|
|
1457
|
-
code: ZodIssueCode.too_big,
|
|
1458
|
-
maximum: check.value,
|
|
1459
|
-
type: "string",
|
|
1460
|
-
inclusive: true,
|
|
1461
|
-
exact: false,
|
|
1462
|
-
message: check.message
|
|
1463
|
-
});
|
|
1464
|
-
status.dirty();
|
|
1465
|
-
}
|
|
1466
|
-
} else if (check.kind === "length") {
|
|
1467
|
-
const tooBig = input.data.length > check.value;
|
|
1468
|
-
const tooSmall = input.data.length < check.value;
|
|
1469
|
-
if (tooBig || tooSmall) {
|
|
1470
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1471
|
-
if (tooBig) {
|
|
1472
|
-
addIssueToContext(ctx, {
|
|
1473
|
-
code: ZodIssueCode.too_big,
|
|
1474
|
-
maximum: check.value,
|
|
1475
|
-
type: "string",
|
|
1476
|
-
inclusive: true,
|
|
1477
|
-
exact: true,
|
|
1478
|
-
message: check.message
|
|
1479
|
-
});
|
|
1480
|
-
} else if (tooSmall) {
|
|
1481
|
-
addIssueToContext(ctx, {
|
|
1482
|
-
code: ZodIssueCode.too_small,
|
|
1483
|
-
minimum: check.value,
|
|
1484
|
-
type: "string",
|
|
1485
|
-
inclusive: true,
|
|
1486
|
-
exact: true,
|
|
1487
|
-
message: check.message
|
|
1488
|
-
});
|
|
1489
|
-
}
|
|
1490
|
-
status.dirty();
|
|
1491
|
-
}
|
|
1492
|
-
} else if (check.kind === "email") {
|
|
1493
|
-
if (!emailRegex.test(input.data)) {
|
|
1494
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1495
|
-
addIssueToContext(ctx, {
|
|
1496
|
-
validation: "email",
|
|
1497
|
-
code: ZodIssueCode.invalid_string,
|
|
1498
|
-
message: check.message
|
|
1499
|
-
});
|
|
1500
|
-
status.dirty();
|
|
1501
|
-
}
|
|
1502
|
-
} else if (check.kind === "emoji") {
|
|
1503
|
-
if (!emojiRegex) {
|
|
1504
|
-
emojiRegex = new RegExp(_emojiRegex, "u");
|
|
1505
|
-
}
|
|
1506
|
-
if (!emojiRegex.test(input.data)) {
|
|
1507
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1508
|
-
addIssueToContext(ctx, {
|
|
1509
|
-
validation: "emoji",
|
|
1510
|
-
code: ZodIssueCode.invalid_string,
|
|
1511
|
-
message: check.message
|
|
1512
|
-
});
|
|
1513
|
-
status.dirty();
|
|
1514
|
-
}
|
|
1515
|
-
} else if (check.kind === "uuid") {
|
|
1516
|
-
if (!uuidRegex.test(input.data)) {
|
|
1517
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1518
|
-
addIssueToContext(ctx, {
|
|
1519
|
-
validation: "uuid",
|
|
1520
|
-
code: ZodIssueCode.invalid_string,
|
|
1521
|
-
message: check.message
|
|
1522
|
-
});
|
|
1523
|
-
status.dirty();
|
|
1524
|
-
}
|
|
1525
|
-
} else if (check.kind === "nanoid") {
|
|
1526
|
-
if (!nanoidRegex.test(input.data)) {
|
|
1527
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1528
|
-
addIssueToContext(ctx, {
|
|
1529
|
-
validation: "nanoid",
|
|
1530
|
-
code: ZodIssueCode.invalid_string,
|
|
1531
|
-
message: check.message
|
|
1532
|
-
});
|
|
1533
|
-
status.dirty();
|
|
1534
|
-
}
|
|
1535
|
-
} else if (check.kind === "cuid") {
|
|
1536
|
-
if (!cuidRegex.test(input.data)) {
|
|
1537
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1538
|
-
addIssueToContext(ctx, {
|
|
1539
|
-
validation: "cuid",
|
|
1540
|
-
code: ZodIssueCode.invalid_string,
|
|
1541
|
-
message: check.message
|
|
1542
|
-
});
|
|
1543
|
-
status.dirty();
|
|
1544
|
-
}
|
|
1545
|
-
} else if (check.kind === "cuid2") {
|
|
1546
|
-
if (!cuid2Regex.test(input.data)) {
|
|
1547
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1548
|
-
addIssueToContext(ctx, {
|
|
1549
|
-
validation: "cuid2",
|
|
1550
|
-
code: ZodIssueCode.invalid_string,
|
|
1551
|
-
message: check.message
|
|
1552
|
-
});
|
|
1553
|
-
status.dirty();
|
|
1554
|
-
}
|
|
1555
|
-
} else if (check.kind === "ulid") {
|
|
1556
|
-
if (!ulidRegex.test(input.data)) {
|
|
1557
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1558
|
-
addIssueToContext(ctx, {
|
|
1559
|
-
validation: "ulid",
|
|
1560
|
-
code: ZodIssueCode.invalid_string,
|
|
1561
|
-
message: check.message
|
|
1562
|
-
});
|
|
1563
|
-
status.dirty();
|
|
1564
|
-
}
|
|
1565
|
-
} else if (check.kind === "url") {
|
|
1566
|
-
try {
|
|
1567
|
-
new URL(input.data);
|
|
1568
|
-
} catch {
|
|
1569
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1570
|
-
addIssueToContext(ctx, {
|
|
1571
|
-
validation: "url",
|
|
1572
|
-
code: ZodIssueCode.invalid_string,
|
|
1573
|
-
message: check.message
|
|
1574
|
-
});
|
|
1575
|
-
status.dirty();
|
|
1576
|
-
}
|
|
1577
|
-
} else if (check.kind === "regex") {
|
|
1578
|
-
check.regex.lastIndex = 0;
|
|
1579
|
-
const testResult = check.regex.test(input.data);
|
|
1580
|
-
if (!testResult) {
|
|
1581
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1582
|
-
addIssueToContext(ctx, {
|
|
1583
|
-
validation: "regex",
|
|
1584
|
-
code: ZodIssueCode.invalid_string,
|
|
1585
|
-
message: check.message
|
|
1586
|
-
});
|
|
1587
|
-
status.dirty();
|
|
1588
|
-
}
|
|
1589
|
-
} else if (check.kind === "trim") {
|
|
1590
|
-
input.data = input.data.trim();
|
|
1591
|
-
} else if (check.kind === "includes") {
|
|
1592
|
-
if (!input.data.includes(check.value, check.position)) {
|
|
1593
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1594
|
-
addIssueToContext(ctx, {
|
|
1595
|
-
code: ZodIssueCode.invalid_string,
|
|
1596
|
-
validation: { includes: check.value, position: check.position },
|
|
1597
|
-
message: check.message
|
|
1598
|
-
});
|
|
1599
|
-
status.dirty();
|
|
1600
|
-
}
|
|
1601
|
-
} else if (check.kind === "toLowerCase") {
|
|
1602
|
-
input.data = input.data.toLowerCase();
|
|
1603
|
-
} else if (check.kind === "toUpperCase") {
|
|
1604
|
-
input.data = input.data.toUpperCase();
|
|
1605
|
-
} else if (check.kind === "startsWith") {
|
|
1606
|
-
if (!input.data.startsWith(check.value)) {
|
|
1607
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1608
|
-
addIssueToContext(ctx, {
|
|
1609
|
-
code: ZodIssueCode.invalid_string,
|
|
1610
|
-
validation: { startsWith: check.value },
|
|
1611
|
-
message: check.message
|
|
1612
|
-
});
|
|
1613
|
-
status.dirty();
|
|
1614
|
-
}
|
|
1615
|
-
} else if (check.kind === "endsWith") {
|
|
1616
|
-
if (!input.data.endsWith(check.value)) {
|
|
1617
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1618
|
-
addIssueToContext(ctx, {
|
|
1619
|
-
code: ZodIssueCode.invalid_string,
|
|
1620
|
-
validation: { endsWith: check.value },
|
|
1621
|
-
message: check.message
|
|
1622
|
-
});
|
|
1623
|
-
status.dirty();
|
|
1624
|
-
}
|
|
1625
|
-
} else if (check.kind === "datetime") {
|
|
1626
|
-
const regex = datetimeRegex(check);
|
|
1627
|
-
if (!regex.test(input.data)) {
|
|
1628
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1629
|
-
addIssueToContext(ctx, {
|
|
1630
|
-
code: ZodIssueCode.invalid_string,
|
|
1631
|
-
validation: "datetime",
|
|
1632
|
-
message: check.message
|
|
1633
|
-
});
|
|
1634
|
-
status.dirty();
|
|
1635
|
-
}
|
|
1636
|
-
} else if (check.kind === "date") {
|
|
1637
|
-
const regex = dateRegex;
|
|
1638
|
-
if (!regex.test(input.data)) {
|
|
1639
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1640
|
-
addIssueToContext(ctx, {
|
|
1641
|
-
code: ZodIssueCode.invalid_string,
|
|
1642
|
-
validation: "date",
|
|
1643
|
-
message: check.message
|
|
1644
|
-
});
|
|
1645
|
-
status.dirty();
|
|
1646
|
-
}
|
|
1647
|
-
} else if (check.kind === "time") {
|
|
1648
|
-
const regex = timeRegex(check);
|
|
1649
|
-
if (!regex.test(input.data)) {
|
|
1650
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1651
|
-
addIssueToContext(ctx, {
|
|
1652
|
-
code: ZodIssueCode.invalid_string,
|
|
1653
|
-
validation: "time",
|
|
1654
|
-
message: check.message
|
|
1655
|
-
});
|
|
1656
|
-
status.dirty();
|
|
1657
|
-
}
|
|
1658
|
-
} else if (check.kind === "duration") {
|
|
1659
|
-
if (!durationRegex.test(input.data)) {
|
|
1660
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1661
|
-
addIssueToContext(ctx, {
|
|
1662
|
-
validation: "duration",
|
|
1663
|
-
code: ZodIssueCode.invalid_string,
|
|
1664
|
-
message: check.message
|
|
1665
|
-
});
|
|
1666
|
-
status.dirty();
|
|
1667
|
-
}
|
|
1668
|
-
} else if (check.kind === "ip") {
|
|
1669
|
-
if (!isValidIP(input.data, check.version)) {
|
|
1670
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1671
|
-
addIssueToContext(ctx, {
|
|
1672
|
-
validation: "ip",
|
|
1673
|
-
code: ZodIssueCode.invalid_string,
|
|
1674
|
-
message: check.message
|
|
1675
|
-
});
|
|
1676
|
-
status.dirty();
|
|
1677
|
-
}
|
|
1678
|
-
} else if (check.kind === "jwt") {
|
|
1679
|
-
if (!isValidJWT(input.data, check.alg)) {
|
|
1680
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1681
|
-
addIssueToContext(ctx, {
|
|
1682
|
-
validation: "jwt",
|
|
1683
|
-
code: ZodIssueCode.invalid_string,
|
|
1684
|
-
message: check.message
|
|
1685
|
-
});
|
|
1686
|
-
status.dirty();
|
|
1687
|
-
}
|
|
1688
|
-
} else if (check.kind === "cidr") {
|
|
1689
|
-
if (!isValidCidr(input.data, check.version)) {
|
|
1690
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1691
|
-
addIssueToContext(ctx, {
|
|
1692
|
-
validation: "cidr",
|
|
1693
|
-
code: ZodIssueCode.invalid_string,
|
|
1694
|
-
message: check.message
|
|
1695
|
-
});
|
|
1696
|
-
status.dirty();
|
|
1697
|
-
}
|
|
1698
|
-
} else if (check.kind === "base64") {
|
|
1699
|
-
if (!base64Regex.test(input.data)) {
|
|
1700
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1701
|
-
addIssueToContext(ctx, {
|
|
1702
|
-
validation: "base64",
|
|
1703
|
-
code: ZodIssueCode.invalid_string,
|
|
1704
|
-
message: check.message
|
|
1705
|
-
});
|
|
1706
|
-
status.dirty();
|
|
1707
|
-
}
|
|
1708
|
-
} else if (check.kind === "base64url") {
|
|
1709
|
-
if (!base64urlRegex.test(input.data)) {
|
|
1710
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1711
|
-
addIssueToContext(ctx, {
|
|
1712
|
-
validation: "base64url",
|
|
1713
|
-
code: ZodIssueCode.invalid_string,
|
|
1714
|
-
message: check.message
|
|
1715
|
-
});
|
|
1716
|
-
status.dirty();
|
|
1717
|
-
}
|
|
1718
|
-
} else {
|
|
1719
|
-
util.assertNever(check);
|
|
1720
|
-
}
|
|
1721
|
-
}
|
|
1722
|
-
return { status: status.value, value: input.data };
|
|
1723
|
-
}
|
|
1724
|
-
_regex(regex, validation, message) {
|
|
1725
|
-
return this.refinement((data) => regex.test(data), {
|
|
1726
|
-
validation,
|
|
1727
|
-
code: ZodIssueCode.invalid_string,
|
|
1728
|
-
...errorUtil.errToObj(message)
|
|
1729
|
-
});
|
|
1730
|
-
}
|
|
1731
|
-
_addCheck(check) {
|
|
1732
|
-
return new _ZodString({
|
|
1733
|
-
...this._def,
|
|
1734
|
-
checks: [...this._def.checks, check]
|
|
1735
|
-
});
|
|
1736
|
-
}
|
|
1737
|
-
email(message) {
|
|
1738
|
-
return this._addCheck({ kind: "email", ...errorUtil.errToObj(message) });
|
|
1739
|
-
}
|
|
1740
|
-
url(message) {
|
|
1741
|
-
return this._addCheck({ kind: "url", ...errorUtil.errToObj(message) });
|
|
1742
|
-
}
|
|
1743
|
-
emoji(message) {
|
|
1744
|
-
return this._addCheck({ kind: "emoji", ...errorUtil.errToObj(message) });
|
|
1745
|
-
}
|
|
1746
|
-
uuid(message) {
|
|
1747
|
-
return this._addCheck({ kind: "uuid", ...errorUtil.errToObj(message) });
|
|
1748
|
-
}
|
|
1749
|
-
nanoid(message) {
|
|
1750
|
-
return this._addCheck({ kind: "nanoid", ...errorUtil.errToObj(message) });
|
|
1751
|
-
}
|
|
1752
|
-
cuid(message) {
|
|
1753
|
-
return this._addCheck({ kind: "cuid", ...errorUtil.errToObj(message) });
|
|
1754
|
-
}
|
|
1755
|
-
cuid2(message) {
|
|
1756
|
-
return this._addCheck({ kind: "cuid2", ...errorUtil.errToObj(message) });
|
|
1757
|
-
}
|
|
1758
|
-
ulid(message) {
|
|
1759
|
-
return this._addCheck({ kind: "ulid", ...errorUtil.errToObj(message) });
|
|
1760
|
-
}
|
|
1761
|
-
base64(message) {
|
|
1762
|
-
return this._addCheck({ kind: "base64", ...errorUtil.errToObj(message) });
|
|
1763
|
-
}
|
|
1764
|
-
base64url(message) {
|
|
1765
|
-
return this._addCheck({
|
|
1766
|
-
kind: "base64url",
|
|
1767
|
-
...errorUtil.errToObj(message)
|
|
1768
|
-
});
|
|
1769
|
-
}
|
|
1770
|
-
jwt(options) {
|
|
1771
|
-
return this._addCheck({ kind: "jwt", ...errorUtil.errToObj(options) });
|
|
1772
|
-
}
|
|
1773
|
-
ip(options) {
|
|
1774
|
-
return this._addCheck({ kind: "ip", ...errorUtil.errToObj(options) });
|
|
1775
|
-
}
|
|
1776
|
-
cidr(options) {
|
|
1777
|
-
return this._addCheck({ kind: "cidr", ...errorUtil.errToObj(options) });
|
|
1778
|
-
}
|
|
1779
|
-
datetime(options) {
|
|
1780
|
-
if (typeof options === "string") {
|
|
1781
|
-
return this._addCheck({
|
|
1782
|
-
kind: "datetime",
|
|
1783
|
-
precision: null,
|
|
1784
|
-
offset: false,
|
|
1785
|
-
local: false,
|
|
1786
|
-
message: options
|
|
1787
|
-
});
|
|
1788
|
-
}
|
|
1789
|
-
return this._addCheck({
|
|
1790
|
-
kind: "datetime",
|
|
1791
|
-
precision: typeof options?.precision === "undefined" ? null : options?.precision,
|
|
1792
|
-
offset: options?.offset ?? false,
|
|
1793
|
-
local: options?.local ?? false,
|
|
1794
|
-
...errorUtil.errToObj(options?.message)
|
|
1795
|
-
});
|
|
1796
|
-
}
|
|
1797
|
-
date(message) {
|
|
1798
|
-
return this._addCheck({ kind: "date", message });
|
|
1799
|
-
}
|
|
1800
|
-
time(options) {
|
|
1801
|
-
if (typeof options === "string") {
|
|
1802
|
-
return this._addCheck({
|
|
1803
|
-
kind: "time",
|
|
1804
|
-
precision: null,
|
|
1805
|
-
message: options
|
|
1806
|
-
});
|
|
1807
|
-
}
|
|
1808
|
-
return this._addCheck({
|
|
1809
|
-
kind: "time",
|
|
1810
|
-
precision: typeof options?.precision === "undefined" ? null : options?.precision,
|
|
1811
|
-
...errorUtil.errToObj(options?.message)
|
|
1812
|
-
});
|
|
1813
|
-
}
|
|
1814
|
-
duration(message) {
|
|
1815
|
-
return this._addCheck({ kind: "duration", ...errorUtil.errToObj(message) });
|
|
1816
|
-
}
|
|
1817
|
-
regex(regex, message) {
|
|
1818
|
-
return this._addCheck({
|
|
1819
|
-
kind: "regex",
|
|
1820
|
-
regex,
|
|
1821
|
-
...errorUtil.errToObj(message)
|
|
1822
|
-
});
|
|
1823
|
-
}
|
|
1824
|
-
includes(value, options) {
|
|
1825
|
-
return this._addCheck({
|
|
1826
|
-
kind: "includes",
|
|
1827
|
-
value,
|
|
1828
|
-
position: options?.position,
|
|
1829
|
-
...errorUtil.errToObj(options?.message)
|
|
1830
|
-
});
|
|
1831
|
-
}
|
|
1832
|
-
startsWith(value, message) {
|
|
1833
|
-
return this._addCheck({
|
|
1834
|
-
kind: "startsWith",
|
|
1835
|
-
value,
|
|
1836
|
-
...errorUtil.errToObj(message)
|
|
1837
|
-
});
|
|
1838
|
-
}
|
|
1839
|
-
endsWith(value, message) {
|
|
1840
|
-
return this._addCheck({
|
|
1841
|
-
kind: "endsWith",
|
|
1842
|
-
value,
|
|
1843
|
-
...errorUtil.errToObj(message)
|
|
1844
|
-
});
|
|
1845
|
-
}
|
|
1846
|
-
min(minLength, message) {
|
|
1847
|
-
return this._addCheck({
|
|
1848
|
-
kind: "min",
|
|
1849
|
-
value: minLength,
|
|
1850
|
-
...errorUtil.errToObj(message)
|
|
1851
|
-
});
|
|
1852
|
-
}
|
|
1853
|
-
max(maxLength, message) {
|
|
1854
|
-
return this._addCheck({
|
|
1855
|
-
kind: "max",
|
|
1856
|
-
value: maxLength,
|
|
1857
|
-
...errorUtil.errToObj(message)
|
|
1858
|
-
});
|
|
1859
|
-
}
|
|
1860
|
-
length(len, message) {
|
|
1861
|
-
return this._addCheck({
|
|
1862
|
-
kind: "length",
|
|
1863
|
-
value: len,
|
|
1864
|
-
...errorUtil.errToObj(message)
|
|
1865
|
-
});
|
|
1866
|
-
}
|
|
1867
|
-
/**
|
|
1868
|
-
* Equivalent to `.min(1)`
|
|
1869
|
-
*/
|
|
1870
|
-
nonempty(message) {
|
|
1871
|
-
return this.min(1, errorUtil.errToObj(message));
|
|
1872
|
-
}
|
|
1873
|
-
trim() {
|
|
1874
|
-
return new _ZodString({
|
|
1875
|
-
...this._def,
|
|
1876
|
-
checks: [...this._def.checks, { kind: "trim" }]
|
|
1877
|
-
});
|
|
1878
|
-
}
|
|
1879
|
-
toLowerCase() {
|
|
1880
|
-
return new _ZodString({
|
|
1881
|
-
...this._def,
|
|
1882
|
-
checks: [...this._def.checks, { kind: "toLowerCase" }]
|
|
1883
|
-
});
|
|
1884
|
-
}
|
|
1885
|
-
toUpperCase() {
|
|
1886
|
-
return new _ZodString({
|
|
1887
|
-
...this._def,
|
|
1888
|
-
checks: [...this._def.checks, { kind: "toUpperCase" }]
|
|
1889
|
-
});
|
|
1890
|
-
}
|
|
1891
|
-
get isDatetime() {
|
|
1892
|
-
return !!this._def.checks.find((ch) => ch.kind === "datetime");
|
|
1893
|
-
}
|
|
1894
|
-
get isDate() {
|
|
1895
|
-
return !!this._def.checks.find((ch) => ch.kind === "date");
|
|
1896
|
-
}
|
|
1897
|
-
get isTime() {
|
|
1898
|
-
return !!this._def.checks.find((ch) => ch.kind === "time");
|
|
1899
|
-
}
|
|
1900
|
-
get isDuration() {
|
|
1901
|
-
return !!this._def.checks.find((ch) => ch.kind === "duration");
|
|
1902
|
-
}
|
|
1903
|
-
get isEmail() {
|
|
1904
|
-
return !!this._def.checks.find((ch) => ch.kind === "email");
|
|
1905
|
-
}
|
|
1906
|
-
get isURL() {
|
|
1907
|
-
return !!this._def.checks.find((ch) => ch.kind === "url");
|
|
1908
|
-
}
|
|
1909
|
-
get isEmoji() {
|
|
1910
|
-
return !!this._def.checks.find((ch) => ch.kind === "emoji");
|
|
1911
|
-
}
|
|
1912
|
-
get isUUID() {
|
|
1913
|
-
return !!this._def.checks.find((ch) => ch.kind === "uuid");
|
|
1914
|
-
}
|
|
1915
|
-
get isNANOID() {
|
|
1916
|
-
return !!this._def.checks.find((ch) => ch.kind === "nanoid");
|
|
1917
|
-
}
|
|
1918
|
-
get isCUID() {
|
|
1919
|
-
return !!this._def.checks.find((ch) => ch.kind === "cuid");
|
|
1920
|
-
}
|
|
1921
|
-
get isCUID2() {
|
|
1922
|
-
return !!this._def.checks.find((ch) => ch.kind === "cuid2");
|
|
1923
|
-
}
|
|
1924
|
-
get isULID() {
|
|
1925
|
-
return !!this._def.checks.find((ch) => ch.kind === "ulid");
|
|
1926
|
-
}
|
|
1927
|
-
get isIP() {
|
|
1928
|
-
return !!this._def.checks.find((ch) => ch.kind === "ip");
|
|
1929
|
-
}
|
|
1930
|
-
get isCIDR() {
|
|
1931
|
-
return !!this._def.checks.find((ch) => ch.kind === "cidr");
|
|
1932
|
-
}
|
|
1933
|
-
get isBase64() {
|
|
1934
|
-
return !!this._def.checks.find((ch) => ch.kind === "base64");
|
|
1935
|
-
}
|
|
1936
|
-
get isBase64url() {
|
|
1937
|
-
return !!this._def.checks.find((ch) => ch.kind === "base64url");
|
|
1938
|
-
}
|
|
1939
|
-
get minLength() {
|
|
1940
|
-
let min = null;
|
|
1941
|
-
for (const ch of this._def.checks) {
|
|
1942
|
-
if (ch.kind === "min") {
|
|
1943
|
-
if (min === null || ch.value > min)
|
|
1944
|
-
min = ch.value;
|
|
1945
|
-
}
|
|
1946
|
-
}
|
|
1947
|
-
return min;
|
|
1948
|
-
}
|
|
1949
|
-
get maxLength() {
|
|
1950
|
-
let max = null;
|
|
1951
|
-
for (const ch of this._def.checks) {
|
|
1952
|
-
if (ch.kind === "max") {
|
|
1953
|
-
if (max === null || ch.value < max)
|
|
1954
|
-
max = ch.value;
|
|
1955
|
-
}
|
|
1956
|
-
}
|
|
1957
|
-
return max;
|
|
1958
|
-
}
|
|
1959
|
-
};
|
|
1960
|
-
ZodString.create = (params) => {
|
|
1961
|
-
return new ZodString({
|
|
1962
|
-
checks: [],
|
|
1963
|
-
typeName: ZodFirstPartyTypeKind.ZodString,
|
|
1964
|
-
coerce: params?.coerce ?? false,
|
|
1965
|
-
...processCreateParams(params)
|
|
1966
|
-
});
|
|
1967
|
-
};
|
|
1968
|
-
function floatSafeRemainder(val, step) {
|
|
1969
|
-
const valDecCount = (val.toString().split(".")[1] || "").length;
|
|
1970
|
-
const stepDecCount = (step.toString().split(".")[1] || "").length;
|
|
1971
|
-
const decCount = valDecCount > stepDecCount ? valDecCount : stepDecCount;
|
|
1972
|
-
const valInt = Number.parseInt(val.toFixed(decCount).replace(".", ""));
|
|
1973
|
-
const stepInt = Number.parseInt(step.toFixed(decCount).replace(".", ""));
|
|
1974
|
-
return valInt % stepInt / 10 ** decCount;
|
|
1975
|
-
}
|
|
1976
|
-
var ZodNumber = class _ZodNumber extends ZodType {
|
|
1977
|
-
constructor() {
|
|
1978
|
-
super(...arguments);
|
|
1979
|
-
this.min = this.gte;
|
|
1980
|
-
this.max = this.lte;
|
|
1981
|
-
this.step = this.multipleOf;
|
|
1982
|
-
}
|
|
1983
|
-
_parse(input) {
|
|
1984
|
-
if (this._def.coerce) {
|
|
1985
|
-
input.data = Number(input.data);
|
|
1986
|
-
}
|
|
1987
|
-
const parsedType = this._getType(input);
|
|
1988
|
-
if (parsedType !== ZodParsedType.number) {
|
|
1989
|
-
const ctx2 = this._getOrReturnCtx(input);
|
|
1990
|
-
addIssueToContext(ctx2, {
|
|
1991
|
-
code: ZodIssueCode.invalid_type,
|
|
1992
|
-
expected: ZodParsedType.number,
|
|
1993
|
-
received: ctx2.parsedType
|
|
1994
|
-
});
|
|
1995
|
-
return INVALID;
|
|
1996
|
-
}
|
|
1997
|
-
let ctx = void 0;
|
|
1998
|
-
const status = new ParseStatus();
|
|
1999
|
-
for (const check of this._def.checks) {
|
|
2000
|
-
if (check.kind === "int") {
|
|
2001
|
-
if (!util.isInteger(input.data)) {
|
|
2002
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
2003
|
-
addIssueToContext(ctx, {
|
|
2004
|
-
code: ZodIssueCode.invalid_type,
|
|
2005
|
-
expected: "integer",
|
|
2006
|
-
received: "float",
|
|
2007
|
-
message: check.message
|
|
2008
|
-
});
|
|
2009
|
-
status.dirty();
|
|
2010
|
-
}
|
|
2011
|
-
} else if (check.kind === "min") {
|
|
2012
|
-
const tooSmall = check.inclusive ? input.data < check.value : input.data <= check.value;
|
|
2013
|
-
if (tooSmall) {
|
|
2014
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
2015
|
-
addIssueToContext(ctx, {
|
|
2016
|
-
code: ZodIssueCode.too_small,
|
|
2017
|
-
minimum: check.value,
|
|
2018
|
-
type: "number",
|
|
2019
|
-
inclusive: check.inclusive,
|
|
2020
|
-
exact: false,
|
|
2021
|
-
message: check.message
|
|
2022
|
-
});
|
|
2023
|
-
status.dirty();
|
|
2024
|
-
}
|
|
2025
|
-
} else if (check.kind === "max") {
|
|
2026
|
-
const tooBig = check.inclusive ? input.data > check.value : input.data >= check.value;
|
|
2027
|
-
if (tooBig) {
|
|
2028
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
2029
|
-
addIssueToContext(ctx, {
|
|
2030
|
-
code: ZodIssueCode.too_big,
|
|
2031
|
-
maximum: check.value,
|
|
2032
|
-
type: "number",
|
|
2033
|
-
inclusive: check.inclusive,
|
|
2034
|
-
exact: false,
|
|
2035
|
-
message: check.message
|
|
2036
|
-
});
|
|
2037
|
-
status.dirty();
|
|
2038
|
-
}
|
|
2039
|
-
} else if (check.kind === "multipleOf") {
|
|
2040
|
-
if (floatSafeRemainder(input.data, check.value) !== 0) {
|
|
2041
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
2042
|
-
addIssueToContext(ctx, {
|
|
2043
|
-
code: ZodIssueCode.not_multiple_of,
|
|
2044
|
-
multipleOf: check.value,
|
|
2045
|
-
message: check.message
|
|
2046
|
-
});
|
|
2047
|
-
status.dirty();
|
|
2048
|
-
}
|
|
2049
|
-
} else if (check.kind === "finite") {
|
|
2050
|
-
if (!Number.isFinite(input.data)) {
|
|
2051
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
2052
|
-
addIssueToContext(ctx, {
|
|
2053
|
-
code: ZodIssueCode.not_finite,
|
|
2054
|
-
message: check.message
|
|
2055
|
-
});
|
|
2056
|
-
status.dirty();
|
|
2057
|
-
}
|
|
2058
|
-
} else {
|
|
2059
|
-
util.assertNever(check);
|
|
2060
|
-
}
|
|
2061
|
-
}
|
|
2062
|
-
return { status: status.value, value: input.data };
|
|
2063
|
-
}
|
|
2064
|
-
gte(value, message) {
|
|
2065
|
-
return this.setLimit("min", value, true, errorUtil.toString(message));
|
|
2066
|
-
}
|
|
2067
|
-
gt(value, message) {
|
|
2068
|
-
return this.setLimit("min", value, false, errorUtil.toString(message));
|
|
2069
|
-
}
|
|
2070
|
-
lte(value, message) {
|
|
2071
|
-
return this.setLimit("max", value, true, errorUtil.toString(message));
|
|
2072
|
-
}
|
|
2073
|
-
lt(value, message) {
|
|
2074
|
-
return this.setLimit("max", value, false, errorUtil.toString(message));
|
|
2075
|
-
}
|
|
2076
|
-
setLimit(kind, value, inclusive, message) {
|
|
2077
|
-
return new _ZodNumber({
|
|
2078
|
-
...this._def,
|
|
2079
|
-
checks: [
|
|
2080
|
-
...this._def.checks,
|
|
2081
|
-
{
|
|
2082
|
-
kind,
|
|
2083
|
-
value,
|
|
2084
|
-
inclusive,
|
|
2085
|
-
message: errorUtil.toString(message)
|
|
2086
|
-
}
|
|
2087
|
-
]
|
|
2088
|
-
});
|
|
2089
|
-
}
|
|
2090
|
-
_addCheck(check) {
|
|
2091
|
-
return new _ZodNumber({
|
|
2092
|
-
...this._def,
|
|
2093
|
-
checks: [...this._def.checks, check]
|
|
2094
|
-
});
|
|
2095
|
-
}
|
|
2096
|
-
int(message) {
|
|
2097
|
-
return this._addCheck({
|
|
2098
|
-
kind: "int",
|
|
2099
|
-
message: errorUtil.toString(message)
|
|
2100
|
-
});
|
|
2101
|
-
}
|
|
2102
|
-
positive(message) {
|
|
2103
|
-
return this._addCheck({
|
|
2104
|
-
kind: "min",
|
|
2105
|
-
value: 0,
|
|
2106
|
-
inclusive: false,
|
|
2107
|
-
message: errorUtil.toString(message)
|
|
2108
|
-
});
|
|
2109
|
-
}
|
|
2110
|
-
negative(message) {
|
|
2111
|
-
return this._addCheck({
|
|
2112
|
-
kind: "max",
|
|
2113
|
-
value: 0,
|
|
2114
|
-
inclusive: false,
|
|
2115
|
-
message: errorUtil.toString(message)
|
|
2116
|
-
});
|
|
2117
|
-
}
|
|
2118
|
-
nonpositive(message) {
|
|
2119
|
-
return this._addCheck({
|
|
2120
|
-
kind: "max",
|
|
2121
|
-
value: 0,
|
|
2122
|
-
inclusive: true,
|
|
2123
|
-
message: errorUtil.toString(message)
|
|
2124
|
-
});
|
|
2125
|
-
}
|
|
2126
|
-
nonnegative(message) {
|
|
2127
|
-
return this._addCheck({
|
|
2128
|
-
kind: "min",
|
|
2129
|
-
value: 0,
|
|
2130
|
-
inclusive: true,
|
|
2131
|
-
message: errorUtil.toString(message)
|
|
2132
|
-
});
|
|
2133
|
-
}
|
|
2134
|
-
multipleOf(value, message) {
|
|
2135
|
-
return this._addCheck({
|
|
2136
|
-
kind: "multipleOf",
|
|
2137
|
-
value,
|
|
2138
|
-
message: errorUtil.toString(message)
|
|
2139
|
-
});
|
|
2140
|
-
}
|
|
2141
|
-
finite(message) {
|
|
2142
|
-
return this._addCheck({
|
|
2143
|
-
kind: "finite",
|
|
2144
|
-
message: errorUtil.toString(message)
|
|
2145
|
-
});
|
|
2146
|
-
}
|
|
2147
|
-
safe(message) {
|
|
2148
|
-
return this._addCheck({
|
|
2149
|
-
kind: "min",
|
|
2150
|
-
inclusive: true,
|
|
2151
|
-
value: Number.MIN_SAFE_INTEGER,
|
|
2152
|
-
message: errorUtil.toString(message)
|
|
2153
|
-
})._addCheck({
|
|
2154
|
-
kind: "max",
|
|
2155
|
-
inclusive: true,
|
|
2156
|
-
value: Number.MAX_SAFE_INTEGER,
|
|
2157
|
-
message: errorUtil.toString(message)
|
|
2158
|
-
});
|
|
2159
|
-
}
|
|
2160
|
-
get minValue() {
|
|
2161
|
-
let min = null;
|
|
2162
|
-
for (const ch of this._def.checks) {
|
|
2163
|
-
if (ch.kind === "min") {
|
|
2164
|
-
if (min === null || ch.value > min)
|
|
2165
|
-
min = ch.value;
|
|
2166
|
-
}
|
|
2167
|
-
}
|
|
2168
|
-
return min;
|
|
2169
|
-
}
|
|
2170
|
-
get maxValue() {
|
|
2171
|
-
let max = null;
|
|
2172
|
-
for (const ch of this._def.checks) {
|
|
2173
|
-
if (ch.kind === "max") {
|
|
2174
|
-
if (max === null || ch.value < max)
|
|
2175
|
-
max = ch.value;
|
|
2176
|
-
}
|
|
2177
|
-
}
|
|
2178
|
-
return max;
|
|
2179
|
-
}
|
|
2180
|
-
get isInt() {
|
|
2181
|
-
return !!this._def.checks.find((ch) => ch.kind === "int" || ch.kind === "multipleOf" && util.isInteger(ch.value));
|
|
2182
|
-
}
|
|
2183
|
-
get isFinite() {
|
|
2184
|
-
let max = null;
|
|
2185
|
-
let min = null;
|
|
2186
|
-
for (const ch of this._def.checks) {
|
|
2187
|
-
if (ch.kind === "finite" || ch.kind === "int" || ch.kind === "multipleOf") {
|
|
2188
|
-
return true;
|
|
2189
|
-
} else if (ch.kind === "min") {
|
|
2190
|
-
if (min === null || ch.value > min)
|
|
2191
|
-
min = ch.value;
|
|
2192
|
-
} else if (ch.kind === "max") {
|
|
2193
|
-
if (max === null || ch.value < max)
|
|
2194
|
-
max = ch.value;
|
|
2195
|
-
}
|
|
2196
|
-
}
|
|
2197
|
-
return Number.isFinite(min) && Number.isFinite(max);
|
|
2198
|
-
}
|
|
2199
|
-
};
|
|
2200
|
-
ZodNumber.create = (params) => {
|
|
2201
|
-
return new ZodNumber({
|
|
2202
|
-
checks: [],
|
|
2203
|
-
typeName: ZodFirstPartyTypeKind.ZodNumber,
|
|
2204
|
-
coerce: params?.coerce || false,
|
|
2205
|
-
...processCreateParams(params)
|
|
2206
|
-
});
|
|
2207
|
-
};
|
|
2208
|
-
var ZodBigInt = class _ZodBigInt extends ZodType {
|
|
2209
|
-
constructor() {
|
|
2210
|
-
super(...arguments);
|
|
2211
|
-
this.min = this.gte;
|
|
2212
|
-
this.max = this.lte;
|
|
2213
|
-
}
|
|
2214
|
-
_parse(input) {
|
|
2215
|
-
if (this._def.coerce) {
|
|
2216
|
-
try {
|
|
2217
|
-
input.data = BigInt(input.data);
|
|
2218
|
-
} catch {
|
|
2219
|
-
return this._getInvalidInput(input);
|
|
2220
|
-
}
|
|
2221
|
-
}
|
|
2222
|
-
const parsedType = this._getType(input);
|
|
2223
|
-
if (parsedType !== ZodParsedType.bigint) {
|
|
2224
|
-
return this._getInvalidInput(input);
|
|
2225
|
-
}
|
|
2226
|
-
let ctx = void 0;
|
|
2227
|
-
const status = new ParseStatus();
|
|
2228
|
-
for (const check of this._def.checks) {
|
|
2229
|
-
if (check.kind === "min") {
|
|
2230
|
-
const tooSmall = check.inclusive ? input.data < check.value : input.data <= check.value;
|
|
2231
|
-
if (tooSmall) {
|
|
2232
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
2233
|
-
addIssueToContext(ctx, {
|
|
2234
|
-
code: ZodIssueCode.too_small,
|
|
2235
|
-
type: "bigint",
|
|
2236
|
-
minimum: check.value,
|
|
2237
|
-
inclusive: check.inclusive,
|
|
2238
|
-
message: check.message
|
|
2239
|
-
});
|
|
2240
|
-
status.dirty();
|
|
2241
|
-
}
|
|
2242
|
-
} else if (check.kind === "max") {
|
|
2243
|
-
const tooBig = check.inclusive ? input.data > check.value : input.data >= check.value;
|
|
2244
|
-
if (tooBig) {
|
|
2245
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
2246
|
-
addIssueToContext(ctx, {
|
|
2247
|
-
code: ZodIssueCode.too_big,
|
|
2248
|
-
type: "bigint",
|
|
2249
|
-
maximum: check.value,
|
|
2250
|
-
inclusive: check.inclusive,
|
|
2251
|
-
message: check.message
|
|
2252
|
-
});
|
|
2253
|
-
status.dirty();
|
|
2254
|
-
}
|
|
2255
|
-
} else if (check.kind === "multipleOf") {
|
|
2256
|
-
if (input.data % check.value !== BigInt(0)) {
|
|
2257
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
2258
|
-
addIssueToContext(ctx, {
|
|
2259
|
-
code: ZodIssueCode.not_multiple_of,
|
|
2260
|
-
multipleOf: check.value,
|
|
2261
|
-
message: check.message
|
|
2262
|
-
});
|
|
2263
|
-
status.dirty();
|
|
2264
|
-
}
|
|
2265
|
-
} else {
|
|
2266
|
-
util.assertNever(check);
|
|
2267
|
-
}
|
|
2268
|
-
}
|
|
2269
|
-
return { status: status.value, value: input.data };
|
|
2270
|
-
}
|
|
2271
|
-
_getInvalidInput(input) {
|
|
2272
|
-
const ctx = this._getOrReturnCtx(input);
|
|
2273
|
-
addIssueToContext(ctx, {
|
|
2274
|
-
code: ZodIssueCode.invalid_type,
|
|
2275
|
-
expected: ZodParsedType.bigint,
|
|
2276
|
-
received: ctx.parsedType
|
|
2277
|
-
});
|
|
2278
|
-
return INVALID;
|
|
2279
|
-
}
|
|
2280
|
-
gte(value, message) {
|
|
2281
|
-
return this.setLimit("min", value, true, errorUtil.toString(message));
|
|
2282
|
-
}
|
|
2283
|
-
gt(value, message) {
|
|
2284
|
-
return this.setLimit("min", value, false, errorUtil.toString(message));
|
|
2285
|
-
}
|
|
2286
|
-
lte(value, message) {
|
|
2287
|
-
return this.setLimit("max", value, true, errorUtil.toString(message));
|
|
2288
|
-
}
|
|
2289
|
-
lt(value, message) {
|
|
2290
|
-
return this.setLimit("max", value, false, errorUtil.toString(message));
|
|
2291
|
-
}
|
|
2292
|
-
setLimit(kind, value, inclusive, message) {
|
|
2293
|
-
return new _ZodBigInt({
|
|
2294
|
-
...this._def,
|
|
2295
|
-
checks: [
|
|
2296
|
-
...this._def.checks,
|
|
2297
|
-
{
|
|
2298
|
-
kind,
|
|
2299
|
-
value,
|
|
2300
|
-
inclusive,
|
|
2301
|
-
message: errorUtil.toString(message)
|
|
2302
|
-
}
|
|
2303
|
-
]
|
|
2304
|
-
});
|
|
2305
|
-
}
|
|
2306
|
-
_addCheck(check) {
|
|
2307
|
-
return new _ZodBigInt({
|
|
2308
|
-
...this._def,
|
|
2309
|
-
checks: [...this._def.checks, check]
|
|
2310
|
-
});
|
|
2311
|
-
}
|
|
2312
|
-
positive(message) {
|
|
2313
|
-
return this._addCheck({
|
|
2314
|
-
kind: "min",
|
|
2315
|
-
value: BigInt(0),
|
|
2316
|
-
inclusive: false,
|
|
2317
|
-
message: errorUtil.toString(message)
|
|
2318
|
-
});
|
|
2319
|
-
}
|
|
2320
|
-
negative(message) {
|
|
2321
|
-
return this._addCheck({
|
|
2322
|
-
kind: "max",
|
|
2323
|
-
value: BigInt(0),
|
|
2324
|
-
inclusive: false,
|
|
2325
|
-
message: errorUtil.toString(message)
|
|
2326
|
-
});
|
|
2327
|
-
}
|
|
2328
|
-
nonpositive(message) {
|
|
2329
|
-
return this._addCheck({
|
|
2330
|
-
kind: "max",
|
|
2331
|
-
value: BigInt(0),
|
|
2332
|
-
inclusive: true,
|
|
2333
|
-
message: errorUtil.toString(message)
|
|
2334
|
-
});
|
|
2335
|
-
}
|
|
2336
|
-
nonnegative(message) {
|
|
2337
|
-
return this._addCheck({
|
|
2338
|
-
kind: "min",
|
|
2339
|
-
value: BigInt(0),
|
|
2340
|
-
inclusive: true,
|
|
2341
|
-
message: errorUtil.toString(message)
|
|
2342
|
-
});
|
|
2343
|
-
}
|
|
2344
|
-
multipleOf(value, message) {
|
|
2345
|
-
return this._addCheck({
|
|
2346
|
-
kind: "multipleOf",
|
|
2347
|
-
value,
|
|
2348
|
-
message: errorUtil.toString(message)
|
|
2349
|
-
});
|
|
2350
|
-
}
|
|
2351
|
-
get minValue() {
|
|
2352
|
-
let min = null;
|
|
2353
|
-
for (const ch of this._def.checks) {
|
|
2354
|
-
if (ch.kind === "min") {
|
|
2355
|
-
if (min === null || ch.value > min)
|
|
2356
|
-
min = ch.value;
|
|
2357
|
-
}
|
|
2358
|
-
}
|
|
2359
|
-
return min;
|
|
2360
|
-
}
|
|
2361
|
-
get maxValue() {
|
|
2362
|
-
let max = null;
|
|
2363
|
-
for (const ch of this._def.checks) {
|
|
2364
|
-
if (ch.kind === "max") {
|
|
2365
|
-
if (max === null || ch.value < max)
|
|
2366
|
-
max = ch.value;
|
|
2367
|
-
}
|
|
2368
|
-
}
|
|
2369
|
-
return max;
|
|
2370
|
-
}
|
|
2371
|
-
};
|
|
2372
|
-
ZodBigInt.create = (params) => {
|
|
2373
|
-
return new ZodBigInt({
|
|
2374
|
-
checks: [],
|
|
2375
|
-
typeName: ZodFirstPartyTypeKind.ZodBigInt,
|
|
2376
|
-
coerce: params?.coerce ?? false,
|
|
2377
|
-
...processCreateParams(params)
|
|
2378
|
-
});
|
|
2379
|
-
};
|
|
2380
|
-
var ZodBoolean = class extends ZodType {
|
|
2381
|
-
_parse(input) {
|
|
2382
|
-
if (this._def.coerce) {
|
|
2383
|
-
input.data = Boolean(input.data);
|
|
2384
|
-
}
|
|
2385
|
-
const parsedType = this._getType(input);
|
|
2386
|
-
if (parsedType !== ZodParsedType.boolean) {
|
|
2387
|
-
const ctx = this._getOrReturnCtx(input);
|
|
2388
|
-
addIssueToContext(ctx, {
|
|
2389
|
-
code: ZodIssueCode.invalid_type,
|
|
2390
|
-
expected: ZodParsedType.boolean,
|
|
2391
|
-
received: ctx.parsedType
|
|
2392
|
-
});
|
|
2393
|
-
return INVALID;
|
|
2394
|
-
}
|
|
2395
|
-
return OK(input.data);
|
|
2396
|
-
}
|
|
2397
|
-
};
|
|
2398
|
-
ZodBoolean.create = (params) => {
|
|
2399
|
-
return new ZodBoolean({
|
|
2400
|
-
typeName: ZodFirstPartyTypeKind.ZodBoolean,
|
|
2401
|
-
coerce: params?.coerce || false,
|
|
2402
|
-
...processCreateParams(params)
|
|
2403
|
-
});
|
|
2404
|
-
};
|
|
2405
|
-
var ZodDate = class _ZodDate extends ZodType {
|
|
2406
|
-
_parse(input) {
|
|
2407
|
-
if (this._def.coerce) {
|
|
2408
|
-
input.data = new Date(input.data);
|
|
2409
|
-
}
|
|
2410
|
-
const parsedType = this._getType(input);
|
|
2411
|
-
if (parsedType !== ZodParsedType.date) {
|
|
2412
|
-
const ctx2 = this._getOrReturnCtx(input);
|
|
2413
|
-
addIssueToContext(ctx2, {
|
|
2414
|
-
code: ZodIssueCode.invalid_type,
|
|
2415
|
-
expected: ZodParsedType.date,
|
|
2416
|
-
received: ctx2.parsedType
|
|
2417
|
-
});
|
|
2418
|
-
return INVALID;
|
|
2419
|
-
}
|
|
2420
|
-
if (Number.isNaN(input.data.getTime())) {
|
|
2421
|
-
const ctx2 = this._getOrReturnCtx(input);
|
|
2422
|
-
addIssueToContext(ctx2, {
|
|
2423
|
-
code: ZodIssueCode.invalid_date
|
|
2424
|
-
});
|
|
2425
|
-
return INVALID;
|
|
2426
|
-
}
|
|
2427
|
-
const status = new ParseStatus();
|
|
2428
|
-
let ctx = void 0;
|
|
2429
|
-
for (const check of this._def.checks) {
|
|
2430
|
-
if (check.kind === "min") {
|
|
2431
|
-
if (input.data.getTime() < check.value) {
|
|
2432
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
2433
|
-
addIssueToContext(ctx, {
|
|
2434
|
-
code: ZodIssueCode.too_small,
|
|
2435
|
-
message: check.message,
|
|
2436
|
-
inclusive: true,
|
|
2437
|
-
exact: false,
|
|
2438
|
-
minimum: check.value,
|
|
2439
|
-
type: "date"
|
|
2440
|
-
});
|
|
2441
|
-
status.dirty();
|
|
2442
|
-
}
|
|
2443
|
-
} else if (check.kind === "max") {
|
|
2444
|
-
if (input.data.getTime() > check.value) {
|
|
2445
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
2446
|
-
addIssueToContext(ctx, {
|
|
2447
|
-
code: ZodIssueCode.too_big,
|
|
2448
|
-
message: check.message,
|
|
2449
|
-
inclusive: true,
|
|
2450
|
-
exact: false,
|
|
2451
|
-
maximum: check.value,
|
|
2452
|
-
type: "date"
|
|
2453
|
-
});
|
|
2454
|
-
status.dirty();
|
|
2455
|
-
}
|
|
2456
|
-
} else {
|
|
2457
|
-
util.assertNever(check);
|
|
2458
|
-
}
|
|
2459
|
-
}
|
|
2460
|
-
return {
|
|
2461
|
-
status: status.value,
|
|
2462
|
-
value: new Date(input.data.getTime())
|
|
2463
|
-
};
|
|
2464
|
-
}
|
|
2465
|
-
_addCheck(check) {
|
|
2466
|
-
return new _ZodDate({
|
|
2467
|
-
...this._def,
|
|
2468
|
-
checks: [...this._def.checks, check]
|
|
2469
|
-
});
|
|
2470
|
-
}
|
|
2471
|
-
min(minDate, message) {
|
|
2472
|
-
return this._addCheck({
|
|
2473
|
-
kind: "min",
|
|
2474
|
-
value: minDate.getTime(),
|
|
2475
|
-
message: errorUtil.toString(message)
|
|
2476
|
-
});
|
|
2477
|
-
}
|
|
2478
|
-
max(maxDate, message) {
|
|
2479
|
-
return this._addCheck({
|
|
2480
|
-
kind: "max",
|
|
2481
|
-
value: maxDate.getTime(),
|
|
2482
|
-
message: errorUtil.toString(message)
|
|
2483
|
-
});
|
|
2484
|
-
}
|
|
2485
|
-
get minDate() {
|
|
2486
|
-
let min = null;
|
|
2487
|
-
for (const ch of this._def.checks) {
|
|
2488
|
-
if (ch.kind === "min") {
|
|
2489
|
-
if (min === null || ch.value > min)
|
|
2490
|
-
min = ch.value;
|
|
2491
|
-
}
|
|
2492
|
-
}
|
|
2493
|
-
return min != null ? new Date(min) : null;
|
|
2494
|
-
}
|
|
2495
|
-
get maxDate() {
|
|
2496
|
-
let max = null;
|
|
2497
|
-
for (const ch of this._def.checks) {
|
|
2498
|
-
if (ch.kind === "max") {
|
|
2499
|
-
if (max === null || ch.value < max)
|
|
2500
|
-
max = ch.value;
|
|
2501
|
-
}
|
|
2502
|
-
}
|
|
2503
|
-
return max != null ? new Date(max) : null;
|
|
2504
|
-
}
|
|
2505
|
-
};
|
|
2506
|
-
ZodDate.create = (params) => {
|
|
2507
|
-
return new ZodDate({
|
|
2508
|
-
checks: [],
|
|
2509
|
-
coerce: params?.coerce || false,
|
|
2510
|
-
typeName: ZodFirstPartyTypeKind.ZodDate,
|
|
2511
|
-
...processCreateParams(params)
|
|
2512
|
-
});
|
|
2513
|
-
};
|
|
2514
|
-
var ZodSymbol = class extends ZodType {
|
|
2515
|
-
_parse(input) {
|
|
2516
|
-
const parsedType = this._getType(input);
|
|
2517
|
-
if (parsedType !== ZodParsedType.symbol) {
|
|
2518
|
-
const ctx = this._getOrReturnCtx(input);
|
|
2519
|
-
addIssueToContext(ctx, {
|
|
2520
|
-
code: ZodIssueCode.invalid_type,
|
|
2521
|
-
expected: ZodParsedType.symbol,
|
|
2522
|
-
received: ctx.parsedType
|
|
2523
|
-
});
|
|
2524
|
-
return INVALID;
|
|
2525
|
-
}
|
|
2526
|
-
return OK(input.data);
|
|
2527
|
-
}
|
|
2528
|
-
};
|
|
2529
|
-
ZodSymbol.create = (params) => {
|
|
2530
|
-
return new ZodSymbol({
|
|
2531
|
-
typeName: ZodFirstPartyTypeKind.ZodSymbol,
|
|
2532
|
-
...processCreateParams(params)
|
|
2533
|
-
});
|
|
2534
|
-
};
|
|
2535
|
-
var ZodUndefined = class extends ZodType {
|
|
2536
|
-
_parse(input) {
|
|
2537
|
-
const parsedType = this._getType(input);
|
|
2538
|
-
if (parsedType !== ZodParsedType.undefined) {
|
|
2539
|
-
const ctx = this._getOrReturnCtx(input);
|
|
2540
|
-
addIssueToContext(ctx, {
|
|
2541
|
-
code: ZodIssueCode.invalid_type,
|
|
2542
|
-
expected: ZodParsedType.undefined,
|
|
2543
|
-
received: ctx.parsedType
|
|
2544
|
-
});
|
|
2545
|
-
return INVALID;
|
|
2546
|
-
}
|
|
2547
|
-
return OK(input.data);
|
|
2548
|
-
}
|
|
2549
|
-
};
|
|
2550
|
-
ZodUndefined.create = (params) => {
|
|
2551
|
-
return new ZodUndefined({
|
|
2552
|
-
typeName: ZodFirstPartyTypeKind.ZodUndefined,
|
|
2553
|
-
...processCreateParams(params)
|
|
2554
|
-
});
|
|
2555
|
-
};
|
|
2556
|
-
var ZodNull = class extends ZodType {
|
|
2557
|
-
_parse(input) {
|
|
2558
|
-
const parsedType = this._getType(input);
|
|
2559
|
-
if (parsedType !== ZodParsedType.null) {
|
|
2560
|
-
const ctx = this._getOrReturnCtx(input);
|
|
2561
|
-
addIssueToContext(ctx, {
|
|
2562
|
-
code: ZodIssueCode.invalid_type,
|
|
2563
|
-
expected: ZodParsedType.null,
|
|
2564
|
-
received: ctx.parsedType
|
|
2565
|
-
});
|
|
2566
|
-
return INVALID;
|
|
2567
|
-
}
|
|
2568
|
-
return OK(input.data);
|
|
2569
|
-
}
|
|
2570
|
-
};
|
|
2571
|
-
ZodNull.create = (params) => {
|
|
2572
|
-
return new ZodNull({
|
|
2573
|
-
typeName: ZodFirstPartyTypeKind.ZodNull,
|
|
2574
|
-
...processCreateParams(params)
|
|
2575
|
-
});
|
|
2576
|
-
};
|
|
2577
|
-
var ZodAny = class extends ZodType {
|
|
2578
|
-
constructor() {
|
|
2579
|
-
super(...arguments);
|
|
2580
|
-
this._any = true;
|
|
2581
|
-
}
|
|
2582
|
-
_parse(input) {
|
|
2583
|
-
return OK(input.data);
|
|
2584
|
-
}
|
|
2585
|
-
};
|
|
2586
|
-
ZodAny.create = (params) => {
|
|
2587
|
-
return new ZodAny({
|
|
2588
|
-
typeName: ZodFirstPartyTypeKind.ZodAny,
|
|
2589
|
-
...processCreateParams(params)
|
|
2590
|
-
});
|
|
2591
|
-
};
|
|
2592
|
-
var ZodUnknown = class extends ZodType {
|
|
2593
|
-
constructor() {
|
|
2594
|
-
super(...arguments);
|
|
2595
|
-
this._unknown = true;
|
|
2596
|
-
}
|
|
2597
|
-
_parse(input) {
|
|
2598
|
-
return OK(input.data);
|
|
2599
|
-
}
|
|
2600
|
-
};
|
|
2601
|
-
ZodUnknown.create = (params) => {
|
|
2602
|
-
return new ZodUnknown({
|
|
2603
|
-
typeName: ZodFirstPartyTypeKind.ZodUnknown,
|
|
2604
|
-
...processCreateParams(params)
|
|
2605
|
-
});
|
|
2606
|
-
};
|
|
2607
|
-
var ZodNever = class extends ZodType {
|
|
2608
|
-
_parse(input) {
|
|
2609
|
-
const ctx = this._getOrReturnCtx(input);
|
|
2610
|
-
addIssueToContext(ctx, {
|
|
2611
|
-
code: ZodIssueCode.invalid_type,
|
|
2612
|
-
expected: ZodParsedType.never,
|
|
2613
|
-
received: ctx.parsedType
|
|
2614
|
-
});
|
|
2615
|
-
return INVALID;
|
|
2616
|
-
}
|
|
2617
|
-
};
|
|
2618
|
-
ZodNever.create = (params) => {
|
|
2619
|
-
return new ZodNever({
|
|
2620
|
-
typeName: ZodFirstPartyTypeKind.ZodNever,
|
|
2621
|
-
...processCreateParams(params)
|
|
2622
|
-
});
|
|
2623
|
-
};
|
|
2624
|
-
var ZodVoid = class extends ZodType {
|
|
2625
|
-
_parse(input) {
|
|
2626
|
-
const parsedType = this._getType(input);
|
|
2627
|
-
if (parsedType !== ZodParsedType.undefined) {
|
|
2628
|
-
const ctx = this._getOrReturnCtx(input);
|
|
2629
|
-
addIssueToContext(ctx, {
|
|
2630
|
-
code: ZodIssueCode.invalid_type,
|
|
2631
|
-
expected: ZodParsedType.void,
|
|
2632
|
-
received: ctx.parsedType
|
|
2633
|
-
});
|
|
2634
|
-
return INVALID;
|
|
2635
|
-
}
|
|
2636
|
-
return OK(input.data);
|
|
2637
|
-
}
|
|
2638
|
-
};
|
|
2639
|
-
ZodVoid.create = (params) => {
|
|
2640
|
-
return new ZodVoid({
|
|
2641
|
-
typeName: ZodFirstPartyTypeKind.ZodVoid,
|
|
2642
|
-
...processCreateParams(params)
|
|
2643
|
-
});
|
|
2644
|
-
};
|
|
2645
|
-
var ZodArray = class _ZodArray extends ZodType {
|
|
2646
|
-
_parse(input) {
|
|
2647
|
-
const { ctx, status } = this._processInputParams(input);
|
|
2648
|
-
const def = this._def;
|
|
2649
|
-
if (ctx.parsedType !== ZodParsedType.array) {
|
|
2650
|
-
addIssueToContext(ctx, {
|
|
2651
|
-
code: ZodIssueCode.invalid_type,
|
|
2652
|
-
expected: ZodParsedType.array,
|
|
2653
|
-
received: ctx.parsedType
|
|
2654
|
-
});
|
|
2655
|
-
return INVALID;
|
|
2656
|
-
}
|
|
2657
|
-
if (def.exactLength !== null) {
|
|
2658
|
-
const tooBig = ctx.data.length > def.exactLength.value;
|
|
2659
|
-
const tooSmall = ctx.data.length < def.exactLength.value;
|
|
2660
|
-
if (tooBig || tooSmall) {
|
|
2661
|
-
addIssueToContext(ctx, {
|
|
2662
|
-
code: tooBig ? ZodIssueCode.too_big : ZodIssueCode.too_small,
|
|
2663
|
-
minimum: tooSmall ? def.exactLength.value : void 0,
|
|
2664
|
-
maximum: tooBig ? def.exactLength.value : void 0,
|
|
2665
|
-
type: "array",
|
|
2666
|
-
inclusive: true,
|
|
2667
|
-
exact: true,
|
|
2668
|
-
message: def.exactLength.message
|
|
2669
|
-
});
|
|
2670
|
-
status.dirty();
|
|
2671
|
-
}
|
|
2672
|
-
}
|
|
2673
|
-
if (def.minLength !== null) {
|
|
2674
|
-
if (ctx.data.length < def.minLength.value) {
|
|
2675
|
-
addIssueToContext(ctx, {
|
|
2676
|
-
code: ZodIssueCode.too_small,
|
|
2677
|
-
minimum: def.minLength.value,
|
|
2678
|
-
type: "array",
|
|
2679
|
-
inclusive: true,
|
|
2680
|
-
exact: false,
|
|
2681
|
-
message: def.minLength.message
|
|
2682
|
-
});
|
|
2683
|
-
status.dirty();
|
|
2684
|
-
}
|
|
2685
|
-
}
|
|
2686
|
-
if (def.maxLength !== null) {
|
|
2687
|
-
if (ctx.data.length > def.maxLength.value) {
|
|
2688
|
-
addIssueToContext(ctx, {
|
|
2689
|
-
code: ZodIssueCode.too_big,
|
|
2690
|
-
maximum: def.maxLength.value,
|
|
2691
|
-
type: "array",
|
|
2692
|
-
inclusive: true,
|
|
2693
|
-
exact: false,
|
|
2694
|
-
message: def.maxLength.message
|
|
2695
|
-
});
|
|
2696
|
-
status.dirty();
|
|
2697
|
-
}
|
|
2698
|
-
}
|
|
2699
|
-
if (ctx.common.async) {
|
|
2700
|
-
return Promise.all([...ctx.data].map((item, i) => {
|
|
2701
|
-
return def.type._parseAsync(new ParseInputLazyPath(ctx, item, ctx.path, i));
|
|
2702
|
-
})).then((result2) => {
|
|
2703
|
-
return ParseStatus.mergeArray(status, result2);
|
|
2704
|
-
});
|
|
2705
|
-
}
|
|
2706
|
-
const result = [...ctx.data].map((item, i) => {
|
|
2707
|
-
return def.type._parseSync(new ParseInputLazyPath(ctx, item, ctx.path, i));
|
|
2708
|
-
});
|
|
2709
|
-
return ParseStatus.mergeArray(status, result);
|
|
2710
|
-
}
|
|
2711
|
-
get element() {
|
|
2712
|
-
return this._def.type;
|
|
2713
|
-
}
|
|
2714
|
-
min(minLength, message) {
|
|
2715
|
-
return new _ZodArray({
|
|
2716
|
-
...this._def,
|
|
2717
|
-
minLength: { value: minLength, message: errorUtil.toString(message) }
|
|
2718
|
-
});
|
|
2719
|
-
}
|
|
2720
|
-
max(maxLength, message) {
|
|
2721
|
-
return new _ZodArray({
|
|
2722
|
-
...this._def,
|
|
2723
|
-
maxLength: { value: maxLength, message: errorUtil.toString(message) }
|
|
2724
|
-
});
|
|
2725
|
-
}
|
|
2726
|
-
length(len, message) {
|
|
2727
|
-
return new _ZodArray({
|
|
2728
|
-
...this._def,
|
|
2729
|
-
exactLength: { value: len, message: errorUtil.toString(message) }
|
|
2730
|
-
});
|
|
2731
|
-
}
|
|
2732
|
-
nonempty(message) {
|
|
2733
|
-
return this.min(1, message);
|
|
2734
|
-
}
|
|
2735
|
-
};
|
|
2736
|
-
ZodArray.create = (schema, params) => {
|
|
2737
|
-
return new ZodArray({
|
|
2738
|
-
type: schema,
|
|
2739
|
-
minLength: null,
|
|
2740
|
-
maxLength: null,
|
|
2741
|
-
exactLength: null,
|
|
2742
|
-
typeName: ZodFirstPartyTypeKind.ZodArray,
|
|
2743
|
-
...processCreateParams(params)
|
|
2744
|
-
});
|
|
2745
|
-
};
|
|
2746
|
-
function deepPartialify(schema) {
|
|
2747
|
-
if (schema instanceof ZodObject) {
|
|
2748
|
-
const newShape = {};
|
|
2749
|
-
for (const key in schema.shape) {
|
|
2750
|
-
const fieldSchema = schema.shape[key];
|
|
2751
|
-
newShape[key] = ZodOptional.create(deepPartialify(fieldSchema));
|
|
2752
|
-
}
|
|
2753
|
-
return new ZodObject({
|
|
2754
|
-
...schema._def,
|
|
2755
|
-
shape: () => newShape
|
|
2756
|
-
});
|
|
2757
|
-
} else if (schema instanceof ZodArray) {
|
|
2758
|
-
return new ZodArray({
|
|
2759
|
-
...schema._def,
|
|
2760
|
-
type: deepPartialify(schema.element)
|
|
2761
|
-
});
|
|
2762
|
-
} else if (schema instanceof ZodOptional) {
|
|
2763
|
-
return ZodOptional.create(deepPartialify(schema.unwrap()));
|
|
2764
|
-
} else if (schema instanceof ZodNullable) {
|
|
2765
|
-
return ZodNullable.create(deepPartialify(schema.unwrap()));
|
|
2766
|
-
} else if (schema instanceof ZodTuple) {
|
|
2767
|
-
return ZodTuple.create(schema.items.map((item) => deepPartialify(item)));
|
|
2768
|
-
} else {
|
|
2769
|
-
return schema;
|
|
2770
|
-
}
|
|
2771
|
-
}
|
|
2772
|
-
var ZodObject = class _ZodObject extends ZodType {
|
|
2773
|
-
constructor() {
|
|
2774
|
-
super(...arguments);
|
|
2775
|
-
this._cached = null;
|
|
2776
|
-
this.nonstrict = this.passthrough;
|
|
2777
|
-
this.augment = this.extend;
|
|
2778
|
-
}
|
|
2779
|
-
_getCached() {
|
|
2780
|
-
if (this._cached !== null)
|
|
2781
|
-
return this._cached;
|
|
2782
|
-
const shape = this._def.shape();
|
|
2783
|
-
const keys = util.objectKeys(shape);
|
|
2784
|
-
this._cached = { shape, keys };
|
|
2785
|
-
return this._cached;
|
|
2786
|
-
}
|
|
2787
|
-
_parse(input) {
|
|
2788
|
-
const parsedType = this._getType(input);
|
|
2789
|
-
if (parsedType !== ZodParsedType.object) {
|
|
2790
|
-
const ctx2 = this._getOrReturnCtx(input);
|
|
2791
|
-
addIssueToContext(ctx2, {
|
|
2792
|
-
code: ZodIssueCode.invalid_type,
|
|
2793
|
-
expected: ZodParsedType.object,
|
|
2794
|
-
received: ctx2.parsedType
|
|
2795
|
-
});
|
|
2796
|
-
return INVALID;
|
|
2797
|
-
}
|
|
2798
|
-
const { status, ctx } = this._processInputParams(input);
|
|
2799
|
-
const { shape, keys: shapeKeys } = this._getCached();
|
|
2800
|
-
const extraKeys = [];
|
|
2801
|
-
if (!(this._def.catchall instanceof ZodNever && this._def.unknownKeys === "strip")) {
|
|
2802
|
-
for (const key in ctx.data) {
|
|
2803
|
-
if (!shapeKeys.includes(key)) {
|
|
2804
|
-
extraKeys.push(key);
|
|
2805
|
-
}
|
|
2806
|
-
}
|
|
2807
|
-
}
|
|
2808
|
-
const pairs = [];
|
|
2809
|
-
for (const key of shapeKeys) {
|
|
2810
|
-
const keyValidator = shape[key];
|
|
2811
|
-
const value = ctx.data[key];
|
|
2812
|
-
pairs.push({
|
|
2813
|
-
key: { status: "valid", value: key },
|
|
2814
|
-
value: keyValidator._parse(new ParseInputLazyPath(ctx, value, ctx.path, key)),
|
|
2815
|
-
alwaysSet: key in ctx.data
|
|
2816
|
-
});
|
|
2817
|
-
}
|
|
2818
|
-
if (this._def.catchall instanceof ZodNever) {
|
|
2819
|
-
const unknownKeys = this._def.unknownKeys;
|
|
2820
|
-
if (unknownKeys === "passthrough") {
|
|
2821
|
-
for (const key of extraKeys) {
|
|
2822
|
-
pairs.push({
|
|
2823
|
-
key: { status: "valid", value: key },
|
|
2824
|
-
value: { status: "valid", value: ctx.data[key] }
|
|
2825
|
-
});
|
|
2826
|
-
}
|
|
2827
|
-
} else if (unknownKeys === "strict") {
|
|
2828
|
-
if (extraKeys.length > 0) {
|
|
2829
|
-
addIssueToContext(ctx, {
|
|
2830
|
-
code: ZodIssueCode.unrecognized_keys,
|
|
2831
|
-
keys: extraKeys
|
|
2832
|
-
});
|
|
2833
|
-
status.dirty();
|
|
2834
|
-
}
|
|
2835
|
-
} else if (unknownKeys === "strip") {
|
|
2836
|
-
} else {
|
|
2837
|
-
throw new Error(`Internal ZodObject error: invalid unknownKeys value.`);
|
|
2838
|
-
}
|
|
2839
|
-
} else {
|
|
2840
|
-
const catchall = this._def.catchall;
|
|
2841
|
-
for (const key of extraKeys) {
|
|
2842
|
-
const value = ctx.data[key];
|
|
2843
|
-
pairs.push({
|
|
2844
|
-
key: { status: "valid", value: key },
|
|
2845
|
-
value: catchall._parse(
|
|
2846
|
-
new ParseInputLazyPath(ctx, value, ctx.path, key)
|
|
2847
|
-
//, ctx.child(key), value, getParsedType(value)
|
|
2848
|
-
),
|
|
2849
|
-
alwaysSet: key in ctx.data
|
|
2850
|
-
});
|
|
2851
|
-
}
|
|
2852
|
-
}
|
|
2853
|
-
if (ctx.common.async) {
|
|
2854
|
-
return Promise.resolve().then(async () => {
|
|
2855
|
-
const syncPairs = [];
|
|
2856
|
-
for (const pair of pairs) {
|
|
2857
|
-
const key = await pair.key;
|
|
2858
|
-
const value = await pair.value;
|
|
2859
|
-
syncPairs.push({
|
|
2860
|
-
key,
|
|
2861
|
-
value,
|
|
2862
|
-
alwaysSet: pair.alwaysSet
|
|
2863
|
-
});
|
|
2864
|
-
}
|
|
2865
|
-
return syncPairs;
|
|
2866
|
-
}).then((syncPairs) => {
|
|
2867
|
-
return ParseStatus.mergeObjectSync(status, syncPairs);
|
|
2868
|
-
});
|
|
2869
|
-
} else {
|
|
2870
|
-
return ParseStatus.mergeObjectSync(status, pairs);
|
|
2871
|
-
}
|
|
2872
|
-
}
|
|
2873
|
-
get shape() {
|
|
2874
|
-
return this._def.shape();
|
|
2875
|
-
}
|
|
2876
|
-
strict(message) {
|
|
2877
|
-
errorUtil.errToObj;
|
|
2878
|
-
return new _ZodObject({
|
|
2879
|
-
...this._def,
|
|
2880
|
-
unknownKeys: "strict",
|
|
2881
|
-
...message !== void 0 ? {
|
|
2882
|
-
errorMap: (issue, ctx) => {
|
|
2883
|
-
const defaultError = this._def.errorMap?.(issue, ctx).message ?? ctx.defaultError;
|
|
2884
|
-
if (issue.code === "unrecognized_keys")
|
|
2885
|
-
return {
|
|
2886
|
-
message: errorUtil.errToObj(message).message ?? defaultError
|
|
2887
|
-
};
|
|
2888
|
-
return {
|
|
2889
|
-
message: defaultError
|
|
2890
|
-
};
|
|
2891
|
-
}
|
|
2892
|
-
} : {}
|
|
2893
|
-
});
|
|
2894
|
-
}
|
|
2895
|
-
strip() {
|
|
2896
|
-
return new _ZodObject({
|
|
2897
|
-
...this._def,
|
|
2898
|
-
unknownKeys: "strip"
|
|
2899
|
-
});
|
|
2900
|
-
}
|
|
2901
|
-
passthrough() {
|
|
2902
|
-
return new _ZodObject({
|
|
2903
|
-
...this._def,
|
|
2904
|
-
unknownKeys: "passthrough"
|
|
2905
|
-
});
|
|
2906
|
-
}
|
|
2907
|
-
// const AugmentFactory =
|
|
2908
|
-
// <Def extends ZodObjectDef>(def: Def) =>
|
|
2909
|
-
// <Augmentation extends ZodRawShape>(
|
|
2910
|
-
// augmentation: Augmentation
|
|
2911
|
-
// ): ZodObject<
|
|
2912
|
-
// extendShape<ReturnType<Def["shape"]>, Augmentation>,
|
|
2913
|
-
// Def["unknownKeys"],
|
|
2914
|
-
// Def["catchall"]
|
|
2915
|
-
// > => {
|
|
2916
|
-
// return new ZodObject({
|
|
2917
|
-
// ...def,
|
|
2918
|
-
// shape: () => ({
|
|
2919
|
-
// ...def.shape(),
|
|
2920
|
-
// ...augmentation,
|
|
2921
|
-
// }),
|
|
2922
|
-
// }) as any;
|
|
2923
|
-
// };
|
|
2924
|
-
extend(augmentation) {
|
|
2925
|
-
return new _ZodObject({
|
|
2926
|
-
...this._def,
|
|
2927
|
-
shape: () => ({
|
|
2928
|
-
...this._def.shape(),
|
|
2929
|
-
...augmentation
|
|
2930
|
-
})
|
|
2931
|
-
});
|
|
2932
|
-
}
|
|
2933
|
-
/**
|
|
2934
|
-
* Prior to zod@1.0.12 there was a bug in the
|
|
2935
|
-
* inferred type of merged objects. Please
|
|
2936
|
-
* upgrade if you are experiencing issues.
|
|
2937
|
-
*/
|
|
2938
|
-
merge(merging) {
|
|
2939
|
-
const merged = new _ZodObject({
|
|
2940
|
-
unknownKeys: merging._def.unknownKeys,
|
|
2941
|
-
catchall: merging._def.catchall,
|
|
2942
|
-
shape: () => ({
|
|
2943
|
-
...this._def.shape(),
|
|
2944
|
-
...merging._def.shape()
|
|
2945
|
-
}),
|
|
2946
|
-
typeName: ZodFirstPartyTypeKind.ZodObject
|
|
2947
|
-
});
|
|
2948
|
-
return merged;
|
|
2949
|
-
}
|
|
2950
|
-
// merge<
|
|
2951
|
-
// Incoming extends AnyZodObject,
|
|
2952
|
-
// Augmentation extends Incoming["shape"],
|
|
2953
|
-
// NewOutput extends {
|
|
2954
|
-
// [k in keyof Augmentation | keyof Output]: k extends keyof Augmentation
|
|
2955
|
-
// ? Augmentation[k]["_output"]
|
|
2956
|
-
// : k extends keyof Output
|
|
2957
|
-
// ? Output[k]
|
|
2958
|
-
// : never;
|
|
2959
|
-
// },
|
|
2960
|
-
// NewInput extends {
|
|
2961
|
-
// [k in keyof Augmentation | keyof Input]: k extends keyof Augmentation
|
|
2962
|
-
// ? Augmentation[k]["_input"]
|
|
2963
|
-
// : k extends keyof Input
|
|
2964
|
-
// ? Input[k]
|
|
2965
|
-
// : never;
|
|
2966
|
-
// }
|
|
2967
|
-
// >(
|
|
2968
|
-
// merging: Incoming
|
|
2969
|
-
// ): ZodObject<
|
|
2970
|
-
// extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
|
|
2971
|
-
// Incoming["_def"]["unknownKeys"],
|
|
2972
|
-
// Incoming["_def"]["catchall"],
|
|
2973
|
-
// NewOutput,
|
|
2974
|
-
// NewInput
|
|
2975
|
-
// > {
|
|
2976
|
-
// const merged: any = new ZodObject({
|
|
2977
|
-
// unknownKeys: merging._def.unknownKeys,
|
|
2978
|
-
// catchall: merging._def.catchall,
|
|
2979
|
-
// shape: () =>
|
|
2980
|
-
// objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
|
|
2981
|
-
// typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
2982
|
-
// }) as any;
|
|
2983
|
-
// return merged;
|
|
2984
|
-
// }
|
|
2985
|
-
setKey(key, schema) {
|
|
2986
|
-
return this.augment({ [key]: schema });
|
|
2987
|
-
}
|
|
2988
|
-
// merge<Incoming extends AnyZodObject>(
|
|
2989
|
-
// merging: Incoming
|
|
2990
|
-
// ): //ZodObject<T & Incoming["_shape"], UnknownKeys, Catchall> = (merging) => {
|
|
2991
|
-
// ZodObject<
|
|
2992
|
-
// extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
|
|
2993
|
-
// Incoming["_def"]["unknownKeys"],
|
|
2994
|
-
// Incoming["_def"]["catchall"]
|
|
2995
|
-
// > {
|
|
2996
|
-
// // const mergedShape = objectUtil.mergeShapes(
|
|
2997
|
-
// // this._def.shape(),
|
|
2998
|
-
// // merging._def.shape()
|
|
2999
|
-
// // );
|
|
3000
|
-
// const merged: any = new ZodObject({
|
|
3001
|
-
// unknownKeys: merging._def.unknownKeys,
|
|
3002
|
-
// catchall: merging._def.catchall,
|
|
3003
|
-
// shape: () =>
|
|
3004
|
-
// objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
|
|
3005
|
-
// typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
3006
|
-
// }) as any;
|
|
3007
|
-
// return merged;
|
|
3008
|
-
// }
|
|
3009
|
-
catchall(index) {
|
|
3010
|
-
return new _ZodObject({
|
|
3011
|
-
...this._def,
|
|
3012
|
-
catchall: index
|
|
3013
|
-
});
|
|
3014
|
-
}
|
|
3015
|
-
pick(mask) {
|
|
3016
|
-
const shape = {};
|
|
3017
|
-
for (const key of util.objectKeys(mask)) {
|
|
3018
|
-
if (mask[key] && this.shape[key]) {
|
|
3019
|
-
shape[key] = this.shape[key];
|
|
3020
|
-
}
|
|
3021
|
-
}
|
|
3022
|
-
return new _ZodObject({
|
|
3023
|
-
...this._def,
|
|
3024
|
-
shape: () => shape
|
|
3025
|
-
});
|
|
3026
|
-
}
|
|
3027
|
-
omit(mask) {
|
|
3028
|
-
const shape = {};
|
|
3029
|
-
for (const key of util.objectKeys(this.shape)) {
|
|
3030
|
-
if (!mask[key]) {
|
|
3031
|
-
shape[key] = this.shape[key];
|
|
3032
|
-
}
|
|
3033
|
-
}
|
|
3034
|
-
return new _ZodObject({
|
|
3035
|
-
...this._def,
|
|
3036
|
-
shape: () => shape
|
|
3037
|
-
});
|
|
3038
|
-
}
|
|
3039
|
-
/**
|
|
3040
|
-
* @deprecated
|
|
3041
|
-
*/
|
|
3042
|
-
deepPartial() {
|
|
3043
|
-
return deepPartialify(this);
|
|
3044
|
-
}
|
|
3045
|
-
partial(mask) {
|
|
3046
|
-
const newShape = {};
|
|
3047
|
-
for (const key of util.objectKeys(this.shape)) {
|
|
3048
|
-
const fieldSchema = this.shape[key];
|
|
3049
|
-
if (mask && !mask[key]) {
|
|
3050
|
-
newShape[key] = fieldSchema;
|
|
3051
|
-
} else {
|
|
3052
|
-
newShape[key] = fieldSchema.optional();
|
|
3053
|
-
}
|
|
3054
|
-
}
|
|
3055
|
-
return new _ZodObject({
|
|
3056
|
-
...this._def,
|
|
3057
|
-
shape: () => newShape
|
|
3058
|
-
});
|
|
3059
|
-
}
|
|
3060
|
-
required(mask) {
|
|
3061
|
-
const newShape = {};
|
|
3062
|
-
for (const key of util.objectKeys(this.shape)) {
|
|
3063
|
-
if (mask && !mask[key]) {
|
|
3064
|
-
newShape[key] = this.shape[key];
|
|
3065
|
-
} else {
|
|
3066
|
-
const fieldSchema = this.shape[key];
|
|
3067
|
-
let newField = fieldSchema;
|
|
3068
|
-
while (newField instanceof ZodOptional) {
|
|
3069
|
-
newField = newField._def.innerType;
|
|
3070
|
-
}
|
|
3071
|
-
newShape[key] = newField;
|
|
3072
|
-
}
|
|
3073
|
-
}
|
|
3074
|
-
return new _ZodObject({
|
|
3075
|
-
...this._def,
|
|
3076
|
-
shape: () => newShape
|
|
3077
|
-
});
|
|
3078
|
-
}
|
|
3079
|
-
keyof() {
|
|
3080
|
-
return createZodEnum(util.objectKeys(this.shape));
|
|
3081
|
-
}
|
|
3082
|
-
};
|
|
3083
|
-
ZodObject.create = (shape, params) => {
|
|
3084
|
-
return new ZodObject({
|
|
3085
|
-
shape: () => shape,
|
|
3086
|
-
unknownKeys: "strip",
|
|
3087
|
-
catchall: ZodNever.create(),
|
|
3088
|
-
typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
3089
|
-
...processCreateParams(params)
|
|
3090
|
-
});
|
|
3091
|
-
};
|
|
3092
|
-
ZodObject.strictCreate = (shape, params) => {
|
|
3093
|
-
return new ZodObject({
|
|
3094
|
-
shape: () => shape,
|
|
3095
|
-
unknownKeys: "strict",
|
|
3096
|
-
catchall: ZodNever.create(),
|
|
3097
|
-
typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
3098
|
-
...processCreateParams(params)
|
|
3099
|
-
});
|
|
3100
|
-
};
|
|
3101
|
-
ZodObject.lazycreate = (shape, params) => {
|
|
3102
|
-
return new ZodObject({
|
|
3103
|
-
shape,
|
|
3104
|
-
unknownKeys: "strip",
|
|
3105
|
-
catchall: ZodNever.create(),
|
|
3106
|
-
typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
3107
|
-
...processCreateParams(params)
|
|
3108
|
-
});
|
|
3109
|
-
};
|
|
3110
|
-
var ZodUnion = class extends ZodType {
|
|
3111
|
-
_parse(input) {
|
|
3112
|
-
const { ctx } = this._processInputParams(input);
|
|
3113
|
-
const options = this._def.options;
|
|
3114
|
-
function handleResults(results) {
|
|
3115
|
-
for (const result of results) {
|
|
3116
|
-
if (result.result.status === "valid") {
|
|
3117
|
-
return result.result;
|
|
3118
|
-
}
|
|
3119
|
-
}
|
|
3120
|
-
for (const result of results) {
|
|
3121
|
-
if (result.result.status === "dirty") {
|
|
3122
|
-
ctx.common.issues.push(...result.ctx.common.issues);
|
|
3123
|
-
return result.result;
|
|
3124
|
-
}
|
|
3125
|
-
}
|
|
3126
|
-
const unionErrors = results.map((result) => new ZodError(result.ctx.common.issues));
|
|
3127
|
-
addIssueToContext(ctx, {
|
|
3128
|
-
code: ZodIssueCode.invalid_union,
|
|
3129
|
-
unionErrors
|
|
3130
|
-
});
|
|
3131
|
-
return INVALID;
|
|
3132
|
-
}
|
|
3133
|
-
if (ctx.common.async) {
|
|
3134
|
-
return Promise.all(options.map(async (option) => {
|
|
3135
|
-
const childCtx = {
|
|
3136
|
-
...ctx,
|
|
3137
|
-
common: {
|
|
3138
|
-
...ctx.common,
|
|
3139
|
-
issues: []
|
|
3140
|
-
},
|
|
3141
|
-
parent: null
|
|
3142
|
-
};
|
|
3143
|
-
return {
|
|
3144
|
-
result: await option._parseAsync({
|
|
3145
|
-
data: ctx.data,
|
|
3146
|
-
path: ctx.path,
|
|
3147
|
-
parent: childCtx
|
|
3148
|
-
}),
|
|
3149
|
-
ctx: childCtx
|
|
3150
|
-
};
|
|
3151
|
-
})).then(handleResults);
|
|
3152
|
-
} else {
|
|
3153
|
-
let dirty = void 0;
|
|
3154
|
-
const issues = [];
|
|
3155
|
-
for (const option of options) {
|
|
3156
|
-
const childCtx = {
|
|
3157
|
-
...ctx,
|
|
3158
|
-
common: {
|
|
3159
|
-
...ctx.common,
|
|
3160
|
-
issues: []
|
|
3161
|
-
},
|
|
3162
|
-
parent: null
|
|
3163
|
-
};
|
|
3164
|
-
const result = option._parseSync({
|
|
3165
|
-
data: ctx.data,
|
|
3166
|
-
path: ctx.path,
|
|
3167
|
-
parent: childCtx
|
|
3168
|
-
});
|
|
3169
|
-
if (result.status === "valid") {
|
|
3170
|
-
return result;
|
|
3171
|
-
} else if (result.status === "dirty" && !dirty) {
|
|
3172
|
-
dirty = { result, ctx: childCtx };
|
|
3173
|
-
}
|
|
3174
|
-
if (childCtx.common.issues.length) {
|
|
3175
|
-
issues.push(childCtx.common.issues);
|
|
3176
|
-
}
|
|
3177
|
-
}
|
|
3178
|
-
if (dirty) {
|
|
3179
|
-
ctx.common.issues.push(...dirty.ctx.common.issues);
|
|
3180
|
-
return dirty.result;
|
|
3181
|
-
}
|
|
3182
|
-
const unionErrors = issues.map((issues2) => new ZodError(issues2));
|
|
3183
|
-
addIssueToContext(ctx, {
|
|
3184
|
-
code: ZodIssueCode.invalid_union,
|
|
3185
|
-
unionErrors
|
|
3186
|
-
});
|
|
3187
|
-
return INVALID;
|
|
3188
|
-
}
|
|
3189
|
-
}
|
|
3190
|
-
get options() {
|
|
3191
|
-
return this._def.options;
|
|
3192
|
-
}
|
|
3193
|
-
};
|
|
3194
|
-
ZodUnion.create = (types, params) => {
|
|
3195
|
-
return new ZodUnion({
|
|
3196
|
-
options: types,
|
|
3197
|
-
typeName: ZodFirstPartyTypeKind.ZodUnion,
|
|
3198
|
-
...processCreateParams(params)
|
|
3199
|
-
});
|
|
3200
|
-
};
|
|
3201
|
-
var getDiscriminator = (type) => {
|
|
3202
|
-
if (type instanceof ZodLazy) {
|
|
3203
|
-
return getDiscriminator(type.schema);
|
|
3204
|
-
} else if (type instanceof ZodEffects) {
|
|
3205
|
-
return getDiscriminator(type.innerType());
|
|
3206
|
-
} else if (type instanceof ZodLiteral) {
|
|
3207
|
-
return [type.value];
|
|
3208
|
-
} else if (type instanceof ZodEnum) {
|
|
3209
|
-
return type.options;
|
|
3210
|
-
} else if (type instanceof ZodNativeEnum) {
|
|
3211
|
-
return util.objectValues(type.enum);
|
|
3212
|
-
} else if (type instanceof ZodDefault) {
|
|
3213
|
-
return getDiscriminator(type._def.innerType);
|
|
3214
|
-
} else if (type instanceof ZodUndefined) {
|
|
3215
|
-
return [void 0];
|
|
3216
|
-
} else if (type instanceof ZodNull) {
|
|
3217
|
-
return [null];
|
|
3218
|
-
} else if (type instanceof ZodOptional) {
|
|
3219
|
-
return [void 0, ...getDiscriminator(type.unwrap())];
|
|
3220
|
-
} else if (type instanceof ZodNullable) {
|
|
3221
|
-
return [null, ...getDiscriminator(type.unwrap())];
|
|
3222
|
-
} else if (type instanceof ZodBranded) {
|
|
3223
|
-
return getDiscriminator(type.unwrap());
|
|
3224
|
-
} else if (type instanceof ZodReadonly) {
|
|
3225
|
-
return getDiscriminator(type.unwrap());
|
|
3226
|
-
} else if (type instanceof ZodCatch) {
|
|
3227
|
-
return getDiscriminator(type._def.innerType);
|
|
3228
|
-
} else {
|
|
3229
|
-
return [];
|
|
3230
|
-
}
|
|
3231
|
-
};
|
|
3232
|
-
var ZodDiscriminatedUnion = class _ZodDiscriminatedUnion extends ZodType {
|
|
3233
|
-
_parse(input) {
|
|
3234
|
-
const { ctx } = this._processInputParams(input);
|
|
3235
|
-
if (ctx.parsedType !== ZodParsedType.object) {
|
|
3236
|
-
addIssueToContext(ctx, {
|
|
3237
|
-
code: ZodIssueCode.invalid_type,
|
|
3238
|
-
expected: ZodParsedType.object,
|
|
3239
|
-
received: ctx.parsedType
|
|
3240
|
-
});
|
|
3241
|
-
return INVALID;
|
|
3242
|
-
}
|
|
3243
|
-
const discriminator = this.discriminator;
|
|
3244
|
-
const discriminatorValue = ctx.data[discriminator];
|
|
3245
|
-
const option = this.optionsMap.get(discriminatorValue);
|
|
3246
|
-
if (!option) {
|
|
3247
|
-
addIssueToContext(ctx, {
|
|
3248
|
-
code: ZodIssueCode.invalid_union_discriminator,
|
|
3249
|
-
options: Array.from(this.optionsMap.keys()),
|
|
3250
|
-
path: [discriminator]
|
|
3251
|
-
});
|
|
3252
|
-
return INVALID;
|
|
3253
|
-
}
|
|
3254
|
-
if (ctx.common.async) {
|
|
3255
|
-
return option._parseAsync({
|
|
3256
|
-
data: ctx.data,
|
|
3257
|
-
path: ctx.path,
|
|
3258
|
-
parent: ctx
|
|
3259
|
-
});
|
|
3260
|
-
} else {
|
|
3261
|
-
return option._parseSync({
|
|
3262
|
-
data: ctx.data,
|
|
3263
|
-
path: ctx.path,
|
|
3264
|
-
parent: ctx
|
|
3265
|
-
});
|
|
3266
|
-
}
|
|
3267
|
-
}
|
|
3268
|
-
get discriminator() {
|
|
3269
|
-
return this._def.discriminator;
|
|
3270
|
-
}
|
|
3271
|
-
get options() {
|
|
3272
|
-
return this._def.options;
|
|
3273
|
-
}
|
|
3274
|
-
get optionsMap() {
|
|
3275
|
-
return this._def.optionsMap;
|
|
3276
|
-
}
|
|
3277
|
-
/**
|
|
3278
|
-
* The constructor of the discriminated union schema. Its behaviour is very similar to that of the normal z.union() constructor.
|
|
3279
|
-
* However, it only allows a union of objects, all of which need to share a discriminator property. This property must
|
|
3280
|
-
* have a different value for each object in the union.
|
|
3281
|
-
* @param discriminator the name of the discriminator property
|
|
3282
|
-
* @param types an array of object schemas
|
|
3283
|
-
* @param params
|
|
3284
|
-
*/
|
|
3285
|
-
static create(discriminator, options, params) {
|
|
3286
|
-
const optionsMap = /* @__PURE__ */ new Map();
|
|
3287
|
-
for (const type of options) {
|
|
3288
|
-
const discriminatorValues = getDiscriminator(type.shape[discriminator]);
|
|
3289
|
-
if (!discriminatorValues.length) {
|
|
3290
|
-
throw new Error(`A discriminator value for key \`${discriminator}\` could not be extracted from all schema options`);
|
|
3291
|
-
}
|
|
3292
|
-
for (const value of discriminatorValues) {
|
|
3293
|
-
if (optionsMap.has(value)) {
|
|
3294
|
-
throw new Error(`Discriminator property ${String(discriminator)} has duplicate value ${String(value)}`);
|
|
3295
|
-
}
|
|
3296
|
-
optionsMap.set(value, type);
|
|
3297
|
-
}
|
|
3298
|
-
}
|
|
3299
|
-
return new _ZodDiscriminatedUnion({
|
|
3300
|
-
typeName: ZodFirstPartyTypeKind.ZodDiscriminatedUnion,
|
|
3301
|
-
discriminator,
|
|
3302
|
-
options,
|
|
3303
|
-
optionsMap,
|
|
3304
|
-
...processCreateParams(params)
|
|
3305
|
-
});
|
|
3306
|
-
}
|
|
3307
|
-
};
|
|
3308
|
-
function mergeValues(a, b) {
|
|
3309
|
-
const aType = getParsedType(a);
|
|
3310
|
-
const bType = getParsedType(b);
|
|
3311
|
-
if (a === b) {
|
|
3312
|
-
return { valid: true, data: a };
|
|
3313
|
-
} else if (aType === ZodParsedType.object && bType === ZodParsedType.object) {
|
|
3314
|
-
const bKeys = util.objectKeys(b);
|
|
3315
|
-
const sharedKeys = util.objectKeys(a).filter((key) => bKeys.indexOf(key) !== -1);
|
|
3316
|
-
const newObj = { ...a, ...b };
|
|
3317
|
-
for (const key of sharedKeys) {
|
|
3318
|
-
const sharedValue = mergeValues(a[key], b[key]);
|
|
3319
|
-
if (!sharedValue.valid) {
|
|
3320
|
-
return { valid: false };
|
|
3321
|
-
}
|
|
3322
|
-
newObj[key] = sharedValue.data;
|
|
3323
|
-
}
|
|
3324
|
-
return { valid: true, data: newObj };
|
|
3325
|
-
} else if (aType === ZodParsedType.array && bType === ZodParsedType.array) {
|
|
3326
|
-
if (a.length !== b.length) {
|
|
3327
|
-
return { valid: false };
|
|
3328
|
-
}
|
|
3329
|
-
const newArray = [];
|
|
3330
|
-
for (let index = 0; index < a.length; index++) {
|
|
3331
|
-
const itemA = a[index];
|
|
3332
|
-
const itemB = b[index];
|
|
3333
|
-
const sharedValue = mergeValues(itemA, itemB);
|
|
3334
|
-
if (!sharedValue.valid) {
|
|
3335
|
-
return { valid: false };
|
|
3336
|
-
}
|
|
3337
|
-
newArray.push(sharedValue.data);
|
|
3338
|
-
}
|
|
3339
|
-
return { valid: true, data: newArray };
|
|
3340
|
-
} else if (aType === ZodParsedType.date && bType === ZodParsedType.date && +a === +b) {
|
|
3341
|
-
return { valid: true, data: a };
|
|
3342
|
-
} else {
|
|
3343
|
-
return { valid: false };
|
|
3344
|
-
}
|
|
3345
|
-
}
|
|
3346
|
-
var ZodIntersection = class extends ZodType {
|
|
3347
|
-
_parse(input) {
|
|
3348
|
-
const { status, ctx } = this._processInputParams(input);
|
|
3349
|
-
const handleParsed = (parsedLeft, parsedRight) => {
|
|
3350
|
-
if (isAborted(parsedLeft) || isAborted(parsedRight)) {
|
|
3351
|
-
return INVALID;
|
|
3352
|
-
}
|
|
3353
|
-
const merged = mergeValues(parsedLeft.value, parsedRight.value);
|
|
3354
|
-
if (!merged.valid) {
|
|
3355
|
-
addIssueToContext(ctx, {
|
|
3356
|
-
code: ZodIssueCode.invalid_intersection_types
|
|
3357
|
-
});
|
|
3358
|
-
return INVALID;
|
|
3359
|
-
}
|
|
3360
|
-
if (isDirty(parsedLeft) || isDirty(parsedRight)) {
|
|
3361
|
-
status.dirty();
|
|
3362
|
-
}
|
|
3363
|
-
return { status: status.value, value: merged.data };
|
|
3364
|
-
};
|
|
3365
|
-
if (ctx.common.async) {
|
|
3366
|
-
return Promise.all([
|
|
3367
|
-
this._def.left._parseAsync({
|
|
3368
|
-
data: ctx.data,
|
|
3369
|
-
path: ctx.path,
|
|
3370
|
-
parent: ctx
|
|
3371
|
-
}),
|
|
3372
|
-
this._def.right._parseAsync({
|
|
3373
|
-
data: ctx.data,
|
|
3374
|
-
path: ctx.path,
|
|
3375
|
-
parent: ctx
|
|
3376
|
-
})
|
|
3377
|
-
]).then(([left, right]) => handleParsed(left, right));
|
|
3378
|
-
} else {
|
|
3379
|
-
return handleParsed(this._def.left._parseSync({
|
|
3380
|
-
data: ctx.data,
|
|
3381
|
-
path: ctx.path,
|
|
3382
|
-
parent: ctx
|
|
3383
|
-
}), this._def.right._parseSync({
|
|
3384
|
-
data: ctx.data,
|
|
3385
|
-
path: ctx.path,
|
|
3386
|
-
parent: ctx
|
|
3387
|
-
}));
|
|
3388
|
-
}
|
|
3389
|
-
}
|
|
3390
|
-
};
|
|
3391
|
-
ZodIntersection.create = (left, right, params) => {
|
|
3392
|
-
return new ZodIntersection({
|
|
3393
|
-
left,
|
|
3394
|
-
right,
|
|
3395
|
-
typeName: ZodFirstPartyTypeKind.ZodIntersection,
|
|
3396
|
-
...processCreateParams(params)
|
|
3397
|
-
});
|
|
3398
|
-
};
|
|
3399
|
-
var ZodTuple = class _ZodTuple extends ZodType {
|
|
3400
|
-
_parse(input) {
|
|
3401
|
-
const { status, ctx } = this._processInputParams(input);
|
|
3402
|
-
if (ctx.parsedType !== ZodParsedType.array) {
|
|
3403
|
-
addIssueToContext(ctx, {
|
|
3404
|
-
code: ZodIssueCode.invalid_type,
|
|
3405
|
-
expected: ZodParsedType.array,
|
|
3406
|
-
received: ctx.parsedType
|
|
3407
|
-
});
|
|
3408
|
-
return INVALID;
|
|
3409
|
-
}
|
|
3410
|
-
if (ctx.data.length < this._def.items.length) {
|
|
3411
|
-
addIssueToContext(ctx, {
|
|
3412
|
-
code: ZodIssueCode.too_small,
|
|
3413
|
-
minimum: this._def.items.length,
|
|
3414
|
-
inclusive: true,
|
|
3415
|
-
exact: false,
|
|
3416
|
-
type: "array"
|
|
3417
|
-
});
|
|
3418
|
-
return INVALID;
|
|
3419
|
-
}
|
|
3420
|
-
const rest = this._def.rest;
|
|
3421
|
-
if (!rest && ctx.data.length > this._def.items.length) {
|
|
3422
|
-
addIssueToContext(ctx, {
|
|
3423
|
-
code: ZodIssueCode.too_big,
|
|
3424
|
-
maximum: this._def.items.length,
|
|
3425
|
-
inclusive: true,
|
|
3426
|
-
exact: false,
|
|
3427
|
-
type: "array"
|
|
3428
|
-
});
|
|
3429
|
-
status.dirty();
|
|
3430
|
-
}
|
|
3431
|
-
const items = [...ctx.data].map((item, itemIndex) => {
|
|
3432
|
-
const schema = this._def.items[itemIndex] || this._def.rest;
|
|
3433
|
-
if (!schema)
|
|
3434
|
-
return null;
|
|
3435
|
-
return schema._parse(new ParseInputLazyPath(ctx, item, ctx.path, itemIndex));
|
|
3436
|
-
}).filter((x) => !!x);
|
|
3437
|
-
if (ctx.common.async) {
|
|
3438
|
-
return Promise.all(items).then((results) => {
|
|
3439
|
-
return ParseStatus.mergeArray(status, results);
|
|
3440
|
-
});
|
|
3441
|
-
} else {
|
|
3442
|
-
return ParseStatus.mergeArray(status, items);
|
|
3443
|
-
}
|
|
3444
|
-
}
|
|
3445
|
-
get items() {
|
|
3446
|
-
return this._def.items;
|
|
3447
|
-
}
|
|
3448
|
-
rest(rest) {
|
|
3449
|
-
return new _ZodTuple({
|
|
3450
|
-
...this._def,
|
|
3451
|
-
rest
|
|
3452
|
-
});
|
|
3453
|
-
}
|
|
3454
|
-
};
|
|
3455
|
-
ZodTuple.create = (schemas, params) => {
|
|
3456
|
-
if (!Array.isArray(schemas)) {
|
|
3457
|
-
throw new Error("You must pass an array of schemas to z.tuple([ ... ])");
|
|
3458
|
-
}
|
|
3459
|
-
return new ZodTuple({
|
|
3460
|
-
items: schemas,
|
|
3461
|
-
typeName: ZodFirstPartyTypeKind.ZodTuple,
|
|
3462
|
-
rest: null,
|
|
3463
|
-
...processCreateParams(params)
|
|
3464
|
-
});
|
|
3465
|
-
};
|
|
3466
|
-
var ZodRecord = class _ZodRecord extends ZodType {
|
|
3467
|
-
get keySchema() {
|
|
3468
|
-
return this._def.keyType;
|
|
3469
|
-
}
|
|
3470
|
-
get valueSchema() {
|
|
3471
|
-
return this._def.valueType;
|
|
3472
|
-
}
|
|
3473
|
-
_parse(input) {
|
|
3474
|
-
const { status, ctx } = this._processInputParams(input);
|
|
3475
|
-
if (ctx.parsedType !== ZodParsedType.object) {
|
|
3476
|
-
addIssueToContext(ctx, {
|
|
3477
|
-
code: ZodIssueCode.invalid_type,
|
|
3478
|
-
expected: ZodParsedType.object,
|
|
3479
|
-
received: ctx.parsedType
|
|
3480
|
-
});
|
|
3481
|
-
return INVALID;
|
|
3482
|
-
}
|
|
3483
|
-
const pairs = [];
|
|
3484
|
-
const keyType = this._def.keyType;
|
|
3485
|
-
const valueType = this._def.valueType;
|
|
3486
|
-
for (const key in ctx.data) {
|
|
3487
|
-
pairs.push({
|
|
3488
|
-
key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, key)),
|
|
3489
|
-
value: valueType._parse(new ParseInputLazyPath(ctx, ctx.data[key], ctx.path, key)),
|
|
3490
|
-
alwaysSet: key in ctx.data
|
|
3491
|
-
});
|
|
3492
|
-
}
|
|
3493
|
-
if (ctx.common.async) {
|
|
3494
|
-
return ParseStatus.mergeObjectAsync(status, pairs);
|
|
3495
|
-
} else {
|
|
3496
|
-
return ParseStatus.mergeObjectSync(status, pairs);
|
|
3497
|
-
}
|
|
3498
|
-
}
|
|
3499
|
-
get element() {
|
|
3500
|
-
return this._def.valueType;
|
|
3501
|
-
}
|
|
3502
|
-
static create(first, second, third) {
|
|
3503
|
-
if (second instanceof ZodType) {
|
|
3504
|
-
return new _ZodRecord({
|
|
3505
|
-
keyType: first,
|
|
3506
|
-
valueType: second,
|
|
3507
|
-
typeName: ZodFirstPartyTypeKind.ZodRecord,
|
|
3508
|
-
...processCreateParams(third)
|
|
3509
|
-
});
|
|
3510
|
-
}
|
|
3511
|
-
return new _ZodRecord({
|
|
3512
|
-
keyType: ZodString.create(),
|
|
3513
|
-
valueType: first,
|
|
3514
|
-
typeName: ZodFirstPartyTypeKind.ZodRecord,
|
|
3515
|
-
...processCreateParams(second)
|
|
3516
|
-
});
|
|
3517
|
-
}
|
|
3518
|
-
};
|
|
3519
|
-
var ZodMap = class extends ZodType {
|
|
3520
|
-
get keySchema() {
|
|
3521
|
-
return this._def.keyType;
|
|
3522
|
-
}
|
|
3523
|
-
get valueSchema() {
|
|
3524
|
-
return this._def.valueType;
|
|
3525
|
-
}
|
|
3526
|
-
_parse(input) {
|
|
3527
|
-
const { status, ctx } = this._processInputParams(input);
|
|
3528
|
-
if (ctx.parsedType !== ZodParsedType.map) {
|
|
3529
|
-
addIssueToContext(ctx, {
|
|
3530
|
-
code: ZodIssueCode.invalid_type,
|
|
3531
|
-
expected: ZodParsedType.map,
|
|
3532
|
-
received: ctx.parsedType
|
|
3533
|
-
});
|
|
3534
|
-
return INVALID;
|
|
3535
|
-
}
|
|
3536
|
-
const keyType = this._def.keyType;
|
|
3537
|
-
const valueType = this._def.valueType;
|
|
3538
|
-
const pairs = [...ctx.data.entries()].map(([key, value], index) => {
|
|
3539
|
-
return {
|
|
3540
|
-
key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, [index, "key"])),
|
|
3541
|
-
value: valueType._parse(new ParseInputLazyPath(ctx, value, ctx.path, [index, "value"]))
|
|
3542
|
-
};
|
|
3543
|
-
});
|
|
3544
|
-
if (ctx.common.async) {
|
|
3545
|
-
const finalMap = /* @__PURE__ */ new Map();
|
|
3546
|
-
return Promise.resolve().then(async () => {
|
|
3547
|
-
for (const pair of pairs) {
|
|
3548
|
-
const key = await pair.key;
|
|
3549
|
-
const value = await pair.value;
|
|
3550
|
-
if (key.status === "aborted" || value.status === "aborted") {
|
|
3551
|
-
return INVALID;
|
|
3552
|
-
}
|
|
3553
|
-
if (key.status === "dirty" || value.status === "dirty") {
|
|
3554
|
-
status.dirty();
|
|
3555
|
-
}
|
|
3556
|
-
finalMap.set(key.value, value.value);
|
|
3557
|
-
}
|
|
3558
|
-
return { status: status.value, value: finalMap };
|
|
3559
|
-
});
|
|
3560
|
-
} else {
|
|
3561
|
-
const finalMap = /* @__PURE__ */ new Map();
|
|
3562
|
-
for (const pair of pairs) {
|
|
3563
|
-
const key = pair.key;
|
|
3564
|
-
const value = pair.value;
|
|
3565
|
-
if (key.status === "aborted" || value.status === "aborted") {
|
|
3566
|
-
return INVALID;
|
|
3567
|
-
}
|
|
3568
|
-
if (key.status === "dirty" || value.status === "dirty") {
|
|
3569
|
-
status.dirty();
|
|
3570
|
-
}
|
|
3571
|
-
finalMap.set(key.value, value.value);
|
|
3572
|
-
}
|
|
3573
|
-
return { status: status.value, value: finalMap };
|
|
3574
|
-
}
|
|
3575
|
-
}
|
|
3576
|
-
};
|
|
3577
|
-
ZodMap.create = (keyType, valueType, params) => {
|
|
3578
|
-
return new ZodMap({
|
|
3579
|
-
valueType,
|
|
3580
|
-
keyType,
|
|
3581
|
-
typeName: ZodFirstPartyTypeKind.ZodMap,
|
|
3582
|
-
...processCreateParams(params)
|
|
3583
|
-
});
|
|
3584
|
-
};
|
|
3585
|
-
var ZodSet = class _ZodSet extends ZodType {
|
|
3586
|
-
_parse(input) {
|
|
3587
|
-
const { status, ctx } = this._processInputParams(input);
|
|
3588
|
-
if (ctx.parsedType !== ZodParsedType.set) {
|
|
3589
|
-
addIssueToContext(ctx, {
|
|
3590
|
-
code: ZodIssueCode.invalid_type,
|
|
3591
|
-
expected: ZodParsedType.set,
|
|
3592
|
-
received: ctx.parsedType
|
|
3593
|
-
});
|
|
3594
|
-
return INVALID;
|
|
3595
|
-
}
|
|
3596
|
-
const def = this._def;
|
|
3597
|
-
if (def.minSize !== null) {
|
|
3598
|
-
if (ctx.data.size < def.minSize.value) {
|
|
3599
|
-
addIssueToContext(ctx, {
|
|
3600
|
-
code: ZodIssueCode.too_small,
|
|
3601
|
-
minimum: def.minSize.value,
|
|
3602
|
-
type: "set",
|
|
3603
|
-
inclusive: true,
|
|
3604
|
-
exact: false,
|
|
3605
|
-
message: def.minSize.message
|
|
3606
|
-
});
|
|
3607
|
-
status.dirty();
|
|
3608
|
-
}
|
|
3609
|
-
}
|
|
3610
|
-
if (def.maxSize !== null) {
|
|
3611
|
-
if (ctx.data.size > def.maxSize.value) {
|
|
3612
|
-
addIssueToContext(ctx, {
|
|
3613
|
-
code: ZodIssueCode.too_big,
|
|
3614
|
-
maximum: def.maxSize.value,
|
|
3615
|
-
type: "set",
|
|
3616
|
-
inclusive: true,
|
|
3617
|
-
exact: false,
|
|
3618
|
-
message: def.maxSize.message
|
|
3619
|
-
});
|
|
3620
|
-
status.dirty();
|
|
3621
|
-
}
|
|
3622
|
-
}
|
|
3623
|
-
const valueType = this._def.valueType;
|
|
3624
|
-
function finalizeSet(elements2) {
|
|
3625
|
-
const parsedSet = /* @__PURE__ */ new Set();
|
|
3626
|
-
for (const element of elements2) {
|
|
3627
|
-
if (element.status === "aborted")
|
|
3628
|
-
return INVALID;
|
|
3629
|
-
if (element.status === "dirty")
|
|
3630
|
-
status.dirty();
|
|
3631
|
-
parsedSet.add(element.value);
|
|
3632
|
-
}
|
|
3633
|
-
return { status: status.value, value: parsedSet };
|
|
3634
|
-
}
|
|
3635
|
-
const elements = [...ctx.data.values()].map((item, i) => valueType._parse(new ParseInputLazyPath(ctx, item, ctx.path, i)));
|
|
3636
|
-
if (ctx.common.async) {
|
|
3637
|
-
return Promise.all(elements).then((elements2) => finalizeSet(elements2));
|
|
3638
|
-
} else {
|
|
3639
|
-
return finalizeSet(elements);
|
|
3640
|
-
}
|
|
3641
|
-
}
|
|
3642
|
-
min(minSize, message) {
|
|
3643
|
-
return new _ZodSet({
|
|
3644
|
-
...this._def,
|
|
3645
|
-
minSize: { value: minSize, message: errorUtil.toString(message) }
|
|
3646
|
-
});
|
|
3647
|
-
}
|
|
3648
|
-
max(maxSize, message) {
|
|
3649
|
-
return new _ZodSet({
|
|
3650
|
-
...this._def,
|
|
3651
|
-
maxSize: { value: maxSize, message: errorUtil.toString(message) }
|
|
3652
|
-
});
|
|
3653
|
-
}
|
|
3654
|
-
size(size, message) {
|
|
3655
|
-
return this.min(size, message).max(size, message);
|
|
3656
|
-
}
|
|
3657
|
-
nonempty(message) {
|
|
3658
|
-
return this.min(1, message);
|
|
3659
|
-
}
|
|
3660
|
-
};
|
|
3661
|
-
ZodSet.create = (valueType, params) => {
|
|
3662
|
-
return new ZodSet({
|
|
3663
|
-
valueType,
|
|
3664
|
-
minSize: null,
|
|
3665
|
-
maxSize: null,
|
|
3666
|
-
typeName: ZodFirstPartyTypeKind.ZodSet,
|
|
3667
|
-
...processCreateParams(params)
|
|
3668
|
-
});
|
|
3669
|
-
};
|
|
3670
|
-
var ZodFunction = class _ZodFunction extends ZodType {
|
|
3671
|
-
constructor() {
|
|
3672
|
-
super(...arguments);
|
|
3673
|
-
this.validate = this.implement;
|
|
3674
|
-
}
|
|
3675
|
-
_parse(input) {
|
|
3676
|
-
const { ctx } = this._processInputParams(input);
|
|
3677
|
-
if (ctx.parsedType !== ZodParsedType.function) {
|
|
3678
|
-
addIssueToContext(ctx, {
|
|
3679
|
-
code: ZodIssueCode.invalid_type,
|
|
3680
|
-
expected: ZodParsedType.function,
|
|
3681
|
-
received: ctx.parsedType
|
|
3682
|
-
});
|
|
3683
|
-
return INVALID;
|
|
3684
|
-
}
|
|
3685
|
-
function makeArgsIssue(args, error) {
|
|
3686
|
-
return makeIssue({
|
|
3687
|
-
data: args,
|
|
3688
|
-
path: ctx.path,
|
|
3689
|
-
errorMaps: [ctx.common.contextualErrorMap, ctx.schemaErrorMap, getErrorMap(), en_default].filter((x) => !!x),
|
|
3690
|
-
issueData: {
|
|
3691
|
-
code: ZodIssueCode.invalid_arguments,
|
|
3692
|
-
argumentsError: error
|
|
3693
|
-
}
|
|
3694
|
-
});
|
|
3695
|
-
}
|
|
3696
|
-
function makeReturnsIssue(returns, error) {
|
|
3697
|
-
return makeIssue({
|
|
3698
|
-
data: returns,
|
|
3699
|
-
path: ctx.path,
|
|
3700
|
-
errorMaps: [ctx.common.contextualErrorMap, ctx.schemaErrorMap, getErrorMap(), en_default].filter((x) => !!x),
|
|
3701
|
-
issueData: {
|
|
3702
|
-
code: ZodIssueCode.invalid_return_type,
|
|
3703
|
-
returnTypeError: error
|
|
3704
|
-
}
|
|
3705
|
-
});
|
|
3706
|
-
}
|
|
3707
|
-
const params = { errorMap: ctx.common.contextualErrorMap };
|
|
3708
|
-
const fn = ctx.data;
|
|
3709
|
-
if (this._def.returns instanceof ZodPromise) {
|
|
3710
|
-
const me = this;
|
|
3711
|
-
return OK(async function(...args) {
|
|
3712
|
-
const error = new ZodError([]);
|
|
3713
|
-
const parsedArgs = await me._def.args.parseAsync(args, params).catch((e) => {
|
|
3714
|
-
error.addIssue(makeArgsIssue(args, e));
|
|
3715
|
-
throw error;
|
|
3716
|
-
});
|
|
3717
|
-
const result = await Reflect.apply(fn, this, parsedArgs);
|
|
3718
|
-
const parsedReturns = await me._def.returns._def.type.parseAsync(result, params).catch((e) => {
|
|
3719
|
-
error.addIssue(makeReturnsIssue(result, e));
|
|
3720
|
-
throw error;
|
|
3721
|
-
});
|
|
3722
|
-
return parsedReturns;
|
|
3723
|
-
});
|
|
3724
|
-
} else {
|
|
3725
|
-
const me = this;
|
|
3726
|
-
return OK(function(...args) {
|
|
3727
|
-
const parsedArgs = me._def.args.safeParse(args, params);
|
|
3728
|
-
if (!parsedArgs.success) {
|
|
3729
|
-
throw new ZodError([makeArgsIssue(args, parsedArgs.error)]);
|
|
3730
|
-
}
|
|
3731
|
-
const result = Reflect.apply(fn, this, parsedArgs.data);
|
|
3732
|
-
const parsedReturns = me._def.returns.safeParse(result, params);
|
|
3733
|
-
if (!parsedReturns.success) {
|
|
3734
|
-
throw new ZodError([makeReturnsIssue(result, parsedReturns.error)]);
|
|
3735
|
-
}
|
|
3736
|
-
return parsedReturns.data;
|
|
3737
|
-
});
|
|
3738
|
-
}
|
|
3739
|
-
}
|
|
3740
|
-
parameters() {
|
|
3741
|
-
return this._def.args;
|
|
3742
|
-
}
|
|
3743
|
-
returnType() {
|
|
3744
|
-
return this._def.returns;
|
|
3745
|
-
}
|
|
3746
|
-
args(...items) {
|
|
3747
|
-
return new _ZodFunction({
|
|
3748
|
-
...this._def,
|
|
3749
|
-
args: ZodTuple.create(items).rest(ZodUnknown.create())
|
|
3750
|
-
});
|
|
3751
|
-
}
|
|
3752
|
-
returns(returnType) {
|
|
3753
|
-
return new _ZodFunction({
|
|
3754
|
-
...this._def,
|
|
3755
|
-
returns: returnType
|
|
3756
|
-
});
|
|
3757
|
-
}
|
|
3758
|
-
implement(func) {
|
|
3759
|
-
const validatedFunc = this.parse(func);
|
|
3760
|
-
return validatedFunc;
|
|
3761
|
-
}
|
|
3762
|
-
strictImplement(func) {
|
|
3763
|
-
const validatedFunc = this.parse(func);
|
|
3764
|
-
return validatedFunc;
|
|
3765
|
-
}
|
|
3766
|
-
static create(args, returns, params) {
|
|
3767
|
-
return new _ZodFunction({
|
|
3768
|
-
args: args ? args : ZodTuple.create([]).rest(ZodUnknown.create()),
|
|
3769
|
-
returns: returns || ZodUnknown.create(),
|
|
3770
|
-
typeName: ZodFirstPartyTypeKind.ZodFunction,
|
|
3771
|
-
...processCreateParams(params)
|
|
3772
|
-
});
|
|
3773
|
-
}
|
|
3774
|
-
};
|
|
3775
|
-
var ZodLazy = class extends ZodType {
|
|
3776
|
-
get schema() {
|
|
3777
|
-
return this._def.getter();
|
|
3778
|
-
}
|
|
3779
|
-
_parse(input) {
|
|
3780
|
-
const { ctx } = this._processInputParams(input);
|
|
3781
|
-
const lazySchema = this._def.getter();
|
|
3782
|
-
return lazySchema._parse({ data: ctx.data, path: ctx.path, parent: ctx });
|
|
3783
|
-
}
|
|
3784
|
-
};
|
|
3785
|
-
ZodLazy.create = (getter, params) => {
|
|
3786
|
-
return new ZodLazy({
|
|
3787
|
-
getter,
|
|
3788
|
-
typeName: ZodFirstPartyTypeKind.ZodLazy,
|
|
3789
|
-
...processCreateParams(params)
|
|
3790
|
-
});
|
|
3791
|
-
};
|
|
3792
|
-
var ZodLiteral = class extends ZodType {
|
|
3793
|
-
_parse(input) {
|
|
3794
|
-
if (input.data !== this._def.value) {
|
|
3795
|
-
const ctx = this._getOrReturnCtx(input);
|
|
3796
|
-
addIssueToContext(ctx, {
|
|
3797
|
-
received: ctx.data,
|
|
3798
|
-
code: ZodIssueCode.invalid_literal,
|
|
3799
|
-
expected: this._def.value
|
|
3800
|
-
});
|
|
3801
|
-
return INVALID;
|
|
3802
|
-
}
|
|
3803
|
-
return { status: "valid", value: input.data };
|
|
3804
|
-
}
|
|
3805
|
-
get value() {
|
|
3806
|
-
return this._def.value;
|
|
3807
|
-
}
|
|
3808
|
-
};
|
|
3809
|
-
ZodLiteral.create = (value, params) => {
|
|
3810
|
-
return new ZodLiteral({
|
|
3811
|
-
value,
|
|
3812
|
-
typeName: ZodFirstPartyTypeKind.ZodLiteral,
|
|
3813
|
-
...processCreateParams(params)
|
|
3814
|
-
});
|
|
3815
|
-
};
|
|
3816
|
-
function createZodEnum(values, params) {
|
|
3817
|
-
return new ZodEnum({
|
|
3818
|
-
values,
|
|
3819
|
-
typeName: ZodFirstPartyTypeKind.ZodEnum,
|
|
3820
|
-
...processCreateParams(params)
|
|
3821
|
-
});
|
|
3822
|
-
}
|
|
3823
|
-
var ZodEnum = class _ZodEnum extends ZodType {
|
|
3824
|
-
_parse(input) {
|
|
3825
|
-
if (typeof input.data !== "string") {
|
|
3826
|
-
const ctx = this._getOrReturnCtx(input);
|
|
3827
|
-
const expectedValues = this._def.values;
|
|
3828
|
-
addIssueToContext(ctx, {
|
|
3829
|
-
expected: util.joinValues(expectedValues),
|
|
3830
|
-
received: ctx.parsedType,
|
|
3831
|
-
code: ZodIssueCode.invalid_type
|
|
3832
|
-
});
|
|
3833
|
-
return INVALID;
|
|
3834
|
-
}
|
|
3835
|
-
if (!this._cache) {
|
|
3836
|
-
this._cache = new Set(this._def.values);
|
|
3837
|
-
}
|
|
3838
|
-
if (!this._cache.has(input.data)) {
|
|
3839
|
-
const ctx = this._getOrReturnCtx(input);
|
|
3840
|
-
const expectedValues = this._def.values;
|
|
3841
|
-
addIssueToContext(ctx, {
|
|
3842
|
-
received: ctx.data,
|
|
3843
|
-
code: ZodIssueCode.invalid_enum_value,
|
|
3844
|
-
options: expectedValues
|
|
3845
|
-
});
|
|
3846
|
-
return INVALID;
|
|
3847
|
-
}
|
|
3848
|
-
return OK(input.data);
|
|
3849
|
-
}
|
|
3850
|
-
get options() {
|
|
3851
|
-
return this._def.values;
|
|
3852
|
-
}
|
|
3853
|
-
get enum() {
|
|
3854
|
-
const enumValues = {};
|
|
3855
|
-
for (const val of this._def.values) {
|
|
3856
|
-
enumValues[val] = val;
|
|
3857
|
-
}
|
|
3858
|
-
return enumValues;
|
|
3859
|
-
}
|
|
3860
|
-
get Values() {
|
|
3861
|
-
const enumValues = {};
|
|
3862
|
-
for (const val of this._def.values) {
|
|
3863
|
-
enumValues[val] = val;
|
|
3864
|
-
}
|
|
3865
|
-
return enumValues;
|
|
3866
|
-
}
|
|
3867
|
-
get Enum() {
|
|
3868
|
-
const enumValues = {};
|
|
3869
|
-
for (const val of this._def.values) {
|
|
3870
|
-
enumValues[val] = val;
|
|
3871
|
-
}
|
|
3872
|
-
return enumValues;
|
|
3873
|
-
}
|
|
3874
|
-
extract(values, newDef = this._def) {
|
|
3875
|
-
return _ZodEnum.create(values, {
|
|
3876
|
-
...this._def,
|
|
3877
|
-
...newDef
|
|
3878
|
-
});
|
|
3879
|
-
}
|
|
3880
|
-
exclude(values, newDef = this._def) {
|
|
3881
|
-
return _ZodEnum.create(this.options.filter((opt) => !values.includes(opt)), {
|
|
3882
|
-
...this._def,
|
|
3883
|
-
...newDef
|
|
3884
|
-
});
|
|
3885
|
-
}
|
|
3886
|
-
};
|
|
3887
|
-
ZodEnum.create = createZodEnum;
|
|
3888
|
-
var ZodNativeEnum = class extends ZodType {
|
|
3889
|
-
_parse(input) {
|
|
3890
|
-
const nativeEnumValues = util.getValidEnumValues(this._def.values);
|
|
3891
|
-
const ctx = this._getOrReturnCtx(input);
|
|
3892
|
-
if (ctx.parsedType !== ZodParsedType.string && ctx.parsedType !== ZodParsedType.number) {
|
|
3893
|
-
const expectedValues = util.objectValues(nativeEnumValues);
|
|
3894
|
-
addIssueToContext(ctx, {
|
|
3895
|
-
expected: util.joinValues(expectedValues),
|
|
3896
|
-
received: ctx.parsedType,
|
|
3897
|
-
code: ZodIssueCode.invalid_type
|
|
3898
|
-
});
|
|
3899
|
-
return INVALID;
|
|
3900
|
-
}
|
|
3901
|
-
if (!this._cache) {
|
|
3902
|
-
this._cache = new Set(util.getValidEnumValues(this._def.values));
|
|
3903
|
-
}
|
|
3904
|
-
if (!this._cache.has(input.data)) {
|
|
3905
|
-
const expectedValues = util.objectValues(nativeEnumValues);
|
|
3906
|
-
addIssueToContext(ctx, {
|
|
3907
|
-
received: ctx.data,
|
|
3908
|
-
code: ZodIssueCode.invalid_enum_value,
|
|
3909
|
-
options: expectedValues
|
|
3910
|
-
});
|
|
3911
|
-
return INVALID;
|
|
3912
|
-
}
|
|
3913
|
-
return OK(input.data);
|
|
3914
|
-
}
|
|
3915
|
-
get enum() {
|
|
3916
|
-
return this._def.values;
|
|
3917
|
-
}
|
|
3918
|
-
};
|
|
3919
|
-
ZodNativeEnum.create = (values, params) => {
|
|
3920
|
-
return new ZodNativeEnum({
|
|
3921
|
-
values,
|
|
3922
|
-
typeName: ZodFirstPartyTypeKind.ZodNativeEnum,
|
|
3923
|
-
...processCreateParams(params)
|
|
3924
|
-
});
|
|
3925
|
-
};
|
|
3926
|
-
var ZodPromise = class extends ZodType {
|
|
3927
|
-
unwrap() {
|
|
3928
|
-
return this._def.type;
|
|
3929
|
-
}
|
|
3930
|
-
_parse(input) {
|
|
3931
|
-
const { ctx } = this._processInputParams(input);
|
|
3932
|
-
if (ctx.parsedType !== ZodParsedType.promise && ctx.common.async === false) {
|
|
3933
|
-
addIssueToContext(ctx, {
|
|
3934
|
-
code: ZodIssueCode.invalid_type,
|
|
3935
|
-
expected: ZodParsedType.promise,
|
|
3936
|
-
received: ctx.parsedType
|
|
3937
|
-
});
|
|
3938
|
-
return INVALID;
|
|
3939
|
-
}
|
|
3940
|
-
const promisified = ctx.parsedType === ZodParsedType.promise ? ctx.data : Promise.resolve(ctx.data);
|
|
3941
|
-
return OK(promisified.then((data) => {
|
|
3942
|
-
return this._def.type.parseAsync(data, {
|
|
3943
|
-
path: ctx.path,
|
|
3944
|
-
errorMap: ctx.common.contextualErrorMap
|
|
3945
|
-
});
|
|
3946
|
-
}));
|
|
3947
|
-
}
|
|
3948
|
-
};
|
|
3949
|
-
ZodPromise.create = (schema, params) => {
|
|
3950
|
-
return new ZodPromise({
|
|
3951
|
-
type: schema,
|
|
3952
|
-
typeName: ZodFirstPartyTypeKind.ZodPromise,
|
|
3953
|
-
...processCreateParams(params)
|
|
3954
|
-
});
|
|
3955
|
-
};
|
|
3956
|
-
var ZodEffects = class extends ZodType {
|
|
3957
|
-
innerType() {
|
|
3958
|
-
return this._def.schema;
|
|
3959
|
-
}
|
|
3960
|
-
sourceType() {
|
|
3961
|
-
return this._def.schema._def.typeName === ZodFirstPartyTypeKind.ZodEffects ? this._def.schema.sourceType() : this._def.schema;
|
|
3962
|
-
}
|
|
3963
|
-
_parse(input) {
|
|
3964
|
-
const { status, ctx } = this._processInputParams(input);
|
|
3965
|
-
const effect = this._def.effect || null;
|
|
3966
|
-
const checkCtx = {
|
|
3967
|
-
addIssue: (arg) => {
|
|
3968
|
-
addIssueToContext(ctx, arg);
|
|
3969
|
-
if (arg.fatal) {
|
|
3970
|
-
status.abort();
|
|
3971
|
-
} else {
|
|
3972
|
-
status.dirty();
|
|
3973
|
-
}
|
|
3974
|
-
},
|
|
3975
|
-
get path() {
|
|
3976
|
-
return ctx.path;
|
|
3977
|
-
}
|
|
3978
|
-
};
|
|
3979
|
-
checkCtx.addIssue = checkCtx.addIssue.bind(checkCtx);
|
|
3980
|
-
if (effect.type === "preprocess") {
|
|
3981
|
-
const processed = effect.transform(ctx.data, checkCtx);
|
|
3982
|
-
if (ctx.common.async) {
|
|
3983
|
-
return Promise.resolve(processed).then(async (processed2) => {
|
|
3984
|
-
if (status.value === "aborted")
|
|
3985
|
-
return INVALID;
|
|
3986
|
-
const result = await this._def.schema._parseAsync({
|
|
3987
|
-
data: processed2,
|
|
3988
|
-
path: ctx.path,
|
|
3989
|
-
parent: ctx
|
|
3990
|
-
});
|
|
3991
|
-
if (result.status === "aborted")
|
|
3992
|
-
return INVALID;
|
|
3993
|
-
if (result.status === "dirty")
|
|
3994
|
-
return DIRTY(result.value);
|
|
3995
|
-
if (status.value === "dirty")
|
|
3996
|
-
return DIRTY(result.value);
|
|
3997
|
-
return result;
|
|
3998
|
-
});
|
|
3999
|
-
} else {
|
|
4000
|
-
if (status.value === "aborted")
|
|
4001
|
-
return INVALID;
|
|
4002
|
-
const result = this._def.schema._parseSync({
|
|
4003
|
-
data: processed,
|
|
4004
|
-
path: ctx.path,
|
|
4005
|
-
parent: ctx
|
|
4006
|
-
});
|
|
4007
|
-
if (result.status === "aborted")
|
|
4008
|
-
return INVALID;
|
|
4009
|
-
if (result.status === "dirty")
|
|
4010
|
-
return DIRTY(result.value);
|
|
4011
|
-
if (status.value === "dirty")
|
|
4012
|
-
return DIRTY(result.value);
|
|
4013
|
-
return result;
|
|
4014
|
-
}
|
|
4015
|
-
}
|
|
4016
|
-
if (effect.type === "refinement") {
|
|
4017
|
-
const executeRefinement = (acc) => {
|
|
4018
|
-
const result = effect.refinement(acc, checkCtx);
|
|
4019
|
-
if (ctx.common.async) {
|
|
4020
|
-
return Promise.resolve(result);
|
|
4021
|
-
}
|
|
4022
|
-
if (result instanceof Promise) {
|
|
4023
|
-
throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");
|
|
4024
|
-
}
|
|
4025
|
-
return acc;
|
|
4026
|
-
};
|
|
4027
|
-
if (ctx.common.async === false) {
|
|
4028
|
-
const inner = this._def.schema._parseSync({
|
|
4029
|
-
data: ctx.data,
|
|
4030
|
-
path: ctx.path,
|
|
4031
|
-
parent: ctx
|
|
4032
|
-
});
|
|
4033
|
-
if (inner.status === "aborted")
|
|
4034
|
-
return INVALID;
|
|
4035
|
-
if (inner.status === "dirty")
|
|
4036
|
-
status.dirty();
|
|
4037
|
-
executeRefinement(inner.value);
|
|
4038
|
-
return { status: status.value, value: inner.value };
|
|
4039
|
-
} else {
|
|
4040
|
-
return this._def.schema._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }).then((inner) => {
|
|
4041
|
-
if (inner.status === "aborted")
|
|
4042
|
-
return INVALID;
|
|
4043
|
-
if (inner.status === "dirty")
|
|
4044
|
-
status.dirty();
|
|
4045
|
-
return executeRefinement(inner.value).then(() => {
|
|
4046
|
-
return { status: status.value, value: inner.value };
|
|
4047
|
-
});
|
|
4048
|
-
});
|
|
4049
|
-
}
|
|
4050
|
-
}
|
|
4051
|
-
if (effect.type === "transform") {
|
|
4052
|
-
if (ctx.common.async === false) {
|
|
4053
|
-
const base = this._def.schema._parseSync({
|
|
4054
|
-
data: ctx.data,
|
|
4055
|
-
path: ctx.path,
|
|
4056
|
-
parent: ctx
|
|
4057
|
-
});
|
|
4058
|
-
if (!isValid(base))
|
|
4059
|
-
return INVALID;
|
|
4060
|
-
const result = effect.transform(base.value, checkCtx);
|
|
4061
|
-
if (result instanceof Promise) {
|
|
4062
|
-
throw new Error(`Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.`);
|
|
4063
|
-
}
|
|
4064
|
-
return { status: status.value, value: result };
|
|
230
|
+
const arg = rawArgs[i];
|
|
231
|
+
if (arg.startsWith("--")) {
|
|
232
|
+
const eqIdx = arg.indexOf("=");
|
|
233
|
+
if (eqIdx !== -1) {
|
|
234
|
+
result[arg.slice(2, eqIdx)] = arg.slice(eqIdx + 1);
|
|
235
|
+
} else if (i + 1 < rawArgs.length && !rawArgs[i + 1].startsWith("--")) {
|
|
236
|
+
result[arg.slice(2)] = rawArgs[i + 1];
|
|
237
|
+
i++;
|
|
4065
238
|
} else {
|
|
4066
|
-
|
|
4067
|
-
if (!isValid(base))
|
|
4068
|
-
return INVALID;
|
|
4069
|
-
return Promise.resolve(effect.transform(base.value, checkCtx)).then((result) => ({
|
|
4070
|
-
status: status.value,
|
|
4071
|
-
value: result
|
|
4072
|
-
}));
|
|
4073
|
-
});
|
|
239
|
+
result[arg.slice(2)] = "true";
|
|
4074
240
|
}
|
|
4075
241
|
}
|
|
4076
|
-
|
|
4077
|
-
}
|
|
4078
|
-
};
|
|
4079
|
-
ZodEffects.create = (schema, effect, params) => {
|
|
4080
|
-
return new ZodEffects({
|
|
4081
|
-
schema,
|
|
4082
|
-
typeName: ZodFirstPartyTypeKind.ZodEffects,
|
|
4083
|
-
effect,
|
|
4084
|
-
...processCreateParams(params)
|
|
4085
|
-
});
|
|
4086
|
-
};
|
|
4087
|
-
ZodEffects.createWithPreprocess = (preprocess, schema, params) => {
|
|
4088
|
-
return new ZodEffects({
|
|
4089
|
-
schema,
|
|
4090
|
-
effect: { type: "preprocess", transform: preprocess },
|
|
4091
|
-
typeName: ZodFirstPartyTypeKind.ZodEffects,
|
|
4092
|
-
...processCreateParams(params)
|
|
4093
|
-
});
|
|
4094
|
-
};
|
|
4095
|
-
var ZodOptional = class extends ZodType {
|
|
4096
|
-
_parse(input) {
|
|
4097
|
-
const parsedType = this._getType(input);
|
|
4098
|
-
if (parsedType === ZodParsedType.undefined) {
|
|
4099
|
-
return OK(void 0);
|
|
4100
|
-
}
|
|
4101
|
-
return this._def.innerType._parse(input);
|
|
4102
|
-
}
|
|
4103
|
-
unwrap() {
|
|
4104
|
-
return this._def.innerType;
|
|
4105
|
-
}
|
|
4106
|
-
};
|
|
4107
|
-
ZodOptional.create = (type, params) => {
|
|
4108
|
-
return new ZodOptional({
|
|
4109
|
-
innerType: type,
|
|
4110
|
-
typeName: ZodFirstPartyTypeKind.ZodOptional,
|
|
4111
|
-
...processCreateParams(params)
|
|
4112
|
-
});
|
|
4113
|
-
};
|
|
4114
|
-
var ZodNullable = class extends ZodType {
|
|
4115
|
-
_parse(input) {
|
|
4116
|
-
const parsedType = this._getType(input);
|
|
4117
|
-
if (parsedType === ZodParsedType.null) {
|
|
4118
|
-
return OK(null);
|
|
4119
|
-
}
|
|
4120
|
-
return this._def.innerType._parse(input);
|
|
4121
|
-
}
|
|
4122
|
-
unwrap() {
|
|
4123
|
-
return this._def.innerType;
|
|
242
|
+
i++;
|
|
4124
243
|
}
|
|
4125
|
-
|
|
4126
|
-
|
|
4127
|
-
|
|
4128
|
-
|
|
4129
|
-
|
|
4130
|
-
|
|
4131
|
-
|
|
4132
|
-
|
|
4133
|
-
|
|
4134
|
-
|
|
4135
|
-
|
|
4136
|
-
|
|
4137
|
-
|
|
4138
|
-
|
|
4139
|
-
|
|
4140
|
-
|
|
4141
|
-
|
|
4142
|
-
|
|
4143
|
-
|
|
244
|
+
return result;
|
|
245
|
+
}
|
|
246
|
+
function promptApproval(request) {
|
|
247
|
+
const rl = createInterface({ input: process.stdin, output: process.stderr });
|
|
248
|
+
let cancelled = false;
|
|
249
|
+
const cancel = () => {
|
|
250
|
+
cancelled = true;
|
|
251
|
+
rl.close();
|
|
252
|
+
};
|
|
253
|
+
const prompt = `
|
|
254
|
+
\u26A0 Step ${request.stepIndex + 1} [${request.stepType}] in ${request.connectorKey} requires approval.
|
|
255
|
+
Capability: ${request.capability}
|
|
256
|
+
${request.description}
|
|
257
|
+
Approve? (y/n): `;
|
|
258
|
+
const promise = new Promise((resolve2) => {
|
|
259
|
+
rl.question(prompt, (answer) => {
|
|
260
|
+
rl.close();
|
|
261
|
+
if (cancelled) return;
|
|
262
|
+
resolve2(answer.trim().toLowerCase() === "y" || answer.trim().toLowerCase() === "yes");
|
|
263
|
+
});
|
|
264
|
+
rl.on("close", () => {
|
|
265
|
+
if (cancelled) resolve2(true);
|
|
4144
266
|
});
|
|
4145
|
-
}
|
|
4146
|
-
removeDefault() {
|
|
4147
|
-
return this._def.innerType;
|
|
4148
|
-
}
|
|
4149
|
-
};
|
|
4150
|
-
ZodDefault.create = (type, params) => {
|
|
4151
|
-
return new ZodDefault({
|
|
4152
|
-
innerType: type,
|
|
4153
|
-
typeName: ZodFirstPartyTypeKind.ZodDefault,
|
|
4154
|
-
defaultValue: typeof params.default === "function" ? params.default : () => params.default,
|
|
4155
|
-
...processCreateParams(params)
|
|
4156
267
|
});
|
|
4157
|
-
};
|
|
4158
|
-
|
|
4159
|
-
|
|
4160
|
-
|
|
4161
|
-
const
|
|
4162
|
-
|
|
4163
|
-
|
|
4164
|
-
|
|
4165
|
-
issues: []
|
|
4166
|
-
}
|
|
4167
|
-
};
|
|
4168
|
-
const result = this._def.innerType._parse({
|
|
4169
|
-
data: newCtx.data,
|
|
4170
|
-
path: newCtx.path,
|
|
4171
|
-
parent: {
|
|
4172
|
-
...newCtx
|
|
4173
|
-
}
|
|
268
|
+
return { promise, cancel };
|
|
269
|
+
}
|
|
270
|
+
async function executeRun(client, connector, args, outputFormat) {
|
|
271
|
+
try {
|
|
272
|
+
const resp = await client.post("/api/run", {
|
|
273
|
+
connector,
|
|
274
|
+
args,
|
|
275
|
+
format: outputFormat
|
|
4174
276
|
});
|
|
4175
|
-
if (
|
|
4176
|
-
|
|
4177
|
-
return {
|
|
4178
|
-
|
|
4179
|
-
|
|
4180
|
-
get error() {
|
|
4181
|
-
return new ZodError(newCtx.common.issues);
|
|
4182
|
-
},
|
|
4183
|
-
input: newCtx.data
|
|
4184
|
-
})
|
|
4185
|
-
};
|
|
4186
|
-
});
|
|
4187
|
-
} else {
|
|
4188
|
-
return {
|
|
4189
|
-
status: "valid",
|
|
4190
|
-
value: result.status === "valid" ? result.value : this._def.catchValue({
|
|
4191
|
-
get error() {
|
|
4192
|
-
return new ZodError(newCtx.common.issues);
|
|
4193
|
-
},
|
|
4194
|
-
input: newCtx.data
|
|
4195
|
-
})
|
|
4196
|
-
};
|
|
277
|
+
if (!resp.requiresApproval) {
|
|
278
|
+
if (!resp.ok) {
|
|
279
|
+
return `Error: ${resp.error ?? "Unknown error from extension"} (${resp.durationMs}ms)`;
|
|
280
|
+
}
|
|
281
|
+
return format(resp.data, resp.columns, connector, outputFormat);
|
|
4197
282
|
}
|
|
4198
|
-
|
|
4199
|
-
|
|
4200
|
-
|
|
4201
|
-
|
|
4202
|
-
|
|
4203
|
-
|
|
4204
|
-
|
|
4205
|
-
|
|
4206
|
-
|
|
4207
|
-
|
|
4208
|
-
|
|
4209
|
-
|
|
4210
|
-
|
|
4211
|
-
|
|
4212
|
-
|
|
4213
|
-
|
|
4214
|
-
|
|
4215
|
-
|
|
4216
|
-
|
|
4217
|
-
|
|
4218
|
-
|
|
4219
|
-
|
|
283
|
+
const requestId = resp.requestId;
|
|
284
|
+
process.stderr.write(`Pipeline requires approval. Waiting for steps...
|
|
285
|
+
`);
|
|
286
|
+
return new Promise((resolve2) => {
|
|
287
|
+
const abortController = new AbortController();
|
|
288
|
+
let activePrompt = null;
|
|
289
|
+
client.connectSSE(
|
|
290
|
+
`/api/run/events/${requestId}`,
|
|
291
|
+
(event, data) => {
|
|
292
|
+
if (event === "approval") {
|
|
293
|
+
const approvalReq = data;
|
|
294
|
+
activePrompt = promptApproval(approvalReq);
|
|
295
|
+
activePrompt.promise.then(async (approved) => {
|
|
296
|
+
activePrompt = null;
|
|
297
|
+
try {
|
|
298
|
+
await client.post("/api/approval", {
|
|
299
|
+
approvalId: approvalReq.approvalId,
|
|
300
|
+
approved
|
|
301
|
+
});
|
|
302
|
+
} catch {
|
|
303
|
+
}
|
|
304
|
+
if (!approved) {
|
|
305
|
+
abortController.abort();
|
|
306
|
+
resolve2(`Aborted: Step ${approvalReq.stepIndex + 1} [${approvalReq.stepType}] was rejected.`);
|
|
307
|
+
}
|
|
308
|
+
});
|
|
309
|
+
} else if (event === "result") {
|
|
310
|
+
if (activePrompt) {
|
|
311
|
+
activePrompt.cancel();
|
|
312
|
+
activePrompt = null;
|
|
313
|
+
process.stderr.write("\n (approved via extension)\n");
|
|
314
|
+
}
|
|
315
|
+
abortController.abort();
|
|
316
|
+
const result = data;
|
|
317
|
+
if (!result.ok) {
|
|
318
|
+
resolve2(`Error: ${result.error ?? "Unknown error"} (${result.durationMs}ms)`);
|
|
319
|
+
} else {
|
|
320
|
+
resolve2(format(result.data, result.columns ?? [], connector, outputFormat));
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
},
|
|
324
|
+
abortController.signal
|
|
325
|
+
).catch(() => {
|
|
4220
326
|
});
|
|
4221
|
-
|
|
4222
|
-
|
|
4223
|
-
return {
|
|
327
|
+
});
|
|
328
|
+
} catch (err) {
|
|
329
|
+
return `Error: ${err instanceof Error ? err.message : String(err)}`;
|
|
4224
330
|
}
|
|
4225
|
-
}
|
|
4226
|
-
|
|
4227
|
-
|
|
4228
|
-
|
|
4229
|
-
|
|
4230
|
-
|
|
4231
|
-
|
|
4232
|
-
|
|
4233
|
-
|
|
4234
|
-
|
|
4235
|
-
|
|
4236
|
-
const data = ctx.data;
|
|
4237
|
-
return this._def.type._parse({
|
|
4238
|
-
data,
|
|
4239
|
-
path: ctx.path,
|
|
4240
|
-
parent: ctx
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
// src/commands/list.ts
|
|
334
|
+
import Table2 from "cli-table3";
|
|
335
|
+
async function executeList(client) {
|
|
336
|
+
try {
|
|
337
|
+
const resp = await client.get("/api/connectors");
|
|
338
|
+
if (resp.connectors.length === 0) return "No connectors installed.";
|
|
339
|
+
const table = new Table2({
|
|
340
|
+
head: ["Connector", "Description", "Access", "Domains", "Capabilities"],
|
|
341
|
+
style: { head: ["cyan"] }
|
|
4241
342
|
});
|
|
343
|
+
for (const c of resp.connectors) {
|
|
344
|
+
table.push([
|
|
345
|
+
c.key,
|
|
346
|
+
c.description ?? "",
|
|
347
|
+
c.access,
|
|
348
|
+
c.domains.join(", "),
|
|
349
|
+
c.capabilities.join(", ")
|
|
350
|
+
]);
|
|
351
|
+
}
|
|
352
|
+
return table.toString();
|
|
353
|
+
} catch (err) {
|
|
354
|
+
return `Error: ${err instanceof Error ? err.message : String(err)}`;
|
|
4242
355
|
}
|
|
4243
|
-
|
|
4244
|
-
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
// src/commands/inspect.ts
|
|
359
|
+
async function executeInspect(client, connectorKey) {
|
|
360
|
+
if (!connectorKey.includes("/")) {
|
|
361
|
+
return "Invalid connector key. Use format: <site>/<command> (e.g., timetracking/report)";
|
|
4245
362
|
}
|
|
4246
|
-
|
|
4247
|
-
|
|
4248
|
-
|
|
4249
|
-
|
|
4250
|
-
|
|
4251
|
-
|
|
4252
|
-
|
|
4253
|
-
data: ctx.data,
|
|
4254
|
-
path: ctx.path,
|
|
4255
|
-
parent: ctx
|
|
4256
|
-
});
|
|
4257
|
-
if (inResult.status === "aborted")
|
|
4258
|
-
return INVALID;
|
|
4259
|
-
if (inResult.status === "dirty") {
|
|
4260
|
-
status.dirty();
|
|
4261
|
-
return DIRTY(inResult.value);
|
|
4262
|
-
} else {
|
|
4263
|
-
return this._def.out._parseAsync({
|
|
4264
|
-
data: inResult.value,
|
|
4265
|
-
path: ctx.path,
|
|
4266
|
-
parent: ctx
|
|
4267
|
-
});
|
|
4268
|
-
}
|
|
4269
|
-
};
|
|
4270
|
-
return handleAsync();
|
|
4271
|
-
} else {
|
|
4272
|
-
const inResult = this._def.in._parseSync({
|
|
4273
|
-
data: ctx.data,
|
|
4274
|
-
path: ctx.path,
|
|
4275
|
-
parent: ctx
|
|
4276
|
-
});
|
|
4277
|
-
if (inResult.status === "aborted")
|
|
4278
|
-
return INVALID;
|
|
4279
|
-
if (inResult.status === "dirty") {
|
|
4280
|
-
status.dirty();
|
|
4281
|
-
return {
|
|
4282
|
-
status: "dirty",
|
|
4283
|
-
value: inResult.value
|
|
4284
|
-
};
|
|
4285
|
-
} else {
|
|
4286
|
-
return this._def.out._parseSync({
|
|
4287
|
-
data: inResult.value,
|
|
4288
|
-
path: ctx.path,
|
|
4289
|
-
parent: ctx
|
|
4290
|
-
});
|
|
4291
|
-
}
|
|
4292
|
-
}
|
|
363
|
+
try {
|
|
364
|
+
const resp = await client.get(
|
|
365
|
+
`/api/connectors/${connectorKey}`
|
|
366
|
+
);
|
|
367
|
+
return renderConnector(resp.connector);
|
|
368
|
+
} catch (err) {
|
|
369
|
+
return `Error: ${err instanceof Error ? err.message : String(err)}`;
|
|
4293
370
|
}
|
|
4294
|
-
|
|
4295
|
-
|
|
4296
|
-
|
|
4297
|
-
|
|
4298
|
-
|
|
4299
|
-
|
|
371
|
+
}
|
|
372
|
+
function renderConnector(c) {
|
|
373
|
+
const lines = [];
|
|
374
|
+
lines.push(`Connector: ${c.site}/${c.name}`);
|
|
375
|
+
lines.push(`Version: ${c.version}`);
|
|
376
|
+
if (c.description) lines.push(`Desc: ${c.description}`);
|
|
377
|
+
lines.push(`Access: ${c.access}`);
|
|
378
|
+
lines.push(`Domains: ${c.domains.join(", ")}`);
|
|
379
|
+
lines.push(`Caps: ${c.capabilities.join(", ")}`);
|
|
380
|
+
if (c.args && c.args.length > 0) {
|
|
381
|
+
lines.push("");
|
|
382
|
+
lines.push("Arguments:");
|
|
383
|
+
for (const a of c.args) {
|
|
384
|
+
const req = a.required ? "(required)" : `(default: ${a.default ?? "none"})`;
|
|
385
|
+
lines.push(` --${a.name} ${a.type} ${req}${a.help ? " " + a.help : ""}`);
|
|
386
|
+
}
|
|
4300
387
|
}
|
|
4301
|
-
|
|
4302
|
-
|
|
4303
|
-
|
|
4304
|
-
const
|
|
4305
|
-
|
|
4306
|
-
|
|
4307
|
-
data.value = Object.freeze(data.value);
|
|
4308
|
-
}
|
|
4309
|
-
return data;
|
|
4310
|
-
};
|
|
4311
|
-
return isAsync(result) ? result.then((data) => freeze(data)) : freeze(result);
|
|
388
|
+
if (c.columns && c.columns.length > 0) {
|
|
389
|
+
lines.push("");
|
|
390
|
+
lines.push("Output columns:");
|
|
391
|
+
for (const col of c.columns) {
|
|
392
|
+
lines.push(` ${col.name} (${col.type})`);
|
|
393
|
+
}
|
|
4312
394
|
}
|
|
4313
|
-
|
|
4314
|
-
|
|
395
|
+
lines.push("");
|
|
396
|
+
lines.push(`Pipeline: ${c.pipeline.length} step(s)`);
|
|
397
|
+
for (let i = 0; i < c.pipeline.length; i++) {
|
|
398
|
+
const s = c.pipeline[i];
|
|
399
|
+
lines.push(` ${i + 1}. ${s.step}${stepSummary(s)}`);
|
|
4315
400
|
}
|
|
4316
|
-
|
|
4317
|
-
ZodReadonly.create = (type, params) => {
|
|
4318
|
-
return new ZodReadonly({
|
|
4319
|
-
innerType: type,
|
|
4320
|
-
typeName: ZodFirstPartyTypeKind.ZodReadonly,
|
|
4321
|
-
...processCreateParams(params)
|
|
4322
|
-
});
|
|
4323
|
-
};
|
|
4324
|
-
function cleanParams(params, data) {
|
|
4325
|
-
const p = typeof params === "function" ? params(data) : typeof params === "string" ? { message: params } : params;
|
|
4326
|
-
const p2 = typeof p === "string" ? { message: p } : p;
|
|
4327
|
-
return p2;
|
|
401
|
+
return lines.join("\n");
|
|
4328
402
|
}
|
|
4329
|
-
function
|
|
4330
|
-
|
|
4331
|
-
|
|
4332
|
-
|
|
4333
|
-
|
|
4334
|
-
|
|
4335
|
-
|
|
4336
|
-
|
|
4337
|
-
|
|
4338
|
-
|
|
4339
|
-
|
|
4340
|
-
|
|
4341
|
-
|
|
4342
|
-
|
|
4343
|
-
|
|
4344
|
-
|
|
4345
|
-
|
|
4346
|
-
}
|
|
4347
|
-
|
|
4348
|
-
|
|
4349
|
-
|
|
403
|
+
function stepSummary(step) {
|
|
404
|
+
switch (step.step) {
|
|
405
|
+
case "navigate":
|
|
406
|
+
return ` \u2192 ${step.url}`;
|
|
407
|
+
case "wait":
|
|
408
|
+
return ` \u2192 ${step.selector ?? "delay"}${step.timeout ? ` (${step.timeout}ms)` : ""}`;
|
|
409
|
+
case "extract":
|
|
410
|
+
return ` \u2192 ${step.selector}`;
|
|
411
|
+
case "click":
|
|
412
|
+
return ` \u2192 ${step.selector}`;
|
|
413
|
+
case "type":
|
|
414
|
+
return ` \u2192 ${step.selector}`;
|
|
415
|
+
case "set":
|
|
416
|
+
return ` \u2192 ${step.name} = ${step.value}`;
|
|
417
|
+
case "filter":
|
|
418
|
+
return ` \u2192 ${step.field} ${step.operator} ${step.value}`;
|
|
419
|
+
case "map":
|
|
420
|
+
return ` \u2192 ${Object.keys(step.fields).join(", ")}`;
|
|
421
|
+
case "cookie":
|
|
422
|
+
return ` \u2192 ${step.domain}`;
|
|
423
|
+
case "fetch":
|
|
424
|
+
return ` \u2192 ${step.url}`;
|
|
425
|
+
case "intercept":
|
|
426
|
+
return ` \u2192 ${step.urlPattern}`;
|
|
427
|
+
default:
|
|
428
|
+
return "";
|
|
429
|
+
}
|
|
4350
430
|
}
|
|
4351
|
-
|
|
4352
|
-
|
|
4353
|
-
};
|
|
4354
|
-
|
|
4355
|
-
|
|
4356
|
-
|
|
4357
|
-
|
|
4358
|
-
|
|
4359
|
-
|
|
4360
|
-
|
|
4361
|
-
|
|
4362
|
-
|
|
4363
|
-
|
|
4364
|
-
|
|
4365
|
-
|
|
4366
|
-
|
|
4367
|
-
|
|
4368
|
-
|
|
4369
|
-
|
|
4370
|
-
|
|
4371
|
-
|
|
4372
|
-
|
|
4373
|
-
ZodFirstPartyTypeKind2["ZodIntersection"] = "ZodIntersection";
|
|
4374
|
-
ZodFirstPartyTypeKind2["ZodTuple"] = "ZodTuple";
|
|
4375
|
-
ZodFirstPartyTypeKind2["ZodRecord"] = "ZodRecord";
|
|
4376
|
-
ZodFirstPartyTypeKind2["ZodMap"] = "ZodMap";
|
|
4377
|
-
ZodFirstPartyTypeKind2["ZodSet"] = "ZodSet";
|
|
4378
|
-
ZodFirstPartyTypeKind2["ZodFunction"] = "ZodFunction";
|
|
4379
|
-
ZodFirstPartyTypeKind2["ZodLazy"] = "ZodLazy";
|
|
4380
|
-
ZodFirstPartyTypeKind2["ZodLiteral"] = "ZodLiteral";
|
|
4381
|
-
ZodFirstPartyTypeKind2["ZodEnum"] = "ZodEnum";
|
|
4382
|
-
ZodFirstPartyTypeKind2["ZodEffects"] = "ZodEffects";
|
|
4383
|
-
ZodFirstPartyTypeKind2["ZodNativeEnum"] = "ZodNativeEnum";
|
|
4384
|
-
ZodFirstPartyTypeKind2["ZodOptional"] = "ZodOptional";
|
|
4385
|
-
ZodFirstPartyTypeKind2["ZodNullable"] = "ZodNullable";
|
|
4386
|
-
ZodFirstPartyTypeKind2["ZodDefault"] = "ZodDefault";
|
|
4387
|
-
ZodFirstPartyTypeKind2["ZodCatch"] = "ZodCatch";
|
|
4388
|
-
ZodFirstPartyTypeKind2["ZodPromise"] = "ZodPromise";
|
|
4389
|
-
ZodFirstPartyTypeKind2["ZodBranded"] = "ZodBranded";
|
|
4390
|
-
ZodFirstPartyTypeKind2["ZodPipeline"] = "ZodPipeline";
|
|
4391
|
-
ZodFirstPartyTypeKind2["ZodReadonly"] = "ZodReadonly";
|
|
4392
|
-
})(ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {}));
|
|
4393
|
-
var instanceOfType = (cls, params = {
|
|
4394
|
-
message: `Input not instance of ${cls.name}`
|
|
4395
|
-
}) => custom((data) => data instanceof cls, params);
|
|
4396
|
-
var stringType = ZodString.create;
|
|
4397
|
-
var numberType = ZodNumber.create;
|
|
4398
|
-
var nanType = ZodNaN.create;
|
|
4399
|
-
var bigIntType = ZodBigInt.create;
|
|
4400
|
-
var booleanType = ZodBoolean.create;
|
|
4401
|
-
var dateType = ZodDate.create;
|
|
4402
|
-
var symbolType = ZodSymbol.create;
|
|
4403
|
-
var undefinedType = ZodUndefined.create;
|
|
4404
|
-
var nullType = ZodNull.create;
|
|
4405
|
-
var anyType = ZodAny.create;
|
|
4406
|
-
var unknownType = ZodUnknown.create;
|
|
4407
|
-
var neverType = ZodNever.create;
|
|
4408
|
-
var voidType = ZodVoid.create;
|
|
4409
|
-
var arrayType = ZodArray.create;
|
|
4410
|
-
var objectType = ZodObject.create;
|
|
4411
|
-
var strictObjectType = ZodObject.strictCreate;
|
|
4412
|
-
var unionType = ZodUnion.create;
|
|
4413
|
-
var discriminatedUnionType = ZodDiscriminatedUnion.create;
|
|
4414
|
-
var intersectionType = ZodIntersection.create;
|
|
4415
|
-
var tupleType = ZodTuple.create;
|
|
4416
|
-
var recordType = ZodRecord.create;
|
|
4417
|
-
var mapType = ZodMap.create;
|
|
4418
|
-
var setType = ZodSet.create;
|
|
4419
|
-
var functionType = ZodFunction.create;
|
|
4420
|
-
var lazyType = ZodLazy.create;
|
|
4421
|
-
var literalType = ZodLiteral.create;
|
|
4422
|
-
var enumType = ZodEnum.create;
|
|
4423
|
-
var nativeEnumType = ZodNativeEnum.create;
|
|
4424
|
-
var promiseType = ZodPromise.create;
|
|
4425
|
-
var effectsType = ZodEffects.create;
|
|
4426
|
-
var optionalType = ZodOptional.create;
|
|
4427
|
-
var nullableType = ZodNullable.create;
|
|
4428
|
-
var preprocessType = ZodEffects.createWithPreprocess;
|
|
4429
|
-
var pipelineType = ZodPipeline.create;
|
|
4430
|
-
var ostring = () => stringType().optional();
|
|
4431
|
-
var onumber = () => numberType().optional();
|
|
4432
|
-
var oboolean = () => booleanType().optional();
|
|
4433
|
-
var coerce = {
|
|
4434
|
-
string: ((arg) => ZodString.create({ ...arg, coerce: true })),
|
|
4435
|
-
number: ((arg) => ZodNumber.create({ ...arg, coerce: true })),
|
|
4436
|
-
boolean: ((arg) => ZodBoolean.create({
|
|
4437
|
-
...arg,
|
|
4438
|
-
coerce: true
|
|
4439
|
-
})),
|
|
4440
|
-
bigint: ((arg) => ZodBigInt.create({ ...arg, coerce: true })),
|
|
4441
|
-
date: ((arg) => ZodDate.create({ ...arg, coerce: true }))
|
|
431
|
+
|
|
432
|
+
// src/commands/validate.ts
|
|
433
|
+
import { readFileSync as readFileSync3 } from "fs";
|
|
434
|
+
|
|
435
|
+
// ../shared/dist/capabilities.js
|
|
436
|
+
var CAPABILITIES = [
|
|
437
|
+
"navigate",
|
|
438
|
+
"cookie_read",
|
|
439
|
+
"cookie_write",
|
|
440
|
+
"dom_read",
|
|
441
|
+
"dom_write",
|
|
442
|
+
"intercept_response",
|
|
443
|
+
"js_evaluate"
|
|
444
|
+
];
|
|
445
|
+
var CAPABILITY_RISK = {
|
|
446
|
+
navigate: "low",
|
|
447
|
+
cookie_read: "medium",
|
|
448
|
+
cookie_write: "high",
|
|
449
|
+
dom_read: "low",
|
|
450
|
+
dom_write: "medium",
|
|
451
|
+
intercept_response: "medium",
|
|
452
|
+
js_evaluate: "high"
|
|
4442
453
|
};
|
|
4443
|
-
var
|
|
454
|
+
var HIGH_RISK_CAPABILITIES = CAPABILITIES.filter((c) => CAPABILITY_RISK[c] === "high");
|
|
4444
455
|
|
|
4445
456
|
// ../shared/dist/pipeline.js
|
|
457
|
+
import { z } from "zod";
|
|
4446
458
|
var STEP_CAPABILITY_MAP = {
|
|
4447
459
|
navigate: "navigate",
|
|
4448
460
|
wait: "navigate",
|
|
@@ -4457,70 +469,70 @@ var STEP_CAPABILITY_MAP = {
|
|
|
4457
469
|
set: null,
|
|
4458
470
|
js_evaluate: "js_evaluate"
|
|
4459
471
|
};
|
|
4460
|
-
var navigateStepSchema =
|
|
4461
|
-
step:
|
|
4462
|
-
url:
|
|
472
|
+
var navigateStepSchema = z.object({
|
|
473
|
+
step: z.literal("navigate"),
|
|
474
|
+
url: z.string()
|
|
4463
475
|
});
|
|
4464
|
-
var waitStepSchema =
|
|
4465
|
-
step:
|
|
4466
|
-
selector:
|
|
4467
|
-
timeout:
|
|
476
|
+
var waitStepSchema = z.object({
|
|
477
|
+
step: z.literal("wait"),
|
|
478
|
+
selector: z.string().optional(),
|
|
479
|
+
timeout: z.number().positive().optional()
|
|
4468
480
|
});
|
|
4469
|
-
var extractStepSchema =
|
|
4470
|
-
step:
|
|
4471
|
-
selector:
|
|
4472
|
-
fields:
|
|
481
|
+
var extractStepSchema = z.object({
|
|
482
|
+
step: z.literal("extract"),
|
|
483
|
+
selector: z.string(),
|
|
484
|
+
fields: z.record(z.string(), z.string())
|
|
4473
485
|
});
|
|
4474
|
-
var clickStepSchema =
|
|
4475
|
-
step:
|
|
4476
|
-
selector:
|
|
486
|
+
var clickStepSchema = z.object({
|
|
487
|
+
step: z.literal("click"),
|
|
488
|
+
selector: z.string()
|
|
4477
489
|
});
|
|
4478
|
-
var typeStepSchema =
|
|
4479
|
-
step:
|
|
4480
|
-
selector:
|
|
4481
|
-
value:
|
|
490
|
+
var typeStepSchema = z.object({
|
|
491
|
+
step: z.literal("type"),
|
|
492
|
+
selector: z.string(),
|
|
493
|
+
value: z.string()
|
|
4482
494
|
});
|
|
4483
|
-
var interceptStepSchema =
|
|
4484
|
-
step:
|
|
4485
|
-
urlPattern:
|
|
4486
|
-
as:
|
|
495
|
+
var interceptStepSchema = z.object({
|
|
496
|
+
step: z.literal("intercept"),
|
|
497
|
+
urlPattern: z.string(),
|
|
498
|
+
as: z.string().optional()
|
|
4487
499
|
});
|
|
4488
|
-
var cookieStepSchema =
|
|
4489
|
-
step:
|
|
4490
|
-
domain:
|
|
4491
|
-
name:
|
|
4492
|
-
as:
|
|
500
|
+
var cookieStepSchema = z.object({
|
|
501
|
+
step: z.literal("cookie"),
|
|
502
|
+
domain: z.string(),
|
|
503
|
+
name: z.string().optional(),
|
|
504
|
+
as: z.string().optional()
|
|
4493
505
|
});
|
|
4494
|
-
var fetchStepSchema =
|
|
4495
|
-
step:
|
|
4496
|
-
url:
|
|
4497
|
-
method:
|
|
4498
|
-
headers:
|
|
4499
|
-
body:
|
|
4500
|
-
as:
|
|
506
|
+
var fetchStepSchema = z.object({
|
|
507
|
+
step: z.literal("fetch"),
|
|
508
|
+
url: z.string(),
|
|
509
|
+
method: z.string().optional(),
|
|
510
|
+
headers: z.record(z.string(), z.string()).optional(),
|
|
511
|
+
body: z.string().optional(),
|
|
512
|
+
as: z.string().optional()
|
|
4501
513
|
});
|
|
4502
|
-
var mapStepSchema =
|
|
4503
|
-
step:
|
|
4504
|
-
fields:
|
|
514
|
+
var mapStepSchema = z.object({
|
|
515
|
+
step: z.literal("map"),
|
|
516
|
+
fields: z.record(z.string(), z.string())
|
|
4505
517
|
});
|
|
4506
|
-
var filterStepSchema =
|
|
4507
|
-
step:
|
|
4508
|
-
field:
|
|
4509
|
-
operator:
|
|
4510
|
-
value:
|
|
518
|
+
var filterStepSchema = z.object({
|
|
519
|
+
step: z.literal("filter"),
|
|
520
|
+
field: z.string(),
|
|
521
|
+
operator: z.enum(["eq", "ne", "gt", "lt", "gte", "lte", "contains", "matches"]),
|
|
522
|
+
value: z.string()
|
|
4511
523
|
});
|
|
4512
|
-
var setStepSchema =
|
|
4513
|
-
step:
|
|
4514
|
-
name:
|
|
4515
|
-
value:
|
|
524
|
+
var setStepSchema = z.object({
|
|
525
|
+
step: z.literal("set"),
|
|
526
|
+
name: z.string(),
|
|
527
|
+
value: z.string()
|
|
4516
528
|
});
|
|
4517
|
-
var jsEvaluateStepSchema =
|
|
4518
|
-
step:
|
|
4519
|
-
code:
|
|
4520
|
-
file:
|
|
4521
|
-
as:
|
|
529
|
+
var jsEvaluateStepSchema = z.object({
|
|
530
|
+
step: z.literal("js_evaluate"),
|
|
531
|
+
code: z.string().optional(),
|
|
532
|
+
file: z.string().optional(),
|
|
533
|
+
as: z.string().optional()
|
|
4522
534
|
});
|
|
4523
|
-
var pipelineStepSchema =
|
|
535
|
+
var pipelineStepSchema = z.discriminatedUnion("step", [
|
|
4524
536
|
navigateStepSchema,
|
|
4525
537
|
waitStepSchema,
|
|
4526
538
|
extractStepSchema,
|
|
@@ -4536,30 +548,31 @@ var pipelineStepSchema = external_exports.discriminatedUnion("step", [
|
|
|
4536
548
|
]);
|
|
4537
549
|
|
|
4538
550
|
// ../shared/dist/connector.js
|
|
4539
|
-
|
|
4540
|
-
var
|
|
4541
|
-
|
|
4542
|
-
|
|
4543
|
-
|
|
4544
|
-
|
|
4545
|
-
|
|
4546
|
-
|
|
551
|
+
import { z as z2 } from "zod";
|
|
552
|
+
var capabilityEnum = z2.enum(CAPABILITIES);
|
|
553
|
+
var connectorArgSchema = z2.object({
|
|
554
|
+
name: z2.string(),
|
|
555
|
+
type: z2.enum(["string", "number", "boolean"]),
|
|
556
|
+
required: z2.boolean().default(false),
|
|
557
|
+
default: z2.union([z2.string(), z2.number(), z2.boolean()]).optional(),
|
|
558
|
+
help: z2.string().optional(),
|
|
559
|
+
pattern: z2.string().optional()
|
|
4547
560
|
});
|
|
4548
|
-
var connectorColumnSchema =
|
|
4549
|
-
name:
|
|
4550
|
-
type:
|
|
561
|
+
var connectorColumnSchema = z2.object({
|
|
562
|
+
name: z2.string(),
|
|
563
|
+
type: z2.enum(["string", "number", "boolean"])
|
|
4551
564
|
});
|
|
4552
|
-
var connectorSchema =
|
|
4553
|
-
site:
|
|
4554
|
-
name:
|
|
4555
|
-
version:
|
|
4556
|
-
description:
|
|
4557
|
-
access:
|
|
4558
|
-
domains:
|
|
4559
|
-
capabilities:
|
|
4560
|
-
args:
|
|
4561
|
-
columns:
|
|
4562
|
-
pipeline:
|
|
565
|
+
var connectorSchema = z2.object({
|
|
566
|
+
site: z2.string().min(1),
|
|
567
|
+
name: z2.string().min(1),
|
|
568
|
+
version: z2.string(),
|
|
569
|
+
description: z2.string().optional(),
|
|
570
|
+
access: z2.enum(["read", "write"]).default("read"),
|
|
571
|
+
domains: z2.array(z2.string()).min(1),
|
|
572
|
+
capabilities: z2.array(capabilityEnum).min(1),
|
|
573
|
+
args: z2.array(connectorArgSchema).optional().default([]),
|
|
574
|
+
columns: z2.array(connectorColumnSchema).optional().default([]),
|
|
575
|
+
pipeline: z2.array(pipelineStepSchema).min(1)
|
|
4563
576
|
});
|
|
4564
577
|
|
|
4565
578
|
// ../shared/dist/loader.js
|
|
@@ -4640,7 +653,7 @@ import { randomUUID } from "crypto";
|
|
|
4640
653
|
function executeValidate(filePath) {
|
|
4641
654
|
let content;
|
|
4642
655
|
try {
|
|
4643
|
-
content =
|
|
656
|
+
content = readFileSync3(filePath, "utf-8");
|
|
4644
657
|
} catch (err) {
|
|
4645
658
|
return `Error: Cannot read file "${filePath}": ${err instanceof Error ? err.message : String(err)}`;
|
|
4646
659
|
}
|
|
@@ -4672,8 +685,8 @@ function executeValidate(filePath) {
|
|
|
4672
685
|
|
|
4673
686
|
// src/commands/daemon-cmd.ts
|
|
4674
687
|
import { spawn } from "child_process";
|
|
4675
|
-
import { readFileSync as
|
|
4676
|
-
import { join } from "path";
|
|
688
|
+
import { readFileSync as readFileSync4, writeFileSync, existsSync as existsSync2, unlinkSync, mkdirSync } from "fs";
|
|
689
|
+
import { join as join2 } from "path";
|
|
4677
690
|
async function executeDaemonStatus(baseUrl) {
|
|
4678
691
|
try {
|
|
4679
692
|
const resp = await fetch(`${baseUrl}/api/status`);
|
|
@@ -4693,7 +706,7 @@ async function executeDaemonStart(baseUrl, cgHome, daemonScript) {
|
|
|
4693
706
|
if (resp.ok) return "Daemon is already running.";
|
|
4694
707
|
} catch {
|
|
4695
708
|
}
|
|
4696
|
-
const pidPath =
|
|
709
|
+
const pidPath = join2(cgHome, "daemon.pid");
|
|
4697
710
|
mkdirSync(cgHome, { recursive: true });
|
|
4698
711
|
const child = spawn("node", [daemonScript], {
|
|
4699
712
|
detached: true,
|
|
@@ -4706,11 +719,11 @@ async function executeDaemonStart(baseUrl, cgHome, daemonScript) {
|
|
|
4706
719
|
return `Daemon started (PID: ${child.pid ?? "unknown"}).`;
|
|
4707
720
|
}
|
|
4708
721
|
async function executeDaemonStop(cgHome) {
|
|
4709
|
-
const pidPath =
|
|
4710
|
-
if (!
|
|
722
|
+
const pidPath = join2(cgHome, "daemon.pid");
|
|
723
|
+
if (!existsSync2(pidPath)) {
|
|
4711
724
|
return "Daemon is not running (no PID file found).";
|
|
4712
725
|
}
|
|
4713
|
-
const pid = parseInt(
|
|
726
|
+
const pid = parseInt(readFileSync4(pidPath, "utf-8").trim(), 10);
|
|
4714
727
|
try {
|
|
4715
728
|
process.kill(pid, "SIGTERM");
|
|
4716
729
|
unlinkSync(pidPath);
|
|
@@ -4852,16 +865,16 @@ async function executeAuditShow(client, id) {
|
|
|
4852
865
|
}
|
|
4853
866
|
|
|
4854
867
|
// src/commands/config-cmd.ts
|
|
4855
|
-
import { readFileSync as
|
|
868
|
+
import { readFileSync as readFileSync5, existsSync as existsSync3 } from "fs";
|
|
4856
869
|
function executeConfigShow(configPath) {
|
|
4857
|
-
if (!
|
|
870
|
+
if (!existsSync3(configPath)) {
|
|
4858
871
|
return [
|
|
4859
872
|
"No config file found.",
|
|
4860
873
|
`Expected at: ${configPath}`,
|
|
4861
874
|
'Using defaults. Run "commandgarden config set <key> <value>" to create one.'
|
|
4862
875
|
].join("\n");
|
|
4863
876
|
}
|
|
4864
|
-
return
|
|
877
|
+
return readFileSync5(configPath, "utf-8");
|
|
4865
878
|
}
|
|
4866
879
|
async function executeConfigSet(client, key, value) {
|
|
4867
880
|
try {
|
|
@@ -4874,14 +887,14 @@ async function executeConfigSet(client, key, value) {
|
|
|
4874
887
|
|
|
4875
888
|
// src/commands/gui-cmd.ts
|
|
4876
889
|
import { spawn as spawn2 } from "child_process";
|
|
4877
|
-
import { readFileSync as
|
|
4878
|
-
import { join as
|
|
890
|
+
import { readFileSync as readFileSync6, writeFileSync as writeFileSync2, existsSync as existsSync4, unlinkSync as unlinkSync2, mkdirSync as mkdirSync2, openSync, closeSync } from "fs";
|
|
891
|
+
import { join as join3 } from "path";
|
|
4879
892
|
import { exec } from "child_process";
|
|
4880
893
|
import { parse as parseYaml2 } from "yaml";
|
|
4881
894
|
function readAppPort(configPath) {
|
|
4882
895
|
try {
|
|
4883
|
-
if (
|
|
4884
|
-
const config2 = parseYaml2(
|
|
896
|
+
if (existsSync4(configPath)) {
|
|
897
|
+
const config2 = parseYaml2(readFileSync6(configPath, "utf-8"));
|
|
4885
898
|
const port = config2?.app?.port;
|
|
4886
899
|
if (typeof port === "number") return port;
|
|
4887
900
|
}
|
|
@@ -4897,9 +910,9 @@ async function executeGuiStart(baseUrl, cgHome, appScript, opts) {
|
|
|
4897
910
|
} catch {
|
|
4898
911
|
return "Daemon is not running. Start it with: cg daemon start (or use cg up)";
|
|
4899
912
|
}
|
|
4900
|
-
const pidPath =
|
|
4901
|
-
if (
|
|
4902
|
-
const pid = parseInt(
|
|
913
|
+
const pidPath = join3(cgHome, "app.pid");
|
|
914
|
+
if (existsSync4(pidPath)) {
|
|
915
|
+
const pid = parseInt(readFileSync6(pidPath, "utf-8").trim(), 10);
|
|
4903
916
|
try {
|
|
4904
917
|
process.kill(pid, 0);
|
|
4905
918
|
return "GUI is already running.";
|
|
@@ -4909,7 +922,7 @@ async function executeGuiStart(baseUrl, cgHome, appScript, opts) {
|
|
|
4909
922
|
}
|
|
4910
923
|
mkdirSync2(cgHome, { recursive: true });
|
|
4911
924
|
if (opts.background) {
|
|
4912
|
-
const logPath =
|
|
925
|
+
const logPath = join3(cgHome, "app.log");
|
|
4913
926
|
const logFd = openSync(logPath, "a");
|
|
4914
927
|
const child2 = spawn2("node", [appScript], { detached: true, stdio: ["ignore", logFd, logFd] });
|
|
4915
928
|
closeSync(logFd);
|
|
@@ -4925,7 +938,7 @@ async function executeGuiStart(baseUrl, cgHome, appScript, opts) {
|
|
|
4925
938
|
process.kill(child2.pid, "SIGTERM");
|
|
4926
939
|
} catch {
|
|
4927
940
|
}
|
|
4928
|
-
if (
|
|
941
|
+
if (existsSync4(pidPath)) unlinkSync2(pidPath);
|
|
4929
942
|
return `GUI failed to start. Check ${logPath} for errors.`;
|
|
4930
943
|
}
|
|
4931
944
|
}
|
|
@@ -4937,13 +950,13 @@ async function executeGuiStart(baseUrl, cgHome, appScript, opts) {
|
|
|
4937
950
|
const ready = await waitForServer(appUrl, child);
|
|
4938
951
|
if (ready) openBrowser(appUrl);
|
|
4939
952
|
}
|
|
4940
|
-
await new Promise((
|
|
953
|
+
await new Promise((resolve2) => child.on("exit", () => resolve2()));
|
|
4941
954
|
return "GUI stopped.";
|
|
4942
955
|
}
|
|
4943
956
|
function executeGuiStop(cgHome) {
|
|
4944
|
-
const pidPath =
|
|
4945
|
-
if (!
|
|
4946
|
-
const pid = parseInt(
|
|
957
|
+
const pidPath = join3(cgHome, "app.pid");
|
|
958
|
+
if (!existsSync4(pidPath)) return "GUI is not running (no PID file found).";
|
|
959
|
+
const pid = parseInt(readFileSync6(pidPath, "utf-8").trim(), 10);
|
|
4947
960
|
try {
|
|
4948
961
|
process.kill(pid, "SIGTERM");
|
|
4949
962
|
unlinkSync2(pidPath);
|
|
@@ -4954,9 +967,9 @@ function executeGuiStop(cgHome) {
|
|
|
4954
967
|
}
|
|
4955
968
|
}
|
|
4956
969
|
function executeGuiStatus(cgHome) {
|
|
4957
|
-
const pidPath =
|
|
4958
|
-
if (!
|
|
4959
|
-
const pid = parseInt(
|
|
970
|
+
const pidPath = join3(cgHome, "app.pid");
|
|
971
|
+
if (!existsSync4(pidPath)) return "GUI: not running (no PID file found).";
|
|
972
|
+
const pid = parseInt(readFileSync6(pidPath, "utf-8").trim(), 10);
|
|
4960
973
|
try {
|
|
4961
974
|
process.kill(pid, 0);
|
|
4962
975
|
return `GUI: running (PID: ${pid}).`;
|
|
@@ -5010,36 +1023,26 @@ async function executeDown(cgHome) {
|
|
|
5010
1023
|
|
|
5011
1024
|
// src/main.ts
|
|
5012
1025
|
var __filename = fileURLToPath(import.meta.url);
|
|
5013
|
-
var __dirname =
|
|
5014
|
-
|
|
5015
|
-
const relative = join3(__dirname, relativePath);
|
|
5016
|
-
if (existsSync4(relative)) return relative;
|
|
1026
|
+
var __dirname = dirname2(__filename);
|
|
1027
|
+
var CLI_VERSION = (() => {
|
|
5017
1028
|
try {
|
|
5018
|
-
const
|
|
5019
|
-
|
|
5020
|
-
const resolved = join3(dirname(pkgJsonPath), entryPoint);
|
|
5021
|
-
if (existsSync4(resolved)) return resolved;
|
|
1029
|
+
const pkg = JSON.parse(readFileSync7(resolve(__dirname, "..", "package.json"), "utf-8"));
|
|
1030
|
+
return pkg.version ?? "0.0.0";
|
|
5022
1031
|
} catch {
|
|
1032
|
+
return "0.0.0";
|
|
5023
1033
|
}
|
|
5024
|
-
|
|
5025
|
-
console.error(`Looked at:
|
|
5026
|
-
- ${relative}`);
|
|
5027
|
-
console.error(`
|
|
5028
|
-
If @commandgarden/cli is installed globally, also run:`);
|
|
5029
|
-
console.error(` cd <monorepo>/commandGarden/${packageName.split("/").pop()} && npm link`);
|
|
5030
|
-
process.exit(1);
|
|
5031
|
-
}
|
|
1034
|
+
})();
|
|
5032
1035
|
var _daemonScript;
|
|
5033
1036
|
function getDaemonScript() {
|
|
5034
|
-
return _daemonScript ??= resolveScript("../../daemon/dist/main.js", "@commandgarden/daemon", "dist/main.js");
|
|
1037
|
+
return _daemonScript ??= resolveScript(__dirname, "../../daemon/dist/main.js", "@commandgarden/daemon", "dist/main.js");
|
|
5035
1038
|
}
|
|
5036
1039
|
var _appScript;
|
|
5037
1040
|
function getAppScript() {
|
|
5038
|
-
return _appScript ??= resolveScript("../../app/dist/server/main.js", "@commandgarden/app", "dist/server/main.js");
|
|
1041
|
+
return _appScript ??= resolveScript(__dirname, "../../app/dist/server/main.js", "@commandgarden/app", "dist/server/main.js");
|
|
5039
1042
|
}
|
|
5040
|
-
var CG_HOME =
|
|
5041
|
-
var TOKEN_PATH =
|
|
5042
|
-
var CONFIG_PATH =
|
|
1043
|
+
var CG_HOME = join4(homedir(), ".commandgarden");
|
|
1044
|
+
var TOKEN_PATH = join4(CG_HOME, "session-token");
|
|
1045
|
+
var CONFIG_PATH = join4(CG_HOME, "config.yaml");
|
|
5043
1046
|
var BASE_URL = `http://127.0.0.1:19825`;
|
|
5044
1047
|
function createClient() {
|
|
5045
1048
|
const token = readToken(TOKEN_PATH);
|
|
@@ -5050,7 +1053,7 @@ function createClient() {
|
|
|
5050
1053
|
return new DaemonClient(BASE_URL, token);
|
|
5051
1054
|
}
|
|
5052
1055
|
var program = new Command();
|
|
5053
|
-
program.name("commandgarden").version(
|
|
1056
|
+
program.name("commandgarden").version(CLI_VERSION).description("Enterprise browser automation CLI");
|
|
5054
1057
|
program.command("run <connector>").description("Run a connector command").option("-f, --format <format>", "output format: table, json, csv", "table").allowUnknownOption().action(async (connector, opts, cmd) => {
|
|
5055
1058
|
const client = createClient();
|
|
5056
1059
|
const connectorArgs = parseConnectorArgs(cmd.args);
|