@alienplatform/commands 3.3.11 → 3.3.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +86 -0
- package/dist/bootstrap.d.ts +72 -0
- package/dist/bootstrap.d.ts.map +1 -0
- package/dist/client.d.ts +25 -2
- package/dist/client.d.ts.map +1 -1
- package/dist/errors.d.ts +82 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/index.d.ts +5 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1132 -433
- package/dist/presigned.d.ts.map +1 -1
- package/dist/receiver-config.d.ts +59 -0
- package/dist/receiver-config.d.ts.map +1 -0
- package/dist/receiver.d.ts +3 -19
- package/dist/receiver.d.ts.map +1 -1
- package/package.json +7 -7
package/dist/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { AlienError, AlienError as AlienError$1, CommandStatusResponseSchema, CreateCommandResponseSchema, LeaseResponseSchema, defineError, defineError as defineError$1 } from "@alienplatform/core";
|
|
2
2
|
import { readFile } from "node:fs/promises";
|
|
3
|
-
|
|
3
|
+
//#region ../../node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/core.js
|
|
4
|
+
var _a$1;
|
|
4
5
|
function $constructor(name, initializer, params) {
|
|
5
6
|
function init(inst, def) {
|
|
6
7
|
if (!inst._zod) Object.defineProperty(inst, "_zod", {
|
|
@@ -51,13 +52,14 @@ var $ZodEncodeError = class extends Error {
|
|
|
51
52
|
this.name = "ZodEncodeError";
|
|
52
53
|
}
|
|
53
54
|
};
|
|
54
|
-
|
|
55
|
+
(_a$1 = globalThis).__zod_globalConfig ?? (_a$1.__zod_globalConfig = {});
|
|
56
|
+
const globalConfig = globalThis.__zod_globalConfig;
|
|
55
57
|
function config(newConfig) {
|
|
56
58
|
if (newConfig) Object.assign(globalConfig, newConfig);
|
|
57
59
|
return globalConfig;
|
|
58
60
|
}
|
|
59
61
|
//#endregion
|
|
60
|
-
//#region ../../node_modules/.pnpm/zod@4.3
|
|
62
|
+
//#region ../../node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/util.js
|
|
61
63
|
function getEnumValues(entries) {
|
|
62
64
|
const numericValues = Object.values(entries).filter((v) => typeof v === "number");
|
|
63
65
|
return Object.entries(entries).filter(([k, _]) => numericValues.indexOf(+k) === -1).map(([_, v]) => v);
|
|
@@ -84,17 +86,13 @@ function cleanRegex(source) {
|
|
|
84
86
|
return source.slice(start, end);
|
|
85
87
|
}
|
|
86
88
|
function floatSafeRemainder(val, step) {
|
|
87
|
-
const
|
|
88
|
-
const
|
|
89
|
-
|
|
90
|
-
if (
|
|
91
|
-
|
|
92
|
-
if (match?.[1]) stepDecCount = Number.parseInt(match[1]);
|
|
93
|
-
}
|
|
94
|
-
const decCount = valDecCount > stepDecCount ? valDecCount : stepDecCount;
|
|
95
|
-
return Number.parseInt(val.toFixed(decCount).replace(".", "")) % Number.parseInt(step.toFixed(decCount).replace(".", "")) / 10 ** decCount;
|
|
89
|
+
const ratio = val / step;
|
|
90
|
+
const roundedRatio = Math.round(ratio);
|
|
91
|
+
const tolerance = Number.EPSILON * Math.max(Math.abs(ratio), 1);
|
|
92
|
+
if (Math.abs(ratio - roundedRatio) < tolerance) return 0;
|
|
93
|
+
return ratio - roundedRatio;
|
|
96
94
|
}
|
|
97
|
-
const EVALUATING = Symbol("evaluating");
|
|
95
|
+
const EVALUATING = /* @__PURE__*/ Symbol("evaluating");
|
|
98
96
|
function defineLazy(object, key, getter) {
|
|
99
97
|
let value = void 0;
|
|
100
98
|
Object.defineProperty(object, key, {
|
|
@@ -138,7 +136,8 @@ const captureStackTrace = "captureStackTrace" in Error ? Error.captureStackTrace
|
|
|
138
136
|
function isObject(data) {
|
|
139
137
|
return typeof data === "object" && data !== null && !Array.isArray(data);
|
|
140
138
|
}
|
|
141
|
-
const allowsEval = cached(() => {
|
|
139
|
+
const allowsEval = /* @__PURE__*/ cached(() => {
|
|
140
|
+
if (globalConfig.jitless) return false;
|
|
142
141
|
if (typeof navigator !== "undefined" && navigator?.userAgent?.includes("Cloudflare")) return false;
|
|
143
142
|
try {
|
|
144
143
|
new Function("");
|
|
@@ -160,9 +159,11 @@ function isPlainObject(o) {
|
|
|
160
159
|
function shallowClone(o) {
|
|
161
160
|
if (isPlainObject(o)) return { ...o };
|
|
162
161
|
if (Array.isArray(o)) return [...o];
|
|
162
|
+
if (o instanceof Map) return new Map(o);
|
|
163
|
+
if (o instanceof Set) return new Set(o);
|
|
163
164
|
return o;
|
|
164
165
|
}
|
|
165
|
-
const propertyKeyTypes = /* @__PURE__
|
|
166
|
+
const propertyKeyTypes = /* @__PURE__*/ new Set([
|
|
166
167
|
"string",
|
|
167
168
|
"number",
|
|
168
169
|
"symbol"
|
|
@@ -266,6 +267,7 @@ function safeExtend(schema, shape) {
|
|
|
266
267
|
} }));
|
|
267
268
|
}
|
|
268
269
|
function merge(a, b) {
|
|
270
|
+
if (a._zod.def.checks?.length) throw new Error(".merge() cannot be used on object schemas containing refinements. Use .safeExtend() instead.");
|
|
269
271
|
return clone(a, mergeDefs(a._zod.def, {
|
|
270
272
|
get shape() {
|
|
271
273
|
const _shape = {
|
|
@@ -278,7 +280,7 @@ function merge(a, b) {
|
|
|
278
280
|
get catchall() {
|
|
279
281
|
return b._zod.def.catchall;
|
|
280
282
|
},
|
|
281
|
-
checks: []
|
|
283
|
+
checks: b._zod.def.checks ?? []
|
|
282
284
|
}));
|
|
283
285
|
}
|
|
284
286
|
function partial(Class, schema, mask) {
|
|
@@ -331,6 +333,11 @@ function aborted(x, startIndex = 0) {
|
|
|
331
333
|
for (let i = startIndex; i < x.issues.length; i++) if (x.issues[i]?.continue !== true) return true;
|
|
332
334
|
return false;
|
|
333
335
|
}
|
|
336
|
+
function explicitlyAborted(x, startIndex = 0) {
|
|
337
|
+
if (x.aborted === true) return true;
|
|
338
|
+
for (let i = startIndex; i < x.issues.length; i++) if (x.issues[i]?.continue === false) return true;
|
|
339
|
+
return false;
|
|
340
|
+
}
|
|
334
341
|
function prefixIssues(path, issues) {
|
|
335
342
|
return issues.map((iss) => {
|
|
336
343
|
var _a;
|
|
@@ -343,15 +350,12 @@ function unwrapMessage(message) {
|
|
|
343
350
|
return typeof message === "string" ? message : message?.message;
|
|
344
351
|
}
|
|
345
352
|
function finalizeIssue(iss, ctx, config) {
|
|
346
|
-
const
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
if (
|
|
351
|
-
|
|
352
|
-
delete full.continue;
|
|
353
|
-
if (!ctx?.reportInput) delete full.input;
|
|
354
|
-
return full;
|
|
353
|
+
const message = iss.message ? iss.message : unwrapMessage(iss.inst?._zod.def?.error?.(iss)) ?? unwrapMessage(ctx?.error?.(iss)) ?? unwrapMessage(config.customError?.(iss)) ?? unwrapMessage(config.localeError?.(iss)) ?? "Invalid input";
|
|
354
|
+
const { inst: _inst, continue: _continue, input: _input, ...rest } = iss;
|
|
355
|
+
rest.path ?? (rest.path = []);
|
|
356
|
+
rest.message = message;
|
|
357
|
+
if (ctx?.reportInput) rest.input = _input;
|
|
358
|
+
return rest;
|
|
355
359
|
}
|
|
356
360
|
function getLengthableOrigin(input) {
|
|
357
361
|
if (Array.isArray(input)) return "array";
|
|
@@ -369,7 +373,7 @@ function issue(...args) {
|
|
|
369
373
|
return { ...iss };
|
|
370
374
|
}
|
|
371
375
|
//#endregion
|
|
372
|
-
//#region ../../node_modules/.pnpm/zod@4.3
|
|
376
|
+
//#region ../../node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/errors.js
|
|
373
377
|
const initializer$1 = (inst, def) => {
|
|
374
378
|
inst.name = "$ZodError";
|
|
375
379
|
Object.defineProperty(inst, "_zod", {
|
|
@@ -402,23 +406,26 @@ function flattenError(error, mapper = (issue) => issue.message) {
|
|
|
402
406
|
}
|
|
403
407
|
function formatError(error, mapper = (issue) => issue.message) {
|
|
404
408
|
const fieldErrors = { _errors: [] };
|
|
405
|
-
const processError = (error) => {
|
|
406
|
-
for (const issue of error.issues) if (issue.code === "invalid_union" && issue.errors.length) issue.errors.map((issues) => processError({ issues }));
|
|
407
|
-
else if (issue.code === "invalid_key") processError({ issues: issue.issues });
|
|
408
|
-
else if (issue.code === "invalid_element") processError({ issues: issue.issues });
|
|
409
|
-
else if (issue.path.length === 0) fieldErrors._errors.push(mapper(issue));
|
|
409
|
+
const processError = (error, path = []) => {
|
|
410
|
+
for (const issue of error.issues) if (issue.code === "invalid_union" && issue.errors.length) issue.errors.map((issues) => processError({ issues }, [...path, ...issue.path]));
|
|
411
|
+
else if (issue.code === "invalid_key") processError({ issues: issue.issues }, [...path, ...issue.path]);
|
|
412
|
+
else if (issue.code === "invalid_element") processError({ issues: issue.issues }, [...path, ...issue.path]);
|
|
410
413
|
else {
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
curr[el]
|
|
414
|
+
const fullpath = [...path, ...issue.path];
|
|
415
|
+
if (fullpath.length === 0) fieldErrors._errors.push(mapper(issue));
|
|
416
|
+
else {
|
|
417
|
+
let curr = fieldErrors;
|
|
418
|
+
let i = 0;
|
|
419
|
+
while (i < fullpath.length) {
|
|
420
|
+
const el = fullpath[i];
|
|
421
|
+
if (!(i === fullpath.length - 1)) curr[el] = curr[el] || { _errors: [] };
|
|
422
|
+
else {
|
|
423
|
+
curr[el] = curr[el] || { _errors: [] };
|
|
424
|
+
curr[el]._errors.push(mapper(issue));
|
|
425
|
+
}
|
|
426
|
+
curr = curr[el];
|
|
427
|
+
i++;
|
|
419
428
|
}
|
|
420
|
-
curr = curr[el];
|
|
421
|
-
i++;
|
|
422
429
|
}
|
|
423
430
|
}
|
|
424
431
|
};
|
|
@@ -426,9 +433,12 @@ function formatError(error, mapper = (issue) => issue.message) {
|
|
|
426
433
|
return fieldErrors;
|
|
427
434
|
}
|
|
428
435
|
//#endregion
|
|
429
|
-
//#region ../../node_modules/.pnpm/zod@4.3
|
|
436
|
+
//#region ../../node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/parse.js
|
|
430
437
|
const _parse = (_Err) => (schema, value, _ctx, _params) => {
|
|
431
|
-
const ctx = _ctx ?
|
|
438
|
+
const ctx = _ctx ? {
|
|
439
|
+
..._ctx,
|
|
440
|
+
async: false
|
|
441
|
+
} : { async: false };
|
|
432
442
|
const result = schema._zod.run({
|
|
433
443
|
value,
|
|
434
444
|
issues: []
|
|
@@ -442,7 +452,10 @@ const _parse = (_Err) => (schema, value, _ctx, _params) => {
|
|
|
442
452
|
return result.value;
|
|
443
453
|
};
|
|
444
454
|
const _parseAsync = (_Err) => async (schema, value, _ctx, params) => {
|
|
445
|
-
const ctx = _ctx ?
|
|
455
|
+
const ctx = _ctx ? {
|
|
456
|
+
..._ctx,
|
|
457
|
+
async: true
|
|
458
|
+
} : { async: true };
|
|
446
459
|
let result = schema._zod.run({
|
|
447
460
|
value,
|
|
448
461
|
issues: []
|
|
@@ -475,7 +488,10 @@ const _safeParse = (_Err) => (schema, value, _ctx) => {
|
|
|
475
488
|
};
|
|
476
489
|
const safeParse$1 = /* @__PURE__*/ _safeParse($ZodRealError);
|
|
477
490
|
const _safeParseAsync = (_Err) => async (schema, value, _ctx) => {
|
|
478
|
-
const ctx = _ctx ?
|
|
491
|
+
const ctx = _ctx ? {
|
|
492
|
+
..._ctx,
|
|
493
|
+
async: true
|
|
494
|
+
} : { async: true };
|
|
479
495
|
let result = schema._zod.run({
|
|
480
496
|
value,
|
|
481
497
|
issues: []
|
|
@@ -491,36 +507,53 @@ const _safeParseAsync = (_Err) => async (schema, value, _ctx) => {
|
|
|
491
507
|
};
|
|
492
508
|
const safeParseAsync$1 = /* @__PURE__*/ _safeParseAsync($ZodRealError);
|
|
493
509
|
const _encode = (_Err) => (schema, value, _ctx) => {
|
|
494
|
-
const ctx = _ctx ?
|
|
510
|
+
const ctx = _ctx ? {
|
|
511
|
+
..._ctx,
|
|
512
|
+
direction: "backward"
|
|
513
|
+
} : { direction: "backward" };
|
|
495
514
|
return _parse(_Err)(schema, value, ctx);
|
|
496
515
|
};
|
|
497
516
|
const _decode = (_Err) => (schema, value, _ctx) => {
|
|
498
517
|
return _parse(_Err)(schema, value, _ctx);
|
|
499
518
|
};
|
|
500
519
|
const _encodeAsync = (_Err) => async (schema, value, _ctx) => {
|
|
501
|
-
const ctx = _ctx ?
|
|
520
|
+
const ctx = _ctx ? {
|
|
521
|
+
..._ctx,
|
|
522
|
+
direction: "backward"
|
|
523
|
+
} : { direction: "backward" };
|
|
502
524
|
return _parseAsync(_Err)(schema, value, ctx);
|
|
503
525
|
};
|
|
504
526
|
const _decodeAsync = (_Err) => async (schema, value, _ctx) => {
|
|
505
527
|
return _parseAsync(_Err)(schema, value, _ctx);
|
|
506
528
|
};
|
|
507
529
|
const _safeEncode = (_Err) => (schema, value, _ctx) => {
|
|
508
|
-
const ctx = _ctx ?
|
|
530
|
+
const ctx = _ctx ? {
|
|
531
|
+
..._ctx,
|
|
532
|
+
direction: "backward"
|
|
533
|
+
} : { direction: "backward" };
|
|
509
534
|
return _safeParse(_Err)(schema, value, ctx);
|
|
510
535
|
};
|
|
511
536
|
const _safeDecode = (_Err) => (schema, value, _ctx) => {
|
|
512
537
|
return _safeParse(_Err)(schema, value, _ctx);
|
|
513
538
|
};
|
|
514
539
|
const _safeEncodeAsync = (_Err) => async (schema, value, _ctx) => {
|
|
515
|
-
const ctx = _ctx ?
|
|
540
|
+
const ctx = _ctx ? {
|
|
541
|
+
..._ctx,
|
|
542
|
+
direction: "backward"
|
|
543
|
+
} : { direction: "backward" };
|
|
516
544
|
return _safeParseAsync(_Err)(schema, value, ctx);
|
|
517
545
|
};
|
|
518
546
|
const _safeDecodeAsync = (_Err) => async (schema, value, _ctx) => {
|
|
519
547
|
return _safeParseAsync(_Err)(schema, value, _ctx);
|
|
520
548
|
};
|
|
521
549
|
//#endregion
|
|
522
|
-
//#region ../../node_modules/.pnpm/zod@4.3
|
|
523
|
-
|
|
550
|
+
//#region ../../node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/regexes.js
|
|
551
|
+
/**
|
|
552
|
+
* @deprecated CUID v1 is deprecated by its authors due to information leakage
|
|
553
|
+
* (timestamps embedded in the id). Use {@link cuid2} instead.
|
|
554
|
+
* See https://github.com/paralleldrive/cuid.
|
|
555
|
+
*/
|
|
556
|
+
const cuid = /^[cC][0-9a-z]{6,}$/;
|
|
524
557
|
const cuid2 = /^[0-9a-z]+$/;
|
|
525
558
|
const ulid = /^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/;
|
|
526
559
|
const xid = /^[0-9a-vA-V]{20}$/;
|
|
@@ -549,6 +582,7 @@ const cidrv4 = /^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-
|
|
|
549
582
|
const cidrv6 = /^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/;
|
|
550
583
|
const base64 = /^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/;
|
|
551
584
|
const base64url = /^[A-Za-z0-9_-]*$/;
|
|
585
|
+
const httpProtocol = /^https?$/;
|
|
552
586
|
const e164 = /^\+[1-9]\d{6,14}$/;
|
|
553
587
|
const dateSource = `(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))`;
|
|
554
588
|
const date$1 = /*@__PURE__*/ new RegExp(`^${dateSource}$`);
|
|
@@ -573,10 +607,11 @@ const string$1 = (params) => {
|
|
|
573
607
|
};
|
|
574
608
|
const integer = /^-?\d+$/;
|
|
575
609
|
const number$1 = /^-?\d+(?:\.\d+)?$/;
|
|
610
|
+
const _undefined$2 = /^undefined$/i;
|
|
576
611
|
const lowercase = /^[^A-Z]*$/;
|
|
577
612
|
const uppercase = /^[^a-z]*$/;
|
|
578
613
|
//#endregion
|
|
579
|
-
//#region ../../node_modules/.pnpm/zod@4.3
|
|
614
|
+
//#region ../../node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/checks.js
|
|
580
615
|
const $ZodCheck = /*@__PURE__*/ $constructor("$ZodCheck", (inst, def) => {
|
|
581
616
|
var _a;
|
|
582
617
|
inst._zod ?? (inst._zod = {});
|
|
@@ -594,8 +629,10 @@ const $ZodCheckLessThan = /*@__PURE__*/ $constructor("$ZodCheckLessThan", (inst,
|
|
|
594
629
|
inst._zod.onattach.push((inst) => {
|
|
595
630
|
const bag = inst._zod.bag;
|
|
596
631
|
const curr = (def.inclusive ? bag.maximum : bag.exclusiveMaximum) ?? Number.POSITIVE_INFINITY;
|
|
597
|
-
if (def.value < curr)
|
|
598
|
-
|
|
632
|
+
if (def.value < curr) {
|
|
633
|
+
if (def.inclusive) bag.maximum = def.value;
|
|
634
|
+
else bag.exclusiveMaximum = def.value;
|
|
635
|
+
}
|
|
599
636
|
});
|
|
600
637
|
inst._zod.check = (payload) => {
|
|
601
638
|
if (def.inclusive ? payload.value <= def.value : payload.value < def.value) return;
|
|
@@ -616,8 +653,10 @@ const $ZodCheckGreaterThan = /*@__PURE__*/ $constructor("$ZodCheckGreaterThan",
|
|
|
616
653
|
inst._zod.onattach.push((inst) => {
|
|
617
654
|
const bag = inst._zod.bag;
|
|
618
655
|
const curr = (def.inclusive ? bag.minimum : bag.exclusiveMinimum) ?? Number.NEGATIVE_INFINITY;
|
|
619
|
-
if (def.value > curr)
|
|
620
|
-
|
|
656
|
+
if (def.value > curr) {
|
|
657
|
+
if (def.inclusive) bag.minimum = def.value;
|
|
658
|
+
else bag.exclusiveMinimum = def.value;
|
|
659
|
+
}
|
|
621
660
|
});
|
|
622
661
|
inst._zod.check = (payload) => {
|
|
623
662
|
if (def.inclusive ? payload.value >= def.value : payload.value > def.value) return;
|
|
@@ -934,7 +973,7 @@ const $ZodCheckOverwrite = /*@__PURE__*/ $constructor("$ZodCheckOverwrite", (ins
|
|
|
934
973
|
};
|
|
935
974
|
});
|
|
936
975
|
//#endregion
|
|
937
|
-
//#region ../../node_modules/.pnpm/zod@4.3
|
|
976
|
+
//#region ../../node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/doc.js
|
|
938
977
|
var Doc = class {
|
|
939
978
|
constructor(args = []) {
|
|
940
979
|
this.content = [];
|
|
@@ -965,14 +1004,14 @@ var Doc = class {
|
|
|
965
1004
|
}
|
|
966
1005
|
};
|
|
967
1006
|
//#endregion
|
|
968
|
-
//#region ../../node_modules/.pnpm/zod@4.3
|
|
1007
|
+
//#region ../../node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/versions.js
|
|
969
1008
|
const version = {
|
|
970
1009
|
major: 4,
|
|
971
|
-
minor:
|
|
972
|
-
patch:
|
|
1010
|
+
minor: 4,
|
|
1011
|
+
patch: 3
|
|
973
1012
|
};
|
|
974
1013
|
//#endregion
|
|
975
|
-
//#region ../../node_modules/.pnpm/zod@4.3
|
|
1014
|
+
//#region ../../node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/schemas.js
|
|
976
1015
|
const $ZodType = /*@__PURE__*/ $constructor("$ZodType", (inst, def) => {
|
|
977
1016
|
var _a;
|
|
978
1017
|
inst ?? (inst = {});
|
|
@@ -993,6 +1032,7 @@ const $ZodType = /*@__PURE__*/ $constructor("$ZodType", (inst, def) => {
|
|
|
993
1032
|
let asyncResult;
|
|
994
1033
|
for (const ch of checks) {
|
|
995
1034
|
if (ch._zod.def.when) {
|
|
1035
|
+
if (explicitlyAborted(payload)) continue;
|
|
996
1036
|
if (!ch._zod.def.when(payload)) continue;
|
|
997
1037
|
} else if (isAborted) continue;
|
|
998
1038
|
const currLen = payload.issues.length;
|
|
@@ -1112,6 +1152,19 @@ const $ZodURL = /*@__PURE__*/ $constructor("$ZodURL", (inst, def) => {
|
|
|
1112
1152
|
inst._zod.check = (payload) => {
|
|
1113
1153
|
try {
|
|
1114
1154
|
const trimmed = payload.value.trim();
|
|
1155
|
+
if (!def.normalize && def.protocol?.source === httpProtocol.source) {
|
|
1156
|
+
if (!/^https?:\/\//i.test(trimmed)) {
|
|
1157
|
+
payload.issues.push({
|
|
1158
|
+
code: "invalid_format",
|
|
1159
|
+
format: "url",
|
|
1160
|
+
note: "Invalid URL format",
|
|
1161
|
+
input: payload.value,
|
|
1162
|
+
inst,
|
|
1163
|
+
continue: !def.abort
|
|
1164
|
+
});
|
|
1165
|
+
return;
|
|
1166
|
+
}
|
|
1167
|
+
}
|
|
1115
1168
|
const url = new URL(trimmed);
|
|
1116
1169
|
if (def.hostname) {
|
|
1117
1170
|
def.hostname.lastIndex = 0;
|
|
@@ -1159,6 +1212,11 @@ const $ZodNanoID = /*@__PURE__*/ $constructor("$ZodNanoID", (inst, def) => {
|
|
|
1159
1212
|
def.pattern ?? (def.pattern = nanoid);
|
|
1160
1213
|
$ZodStringFormat.init(inst, def);
|
|
1161
1214
|
});
|
|
1215
|
+
/**
|
|
1216
|
+
* @deprecated CUID v1 is deprecated by its authors due to information leakage
|
|
1217
|
+
* (timestamps embedded in the id). Use {@link $ZodCUID2} instead.
|
|
1218
|
+
* See https://github.com/paralleldrive/cuid.
|
|
1219
|
+
*/
|
|
1162
1220
|
const $ZodCUID = /*@__PURE__*/ $constructor("$ZodCUID", (inst, def) => {
|
|
1163
1221
|
def.pattern ?? (def.pattern = cuid);
|
|
1164
1222
|
$ZodStringFormat.init(inst, def);
|
|
@@ -1248,6 +1306,7 @@ const $ZodCIDRv6 = /*@__PURE__*/ $constructor("$ZodCIDRv6", (inst, def) => {
|
|
|
1248
1306
|
});
|
|
1249
1307
|
function isValidBase64(data) {
|
|
1250
1308
|
if (data === "") return true;
|
|
1309
|
+
if (/\s/.test(data)) return false;
|
|
1251
1310
|
if (data.length % 4 !== 0) return false;
|
|
1252
1311
|
try {
|
|
1253
1312
|
atob(data);
|
|
@@ -1347,6 +1406,22 @@ const $ZodNumberFormat = /*@__PURE__*/ $constructor("$ZodNumberFormat", (inst, d
|
|
|
1347
1406
|
$ZodCheckNumberFormat.init(inst, def);
|
|
1348
1407
|
$ZodNumber.init(inst, def);
|
|
1349
1408
|
});
|
|
1409
|
+
const $ZodUndefined = /*@__PURE__*/ $constructor("$ZodUndefined", (inst, def) => {
|
|
1410
|
+
$ZodType.init(inst, def);
|
|
1411
|
+
inst._zod.pattern = _undefined$2;
|
|
1412
|
+
inst._zod.values = /* @__PURE__ */ new Set([void 0]);
|
|
1413
|
+
inst._zod.parse = (payload, _ctx) => {
|
|
1414
|
+
const input = payload.value;
|
|
1415
|
+
if (typeof input === "undefined") return payload;
|
|
1416
|
+
payload.issues.push({
|
|
1417
|
+
expected: "undefined",
|
|
1418
|
+
code: "invalid_type",
|
|
1419
|
+
input,
|
|
1420
|
+
inst
|
|
1421
|
+
});
|
|
1422
|
+
return payload;
|
|
1423
|
+
};
|
|
1424
|
+
});
|
|
1350
1425
|
const $ZodUnknown = /*@__PURE__*/ $constructor("$ZodUnknown", (inst, def) => {
|
|
1351
1426
|
$ZodType.init(inst, def);
|
|
1352
1427
|
inst._zod.parse = (payload) => payload;
|
|
@@ -1395,13 +1470,23 @@ const $ZodArray = /*@__PURE__*/ $constructor("$ZodArray", (inst, def) => {
|
|
|
1395
1470
|
return payload;
|
|
1396
1471
|
};
|
|
1397
1472
|
});
|
|
1398
|
-
function handlePropertyResult(result, final, key, input, isOptionalOut) {
|
|
1473
|
+
function handlePropertyResult(result, final, key, input, isOptionalIn, isOptionalOut) {
|
|
1474
|
+
const isPresent = key in input;
|
|
1399
1475
|
if (result.issues.length) {
|
|
1400
|
-
if (isOptionalOut && !
|
|
1476
|
+
if (isOptionalIn && isOptionalOut && !isPresent) return;
|
|
1401
1477
|
final.issues.push(...prefixIssues(key, result.issues));
|
|
1402
1478
|
}
|
|
1479
|
+
if (!isPresent && !isOptionalIn) {
|
|
1480
|
+
if (!result.issues.length) final.issues.push({
|
|
1481
|
+
code: "invalid_type",
|
|
1482
|
+
expected: "nonoptional",
|
|
1483
|
+
input: void 0,
|
|
1484
|
+
path: [key]
|
|
1485
|
+
});
|
|
1486
|
+
return;
|
|
1487
|
+
}
|
|
1403
1488
|
if (result.value === void 0) {
|
|
1404
|
-
if (
|
|
1489
|
+
if (isPresent) final.value[key] = void 0;
|
|
1405
1490
|
} else final.value[key] = result.value;
|
|
1406
1491
|
}
|
|
1407
1492
|
function normalizeDef(def) {
|
|
@@ -1421,8 +1506,10 @@ function handleCatchall(proms, input, payload, ctx, def, inst) {
|
|
|
1421
1506
|
const keySet = def.keySet;
|
|
1422
1507
|
const _catchall = def.catchall._zod;
|
|
1423
1508
|
const t = _catchall.def.type;
|
|
1509
|
+
const isOptionalIn = _catchall.optin === "optional";
|
|
1424
1510
|
const isOptionalOut = _catchall.optout === "optional";
|
|
1425
1511
|
for (const key in input) {
|
|
1512
|
+
if (key === "__proto__") continue;
|
|
1426
1513
|
if (keySet.has(key)) continue;
|
|
1427
1514
|
if (t === "never") {
|
|
1428
1515
|
unrecognized.push(key);
|
|
@@ -1432,8 +1519,8 @@ function handleCatchall(proms, input, payload, ctx, def, inst) {
|
|
|
1432
1519
|
value: input[key],
|
|
1433
1520
|
issues: []
|
|
1434
1521
|
}, ctx);
|
|
1435
|
-
if (r instanceof Promise) proms.push(r.then((r) => handlePropertyResult(r, payload, key, input, isOptionalOut)));
|
|
1436
|
-
else handlePropertyResult(r, payload, key, input, isOptionalOut);
|
|
1522
|
+
if (r instanceof Promise) proms.push(r.then((r) => handlePropertyResult(r, payload, key, input, isOptionalIn, isOptionalOut)));
|
|
1523
|
+
else handlePropertyResult(r, payload, key, input, isOptionalIn, isOptionalOut);
|
|
1437
1524
|
}
|
|
1438
1525
|
if (unrecognized.length) payload.issues.push({
|
|
1439
1526
|
code: "unrecognized_keys",
|
|
@@ -1489,13 +1576,14 @@ const $ZodObject = /*@__PURE__*/ $constructor("$ZodObject", (inst, def) => {
|
|
|
1489
1576
|
const shape = value.shape;
|
|
1490
1577
|
for (const key of value.keys) {
|
|
1491
1578
|
const el = shape[key];
|
|
1579
|
+
const isOptionalIn = el._zod.optin === "optional";
|
|
1492
1580
|
const isOptionalOut = el._zod.optout === "optional";
|
|
1493
1581
|
const r = el._zod.run({
|
|
1494
1582
|
value: input[key],
|
|
1495
1583
|
issues: []
|
|
1496
1584
|
}, ctx);
|
|
1497
|
-
if (r instanceof Promise) proms.push(r.then((r) => handlePropertyResult(r, payload, key, input, isOptionalOut)));
|
|
1498
|
-
else handlePropertyResult(r, payload, key, input, isOptionalOut);
|
|
1585
|
+
if (r instanceof Promise) proms.push(r.then((r) => handlePropertyResult(r, payload, key, input, isOptionalIn, isOptionalOut)));
|
|
1586
|
+
else handlePropertyResult(r, payload, key, input, isOptionalIn, isOptionalOut);
|
|
1499
1587
|
}
|
|
1500
1588
|
if (!catchall) return proms.length ? Promise.all(proms).then(() => payload) : payload;
|
|
1501
1589
|
return handleCatchall(proms, input, payload, ctx, _normalized.value, inst);
|
|
@@ -1524,9 +1612,11 @@ const $ZodObjectJIT = /*@__PURE__*/ $constructor("$ZodObjectJIT", (inst, def) =>
|
|
|
1524
1612
|
for (const key of normalized.keys) {
|
|
1525
1613
|
const id = ids[key];
|
|
1526
1614
|
const k = esc(key);
|
|
1527
|
-
const
|
|
1615
|
+
const schema = shape[key];
|
|
1616
|
+
const isOptionalIn = schema?._zod?.optin === "optional";
|
|
1617
|
+
const isOptionalOut = schema?._zod?.optout === "optional";
|
|
1528
1618
|
doc.write(`const ${id} = ${parseStr(key)};`);
|
|
1529
|
-
if (isOptionalOut) doc.write(`
|
|
1619
|
+
if (isOptionalIn && isOptionalOut) doc.write(`
|
|
1530
1620
|
if (${id}.issues.length) {
|
|
1531
1621
|
if (${k} in input) {
|
|
1532
1622
|
payload.issues = payload.issues.concat(${id}.issues.map(iss => ({
|
|
@@ -1544,6 +1634,32 @@ const $ZodObjectJIT = /*@__PURE__*/ $constructor("$ZodObjectJIT", (inst, def) =>
|
|
|
1544
1634
|
newResult[${k}] = ${id}.value;
|
|
1545
1635
|
}
|
|
1546
1636
|
|
|
1637
|
+
`);
|
|
1638
|
+
else if (!isOptionalIn) doc.write(`
|
|
1639
|
+
const ${id}_present = ${k} in input;
|
|
1640
|
+
if (${id}.issues.length) {
|
|
1641
|
+
payload.issues = payload.issues.concat(${id}.issues.map(iss => ({
|
|
1642
|
+
...iss,
|
|
1643
|
+
path: iss.path ? [${k}, ...iss.path] : [${k}]
|
|
1644
|
+
})));
|
|
1645
|
+
}
|
|
1646
|
+
if (!${id}_present && !${id}.issues.length) {
|
|
1647
|
+
payload.issues.push({
|
|
1648
|
+
code: "invalid_type",
|
|
1649
|
+
expected: "nonoptional",
|
|
1650
|
+
input: undefined,
|
|
1651
|
+
path: [${k}]
|
|
1652
|
+
});
|
|
1653
|
+
}
|
|
1654
|
+
|
|
1655
|
+
if (${id}_present) {
|
|
1656
|
+
if (${id}.value === undefined) {
|
|
1657
|
+
newResult[${k}] = undefined;
|
|
1658
|
+
} else {
|
|
1659
|
+
newResult[${k}] = ${id}.value;
|
|
1660
|
+
}
|
|
1661
|
+
}
|
|
1662
|
+
|
|
1547
1663
|
`);
|
|
1548
1664
|
else doc.write(`
|
|
1549
1665
|
if (${id}.issues.length) {
|
|
@@ -1626,10 +1742,9 @@ const $ZodUnion = /*@__PURE__*/ $constructor("$ZodUnion", (inst, def) => {
|
|
|
1626
1742
|
return new RegExp(`^(${patterns.map((p) => cleanRegex(p.source)).join("|")})$`);
|
|
1627
1743
|
}
|
|
1628
1744
|
});
|
|
1629
|
-
const
|
|
1630
|
-
const first = def.options[0]._zod.run;
|
|
1745
|
+
const first = def.options.length === 1 ? def.options[0]._zod.run : null;
|
|
1631
1746
|
inst._zod.parse = (payload, ctx) => {
|
|
1632
|
-
if (
|
|
1747
|
+
if (first) return first(payload, ctx);
|
|
1633
1748
|
let async = false;
|
|
1634
1749
|
const results = [];
|
|
1635
1750
|
for (const option of def.options) {
|
|
@@ -1770,20 +1885,23 @@ const $ZodEnum = /*@__PURE__*/ $constructor("$ZodEnum", (inst, def) => {
|
|
|
1770
1885
|
});
|
|
1771
1886
|
const $ZodTransform = /*@__PURE__*/ $constructor("$ZodTransform", (inst, def) => {
|
|
1772
1887
|
$ZodType.init(inst, def);
|
|
1888
|
+
inst._zod.optin = "optional";
|
|
1773
1889
|
inst._zod.parse = (payload, ctx) => {
|
|
1774
1890
|
if (ctx.direction === "backward") throw new $ZodEncodeError(inst.constructor.name);
|
|
1775
1891
|
const _out = def.transform(payload.value, payload);
|
|
1776
1892
|
if (ctx.async) return (_out instanceof Promise ? _out : Promise.resolve(_out)).then((output) => {
|
|
1777
1893
|
payload.value = output;
|
|
1894
|
+
payload.fallback = true;
|
|
1778
1895
|
return payload;
|
|
1779
1896
|
});
|
|
1780
1897
|
if (_out instanceof Promise) throw new $ZodAsyncError();
|
|
1781
1898
|
payload.value = _out;
|
|
1899
|
+
payload.fallback = true;
|
|
1782
1900
|
return payload;
|
|
1783
1901
|
};
|
|
1784
1902
|
});
|
|
1785
1903
|
function handleOptionalResult(result, input) {
|
|
1786
|
-
if (result.issues.length
|
|
1904
|
+
if (input === void 0 && (result.issues.length || result.fallback)) return {
|
|
1787
1905
|
issues: [],
|
|
1788
1906
|
value: void 0
|
|
1789
1907
|
};
|
|
@@ -1802,9 +1920,10 @@ const $ZodOptional = /*@__PURE__*/ $constructor("$ZodOptional", (inst, def) => {
|
|
|
1802
1920
|
});
|
|
1803
1921
|
inst._zod.parse = (payload, ctx) => {
|
|
1804
1922
|
if (def.innerType._zod.optin === "optional") {
|
|
1923
|
+
const input = payload.value;
|
|
1805
1924
|
const result = def.innerType._zod.run(payload, ctx);
|
|
1806
|
-
if (result instanceof Promise) return result.then((r) => handleOptionalResult(r,
|
|
1807
|
-
return handleOptionalResult(result,
|
|
1925
|
+
if (result instanceof Promise) return result.then((r) => handleOptionalResult(r, input));
|
|
1926
|
+
return handleOptionalResult(result, input);
|
|
1808
1927
|
}
|
|
1809
1928
|
if (payload.value === void 0) return payload;
|
|
1810
1929
|
return def.innerType._zod.run(payload, ctx);
|
|
@@ -1889,7 +2008,7 @@ function handleNonOptionalResult(payload, inst) {
|
|
|
1889
2008
|
}
|
|
1890
2009
|
const $ZodCatch = /*@__PURE__*/ $constructor("$ZodCatch", (inst, def) => {
|
|
1891
2010
|
$ZodType.init(inst, def);
|
|
1892
|
-
|
|
2011
|
+
inst._zod.optin = "optional";
|
|
1893
2012
|
defineLazy(inst._zod, "optout", () => def.innerType._zod.optout);
|
|
1894
2013
|
defineLazy(inst._zod, "values", () => def.innerType._zod.values);
|
|
1895
2014
|
inst._zod.parse = (payload, ctx) => {
|
|
@@ -1904,6 +2023,7 @@ const $ZodCatch = /*@__PURE__*/ $constructor("$ZodCatch", (inst, def) => {
|
|
|
1904
2023
|
input: payload.value
|
|
1905
2024
|
});
|
|
1906
2025
|
payload.issues = [];
|
|
2026
|
+
payload.fallback = true;
|
|
1907
2027
|
}
|
|
1908
2028
|
return payload;
|
|
1909
2029
|
});
|
|
@@ -1915,6 +2035,7 @@ const $ZodCatch = /*@__PURE__*/ $constructor("$ZodCatch", (inst, def) => {
|
|
|
1915
2035
|
input: payload.value
|
|
1916
2036
|
});
|
|
1917
2037
|
payload.issues = [];
|
|
2038
|
+
payload.fallback = true;
|
|
1918
2039
|
}
|
|
1919
2040
|
return payload;
|
|
1920
2041
|
};
|
|
@@ -1943,7 +2064,8 @@ function handlePipeResult(left, next, ctx) {
|
|
|
1943
2064
|
}
|
|
1944
2065
|
return next._zod.run({
|
|
1945
2066
|
value: left.value,
|
|
1946
|
-
issues: left.issues
|
|
2067
|
+
issues: left.issues,
|
|
2068
|
+
fallback: left.fallback
|
|
1947
2069
|
}, ctx);
|
|
1948
2070
|
}
|
|
1949
2071
|
const $ZodReadonly = /*@__PURE__*/ $constructor("$ZodReadonly", (inst, def) => {
|
|
@@ -1990,7 +2112,7 @@ function handleRefineResult(result, payload, input, inst) {
|
|
|
1990
2112
|
}
|
|
1991
2113
|
}
|
|
1992
2114
|
//#endregion
|
|
1993
|
-
//#region ../../node_modules/.pnpm/zod@4.3
|
|
2115
|
+
//#region ../../node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/registries.js
|
|
1994
2116
|
var _a;
|
|
1995
2117
|
var $ZodRegistry = class {
|
|
1996
2118
|
constructor() {
|
|
@@ -2037,7 +2159,7 @@ function registry() {
|
|
|
2037
2159
|
(_a = globalThis).__zod_globalRegistry ?? (_a.__zod_globalRegistry = registry());
|
|
2038
2160
|
const globalRegistry = globalThis.__zod_globalRegistry;
|
|
2039
2161
|
//#endregion
|
|
2040
|
-
//#region ../../node_modules/.pnpm/zod@4.3
|
|
2162
|
+
//#region ../../node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/api.js
|
|
2041
2163
|
// @__NO_SIDE_EFFECTS__
|
|
2042
2164
|
function _string(Class, params) {
|
|
2043
2165
|
return new Class({
|
|
@@ -2138,6 +2260,11 @@ function _nanoid(Class, params) {
|
|
|
2138
2260
|
...normalizeParams(params)
|
|
2139
2261
|
});
|
|
2140
2262
|
}
|
|
2263
|
+
/**
|
|
2264
|
+
* @deprecated CUID v1 is deprecated by its authors due to information leakage
|
|
2265
|
+
* (timestamps embedded in the id). Use {@link _cuid2} instead.
|
|
2266
|
+
* See https://github.com/paralleldrive/cuid.
|
|
2267
|
+
*/
|
|
2141
2268
|
// @__NO_SIDE_EFFECTS__
|
|
2142
2269
|
function _cuid(Class, params) {
|
|
2143
2270
|
return new Class({
|
|
@@ -2327,6 +2454,13 @@ function _int(Class, params) {
|
|
|
2327
2454
|
});
|
|
2328
2455
|
}
|
|
2329
2456
|
// @__NO_SIDE_EFFECTS__
|
|
2457
|
+
function _undefined$1(Class, params) {
|
|
2458
|
+
return new Class({
|
|
2459
|
+
type: "undefined",
|
|
2460
|
+
...normalizeParams(params)
|
|
2461
|
+
});
|
|
2462
|
+
}
|
|
2463
|
+
// @__NO_SIDE_EFFECTS__
|
|
2330
2464
|
function _unknown(Class) {
|
|
2331
2465
|
return new Class({ type: "unknown" });
|
|
2332
2466
|
}
|
|
@@ -2502,7 +2636,7 @@ function _refine(Class, fn, _params) {
|
|
|
2502
2636
|
});
|
|
2503
2637
|
}
|
|
2504
2638
|
// @__NO_SIDE_EFFECTS__
|
|
2505
|
-
function _superRefine(fn) {
|
|
2639
|
+
function _superRefine(fn, params) {
|
|
2506
2640
|
const ch = /* @__PURE__ */ _check((payload) => {
|
|
2507
2641
|
payload.addIssue = (issue$2) => {
|
|
2508
2642
|
if (typeof issue$2 === "string") payload.issues.push(issue(issue$2, payload.value, ch._zod.def));
|
|
@@ -2517,7 +2651,7 @@ function _superRefine(fn) {
|
|
|
2517
2651
|
}
|
|
2518
2652
|
};
|
|
2519
2653
|
return fn(payload.value, payload);
|
|
2520
|
-
});
|
|
2654
|
+
}, params);
|
|
2521
2655
|
return ch;
|
|
2522
2656
|
}
|
|
2523
2657
|
// @__NO_SIDE_EFFECTS__
|
|
@@ -2530,7 +2664,7 @@ function _check(fn, params) {
|
|
|
2530
2664
|
return ch;
|
|
2531
2665
|
}
|
|
2532
2666
|
//#endregion
|
|
2533
|
-
//#region ../../node_modules/.pnpm/zod@4.3
|
|
2667
|
+
//#region ../../node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/to-json-schema.js
|
|
2534
2668
|
function initializeContext(params) {
|
|
2535
2669
|
let target = params?.target ?? "draft-2020-12";
|
|
2536
2670
|
if (target === "draft-4") target = "draft-04";
|
|
@@ -2596,7 +2730,7 @@ function process$1(schema, ctx, _params = {
|
|
|
2596
2730
|
delete result.schema.examples;
|
|
2597
2731
|
delete result.schema.default;
|
|
2598
2732
|
}
|
|
2599
|
-
if (ctx.io === "input" && result.schema
|
|
2733
|
+
if (ctx.io === "input" && "_prefault" in result.schema) (_a = result.schema).default ?? (_a.default = result.schema._prefault);
|
|
2600
2734
|
delete result.schema._prefault;
|
|
2601
2735
|
return ctx.seen.get(schema).schema;
|
|
2602
2736
|
}
|
|
@@ -2701,7 +2835,7 @@ function finalize(ctx, schema) {
|
|
|
2701
2835
|
if (key === "$ref" || key === "allOf") continue;
|
|
2702
2836
|
if (!(key in _cached)) delete schema[key];
|
|
2703
2837
|
}
|
|
2704
|
-
if (refSchema.$ref) for (const key in schema) {
|
|
2838
|
+
if (refSchema.$ref && refSeen.def) for (const key in schema) {
|
|
2705
2839
|
if (key === "$ref" || key === "allOf") continue;
|
|
2706
2840
|
if (key in refSeen.def && JSON.stringify(schema[key]) === JSON.stringify(refSeen.def[key])) delete schema[key];
|
|
2707
2841
|
}
|
|
@@ -2736,13 +2870,20 @@ function finalize(ctx, schema) {
|
|
|
2736
2870
|
result.$id = ctx.external.uri(id);
|
|
2737
2871
|
}
|
|
2738
2872
|
Object.assign(result, root.def ?? root.schema);
|
|
2873
|
+
const rootMetaId = ctx.metadataRegistry.get(schema)?.id;
|
|
2874
|
+
if (rootMetaId !== void 0 && result.id === rootMetaId) delete result.id;
|
|
2739
2875
|
const defs = ctx.external?.defs ?? {};
|
|
2740
2876
|
for (const entry of ctx.seen.entries()) {
|
|
2741
2877
|
const seen = entry[1];
|
|
2742
|
-
if (seen.def && seen.defId)
|
|
2878
|
+
if (seen.def && seen.defId) {
|
|
2879
|
+
if (seen.def.id === seen.defId) delete seen.def.id;
|
|
2880
|
+
defs[seen.defId] = seen.def;
|
|
2881
|
+
}
|
|
2882
|
+
}
|
|
2883
|
+
if (ctx.external) {} else if (Object.keys(defs).length > 0) {
|
|
2884
|
+
if (ctx.target === "draft-2020-12") result.$defs = defs;
|
|
2885
|
+
else result.definitions = defs;
|
|
2743
2886
|
}
|
|
2744
|
-
if (ctx.external) {} else if (Object.keys(defs).length > 0) if (ctx.target === "draft-2020-12") result.$defs = defs;
|
|
2745
|
-
else result.definitions = defs;
|
|
2746
2887
|
try {
|
|
2747
2888
|
const finalized = JSON.parse(JSON.stringify(result));
|
|
2748
2889
|
Object.defineProperty(finalized, "~standard", {
|
|
@@ -2773,7 +2914,10 @@ function isTransforming(_schema, _ctx) {
|
|
|
2773
2914
|
if (def.type === "promise" || def.type === "optional" || def.type === "nonoptional" || def.type === "nullable" || def.type === "readonly" || def.type === "default" || def.type === "prefault") return isTransforming(def.innerType, ctx);
|
|
2774
2915
|
if (def.type === "intersection") return isTransforming(def.left, ctx) || isTransforming(def.right, ctx);
|
|
2775
2916
|
if (def.type === "record" || def.type === "map") return isTransforming(def.keyType, ctx) || isTransforming(def.valueType, ctx);
|
|
2776
|
-
if (def.type === "pipe")
|
|
2917
|
+
if (def.type === "pipe") {
|
|
2918
|
+
if (_schema._zod.traits.has("$ZodCodec")) return true;
|
|
2919
|
+
return isTransforming(def.in, ctx) || isTransforming(def.out, ctx);
|
|
2920
|
+
}
|
|
2777
2921
|
if (def.type === "object") {
|
|
2778
2922
|
for (const key in def.shape) if (isTransforming(def.shape[key], ctx)) return true;
|
|
2779
2923
|
return false;
|
|
@@ -2815,7 +2959,7 @@ const createStandardJSONSchemaMethod = (schema, io, processors = {}) => (params)
|
|
|
2815
2959
|
return finalize(ctx, schema);
|
|
2816
2960
|
};
|
|
2817
2961
|
//#endregion
|
|
2818
|
-
//#region ../../node_modules/.pnpm/zod@4.3
|
|
2962
|
+
//#region ../../node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/json-schema-processors.js
|
|
2819
2963
|
const formatMap = {
|
|
2820
2964
|
guid: "uuid",
|
|
2821
2965
|
url: "uri",
|
|
@@ -2849,26 +2993,26 @@ const numberProcessor = (schema, ctx, _json, _params) => {
|
|
|
2849
2993
|
const { minimum, maximum, format, multipleOf, exclusiveMaximum, exclusiveMinimum } = schema._zod.bag;
|
|
2850
2994
|
if (typeof format === "string" && format.includes("int")) json.type = "integer";
|
|
2851
2995
|
else json.type = "number";
|
|
2852
|
-
|
|
2853
|
-
|
|
2854
|
-
|
|
2855
|
-
|
|
2856
|
-
|
|
2857
|
-
|
|
2858
|
-
|
|
2859
|
-
else
|
|
2860
|
-
}
|
|
2861
|
-
if (
|
|
2862
|
-
|
|
2863
|
-
|
|
2864
|
-
|
|
2865
|
-
|
|
2866
|
-
|
|
2867
|
-
if (typeof exclusiveMaximum === "number" && ctx.target !== "draft-04") if (exclusiveMaximum <= maximum) delete json.maximum;
|
|
2868
|
-
else delete json.exclusiveMaximum;
|
|
2869
|
-
}
|
|
2996
|
+
const exMin = typeof exclusiveMinimum === "number" && exclusiveMinimum >= (minimum ?? Number.NEGATIVE_INFINITY);
|
|
2997
|
+
const exMax = typeof exclusiveMaximum === "number" && exclusiveMaximum <= (maximum ?? Number.POSITIVE_INFINITY);
|
|
2998
|
+
const legacy = ctx.target === "draft-04" || ctx.target === "openapi-3.0";
|
|
2999
|
+
if (exMin) {
|
|
3000
|
+
if (legacy) {
|
|
3001
|
+
json.minimum = exclusiveMinimum;
|
|
3002
|
+
json.exclusiveMinimum = true;
|
|
3003
|
+
} else json.exclusiveMinimum = exclusiveMinimum;
|
|
3004
|
+
} else if (typeof minimum === "number") json.minimum = minimum;
|
|
3005
|
+
if (exMax) {
|
|
3006
|
+
if (legacy) {
|
|
3007
|
+
json.maximum = exclusiveMaximum;
|
|
3008
|
+
json.exclusiveMaximum = true;
|
|
3009
|
+
} else json.exclusiveMaximum = exclusiveMaximum;
|
|
3010
|
+
} else if (typeof maximum === "number") json.maximum = maximum;
|
|
2870
3011
|
if (typeof multipleOf === "number") json.multipleOf = multipleOf;
|
|
2871
3012
|
};
|
|
3013
|
+
const undefinedProcessor = (_schema, ctx, _json, _params) => {
|
|
3014
|
+
if (ctx.unrepresentable === "throw") throw new Error("Undefined cannot be represented in JSON Schema");
|
|
3015
|
+
};
|
|
2872
3016
|
const neverProcessor = (_schema, _ctx, json, _params) => {
|
|
2873
3017
|
json.not = {};
|
|
2874
3018
|
};
|
|
@@ -3005,7 +3149,8 @@ const catchProcessor = (schema, ctx, json, params) => {
|
|
|
3005
3149
|
};
|
|
3006
3150
|
const pipeProcessor = (schema, ctx, _json, params) => {
|
|
3007
3151
|
const def = schema._zod.def;
|
|
3008
|
-
const
|
|
3152
|
+
const inIsTransform = def.in._zod.traits.has("$ZodTransform");
|
|
3153
|
+
const innerType = ctx.io === "input" ? inIsTransform ? def.out : def.in : def.out;
|
|
3009
3154
|
process$1(innerType, ctx, params);
|
|
3010
3155
|
const seen = ctx.seen.get(schema);
|
|
3011
3156
|
seen.ref = innerType;
|
|
@@ -3024,7 +3169,7 @@ const optionalProcessor = (schema, ctx, _json, params) => {
|
|
|
3024
3169
|
seen.ref = def.innerType;
|
|
3025
3170
|
};
|
|
3026
3171
|
//#endregion
|
|
3027
|
-
//#region ../../node_modules/.pnpm/zod@4.3
|
|
3172
|
+
//#region ../../node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/classic/iso.js
|
|
3028
3173
|
const ZodISODateTime = /*@__PURE__*/ $constructor("ZodISODateTime", (inst, def) => {
|
|
3029
3174
|
$ZodISODateTime.init(inst, def);
|
|
3030
3175
|
ZodStringFormat.init(inst, def);
|
|
@@ -3054,7 +3199,7 @@ function duration(params) {
|
|
|
3054
3199
|
return /* @__PURE__ */ _isoDuration(ZodISODuration, params);
|
|
3055
3200
|
}
|
|
3056
3201
|
//#endregion
|
|
3057
|
-
//#region ../../node_modules/.pnpm/zod@4.3
|
|
3202
|
+
//#region ../../node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/classic/errors.js
|
|
3058
3203
|
const initializer = (inst, issues) => {
|
|
3059
3204
|
$ZodError.init(inst, issues);
|
|
3060
3205
|
inst.name = "ZodError";
|
|
@@ -3074,10 +3219,9 @@ const initializer = (inst, issues) => {
|
|
|
3074
3219
|
} }
|
|
3075
3220
|
});
|
|
3076
3221
|
};
|
|
3077
|
-
$constructor("ZodError", initializer);
|
|
3078
|
-
const ZodRealError = $constructor("ZodError", initializer, { Parent: Error });
|
|
3222
|
+
const ZodRealError = /*@__PURE__*/ $constructor("ZodError", initializer, { Parent: Error });
|
|
3079
3223
|
//#endregion
|
|
3080
|
-
//#region ../../node_modules/.pnpm/zod@4.3
|
|
3224
|
+
//#region ../../node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/classic/parse.js
|
|
3081
3225
|
const parse = /* @__PURE__ */ _parse(ZodRealError);
|
|
3082
3226
|
const parseAsync = /* @__PURE__ */ _parseAsync(ZodRealError);
|
|
3083
3227
|
const safeParse = /* @__PURE__ */ _safeParse(ZodRealError);
|
|
@@ -3091,7 +3235,43 @@ const safeDecode = /* @__PURE__ */ _safeDecode(ZodRealError);
|
|
|
3091
3235
|
const safeEncodeAsync = /* @__PURE__ */ _safeEncodeAsync(ZodRealError);
|
|
3092
3236
|
const safeDecodeAsync = /* @__PURE__ */ _safeDecodeAsync(ZodRealError);
|
|
3093
3237
|
//#endregion
|
|
3094
|
-
//#region ../../node_modules/.pnpm/zod@4.3
|
|
3238
|
+
//#region ../../node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/classic/schemas.js
|
|
3239
|
+
const _installedGroups = /* @__PURE__ */ new WeakMap();
|
|
3240
|
+
function _installLazyMethods(inst, group, methods) {
|
|
3241
|
+
const proto = Object.getPrototypeOf(inst);
|
|
3242
|
+
let installed = _installedGroups.get(proto);
|
|
3243
|
+
if (!installed) {
|
|
3244
|
+
installed = /* @__PURE__ */ new Set();
|
|
3245
|
+
_installedGroups.set(proto, installed);
|
|
3246
|
+
}
|
|
3247
|
+
if (installed.has(group)) return;
|
|
3248
|
+
installed.add(group);
|
|
3249
|
+
for (const key in methods) {
|
|
3250
|
+
const fn = methods[key];
|
|
3251
|
+
Object.defineProperty(proto, key, {
|
|
3252
|
+
configurable: true,
|
|
3253
|
+
enumerable: false,
|
|
3254
|
+
get() {
|
|
3255
|
+
const bound = fn.bind(this);
|
|
3256
|
+
Object.defineProperty(this, key, {
|
|
3257
|
+
configurable: true,
|
|
3258
|
+
writable: true,
|
|
3259
|
+
enumerable: true,
|
|
3260
|
+
value: bound
|
|
3261
|
+
});
|
|
3262
|
+
return bound;
|
|
3263
|
+
},
|
|
3264
|
+
set(v) {
|
|
3265
|
+
Object.defineProperty(this, key, {
|
|
3266
|
+
configurable: true,
|
|
3267
|
+
writable: true,
|
|
3268
|
+
enumerable: true,
|
|
3269
|
+
value: v
|
|
3270
|
+
});
|
|
3271
|
+
}
|
|
3272
|
+
});
|
|
3273
|
+
}
|
|
3274
|
+
}
|
|
3095
3275
|
const ZodType = /*@__PURE__*/ $constructor("ZodType", (inst, def) => {
|
|
3096
3276
|
$ZodType.init(inst, def);
|
|
3097
3277
|
Object.assign(inst["~standard"], { jsonSchema: {
|
|
@@ -3102,20 +3282,6 @@ const ZodType = /*@__PURE__*/ $constructor("ZodType", (inst, def) => {
|
|
|
3102
3282
|
inst.def = def;
|
|
3103
3283
|
inst.type = def.type;
|
|
3104
3284
|
Object.defineProperty(inst, "_def", { value: def });
|
|
3105
|
-
inst.check = (...checks) => {
|
|
3106
|
-
return inst.clone(mergeDefs(def, { checks: [...def.checks ?? [], ...checks.map((ch) => typeof ch === "function" ? { _zod: {
|
|
3107
|
-
check: ch,
|
|
3108
|
-
def: { check: "custom" },
|
|
3109
|
-
onattach: []
|
|
3110
|
-
} } : ch)] }), { parent: true });
|
|
3111
|
-
};
|
|
3112
|
-
inst.with = inst.check;
|
|
3113
|
-
inst.clone = (def, params) => clone(inst, def, params);
|
|
3114
|
-
inst.brand = () => inst;
|
|
3115
|
-
inst.register = ((reg, meta) => {
|
|
3116
|
-
reg.add(inst, meta);
|
|
3117
|
-
return inst;
|
|
3118
|
-
});
|
|
3119
3285
|
inst.parse = (data, params) => parse(inst, data, params, { callee: inst.parse });
|
|
3120
3286
|
inst.safeParse = (data, params) => safeParse(inst, data, params);
|
|
3121
3287
|
inst.parseAsync = async (data, params) => parseAsync(inst, data, params, { callee: inst.parseAsync });
|
|
@@ -3129,43 +3295,106 @@ const ZodType = /*@__PURE__*/ $constructor("ZodType", (inst, def) => {
|
|
|
3129
3295
|
inst.safeDecode = (data, params) => safeDecode(inst, data, params);
|
|
3130
3296
|
inst.safeEncodeAsync = async (data, params) => safeEncodeAsync(inst, data, params);
|
|
3131
3297
|
inst.safeDecodeAsync = async (data, params) => safeDecodeAsync(inst, data, params);
|
|
3132
|
-
inst
|
|
3133
|
-
|
|
3134
|
-
|
|
3135
|
-
|
|
3136
|
-
|
|
3137
|
-
|
|
3138
|
-
|
|
3139
|
-
|
|
3140
|
-
|
|
3141
|
-
|
|
3142
|
-
|
|
3143
|
-
|
|
3144
|
-
|
|
3145
|
-
|
|
3146
|
-
|
|
3147
|
-
|
|
3148
|
-
|
|
3149
|
-
|
|
3150
|
-
|
|
3151
|
-
|
|
3152
|
-
|
|
3153
|
-
|
|
3298
|
+
_installLazyMethods(inst, "ZodType", {
|
|
3299
|
+
check(...chks) {
|
|
3300
|
+
const def = this.def;
|
|
3301
|
+
return this.clone(mergeDefs(def, { checks: [...def.checks ?? [], ...chks.map((ch) => typeof ch === "function" ? { _zod: {
|
|
3302
|
+
check: ch,
|
|
3303
|
+
def: { check: "custom" },
|
|
3304
|
+
onattach: []
|
|
3305
|
+
} } : ch)] }), { parent: true });
|
|
3306
|
+
},
|
|
3307
|
+
with(...chks) {
|
|
3308
|
+
return this.check(...chks);
|
|
3309
|
+
},
|
|
3310
|
+
clone(def, params) {
|
|
3311
|
+
return clone(this, def, params);
|
|
3312
|
+
},
|
|
3313
|
+
brand() {
|
|
3314
|
+
return this;
|
|
3315
|
+
},
|
|
3316
|
+
register(reg, meta) {
|
|
3317
|
+
reg.add(this, meta);
|
|
3318
|
+
return this;
|
|
3319
|
+
},
|
|
3320
|
+
refine(check, params) {
|
|
3321
|
+
return this.check(refine(check, params));
|
|
3322
|
+
},
|
|
3323
|
+
superRefine(refinement, params) {
|
|
3324
|
+
return this.check(superRefine(refinement, params));
|
|
3325
|
+
},
|
|
3326
|
+
overwrite(fn) {
|
|
3327
|
+
return this.check(/* @__PURE__ */ _overwrite(fn));
|
|
3328
|
+
},
|
|
3329
|
+
optional() {
|
|
3330
|
+
return optional(this);
|
|
3331
|
+
},
|
|
3332
|
+
exactOptional() {
|
|
3333
|
+
return exactOptional(this);
|
|
3334
|
+
},
|
|
3335
|
+
nullable() {
|
|
3336
|
+
return nullable(this);
|
|
3337
|
+
},
|
|
3338
|
+
nullish() {
|
|
3339
|
+
return optional(nullable(this));
|
|
3340
|
+
},
|
|
3341
|
+
nonoptional(params) {
|
|
3342
|
+
return nonoptional(this, params);
|
|
3343
|
+
},
|
|
3344
|
+
array() {
|
|
3345
|
+
return array(this);
|
|
3346
|
+
},
|
|
3347
|
+
or(arg) {
|
|
3348
|
+
return union([this, arg]);
|
|
3349
|
+
},
|
|
3350
|
+
and(arg) {
|
|
3351
|
+
return intersection(this, arg);
|
|
3352
|
+
},
|
|
3353
|
+
transform(tx) {
|
|
3354
|
+
return pipe(this, transform(tx));
|
|
3355
|
+
},
|
|
3356
|
+
default(d) {
|
|
3357
|
+
return _default(this, d);
|
|
3358
|
+
},
|
|
3359
|
+
prefault(d) {
|
|
3360
|
+
return prefault(this, d);
|
|
3361
|
+
},
|
|
3362
|
+
catch(params) {
|
|
3363
|
+
return _catch(this, params);
|
|
3364
|
+
},
|
|
3365
|
+
pipe(target) {
|
|
3366
|
+
return pipe(this, target);
|
|
3367
|
+
},
|
|
3368
|
+
readonly() {
|
|
3369
|
+
return readonly(this);
|
|
3370
|
+
},
|
|
3371
|
+
describe(description) {
|
|
3372
|
+
const cl = this.clone();
|
|
3373
|
+
globalRegistry.add(cl, { description });
|
|
3374
|
+
return cl;
|
|
3375
|
+
},
|
|
3376
|
+
meta(...args) {
|
|
3377
|
+
if (args.length === 0) return globalRegistry.get(this);
|
|
3378
|
+
const cl = this.clone();
|
|
3379
|
+
globalRegistry.add(cl, args[0]);
|
|
3380
|
+
return cl;
|
|
3381
|
+
},
|
|
3382
|
+
isOptional() {
|
|
3383
|
+
return this.safeParse(void 0).success;
|
|
3384
|
+
},
|
|
3385
|
+
isNullable() {
|
|
3386
|
+
return this.safeParse(null).success;
|
|
3387
|
+
},
|
|
3388
|
+
apply(fn) {
|
|
3389
|
+
return fn(this);
|
|
3390
|
+
}
|
|
3391
|
+
});
|
|
3154
3392
|
Object.defineProperty(inst, "description", {
|
|
3155
3393
|
get() {
|
|
3156
3394
|
return globalRegistry.get(inst)?.description;
|
|
3157
3395
|
},
|
|
3158
3396
|
configurable: true
|
|
3159
3397
|
});
|
|
3160
|
-
inst.meta = (...args) => {
|
|
3161
|
-
if (args.length === 0) return globalRegistry.get(inst);
|
|
3162
|
-
const cl = inst.clone();
|
|
3163
|
-
globalRegistry.add(cl, args[0]);
|
|
3164
|
-
return cl;
|
|
3165
|
-
};
|
|
3166
|
-
inst.isOptional = () => inst.safeParse(void 0).success;
|
|
3167
|
-
inst.isNullable = () => inst.safeParse(null).success;
|
|
3168
|
-
inst.apply = (fn) => fn(inst);
|
|
3169
3398
|
return inst;
|
|
3170
3399
|
});
|
|
3171
3400
|
/** @internal */
|
|
@@ -3177,21 +3406,53 @@ const _ZodString = /*@__PURE__*/ $constructor("_ZodString", (inst, def) => {
|
|
|
3177
3406
|
inst.format = bag.format ?? null;
|
|
3178
3407
|
inst.minLength = bag.minimum ?? null;
|
|
3179
3408
|
inst.maxLength = bag.maximum ?? null;
|
|
3180
|
-
|
|
3181
|
-
|
|
3182
|
-
|
|
3183
|
-
|
|
3184
|
-
|
|
3185
|
-
|
|
3186
|
-
|
|
3187
|
-
|
|
3188
|
-
|
|
3189
|
-
|
|
3190
|
-
|
|
3191
|
-
|
|
3192
|
-
|
|
3193
|
-
|
|
3194
|
-
|
|
3409
|
+
_installLazyMethods(inst, "_ZodString", {
|
|
3410
|
+
regex(...args) {
|
|
3411
|
+
return this.check(/* @__PURE__ */ _regex(...args));
|
|
3412
|
+
},
|
|
3413
|
+
includes(...args) {
|
|
3414
|
+
return this.check(/* @__PURE__ */ _includes(...args));
|
|
3415
|
+
},
|
|
3416
|
+
startsWith(...args) {
|
|
3417
|
+
return this.check(/* @__PURE__ */ _startsWith(...args));
|
|
3418
|
+
},
|
|
3419
|
+
endsWith(...args) {
|
|
3420
|
+
return this.check(/* @__PURE__ */ _endsWith(...args));
|
|
3421
|
+
},
|
|
3422
|
+
min(...args) {
|
|
3423
|
+
return this.check(/* @__PURE__ */ _minLength(...args));
|
|
3424
|
+
},
|
|
3425
|
+
max(...args) {
|
|
3426
|
+
return this.check(/* @__PURE__ */ _maxLength(...args));
|
|
3427
|
+
},
|
|
3428
|
+
length(...args) {
|
|
3429
|
+
return this.check(/* @__PURE__ */ _length(...args));
|
|
3430
|
+
},
|
|
3431
|
+
nonempty(...args) {
|
|
3432
|
+
return this.check(/* @__PURE__ */ _minLength(1, ...args));
|
|
3433
|
+
},
|
|
3434
|
+
lowercase(params) {
|
|
3435
|
+
return this.check(/* @__PURE__ */ _lowercase(params));
|
|
3436
|
+
},
|
|
3437
|
+
uppercase(params) {
|
|
3438
|
+
return this.check(/* @__PURE__ */ _uppercase(params));
|
|
3439
|
+
},
|
|
3440
|
+
trim() {
|
|
3441
|
+
return this.check(/* @__PURE__ */ _trim());
|
|
3442
|
+
},
|
|
3443
|
+
normalize(...args) {
|
|
3444
|
+
return this.check(/* @__PURE__ */ _normalize(...args));
|
|
3445
|
+
},
|
|
3446
|
+
toLowerCase() {
|
|
3447
|
+
return this.check(/* @__PURE__ */ _toLowerCase());
|
|
3448
|
+
},
|
|
3449
|
+
toUpperCase() {
|
|
3450
|
+
return this.check(/* @__PURE__ */ _toUpperCase());
|
|
3451
|
+
},
|
|
3452
|
+
slugify() {
|
|
3453
|
+
return this.check(/* @__PURE__ */ _slugify());
|
|
3454
|
+
}
|
|
3455
|
+
});
|
|
3195
3456
|
});
|
|
3196
3457
|
const ZodString = /*@__PURE__*/ $constructor("ZodString", (inst, def) => {
|
|
3197
3458
|
$ZodString.init(inst, def);
|
|
@@ -3247,6 +3508,9 @@ const ZodURL = /*@__PURE__*/ $constructor("ZodURL", (inst, def) => {
|
|
|
3247
3508
|
$ZodURL.init(inst, def);
|
|
3248
3509
|
ZodStringFormat.init(inst, def);
|
|
3249
3510
|
});
|
|
3511
|
+
function url(params) {
|
|
3512
|
+
return /* @__PURE__ */ _url(ZodURL, params);
|
|
3513
|
+
}
|
|
3250
3514
|
const ZodEmoji = /*@__PURE__*/ $constructor("ZodEmoji", (inst, def) => {
|
|
3251
3515
|
$ZodEmoji.init(inst, def);
|
|
3252
3516
|
ZodStringFormat.init(inst, def);
|
|
@@ -3255,6 +3519,11 @@ const ZodNanoID = /*@__PURE__*/ $constructor("ZodNanoID", (inst, def) => {
|
|
|
3255
3519
|
$ZodNanoID.init(inst, def);
|
|
3256
3520
|
ZodStringFormat.init(inst, def);
|
|
3257
3521
|
});
|
|
3522
|
+
/**
|
|
3523
|
+
* @deprecated CUID v1 is deprecated by its authors due to information leakage
|
|
3524
|
+
* (timestamps embedded in the id). Use {@link ZodCUID2} instead.
|
|
3525
|
+
* See https://github.com/paralleldrive/cuid.
|
|
3526
|
+
*/
|
|
3258
3527
|
const ZodCUID = /*@__PURE__*/ $constructor("ZodCUID", (inst, def) => {
|
|
3259
3528
|
$ZodCUID.init(inst, def);
|
|
3260
3529
|
ZodStringFormat.init(inst, def);
|
|
@@ -3311,21 +3580,53 @@ const ZodNumber = /*@__PURE__*/ $constructor("ZodNumber", (inst, def) => {
|
|
|
3311
3580
|
$ZodNumber.init(inst, def);
|
|
3312
3581
|
ZodType.init(inst, def);
|
|
3313
3582
|
inst._zod.processJSONSchema = (ctx, json, params) => numberProcessor(inst, ctx, json, params);
|
|
3314
|
-
inst
|
|
3315
|
-
|
|
3316
|
-
|
|
3317
|
-
|
|
3318
|
-
|
|
3319
|
-
|
|
3320
|
-
|
|
3321
|
-
|
|
3322
|
-
|
|
3323
|
-
|
|
3324
|
-
|
|
3325
|
-
|
|
3326
|
-
|
|
3327
|
-
|
|
3328
|
-
|
|
3583
|
+
_installLazyMethods(inst, "ZodNumber", {
|
|
3584
|
+
gt(value, params) {
|
|
3585
|
+
return this.check(/* @__PURE__ */ _gt(value, params));
|
|
3586
|
+
},
|
|
3587
|
+
gte(value, params) {
|
|
3588
|
+
return this.check(/* @__PURE__ */ _gte(value, params));
|
|
3589
|
+
},
|
|
3590
|
+
min(value, params) {
|
|
3591
|
+
return this.check(/* @__PURE__ */ _gte(value, params));
|
|
3592
|
+
},
|
|
3593
|
+
lt(value, params) {
|
|
3594
|
+
return this.check(/* @__PURE__ */ _lt(value, params));
|
|
3595
|
+
},
|
|
3596
|
+
lte(value, params) {
|
|
3597
|
+
return this.check(/* @__PURE__ */ _lte(value, params));
|
|
3598
|
+
},
|
|
3599
|
+
max(value, params) {
|
|
3600
|
+
return this.check(/* @__PURE__ */ _lte(value, params));
|
|
3601
|
+
},
|
|
3602
|
+
int(params) {
|
|
3603
|
+
return this.check(int(params));
|
|
3604
|
+
},
|
|
3605
|
+
safe(params) {
|
|
3606
|
+
return this.check(int(params));
|
|
3607
|
+
},
|
|
3608
|
+
positive(params) {
|
|
3609
|
+
return this.check(/* @__PURE__ */ _gt(0, params));
|
|
3610
|
+
},
|
|
3611
|
+
nonnegative(params) {
|
|
3612
|
+
return this.check(/* @__PURE__ */ _gte(0, params));
|
|
3613
|
+
},
|
|
3614
|
+
negative(params) {
|
|
3615
|
+
return this.check(/* @__PURE__ */ _lt(0, params));
|
|
3616
|
+
},
|
|
3617
|
+
nonpositive(params) {
|
|
3618
|
+
return this.check(/* @__PURE__ */ _lte(0, params));
|
|
3619
|
+
},
|
|
3620
|
+
multipleOf(value, params) {
|
|
3621
|
+
return this.check(/* @__PURE__ */ _multipleOf(value, params));
|
|
3622
|
+
},
|
|
3623
|
+
step(value, params) {
|
|
3624
|
+
return this.check(/* @__PURE__ */ _multipleOf(value, params));
|
|
3625
|
+
},
|
|
3626
|
+
finite() {
|
|
3627
|
+
return this;
|
|
3628
|
+
}
|
|
3629
|
+
});
|
|
3329
3630
|
const bag = inst._zod.bag;
|
|
3330
3631
|
inst.minValue = Math.max(bag.minimum ?? Number.NEGATIVE_INFINITY, bag.exclusiveMinimum ?? Number.NEGATIVE_INFINITY) ?? null;
|
|
3331
3632
|
inst.maxValue = Math.min(bag.maximum ?? Number.POSITIVE_INFINITY, bag.exclusiveMaximum ?? Number.POSITIVE_INFINITY) ?? null;
|
|
@@ -3343,6 +3644,14 @@ const ZodNumberFormat = /*@__PURE__*/ $constructor("ZodNumberFormat", (inst, def
|
|
|
3343
3644
|
function int(params) {
|
|
3344
3645
|
return /* @__PURE__ */ _int(ZodNumberFormat, params);
|
|
3345
3646
|
}
|
|
3647
|
+
const ZodUndefined = /*@__PURE__*/ $constructor("ZodUndefined", (inst, def) => {
|
|
3648
|
+
$ZodUndefined.init(inst, def);
|
|
3649
|
+
ZodType.init(inst, def);
|
|
3650
|
+
inst._zod.processJSONSchema = (ctx, json, params) => undefinedProcessor(inst, ctx, json, params);
|
|
3651
|
+
});
|
|
3652
|
+
function _undefined(params) {
|
|
3653
|
+
return /* @__PURE__ */ _undefined$1(ZodUndefined, params);
|
|
3654
|
+
}
|
|
3346
3655
|
const ZodUnknown = /*@__PURE__*/ $constructor("ZodUnknown", (inst, def) => {
|
|
3347
3656
|
$ZodUnknown.init(inst, def);
|
|
3348
3657
|
ZodType.init(inst, def);
|
|
@@ -3364,11 +3673,23 @@ const ZodArray = /*@__PURE__*/ $constructor("ZodArray", (inst, def) => {
|
|
|
3364
3673
|
ZodType.init(inst, def);
|
|
3365
3674
|
inst._zod.processJSONSchema = (ctx, json, params) => arrayProcessor(inst, ctx, json, params);
|
|
3366
3675
|
inst.element = def.element;
|
|
3367
|
-
inst
|
|
3368
|
-
|
|
3369
|
-
|
|
3370
|
-
|
|
3371
|
-
|
|
3676
|
+
_installLazyMethods(inst, "ZodArray", {
|
|
3677
|
+
min(n, params) {
|
|
3678
|
+
return this.check(/* @__PURE__ */ _minLength(n, params));
|
|
3679
|
+
},
|
|
3680
|
+
nonempty(params) {
|
|
3681
|
+
return this.check(/* @__PURE__ */ _minLength(1, params));
|
|
3682
|
+
},
|
|
3683
|
+
max(n, params) {
|
|
3684
|
+
return this.check(/* @__PURE__ */ _maxLength(n, params));
|
|
3685
|
+
},
|
|
3686
|
+
length(n, params) {
|
|
3687
|
+
return this.check(/* @__PURE__ */ _length(n, params));
|
|
3688
|
+
},
|
|
3689
|
+
unwrap() {
|
|
3690
|
+
return this.element;
|
|
3691
|
+
}
|
|
3692
|
+
});
|
|
3372
3693
|
});
|
|
3373
3694
|
function array(element, params) {
|
|
3374
3695
|
return /* @__PURE__ */ _array(ZodArray, element, params);
|
|
@@ -3380,38 +3701,62 @@ const ZodObject = /*@__PURE__*/ $constructor("ZodObject", (inst, def) => {
|
|
|
3380
3701
|
defineLazy(inst, "shape", () => {
|
|
3381
3702
|
return def.shape;
|
|
3382
3703
|
});
|
|
3383
|
-
inst
|
|
3384
|
-
|
|
3385
|
-
|
|
3386
|
-
|
|
3387
|
-
|
|
3388
|
-
|
|
3389
|
-
|
|
3390
|
-
|
|
3391
|
-
|
|
3392
|
-
|
|
3393
|
-
|
|
3394
|
-
|
|
3395
|
-
|
|
3396
|
-
|
|
3397
|
-
|
|
3398
|
-
|
|
3399
|
-
|
|
3400
|
-
|
|
3401
|
-
|
|
3402
|
-
|
|
3704
|
+
_installLazyMethods(inst, "ZodObject", {
|
|
3705
|
+
keyof() {
|
|
3706
|
+
return _enum(Object.keys(this._zod.def.shape));
|
|
3707
|
+
},
|
|
3708
|
+
catchall(catchall) {
|
|
3709
|
+
return this.clone({
|
|
3710
|
+
...this._zod.def,
|
|
3711
|
+
catchall
|
|
3712
|
+
});
|
|
3713
|
+
},
|
|
3714
|
+
passthrough() {
|
|
3715
|
+
return this.clone({
|
|
3716
|
+
...this._zod.def,
|
|
3717
|
+
catchall: unknown()
|
|
3718
|
+
});
|
|
3719
|
+
},
|
|
3720
|
+
loose() {
|
|
3721
|
+
return this.clone({
|
|
3722
|
+
...this._zod.def,
|
|
3723
|
+
catchall: unknown()
|
|
3724
|
+
});
|
|
3725
|
+
},
|
|
3726
|
+
strict() {
|
|
3727
|
+
return this.clone({
|
|
3728
|
+
...this._zod.def,
|
|
3729
|
+
catchall: never()
|
|
3730
|
+
});
|
|
3731
|
+
},
|
|
3732
|
+
strip() {
|
|
3733
|
+
return this.clone({
|
|
3734
|
+
...this._zod.def,
|
|
3735
|
+
catchall: void 0
|
|
3736
|
+
});
|
|
3737
|
+
},
|
|
3738
|
+
extend(incoming) {
|
|
3739
|
+
return extend(this, incoming);
|
|
3740
|
+
},
|
|
3741
|
+
safeExtend(incoming) {
|
|
3742
|
+
return safeExtend(this, incoming);
|
|
3743
|
+
},
|
|
3744
|
+
merge(other) {
|
|
3745
|
+
return merge(this, other);
|
|
3746
|
+
},
|
|
3747
|
+
pick(mask) {
|
|
3748
|
+
return pick(this, mask);
|
|
3749
|
+
},
|
|
3750
|
+
omit(mask) {
|
|
3751
|
+
return omit(this, mask);
|
|
3752
|
+
},
|
|
3753
|
+
partial(...args) {
|
|
3754
|
+
return partial(ZodOptional, this, args[0]);
|
|
3755
|
+
},
|
|
3756
|
+
required(...args) {
|
|
3757
|
+
return required(ZodNonOptional, this, args[0]);
|
|
3758
|
+
}
|
|
3403
3759
|
});
|
|
3404
|
-
inst.extend = (incoming) => {
|
|
3405
|
-
return extend(inst, incoming);
|
|
3406
|
-
};
|
|
3407
|
-
inst.safeExtend = (incoming) => {
|
|
3408
|
-
return safeExtend(inst, incoming);
|
|
3409
|
-
};
|
|
3410
|
-
inst.merge = (other) => merge(inst, other);
|
|
3411
|
-
inst.pick = (mask) => pick(inst, mask);
|
|
3412
|
-
inst.omit = (mask) => omit(inst, mask);
|
|
3413
|
-
inst.partial = (...args) => partial(ZodOptional, inst, args[0]);
|
|
3414
|
-
inst.required = (...args) => required(ZodNonOptional, inst, args[0]);
|
|
3415
3760
|
});
|
|
3416
3761
|
function object(shape, params) {
|
|
3417
3762
|
const def = {
|
|
@@ -3504,9 +3849,11 @@ const ZodTransform = /*@__PURE__*/ $constructor("ZodTransform", (inst, def) => {
|
|
|
3504
3849
|
const output = def.transform(payload.value, payload);
|
|
3505
3850
|
if (output instanceof Promise) return output.then((output) => {
|
|
3506
3851
|
payload.value = output;
|
|
3852
|
+
payload.fallback = true;
|
|
3507
3853
|
return payload;
|
|
3508
3854
|
});
|
|
3509
3855
|
payload.value = output;
|
|
3856
|
+
payload.fallback = true;
|
|
3510
3857
|
return payload;
|
|
3511
3858
|
};
|
|
3512
3859
|
});
|
|
@@ -3644,8 +3991,8 @@ const ZodCustom = /*@__PURE__*/ $constructor("ZodCustom", (inst, def) => {
|
|
|
3644
3991
|
function refine(fn, _params = {}) {
|
|
3645
3992
|
return /* @__PURE__ */ _refine(ZodCustom, fn, _params);
|
|
3646
3993
|
}
|
|
3647
|
-
function superRefine(fn) {
|
|
3648
|
-
return /* @__PURE__ */ _superRefine(fn);
|
|
3994
|
+
function superRefine(fn, params) {
|
|
3995
|
+
return /* @__PURE__ */ _superRefine(fn, params);
|
|
3649
3996
|
}
|
|
3650
3997
|
//#endregion
|
|
3651
3998
|
//#region src/errors.ts
|
|
@@ -3657,6 +4004,52 @@ function superRefine(fn) {
|
|
|
3657
4004
|
* `@alienplatform/core` so it carries the shared `AlienError` identity.
|
|
3658
4005
|
*/
|
|
3659
4006
|
/**
|
|
4007
|
+
* Error thrown when hosted command bootstrap configuration is invalid.
|
|
4008
|
+
*/
|
|
4009
|
+
const CommandBootstrapConfigInvalidError = defineError$1({
|
|
4010
|
+
code: "COMMAND_BOOTSTRAP_CONFIG_INVALID",
|
|
4011
|
+
context: object({
|
|
4012
|
+
field: string(),
|
|
4013
|
+
reason: string()
|
|
4014
|
+
}),
|
|
4015
|
+
message: ({ reason }) => `Command bootstrap configuration invalid: ${reason}`,
|
|
4016
|
+
retryable: false,
|
|
4017
|
+
internal: false,
|
|
4018
|
+
httpStatusCode: 400
|
|
4019
|
+
});
|
|
4020
|
+
/**
|
|
4021
|
+
* Error thrown when a network or transport failure prevents hosted command
|
|
4022
|
+
* bootstrap.
|
|
4023
|
+
*/
|
|
4024
|
+
const CommandBootstrapFailedError = defineError$1({
|
|
4025
|
+
code: "COMMAND_BOOTSTRAP_FAILED",
|
|
4026
|
+
context: object({
|
|
4027
|
+
deploymentId: string(),
|
|
4028
|
+
role: _enum(["sender", "receiver"]),
|
|
4029
|
+
reason: string()
|
|
4030
|
+
}),
|
|
4031
|
+
message: ({ deploymentId, role, reason }) => `Failed to bootstrap command ${role} access for deployment '${deploymentId}': ${reason}`,
|
|
4032
|
+
retryable: true,
|
|
4033
|
+
internal: false,
|
|
4034
|
+
httpStatusCode: 503
|
|
4035
|
+
});
|
|
4036
|
+
/**
|
|
4037
|
+
* Error thrown when the Alien Platform API rejects command bootstrap.
|
|
4038
|
+
*/
|
|
4039
|
+
const PlatformHttpError = defineError$1({
|
|
4040
|
+
code: "PLATFORM_HTTP_ERROR",
|
|
4041
|
+
context: object({
|
|
4042
|
+
method: string(),
|
|
4043
|
+
url: string(),
|
|
4044
|
+
status: number(),
|
|
4045
|
+
statusText: string()
|
|
4046
|
+
}),
|
|
4047
|
+
message: ({ method, url, status, statusText }) => `Alien Platform ${method} ${url} failed: ${status} ${statusText}`,
|
|
4048
|
+
retryable: false,
|
|
4049
|
+
internal: false,
|
|
4050
|
+
httpStatusCode: 500
|
|
4051
|
+
});
|
|
4052
|
+
/**
|
|
3660
4053
|
* Error thrown when command creation fails.
|
|
3661
4054
|
*/
|
|
3662
4055
|
const CommandCreationFailedError = defineError$1({
|
|
@@ -3839,33 +4232,253 @@ const MalformedResponseError = defineError$1({
|
|
|
3839
4232
|
httpStatusCode: 502
|
|
3840
4233
|
});
|
|
3841
4234
|
//#endregion
|
|
3842
|
-
//#region src/
|
|
4235
|
+
//#region src/wire.ts
|
|
3843
4236
|
/**
|
|
3844
|
-
*
|
|
3845
|
-
* expiration check, http vs local backend dispatch, and the `..` traversal
|
|
3846
|
-
* guard for local paths.
|
|
4237
|
+
* Wire-response validation.
|
|
3847
4238
|
*
|
|
3848
|
-
*
|
|
3849
|
-
*
|
|
3850
|
-
*
|
|
3851
|
-
*
|
|
3852
|
-
*
|
|
3853
|
-
* deployment, and the local backend is how the local platform delivers
|
|
3854
|
-
* bodies.
|
|
4239
|
+
* The command server's JSON responses are validated at the fetch boundary
|
|
4240
|
+
* against the Kubb-generated zod schemas in `@alienplatform/core`. A body that
|
|
4241
|
+
* doesn't match its schema becomes a typed {@link MalformedResponseError} here,
|
|
4242
|
+
* rather than a `TypeError` thrown deep in the caller when a missing field is
|
|
4243
|
+
* later dereferenced.
|
|
3855
4244
|
*/
|
|
3856
4245
|
/**
|
|
3857
|
-
*
|
|
3858
|
-
*
|
|
3859
|
-
*
|
|
4246
|
+
* Validate a decoded JSON response against `schema`, returning the typed value
|
|
4247
|
+
* or throwing a {@link MalformedResponseError} naming the request that produced
|
|
4248
|
+
* the malformed body.
|
|
3860
4249
|
*/
|
|
3861
|
-
|
|
3862
|
-
|
|
3863
|
-
|
|
3864
|
-
|
|
3865
|
-
|
|
4250
|
+
function parseWireResponse(schema, value, method, url) {
|
|
4251
|
+
const result = schema.safeParse(value);
|
|
4252
|
+
if (result.success) return result.data;
|
|
4253
|
+
throw new AlienError$1(MalformedResponseError.create({
|
|
4254
|
+
method,
|
|
4255
|
+
url,
|
|
4256
|
+
reason: result.error.message
|
|
4257
|
+
}));
|
|
3866
4258
|
}
|
|
3867
|
-
|
|
3868
|
-
|
|
4259
|
+
//#endregion
|
|
4260
|
+
//#region src/bootstrap.ts
|
|
4261
|
+
const DEFAULT_PLATFORM_URL = "https://api.alien.dev";
|
|
4262
|
+
const BOOTSTRAP_PATH = "/v1/commands/bootstrap";
|
|
4263
|
+
const BOOTSTRAP_TIMEOUT_MS = 3e4;
|
|
4264
|
+
const REFRESH_SKEW_MS = 3e4;
|
|
4265
|
+
const BootstrapConnectionSchema = object({
|
|
4266
|
+
managerUrl: url(),
|
|
4267
|
+
token: string().min(1),
|
|
4268
|
+
expiresAt: datetime({ offset: true })
|
|
4269
|
+
});
|
|
4270
|
+
const CommandTargetSchema = object({
|
|
4271
|
+
resourceId: string().min(1),
|
|
4272
|
+
resourceType: _enum(["container", "daemon"])
|
|
4273
|
+
});
|
|
4274
|
+
const SenderBootstrapResponseSchema = BootstrapConnectionSchema.extend({ target: _undefined().optional() });
|
|
4275
|
+
const ReceiverBootstrapResponseSchema = BootstrapConnectionSchema.extend({ target: CommandTargetSchema });
|
|
4276
|
+
/**
|
|
4277
|
+
* Execute an authenticated request and retry it once when the server rejects
|
|
4278
|
+
* credentials that the provider can refresh.
|
|
4279
|
+
*/
|
|
4280
|
+
async function requestWithRefreshingConnection(provider, request, signal) {
|
|
4281
|
+
let result = await request(await provider.get(signal));
|
|
4282
|
+
if (result.response.status !== 401) return result;
|
|
4283
|
+
const refreshed = await provider.refresh(signal);
|
|
4284
|
+
if (refreshed === void 0) return result;
|
|
4285
|
+
result = await request(refreshed);
|
|
4286
|
+
return result;
|
|
4287
|
+
}
|
|
4288
|
+
var FixedCommandConnectionProvider = class {
|
|
4289
|
+
connection;
|
|
4290
|
+
constructor(connection) {
|
|
4291
|
+
this.connection = connection;
|
|
4292
|
+
}
|
|
4293
|
+
get() {
|
|
4294
|
+
return Promise.resolve(this.connection);
|
|
4295
|
+
}
|
|
4296
|
+
refresh() {
|
|
4297
|
+
return Promise.resolve(void 0);
|
|
4298
|
+
}
|
|
4299
|
+
};
|
|
4300
|
+
/**
|
|
4301
|
+
* Refreshable hosted-Platform connection. Refreshes before expiration and
|
|
4302
|
+
* coalesces concurrent refreshes so one reused client does not stampede the
|
|
4303
|
+
* bootstrap endpoint.
|
|
4304
|
+
*/
|
|
4305
|
+
var HostedCommandConnectionProvider = class {
|
|
4306
|
+
request;
|
|
4307
|
+
apiKey;
|
|
4308
|
+
platformUrl;
|
|
4309
|
+
fetchImpl;
|
|
4310
|
+
current;
|
|
4311
|
+
refreshInFlight;
|
|
4312
|
+
constructor(options) {
|
|
4313
|
+
const deploymentId = requireNonEmpty(options.deploymentId, "deploymentId");
|
|
4314
|
+
this.apiKey = requireNonEmpty(options.apiKey, "apiKey");
|
|
4315
|
+
if (options.role === "sender" && options.target !== void 0) throw invalidConfig("target", "target is only valid for receiver bootstrap");
|
|
4316
|
+
this.request = options.role === "sender" ? {
|
|
4317
|
+
deploymentId,
|
|
4318
|
+
role: "sender"
|
|
4319
|
+
} : {
|
|
4320
|
+
deploymentId,
|
|
4321
|
+
role: "receiver",
|
|
4322
|
+
target: requireNonEmpty(options.target, "target")
|
|
4323
|
+
};
|
|
4324
|
+
this.platformUrl = validatePlatformUrl(options.platformUrl ?? DEFAULT_PLATFORM_URL);
|
|
4325
|
+
this.fetchImpl = options.fetch ?? globalThis.fetch;
|
|
4326
|
+
}
|
|
4327
|
+
async get(signal) {
|
|
4328
|
+
if (this.current !== void 0 && this.current.expiresAt.getTime() - Date.now() > REFRESH_SKEW_MS) return this.current;
|
|
4329
|
+
return this.refresh(signal);
|
|
4330
|
+
}
|
|
4331
|
+
async refresh(signal) {
|
|
4332
|
+
if (this.refreshInFlight !== void 0) return this.refreshInFlight;
|
|
4333
|
+
const refresh = this.bootstrap(signal);
|
|
4334
|
+
this.refreshInFlight = refresh;
|
|
4335
|
+
try {
|
|
4336
|
+
const connection = await refresh;
|
|
4337
|
+
this.current = connection;
|
|
4338
|
+
return connection;
|
|
4339
|
+
} finally {
|
|
4340
|
+
if (this.refreshInFlight === refresh) this.refreshInFlight = void 0;
|
|
4341
|
+
}
|
|
4342
|
+
}
|
|
4343
|
+
async bootstrap(signal) {
|
|
4344
|
+
const url = buildBootstrapUrl(this.platformUrl);
|
|
4345
|
+
const controller = new AbortController();
|
|
4346
|
+
const timeout = setTimeout(() => controller.abort(), BOOTSTRAP_TIMEOUT_MS);
|
|
4347
|
+
const abort = () => controller.abort(signal?.reason);
|
|
4348
|
+
if (signal?.aborted) abort();
|
|
4349
|
+
else signal?.addEventListener("abort", abort, { once: true });
|
|
4350
|
+
let response;
|
|
4351
|
+
try {
|
|
4352
|
+
response = await this.fetchImpl(url, {
|
|
4353
|
+
method: "POST",
|
|
4354
|
+
headers: {
|
|
4355
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
4356
|
+
"Content-Type": "application/json"
|
|
4357
|
+
},
|
|
4358
|
+
body: JSON.stringify(this.request),
|
|
4359
|
+
signal: controller.signal
|
|
4360
|
+
});
|
|
4361
|
+
} catch (error) {
|
|
4362
|
+
throw (await AlienError$1.from(error)).withContext(CommandBootstrapFailedError.create({
|
|
4363
|
+
deploymentId: this.request.deploymentId,
|
|
4364
|
+
role: this.request.role,
|
|
4365
|
+
reason: error instanceof Error ? error.message : String(error)
|
|
4366
|
+
}));
|
|
4367
|
+
} finally {
|
|
4368
|
+
clearTimeout(timeout);
|
|
4369
|
+
signal?.removeEventListener("abort", abort);
|
|
4370
|
+
}
|
|
4371
|
+
if (!response.ok) {
|
|
4372
|
+
const context = {
|
|
4373
|
+
method: "POST",
|
|
4374
|
+
url,
|
|
4375
|
+
status: response.status,
|
|
4376
|
+
statusText: response.statusText
|
|
4377
|
+
};
|
|
4378
|
+
const definition = PlatformHttpError.create(context);
|
|
4379
|
+
throw new AlienError$1({
|
|
4380
|
+
code: definition.metadata.code,
|
|
4381
|
+
message: definition.metadata.message(context),
|
|
4382
|
+
retryable: response.status === 408 || response.status === 429 || response.status >= 500,
|
|
4383
|
+
internal: definition.metadata.internal,
|
|
4384
|
+
httpStatusCode: definition.metadata.httpStatusCode,
|
|
4385
|
+
context
|
|
4386
|
+
});
|
|
4387
|
+
}
|
|
4388
|
+
let value;
|
|
4389
|
+
try {
|
|
4390
|
+
value = await response.json();
|
|
4391
|
+
} catch (error) {
|
|
4392
|
+
throw new AlienError$1(MalformedResponseError.create({
|
|
4393
|
+
method: "POST",
|
|
4394
|
+
url,
|
|
4395
|
+
reason: error instanceof Error ? error.message : String(error)
|
|
4396
|
+
}));
|
|
4397
|
+
}
|
|
4398
|
+
if (this.request.role === "sender") {
|
|
4399
|
+
const parsed = parseWireResponse(SenderBootstrapResponseSchema, value, "POST", url);
|
|
4400
|
+
return {
|
|
4401
|
+
role: "sender",
|
|
4402
|
+
managerUrl: parsed.managerUrl,
|
|
4403
|
+
token: parsed.token,
|
|
4404
|
+
expiresAt: new Date(parsed.expiresAt)
|
|
4405
|
+
};
|
|
4406
|
+
}
|
|
4407
|
+
const parsed = parseWireResponse(ReceiverBootstrapResponseSchema, value, "POST", url);
|
|
4408
|
+
return {
|
|
4409
|
+
role: "receiver",
|
|
4410
|
+
managerUrl: parsed.managerUrl,
|
|
4411
|
+
token: parsed.token,
|
|
4412
|
+
expiresAt: new Date(parsed.expiresAt),
|
|
4413
|
+
target: parsed.target
|
|
4414
|
+
};
|
|
4415
|
+
}
|
|
4416
|
+
};
|
|
4417
|
+
function managerCommandsUrl(managerUrl) {
|
|
4418
|
+
let url;
|
|
4419
|
+
try {
|
|
4420
|
+
url = new URL(managerUrl);
|
|
4421
|
+
} catch {
|
|
4422
|
+
throw invalidConfig("managerUrl", `managerUrl is not a valid URL: ${managerUrl}`);
|
|
4423
|
+
}
|
|
4424
|
+
if (url.protocol !== "http:" && url.protocol !== "https:") throw invalidConfig("managerUrl", "managerUrl must use HTTP or HTTPS");
|
|
4425
|
+
const basePath = url.pathname.replace(/\/+$/, "");
|
|
4426
|
+
url.pathname = `${basePath}/v1`;
|
|
4427
|
+
return url.toString();
|
|
4428
|
+
}
|
|
4429
|
+
function buildBootstrapUrl(platformUrl) {
|
|
4430
|
+
const url = new URL(platformUrl);
|
|
4431
|
+
url.pathname = `${url.pathname.replace(/\/+$/, "")}${BOOTSTRAP_PATH}`;
|
|
4432
|
+
return url.toString();
|
|
4433
|
+
}
|
|
4434
|
+
function validatePlatformUrl(value) {
|
|
4435
|
+
let url;
|
|
4436
|
+
try {
|
|
4437
|
+
url = new URL(value);
|
|
4438
|
+
} catch {
|
|
4439
|
+
throw invalidConfig("platformUrl", `platformUrl is not a valid URL: ${value}`);
|
|
4440
|
+
}
|
|
4441
|
+
if (url.protocol !== "http:" && url.protocol !== "https:") throw invalidConfig("platformUrl", "platformUrl must use HTTP or HTTPS");
|
|
4442
|
+
return value;
|
|
4443
|
+
}
|
|
4444
|
+
function requireNonEmpty(value, field) {
|
|
4445
|
+
if (value === void 0 || value.trim() === "") throw invalidConfig(field, `${field} must not be empty`);
|
|
4446
|
+
return value;
|
|
4447
|
+
}
|
|
4448
|
+
function invalidConfig(field, reason) {
|
|
4449
|
+
return new AlienError$1(CommandBootstrapConfigInvalidError.create({
|
|
4450
|
+
field,
|
|
4451
|
+
reason
|
|
4452
|
+
}));
|
|
4453
|
+
}
|
|
4454
|
+
//#endregion
|
|
4455
|
+
//#region src/presigned.ts
|
|
4456
|
+
/**
|
|
4457
|
+
* Presigned-transfer mechanics shared by the sender and the receiver:
|
|
4458
|
+
* expiration check, http vs local backend dispatch, and the `..` traversal
|
|
4459
|
+
* guard for local paths.
|
|
4460
|
+
*
|
|
4461
|
+
* Mechanics are identical everywhere; POLICY is explicit at each call site
|
|
4462
|
+
* via `allowLocal`:
|
|
4463
|
+
* - The sender ({@link ../client.js}) gates the local (dev-only) backend
|
|
4464
|
+
* behind its `allowLocalStorage` client option, default off.
|
|
4465
|
+
* - The receiver passes `allowLocal: true` — receivers run inside the
|
|
4466
|
+
* deployment, and the local backend is how the local platform delivers
|
|
4467
|
+
* bodies.
|
|
4468
|
+
*/
|
|
4469
|
+
/**
|
|
4470
|
+
* Cap on a single presigned transfer. Without it a stalled connection hangs
|
|
4471
|
+
* the receiver's poll loop (fetch has no default timeout); generous because
|
|
4472
|
+
* bodies can be multi-megabyte over slow links.
|
|
4473
|
+
*/
|
|
4474
|
+
const PRESIGNED_TIMEOUT_MS = 12e4;
|
|
4475
|
+
/** Keep the transfer cap while also respecting the caller's absolute budget. */
|
|
4476
|
+
function transferSignal(callerSignal) {
|
|
4477
|
+
const timeoutSignal = AbortSignal.timeout(PRESIGNED_TIMEOUT_MS);
|
|
4478
|
+
return callerSignal === void 0 ? timeoutSignal : AbortSignal.any([timeoutSignal, callerSignal]);
|
|
4479
|
+
}
|
|
4480
|
+
/** Remove bearer-equivalent URL credentials before reporting a failure. */
|
|
4481
|
+
function redactUrlForError(raw) {
|
|
3869
4482
|
try {
|
|
3870
4483
|
const parsed = new URL(raw);
|
|
3871
4484
|
parsed.username = "";
|
|
@@ -3951,12 +4564,13 @@ async function uploadPresigned(request, bytes, options) {
|
|
|
3951
4564
|
assertNotExpired(request, "upload");
|
|
3952
4565
|
if (request.backend.type === "http") {
|
|
3953
4566
|
const fetchImpl = options.fetchImpl ?? fetch;
|
|
4567
|
+
const body = new Uint8Array(bytes);
|
|
3954
4568
|
let response;
|
|
3955
4569
|
try {
|
|
3956
4570
|
response = await fetchImpl(request.backend.url, {
|
|
3957
4571
|
method: request.backend.method,
|
|
3958
4572
|
headers: request.backend.headers,
|
|
3959
|
-
body
|
|
4573
|
+
body,
|
|
3960
4574
|
signal: transferSignal(options.signal)
|
|
3961
4575
|
});
|
|
3962
4576
|
} catch {
|
|
@@ -3979,31 +4593,6 @@ async function uploadPresigned(request, bytes, options) {
|
|
|
3979
4593
|
await writeFile(filePath, bytes);
|
|
3980
4594
|
}
|
|
3981
4595
|
//#endregion
|
|
3982
|
-
//#region src/wire.ts
|
|
3983
|
-
/**
|
|
3984
|
-
* Wire-response validation.
|
|
3985
|
-
*
|
|
3986
|
-
* The command server's JSON responses are validated at the fetch boundary
|
|
3987
|
-
* against the Kubb-generated zod schemas in `@alienplatform/core`. A body that
|
|
3988
|
-
* doesn't match its schema becomes a typed {@link MalformedResponseError} here,
|
|
3989
|
-
* rather than a `TypeError` thrown deep in the caller when a missing field is
|
|
3990
|
-
* later dereferenced.
|
|
3991
|
-
*/
|
|
3992
|
-
/**
|
|
3993
|
-
* Validate a decoded JSON response against `schema`, returning the typed value
|
|
3994
|
-
* or throwing a {@link MalformedResponseError} naming the request that produced
|
|
3995
|
-
* the malformed body.
|
|
3996
|
-
*/
|
|
3997
|
-
function parseWireResponse(schema, value, method, url) {
|
|
3998
|
-
const result = schema.safeParse(value);
|
|
3999
|
-
if (result.success) return result.data;
|
|
4000
|
-
throw new AlienError$1(MalformedResponseError.create({
|
|
4001
|
-
method,
|
|
4002
|
-
url,
|
|
4003
|
-
reason: result.error.message
|
|
4004
|
-
}));
|
|
4005
|
-
}
|
|
4006
|
-
//#endregion
|
|
4007
4596
|
//#region src/client.ts
|
|
4008
4597
|
/**
|
|
4009
4598
|
* Command sender — invoke commands on remote Alien deployments.
|
|
@@ -4093,20 +4682,49 @@ function isTerminalState(state) {
|
|
|
4093
4682
|
/**
|
|
4094
4683
|
* Command sender for invoking deployment commands.
|
|
4095
4684
|
*/
|
|
4096
|
-
var CommandsClient = class {
|
|
4097
|
-
managerUrl;
|
|
4685
|
+
var CommandsClient = class CommandsClient {
|
|
4098
4686
|
deploymentId;
|
|
4099
|
-
token;
|
|
4100
4687
|
defaultTimeout;
|
|
4101
4688
|
allowLocalStorage;
|
|
4102
4689
|
fetchImpl;
|
|
4690
|
+
connectionProvider;
|
|
4103
4691
|
constructor(config) {
|
|
4104
|
-
this.managerUrl = config.managerUrl;
|
|
4105
4692
|
this.deploymentId = config.deploymentId;
|
|
4106
|
-
this.token = config.token;
|
|
4107
4693
|
this.defaultTimeout = config.timeoutMs ?? 6e4;
|
|
4108
4694
|
this.allowLocalStorage = config.allowLocalStorage ?? false;
|
|
4109
4695
|
this.fetchImpl = config.fetch ?? globalThis.fetch;
|
|
4696
|
+
this.connectionProvider = new FixedCommandConnectionProvider({
|
|
4697
|
+
role: "sender",
|
|
4698
|
+
managerUrl: config.managerUrl,
|
|
4699
|
+
token: config.token,
|
|
4700
|
+
expiresAt: /* @__PURE__ */ new Date(864e13)
|
|
4701
|
+
});
|
|
4702
|
+
}
|
|
4703
|
+
/**
|
|
4704
|
+
* Connect to an Alien-hosted deployment using only its ID and an Alien API
|
|
4705
|
+
* key. Alien resolves the deployment's current manager and mints a
|
|
4706
|
+
* short-lived command-only credential. Reused clients refresh that
|
|
4707
|
+
* connection before expiry and once after a manager 401.
|
|
4708
|
+
*/
|
|
4709
|
+
static async forDeployment(config) {
|
|
4710
|
+
const provider = new HostedCommandConnectionProvider({
|
|
4711
|
+
deploymentId: config.deploymentId,
|
|
4712
|
+
apiKey: config.apiKey,
|
|
4713
|
+
role: "sender",
|
|
4714
|
+
platformUrl: config.platformUrl,
|
|
4715
|
+
fetch: config.fetch
|
|
4716
|
+
});
|
|
4717
|
+
const initial = await provider.get();
|
|
4718
|
+
const client = new CommandsClient({
|
|
4719
|
+
managerUrl: initial.managerUrl,
|
|
4720
|
+
deploymentId: config.deploymentId,
|
|
4721
|
+
token: initial.token,
|
|
4722
|
+
timeoutMs: config.timeoutMs,
|
|
4723
|
+
allowLocalStorage: config.allowLocalStorage,
|
|
4724
|
+
fetch: config.fetch
|
|
4725
|
+
});
|
|
4726
|
+
client.connectionProvider = provider;
|
|
4727
|
+
return client;
|
|
4110
4728
|
}
|
|
4111
4729
|
/**
|
|
4112
4730
|
* Scope this client to one target command-capable resource: every `invoke`
|
|
@@ -4168,24 +4786,29 @@ var CommandsClient = class {
|
|
|
4168
4786
|
* `buildLeaseEndpoint`, which appends path segments while leaving the query
|
|
4169
4787
|
* untouched.
|
|
4170
4788
|
*/
|
|
4171
|
-
buildManagerUrl(path) {
|
|
4172
|
-
const url = new URL(
|
|
4789
|
+
buildManagerUrl(managerUrl, path) {
|
|
4790
|
+
const url = new URL(managerUrl);
|
|
4173
4791
|
url.pathname = `${url.pathname.replace(/\/+$/, "")}${path.startsWith("/") ? path : `/${path}`}`;
|
|
4174
4792
|
return url.toString();
|
|
4175
4793
|
}
|
|
4176
4794
|
async managerFetch(method, path, schema, options) {
|
|
4177
|
-
const url = this.buildManagerUrl(path);
|
|
4178
4795
|
try {
|
|
4179
|
-
const
|
|
4180
|
-
|
|
4181
|
-
|
|
4182
|
-
|
|
4183
|
-
|
|
4184
|
-
|
|
4185
|
-
|
|
4186
|
-
|
|
4187
|
-
|
|
4188
|
-
|
|
4796
|
+
const { response, url } = await requestWithRefreshingConnection(this.connectionProvider, async (connection) => {
|
|
4797
|
+
const url = this.buildManagerUrl(connection.managerUrl, path);
|
|
4798
|
+
const headers = { Authorization: `Bearer ${connection.token}` };
|
|
4799
|
+
const init = {
|
|
4800
|
+
method,
|
|
4801
|
+
headers
|
|
4802
|
+
};
|
|
4803
|
+
if (options.body !== void 0) {
|
|
4804
|
+
headers["Content-Type"] = "application/json";
|
|
4805
|
+
init.body = JSON.stringify(options.body);
|
|
4806
|
+
}
|
|
4807
|
+
return {
|
|
4808
|
+
response: await this.fetchImpl(url, init),
|
|
4809
|
+
url
|
|
4810
|
+
};
|
|
4811
|
+
});
|
|
4189
4812
|
if (!response.ok) {
|
|
4190
4813
|
const errorBody = await response.text().catch(() => "");
|
|
4191
4814
|
throw new AlienError$1(ManagerHttpError.create({
|
|
@@ -4297,83 +4920,13 @@ var TargetedCommands = class {
|
|
|
4297
4920
|
}
|
|
4298
4921
|
};
|
|
4299
4922
|
//#endregion
|
|
4300
|
-
//#region src/receiver.ts
|
|
4301
|
-
/**
|
|
4302
|
-
* Pull command receiver — the app-owned lease loop for Containers and Daemons.
|
|
4303
|
-
*
|
|
4304
|
-
* Behavior-identical twin of the Rust `alien_commands::Receiver`. It leases
|
|
4305
|
-
* commands addressed to its own target resource from the command server over
|
|
4306
|
-
* outbound HTTPS (no inbound connections), dispatches them to
|
|
4307
|
-
* in-process handlers, and submits responses through the envelope's
|
|
4308
|
-
* response-handling flow (inline or presigned storage upload).
|
|
4309
|
-
*
|
|
4310
|
-
* Pure `fetch`; no bindings. The receiver implements these public
|
|
4311
|
-
* command-delivery semantics:
|
|
4312
|
-
* - required identity plus token-or-token-file env, with fail-fast validation
|
|
4313
|
-
* - execution budget = `min(envelope.deadline, leaseExpiresAt − safety margin)`;
|
|
4314
|
-
* on expiry the handler's `signal` fires and a `HANDLER_TIMEOUT` is submitted
|
|
4315
|
-
* - error codes `UNKNOWN_COMMAND` / handler `error.code` (falling back to
|
|
4316
|
-
* `HANDLER_ERROR`) / `HANDLER_TIMEOUT`, with params-decode failures retaining
|
|
4317
|
-
* their decode error code
|
|
4318
|
-
* - at-least-once delivery; `ctx.attempt` starts at 1
|
|
4319
|
-
* - drain: shutdown stops polls, waits up to 30s, then aborts and releases
|
|
4320
|
-
* - lease params 5s / maxLeases 1 / leaseSeconds 60, all env-tunable
|
|
4321
|
-
* - `ctx.input` = decoded param bytes; success body = `JSON.stringify(return)`;
|
|
4322
|
-
* `ctx.deadline` = the effective budget, always present while a lease is held
|
|
4323
|
-
*
|
|
4324
|
-
* # Bootstrap
|
|
4325
|
-
*
|
|
4326
|
-
* ```typescript
|
|
4327
|
-
* import { createCommandReceiver } from "@alienplatform/commands"
|
|
4328
|
-
*
|
|
4329
|
-
* const receiver = createCommandReceiver()
|
|
4330
|
-
* receiver.command("generate-report", async params => {
|
|
4331
|
-
* return { report: params }
|
|
4332
|
-
* })
|
|
4333
|
-
* await receiver.run() // call receiver.stop() to drain and return
|
|
4334
|
-
* ```
|
|
4335
|
-
*/
|
|
4336
|
-
/**
|
|
4337
|
-
* Presigned-transfer policy for receivers: the local backend is always
|
|
4338
|
-
* allowed — receivers run inside the deployment, and the local backend is
|
|
4339
|
-
* how the local platform delivers bodies. (Senders gate it behind the
|
|
4340
|
-
* `allowLocalStorage` client option instead.)
|
|
4341
|
-
*/
|
|
4342
|
-
const RECEIVER_ALLOW_LOCAL = true;
|
|
4343
|
-
/** Error code submitted when a leased command has no registered handler. */
|
|
4344
|
-
const ERROR_CODE_UNKNOWN_COMMAND = "UNKNOWN_COMMAND";
|
|
4345
|
-
/** Error code submitted when a handler exceeds its execution budget. */
|
|
4346
|
-
const ERROR_CODE_HANDLER_TIMEOUT = "HANDLER_TIMEOUT";
|
|
4347
|
-
/** Error code submitted when a handler throws/rejects (or its response fails to serialize). */
|
|
4348
|
-
const ERROR_CODE_HANDLER_ERROR = "HANDLER_ERROR";
|
|
4349
|
-
/** Lease poll interval, in ms. */
|
|
4923
|
+
//#region src/receiver-config.ts
|
|
4350
4924
|
const DEFAULT_POLL_INTERVAL_MS = 5e3;
|
|
4351
|
-
/** Max leases requested per poll. One process executes one command at a time by default. */
|
|
4352
4925
|
const DEFAULT_MAX_LEASES = 1;
|
|
4353
|
-
/** Requested lease duration, in seconds. */
|
|
4354
4926
|
const DEFAULT_LEASE_SECONDS = 60;
|
|
4355
|
-
/** Maximum interval reached by the empty/error poll backoff. */
|
|
4356
4927
|
const DEFAULT_POLL_MAX_INTERVAL_MS = 3e4;
|
|
4357
|
-
/** Fractional randomization applied to poll sleeps. */
|
|
4358
4928
|
const DEFAULT_POLL_JITTER = .1;
|
|
4359
|
-
/** Time allowed for in-flight handlers to finish before abort + release. */
|
|
4360
4929
|
const DEFAULT_DRAIN_TIMEOUT_MS = 3e4;
|
|
4361
|
-
/**
|
|
4362
|
-
* Safety margin subtracted from a lease's expiry when computing the execution
|
|
4363
|
-
* budget, in ms. Stopping this far before the lease actually expires
|
|
4364
|
-
* guarantees the response is submitted (or the handler abandoned) while the
|
|
4365
|
-
* lease is still held, so an expired lease is never redelivered while a
|
|
4366
|
-
* duplicate is still in flight. Twin of the Rust receiver's
|
|
4367
|
-
* `LEASE_SAFETY_MARGIN` (5s).
|
|
4368
|
-
*/
|
|
4369
|
-
const LEASE_SAFETY_MARGIN_MS = 5e3;
|
|
4370
|
-
/**
|
|
4371
|
-
* Timeout on control-plane HTTP calls (lease acquire, response submit), in
|
|
4372
|
-
* ms. `fetch` has no default timeout, so a hung call would otherwise freeze
|
|
4373
|
-
* the poll loop indefinitely. Twin of the Rust receiver's 30s reqwest
|
|
4374
|
-
* timeout.
|
|
4375
|
-
*/
|
|
4376
|
-
const CONTROL_TIMEOUT_MS = 3e4;
|
|
4377
4930
|
const ENV_ALIEN_COMMANDS_URL = "ALIEN_COMMANDS_URL";
|
|
4378
4931
|
const ENV_ALIEN_COMMANDS_TOKEN = "ALIEN_COMMANDS_TOKEN";
|
|
4379
4932
|
const ENV_ALIEN_COMMANDS_TOKEN_FILE = "ALIEN_COMMANDS_TOKEN_FILE";
|
|
@@ -4386,18 +4939,26 @@ const ENV_ALIEN_COMMANDS_POLL_INTERVAL_MS = "ALIEN_COMMANDS_POLL_INTERVAL_MS";
|
|
|
4386
4939
|
const ENV_ALIEN_COMMANDS_POLL_MAX_INTERVAL_MS = "ALIEN_COMMANDS_POLL_MAX_INTERVAL_MS";
|
|
4387
4940
|
const ENV_ALIEN_COMMANDS_POLL_JITTER = "ALIEN_COMMANDS_POLL_JITTER";
|
|
4388
4941
|
const ENV_ALIEN_COMMANDS_DRAIN_TIMEOUT_MS = "ALIEN_COMMANDS_DRAIN_TIMEOUT_MS";
|
|
4389
|
-
|
|
4390
|
-
|
|
4391
|
-
|
|
4392
|
-
|
|
4393
|
-
|
|
4394
|
-
|
|
4395
|
-
|
|
4396
|
-
|
|
4397
|
-
|
|
4398
|
-
|
|
4399
|
-
|
|
4400
|
-
|
|
4942
|
+
function resolveReceiverConfig(options) {
|
|
4943
|
+
if (isHostedOptions(options)) return {
|
|
4944
|
+
connectionProvider: new HostedReceiverConnectionProvider(new HostedCommandConnectionProvider({
|
|
4945
|
+
deploymentId: options.deploymentId,
|
|
4946
|
+
apiKey: options.apiKey,
|
|
4947
|
+
role: "receiver",
|
|
4948
|
+
target: options.target,
|
|
4949
|
+
platformUrl: options.platformUrl,
|
|
4950
|
+
fetch: options.fetch
|
|
4951
|
+
}), options.deploymentId),
|
|
4952
|
+
runtimeConfig: validateRuntimeConfig({}, options)
|
|
4953
|
+
};
|
|
4954
|
+
const config = validateConfig(options.env ?? (typeof process !== "undefined" ? process.env : {}), options);
|
|
4955
|
+
return {
|
|
4956
|
+
connectionProvider: new EnvironmentReceiverConnectionProvider(config),
|
|
4957
|
+
runtimeConfig: config
|
|
4958
|
+
};
|
|
4959
|
+
}
|
|
4960
|
+
function isHostedOptions(options) {
|
|
4961
|
+
return "deploymentId" in options || "apiKey" in options || "target" in options;
|
|
4401
4962
|
}
|
|
4402
4963
|
function requireEnv(env, name) {
|
|
4403
4964
|
const value = env[name];
|
|
@@ -4450,12 +5011,6 @@ function validateConfig(env, options) {
|
|
|
4450
5011
|
envVar: ENV_ALIEN_COMMANDS_TARGET_RESOURCE_TYPE,
|
|
4451
5012
|
reason: `${ENV_ALIEN_COMMANDS_TARGET_RESOURCE_TYPE} must be 'container' or 'daemon', got '${rawType}'`
|
|
4452
5013
|
}));
|
|
4453
|
-
const pollIntervalMs = numericConfig(env, ENV_ALIEN_COMMANDS_POLL_INTERVAL_MS, options.pollIntervalMs, DEFAULT_POLL_INTERVAL_MS, (value) => Number.isInteger(value) && value > 0);
|
|
4454
|
-
const pollMaxIntervalMs = numericConfig(env, ENV_ALIEN_COMMANDS_POLL_MAX_INTERVAL_MS, options.pollMaxIntervalMs, DEFAULT_POLL_MAX_INTERVAL_MS, (value) => Number.isInteger(value) && value > 0);
|
|
4455
|
-
if (pollMaxIntervalMs < pollIntervalMs) throw new AlienError$1(CommandReceiverConfigInvalidError.create({
|
|
4456
|
-
envVar: ENV_ALIEN_COMMANDS_POLL_MAX_INTERVAL_MS,
|
|
4457
|
-
reason: `${ENV_ALIEN_COMMANDS_POLL_MAX_INTERVAL_MS} must be at least ${ENV_ALIEN_COMMANDS_POLL_INTERVAL_MS}`
|
|
4458
|
-
}));
|
|
4459
5014
|
return {
|
|
4460
5015
|
url,
|
|
4461
5016
|
token,
|
|
@@ -4463,6 +5018,17 @@ function validateConfig(env, options) {
|
|
|
4463
5018
|
deploymentId,
|
|
4464
5019
|
resourceId,
|
|
4465
5020
|
resourceType: rawType,
|
|
5021
|
+
...validateRuntimeConfig(env, options)
|
|
5022
|
+
};
|
|
5023
|
+
}
|
|
5024
|
+
function validateRuntimeConfig(env, options) {
|
|
5025
|
+
const pollIntervalMs = numericConfig(env, ENV_ALIEN_COMMANDS_POLL_INTERVAL_MS, options.pollIntervalMs, DEFAULT_POLL_INTERVAL_MS, (value) => Number.isInteger(value) && value > 0);
|
|
5026
|
+
const pollMaxIntervalMs = numericConfig(env, ENV_ALIEN_COMMANDS_POLL_MAX_INTERVAL_MS, options.pollMaxIntervalMs, DEFAULT_POLL_MAX_INTERVAL_MS, (value) => Number.isInteger(value) && value > 0);
|
|
5027
|
+
if (pollMaxIntervalMs < pollIntervalMs) throw new AlienError$1(CommandReceiverConfigInvalidError.create({
|
|
5028
|
+
envVar: ENV_ALIEN_COMMANDS_POLL_MAX_INTERVAL_MS,
|
|
5029
|
+
reason: `${ENV_ALIEN_COMMANDS_POLL_MAX_INTERVAL_MS} must be at least ${ENV_ALIEN_COMMANDS_POLL_INTERVAL_MS}`
|
|
5030
|
+
}));
|
|
5031
|
+
return {
|
|
4466
5032
|
pollIntervalMs,
|
|
4467
5033
|
pollMaxIntervalMs,
|
|
4468
5034
|
pollJitter: numericConfig(env, ENV_ALIEN_COMMANDS_POLL_JITTER, options.pollJitter, DEFAULT_POLL_JITTER, (value) => value >= 0 && value <= 1),
|
|
@@ -4479,12 +5045,16 @@ var TokenSource = class {
|
|
|
4479
5045
|
this.token = token;
|
|
4480
5046
|
this.tokenFile = tokenFile;
|
|
4481
5047
|
}
|
|
4482
|
-
get
|
|
4483
|
-
return this.token === void 0 && this.tokenFile !== void 0;
|
|
4484
|
-
}
|
|
4485
|
-
async read(forceRefresh = false) {
|
|
5048
|
+
async get() {
|
|
4486
5049
|
if (this.token !== void 0) return this.token;
|
|
4487
|
-
if (
|
|
5050
|
+
if (this.cachedFileToken !== void 0) return this.cachedFileToken;
|
|
5051
|
+
return this.readFileToken();
|
|
5052
|
+
}
|
|
5053
|
+
async refresh() {
|
|
5054
|
+
if (this.token !== void 0) return void 0;
|
|
5055
|
+
return this.readFileToken();
|
|
5056
|
+
}
|
|
5057
|
+
async readFileToken() {
|
|
4488
5058
|
const path = this.tokenFile;
|
|
4489
5059
|
let token;
|
|
4490
5060
|
try {
|
|
@@ -4503,8 +5073,130 @@ var TokenSource = class {
|
|
|
4503
5073
|
return token;
|
|
4504
5074
|
}
|
|
4505
5075
|
};
|
|
4506
|
-
var
|
|
5076
|
+
var EnvironmentReceiverConnectionProvider = class {
|
|
4507
5077
|
config;
|
|
5078
|
+
tokenSource;
|
|
5079
|
+
constructor(config) {
|
|
5080
|
+
this.config = config;
|
|
5081
|
+
this.tokenSource = new TokenSource(config.token, config.tokenFile);
|
|
5082
|
+
}
|
|
5083
|
+
async get() {
|
|
5084
|
+
return this.connection(await this.tokenSource.get());
|
|
5085
|
+
}
|
|
5086
|
+
async refresh() {
|
|
5087
|
+
const token = await this.tokenSource.refresh();
|
|
5088
|
+
return token === void 0 ? void 0 : this.connection(token);
|
|
5089
|
+
}
|
|
5090
|
+
connection(token) {
|
|
5091
|
+
return {
|
|
5092
|
+
url: this.config.url,
|
|
5093
|
+
token,
|
|
5094
|
+
deploymentId: this.config.deploymentId,
|
|
5095
|
+
resourceId: this.config.resourceId,
|
|
5096
|
+
resourceType: this.config.resourceType
|
|
5097
|
+
};
|
|
5098
|
+
}
|
|
5099
|
+
};
|
|
5100
|
+
var HostedReceiverConnectionProvider = class {
|
|
5101
|
+
provider;
|
|
5102
|
+
deploymentId;
|
|
5103
|
+
constructor(provider, deploymentId) {
|
|
5104
|
+
this.provider = provider;
|
|
5105
|
+
this.deploymentId = deploymentId;
|
|
5106
|
+
}
|
|
5107
|
+
async get(signal) {
|
|
5108
|
+
return this.receiverConnection(await this.provider.get(signal));
|
|
5109
|
+
}
|
|
5110
|
+
async refresh(signal) {
|
|
5111
|
+
const connection = await this.provider.refresh(signal);
|
|
5112
|
+
return connection === void 0 ? void 0 : this.receiverConnection(connection);
|
|
5113
|
+
}
|
|
5114
|
+
receiverConnection(connection) {
|
|
5115
|
+
if (connection.role !== "receiver") throw new AlienError$1(InvalidEnvelopeError.create({
|
|
5116
|
+
field: "role",
|
|
5117
|
+
reason: "Receiver bootstrap returned a sender connection"
|
|
5118
|
+
}));
|
|
5119
|
+
return {
|
|
5120
|
+
url: managerCommandsUrl(connection.managerUrl),
|
|
5121
|
+
token: connection.token,
|
|
5122
|
+
deploymentId: this.deploymentId,
|
|
5123
|
+
resourceId: connection.target.resourceId,
|
|
5124
|
+
resourceType: connection.target.resourceType
|
|
5125
|
+
};
|
|
5126
|
+
}
|
|
5127
|
+
};
|
|
5128
|
+
//#endregion
|
|
5129
|
+
//#region src/receiver.ts
|
|
5130
|
+
/**
|
|
5131
|
+
* Pull command receiver — the app-owned lease loop for Containers and Daemons.
|
|
5132
|
+
*
|
|
5133
|
+
* Behavior-identical twin of the Rust `alien_commands::Receiver`. It leases
|
|
5134
|
+
* commands addressed to its own target resource from the command server over
|
|
5135
|
+
* outbound HTTPS (no inbound connections), dispatches them to
|
|
5136
|
+
* in-process handlers, and submits responses through the envelope's
|
|
5137
|
+
* response-handling flow (inline or presigned storage upload).
|
|
5138
|
+
*
|
|
5139
|
+
* Pure `fetch`; no bindings. The receiver implements these public
|
|
5140
|
+
* command-delivery semantics:
|
|
5141
|
+
* - required identity plus token-or-token-file env, with fail-fast validation
|
|
5142
|
+
* - execution budget = `min(envelope.deadline, leaseExpiresAt − safety margin)`;
|
|
5143
|
+
* on expiry the handler's `signal` fires and a `HANDLER_TIMEOUT` is submitted
|
|
5144
|
+
* - error codes `UNKNOWN_COMMAND` / handler `error.code` (falling back to
|
|
5145
|
+
* `HANDLER_ERROR`) / `HANDLER_TIMEOUT`, with params-decode failures retaining
|
|
5146
|
+
* their decode error code
|
|
5147
|
+
* - at-least-once delivery; `ctx.attempt` starts at 1
|
|
5148
|
+
* - drain: shutdown stops polls, waits up to 30s, then aborts and releases
|
|
5149
|
+
* - lease params 5s / maxLeases 1 / leaseSeconds 60, all env-tunable
|
|
5150
|
+
* - `ctx.input` = decoded param bytes; success body = `JSON.stringify(return)`;
|
|
5151
|
+
* `ctx.deadline` = the effective budget, always present while a lease is held
|
|
5152
|
+
*
|
|
5153
|
+
* # Bootstrap
|
|
5154
|
+
*
|
|
5155
|
+
* ```typescript
|
|
5156
|
+
* import { createCommandReceiver } from "@alienplatform/commands"
|
|
5157
|
+
*
|
|
5158
|
+
* const receiver = createCommandReceiver()
|
|
5159
|
+
* receiver.command("generate-report", async params => {
|
|
5160
|
+
* return { report: params }
|
|
5161
|
+
* })
|
|
5162
|
+
* await receiver.run() // call receiver.stop() to drain and return
|
|
5163
|
+
* ```
|
|
5164
|
+
*/
|
|
5165
|
+
/**
|
|
5166
|
+
* Presigned-transfer policy for receivers: the local backend is always
|
|
5167
|
+
* allowed — receivers run inside the deployment, and the local backend is
|
|
5168
|
+
* how the local platform delivers bodies. (Senders gate it behind the
|
|
5169
|
+
* `allowLocalStorage` client option instead.)
|
|
5170
|
+
*/
|
|
5171
|
+
const RECEIVER_ALLOW_LOCAL = true;
|
|
5172
|
+
/** Error code submitted when a leased command has no registered handler. */
|
|
5173
|
+
const ERROR_CODE_UNKNOWN_COMMAND = "UNKNOWN_COMMAND";
|
|
5174
|
+
/** Error code submitted when a handler exceeds its execution budget. */
|
|
5175
|
+
const ERROR_CODE_HANDLER_TIMEOUT = "HANDLER_TIMEOUT";
|
|
5176
|
+
/** Error code submitted when a handler throws/rejects (or its response fails to serialize). */
|
|
5177
|
+
const ERROR_CODE_HANDLER_ERROR = "HANDLER_ERROR";
|
|
5178
|
+
/**
|
|
5179
|
+
* Safety margin subtracted from a lease's expiry when computing the execution
|
|
5180
|
+
* budget, in ms. Stopping this far before the lease actually expires
|
|
5181
|
+
* guarantees the response is submitted (or the handler abandoned) while the
|
|
5182
|
+
* lease is still held, so an expired lease is never redelivered while a
|
|
5183
|
+
* duplicate is still in flight. Twin of the Rust receiver's
|
|
5184
|
+
* `LEASE_SAFETY_MARGIN` (5s).
|
|
5185
|
+
*/
|
|
5186
|
+
const LEASE_SAFETY_MARGIN_MS = 5e3;
|
|
5187
|
+
/**
|
|
5188
|
+
* Timeout on control-plane HTTP calls (lease acquire, response submit), in
|
|
5189
|
+
* ms. `fetch` has no default timeout, so a hung call would otherwise freeze
|
|
5190
|
+
* the poll loop indefinitely. Twin of the Rust receiver's 30s reqwest
|
|
5191
|
+
* timeout.
|
|
5192
|
+
*/
|
|
5193
|
+
const CONTROL_TIMEOUT_MS = 3e4;
|
|
5194
|
+
function createCommandReceiver(options = {}) {
|
|
5195
|
+
const { connectionProvider, runtimeConfig } = resolveReceiverConfig(options);
|
|
5196
|
+
return new PullCommandReceiver(connectionProvider, runtimeConfig, options);
|
|
5197
|
+
}
|
|
5198
|
+
var PullCommandReceiver = class {
|
|
5199
|
+
connectionProvider;
|
|
4508
5200
|
fetchImpl;
|
|
4509
5201
|
pollIntervalMs;
|
|
4510
5202
|
leaseSeconds;
|
|
@@ -4512,12 +5204,11 @@ var PullCommandReceiver = class {
|
|
|
4512
5204
|
pollMaxIntervalMs;
|
|
4513
5205
|
pollJitter;
|
|
4514
5206
|
drainTimeoutMs;
|
|
4515
|
-
tokenSource;
|
|
4516
5207
|
handlers = /* @__PURE__ */ new Map();
|
|
4517
5208
|
shutdown = new AbortController();
|
|
4518
5209
|
active = /* @__PURE__ */ new Map();
|
|
4519
|
-
constructor(config, options) {
|
|
4520
|
-
this.
|
|
5210
|
+
constructor(connectionProvider, config, options) {
|
|
5211
|
+
this.connectionProvider = connectionProvider;
|
|
4521
5212
|
this.fetchImpl = options.fetch ?? globalThis.fetch;
|
|
4522
5213
|
this.pollIntervalMs = config.pollIntervalMs;
|
|
4523
5214
|
this.pollMaxIntervalMs = config.pollMaxIntervalMs;
|
|
@@ -4525,7 +5216,6 @@ var PullCommandReceiver = class {
|
|
|
4525
5216
|
this.leaseSeconds = config.leaseSeconds;
|
|
4526
5217
|
this.maxLeases = config.maxLeases;
|
|
4527
5218
|
this.drainTimeoutMs = config.drainTimeoutMs;
|
|
4528
|
-
this.tokenSource = new TokenSource(config.token, config.tokenFile);
|
|
4529
5219
|
}
|
|
4530
5220
|
command(name, schemaOrHandler, validatedHandler) {
|
|
4531
5221
|
const schema = validatedHandler === void 0 ? void 0 : schemaOrHandler;
|
|
@@ -4573,6 +5263,7 @@ var PullCommandReceiver = class {
|
|
|
4573
5263
|
nextPollMs = this.pollIntervalMs;
|
|
4574
5264
|
} else nextPollMs = this.nextBackoff(nextPollMs);
|
|
4575
5265
|
} catch (error) {
|
|
5266
|
+
if (this.shutdown.signal.aborted) break;
|
|
4576
5267
|
if (error instanceof AlienError$1 && !error.retryable) {
|
|
4577
5268
|
terminalError = error;
|
|
4578
5269
|
break;
|
|
@@ -4580,13 +5271,13 @@ var PullCommandReceiver = class {
|
|
|
4580
5271
|
logWarn("Failed to acquire command leases, will retry", error);
|
|
4581
5272
|
nextPollMs = this.nextBackoff(nextPollMs);
|
|
4582
5273
|
}
|
|
4583
|
-
for (const lease of leases) {
|
|
5274
|
+
for (const { lease, connection } of leases) {
|
|
4584
5275
|
if (this.active.has(lease.commandId)) {
|
|
4585
5276
|
await this.releaseLease(lease.leaseId);
|
|
4586
5277
|
continue;
|
|
4587
5278
|
}
|
|
4588
5279
|
const controller = new AbortController();
|
|
4589
|
-
const task = this.processLease(lease, controller).finally(() => {
|
|
5280
|
+
const task = this.processLease(lease, controller, connection).finally(() => {
|
|
4590
5281
|
if (this.active.get(lease.commandId)?.lease.leaseId === lease.leaseId) this.active.delete(lease.commandId);
|
|
4591
5282
|
});
|
|
4592
5283
|
this.active.set(lease.commandId, {
|
|
@@ -4617,25 +5308,27 @@ var PullCommandReceiver = class {
|
|
|
4617
5308
|
return Math.max(0, Math.round(ms * factor));
|
|
4618
5309
|
}
|
|
4619
5310
|
/** Build the lease request this receiver sends (pure — unit-testable). */
|
|
4620
|
-
buildLeaseRequest(maxLeases) {
|
|
5311
|
+
buildLeaseRequest(maxLeases, connection) {
|
|
4621
5312
|
return {
|
|
4622
|
-
deploymentId:
|
|
5313
|
+
deploymentId: connection.deploymentId,
|
|
4623
5314
|
target: {
|
|
4624
|
-
resourceId:
|
|
4625
|
-
resourceType:
|
|
5315
|
+
resourceId: connection.resourceId,
|
|
5316
|
+
resourceType: connection.resourceType
|
|
4626
5317
|
},
|
|
4627
5318
|
maxLeases,
|
|
4628
5319
|
leaseSeconds: this.leaseSeconds
|
|
4629
5320
|
};
|
|
4630
5321
|
}
|
|
4631
5322
|
async acquireLeases(maxLeases) {
|
|
4632
|
-
const endpoint =
|
|
4633
|
-
|
|
4634
|
-
|
|
4635
|
-
|
|
4636
|
-
|
|
4637
|
-
|
|
4638
|
-
|
|
5323
|
+
const { response, endpoint, connection } = await this.authenticatedFetch((connection) => ({
|
|
5324
|
+
endpoint: buildLeaseEndpoint(connection.url),
|
|
5325
|
+
init: {
|
|
5326
|
+
method: "POST",
|
|
5327
|
+
headers: { "Content-Type": "application/json" },
|
|
5328
|
+
body: JSON.stringify(this.buildLeaseRequest(maxLeases, connection)),
|
|
5329
|
+
signal: AbortSignal.timeout(CONTROL_TIMEOUT_MS)
|
|
5330
|
+
}
|
|
5331
|
+
}));
|
|
4639
5332
|
if (!response.ok) {
|
|
4640
5333
|
const context = {
|
|
4641
5334
|
method: "POST",
|
|
@@ -4655,21 +5348,25 @@ var PullCommandReceiver = class {
|
|
|
4655
5348
|
}
|
|
4656
5349
|
const parsed = parseWireResponse(LeaseResponseSchema, await response.json(), "POST", endpoint);
|
|
4657
5350
|
for (const lease of parsed.leases) resolveEnvelopeUrls(lease.envelope, endpoint);
|
|
4658
|
-
return parsed.leases
|
|
5351
|
+
return parsed.leases.map((lease) => ({
|
|
5352
|
+
lease,
|
|
5353
|
+
connection
|
|
5354
|
+
}));
|
|
4659
5355
|
}
|
|
4660
|
-
async authenticatedFetch(
|
|
4661
|
-
|
|
4662
|
-
const
|
|
5356
|
+
async authenticatedFetch(buildRequest) {
|
|
5357
|
+
return requestWithRefreshingConnection(this.connectionProvider, async (connection) => {
|
|
5358
|
+
const { endpoint, init } = buildRequest(connection);
|
|
4663
5359
|
const headers = new Headers(init.headers);
|
|
4664
|
-
headers.set("Authorization", `Bearer ${token}`);
|
|
4665
|
-
return
|
|
4666
|
-
|
|
4667
|
-
|
|
4668
|
-
|
|
4669
|
-
|
|
4670
|
-
|
|
4671
|
-
|
|
4672
|
-
|
|
5360
|
+
headers.set("Authorization", `Bearer ${connection.token}`);
|
|
5361
|
+
return {
|
|
5362
|
+
response: await this.fetchImpl(endpoint, {
|
|
5363
|
+
...init,
|
|
5364
|
+
headers
|
|
5365
|
+
}),
|
|
5366
|
+
endpoint,
|
|
5367
|
+
connection
|
|
5368
|
+
};
|
|
5369
|
+
}, this.shutdown.signal);
|
|
4673
5370
|
}
|
|
4674
5371
|
/**
|
|
4675
5372
|
* Process one leased command end to end: execute (or reject) it, then submit
|
|
@@ -4677,9 +5374,9 @@ var PullCommandReceiver = class {
|
|
|
4677
5374
|
* submit, and a submit failure produces no ack, so the lease expires and the
|
|
4678
5375
|
* command is redelivered.
|
|
4679
5376
|
*/
|
|
4680
|
-
async processLease(lease, controller) {
|
|
5377
|
+
async processLease(lease, controller, identity) {
|
|
4681
5378
|
const executionBudget = commandBudget(lease.envelope.deadline ?? void 0, lease.leaseExpiresAt);
|
|
4682
|
-
const response = await this.executeLease(lease, controller, executionBudget);
|
|
5379
|
+
const response = await this.executeLease(lease, controller, executionBudget, identity);
|
|
4683
5380
|
if (response === void 0) {
|
|
4684
5381
|
await this.releaseLease(lease.leaseId);
|
|
4685
5382
|
return;
|
|
@@ -4695,8 +5392,8 @@ var PullCommandReceiver = class {
|
|
|
4695
5392
|
logCommandProcessed({
|
|
4696
5393
|
commandId: lease.commandId,
|
|
4697
5394
|
leaseId: lease.leaseId,
|
|
4698
|
-
targetResourceId:
|
|
4699
|
-
targetResourceType:
|
|
5395
|
+
targetResourceId: identity.resourceId,
|
|
5396
|
+
targetResourceType: identity.resourceType,
|
|
4700
5397
|
attempt: lease.attempt,
|
|
4701
5398
|
deadline: lease.envelope.deadline ?? null,
|
|
4702
5399
|
handlerStatus,
|
|
@@ -4707,7 +5404,7 @@ var PullCommandReceiver = class {
|
|
|
4707
5404
|
* Execute a leased command under its budget and produce the response to
|
|
4708
5405
|
* submit. Never submits (keeps the "only the loop submits, once" invariant).
|
|
4709
5406
|
*/
|
|
4710
|
-
async executeLease(lease, controller, budget) {
|
|
5407
|
+
async executeLease(lease, controller, budget, identity) {
|
|
4711
5408
|
const { envelope, attempt } = lease;
|
|
4712
5409
|
const handler = this.handlers.get(envelope.command);
|
|
4713
5410
|
if (!handler) return errorResponse(ERROR_CODE_UNKNOWN_COMMAND, `No handler registered for command '${envelope.command}'`);
|
|
@@ -4725,8 +5422,8 @@ var PullCommandReceiver = class {
|
|
|
4725
5422
|
commandId: envelope.commandId,
|
|
4726
5423
|
attempt,
|
|
4727
5424
|
target: {
|
|
4728
|
-
resourceId:
|
|
4729
|
-
resourceType:
|
|
5425
|
+
resourceId: identity.resourceId,
|
|
5426
|
+
resourceType: identity.resourceType
|
|
4730
5427
|
},
|
|
4731
5428
|
traceContext: envelope.traceContext ?? void 0
|
|
4732
5429
|
};
|
|
@@ -4735,14 +5432,16 @@ var PullCommandReceiver = class {
|
|
|
4735
5432
|
return runUnderBudget(execute, budget, controller, envelope.command);
|
|
4736
5433
|
}
|
|
4737
5434
|
async releaseLease(leaseId) {
|
|
4738
|
-
const endpoint = buildReleaseEndpoint(this.config.url, leaseId);
|
|
4739
5435
|
try {
|
|
4740
|
-
const response = await this.authenticatedFetch(
|
|
4741
|
-
|
|
4742
|
-
|
|
4743
|
-
|
|
4744
|
-
|
|
4745
|
-
|
|
5436
|
+
const { response } = await this.authenticatedFetch((connection) => ({
|
|
5437
|
+
endpoint: buildReleaseEndpoint(connection.url, leaseId),
|
|
5438
|
+
init: {
|
|
5439
|
+
method: "POST",
|
|
5440
|
+
headers: { "Content-Type": "application/json" },
|
|
5441
|
+
body: JSON.stringify({ leaseId }),
|
|
5442
|
+
signal: AbortSignal.timeout(CONTROL_TIMEOUT_MS)
|
|
5443
|
+
}
|
|
5444
|
+
}));
|
|
4746
5445
|
if (response.ok || response.status === 409 || response.status === 410) return;
|
|
4747
5446
|
const body = await response.text().catch(() => "");
|
|
4748
5447
|
logWarn(`Failed to release command lease '${leaseId}' (${response.status}: ${body})`, response);
|
|
@@ -5090,4 +5789,4 @@ function safeDiagnosticToken(value) {
|
|
|
5090
5789
|
return typeof value === "string" && /^[A-Za-z0-9_.-]{1,64}$/.test(value) ? value : void 0;
|
|
5091
5790
|
}
|
|
5092
5791
|
//#endregion
|
|
5093
|
-
export { AlienError, CommandCreationFailedError, CommandExpiredError, CommandReceiverConfigInvalidError, CommandStatusFailedError, CommandTimeoutError, CommandsClient, DeploymentCommandError, InvalidEnvelopeError, MalformedResponseError, ManagerHttpError, ResponseDecodingFailedError, StorageOperationFailedError, TargetedCommands, createCommandReceiver, defineError };
|
|
5792
|
+
export { AlienError, CommandBootstrapConfigInvalidError, CommandBootstrapFailedError, CommandCreationFailedError, CommandExpiredError, CommandReceiverConfigInvalidError, CommandStatusFailedError, CommandTimeoutError, CommandsClient, DeploymentCommandError, InvalidEnvelopeError, MalformedResponseError, ManagerHttpError, PlatformHttpError, ResponseDecodingFailedError, StorageOperationFailedError, TargetedCommands, createCommandReceiver, defineError };
|