@brainervirus/workit-cursor 8.22.1 → 8.22.3
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/.cursor-plugin/plugin.json +1 -1
- package/dist/cursor-session-start.js +60 -1644
- package/dist/mcp-server.js +1 -1641
- package/dist/workit-hook.js +59 -1672
- package/package.json +3 -3
|
@@ -967,7 +967,7 @@ var cuid, cuid2, ulid, xid, ksuid, nanoid, duration, guid, uuid = (version) => {
|
|
|
967
967
|
if (!version)
|
|
968
968
|
return /^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/;
|
|
969
969
|
return new RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${version}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`);
|
|
970
|
-
}, email, _emoji = `^(?=[\\s\\S]*[\\p{Extended_Pictographic}\\p{Regional_Indicator}\\u20E3])[\\p{Extended_Pictographic}\\p{Emoji_Component}]+$`, ipv4, ipv6, cidrv4, cidrv6, base64, base64url, httpProtocol, e164,
|
|
970
|
+
}, email, _emoji = `^(?=[\\s\\S]*[\\p{Extended_Pictographic}\\p{Regional_Indicator}\\u20E3])[\\p{Extended_Pictographic}\\p{Emoji_Component}]+$`, ipv4, ipv6, cidrv4, cidrv6, base64, base64url, httpProtocol, e164, 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])))`, date, anyString, integer, number, boolean, lowercase, uppercase;
|
|
971
971
|
var init_regexes = __esm(() => {
|
|
972
972
|
cuid = /^[cC][0-9a-z]{6,}$/;
|
|
973
973
|
cuid2 = /^[0-9a-z]+$/;
|
|
@@ -986,8 +986,6 @@ var init_regexes = __esm(() => {
|
|
|
986
986
|
base64url = /^(?:[A-Za-z0-9_-]{4})*(?:[A-Za-z0-9_-]{2,3})?$/;
|
|
987
987
|
httpProtocol = /^https?$/;
|
|
988
988
|
e164 = /^\+[1-9]\d{6,14}$/;
|
|
989
|
-
creditCard = /^\d(?:[ -]?\d){11,18}$/;
|
|
990
|
-
iban = /^[A-Z]{2}(?!00|01|99)\d{2}[A-Z0-9]{11,30}$/;
|
|
991
989
|
date = /* @__PURE__ */ anchor(dateSource);
|
|
992
990
|
anyString = /^[\s\S]{0,}$/;
|
|
993
991
|
integer = /^-?\d+$/;
|
|
@@ -1472,40 +1470,6 @@ function isValidBase64URL(data) {
|
|
|
1472
1470
|
const padded = base64.padEnd(Math.ceil(base64.length / 4) * 4, "=");
|
|
1473
1471
|
return isValidBase64(padded);
|
|
1474
1472
|
}
|
|
1475
|
-
function isLuhnAlgo(digits) {
|
|
1476
|
-
let length = digits.length;
|
|
1477
|
-
let bit = 1;
|
|
1478
|
-
let sum = 0;
|
|
1479
|
-
while (length) {
|
|
1480
|
-
const value = digits.charCodeAt(--length) - 48;
|
|
1481
|
-
bit ^= 1;
|
|
1482
|
-
sum += bit ? [0, 2, 4, 6, 8, 1, 3, 5, 7, 9][value] : value;
|
|
1483
|
-
}
|
|
1484
|
-
return sum % 10 === 0;
|
|
1485
|
-
}
|
|
1486
|
-
function isValidCreditCard(input) {
|
|
1487
|
-
if (!creditCard.test(input))
|
|
1488
|
-
return false;
|
|
1489
|
-
return isLuhnAlgo(input.replace(CC_SANITIZE, ""));
|
|
1490
|
-
}
|
|
1491
|
-
function isIso7064Mod97(iban2) {
|
|
1492
|
-
let remainder = 0;
|
|
1493
|
-
const len = iban2.length;
|
|
1494
|
-
for (let i = 4;i < len; i++) {
|
|
1495
|
-
const code = iban2.charCodeAt(i);
|
|
1496
|
-
remainder = (code >= 65 ? remainder * 100 + (code - 55) : remainder * 10 + (code - 48)) % 97;
|
|
1497
|
-
}
|
|
1498
|
-
for (let i = 0;i < 4; i++) {
|
|
1499
|
-
const code = iban2.charCodeAt(i);
|
|
1500
|
-
remainder = (code >= 65 ? remainder * 100 + (code - 55) : remainder * 10 + (code - 48)) % 97;
|
|
1501
|
-
}
|
|
1502
|
-
return remainder === 1;
|
|
1503
|
-
}
|
|
1504
|
-
function isValidIBAN(input) {
|
|
1505
|
-
if (!iban.test(input))
|
|
1506
|
-
return false;
|
|
1507
|
-
return isIso7064Mod97(input);
|
|
1508
|
-
}
|
|
1509
1473
|
function isValidJWT(token, algorithm = null) {
|
|
1510
1474
|
try {
|
|
1511
1475
|
const tokensParts = token.split(".");
|
|
@@ -1831,7 +1795,7 @@ function handleRefineResult(result, payload, input, inst) {
|
|
|
1831
1795
|
payload.issues.push(issue(_iss));
|
|
1832
1796
|
}
|
|
1833
1797
|
}
|
|
1834
|
-
var $ZodType, toStandardResult = (r, ctx) => r.issues.length ? { issues: r.issues.map((iss) => finalizeIssue(iss, ctx, config())) } : { value: r.value }, $ZodString, $ZodStringFormat, $ZodGUID, $ZodUUID, $ZodEmail, URL_BAD_FORMAT = 1, URL_UNPARSEABLE = 2, asciiTabOrNewline, $ZodURL, $ZodEmoji, $ZodNanoID, $ZodCUID, $ZodCUID2, $ZodULID, $ZodXID, $ZodKSUID, $ZodISODateTime, $ZodISODate, $ZodISOTime, $ZodISODuration, $ZodIPv4, ipv6Alphabet, $ZodIPv6, $ZodCIDRv4, $ZodCIDRv6, base64Charset, $ZodBase64, base64urlCharset, $ZodBase64URL, $ZodE164,
|
|
1798
|
+
var $ZodType, toStandardResult = (r, ctx) => r.issues.length ? { issues: r.issues.map((iss) => finalizeIssue(iss, ctx, config())) } : { value: r.value }, $ZodString, $ZodStringFormat, $ZodGUID, $ZodUUID, $ZodEmail, URL_BAD_FORMAT = 1, URL_UNPARSEABLE = 2, asciiTabOrNewline, $ZodURL, $ZodEmoji, $ZodNanoID, $ZodCUID, $ZodCUID2, $ZodULID, $ZodXID, $ZodKSUID, $ZodISODateTime, $ZodISODate, $ZodISOTime, $ZodISODuration, $ZodIPv4, ipv6Alphabet, $ZodIPv6, $ZodCIDRv4, $ZodCIDRv6, base64Charset, $ZodBase64, base64urlCharset, $ZodBase64URL, $ZodE164, $ZodJWT, $ZodNumber, $ZodNumberFormat, $ZodBoolean, $ZodUnknown, $ZodNever, $ZodArray, NO_SYMBOL_KEYS, $ZodObject, $ZodObjectJIT, $ZodUnion, $ZodDiscriminatedUnion, $ZodIntersection, $ZodRecord, $ZodEnum, $ZodLiteral, $ZodTransform, $ZodOptional, $ZodExactOptional, $ZodNullable, $ZodDefault, $ZodPrefault, $ZodNonOptional, $ZodCatch, $ZodPipe, $ZodReadonly, $ZodCustom;
|
|
1835
1799
|
var init_schemas = __esm(() => {
|
|
1836
1800
|
init_checks();
|
|
1837
1801
|
init_core();
|
|
@@ -2186,7 +2150,6 @@ var init_schemas = __esm(() => {
|
|
|
2186
2150
|
def.pattern ?? (def.pattern = e164);
|
|
2187
2151
|
$ZodStringFormat.init(inst, def);
|
|
2188
2152
|
});
|
|
2189
|
-
CC_SANITIZE = /[- ]/g;
|
|
2190
2153
|
$ZodJWT = /* @__PURE__ */ $constructor("$ZodJWT", (inst, def) => {
|
|
2191
2154
|
$ZodStringFormat.init(inst, def);
|
|
2192
2155
|
inst._zod.check = (payload) => {
|
|
@@ -3164,9 +3127,6 @@ function settle(inst, answer) {
|
|
|
3164
3127
|
recursive.set(inst, answer === PROVEN);
|
|
3165
3128
|
return answer;
|
|
3166
3129
|
}
|
|
3167
|
-
function isRecursiveSchema(inst) {
|
|
3168
|
-
return isRecursive(inst, new Set, true) !== NONE;
|
|
3169
|
-
}
|
|
3170
3130
|
function bucketFor(state, inst) {
|
|
3171
3131
|
let bucket = state.buckets.get(inst);
|
|
3172
3132
|
if (!bucket) {
|
|
@@ -3476,1574 +3436,10 @@ var init_registries = __esm(() => {
|
|
|
3476
3436
|
});
|
|
3477
3437
|
|
|
3478
3438
|
// node_modules/zod/v4/core/compile.js
|
|
3479
|
-
|
|
3480
|
-
try {
|
|
3481
|
-
return compileFn(schema, { assertOnly: true });
|
|
3482
|
-
} catch {
|
|
3483
|
-
return parser;
|
|
3484
|
-
}
|
|
3485
|
-
}
|
|
3486
|
-
function compile(schema, options) {
|
|
3487
|
-
try {
|
|
3488
|
-
const parser = compileFn(schema);
|
|
3489
|
-
const clone = withParser(schema, parser);
|
|
3490
|
-
clone._zod.bag.validator = compileValidator(schema, parser);
|
|
3491
|
-
return clone;
|
|
3492
|
-
} catch (err) {
|
|
3493
|
-
if (options?.strict)
|
|
3494
|
-
throw err;
|
|
3495
|
-
return schema;
|
|
3496
|
-
}
|
|
3497
|
-
}
|
|
3498
|
-
function withParser(schema, parser) {
|
|
3499
|
-
if (isRecursiveSchema(schema)) {
|
|
3500
|
-
throw new ZodCompileUnsupportedError("a schema whose subtree contains a reference cycle");
|
|
3501
|
-
}
|
|
3502
|
-
const clone2 = clone(schema);
|
|
3503
|
-
const liveRun = schema._zod.run;
|
|
3504
|
-
const originalRun = liveRun.__originalRun ?? liveRun;
|
|
3505
|
-
const wrapped = (payload, ctx) => {
|
|
3506
|
-
if (ctx?.async || ctx?.direction === "backward" || ctx?.skipChecks || ctx?.[FALLBACK_FLAG]) {
|
|
3507
|
-
return originalRun(payload, ctx);
|
|
3508
|
-
}
|
|
3509
|
-
if (ctx && isBackEdge(ctx, payload.value)) {
|
|
3510
|
-
return originalRun(payload, ctx);
|
|
3511
|
-
}
|
|
3512
|
-
const out = parser(payload.value);
|
|
3513
|
-
if (out !== INVALID) {
|
|
3514
|
-
payload.value = out;
|
|
3515
|
-
return payload;
|
|
3516
|
-
}
|
|
3517
|
-
if (ctx)
|
|
3518
|
-
ctx[FALLBACK_FLAG] = true;
|
|
3519
|
-
return originalRun(payload, ctx);
|
|
3520
|
-
};
|
|
3521
|
-
wrapped.__originalRun = originalRun;
|
|
3522
|
-
clone2._zod.bag.fallbackRun = originalRun;
|
|
3523
|
-
clone2._zod.bag.validator = parser;
|
|
3524
|
-
clone2._zod.run = wrapped;
|
|
3525
|
-
if (!liveRun.__originalRun)
|
|
3526
|
-
installCompiledUserMethods(clone2, schema, parser);
|
|
3527
|
-
return clone2;
|
|
3528
|
-
}
|
|
3529
|
-
function installCompiledUserMethods(target, source, parser) {
|
|
3530
|
-
const targetAny = target;
|
|
3531
|
-
const sourceAny = source;
|
|
3532
|
-
if (typeof sourceAny.safeParse === "function") {
|
|
3533
|
-
const originalSafeParse = sourceAny.safeParse;
|
|
3534
|
-
targetAny.safeParse = (data, params) => {
|
|
3535
|
-
const out = parser(data);
|
|
3536
|
-
if (out !== INVALID) {
|
|
3537
|
-
return { success: true, data: out };
|
|
3538
|
-
}
|
|
3539
|
-
return originalSafeParse(data, params);
|
|
3540
|
-
};
|
|
3541
|
-
}
|
|
3542
|
-
if (typeof sourceAny.parse === "function") {
|
|
3543
|
-
const originalParse = sourceAny.parse;
|
|
3544
|
-
targetAny.parse = (data, params) => {
|
|
3545
|
-
const out = parser(data);
|
|
3546
|
-
if (out !== INVALID) {
|
|
3547
|
-
return out;
|
|
3548
|
-
}
|
|
3549
|
-
return originalParse(data, params);
|
|
3550
|
-
};
|
|
3551
|
-
}
|
|
3552
|
-
}
|
|
3553
|
-
function compileFn(schema, options) {
|
|
3554
|
-
let recursive = true;
|
|
3555
|
-
try {
|
|
3556
|
-
recursive = isRecursiveSchema(schema);
|
|
3557
|
-
} catch {}
|
|
3558
|
-
if (recursive) {
|
|
3559
|
-
throw new ZodCompileUnsupportedError("a schema whose subtree contains a reference cycle");
|
|
3560
|
-
}
|
|
3561
|
-
const ctx = {
|
|
3562
|
-
constants: new Map,
|
|
3563
|
-
constantCounter: 0,
|
|
3564
|
-
varCounter: 0,
|
|
3565
|
-
definite: true
|
|
3566
|
-
};
|
|
3567
|
-
const doc = new Doc(["input"]);
|
|
3568
|
-
const outputAccessor = generateCheck(doc, ctx, schema, "input", !options?.assertOnly);
|
|
3569
|
-
doc.write(outputAccessor === null ? `return true;` : `return ${outputAccessor};`);
|
|
3570
|
-
const constantNames = ["INVALID", ...ctx.constants.keys()];
|
|
3571
|
-
const constantValues = [INVALID, ...ctx.constants.values()];
|
|
3572
|
-
const code = doc.content.join(`
|
|
3573
|
-
`);
|
|
3574
|
-
const fullCode = options?.debug ? constantNames.length > 0 ? `// Constants: ${constantNames.join(", ")}
|
|
3575
|
-
${code}` : code : "";
|
|
3576
|
-
const F = Function;
|
|
3577
|
-
const factoryCode = `return (input) => {
|
|
3578
|
-
${code}
|
|
3579
|
-
}`;
|
|
3580
|
-
let fn;
|
|
3581
|
-
try {
|
|
3582
|
-
const factory = new F(...constantNames, factoryCode);
|
|
3583
|
-
fn = factory(...constantValues);
|
|
3584
|
-
} catch (err) {
|
|
3585
|
-
throw new ZodCompileUnsupportedError(`this schema (generated code failed to evaluate: ${err.message})`);
|
|
3586
|
-
}
|
|
3587
|
-
if (options?.debug) {
|
|
3588
|
-
fn.code = fullCode;
|
|
3589
|
-
}
|
|
3590
|
-
fn.definite = ctx.definite;
|
|
3591
|
-
return fn;
|
|
3592
|
-
}
|
|
3593
|
-
function addConstant(ctx, value) {
|
|
3594
|
-
for (const [name, v] of ctx.constants) {
|
|
3595
|
-
if (v === value)
|
|
3596
|
-
return name;
|
|
3597
|
-
}
|
|
3598
|
-
const name = `c${ctx.constantCounter++}`;
|
|
3599
|
-
ctx.constants.set(name, value);
|
|
3600
|
-
return name;
|
|
3601
|
-
}
|
|
3602
|
-
function addUserConstant(ctx, fn) {
|
|
3603
|
-
ctx.definite = false;
|
|
3604
|
-
return addConstant(ctx, fn);
|
|
3605
|
-
}
|
|
3606
|
-
function newVar(ctx) {
|
|
3607
|
-
return `v${ctx.varCounter++}`;
|
|
3608
|
-
}
|
|
3609
|
-
function runtimeRun(schema, value) {
|
|
3610
|
-
const result = schema._zod.run({ value, issues: [] }, {});
|
|
3611
|
-
if (result && typeof result.then === "function")
|
|
3612
|
-
return INVALID;
|
|
3613
|
-
const r = result;
|
|
3614
|
-
return r.issues.length === 0 ? r.value : INVALID;
|
|
3615
|
-
}
|
|
3616
|
-
function compileChild(doc, ctx, schema, accessor, needsValue = true) {
|
|
3617
|
-
const contentLen = doc.content.length;
|
|
3618
|
-
const constantCount = ctx.constants.size;
|
|
3619
|
-
const constantCounter = ctx.constantCounter;
|
|
3620
|
-
const varCounter = ctx.varCounter;
|
|
3621
|
-
try {
|
|
3622
|
-
return generateCheck(doc, ctx, schema, accessor, needsValue);
|
|
3623
|
-
} catch (err) {
|
|
3624
|
-
if (!(err instanceof ZodCompileUnsupportedError) || !err.islandable)
|
|
3625
|
-
throw err;
|
|
3626
|
-
doc.content.length = contentLen;
|
|
3627
|
-
if (ctx.constants.size > constantCount) {
|
|
3628
|
-
const trailing = Array.from(ctx.constants.keys()).slice(constantCount);
|
|
3629
|
-
for (const k of trailing)
|
|
3630
|
-
ctx.constants.delete(k);
|
|
3631
|
-
}
|
|
3632
|
-
ctx.constantCounter = constantCounter;
|
|
3633
|
-
ctx.varCounter = varCounter;
|
|
3634
|
-
return emitRuntimeIsland(doc, ctx, schema, accessor);
|
|
3635
|
-
}
|
|
3636
|
-
}
|
|
3637
|
-
function emitRuntimeIsland(doc, ctx, schema, accessor) {
|
|
3638
|
-
ctx.definite = false;
|
|
3639
|
-
const schemaConst = addConstant(ctx, schema);
|
|
3640
|
-
const runConst = addConstant(ctx, runtimeRun);
|
|
3641
|
-
const outVar = newVar(ctx);
|
|
3642
|
-
doc.write(`const ${outVar} = ${runConst}(${schemaConst}, ${accessor});`);
|
|
3643
|
-
doc.write(`if (${outVar} === INVALID) return INVALID;`);
|
|
3644
|
-
return outVar;
|
|
3645
|
-
}
|
|
3646
|
-
function generateChecks(doc, ctx, schema, accessor) {
|
|
3647
|
-
const schemaChecks = schema._zod.def.checks;
|
|
3648
|
-
if (!schemaChecks || schemaChecks.length === 0)
|
|
3649
|
-
return accessor;
|
|
3650
|
-
let currentAccessor = accessor;
|
|
3651
|
-
for (const check of schemaChecks) {
|
|
3652
|
-
const def = check._zod.def;
|
|
3653
|
-
if (def.when && !WHEN_DEFAULTED_CHECKS.has(def.check)) {
|
|
3654
|
-
throw new ZodCompileUnsupportedError(`check with a custom "when" condition`);
|
|
3655
|
-
}
|
|
3656
|
-
switch (def.check) {
|
|
3657
|
-
case "greater_than":
|
|
3658
|
-
generateGreaterThanCheck(doc, ctx, def, currentAccessor);
|
|
3659
|
-
break;
|
|
3660
|
-
case "less_than":
|
|
3661
|
-
generateLessThanCheck(doc, ctx, def, currentAccessor);
|
|
3662
|
-
break;
|
|
3663
|
-
case "multiple_of":
|
|
3664
|
-
generateMultipleOfCheck(doc, ctx, def, currentAccessor);
|
|
3665
|
-
break;
|
|
3666
|
-
case "number_format":
|
|
3667
|
-
generateNumberFormatCheck(doc, def, currentAccessor);
|
|
3668
|
-
break;
|
|
3669
|
-
case "min_length": {
|
|
3670
|
-
const min = numericOperand(def.minimum, "min_length");
|
|
3671
|
-
const len = codePointLengthVar(doc, ctx, currentAccessor, `${currentAccessor}.length >= ${min} && ${currentAccessor}.length < ${def.minimum * 2}`);
|
|
3672
|
-
doc.write(`if (${len} < ${min}) return INVALID;`);
|
|
3673
|
-
break;
|
|
3674
|
-
}
|
|
3675
|
-
case "max_length": {
|
|
3676
|
-
const max = numericOperand(def.maximum, "max_length");
|
|
3677
|
-
const len = codePointLengthVar(doc, ctx, currentAccessor, `${currentAccessor}.length > ${max}`);
|
|
3678
|
-
doc.write(`if (${len} > ${max}) return INVALID;`);
|
|
3679
|
-
break;
|
|
3680
|
-
}
|
|
3681
|
-
case "length_equals": {
|
|
3682
|
-
const exact = numericOperand(def.length, "length_equals");
|
|
3683
|
-
const len = codePointLengthVar(doc, ctx, currentAccessor, `${currentAccessor}.length >= ${exact} && ${currentAccessor}.length <= ${def.length * 2}`);
|
|
3684
|
-
doc.write(`if (${len} !== ${exact}) return INVALID;`);
|
|
3685
|
-
break;
|
|
3686
|
-
}
|
|
3687
|
-
case "min_size":
|
|
3688
|
-
doc.write(`if (${currentAccessor}.size < ${numericOperand(def.minimum, "min_size")}) return INVALID;`);
|
|
3689
|
-
break;
|
|
3690
|
-
case "max_size":
|
|
3691
|
-
doc.write(`if (${currentAccessor}.size > ${numericOperand(def.maximum, "max_size")}) return INVALID;`);
|
|
3692
|
-
break;
|
|
3693
|
-
case "size_equals":
|
|
3694
|
-
doc.write(`if (${currentAccessor}.size !== ${numericOperand(def.size, "size_equals")}) return INVALID;`);
|
|
3695
|
-
break;
|
|
3696
|
-
case "string_format":
|
|
3697
|
-
currentAccessor = generateStringFormatCheck(doc, ctx, def, currentAccessor);
|
|
3698
|
-
break;
|
|
3699
|
-
case "custom":
|
|
3700
|
-
currentAccessor = generateCustomRefineCheck(doc, ctx, check, currentAccessor);
|
|
3701
|
-
break;
|
|
3702
|
-
case "bigint_format":
|
|
3703
|
-
generateBigIntFormatCheck(doc, def, currentAccessor);
|
|
3704
|
-
break;
|
|
3705
|
-
case "mime_type":
|
|
3706
|
-
generateMimeTypeCheck(doc, ctx, def, currentAccessor);
|
|
3707
|
-
break;
|
|
3708
|
-
case "property":
|
|
3709
|
-
generatePropertyCheck(doc, ctx, def, currentAccessor);
|
|
3710
|
-
break;
|
|
3711
|
-
case "properties":
|
|
3712
|
-
generatePropertiesChecks(doc, ctx, def, currentAccessor);
|
|
3713
|
-
break;
|
|
3714
|
-
case "overwrite": {
|
|
3715
|
-
const newAccessor = newVar(ctx);
|
|
3716
|
-
generateOverwriteCheck(doc, ctx, check, currentAccessor, newAccessor);
|
|
3717
|
-
currentAccessor = newAccessor;
|
|
3718
|
-
break;
|
|
3719
|
-
}
|
|
3720
|
-
default: {
|
|
3721
|
-
throw new ZodCompileUnsupportedError(`check type ${def.check}`);
|
|
3722
|
-
}
|
|
3723
|
-
}
|
|
3724
|
-
}
|
|
3725
|
-
return currentAccessor;
|
|
3726
|
-
}
|
|
3727
|
-
function codePointLengthVar(doc, ctx, accessor, inDoubt) {
|
|
3728
|
-
const cpLen = addConstant(ctx, codePointLength);
|
|
3729
|
-
const v = newVar(ctx);
|
|
3730
|
-
doc.write(`const ${v} = typeof ${accessor} === "string" && ${inDoubt} ? ${cpLen}(${accessor}) : ${accessor}.length;`);
|
|
3731
|
-
return v;
|
|
3732
|
-
}
|
|
3733
|
-
function numericOperand(value, label) {
|
|
3734
|
-
if (typeof value !== "number" || !Number.isFinite(value)) {
|
|
3735
|
-
throw new ZodCompileUnsupportedError(`${label} bound of type ${typeof value}`);
|
|
3736
|
-
}
|
|
3737
|
-
return `${value}`;
|
|
3738
|
-
}
|
|
3739
|
-
function comparisonOperand(ctx, value) {
|
|
3740
|
-
if (typeof value === "bigint")
|
|
3741
|
-
return `${value}n`;
|
|
3742
|
-
if (typeof value === "number") {
|
|
3743
|
-
if (Number.isNaN(value))
|
|
3744
|
-
throw new ZodCompileUnsupportedError("comparison check with NaN bound");
|
|
3745
|
-
return `${value}`;
|
|
3746
|
-
}
|
|
3747
|
-
if (value instanceof Date) {
|
|
3748
|
-
if (Number.isNaN(value.getTime())) {
|
|
3749
|
-
throw new ZodCompileUnsupportedError("comparison check with Invalid Date bound");
|
|
3750
|
-
}
|
|
3751
|
-
return addConstant(ctx, value);
|
|
3752
|
-
}
|
|
3753
|
-
throw new ZodCompileUnsupportedError(`comparison check bound of type ${typeof value}`);
|
|
3754
|
-
}
|
|
3755
|
-
function generateGreaterThanCheck(doc, ctx, def, accessor) {
|
|
3756
|
-
const op = def.inclusive ? "<" : "<=";
|
|
3757
|
-
doc.write(`if (${accessor} ${op} ${comparisonOperand(ctx, def.value)}) return INVALID;`);
|
|
3758
|
-
}
|
|
3759
|
-
function generateLessThanCheck(doc, ctx, def, accessor) {
|
|
3760
|
-
const op = def.inclusive ? ">" : ">=";
|
|
3761
|
-
doc.write(`if (${accessor} ${op} ${comparisonOperand(ctx, def.value)}) return INVALID;`);
|
|
3762
|
-
}
|
|
3763
|
-
function generateMultipleOfCheck(doc, ctx, def, accessor) {
|
|
3764
|
-
if (typeof def.value === "bigint") {
|
|
3765
|
-
if (def.value === BigInt(0))
|
|
3766
|
-
throw new ZodCompileUnsupportedError("multiple_of check with a zero divisor");
|
|
3767
|
-
doc.write(`if (${accessor} % ${def.value}n !== 0n) return INVALID;`);
|
|
3768
|
-
} else {
|
|
3769
|
-
const remainder = addConstant(ctx, floatSafeRemainder);
|
|
3770
|
-
doc.write(`if (${remainder}(${accessor}, ${numericOperand(def.value, "multiple_of")}) !== 0) return INVALID;`);
|
|
3771
|
-
}
|
|
3772
|
-
}
|
|
3773
|
-
function generateNumberFormatCheck(doc, def, accessor) {
|
|
3774
|
-
const format = def.format;
|
|
3775
|
-
switch (format) {
|
|
3776
|
-
case "safeint":
|
|
3777
|
-
doc.write(`if (!Number.isSafeInteger(${accessor})) return INVALID;`);
|
|
3778
|
-
break;
|
|
3779
|
-
case "int32":
|
|
3780
|
-
doc.write(`if (!Number.isInteger(${accessor}) || ${accessor} < -2147483648 || ${accessor} > 2147483647) return INVALID;`);
|
|
3781
|
-
break;
|
|
3782
|
-
case "uint32":
|
|
3783
|
-
doc.write(`if (!Number.isInteger(${accessor}) || ${accessor} < 0 || ${accessor} > 4294967295) return INVALID;`);
|
|
3784
|
-
break;
|
|
3785
|
-
case "float32":
|
|
3786
|
-
doc.write(`if (!Number.isFinite(${accessor}) || ${accessor} < -3.4028234663852886e38 || ${accessor} > 3.4028234663852886e38) return INVALID;`);
|
|
3787
|
-
break;
|
|
3788
|
-
case "float64":
|
|
3789
|
-
doc.write(`if (!Number.isFinite(${accessor})) return INVALID;`);
|
|
3790
|
-
break;
|
|
3791
|
-
default: {
|
|
3792
|
-
throw new ZodCompileUnsupportedError(`number format ${format}`);
|
|
3793
|
-
}
|
|
3794
|
-
}
|
|
3795
|
-
}
|
|
3796
|
-
function generateBigIntFormatCheck(doc, def, accessor) {
|
|
3797
|
-
const format = def.format;
|
|
3798
|
-
if (!format)
|
|
3799
|
-
return;
|
|
3800
|
-
switch (format) {
|
|
3801
|
-
case "int64":
|
|
3802
|
-
doc.write(`if (${accessor} < -9223372036854775808n || ${accessor} > 9223372036854775807n) return INVALID;`);
|
|
3803
|
-
break;
|
|
3804
|
-
case "uint64":
|
|
3805
|
-
doc.write(`if (${accessor} < 0n || ${accessor} > 18446744073709551615n) return INVALID;`);
|
|
3806
|
-
break;
|
|
3807
|
-
default: {
|
|
3808
|
-
throw new ZodCompileUnsupportedError(`bigint format ${format}`);
|
|
3809
|
-
}
|
|
3810
|
-
}
|
|
3811
|
-
}
|
|
3812
|
-
function generateMimeTypeCheck(doc, ctx, def, accessor) {
|
|
3813
|
-
const mimeTypes = def.mime;
|
|
3814
|
-
if (mimeTypes && mimeTypes.length > 0) {
|
|
3815
|
-
const mimeSet = addConstant(ctx, new Set(mimeTypes));
|
|
3816
|
-
doc.write(`if (!${mimeSet}.has(${accessor}.type)) return INVALID;`);
|
|
3817
|
-
}
|
|
3818
|
-
}
|
|
3819
|
-
function generatePropertiesChecks(doc, ctx, def, accessor) {
|
|
3820
|
-
if (def.when) {
|
|
3821
|
-
throw new ZodCompileUnsupportedError(`check with a custom "when" condition`);
|
|
3822
|
-
}
|
|
3823
|
-
doc.write(`if (${accessor} == null) return INVALID;`);
|
|
3824
|
-
const shape = def.shape;
|
|
3825
|
-
for (const key of Reflect.ownKeys(shape)) {
|
|
3826
|
-
const keyExpr = typeof key === "symbol" ? addConstant(ctx, key) : esc(key);
|
|
3827
|
-
const inputVar = newVar(ctx);
|
|
3828
|
-
doc.write(`const ${inputVar} = ${accessor}[${keyExpr}];`);
|
|
3829
|
-
compileChild(doc, ctx, shape[key], inputVar, false);
|
|
3830
|
-
}
|
|
3831
|
-
}
|
|
3832
|
-
function generatePropertyCheck(doc, ctx, def, accessor) {
|
|
3833
|
-
const propAccessor = `${accessor}[${JSON.stringify(def.property)}]`;
|
|
3834
|
-
generateCheck(doc, ctx, def.schema, propAccessor);
|
|
3835
|
-
}
|
|
3836
|
-
function generateOverwriteCheck(doc, ctx, check, currentAccessor, newAccessor) {
|
|
3837
|
-
const tx = check._zod.def.tx;
|
|
3838
|
-
if (!tx) {
|
|
3839
|
-
throw new ZodCompileUnsupportedError("overwrite check without a transform function");
|
|
3840
|
-
}
|
|
3841
|
-
if (isAsyncFunction(tx)) {
|
|
3842
|
-
throw new ZodCompileAsyncError("z.compile: async overwrite transforms are not supported");
|
|
3843
|
-
}
|
|
3844
|
-
const txConst = addConstant(ctx, tx);
|
|
3845
|
-
doc.write(`const ${newAccessor} = ${txConst}(${currentAccessor});`);
|
|
3846
|
-
}
|
|
3847
|
-
function throwAsync() {
|
|
3848
|
-
throw new $ZodAsyncError;
|
|
3849
|
-
}
|
|
3850
|
-
function pushIssue(issue) {
|
|
3851
|
-
this.issues.push(issue);
|
|
3852
|
-
}
|
|
3853
|
-
function generateCustomRefineCheck(doc, ctx, check, accessor) {
|
|
3854
|
-
const def = check._zod.def;
|
|
3855
|
-
if (def.fn) {
|
|
3856
|
-
if (isAsyncFunction(def.fn)) {
|
|
3857
|
-
throw new ZodCompileAsyncError("z.compile: async .refine() predicates are not supported");
|
|
3858
|
-
}
|
|
3859
|
-
const fnConst = addUserConstant(ctx, def.fn);
|
|
3860
|
-
const throwAsyncConst = addConstant(ctx, throwAsync);
|
|
3861
|
-
const resVar = newVar(ctx);
|
|
3862
|
-
doc.write(`const ${resVar} = ${fnConst}(${accessor});`);
|
|
3863
|
-
doc.write(`if (${resVar} instanceof Promise) ${throwAsyncConst}();`);
|
|
3864
|
-
doc.write(`if (!${resVar}) return INVALID;`);
|
|
3865
|
-
return accessor;
|
|
3866
|
-
}
|
|
3867
|
-
if (check._zod.check) {
|
|
3868
|
-
if (isAsyncFunction(check._zod.check)) {
|
|
3869
|
-
throw new ZodCompileAsyncError("z.compile: async .superRefine() / check functions are not supported");
|
|
3870
|
-
}
|
|
3871
|
-
const checkFn = check._zod.check;
|
|
3872
|
-
const helperFn = (value) => {
|
|
3873
|
-
const fakePayload = { value, issues: [], addIssue: pushIssue };
|
|
3874
|
-
const result = checkFn(fakePayload);
|
|
3875
|
-
if (result instanceof Promise)
|
|
3876
|
-
throwAsync();
|
|
3877
|
-
return fakePayload.issues.length === 0 ? fakePayload.value : INVALID;
|
|
3878
|
-
};
|
|
3879
|
-
const helperConst = addUserConstant(ctx, helperFn);
|
|
3880
|
-
const outVar = newVar(ctx);
|
|
3881
|
-
doc.write(`const ${outVar} = ${helperConst}(${accessor});`);
|
|
3882
|
-
doc.write(`if (${outVar} === INVALID) return INVALID;`);
|
|
3883
|
-
return outVar;
|
|
3884
|
-
}
|
|
3885
|
-
throw new ZodCompileUnsupportedError("custom check without a predicate or check function");
|
|
3886
|
-
}
|
|
3887
|
-
function generateStringFormatCheck(doc, ctx, def, accessor, needsValue = true) {
|
|
3888
|
-
const fmt = def.format;
|
|
3889
|
-
if (fmt === "base64") {
|
|
3890
|
-
const validator = addConstant(ctx, isValidBase64);
|
|
3891
|
-
doc.write(`if (!${validator}(${accessor})) return INVALID;`);
|
|
3892
|
-
return accessor;
|
|
3893
|
-
}
|
|
3894
|
-
if (fmt === "base64url") {
|
|
3895
|
-
const validator = addConstant(ctx, isValidBase64URL);
|
|
3896
|
-
doc.write(`if (!${validator}(${accessor})) return INVALID;`);
|
|
3897
|
-
return accessor;
|
|
3898
|
-
}
|
|
3899
|
-
if (fmt === "jwt") {
|
|
3900
|
-
const validator = addConstant(ctx, isValidJWT);
|
|
3901
|
-
const alg = addConstant(ctx, def.alg ?? null);
|
|
3902
|
-
doc.write(`if (!${validator}(${accessor}, ${alg})) return INVALID;`);
|
|
3903
|
-
return accessor;
|
|
3904
|
-
}
|
|
3905
|
-
if (fmt === "ipv6") {
|
|
3906
|
-
const validator = addConstant(ctx, isValidIPv6);
|
|
3907
|
-
doc.write(`if (!${validator}(${accessor})) return INVALID;`);
|
|
3908
|
-
return accessor;
|
|
3909
|
-
}
|
|
3910
|
-
if (fmt === "cidrv6") {
|
|
3911
|
-
const validator = addConstant(ctx, isValidCIDRv6);
|
|
3912
|
-
doc.write(`if (!${validator}(${accessor})) return INVALID;`);
|
|
3913
|
-
return accessor;
|
|
3914
|
-
}
|
|
3915
|
-
if (fmt === "credit_card") {
|
|
3916
|
-
const validator = addConstant(ctx, isValidCreditCard);
|
|
3917
|
-
doc.write(`if (!${validator}(${accessor})) return INVALID;`);
|
|
3918
|
-
return accessor;
|
|
3919
|
-
}
|
|
3920
|
-
if (fmt === "iban") {
|
|
3921
|
-
const validator = addConstant(ctx, isValidIBAN);
|
|
3922
|
-
doc.write(`if (!${validator}(${accessor})) return INVALID;`);
|
|
3923
|
-
return accessor;
|
|
3924
|
-
}
|
|
3925
|
-
const formatDef = def;
|
|
3926
|
-
if (fmt === "url" || fmt === "httpurl" || formatDef.normalize || formatDef.hostname !== undefined || formatDef.protocol !== undefined) {
|
|
3927
|
-
const parseConst = addConstant(ctx, validateURL);
|
|
3928
|
-
const defConst = addConstant(ctx, def);
|
|
3929
|
-
const trimVar = newVar(ctx);
|
|
3930
|
-
const urlVar = newVar(ctx);
|
|
3931
|
-
doc.write(`const ${trimVar} = ${accessor}.trim();`);
|
|
3932
|
-
doc.write(`const ${urlVar} = ${parseConst}(${trimVar}, ${defConst});`);
|
|
3933
|
-
doc.write(`if (typeof ${urlVar} === "number") return INVALID;`);
|
|
3934
|
-
if (formatDef.hostname !== undefined) {
|
|
3935
|
-
const hostnameConst = addConstant(ctx, urlHostnameOk);
|
|
3936
|
-
doc.write(`if (!${hostnameConst}(${urlVar}, ${defConst}.hostname)) return INVALID;`);
|
|
3937
|
-
}
|
|
3938
|
-
if (formatDef.protocol !== undefined) {
|
|
3939
|
-
const protocolConst = addConstant(ctx, urlProtocolOk);
|
|
3940
|
-
doc.write(`if (!${protocolConst}(${urlVar}, ${defConst}.protocol)) return INVALID;`);
|
|
3941
|
-
}
|
|
3942
|
-
if (!needsValue)
|
|
3943
|
-
return null;
|
|
3944
|
-
const outputVar = newVar(ctx);
|
|
3945
|
-
const outputExpr = formatDef.normalize ? `${urlVar}.href` : `${addConstant(ctx, stripTabAndNewline)}(${trimVar})`;
|
|
3946
|
-
doc.write(`const ${outputVar} = ${outputExpr};`);
|
|
3947
|
-
return outputVar;
|
|
3948
|
-
}
|
|
3949
|
-
const customFn = def.fn;
|
|
3950
|
-
if (customFn) {
|
|
3951
|
-
if (isAsyncFunction(customFn))
|
|
3952
|
-
throw new ZodCompileUnsupportedError(`async string format ${fmt}`);
|
|
3953
|
-
const fnConst = addConstant(ctx, customFn);
|
|
3954
|
-
doc.write(`if (!${fnConst}(${accessor})) return INVALID;`);
|
|
3955
|
-
return accessor;
|
|
3956
|
-
}
|
|
3957
|
-
if (PATTERN_IS_COMPLETE.has(fmt) && def.pattern) {
|
|
3958
|
-
const patternConst = addConstant(ctx, def.pattern);
|
|
3959
|
-
doc.write(`${patternConst}.lastIndex = 0;`);
|
|
3960
|
-
doc.write(`if (!${patternConst}.test(${accessor})) return INVALID;`);
|
|
3961
|
-
return accessor;
|
|
3962
|
-
}
|
|
3963
|
-
const format = def.format;
|
|
3964
|
-
switch (format) {
|
|
3965
|
-
case "regex":
|
|
3966
|
-
throw new ZodCompileUnsupportedError("regex format without a pattern");
|
|
3967
|
-
case "lowercase":
|
|
3968
|
-
doc.write(`if (${accessor} !== ${accessor}.toLowerCase()) return INVALID;`);
|
|
3969
|
-
break;
|
|
3970
|
-
case "uppercase":
|
|
3971
|
-
doc.write(`if (${accessor} !== ${accessor}.toUpperCase()) return INVALID;`);
|
|
3972
|
-
break;
|
|
3973
|
-
case "includes":
|
|
3974
|
-
doc.write(`if (!${accessor}.includes(${esc(def.includes)})) return INVALID;`);
|
|
3975
|
-
break;
|
|
3976
|
-
case "starts_with": {
|
|
3977
|
-
const prefix = def.prefix;
|
|
3978
|
-
doc.write(`if (${accessor}.slice(0, ${prefix.length}) !== ${esc(prefix)}) return INVALID;`);
|
|
3979
|
-
break;
|
|
3980
|
-
}
|
|
3981
|
-
case "ends_with": {
|
|
3982
|
-
const suffix = def.suffix;
|
|
3983
|
-
doc.write(`if (${accessor}.slice(-${suffix.length}) !== ${esc(suffix)}) return INVALID;`);
|
|
3984
|
-
break;
|
|
3985
|
-
}
|
|
3986
|
-
default: {
|
|
3987
|
-
throw new ZodCompileUnsupportedError(`string format ${format}`);
|
|
3988
|
-
}
|
|
3989
|
-
}
|
|
3990
|
-
return accessor;
|
|
3991
|
-
}
|
|
3992
|
-
function generateCheck(doc, ctx, schema, accessor, needsValue = true) {
|
|
3993
|
-
const def = schema._zod.def;
|
|
3994
|
-
const type = def.type;
|
|
3995
|
-
if (def.coerce) {
|
|
3996
|
-
throw new ZodCompileUnsupportedError(`coercion (z.coerce.${type}())`);
|
|
3997
|
-
}
|
|
3998
|
-
const buildsValue = needsValue || !!def.checks?.length;
|
|
3999
|
-
let typeAccessor;
|
|
4000
|
-
switch (type) {
|
|
4001
|
-
case "string":
|
|
4002
|
-
typeAccessor = generateStringCheck(doc, ctx, schema, accessor, buildsValue);
|
|
4003
|
-
break;
|
|
4004
|
-
case "number":
|
|
4005
|
-
typeAccessor = generateNumberCheck(doc, schema, accessor);
|
|
4006
|
-
break;
|
|
4007
|
-
case "boolean":
|
|
4008
|
-
typeAccessor = generateBooleanCheck(doc, accessor);
|
|
4009
|
-
break;
|
|
4010
|
-
case "bigint":
|
|
4011
|
-
typeAccessor = generateBigIntCheck(doc, schema, accessor);
|
|
4012
|
-
break;
|
|
4013
|
-
case "symbol":
|
|
4014
|
-
typeAccessor = generateSymbolCheck(doc, accessor);
|
|
4015
|
-
break;
|
|
4016
|
-
case "undefined":
|
|
4017
|
-
typeAccessor = generateUndefinedCheck(doc, accessor);
|
|
4018
|
-
break;
|
|
4019
|
-
case "null":
|
|
4020
|
-
typeAccessor = generateNullCheck(doc, accessor);
|
|
4021
|
-
break;
|
|
4022
|
-
case "any":
|
|
4023
|
-
case "unknown":
|
|
4024
|
-
typeAccessor = accessor;
|
|
4025
|
-
break;
|
|
4026
|
-
case "never":
|
|
4027
|
-
doc.write("return INVALID;");
|
|
4028
|
-
typeAccessor = accessor;
|
|
4029
|
-
break;
|
|
4030
|
-
case "void":
|
|
4031
|
-
typeAccessor = generateVoidCheck(doc, accessor);
|
|
4032
|
-
break;
|
|
4033
|
-
case "nan":
|
|
4034
|
-
typeAccessor = generateNaNCheck(doc, accessor);
|
|
4035
|
-
break;
|
|
4036
|
-
case "date":
|
|
4037
|
-
typeAccessor = generateDateCheck(doc, accessor);
|
|
4038
|
-
break;
|
|
4039
|
-
case "object":
|
|
4040
|
-
typeAccessor = generateObjectCheck(doc, ctx, schema, accessor, buildsValue);
|
|
4041
|
-
break;
|
|
4042
|
-
case "optional":
|
|
4043
|
-
typeAccessor = generateOptionalCheck(doc, ctx, schema, accessor, buildsValue);
|
|
4044
|
-
break;
|
|
4045
|
-
case "nullable":
|
|
4046
|
-
typeAccessor = generateNullableCheck(doc, ctx, schema, accessor, buildsValue);
|
|
4047
|
-
break;
|
|
4048
|
-
case "array":
|
|
4049
|
-
typeAccessor = generateArrayCheck(doc, ctx, schema, accessor, buildsValue);
|
|
4050
|
-
break;
|
|
4051
|
-
case "literal":
|
|
4052
|
-
typeAccessor = generateLiteralCheck(doc, ctx, schema, accessor);
|
|
4053
|
-
break;
|
|
4054
|
-
case "enum":
|
|
4055
|
-
typeAccessor = generateEnumCheck(doc, ctx, schema, accessor);
|
|
4056
|
-
break;
|
|
4057
|
-
case "readonly": {
|
|
4058
|
-
const innerOut = generateWrapperCheck(doc, ctx, schema, accessor);
|
|
4059
|
-
const frozenVar = newVar(ctx);
|
|
4060
|
-
doc.write(`const ${frozenVar} = Object.freeze(${innerOut});`);
|
|
4061
|
-
typeAccessor = frozenVar;
|
|
4062
|
-
break;
|
|
4063
|
-
}
|
|
4064
|
-
case "success":
|
|
4065
|
-
generateWrapperCheck(doc, ctx, schema, accessor);
|
|
4066
|
-
typeAccessor = "true";
|
|
4067
|
-
break;
|
|
4068
|
-
case "default":
|
|
4069
|
-
case "prefault":
|
|
4070
|
-
typeAccessor = generateDefaultCheck(doc, ctx, schema, accessor);
|
|
4071
|
-
break;
|
|
4072
|
-
case "nonoptional":
|
|
4073
|
-
typeAccessor = generateNonOptionalCheck(doc, ctx, schema, accessor);
|
|
4074
|
-
break;
|
|
4075
|
-
case "tuple":
|
|
4076
|
-
typeAccessor = generateTupleCheck(doc, ctx, schema, accessor);
|
|
4077
|
-
break;
|
|
4078
|
-
case "union":
|
|
4079
|
-
typeAccessor = generateUnionCheck(doc, ctx, schema, accessor);
|
|
4080
|
-
break;
|
|
4081
|
-
case "intersection":
|
|
4082
|
-
typeAccessor = generateIntersectionCheck(doc, ctx, schema, accessor);
|
|
4083
|
-
break;
|
|
4084
|
-
case "record":
|
|
4085
|
-
typeAccessor = generateRecordCheck(doc, ctx, schema, accessor);
|
|
4086
|
-
break;
|
|
4087
|
-
case "map":
|
|
4088
|
-
typeAccessor = generateMapCheck(doc, ctx, schema, accessor);
|
|
4089
|
-
break;
|
|
4090
|
-
case "set":
|
|
4091
|
-
typeAccessor = generateSetCheck(doc, ctx, schema, accessor);
|
|
4092
|
-
break;
|
|
4093
|
-
case "file":
|
|
4094
|
-
typeAccessor = generateFileCheck(doc, accessor);
|
|
4095
|
-
break;
|
|
4096
|
-
case "template_literal":
|
|
4097
|
-
typeAccessor = generateTemplateLiteralCheck(doc, ctx, schema, accessor);
|
|
4098
|
-
break;
|
|
4099
|
-
case "lazy":
|
|
4100
|
-
typeAccessor = generateLazyCheck(doc, ctx, schema, accessor);
|
|
4101
|
-
break;
|
|
4102
|
-
case "pipe":
|
|
4103
|
-
typeAccessor = generatePipeCheck(doc, ctx, schema, accessor);
|
|
4104
|
-
break;
|
|
4105
|
-
case "custom":
|
|
4106
|
-
typeAccessor = generateCustomCheck(doc, ctx, schema, accessor);
|
|
4107
|
-
break;
|
|
4108
|
-
case "transform":
|
|
4109
|
-
typeAccessor = generateTransformCheck(doc, ctx, schema, accessor);
|
|
4110
|
-
break;
|
|
4111
|
-
case "catch":
|
|
4112
|
-
typeAccessor = generateCatchCheck(doc, ctx, schema, accessor);
|
|
4113
|
-
break;
|
|
4114
|
-
default: {
|
|
4115
|
-
throw new ZodCompileUnsupportedError(`schema type ${type}`);
|
|
4116
|
-
}
|
|
4117
|
-
}
|
|
4118
|
-
if (typeAccessor === null)
|
|
4119
|
-
return null;
|
|
4120
|
-
return generateChecks(doc, ctx, schema, typeAccessor);
|
|
4121
|
-
}
|
|
4122
|
-
function generateStringCheck(doc, ctx, schema, accessor, needsValue = true) {
|
|
4123
|
-
doc.write(`if (typeof ${accessor} !== "string") return INVALID;`);
|
|
4124
|
-
const def = schema._zod.def;
|
|
4125
|
-
if (def.format === undefined)
|
|
4126
|
-
return accessor;
|
|
4127
|
-
return generateStringFormatCheck(doc, ctx, def, accessor, needsValue);
|
|
4128
|
-
}
|
|
4129
|
-
function generateNumberCheck(doc, schema, accessor) {
|
|
4130
|
-
doc.write(`if (typeof ${accessor} !== "number" || !Number.isFinite(${accessor})) return INVALID;`);
|
|
4131
|
-
const def = schema._zod.def;
|
|
4132
|
-
if (def.check === "number_format" && def.format) {
|
|
4133
|
-
generateNumberFormatCheck(doc, { format: def.format }, accessor);
|
|
4134
|
-
}
|
|
4135
|
-
return accessor;
|
|
4136
|
-
}
|
|
4137
|
-
function generateBooleanCheck(doc, accessor) {
|
|
4138
|
-
doc.write(`if (typeof ${accessor} !== "boolean") return INVALID;`);
|
|
4139
|
-
return accessor;
|
|
4140
|
-
}
|
|
4141
|
-
function generateBigIntCheck(doc, schema, accessor) {
|
|
4142
|
-
doc.write(`if (typeof ${accessor} !== "bigint") return INVALID;`);
|
|
4143
|
-
const def = schema._zod.def;
|
|
4144
|
-
if (def.format) {
|
|
4145
|
-
switch (def.format) {
|
|
4146
|
-
case "int64":
|
|
4147
|
-
doc.write(`if (${accessor} < -9223372036854775808n || ${accessor} > 9223372036854775807n) return INVALID;`);
|
|
4148
|
-
break;
|
|
4149
|
-
case "uint64":
|
|
4150
|
-
doc.write(`if (${accessor} < 0n || ${accessor} > 18446744073709551615n) return INVALID;`);
|
|
4151
|
-
break;
|
|
4152
|
-
}
|
|
4153
|
-
}
|
|
4154
|
-
return accessor;
|
|
4155
|
-
}
|
|
4156
|
-
function generateSymbolCheck(doc, accessor) {
|
|
4157
|
-
doc.write(`if (typeof ${accessor} !== "symbol") return INVALID;`);
|
|
4158
|
-
return accessor;
|
|
4159
|
-
}
|
|
4160
|
-
function generateUndefinedCheck(doc, accessor) {
|
|
4161
|
-
doc.write(`if (${accessor} !== undefined) return INVALID;`);
|
|
4162
|
-
return accessor;
|
|
4163
|
-
}
|
|
4164
|
-
function generateNullCheck(doc, accessor) {
|
|
4165
|
-
doc.write(`if (${accessor} !== null) return INVALID;`);
|
|
4166
|
-
return accessor;
|
|
4167
|
-
}
|
|
4168
|
-
function generateVoidCheck(doc, accessor) {
|
|
4169
|
-
doc.write(`if (${accessor} !== undefined) return INVALID;`);
|
|
4170
|
-
return accessor;
|
|
4171
|
-
}
|
|
4172
|
-
function generateNaNCheck(doc, accessor) {
|
|
4173
|
-
doc.write(`if (typeof ${accessor} !== "number" || !Number.isNaN(${accessor})) return INVALID;`);
|
|
4174
|
-
return accessor;
|
|
4175
|
-
}
|
|
4176
|
-
function generateDateCheck(doc, accessor) {
|
|
4177
|
-
doc.write(`if (!(${accessor} instanceof Date) || Number.isNaN(${accessor}.getTime())) return INVALID;`);
|
|
4178
|
-
return accessor;
|
|
4179
|
-
}
|
|
4180
|
-
function generateObjectCheck(doc, ctx, schema, accessor, buildsValue = true) {
|
|
4181
|
-
const def = schema._zod.def;
|
|
4182
|
-
doc.write(`if (typeof ${accessor} !== "object" || ${accessor} === null || Array.isArray(${accessor})) return INVALID;`);
|
|
4183
|
-
const shape = def.shape;
|
|
4184
|
-
const keys = Object.keys(shape);
|
|
4185
|
-
const symbolKeys = Object.getOwnPropertySymbols(shape);
|
|
4186
|
-
const allKeys = symbolKeys.length ? [...keys, ...symbolKeys] : keys;
|
|
4187
|
-
const keyExpr = (k) => typeof k === "symbol" ? addConstant(ctx, k) : esc(k);
|
|
4188
|
-
const propKey = (k) => typeof k === "symbol" ? `[${keyExpr(k)}]` : esc(k);
|
|
4189
|
-
const propShape = shape;
|
|
4190
|
-
if (keys.includes("__proto__")) {
|
|
4191
|
-
throw new ZodCompileUnsupportedError('object shape key "__proto__"');
|
|
4192
|
-
}
|
|
4193
|
-
const propOutputs = new Map;
|
|
4194
|
-
for (const key of allKeys) {
|
|
4195
|
-
const propSchema = propShape[key];
|
|
4196
|
-
const kx = keyExpr(key);
|
|
4197
|
-
const inputVar = newVar(ctx);
|
|
4198
|
-
doc.write(`const ${inputVar} = ${accessor}[${kx}];`);
|
|
4199
|
-
if (propSchema._zod.optin !== undefined) {
|
|
4200
|
-
const outputVar = newVar(ctx);
|
|
4201
|
-
doc.write(`let ${outputVar} = (() => {`);
|
|
4202
|
-
doc.indented((d) => {
|
|
4203
|
-
const outputAccessor = compileChild(d, ctx, propSchema, inputVar);
|
|
4204
|
-
d.write(`return ${outputAccessor};`);
|
|
4205
|
-
});
|
|
4206
|
-
doc.write(`})();`);
|
|
4207
|
-
if (propSchema._zod.optout === "optional") {
|
|
4208
|
-
doc.write(`if (${outputVar} === INVALID) {`);
|
|
4209
|
-
doc.indented((d) => {
|
|
4210
|
-
d.write(`if (${kx} in ${accessor}) return INVALID;`);
|
|
4211
|
-
d.write(`${outputVar} = undefined;`);
|
|
4212
|
-
});
|
|
4213
|
-
doc.write(`}`);
|
|
4214
|
-
} else {
|
|
4215
|
-
doc.write(`if (${outputVar} === INVALID) return INVALID;`);
|
|
4216
|
-
}
|
|
4217
|
-
propOutputs.set(key, outputVar);
|
|
4218
|
-
} else {
|
|
4219
|
-
if (requiresPresenceCheck(propSchema)) {
|
|
4220
|
-
doc.write(`if (!(${kx} in ${accessor})) return INVALID;`);
|
|
4221
|
-
}
|
|
4222
|
-
const outputAccessor = compileChild(doc, ctx, propSchema, inputVar, buildsValue);
|
|
4223
|
-
if (outputAccessor !== null)
|
|
4224
|
-
propOutputs.set(key, outputAccessor);
|
|
4225
|
-
}
|
|
4226
|
-
}
|
|
4227
|
-
const catchall = def.catchall;
|
|
4228
|
-
let unknownKeysMode = "none";
|
|
4229
|
-
if (catchall) {
|
|
4230
|
-
const catchallType = catchall._zod.def.type;
|
|
4231
|
-
if (catchallType === "never") {
|
|
4232
|
-
const condition = keys.map((k) => `k !== ${esc(k)}`).join(" && ") || "true";
|
|
4233
|
-
doc.write(`for (const k in ${accessor}) {`);
|
|
4234
|
-
doc.indented((d) => {
|
|
4235
|
-
d.write(`if (${condition}) return INVALID;`);
|
|
4236
|
-
});
|
|
4237
|
-
doc.write(`}`);
|
|
4238
|
-
} else if ((catchallType === "unknown" || catchallType === "any") && !catchall._zod.def.checks?.length) {
|
|
4239
|
-
unknownKeysMode = "passthrough";
|
|
4240
|
-
} else {
|
|
4241
|
-
unknownKeysMode = "schema";
|
|
4242
|
-
}
|
|
4243
|
-
}
|
|
4244
|
-
const outputVar = newVar(ctx);
|
|
4245
|
-
const hasConditionalKeys = allKeys.some((k) => mayOmitUndefined(propShape[k]) || dropsWhenAbsent(propShape[k]));
|
|
4246
|
-
if (!buildsValue) {
|
|
4247
|
-
if (unknownKeysMode === "schema") {
|
|
4248
|
-
const knownSet = keys.length > 0 ? addConstant(ctx, new Set(keys)) : null;
|
|
4249
|
-
doc.write(`for (const k in ${accessor}) {`);
|
|
4250
|
-
doc.indented((d) => {
|
|
4251
|
-
d.write(`if (k === "__proto__") continue;`);
|
|
4252
|
-
if (knownSet)
|
|
4253
|
-
d.write(`if (${knownSet}.has(k)) continue;`);
|
|
4254
|
-
const valVar = newVar(ctx);
|
|
4255
|
-
d.write(`const ${valVar} = ${accessor}[k];`);
|
|
4256
|
-
compileChild(d, ctx, catchall, valVar, false);
|
|
4257
|
-
});
|
|
4258
|
-
doc.write(`}`);
|
|
4259
|
-
}
|
|
4260
|
-
return null;
|
|
4261
|
-
}
|
|
4262
|
-
if (!hasConditionalKeys) {
|
|
4263
|
-
const propLiterals = allKeys.map((k) => `${propKey(k)}: ${propOutputs.get(k)}`).join(", ");
|
|
4264
|
-
doc.write(`const ${outputVar} = { ${propLiterals} };`);
|
|
4265
|
-
} else {
|
|
4266
|
-
doc.write(`const ${outputVar} = {};`);
|
|
4267
|
-
for (const k of allKeys) {
|
|
4268
|
-
const kx = keyExpr(k);
|
|
4269
|
-
const out = propOutputs.get(k);
|
|
4270
|
-
if (dropsWhenAbsent(propShape[k])) {
|
|
4271
|
-
doc.write(`if (${kx} in ${accessor}) ${outputVar}[${kx}] = ${out};`);
|
|
4272
|
-
} else if (mayOmitUndefined(propShape[k])) {
|
|
4273
|
-
doc.write(`if (${out} !== undefined || ${kx} in ${accessor}) ${outputVar}[${kx}] = ${out};`);
|
|
4274
|
-
} else {
|
|
4275
|
-
doc.write(`${outputVar}[${kx}] = ${out};`);
|
|
4276
|
-
}
|
|
4277
|
-
}
|
|
4278
|
-
}
|
|
4279
|
-
if (unknownKeysMode !== "none") {
|
|
4280
|
-
const knownSet = keys.length > 0 ? addConstant(ctx, new Set(keys)) : null;
|
|
4281
|
-
doc.write(`for (const k in ${accessor}) {`);
|
|
4282
|
-
doc.indented((d) => {
|
|
4283
|
-
d.write(`if (k === "__proto__") continue;`);
|
|
4284
|
-
if (knownSet)
|
|
4285
|
-
d.write(`if (${knownSet}.has(k)) continue;`);
|
|
4286
|
-
if (unknownKeysMode === "passthrough") {
|
|
4287
|
-
d.write(`${outputVar}[k] = ${accessor}[k];`);
|
|
4288
|
-
} else {
|
|
4289
|
-
const valVar = newVar(ctx);
|
|
4290
|
-
d.write(`const ${valVar} = ${accessor}[k];`);
|
|
4291
|
-
const catchallOut = compileChild(d, ctx, catchall, valVar);
|
|
4292
|
-
d.write(`${outputVar}[k] = ${catchallOut};`);
|
|
4293
|
-
}
|
|
4294
|
-
});
|
|
4295
|
-
doc.write(`}`);
|
|
4296
|
-
}
|
|
4297
|
-
return outputVar;
|
|
4298
|
-
}
|
|
4299
|
-
function generateOptionalCheck(doc, ctx, schema, accessor, buildsValue = true) {
|
|
4300
|
-
const def = schema._zod.def;
|
|
4301
|
-
if (isExactOptional(schema)) {
|
|
4302
|
-
return generateCheck(doc, ctx, def.innerType, accessor, buildsValue);
|
|
4303
|
-
}
|
|
4304
|
-
if (def.innerType._zod.optin === "defaulted") {
|
|
4305
|
-
const outputVar = newVar(ctx);
|
|
4306
|
-
const branchVar = newVar(ctx);
|
|
4307
|
-
doc.write(`let ${outputVar};`);
|
|
4308
|
-
doc.write(`if (${accessor} === undefined) {`);
|
|
4309
|
-
doc.indented((d) => {
|
|
4310
|
-
d.write(`const ${branchVar} = (() => {`);
|
|
4311
|
-
d.indented((d2) => {
|
|
4312
|
-
const innerOutput = generateCheck(d2, ctx, def.innerType, accessor);
|
|
4313
|
-
d2.write(`return ${innerOutput};`);
|
|
4314
|
-
});
|
|
4315
|
-
d.write(`})();`);
|
|
4316
|
-
d.write(`if (${branchVar} !== INVALID) ${outputVar} = ${branchVar};`);
|
|
4317
|
-
});
|
|
4318
|
-
doc.write(`} else {`);
|
|
4319
|
-
doc.indented((d) => {
|
|
4320
|
-
const innerOutput = generateCheck(d, ctx, def.innerType, accessor);
|
|
4321
|
-
d.write(`${outputVar} = ${innerOutput};`);
|
|
4322
|
-
});
|
|
4323
|
-
doc.write(`}`);
|
|
4324
|
-
return outputVar;
|
|
4325
|
-
}
|
|
4326
|
-
const outputVar = buildsValue ? newVar(ctx) : null;
|
|
4327
|
-
if (outputVar)
|
|
4328
|
-
doc.write(`let ${outputVar};`);
|
|
4329
|
-
doc.write(`if (${accessor} !== undefined) {`);
|
|
4330
|
-
doc.indented((d) => {
|
|
4331
|
-
const innerOutput = generateCheck(d, ctx, def.innerType, accessor, buildsValue);
|
|
4332
|
-
if (outputVar && innerOutput !== null)
|
|
4333
|
-
d.write(`${outputVar} = ${innerOutput};`);
|
|
4334
|
-
});
|
|
4335
|
-
doc.write(`}`);
|
|
4336
|
-
return outputVar;
|
|
4337
|
-
}
|
|
4338
|
-
function isExactOptional(schema) {
|
|
4339
|
-
return schema._zod.traits?.has("$ZodExactOptional") === true;
|
|
4340
|
-
}
|
|
4341
|
-
function requiresPresenceCheck(schema) {
|
|
4342
|
-
return schema._zod.optin === undefined && fastPathAcceptsAbsence(schema);
|
|
4343
|
-
}
|
|
4344
|
-
function fastPathAcceptsAbsence(schema) {
|
|
4345
|
-
if (schema._zod.def.coerce)
|
|
4346
|
-
return true;
|
|
4347
|
-
const def = schema._zod.def;
|
|
4348
|
-
switch (def.type) {
|
|
4349
|
-
case "any":
|
|
4350
|
-
case "unknown":
|
|
4351
|
-
case "undefined":
|
|
4352
|
-
case "void":
|
|
4353
|
-
case "default":
|
|
4354
|
-
case "prefault":
|
|
4355
|
-
case "transform":
|
|
4356
|
-
case "custom":
|
|
4357
|
-
case "lazy":
|
|
4358
|
-
return true;
|
|
4359
|
-
case "string":
|
|
4360
|
-
case "number":
|
|
4361
|
-
case "boolean":
|
|
4362
|
-
case "bigint":
|
|
4363
|
-
case "symbol":
|
|
4364
|
-
case "null":
|
|
4365
|
-
case "never":
|
|
4366
|
-
case "nan":
|
|
4367
|
-
case "date":
|
|
4368
|
-
case "object":
|
|
4369
|
-
case "array":
|
|
4370
|
-
case "tuple":
|
|
4371
|
-
case "record":
|
|
4372
|
-
case "map":
|
|
4373
|
-
case "set":
|
|
4374
|
-
case "file":
|
|
4375
|
-
case "template_literal":
|
|
4376
|
-
return false;
|
|
4377
|
-
case "nonoptional":
|
|
4378
|
-
return def.innerType ? fastPathAcceptsAbsence(def.innerType) : false;
|
|
4379
|
-
case "literal":
|
|
4380
|
-
return !!def.values?.includes(undefined);
|
|
4381
|
-
case "enum":
|
|
4382
|
-
return !!schema._zod.values?.has(undefined);
|
|
4383
|
-
case "optional":
|
|
4384
|
-
case "nullable":
|
|
4385
|
-
case "readonly":
|
|
4386
|
-
case "success":
|
|
4387
|
-
return def.innerType ? fastPathAcceptsAbsence(def.innerType) : true;
|
|
4388
|
-
case "catch":
|
|
4389
|
-
return true;
|
|
4390
|
-
case "union":
|
|
4391
|
-
return def.options ? def.options.some(fastPathAcceptsAbsence) : true;
|
|
4392
|
-
case "intersection":
|
|
4393
|
-
if (!def.left || !def.right)
|
|
4394
|
-
return true;
|
|
4395
|
-
return fastPathAcceptsAbsence(def.left) && fastPathAcceptsAbsence(def.right);
|
|
4396
|
-
case "pipe":
|
|
4397
|
-
return def.in ? fastPathAcceptsAbsence(def.in) : true;
|
|
4398
|
-
default:
|
|
4399
|
-
return true;
|
|
4400
|
-
}
|
|
4401
|
-
}
|
|
4402
|
-
function dropsWhenAbsent(schema) {
|
|
4403
|
-
return schema._zod.optin === "optional" && schema._zod.optout === "optional";
|
|
4404
|
-
}
|
|
4405
|
-
function mayOmitUndefined(schema) {
|
|
4406
|
-
return (schema._zod.optin !== "defaulted" || schema._zod.optout === "optional") && mayOutputUndefined(schema);
|
|
4407
|
-
}
|
|
4408
|
-
function mayOutputUndefined(schema) {
|
|
4409
|
-
const def = schema._zod.def;
|
|
4410
|
-
switch (def.type) {
|
|
4411
|
-
case "string":
|
|
4412
|
-
case "number":
|
|
4413
|
-
case "boolean":
|
|
4414
|
-
case "bigint":
|
|
4415
|
-
case "symbol":
|
|
4416
|
-
case "null":
|
|
4417
|
-
case "nan":
|
|
4418
|
-
case "date":
|
|
4419
|
-
case "object":
|
|
4420
|
-
case "array":
|
|
4421
|
-
case "tuple":
|
|
4422
|
-
case "record":
|
|
4423
|
-
case "map":
|
|
4424
|
-
case "set":
|
|
4425
|
-
case "file":
|
|
4426
|
-
case "template_literal":
|
|
4427
|
-
case "never":
|
|
4428
|
-
case "success":
|
|
4429
|
-
return false;
|
|
4430
|
-
case "literal":
|
|
4431
|
-
return !!def.values?.includes(undefined);
|
|
4432
|
-
case "enum":
|
|
4433
|
-
return !!schema._zod.values?.has(undefined);
|
|
4434
|
-
case "optional":
|
|
4435
|
-
return true;
|
|
4436
|
-
case "nullable":
|
|
4437
|
-
case "readonly":
|
|
4438
|
-
case "nonoptional":
|
|
4439
|
-
return def.innerType ? mayOutputUndefined(def.innerType) : true;
|
|
4440
|
-
case "union":
|
|
4441
|
-
return def.options ? def.options.some(mayOutputUndefined) : true;
|
|
4442
|
-
case "intersection":
|
|
4443
|
-
return !def.left || !def.right || mayOutputUndefined(def.left) || mayOutputUndefined(def.right);
|
|
4444
|
-
case "pipe":
|
|
4445
|
-
return def.out ? mayOutputUndefined(def.out) : true;
|
|
4446
|
-
default:
|
|
4447
|
-
return true;
|
|
4448
|
-
}
|
|
4449
|
-
}
|
|
4450
|
-
function generateNullableCheck(doc, ctx, schema, accessor, buildsValue = true) {
|
|
4451
|
-
const def = schema._zod.def;
|
|
4452
|
-
const outputVar = buildsValue ? newVar(ctx) : null;
|
|
4453
|
-
if (outputVar)
|
|
4454
|
-
doc.write(`let ${outputVar} = null;`);
|
|
4455
|
-
doc.write(`if (${accessor} !== null) {`);
|
|
4456
|
-
doc.indented((d) => {
|
|
4457
|
-
const innerOutput = generateCheck(d, ctx, def.innerType, accessor, buildsValue);
|
|
4458
|
-
if (outputVar && innerOutput !== null)
|
|
4459
|
-
d.write(`${outputVar} = ${innerOutput};`);
|
|
4460
|
-
});
|
|
4461
|
-
doc.write(`}`);
|
|
4462
|
-
return outputVar;
|
|
4463
|
-
}
|
|
4464
|
-
function generateArrayCheck(doc, ctx, schema, accessor, buildsValue = true) {
|
|
4465
|
-
const def = schema._zod.def;
|
|
4466
|
-
doc.write(`if (!Array.isArray(${accessor})) return INVALID;`);
|
|
4467
|
-
const outputVar = buildsValue ? newVar(ctx) : null;
|
|
4468
|
-
const iVar = newVar(ctx);
|
|
4469
|
-
const elemVar = newVar(ctx);
|
|
4470
|
-
if (outputVar)
|
|
4471
|
-
doc.write(`const ${outputVar} = new Array(${accessor}.length);`);
|
|
4472
|
-
doc.write(`for (let ${iVar} = 0; ${iVar} < ${accessor}.length; ${iVar}++) {`);
|
|
4473
|
-
doc.indented((d) => {
|
|
4474
|
-
d.write(`const ${elemVar} = ${accessor}[${iVar}];`);
|
|
4475
|
-
const elemOutput = compileChild(d, ctx, def.element, elemVar, buildsValue);
|
|
4476
|
-
if (outputVar && elemOutput !== null)
|
|
4477
|
-
d.write(`${outputVar}[${iVar}] = ${elemOutput};`);
|
|
4478
|
-
});
|
|
4479
|
-
doc.write(`}`);
|
|
4480
|
-
return outputVar;
|
|
4481
|
-
}
|
|
4482
|
-
function generateLiteralCheck(doc, ctx, schema, accessor) {
|
|
4483
|
-
const def = schema._zod.def;
|
|
4484
|
-
const values = def.values;
|
|
4485
|
-
if (values.length !== 1) {
|
|
4486
|
-
const literalSet = addConstant(ctx, new Set(values));
|
|
4487
|
-
doc.write(`if (!${literalSet}.has(${accessor})) return INVALID;`);
|
|
4488
|
-
return accessor;
|
|
4489
|
-
}
|
|
4490
|
-
const value = values[0];
|
|
4491
|
-
if (typeof value === "number" && Number.isNaN(value)) {
|
|
4492
|
-
const literalSet = addConstant(ctx, new Set(values));
|
|
4493
|
-
doc.write(`if (!${literalSet}.has(${accessor})) return INVALID;`);
|
|
4494
|
-
return accessor;
|
|
4495
|
-
}
|
|
4496
|
-
if (typeof value === "string") {
|
|
4497
|
-
doc.write(`if (${accessor} !== ${esc(value)}) return INVALID;`);
|
|
4498
|
-
} else if (typeof value === "number" || typeof value === "boolean") {
|
|
4499
|
-
doc.write(`if (${accessor} !== ${value}) return INVALID;`);
|
|
4500
|
-
} else if (value === null) {
|
|
4501
|
-
doc.write(`if (${accessor} !== null) return INVALID;`);
|
|
4502
|
-
} else if (value === undefined) {
|
|
4503
|
-
doc.write(`if (${accessor} !== undefined) return INVALID;`);
|
|
4504
|
-
} else if (typeof value === "bigint") {
|
|
4505
|
-
doc.write(`if (${accessor} !== ${value}n) return INVALID;`);
|
|
4506
|
-
} else {
|
|
4507
|
-
throw new ZodCompileUnsupportedError(`literal type ${typeof value}`);
|
|
4508
|
-
}
|
|
4509
|
-
return accessor;
|
|
4510
|
-
}
|
|
4511
|
-
function generateEnumCheck(doc, ctx, schema, accessor) {
|
|
4512
|
-
const values = schema._zod.values;
|
|
4513
|
-
if (!values) {
|
|
4514
|
-
throw new ZodCompileUnsupportedError("enum schema without enumerated values");
|
|
4515
|
-
}
|
|
4516
|
-
const enumSet = addConstant(ctx, values);
|
|
4517
|
-
doc.write(`if (!${enumSet}.has(${accessor})) return INVALID;`);
|
|
4518
|
-
return accessor;
|
|
4519
|
-
}
|
|
4520
|
-
function generateWrapperCheck(doc, ctx, schema, accessor) {
|
|
4521
|
-
const def = schema._zod.def;
|
|
4522
|
-
return generateCheck(doc, ctx, def.innerType, accessor);
|
|
4523
|
-
}
|
|
4524
|
-
function generateDefaultCheck(doc, ctx, schema, accessor) {
|
|
4525
|
-
const def = schema._zod.def;
|
|
4526
|
-
const descriptor = Object.getOwnPropertyDescriptor(schema._zod.def, "defaultValue");
|
|
4527
|
-
const defaultGetter = descriptor ? () => schema._zod.def.defaultValue : undefined;
|
|
4528
|
-
if (schema._zod.def.type === "prefault") {
|
|
4529
|
-
if (!defaultGetter) {
|
|
4530
|
-
return generateCheck(doc, ctx, def.innerType, accessor);
|
|
4531
|
-
}
|
|
4532
|
-
const defaultFn = addConstant(ctx, defaultGetter);
|
|
4533
|
-
const inputVar = newVar(ctx);
|
|
4534
|
-
doc.write(`let ${inputVar} = ${accessor};`);
|
|
4535
|
-
doc.write(`if (${accessor} === undefined) ${inputVar} = ${defaultFn}();`);
|
|
4536
|
-
return generateCheck(doc, ctx, def.innerType, inputVar);
|
|
4537
|
-
}
|
|
4538
|
-
const outputVar = newVar(ctx);
|
|
4539
|
-
if (defaultGetter) {
|
|
4540
|
-
const defaultFn = addConstant(ctx, defaultGetter);
|
|
4541
|
-
const cloneFn = addConstant(ctx, shallowClone);
|
|
4542
|
-
doc.write(`let ${outputVar};`);
|
|
4543
|
-
doc.write(`if (${accessor} === undefined) {`);
|
|
4544
|
-
doc.indented((d) => {
|
|
4545
|
-
d.write(`${outputVar} = ${cloneFn}(${defaultFn}());`);
|
|
4546
|
-
});
|
|
4547
|
-
doc.write(`} else {`);
|
|
4548
|
-
doc.indented((d) => {
|
|
4549
|
-
const innerOutput = generateCheck(d, ctx, def.innerType, accessor);
|
|
4550
|
-
d.write(`${outputVar} = ${innerOutput} === undefined ? ${cloneFn}(${defaultFn}()) : ${innerOutput};`);
|
|
4551
|
-
});
|
|
4552
|
-
doc.write(`}`);
|
|
4553
|
-
} else {
|
|
4554
|
-
doc.write(`let ${outputVar};`);
|
|
4555
|
-
doc.write(`if (${accessor} !== undefined) {`);
|
|
4556
|
-
doc.indented((d) => {
|
|
4557
|
-
const innerOutput = generateCheck(d, ctx, def.innerType, accessor);
|
|
4558
|
-
d.write(`${outputVar} = ${innerOutput};`);
|
|
4559
|
-
});
|
|
4560
|
-
doc.write(`}`);
|
|
4561
|
-
}
|
|
4562
|
-
return outputVar;
|
|
4563
|
-
}
|
|
4564
|
-
function generateNonOptionalCheck(doc, ctx, schema, accessor) {
|
|
4565
|
-
const def = schema._zod.def;
|
|
4566
|
-
const innerOutput = generateCheck(doc, ctx, def.innerType, accessor);
|
|
4567
|
-
const outputVar = newVar(ctx);
|
|
4568
|
-
doc.write(`const ${outputVar} = ${innerOutput};`);
|
|
4569
|
-
doc.write(`if (${outputVar} === undefined) return INVALID;`);
|
|
4570
|
-
return outputVar;
|
|
4571
|
-
}
|
|
4572
|
-
function generateTupleCheck(doc, ctx, schema, accessor) {
|
|
4573
|
-
const def = schema._zod.def;
|
|
4574
|
-
const items = def.items;
|
|
4575
|
-
const rest = def.rest;
|
|
4576
|
-
doc.write(`if (!Array.isArray(${accessor})) return INVALID;`);
|
|
4577
|
-
const optinStart = getTupleOptStart(items, "optin");
|
|
4578
|
-
const optoutStart = getTupleOptStart(items, "optout");
|
|
4579
|
-
if (rest) {
|
|
4580
|
-
doc.write(`if (${accessor}.length < ${optinStart}) return INVALID;`);
|
|
4581
|
-
} else {
|
|
4582
|
-
doc.write(`if (${accessor}.length < ${optinStart} || ${accessor}.length > ${items.length}) return INVALID;`);
|
|
4583
|
-
}
|
|
4584
|
-
const outputVar = newVar(ctx);
|
|
4585
|
-
doc.write(`const ${outputVar} = [];`);
|
|
4586
|
-
for (let i = 0;i < items.length; i++) {
|
|
4587
|
-
const itemSchema = items[i];
|
|
4588
|
-
if (i >= optoutStart) {
|
|
4589
|
-
doc.write(`if (${outputVar}.length === ${i}) {`);
|
|
4590
|
-
doc.indented((d) => {
|
|
4591
|
-
d.write(`if (${i} < ${accessor}.length) {`);
|
|
4592
|
-
d.indented((d2) => {
|
|
4593
|
-
const elemVar = newVar(ctx);
|
|
4594
|
-
d2.write(`const ${elemVar} = ${accessor}[${i}];`);
|
|
4595
|
-
const elemOutput = compileChild(d2, ctx, itemSchema, elemVar);
|
|
4596
|
-
d2.write(`${outputVar}[${i}] = ${elemOutput};`);
|
|
4597
|
-
});
|
|
4598
|
-
d.write(`} else {`);
|
|
4599
|
-
d.indented((d2) => {
|
|
4600
|
-
if (dropsWhenAbsent(itemSchema)) {
|
|
4601
|
-
d2.write(`${outputVar}.length = ${i};`);
|
|
4602
|
-
return;
|
|
4603
|
-
}
|
|
4604
|
-
const elemVar = newVar(ctx);
|
|
4605
|
-
const branchVar = newVar(ctx);
|
|
4606
|
-
d2.write(`const ${elemVar} = undefined;`);
|
|
4607
|
-
d2.write(`const ${branchVar} = (() => {`);
|
|
4608
|
-
d2.indented((d3) => {
|
|
4609
|
-
const elemOutput = compileChild(d3, ctx, itemSchema, elemVar);
|
|
4610
|
-
d3.write(`return ${elemOutput};`);
|
|
4611
|
-
});
|
|
4612
|
-
d2.write(`})();`);
|
|
4613
|
-
d2.write(`if (${branchVar} === INVALID || ${branchVar} === undefined) ${outputVar}.length = ${i};`);
|
|
4614
|
-
d2.write(`else ${outputVar}[${i}] = ${branchVar};`);
|
|
4615
|
-
});
|
|
4616
|
-
d.write(`}`);
|
|
4617
|
-
});
|
|
4618
|
-
doc.write(`}`);
|
|
4619
|
-
} else {
|
|
4620
|
-
const elemVar = newVar(ctx);
|
|
4621
|
-
doc.write(`const ${elemVar} = ${accessor}[${i}];`);
|
|
4622
|
-
const elemOutput = compileChild(doc, ctx, itemSchema, elemVar);
|
|
4623
|
-
doc.write(`${outputVar}[${i}] = ${elemOutput};`);
|
|
4624
|
-
}
|
|
4625
|
-
}
|
|
4626
|
-
if (rest) {
|
|
4627
|
-
const iVar = newVar(ctx);
|
|
4628
|
-
const elemVar = newVar(ctx);
|
|
4629
|
-
doc.write(`for (let ${iVar} = ${items.length}; ${iVar} < ${accessor}.length; ${iVar}++) {`);
|
|
4630
|
-
doc.indented((d) => {
|
|
4631
|
-
d.write(`const ${elemVar} = ${accessor}[${iVar}];`);
|
|
4632
|
-
const elemOutput = compileChild(d, ctx, rest, elemVar);
|
|
4633
|
-
d.write(`${outputVar}[${iVar}] = ${elemOutput};`);
|
|
4634
|
-
});
|
|
4635
|
-
doc.write(`}`);
|
|
4636
|
-
}
|
|
4637
|
-
return outputVar;
|
|
4638
|
-
}
|
|
4639
|
-
function getTupleOptStart(items, key) {
|
|
4640
|
-
for (let i = items.length - 1;i >= 0; i--) {
|
|
4641
|
-
const omittable = key === "optin" ? items[i]._zod.optin !== undefined : items[i]._zod.optout === "optional";
|
|
4642
|
-
if (!omittable)
|
|
4643
|
-
return i + 1;
|
|
4644
|
-
}
|
|
4645
|
-
return 0;
|
|
4646
|
-
}
|
|
4647
|
-
function generateUnionCheck(doc, ctx, schema, accessor) {
|
|
4648
|
-
const def = schema._zod.def;
|
|
4649
|
-
const options = def.options;
|
|
4650
|
-
if (def.discriminator) {
|
|
4651
|
-
return generateDiscriminatedUnionCheck(doc, ctx, def, accessor);
|
|
4652
|
-
}
|
|
4653
|
-
if (def.inclusive === false) {
|
|
4654
|
-
throw new ZodCompileUnsupportedError("exclusive unions (z.xor)");
|
|
4655
|
-
}
|
|
4656
|
-
if (options.length === 0) {
|
|
4657
|
-
doc.write("return INVALID;");
|
|
4658
|
-
return accessor;
|
|
4659
|
-
}
|
|
4660
|
-
if (options.length === 1) {
|
|
4661
|
-
return generateCheck(doc, ctx, options[0], accessor);
|
|
4662
|
-
}
|
|
4663
|
-
const allLiterals = options.every((opt) => opt._zod.def.type === "literal" && !opt._zod.def.checks?.length);
|
|
4664
|
-
if (allLiterals) {
|
|
4665
|
-
const values = new Set(options.flatMap((opt) => opt._zod.def.values));
|
|
4666
|
-
const valuesConst = addConstant(ctx, values);
|
|
4667
|
-
doc.write(`if (!${valuesConst}.has(${accessor})) return INVALID;`);
|
|
4668
|
-
return accessor;
|
|
4669
|
-
}
|
|
4670
|
-
const outputVar = newVar(ctx);
|
|
4671
|
-
doc.write(`let ${outputVar};`);
|
|
4672
|
-
for (let i = 0;i < options.length; i++) {
|
|
4673
|
-
const opt = options[i];
|
|
4674
|
-
if (i === 0) {
|
|
4675
|
-
doc.write(`${outputVar} = (() => {`);
|
|
4676
|
-
} else {
|
|
4677
|
-
doc.write(`if (${outputVar} === INVALID) ${outputVar} = (() => {`);
|
|
4678
|
-
}
|
|
4679
|
-
doc.indented((d) => {
|
|
4680
|
-
const branchOutput = generateCheck(d, ctx, opt, accessor);
|
|
4681
|
-
d.write(`return ${branchOutput};`);
|
|
4682
|
-
});
|
|
4683
|
-
doc.write(`})();`);
|
|
4684
|
-
}
|
|
4685
|
-
doc.write(`if (${outputVar} === INVALID) return INVALID;`);
|
|
4686
|
-
return outputVar;
|
|
4687
|
-
}
|
|
4688
|
-
function generateDiscriminatedUnionCheck(doc, ctx, def, accessor) {
|
|
4689
|
-
if (def.unionFallback) {
|
|
4690
|
-
throw new ZodCompileUnsupportedError("discriminated union with unionFallback");
|
|
4691
|
-
}
|
|
4692
|
-
if (def.options.length === 0) {
|
|
4693
|
-
doc.write("return INVALID;");
|
|
4694
|
-
return accessor;
|
|
4695
|
-
}
|
|
4696
|
-
const discVar = newVar(ctx);
|
|
4697
|
-
const outputVar = newVar(ctx);
|
|
4698
|
-
doc.write(`const ${discVar} = ${accessor}?.[${esc(def.discriminator)}];`);
|
|
4699
|
-
doc.write(`let ${outputVar};`);
|
|
4700
|
-
let firstBranch = true;
|
|
4701
|
-
const claimed = new Set;
|
|
4702
|
-
for (const option of def.options) {
|
|
4703
|
-
const values = option._zod.propValues?.[def.discriminator];
|
|
4704
|
-
if (!values || values.size === 0) {
|
|
4705
|
-
throw new ZodCompileUnsupportedError("discriminated union option without static discriminator values");
|
|
4706
|
-
}
|
|
4707
|
-
for (const value of values) {
|
|
4708
|
-
if (claimed.has(value)) {
|
|
4709
|
-
throw new ZodCompileUnsupportedError(`duplicate discriminator value ${String(value)}`);
|
|
4710
|
-
}
|
|
4711
|
-
claimed.add(value);
|
|
4712
|
-
}
|
|
4713
|
-
const conditions = Array.from(values, (value) => literalEquality(ctx, discVar, value));
|
|
4714
|
-
const prefix = firstBranch ? "if" : "else if";
|
|
4715
|
-
doc.write(`${prefix} (${conditions.join(" || ")}) {`);
|
|
4716
|
-
doc.indented((d) => {
|
|
4717
|
-
const branchOutput = generateCheck(d, ctx, option, accessor);
|
|
4718
|
-
d.write(`${outputVar} = ${branchOutput};`);
|
|
4719
|
-
});
|
|
4720
|
-
doc.write(`}`);
|
|
4721
|
-
firstBranch = false;
|
|
4722
|
-
}
|
|
4723
|
-
doc.write(`else { return INVALID; }`);
|
|
4724
|
-
return outputVar;
|
|
4725
|
-
}
|
|
4726
|
-
function literalEquality(ctx, accessor, value) {
|
|
4727
|
-
if (typeof value === "string")
|
|
4728
|
-
return `${accessor} === ${esc(value)}`;
|
|
4729
|
-
if (typeof value === "number") {
|
|
4730
|
-
if (Number.isNaN(value))
|
|
4731
|
-
return `Number.isNaN(${accessor})`;
|
|
4732
|
-
return `${accessor} === ${value}`;
|
|
4733
|
-
}
|
|
4734
|
-
if (typeof value === "boolean")
|
|
4735
|
-
return `${accessor} === ${value}`;
|
|
4736
|
-
if (value === null)
|
|
4737
|
-
return `${accessor} === null`;
|
|
4738
|
-
if (value === undefined)
|
|
4739
|
-
return `${accessor} === undefined`;
|
|
4740
|
-
if (typeof value === "bigint")
|
|
4741
|
-
return `${accessor} === ${value}n`;
|
|
4742
|
-
if (typeof value === "symbol") {
|
|
4743
|
-
const symbolConst = addConstant(ctx, value);
|
|
4744
|
-
return `${accessor} === ${symbolConst}`;
|
|
4745
|
-
}
|
|
4746
|
-
throw new ZodCompileUnsupportedError(`literal discriminator value ${String(value)}`);
|
|
4747
|
-
}
|
|
4748
|
-
function generateIntersectionCheck(doc, ctx, schema, accessor) {
|
|
4749
|
-
const def = schema._zod.def;
|
|
4750
|
-
ctx.definite = false;
|
|
4751
|
-
const leftOutput = compileChild(doc, ctx, def.left, accessor);
|
|
4752
|
-
const rightOutput = compileChild(doc, ctx, def.right, accessor);
|
|
4753
|
-
const mergeConst = addConstant(ctx, mergeValues);
|
|
4754
|
-
const mergedVar = newVar(ctx);
|
|
4755
|
-
doc.write(`const ${mergedVar} = ${mergeConst}(${leftOutput}, ${rightOutput});`);
|
|
4756
|
-
doc.write(`if (!${mergedVar}.valid) return INVALID;`);
|
|
4757
|
-
return `${mergedVar}.data`;
|
|
4758
|
-
}
|
|
4759
|
-
function generateRecordCheck(doc, ctx, schema, accessor) {
|
|
4760
|
-
const def = schema._zod.def;
|
|
4761
|
-
const isPlainObjectConst = addConstant(ctx, isPlainObject);
|
|
4762
|
-
doc.write(`if (!${isPlainObjectConst}(${accessor})) return INVALID;`);
|
|
4763
|
-
const outputVar = newVar(ctx);
|
|
4764
|
-
const kVar = newVar(ctx);
|
|
4765
|
-
const valVar = newVar(ctx);
|
|
4766
|
-
doc.write(`const ${outputVar} = {};`);
|
|
4767
|
-
const recordDef = def;
|
|
4768
|
-
const keyValues = recordDef.partial ? undefined : def.keyType._zod.values;
|
|
4769
|
-
if (keyValues) {
|
|
4770
|
-
const inputKeys = [];
|
|
4771
|
-
for (const key of keyValues) {
|
|
4772
|
-
if (!(typeof key === "string" || typeof key === "number" || typeof key === "symbol")) {
|
|
4773
|
-
throw new ZodCompileUnsupportedError(`record key value ${String(key)}`);
|
|
4774
|
-
}
|
|
4775
|
-
const inputKey = typeof key === "number" ? key.toString() : key;
|
|
4776
|
-
if (inputKey === "__proto__") {
|
|
4777
|
-
throw new ZodCompileUnsupportedError('record key "__proto__"');
|
|
4778
|
-
}
|
|
4779
|
-
inputKeys.push(inputKey);
|
|
4780
|
-
const keyConst = addConstant(ctx, key);
|
|
4781
|
-
const outKey = generateCheck(doc, ctx, def.keyType, keyConst);
|
|
4782
|
-
const valueVar = newVar(ctx);
|
|
4783
|
-
doc.write(`const ${valueVar} = ${accessor}[${literalPropertyKey(ctx, inputKey)}];`);
|
|
4784
|
-
const valOutput = compileChild(doc, ctx, def.valueType, valueVar);
|
|
4785
|
-
doc.write(`${outputVar}[${outKey}] = ${valOutput};`);
|
|
4786
|
-
}
|
|
4787
|
-
const knownKeysConst = addConstant(ctx, new Set(inputKeys));
|
|
4788
|
-
doc.write(`for (const ${kVar} in ${accessor}) {`);
|
|
4789
|
-
doc.indented((d) => {
|
|
4790
|
-
d.write(`if (${knownKeysConst}.has(${kVar})) continue;`);
|
|
4791
|
-
if (recordDef.mode === "loose") {
|
|
4792
|
-
d.write(`if (${kVar} !== "__proto__") ${outputVar}[${kVar}] = ${accessor}[${kVar}];`);
|
|
4793
|
-
} else {
|
|
4794
|
-
d.write(`return INVALID;`);
|
|
4795
|
-
}
|
|
4796
|
-
});
|
|
4797
|
-
doc.write(`}`);
|
|
4798
|
-
return outputVar;
|
|
4799
|
-
}
|
|
4800
|
-
const keyDef = def.keyType._zod.def;
|
|
4801
|
-
const keyIsBareString = keyDef.type === "string" && keyDef.format === undefined && !keyDef.coerce && (keyDef.checks?.length ?? 0) === 0;
|
|
4802
|
-
if (!keyIsBareString) {
|
|
4803
|
-
const isLoose = def.mode === "loose";
|
|
4804
|
-
const keyFn = compileFn(def.keyType);
|
|
4805
|
-
if (keyFn.definite === false)
|
|
4806
|
-
ctx.definite = false;
|
|
4807
|
-
const keyFast = addConstant(ctx, keyFn);
|
|
4808
|
-
const numericConst = addConstant(ctx, number);
|
|
4809
|
-
const outKeyVar = newVar(ctx);
|
|
4810
|
-
emitOwnKeys(doc, ctx, accessor, kVar, (d) => {
|
|
4811
|
-
d.write(`let ${outKeyVar} = ${keyFast}(${kVar});`);
|
|
4812
|
-
d.write(`if (${outKeyVar} === INVALID && typeof ${kVar} === "string" && ${numericConst}.test(${kVar})) ${outKeyVar} = ${keyFast}(Number(${kVar}));`);
|
|
4813
|
-
if (isLoose) {
|
|
4814
|
-
d.write(`if (${outKeyVar} === INVALID) { ${outputVar}[${kVar}] = ${accessor}[${kVar}]; continue; }`);
|
|
4815
|
-
} else {
|
|
4816
|
-
d.write(`if (${outKeyVar} === INVALID) return INVALID;`);
|
|
4817
|
-
}
|
|
4818
|
-
d.write(`if (${outKeyVar} === "__proto__") continue;`);
|
|
4819
|
-
const valueVar = newVar(ctx);
|
|
4820
|
-
d.write(`const ${valueVar} = ${accessor}[${kVar}];`);
|
|
4821
|
-
const valOutput = compileChild(d, ctx, def.valueType, valueVar);
|
|
4822
|
-
d.write(`${outputVar}[${outKeyVar}] = ${valOutput};`);
|
|
4823
|
-
});
|
|
4824
|
-
return outputVar;
|
|
4825
|
-
}
|
|
4826
|
-
emitOwnKeys(doc, ctx, accessor, kVar, (d) => {
|
|
4827
|
-
d.write(`const ${valVar} = ${accessor}[${kVar}];`);
|
|
4828
|
-
const valOutput = compileChild(d, ctx, def.valueType, valVar);
|
|
4829
|
-
d.write(`${outputVar}[${kVar}] = ${valOutput};`);
|
|
4830
|
-
}, `return INVALID;`);
|
|
4831
|
-
return outputVar;
|
|
4832
|
-
}
|
|
4833
|
-
function emitOwnKeys(doc, ctx, accessor, kVar, body, onSymbol) {
|
|
4834
|
-
const propIsEnumerableConst = addConstant(ctx, Object.prototype.propertyIsEnumerable);
|
|
4835
|
-
const symsVar = newVar(ctx);
|
|
4836
|
-
const keysVar = newVar(ctx);
|
|
4837
|
-
const iVar = newVar(ctx);
|
|
4838
|
-
doc.write(`const ${symsVar} = Object.getOwnPropertySymbols(${accessor});`);
|
|
4839
|
-
doc.write(`const ${keysVar} = Object.getOwnPropertyNames(${accessor});`);
|
|
4840
|
-
doc.write(`for (let ${iVar} = 0; ${iVar} < ${keysVar}.length; ${iVar}++) {`);
|
|
4841
|
-
doc.indented((d) => {
|
|
4842
|
-
d.write(`const ${kVar} = ${keysVar}[${iVar}];`);
|
|
4843
|
-
d.write(`if (${kVar} === "__proto__" || !${propIsEnumerableConst}.call(${accessor}, ${kVar})) continue;`);
|
|
4844
|
-
body(d);
|
|
4845
|
-
});
|
|
4846
|
-
doc.write(`}`);
|
|
4847
|
-
doc.write(`for (let ${iVar} = 0; ${iVar} < ${symsVar}.length; ${iVar}++) {`);
|
|
4848
|
-
doc.indented((d) => {
|
|
4849
|
-
d.write(`const ${kVar} = ${symsVar}[${iVar}];`);
|
|
4850
|
-
d.write(`if (!${propIsEnumerableConst}.call(${accessor}, ${kVar})) continue;`);
|
|
4851
|
-
if (onSymbol)
|
|
4852
|
-
d.write(onSymbol);
|
|
4853
|
-
else
|
|
4854
|
-
body(d);
|
|
4855
|
-
});
|
|
4856
|
-
doc.write(`}`);
|
|
4857
|
-
}
|
|
4858
|
-
function literalPropertyKey(ctx, key) {
|
|
4859
|
-
if (typeof key === "string")
|
|
4860
|
-
return esc(key);
|
|
4861
|
-
return addConstant(ctx, key);
|
|
4862
|
-
}
|
|
4863
|
-
function generateMapCheck(doc, ctx, schema, accessor) {
|
|
4864
|
-
const def = schema._zod.def;
|
|
4865
|
-
doc.write(`if (!(${accessor} instanceof Map)) return INVALID;`);
|
|
4866
|
-
const outputVar = newVar(ctx);
|
|
4867
|
-
const kVar = newVar(ctx);
|
|
4868
|
-
const valVar = newVar(ctx);
|
|
4869
|
-
doc.write(`const ${outputVar} = new Map();`);
|
|
4870
|
-
doc.write(`for (const [${kVar}, ${valVar}] of ${accessor}) {`);
|
|
4871
|
-
doc.indented((d) => {
|
|
4872
|
-
const keyOutput = generateCheck(d, ctx, def.keyType, kVar);
|
|
4873
|
-
const valOutput = generateCheck(d, ctx, def.valueType, valVar);
|
|
4874
|
-
d.write(`${outputVar}.set(${keyOutput}, ${valOutput});`);
|
|
4875
|
-
});
|
|
4876
|
-
doc.write(`}`);
|
|
4877
|
-
return outputVar;
|
|
4878
|
-
}
|
|
4879
|
-
function generateSetCheck(doc, ctx, schema, accessor) {
|
|
4880
|
-
const def = schema._zod.def;
|
|
4881
|
-
doc.write(`if (!(${accessor} instanceof Set)) return INVALID;`);
|
|
4882
|
-
const outputVar = newVar(ctx);
|
|
4883
|
-
const valVar = newVar(ctx);
|
|
4884
|
-
doc.write(`const ${outputVar} = new Set();`);
|
|
4885
|
-
doc.write(`for (const ${valVar} of ${accessor}) {`);
|
|
4886
|
-
doc.indented((d) => {
|
|
4887
|
-
const valOutput = generateCheck(d, ctx, def.valueType, valVar);
|
|
4888
|
-
d.write(`${outputVar}.add(${valOutput});`);
|
|
4889
|
-
});
|
|
4890
|
-
doc.write(`}`);
|
|
4891
|
-
return outputVar;
|
|
4892
|
-
}
|
|
4893
|
-
function generateFileCheck(doc, accessor) {
|
|
4894
|
-
doc.write(`if (!(${accessor} instanceof File)) return INVALID;`);
|
|
4895
|
-
return accessor;
|
|
4896
|
-
}
|
|
4897
|
-
function generateTemplateLiteralCheck(doc, ctx, schema, accessor) {
|
|
4898
|
-
doc.write(`if (typeof ${accessor} !== "string") return INVALID;`);
|
|
4899
|
-
const pattern = schema._zod.pattern;
|
|
4900
|
-
if (pattern) {
|
|
4901
|
-
const patternConst = addConstant(ctx, pattern);
|
|
4902
|
-
doc.write(`${patternConst}.lastIndex = 0;`);
|
|
4903
|
-
doc.write(`if (!${patternConst}.test(${accessor})) return INVALID;`);
|
|
4904
|
-
}
|
|
4905
|
-
return accessor;
|
|
4906
|
-
}
|
|
4907
|
-
function generateLazyCheck(doc, ctx, schema, accessor) {
|
|
4908
|
-
const def = schema._zod.def;
|
|
4909
|
-
const getterConst = addUserConstant(ctx, def.getter);
|
|
4910
|
-
const cacheConst = addConstant(ctx, { parser: null });
|
|
4911
|
-
doc.write(`if (!${cacheConst}.parser) {`);
|
|
4912
|
-
doc.indented((d) => {
|
|
4913
|
-
d.write(`const inner = ${getterConst}();`);
|
|
4914
|
-
d.write(`${cacheConst}.parser = function(input) {`);
|
|
4915
|
-
d.indented((d2) => {
|
|
4916
|
-
d2.write(`const result = inner._zod.run({ value: input, issues: [] }, {});`);
|
|
4917
|
-
d2.write(`return result.issues.length === 0 ? result.value : INVALID;`);
|
|
4918
|
-
});
|
|
4919
|
-
d.write(`};`);
|
|
4920
|
-
});
|
|
4921
|
-
doc.write(`}`);
|
|
4922
|
-
const outputVar = newVar(ctx);
|
|
4923
|
-
doc.write(`const ${outputVar} = ${cacheConst}.parser(${accessor});`);
|
|
4924
|
-
doc.write(`if (${outputVar} === INVALID) return INVALID;`);
|
|
4925
|
-
return outputVar;
|
|
4926
|
-
}
|
|
4927
|
-
function generatePipeCheck(doc, ctx, schema, accessor) {
|
|
4928
|
-
const def = schema._zod.def;
|
|
4929
|
-
const inputOutput = generateCheck(doc, ctx, def.in, accessor);
|
|
4930
|
-
if (def.transform) {
|
|
4931
|
-
if (isAsyncFunction(def.transform)) {
|
|
4932
|
-
throw new ZodCompileAsyncError("z.compile: async transforms in pipes are not supported");
|
|
4933
|
-
}
|
|
4934
|
-
const transformFn = def.transform;
|
|
4935
|
-
const helperFn = (value) => {
|
|
4936
|
-
const fakePayload = { value, issues: [], addIssue: pushIssue };
|
|
4937
|
-
const result = transformFn(value, fakePayload);
|
|
4938
|
-
if (result instanceof Promise)
|
|
4939
|
-
return INVALID;
|
|
4940
|
-
return fakePayload.issues.length === 0 ? result : INVALID;
|
|
4941
|
-
};
|
|
4942
|
-
const helperConst = addUserConstant(ctx, helperFn);
|
|
4943
|
-
const transformedVar = newVar(ctx);
|
|
4944
|
-
doc.write(`const ${transformedVar} = ${helperConst}(${inputOutput});`);
|
|
4945
|
-
doc.write(`if (${transformedVar} === INVALID) return INVALID;`);
|
|
4946
|
-
return generateCheck(doc, ctx, def.out, transformedVar);
|
|
4947
|
-
} else {
|
|
4948
|
-
return generateCheck(doc, ctx, def.out, inputOutput);
|
|
4949
|
-
}
|
|
4950
|
-
}
|
|
4951
|
-
function isAsyncFunction(fn) {
|
|
4952
|
-
return typeof fn === "function" && (fn.constructor.name === "AsyncFunction" || fn[Symbol.toStringTag] === "AsyncFunction");
|
|
4953
|
-
}
|
|
4954
|
-
function generateCustomCheck(doc, ctx, schema, accessor) {
|
|
4955
|
-
const def = schema._zod.def;
|
|
4956
|
-
if (def.fn) {
|
|
4957
|
-
if (isAsyncFunction(def.fn)) {
|
|
4958
|
-
throw new ZodCompileAsyncError("z.compile: async custom predicates are not supported");
|
|
4959
|
-
}
|
|
4960
|
-
const fnConst = addUserConstant(ctx, def.fn);
|
|
4961
|
-
const throwAsyncConst = addConstant(ctx, throwAsync);
|
|
4962
|
-
const resVar = newVar(ctx);
|
|
4963
|
-
doc.write(`const ${resVar} = ${fnConst}(${accessor});`);
|
|
4964
|
-
doc.write(`if (${resVar} instanceof Promise) ${throwAsyncConst}();`);
|
|
4965
|
-
doc.write(`if (!${resVar}) return INVALID;`);
|
|
4966
|
-
} else {
|
|
4967
|
-
throw new ZodCompileUnsupportedError("custom schema without a predicate function");
|
|
4968
|
-
}
|
|
4969
|
-
return accessor;
|
|
4970
|
-
}
|
|
4971
|
-
function runtimeCatch(innerSchema, catchValue, value) {
|
|
4972
|
-
const result = innerSchema._zod.run({ value, issues: [] }, {});
|
|
4973
|
-
if (result && typeof result.then === "function")
|
|
4974
|
-
return INVALID;
|
|
4975
|
-
const r = result;
|
|
4976
|
-
if (r.issues.length === 0)
|
|
4977
|
-
return r.value;
|
|
4978
|
-
return catchValue();
|
|
4979
|
-
}
|
|
4980
|
-
function generateCatchCheck(doc, ctx, schema, accessor) {
|
|
4981
|
-
const def = schema._zod.def;
|
|
4982
|
-
if (!def.catchValue[CONSTANT_CATCH]) {
|
|
4983
|
-
throw new ZodCompileUnsupportedError("catch with a callback (only a constant catch value compiles)", false);
|
|
4984
|
-
}
|
|
4985
|
-
const outputVar = newVar(ctx);
|
|
4986
|
-
doc.write(`let ${outputVar} = (() => {`);
|
|
4987
|
-
doc.indented((d) => {
|
|
4988
|
-
const innerOut = compileChild(d, ctx, def.innerType, accessor);
|
|
4989
|
-
d.write(`return ${innerOut};`);
|
|
4990
|
-
});
|
|
4991
|
-
doc.write(`})();`);
|
|
4992
|
-
const innerConst = addConstant(ctx, def.innerType);
|
|
4993
|
-
const catchConst = addUserConstant(ctx, def.catchValue);
|
|
4994
|
-
const catchHelperConst = addConstant(ctx, runtimeCatch);
|
|
4995
|
-
doc.write(`if (${outputVar} === INVALID) {`);
|
|
4996
|
-
doc.indented((d) => {
|
|
4997
|
-
d.write(`${outputVar} = ${catchHelperConst}(${innerConst}, ${catchConst}, ${accessor});`);
|
|
4998
|
-
d.write(`if (${outputVar} === INVALID) return INVALID;`);
|
|
4999
|
-
});
|
|
5000
|
-
doc.write(`}`);
|
|
5001
|
-
return outputVar;
|
|
5002
|
-
}
|
|
5003
|
-
function generateTransformCheck(doc, ctx, schema, accessor) {
|
|
5004
|
-
const def = schema._zod.def;
|
|
5005
|
-
if (def.transform) {
|
|
5006
|
-
if (isAsyncFunction(def.transform)) {
|
|
5007
|
-
throw new ZodCompileAsyncError("z.compile: async transforms are not supported");
|
|
5008
|
-
}
|
|
5009
|
-
const transformFn = def.transform;
|
|
5010
|
-
const helperFn = (value) => {
|
|
5011
|
-
const fakePayload = { value, issues: [], addIssue: pushIssue };
|
|
5012
|
-
const result = transformFn(value, fakePayload);
|
|
5013
|
-
if (result instanceof Promise)
|
|
5014
|
-
return INVALID;
|
|
5015
|
-
return fakePayload.issues.length === 0 ? result : INVALID;
|
|
5016
|
-
};
|
|
5017
|
-
const helperConst = addUserConstant(ctx, helperFn);
|
|
5018
|
-
const outputVar = newVar(ctx);
|
|
5019
|
-
doc.write(`const ${outputVar} = ${helperConst}(${accessor});`);
|
|
5020
|
-
doc.write(`if (${outputVar} === INVALID) return INVALID;`);
|
|
5021
|
-
return outputVar;
|
|
5022
|
-
}
|
|
5023
|
-
return accessor;
|
|
5024
|
-
}
|
|
5025
|
-
var INVALID, FALLBACK_FLAG, ZodCompileAsyncError, ZodCompileUnsupportedError, WHEN_DEFAULTED_CHECKS, PATTERN_IS_COMPLETE;
|
|
3439
|
+
var INVALID, FALLBACK_FLAG, WHEN_DEFAULTED_CHECKS, PATTERN_IS_COMPLETE;
|
|
5026
3440
|
var init_compile = __esm(() => {
|
|
5027
|
-
init_core();
|
|
5028
|
-
init_memoizer();
|
|
5029
|
-
init_regexes();
|
|
5030
|
-
init_schemas();
|
|
5031
|
-
init_util();
|
|
5032
3441
|
INVALID = Symbol.for("zod.compile.invalid");
|
|
5033
3442
|
FALLBACK_FLAG = Symbol.for("zod.compile.fallback");
|
|
5034
|
-
ZodCompileAsyncError = class ZodCompileAsyncError extends Error {
|
|
5035
|
-
constructor(message = "z.compile does not support async refinements, transforms, or checks") {
|
|
5036
|
-
super(message);
|
|
5037
|
-
this.name = "ZodCompileAsyncError";
|
|
5038
|
-
}
|
|
5039
|
-
};
|
|
5040
|
-
ZodCompileUnsupportedError = class ZodCompileUnsupportedError extends Error {
|
|
5041
|
-
constructor(feature, islandable = true) {
|
|
5042
|
-
super(`z.compile does not support ${feature}; this schema must use the runtime parser`);
|
|
5043
|
-
this.name = "ZodCompileUnsupportedError";
|
|
5044
|
-
this.islandable = islandable;
|
|
5045
|
-
}
|
|
5046
|
-
};
|
|
5047
3443
|
WHEN_DEFAULTED_CHECKS = new Set([
|
|
5048
3444
|
"max_size",
|
|
5049
3445
|
"min_size",
|
|
@@ -7604,7 +6000,6 @@ var init_coerce = () => {};
|
|
|
7604
6000
|
|
|
7605
6001
|
// node_modules/zod/v4/classic/external.js
|
|
7606
6002
|
var init_external = __esm(() => {
|
|
7607
|
-
init_core2();
|
|
7608
6003
|
init_core2();
|
|
7609
6004
|
init_locales();
|
|
7610
6005
|
init_iso();
|
|
@@ -7637,8 +6032,7 @@ function resolveIdRef(kind, ref, ids) {
|
|
|
7637
6032
|
function parseOperation(family, input) {
|
|
7638
6033
|
if (typeof input === "object" && input !== null && "schemaVersion" in input && input.schemaVersion !== SCHEMA_VERSION)
|
|
7639
6034
|
return failure2("unsupported_version", "unsupported schema version", { operation: family });
|
|
7640
|
-
const
|
|
7641
|
-
const parsed = compiled.success ? operationSchemas[family].safeParse(input) : compiled;
|
|
6035
|
+
const parsed = operationSchemas[family].safeParse(input);
|
|
7642
6036
|
if (parsed.success)
|
|
7643
6037
|
return success(null, null, parsed.data);
|
|
7644
6038
|
const fields = parsed.error.issues.map((issue) => ({
|
|
@@ -7724,7 +6118,7 @@ function requirementId(input) {
|
|
|
7724
6118
|
}
|
|
7725
6119
|
});
|
|
7726
6120
|
}
|
|
7727
|
-
var SCHEMA_VERSION = 1, POLICY_VERSION = "1.0.0",
|
|
6121
|
+
var SCHEMA_VERSION = 1, POLICY_VERSION = "1.0.0", uuidPattern, digestPattern, invalidUnicode = (value) => {
|
|
7728
6122
|
for (let i = 0;i < value.length; i += 1) {
|
|
7729
6123
|
const code = value.charCodeAt(i);
|
|
7730
6124
|
if (code >= 55296 && code <= 56319) {
|
|
@@ -7886,7 +6280,7 @@ var SCHEMA_VERSION = 1, POLICY_VERSION = "1.0.0", OPERATION_FAMILIES, uuidPatter
|
|
|
7886
6280
|
if (critical.length > 0)
|
|
7887
6281
|
return { ...first, critical };
|
|
7888
6282
|
return { success: true, data: parsed.data, stripped: [...new Set(stripped)] };
|
|
7889
|
-
}, workspaceRecordSchema, capabilitySchema, requirementEvaluationSchema, taskViewSchema, taskSummarySchema, taskListItemSchema, exportBundleSchema, callerSchema, base, revisions, taskId, operation = (shape) => object({ ...base, ...shape }).strict(), taskOperations, rawJudgment, policyOperations, evidenceOperations, findingOperations, decisionOperations, workerOperations, stateOperations, operationSchemas, OPERATION_ACTIONS, withImplicitTask = (options) => Object.values(options).map((option) => ("taskId" in option.shape) ? option.extend({ taskId: id.optional() }) : option), advertised = (options) => discriminatedUnion("action", withImplicitTask(options)), advertisedOperationSchemas,
|
|
6283
|
+
}, workspaceRecordSchema, capabilitySchema, requirementEvaluationSchema, taskViewSchema, taskSummarySchema, taskListItemSchema, exportBundleSchema, callerSchema, base, revisions, taskId, operation = (shape) => object({ ...base, ...shape }).strict(), taskOperations, rawJudgment, policyOperations, evidenceOperations, findingOperations, decisionOperations, workerOperations, stateOperations, operationSchemas, OPERATION_ACTIONS, withImplicitTask = (options) => Object.values(options).map((option) => ("taskId" in option.shape) ? option.extend({ taskId: id.optional() }) : option), advertised = (options) => discriminatedUnion("action", withImplicitTask(options)), advertisedOperationSchemas, success = (revisionValue, workspaceRevisionValue, data) => ({
|
|
7890
6284
|
ok: true,
|
|
7891
6285
|
schemaVersion: 1,
|
|
7892
6286
|
revision: revisionValue,
|
|
@@ -7903,15 +6297,6 @@ var SCHEMA_VERSION = 1, POLICY_VERSION = "1.0.0", OPERATION_FAMILIES, uuidPatter
|
|
|
7903
6297
|
}, compareNullableText = (left, right) => left === right ? 0 : left === null ? -1 : right === null ? 1 : compareCodeUnits(left, right), compareBooleanNullable = (left, right) => left === right ? 0 : left === null ? -1 : right === null ? 1 : Number(left) - Number(right);
|
|
7904
6298
|
var init_task_contract = __esm(() => {
|
|
7905
6299
|
init_zod();
|
|
7906
|
-
OPERATION_FAMILIES = [
|
|
7907
|
-
"task",
|
|
7908
|
-
"policy",
|
|
7909
|
-
"evidence",
|
|
7910
|
-
"finding",
|
|
7911
|
-
"decision",
|
|
7912
|
-
"worker",
|
|
7913
|
-
"state"
|
|
7914
|
-
];
|
|
7915
6300
|
uuidPattern = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
|
|
7916
6301
|
digestPattern = /^[0-9a-f]{64}$/;
|
|
7917
6302
|
text = string2().check((ctx) => {
|
|
@@ -8469,7 +6854,6 @@ var init_task_contract = __esm(() => {
|
|
|
8469
6854
|
worker: advertised(workerOperations),
|
|
8470
6855
|
state: advertised(stateOperations)
|
|
8471
6856
|
};
|
|
8472
|
-
compiledOperationSchemas = Object.fromEntries(OPERATION_FAMILIES.map((family) => [family, compile(operationSchemas[family])]));
|
|
8473
6857
|
});
|
|
8474
6858
|
|
|
8475
6859
|
// packages/workit-core/src/git/rev.ts
|
|
@@ -18403,9 +16787,15 @@ var sessionMarkerFile = (input, session, store) => {
|
|
|
18403
16787
|
}
|
|
18404
16788
|
const name = createHash14("sha256").update(`${input.host}\x00${session}`).digest("hex").slice(0, 32);
|
|
18405
16789
|
return path20.join(dir, "hooks", `skills-${name}.json`);
|
|
18406
|
-
}, list2 = (value) => Array.isArray(value) ? value.filter((item) => typeof item === "string") : [],
|
|
16790
|
+
}, list2 = (value) => Array.isArray(value) ? value.filter((item) => typeof item === "string") : [], EMPTY, readRaw = (file) => {
|
|
18407
16791
|
try {
|
|
18408
|
-
|
|
16792
|
+
return fs16.readFileSync(file, "utf8");
|
|
16793
|
+
} catch {
|
|
16794
|
+
return "";
|
|
16795
|
+
}
|
|
16796
|
+
}, parseMarker = (text) => {
|
|
16797
|
+
try {
|
|
16798
|
+
const value = JSON.parse(text);
|
|
18409
16799
|
return {
|
|
18410
16800
|
nudged: list2(value.nudged),
|
|
18411
16801
|
loaded: list2(value.loaded),
|
|
@@ -18414,24 +16804,46 @@ var sessionMarkerFile = (input, session, store) => {
|
|
|
18414
16804
|
judges: list2(value.judges)
|
|
18415
16805
|
};
|
|
18416
16806
|
} catch {
|
|
18417
|
-
return {
|
|
16807
|
+
return { ...EMPTY };
|
|
16808
|
+
}
|
|
16809
|
+
}, readSessionMarker = (file) => parseMarker(readRaw(file)), writeAtomic = (file, marker) => {
|
|
16810
|
+
fs16.mkdirSync(path20.dirname(file), { recursive: true });
|
|
16811
|
+
const temp = `${file}.${process.pid}.${Math.random().toString(36).slice(2)}.tmp`;
|
|
16812
|
+
try {
|
|
16813
|
+
fs16.writeFileSync(temp, JSON.stringify(marker));
|
|
16814
|
+
fs16.renameSync(temp, file);
|
|
16815
|
+
} catch (error) {
|
|
16816
|
+
fs16.rmSync(temp, { force: true });
|
|
16817
|
+
throw error;
|
|
18418
16818
|
}
|
|
18419
16819
|
}, writeSessionMarker = (file, marker) => {
|
|
18420
16820
|
try {
|
|
18421
|
-
|
|
18422
|
-
|
|
16821
|
+
writeAtomic(file, marker);
|
|
16822
|
+
} catch {}
|
|
16823
|
+
}, updateSessionMarker = (file, change) => {
|
|
16824
|
+
try {
|
|
16825
|
+
for (let attempt = 0;attempt < 2; attempt++) {
|
|
16826
|
+
const before = readRaw(file);
|
|
16827
|
+
const next = change(parseMarker(before));
|
|
16828
|
+
if (attempt === 0 && readRaw(file) !== before)
|
|
16829
|
+
continue;
|
|
16830
|
+
writeAtomic(file, next);
|
|
16831
|
+
return;
|
|
16832
|
+
}
|
|
18423
16833
|
} catch {}
|
|
18424
16834
|
}, trackJudge = (input, agentId, running) => {
|
|
18425
16835
|
const session = input.session.id;
|
|
18426
16836
|
const file = session && agentId ? sessionMarkerFile(input, session) : null;
|
|
18427
16837
|
if (!file || !agentId)
|
|
18428
16838
|
return;
|
|
18429
|
-
|
|
18430
|
-
|
|
18431
|
-
|
|
16839
|
+
updateSessionMarker(file, (marker) => {
|
|
16840
|
+
const rest = marker.judges.filter((id) => id !== agentId);
|
|
16841
|
+
return { ...marker, judges: running ? [...rest, agentId] : rest };
|
|
16842
|
+
});
|
|
18432
16843
|
};
|
|
18433
16844
|
var init_session_marker = __esm(() => {
|
|
18434
16845
|
init_paths();
|
|
16846
|
+
EMPTY = { nudged: [], loaded: [], raw: [], stops: [], judges: [] };
|
|
18435
16847
|
});
|
|
18436
16848
|
|
|
18437
16849
|
// packages/workit-core/src/hooks/shell-words.ts
|
|
@@ -19941,8 +18353,8 @@ var NONE2, SHELLS, POWERSHELLS, EVALS, WRAPPERS, WRAPPER_VALUES, KEYWORDS, DECLA
|
|
|
19941
18353
|
}, nudgeFor = (action, host, session) => {
|
|
19942
18354
|
switch (action.kind) {
|
|
19943
18355
|
case "commit": {
|
|
19944
|
-
const
|
|
19945
|
-
return action.amend ? `workit: raw ${quote("git commit --amend")} is recorded for this session; for new commits prefer ${quote(`${
|
|
18356
|
+
const workit = host === "cursor" && session ? `workit --session ${session}` : "workit";
|
|
18357
|
+
return action.amend ? `workit: raw ${quote("git commit --amend")} is recorded for this session; for new commits prefer ${quote(`${workit} git commit -m '<msg>'`)} (adds the Workit-Session trailer and checks branch and commit policy).` : `workit: prefer ${quote(`${workit} git commit -m '<msg>' [--all | -- <paths>]`)}: it adds the Workit-Session trailer and checks branch and commit policy.`;
|
|
19946
18358
|
}
|
|
19947
18359
|
case "push":
|
|
19948
18360
|
return action.blindForce ? `workit: ${quote("git push --force")} overwrites without a lease; use ${quote("workit git push --force-with-lease")}.` : `workit: prefer ${quote("workit git push")}: it refuses protected branches and verifies the remote tip.`;
|
|
@@ -20447,7 +18859,7 @@ function claudeSettingsFiles(cwd, env, platform = process.platform) {
|
|
|
20447
18859
|
];
|
|
20448
18860
|
}
|
|
20449
18861
|
function claudeRules(cwd, env = process.env) {
|
|
20450
|
-
const rules =
|
|
18862
|
+
const rules = EMPTY2();
|
|
20451
18863
|
try {
|
|
20452
18864
|
for (const file of claudeSettingsFiles(cwd, env)) {
|
|
20453
18865
|
const text = readText2(file);
|
|
@@ -20486,7 +18898,7 @@ function claudeRules(cwd, env = process.env) {
|
|
|
20486
18898
|
return rules;
|
|
20487
18899
|
}
|
|
20488
18900
|
function opencodeRules(cwd, env = process.env) {
|
|
20489
|
-
const rules =
|
|
18901
|
+
const rules = EMPTY2();
|
|
20490
18902
|
try {
|
|
20491
18903
|
const config = env.XDG_CONFIG_HOME || path23.join(homeOf(env), ".config");
|
|
20492
18904
|
const files = [
|
|
@@ -20507,7 +18919,7 @@ function opencodeRules(cwd, env = process.env) {
|
|
|
20507
18919
|
return rules;
|
|
20508
18920
|
}
|
|
20509
18921
|
function codexRules(cwd, env = process.env) {
|
|
20510
|
-
const rules =
|
|
18922
|
+
const rules = EMPTY2();
|
|
20511
18923
|
try {
|
|
20512
18924
|
const home = env.CODEX_HOME || path23.join(homeOf(env), ".codex");
|
|
20513
18925
|
const top = gitTop(cwd) ?? cwd;
|
|
@@ -20536,7 +18948,7 @@ function codexRules(cwd, env = process.env) {
|
|
|
20536
18948
|
return rules;
|
|
20537
18949
|
}
|
|
20538
18950
|
function cursorRules(cwd, env = process.env) {
|
|
20539
|
-
const rules =
|
|
18951
|
+
const rules = EMPTY2();
|
|
20540
18952
|
try {
|
|
20541
18953
|
const top = gitTop(cwd) ?? cwd;
|
|
20542
18954
|
for (const file of [
|
|
@@ -20592,7 +19004,7 @@ function wrapAllowed(read, words, command, options = {}) {
|
|
|
20592
19004
|
return { ok: false, why: "allowlisted" };
|
|
20593
19005
|
return { ok: true };
|
|
20594
19006
|
}
|
|
20595
|
-
var
|
|
19007
|
+
var EMPTY2 = () => ({ deny: [], allow: [] }), readText2 = (file) => {
|
|
20596
19008
|
try {
|
|
20597
19009
|
return fs18.readFileSync(file, "utf8");
|
|
20598
19010
|
} catch (error) {
|
|
@@ -21886,7 +20298,7 @@ function stopDecision(input, descriptor) {
|
|
|
21886
20298
|
if (file && marker) {
|
|
21887
20299
|
if (marker.stops.includes(key))
|
|
21888
20300
|
return NONE4;
|
|
21889
|
-
|
|
20301
|
+
updateSessionMarker(file, (fresh) => ({ ...fresh, stops: [...fresh.stops, key] }));
|
|
21890
20302
|
}
|
|
21891
20303
|
return {
|
|
21892
20304
|
kind: "continue",
|
|
@@ -21965,24 +20377,28 @@ var NONE4, QUESTION, OFFER, YES_NO, LIST_ITEM, asksUser = (message) => {
|
|
|
21965
20377
|
kind: "checks",
|
|
21966
20378
|
reason: `PR #${pr}'s checks were last seen ${state} at ${short(head)}, and this workspace's endpoint is \`${endpoint}\`: run \`workit ci wait --pr ${pr}\`${state === "failing" ? " after fixing the failures `workit pr status` lists (then push)" : ""}.`
|
|
21967
20379
|
};
|
|
21968
|
-
},
|
|
20380
|
+
}, taskJudgment = (cwd) => {
|
|
21969
20381
|
try {
|
|
21970
20382
|
const store = new TaskStore(cwd);
|
|
21971
20383
|
const listed = store.listTaskIndex();
|
|
21972
20384
|
const key = store.currentKey();
|
|
21973
20385
|
if (!listed.ok || !key.ok)
|
|
21974
|
-
return
|
|
20386
|
+
return null;
|
|
21975
20387
|
const entry = listed.data.filter((item) => item.key === key.data.key && item.status !== "closed").toSorted((left, right) => right.updatedAt.localeCompare(left.updatedAt))[0];
|
|
21976
20388
|
const task = entry ? store.readTask(entry.id) : null;
|
|
21977
|
-
return task?.ok === true
|
|
20389
|
+
return task?.ok === true ? latestJudgment(task.data) : null;
|
|
21978
20390
|
} catch {
|
|
21979
|
-
return
|
|
20391
|
+
return null;
|
|
21980
20392
|
}
|
|
21981
20393
|
}, unverified = (cwd, branch, all, descriptor, verification) => {
|
|
21982
20394
|
const check = checkVerdicts(cwd, branch, all);
|
|
21983
20395
|
if (check.accepted.accepted || check.accepted.reasons.includes("failing_verdict"))
|
|
21984
20396
|
return null;
|
|
21985
|
-
const
|
|
20397
|
+
const judgment = taskJudgment(cwd);
|
|
20398
|
+
const high = judgment?.riskTier === "high";
|
|
20399
|
+
if (judgment && !judgment.behaviorChange && !high)
|
|
20400
|
+
return null;
|
|
20401
|
+
const independent = verification === "independent" || high;
|
|
21986
20402
|
if (!independent && check.review === "self-reviewed")
|
|
21987
20403
|
return null;
|
|
21988
20404
|
const has = check.review === "self-reviewed" ? "only a self verdict" : "no current verdict";
|
|
@@ -23586,7 +22002,7 @@ var init_cursor = __esm(() => {
|
|
|
23586
22002
|
};
|
|
23587
22003
|
},
|
|
23588
22004
|
render: render3,
|
|
23589
|
-
addendum: (input) => input.session.id ? `<workit-session>Cursor puts no session id in the shell:
|
|
22005
|
+
addendum: (input) => input.session.id ? `<workit-session>Cursor puts no session id in the shell: start workit commands that record authorship with the global flag \`--session ${input.session.id}\` (e.g. \`workit --session ${input.session.id} git commit -m …\`; a leading env assignment can miss the \`Shell(workit)\` allowlist). A verifier uses its own id, never this one.</workit-session>` : null
|
|
23590
22006
|
};
|
|
23591
22007
|
});
|
|
23592
22008
|
|