@kaisers-io/refs 0.1.3 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/refs.mjs +89 -363
- package/dist/refs.mjs +370 -0
- package/package.json +6 -4
package/bin/refs.mjs
CHANGED
|
@@ -1,370 +1,96 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
`)}const lt=e=>(t,n,r,i)=>{let a=r?{...r,async:!1}:{async:!1},o=t._zod.run({value:n,issues:[]},a);if(o instanceof Promise)throw new Se;if(o.issues.length){let t=new((i?.Err)??e)(o.issues.map(e=>D(e,a,S())));throw Fe(t,i?.callee),t}return o.value},ut=e=>async(t,n,r,i)=>{let a=r?{...r,async:!0}:{async:!0},o=t._zod.run({value:n,issues:[]},a);if(o instanceof Promise&&(o=await o),o.issues.length){let t=new((i?.Err)??e)(o.issues.map(e=>D(e,a,S())));throw Fe(t,i?.callee),t}return o.value},dt=e=>(t,n,r)=>{let i=r?{...r,async:!1}:{async:!1},a=t._zod.run({value:n,issues:[]},i);if(a instanceof Promise)throw new Se;return a.issues.length?{success:!1,error:new(e??it)(a.issues.map(e=>D(e,i,S())))}:{success:!0,data:a.value}},ft=dt(at),pt=e=>async(t,n,r)=>{let i=r?{...r,async:!0}:{async:!0},a=t._zod.run({value:n,issues:[]},i);return a instanceof Promise&&(a=await a),a.issues.length?{success:!1,error:new e(a.issues.map(e=>D(e,i,S())))}:{success:!0,data:a.value}},mt=pt(at),ht=e=>(t,n,r)=>{let i=r?{...r,direction:`backward`}:{direction:`backward`};return lt(e)(t,n,i)},gt=e=>(t,n,r)=>lt(e)(t,n,r),_t=e=>async(t,n,r)=>{let i=r?{...r,direction:`backward`}:{direction:`backward`};return ut(e)(t,n,i)},vt=e=>async(t,n,r)=>ut(e)(t,n,r),yt=e=>(t,n,r)=>{let i=r?{...r,direction:`backward`}:{direction:`backward`};return dt(e)(t,n,i)},bt=e=>(t,n,r)=>dt(e)(t,n,r),xt=e=>async(t,n,r)=>{let i=r?{...r,direction:`backward`}:{direction:`backward`};return pt(e)(t,n,i)},St=e=>async(t,n,r)=>pt(e)(t,n,r),Ct=/^[cC][0-9a-z]{6,}$/,wt=/^[0-9a-z]+$/,Tt=/^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/,Et=/^[0-9a-vA-V]{20}$/,Dt=/^[A-Za-z0-9]{27}$/,Ot=/^[a-zA-Z0-9_-]{21}$/,kt=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/,At=/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/,jt=e=>e?RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${e}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`):/^([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)$/,Mt=/^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/;function Nt(){return RegExp(`^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`,`u`)}const Pt=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,Ft=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$/,It=/^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/([0-9]|[1-2][0-9]|3[0-2])$/,Lt=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,Rt=/^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/,zt=/^[A-Za-z0-9_-]*$/,Bt=/^https?$/,Vt=/^\+[1-9]\d{6,14}$/,Ht=`(?:(?:\\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])))`,Ut=RegExp(`^${Ht}$`);function Wt(e){let t=`(?:[01]\\d|2[0-3]):[0-5]\\d`;return typeof e.precision==`number`?e.precision===-1?`${t}`:e.precision===0?`${t}:[0-5]\\d`:`${t}:[0-5]\\d\\.\\d{${e.precision}}`:`${t}(?::[0-5]\\d(?:\\.\\d+)?)?`}function Gt(e){return RegExp(`^${Wt(e)}$`)}function Kt(e){let t=Wt({precision:e.precision}),n=[`Z`];e.local&&n.push(``),e.offset&&n.push(`([+-](?:[01]\\d|2[0-3]):[0-5]\\d)`);let r=`${t}(?:${n.join(`|`)})`;return RegExp(`^${Ht}T(?:${r})$`)}const qt=e=>{let t=e?`[\\s\\S]{${e?.minimum??0},${e?.maximum??``}}`:`[\\s\\S]*`;return RegExp(`^${t}$`)},Jt=/^-?\d+$/,Yt=/^-?\d+(?:\.\d+)?$/,Xt=/^[^A-Z]*$/,Zt=/^[^a-z]*$/,k=x(`$ZodCheck`,(e,t)=>{var n;e._zod??={},e._zod.def=t,(n=e._zod).onattach??(n.onattach=[])}),Qt={number:`number`,bigint:`bigint`,object:`date`},$t=x(`$ZodCheckLessThan`,(e,t)=>{k.init(e,t);let n=Qt[typeof t.value];e._zod.onattach.push(e=>{let n=e._zod.bag,r=(t.inclusive?n.maximum:n.exclusiveMaximum)??1/0;t.value<r&&(t.inclusive?n.maximum=t.value:n.exclusiveMaximum=t.value)}),e._zod.check=r=>{(t.inclusive?r.value<=t.value:r.value<t.value)||r.issues.push({origin:n,code:`too_big`,maximum:typeof t.value==`object`?t.value.getTime():t.value,input:r.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),en=x(`$ZodCheckGreaterThan`,(e,t)=>{k.init(e,t);let n=Qt[typeof t.value];e._zod.onattach.push(e=>{let n=e._zod.bag,r=(t.inclusive?n.minimum:n.exclusiveMinimum)??-1/0;t.value>r&&(t.inclusive?n.minimum=t.value:n.exclusiveMinimum=t.value)}),e._zod.check=r=>{(t.inclusive?r.value>=t.value:r.value>t.value)||r.issues.push({origin:n,code:`too_small`,minimum:typeof t.value==`object`?t.value.getTime():t.value,input:r.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),tn=x(`$ZodCheckMultipleOf`,(e,t)=>{k.init(e,t),e._zod.onattach.push(e=>{var n;(n=e._zod.bag).multipleOf??(n.multipleOf=t.value)}),e._zod.check=n=>{if(typeof n.value!=typeof t.value)throw Error(`Cannot mix number and bigint in multiple_of check.`);(typeof n.value==`bigint`?n.value%t.value===BigInt(0):Ae(n.value,t.value)===0)||n.issues.push({origin:typeof n.value,code:`not_multiple_of`,divisor:t.value,input:n.value,inst:e,continue:!t.abort})}}),nn=x(`$ZodCheckNumberFormat`,(e,t)=>{k.init(e,t),t.format=t.format||`float64`;let n=t.format?.includes(`int`),r=n?`int`:`number`,[i,a]=Ue[t.format];e._zod.onattach.push(e=>{let r=e._zod.bag;r.format=t.format,r.minimum=i,r.maximum=a,n&&(r.pattern=Jt)}),e._zod.check=o=>{let s=o.value;if(n){if(!Number.isInteger(s)){o.issues.push({expected:r,format:t.format,code:`invalid_type`,continue:!1,input:s,inst:e});return}if(!Number.isSafeInteger(s)){s>0?o.issues.push({input:s,code:`too_big`,maximum:2**53-1,note:`Integers must be within the safe integer range.`,inst:e,origin:r,inclusive:!0,continue:!t.abort}):o.issues.push({input:s,code:`too_small`,minimum:-(2**53-1),note:`Integers must be within the safe integer range.`,inst:e,origin:r,inclusive:!0,continue:!t.abort});return}}s<i&&o.issues.push({origin:`number`,input:s,code:`too_small`,minimum:i,inclusive:!0,inst:e,continue:!t.abort}),s>a&&o.issues.push({origin:`number`,input:s,code:`too_big`,maximum:a,inclusive:!0,inst:e,continue:!t.abort})}}),rn=x(`$ZodCheckMaxLength`,(e,t)=>{var n;k.init(e,t),(n=e._zod.def).when??(n.when=e=>{let t=e.value;return!Oe(t)&&t.length!==void 0}),e._zod.onattach.push(e=>{let n=e._zod.bag.maximum??1/0;t.maximum<n&&(e._zod.bag.maximum=t.maximum)}),e._zod.check=n=>{let r=n.value;if(r.length<=t.maximum)return;let i=tt(r);n.issues.push({origin:i,code:`too_big`,maximum:t.maximum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),an=x(`$ZodCheckMinLength`,(e,t)=>{var n;k.init(e,t),(n=e._zod.def).when??(n.when=e=>{let t=e.value;return!Oe(t)&&t.length!==void 0}),e._zod.onattach.push(e=>{let n=e._zod.bag.minimum??-1/0;t.minimum>n&&(e._zod.bag.minimum=t.minimum)}),e._zod.check=n=>{let r=n.value;if(r.length>=t.minimum)return;let i=tt(r);n.issues.push({origin:i,code:`too_small`,minimum:t.minimum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),on=x(`$ZodCheckLengthEquals`,(e,t)=>{var n;k.init(e,t),(n=e._zod.def).when??(n.when=e=>{let t=e.value;return!Oe(t)&&t.length!==void 0}),e._zod.onattach.push(e=>{let n=e._zod.bag;n.minimum=t.length,n.maximum=t.length,n.length=t.length}),e._zod.check=n=>{let r=n.value,i=r.length;if(i===t.length)return;let a=tt(r),o=i>t.length;n.issues.push({origin:a,...o?{code:`too_big`,maximum:t.length}:{code:`too_small`,minimum:t.length},inclusive:!0,exact:!0,input:n.value,inst:e,continue:!t.abort})}}),sn=x(`$ZodCheckStringFormat`,(e,t)=>{var n,r;k.init(e,t),e._zod.onattach.push(e=>{let n=e._zod.bag;n.format=t.format,t.pattern&&(n.patterns??=new Set,n.patterns.add(t.pattern))}),t.pattern?(n=e._zod).check??(n.check=n=>{t.pattern.lastIndex=0,!t.pattern.test(n.value)&&n.issues.push({origin:`string`,code:`invalid_format`,format:t.format,input:n.value,...t.pattern?{pattern:t.pattern.toString()}:{},inst:e,continue:!t.abort})}):(r=e._zod).check??(r.check=()=>{})}),cn=x(`$ZodCheckRegex`,(e,t)=>{sn.init(e,t),e._zod.check=n=>{t.pattern.lastIndex=0,!t.pattern.test(n.value)&&n.issues.push({origin:`string`,code:`invalid_format`,format:`regex`,input:n.value,pattern:t.pattern.toString(),inst:e,continue:!t.abort})}}),ln=x(`$ZodCheckLowerCase`,(e,t)=>{t.pattern??=Xt,sn.init(e,t)}),un=x(`$ZodCheckUpperCase`,(e,t)=>{t.pattern??=Zt,sn.init(e,t)}),dn=x(`$ZodCheckIncludes`,(e,t)=>{k.init(e,t);let n=Ve(t.includes),r=new RegExp(typeof t.position==`number`?`^.{${t.position}}${n}`:n);t.pattern=r,e._zod.onattach.push(e=>{let t=e._zod.bag;t.patterns??=new Set,t.patterns.add(r)}),e._zod.check=n=>{n.value.includes(t.includes,t.position)||n.issues.push({origin:`string`,code:`invalid_format`,format:`includes`,includes:t.includes,input:n.value,inst:e,continue:!t.abort})}}),fn=x(`$ZodCheckStartsWith`,(e,t)=>{k.init(e,t);let n=RegExp(`^${Ve(t.prefix)}.*`);t.pattern??=n,e._zod.onattach.push(e=>{let t=e._zod.bag;t.patterns??=new Set,t.patterns.add(n)}),e._zod.check=n=>{n.value.startsWith(t.prefix)||n.issues.push({origin:`string`,code:`invalid_format`,format:`starts_with`,prefix:t.prefix,input:n.value,inst:e,continue:!t.abort})}}),pn=x(`$ZodCheckEndsWith`,(e,t)=>{k.init(e,t);let n=RegExp(`.*${Ve(t.suffix)}$`);t.pattern??=n,e._zod.onattach.push(e=>{let t=e._zod.bag;t.patterns??=new Set,t.patterns.add(n)}),e._zod.check=n=>{n.value.endsWith(t.suffix)||n.issues.push({origin:`string`,code:`invalid_format`,format:`ends_with`,suffix:t.suffix,input:n.value,inst:e,continue:!t.abort})}}),mn=x(`$ZodCheckOverwrite`,(e,t)=>{k.init(e,t),e._zod.check=e=>{e.value=t.tx(e.value)}});var hn=class{constructor(e=[]){this.content=[],this.indent=0,this&&(this.args=e)}indented(e){this.indent+=1,e(this),--this.indent}write(e){if(typeof e==`function`){e(this,{execution:`sync`}),e(this,{execution:`async`});return}let t=e.split(`
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
...iss,
|
|
10
|
-
path: iss.path ? [${o}, ...iss.path] : [${o}]
|
|
11
|
-
})));
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
if (${n}.value === undefined) {
|
|
16
|
-
if (${o} in input) {
|
|
17
|
-
newResult[${o}] = undefined;
|
|
18
|
-
}
|
|
19
|
-
} else {
|
|
20
|
-
newResult[${o}] = ${n}.value;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
`):c?t.write(`
|
|
24
|
-
if (${n}.issues.length) {
|
|
25
|
-
payload.issues = payload.issues.concat(${n}.issues.map(iss => ({
|
|
26
|
-
...iss,
|
|
27
|
-
path: iss.path ? [${o}, ...iss.path] : [${o}]
|
|
28
|
-
})));
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
if (${n}.value === undefined) {
|
|
32
|
-
if (${o} in input) {
|
|
33
|
-
newResult[${o}] = undefined;
|
|
34
|
-
}
|
|
35
|
-
} else {
|
|
36
|
-
newResult[${o}] = ${n}.value;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
`):t.write(`
|
|
40
|
-
const ${n}_present = ${o} in input;
|
|
41
|
-
if (${n}.issues.length) {
|
|
42
|
-
payload.issues = payload.issues.concat(${n}.issues.map(iss => ({
|
|
43
|
-
...iss,
|
|
44
|
-
path: iss.path ? [${o}, ...iss.path] : [${o}]
|
|
45
|
-
})));
|
|
46
|
-
}
|
|
47
|
-
if (!${n}_present && !${n}.issues.length) {
|
|
48
|
-
payload.issues.push({
|
|
49
|
-
code: "invalid_type",
|
|
50
|
-
expected: "nonoptional",
|
|
51
|
-
input: undefined,
|
|
52
|
-
path: [${o}]
|
|
53
|
-
});
|
|
54
|
-
}
|
|
2
|
+
// Committed stub — the published/linked `refs` executable. The real CLI is the tsdown
|
|
3
|
+
// bundle at ../dist/refs.mjs (gitignored build output; `pnpm build` produces it). This
|
|
4
|
+
// file exists so the bin path is always valid: a fresh clone gets an actionable message
|
|
5
|
+
// instead of a broken symlink and a shell-level "command not found".
|
|
6
|
+
import { existsSync } from 'node:fs';
|
|
7
|
+
import { join } from 'node:path';
|
|
8
|
+
import { pathToFileURL } from 'node:url';
|
|
55
9
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
newResult[${o}] = ${n}.value;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
10
|
+
const REQUIRED_NODE_MAJOR = 24;
|
|
11
|
+
const REQUIRED_NODE_MINOR_MIN = 12;
|
|
12
|
+
const EXIT_FAILURE = 1;
|
|
13
|
+
const FALLBACK_VERSION_PART = 0;
|
|
63
14
|
|
|
64
|
-
`)}t.write(`payload.value = newResult;`),t.write(`return payload;`);let s=t.compile();return(t,n)=>s(e,t,n)},a,o=Ie,s=!we.jitless,c=s&&Le.value,l=t.catchall,u;e._zod.parse=(d,f)=>{u??=r.value;let ee=d.value;return o(ee)?s&&c&&f?.async===!1&&f.jitless!==!0?(a||=i(t.shape),d=a(d,f),l?Qn([],ee,d,f,u,e):d):n(d,f):(d.issues.push({expected:`object`,code:`invalid_type`,input:ee,inst:e}),d)}});function tr(e,t,n,r){for(let n of e)if(n.issues.length===0)return t.value=n.value,t;let i=e.filter(e=>!Ze(e));return i.length===1?(t.value=i[0].value,i[0]):(t.issues.push({code:`invalid_union`,input:t.value,inst:n,errors:e.map(e=>e.issues.map(e=>D(e,r,S())))}),t)}const nr=x(`$ZodUnion`,(e,t)=>{A.init(e,t),C(e._zod,`optin`,()=>t.options.some(e=>e._zod.optin===`optional`)?`optional`:void 0),C(e._zod,`optout`,()=>t.options.some(e=>e._zod.optout===`optional`)?`optional`:void 0),C(e._zod,`values`,()=>{if(t.options.every(e=>e._zod.values))return new Set(t.options.flatMap(e=>Array.from(e._zod.values)))}),C(e._zod,`pattern`,()=>{if(t.options.every(e=>e._zod.pattern)){let e=t.options.map(e=>e._zod.pattern);return RegExp(`^(${e.map(e=>ke(e.source)).join(`|`)})$`)}});let n=t.options.length===1?t.options[0]._zod.run:null;e._zod.parse=(r,i)=>{if(n)return n(r,i);let a=!1,o=[];for(let e of t.options){let t=e._zod.run({value:r.value,issues:[]},i);if(t instanceof Promise)o.push(t),a=!0;else{if(t.issues.length===0)return t;o.push(t)}}return a?Promise.all(o).then(t=>tr(t,r,e,i)):tr(o,r,e,i)}}),rr=x(`$ZodIntersection`,(e,t)=>{A.init(e,t),e._zod.parse=(e,n)=>{let r=e.value,i=t.left._zod.run({value:r,issues:[]},n),a=t.right._zod.run({value:r,issues:[]},n);return i instanceof Promise||a instanceof Promise?Promise.all([i,a]).then(([t,n])=>ar(e,t,n)):ar(e,i,a)}});function ir(e,t){if(e===t||e instanceof Date&&t instanceof Date&&+e==+t)return{valid:!0,data:e};if(Re(e)&&Re(t)){let n=Object.keys(t),r=Object.keys(e).filter(e=>n.indexOf(e)!==-1),i={...e,...t};for(let n of r){let r=ir(e[n],t[n]);if(!r.valid)return{valid:!1,mergeErrorPath:[n,...r.mergeErrorPath]};i[n]=r.data}return{valid:!0,data:i}}if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return{valid:!1,mergeErrorPath:[]};let n=[];for(let r=0;r<e.length;r++){let i=e[r],a=t[r],o=ir(i,a);if(!o.valid)return{valid:!1,mergeErrorPath:[r,...o.mergeErrorPath]};n.push(o.data)}return{valid:!0,data:n}}return{valid:!1,mergeErrorPath:[]}}function ar(e,t,n){let r=new Map,i;for(let n of t.issues)if(n.code===`unrecognized_keys`){i??=n;for(let e of n.keys)r.has(e)||r.set(e,{}),r.get(e).l=!0}else e.issues.push(n);for(let t of n.issues)if(t.code===`unrecognized_keys`)for(let e of t.keys)r.has(e)||r.set(e,{}),r.get(e).r=!0;else e.issues.push(t);let a=[...r].filter(([,e])=>e.l&&e.r).map(([e])=>e);if(a.length&&i&&e.issues.push({...i,keys:a}),Ze(e))return e;let o=ir(t.value,n.value);if(!o.valid)throw Error(`Unmergable intersection. Error path: ${JSON.stringify(o.mergeErrorPath)}`);return e.value=o.data,e}const or=x(`$ZodRecord`,(e,t)=>{A.init(e,t),e._zod.parse=(n,r)=>{let i=n.value;if(!Re(i))return n.issues.push({expected:`record`,code:`invalid_type`,input:i,inst:e}),n;let a=[],o=t.keyType._zod.values;if(o){n.value={};let s=new Set;for(let c of o)if(typeof c==`string`||typeof c==`number`||typeof c==`symbol`){s.add(typeof c==`number`?c.toString():c);let o=t.keyType._zod.run({value:c,issues:[]},r);if(o instanceof Promise)throw Error(`Async schemas not supported in object keys currently`);if(o.issues.length){n.issues.push({code:`invalid_key`,origin:`record`,issues:o.issues.map(e=>D(e,r,S())),input:c,path:[c],inst:e});continue}let l=o.value,u=t.valueType._zod.run({value:i[c],issues:[]},r);u instanceof Promise?a.push(u.then(e=>{e.issues.length&&n.issues.push(...$e(c,e.issues)),n.value[l]=e.value})):(u.issues.length&&n.issues.push(...$e(c,u.issues)),n.value[l]=u.value)}let c;for(let e in i)s.has(e)||(c??=[],c.push(e));c&&c.length>0&&n.issues.push({code:`unrecognized_keys`,input:i,inst:e,keys:c})}else{n.value={};for(let o of Reflect.ownKeys(i)){if(o===`__proto__`||!Object.prototype.propertyIsEnumerable.call(i,o))continue;let s=t.keyType._zod.run({value:o,issues:[]},r);if(s instanceof Promise)throw Error(`Async schemas not supported in object keys currently`);if(typeof o==`string`&&Yt.test(o)&&s.issues.length){let e=t.keyType._zod.run({value:Number(o),issues:[]},r);if(e instanceof Promise)throw Error(`Async schemas not supported in object keys currently`);e.issues.length===0&&(s=e)}if(s.issues.length){t.mode===`loose`?n.value[o]=i[o]:n.issues.push({code:`invalid_key`,origin:`record`,issues:s.issues.map(e=>D(e,r,S())),input:o,path:[o],inst:e});continue}let c=t.valueType._zod.run({value:i[o],issues:[]},r);c instanceof Promise?a.push(c.then(e=>{e.issues.length&&n.issues.push(...$e(o,e.issues)),n.value[s.value]=e.value})):(c.issues.length&&n.issues.push(...$e(o,c.issues)),n.value[s.value]=c.value)}}return a.length?Promise.all(a).then(()=>n):n}}),sr=x(`$ZodEnum`,(e,t)=>{A.init(e,t);let n=Te(t.entries),r=new Set(n);e._zod.values=r,e._zod.pattern=RegExp(`^(${n.filter(e=>Be.has(typeof e)).map(e=>typeof e==`string`?Ve(e):e.toString()).join(`|`)})$`),e._zod.parse=(t,i)=>{let a=t.value;return r.has(a)||t.issues.push({code:`invalid_value`,values:n,input:a,inst:e}),t}}),cr=x(`$ZodTransform`,(e,t)=>{A.init(e,t),e._zod.optin=`optional`,e._zod.parse=(n,r)=>{if(r.direction===`backward`)throw new Ce(e.constructor.name);let i=t.transform(n.value,n);if(r.async)return(i instanceof Promise?i:Promise.resolve(i)).then(e=>(n.value=e,n.fallback=!0,n));if(i instanceof Promise)throw new Se;return n.value=i,n.fallback=!0,n}});function lr(e,t){return t===void 0&&(e.issues.length||e.fallback)?{issues:[],value:void 0}:e}const ur=x(`$ZodOptional`,(e,t)=>{A.init(e,t),e._zod.optin=`optional`,e._zod.optout=`optional`,C(e._zod,`values`,()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,void 0]):void 0),C(e._zod,`pattern`,()=>{let e=t.innerType._zod.pattern;return e?RegExp(`^(${ke(e.source)})?$`):void 0}),e._zod.parse=(e,n)=>{if(t.innerType._zod.optin===`optional`){let r=e.value,i=t.innerType._zod.run(e,n);return i instanceof Promise?i.then(e=>lr(e,r)):lr(i,r)}return e.value===void 0?e:t.innerType._zod.run(e,n)}}),dr=x(`$ZodExactOptional`,(e,t)=>{ur.init(e,t),C(e._zod,`values`,()=>t.innerType._zod.values),C(e._zod,`pattern`,()=>t.innerType._zod.pattern),e._zod.parse=(e,n)=>t.innerType._zod.run(e,n)}),fr=x(`$ZodNullable`,(e,t)=>{A.init(e,t),C(e._zod,`optin`,()=>t.innerType._zod.optin),C(e._zod,`optout`,()=>t.innerType._zod.optout),C(e._zod,`pattern`,()=>{let e=t.innerType._zod.pattern;return e?RegExp(`^(${ke(e.source)}|null)$`):void 0}),C(e._zod,`values`,()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,null]):void 0),e._zod.parse=(e,n)=>e.value===null?e:t.innerType._zod.run(e,n)}),pr=x(`$ZodDefault`,(e,t)=>{A.init(e,t),e._zod.optin=`optional`,C(e._zod,`values`,()=>t.innerType._zod.values),e._zod.parse=(e,n)=>{if(n.direction===`backward`)return t.innerType._zod.run(e,n);if(e.value===void 0)return e.value=t.defaultValue,e;let r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(e=>mr(e,t)):mr(r,t)}});function mr(e,t){return e.value===void 0&&(e.value=t.defaultValue),e}const hr=x(`$ZodPrefault`,(e,t)=>{A.init(e,t),e._zod.optin=`optional`,C(e._zod,`values`,()=>t.innerType._zod.values),e._zod.parse=(e,n)=>(n.direction===`backward`||e.value===void 0&&(e.value=t.defaultValue),t.innerType._zod.run(e,n))}),gr=x(`$ZodNonOptional`,(e,t)=>{A.init(e,t),C(e._zod,`values`,()=>{let e=t.innerType._zod.values;return e?new Set([...e].filter(e=>e!==void 0)):void 0}),e._zod.parse=(n,r)=>{let i=t.innerType._zod.run(n,r);return i instanceof Promise?i.then(t=>_r(t,e)):_r(i,e)}});function _r(e,t){return!e.issues.length&&e.value===void 0&&e.issues.push({code:`invalid_type`,expected:`nonoptional`,input:e.value,inst:t}),e}const vr=x(`$ZodCatch`,(e,t)=>{A.init(e,t),e._zod.optin=`optional`,C(e._zod,`optout`,()=>t.innerType._zod.optout),C(e._zod,`values`,()=>t.innerType._zod.values),e._zod.parse=(e,n)=>{if(n.direction===`backward`)return t.innerType._zod.run(e,n);let r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(r=>(e.value=r.value,r.issues.length&&(e.value=t.catchValue({...e,error:{issues:r.issues.map(e=>D(e,n,S()))},input:e.value}),e.issues=[],e.fallback=!0),e)):(e.value=r.value,r.issues.length&&(e.value=t.catchValue({...e,error:{issues:r.issues.map(e=>D(e,n,S()))},input:e.value}),e.issues=[],e.fallback=!0),e)}}),yr=x(`$ZodPipe`,(e,t)=>{A.init(e,t),C(e._zod,`values`,()=>t.in._zod.values),C(e._zod,`optin`,()=>t.in._zod.optin),C(e._zod,`optout`,()=>t.out._zod.optout),C(e._zod,`propValues`,()=>t.in._zod.propValues),e._zod.parse=(e,n)=>{if(n.direction===`backward`){let r=t.out._zod.run(e,n);return r instanceof Promise?r.then(e=>br(e,t.in,n)):br(r,t.in,n)}let r=t.in._zod.run(e,n);return r instanceof Promise?r.then(e=>br(e,t.out,n)):br(r,t.out,n)}});function br(e,t,n){return e.issues.length?(e.aborted=!0,e):t._zod.run({value:e.value,issues:e.issues,fallback:e.fallback},n)}const xr=x(`$ZodPreprocess`,(e,t)=>{yr.init(e,t)}),Sr=x(`$ZodReadonly`,(e,t)=>{A.init(e,t),C(e._zod,`propValues`,()=>t.innerType._zod.propValues),C(e._zod,`values`,()=>t.innerType._zod.values),C(e._zod,`optin`,()=>t.innerType?._zod?.optin),C(e._zod,`optout`,()=>t.innerType?._zod?.optout),e._zod.parse=(e,n)=>{if(n.direction===`backward`)return t.innerType._zod.run(e,n);let r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(Cr):Cr(r)}});function Cr(e){return e.value=Object.freeze(e.value),e}const wr=x(`$ZodCustom`,(e,t)=>{k.init(e,t),A.init(e,t),e._zod.parse=(e,t)=>e,e._zod.check=n=>{let r=n.value,i=t.fn(r);if(i instanceof Promise)return i.then(t=>Tr(t,n,r,e));Tr(i,n,r,e)}});function Tr(e,t,n,r){if(!e){let e={code:`custom`,input:n,inst:r,path:[...r._zod.def.path??[]],continue:!r._zod.def.abort};r._zod.def.params&&(e.params=r._zod.def.params),t.issues.push(nt(e))}}var Er,Dr=class{constructor(){this._map=new WeakMap,this._idmap=new Map}add(e,...t){let n=t[0];return this._map.set(e,n),n&&typeof n==`object`&&`id`in n&&this._idmap.set(n.id,e),this}clear(){return this._map=new WeakMap,this._idmap=new Map,this}remove(e){let t=this._map.get(e);return t&&typeof t==`object`&&`id`in t&&this._idmap.delete(t.id),this._map.delete(e),this}get(e){let t=e._zod.parent;if(t){let n={...this.get(t)??{}};delete n.id;let r={...n,...this._map.get(e)};return Object.keys(r).length?r:void 0}return this._map.get(e)}has(e){return this._map.has(e)}};function Or(){return new Dr}(Er=globalThis).__zod_globalRegistry??(Er.__zod_globalRegistry=Or());const kr=globalThis.__zod_globalRegistry;function Ar(e,t){return new e({type:`string`,...E(t)})}function jr(e,t){return new e({type:`string`,format:`email`,check:`string_format`,abort:!1,...E(t)})}function Mr(e,t){return new e({type:`string`,format:`guid`,check:`string_format`,abort:!1,...E(t)})}function Nr(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,...E(t)})}function Pr(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v4`,...E(t)})}function Fr(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v6`,...E(t)})}function Ir(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v7`,...E(t)})}function Lr(e,t){return new e({type:`string`,format:`url`,check:`string_format`,abort:!1,...E(t)})}function Rr(e,t){return new e({type:`string`,format:`emoji`,check:`string_format`,abort:!1,...E(t)})}function zr(e,t){return new e({type:`string`,format:`nanoid`,check:`string_format`,abort:!1,...E(t)})}function Br(e,t){return new e({type:`string`,format:`cuid`,check:`string_format`,abort:!1,...E(t)})}function Vr(e,t){return new e({type:`string`,format:`cuid2`,check:`string_format`,abort:!1,...E(t)})}function Hr(e,t){return new e({type:`string`,format:`ulid`,check:`string_format`,abort:!1,...E(t)})}function Ur(e,t){return new e({type:`string`,format:`xid`,check:`string_format`,abort:!1,...E(t)})}function Wr(e,t){return new e({type:`string`,format:`ksuid`,check:`string_format`,abort:!1,...E(t)})}function Gr(e,t){return new e({type:`string`,format:`ipv4`,check:`string_format`,abort:!1,...E(t)})}function Kr(e,t){return new e({type:`string`,format:`ipv6`,check:`string_format`,abort:!1,...E(t)})}function qr(e,t){return new e({type:`string`,format:`cidrv4`,check:`string_format`,abort:!1,...E(t)})}function Jr(e,t){return new e({type:`string`,format:`cidrv6`,check:`string_format`,abort:!1,...E(t)})}function Yr(e,t){return new e({type:`string`,format:`base64`,check:`string_format`,abort:!1,...E(t)})}function Xr(e,t){return new e({type:`string`,format:`base64url`,check:`string_format`,abort:!1,...E(t)})}function Zr(e,t){return new e({type:`string`,format:`e164`,check:`string_format`,abort:!1,...E(t)})}function Qr(e,t){return new e({type:`string`,format:`jwt`,check:`string_format`,abort:!1,...E(t)})}function $r(e,t){return new e({type:`string`,format:`datetime`,check:`string_format`,offset:!1,local:!1,precision:null,...E(t)})}function ei(e,t){return new e({type:`string`,format:`date`,check:`string_format`,...E(t)})}function ti(e,t){return new e({type:`string`,format:`time`,check:`string_format`,precision:null,...E(t)})}function ni(e,t){return new e({type:`string`,format:`duration`,check:`string_format`,...E(t)})}function ri(e,t){return new e({type:`number`,checks:[],...E(t)})}function ii(e,t){return new e({type:`number`,check:`number_format`,abort:!1,format:`safeint`,...E(t)})}function ai(e){return new e({type:`unknown`})}function oi(e,t){return new e({type:`never`,...E(t)})}function si(e,t){return new $t({check:`less_than`,...E(t),value:e,inclusive:!1})}function ci(e,t){return new $t({check:`less_than`,...E(t),value:e,inclusive:!0})}function li(e,t){return new en({check:`greater_than`,...E(t),value:e,inclusive:!1})}function ui(e,t){return new en({check:`greater_than`,...E(t),value:e,inclusive:!0})}function di(e,t){return new tn({check:`multiple_of`,...E(t),value:e})}function fi(e,t){return new rn({check:`max_length`,...E(t),maximum:e})}function pi(e,t){return new an({check:`min_length`,...E(t),minimum:e})}function mi(e,t){return new on({check:`length_equals`,...E(t),length:e})}function hi(e,t){return new cn({check:`string_format`,format:`regex`,...E(t),pattern:e})}function gi(e){return new ln({check:`string_format`,format:`lowercase`,...E(e)})}function _i(e){return new un({check:`string_format`,format:`uppercase`,...E(e)})}function vi(e,t){return new dn({check:`string_format`,format:`includes`,...E(t),includes:e})}function yi(e,t){return new fn({check:`string_format`,format:`starts_with`,...E(t),prefix:e})}function bi(e,t){return new pn({check:`string_format`,format:`ends_with`,...E(t),suffix:e})}function xi(e){return new mn({check:`overwrite`,tx:e})}function Si(e){return xi(t=>t.normalize(e))}function Ci(){return xi(e=>e.trim())}function wi(){return xi(e=>e.toLowerCase())}function Ti(){return xi(e=>e.toUpperCase())}function Ei(){return xi(e=>Pe(e))}function Di(e,t,n){return new e({type:`array`,element:t,...E(n)})}function Oi(e,t,n){return new e({type:`custom`,check:`custom`,fn:t,...E(n)})}function ki(e,t){let n=Ai(t=>(t.addIssue=e=>{if(typeof e==`string`)t.issues.push(nt(e,t.value,n._zod.def));else{let r=e;r.fatal&&(r.continue=!1),r.code??=`custom`,r.input??=t.value,r.inst??=n,r.continue??=!n._zod.def.abort,t.issues.push(nt(r))}},e(t.value,t)),t);return n}function Ai(e,t){let n=new k({check:`custom`,...E(t)});return n._zod.check=e,n}function ji(e){let t=e?.target??`draft-2020-12`;return t===`draft-4`&&(t=`draft-04`),t===`draft-7`&&(t=`draft-07`),{processors:e.processors??{},metadataRegistry:e?.metadata??kr,target:t,unrepresentable:e?.unrepresentable??`throw`,override:e?.override??(()=>{}),io:e?.io??`output`,counter:0,seen:new Map,cycles:e?.cycles??`ref`,reused:e?.reused??`inline`,external:e?.external??void 0}}function M(e,t,n={path:[],schemaPath:[]}){var r;let i=e._zod.def,a=t.seen.get(e);if(a)return a.count++,n.schemaPath.includes(e)&&(a.cycle=n.path),a.schema;let o={schema:{},count:1,cycle:void 0,path:n.path};t.seen.set(e,o);let s=e._zod.toJSONSchema?.();if(s)o.schema=s;else{let r={...n,schemaPath:[...n.schemaPath,e],path:n.path};if(e._zod.processJSONSchema)e._zod.processJSONSchema(t,o.schema,r);else{let n=o.schema,a=t.processors[i.type];if(!a)throw Error(`[toJSONSchema]: Non-representable type encountered: ${i.type}`);a(e,t,n,r)}let a=e._zod.parent;a&&(o.ref||=a,M(a,t,r),t.seen.get(a).isParent=!0)}let c=t.metadataRegistry.get(e);return c&&Object.assign(o.schema,c),t.io===`input`&&N(e)&&(delete o.schema.examples,delete o.schema.default),t.io===`input`&&`_prefault`in o.schema&&((r=o.schema).default??(r.default=o.schema._prefault)),delete o.schema._prefault,t.seen.get(e).schema}function Mi(e,t){let n=e.seen.get(t);if(!n)throw Error(`Unprocessed schema. This is a bug in Zod.`);let r=new Map;for(let t of e.seen.entries()){let n=e.metadataRegistry.get(t[0])?.id;if(n){let e=r.get(n);if(e&&e!==t[0])throw Error(`Duplicate schema id "${n}" detected during JSON Schema conversion. Two different schemas cannot share the same id when converted together.`);r.set(n,t[0])}}let i=t=>{let r=e.target===`draft-2020-12`?`$defs`:`definitions`;if(e.external){let n=e.external.registry.get(t[0])?.id,i=e.external.uri??(e=>e);if(n)return{ref:i(n)};let a=t[1].defId??t[1].schema.id??`schema${e.counter++}`;return t[1].defId=a,{defId:a,ref:`${i(`__shared`)}#/${r}/${a}`}}if(t[1]===n)return{ref:`#`};let i=`#/${r}/`,a=t[1].schema.id??`__schema${e.counter++}`;return{defId:a,ref:i+a}},a=e=>{if(e[1].schema.$ref)return;let t=e[1],{ref:n,defId:r}=i(e);t.def={...t.schema},r&&(t.defId=r);let a=t.schema;for(let e in a)delete a[e];a.$ref=n};if(e.cycles===`throw`)for(let t of e.seen.entries()){let e=t[1];if(e.cycle)throw Error(`Cycle detected: #/${e.cycle?.join(`/`)}/<root>
|
|
15
|
+
// Node error codes a broken/un-installed source tree can realistically throw when the stub
|
|
16
|
+
// tries `await import(...)` on src/main.ts or src/context.ts: missing workspace deps (no
|
|
17
|
+
// `pnpm install`), TypeScript syntax Node's type stripping can't erase, or an extension Node
|
|
18
|
+
// refuses to load as a module.
|
|
19
|
+
const SOURCE_LOAD_ERROR_CODES = new Set([
|
|
20
|
+
'ERR_MODULE_NOT_FOUND',
|
|
21
|
+
'ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX',
|
|
22
|
+
'ERR_UNKNOWN_FILE_EXTENSION',
|
|
23
|
+
]);
|
|
65
24
|
|
|
66
|
-
Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`)}for(let n of e.seen.entries()){let r=n[1];if(t===n[0]){a(n);continue}if(e.external){let r=e.external.registry.get(n[0])?.id;if(t!==n[0]&&r){a(n);continue}}if(e.metadataRegistry.get(n[0])?.id){a(n);continue}if(r.cycle){a(n);continue}if(r.count>1&&e.reused===`ref`){a(n);continue}}}function Ni(e,t){let n=e.seen.get(t);if(!n)throw Error(`Unprocessed schema. This is a bug in Zod.`);let r=t=>{let n=e.seen.get(t);if(n.ref===null)return;let i=n.def??n.schema,a={...i},o=n.ref;if(n.ref=null,o){r(o);let n=e.seen.get(o),s=n.schema;if(s.$ref&&(e.target===`draft-07`||e.target===`draft-04`||e.target===`openapi-3.0`)?(i.allOf=i.allOf??[],i.allOf.push(s)):Object.assign(i,s),Object.assign(i,a),t._zod.parent===o)for(let e in i)e===`$ref`||e===`allOf`||e in a||delete i[e];if(s.$ref&&n.def)for(let e in i)e===`$ref`||e===`allOf`||e in n.def&&JSON.stringify(i[e])===JSON.stringify(n.def[e])&&delete i[e]}let s=t._zod.parent;if(s&&s!==o){r(s);let t=e.seen.get(s);if(t?.schema.$ref&&(i.$ref=t.schema.$ref,t.def))for(let e in i)e===`$ref`||e===`allOf`||e in t.def&&JSON.stringify(i[e])===JSON.stringify(t.def[e])&&delete i[e]}e.override({zodSchema:t,jsonSchema:i,path:n.path??[]})};for(let t of[...e.seen.entries()].reverse())r(t[0]);let i={};if(e.target===`draft-2020-12`?i.$schema=`https://json-schema.org/draft/2020-12/schema`:e.target===`draft-07`?i.$schema=`http://json-schema.org/draft-07/schema#`:e.target===`draft-04`?i.$schema=`http://json-schema.org/draft-04/schema#`:e.target,e.external?.uri){let n=e.external.registry.get(t)?.id;if(!n)throw Error("Schema is missing an `id` property");i.$id=e.external.uri(n)}Object.assign(i,n.def??n.schema);let a=e.metadataRegistry.get(t)?.id;a!==void 0&&i.id===a&&delete i.id;let o=e.external?.defs??{};for(let t of e.seen.entries()){let e=t[1];e.def&&e.defId&&(e.def.id===e.defId&&delete e.def.id,o[e.defId]=e.def)}e.external||Object.keys(o).length>0&&(e.target===`draft-2020-12`?i.$defs=o:i.definitions=o);try{let n=JSON.parse(JSON.stringify(i));return Object.defineProperty(n,"~standard",{value:{...t[`~standard`],jsonSchema:{input:Fi(t,`input`,e.processors),output:Fi(t,`output`,e.processors)}},enumerable:!1,writable:!1}),n}catch{throw Error(`Error converting schema to JSON.`)}}function N(e,t){let n=t??{seen:new Set};if(n.seen.has(e))return!1;n.seen.add(e);let r=e._zod.def;if(r.type===`transform`)return!0;if(r.type===`array`)return N(r.element,n);if(r.type===`set`)return N(r.valueType,n);if(r.type===`lazy`)return N(r.getter(),n);if(r.type===`promise`||r.type===`optional`||r.type===`nonoptional`||r.type===`nullable`||r.type===`readonly`||r.type==="default"||r.type===`prefault`)return N(r.innerType,n);if(r.type===`intersection`)return N(r.left,n)||N(r.right,n);if(r.type===`record`||r.type===`map`)return N(r.keyType,n)||N(r.valueType,n);if(r.type===`pipe`)return e._zod.traits.has(`$ZodCodec`)?!0:N(r.in,n)||N(r.out,n);if(r.type===`object`){for(let e in r.shape)if(N(r.shape[e],n))return!0;return!1}if(r.type===`union`){for(let e of r.options)if(N(e,n))return!0;return!1}if(r.type===`tuple`){for(let e of r.items)if(N(e,n))return!0;return!!(r.rest&&N(r.rest,n))}return!1}const Pi=(e,t={})=>n=>{let r=ji({...n,processors:t});return M(e,r),Mi(r,e),Ni(r,e)},Fi=(e,t,n={})=>r=>{let{libraryOptions:i,target:a}=r??{},o=ji({...i??{},target:a,io:t,processors:n});return M(e,o),Mi(o,e),Ni(o,e)},Ii={guid:`uuid`,url:`uri`,datetime:`date-time`,json_string:`json-string`,regex:``},Li=(e,t,n,r)=>{let i=n;i.type=`string`;let{minimum:a,maximum:o,format:s,patterns:c,contentEncoding:l}=e._zod.bag;if(typeof a==`number`&&(i.minLength=a),typeof o==`number`&&(i.maxLength=o),s&&(i.format=Ii[s]??s,i.format===``&&delete i.format,s===`time`&&delete i.format),l&&(i.contentEncoding=l),c&&c.size>0){let e=[...c];e.length===1?i.pattern=e[0].source:e.length>1&&(i.allOf=[...e.map(e=>({...t.target===`draft-07`||t.target===`draft-04`||t.target===`openapi-3.0`?{type:`string`}:{},pattern:e.source}))])}},Ri=(e,t,n,r)=>{let i=n,{minimum:a,maximum:o,format:s,multipleOf:c,exclusiveMaximum:l,exclusiveMinimum:u}=e._zod.bag;typeof s==`string`&&s.includes(`int`)?i.type=`integer`:i.type=`number`;let d=typeof u==`number`&&u>=(a??-1/0),f=typeof l==`number`&&l<=(o??1/0),ee=t.target===`draft-04`||t.target===`openapi-3.0`;d?ee?(i.minimum=u,i.exclusiveMinimum=!0):i.exclusiveMinimum=u:typeof a==`number`&&(i.minimum=a),f?ee?(i.maximum=l,i.exclusiveMaximum=!0):i.exclusiveMaximum=l:typeof o==`number`&&(i.maximum=o),typeof c==`number`&&(i.multipleOf=c)},zi=(e,t,n,r)=>{n.not={}},Bi=(e,t,n,r)=>{let i=e._zod.def,a=Te(i.entries);a.every(e=>typeof e==`number`)&&(n.type=`number`),a.every(e=>typeof e==`string`)&&(n.type=`string`),n.enum=a},Vi=(e,t,n,r)=>{if(t.unrepresentable===`throw`)throw Error(`Custom types cannot be represented in JSON Schema`)},Hi=(e,t,n,r)=>{if(t.unrepresentable===`throw`)throw Error(`Transforms cannot be represented in JSON Schema`)},Ui=(e,t,n,r)=>{let i=n,a=e._zod.def,{minimum:o,maximum:s}=e._zod.bag;typeof o==`number`&&(i.minItems=o),typeof s==`number`&&(i.maxItems=s),i.type=`array`,i.items=M(a.element,t,{...r,path:[...r.path,`items`]})},Wi=(e,t,n,r)=>{let i=n,a=e._zod.def;i.type=`object`,i.properties={};let o=a.shape;for(let e in o)i.properties[e]=M(o[e],t,{...r,path:[...r.path,`properties`,e]});let s=new Set(Object.keys(o)),c=new Set([...s].filter(e=>{let n=a.shape[e]._zod;return t.io===`input`?n.optin===void 0:n.optout===void 0}));c.size>0&&(i.required=Array.from(c)),a.catchall?._zod.def.type===`never`?i.additionalProperties=!1:a.catchall?a.catchall&&(i.additionalProperties=M(a.catchall,t,{...r,path:[...r.path,`additionalProperties`]})):t.io===`output`&&(i.additionalProperties=!1)},Gi=(e,t,n,r)=>{let i=e._zod.def,a=i.inclusive===!1,o=i.options.map((e,n)=>M(e,t,{...r,path:[...r.path,a?`oneOf`:`anyOf`,n]}));a?n.oneOf=o:n.anyOf=o},Ki=(e,t,n,r)=>{let i=e._zod.def,a=M(i.left,t,{...r,path:[...r.path,`allOf`,0]}),o=M(i.right,t,{...r,path:[...r.path,`allOf`,1]}),s=e=>`allOf`in e&&Object.keys(e).length===1;n.allOf=[...s(a)?a.allOf:[a],...s(o)?o.allOf:[o]]},qi=(e,t,n,r)=>{let i=n,a=e._zod.def;i.type=`object`;let o=a.keyType,s=o._zod.bag?.patterns;if(a.mode===`loose`&&s&&s.size>0){let e=M(a.valueType,t,{...r,path:[...r.path,`patternProperties`,`*`]});i.patternProperties={};for(let t of s)i.patternProperties[t.source]=e}else(t.target===`draft-07`||t.target===`draft-2020-12`)&&(i.propertyNames=M(a.keyType,t,{...r,path:[...r.path,`propertyNames`]})),i.additionalProperties=M(a.valueType,t,{...r,path:[...r.path,`additionalProperties`]});let c=o._zod.values;if(c){let e=[...c].filter(e=>typeof e==`string`||typeof e==`number`);e.length>0&&(i.required=e)}},Ji=(e,t,n,r)=>{let i=e._zod.def,a=M(i.innerType,t,r),o=t.seen.get(e);t.target===`openapi-3.0`?(o.ref=i.innerType,n.nullable=!0):n.anyOf=[a,{type:`null`}]},Yi=(e,t,n,r)=>{let i=e._zod.def;M(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType},Xi=(e,t,n,r)=>{let i=e._zod.def;M(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType,n.default=JSON.parse(JSON.stringify(i.defaultValue))},Zi=(e,t,n,r)=>{let i=e._zod.def;M(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType,t.io===`input`&&(n._prefault=JSON.parse(JSON.stringify(i.defaultValue)))},Qi=(e,t,n,r)=>{let i=e._zod.def;M(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType;let o;try{o=i.catchValue(void 0)}catch{throw Error(`Dynamic catch values are not supported in JSON Schema`)}n.default=o},$i=(e,t,n,r)=>{let i=e._zod.def,a=i.in._zod.traits.has(`$ZodTransform`),o=t.io===`input`?a?i.out:i.in:i.out;M(o,t,r);let s=t.seen.get(e);s.ref=o},ea=(e,t,n,r)=>{let i=e._zod.def;M(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType,n.readOnly=!0},ta=(e,t,n,r)=>{let i=e._zod.def;M(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType},na=x(`ZodISODateTime`,(e,t)=>{kn.init(e,t),L.init(e,t)});function ra(e){return $r(na,e)}const ia=x(`ZodISODate`,(e,t)=>{An.init(e,t),L.init(e,t)});function aa(e){return ei(ia,e)}const oa=x(`ZodISOTime`,(e,t)=>{jn.init(e,t),L.init(e,t)});function sa(e){return ti(oa,e)}const ca=x(`ZodISODuration`,(e,t)=>{Mn.init(e,t),L.init(e,t)});function la(e){return ni(ca,e)}const P=x(`ZodError`,(e,t)=>{it.init(e,t),e.name=`ZodError`,Object.defineProperties(e,{format:{value:t=>st(e,t)},flatten:{value:t=>ot(e,t)},addIssue:{value:t=>{e.issues.push(t),e.message=JSON.stringify(e.issues,Ee,2)}},addIssues:{value:t=>{e.issues.push(...t),e.message=JSON.stringify(e.issues,Ee,2)}},isEmpty:{get(){return e.issues.length===0}}})},{Parent:Error}),ua=lt(P),da=ut(P),fa=dt(P),pa=pt(P),ma=ht(P),ha=gt(P),ga=_t(P),_a=vt(P),va=yt(P),ya=bt(P),ba=xt(P),xa=St(P),Sa=new WeakMap;function Ca(e,t,n){let r=Object.getPrototypeOf(e),i=Sa.get(r);if(i||(i=new Set,Sa.set(r,i)),!i.has(t)){i.add(t);for(let e in n){let t=n[e];Object.defineProperty(r,e,{configurable:!0,enumerable:!1,get(){let n=t.bind(this);return Object.defineProperty(this,e,{configurable:!0,writable:!0,enumerable:!0,value:n}),n},set(t){Object.defineProperty(this,e,{configurable:!0,writable:!0,enumerable:!0,value:t})}})}}}const F=x(`ZodType`,(e,t)=>(A.init(e,t),Object.assign(e[`~standard`],{jsonSchema:{input:Fi(e,`input`),output:Fi(e,`output`)}}),e.toJSONSchema=Pi(e,{}),e.def=t,e.type=t.type,Object.defineProperty(e,"_def",{value:t}),e.parse=(t,n)=>ua(e,t,n,{callee:e.parse}),e.safeParse=(t,n)=>fa(e,t,n),e.parseAsync=async(t,n)=>da(e,t,n,{callee:e.parseAsync}),e.safeParseAsync=async(t,n)=>pa(e,t,n),e.spa=e.safeParseAsync,e.encode=(t,n)=>ma(e,t,n),e.decode=(t,n)=>ha(e,t,n),e.encodeAsync=async(t,n)=>ga(e,t,n),e.decodeAsync=async(t,n)=>_a(e,t,n),e.safeEncode=(t,n)=>va(e,t,n),e.safeDecode=(t,n)=>ya(e,t,n),e.safeEncodeAsync=async(t,n)=>ba(e,t,n),e.safeDecodeAsync=async(t,n)=>xa(e,t,n),Ca(e,`ZodType`,{check(...e){let t=this.def;return this.clone(w(t,{checks:[...t.checks??[],...e.map(e=>typeof e==`function`?{_zod:{check:e,def:{check:`custom`},onattach:[]}}:e)]}),{parent:!0})},with(...e){return this.check(...e)},clone(e,t){return T(this,e,t)},brand(){return this},register(e,t){return e.add(this,t),this},refine(e,t){return this.check(Po(e,t))},superRefine(e,t){return this.check(Fo(e,t))},overwrite(e){return this.check(xi(e))},optional(){return ho(this)},exactOptional(){return _o(this)},nullable(){return yo(this)},nullish(){return ho(yo(this))},nonoptional(e){return To(this,e)},array(){return eo(this)},or(e){return io([this,e])},and(e){return oo(this,e)},transform(e){return ko(this,po(e))},default(e){return xo(this,e)},prefault(e){return Co(this,e)},catch(e){return Do(this,e)},pipe(e){return ko(this,e)},readonly(){return Mo(this)},describe(e){let t=this.clone();return kr.add(t,{description:e}),t},meta(...e){if(e.length===0)return kr.get(this);let t=this.clone();return kr.add(t,e[0]),t},isOptional(){return this.safeParse(void 0).success},isNullable(){return this.safeParse(null).success},apply(e){return e(this)}}),Object.defineProperty(e,"description",{get(){return kr.get(e)?.description},configurable:!0}),e)),wa=x(`_ZodString`,(e,t)=>{_n.init(e,t),F.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Li(e,t,n,r);let n=e._zod.bag;e.format=n.format??null,e.minLength=n.minimum??null,e.maxLength=n.maximum??null,Ca(e,`_ZodString`,{regex(...e){return this.check(hi(...e))},includes(...e){return this.check(vi(...e))},startsWith(...e){return this.check(yi(...e))},endsWith(...e){return this.check(bi(...e))},min(...e){return this.check(pi(...e))},max(...e){return this.check(fi(...e))},length(...e){return this.check(mi(...e))},nonempty(...e){return this.check(pi(1,...e))},lowercase(e){return this.check(gi(e))},uppercase(e){return this.check(_i(e))},trim(){return this.check(Ci())},normalize(...e){return this.check(Si(...e))},toLowerCase(){return this.check(wi())},toUpperCase(){return this.check(Ti())},slugify(){return this.check(Ei())}})}),Ta=x(`ZodString`,(e,t)=>{_n.init(e,t),wa.init(e,t),e.email=t=>e.check(jr(Ea,t)),e.url=t=>e.check(Lr(ka,t)),e.jwt=t=>e.check(Qr(Wa,t)),e.emoji=t=>e.check(Rr(Aa,t)),e.guid=t=>e.check(Mr(Da,t)),e.uuid=t=>e.check(Nr(Oa,t)),e.uuidv4=t=>e.check(Pr(Oa,t)),e.uuidv6=t=>e.check(Fr(Oa,t)),e.uuidv7=t=>e.check(Ir(Oa,t)),e.nanoid=t=>e.check(zr(ja,t)),e.guid=t=>e.check(Mr(Da,t)),e.cuid=t=>e.check(Br(Ma,t)),e.cuid2=t=>e.check(Vr(Na,t)),e.ulid=t=>e.check(Hr(Pa,t)),e.base64=t=>e.check(Yr(Va,t)),e.base64url=t=>e.check(Xr(Ha,t)),e.xid=t=>e.check(Ur(Fa,t)),e.ksuid=t=>e.check(Wr(Ia,t)),e.ipv4=t=>e.check(Gr(La,t)),e.ipv6=t=>e.check(Kr(Ra,t)),e.cidrv4=t=>e.check(qr(za,t)),e.cidrv6=t=>e.check(Jr(Ba,t)),e.e164=t=>e.check(Zr(Ua,t)),e.datetime=t=>e.check(ra(t)),e.date=t=>e.check(aa(t)),e.time=t=>e.check(sa(t)),e.duration=t=>e.check(la(t))});function I(e){return Ar(Ta,e)}const L=x(`ZodStringFormat`,(e,t)=>{j.init(e,t),wa.init(e,t)}),Ea=x(`ZodEmail`,(e,t)=>{bn.init(e,t),L.init(e,t)}),Da=x(`ZodGUID`,(e,t)=>{vn.init(e,t),L.init(e,t)}),Oa=x(`ZodUUID`,(e,t)=>{yn.init(e,t),L.init(e,t)}),ka=x(`ZodURL`,(e,t)=>{xn.init(e,t),L.init(e,t)}),Aa=x(`ZodEmoji`,(e,t)=>{Sn.init(e,t),L.init(e,t)}),ja=x(`ZodNanoID`,(e,t)=>{Cn.init(e,t),L.init(e,t)}),Ma=x(`ZodCUID`,(e,t)=>{wn.init(e,t),L.init(e,t)}),Na=x(`ZodCUID2`,(e,t)=>{Tn.init(e,t),L.init(e,t)}),Pa=x(`ZodULID`,(e,t)=>{En.init(e,t),L.init(e,t)}),Fa=x(`ZodXID`,(e,t)=>{Dn.init(e,t),L.init(e,t)}),Ia=x(`ZodKSUID`,(e,t)=>{On.init(e,t),L.init(e,t)}),La=x(`ZodIPv4`,(e,t)=>{Nn.init(e,t),L.init(e,t)}),Ra=x(`ZodIPv6`,(e,t)=>{Pn.init(e,t),L.init(e,t)}),za=x(`ZodCIDRv4`,(e,t)=>{Fn.init(e,t),L.init(e,t)}),Ba=x(`ZodCIDRv6`,(e,t)=>{In.init(e,t),L.init(e,t)}),Va=x(`ZodBase64`,(e,t)=>{Rn.init(e,t),L.init(e,t)}),Ha=x(`ZodBase64URL`,(e,t)=>{Bn.init(e,t),L.init(e,t)}),Ua=x(`ZodE164`,(e,t)=>{Vn.init(e,t),L.init(e,t)}),Wa=x(`ZodJWT`,(e,t)=>{Un.init(e,t),L.init(e,t)}),Ga=x(`ZodNumber`,(e,t)=>{Wn.init(e,t),F.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ri(e,t,n,r),Ca(e,`ZodNumber`,{gt(e,t){return this.check(li(e,t))},gte(e,t){return this.check(ui(e,t))},min(e,t){return this.check(ui(e,t))},lt(e,t){return this.check(si(e,t))},lte(e,t){return this.check(ci(e,t))},max(e,t){return this.check(ci(e,t))},int(e){return this.check(Ja(e))},safe(e){return this.check(Ja(e))},positive(e){return this.check(li(0,e))},nonnegative(e){return this.check(ui(0,e))},negative(e){return this.check(si(0,e))},nonpositive(e){return this.check(ci(0,e))},multipleOf(e,t){return this.check(di(e,t))},step(e,t){return this.check(di(e,t))},finite(){return this}});let n=e._zod.bag;e.minValue=Math.max(n.minimum??-1/0,n.exclusiveMinimum??-1/0)??null,e.maxValue=Math.min(n.maximum??1/0,n.exclusiveMaximum??1/0)??null,e.isInt=(n.format??``).includes(`int`)||Number.isSafeInteger(n.multipleOf??.5),e.isFinite=!0,e.format=n.format??null});function Ka(e){return ri(Ga,e)}const qa=x(`ZodNumberFormat`,(e,t)=>{Gn.init(e,t),Ga.init(e,t)});function Ja(e){return ii(qa,e)}const Ya=x(`ZodUnknown`,(e,t)=>{Kn.init(e,t),F.init(e,t),e._zod.processJSONSchema=(e,t,n)=>void 0});function Xa(){return ai(Ya)}const Za=x(`ZodNever`,(e,t)=>{qn.init(e,t),F.init(e,t),e._zod.processJSONSchema=(t,n,r)=>zi(e,t,n,r)});function Qa(e){return oi(Za,e)}const $a=x(`ZodArray`,(e,t)=>{Yn.init(e,t),F.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ui(e,t,n,r),e.element=t.element,Ca(e,`ZodArray`,{min(e,t){return this.check(pi(e,t))},nonempty(e){return this.check(pi(1,e))},max(e,t){return this.check(fi(e,t))},length(e,t){return this.check(mi(e,t))},unwrap(){return this.element}})});function eo(e,t){return Di($a,e,t)}const to=x(`ZodObject`,(e,t)=>{er.init(e,t),F.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Wi(e,t,n,r),C(e,`shape`,()=>t.shape),Ca(e,`ZodObject`,{keyof(){return uo(Object.keys(this._zod.def.shape))},catchall(e){return this.clone({...this._zod.def,catchall:e})},passthrough(){return this.clone({...this._zod.def,catchall:Xa()})},loose(){return this.clone({...this._zod.def,catchall:Xa()})},strict(){return this.clone({...this._zod.def,catchall:Qa()})},strip(){return this.clone({...this._zod.def,catchall:void 0})},extend(e){return Ke(this,e)},safeExtend(e){return qe(this,e)},merge(e){return Je(this,e)},pick(e){return We(this,e)},omit(e){return Ge(this,e)},partial(...e){return Ye(mo,this,e[0])},required(...e){return Xe(wo,this,e[0])}})});function R(e,t){return new to({type:`object`,shape:e,catchall:Qa(),...E(t)})}function no(e,t){return new to({type:`object`,shape:e,catchall:Xa(),...E(t)})}const ro=x(`ZodUnion`,(e,t)=>{nr.init(e,t),F.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Gi(e,t,n,r),e.options=t.options});function io(e,t){return new ro({type:`union`,options:e,...E(t)})}const ao=x(`ZodIntersection`,(e,t)=>{rr.init(e,t),F.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ki(e,t,n,r)});function oo(e,t){return new ao({type:`intersection`,left:e,right:t})}const so=x(`ZodRecord`,(e,t)=>{or.init(e,t),F.init(e,t),e._zod.processJSONSchema=(t,n,r)=>qi(e,t,n,r),e.keyType=t.keyType,e.valueType=t.valueType});function co(e,t,n){return!t||!t._zod?new so({type:`record`,keyType:I(),valueType:e,...E(t)}):new so({type:`record`,keyType:e,valueType:t,...E(n)})}const lo=x(`ZodEnum`,(e,t)=>{sr.init(e,t),F.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Bi(e,t,n,r),e.enum=t.entries,e.options=Object.values(t.entries);let n=new Set(Object.keys(t.entries));e.extract=(e,r)=>{let i={};for(let r of e)if(n.has(r))i[r]=t.entries[r];else throw Error(`Key ${r} not found in enum`);return new lo({...t,checks:[],...E(r),entries:i})},e.exclude=(e,r)=>{let i={...t.entries};for(let t of e)if(n.has(t))delete i[t];else throw Error(`Key ${t} not found in enum`);return new lo({...t,checks:[],...E(r),entries:i})}});function uo(e,t){let n=Array.isArray(e)?Object.fromEntries(e.map(e=>[e,e])):e;return new lo({type:`enum`,entries:n,...E(t)})}const fo=x(`ZodTransform`,(e,t)=>{cr.init(e,t),F.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Hi(e,t,n,r),e._zod.parse=(n,r)=>{if(r.direction===`backward`)throw new Ce(e.constructor.name);n.addIssue=r=>{if(typeof r==`string`)n.issues.push(nt(r,n.value,t));else{let t=r;t.fatal&&(t.continue=!1),t.code??=`custom`,t.input??=n.value,t.inst??=e,n.issues.push(nt(t))}};let i=t.transform(n.value,n);return i instanceof Promise?i.then(e=>(n.value=e,n.fallback=!0,n)):(n.value=i,n.fallback=!0,n)}});function po(e){return new fo({type:`transform`,transform:e})}const mo=x(`ZodOptional`,(e,t)=>{ur.init(e,t),F.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ta(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function ho(e){return new mo({type:`optional`,innerType:e})}const go=x(`ZodExactOptional`,(e,t)=>{dr.init(e,t),F.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ta(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function _o(e){return new go({type:`optional`,innerType:e})}const vo=x(`ZodNullable`,(e,t)=>{fr.init(e,t),F.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ji(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function yo(e){return new vo({type:`nullable`,innerType:e})}const bo=x(`ZodDefault`,(e,t)=>{pr.init(e,t),F.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Xi(e,t,n,r),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap});function xo(e,t){return new bo({type:`default`,innerType:e,get defaultValue(){return typeof t==`function`?t():ze(t)}})}const So=x(`ZodPrefault`,(e,t)=>{hr.init(e,t),F.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Zi(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Co(e,t){return new So({type:`prefault`,innerType:e,get defaultValue(){return typeof t==`function`?t():ze(t)}})}const wo=x(`ZodNonOptional`,(e,t)=>{gr.init(e,t),F.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Yi(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function To(e,t){return new wo({type:`nonoptional`,innerType:e,...E(t)})}const Eo=x(`ZodCatch`,(e,t)=>{vr.init(e,t),F.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Qi(e,t,n,r),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap});function Do(e,t){return new Eo({type:`catch`,innerType:e,catchValue:typeof t==`function`?t:()=>t})}const Oo=x(`ZodPipe`,(e,t)=>{yr.init(e,t),F.init(e,t),e._zod.processJSONSchema=(t,n,r)=>$i(e,t,n,r),e.in=t.in,e.out=t.out});function ko(e,t){return new Oo({type:`pipe`,in:e,out:t})}const Ao=x(`ZodPreprocess`,(e,t)=>{Oo.init(e,t),xr.init(e,t)}),jo=x(`ZodReadonly`,(e,t)=>{Sr.init(e,t),F.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ea(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Mo(e){return new jo({type:`readonly`,innerType:e})}const No=x(`ZodCustom`,(e,t)=>{wr.init(e,t),F.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Vi(e,t,n,r)});function Po(e,t={}){return Oi(No,e,t)}function Fo(e,t){return ki(e,t)}function Io(e,t){return new Ao({type:`pipe`,in:po(e),out:t})}const Lo=new Set([`__proto__`,`constructor`,`prototype`]),Ro=(e,t,n)=>Io((n,r)=>{if(typeof n==`object`&&n)for(let i of Reflect.ownKeys(n))(typeof i!=`string`||!e(i))&&r.addIssue({code:`custom`,message:t(String(i)),path:[String(i)]});return n},n),zo=e=>e.length>=1&&!Lo.has(e),Bo=e=>Ro(zo,()=>`package key must be non-empty and not "__proto__", "constructor", or "prototype"`,co(I().min(1),e)),Vo=[`blobless`,`full`],Ho=[`ssh`,`https`],Uo=/^(?!\.{1,2}$)[^/\\%:]+$/u,Wo=/^[a-z0-9][a-z0-9.-]*(?:_[1-9]\d{0,4})?$/u,Go=/^(?<amount>[1-9]\d{0,3})(?<unit>[mhd])$/u,Ko={d:864e5,h:36e5,m:6e4},qo=e=>e!==``&&/^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/u.test(e),Jo=e=>{let t=e.groups?.port;if(!t)return!0;let n=Number(t);return n>=1&&n<=65535},Yo=e=>{let t=e.match(/_(?<port>\d+)$/u);if(t&&!Jo(t))return!1;let n=e;return t&&(n=e.slice(0,e.length-t[0].length)),n.split(`.`).every(e=>qo(e))},z=I().refine(e=>{let[t,...n]=e.split(`/`);return t===void 0||n.length<2||!Wo.test(t)||!Yo(t)?!1:n.every(e=>Uo.test(e))},`ref key must be host/path…/repo with safe, non-empty segments`).brand(),Xo=I().regex(Go,`duration must be <n>m, <n>h, or <n>d`).brand(),Zo=e=>{let t=Go.exec(e);if(t===null)throw Error(`invalid duration: ${e}`);let{amount:n,unit:r}=t.groups??{};if(!n||!r)throw Error(`invalid duration: ${e}`);return Number(n)*Ko[r]},Qo=uo(Vo),$o=uo(Ho),es=I().refine(e=>e.includes(`{version}`),`tag format must contain {version}`),ts=I().refine(e=>{if(e===`.`)return!0;let t=e.split(`/`);return t.length>0&&t.every(e=>Uo.test(e)&&e!==`.`)},`package path must be "." or a normalized relative path without traversal`),ns={clone_mode:`blobless`,git_transport:`https`,sync_ttl:`1h`},rs=R({clone_mode:Qo.default(ns.clone_mode),git_transport:$o.default(ns.git_transport),sync_ttl:Xo.default(Xo.parse(ns.sync_ttl))}),is=R((e=>Object.fromEntries(Object.entries(e).map(([e,t])=>[e,t.removeDefault().optional()])))(rs.shape)),as=R({description:I().min(1),path:ts,tag_format:es.optional()}),os=R({default_branch:I().min(1),description:I().min(1),packages:Bo(as).optional(),tag_format:es,url:I().min(1),...is.shape}),ss=R({meta:no({cli_version:I().min(1),schema_version:Ka().int().positive()}),refs:Ro(e=>z.safeParse(e).success,()=>`ref key must be host/path…/repo with safe, non-empty segments`,co(I(),os)).default({}),settings:rs});
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
* 3. Neither the name of the copyright holder nor the names of its contributors
|
|
80
|
-
* may be used to endorse or promote products derived from this software without
|
|
81
|
-
* specific prior written permission.
|
|
82
|
-
*
|
|
83
|
-
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
84
|
-
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
85
|
-
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
86
|
-
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
87
|
-
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
88
|
-
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
89
|
-
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
90
|
-
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
91
|
-
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
92
|
-
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
93
|
-
*/
|
|
94
|
-
let cs=/^(\d{4}-\d{2}-\d{2})?[T ]?(?:(\d{2}):\d{2}(?::\d{2}(?:\.\d+)?)?)?(Z|[-+]\d{2}:\d{2})?$/i;var ls=class e extends Date{#e=!1;#t=!1;#n=null;constructor(e){let t=!0,n=!0,r=`Z`;if(typeof e==`string`){let i=e.match(cs);i?(i[1]||(t=!1,e=`0000-01-01T${e}`),n=!!i[2],n&&e[10]===` `&&(e=e.replace(` `,`T`)),i[2]&&+i[2]>23?e=``:(r=i[3]||null,e=e.toUpperCase(),!r&&n&&(e+=`Z`))):e=``}super(e),isNaN(this.getTime())||(this.#e=t,this.#t=n,this.#n=r)}isDateTime(){return this.#e&&this.#t}isLocal(){return!this.#e||!this.#t||!this.#n}isDate(){return this.#e&&!this.#t}isTime(){return this.#t&&!this.#e}isValid(){return this.#e||this.#t}toISOString(){let e=super.toISOString();if(this.isDate())return e.slice(0,10);if(this.isTime())return e.slice(11,23);if(this.#n===null)return e.slice(0,-1);if(this.#n===`Z`)return e;let t=this.#n.slice(1,3)*60+ +this.#n.slice(4,6);return t=this.#n[0]===`-`?t:-t,new Date(this.getTime()-t*6e4).toISOString().slice(0,-1)+this.#n}static wrapAsOffsetDateTime(t,n=`Z`){let r=new e(t);return r.#n=n,r}static wrapAsLocalDateTime(t){let n=new e(t);return n.#n=null,n}static wrapAsLocalDate(t){let n=new e(t);return n.#t=!1,n.#n=null,n}static wrapAsLocalTime(t){let n=new e(t);return n.#e=!1,n.#n=null,n}};
|
|
95
|
-
/*!
|
|
96
|
-
* Copyright (c) Squirrel Chat et al., All rights reserved.
|
|
97
|
-
* SPDX-License-Identifier: BSD-3-Clause
|
|
98
|
-
*
|
|
99
|
-
* Redistribution and use in source and binary forms, with or without
|
|
100
|
-
* modification, are permitted provided that the following conditions are met:
|
|
101
|
-
*
|
|
102
|
-
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
103
|
-
* list of conditions and the following disclaimer.
|
|
104
|
-
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
105
|
-
* this list of conditions and the following disclaimer in the
|
|
106
|
-
* documentation and/or other materials provided with the distribution.
|
|
107
|
-
* 3. Neither the name of the copyright holder nor the names of its contributors
|
|
108
|
-
* may be used to endorse or promote products derived from this software without
|
|
109
|
-
* specific prior written permission.
|
|
110
|
-
*
|
|
111
|
-
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
112
|
-
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
113
|
-
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
114
|
-
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
115
|
-
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
116
|
-
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
117
|
-
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
118
|
-
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
119
|
-
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
120
|
-
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
121
|
-
*/
|
|
122
|
-
function us(e,t){let n=e.slice(0,t).split(/\r\n|\n|\r/g);return[n.length,n.pop().length+1]}function ds(e,t,n){let r=e.split(/\r\n|\n|\r/g),i=``,a=(Math.log10(t+1)|0)+1;for(let e=t-1;e<=t+1;e++){let o=r[e-1];o&&(i+=e.toString().padEnd(a,` `),i+=`: `,i+=o,i+=`
|
|
123
|
-
`,e===t&&(i+=` `.repeat(a+n+2),i+=`^
|
|
124
|
-
`))}return i}var B=class extends Error{line;column;codeblock;constructor(e,t){let[n,r]=us(t.toml,t.ptr),i=ds(t.toml,n,r);super(`Invalid TOML document: ${e}\n\n${i}`,t),this.line=n,this.column=r,this.codeblock=i}};
|
|
125
|
-
/*!
|
|
126
|
-
* Copyright (c) Squirrel Chat et al., All rights reserved.
|
|
127
|
-
* SPDX-License-Identifier: BSD-3-Clause
|
|
128
|
-
*
|
|
129
|
-
* Redistribution and use in source and binary forms, with or without
|
|
130
|
-
* modification, are permitted provided that the following conditions are met:
|
|
131
|
-
*
|
|
132
|
-
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
133
|
-
* list of conditions and the following disclaimer.
|
|
134
|
-
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
135
|
-
* this list of conditions and the following disclaimer in the
|
|
136
|
-
* documentation and/or other materials provided with the distribution.
|
|
137
|
-
* 3. Neither the name of the copyright holder nor the names of its contributors
|
|
138
|
-
* may be used to endorse or promote products derived from this software without
|
|
139
|
-
* specific prior written permission.
|
|
140
|
-
*
|
|
141
|
-
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
142
|
-
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
143
|
-
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
144
|
-
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
145
|
-
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
146
|
-
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
147
|
-
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
148
|
-
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
149
|
-
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
150
|
-
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
151
|
-
*/
|
|
152
|
-
let fs=/^((0x[0-9a-fA-F](_?[0-9a-fA-F])*)|(([+-]|0[ob])?\d(_?\d)*))$/,ps=/^[+-]?\d(_?\d)*(\.\d(_?\d)*)?([eE][+-]?\d(_?\d)*)?$/,ms=/^[+-]?0[0-9_]/;function hs(e,t){let n=e[t++],r=n,i=n===`'`,a=n===e[t]&&n===e[t+1];a&&(e[t+=2]===`
|
|
153
|
-
`?t++:e[t]===`\r`&&e[t+1]===`
|
|
154
|
-
`&&(t+=2));let o=``,s=t,c=0;for(let l=t;l<e.length;l++)if(n=e[l],a&&(n===`
|
|
155
|
-
`||n===`\r`&&e[l+1]===`
|
|
156
|
-
`))c&&=3;else if(n<` `&&n!==` `||n===``)throw new B(`control characters are not allowed in strings`,{toml:e,ptr:l});else if((!c||c===3)&&n===r&&(!a||e[l+1]===r&&e[l+2]===r))return a&&(e[l+3]===r&&l++,e[l+3]===r&&l++),[c?o:o+e.slice(s,l),l+(a?3:1)];else if(!c)!i&&n===`\\`&&(o+=e.slice(s,s=l),c=1);else if(c===1)if(n===`x`||n===`u`||n===`U`){let t=0,r=n===`x`?2:n===`u`?4:8;for(let n=0;n<r;n++,l++){let n=e.charCodeAt(l+1),r=n>=48&&n<=57?n-48:n>=65&&n<=70?n-65+10:n>=97&&n<=102?n-97+10:-1;if(r<0)throw new B(`invalid non-hex character in unicode escape`,{toml:e,ptr:l+1});t=t<<4|r}if(t<0||t>1114111||t>=55296&&t<=57343)throw new B(`invalid unicode escape`,{toml:e,ptr:l});o+=String.fromCodePoint(t),s=l+1,c=0}else if(n===` `||n===` `)c=2;else{if(n===`b`)o+=`\b`;else if(n===`t`)o+=` `;else if(n===`n`)o+=`
|
|
157
|
-
`;else if(n===`f`)o+=`\f`;else if(n===`r`)o+=`\r`;else if(n===`e`)o+=`\x1B`;else if(n===`"`)o+=`"`;else if(n===`\\`)o+=`\\`;else throw new B(`unrecognized escape sequence`,{toml:e,ptr:l});s=l+1,c=0}else if(n!==` `&&n!==` `){if(c===2)throw new B(`invalid escape: only line-ending whitespace may be escaped`,{toml:e,ptr:s});c=+(!i&&n===`\\`),s=l}throw new B(`unfinished string`,{toml:e,ptr:t})}function gs(e,t,n,r){if(e===`true`)return!0;if(e===`false`)return!1;if(e===`-inf`)return-1/0;if(e===`inf`||e===`+inf`)return 1/0;if(e===`nan`||e===`+nan`||e===`-nan`)return NaN;if(e===`-0`)return r?0n:0;let i=fs.test(e);if(i||ps.test(e)){if(ms.test(e))throw new B(`leading zeroes are not allowed`,{toml:t,ptr:n});e=e.replace(/_/g,``);let a=+e;if(isNaN(a))throw new B(`invalid number`,{toml:t,ptr:n});if(i){if((i=!Number.isSafeInteger(a))&&!r)throw new B(`integer value cannot be represented losslessly`,{toml:t,ptr:n});(i||r===!0)&&(a=BigInt(e))}return a}let a=new ls(e);if(!a.isValid())throw new B(`invalid value`,{toml:t,ptr:n});return a}
|
|
158
|
-
/*!
|
|
159
|
-
* Copyright (c) Squirrel Chat et al., All rights reserved.
|
|
160
|
-
* SPDX-License-Identifier: BSD-3-Clause
|
|
161
|
-
*
|
|
162
|
-
* Redistribution and use in source and binary forms, with or without
|
|
163
|
-
* modification, are permitted provided that the following conditions are met:
|
|
164
|
-
*
|
|
165
|
-
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
166
|
-
* list of conditions and the following disclaimer.
|
|
167
|
-
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
168
|
-
* this list of conditions and the following disclaimer in the
|
|
169
|
-
* documentation and/or other materials provided with the distribution.
|
|
170
|
-
* 3. Neither the name of the copyright holder nor the names of its contributors
|
|
171
|
-
* may be used to endorse or promote products derived from this software without
|
|
172
|
-
* specific prior written permission.
|
|
173
|
-
*
|
|
174
|
-
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
175
|
-
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
176
|
-
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
177
|
-
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
178
|
-
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
179
|
-
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
180
|
-
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
181
|
-
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
182
|
-
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
183
|
-
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
184
|
-
*/
|
|
185
|
-
function _s(e,t=0,n=e.length){let r=e.indexOf(`
|
|
186
|
-
`,t);return e[r-1]===`\r`&&r--,r<=n?r:-1}function vs(e,t){for(let n=t;n<e.length;n++){let r=e[n];if(r===`
|
|
187
|
-
`)return n;if(r===`\r`&&e[n+1]===`
|
|
188
|
-
`)return n+1;if(r<` `&&r!==` `||r===``)throw new B(`control characters are not allowed in comments`,{toml:e,ptr:t})}return e.length}function ys(e,t,n,r){let i;for(;;){for(;(i=e[t])===` `||i===` `||!n&&(i===`
|
|
189
|
-
`||i===`\r`&&e[t+1]===`
|
|
190
|
-
`);)t++;if(r||i!==`#`)break;t=vs(e,t)}return t}function bs(e,t,n,r,i=!1){if(!r)return t=_s(e,t),t<0?e.length:t;for(let a=t;a<e.length;a++){let t=e[a];if(t===`#`)a=_s(e,a);else if(t===n)return a+1;else if(t===r||i&&(t===`
|
|
191
|
-
`||t===`\r`&&e[a+1]===`
|
|
192
|
-
`))return a}throw new B(`cannot find end of structure`,{toml:e,ptr:t})}
|
|
193
|
-
/*!
|
|
194
|
-
* Copyright (c) Squirrel Chat et al., All rights reserved.
|
|
195
|
-
* SPDX-License-Identifier: BSD-3-Clause
|
|
196
|
-
*
|
|
197
|
-
* Redistribution and use in source and binary forms, with or without
|
|
198
|
-
* modification, are permitted provided that the following conditions are met:
|
|
199
|
-
*
|
|
200
|
-
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
201
|
-
* list of conditions and the following disclaimer.
|
|
202
|
-
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
203
|
-
* this list of conditions and the following disclaimer in the
|
|
204
|
-
* documentation and/or other materials provided with the distribution.
|
|
205
|
-
* 3. Neither the name of the copyright holder nor the names of its contributors
|
|
206
|
-
* may be used to endorse or promote products derived from this software without
|
|
207
|
-
* specific prior written permission.
|
|
208
|
-
*
|
|
209
|
-
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
210
|
-
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
211
|
-
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
212
|
-
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
213
|
-
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
214
|
-
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
215
|
-
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
216
|
-
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
217
|
-
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
218
|
-
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
219
|
-
*/
|
|
220
|
-
function xs(e,t,n){let r=e.slice(t,n),i=r.indexOf(`#`);return i>-1&&(vs(e,i),r=r.slice(0,i)),[r.trimEnd(),i]}function Ss(e,t,n,r,i){if(r===0)throw new B(`document contains excessively nested structures. aborting.`,{toml:e,ptr:t});let a=e[t];if(a===`[`||a===`{`){let[o,s]=a===`[`?Es(e,t,r,i):Ts(e,t,r,i);if(n){if(s=ys(e,s),e[s]===`,`)s++;else if(e[s]!==n)throw new B(`expected comma or end of structure`,{toml:e,ptr:s})}return[o,s]}if(a===`"`||a===`'`){let[r,i]=hs(e,t);if(n){if(i=ys(e,i),e[i]&&e[i]!==`,`&&e[i]!==n&&e[i]!==`
|
|
221
|
-
`&&e[i]!==`\r`)throw new B(`unexpected character encountered`,{toml:e,ptr:i});e[i]===`,`&&i++}return[r,i]}let o=bs(e,t,`,`,n),s=xs(e,t,o-+(e[o-1]===`,`));if(!s[0])throw new B(`incomplete key-value declaration: no value specified`,{toml:e,ptr:t});return n&&s[1]>-1&&(o=ys(e,t+s[1]),e[o]===`,`&&o++),[gs(s[0],e,t,i),o]}
|
|
222
|
-
/*!
|
|
223
|
-
* Copyright (c) Squirrel Chat et al., All rights reserved.
|
|
224
|
-
* SPDX-License-Identifier: BSD-3-Clause
|
|
225
|
-
*
|
|
226
|
-
* Redistribution and use in source and binary forms, with or without
|
|
227
|
-
* modification, are permitted provided that the following conditions are met:
|
|
228
|
-
*
|
|
229
|
-
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
230
|
-
* list of conditions and the following disclaimer.
|
|
231
|
-
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
232
|
-
* this list of conditions and the following disclaimer in the
|
|
233
|
-
* documentation and/or other materials provided with the distribution.
|
|
234
|
-
* 3. Neither the name of the copyright holder nor the names of its contributors
|
|
235
|
-
* may be used to endorse or promote products derived from this software without
|
|
236
|
-
* specific prior written permission.
|
|
237
|
-
*
|
|
238
|
-
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
239
|
-
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
240
|
-
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
241
|
-
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
242
|
-
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
243
|
-
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
244
|
-
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
245
|
-
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
246
|
-
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
247
|
-
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
248
|
-
*/
|
|
249
|
-
let Cs=/^[a-zA-Z0-9-_]+[ \t]*$/;function ws(e,t,n=`=`){let r=t-1,i=[],a=e.indexOf(n,t);if(a<0)throw new B(`incomplete key-value: cannot find end of key`,{toml:e,ptr:t});do{let o=e[t=++r];if(o!==` `&&o!==` `)if(o===`"`||o===`'`){if(o===e[t+1]&&o===e[t+2])throw new B(`multiline strings are not allowed in keys`,{toml:e,ptr:t});let[s,c]=hs(e,t);r=e.indexOf(`.`,c);let l=e.slice(c,r<0||r>a?a:r),u=_s(l);if(u>-1)throw new B(`newlines are not allowed in keys`,{toml:e,ptr:t+r+u});if(l.trimStart())throw new B(`found extra tokens after the string part`,{toml:e,ptr:c});if(a<c&&(a=e.indexOf(n,c),a<0))throw new B(`incomplete key-value: cannot find end of key`,{toml:e,ptr:t});i.push(s)}else{r=e.indexOf(`.`,t);let n=e.slice(t,r<0||r>a?a:r);if(!Cs.test(n))throw new B(`only letter, numbers, dashes and underscores are allowed in keys`,{toml:e,ptr:t});i.push(n.trimEnd())}}while(r+1&&r<a);return[i,ys(e,a+1,!0,!0)]}function Ts(e,t,n,r){let i={},a=new Set,o;for(t++;(o=e[t++])!==`}`&&o;)if(o===`,`)throw new B(`expected value, found comma`,{toml:e,ptr:t-1});else if(o===`#`)t=vs(e,t);else if(o!==` `&&o!==` `&&o!==`
|
|
250
|
-
`&&o!==`\r`){let o,s=i,c=!1,[l,u]=ws(e,t-1);for(let n=0;n<l.length;n++){if(n&&(s=c?s[o]:s[o]={}),o=l[n],(c=Object.hasOwn(s,o))&&(typeof s[o]!=`object`||a.has(s[o])))throw new B(`trying to redefine an already defined value`,{toml:e,ptr:t});!c&&o===`__proto__`&&Object.defineProperty(s,o,{enumerable:!0,configurable:!0,writable:!0})}if(c)throw new B(`trying to redefine an already defined value`,{toml:e,ptr:t});let[d,f]=Ss(e,u,`}`,n-1,r);a.add(d),s[o]=d,t=f}if(!o)throw new B(`unfinished table encountered`,{toml:e,ptr:t});return[i,t]}function Es(e,t,n,r){let i=[],a;for(t++;(a=e[t++])!==`]`&&a;)if(a===`,`)throw new B(`expected value, found comma`,{toml:e,ptr:t-1});else if(a===`#`)t=vs(e,t);else if(a!==` `&&a!==` `&&a!==`
|
|
251
|
-
`&&a!==`\r`){let a=Ss(e,t-1,`]`,n-1,r);i.push(a[0]),t=a[1]}if(!a)throw new B(`unfinished array encountered`,{toml:e,ptr:t});return[i,t]}
|
|
252
|
-
/*!
|
|
253
|
-
* Copyright (c) Squirrel Chat et al., All rights reserved.
|
|
254
|
-
* SPDX-License-Identifier: BSD-3-Clause
|
|
255
|
-
*
|
|
256
|
-
* Redistribution and use in source and binary forms, with or without
|
|
257
|
-
* modification, are permitted provided that the following conditions are met:
|
|
258
|
-
*
|
|
259
|
-
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
260
|
-
* list of conditions and the following disclaimer.
|
|
261
|
-
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
262
|
-
* this list of conditions and the following disclaimer in the
|
|
263
|
-
* documentation and/or other materials provided with the distribution.
|
|
264
|
-
* 3. Neither the name of the copyright holder nor the names of its contributors
|
|
265
|
-
* may be used to endorse or promote products derived from this software without
|
|
266
|
-
* specific prior written permission.
|
|
267
|
-
*
|
|
268
|
-
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
269
|
-
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
270
|
-
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
271
|
-
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
272
|
-
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
273
|
-
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
274
|
-
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
275
|
-
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
276
|
-
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
277
|
-
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
278
|
-
*/
|
|
279
|
-
function Ds(e,t,n,r){let i=t,a=n,o,s=!1,c;for(let t=0;t<e.length;t++){if(t){if(i=s?i[o]:i[o]={},a=(c=a[o]).c,r===0&&(c.t===1||c.t===2))return null;if(c.t===2){let e=i.length-1;i=i[e],a=a[e].c}}if(o=e[t],(s=Object.hasOwn(i,o))&&a[o]?.t===0&&a[o]?.d)return null;s||(o===`__proto__`&&(Object.defineProperty(i,o,{enumerable:!0,configurable:!0,writable:!0}),Object.defineProperty(a,o,{enumerable:!0,configurable:!0,writable:!0})),a[o]={t:t<e.length-1&&r===2?3:r,d:!1,i:0,c:{}})}if(c=a[o],c.t!==r&&!(r===1&&c.t===3)||(r===2&&(c.d||(c.d=!0,i[o]=[]),i[o].push(i={}),c.c[c.i++]=c={t:1,d:!1,i:0,c:{}}),c.d))return null;if(c.d=!0,r===1)i=s?i[o]:i[o]={};else if(r===0&&s)return null;return[o,i,c.c]}function Os(e,{maxDepth:t=1e3,integersAsBigInt:n}={}){let r={},i={},a=r,o=i;for(let s=ys(e,0);s<e.length;){if(e[s]===`[`){let t=e[++s]===`[`,n=ws(e,s+=+t,`]`);if(t){if(e[n[1]-1]!==`]`)throw new B(`expected end of table declaration`,{toml:e,ptr:n[1]-1});n[1]++}let c=Ds(n[0],r,i,t?2:1);if(!c)throw new B(`trying to redefine an already defined table or value`,{toml:e,ptr:s});o=c[2],a=c[1],s=n[1]}else{let r=ws(e,s),i=Ds(r[0],a,o,0);if(!i)throw new B(`trying to redefine an already defined table or value`,{toml:e,ptr:s});let c=Ss(e,r[1],void 0,t,n);i[1][i[0]]=c[0],s=c[1]}if(s=ys(e,s,!0),e[s]&&e[s]!==`
|
|
280
|
-
`&&e[s]!==`\r`)throw new B(`each key-value declaration must be followed by an end-of-line`,{toml:e,ptr:s});s=ys(e,s)}return r}
|
|
281
|
-
/*!
|
|
282
|
-
* Copyright (c) Squirrel Chat et al., All rights reserved.
|
|
283
|
-
* SPDX-License-Identifier: BSD-3-Clause
|
|
284
|
-
*
|
|
285
|
-
* Redistribution and use in source and binary forms, with or without
|
|
286
|
-
* modification, are permitted provided that the following conditions are met:
|
|
287
|
-
*
|
|
288
|
-
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
289
|
-
* list of conditions and the following disclaimer.
|
|
290
|
-
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
291
|
-
* this list of conditions and the following disclaimer in the
|
|
292
|
-
* documentation and/or other materials provided with the distribution.
|
|
293
|
-
* 3. Neither the name of the copyright holder nor the names of its contributors
|
|
294
|
-
* may be used to endorse or promote products derived from this software without
|
|
295
|
-
* specific prior written permission.
|
|
296
|
-
*
|
|
297
|
-
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
298
|
-
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
299
|
-
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
300
|
-
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
301
|
-
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
302
|
-
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
303
|
-
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
304
|
-
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
305
|
-
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
306
|
-
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
307
|
-
*/
|
|
308
|
-
let ks=/^[a-z0-9-_]+$/i;function As(e){let t=typeof e;if(t===`object`){if(Array.isArray(e))return`array`;if(e instanceof Date)return`date`}return t}function js(e){for(let t=0;t<e.length;t++)if(As(e[t])!==`object`)return!1;return e.length!=0}function Ms(e){return JSON.stringify(e).replace(/\x7f/g,`\\u007f`)}function Ns(e,t,n,r){if(n===0)throw Error(`Could not stringify the object: maximum object depth exceeded`);if(t===`number`)return isNaN(e)?`nan`:e===1/0?`inf`:e===-1/0?`-inf`:Number.isInteger(e)&&(r||!Number.isSafeInteger(e))?e.toFixed(1):e.toString();if(t===`bigint`||t===`boolean`)return e.toString();if(t===`string`)return Ms(e);if(t===`date`){if(isNaN(e.getTime()))throw TypeError(`cannot serialize invalid date`);return e.toISOString()}if(t===`object`)return Ps(e,n,r);if(t===`array`)return Fs(e,n,r)}function Ps(e,t,n){let r=Object.keys(e);if(r.length===0)return`{}`;let i=`{ `;for(let a=0;a<r.length;a++){let o=r[a];a&&(i+=`, `),i+=ks.test(o)?o:Ms(o),i+=` = `,i+=Ns(e[o],As(e[o]),t-1,n)}return i+` }`}function Fs(e,t,n){if(e.length===0)return`[]`;let r=`[ `;for(let i=0;i<e.length;i++){if(i&&(r+=`, `),e[i]===null||e[i]===void 0)throw TypeError(`arrays cannot contain null or undefined values`);r+=Ns(e[i],As(e[i]),t-1,n)}return r+` ]`}function Is(e,t,n,r){if(n===0)throw Error(`Could not stringify the object: maximum object depth exceeded`);let i=``;for(let a=0;a<e.length;a++)i+=`${i&&`
|
|
309
|
-
`}[[${t}]]\n`,i+=Ls(0,e[a],t,n,r);return i}function Ls(e,t,n,r,i){if(r===0)throw Error(`Could not stringify the object: maximum object depth exceeded`);let a=``,o=``,s=Object.keys(t);for(let e=0;e<s.length;e++){let c=s[e];if(t[c]!==null&&t[c]!==void 0){let e=As(t[c]);if(e===`symbol`||e===`function`)throw TypeError(`cannot serialize values of type '${e}'`);let s=ks.test(c)?c:Ms(c);if(e===`array`&&js(t[c]))o+=(o&&`
|
|
310
|
-
`)+Is(t[c],n?`${n}.${s}`:s,r-1,i);else if(e===`object`){let e=n?`${n}.${s}`:s;o+=(o&&`
|
|
311
|
-
`)+Ls(e,t[c],e,r-1,i)}else a+=s,a+=` = `,a+=Ns(t[c],e,r,i),a+=`
|
|
312
|
-
`}}return e&&(a||!o)&&(a=a?`[${e}]\n${a}`:`[${e}]`),a&&o?`${a}\n${o}`:a||o}function Rs(e,{maxDepth:t=1e3,numbersAsFloat:n=!1}={}){if(As(e)!==`object`)throw TypeError(`stringify can only be called with an object`);let r=Ls(0,e,``,t,n);return r[r.length-1]===`
|
|
313
|
-
`?r:r+`
|
|
314
|
-
`}const V=e=>typeof e==`object`&&!!e&&`code`in e&&e.code===`ENOENT`,zs=async(e,t)=>{await a(ne(e),{recursive:!0});let n=`${e}.tmp-${se()}`;await ee(n,t,`utf8`),await l(n,e)},H=e=>{let t=ae(e.REFS_HOME??m(de(),`.kaisers-io`,`refs`));return{configPath:m(t,`config.toml`),hooksDir:m(t,`hooks`),locksDir:m(t,`locks`),root:t,sourcesDir:m(t,`sources`),statePath:m(t,`state.json`)}},U=(e,t)=>m(e.sourcesDir,...t.split(`/`)),Bs=e=>`${e.configPath}.bak`,Vs=e=>{let t=[],n=e;for(;!le(n);){let e=ne(n);if(e===n)break;t.unshift(te(n)),n=e}return{ancestor:n,missing:t}},Hs=e=>{let{ancestor:t,missing:n}=Vs(e),r=ue(t);return n.length===0?r:m(r,...n)},Us=(e,t)=>{let n=ie(Hs(e.sourcesDir),Hs(t)),r=n===`..`||n.startsWith(`..`+oe);if(!(n!==``&&!r&&!re(n)))throw b(`path escapes sources directory (containment violation): ${t}`)},Ws=e=>typeof e==`object`&&!!e&&!Array.isArray(e),Gs=(e,t)=>Ws(e)?e:t,Ks=async e=>{try{return await o(e.configPath,`utf8`)}catch(e){throw V(e)?v(`no config found — run: refs init`):e}},qs=(e,t)=>{try{return Os(e)}catch(e){throw e instanceof B?b(`invalid TOML in ${t}: ${e.message}`):e}},Js=e=>typeof e==`number`&&Number.isInteger(e)&&e>=1,Ys=e=>{let{meta:t}=e;if(!Ws(t))return;let n=t.schema_version;if(Js(n))return n},Xs=(e,t)=>{let n=Ys(e);if(n===void 0)throw b(`config schema version is missing or invalid in ${t} — run: refs migrate`);if(n>1)throw b(`config schema ${n} is newer than this CLI supports — upgrade refs`);if(n<1)throw b(`config schema ${n} is older than expected 1 — run: refs migrate`)},W=async e=>{let t=await Ks(e),n=qs(t,e.configPath);Xs(n,e.configPath);let r=ss.safeParse(n);if(!r.success)throw b(O(r.error));return r.data},Zs=async(e,t)=>{let n=ss.safeParse(t);if(!n.success)throw b(O(n.error));await zs(e.configPath,Rs(n.data))},Qs=async e=>{try{return await f(e),!0}catch(e){if(V(e))return!1;throw e}},$s=async(e,t)=>await Qs(e.configPath)?`noop`:(await zs(e.configPath,`# refs configuration
|
|
315
|
-
#
|
|
316
|
-
# Every global setting under [settings] can also be set per-ref: add the same
|
|
317
|
-
# key directly inside a [refs."host/owner/repo"] table to override it just for
|
|
318
|
-
# that ref — every global setting is per-ref overridable.
|
|
25
|
+
const [major = FALLBACK_VERSION_PART, minor = FALLBACK_VERSION_PART] = process.versions.node
|
|
26
|
+
.split('.')
|
|
27
|
+
.map(Number);
|
|
28
|
+
if (
|
|
29
|
+
major < REQUIRED_NODE_MAJOR ||
|
|
30
|
+
(major === REQUIRED_NODE_MAJOR && minor < REQUIRED_NODE_MINOR_MIN)
|
|
31
|
+
) {
|
|
32
|
+
console.error(
|
|
33
|
+
`refs requires Node.js >=24.12 — you are running Node.js ${process.versions.node}.`,
|
|
34
|
+
);
|
|
35
|
+
console.error('Install a matching version, e.g.: nvm install 24');
|
|
36
|
+
process.exit(EXIT_FAILURE);
|
|
37
|
+
}
|
|
319
38
|
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
39
|
+
const printNotBuiltMessage = () => {
|
|
40
|
+
console.error('refs is not built — the CLI bundle (dist/refs.mjs) is missing.');
|
|
41
|
+
console.error('Run: pnpm install && pnpm build (or `pnpm dev` in packages/cli for watch mode)');
|
|
42
|
+
};
|
|
323
43
|
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
clone_mode = "blobless"
|
|
327
|
-
# Transport for npm:-resolved adds: their clone url is rewritten to this before cloning.
|
|
328
|
-
# One of "https" (default) or "ssh" (for private-package setups with forge ssh keys).
|
|
329
|
-
# Explicitly-typed git urls are always used verbatim.
|
|
330
|
-
git_transport = "https"
|
|
331
|
-
# How long a ref's fetched state is considered fresh before refs re-fetches it.
|
|
332
|
-
# Format: <n>m, <n>h, or <n>d (e.g. "30m", "1h", "1d"). Default: "1h".
|
|
333
|
-
sync_ttl = "1h"
|
|
44
|
+
const isSourceLoadError = (error) =>
|
|
45
|
+
error instanceof Error && SOURCE_LOAD_ERROR_CODES.has(error.code);
|
|
334
46
|
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
-
|
|
367
|
-
|
|
368
|
-
Expecting one of '${n.join(`', '`)}'`);let r=`${e}Help`;return this.on(r,e=>{let n;n=typeof t==`function`?t({error:e.error,command:e.command}):t,n&&e.write(`${n}\n`)}),this}_outputHelpIfRequested(e){let t=this._getHelpOption();t&&e.find(e=>t.is(e))&&(this.outputHelp(),this._exit(0,`commander.helpDisplayed`,`(outputHelp)`))}};function Cd(e){return e.map(e=>{if(!e.startsWith(`--inspect`))return e;let t,n=`127.0.0.1`,r=`9229`,i;return(i=e.match(/^(--inspect(-brk)?)$/))===null?(i=e.match(/^(--inspect(-brk|-port)?)=([^:]+)$/))===null?(i=e.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/))!==null&&(t=i[1],n=i[3],r=i[4]):(t=i[1],/^\d+$/.test(i[3])?r=i[3]:n=i[3]):t=i[1],t&&r!==`0`?`${t}=${n}:${parseInt(r)+1}`:e})}function wd(){if(h.env.NO_COLOR||h.env.FORCE_COLOR===`0`||h.env.FORCE_COLOR===`false`)return!1;if(h.env.FORCE_COLOR||h.env.CLICOLOR_FORCE!==void 0)return!0}new Sd;const Td=[],Ed=e=>Array.isArray(e)?e:[e],Q=(e,t,n,r,i)=>{if(t.json){let t={data:r,ok:!0,warnings:i??Td};e.out(JSON.stringify(t));return}for(let t of Ed(n))e.out(t);for(let t of i??Td)e.errLine(`refs: warning: ${t}`)},Dd=(e,t,n)=>{if(t.json){let t={error:{code:n.code,message:n.message},ok:!1};e.out(JSON.stringify(t));return}e.errLine(`refs: ${n.message}`)},Od=(e,t)=>{e.errLine(`refs: ${t}`)},$=(e,t,n)=>async()=>{try{await n()}catch(n){let r=be(n,{verbose:t.verbose});Dd(e,t,r),process.exitCode=r.exitCode}};var kd=`0.1.3`;const Ad=async e=>{let t=await e.runner.run(`git`,[`--version`]);return t.exitCode===0?{detail:t.stdout.trim(),name:`git`,status:`ok`}:{detail:t.stderr.trim()||`git --version exited with code ${t.exitCode}`,name:`git`,status:`fail`}},jd=/^v(?<major>\d+)\.(?<minor>\d+)/u,Md=e=>{let t=jd.exec(e),n=t?.groups?.major,r=t?.groups?.minor;if(!(n===void 0||r===void 0))return{major:Number(n),minor:Number(r)}},Nd=e=>e===void 0?!1:e.major===24&&e.minor>=12,Pd=e=>{let{nodeVersion:t}=e;return Nd(Md(t))?{detail:t,name:`node`,status:`ok`}:{detail:`${t} does not satisfy the required range >=24.12 <25`,name:`node`,status:`fail`}},Fd=e=>e instanceof Error?e.message:String(e),Id=()=>ss.parse({meta:{cli_version:`0.0.0`,schema_version:1},refs:{},settings:{}}),Ld=async e=>{try{return{config:await W(e)}}catch(e){return{config:Id(),errorMessage:Fd(e)}}},Rd=e=>e===void 0?{detail:`config is present and matches the current schema`,name:`config`,status:`ok`}:{detail:e,name:`config`,status:`fail`},zd=[`.claude`,`skills`,`refs`,`SKILL.md`],Bd=[`.codex`,`skills`,`refs`,`SKILL.md`],Vd=e=>e===void 0?[]:[m(e,...zd),m(e,...Bd)],Hd=async t=>{try{return await e(t),!0}catch{return!1}},Ud=async e=>{let t=Vd(e.env.HOME);return(await Promise.all(t.map(e=>Hd(e)))).some(Boolean)?{detail:`the refs skill is installed`,name:`skill`,status:`ok`}:{detail:`refs skill not found — install it: npx skills add kaisers-io/refs`,name:`skill`,status:`warn`}},Wd=(e,t)=>Object.keys(t.refs).map(t=>({dest:U(e,z.parse(t)),key:t})).filter(e=>G(e.dest)),Gd=[`pre-commit`,`pre-push`],Kd=async(t,r)=>{try{return await e(m(t.hooksDir,r),n.X_OK),!0}catch{return!1}},qd=async e=>{let t=await Promise.all(Gd.map(t=>Kd(e,t)));return Gd.filter((e,n)=>!t[n])},Jd=async(e,t,n)=>{let r=await e.runner.run(`git`,[`config`,`--local`,`--get`,`core.hooksPath`],{cwd:n});return r.exitCode===0&&r.stdout.trim()===t.hooksDir},Yd=e=>e.missingHooks.length>0?{detail:`${e.missingHooks.map(e=>`hooks/${e}`).join(`, `)} missing or not executable — run: refs init`,name:`hooks-guard`,status:`fail`}:e.badKeys.length>0?{detail:`core.hooksPath not set for: ${e.badKeys.join(`, `)} — run: refs init`,name:`hooks-guard`,status:`fail`}:{detail:`${Gd.map(e=>`hooks/${e}`).join(`, `)} present; ${e.checkoutCount} checkout(s) guarded`,name:`hooks-guard`,status:`ok`},Xd=async(e,t,n)=>{let r=Wd(t,n),[i,a]=await Promise.all([qd(t),Promise.all(r.map(n=>Jd(e,t,n.dest)))]),o=r.filter((e,t)=>!a[t]).map(e=>e.key);return Yd({badKeys:o,checkoutCount:r.length,missingHooks:i})},Zd=async(e,t)=>{let n=await e.runner.run(`git`,[`status`,`--porcelain`],{cwd:t.dest});return n.exitCode===0?{broken:!1,detail:``,dirty:n.stdout.trim()!==``,key:t.key}:{broken:!0,detail:n.stderr.trim(),dirty:!1,key:t.key}},Qd=e=>{let t=e.filter(e=>e.broken);if(t.length>0)return{detail:t.map(e=>`${e.key}: git status failed — ${e.detail}`).join(`; `),name:`dirty-checkouts`,status:`fail`};let n=e.filter(e=>e.dirty).map(e=>e.key);return n.length===0?{detail:`no local changes in any checkout`,name:`dirty-checkouts`,status:`ok`}:{detail:`local changes will be discarded on next sync: ${n.join(`, `)}`,name:`dirty-checkouts`,status:`warn`}},$d=async(e,t,n)=>{let r=Wd(t,n),i=await Promise.all(r.map(t=>Zd(e,t)));return Qd(i)},ef=async e=>{try{return await Z(e)}catch{return Ru.parse({})}},tf=async e=>{try{return(await s(e,{withFileTypes:!0})).filter(e=>e.isDirectory()).map(e=>e.name)}catch(e){if(V(e))return[];throw e}},nf=async(e,t)=>{if(G(e))return[[...t]];let n=await tf(e);return(await Promise.all(n.map(n=>nf(m(e,n),[...t,n])))).flat()},rf=(e,t,n)=>{let r=e.refs[t]?.pending_proposal_at;return r===void 0?!1:n-Date.parse(r)<864e5},af=(e,t,n)=>rf(t,e.key,n)?`${e.key}: pending add`:`${e.key}: orphan — remove with: rm -rf ${e.dest}`,of=(e,t)=>({dest:m(e.sourcesDir,...t),key:t.join(`/`)}),sf=async(e,t,n)=>{let r=(await nf(e.sourcesDir,[])).map(t=>of(e,t)).filter(e=>!Object.hasOwn(t.refs,e.key));if(r.length===0)return{detail:`no orphaned checkouts under sources/`,name:`orphans`,status:`ok`};let i=Date.now();return{detail:r.map(e=>af(e,n,i)).join(`; `),name:`orphans`,status:`warn`}},cf=/^(?<user>[^/\s@]+)@(?<host>[^:/\s]+):/u,lf=e=>e===``?{}:{user:e},uf=e=>e===``?{}:{port:e},df=e=>{try{let t=new URL(e);return t.protocol===`ssh:`?{host:t.hostname,...lf(t.username),...uf(t.port)}:void 0}catch{return}},ff=e=>{let t=cf.exec(e),n=t?.groups?.host;return n===void 0?df(e):{host:n,user:t?.groups?.user??`git`}},pf=e=>e.port===void 0?e.host:`${e.host}:${e.port}`,mf=e=>e.user===void 0?pf(e):`${e.user}@${pf(e)}`,hf=e=>{let t=Object.values(e.refs).map(e=>ff(e.url)).filter(e=>e!==void 0),n=new Map;for(let e of t)n.set(mf(e),e);return[...n.values()].toSorted((e,t)=>mf(e).localeCompare(mf(t)))},gf=/Permission denied/u,_f=[/Could not resolve hostname/u,/Connection refused/u,/Host key verification failed/u,/timed out/u],vf=e=>e.user===void 0?e.host:`${e.user}@${e.host}`,yf=e=>{let t=[`-o`,`ConnectTimeout=5`,`-o`,`BatchMode=yes`],n=vf(e);return e.port===void 0?[...t,`-T`,n]:[...t,`-p`,e.port,`-T`,n]},bf=async(e,t,n)=>{let r=mf(t),i=await e.runner.run(`ssh`,yf(t),{timeoutMs:n});return i.timedOut===!0?{host:r,outcome:`timeout`}:gf.test(i.stderr)?{host:r,outcome:`denied`}:_f.some(e=>e.test(i.stderr))?{detail:i.stderr.trim(),host:r,outcome:`connection-warn`}:{host:r,outcome:`ok`}},xf=(e,t)=>{let n=e.filter(e=>e.outcome===`timeout`).map(e=>e.host);if(n.length!==0)return{detail:`ssh probe timed out after ${t/1e3}s: ${n.join(`, `)}`,name:`ssh-auth`,status:`fail`}},Sf=e=>{let t=e.filter(e=>e.outcome===`denied`).map(e=>e.host);if(t.length!==0)return{detail:`ssh permission denied for: ${t.join(`, `)}`,name:`ssh-auth`,status:`fail`}},Cf=e=>{let t=e.filter(e=>e.outcome===`connection-warn`);if(t.length!==0)return{detail:`ssh connection issue, treated as warn: ${t.map(e=>`${e.host} (${e.detail??``})`).join(`; `)}`,name:`ssh-auth`,status:`warn`}},wf=e=>({detail:`ssh auth ok for: ${e.map(e=>e.host).join(`, `)}`,name:`ssh-auth`,status:`ok`}),Tf=(e,t)=>xf(e,t)??Sf(e)??Cf(e)??wf(e),Ef=async(e,t,n)=>{let r=hf(t);if(r.length===0)return;let i=n?.timeoutMs??1e4,a=await Promise.all(r.map(t=>bf(e,t,i)));return Tf(a,i)},Df=async e=>{try{return await e.run()}catch(t){return{detail:`check crashed: ${Fd(t)}`,name:e.name,status:`fail`}}},Of=async e=>{let[t,...n]=e;if(t===void 0)return[];let r=await Df(t),i=await Of(n);return r===void 0?i:[r,...i]},kf=e=>{let{configLoad:t,ctx:n,home:r,state:i}=e;return[{name:`git`,run:()=>Ad(n)},{name:`node`,run:()=>Promise.resolve(Pd(n))},{name:`config`,run:()=>Promise.resolve(Rd(t.errorMessage))},{name:`hooks-guard`,run:()=>Xd(n,r,t.config)},{name:`dirty-checkouts`,run:()=>$d(n,r,t.config)},{name:`orphans`,run:()=>sf(r,t.config,i)},{name:`skill`,run:()=>Ud(n)},{name:`ssh-auth`,run:()=>Ef(n,t.config)}]},Af=async e=>{let t=H(e.env),n=await Ld(t),r=await ef(t);return Of(kf({configLoad:n,ctx:e,home:t,state:r}))},jf={fail:`FAIL`,ok:`OK`,warn:`WARN`},Mf=e=>e.map(e=>`[${jf[e.status]}] ${e.name}: ${e.detail}`),Nf=e=>e.some(e=>e.status===`fail`),Pf=(e,t)=>{e.command(`doctor`).description(`Run environment/integrity checks (git, node, config, hooks, checkouts, ssh).`).action((e,n)=>{let r=n.optsWithGlobals(),i={json:r.json===!0,verbose:r.verbose===!0};return $(t,i,async()=>{let e=await Af(t);Q(t,i,Mf(e),{checks:e}),Nf(e)&&(process.exitCode=g.UNEXPECTED)})()})},Ff=async e=>{let t=H(e.env),n=await Y(t,`home`,()=>cc(t,kd));return n===`migrated`?{backup:Bs(t),result:n}:{backup:null,result:n}},If=e=>e.result===`migrated`&&e.backup!==null?`config migrated (backup: ${te(e.backup)})`:e.result===`seeded`?`config seeded`:`config up to date`,Lf=(e,t)=>{e.command(`migrate`).description(`Migrate the refs config to the current schema, seeding it if absent.`).action((e,n)=>{let r=n.optsWithGlobals(),i={json:r.json===!0,verbose:r.verbose===!0};return $(t,i,async()=>{let e=await Ff(t);Q(t,i,If(e),e)})()})},Rf=(e,t,n)=>e===void 0?!0:n-Date.parse(e)>t,zf=(e,t,n)=>{let r=e.state.refs[t],i=Zo(X(`sync_ttl`,n,e.settings));return{clone_mode:X(`clone_mode`,n,e.settings),description:n.description,key:t,missing:!G(U(e.home,z.parse(t))),packages:Object.keys(n.packages??{}).toSorted(),stale:Rf(r?.last_fetched_at,i,e.now)}},Bf=e=>{let t={home:e.home,now:e.now,settings:e.config.settings,state:e.state};return Object.entries(e.config.refs).map(([e,n])=>zf(t,e,n)).toSorted((e,t)=>e.key.localeCompare(t.key))},Vf=async e=>{let t=H(e.env),n=await W(t),r=await Z(t);return Bf({config:n,home:t,now:Date.now(),state:r})},Hf=e=>{let t=[];return e.stale&&t.push(`[stale]`),e.missing&&t.push(`[missing]`),t.length===0?``:` ${t.join(` `)}`},Uf=e=>e.length===0?[`no refs configured — run: refs add <source>`]:e.map(e=>`${e.key} ${e.description}${Hf(e)}`),Wf=e=>e.split(`/`),Gf=(e,t)=>{let n=Wf(e);if(t.length>n.length)return!1;let r=n.length-t.length;return t.every((e,t)=>e===n[r+t])},Kf=(e,t)=>{if(Object.hasOwn(e.refs,t))return z.parse(t);let n=Wf(t),r=Object.keys(e.refs).filter(e=>Gf(e,n)).toSorted(),[i]=r;if(i===void 0)throw v(`no ref matches '${t}'`);if(r.length>1)throw y(`'${t}' matches more than one ref: ${r.join(`, `)}`);return z.parse(i)},qf=(e,t)=>{e.command(`list`).description(`List configured refs with their staleness/missing checkout status.`).action((e,n)=>{let r=n.optsWithGlobals(),i={json:r.json===!0,verbose:r.verbose===!0};return $(t,i,async()=>{let e=await Vf(t);Q(t,i,Uf(e),e)})()})},Jf=e=>`ref:${e.replaceAll(`/`,`_`)}`,Yf=e=>e.REFS_ALLOW_FILE_URLS===`1`,Xf=(e,t)=>{let n=J(t,{allowFileUrls:Yf(e.env)});return{cloneUrl:n.cloneUrl,key:n.key}},Zf=async(e,t)=>{if(t===``)throw y(`refs add npm: requires a package name, e.g. npm:left-pad`);Od(e,`resolving npm package '${t}'…`);let n=await du(e.fetcher,t),r={cloneUrl:n.cloneUrl,key:n.key,npmPkgName:t};return n.directory!==void 0&&(r.npmDirectory=n.directory),r},Qf=(e,t)=>t.startsWith(`npm:`)?Zf(e,t.slice(4)):Promise.resolve(Xf(e,t)),$f=(e,t)=>{if(e.npmPkgName===void 0)return e;let n=X(`git_transport`,void 0,t);return{...e,cloneUrl:xl(e.cloneUrl,n)}},ep=e=>`ref '${e}' already exists — use refs edit or refs remove`,tp=(e,t)=>{if(e.refs[t]!==void 0)throw ve(ep(t))},np=async e=>{try{return await s(e,{withFileTypes:!0})}catch(e){if(V(e))return;throw e}},rp=e=>e.filter(e=>e.isDirectory()).map(e=>e.name),ip=async(e,t)=>{let n=await np(e);if(n===void 0)return{kind:`stop`};let r=rp(n);if(r.includes(t))return{kind:`continue`,nextDir:m(e,t)};let i=r.find(e=>e.toLowerCase()===t.toLowerCase());return i===void 0?{kind:`stop`}:{kind:`collision`,name:i}},ap=async(e,t,n)=>{let[r,...i]=t;if(r===void 0)return;let a=await ip(e,r);if(a.kind!==`stop`)return a.kind===`collision`?[...n,a.name].join(`/`):ap(a.nextDir,i,[...n,r])},op=[],sp=async(e,t)=>{let n=await ap(e.sourcesDir,t.split(`/`),op);if(n!==void 0)throw ve(`checkout path for '${t}' collides case-insensitively with existing '${n}'`)},cp=[],lp=e=>e===void 0?cp:[e],up=async e=>{try{return await i(e),!0}catch(e){if(V(e))return!1;throw e}},dp=async e=>{try{return await s(e)}catch(e){if(V(e))return;throw e}},fp=async e=>{try{return(await i(e)).isDirectory()}catch(e){if(V(e))return;throw e}},pp=async e=>{let t=await dp(e);if(t===void 0)return!0;if(t.length!==0)return!1;try{await d(e)}catch(e){if(!V(e))throw e}return!0},mp=async e=>{let t=await fp(e);return t===void 0?!0:t?pp(e):!1},hp=async(e,t)=>{t!==e.sourcesDir&&await mp(t)&&await hp(e,ne(t))},gp=async(e,t)=>await up(t)?(Us(e,t),await u(t,{force:!0,recursive:!0}),await hp(e,ne(t)),{removedCheckout:!0}):{removedCheckout:!1,warning:`checkout was already missing`},_p=(e,t)=>Object.fromEntries(Object.entries(e).filter(([e])=>e!==t)),vp=async(e,t)=>{let n=await W(e);await Zs(e,{...n,refs:_p(n.refs,t)});let r=await Z(e);await Vu(e,{...r,refs:_p(r.refs,t)})},yp=async(e,t)=>{let n=H(e.env),r=Kf(await W(n),t),i=U(n,r),{removedCheckout:a,warning:o}=await Y(n,Jf(r),()=>gp(n,i));return await Y(n,`home`,()=>vp(n,r)),{data:{key:r,removed_checkout:a},warnings:lp(o)}},bp=e=>e.removed_checkout?[`removed ${e.key} (checkout deleted)`]:[`removed ${e.key} (checkout was already missing)`],xp=(e,t)=>{e.command(`remove`).description(`Remove a configured ref: its config/state entry AND its checkout directory.`).argument(`<ref>`,`full ref key or a unique suffix, e.g. next.js`).action((e,n,r)=>{let i=r.optsWithGlobals(),a={json:i.json===!0,verbose:i.verbose===!0};return $(t,a,async()=>{let{data:n,warnings:r}=await yp(t,e);Q(t,a,bp(n),n,r)})()})},Sp=e=>`no ref matches '${e}' — run refs list, or add it: refs add <url>`,Cp=/^[a-z][a-z0-9+.-]*:\/\//iu,wp=/^git@[^:/\s]+:[^\s]+$/u,Tp=e=>Cp.test(e)||wp.test(e),Ep=(e,t)=>{try{return J(e,t)}catch{if(Tp(e))throw b(`query looks like a git url but is not a supported form — check the url (credentials are never accepted) or run: refs resolve <package|ref-suffix>`);return}},Dp=(e,t,n)=>{let r=Ep(t,n);if(r!==void 0){if(Object.hasOwn(e.refs,r.key))return{key:r.key};throw v(Sp(t))}},Op=(e,t)=>{let n=[];for(let r of Object.keys(e.refs).toSorted()){let i=e.refs[r]?.packages?.[t];i!==void 0&&n.push({entry:i,key:z.parse(r)})}return n},kp=(e,t)=>`package '${e}' is registered by more than one ref: ${t.join(`, `)} — use the full ref key`,Ap=(e,t)=>{let n=Op(e,t),[r]=n;if(r!==void 0){if(n.length>1)throw y(kp(t,n.map(e=>e.key)));return r}},jp=(e,t)=>{let n=t.split(`/`);for(let t=n.length-1;t>=1;--t){let r=n.slice(0,t).join(`/`),i=Ap(e,r);if(i!==void 0)return{...i,name:r}}},Mp=(e,t)=>{try{return Kf(e,t)}catch(e){throw e instanceof _&&e.code===`not_found`?v(Sp(t)):e}},Np=(e,t,n)=>{let r=Dp(e,t,n);if(r!==void 0)return r;let i=Ap(e,t);if(i!==void 0)return{key:i.key,packageMatch:{...i,name:t}};let a=jp(e,t);return a===void 0?{key:Mp(e,t)}:{key:a.key,packageMatch:a}},Pp=(e,t)=>{let n=e.refs[t];if(n===void 0)throw Error(`internal: resolved ref key '${t}' is missing from config.refs`);return n},Fp=(e,t)=>{if(e.packageMatch===void 0)return null;let{entry:n,name:r}=e.packageMatch;return{local_path:m(t,n.path),name:r,path:n.path}},Ip=async(e,t)=>{let n=H(e.env),r=await W(n),i=Np(r,t,{allowFileUrls:Yf(e.env)}),a=Pp(r,i.key),o=await Z(n),s=U(n,i.key),c=Zo(X(`sync_ttl`,a,r.settings));return{key:i.key,local_path:s,missing:!G(s),package:Fp(i,s),stale:Rf(o.refs[i.key]?.last_fetched_at,c,Date.now())}},Lp=e=>{let t=[e.key,`local_path: ${e.local_path}`];return e.package!==null&&t.push(`package: ${e.package.name}`,`local_path: ${e.package.local_path}`),t},Rp=(e,t)=>{e.command(`resolve`).description(`Resolve a git url, npm package name, import path, or ref-key suffix to its ref/package.`).argument(`<query>`,`git url, npm package name, import path, or unique ref-key suffix`).action((e,n,r)=>{let i=r.optsWithGlobals(),a={json:i.json===!0,verbose:i.verbose===!0};return $(t,a,async()=>{let n=await Ip(t,e);Q(t,a,Lp(n),n)})()})},zp={},Bp=(e,t)=>{let n=e.refs[t];if(n===void 0)throw Error(`internal: matched ref key '${t}' is missing from config.refs`);return n},Vp=e=>e instanceof Error?e.message:String(e),Hp=async(e,t)=>{if(!G(t))return{tags:[]};try{return{tags:await Oc(e.runner,t,5)}}catch(e){return{tags:[],warning:`could not list tags: ${Vp(e)}`}}},Up=[],Wp=e=>e===void 0?Up:[e],Gp=async(e,t)=>{let n=H(e.env),r=await W(n),i=Kf(r,t),a=Bp(r,i),o=await Z(n),s=U(n,i),{tags:c,warning:l}=await Hp(e,s);return{data:{...a,key:i,local_path:s,sample_tags:c,state:o.refs[i]??zp},warnings:Wp(l)}},Kp=e=>{let t=[`${e.key} ${e.description}`,`url: ${e.url}`,`local_path: ${e.local_path}`];return e.sample_tags.length>0&&t.push(`tags: ${e.sample_tags.join(`, `)}`),t},qp=(e,t)=>{e.command(`show`).description(`Show a configured ref: full entry, state, local path, and sample tags.`).argument(`<ref>`,`full ref key or a unique suffix, e.g. next.js`).action((e,n,r)=>{let i=r.optsWithGlobals(),a={json:i.json===!0,verbose:i.verbose===!0};return $(t,a,async()=>{let{data:n,warnings:r}=await Gp(t,e);Q(t,a,Kp(n),n,r)})()})},Jp=(e,t)=>{let n={head_sha:t.headSha,last_fetched_at:new Date().toISOString()},r=t.effectiveCloneMode??e?.effective_clone_mode;return r!==void 0&&(n.effective_clone_mode=r),n},Yp=async(e,t,n)=>{let r=await W(e),i=r.refs[t];i!==void 0&&(r.refs[t]={...i,default_branch:n},await Zs(e,r))},Xp=(e,t,n)=>Y(e,`home`,async()=>{n.branchRenamedTo!==void 0&&await Yp(e,t,n.branchRenamedTo);let r=await Z(e);r.refs[t]=Jp(r.refs[t],n),await Vu(e,r)}),Zp=async(e,t,n)=>{try{await Y(e,`home`,async()=>{let r=await Z(e);r.refs[t]={...r.refs[t],last_error:n},await Vu(e,r)})}catch{}},Qp=e=>{let t=0,n=[];return{acquire:()=>{if(t<e)return t+=1,Promise.resolve();let{promise:r,resolve:i}=Promise.withResolvers();return n.push(()=>{t+=1,i()}),r},release:()=>{--t;let e=n.shift();e!==void 0&&e()}}},$p=async(e,t)=>{await e.acquire();try{return await t()}finally{e.release()}},em=(e,t,n)=>`checkout at ${e} points at '${q(t)}' — expected '${q(n)}'; remove the checkout directory or run refs remove before retrying`,tm=e=>e.exitCode===0?e.stdout.trim():`(no origin remote)`,nm=(e,t)=>{try{return J(e,{allowFileUrls:t}).key}catch{return}},rm=async(e,t)=>{let n=await e.run(`git`,[`remote`,`get-url`,`origin`],{cwd:t.dest}),r=tm(n),i=nm(t.expectedUrl,t.allowFileUrls),a=nm(r,t.allowFileUrls);if(!(i!==void 0&&a===i))throw ve(em(t.dest,r,t.expectedUrl))},im=e=>`checkout at ${e} exists but is not refs-managed — remove it (rm -rf ${e}) and retry`,am=async(e,t)=>{let n=await e.run(`git`,[`config`,`--local`,`core.hooksPath`],{cwd:t.dest});if(n.exitCode!==0||n.stdout.trim()!==t.hooksDir)throw ve(im(t.dest))},om=async(e,t)=>{await a(ne(t.dest),{recursive:!0}),Od(e,`cloning ${q(t.cloneUrl)} into ${t.dest}…`);let n=await yc(e.runner,t);return n.warning===void 0?{effectiveMode:n.effectiveMode}:{effectiveMode:n.effectiveMode,warning:n.warning}},sm=async(e,t)=>(Us(t.home,t.dest),G(t.dest)?(await rm(e.runner,{allowFileUrls:t.allowFileUrls,dest:t.dest,expectedUrl:t.cloneUrl}),await am(e.runner,{dest:t.dest,hooksDir:t.hooksDir}),{}):om(e,t)),cm=(e,t)=>`checkout for '${e}' at ${t} is missing or corrupt (git rev-parse HEAD failed) — run: refs remove ${e}, then refs add <source> --dry-run again`,lm=(e,t,n)=>`checkout for '${e}' at ${t} has a HEAD sha refs cannot store yet (${n.length} hex chars, expected 40) — only SHA-1 repositories are supported for now; \`--object-format=sha256\` repositories are not yet supported`,um=async(e,t)=>{await rm(e,t),await am(e,{dest:t.dest,hooksDir:t.hooksDir});let n=await e.run(`git`,[`rev-parse`,`HEAD`],{cwd:t.dest});if(n.exitCode!==0)throw b(cm(t.key,t.dest));let r=n.stdout.trim();if(!Lu.shape.head_sha.safeParse(r).success)throw b(lm(t.key,t.dest,r));return r},dm=(e,t,n)=>`sync produced a HEAD sha for '${e}' at ${t} that refs cannot store yet (${n.length} hex chars) — only SHA-1 repositories are supported for now`,fm=(e,t,n)=>{if(!Lu.shape.head_sha.safeParse(n).success)throw b(dm(e,t,n));return n},pm=(e,t,n)=>{let r={effectiveCloneMode:t.effectiveMode,headSha:n.headSha,status:`cloned`};return n.actualBranch!==e.ref.default_branch&&(r.branchRenamedTo=n.actualBranch),t.warning!==void 0&&(r.warning=t.warning),r},mm=async(e,t,n)=>{await a(ne(n),{recursive:!0});let r=X(`clone_mode`,t.ref,t.settings),i=await yc(e.runner,{cloneUrl:t.ref.url,dest:n,hooksDir:t.home.hooksDir,mode:r}),o=await xc(e.runner,n),s=await um(e.runner,{allowFileUrls:Yf(e.env),dest:n,expectedUrl:t.ref.url,hooksDir:t.home.hooksDir,key:t.key});return pm(t,i,{actualBranch:o,headSha:s})},hm=async(e,t,n)=>{await am(e.runner,{dest:n,hooksDir:t.home.hooksDir}),await rm(e.runner,{allowFileUrls:Yf(e.env),dest:n,expectedUrl:t.ref.url});let r=await Dc(e.runner,{defaultBranch:t.ref.default_branch,dir:n}),i={headSha:fm(t.key,n,r.newSha),status:r.status};return r.branchRenamedTo!==void 0&&(i.branchRenamedTo=r.branchRenamedTo),r.warning!==void 0&&(i.warning=r.warning),i},gm=(e,t)=>Y(t.home,Jf(t.key),()=>{let n=U(t.home,t.key);return Us(t.home,n),G(n)?hm(e,t,n):mm(e,t,n)}),_m=e=>e instanceof Error?e.message:String(e),vm=e=>{let t=[];e.branchRenamedTo!==void 0&&t.push(`default branch renamed to ${e.branchRenamedTo}`),e.warning!==void 0&&t.push(e.warning);let[n]=t;if(n!==void 0)return t.join(` | `)},ym=(e,t)=>{let n={key:e,status:t.status},r=vm(t);return r!==void 0&&(n.warning=r),n},bm=async(e,t)=>{try{let n=await gm(e,t);return await Xp(t.home,t.key,n),ym(t.key,n)}catch(e){let n=_m(e);return await Zp(t.home,t.key,n),{error:n,key:t.key,status:`failed`}}},xm=(e,t)=>e.status===`fulfilled`?e.value:{error:_m(e.reason),key:t,status:`failed`},Sm=async(e,t)=>{let n=Qp(4);return(await Promise.allSettled(t.map(t=>$p(n,()=>bm(e,t))))).map((e,n)=>{let r=t[n];if(r===void 0)throw Error(`internal: sync target at index ${n} is missing`);return xm(e,r.key)})},Cm=(e,t)=>{let n=e.refs[t];if(n===void 0)throw Error(`internal: matched ref key '${t}' is missing from config.refs`);return n},wm=(e,t,n)=>({home:e,key:n,ref:Cm(t,n),settings:t.settings}),Tm=(e,t,n)=>n.length===0?Object.keys(t.refs).toSorted().map(n=>wm(e,t,z.parse(n))):n.map(n=>wm(e,t,Kf(t,n))),Em=(e,t,n)=>{let r=Date.now();return t.filter(t=>{let i=Zo(X(`sync_ttl`,t.ref,t.settings)),a=Rf(n.refs[t.key]?.last_fetched_at,i,r),o=!G(U(e,t.key));return a||o})},Dm=async(e,t,n)=>{if(!n)return t;let r=await Z(e);return Em(e,t,r)},Om=async(e,t)=>{let n=H(e.env),r=await W(n),i=Tm(n,r,t.refs),a=await Sm(e,await Dm(n,i,t.staleOnly));return{failedCount:a.filter(e=>e.status===`failed`).length,results:a}},km=[`updated`,`fresh`,`cloned`,`restored`,`failed`],Am={cloned:`Cloned`,failed:`Failed`,fresh:`Fresh`,restored:`Restored`,updated:`Updated`},jm=e=>{let t={cloned:[],failed:[],fresh:[],restored:[],updated:[]};for(let n of e)t[n.status].push(n);return t},Mm=e=>e.status===`failed`?` ${e.key}: ${e.error??`unknown error`}`:e.warning===void 0?` ${e.key}`:` ${e.key} (${e.warning})`,Nm=e=>{let t=jm(e),n=[km.map(e=>`${Am[e]} (${t[e].length})`).join(` / `)];for(let e of km)for(let r of t[e])n.push(Mm(r));return n},Pm=(e,t)=>({refs:e,staleOnly:t.staleOnly===!0}),Fm=(e,t)=>{e.command(`sync`).description(`Fetch (or re-clone, if the checkout is missing) configured refs — all by default.`).argument(`[refs...]`,`ref keys or unique suffixes to sync (default: every configured ref)`).option(`--stale-only`,`skip refs whose last sync is still within their ref's sync_ttl`).action((e,n,r)=>{let i=r.optsWithGlobals(),a={json:i.json===!0,verbose:i.verbose===!0};return $(t,a,async()=>{let r=await Om(t,Pm(e,n));Q(t,a,Nm(r.results),{results:r.results}),r.failedCount>0&&(process.exitCode=g.UNEXPECTED)})()})},Im=(e,t)=>{let n=e.refs[t];if(n===void 0)throw Error(`internal: matched ref key '${t}' is missing from config.refs`);return n},Lm=(e,t,n)=>{if(n===void 0)return e.tag_format;let r=e.packages?.[n];if(r===void 0)throw v(`no package '${n}' registered on ref '${t}'`);return r.tag_format??e.tag_format},Rm=(e,t)=>{if(!G(e))throw v(`checkout for '${t}' is missing — run: refs sync ${t}`)},zm=async(e,t)=>{let n=H(e.env),r=await W(n),i=Kf(r,t.query),a=Im(r,i),o=Lm(a,i,t.opts.packageName),s=U(n,i);Rm(s,i);let c=await Uc(e.runner,s,o,t.version);return{key:i,ref_path:`refs/tags/${c}`,tag:c,version:t.version}},Bm=e=>[`${e.key}@${e.version} -> ${e.tag}`],Vm=e=>{let t={};return e.package!==void 0&&(t.packageName=e.package),t},Hm=[Pf,Lf,xp,Rp,qp,Fm,(e,t)=>{e.command(`tag`).description(`Resolve a version to its git tag, via the ref's (or a package's) tag_format.`).argument(`<ref>`,`full ref key or a unique suffix, e.g. next.js`).argument(`<version>`,`version to resolve, e.g. 15.3.0`).option(`--package <name>`,`resolve against this package's tag_format instead of the ref's`).action((e,n,r,i)=>{let a=i.optsWithGlobals(),o={json:a.json===!0,verbose:a.verbose===!0};return $(t,o,async()=>{let i=await zm(t,{opts:Vm(r),query:e,version:n});Q(t,o,Bm(i),i)})()})}],Um=e=>e.description===void 0?{path:e.path}:{description:e.description,path:e.path},Wm=(e,t,n)=>e.length>0?Object.fromEntries(e.map(e=>[e.name,Um(e)])):n===void 0?{}:{[n]:{path:t??`.`}},Gm=e=>{let t=e.description??``;return e.tag_format===void 0?{description:t,path:e.path}:{description:t,path:e.path,tag_format:e.tag_format}},Km=e=>{let t=Object.entries(e);if(t.length!==0)return Object.fromEntries(t.map(([e,t])=>[e,Gm(t)]))},qm=e=>e.description===void 0||e.description===``,Jm=e=>Object.entries(e).filter(([,e])=>qm(e)).map(([e])=>e).toSorted(),Ym=e=>{let t=Jm(e);if(t.length!==0)throw b(`packages without a detected description: ${t.join(`, `)} — run the two-phase flow instead: refs add <source> --dry-run --json > proposal.json, fill in the package descriptions, then refs add --proposal proposal.json`)},Xm=e=>{if(Object.keys(e).length!==0)return e},Zm=e=>{if(e===null)throw b(`tag_format_candidate must be set to a valid tag format (containing '{version}') before finalizing — edit the proposal and provide one, or add the ref manually`);return e},Qm=e=>e.packages===void 0?{default_branch:e.default_branch,description:e.description,tag_format:e.tag_format,url:e.url}:{default_branch:e.default_branch,description:e.description,packages:e.packages,tag_format:e.tag_format,url:e.url},$m=[],eh=e=>e===void 0?[...$m]:[e],th=async(e,t,n)=>{let r=await xc(e.runner,t),i=Vc(await Oc(e.runner,t));return Od(e,`detecting workspace packages…`),{defaultBranch:r,packages:Wm(await cd(t),n.npmDirectory,n.npmPkgName),tagFormatCandidate:i}},nh=(e,t)=>Y(t.home,Jf(t.resolved.key),async()=>{let n=await sm(e,{allowFileUrls:Yf(e.env),cloneUrl:t.resolved.cloneUrl,dest:t.dest,home:t.home,hooksDir:t.home.hooksDir,mode:t.cloneMode}),r={fields:await th(e,t.dest,t.resolved)};return n.effectiveMode!==void 0&&(r.effectiveMode=n.effectiveMode),n.warning!==void 0&&(r.warning=n.warning),r}),rh=e=>{let t={default_branch:e.cloneResult.fields.defaultBranch,description:``,key:e.resolved.key,packages:e.cloneResult.fields.packages,tag_format_candidate:e.cloneResult.fields.tagFormatCandidate,url:e.resolved.cloneUrl},n={dest:e.dest,proposal:t};return e.cloneResult.effectiveMode!==void 0&&(n.effectiveCloneMode=e.cloneResult.effectiveMode),e.cloneResult.warning!==void 0&&(n.warning=e.cloneResult.warning),n},ih=async(e,t)=>{let n=H(e.env),r=await W(n),i=$f(await Qf(e,t),r.settings);tp(r,i.key),await sp(n,i.key);let a=U(n,i.key),o=X(`clone_mode`,void 0,r.settings),s=await nh(e,{cloneMode:o,dest:a,home:n,resolved:i});return rh({cloneResult:s,dest:a,resolved:i})},ah=(e,t,n)=>Y(e,`home`,async()=>{tp(await W(e),t);let r=await Z(e),i=r.refs[t],a=n??i?.effective_clone_mode,o={...i,pending_proposal_at:new Date().toISOString()};a!==void 0&&(o.effective_clone_mode=a),r.refs[t]=o,await Vu(e,r)}),oh=(e,t)=>{let n=ss.safeParse(e);if(!n.success)throw b(O(n.error));let r=Ru.safeParse(t);if(!r.success)throw b(O(r.error));return{config:n.data,state:r.data}},sh=async(e,t)=>{let n=await W(e.home);tp(n,e.ref.key);let r=Qm(e.ref);n.refs[e.ref.key]=r;let i=await Z(e.home);return i.refs[e.ref.key]={effective_clone_mode:e.effectiveCloneMode??i.refs[e.ref.key]?.effective_clone_mode??X(`clone_mode`,void 0,n.settings),head_sha:t,last_fetched_at:new Date().toISOString()},{...oh(n,i),entry:r}},ch=async(e,t)=>{let n=Yf(e.env),r=await Y(t.home,Jf(t.ref.key),()=>(Us(t.home,t.dest),um(e.runner,{allowFileUrls:n,dest:t.dest,expectedUrl:t.ref.url,hooksDir:t.home.hooksDir,key:t.ref.key})));return Y(t.home,`home`,async()=>{let{config:e,entry:n,state:i}=await sh(t,r);return await Vu(t.home,i),await Zs(t.home,e),{entry:n,key:t.ref.key}})},lh=(e,t)=>t===`-`?e.readStdin():o(t,`utf8`),uh=e=>e instanceof Error?e.message:String(e),dh=e=>{try{return JSON.parse(e)}catch(e){throw b(`invalid JSON in proposal: ${uh(e)}`)}},fh=e=>typeof e==`object`&&!!e&&!Array.isArray(e),ph=e=>fh(e)&&`ok`in e&&!(`key`in e),mh=e=>{if(!ph(e))return e;if(e.ok===!1)throw b(`proposal file contains a failed refs envelope (ok is false) — re-run the dry-run`);if(fh(e.data))return e.data;throw b(`proposal file is a refs envelope without a usable data object — re-run the dry-run`)},hh=e=>e.code===`unrecognized_keys`,gh=e=>e.path.length===0,_h=(e,t)=>{let n=t.toSorted().map(e=>`"${e}"`).join(`, `);return e===``?`✖ unrecognized key(s) in proposal: ${n}`:`✖ unrecognized key(s) in proposal at ${e}: ${n}`},vh=e=>{let t=new Map;for(let n of e){let e=ct(n.path);t.set(e,[...t.get(e)??[],...n.keys])}return[...t.entries()].toSorted(([e],[t])=>e.localeCompare(t)).map(([e,t])=>_h(e,t))},yh=e=>`✖ invalid proposal: ${e.message}`,bh=e=>{let t=e.issues.filter(e=>hh(e)),n=e.issues.filter(e=>!hh(e)),r=n.filter(e=>gh(e));if(t.length===0&&r.length===0)return O(e);let i=n.filter(e=>!gh(e)),a=[...vh(t),...r.map(e=>yh(e))];return i.length>0&&a.push(O({issues:i})),a.join(`
|
|
369
|
-
|
|
370
|
-
|
|
47
|
+
const printSourceLoadFailure = (error) => {
|
|
48
|
+
const [firstLine = ''] = error.message.split('\n');
|
|
49
|
+
console.error(`refs could not run from source (${error.code}: ${firstLine})`);
|
|
50
|
+
console.error('Run: pnpm install && pnpm build');
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
// Imports the two source modules the dev fallback needs. Split out of loadFromSource so the
|
|
54
|
+
// narrow try/catch around the import calls stays isolated: a module-loading failure here gets
|
|
55
|
+
// an actionable message, while a failure from actually running the CLI (see the bottom of this
|
|
56
|
+
// file) must keep propagating unchanged.
|
|
57
|
+
const importSourceModules = async (srcMain) => {
|
|
58
|
+
try {
|
|
59
|
+
const { run } = await import(pathToFileURL(srcMain).href);
|
|
60
|
+
const { realContext } = await import(
|
|
61
|
+
pathToFileURL(join(import.meta.dirname, '../src/context.ts')).href
|
|
62
|
+
);
|
|
63
|
+
return { realContext, run };
|
|
64
|
+
} catch (error) {
|
|
65
|
+
if (!isSourceLoadError(error)) {
|
|
66
|
+
throw error;
|
|
67
|
+
}
|
|
68
|
+
printSourceLoadFailure(error);
|
|
69
|
+
process.exit(EXIT_FAILURE);
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
// Dev fallback: run the TypeScript source directly via Node's native type stripping
|
|
74
|
+
// (stable in the exact engine range this package requires). Works only in a workspace
|
|
75
|
+
// checkout where ../src exists; the published package always ships dist/.
|
|
76
|
+
const loadFromSource = () => {
|
|
77
|
+
const srcMain = join(import.meta.dirname, '../src/main.ts');
|
|
78
|
+
// eslint-disable-next-line node/no-sync -- one-shot startup check before any I/O; simplest correct option for a zero-dependency stub
|
|
79
|
+
if (!existsSync(srcMain)) {
|
|
80
|
+
printNotBuiltMessage();
|
|
81
|
+
process.exit(EXIT_FAILURE);
|
|
82
|
+
// Unreachable in practice — defense-in-depth in case process.exit is ever intercepted.
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
return importSourceModules(srcMain);
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
const bundle = join(import.meta.dirname, '../dist/refs.mjs');
|
|
89
|
+
let loadModules = loadFromSource;
|
|
90
|
+
// eslint-disable-next-line node/no-sync -- one-shot startup check before any I/O; simplest correct option for a zero-dependency stub
|
|
91
|
+
if (existsSync(bundle)) {
|
|
92
|
+
loadModules = () => import(pathToFileURL(bundle).href);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const { realContext, run } = await loadModules();
|
|
96
|
+
await run(realContext(), process.argv);
|