@kaisers-io/refs 0.18.0 → 0.18.2
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/CHANGELOG.md +50 -4
- package/README.md +60 -71
- package/dist/refs.mjs +204 -45
- package/package.json +4 -4
package/dist/refs.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{access as e,chmod as t,constants as n,copyFile as r,lstat as i,mkdir as a,open as o,readFile as s,readdir as c,realpath as l,rename as u,rm as d,rmdir as f,stat as p,utimes as ee,writeFile as te}from"node:fs/promises";import ne,{constants as re,existsSync as ie,realpathSync as ae}from"node:fs";import oe,{basename as se,dirname as m,isAbsolute as ce,join as h,parse as le,posix as ue,relative as de,resolve as fe,sep as pe}from"node:path";import{createHash as me,randomUUID as he}from"node:crypto";import{homedir as ge}from"node:os";import{EventEmitter as _e,once as ve}from"node:events";import ye,{spawn as be}from"node:child_process";import{setTimeout as xe}from"node:timers/promises";import g from"node:process";import{stripVTControlCharacters as Se}from"node:util";const Ce=/[\u0000-\u0020\u007F~^:?*[\\]/u,we=e=>e.length>0&&!e.startsWith(`.`)&&!e.endsWith(`.lock`),Te=e=>e.length===0||e===`HEAD`||e.startsWith(`-`)||Ce.test(e)||e.includes(`..`)||e.includes(`@{`)||e.endsWith(`.`)||e.endsWith(`/`)||e.startsWith(`/`)?!1:e.split(`/`).every(e=>we(e));function Ee(e){let t=Object.values(e).filter(e=>typeof e==`number`);return Object.entries(e).filter(([e,n])=>t.indexOf(+e)===-1).map(([e,t])=>t)}function De(e,t=`|`){return e.map(e=>Ze(e)).join(t)}function Oe(e,t){return typeof t==`bigint`?t.toString():t}var ke=class{constructor(e){this._getter=e,this._value=void 0}get value(){let e=this._getter;return e!==void 0&&(this._value=e(),this._getter=void 0),this._value}};function Ae(e){return new ke(e)}function je(e){return e==null}function Me(e){let t=+!!e.startsWith(`^`),n=e.endsWith(`$`)?e.length-1:e.length;return e.slice(t,n)}function Ne(e,t){let n=e/t,r=Math.round(n),i=4*2**-52*Math.max(Math.abs(n),1);return Math.abs(n-r)<i?0:n-r}function Pe(e,t,n){Object.defineProperty(e,t,{value:n,writable:!0,enumerable:!0,configurable:!0})}function Fe(e){let t=Object.getOwnPropertyDescriptor(e,`shape`);return t?.get?t.get.raw:t?.value}function Ie(e){return Fe(e._zod.def)??e._zod.def.shape}function Le(e,t,n){Object.defineProperty(e,t,{get(){let e=n();return Pe(this,t,e),e},enumerable:!0,configurable:!0})}function Re(e,t,n){t in e?Pe(e,t,n):e[t]=n}function ze(e,t,n,r){let i=Ie(t);for(let a of n){let n=Object.getOwnPropertyDescriptor(i,a);n.enumerable&&(n.get?Le(e,a,()=>{let e=t._zod.def.shape[a];return r?r(e,a):e}):Re(e,a,r?r(n.value,a):n.value))}}function Be(e,t){for(let n of Reflect.ownKeys(t)){let r=Object.getOwnPropertyDescriptor(t,n);r.enumerable&&(r.get?Le(e,n,()=>t[n]):Re(e,n,r.value))}}function _(...e){let t={};for(let n of e){let e=Object.getOwnPropertyDescriptors(n);Object.assign(t,e)}return Object.defineProperties({},t)}function Ve(e){return JSON.stringify(e)}function He(e){return e.toLowerCase().trim().replace(/[^\w\s-]/g,``).replace(/[\s_-]+/g,`-`).replace(/^-+|-+$/g,``)}const Ue=`captureStackTrace`in Error?Error.captureStackTrace:(...e)=>{};function We(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}const Ge=Ae(()=>{if(x.jitless||typeof navigator<`u`&&navigator?.userAgent?.includes(`Cloudflare`))return!1;try{return Function(``),!0}catch{return!1}});function Ke(e){if(We(e)===!1)return!1;let t=e.constructor;if(t===void 0||typeof t!=`function`)return!0;let n=t.prototype;return We(n)!==!1&&Object.prototype.hasOwnProperty.call(n,`isPrototypeOf`)!==!1}function qe(e){return Ke(e)?{...e}:Array.isArray(e)?[...e]:e instanceof Map?new Map(e):e instanceof Set?new Set(e):e}const Je=new Set([`string`,`number`,`symbol`]);function Ye(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function Xe(e,t,n){let r=new e._zod.constr(t??e._zod.def);return(!t||n?.parent)&&(r._zod.parent=e),r}function v(e){let t=e;if(!t)return{};if(typeof t==`string`)return{error:()=>t};if(t?.message!==void 0){if(t?.error!==void 0)throw Error("Cannot specify both `message` and `error` params");t.error=t.message}return delete t.message,typeof t.error==`string`?{...t,error:()=>t.error}:t}function Ze(e){return typeof e==`bigint`?e.toString()+`n`:typeof e==`string`?`"${e}"`:`${e}`}function Qe(e){return Object.keys(e).filter(t=>e[t]._zod.optin!==void 0&&e[t]._zod.optout===`optional`)}const $e={safeint:[-(2**53-1),2**53-1],int32:[-2147483648,2147483647],uint32:[0,4294967295],float32:[-34028234663852886e22,34028234663852886e22],float64:[-Number.MAX_VALUE,Number.MAX_VALUE]},et={int64:[BigInt(`-9223372036854775808`),BigInt(`9223372036854775807`)],uint64:[BigInt(0),BigInt(`18446744073709551615`)]};function tt(e,t){let n=e._zod.def,r=n.checks;if(r&&r.length>0)throw Error(`.pick() cannot be used on object schemas containing refinements`);let i={};return ze(i,e,nt(e,t)),Xe(e,_(n,{shape:i,checks:[]}))}function nt(e,t){let n=Ie(e),r=[];for(let e of Reflect.ownKeys(t)){if(!Object.getOwnPropertyDescriptor(n,e)?.enumerable)throw Error(`Unrecognized key: "${String(e)}"`);t[e]&&r.push(e)}return r}function rt(e,t){let n=e._zod.def,r=n.checks;if(r&&r.length>0)throw Error(`.omit() cannot be used on object schemas containing refinements`);let i=new Set(nt(e,t)),a={};return ze(a,e,Reflect.ownKeys(Ie(e)).filter(e=>!i.has(e))),Xe(e,_(n,{shape:a,checks:[]}))}function it(e,t){if(!Ke(t))throw Error(`Invalid input to extend: expected a plain object`);let n=e._zod.def.checks;if(n&&n.length>0){let n=Ie(e);for(let e of Reflect.ownKeys(t))if(Object.getOwnPropertyDescriptor(n,e)!==void 0)throw Error("Cannot overwrite keys on object schemas containing refinements. Use `.safeExtend()` instead.")}return Xe(e,_(e._zod.def,{shape:at(e,t)}))}function at(e,t){let n={};return ze(n,e,Reflect.ownKeys(Ie(e))),Be(n,t),n}function ot(e,t){if(!Ke(t))throw Error(`Invalid input to safeExtend: expected a plain object`);return Xe(e,_(e._zod.def,{shape:at(e,t)}))}function st(e,t){if(!t?._zod?.def)throw Error("Invalid input to merge: expected an object schema. To merge a plain shape, use `.extend()`.");if(e._zod.def.checks?.length)throw Error(`.merge() cannot be used on object schemas containing refinements. Use .safeExtend() instead.`);let n={};return ze(n,e,Reflect.ownKeys(Ie(e))),ze(n,t,Reflect.ownKeys(Ie(t))),Xe(e,_(e._zod.def,{shape:n,get catchall(){return t._zod.def.catchall},checks:t._zod.def.checks??[]}))}function ct(e,t,n,r=`partial`){let i=t._zod.def.checks;if(i&&i.length>0)throw Error(`.${r}() cannot be used on object schemas containing refinements`);let a=n?new Set(nt(t,n)):void 0,o={};return ze(o,t,Reflect.ownKeys(Ie(t)),e&&((t,n)=>a&&!a.has(n)?t:new e({type:`optional`,innerType:t}))),Xe(t,_(t._zod.def,{shape:o,checks:[]}))}function lt(e,t,n){let r=n?new Set(nt(t,n)):void 0,i={};return ze(i,t,Reflect.ownKeys(Ie(t)),(t,n)=>r&&!r.has(n)?t:new e({type:`nonoptional`,innerType:t})),Xe(t,_(t._zod.def,{shape:i}))}function ut(e,t=0){if(e.aborted===!0)return!0;for(let n=t;n<e.issues.length;n++)if(e.issues[n]?.continue!==!0)return!0;return!1}function dt(e,t=0){if(e.aborted===!0)return!0;for(let n=t;n<e.issues.length;n++)if(e.issues[n]?.continue===!1)return!0;return!1}function ft(e,t){return t.map(t=>{var n;return(n=t).path??(n.path=[]),t.path.unshift(e),t})}function pt(e){return typeof e==`string`?e:e?.message}function mt(e,t,n){var r;for(let i=t;i<e.length;i++)(r=e[i]).schema??(r.schema=n)}function ht(e,t,n){var r;let i=e.inst?._zod?.traits;i?.has(`$ZodType`)&&(i.has(`$ZodCheck`)?(r=e).schema??(r.schema=e.inst):e.schema=e.inst);let a=e.schema===e.inst?void 0:e.schema?._zod.def?.error,o=e.message?e.message:pt(e.inst?._zod.def?.error?.(e))??pt(a?.(e))??pt(t?.error?.(e))??pt(n.customError?.(e))??pt(n.localeError?.(e))??`Invalid input`,s={};for(let t of Object.keys(e))t!==`inst`&&t!==`schema`&&t!==`continue`&&t!==`input`&&t!==`__proto__`&&(s[t]=e[t]);return s.path??=[],s.message=o,t?.reportInput&&(s.input=e.input),s}const gt=/[\uD800-\uDBFF]/;function _t(e){let t=e.length;if(!gt.test(e))return t;let n=t;for(let r=0;r<t-1;r++)(e.charCodeAt(r)&64512)==55296&&(e.charCodeAt(r+1)&64512)==56320&&(n--,r++);return n}function vt(e){return Array.isArray(e)?`array`:typeof e==`string`?`string`:`unknown`}function yt(e){let t=typeof e;switch(t){case`number`:return Number.isNaN(e)?`nan`:`number`;case`object`:{if(e===null)return`null`;if(Array.isArray(e))return`array`;let t=e;if(t&&Object.getPrototypeOf(t)!==Object.prototype&&`constructor`in t&&t.constructor)return t.constructor.name}}return t}function bt(...e){let[t,n,r]=e;return typeof t==`string`?{message:t,code:`custom`,input:n,inst:r}:{...t}}function xt(e,t){for(let n in t){let r=Object.getOwnPropertyDescriptor(t,n);r.get?Object.defineProperty(e,n,{...r,enumerable:!1}):Tt(e,n,r.value)}for(let n of Object.getOwnPropertySymbols(t))Tt(e,n,t[n])}function St(e,t,n,r=!0){return Object.defineProperty(e,t,{configurable:!0,writable:!0,enumerable:r,value:n}),n}function Ct(e,t,n){return St(e,t,n,!1)}function wt(e,t){for(let n in e){let r=e[n];Object.defineProperty(t,n,{configurable:!0,enumerable:!0,get(){return St(this,n,r(this))},set(e){St(this,n,e)}})}return t}function Tt(e,t,n){Object.defineProperty(e,t,{configurable:!0,get(){return this==null?n:St(this,t,n.bind(this))},set(e){St(this,t,e)}})}function Et(e,t){let n=Object.getPrototypeOf(e);return t in n?void 0:n}let Dt,Ot=!1;const kt={configurable:!0,get(){Ot=!0}};function y(e,t,n){let r=Object.getPrototypeOf(e._zod);if(t in r&&Dt!==e._zod){Dt=void 0;return}Dt=e._zod,Object.defineProperty(r,t,{configurable:!0,get(){Object.defineProperty(this,t,kt);let e=Ot;Ot=!1;try{let r=n(this);return Ot?delete this[t]:Object.defineProperty(this,t,{configurable:!0,writable:!0,value:r}),Ot||=e,r}catch(n){throw delete this[t],Ot||=e,n}},set(e){Object.defineProperty(this,t,{configurable:!0,writable:!0,value:e})}})}function At(e,t,n,r){let i=Et(e,t);i&&Object.defineProperty(i,t,{configurable:!0,get(){let e={configurable:!0,writable:!0,enumerable:r,value:void 0};return Object.defineProperty(this,t,e),e.value=n(this),Object.defineProperty(this,t,e),e.value},set(e){Object.defineProperty(this,t,{configurable:!0,writable:!0,enumerable:r,value:e})}})}function jt(e){let t=()=>e;return t[`~constantCatch`]=!0,t}var Mt;const Nt={value:void 0,enumerable:!1};let Pt=`captureStackTrace`in Error?Error:null;function Ft(e){let t=Pt;if(t){let n=t.stackTraceLimit;if(typeof n==`number`){try{t.stackTraceLimit=0}catch{return Pt=null,new e}try{return new e}finally{t.stackTraceLimit=n}}}return new e}function b(e,t,n,r){let i={};function a(e){this.def=e,this.constr=d,this.traits=new Set}a.prototype=i;let o=n,s=o&&new WeakSet;function c(n,r){if(!n._zod){Nt.value=new a(r);try{Object.defineProperty(n,"_zod",Nt)}finally{Nt.value=void 0}}if(n._zod.traits.has(e))return;if(n._zod.traits.add(e),t(n,r),s){let e=Object.getPrototypeOf(n),t=n._zod.constr.prototype,r=e;for(;r&&r!==t;)r=Object.getPrototypeOf(r);let i=r??e;s.has(i)||(s.add(i),xt(i,o))}let i=d.prototype;for(let e in i)Object.prototype.hasOwnProperty.call(i,e)&&(e in n||(n[e]=i[e].bind(n)))}let l=r?.Parent??Object;class u extends l{}Object.defineProperty(u,"name",{value:e});function d(e){let t=r?.Parent?Ft(u):this;c(t,e);let n=t._zod.deferred;if(n){for(let e of n)e();t._zod.deferred=void 0}let i=globalThis.__zod_globalConfig?.postProcessor;return i&&i(t),t}return Object.defineProperty(d,"init",{value:c}),Object.defineProperty(d,Symbol.hasInstance,{value:t=>r?.Parent&&t instanceof r.Parent?!0:t?._zod?.traits?.has(e)}),Object.defineProperty(d,"name",{value:e}),d}var It=class extends Error{constructor(){super(`Encountered Promise during synchronous parse. Use .parseAsync() instead.`)}},Lt=class extends Error{constructor(e){super(`Encountered unidirectional transform during encode: ${e}`),this.name=`ZodEncodeError`}};(Mt=globalThis).__zod_globalConfig??(Mt.__zod_globalConfig={});const x=globalThis.__zod_globalConfig;function Rt(e){return e&&Object.assign(x,e),x}function zt(){let e=this._zod;return e.message??=JSON.stringify(e.def,Oe,2),e.message}function Bt(e){this._zod.message=e}const Vt={get:zt,set:Bt,enumerable:!0,configurable:!0},Ht={value:void 0,enumerable:!1},Ut=new WeakSet([Object.prototype,Error.prototype]),Wt=(e,t)=>{e.name=`$ZodError`,Ht.value=t,Object.defineProperty(e,"issues",Ht),Ht.value=void 0,Object.defineProperty(e,"message",Vt);let n=Object.getPrototypeOf(e);Ut.has(n)||(Ut.add(n),Object.defineProperty(n,"toString",{configurable:!0,enumerable:!1,get(){let e=()=>this.message;return Object.defineProperty(this,"toString",{value:e,configurable:!0,writable:!0}),e},set(e){Object.defineProperty(this,"toString",{value:e,configurable:!0,writable:!0})}}))},Gt=b(`$ZodError`,Wt);b(`$ZodError`,Wt,void 0,{Parent:Error});function Kt(e,t,n){return Object.prototype.hasOwnProperty.call(e,t)||(t===`__proto__`?Object.defineProperty(e,t,{value:n(),writable:!0,enumerable:!0,configurable:!0}):e[t]=n()),e[t]}function qt(e,t=e=>e.message){let n={},r=[];for(let i of e.issues)i.path.length>0?Kt(n,i.path[0],()=>[]).push(t(i)):r.push(t(i));return{formErrors:r,fieldErrors:n}}function Jt(e,t=e=>e.message){let n={_errors:[]},r=(e,i=[])=>{for(let a of e.issues)if(a.code===`invalid_union`&&a.errors.length)a.errors.map(e=>r({issues:e},[...i,...a.path]));else if(a.code===`invalid_key`)r({issues:a.issues},[...i,...a.path]);else if(a.code===`invalid_element`)r({issues:a.issues},[...i,...a.path]);else{let e=[...i,...a.path];if(e.length===0)n._errors.push(t(a));else{let r=n,i=0;for(;i<e.length;){let n=e[i],o=i===e.length-1;if(n===`_errors`){o&&r._errors.push(t(a)),i++;continue}Object.prototype.hasOwnProperty.call(r,n)||Object.defineProperty(r,n,{value:{_errors:[]},enumerable:!0,writable:!0,configurable:!0});let s=r[n];o&&s._errors.push(t(a)),r=s,i++}}}};return r(e),n}function Yt(e){let t=[],n=e.map(e=>typeof e==`object`?e.key:e);for(let e of n)typeof e==`number`?t.push(`[${e}]`):typeof e==`symbol`?t.push(`[${JSON.stringify(String(e))}]`):/[^\w$]/.test(e)?t.push(`[${JSON.stringify(e)}]`):(t.length&&t.push(`.`),t.push(e));return t.join(``)}function S(e){let t=[],n=[...e.issues].sort((e,t)=>(e.path??[]).length-(t.path??[]).length);for(let e of n)t.push(`✖ ${e.message}`),e.path?.length&&t.push(` → at ${Yt(e.path)}`);return t.join(`
|
|
3
|
-
`)}function Xt(e,t){return{callee:t?.callee??e,Err:t?.Err}}const Zt=e=>{let t=(n,r,i,a)=>{let o=i?{...i,async:!1}:{async:!1},s=n._zod.run({value:r,issues:[]},o);if(s instanceof Promise)throw new It;if(s.issues.length){let n=new((a?.Err)??e)(s.issues.map(e=>ht(e,o,Rt())));throw Ue(n,a?.callee??t),n}return s.value};return t},Qt=e=>{let t=async(n,r,i,a)=>{let o=i?{...i,async:!0}:{async:!0},s=n._zod.run({value:r,issues:[]},o);if(s instanceof Promise&&(s=await s),s.issues.length){let n=new((a?.Err)??e)(s.issues.map(e=>ht(e,o,Rt())));throw Ue(n,a?.callee??t),n}return s.value};return t},$t=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 It;return a.issues.length?en(e,a.issues,i):{success:!0,data:a.value}};function en(e,t,n){let r;return{success:!1,get error(){return r||(r=new e(t.map(e=>ht(e,n,Rt()))),t=void 0,n=void 0),r},set error(e){r=e,t=void 0,n=void 0}}}const tn=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?en(e,a.issues,i):{success:!0,data:a.value}},nn=Symbol.for(`zod.compile.invalid`),rn=Symbol.for(`zod.compile.fallback`),an=((e,t,n)=>{let r=e._zod.bag.validator;if(r!==void 0){if(r(t)!==nn)return!0;if(r.definite===!0&&n===void 0)return!1}return on(e,t,n)});function on(e,t,n){let r=n?{...n,async:!1,abortEarly:!0}:{async:!1,abortEarly:!0},i=e._zod.bag.fallbackRun,a;if(i?(r[rn]=!0,a=i({value:t,issues:[]},r)):a=e._zod.run({value:t,issues:[]},r),a instanceof Promise)throw new It;return a.issues.length===0}const sn=async(e,t,n)=>{let r=n?{...n,async:!0,abortEarly:!0}:{async:!0,abortEarly:!0},i=e._zod.run({value:t,issues:[]},r);return i instanceof Promise&&(i=await i),i.issues.length===0},cn=e=>{let t=Zt(e),n=(e,r,i,a)=>{let o=i?{...i,direction:`backward`}:{direction:`backward`};return t(e,r,o,Xt(n,a))};return n},ln=e=>{let t=Zt(e),n=(e,r,i,a)=>t(e,r,i,Xt(n,a));return n},un=e=>{let t=Qt(e),n=async(e,r,i,a)=>{let o=i?{...i,direction:`backward`}:{direction:`backward`};return await t(e,r,o,Xt(n,a))};return n},dn=e=>{let t=Qt(e),n=async(e,r,i,a)=>await t(e,r,i,Xt(n,a));return n},fn=e=>(t,n,r)=>{let i=r?{...r,direction:`backward`}:{direction:`backward`};return $t(e)(t,n,i)},pn=e=>(t,n,r)=>$t(e)(t,n,r),mn=e=>async(t,n,r)=>{let i=r?{...r,direction:`backward`}:{direction:`backward`};return tn(e)(t,n,i)},hn=e=>async(t,n,r)=>tn(e)(t,n,r),gn=/^[cC][0-9a-z]{6,}$/,_n=/^[0-9a-z]+$/,vn=/^[0-7][0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{25}$/,yn=/^[0-9a-vA-V]{20}$/,bn=/^[A-Za-z0-9]{27}$/,xn=/^[a-zA-Z0-9_-]{21}$/;function Sn(e){return RegExp(`^[a-zA-Z0-9_-]{${e}}$`)}const Cn=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/,wn=/^([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})$/,Tn=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)$/,En=/^(?:[A-Za-z0-9_'+\-]+\.)*[A-Za-z0-9_'+\-]*[A-Za-z0-9_+-]@(?:[A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/;function Dn(){return RegExp(`^(?=[\\s\\S]*[\\p{Extended_Pictographic}\\p{Regional_Indicator}\\u20E3])[\\p{Extended_Pictographic}\\p{Emoji_Component}]+$`,`u`)}const On=/^(?:(?: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])$/,kn=/^(([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}|:))$/,An=/^((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])$/,jn=/^(([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}|:))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,Mn=/^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/,Nn=/^(?:[A-Za-z0-9_-]{4})*(?:[A-Za-z0-9_-]{2,3})?$/,Pn=/^https?$/,Fn=/^\+[1-9]\d{6,14}$/,In=`(?:(?:\\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])))`;function Ln(e){return RegExp(`^${e}$`)}const Rn=Ln(In);function zn(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}}`:e.seconds?`${t}:[0-5]\\d(?:\\.\\d+)?`:`${t}(?::[0-5]\\d(?:\\.\\d+)?)?`}function Bn(e){return RegExp(`^${zn(e)}$`)}function Vn(e){let t=[`Z`];e.offset&&t.push(`([+-](?:[01]\\d|2[0-3]):[0-5]\\d)`);let n=`${zn({precision:e.precision,seconds:!0})}(?:${t.join(`|`)})`,r=e.local?`${n}|${zn({precision:e.precision})}`:n;return RegExp(`^${In}T(?:${r})$`)}const Hn=/^[\s\S]{0,}$/,Un=/^-?\d+$/,Wn=/^-?\d+(?:\.\d+)?$/,Gn=/^(?:true|false)$/i,Kn=/^[^A-Z]*$/,qn=/^[^a-z]*$/,C=b(`$ZodCheck`,(e,t)=>{var n;e._zod??={},e._zod.def=t,(n=e._zod).onattach??(n.onattach=[])}),Jn=e=>{let t=e.value;return!je(t)&&t.length!==void 0},Yn={number:`number`,bigint:`bigint`,object:`date`},Xn=b(`$ZodCheckLessThan`,(e,t)=>{C.init(e,t);let n=Yn[typeof t.value];e._zod.check=r=>{(t.inclusive?r.value<=t.value:r.value<t.value)||r.issues.push({origin:Yn[typeof r.value]??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})}}),Zn=b(`$ZodCheckGreaterThan`,(e,t)=>{C.init(e,t);let n=Yn[typeof t.value];e._zod.check=r=>{(t.inclusive?r.value>=t.value:r.value>t.value)||r.issues.push({origin:Yn[typeof r.value]??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})}}),Qn=b(`$ZodCheckMultipleOf`,(e,t)=>{C.init(e,t),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`?t.value!==BigInt(0)&&n.value%t.value===BigInt(0):Ne(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})}}),$n=b(`$ZodCheckNumberFormat`,(e,t)=>{C.init(e,t),t.format=t.format||`float64`;let n=t.format?.includes(`int`),r=n?`int`:`number`,[i,a]=$e[t.format];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})}}),er=b(`$ZodCheckMaxLength`,(e,t)=>{var n;C.init(e,t),(n=e._zod.def).when??(n.when=Jn),e._zod.check=n=>{let r=n.value,i=r.length;if((typeof r==`string`&&i>t.maximum?_t(r):i)<=t.maximum)return;let a=vt(r);n.issues.push({origin:a,code:`too_big`,maximum:t.maximum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),tr=b(`$ZodCheckMinLength`,(e,t)=>{var n;C.init(e,t),(n=e._zod.def).when??(n.when=Jn),e._zod.check=n=>{let r=n.value,i=r.length;if((typeof r==`string`&&i>=t.minimum&&i<t.minimum*2?_t(r):i)>=t.minimum)return;let a=vt(r);n.issues.push({origin:a,code:`too_small`,minimum:t.minimum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),nr=b(`$ZodCheckLengthEquals`,(e,t)=>{var n;C.init(e,t),(n=e._zod.def).when??(n.when=Jn),e._zod.check=n=>{let r=n.value,i=r.length,a=typeof r==`string`&&i>=t.length&&i<=t.length*2?_t(r):i;if(a===t.length)return;let o=vt(r),s=a>t.length;n.issues.push({origin:o,...s?{code:`too_big`,maximum:t.length}:{code:`too_small`,minimum:t.length},inclusive:!0,exact:!0,input:n.value,inst:e,continue:!t.abort})}}),rr=b(`$ZodCheckStringFormat`,(e,t)=>{var n,r;C.init(e,t),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=()=>{})}),ir=b(`$ZodCheckRegex`,(e,t)=>{rr.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})}}),ar=b(`$ZodCheckLowerCase`,(e,t)=>{t.pattern??=Kn,rr.init(e,t)}),or=b(`$ZodCheckUpperCase`,(e,t)=>{t.pattern??=qn,rr.init(e,t)}),sr=b(`$ZodCheckIncludes`,(e,t)=>{C.init(e,t);let n=Ye(t.includes);t.pattern=new RegExp(typeof t.position==`number`?`^.{${t.position},}${n}`:n),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})}}),cr=b(`$ZodCheckStartsWith`,(e,t)=>{C.init(e,t);let n=RegExp(`^${Ye(t.prefix)}.*`);t.pattern??=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})}}),lr=b(`$ZodCheckEndsWith`,(e,t)=>{C.init(e,t);let n=RegExp(`.*${Ye(t.suffix)}$`);t.pattern??=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})}}),ur=b(`$ZodCheckOverwrite`,(e,t)=>{C.init(e,t),e._zod.check=e=>{e.value=t.tx(e.value)}});var dr=class{constructor(e=[],t={}){this.content=[],this.indent=0,this.args=e,this.closed=t}indented(e){this.indent+=1;try{e(this)}finally{--this.indent}}write(e){if(typeof e==`function`){e(this,{execution:`sync`}),e(this,{execution:`async`});return}let t=e.split(`
|
|
2
|
+
import{access as e,chmod as t,constants as n,copyFile as r,lstat as i,mkdir as a,open as o,readFile as s,readdir as c,realpath as l,rename as u,rm as d,rmdir as f,stat as p,utimes as ee,writeFile as te}from"node:fs/promises";import ne,{constants as re,existsSync as ie,realpathSync as ae}from"node:fs";import oe,{basename as se,dirname as m,isAbsolute as ce,join as h,parse as le,posix as ue,relative as de,resolve as fe,sep as pe}from"node:path";import{createHash as me,randomUUID as he}from"node:crypto";import{homedir as ge}from"node:os";import{EventEmitter as _e,once as ve}from"node:events";import ye,{spawn as be}from"node:child_process";import{setTimeout as xe}from"node:timers/promises";import g from"node:process";import{stripVTControlCharacters as Se}from"node:util";const Ce=/[\u0000-\u0020\u007F~^:?*[\\]/u,we=e=>e.length>0&&!e.startsWith(`.`)&&!e.endsWith(`.lock`),Te=e=>e.length===0||e===`HEAD`||e.startsWith(`-`)||Ce.test(e)||e.includes(`..`)||e.includes(`@{`)||e.endsWith(`.`)||e.endsWith(`/`)||e.startsWith(`/`)?!1:e.split(`/`).every(e=>we(e));function Ee(e){let t=Object.values(e).filter(e=>typeof e==`number`);return Object.entries(e).filter(([e,n])=>t.indexOf(+e)===-1).map(([e,t])=>t)}function De(e,t=`|`){return e.map(e=>Ze(e)).join(t)}function Oe(e,t){return typeof t==`bigint`?t.toString():t}var ke=class{constructor(e){this._getter=e,this._value=void 0}get value(){let e=this._getter;return e!==void 0&&(this._value=e(),this._getter=void 0),this._value}};function Ae(e){return new ke(e)}function je(e){return e==null}function Me(e){let t=+!!e.startsWith(`^`),n=e.endsWith(`$`)?e.length-1:e.length;return e.slice(t,n)}function Ne(e,t){let n=e/t,r=Math.round(n),i=4*2**-52*Math.max(Math.abs(n),1);return Math.abs(n-r)<i?0:n-r}function Pe(e,t,n){Object.defineProperty(e,t,{value:n,writable:!0,enumerable:!0,configurable:!0})}function Fe(e){let t=Object.getOwnPropertyDescriptor(e,`shape`);return t?.get?t.get.raw:t?.value}function Ie(e){return Fe(e._zod.def)??e._zod.def.shape}function Le(e,t,n){Object.defineProperty(e,t,{get(){let e=n();return Pe(this,t,e),e},enumerable:!0,configurable:!0})}function Re(e,t,n){t in e?Pe(e,t,n):e[t]=n}function ze(e,t,n,r){let i=Ie(t);for(let a of n){let n=Object.getOwnPropertyDescriptor(i,a);n.enumerable&&(n.get?Le(e,a,()=>{let e=t._zod.def.shape[a];return r?r(e,a):e}):Re(e,a,r?r(n.value,a):n.value))}}function Be(e,t){for(let n of Reflect.ownKeys(t)){let r=Object.getOwnPropertyDescriptor(t,n);r.enumerable&&(r.get?Le(e,n,()=>t[n]):Re(e,n,r.value))}}function _(...e){let t={};for(let n of e){let e=Object.getOwnPropertyDescriptors(n);Object.assign(t,e)}return Object.defineProperties({},t)}function Ve(e){return JSON.stringify(e)}function He(e){return e.toLowerCase().trim().replace(/[^\w\s-]/g,``).replace(/[\s_-]+/g,`-`).replace(/^-+|-+$/g,``)}const Ue=`captureStackTrace`in Error?Error.captureStackTrace:(...e)=>{};function We(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}const Ge=/* @__PURE__*/ Ae(()=>{if(x.jitless||typeof navigator<`u`&&navigator?.userAgent?.includes(`Cloudflare`))return!1;try{return Function(``),!0}catch{return!1}});function Ke(e){if(We(e)===!1)return!1;let t=e.constructor;if(t===void 0||typeof t!=`function`)return!0;let n=t.prototype;return We(n)!==!1&&Object.prototype.hasOwnProperty.call(n,`isPrototypeOf`)!==!1}function qe(e){return Ke(e)?{...e}:Array.isArray(e)?[...e]:e instanceof Map?new Map(e):e instanceof Set?new Set(e):e}const Je=/* @__PURE__*/ new Set([`string`,`number`,`symbol`]);function Ye(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function Xe(e,t,n){let r=new e._zod.constr(t??e._zod.def);return(!t||n?.parent)&&(r._zod.parent=e),r}function v(e){let t=e;if(!t)return{};if(typeof t==`string`)return{error:()=>t};if(t?.message!==void 0){if(t?.error!==void 0)throw Error("Cannot specify both `message` and `error` params");t.error=t.message}return delete t.message,typeof t.error==`string`?{...t,error:()=>t.error}:t}function Ze(e){return typeof e==`bigint`?e.toString()+`n`:typeof e==`string`?`"${e}"`:`${e}`}function Qe(e){return Object.keys(e).filter(t=>e[t]._zod.optin!==void 0&&e[t]._zod.optout===`optional`)}const $e={safeint:[-(2**53-1),2**53-1],int32:[-2147483648,2147483647],uint32:[0,4294967295],float32:[-34028234663852886e22,34028234663852886e22],float64:[-Number.MAX_VALUE,Number.MAX_VALUE]},et={int64:[/* @__PURE__*/ BigInt(`-9223372036854775808`),/* @__PURE__*/ BigInt(`9223372036854775807`)],uint64:[/* @__PURE__*/ BigInt(0),/* @__PURE__*/ BigInt(`18446744073709551615`)]};function tt(e,t){let n=e._zod.def,r=n.checks;if(r&&r.length>0)throw Error(`.pick() cannot be used on object schemas containing refinements`);let i={};return ze(i,e,nt(e,t)),Xe(e,_(n,{shape:i,checks:[]}))}function nt(e,t){let n=Ie(e),r=[];for(let e of Reflect.ownKeys(t)){if(!Object.getOwnPropertyDescriptor(n,e)?.enumerable)throw Error(`Unrecognized key: "${String(e)}"`);t[e]&&r.push(e)}return r}function rt(e,t){let n=e._zod.def,r=n.checks;if(r&&r.length>0)throw Error(`.omit() cannot be used on object schemas containing refinements`);let i=new Set(nt(e,t)),a={};return ze(a,e,Reflect.ownKeys(Ie(e)).filter(e=>!i.has(e))),Xe(e,_(n,{shape:a,checks:[]}))}function it(e,t){if(!Ke(t))throw Error(`Invalid input to extend: expected a plain object`);let n=e._zod.def.checks;if(n&&n.length>0){let n=Ie(e);for(let e of Reflect.ownKeys(t))if(Object.getOwnPropertyDescriptor(n,e)!==void 0)throw Error("Cannot overwrite keys on object schemas containing refinements. Use `.safeExtend()` instead.")}return Xe(e,_(e._zod.def,{shape:at(e,t)}))}function at(e,t){let n={};return ze(n,e,Reflect.ownKeys(Ie(e))),Be(n,t),n}function ot(e,t){if(!Ke(t))throw Error(`Invalid input to safeExtend: expected a plain object`);return Xe(e,_(e._zod.def,{shape:at(e,t)}))}function st(e,t){if(!t?._zod?.def)throw Error("Invalid input to merge: expected an object schema. To merge a plain shape, use `.extend()`.");if(e._zod.def.checks?.length)throw Error(`.merge() cannot be used on object schemas containing refinements. Use .safeExtend() instead.`);let n={};return ze(n,e,Reflect.ownKeys(Ie(e))),ze(n,t,Reflect.ownKeys(Ie(t))),Xe(e,_(e._zod.def,{shape:n,get catchall(){return t._zod.def.catchall},checks:t._zod.def.checks??[]}))}function ct(e,t,n,r=`partial`){let i=t._zod.def.checks;if(i&&i.length>0)throw Error(`.${r}() cannot be used on object schemas containing refinements`);let a=n?new Set(nt(t,n)):void 0,o={};return ze(o,t,Reflect.ownKeys(Ie(t)),e&&((t,n)=>a&&!a.has(n)?t:new e({type:`optional`,innerType:t}))),Xe(t,_(t._zod.def,{shape:o,checks:[]}))}function lt(e,t,n){let r=n?new Set(nt(t,n)):void 0,i={};return ze(i,t,Reflect.ownKeys(Ie(t)),(t,n)=>r&&!r.has(n)?t:new e({type:`nonoptional`,innerType:t})),Xe(t,_(t._zod.def,{shape:i}))}function ut(e,t=0){if(e.aborted===!0)return!0;for(let n=t;n<e.issues.length;n++)if(e.issues[n]?.continue!==!0)return!0;return!1}function dt(e,t=0){if(e.aborted===!0)return!0;for(let n=t;n<e.issues.length;n++)if(e.issues[n]?.continue===!1)return!0;return!1}function ft(e,t){return t.map(t=>{var n;return(n=t).path??(n.path=[]),t.path.unshift(e),t})}function pt(e){return typeof e==`string`?e:e?.message}function mt(e){let t=[];for(let n of e??[]){let e=n._zod.def;if(!/_(length|size)$|_equals$/.test(e.check))break;let r=e.maximum??e.length??e.size;r>=0&&t.push([r,n])}return t}function ht(e,t,n){var r;for(let i=t;i<e.length;i++)(r=e[i]).schema??(r.schema=n)}function gt(e,t,n){var r;let i=e.inst?._zod?.traits;i?.has(`$ZodType`)&&(i.has(`$ZodCheck`)?(r=e).schema??(r.schema=e.inst):e.schema=e.inst);let a=e.schema===e.inst?void 0:e.schema?._zod.def?.error,o=e.message?e.message:pt(e.inst?._zod.def?.error?.(e))??pt(a?.(e))??pt(t?.error?.(e))??pt(n.customError?.(e))??pt(n.localeError?.(e))??`Invalid input`,s={};for(let t of Object.keys(e))t!==`inst`&&t!==`schema`&&t!==`continue`&&t!==`input`&&t!==`__proto__`&&(s[t]=e[t]);return s.path??=[],s.message=o,t?.reportInput&&(s.input=e.input),s}const _t=/[\uD800-\uDBFF]/;function vt(e){let t=e.length;if(!_t.test(e))return t;let n=t;for(let r=0;r<t-1;r++)(e.charCodeAt(r)&64512)==55296&&(e.charCodeAt(r+1)&64512)==56320&&(n--,r++);return n}function yt(e){return Array.isArray(e)?`array`:typeof e==`string`?`string`:`unknown`}function bt(e){let t=typeof e;switch(t){case`number`:return Number.isNaN(e)?`nan`:`number`;case`object`:{if(e===null)return`null`;if(Array.isArray(e))return`array`;let t=e;if(t&&Object.getPrototypeOf(t)!==Object.prototype&&`constructor`in t&&t.constructor)return t.constructor.name}}return t}function xt(...e){let[t,n,r]=e;return typeof t==`string`?{message:t,code:`custom`,input:n,inst:r}:{...t}}function St(e,t){for(let n in t){let r=Object.getOwnPropertyDescriptor(t,n);r.get?Object.defineProperty(e,n,{...r,enumerable:!1}):Et(e,n,r.value)}}function Ct(e,t,n,r=!0){return Object.defineProperty(e,t,{configurable:!0,writable:!0,enumerable:r,value:n}),n}function wt(e,t,n){return Ct(e,t,n,!1)}function Tt(e,t){for(let n in e){let r=e[n];Object.defineProperty(t,n,{configurable:!0,enumerable:!0,get(){return Ct(this,n,r(this))},set(e){Ct(this,n,e)}})}return t}function Et(e,t,n){Object.defineProperty(e,t,{configurable:!0,get(){return this==null?n:Ct(this,t,n.bind(this))},set(e){Ct(this,t,e)}})}function Dt(e,t){let n=Object.getPrototypeOf(e);return t in n?void 0:n}let Ot,kt=!1;const At={configurable:!0,get(){kt=!0}};function y(e,t,n){let r=Object.getPrototypeOf(e._zod);t in r&&Ot!==e._zod?Ot=void 0:(Ot=e._zod,Object.defineProperty(r,t,{configurable:!0,get(){Object.defineProperty(this,t,At);let e=kt;kt=!1;try{let r=n(this);return kt?delete this[t]:Object.defineProperty(this,t,{configurable:!0,writable:!0,value:r}),kt||=e,r}catch(n){throw delete this[t],kt||=e,n}},set(e){Object.defineProperty(this,t,{configurable:!0,writable:!0,value:e})}}))}function jt(e,t,n,r){let i=Dt(e,t);i&&Object.defineProperty(i,t,{configurable:!0,get(){let e={configurable:!0,writable:!0,enumerable:r,value:void 0};return Object.defineProperty(this,t,e),e.value=n(this),Object.defineProperty(this,t,e),e.value},set(e){Object.defineProperty(this,t,{configurable:!0,writable:!0,enumerable:r,value:e})}})}function Mt(e){let t=()=>e;return t[`~constantCatch`]=!0,t}var Nt;const Pt={value:void 0,enumerable:!1};let Ft=`captureStackTrace`in Error?Error:null;function It(e){let t=Ft;if(t){let n=t.stackTraceLimit;if(typeof n==`number`){try{t.stackTraceLimit=0}catch{return Ft=null,new e}try{return new e}finally{t.stackTraceLimit=n}}}return new e}function b(e,t,n,r){let i={};function a(e){this.def=e,this.constr=d,this.traits=/* @__PURE__ */ new Set}a.prototype=i;let o=n,s=o&&/* @__PURE__ */ new WeakSet;function c(n,r){if(!n._zod){Pt.value=new a(r);try{Object.defineProperty(n,"_zod",Pt)}finally{Pt.value=void 0}}else if(n._zod.traits.has(e))return;if(n._zod.traits.add(e),t(n,r),s){let e=Object.getPrototypeOf(n),t=n._zod.constr.prototype,r=e;for(;r&&r!==t;)r=Object.getPrototypeOf(r);let i=r??e;s.has(i)||(s.add(i),St(i,o))}let i=d.prototype;for(let e in i)Object.prototype.hasOwnProperty.call(i,e)&&(e in n||(n[e]=i[e].bind(n)))}let l=r?.Parent??Object;class u extends l{}Object.defineProperty(u,"name",{value:e});function d(e){let t=r?.Parent?It(u):this;c(t,e);let n=t._zod.deferred;if(n){for(let e of n)e();t._zod.deferred=void 0}let i=globalThis.__zod_globalConfig?.postProcessor;return i&&i(t),t}return Object.defineProperty(d,"init",{value:c}),Object.defineProperty(d,Symbol.hasInstance,{value:t=>r?.Parent&&t instanceof r.Parent?!0:t?._zod?.traits?.has(e)}),Object.defineProperty(d,"name",{value:e}),d}var Lt=class extends Error{constructor(){super(`Encountered Promise during synchronous parse. Use .parseAsync() instead.`)}},Rt=class extends Error{constructor(e){super(`Encountered unidirectional transform during encode: ${e}`),this.name=`ZodEncodeError`}};(Nt=globalThis).__zod_globalConfig??(Nt.__zod_globalConfig={});const x=globalThis.__zod_globalConfig;function zt(e){return e&&Object.assign(x,e),x}function Bt(){let e=this._zod;return e.message??=JSON.stringify(e.def,Oe,2),e.message}function Vt(e){this._zod.message=e}const Ht={get:Bt,set:Vt,enumerable:!0,configurable:!0},Ut={value:void 0,enumerable:!1},Wt=/* @__PURE__ */ new WeakSet([Object.prototype,Error.prototype]),Gt=(e,t)=>{e.name=`$ZodError`,Ut.value=t,Object.defineProperty(e,"issues",Ut),Ut.value=void 0,Object.defineProperty(e,"message",Ht);let n=Object.getPrototypeOf(e);Wt.has(n)||(Wt.add(n),Object.defineProperty(n,"toString",{configurable:!0,enumerable:!1,get(){let e=()=>this.message;return Object.defineProperty(this,"toString",{value:e,configurable:!0,writable:!0}),e},set(e){Object.defineProperty(this,"toString",{value:e,configurable:!0,writable:!0})}}))},Kt=b(`$ZodError`,Gt);b(`$ZodError`,Gt,void 0,{Parent:Error});function qt(e,t,n){return Object.prototype.hasOwnProperty.call(e,t)||(t===`__proto__`?Object.defineProperty(e,t,{value:n(),writable:!0,enumerable:!0,configurable:!0}):e[t]=n()),e[t]}function Jt(e,t=e=>e.message){let n={},r=[];for(let i of e.issues)i.path.length>0?qt(n,i.path[0],()=>[]).push(t(i)):r.push(t(i));return{formErrors:r,fieldErrors:n}}function Yt(e,t=e=>e.message){let n={_errors:[]},r=(e,i=[])=>{for(let a of e.issues)if(a.code===`invalid_union`&&a.errors.length)a.errors.map(e=>r({issues:e},[...i,...a.path]));else if(a.code===`invalid_key`)r({issues:a.issues},[...i,...a.path]);else if(a.code===`invalid_element`)r({issues:a.issues},[...i,...a.path]);else{let e=[...i,...a.path];if(e.length===0)n._errors.push(t(a));else{let r=n,i=0;for(;i<e.length;){let n=e[i],o=i===e.length-1;if(n===`_errors`){o&&r._errors.push(t(a)),i++;continue}Object.prototype.hasOwnProperty.call(r,n)||Object.defineProperty(r,n,{value:{_errors:[]},enumerable:!0,writable:!0,configurable:!0});let s=r[n];o&&s._errors.push(t(a)),r=s,i++}}}};return r(e),n}function Xt(e){let t=[],n=e.map(e=>typeof e==`object`?e.key:e);for(let e of n)typeof e==`number`?t.push(`[${e}]`):typeof e==`symbol`?t.push(`[${JSON.stringify(String(e))}]`):/[^\w$]/.test(e)?t.push(`[${JSON.stringify(e)}]`):(t.length&&t.push(`.`),t.push(e));return t.join(``)}function S(e){let t=[],n=[...e.issues].sort((e,t)=>(e.path??[]).length-(t.path??[]).length);for(let e of n)t.push(`✖ ${e.message}`),e.path?.length&&t.push(` → at ${Xt(e.path)}`);return t.join(`
|
|
3
|
+
`)}function Zt(e,t){return{callee:t?.callee??e,Err:t?.Err}}const Qt=e=>{let t=(n,r,i,a)=>{let o=i?{...i,async:!1}:{async:!1},s=n._zod.run({value:r,issues:[]},o);if(s instanceof Promise)throw new Lt;if(s.issues.length){let n=new((a?.Err)??e)(s.issues.map(e=>gt(e,o,zt())));throw Ue(n,a?.callee??t),n}return s.value};return t},$t=e=>{let t=async(n,r,i,a)=>{let o=i?{...i,async:!0}:{async:!0},s=n._zod.run({value:r,issues:[]},o);if(s instanceof Promise&&(s=await s),s.issues.length){let n=new((a?.Err)??e)(s.issues.map(e=>gt(e,o,zt())));throw Ue(n,a?.callee??t),n}return s.value};return t},en=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 Lt;return a.issues.length?tn(e,a.issues,i):{success:!0,data:a.value}};function tn(e,t,n){let r;return{success:!1,get error(){return r||(r=new e(t.map(e=>gt(e,n,zt()))),t=void 0,n=void 0),r},set error(e){r=e,t=void 0,n=void 0}}}const nn=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?tn(e,a.issues,i):{success:!0,data:a.value}},rn=/* @__PURE__ */ Symbol.for(`zod.compile.invalid`),an=/* @__PURE__ */ Symbol.for(`zod.compile.fallback`),on=((e,t,n)=>{let r=e._zod.bag.validator;if(r!==void 0){if(r(t)!==rn)return!0;if(r.definite===!0&&n===void 0)return!1}return sn(e,t,n)});function sn(e,t,n){let r=n?{...n,async:!1,abortEarly:!0}:{async:!1,abortEarly:!0},i=e._zod.bag.fallbackRun,a;if(i?(r[an]=!0,a=i({value:t,issues:[]},r)):a=e._zod.run({value:t,issues:[]},r),a instanceof Promise)throw new Lt;return a.issues.length===0}const cn=async(e,t,n)=>{let r=n?{...n,async:!0,abortEarly:!0}:{async:!0,abortEarly:!0},i=e._zod.run({value:t,issues:[]},r);return i instanceof Promise&&(i=await i),i.issues.length===0},ln=e=>{let t=Qt(e),n=(e,r,i,a)=>{let o=i?{...i,direction:`backward`}:{direction:`backward`};return t(e,r,o,Zt(n,a))};return n},un=e=>{let t=Qt(e),n=(e,r,i,a)=>t(e,r,i,Zt(n,a));return n},dn=e=>{let t=$t(e),n=async(e,r,i,a)=>{let o=i?{...i,direction:`backward`}:{direction:`backward`};return await t(e,r,o,Zt(n,a))};return n},fn=e=>{let t=$t(e),n=async(e,r,i,a)=>await t(e,r,i,Zt(n,a));return n},pn=e=>(t,n,r)=>{let i=r?{...r,direction:`backward`}:{direction:`backward`};return en(e)(t,n,i)},mn=e=>(t,n,r)=>en(e)(t,n,r),hn=e=>async(t,n,r)=>{let i=r?{...r,direction:`backward`}:{direction:`backward`};return nn(e)(t,n,i)},gn=e=>async(t,n,r)=>nn(e)(t,n,r),_n=/^[cC][0-9a-z]{6,}$/,vn=/^[0-9a-z]+$/,yn=/^[0-7][0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{25}$/,bn=/^[0-9a-vA-V]{20}$/,xn=/^[A-Za-z0-9]{27}$/,Sn=/^[a-zA-Z0-9_-]{21}$/;function Cn(e){return RegExp(`^[a-zA-Z0-9_-]{${e}}$`)}const wn=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/,Tn=/^([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})$/,En=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)$/,Dn=/^(?:[A-Za-z0-9_'+\-]+\.)*[A-Za-z0-9_'+\-]*[A-Za-z0-9_+-]@(?:[A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/;function On(){return/* @__PURE__ */ RegExp(`^(?=[\\s\\S]*[\\p{Extended_Pictographic}\\p{Regional_Indicator}\\u20E3])[\\p{Extended_Pictographic}\\p{Emoji_Component}]+$`,`u`)}const kn=/^(?:(?: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])$/,An=/^(([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}|:))$/,jn=/^((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])$/,Mn=/^(([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}|:))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,Nn=/^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/,Pn=/^(?:[A-Za-z0-9_-]{4})*(?:[A-Za-z0-9_-]{2,3})?$/,Fn=/^https?$/,In=/^\+[1-9]\d{6,14}$/,Ln=`(?:(?:\\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])))`;function Rn(e){return RegExp(`^${e}$`)}const zn=/*@__PURE__*/ Rn(Ln);function Bn(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}}`:e.seconds?`${t}:[0-5]\\d(?:\\.\\d+)?`:`${t}(?::[0-5]\\d(?:\\.\\d+)?)?`}function Vn(e){return RegExp(`^${Bn(e)}$`)}function Hn(e){let t=[`Z`];e.offset&&t.push(`([+-](?:[01]\\d|2[0-3]):[0-5]\\d)`);let n=`${Bn({precision:e.precision,seconds:!0})}(?:${t.join(`|`)})`,r=e.local?`${n}|${Bn({precision:e.precision})}`:n;return RegExp(`^${Ln}T(?:${r})$`)}const Un=/^[\s\S]{0,}$/,Wn=/^-?\d+$/,Gn=/^-?\d+(?:\.\d+)?$/,Kn=/^(?:true|false)$/i,qn=/^[^A-Z]*$/,Jn=/^[^a-z]*$/,C=/*@__PURE__*/ b(`$ZodCheck`,(e,t)=>{var n;e._zod??={},e._zod.def=t,(n=e._zod).onattach??(n.onattach=[])}),Yn=e=>{let t=e.value;return!je(t)&&t.length!==void 0},Xn={number:`number`,bigint:`bigint`,object:`date`},Zn=/*@__PURE__*/ b(`$ZodCheckLessThan`,(e,t)=>{C.init(e,t);let n=Xn[typeof t.value];e._zod.check=r=>{(t.inclusive?r.value<=t.value:r.value<t.value)||r.issues.push({origin:Xn[typeof r.value]??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})}}),Qn=/*@__PURE__*/ b(`$ZodCheckGreaterThan`,(e,t)=>{C.init(e,t);let n=Xn[typeof t.value];e._zod.check=r=>{(t.inclusive?r.value>=t.value:r.value>t.value)||r.issues.push({origin:Xn[typeof r.value]??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})}}),$n=/*@__PURE__*/ b(`$ZodCheckMultipleOf`,(e,t)=>{C.init(e,t),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`?t.value!==BigInt(0)&&n.value%t.value===BigInt(0):Ne(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})}}),er=/*@__PURE__*/ b(`$ZodCheckNumberFormat`,(e,t)=>{C.init(e,t),t.format=t.format||`float64`;let n=t.format?.includes(`int`),r=n?`int`:`number`,[i,a]=$e[t.format];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})}}),tr=/*@__PURE__*/ b(`$ZodCheckMaxLength`,(e,t)=>{var n;C.init(e,t),(n=e._zod.def).when??(n.when=Yn),e._zod.check=n=>{let r=n.value,i=r.length;if((typeof r==`string`&&i>t.maximum?vt(r):i)<=t.maximum)return;let a=yt(r);n.issues.push({origin:a,code:`too_big`,maximum:t.maximum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),nr=/*@__PURE__*/ b(`$ZodCheckMinLength`,(e,t)=>{var n;C.init(e,t),(n=e._zod.def).when??(n.when=Yn),e._zod.check=n=>{let r=n.value,i=r.length;if((typeof r==`string`&&i>=t.minimum&&i<t.minimum*2?vt(r):i)>=t.minimum)return;let a=yt(r);n.issues.push({origin:a,code:`too_small`,minimum:t.minimum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),rr=/*@__PURE__*/ b(`$ZodCheckLengthEquals`,(e,t)=>{var n;C.init(e,t),(n=e._zod.def).when??(n.when=Yn),e._zod.check=n=>{let r=n.value,i=r.length,a=typeof r==`string`&&i>=t.length&&i<=t.length*2?vt(r):i;if(a===t.length)return;let o=yt(r),s=a>t.length;n.issues.push({origin:o,...s?{code:`too_big`,maximum:t.length}:{code:`too_small`,minimum:t.length},inclusive:!0,exact:!0,input:n.value,inst:e,continue:!t.abort})}}),ir=/*@__PURE__*/ b(`$ZodCheckStringFormat`,(e,t)=>{var n,r;C.init(e,t),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=()=>{})}),ar=/*@__PURE__*/ b(`$ZodCheckRegex`,(e,t)=>{ir.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})}}),or=/*@__PURE__*/ b(`$ZodCheckLowerCase`,(e,t)=>{t.pattern??=qn,ir.init(e,t)}),sr=/*@__PURE__*/ b(`$ZodCheckUpperCase`,(e,t)=>{t.pattern??=Jn,ir.init(e,t)}),cr=/*@__PURE__*/ b(`$ZodCheckIncludes`,(e,t)=>{C.init(e,t);let n=Ye(t.includes);t.pattern=new RegExp(typeof t.position==`number`?`^.{${t.position},}${n}`:n),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})}}),lr=/*@__PURE__*/ b(`$ZodCheckStartsWith`,(e,t)=>{C.init(e,t);let n=RegExp(`^${Ye(t.prefix)}.*`);t.pattern??=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})}}),ur=/*@__PURE__*/ b(`$ZodCheckEndsWith`,(e,t)=>{C.init(e,t);let n=RegExp(`.*${Ye(t.suffix)}$`);t.pattern??=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})}}),dr=/*@__PURE__*/ b(`$ZodCheckOverwrite`,(e,t)=>{C.init(e,t),e._zod.check=e=>{e.value=t.tx(e.value)}});var fr=class{constructor(e=[],t={}){this.content=[],this.indent=0,this.args=e,this.closed=t}indented(e){this.indent+=1;try{e(this)}finally{--this.indent}}write(e){if(typeof e==`function`){e(this,{execution:`sync`}),e(this,{execution:`async`});return}let t=e.split(`
|
|
4
4
|
`).filter(e=>e),n=Math.min(...t.map(e=>e.length-e.trimStart().length)),r=t.map(e=>e.slice(n)).map(e=>` `.repeat(this.indent*2)+e);for(let e of r)this.content.push(e)}compile(){let e=Function,t=this?.content??[``];return new e(...Object.keys(this.closed),`return function (${this.args.join(`, `)}) {\n${t.join(`
|
|
5
|
-
`)}\n};`)(...Object.values(this.closed))}};const fr={major:4,minor:6,patch:2},w=b(`$ZodType`,(e,t)=>{var n;e??={},e._zod.def=t,e._zod.bag=e._zod.bag||{},e._zod.version=fr;let r=e._zod.def.checks,i=e._zod.traits.has(`$ZodCheck`)?[e,...r??[]]:r?.length?[...r]:[];for(let t of i)for(let n of t._zod.onattach)n(e);if(i.length===0)(n=e._zod).deferred??(n.deferred=[]),e._zod.deferred?.push(()=>{e._zod.run=e._zod.parse});else{let t=(t,n,r)=>{if(t.memo)return t;let i=ut(t),a;for(let o of n){if(o._zod.def.when){if(dt(t)||!o._zod.def.when(t))continue}else if(i)continue;let n=t.issues.length,s=o._zod.check(t);if(s instanceof Promise&&r?.async===!1)throw new It;if(a||s instanceof Promise)a=(a??Promise.resolve()).then(async()=>{await s,t.issues.length!==n&&(mt(t.issues,n,e),i||=ut(t,n))});else{if(t.issues.length===n)continue;mt(t.issues,n,e),i||=ut(t,n)}}return a?a.then(()=>t):t},n=(n,r,a)=>{if(ut(n))return n.aborted=!0,n;let o=t(r,i,a);if(o instanceof Promise){if(a.async===!1)throw new It;return o.then(t=>e._zod.parse(t,a))}return e._zod.parse(o,a)};e._zod.run=(r,a)=>{if(a.skipChecks)return e._zod.parse(r,a);if(a.direction===`backward`){let t=e._zod.parse({value:r.value,issues:[]},{...a,skipChecks:!0});return t instanceof Promise?t.then(e=>n(e,r,a)):n(t,r,a)}let o=e._zod.parse(r,a);if(o instanceof Promise){if(a.async===!1)throw new It;return o.then(e=>t(e,i,a))}return t(o,i,a)}}},{get"~standard"(){return Ct(this,`~standard`,hr(this))},set"~standard"(e){St(this,`~standard`,e)}}),pr=(e,t)=>e.issues.length?{issues:e.issues.map(e=>ht(e,t,Rt()))}:{value:e.value};async function mr(e,t){let n={async:!0};return pr(await e._zod.run({value:t,issues:[]},n),n)}function hr(e){return{validate:t=>{let n={async:!1};try{let r=e._zod.run({value:t,issues:[]},n);if(!(r instanceof Promise))return pr(r,n)}catch{}return mr(e,t)},vendor:`zod`,version:1}}const gr=b(`$ZodString`,(e,t)=>{w.init(e,t),e._zod.pattern=t.pattern??Hn,e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=String(n.value)}catch{}return typeof n.value==`string`||n.issues.push({expected:`string`,code:`invalid_type`,input:n.value,inst:e}),n}}),T=b(`$ZodStringFormat`,(e,t)=>{rr.init(e,t),gr.init(e,t)}),_r=b(`$ZodGUID`,(e,t)=>{t.pattern??=wn,T.init(e,t)}),vr=b(`$ZodUUID`,(e,t)=>{if(t.version){let e={v1:1,v2:2,v3:3,v4:4,v5:5,v6:6,v7:7,v8:8}[t.version];if(e===void 0)throw Error(`Invalid UUID version: "${t.version}"`);t.pattern??=Tn(e)}else t.pattern??=Tn();T.init(e,t)}),yr=b(`$ZodEmail`,(e,t)=>{t.pattern??=En,T.init(e,t)});function br(e,t){if(!t.normalize&&t.protocol?.source===Pn.source&&!/^https?:\/\//i.test(e))return 1;try{return new URL(e)}catch{return 2}}const xr=/[\t\n\r]/g;function Sr(e){return e.replace(xr,``)}function Cr(e,t){return t.lastIndex=0,t.test(e.hostname)}function wr(e,t){return t.lastIndex=0,t.test(e.protocol.endsWith(`:`)?e.protocol.slice(0,-1):e.protocol)}const Tr=b(`$ZodURL`,(e,t)=>{T.init(e,t),e._zod.check=n=>{try{let r=n.value.trim(),i=br(r,t);if(i===1){n.issues.push({code:`invalid_format`,format:`url`,note:`Invalid URL format`,input:n.value,inst:e,continue:!t.abort});return}if(i===2){n.issues.push({code:`invalid_format`,format:`url`,input:n.value,inst:e,continue:!t.abort});return}t.hostname&&!Cr(i,t.hostname)&&n.issues.push({code:`invalid_format`,format:`url`,note:`Invalid hostname`,pattern:t.hostname.source,input:n.value,inst:e,continue:!t.abort}),t.protocol&&!wr(i,t.protocol)&&n.issues.push({code:`invalid_format`,format:`url`,note:`Invalid protocol`,pattern:t.protocol.source,input:n.value,inst:e,continue:!t.abort}),n.value=t.normalize?i.href:Sr(r);return}catch{n.issues.push({code:`invalid_format`,format:`url`,input:n.value,inst:e,continue:!t.abort})}}}),Er=b(`$ZodEmoji`,(e,t)=>{t.pattern??=Dn(),T.init(e,t)}),Dr=b(`$ZodNanoID`,(e,t)=>{if(t.length!==void 0&&(!Number.isInteger(t.length)||t.length<1))throw Error(`Invalid nanoid length: ${t.length}`);t.pattern??=t.length===void 0?xn:Sn(t.length),T.init(e,t)}),Or=b(`$ZodCUID`,(e,t)=>{t.pattern??=gn,T.init(e,t)}),kr=b(`$ZodCUID2`,(e,t)=>{t.pattern??=_n,T.init(e,t)}),Ar=b(`$ZodULID`,(e,t)=>{t.pattern??=vn,T.init(e,t)}),jr=b(`$ZodXID`,(e,t)=>{t.pattern??=yn,T.init(e,t)}),Mr=b(`$ZodKSUID`,(e,t)=>{t.pattern??=bn,T.init(e,t)}),Nr=b(`$ZodISODateTime`,(e,t)=>{t.pattern??=Vn(t),T.init(e,t)}),Pr=b(`$ZodISODate`,(e,t)=>{t.pattern??=Rn,T.init(e,t)}),Fr=b(`$ZodISOTime`,(e,t)=>{t.pattern??=Bn(t),T.init(e,t)}),Ir=b(`$ZodISODuration`,(e,t)=>{t.pattern??=Cn,T.init(e,t)}),Lr=b(`$ZodIPv4`,(e,t)=>{t.pattern??=On,T.init(e,t)}),Rr=/^[0-9a-fA-F:.]+$/;function zr(e){if(!Rr.test(e))return!1;try{return new URL(`http://[${e}]`),!0}catch{return!1}}const Br=b(`$ZodIPv6`,(e,t)=>{t.pattern??=kn,T.init(e,t),e._zod.check=n=>{zr(n.value)||n.issues.push({code:`invalid_format`,format:`ipv6`,input:n.value,inst:e,continue:!t.abort})}}),Vr=b(`$ZodCIDRv4`,(e,t)=>{t.pattern??=An,T.init(e,t)});function Hr(e){let t=e.split(`/`);if(t.length!==2)return!1;let[n,r]=t;if(!r)return!1;let i=Number(r);return`${i}`!==r||i<0||i>128?!1:zr(n)}const Ur=b(`$ZodCIDRv6`,(e,t)=>{t.pattern??=jn,T.init(e,t),e._zod.check=n=>{Hr(n.value)||n.issues.push({code:`invalid_format`,format:`cidrv6`,input:n.value,inst:e,continue:!t.abort})}});function Wr(e){if(e===``)return!0;if(/\s/.test(e)||e.length%4!=0)return!1;try{return atob(e),!0}catch{return!1}}const Gr=/^[0-9a-zA-Z+/]*={0,2}$/,Kr=b(`$ZodBase64`,(e,t)=>{t.pattern??=Gr,T.init(e,t),e._zod.check=n=>{Wr(n.value)||n.issues.push({code:`invalid_format`,format:`base64`,input:n.value,inst:e,continue:!t.abort})}}),qr=/^[A-Za-z0-9_-]*$/;function Jr(e){if(!qr.test(e))return!1;let t=e.replace(/[-_]/g,e=>e===`-`?`+`:`/`);return Wr(t.padEnd(Math.ceil(t.length/4)*4,`=`))}const Yr=b(`$ZodBase64URL`,(e,t)=>{t.pattern??=qr,T.init(e,t),e._zod.check=n=>{Jr(n.value)||n.issues.push({code:`invalid_format`,format:`base64url`,input:n.value,inst:e,continue:!t.abort})}}),Xr=b(`$ZodE164`,(e,t)=>{t.pattern??=Fn,T.init(e,t)});function Zr(e,t=null){try{let n=e.split(`.`);if(n.length!==3)return!1;let[r]=n;if(!r)return!1;let i=JSON.parse(atob(r));return!(`typ`in i&&i?.typ!==`JWT`||!i.alg||t&&(!(`alg`in i)||i.alg!==t))}catch{return!1}}const Qr=b(`$ZodJWT`,(e,t)=>{T.init(e,t),e._zod.check=n=>{Zr(n.value,t.alg)||n.issues.push({code:`invalid_format`,format:`jwt`,input:n.value,inst:e,continue:!t.abort})}}),$r=b(`$ZodNumber`,(e,t)=>{w.init(e,t),e._zod.pattern=Wn,e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=Number(n.value)}catch{}let i=n.value;if(typeof i==`number`&&!Number.isNaN(i)&&Number.isFinite(i))return n;let a=typeof i==`number`?Number.isNaN(i)?`NaN`:Number.isFinite(i)?void 0:String(i):void 0;return n.issues.push({expected:`number`,code:`invalid_type`,input:i,inst:e,...a?{received:a}:{}}),n}}),ei=b(`$ZodNumberFormat`,(e,t)=>{$n.init(e,t),$r.init(e,t)}),ti=b(`$ZodBoolean`,(e,t)=>{w.init(e,t),e._zod.pattern=Gn,e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=!!n.value}catch{}let i=n.value;return typeof i==`boolean`||n.issues.push({expected:`boolean`,code:`invalid_type`,input:i,inst:e}),n}}),ni=b(`$ZodUnknown`,(e,t)=>{w.init(e,t),e._zod.parse=e=>e}),ri=b(`$ZodNever`,(e,t)=>{w.init(e,t),e._zod.parse=(t,n)=>(t.issues.push({expected:`never`,code:`invalid_type`,input:t.value,inst:e}),t)});function ii(e,t,n){e.issues.length&&t.issues.push(...ft(n,e.issues)),t.value[n]=e.value}const ai=b(`$ZodArray`,(e,t)=>{w.init(e,t);let n=x.memoizer;n?.attach(e),e._zod.parse=(r,i)=>{let a=r.value;if(!Array.isArray(a))return r.issues.push({expected:`array`,code:`invalid_type`,input:a,inst:e}),r;r.value=n?n.alloc(e,r,Array(a.length),i):Array(a.length);let o=[],s=i?.abortEarly;for(let e=0;e<a.length;e++){let n=a[e],c=t.element._zod.run({value:n,issues:[]},i);if(c instanceof Promise)o.push(c.then(t=>ii(t,r,e)));else if(ii(c,r,e),s&&c.issues.length!==0&&ut(c))break}return o.length?Promise.all(o).then(()=>r):r}});function oi(e,t,n,r,i,a){let o=n in r,s=a===`optional`;if(o||!s||i!==`optional`){if(e.issues.length){if(i!==void 0&&s&&!o)return;t.issues.push(...ft(n,e.issues))}if(!o&&i===void 0){e.issues.length||t.issues.push({code:`invalid_type`,expected:`nonoptional`,input:void 0,path:[n]});return}e.value===void 0?(o||i===`defaulted`&&!s)&&(t.value[n]=void 0):t.value[n]=e.value}}const si=[];function ci(e){let t=Object.keys(e.shape),n=Object.getOwnPropertySymbols(e.shape),r=n.length?n:si,i=r.length?[...t,...r]:t;for(let t of i)if(!e.shape?.[t]?._zod?.traits?.has(`$ZodType`))throw Error(`Invalid element at key "${String(t)}": expected a Zod schema`);let a=Qe(e.shape);return{...e,allKeys:i,symbolKeys:r,keySet:new Set(t),numKeys:t.length,optionalKeys:new Set(a)}}function li(e,t,n,r,i,a,o){let s=[],c=i.keySet,l=i.catchall._zod,u=l.def.type,d=l.optin,f=l.optout,p=0;for(let i in t){if(o&&n.issues.length!==p){if(ut(n,p))break;p=n.issues.length}if(c.has(i))continue;if(i===`__proto__`){u===`never`&&s.push(i);continue}if(u===`never`){s.push(i);continue}let a=l.run({value:t[i],issues:[]},r);a instanceof Promise?e.push(a.then(e=>oi(e,n,i,t,d,f))):oi(a,n,i,t,d,f)}return s.length&&n.issues.push({code:`unrecognized_keys`,keys:s,input:t,inst:a,continue:!0}),e.length?Promise.all(e).then(()=>n):n}const ui=b(`$ZodObject`,(e,t)=>{w.init(e,t);let n=Object.getOwnPropertyDescriptor(t,`shape`),r=n?.get?n.get.raw:t.shape??{};if(r){let e=()=>{let n={...r};return Object.defineProperty(t,"shape",{value:n}),e.raw=n,n};e.raw=r,Object.defineProperty(t,"shape",{get:e})}let i=Ae(()=>ci(t));y(e,`propValues`,e=>{let t=e.def.shape,n={};for(let e in t){let r=t[e]._zod;if(r.values){Object.prototype.hasOwnProperty.call(n,e)||Pe(n,e,new Set);for(let t of r.values)n[e].add(t);r.optin!==void 0&&n[e].add(void 0)}}return n});let a=We,o=t.catchall,s,c=x.memoizer;c?.attach(e),e._zod.parse=(t,n)=>{s??=i.value;let r=t.value;if(!a(r))return t.issues.push({expected:`object`,code:`invalid_type`,input:r,inst:e}),t;t.value=c?c.alloc(e,t,{},n):{};let l=[],u=s.shape,d=n?.abortEarly,f=t.issues.length;for(let e of s.allKeys){if(d&&t.issues.length!==f){if(ut(t,f))break;f=t.issues.length}if(e===`__proto__`)continue;let i=u[e],a=i._zod.optin,o=i._zod.optout,s=i._zod.run({value:r[e],issues:[]},n);s instanceof Promise?l.push(s.then(n=>oi(n,t,e,r,a,o))):oi(s,t,e,r,a,o)}return o?li(l,r,t,n,i.value,e,d===!0):l.length?Promise.all(l).then(()=>t):t}}),di=b(`$ZodObjectJIT`,(e,t)=>{ui.init(e,t);let n=e._zod.parse,r=Ae(()=>ci(t)),i=x.memoizer,a=t=>{let n=r.value,a=n.symbolKeys,o=new dr([`payload`,`ctx`],{shape:t,inst:e,memo:i,syms:a}),s=e=>`shape[${e}]._zod.run({ value: input[${e}], issues: [] }, ctx)`,c=(e,t)=>`
|
|
5
|
+
`)}\n};`)(...Object.values(this.closed))}};const pr={major:4,minor:6,patch:7},w=/*@__PURE__*/ b(`$ZodType`,(e,t)=>{var n;e??={},e._zod.def=t,e._zod.bag=e._zod.bag||{},e._zod.version=pr;let r=e._zod.def.checks,i=e._zod.traits.has(`$ZodCheck`)?[e,...r??[]]:r?.length?[...r]:[];for(let t of i)for(let n of t._zod.onattach)n(e);if(i.length===0)(n=e._zod).deferred??(n.deferred=[]),e._zod.deferred?.push(()=>{e._zod.run=e._zod.parse});else{let t=(t,n,r)=>{if(t.memo)return t;let i=ut(t),a;for(let o of n){if(o._zod.def.when){if(dt(t)||!o._zod.def.when(t))continue}else if(i)continue;let n=t.issues.length,s=o._zod.check(t);if(s instanceof Promise&&r?.async===!1)throw new Lt;if(a||s instanceof Promise)a=(a??Promise.resolve()).then(async()=>{await s,t.issues.length!==n&&(ht(t.issues,n,e),i||=ut(t,n))});else{if(t.issues.length===n)continue;ht(t.issues,n,e),i||=ut(t,n)}}return a?a.then(()=>t):t},n=(n,r,a)=>{if(ut(n))return n.aborted=!0,n;let o=t(r,i,a);if(o instanceof Promise){if(a.async===!1)throw new Lt;return o.then(t=>e._zod.parse(t,a))}return e._zod.parse(o,a)};e._zod.run=(r,a)=>{if(a.skipChecks)return e._zod.parse(r,a);if(a.direction===`backward`){let t=e._zod.parse({value:r.value,issues:[]},{...a,skipChecks:!0});return t instanceof Promise?t.then(e=>n(e,r,a)):n(t,r,a)}let o=e._zod.parse(r,a);if(o instanceof Promise){if(a.async===!1)throw new Lt;return o.then(e=>t(e,i,a))}return t(o,i,a)}}},{get"~standard"(){return wt(this,`~standard`,gr(this))},set"~standard"(e){Ct(this,`~standard`,e)}}),mr=(e,t)=>e.issues.length?{issues:e.issues.map(e=>gt(e,t,zt()))}:{value:e.value};async function hr(e,t){let n={async:!0};return mr(await e._zod.run({value:t,issues:[]},n),n)}function gr(e){return{validate:t=>{let n={async:!1};try{let r=e._zod.run({value:t,issues:[]},n);if(!(r instanceof Promise))return mr(r,n)}catch{}return hr(e,t)},vendor:`zod`,version:1}}const _r=/*@__PURE__*/ b(`$ZodString`,(e,t)=>{w.init(e,t),e._zod.pattern=t.pattern??Un,e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=String(n.value)}catch{}return typeof n.value==`string`||n.issues.push({expected:`string`,code:`invalid_type`,input:n.value,inst:e}),n}}),T=/*@__PURE__*/ b(`$ZodStringFormat`,(e,t)=>{ir.init(e,t),_r.init(e,t)}),vr=/*@__PURE__*/ b(`$ZodGUID`,(e,t)=>{t.pattern??=Tn,T.init(e,t)}),yr=/*@__PURE__*/ b(`$ZodUUID`,(e,t)=>{if(t.version){let e={v1:1,v2:2,v3:3,v4:4,v5:5,v6:6,v7:7,v8:8}[t.version];if(e===void 0)throw Error(`Invalid UUID version: "${t.version}"`);t.pattern??=En(e)}else t.pattern??=En();T.init(e,t)}),br=/*@__PURE__*/ b(`$ZodEmail`,(e,t)=>{t.pattern??=Dn,T.init(e,t)});function xr(e){try{return typeof URL<`u`&&typeof URL.canParse==`function`?URL.canParse(e):(new URL(e),!0)}catch{return!1}}function Sr(e,t){return!(`normalize`in t)&&!(`hostname`in t)&&!(`protocol`in t)?xr(e)||2:Cr(e,t)}function Cr(e,t){if(!t.normalize&&t.protocol?.source===Fn.source&&!/^https?:\/\//i.test(e))return 1;try{if(typeof URL<`u`){let t=URL;if(typeof t.parse==`function`)return t.parse(e)??2}return new URL(e)}catch{return 2}}const wr=/[\t\n\r]/g;function Tr(e){return e.replace(wr,``)}function Er(e,t){return t.lastIndex=0,t.test(e.hostname)}function Dr(e,t){return t.lastIndex=0,t.test(e.protocol.endsWith(`:`)?e.protocol.slice(0,-1):e.protocol)}const Or=/*@__PURE__*/ b(`$ZodURL`,(e,t)=>{T.init(e,t),e._zod.check=n=>{try{let r=n.value.trim(),i=Sr(r,t);if(i===1){n.issues.push({code:`invalid_format`,format:`url`,note:`Invalid URL format`,input:n.value,inst:e,continue:!t.abort});return}if(i===2){n.issues.push({code:`invalid_format`,format:`url`,input:n.value,inst:e,continue:!t.abort});return}if(i===!0){n.value=Tr(r);return}t.hostname&&!Er(i,t.hostname)&&n.issues.push({code:`invalid_format`,format:`url`,note:`Invalid hostname`,pattern:t.hostname.source,input:n.value,inst:e,continue:!t.abort}),t.protocol&&!Dr(i,t.protocol)&&n.issues.push({code:`invalid_format`,format:`url`,note:`Invalid protocol`,pattern:t.protocol.source,input:n.value,inst:e,continue:!t.abort}),n.value=t.normalize?i.href:Tr(r);return}catch{n.issues.push({code:`invalid_format`,format:`url`,input:n.value,inst:e,continue:!t.abort})}}}),kr=/*@__PURE__*/ b(`$ZodEmoji`,(e,t)=>{t.pattern??=On(),T.init(e,t)}),Ar=/*@__PURE__*/ b(`$ZodNanoID`,(e,t)=>{if(t.length!==void 0&&(!Number.isInteger(t.length)||t.length<1))throw Error(`Invalid nanoid length: ${t.length}`);t.pattern??=t.length===void 0?Sn:Cn(t.length),T.init(e,t)}),jr=/*@__PURE__*/ b(`$ZodCUID`,(e,t)=>{t.pattern??=_n,T.init(e,t)}),Mr=/*@__PURE__*/ b(`$ZodCUID2`,(e,t)=>{t.pattern??=vn,T.init(e,t)}),Nr=/*@__PURE__*/ b(`$ZodULID`,(e,t)=>{t.pattern??=yn,T.init(e,t)}),Pr=/*@__PURE__*/ b(`$ZodXID`,(e,t)=>{t.pattern??=bn,T.init(e,t)}),Fr=/*@__PURE__*/ b(`$ZodKSUID`,(e,t)=>{t.pattern??=xn,T.init(e,t)}),Ir=/*@__PURE__*/ b(`$ZodISODateTime`,(e,t)=>{t.pattern??=Hn(t),T.init(e,t)}),Lr=/*@__PURE__*/ b(`$ZodISODate`,(e,t)=>{t.pattern??=zn,T.init(e,t)}),Rr=/*@__PURE__*/ b(`$ZodISOTime`,(e,t)=>{t.pattern??=Vn(t),T.init(e,t)}),zr=/*@__PURE__*/ b(`$ZodISODuration`,(e,t)=>{t.pattern??=wn,T.init(e,t)}),Br=/*@__PURE__*/ b(`$ZodIPv4`,(e,t)=>{t.pattern??=kn,T.init(e,t)}),Vr=/^[0-9a-fA-F:.]+$/;function Hr(e){return Vr.test(e)?xr(`http://[${e}]`):!1}const Ur=/*@__PURE__*/ b(`$ZodIPv6`,(e,t)=>{t.pattern??=An,T.init(e,t),e._zod.check=n=>{Hr(n.value)||n.issues.push({code:`invalid_format`,format:`ipv6`,input:n.value,inst:e,continue:!t.abort})}}),Wr=/*@__PURE__*/ b(`$ZodCIDRv4`,(e,t)=>{t.pattern??=jn,T.init(e,t)});function Gr(e){let t=e.split(`/`);if(t.length!==2)return!1;let[n,r]=t;if(!r)return!1;let i=Number(r);return`${i}`!==r||i<0||i>128?!1:Hr(n)}const Kr=/*@__PURE__*/ b(`$ZodCIDRv6`,(e,t)=>{t.pattern??=Mn,T.init(e,t),e._zod.check=n=>{Gr(n.value)||n.issues.push({code:`invalid_format`,format:`cidrv6`,input:n.value,inst:e,continue:!t.abort})}});function qr(e){if(e===``)return!0;if(/\s/.test(e)||e.length%4!=0)return!1;try{return atob(e),!0}catch{return!1}}const Jr=/^[0-9a-zA-Z+/]*={0,2}$/,Yr=/*@__PURE__*/ b(`$ZodBase64`,(e,t)=>{t.pattern??=Jr,T.init(e,t),e._zod.check=n=>{qr(n.value)||n.issues.push({code:`invalid_format`,format:`base64`,input:n.value,inst:e,continue:!t.abort})}}),Xr=/^[A-Za-z0-9_-]*$/;function Zr(e){if(!Xr.test(e))return!1;let t=e.replace(/[-_]/g,e=>e===`-`?`+`:`/`);return qr(t.padEnd(Math.ceil(t.length/4)*4,`=`))}const Qr=/*@__PURE__*/ b(`$ZodBase64URL`,(e,t)=>{t.pattern??=Xr,T.init(e,t),e._zod.check=n=>{Zr(n.value)||n.issues.push({code:`invalid_format`,format:`base64url`,input:n.value,inst:e,continue:!t.abort})}}),$r=/*@__PURE__*/ b(`$ZodE164`,(e,t)=>{t.pattern??=In,T.init(e,t)});function ei(e,t=null){try{let n=e.split(`.`);if(n.length!==3)return!1;let[r]=n;if(!r)return!1;let i=JSON.parse(atob(r));return!(`typ`in i&&i?.typ!==`JWT`||!i.alg||t&&(!(`alg`in i)||i.alg!==t))}catch{return!1}}const ti=/*@__PURE__*/ b(`$ZodJWT`,(e,t)=>{T.init(e,t),e._zod.check=n=>{ei(n.value,t.alg)||n.issues.push({code:`invalid_format`,format:`jwt`,input:n.value,inst:e,continue:!t.abort})}}),ni=/*@__PURE__*/ b(`$ZodNumber`,(e,t)=>{w.init(e,t),e._zod.pattern=Gn,e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=Number(n.value)}catch{}let i=n.value;if(typeof i==`number`&&!Number.isNaN(i)&&Number.isFinite(i))return n;let a=typeof i==`number`?Number.isNaN(i)?`NaN`:Number.isFinite(i)?void 0:String(i):void 0;return n.issues.push({expected:`number`,code:`invalid_type`,input:i,inst:e,...a?{received:a}:{}}),n}}),ri=/*@__PURE__*/ b(`$ZodNumberFormat`,(e,t)=>{er.init(e,t),ni.init(e,t)}),ii=/*@__PURE__*/ b(`$ZodBoolean`,(e,t)=>{w.init(e,t),e._zod.pattern=Kn,e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=!!n.value}catch{}let i=n.value;return typeof i==`boolean`||n.issues.push({expected:`boolean`,code:`invalid_type`,input:i,inst:e}),n}}),ai=/*@__PURE__*/ b(`$ZodUnknown`,(e,t)=>{w.init(e,t),e._zod.parse=e=>e}),oi=/*@__PURE__*/ b(`$ZodNever`,(e,t)=>{w.init(e,t),e._zod.parse=(t,n)=>(t.issues.push({expected:`never`,code:`invalid_type`,input:t.value,inst:e}),t)});function si(e,t){let n=mt(e._zod.def.checks);if(!n.length)return;let r=Math.min(...n.map(e=>e[0])),i=e._zod.parse;e._zod.parse=(n,a)=>{let o=t(n.value);if(o>r&&!a?.skipChecks&&a?.direction!==`backward`){for(let[t,r]of mt(e._zod.def.checks))if(o>t&&r._zod.def.when(n)){let t=n.issues.length;return r._zod.check(n),n.issues[t].continue=!1,ht(n.issues,t,e),n}}return i(n,a)}}const ci=e=>Array.isArray(e)?e.length:-1;function li(e,t,n){e.issues.length&&t.issues.push(...ft(n,e.issues)),t.value[n]=e.value}const ui=/*@__PURE__*/ b(`$ZodArray`,(e,t)=>{w.init(e,t);let n=x.memoizer;n?.attach(e),e._zod.parse=(r,i)=>{let a=r.value;if(!Array.isArray(a))return r.issues.push({expected:`array`,code:`invalid_type`,input:a,inst:e}),r;r.value=n?n.alloc(e,r,Array(a.length),i):Array(a.length);let o=[],s=i?.abortEarly;for(let e=0;e<a.length;e++){let n=a[e],c=t.element._zod.run({value:n,issues:[]},i);if(c instanceof Promise)o.push(c.then(t=>li(t,r,e)));else if(li(c,r,e),s&&c.issues.length!==0&&ut(c))break}return o.length?Promise.all(o).then(()=>r):r},si(e,ci)});function di(e,t,n,r,i,a){let o=n in r,s=a===`optional`;if(o||!s||i!==`optional`){if(e.issues.length){if(i!==void 0&&s&&!o)return;t.issues.push(...ft(n,e.issues))}!o&&i===void 0?e.issues.length||t.issues.push({code:`invalid_type`,expected:`nonoptional`,input:void 0,path:[n]}):e.value===void 0?(o||i===`defaulted`&&!s)&&(t.value[n]=void 0):t.value[n]=e.value}}const fi=[];function pi(e){let t=Object.keys(e.shape),n=Object.getOwnPropertySymbols(e.shape),r=n.length?n:fi,i=r.length?[...t,...r]:t;for(let t of i)if(!e.shape?.[t]?._zod?.traits?.has(`$ZodType`))throw Error(`Invalid element at key "${String(t)}": expected a Zod schema`);let a=Qe(e.shape);return{...e,allKeys:i,symbolKeys:r,keySet:new Set(t),numKeys:t.length,optionalKeys:new Set(a)}}function mi(e,t,n,r,i,a,o){let s=[],c=i.keySet,l=i.catchall._zod,u=l.def.type,d=l.optin,f=l.optout,p=0;for(let i in t){if(o&&n.issues.length!==p){if(ut(n,p))break;p=n.issues.length}if(c.has(i))continue;if(i===`__proto__`){u===`never`&&s.push(i);continue}if(u===`never`){s.push(i);continue}let a=l.run({value:t[i],issues:[]},r);a instanceof Promise?e.push(a.then(e=>di(e,n,i,t,d,f))):di(a,n,i,t,d,f)}return s.length&&n.issues.push({code:`unrecognized_keys`,keys:s,input:t,inst:a,continue:!0}),e.length?Promise.all(e).then(()=>n):n}const hi=/*@__PURE__*/ b(`$ZodObject`,(e,t)=>{w.init(e,t);let n=Object.getOwnPropertyDescriptor(t,`shape`),r=n?.get?n.get.raw:t.shape??{};if(r){let e=()=>{let n={...r};return Object.defineProperty(t,"shape",{value:n}),e.raw=n,n};e.raw=r,Object.defineProperty(t,"shape",{get:e})}let i=Ae(()=>pi(t));y(e,`propValues`,e=>{let t=e.def.shape,n={};for(let e in t){let r=t[e]._zod;if(r.values){Object.prototype.hasOwnProperty.call(n,e)||Pe(n,e,/* @__PURE__ */ new Set);for(let t of r.values)n[e].add(t);r.optin!==void 0&&n[e].add(void 0)}}return n});let a=We,o=t.catchall,s,c=x.memoizer;c?.attach(e),e._zod.parse=(t,n)=>{s??=i.value;let r=t.value;if(!a(r))return t.issues.push({expected:`object`,code:`invalid_type`,input:r,inst:e}),t;t.value=c?c.alloc(e,t,{},n):{};let l=[],u=s.shape,d=n?.abortEarly,f=t.issues.length;for(let e of s.allKeys){if(d&&t.issues.length!==f){if(ut(t,f))break;f=t.issues.length}if(e===`__proto__`)continue;let i=u[e],a=i._zod.optin,o=i._zod.optout,s=i._zod.run({value:r[e],issues:[]},n);s instanceof Promise?l.push(s.then(n=>di(n,t,e,r,a,o))):di(s,t,e,r,a,o)}return o?mi(l,r,t,n,i.value,e,d===!0):l.length?Promise.all(l).then(()=>t):t}}),gi=/*@__PURE__*/ b(`$ZodObjectJIT`,(e,t)=>{hi.init(e,t);let n=e._zod.parse,r=Ae(()=>pi(t)),i=x.memoizer,a=t=>{let n=r.value,a=n.symbolKeys,o=new fr([`payload`,`ctx`],{shape:t,inst:e,memo:i,syms:a}),s=e=>`shape[${e}]._zod.run({ value: input[${e}], issues: [] }, ctx)`,c=(e,t)=>`
|
|
6
6
|
let ${e}_ab = false;
|
|
7
7
|
for (let i = 0; i < ${e}.issues.length; i++) {
|
|
8
8
|
const iss = ${e}.issues[i];
|
|
@@ -52,9 +52,65 @@ import{access as e,chmod as t,constants as n,copyFile as r,lstat as i,mkdir as a
|
|
|
52
52
|
newResult[${r}] = ${n}.value;
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
`)}return o.write(`payload.value = newResult;`),o.write(`return payload;`),o.compile()},o,s=We,c=!x.jitless,l=c&&Ge.value,u=t.catchall,d;e._zod.parse=(i,f)=>{d??=r.value;let p=i.value;return s(p)?c&&l&&f?.async===!1&&f.jitless!==!0?(o||=a(t.shape),i=o(i,f),u?li([],p,i,f,d,e,f?.abortEarly===!0):i):n(i,f):(i.issues.push({expected:`object`,code:`invalid_type`,input:p,inst:e}),i)}});function fi(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=>!ut(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=>ht(e,r,Rt())))}),t)}const pi=b(`$ZodUnion`,(e,t)=>{w.init(e,t),y(e,`optin`,e=>e.def.options.some(e=>e._zod.optin===`defaulted`)?`defaulted`:e.def.options.some(e=>e._zod.optin!==void 0)?`optional`:void 0),y(e,`optout`,e=>e.def.options.some(e=>e._zod.optout===`optional`)?`optional`:void 0),y(e,`values`,e=>{if(e.def.options.every(e=>e._zod.values))return new Set(e.def.options.flatMap(e=>Array.from(e._zod.values)))}),y(e,`pattern`,e=>{if(e.def.options.every(e=>e._zod.pattern)){let t=e.def.options.map(e=>e._zod.pattern);return RegExp(`^(${t.map(e=>Me(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=>fi(t,r,e,i)):fi(o,r,e,i)}}),mi=b(`$ZodIntersection`,(e,t)=>{w.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])=>gi(e,t,n)):gi(e,i,a)}});function hi(e,t){if(e===t||e instanceof Date&&t instanceof Date&&+e==+t)return{valid:!0,data:e};if(Ke(e)&&Ke(t)){let n=Object.keys(t),r=Object.keys(e).filter(e=>n.indexOf(e)!==-1),i={...e,...t};Object.prototype.hasOwnProperty.call(i,`__proto__`)&&delete i.__proto__;for(let n of r){if(n===`__proto__`)continue;let r=hi(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=hi(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 gi(e,t,n){let r=new Map,i,a=new Map,o=(e,t)=>{let n;if(e.code===`unrecognized_keys`&&!e.path?.length)i??=e,n=e.keys;else if(e.code===`invalid_key`&&e.origin===`record`&&e.path?.length===1){let t=String(e.path[0]);a.has(t)||a.set(t,e),n=[t]}else return!1;for(let e of n)r.has(e)||r.set(e,{}),r.get(e)[t]=!0;return!0};for(let n of t.issues)o(n,`l`)||e.issues.push(n);for(let t of n.issues)o(t,`r`)||e.issues.push(t);let s=[...r].filter(([,e])=>e.l&&e.r).map(([e])=>e);if(s.length){let t=i?s.filter(e=>i.keys.includes(e)):[];t.length&&e.issues.push({...i,keys:t});for(let n of s)!t.includes(n)&&a.has(n)&&e.issues.push(a.get(n))}let c=hi(t.value,n.value);if(!c.valid){if(ut(e))return e;throw Error(`Unmergable intersection. Error path: ${JSON.stringify(c.mergeErrorPath)}`)}return e.value=c.data,e}const _i=b(`$ZodRecord`,(e,t)=>{w.init(e,t);let n=x.memoizer;n?.attach(e),e._zod.parse=(r,i)=>{let a=r.value;if(!Ke(a))return r.issues.push({expected:`record`,code:`invalid_type`,input:a,inst:e}),r;let o=[],s=t.keyType._zod.values;if(s&&!t.partial){r.value=n?n.alloc(e,r,{},i):{};let c=new Set;for(let n of s)if(typeof n==`string`||typeof n==`number`||typeof n==`symbol`){if(c.add(typeof n==`number`?n.toString():n),n===`__proto__`)continue;let s=t.keyType._zod.run({value:n,issues:[]},i);if(s instanceof Promise)throw Error(`Async schemas not supported in object keys currently`);if(s.issues.length){r.issues.push({code:`invalid_key`,origin:`record`,issues:s.issues.map(e=>ht(e,i,Rt())),input:n,path:[n],inst:e});continue}let l=s.value;if(l===`__proto__`)continue;let u=t.valueType._zod.run({value:a[n],issues:[]},i);u instanceof Promise?o.push(u.then(e=>{e.issues.length&&r.issues.push(...ft(n,e.issues)),r.value[l]=e.value})):(u.issues.length&&r.issues.push(...ft(n,u.issues)),r.value[l]=u.value)}let l;for(let e in a)if(!c.has(e)){if(t.mode===`loose`){if(e===`__proto__`)continue;r.value[e]=a[e]}else l??=[],l.push(e)}l&&l.length>0&&r.issues.push({code:`unrecognized_keys`,input:a,inst:e,keys:l,continue:!0})}else{r.value=n?n.alloc(e,r,{},i):{};let c;for(let n of Reflect.ownKeys(a)){if(n===`__proto__`||!Object.prototype.propertyIsEnumerable.call(a,n))continue;let l=t.keyType._zod.run({value:n,issues:[]},i);if(l instanceof Promise)throw Error(`Async schemas not supported in object keys currently`);if(typeof n==`string`&&Wn.test(n)&&l.issues.length){let e=t.keyType._zod.run({value:Number(n),issues:[]},i);if(e instanceof Promise)throw Error(`Async schemas not supported in object keys currently`);e.issues.length===0&&(l=e)}if(l.issues.length){t.mode===`loose`?r.value[n]=a[n]:s?(c??=[],c.push(n)):r.issues.push({code:`invalid_key`,origin:`record`,issues:l.issues.map(e=>ht(e,i,Rt())),input:n,path:[n],inst:e});continue}let u=l.value;if(u===`__proto__`)continue;let d=t.valueType._zod.run({value:a[n],issues:[]},i);d instanceof Promise?o.push(d.then(e=>{e.issues.length&&r.issues.push(...ft(n,e.issues)),r.value[u]=e.value})):(d.issues.length&&r.issues.push(...ft(n,d.issues)),r.value[u]=d.value)}c&&c.length>0&&r.issues.push({code:`unrecognized_keys`,input:a,inst:e,keys:c,continue:!0})}return o.length?Promise.all(o).then(()=>r):r}}),vi=b(`$ZodEnum`,(e,t)=>{w.init(e,t);let n=Ee(t.entries),r=new Set(n);e._zod.values=r,y(e,`pattern`,e=>{let t=Ee(e.def.entries).filter(e=>Je.has(typeof e));return RegExp(t.length?`^(${t.map(e=>Ye(e.toString())).join(`|`)})$`:`^[^\\s\\S]$`)}),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}}),yi=b(`$ZodTransform`,(e,t)=>{w.init(e,t),e._zod.optin=`optional`,x.memoizer?.guard(e),e._zod.parse=(n,r)=>{if(r.direction===`backward`)throw new Lt(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));if(i instanceof Promise)throw new It;return n.value=i,n}});function bi(e,t){return e.value=t.issues.length?void 0:t.value,e}const xi=b(`$ZodOptional`,(e,t)=>{w.init(e,t),y(e,`optin`,e=>e.def.innerType._zod.optin===`defaulted`?`defaulted`:`optional`),e._zod.optout=`optional`,y(e,`values`,e=>{let t=e.def.innerType._zod.values;return t?new Set([...t,void 0]):void 0}),y(e,`pattern`,e=>{let t=e.def.innerType._zod.pattern;return t?RegExp(`^(${Me(t.source)})?$`):void 0}),e._zod.parse=(e,n)=>{if(e.value===void 0){if(t.innerType._zod.optin!==`defaulted`)return e;let r=t.innerType._zod.run({value:e.value,issues:[]},n);return r instanceof Promise?r.then(t=>bi(e,t)):bi(e,r)}return t.innerType._zod.run(e,n)}}),Si=b(`$ZodExactOptional`,(e,t)=>{xi.init(e,t),y(e,`values`,e=>e.def.innerType._zod.values),y(e,`pattern`,e=>e.def.innerType._zod.pattern),e._zod.parse=(e,n)=>t.innerType._zod.run(e,n)}),Ci=b(`$ZodNullable`,(e,t)=>{w.init(e,t),y(e,`optin`,e=>e.def.innerType._zod.optin),y(e,`optout`,e=>e.def.innerType._zod.optout),y(e,`pattern`,e=>{let t=e.def.innerType._zod.pattern;return t?RegExp(`^(${Me(t.source)}|null)$`):void 0}),y(e,`values`,e=>e.def.innerType._zod.values?new Set([...e.def.innerType._zod.values,null]):void 0),e._zod.parse=(e,n)=>e.value===null?e:t.innerType._zod.run(e,n)}),wi=b(`$ZodDefault`,(e,t)=>{w.init(e,t),e._zod.optin=`defaulted`,y(e,`values`,e=>e.def.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=>Ti(e,t)):Ti(r,t)}});function Ti(e,t){return e.value===void 0&&(e.value=t.defaultValue),e}const Ei=b(`$ZodPrefault`,(e,t)=>{w.init(e,t),e._zod.optin=`defaulted`,y(e,`values`,e=>e.def.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))}),Di=b(`$ZodNonOptional`,(e,t)=>{w.init(e,t),y(e,`values`,e=>{let t=e.def.innerType._zod.values;return t?new Set([...t].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=>Oi(t,e)):Oi(i,e)}});function Oi(e,t){return!e.issues.length&&e.value===void 0&&e.issues.push({code:`invalid_type`,expected:`nonoptional`,input:e.value,inst:t}),e}function ki(e,t,n,r){return t.issues.length?(e.value=n.catchValue({...t,value:e.value,error:{issues:t.issues.map(e=>ht(e,r,Rt()))},input:e.value}),e):(e.value=t.value,t.memo&&(e.memo=!0),e)}const Ai=b(`$ZodCatch`,(e,t)=>{w.init(e,t),y(e,`optin`,e=>e.def.innerType._zod.optin===`defaulted`?`defaulted`:`optional`),y(e,`optout`,e=>e.def.innerType._zod.optout),y(e,`values`,e=>e.def.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({value:e.value,issues:[]},n);return r instanceof Promise?r.then(r=>ki(e,r,t,n)):ki(e,r,t,n)}}),ji=b(`$ZodPipe`,(e,t)=>{w.init(e,t),y(e,`values`,e=>e.def.in._zod.values),y(e,`optin`,e=>e.def.in._zod.optin),y(e,`optout`,e=>e.def.out._zod.optout),y(e,`propValues`,e=>e.def.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=>Mi(e,t.in,n)):Mi(r,t.in,n)}let r=t.in._zod.run(e,n);return r instanceof Promise?r.then(e=>Mi(e,t.out,n)):Mi(r,t.out,n)}});function Mi(e,t,n){return e.issues.some(e=>e.code!==`unrecognized_keys`)?(e.aborted=!0,e):t._zod.run({value:e.value,issues:e.issues},n)}const Ni=b(`$ZodPreprocess`,(e,t)=>{ji.init(e,t)}),Pi=b(`$ZodReadonly`,(e,t)=>{w.init(e,t),y(e,`propValues`,e=>e.def.innerType._zod.propValues),y(e,`values`,e=>e.def.innerType._zod.values),y(e,`optin`,e=>e.def.innerType?._zod?.optin),y(e,`optout`,e=>e.def.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(Fi):Fi(r)}});function Fi(e){return e.memo||(e.value=Object.freeze(e.value)),e}const Ii=b(`$ZodCustom`,(e,t)=>{C.init(e,t),w.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=>Li(t,n,r,e));Li(i,n,r,e)}});function Li(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(bt(e))}}var Ri=class extends Error{constructor(){super(`Cannot parse a reference cycle that closes through a transform`),this.name=`ZodCyclicError`}};const zi=`~memo`,Bi=[];function Vi(e){return e!==null&&(typeof e==`object`||typeof e==`function`)}function Hi(e){return e.map(e=>e.path?{...e,path:e.path.slice()}:{...e})}const Ui=new WeakMap;function Wi(e,t,n){let r=Ui.get(e);if(r!==void 0)return r?2:0;if(t.has(e))return 2;t.add(e);let i=0,a=e=>{if(i!==2&&e?._zod){let r=Wi(e,t,n);r>i&&(i=r)}},o=(e,r)=>{let i=0;for(let a of Reflect.ownKeys(e)){let o=Object.getOwnPropertyDescriptor(e,a);if(r&&!o.enumerable)continue;let s=o.get?1:o.value?._zod?Wi(o.value,t,n):0;s>i&&(i=s)}return i},s=e=>{e>i&&(i=e)},c=e._zod.def;switch(c.type){case`object`:{let e=Fe(c);s(e?o(e,!0):1),a(c.catchall);break}case`properties`:s(o(c.shape,!1));break;case`array`:a(c.element);break;case`tuple`:for(let e of c.items)a(e);a(c.rest);break;case`record`:case`map`:a(c.keyType),a(c.valueType);break;case`set`:a(c.valueType);break;case`union`:for(let e of c.options)a(e);break;case`intersection`:a(c.left),a(c.right);break;case`optional`:case`nullable`:case`default`:case`prefault`:case`catch`:case`readonly`:case`nonoptional`:case`promise`:case`success`:a(c.innerType);break;case`pipe`:a(c.in),a(c.out);break;case`function`:a(c.input),a(c.output);break;case`lazy`:{let r=c._cachedInner??(n?e._zod.innerType:void 0);s(r?Wi(r,t,!1):1);break}case`template_literal`:case`string`:case`number`:case`int`:case`boolean`:case`bigint`:case`symbol`:case`undefined`:case`null`:case`void`:case`never`:case`any`:case`unknown`:case`date`:case`nan`:case`enum`:case`literal`:case`file`:case`transform`:case`custom`:break;default:for(let e in c){let t=Object.getOwnPropertyDescriptor(c,e);if(!t||t.get)continue;let n=t.value;if(n&&typeof n==`object`){if(n._zod)a(n);else if(Array.isArray(n))for(let e of n)a(e)}}}return t.delete(e),Gi(e,i)}function Gi(e,t){return t!==1&&Ui.set(e,t===2),t}function Ki(e,t){let n=e.buckets.get(t);return n||(n=new WeakMap,e.buckets.set(t,n)),n}let qi;const Ji=[],Yi={alloc(e,t,n){let r=qi;if(!r)return n;qi=void 0;let i={value:n,issues:null};return r.set(t.value,i),Ji.push(i),n},guard(e){var t;(t=e._zod).deferred??(t.deferred=[]),e._zod.deferred.push(()=>{let t=e._zod.parse,n=(e,n)=>{if(n.direction!==`backward`&&Zi(n,e.value))throw new Ri;return t(e,n)};e._zod.parse=n,e._zod.run===t&&(e._zod.run=n)})},attach(e){var t;let n,r=!1,i,a;(t=e._zod).deferred??(t.deferred=[]),e._zod.deferred.push(()=>{let t=e._zod.parse,o=(s,c)=>{if(n===void 0){let i=Wi(e,new Set,!1);if(i===0)return e._zod.parse=t,e._zod.run===o&&(e._zod.run=t),t(s,c);i===2||r?n=!0:r=!0}let l=s.value;if(!Vi(l))return t(s,c);let u=c[zi];u||(u={buckets:new WeakMap,backEdges:void 0},c[zi]=u);let d;i===c?d=a:(d=Ki(u,e),i=c,a=d);let f=d.get(l);if(f)return s.value=f.value,f.issues?f.issues.length&&s.issues.push(...Hi(f.issues)):(s.memo=!0,u.backEdges??(u.backEdges=new WeakSet),u.backEdges.add(f.value)),s;qi=d;let p=Ji.length,ee=t(s,c);qi=void 0;let te=Ji.length>p?Ji.pop():void 0;return ee instanceof Promise?ee.then(e=>(te&&(te.issues=e.issues.length?Hi(e.issues):Bi),e)):(te&&(te.issues=ee.issues.length?Hi(ee.issues):Bi),ee)};e._zod.parse=o,e._zod.run===t&&(e._zod.run=o)})}};function Xi(){return Yi}function Zi(e,t){let n=e[zi]?.backEdges;return n!==void 0&&Vi(t)&&n.has(t)}const Qi=()=>{let e={string:{unit:`characters`,verb:`to have`},file:{unit:`bytes`,verb:`to have`},array:{unit:`items`,verb:`to have`},set:{unit:`items`,verb:`to have`},map:{unit:`entries`,verb:`to have`}};function t(t){return e[t]??null}let n={regex:`input`,email:`email address`,url:`URL`,emoji:`emoji`,uuid:`UUID`,uuidv4:`UUIDv4`,uuidv6:`UUIDv6`,nanoid:`nanoid`,guid:`GUID`,cuid:`cuid`,cuid2:`cuid2`,ulid:`ULID`,xid:`XID`,ksuid:`KSUID`,datetime:`ISO datetime`,date:`ISO date`,time:`ISO time`,duration:`ISO duration`,ipv4:`IPv4 address`,ipv6:`IPv6 address`,mac:`MAC address`,cidrv4:`IPv4 range`,cidrv6:`IPv6 range`,base64:`base64-encoded string`,base64url:`base64url-encoded string`,json_string:`JSON string`,e164:`E.164 number`,credit_card:`credit card number`,iban:`IBAN`,jwt:`JWT`,template_literal:`input`},r={nan:`NaN`};function i(e,t){return e===`number`&&typeof t==`number`&&!Number.isFinite(t)?String(t):r[e]??e}return e=>{switch(e.code){case`invalid_type`:return`Invalid input: expected ${i(e.expected)}, received ${i(yt(e.input),e.input)}`;case`invalid_value`:return e.values.length===1?`Invalid input: expected ${Ze(e.values[0])}`:`Invalid option: expected one of ${De(e.values,`|`)}`;case`too_big`:{let n=e.exact?`exactly `:e.inclusive?`<=`:`<`,r=t(e.origin);return r?`Too big: expected ${e.origin??`value`} to have ${n}${e.maximum.toString()} ${r.unit??`elements`}`:`Too big: expected ${e.origin??`value`} to be ${n}${e.maximum.toString()}`}case`too_small`:{let n=e.exact?`exactly `:e.inclusive?`>=`:`>`,r=t(e.origin);return r?`Too small: expected ${e.origin} to have ${n}${e.minimum.toString()} ${r.unit}`:`Too small: expected ${e.origin} to be ${n}${e.minimum.toString()}`}case`invalid_format`:{let t=e;return t.format===`starts_with`?`Invalid string: must start with "${t.prefix}"`:t.format===`ends_with`?`Invalid string: must end with "${t.suffix}"`:t.format===`includes`?`Invalid string: must include "${t.includes}"`:t.format===`regex`?`Invalid string: must match pattern ${t.pattern}`:`Invalid ${n[t.format]??e.format}`}case`not_multiple_of`:return`Invalid number: must be a multiple of ${e.divisor}`;case`unrecognized_keys`:return`Unrecognized key${e.keys.length>1?`s`:``}: ${De(e.keys,`, `)}`;case`invalid_key`:return`Invalid key in ${e.origin}`;case`invalid_union`:return e.options&&Array.isArray(e.options)&&e.options.length>0?`Invalid discriminator value. Expected ${e.options.map(e=>`'${e}'`).join(` | `)}`:e.inclusive===!1?`Invalid input: more than one option matched`:`Invalid input`;case`invalid_element`:return`Invalid value in ${e.origin}`;default:return`Invalid input`}}};function $i(){return{localeError:Qi()}}var ea,ta=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 na(){return new ta}(ea=globalThis).__zod_globalRegistry??(ea.__zod_globalRegistry=na());const ra=globalThis.__zod_globalRegistry;function ia(e,t){return new e({type:`string`,...v(t)})}function aa(e,t){return new e({type:`string`,format:`email`,check:`string_format`,abort:!1,...v(t)})}function oa(e,t){return new e({type:`string`,format:`guid`,check:`string_format`,abort:!1,...v(t)})}function sa(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,...v(t)})}function ca(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v4`,...v(t)})}function la(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v6`,...v(t)})}function ua(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v7`,...v(t)})}function da(e,t){return new e({type:`string`,format:`url`,check:`string_format`,abort:!1,...v(t)})}function fa(e,t){return new e({type:`string`,format:`emoji`,check:`string_format`,abort:!1,...v(t)})}function pa(e,t){return new e({type:`string`,format:`nanoid`,check:`string_format`,abort:!1,...v(t)})}function ma(e,t){return new e({type:`string`,format:`cuid`,check:`string_format`,abort:!1,...v(t)})}function ha(e,t){return new e({type:`string`,format:`cuid2`,check:`string_format`,abort:!1,...v(t)})}function ga(e,t){return new e({type:`string`,format:`ulid`,check:`string_format`,abort:!1,...v(t)})}function _a(e,t){return new e({type:`string`,format:`xid`,check:`string_format`,abort:!1,...v(t)})}function va(e,t){return new e({type:`string`,format:`ksuid`,check:`string_format`,abort:!1,...v(t)})}function ya(e,t){return new e({type:`string`,format:`ipv4`,check:`string_format`,abort:!1,...v(t)})}function ba(e,t){return new e({type:`string`,format:`ipv6`,check:`string_format`,abort:!1,...v(t)})}function xa(e,t){return new e({type:`string`,format:`cidrv4`,check:`string_format`,abort:!1,...v(t)})}function Sa(e,t){return new e({type:`string`,format:`cidrv6`,check:`string_format`,abort:!1,...v(t)})}function Ca(e,t){return new e({type:`string`,format:`base64`,check:`string_format`,abort:!1,...v(t)})}function wa(e,t){return new e({type:`string`,format:`base64url`,check:`string_format`,abort:!1,...v(t)})}function Ta(e,t){return new e({type:`string`,format:`e164`,check:`string_format`,abort:!1,...v(t)})}function Ea(e,t){return new e({type:`string`,format:`jwt`,check:`string_format`,abort:!1,...v(t)})}function Da(e,t){return new e({type:`string`,format:`datetime`,check:`string_format`,offset:!1,local:!1,precision:null,...v(t)})}function Oa(e,t){return new e({type:`string`,format:`date`,check:`string_format`,...v(t)})}function ka(e,t){return new e({type:`string`,format:`time`,check:`string_format`,precision:null,...v(t)})}function Aa(e,t){return new e({type:`string`,format:`duration`,check:`string_format`,...v(t)})}function ja(e,t){return new e({type:`number`,checks:[],...v(t)})}function Ma(e,t){return new e({type:`number`,check:`number_format`,abort:!1,format:`safeint`,...v(t)})}function Na(e,t){return new e({type:`boolean`,...v(t)})}function Pa(e){return new e({type:`unknown`})}function Fa(e,t){return new e({type:`never`,...v(t)})}function Ia(e,t){return new Xn({check:`less_than`,...v(t),value:e,inclusive:!1})}function La(e,t){return new Xn({check:`less_than`,...v(t),value:e,inclusive:!0})}function Ra(e,t){return new Zn({check:`greater_than`,...v(t),value:e,inclusive:!1})}function za(e,t){return new Zn({check:`greater_than`,...v(t),value:e,inclusive:!0})}function Ba(e,t){return new Qn({check:`multiple_of`,...v(t),value:e})}function Va(e,t){return new er({check:`max_length`,...v(t),maximum:e})}function Ha(e,t){return new tr({check:`min_length`,...v(t),minimum:e})}function Ua(e,t){return new nr({check:`length_equals`,...v(t),length:e})}function Wa(e,t){return new ir({check:`string_format`,format:`regex`,...v(t),pattern:e})}function Ga(e){return new ar({check:`string_format`,format:`lowercase`,...v(e)})}function Ka(e){return new or({check:`string_format`,format:`uppercase`,...v(e)})}function qa(e,t){return new sr({check:`string_format`,format:`includes`,...v(t),includes:e})}function Ja(e,t){return new cr({check:`string_format`,format:`starts_with`,...v(t),prefix:e})}function Ya(e,t){return new lr({check:`string_format`,format:`ends_with`,...v(t),suffix:e})}function Xa(e){return new ur({check:`overwrite`,tx:e})}function Za(e){return Xa(t=>t.normalize(e))}function Qa(){return Xa(e=>e.trim())}function $a(){return Xa(e=>e.toLowerCase())}function eo(){return Xa(e=>e.toUpperCase())}function to(){return Xa(e=>He(e))}function no(e,t,n){return new e({type:`array`,element:t,...v(n)})}function ro(e,t,n){return new e({type:`custom`,check:`custom`,fn:t,...v(n)})}function io(e,t){let n=ao(t=>(t.addIssue=e=>{if(typeof e==`string`)t.issues.push(bt(e,t.value,n._zod.def));else{let r=e;r.fatal&&(r.continue=!1),r.code??=`custom`,`input`in r||(r.input=t.value),r.inst??=n,r.continue??=!n._zod.def.abort,t.issues.push(bt(r))}},e(t.value,t)),t);return n}function ao(e,t){let n=new C({check:`custom`,...v(t)});return n._zod.check=e,n}function oo(e,...t){for(let n of t)for(let t of Reflect.ownKeys(n))Object.prototype.propertyIsEnumerable.call(n,t)&&Pe(e,t,n[t]);return e}function so(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??ra,target:t,unrepresentable:e?.unrepresentable??`throw`,override:e?.override??(()=>{}),io:e?.io??`output`,counter:0,seen:new Map,sharedDefsExtractedFor:void 0,sharedEmitDoneFor:void 0,cycles:e?.cycles??`ref`,reused:e?.reused??`inline`,intersections:[],deferred:[],external:e?.external??void 0}}function co(e,t,n,r,i){let a=typeof t.unrepresentable==`function`?t.unrepresentable({zodSchema:e,path:r.path,message:i}):t.unrepresentable;if(a===`any`)return!1;if(a===void 0||a===`throw`)throw Error(i);return Object.assign(n,a),!0}function E(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),t.sharedDefsExtractedFor=void 0,t.sharedEmitDoneFor=void 0;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,E(a,t,r),t.seen.get(a).isParent=!0)}let c=t.metadataRegistry.get(e);return c&&oo(o.schema,c),t.io===`input`&&D(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 lo(e){return e.replace(/~/g,`~0`).replace(/\//g,`~1`)}function uo(e,t){let n=e.seen.get(t);if(!n)throw Error(`Unprocessed schema. This is a bug in Zod.`);if(e.external&&e.sharedDefsExtractedFor===e.external)return;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}/${lo(a)}`}}let i=`#/${r}/`;if(t[1]===n&&!t[1].schema.id)return{ref:`#`};let a=t[1].schema.id??`__schema${e.counter++}`;return{defId:a,ref:i+lo(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>
|
|
55
|
+
`)}return o.write(`payload.value = newResult;`),o.write(`return payload;`),o.compile()},o,s=We,c=!x.jitless,l=c&&Ge.value,u=t.catchall,d;e._zod.parse=(i,f)=>{d??=r.value;let p=i.value;return s(p)?c&&l&&f?.async===!1&&f.jitless!==!0?(o||=a(t.shape),i=o(i,f),u?mi([],p,i,f,d,e,f?.abortEarly===!0):i):n(i,f):(i.issues.push({expected:`object`,code:`invalid_type`,input:p,inst:e}),i)}});function _i(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=>!ut(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=>gt(e,r,zt())))}),t)}const vi=/*@__PURE__*/ b(`$ZodUnion`,(e,t)=>{w.init(e,t),y(e,`optin`,e=>e.def.options.some(e=>e._zod.optin===`defaulted`)?`defaulted`:e.def.options.some(e=>e._zod.optin!==void 0)?`optional`:void 0),y(e,`optout`,e=>e.def.options.some(e=>e._zod.optout===`optional`)?`optional`:void 0),y(e,`values`,e=>{if(e.def.options.every(e=>e._zod.values))return new Set(e.def.options.flatMap(e=>Array.from(e._zod.values)))}),y(e,`pattern`,e=>{if(e.def.options.every(e=>e._zod.pattern)){let t=e.def.options.map(e=>e._zod.pattern);return RegExp(`^(${t.map(e=>Me(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=>_i(t,r,e,i)):_i(o,r,e,i)}}),yi=/*@__PURE__*/ b(`$ZodIntersection`,(e,t)=>{w.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])=>xi(e,t,n)):xi(e,i,a)}});function bi(e,t){if(e===t||e instanceof Date&&t instanceof Date&&+e==+t)return{valid:!0,data:e};if(Ke(e)&&Ke(t)){let n=Object.keys(t),r=Object.keys(e).filter(e=>n.indexOf(e)!==-1),i={...e,...t};Object.prototype.hasOwnProperty.call(i,`__proto__`)&&delete i.__proto__;for(let n of r){if(n===`__proto__`)continue;let r=bi(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=bi(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 xi(e,t,n){let r=/* @__PURE__ */ new Map,i,a=/* @__PURE__ */ new Map,o=(e,t)=>{let n;if(e.code===`unrecognized_keys`&&!e.path?.length)i??=e,n=e.keys;else if(e.code===`invalid_key`&&e.origin===`record`&&e.path?.length===1){let t=String(e.path[0]);a.has(t)||a.set(t,e),n=[t]}else return!1;for(let e of n)r.has(e)||r.set(e,{}),r.get(e)[t]=!0;return!0};for(let n of t.issues)o(n,`l`)||e.issues.push(n);for(let t of n.issues)o(t,`r`)||e.issues.push(t);let s=[...r].filter(([,e])=>e.l&&e.r).map(([e])=>e);if(s.length){let t=i?s.filter(e=>i.keys.includes(e)):[];t.length&&e.issues.push({...i,keys:t});for(let n of s)!t.includes(n)&&a.has(n)&&e.issues.push(a.get(n))}let c=bi(t.value,n.value);if(!c.valid){if(ut(e))return e;throw Error(`Unmergable intersection. Error path: ${JSON.stringify(c.mergeErrorPath)}`)}return e.value=c.data,e}const Si=/*@__PURE__*/ b(`$ZodRecord`,(e,t)=>{w.init(e,t);let n=x.memoizer;n?.attach(e),e._zod.parse=(r,i)=>{let a=r.value;if(!Ke(a))return r.issues.push({expected:`record`,code:`invalid_type`,input:a,inst:e}),r;let o=[],s=t.keyType._zod.values;if(s&&!t.partial){r.value=n?n.alloc(e,r,{},i):{};let c=/* @__PURE__ */ new Set;for(let n of s)if(typeof n==`string`||typeof n==`number`||typeof n==`symbol`){if(c.add(typeof n==`number`?n.toString():n),n===`__proto__`)continue;let s=t.keyType._zod.run({value:n,issues:[]},i);if(s instanceof Promise)throw Error(`Async schemas not supported in object keys currently`);if(s.issues.length){r.issues.push({code:`invalid_key`,origin:`record`,issues:s.issues.map(e=>gt(e,i,zt())),input:n,path:[n],inst:e});continue}let l=s.value;if(l===`__proto__`)continue;let u=t.valueType._zod.run({value:a[n],issues:[]},i);u instanceof Promise?o.push(u.then(e=>{e.issues.length&&r.issues.push(...ft(n,e.issues)),r.value[l]=e.value})):(u.issues.length&&r.issues.push(...ft(n,u.issues)),r.value[l]=u.value)}let l;for(let e in a)if(!c.has(e)){if(t.mode===`loose`){if(e===`__proto__`)continue;r.value[e]=a[e]}else l??=[],l.push(e)}l&&l.length>0&&r.issues.push({code:`unrecognized_keys`,input:a,inst:e,keys:l,continue:!0})}else{r.value=n?n.alloc(e,r,{},i):{};let c;for(let n of Reflect.ownKeys(a)){if(n===`__proto__`||!Object.prototype.propertyIsEnumerable.call(a,n))continue;let l=t.keyType._zod.run({value:n,issues:[]},i);if(l instanceof Promise)throw Error(`Async schemas not supported in object keys currently`);if(typeof n==`string`&&Gn.test(n)&&l.issues.length){let e=t.keyType._zod.run({value:Number(n),issues:[]},i);if(e instanceof Promise)throw Error(`Async schemas not supported in object keys currently`);e.issues.length===0&&(l=e)}if(l.issues.length){t.mode===`loose`?r.value[n]=a[n]:s?(c??=[],c.push(n)):r.issues.push({code:`invalid_key`,origin:`record`,issues:l.issues.map(e=>gt(e,i,zt())),input:n,path:[n],inst:e});continue}let u=l.value;if(u===`__proto__`)continue;let d=t.valueType._zod.run({value:a[n],issues:[]},i);d instanceof Promise?o.push(d.then(e=>{e.issues.length&&r.issues.push(...ft(n,e.issues)),r.value[u]=e.value})):(d.issues.length&&r.issues.push(...ft(n,d.issues)),r.value[u]=d.value)}c&&c.length>0&&r.issues.push({code:`unrecognized_keys`,input:a,inst:e,keys:c,continue:!0})}return o.length?Promise.all(o).then(()=>r):r}}),Ci=/*@__PURE__*/ b(`$ZodEnum`,(e,t)=>{w.init(e,t);let n=Ee(t.entries),r=new Set(n);e._zod.values=r,y(e,`pattern`,e=>{let t=Ee(e.def.entries).filter(e=>Je.has(typeof e));return RegExp(t.length?`^(${t.map(e=>Ye(e.toString())).join(`|`)})$`:`^[^\\s\\S]$`)}),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}}),wi=/*@__PURE__*/ b(`$ZodTransform`,(e,t)=>{w.init(e,t),e._zod.optin=`optional`,x.memoizer?.guard(e),e._zod.parse=(n,r)=>{if(r.direction===`backward`)throw new Rt(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));if(i instanceof Promise)throw new Lt;return n.value=i,n}});function Ti(e,t){return e.value=t.issues.length?void 0:t.value,e}const Ei=/*@__PURE__*/ b(`$ZodOptional`,(e,t)=>{w.init(e,t),y(e,`optin`,e=>e.def.innerType._zod.optin===`defaulted`?`defaulted`:`optional`),e._zod.optout=`optional`,y(e,`values`,e=>{let t=e.def.innerType._zod.values;return t?/* @__PURE__ */ new Set([...t,void 0]):void 0}),y(e,`pattern`,e=>{let t=e.def.innerType._zod.pattern;return t?RegExp(`^(${Me(t.source)})?$`):void 0}),e._zod.parse=(e,n)=>{if(e.value===void 0){if(t.innerType._zod.optin!==`defaulted`)return e;let r=t.innerType._zod.run({value:e.value,issues:[]},n);return r instanceof Promise?r.then(t=>Ti(e,t)):Ti(e,r)}return t.innerType._zod.run(e,n)}}),Di=/*@__PURE__*/ b(`$ZodExactOptional`,(e,t)=>{Ei.init(e,t),y(e,`values`,e=>e.def.innerType._zod.values),y(e,`pattern`,e=>e.def.innerType._zod.pattern),e._zod.parse=(e,n)=>t.innerType._zod.run(e,n)}),Oi=/*@__PURE__*/ b(`$ZodNullable`,(e,t)=>{w.init(e,t),y(e,`optin`,e=>e.def.innerType._zod.optin),y(e,`optout`,e=>e.def.innerType._zod.optout),y(e,`pattern`,e=>{let t=e.def.innerType._zod.pattern;return t?RegExp(`^(${Me(t.source)}|null)$`):void 0}),y(e,`values`,e=>e.def.innerType._zod.values?/* @__PURE__ */ new Set([...e.def.innerType._zod.values,null]):void 0),e._zod.parse=(e,n)=>e.value===null?e:t.innerType._zod.run(e,n)}),ki=/*@__PURE__*/ b(`$ZodDefault`,(e,t)=>{w.init(e,t),e._zod.optin=`defaulted`,y(e,`values`,e=>e.def.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=>Ai(e,t)):Ai(r,t)}});function Ai(e,t){return e.value===void 0&&(e.value=t.defaultValue),e}const ji=/*@__PURE__*/ b(`$ZodPrefault`,(e,t)=>{w.init(e,t),e._zod.optin=`defaulted`,y(e,`values`,e=>e.def.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))}),Mi=/*@__PURE__*/ b(`$ZodNonOptional`,(e,t)=>{w.init(e,t),y(e,`values`,e=>{let t=e.def.innerType._zod.values;return t?new Set([...t].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=>Ni(t,e)):Ni(i,e)}});function Ni(e,t){return!e.issues.length&&e.value===void 0&&e.issues.push({code:`invalid_type`,expected:`nonoptional`,input:e.value,inst:t}),e}function Pi(e,t,n,r){return t.issues.length?(e.value=n.catchValue({...t,value:e.value,error:{issues:t.issues.map(e=>gt(e,r,zt()))},input:e.value}),e):(e.value=t.value,t.memo&&(e.memo=!0),e)}const Fi=/*@__PURE__*/ b(`$ZodCatch`,(e,t)=>{w.init(e,t),y(e,`optin`,e=>e.def.innerType._zod.optin===`defaulted`?`defaulted`:`optional`),y(e,`optout`,e=>e.def.innerType._zod.optout),y(e,`values`,e=>e.def.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({value:e.value,issues:[]},n);return r instanceof Promise?r.then(r=>Pi(e,r,t,n)):Pi(e,r,t,n)}}),Ii=/*@__PURE__*/ b(`$ZodPipe`,(e,t)=>{w.init(e,t),y(e,`values`,e=>e.def.in._zod.values),y(e,`optin`,e=>e.def.in._zod.optin),y(e,`optout`,e=>e.def.out._zod.optout),y(e,`propValues`,e=>e.def.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=>Li(e,t.in,n)):Li(r,t.in,n)}let r=t.in._zod.run(e,n);return r instanceof Promise?r.then(e=>Li(e,t.out,n)):Li(r,t.out,n)}});function Li(e,t,n){return e.issues.some(e=>e.code!==`unrecognized_keys`)?(e.aborted=!0,e):t._zod.run({value:e.value,issues:e.issues},n)}const Ri=/*@__PURE__*/ b(`$ZodPreprocess`,(e,t)=>{Ii.init(e,t)}),zi=/*@__PURE__*/ b(`$ZodReadonly`,(e,t)=>{w.init(e,t),y(e,`propValues`,e=>e.def.innerType._zod.propValues),y(e,`values`,e=>e.def.innerType._zod.values),y(e,`optin`,e=>e.def.innerType?._zod?.optin),y(e,`optout`,e=>e.def.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(Bi):Bi(r)}});function Bi(e){return e.memo||(e.value=Object.freeze(e.value)),e}const Vi=/*@__PURE__*/ b(`$ZodCustom`,(e,t)=>{C.init(e,t),w.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=>Hi(t,n,r,e));Hi(i,n,r,e)}});function Hi(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(xt(e))}}var Ui=class extends Error{constructor(){super(`Cannot parse a reference cycle that closes through a transform`),this.name=`ZodCyclicError`}};const Wi=`~memo`,Gi=[];function Ki(e){return typeof e==`object`&&!!e}function qi(e){return e.map(e=>e.path?{...e,path:e.path.slice()}:{...e})}const Ji=/*@__PURE__*/ new WeakMap;function Yi(e,t,n){let r=Ji.get(e);if(r!==void 0)return r?2:0;if(t.has(e))return 2;t.add(e);let i=0,a=e=>{if(i!==2&&e?._zod){let r=Yi(e,t,n);r>i&&(i=r)}},o=(e,r)=>{let i=0;for(let a of Reflect.ownKeys(e)){let o=Object.getOwnPropertyDescriptor(e,a);if(r&&!o.enumerable)continue;let s=o.get?1:o.value?._zod?Yi(o.value,t,n):0;s>i&&(i=s)}return i},s=e=>{e>i&&(i=e)},c=e._zod.def;switch(c.type){case`object`:{let e=Fe(c);s(e?o(e,!0):1),a(c.catchall);break}case`array`:a(c.element);break;case`tuple`:for(let e of c.items)a(e);a(c.rest);break;case`record`:case`map`:a(c.keyType),a(c.valueType);break;case`set`:a(c.valueType);break;case`union`:for(let e of c.options)a(e);break;case`intersection`:a(c.left),a(c.right);break;case`optional`:case`nullable`:case`default`:case`prefault`:case`catch`:case`readonly`:case`nonoptional`:case`promise`:case`success`:a(c.innerType);break;case`pipe`:a(c.in),a(c.out);break;case`function`:a(c.input),a(c.output);break;case`lazy`:{let r=c._cachedInner??(n?e._zod.innerType:void 0);s(r?Yi(r,t,!1):1);break}case`template_literal`:case`string`:case`number`:case`int`:case`boolean`:case`bigint`:case`symbol`:case`undefined`:case`null`:case`void`:case`never`:case`any`:case`unknown`:case`date`:case`nan`:case`enum`:case`literal`:case`file`:case`transform`:case`custom`:break;default:for(let e in c){let t=Object.getOwnPropertyDescriptor(c,e);if(!t||t.get)continue;let n=t.value;if(n&&typeof n==`object`){if(n._zod)a(n);else if(Array.isArray(n))for(let e of n)a(e)}}}return t.delete(e),Xi(e,i)}function Xi(e,t){return t!==1&&Ji.set(e,t===2),t}function Zi(e,t){let n=e.buckets.get(t);return n||(n=/* @__PURE__ */ new WeakMap,e.buckets.set(t,n)),n}let Qi;const $i=[],ea={alloc(e,t,n){let r=Qi;if(!r)return n;Qi=void 0;let i={value:n,issues:null};return r.set(t.value,i),$i.push(i),n},guard(e){var t;(t=e._zod).deferred??(t.deferred=[]),e._zod.deferred.push(()=>{let t=e._zod.parse,n=(e,n)=>{if(n.direction!==`backward`&&na(n,e.value))throw new Ui;return t(e,n)};e._zod.parse=n,e._zod.run===t&&(e._zod.run=n)})},attach(e){var t;let n,r=!1,i,a;(t=e._zod).deferred??(t.deferred=[]),e._zod.deferred.push(()=>{let t=e._zod.parse,o=(s,c)=>{if(n===void 0){let i=Yi(e,/* @__PURE__ */ new Set,!1);if(i===0)return e._zod.parse=t,e._zod.run===o&&(e._zod.run=t),t(s,c);i===2||r?n=!0:r=!0}let l=s.value;if(!Ki(l))return t(s,c);let u=c[Wi];u||(u={buckets:/* @__PURE__ */ new WeakMap,backEdges:void 0},c[Wi]=u);let d;i===c?d=a:(d=Zi(u,e),i=c,a=d);let f=d.get(l);if(f)return s.value=f.value,f.issues?f.issues.length&&s.issues.push(...qi(f.issues)):(s.memo=!0,u.backEdges??(u.backEdges=/* @__PURE__ */ new WeakSet),u.backEdges.add(f.value)),s;Qi=d;let p=$i.length,ee=t(s,c);Qi=void 0;let te=$i.length>p?$i.pop():void 0;return ee instanceof Promise?ee.then(e=>(te&&(te.issues=e.issues.length?qi(e.issues):Gi),e)):(te&&(te.issues=ee.issues.length?qi(ee.issues):Gi),ee)};e._zod.parse=o,e._zod.run===t&&(e._zod.run=o)})}};function ta(){return ea}function na(e,t){let n=e[Wi]?.backEdges;return n!==void 0&&Ki(t)&&n.has(t)}const ra=()=>{let e={string:{unit:`characters`,verb:`to have`},file:{unit:`bytes`,verb:`to have`},array:{unit:`items`,verb:`to have`},set:{unit:`items`,verb:`to have`},map:{unit:`entries`,verb:`to have`}};function t(t){return e[t]??null}let n={regex:`input`,email:`email address`,url:`URL`,emoji:`emoji`,uuid:`UUID`,uuidv4:`UUIDv4`,uuidv6:`UUIDv6`,nanoid:`nanoid`,guid:`GUID`,cuid:`cuid`,cuid2:`cuid2`,ulid:`ULID`,xid:`XID`,ksuid:`KSUID`,datetime:`ISO datetime`,date:`ISO date`,time:`ISO time`,duration:`ISO duration`,ipv4:`IPv4 address`,ipv6:`IPv6 address`,mac:`MAC address`,cidrv4:`IPv4 range`,cidrv6:`IPv6 range`,base64:`base64-encoded string`,base64url:`base64url-encoded string`,json_string:`JSON string`,e164:`E.164 number`,currency_code:`currency code`,credit_card:`credit card number`,iban:`IBAN`,jwt:`JWT`,template_literal:`input`},r={nan:`NaN`};function i(e,t){return e===`number`&&typeof t==`number`&&!Number.isFinite(t)?String(t):r[e]??e}return e=>{switch(e.code){case`invalid_type`:return`Invalid input: expected ${i(e.expected)}, received ${i(bt(e.input),e.input)}`;case`invalid_value`:return e.values.length===1?`Invalid input: expected ${Ze(e.values[0])}`:`Invalid option: expected one of ${De(e.values,`|`)}`;case`too_big`:{let n=e.exact?`exactly `:e.inclusive?`<=`:`<`,r=t(e.origin);return r?`Too big: expected ${e.origin??`value`} to have ${n}${e.maximum.toString()} ${r.unit??`elements`}`:`Too big: expected ${e.origin??`value`} to be ${n}${e.maximum.toString()}`}case`too_small`:{let n=e.exact?`exactly `:e.inclusive?`>=`:`>`,r=t(e.origin);return r?`Too small: expected ${e.origin} to have ${n}${e.minimum.toString()} ${r.unit}`:`Too small: expected ${e.origin} to be ${n}${e.minimum.toString()}`}case`invalid_format`:{let t=e;return t.format===`starts_with`?`Invalid string: must start with "${t.prefix}"`:t.format===`ends_with`?`Invalid string: must end with "${t.suffix}"`:t.format===`includes`?`Invalid string: must include "${t.includes}"`:t.format===`regex`?`Invalid string: must match pattern ${t.pattern}`:`Invalid ${n[t.format]??e.format}`}case`not_multiple_of`:return`Invalid number: must be a multiple of ${e.divisor}`;case`unrecognized_keys`:return`Unrecognized key${e.keys.length>1?`s`:``}: ${De(e.keys,`, `)}`;case`invalid_key`:return`Invalid key in ${e.origin}`;case`invalid_union`:return e.options&&Array.isArray(e.options)&&e.options.length>0?`Invalid discriminator value. Expected ${e.options.map(e=>`'${e}'`).join(` | `)}`:e.inclusive===!1?`Invalid input: more than one option matched`:`Invalid input`;case`invalid_element`:return`Invalid value in ${e.origin}`;default:return`Invalid input`}}};function ia(){return{localeError:ra()}}var aa,oa=class{constructor(){this._map=/* @__PURE__ */ new WeakMap,this._idmap=/* @__PURE__ */ 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=/* @__PURE__ */ new WeakMap,this._idmap=/* @__PURE__ */ 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 sa(){return new oa}(aa=globalThis).__zod_globalRegistry??(aa.__zod_globalRegistry=sa());const ca=globalThis.__zod_globalRegistry;function la(e){return e.checks&&=[...e.checks],e}// @__NO_SIDE_EFFECTS__
|
|
56
|
+
function ua(e,t){return new e(la({type:`string`,...v(t)}))}// @__NO_SIDE_EFFECTS__
|
|
57
|
+
function da(e,t){return new e({type:`string`,format:`email`,check:`string_format`,abort:!1,...v(t)})}// @__NO_SIDE_EFFECTS__
|
|
58
|
+
function fa(e,t){return new e({type:`string`,format:`guid`,check:`string_format`,abort:!1,...v(t)})}// @__NO_SIDE_EFFECTS__
|
|
59
|
+
function pa(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,...v(t)})}// @__NO_SIDE_EFFECTS__
|
|
60
|
+
function ma(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v4`,...v(t)})}// @__NO_SIDE_EFFECTS__
|
|
61
|
+
function ha(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v6`,...v(t)})}// @__NO_SIDE_EFFECTS__
|
|
62
|
+
function ga(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v7`,...v(t)})}// @__NO_SIDE_EFFECTS__
|
|
63
|
+
function _a(e,t){return new e({type:`string`,format:`url`,check:`string_format`,abort:!1,...v(t)})}// @__NO_SIDE_EFFECTS__
|
|
64
|
+
function va(e,t){return new e({type:`string`,format:`emoji`,check:`string_format`,abort:!1,...v(t)})}// @__NO_SIDE_EFFECTS__
|
|
65
|
+
function ya(e,t){return new e({type:`string`,format:`nanoid`,check:`string_format`,abort:!1,...v(t)})}// @__NO_SIDE_EFFECTS__
|
|
66
|
+
function ba(e,t){return new e({type:`string`,format:`cuid`,check:`string_format`,abort:!1,...v(t)})}// @__NO_SIDE_EFFECTS__
|
|
67
|
+
function xa(e,t){return new e({type:`string`,format:`cuid2`,check:`string_format`,abort:!1,...v(t)})}// @__NO_SIDE_EFFECTS__
|
|
68
|
+
function Sa(e,t){return new e({type:`string`,format:`ulid`,check:`string_format`,abort:!1,...v(t)})}// @__NO_SIDE_EFFECTS__
|
|
69
|
+
function Ca(e,t){return new e({type:`string`,format:`xid`,check:`string_format`,abort:!1,...v(t)})}// @__NO_SIDE_EFFECTS__
|
|
70
|
+
function wa(e,t){return new e({type:`string`,format:`ksuid`,check:`string_format`,abort:!1,...v(t)})}// @__NO_SIDE_EFFECTS__
|
|
71
|
+
function Ta(e,t){return new e({type:`string`,format:`ipv4`,check:`string_format`,abort:!1,...v(t)})}// @__NO_SIDE_EFFECTS__
|
|
72
|
+
function Ea(e,t){return new e({type:`string`,format:`ipv6`,check:`string_format`,abort:!1,...v(t)})}// @__NO_SIDE_EFFECTS__
|
|
73
|
+
function Da(e,t){return new e({type:`string`,format:`cidrv4`,check:`string_format`,abort:!1,...v(t)})}// @__NO_SIDE_EFFECTS__
|
|
74
|
+
function Oa(e,t){return new e({type:`string`,format:`cidrv6`,check:`string_format`,abort:!1,...v(t)})}// @__NO_SIDE_EFFECTS__
|
|
75
|
+
function ka(e,t){return new e({type:`string`,format:`base64`,check:`string_format`,abort:!1,...v(t)})}// @__NO_SIDE_EFFECTS__
|
|
76
|
+
function Aa(e,t){return new e({type:`string`,format:`base64url`,check:`string_format`,abort:!1,...v(t)})}// @__NO_SIDE_EFFECTS__
|
|
77
|
+
function ja(e,t){return new e({type:`string`,format:`e164`,check:`string_format`,abort:!1,...v(t)})}// @__NO_SIDE_EFFECTS__
|
|
78
|
+
function Ma(e,t){return new e({type:`string`,format:`jwt`,check:`string_format`,abort:!1,...v(t)})}// @__NO_SIDE_EFFECTS__
|
|
79
|
+
function Na(e,t){return new e({type:`string`,format:`datetime`,check:`string_format`,offset:!1,local:!1,precision:null,...v(t)})}// @__NO_SIDE_EFFECTS__
|
|
80
|
+
function Pa(e,t){return new e({type:`string`,format:`date`,check:`string_format`,...v(t)})}// @__NO_SIDE_EFFECTS__
|
|
81
|
+
function Fa(e,t){return new e({type:`string`,format:`time`,check:`string_format`,precision:null,...v(t)})}// @__NO_SIDE_EFFECTS__
|
|
82
|
+
function Ia(e,t){return new e({type:`string`,format:`duration`,check:`string_format`,...v(t)})}// @__NO_SIDE_EFFECTS__
|
|
83
|
+
function La(e,t){return new e(la({type:`number`,checks:[],...v(t)}))}// @__NO_SIDE_EFFECTS__
|
|
84
|
+
function Ra(e,t){return new e({type:`number`,check:`number_format`,abort:!1,format:`safeint`,...v(t)})}// @__NO_SIDE_EFFECTS__
|
|
85
|
+
function za(e,t){return new e({type:`boolean`,...v(t)})}// @__NO_SIDE_EFFECTS__
|
|
86
|
+
function Ba(e){return new e({type:`unknown`})}// @__NO_SIDE_EFFECTS__
|
|
87
|
+
function Va(e,t){return new e({type:`never`,...v(t)})}// @__NO_SIDE_EFFECTS__
|
|
88
|
+
function Ha(e,t){return new Zn({check:`less_than`,...v(t),value:e,inclusive:!1})}// @__NO_SIDE_EFFECTS__
|
|
89
|
+
function Ua(e,t){return new Zn({check:`less_than`,...v(t),value:e,inclusive:!0})}// @__NO_SIDE_EFFECTS__
|
|
90
|
+
function Wa(e,t){return new Qn({check:`greater_than`,...v(t),value:e,inclusive:!1})}// @__NO_SIDE_EFFECTS__
|
|
91
|
+
function Ga(e,t){return new Qn({check:`greater_than`,...v(t),value:e,inclusive:!0})}// @__NO_SIDE_EFFECTS__
|
|
92
|
+
function Ka(e,t){return new $n({check:`multiple_of`,...v(t),value:e})}// @__NO_SIDE_EFFECTS__
|
|
93
|
+
function qa(e,t){return new tr({check:`max_length`,...v(t),maximum:e})}// @__NO_SIDE_EFFECTS__
|
|
94
|
+
function Ja(e,t){return new nr({check:`min_length`,...v(t),minimum:e})}// @__NO_SIDE_EFFECTS__
|
|
95
|
+
function Ya(e,t){return new rr({check:`length_equals`,...v(t),length:e})}// @__NO_SIDE_EFFECTS__
|
|
96
|
+
function Xa(e,t){return new ar({check:`string_format`,format:`regex`,...v(t),pattern:e})}// @__NO_SIDE_EFFECTS__
|
|
97
|
+
function Za(e){return new or({check:`string_format`,format:`lowercase`,...v(e)})}// @__NO_SIDE_EFFECTS__
|
|
98
|
+
function Qa(e){return new sr({check:`string_format`,format:`uppercase`,...v(e)})}// @__NO_SIDE_EFFECTS__
|
|
99
|
+
function $a(e,t){return new cr({check:`string_format`,format:`includes`,...v(t),includes:e})}// @__NO_SIDE_EFFECTS__
|
|
100
|
+
function eo(e,t){return new lr({check:`string_format`,format:`starts_with`,...v(t),prefix:e})}// @__NO_SIDE_EFFECTS__
|
|
101
|
+
function to(e,t){return new ur({check:`string_format`,format:`ends_with`,...v(t),suffix:e})}// @__NO_SIDE_EFFECTS__
|
|
102
|
+
function no(e){return new dr({check:`overwrite`,tx:e})}// @__NO_SIDE_EFFECTS__
|
|
103
|
+
function ro(e){return/* @__PURE__ */ no(t=>t.normalize(e))}// @__NO_SIDE_EFFECTS__
|
|
104
|
+
function io(){return/* @__PURE__ */ no(e=>e.trim())}// @__NO_SIDE_EFFECTS__
|
|
105
|
+
function ao(){return/* @__PURE__ */ no(e=>e.toLowerCase())}// @__NO_SIDE_EFFECTS__
|
|
106
|
+
function oo(){return/* @__PURE__ */ no(e=>e.toUpperCase())}// @__NO_SIDE_EFFECTS__
|
|
107
|
+
function so(){return/* @__PURE__ */ no(e=>He(e))}// @__NO_SIDE_EFFECTS__
|
|
108
|
+
function co(e,t,n){return new e({type:`array`,element:t,...v(n)})}// @__NO_SIDE_EFFECTS__
|
|
109
|
+
function lo(e,t,n){return new e({type:`custom`,check:`custom`,fn:t,...v(n)})}// @__NO_SIDE_EFFECTS__
|
|
110
|
+
function uo(e,t){let n=/* @__PURE__ */ fo(t=>(t.addIssue=e=>{if(typeof e==`string`)t.issues.push(xt(e,t.value,n._zod.def));else{let r=e;r.fatal&&(r.continue=!1),r.code??=`custom`,`input`in r||(r.input=t.value),r.inst??=n,r.continue??=!n._zod.def.abort,t.issues.push(xt(r))}},e(t.value,t)),t);return n}// @__NO_SIDE_EFFECTS__
|
|
111
|
+
function fo(e,t){let n=new C({check:`custom`,...v(t)});return n._zod.check=e,n}function po(e,...t){for(let n of t)for(let t of Reflect.ownKeys(n))Object.prototype.propertyIsEnumerable.call(n,t)&&Pe(e,t,n[t]);return e}function mo(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??ca,target:t,unrepresentable:e?.unrepresentable??`throw`,override:e?.override??(()=>{}),io:e?.io??`output`,counter:0,seen:/* @__PURE__ */ new Map,sharedDefsExtractedFor:void 0,sharedEmitDoneFor:void 0,cycles:e?.cycles??`ref`,reused:e?.reused??`inline`,intersections:[],deferred:[],external:e?.external??void 0}}function ho(e,t,n,r,i){let a=typeof t.unrepresentable==`function`?t.unrepresentable({zodSchema:e,path:r.path,message:i}):t.unrepresentable;if(a===`any`)return!1;if(a===void 0||a===`throw`)throw Error(i);return Object.assign(n,a),!0}function E(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),t.sharedDefsExtractedFor=void 0,t.sharedEmitDoneFor=void 0;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,E(a,t,r),t.seen.get(a).isParent=!0)}let c=t.metadataRegistry.get(e);return c&&po(o.schema,c),t.io===`input`&&D(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 go(e){return e.replace(/~/g,`~0`).replace(/\//g,`~1`)}function _o(e,t){let n=e.seen.get(t);if(!n)throw Error(`Unprocessed schema. This is a bug in Zod.`);if(e.external&&e.sharedDefsExtractedFor===e.external)return;let r=/* @__PURE__ */ 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}/${go(a)}`}}let i=`#/${r}/`;if(t[1]===n&&!t[1].schema.id)return{ref:`#`};let a=t[1].schema.id??`__schema${e.counter++}`;return{defId:a,ref:i+go(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>
|
|
56
112
|
|
|
57
|
-
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}r.count>1&&e.reused===`ref`&&a(n)}e.external&&(e.sharedDefsExtractedFor=e.external)}function fo(e){let t=e.anyOf;if(!Array.isArray(t)||t.length===0||e.type!==void 0)return;let n=[];for(let e of t){if(!e||typeof e!=`object`)return;fo(e);let t=Object.keys(e);if(t.length!==1||t[0]!==`type`)return;let r=e.type;for(let e of Array.isArray(r)?r:[r]){if(typeof e!=`string`)return;n.includes(e)||n.push(e)}}delete e.anyOf,e.type=n.length===1?n[0]:n}const po=new Set([`type`,`properties`,`required`,`additionalProperties`]),mo=[`oneOf`,`anyOf`];function ho(e){let t=e.additionalProperties;return t===void 0||t===!1||typeof t!=`object`||!t?null:Object.keys(t).length?t:null}function go(e){let t=[];for(let n of e){if(typeof n!=`object`||n.type!==`object`)return null;for(let e in n)if(!po.has(e))return null;t.push(n)}let n={},r=new Set;for(let e of t){for(let r in e.properties){if(Object.prototype.hasOwnProperty.call(n,r))continue;let e=[];for(let n of t){let t=n.properties?.[r]??ho(n);t!=null&&(e.some(e=>JSON.stringify(e)===JSON.stringify(t))||e.push(t))}Pe(n,r,e.length===1?e[0]:go(e)??{allOf:e})}for(let t of e.required??[])r.add(t)}let i={type:`object`,properties:n};if(r.size&&(i.required=[...r]),t.every(e=>e.additionalProperties===!1))i.additionalProperties=!1;else{let e=[];for(let n of t){let t=ho(n);t&&!e.some(e=>JSON.stringify(e)===JSON.stringify(t))&&e.push(t)}e.length===1?i.additionalProperties=e[0]:e.length>1&&(i.additionalProperties={allOf:e})}return i}function _o(e){let t=e.allOf;if(!Array.isArray(t)||t.length<2)return;for(let t of po)if(t in e)return;let n=t.filter(e=>mo.some(t=>Array.isArray(e[t]))),r=null;if(!n.length)r=go(t);else{let e=n[0],i=mo.find(t=>Array.isArray(e[t]));if(Object.keys(e).length!==1)return;let a=t.filter(t=>t!==e),o=e[i].map(e=>go([...a,e]));if(o.some(e=>!e))return;r={[i]:o}}r&&(delete e.allOf,oo(e,r))}function vo(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)):oo(i,s),oo(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??[]})};if(!e.external||e.sharedEmitDoneFor!==e.external){for(let t of[...e.seen.entries()].reverse())r(t[0]);if(e.target!==`openapi-3.0`)for(let t of e.seen.entries())fo(t[1].def??t[1].schema);for(let t of e.deferred)t();if(e.intersections.length){let t=new Map;for(let n of e.seen.values())for(let e of[n.schema,n.def]){let n=e?.allOf;if(!Array.isArray(n))continue;let r=t.get(n);r?r.push(e):t.set(n,[e])}for(let n of e.intersections)for(let e of t.get(n)??[])_o(e)}}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)}oo(i,n.defId?n.schema: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??{};if(!e.external||e.sharedEmitDoneFor!==e.external)for(let t of e.seen.entries()){let e=t[1];e.def&&e.defId&&(e.def.id===e.defId&&delete e.def.id,Pe(o,e.defId,e.def))}e.external&&(e.sharedEmitDoneFor=e.external),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:bo(t,`input`,e.processors),output:bo(t,`output`,e.processors)}},enumerable:!1,writable:!1}),n}catch{throw Error(`Error converting schema to JSON.`)}}function D(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 D(r.element,n);if(r.type===`set`)return D(r.valueType,n);if(r.type===`lazy`)return D(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`||r.type===`catch`)return D(r.innerType,n);if(r.type===`intersection`)return D(r.left,n)||D(r.right,n);if(r.type===`record`||r.type===`map`)return D(r.keyType,n)||D(r.valueType,n);if(r.type===`pipe`)return e._zod.traits.has(`$ZodCodec`)?!0:D(r.in,n)||D(r.out,n);if(r.type===`object`){for(let e in r.shape)if(D(r.shape[e],n))return!0;return!1}if(r.type===`union`){for(let e of r.options)if(D(e,n))return!0;return!1}if(r.type===`tuple`){for(let e of r.items)if(D(e,n))return!0;return!!(r.rest&&D(r.rest,n))}return!1}const yo=(e,t={})=>n=>{let r=so({...n,processors:t});return E(e,r),uo(r,e),vo(r,e)},bo=(e,t,n={})=>r=>{let{libraryOptions:i,target:a}=r??{},o=so({...i??{},target:a,io:t,processors:n});return E(e,o),uo(o,e),vo(o,e)},xo=(e,t,n)=>{(e[t]===void 0||n>e[t])&&(e[t]=n)},So=(e,t,n)=>{(e[t]===void 0||n<e[t])&&(e[t]=n)},Co=(e,t)=>{xo(e,`minimum`,t),So(e,`maximum`,t)},wo=(e,t)=>{e.multipleOf??=[],e.multipleOf.includes(t)||e.multipleOf.push(t)},To=(e,t)=>{e.patterns??=new Set,e.patterns.add(t)},Eo=(e,t)=>{e.mime=e.mime?e.mime.filter(e=>t.includes(e)):[...t]},Do=(e,t)=>{e.format=t,t.includes(`int`)&&(e.isInt=!0)},Oo=(e,t)=>xo(e,`minimum`,t.minimum),ko=(e,t)=>So(e,`maximum`,t.maximum),Ao=e=>(t,n)=>{Do(t,n.format);let[r,i]=e[n.format];xo(t,`minimum`,r),So(t,`maximum`,i)},jo={greater_than:(e,t)=>xo(e,t.inclusive?`minimum`:`exclusiveMinimum`,t.value),less_than:(e,t)=>So(e,t.inclusive?`maximum`:`exclusiveMaximum`,t.value),multiple_of:(e,t)=>wo(e,t.value),number_format:Ao($e),bigint_format:Ao(et),min_length:Oo,max_length:ko,length_equals:(e,t)=>Co(e,t.length),min_size:Oo,max_size:ko,size_equals:(e,t)=>Co(e,t.size),string_format:(e,t)=>{Do(e,t.format),t.pattern&&To(e,t.pattern),(t.format===`base64`||t.format===`base64url`)&&(e.contentEncoding=t.format),(t.local||t.precision===-1)&&(e.laxFormat=!0)},mime_type:(e,t)=>Eo(e,t.mime)};function O(e){let t={},n=e._zod.def,r=e._zod.traits.has(`$ZodCheck`)?[e,...n.checks??[]]:n.checks??[];for(let e of r)jo[e._zod.def.check]?.(t,e._zod.def);let i=e._zod.bag;i.minimum!==void 0&&xo(t,`minimum`,i.minimum),i.exclusiveMinimum!==void 0&&xo(t,`exclusiveMinimum`,i.exclusiveMinimum),i.maximum!==void 0&&So(t,`maximum`,i.maximum),i.exclusiveMaximum!==void 0&&So(t,`exclusiveMaximum`,i.exclusiveMaximum),i.multipleOf!==void 0&&wo(t,i.multipleOf),i.format!==void 0&&(t.format??=i.format,i.format.includes(`int`)&&(t.isInt=!0)),i.mime&&Eo(t,i.mime);for(let e of i.patterns??[])To(t,e);return t}const Mo={guid:`uuid`,url:`uri`,datetime:`date-time`,json_string:`json-string`,regex:``},No=new Map([[Gr,Mn],[qr,Nn]]),Po=e=>No.get(e)??e,Fo=(e,t,n,r)=>{let i=n;i.type=`string`;let{minimum:a,maximum:o,format:s,patterns:c,contentEncoding:l,laxFormat:u}=O(e);if(typeof a==`number`&&(i.minLength=a),typeof o==`number`&&(i.maxLength=o),s&&(i.format=Mo[s]??s,i.format===``&&delete i.format,(s===`time`||u)&&delete i.format),l&&(i.contentEncoding=l),c&&c.size>0){let e=[...c].map(Po);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}))])}},Io=(e,t,n,r)=>{let i=n,{minimum:a,maximum:o,multipleOf:s,exclusiveMaximum:c,exclusiveMinimum:l,isInt:u}=O(e);i.type=u?`integer`:`number`;let d=typeof l==`number`&&l>=(a??-1/0),f=typeof c==`number`&&c<=(o??1/0),p=t.target===`draft-04`||t.target===`openapi-3.0`;if(d?p?(i.minimum=l,i.exclusiveMinimum=!0):i.exclusiveMinimum=l:typeof a==`number`&&(i.minimum=a),f?p?(i.maximum=c,i.exclusiveMaximum=!0):i.exclusiveMaximum=c:typeof o==`number`&&(i.maximum=o),s){let n=new Set;for(let a of s)Number.isFinite(a)&&a!==0?n.add(Math.abs(a)):co(e,t,i,r,`A multipleOf divisor of ${a} cannot be represented in JSON Schema`);let[a,...o]=n;a!==void 0&&(i.multipleOf=a),o.length&&(i.allOf=[...i.allOf??[],...o.map(e=>({multipleOf:e}))])}},Lo=(e,t,n,r)=>{n.type=`boolean`},Ro=(e,t,n,r)=>{n.not={}},zo=(e,t,n,r)=>{let i=e._zod.def,a=Ee(i.entries);if(a.length===0){n.not={};return}a.every(e=>typeof e==`number`)&&(n.type=`number`),a.every(e=>typeof e==`string`)&&(n.type=`string`),n.enum=a},Bo=(e,t,n,r)=>{co(e,t,n,r,`Custom types cannot be represented in JSON Schema`)},Vo=(e,t,n,r)=>{co(e,t,n,r,`Transforms cannot be represented in JSON Schema`)},Ho=(e,t,n,r)=>{let i=n,a=e._zod.def,{minimum:o,maximum:s}=O(e);typeof o==`number`&&(i.minItems=o),typeof s==`number`&&(i.maxItems=s),i.type=`array`,i.items=E(a.element,t,{...r,path:[...r.path,`items`]})};function Uo(e){let t=e._zod.def;return t.type===`pipe`&&t.in._zod.traits.has(`$ZodTransform`)?Uo(t.out):t.type===`catch`?Uo(t.innerType):e._zod.optin}const Wo=(e,t,n,r)=>{let i=n,a=e._zod.def,o=a.shape;if(Object.getOwnPropertySymbols(o).length&&co(e,t,i,r,`Symbol keys cannot be represented in JSON Schema`))return;i.type=`object`,i.properties={};for(let e in o)Pe(i.properties,e,E(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];return t.io===`input`?Uo(n)===void 0:n._zod.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=E(a.catchall,t,{...r,path:[...r.path,`additionalProperties`]})):t.io===`output`&&(i.additionalProperties=!1)},Go=(e,t,n,r)=>{let i=e._zod.def,a=i.inclusive===!1,o=i.options.map((e,n)=>E(e,t,{...r,path:[...r.path,a?`oneOf`:`anyOf`,n]}));a?n.oneOf=o:n.anyOf=o},Ko=(e,t,n,r)=>{let i=e._zod.def,a=E(i.left,t,{...r,path:[...r.path,`allOf`,0]}),o=E(i.right,t,{...r,path:[...r.path,`allOf`,1]}),s=e=>`allOf`in e&&Object.keys(e).length===1,c=[...s(a)?a.allOf:[a],...s(o)?o.allOf:[o]];n.allOf=c,t.intersections.push(c)};function qo(e,t,n){if(t.$ref){if(n.has(t))return t;n.add(t);let r=e.get(t)?.def;if(!r)return t;let i=qo(e,r,n);return i===r?t:i}for(let r of[`anyOf`,`oneOf`]){let i=t[r];if(!Array.isArray(i))continue;let a=i.map(t=>qo(e,t,n));a.some((e,t)=>e!==i[t])&&(t={...t,[r]:a})}let r=Array.isArray(t.type)?t.type:[t.type],i=!r.includes(`string`)&&r.some(e=>e===`number`||e===`integer`),a=t.enum??(t.const===void 0?void 0:[t.const]);if(!i&&!a?.some(e=>typeof e==`number`))return t;let{minimum:o,maximum:s,exclusiveMinimum:c,exclusiveMaximum:l,multipleOf:u,format:d,id:f,...p}=t;return p.enum?p.enum=p.enum.map(e=>typeof e==`number`?String(e):e):typeof p.const==`number`&&(p.const=String(p.const)),i?(p.type=`string`,a||(p.pattern=(r.includes(`number`)?Wn:Un).source),p):p}const Jo=new WeakMap;function Yo(e){let t=new Map;for(let n of e.seen.values())n.def&&!t.has(n.schema)&&t.set(n.schema,n);let n=new Map;for(let r of Jo.get(e)??[]){let i=e.seen.get(r),a=(i?.def??i?.schema)?.propertyNames;if(!a||a===!0||n.has(a))continue;let o=qo(t,a,new Set);o!==a&&n.set(a,o)}if(n.size)for(let t of e.seen.values())for(let e of[t.schema,t.def]){let t=e&&n.get(e.propertyNames);t&&(e.propertyNames=t)}}const Xo=(e,t,n,r)=>{let i=n,a=e._zod.def;i.type=`object`;let o=a.keyType,s=O(o).patterns;if(a.mode===`loose`&&s&&s.size>0){let e=E(a.valueType,t,{...r,path:[...r.path,`patternProperties`,`*`]});i.patternProperties={};for(let t of s)Pe(i.patternProperties,Po(t).source,e)}else{if(t.target===`draft-07`||t.target===`draft-2020-12`){i.propertyNames=E(a.keyType,t,{...r,path:[...r.path,`propertyNames`]});let n=Jo.get(t);n||(n=[],Jo.set(t,n),t.deferred.push(()=>Yo(t))),n.push(e)}i.additionalProperties=E(a.valueType,t,{...r,path:[...r.path,`additionalProperties`]})}let c=o._zod.values,l=t.io===`input`&&Uo(a.valueType)!==void 0;if(c&&!a.partial&&!l){let e=[...c].filter(e=>typeof e==`string`||typeof e==`number`);e.length>0&&(i.required=e.map(String))}},Zo=(e,t,n,r)=>{let i=e._zod.def,a=E(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`}]},Qo=(e,t,n,r)=>{let i=e._zod.def;E(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType},$o=Symbol();function es(e,t,n,r,i){let a=!1,o=JSON.stringify(e,(e,t)=>typeof t==`bigint`?(a=!0,null):t);return a?(co(t,n,r,i,`BigInt defaults cannot be represented in JSON Schema`),$o):JSON.parse(o)}const ts=(e,t,n,r)=>{let i=e._zod.def;E(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType;let o=es(i.defaultValue,e,t,n,r);o!==$o&&(n.default=o)},ns=(e,t,n,r)=>{let i=e._zod.def;E(i.innerType,t,r);let a=t.seen.get(e);if(a.ref=i.innerType,t.io!==`input`)return;let o=es(i.defaultValue,e,t,n,r);o!==$o&&(n._prefault=o)},rs=(e,t,n,r)=>{let i=e._zod.def;E(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType;let o;try{o=i.catchValue(void 0)}catch{co(e,t,n,r,`Dynamic catch values are not supported in JSON Schema`);return}n.default=o},is=(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;E(o,t,r);let s=t.seen.get(e);s.ref=o},as=(e,t,n,r)=>{let i=e._zod.def;E(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType,n.readOnly=!0},os=(e,t,n,r)=>{let i=e._zod.def;E(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType},ss=new WeakSet([Object.prototype,Error.prototype]);function cs(e,t,n){Object.defineProperty(e,t,{configurable:!0,enumerable:!1,get(){let e=n(this);return Object.defineProperty(this,t,{value:e,configurable:!0,writable:!0}),e},set(e){Object.defineProperty(this,t,{value:e,configurable:!0,writable:!0})}})}const k=b(`ZodError`,(e,t)=>{Gt.init(e,t),e.name=`ZodError`;let n=Object.getPrototypeOf(e);ss.has(n)||(ss.add(n),cs(n,`format`,e=>t=>Jt(e,t)),cs(n,`flatten`,e=>t=>qt(e,t)),cs(n,`addIssue`,e=>t=>{e.issues.push(t),e.message=JSON.stringify(e.issues,Oe,2)}),cs(n,`addIssues`,e=>t=>{e.issues.push(...t),e.message=JSON.stringify(e.issues,Oe,2)}),Object.defineProperty(n,"isEmpty",{configurable:!0,enumerable:!1,get(){return this.issues.length===0}}))},void 0,{Parent:Error}),ls=Zt(k),us=Qt(k),ds=$t(k),fs=tn(k),ps=cn(k),ms=ln(k),hs=un(k),gs=dn(k),_s=fn(k),vs=pn(k),ys=mn(k),bs=hn(k);function xs(){x.localeError||Rt($i())}function Ss(){x.memoizer||Rt({memoizer:Xi()})}const A=b(`ZodType`,(e,t)=>(xs(),w.init(e,t),e.def=t,e.type=t.type,e),{check(...e){let t=this.def;return this.clone(_(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 Xe(this,e,t)},brand(){return this},register(e,t){return e.add(this,t),this},refine(e,t){return this.check(Rc(e,t))},superRefine(e,t){return this.check(zc(e,t))},overwrite(e){return this.check(Xa(e))},optional(){return yc(this)},exactOptional(){return xc(this)},nullable(){return Cc(this)},nullish(){return yc(Cc(this))},nonoptional(e){return kc(this,e)},array(){return ac(this)},or(e){return lc([this,e])},and(e){return dc(this,e)},transform(e){return Nc(this,_c(e))},default(e){return Tc(this,e)},prefault(e){return Dc(this,e)},catch(e){return jc(this,e)},pipe(e){return Nc(this,e)},readonly(){return Ic(this)},describe(e){let t=this.clone();return ra.add(t,{description:e}),t},meta(...e){if(e.length===0)return ra.get(this);let t=this.clone();return ra.add(t,e[0]),t},isOptional(){return this.safeParse(void 0).success},isNullable(){return this.safeParse(null).success},apply(e,...t){return t.length===0?e(this):e(this,...t)},get"~standard"(){return Ct(this,`~standard`,{...hr(this),jsonSchema:{input:bo(this,`input`),output:bo(this,`output`)}})},set"~standard"(e){St(this,`~standard`,e)},parse:function e(t,n){return ls(this,t,n,{callee:e})},parseAsync:async function e(t,n){return await us(this,t,n,{callee:e})},safeParse(e,t){return ds(this,e,t)},async safeParseAsync(e,t){return fs(this,e,t)},get spa(){return this?.safeParseAsync},set spa(e){St(this,`spa`,e)},validate(e,t){return an(this,e,t)},validateAsync(e,t){return sn(this,e,t)},encode:function e(t,n){return ps(this,t,n,{callee:e})},decode:function e(t,n){return ms(this,t,n,{callee:e})},encodeAsync:async function e(t,n){return await hs(this,t,n,{callee:e})},decodeAsync:async function e(t,n){return await gs(this,t,n,{callee:e})},safeEncode(e,t){return _s(this,e,t)},safeDecode(e,t){return vs(this,e,t)},async safeEncodeAsync(e,t){return ys(this,e,t)},async safeDecodeAsync(e,t){return bs(this,e,t)},toJSONSchema(e){return yo(this,{})(e)},get description(){return ra.get(this)?.description},get _def(){return this._zod.def}}),Cs=b(`_ZodString`,(e,t)=>{gr.init(e,t),A.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Fo(e,t,n,r)},wt({format:e=>O(e).format??null,minLength:e=>O(e).minimum??null,maxLength:e=>O(e).maximum??null},{regex(...e){return this.check(Wa(...e))},includes(...e){return this.check(qa(...e))},startsWith(...e){return this.check(Ja(...e))},endsWith(...e){return this.check(Ya(...e))},min(...e){return this.check(Ha(...e))},max(...e){return this.check(Va(...e))},length(...e){return this.check(Ua(...e))},nonempty(...e){return this.check(Ha(1,...e))},lowercase(e){return this.check(Ga(e))},uppercase(e){return this.check(Ka(e))},trim(){return this.check(Qa())},normalize(...e){return this.check(Za(...e))},toLowerCase(){return this.check($a())},toUpperCase(){return this.check(eo())},slugify(){return this.check(to())}})),ws=b(`ZodString`,(e,t)=>{gr.init(e,t),Cs.init(e,t)},{email(e){return this.check(aa(ks,e))},url(e){return this.check(da(Ms,e))},jwt(e){return this.check(Ea(qs,e))},emoji(e){return this.check(fa(Ns,e))},guid(e){return this.check(oa(As,e))},uuid(e){return this.check(sa(js,e))},uuidv4(e){return this.check(ca(js,e))},uuidv6(e){return this.check(la(js,e))},uuidv7(e){return this.check(ua(js,e))},nanoid(e){return this.check(pa(Ps,e))},cuid(e){return this.check(ma(Fs,e))},cuid2(e){return this.check(ha(Is,e))},ulid(e){return this.check(ga(Ls,e))},base64(e){return this.check(Ca(Ws,e))},base64url(e){return this.check(wa(Gs,e))},xid(e){return this.check(_a(Rs,e))},ksuid(e){return this.check(va(zs,e))},ipv4(e){return this.check(ya(Bs,e))},ipv6(e){return this.check(ba(Vs,e))},cidrv4(e){return this.check(xa(Hs,e))},cidrv6(e){return this.check(Sa(Us,e))},e164(e){return this.check(Ta(Ks,e))},datetime(e){return this.check(Da(Ts,e))},date(e){return this.check(Oa(Es,e))},time(e){return this.check(ka(Ds,e))},duration(e){return this.check(Aa(Os,e))}});function j(e){return ia(ws,e)}const M=b(`ZodStringFormat`,(e,t)=>{T.init(e,t),Cs.init(e,t)}),Ts=b(`ZodISODateTime`,(e,t)=>{Nr.init(e,t),M.init(e,t)}),Es=b(`ZodISODate`,(e,t)=>{Pr.init(e,t),M.init(e,t)}),Ds=b(`ZodISOTime`,(e,t)=>{Fr.init(e,t),M.init(e,t)}),Os=b(`ZodISODuration`,(e,t)=>{Ir.init(e,t),M.init(e,t)}),ks=b(`ZodEmail`,(e,t)=>{yr.init(e,t),M.init(e,t)}),As=b(`ZodGUID`,(e,t)=>{_r.init(e,t),M.init(e,t)}),js=b(`ZodUUID`,(e,t)=>{vr.init(e,t),M.init(e,t)}),Ms=b(`ZodURL`,(e,t)=>{Tr.init(e,t),M.init(e,t)}),Ns=b(`ZodEmoji`,(e,t)=>{Er.init(e,t),M.init(e,t)}),Ps=b(`ZodNanoID`,(e,t)=>{Dr.init(e,t),M.init(e,t)}),Fs=b(`ZodCUID`,(e,t)=>{Or.init(e,t),M.init(e,t)}),Is=b(`ZodCUID2`,(e,t)=>{kr.init(e,t),M.init(e,t)}),Ls=b(`ZodULID`,(e,t)=>{Ar.init(e,t),M.init(e,t)}),Rs=b(`ZodXID`,(e,t)=>{jr.init(e,t),M.init(e,t)}),zs=b(`ZodKSUID`,(e,t)=>{Mr.init(e,t),M.init(e,t)}),Bs=b(`ZodIPv4`,(e,t)=>{Lr.init(e,t),M.init(e,t)}),Vs=b(`ZodIPv6`,(e,t)=>{Br.init(e,t),M.init(e,t)}),Hs=b(`ZodCIDRv4`,(e,t)=>{Vr.init(e,t),M.init(e,t)}),Us=b(`ZodCIDRv6`,(e,t)=>{Ur.init(e,t),M.init(e,t)}),Ws=b(`ZodBase64`,(e,t)=>{Kr.init(e,t),M.init(e,t)}),Gs=b(`ZodBase64URL`,(e,t)=>{Yr.init(e,t),M.init(e,t)}),Ks=b(`ZodE164`,(e,t)=>{Xr.init(e,t),M.init(e,t)}),qs=b(`ZodJWT`,(e,t)=>{Qr.init(e,t),M.init(e,t)}),Js=b(`ZodNumber`,(e,t)=>{$r.init(e,t),A.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Io(e,t,n,r),e.isFinite=!0},wt({minValue:e=>{let{minimum:t,exclusiveMinimum:n}=O(e);return Math.max(t??-1/0,n??-1/0)},maxValue:e=>{let{maximum:t,exclusiveMaximum:n}=O(e);return Math.min(t??1/0,n??1/0)},isInt:e=>{let{isInt:t,multipleOf:n}=O(e);return!!t||!!n?.some(Number.isSafeInteger)},format:e=>O(e).format??null},{gt(e,t){return this.check(Ra(e,t))},gte(e,t){return this.check(za(e,t))},min(e,t){return this.check(za(e,t))},lt(e,t){return this.check(Ia(e,t))},lte(e,t){return this.check(La(e,t))},max(e,t){return this.check(La(e,t))},int(e){return this.check(Zs(e))},safe(e){return this.check(Zs(e))},positive(e){return this.check(Ra(0,e))},nonnegative(e){return this.check(za(0,e))},negative(e){return this.check(Ia(0,e))},nonpositive(e){return this.check(La(0,e))},multipleOf(e,t){return this.check(Ba(e,t))},step(e,t){return this.check(Ba(e,t))},finite(){return this}}));function Ys(e){return ja(Js,e)}const Xs=b(`ZodNumberFormat`,(e,t)=>{ei.init(e,t),Js.init(e,t)});function Zs(e){return Ma(Xs,e)}const Qs=b(`ZodBoolean`,(e,t)=>{ti.init(e,t),A.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Lo(e,t,n,r)});function $s(e){return Na(Qs,e)}const ec=b(`ZodUnknown`,(e,t)=>{ni.init(e,t),A.init(e,t),e._zod.processJSONSchema=(e,t,n)=>void 0});function tc(){return Pa(ec)}const nc=b(`ZodNever`,(e,t)=>{ri.init(e,t),A.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ro(e,t,n,r)});function rc(e){return Fa(nc,e)}const ic=b(`ZodArray`,(e,t)=>{Ss(),ai.init(e,t),A.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ho(e,t,n,r),e.element=t.element},{min(e,t){return this.check(Ha(e,t))},nonempty(e){return this.check(Ha(1,e))},max(e,t){return this.check(Va(e,t))},length(e,t){return this.check(Ua(e,t))},unwrap(){return this.element}});function ac(e,t){return no(ic,e,t)}const oc=b(`ZodObject`,(e,t)=>{Ss(),di.init(e,t),A.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Wo(e,t,n,r),At(e,`shape`,e=>e._zod.def.shape,!1)},{keyof(){return hc(Object.keys(this._zod.def.shape))},catchall(e){return this.clone(_(this._zod.def,{catchall:e}))},passthrough(){return this.clone(_(this._zod.def,{catchall:tc()}))},loose(){return this.clone(_(this._zod.def,{catchall:tc()}))},strict(){return this.clone(_(this._zod.def,{catchall:rc()}))},strip(){return this.clone(_(this._zod.def,{catchall:void 0}))},extend(e){return it(this,e)},safeExtend(e){return ot(this,e)},merge(e){return st(this,e)},pick(e){return tt(this,e)},omit(e){return rt(this,e)},partial(...e){return ct(vc,this,e[0])},exactPartial(...e){return ct(bc,this,e[0],`exactPartial`)},required(...e){return lt(Oc,this,e[0])}});function N(e,t){return new oc({type:`object`,shape:e,catchall:rc(),...v(t)})}function sc(e,t){return new oc({type:`object`,shape:e,catchall:tc(),...v(t)})}const cc=b(`ZodUnion`,(e,t)=>{pi.init(e,t),A.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Go(e,t,n,r),e.options=t.options});function lc(e,t){return new cc({type:`union`,options:e,...v(t)})}const uc=b(`ZodIntersection`,(e,t)=>{mi.init(e,t),A.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ko(e,t,n,r)});function dc(e,t){return new uc({type:`intersection`,left:e,right:t})}const fc=b(`ZodRecord`,(e,t)=>{Ss(),_i.init(e,t),A.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Xo(e,t,n,r),e.keyType=t.keyType,e.valueType=t.valueType});function pc(e,t,n){return!t||!t._zod?new fc({type:`record`,keyType:j(),valueType:e,...v(t)}):new fc({type:`record`,keyType:e,valueType:t,...v(n)})}const mc=b(`ZodEnum`,(e,t)=>{vi.init(e,t),A.init(e,t),e._zod.processJSONSchema=(t,n,r)=>zo(e,t,n,r),e.enum=t.entries,e.options=[...e._zod.values];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 mc({...t,checks:[],...v(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 mc({...t,checks:[],...v(r),entries:i})}});function hc(e,t){let n=Array.isArray(e)?Object.fromEntries(e.map(e=>[e,e])):e;return new mc({type:`enum`,entries:n,...v(t)})}const gc=b(`ZodTransform`,(e,t)=>{Ss(),yi.init(e,t),A.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Vo(e,t,n,r),e._zod.parse=(n,r)=>{if(r.direction===`backward`)throw new Lt(e.constructor.name);n.addIssue=r=>{if(typeof r==`string`)n.issues.push(bt(r,n.value,t));else{let t=r;t.fatal&&(t.continue=!1),t.code??=`custom`,`input`in t||(t.input=n.value),t.inst??=e,n.issues.push(bt(t))}};let i=t.transform(n.value,n);return i instanceof Promise?i.then(e=>(n.value=e,n)):(n.value=i,n)}});function _c(e){return new gc({type:`transform`,transform:e})}const vc=b(`ZodOptional`,(e,t)=>{xi.init(e,t),A.init(e,t),e._zod.processJSONSchema=(t,n,r)=>os(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function yc(e){return new vc({type:`optional`,innerType:e})}const bc=b(`ZodExactOptional`,(e,t)=>{Si.init(e,t),A.init(e,t),e._zod.processJSONSchema=(t,n,r)=>os(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function xc(e){return new bc({type:`optional`,innerType:e})}const Sc=b(`ZodNullable`,(e,t)=>{Ci.init(e,t),A.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Zo(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Cc(e){return new Sc({type:`nullable`,innerType:e})}const wc=b(`ZodDefault`,(e,t)=>{wi.init(e,t),A.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ts(e,t,n,r),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap});function Tc(e,t){return new wc({type:`default`,innerType:e,get defaultValue(){return typeof t==`function`?t():qe(t)}})}const Ec=b(`ZodPrefault`,(e,t)=>{Ei.init(e,t),A.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ns(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Dc(e,t){return new Ec({type:`prefault`,innerType:e,get defaultValue(){return typeof t==`function`?t():qe(t)}})}const Oc=b(`ZodNonOptional`,(e,t)=>{Di.init(e,t),A.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Qo(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function kc(e,t){return new Oc({type:`nonoptional`,innerType:e,...v(t)})}const Ac=b(`ZodCatch`,(e,t)=>{Ai.init(e,t),A.init(e,t),e._zod.processJSONSchema=(t,n,r)=>rs(e,t,n,r),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap});function jc(e,t){return new Ac({type:`catch`,innerType:e,catchValue:typeof t==`function`?t:jt(t)})}const Mc=b(`ZodPipe`,(e,t)=>{ji.init(e,t),A.init(e,t),e._zod.processJSONSchema=(t,n,r)=>is(e,t,n,r),e.in=t.in,e.out=t.out});function Nc(e,t){return new Mc({type:`pipe`,in:e,out:t})}const Pc=b(`ZodPreprocess`,(e,t)=>{Mc.init(e,t),Ni.init(e,t)}),Fc=b(`ZodReadonly`,(e,t)=>{Pi.init(e,t),A.init(e,t),e._zod.processJSONSchema=(t,n,r)=>as(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Ic(e){return new Fc({type:`readonly`,innerType:e})}const Lc=b(`ZodCustom`,(e,t)=>{Ii.init(e,t),A.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Bo(e,t,n,r)});function Rc(e,t={}){return ro(Lc,e,t)}function zc(e,t){return io(e,t)}function Bc(e,t){return new Pc({type:`pipe`,in:_c(e),out:t})}function Vc(e){return Da(Ts,e)}const Hc=[`blobless`,`full`],Uc=[`ssh`,`https`],Wc=/^(?!\.{1,2}$)[^/\\%:]+$/u,Gc=/^[a-z0-9][a-z0-9.-]*(?:_[1-9]\d{0,4})?$/u,Kc=/^(?<amount>[1-9]\d{0,3})(?<unit>[mhd])$/u,qc={d:864e5,h:36e5,m:6e4},Jc=e=>e!==``&&/^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/u.test(e),Yc=e=>{if(e===void 0)return!0;let t=Number(e);return t>=1&&t<=65535},Xc=e=>{let[t=``,n]=e.split(`_`);return Yc(n)?t.split(`.`).every(e=>Jc(e)):!1},Zc=e=>e.length>0&&e.isWellFormed(),Qc=j().refine(Zc,`must be non-empty text that survives being written to the config`),$c=Qc.refine(Te,`must be a name git accepts for a branch (git check-ref-format --branch)`),el=e=>{let[t,...n]=e.split(`/`);return t===void 0||n.length<2||!Gc.test(t)||!Xc(t)?!1:n.every(e=>Wc.test(e))},tl=e=>Wc.test(e),nl=j().refine(e=>Zc(e)&&el(e),`ref key must be host/path…/repo with safe, non-empty segments`).brand(),rl=j().regex(Kc,`duration must be <n>m, <n>h, or <n>d`).brand(),il=e=>{let t=Kc.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)*qc[r]},al=hc(Hc),ol=hc(Uc),sl=Qc.refine(e=>e.includes(`{version}`),`tag format must contain {version}`),cl=Qc.refine(e=>{if(e===`.`)return!0;let t=e.split(`/`);return t.length>0&&t.every(e=>Wc.test(e)&&e!==`.`)},`package path must be "." or a normalized relative path without traversal`),ll=new Set([`__proto__`,`constructor`,`prototype`]),ul=(e,t,n)=>Bc((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),dl=e=>Zc(e)&&!ll.has(e),fl=e=>ul(dl,()=>`package key must be non-empty, storable text, and not "__proto__", "constructor", or "prototype"`,pc(j().min(1),e)),pl=e=>dl(e),ml={clone_mode:`blobless`,git_transport:`https`,sync_ttl:`1h`},hl=N({clone_mode:al.default(ml.clone_mode),git_transport:ol.default(ml.git_transport),sync_ttl:rl.default(rl.parse(ml.sync_ttl))}),gl=N((e=>Object.fromEntries(Object.entries(e).map(([e,t])=>[e,t.removeDefault().optional()])))(hl.shape)),_l=N({name:Qc,path:cl}),vl=N({description:Qc,path:cl,tag_format:sl.optional()}),yl=N({declined_packages:ac(_l).optional(),default_branch:Qc,description:Qc,packages:fl(vl).optional(),tag_format:sl.optional(),url:Qc,...gl.shape}),bl=sc({cli_version:Qc,schema_version:Ys().int().positive()}),xl=ul(e=>nl.safeParse(e).success,()=>`ref key must be host/path…/repo with safe, non-empty segments`,pc(j(),yl)),Sl=N({check:$s().default(!0),notify:$s().default(!0)}),Cl=N({meta:bl,refs:xl.default({}),settings:hl,updates:Sl.optional()});
|
|
113
|
+
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);else{if(e.external){let r=e.external.registry.get(n[0])?.id;if(t!==n[0]&&r){a(n);continue}}(e.metadataRegistry.get(n[0])?.id||r.cycle||r.count>1&&e.reused===`ref`)&&a(n)}}e.external&&(e.sharedDefsExtractedFor=e.external)}function vo(e){let t=e.anyOf;if(!Array.isArray(t)||t.length===0||e.type!==void 0)return;let n=[];for(let e of t){if(!e||typeof e!=`object`)return;vo(e);let t=Object.keys(e);if(t.length!==1||t[0]!==`type`)return;let r=e.type;for(let e of Array.isArray(r)?r:[r]){if(typeof e!=`string`)return;n.includes(e)||n.push(e)}}delete e.anyOf,e.type=n.length===1?n[0]:n}const yo=/* @__PURE__ */ new Set([`type`,`properties`,`required`,`additionalProperties`]),bo=[`oneOf`,`anyOf`];function xo(e){let t=e.additionalProperties;return t===void 0||t===!1||typeof t!=`object`||!t?null:Object.keys(t).length?t:null}function So(e){let t=[];for(let n of e){if(typeof n!=`object`||n.type!==`object`)return null;for(let e in n)if(!yo.has(e))return null;t.push(n)}let n={},r=/* @__PURE__ */ new Set;for(let e of t){for(let r in e.properties){if(Object.prototype.hasOwnProperty.call(n,r))continue;let e=[];for(let n of t){let t=n.properties?.[r]??xo(n);t!=null&&(e.some(e=>JSON.stringify(e)===JSON.stringify(t))||e.push(t))}Pe(n,r,e.length===1?e[0]:So(e)??{allOf:e})}for(let t of e.required??[])r.add(t)}let i={type:`object`,properties:n};if(r.size&&(i.required=[...r]),t.every(e=>e.additionalProperties===!1))i.additionalProperties=!1;else{let e=[];for(let n of t){let t=xo(n);t&&!e.some(e=>JSON.stringify(e)===JSON.stringify(t))&&e.push(t)}e.length===1?i.additionalProperties=e[0]:e.length>1&&(i.additionalProperties={allOf:e})}return i}function Co(e){let t=e.allOf;if(!Array.isArray(t)||t.length<2)return;for(let t of yo)if(t in e)return;let n=t.filter(e=>bo.some(t=>Array.isArray(e[t]))),r=null;if(!n.length)r=So(t);else{let e=n[0],i=bo.find(t=>Array.isArray(e[t]));if(Object.keys(e).length!==1)return;let a=t.filter(t=>t!==e),o=e[i].map(e=>So([...a,e]));if(o.some(e=>!e))return;r={[i]:o}}r&&(delete e.allOf,po(e,r))}function wo(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)):po(i,s),po(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??[]})};if(!e.external||e.sharedEmitDoneFor!==e.external){for(let t of[...e.seen.entries()].reverse())r(t[0]);if(e.target!==`openapi-3.0`)for(let t of e.seen.entries())vo(t[1].def??t[1].schema);for(let t of e.deferred)t();if(e.intersections.length){let t=/* @__PURE__ */ new Map;for(let n of e.seen.values())for(let e of[n.schema,n.def]){let n=e?.allOf;if(!Array.isArray(n))continue;let r=t.get(n);r?r.push(e):t.set(n,[e])}for(let n of e.intersections)for(let e of t.get(n)??[])Co(e)}}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)}po(i,n.defId?n.schema: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??{};if(!e.external||e.sharedEmitDoneFor!==e.external)for(let t of e.seen.entries()){let e=t[1];e.def&&e.defId&&(e.def.id===e.defId&&delete e.def.id,Pe(o,e.defId,e.def))}e.external&&(e.sharedEmitDoneFor=e.external),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:Eo(t,`input`,e.processors),output:Eo(t,`output`,e.processors)}},enumerable:!1,writable:!1}),n}catch{throw Error(`Error converting schema to JSON.`)}}function D(e,t){let n=t??{seen:/* @__PURE__ */ 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 D(r.element,n);if(r.type===`set`)return D(r.valueType,n);if(r.type===`lazy`)return D(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`||r.type===`catch`)return D(r.innerType,n);if(r.type===`intersection`)return D(r.left,n)||D(r.right,n);if(r.type===`record`||r.type===`map`)return D(r.keyType,n)||D(r.valueType,n);if(r.type===`pipe`)return e._zod.traits.has(`$ZodCodec`)?!0:D(r.in,n)||D(r.out,n);if(r.type===`object`){for(let e in r.shape)if(D(r.shape[e],n))return!0;return!1}if(r.type===`union`){for(let e of r.options)if(D(e,n))return!0;return!1}if(r.type===`tuple`){for(let e of r.items)if(D(e,n))return!0;return!!(r.rest&&D(r.rest,n))}return!1}const To=(e,t={})=>n=>{let r=mo({...n,processors:t});return E(e,r),_o(r,e),wo(r,e)},Eo=(e,t,n={})=>r=>{let{libraryOptions:i,target:a}=r??{},o=mo({...i??{},target:a,io:t,processors:n});return E(e,o),_o(o,e),wo(o,e)},Do=(e,t,n)=>{(e[t]===void 0||n>e[t])&&(e[t]=n)},Oo=(e,t,n)=>{(e[t]===void 0||n<e[t])&&(e[t]=n)},ko=(e,t)=>{Do(e,`minimum`,t),Oo(e,`maximum`,t)},Ao=(e,t)=>{e.multipleOf??=[],e.multipleOf.includes(t)||e.multipleOf.push(t)},jo=(e,t)=>{e.patterns??=/* @__PURE__ */ new Set,e.patterns.add(t)},Mo=(e,t)=>{e.mime=e.mime?e.mime.filter(e=>t.includes(e)):[...t]},No=(e,t)=>{e.format=t,t.includes(`int`)&&(e.isInt=!0)},Po=(e,t)=>Do(e,`minimum`,t.minimum),Fo=(e,t)=>Oo(e,`maximum`,t.maximum),Io=e=>(t,n)=>{No(t,n.format);let[r,i]=e[n.format];Do(t,`minimum`,r),Oo(t,`maximum`,i)},Lo={greater_than:(e,t)=>Do(e,t.inclusive?`minimum`:`exclusiveMinimum`,t.value),less_than:(e,t)=>Oo(e,t.inclusive?`maximum`:`exclusiveMaximum`,t.value),multiple_of:(e,t)=>Ao(e,t.value),number_format:Io($e),bigint_format:Io(et),min_length:Po,max_length:Fo,length_equals:(e,t)=>ko(e,t.length),min_size:Po,max_size:Fo,size_equals:(e,t)=>ko(e,t.size),string_format:(e,t)=>{No(e,t.format),t.pattern&&jo(e,t.pattern),(t.format===`base64`||t.format===`base64url`)&&(e.contentEncoding=t.format),(t.local||t.precision===-1)&&(e.laxFormat=!0)},mime_type:(e,t)=>Mo(e,t.mime)};function O(e){let t={},n=e._zod.def,r=e._zod.traits.has(`$ZodCheck`)?[e,...n.checks??[]]:n.checks??[];for(let e of r)Lo[e._zod.def.check]?.(t,e._zod.def);let i=e._zod.bag;i.minimum!==void 0&&Do(t,`minimum`,i.minimum),i.exclusiveMinimum!==void 0&&Do(t,`exclusiveMinimum`,i.exclusiveMinimum),i.maximum!==void 0&&Oo(t,`maximum`,i.maximum),i.exclusiveMaximum!==void 0&&Oo(t,`exclusiveMaximum`,i.exclusiveMaximum),i.multipleOf!==void 0&&Ao(t,i.multipleOf),i.format!==void 0&&(t.format??=i.format,i.format.includes(`int`)&&(t.isInt=!0)),i.mime&&Mo(t,i.mime);for(let e of i.patterns??[])jo(t,e);return t}const Ro={guid:`uuid`,url:`uri`,datetime:`date-time`,json_string:`json-string`,regex:``},zo=/* @__PURE__ */ new Map([[Jr,Nn],[Xr,Pn]]),Bo=e=>zo.get(e)??e,Vo=(e,t,n,r)=>{let i=n;i.type=`string`;let{minimum:a,maximum:o,format:s,patterns:c,contentEncoding:l,laxFormat:u}=O(e);if(typeof a==`number`&&(i.minLength=a),typeof o==`number`&&(i.maxLength=o),s&&(i.format=Ro[s]??s,i.format===``&&delete i.format,(s===`time`||u)&&delete i.format),l&&(i.contentEncoding=l),c&&c.size>0){let e=[...c].map(Bo);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}))])}},Ho=(e,t,n,r)=>{let i=n,{minimum:a,maximum:o,multipleOf:s,exclusiveMaximum:c,exclusiveMinimum:l,isInt:u}=O(e);i.type=u?`integer`:`number`;let d=typeof l==`number`&&l>=(a??-1/0),f=typeof c==`number`&&c<=(o??1/0),p=t.target===`draft-04`||t.target===`openapi-3.0`;if(d?p?(i.minimum=l,i.exclusiveMinimum=!0):i.exclusiveMinimum=l:typeof a==`number`&&(i.minimum=a),f?p?(i.maximum=c,i.exclusiveMaximum=!0):i.exclusiveMaximum=c:typeof o==`number`&&(i.maximum=o),s){let n=/* @__PURE__ */ new Set;for(let a of s)Number.isFinite(a)&&a!==0?n.add(Math.abs(a)):ho(e,t,i,r,`A multipleOf divisor of ${a} cannot be represented in JSON Schema`);let[a,...o]=n;a!==void 0&&(i.multipleOf=a),o.length&&(i.allOf=[...i.allOf??[],...o.map(e=>({multipleOf:e}))])}},Uo=(e,t,n,r)=>{n.type=`boolean`},Wo=(e,t,n,r)=>{n.not={}},Go=(e,t,n,r)=>{let i=e._zod.def,a=Ee(i.entries);a.length===0?n.not={}:(a.every(e=>typeof e==`number`)&&(n.type=`number`),a.every(e=>typeof e==`string`)&&(n.type=`string`),n.enum=a)},Ko=(e,t,n,r)=>{ho(e,t,n,r,`Custom types cannot be represented in JSON Schema`)},qo=(e,t,n,r)=>{ho(e,t,n,r,`Transforms cannot be represented in JSON Schema`)},Jo=(e,t,n,r)=>{let i=n,a=e._zod.def,{minimum:o,maximum:s}=O(e);typeof o==`number`&&(i.minItems=o),typeof s==`number`&&(i.maxItems=s),i.type=`array`,i.items=E(a.element,t,{...r,path:[...r.path,`items`]})};function Yo(e){let t=e._zod.def;return t.type===`pipe`&&t.in._zod.traits.has(`$ZodTransform`)?Yo(t.out):t.type===`catch`?Yo(t.innerType):e._zod.optin}const Xo=(e,t,n,r)=>{let i=n,a=e._zod.def,o=a.shape;if(Object.getOwnPropertySymbols(o).length&&ho(e,t,i,r,`Symbol keys cannot be represented in JSON Schema`))return;i.type=`object`,i.properties={};for(let e in o)Pe(i.properties,e,E(o[e],t,{...r,path:[...r.path,`properties`,e]}));let s=[];for(let e of Object.keys(o)){let n=a.shape[e];(t.io===`input`?Yo(n)===void 0:n._zod.optout===void 0)&&s.push(e)}s.length>0&&(i.required=s),a.catchall?._zod.def.type===`never`?i.additionalProperties=!1:a.catchall?a.catchall&&(i.additionalProperties=E(a.catchall,t,{...r,path:[...r.path,`additionalProperties`]})):t.io===`output`&&(i.additionalProperties=!1)},Zo=(e,t,n,r)=>{let i=e._zod.def,a=i.inclusive===!1,o=i.options.map((e,n)=>E(e,t,{...r,path:[...r.path,a?`oneOf`:`anyOf`,n]}));a?n.oneOf=o:n.anyOf=o},Qo=(e,t,n,r)=>{let i=e._zod.def,a=E(i.left,t,{...r,path:[...r.path,`allOf`,0]}),o=E(i.right,t,{...r,path:[...r.path,`allOf`,1]}),s=e=>`allOf`in e&&Object.keys(e).length===1,c=[...s(a)?a.allOf:[a],...s(o)?o.allOf:[o]];n.allOf=c,t.intersections.push(c)};function $o(e,t,n){if(t.$ref){if(n.has(t))return t;n.add(t);let r=e.get(t)?.def;if(!r)return t;let i=$o(e,r,n);return i===r?t:i}for(let r of[`anyOf`,`oneOf`]){let i=t[r];if(!Array.isArray(i))continue;let a=i.map(t=>$o(e,t,n));a.some((e,t)=>e!==i[t])&&(t={...t,[r]:a})}let r=Array.isArray(t.type)?t.type:[t.type],i=!r.includes(`string`)&&r.some(e=>e===`number`||e===`integer`),a=t.enum??(t.const===void 0?void 0:[t.const]);if(!i&&!a?.some(e=>typeof e==`number`))return t;let{minimum:o,maximum:s,exclusiveMinimum:c,exclusiveMaximum:l,multipleOf:u,format:d,id:f,...p}=t;return p.enum?p.enum=p.enum.map(e=>typeof e==`number`?String(e):e):typeof p.const==`number`&&(p.const=String(p.const)),i&&(p.type=`string`,a||(p.pattern=(r.includes(`number`)?Gn:Wn).source)),p}const es=/* @__PURE__ */ new WeakMap;function ts(e){let t=/* @__PURE__ */ new Map;for(let n of e.seen.values())n.def&&!t.has(n.schema)&&t.set(n.schema,n);let n=/* @__PURE__ */ new Map;for(let r of es.get(e)??[]){let i=e.seen.get(r),a=(i?.def??i?.schema)?.propertyNames;if(!a||a===!0||n.has(a))continue;let o=$o(t,a,/* @__PURE__ */ new Set);o!==a&&n.set(a,o)}if(n.size)for(let t of e.seen.values())for(let e of[t.schema,t.def]){let t=e&&n.get(e.propertyNames);t&&(e.propertyNames=t)}}const ns=(e,t,n,r)=>{let i=n,a=e._zod.def;i.type=`object`;let o=a.keyType,s=O(o).patterns;if(a.mode===`loose`&&s&&s.size>0){let e=E(a.valueType,t,{...r,path:[...r.path,`patternProperties`,`*`]});i.patternProperties={};for(let t of s)Pe(i.patternProperties,Bo(t).source,e)}else{if(t.target===`draft-07`||t.target===`draft-2020-12`){i.propertyNames=E(a.keyType,t,{...r,path:[...r.path,`propertyNames`]});let n=es.get(t);n||(n=[],es.set(t,n),t.deferred.push(()=>ts(t))),n.push(e)}i.additionalProperties=E(a.valueType,t,{...r,path:[...r.path,`additionalProperties`]})}let c=o._zod.values,l=t.io===`input`&&Yo(a.valueType)!==void 0;if(c&&!a.partial&&!l){let e=[...c].filter(e=>typeof e==`string`||typeof e==`number`);e.length>0&&(i.required=e.map(String))}},rs=(e,t,n,r)=>{let i=e._zod.def,a=E(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`}]},is=(e,t,n,r)=>{let i=e._zod.def;E(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType},as=Symbol();function os(e,t,n,r,i){let a=!1,o=JSON.stringify(e,(e,t)=>typeof t==`bigint`?(a=!0,null):t);return a?(ho(t,n,r,i,`BigInt defaults cannot be represented in JSON Schema`),as):JSON.parse(o)}const ss=(e,t,n,r)=>{let i=e._zod.def;E(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType;let o=os(i.defaultValue,e,t,n,r);o!==as&&(n.default=o)},cs=(e,t,n,r)=>{let i=e._zod.def;E(i.innerType,t,r);let a=t.seen.get(e);if(a.ref=i.innerType,t.io!==`input`)return;let o=os(i.defaultValue,e,t,n,r);o!==as&&(n._prefault=o)},ls=(e,t,n,r)=>{let i=e._zod.def;E(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType;let o;try{o=i.catchValue(void 0)}catch{ho(e,t,n,r,`Dynamic catch values are not supported in JSON Schema`);return}n.default=o},us=(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;E(o,t,r);let s=t.seen.get(e);s.ref=o},ds=(e,t,n,r)=>{let i=e._zod.def;E(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType,n.readOnly=!0},fs=(e,t,n,r)=>{let i=e._zod.def;E(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType},ps=/* @__PURE__ */ new WeakSet([Object.prototype,Error.prototype]);function ms(e,t,n){Object.defineProperty(e,t,{configurable:!0,enumerable:!1,get(){let e=n(this);return Object.defineProperty(this,t,{value:e,configurable:!0,writable:!0}),e},set(e){Object.defineProperty(this,t,{value:e,configurable:!0,writable:!0})}})}const k=/*@__PURE__*/ b(`ZodError`,(e,t)=>{Kt.init(e,t),e.name=`ZodError`;let n=Object.getPrototypeOf(e);ps.has(n)||(ps.add(n),ms(n,`format`,e=>t=>Yt(e,t)),ms(n,`flatten`,e=>t=>Jt(e,t)),ms(n,`addIssue`,e=>t=>{e.issues.push(t),e.message=JSON.stringify(e.issues,Oe,2)}),ms(n,`addIssues`,e=>t=>{e.issues.push(...t),e.message=JSON.stringify(e.issues,Oe,2)}),Object.defineProperty(n,"isEmpty",{configurable:!0,enumerable:!1,get(){return this.issues.length===0}}))},void 0,{Parent:Error}),hs=/* @__PURE__ */ Qt(k),gs=/* @__PURE__ */ $t(k),_s=/* @__PURE__ */ en(k),vs=/* @__PURE__ */ nn(k),ys=/* @__PURE__ */ ln(k),bs=/* @__PURE__ */ un(k),xs=/* @__PURE__ */ dn(k),Ss=/* @__PURE__ */ fn(k),Cs=/* @__PURE__ */ pn(k),ws=/* @__PURE__ */ mn(k),Ts=/* @__PURE__ */ hn(k),Es=/* @__PURE__ */ gn(k);function Ds(){x.localeError||zt(ia())}function Os(){x.memoizer||zt({memoizer:ta()})}const A=/*@__PURE__*/ b(`ZodType`,(e,t)=>(Ds(),w.init(e,t),e.def=t,e.type=t.type,e),{check(...e){let t=this.def;return this.clone(_(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 Xe(this,e,t)},brand(){return this},register(e,t){return e.add(this,t),this},refine(e,t){return this.check(Wc(e,t))},superRefine(e,t){return this.check(Gc(e,t))},overwrite(e){return this.check(/* @__PURE__ */ no(e))},optional(){return Tc(this)},exactOptional(){return Dc(this)},nullable(){return kc(this)},nullish(){return Tc(kc(this))},nonoptional(e){return Fc(this,e)},array(){return dc(this)},or(e){return hc([this,e])},and(e){return _c(this,e)},transform(e){return zc(this,Cc(e))},default(e){return jc(this,e)},prefault(e){return Nc(this,e)},catch(e){return Lc(this,e)},pipe(e){return zc(this,e)},readonly(){return Hc(this)},describe(e){let t=this.clone();return ca.add(t,{description:e}),t},meta(...e){if(e.length===0)return ca.get(this);let t=this.clone();return ca.add(t,e[0]),t},isOptional(){return this.safeParse(void 0).success},isNullable(){return this.safeParse(null).success},apply(e,...t){return t.length===0?e(this):e(this,...t)},get"~standard"(){return wt(this,`~standard`,{...gr(this),jsonSchema:{input:Eo(this,`input`),output:Eo(this,`output`)}})},set"~standard"(e){Ct(this,`~standard`,e)},parse:function e(t,n){return hs(this,t,n,{callee:e})},parseAsync:async function e(t,n){return await gs(this,t,n,{callee:e})},safeParse(e,t){return _s(this,e,t)},async safeParseAsync(e,t){return vs(this,e,t)},get spa(){return this?.safeParseAsync},set spa(e){Ct(this,`spa`,e)},validate(e,t){return on(this,e,t)},validateAsync(e,t){return cn(this,e,t)},encode:function e(t,n){return ys(this,t,n,{callee:e})},decode:function e(t,n){return bs(this,t,n,{callee:e})},encodeAsync:async function e(t,n){return await xs(this,t,n,{callee:e})},decodeAsync:async function e(t,n){return await Ss(this,t,n,{callee:e})},safeEncode(e,t){return Cs(this,e,t)},safeDecode(e,t){return ws(this,e,t)},async safeEncodeAsync(e,t){return Ts(this,e,t)},async safeDecodeAsync(e,t){return Es(this,e,t)},toJSONSchema(e){return To(this,{})(e)},get description(){return ca.get(this)?.description},get _def(){return this._zod.def}}),ks=/*@__PURE__*/ b(`_ZodString`,(e,t)=>{_r.init(e,t),A.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Vo(e,t,n,r)},/*@__PURE__*/ Tt({format:e=>O(e).format??null,minLength:e=>O(e).minimum??null,maxLength:e=>O(e).maximum??null},{regex(...e){return this.check(/* @__PURE__ */ Xa(...e))},includes(...e){return this.check(/* @__PURE__ */ $a(...e))},startsWith(...e){return this.check(/* @__PURE__ */ eo(...e))},endsWith(...e){return this.check(/* @__PURE__ */ to(...e))},min(...e){return this.check(/* @__PURE__ */ Ja(...e))},max(...e){return this.check(/* @__PURE__ */ qa(...e))},length(...e){return this.check(/* @__PURE__ */ Ya(...e))},nonempty(...e){return this.check(/* @__PURE__ */ Ja(1,...e))},lowercase(e){return this.check(/* @__PURE__ */ Za(e))},uppercase(e){return this.check(/* @__PURE__ */ Qa(e))},trim(){return this.check(/* @__PURE__ */ io())},normalize(...e){return this.check(/* @__PURE__ */ ro(...e))},toLowerCase(){return this.check(/* @__PURE__ */ ao())},toUpperCase(){return this.check(/* @__PURE__ */ oo())},slugify(){return this.check(/* @__PURE__ */ so())}})),As=/*@__PURE__*/ b(`ZodString`,(e,t)=>{_r.init(e,t),ks.init(e,t)},{email(e){return this.check(/* @__PURE__ */ da(Fs,e))},url(e){return this.check(/* @__PURE__ */ _a(Rs,e))},jwt(e){return this.check(/* @__PURE__ */ Ma($s,e))},emoji(e){return this.check(/* @__PURE__ */ va(zs,e))},guid(e){return this.check(/* @__PURE__ */ fa(Is,e))},uuid(e){return this.check(/* @__PURE__ */ pa(Ls,e))},uuidv4(e){return this.check(/* @__PURE__ */ ma(Ls,e))},uuidv6(e){return this.check(/* @__PURE__ */ ha(Ls,e))},uuidv7(e){return this.check(/* @__PURE__ */ ga(Ls,e))},nanoid(e){return this.check(/* @__PURE__ */ ya(Bs,e))},cuid(e){return this.check(/* @__PURE__ */ ba(Vs,e))},cuid2(e){return this.check(/* @__PURE__ */ xa(Hs,e))},ulid(e){return this.check(/* @__PURE__ */ Sa(Us,e))},base64(e){return this.check(/* @__PURE__ */ ka(Xs,e))},base64url(e){return this.check(/* @__PURE__ */ Aa(Zs,e))},xid(e){return this.check(/* @__PURE__ */ Ca(Ws,e))},ksuid(e){return this.check(/* @__PURE__ */ wa(Gs,e))},ipv4(e){return this.check(/* @__PURE__ */ Ta(Ks,e))},ipv6(e){return this.check(/* @__PURE__ */ Ea(qs,e))},cidrv4(e){return this.check(/* @__PURE__ */ Da(Js,e))},cidrv6(e){return this.check(/* @__PURE__ */ Oa(Ys,e))},e164(e){return this.check(/* @__PURE__ */ ja(Qs,e))},datetime(e){return this.check(/* @__PURE__ */ Na(js,e))},date(e){return this.check(/* @__PURE__ */ Pa(Ms,e))},time(e){return this.check(/* @__PURE__ */ Fa(Ns,e))},duration(e){return this.check(/* @__PURE__ */ Ia(Ps,e))}});function j(e){return/* @__PURE__ */ ua(As,e)}const M=/*@__PURE__*/ b(`ZodStringFormat`,(e,t)=>{T.init(e,t),ks.init(e,t)}),js=/*@__PURE__*/ b(`ZodISODateTime`,(e,t)=>{Ir.init(e,t),M.init(e,t)}),Ms=/*@__PURE__*/ b(`ZodISODate`,(e,t)=>{Lr.init(e,t),M.init(e,t)}),Ns=/*@__PURE__*/ b(`ZodISOTime`,(e,t)=>{Rr.init(e,t),M.init(e,t)}),Ps=/*@__PURE__*/ b(`ZodISODuration`,(e,t)=>{zr.init(e,t),M.init(e,t)}),Fs=/*@__PURE__*/ b(`ZodEmail`,(e,t)=>{br.init(e,t),M.init(e,t)}),Is=/*@__PURE__*/ b(`ZodGUID`,(e,t)=>{vr.init(e,t),M.init(e,t)}),Ls=/*@__PURE__*/ b(`ZodUUID`,(e,t)=>{yr.init(e,t),M.init(e,t)}),Rs=/*@__PURE__*/ b(`ZodURL`,(e,t)=>{Or.init(e,t),M.init(e,t)}),zs=/*@__PURE__*/ b(`ZodEmoji`,(e,t)=>{kr.init(e,t),M.init(e,t)}),Bs=/*@__PURE__*/ b(`ZodNanoID`,(e,t)=>{Ar.init(e,t),M.init(e,t)}),Vs=/*@__PURE__*/ b(`ZodCUID`,(e,t)=>{jr.init(e,t),M.init(e,t)}),Hs=/*@__PURE__*/ b(`ZodCUID2`,(e,t)=>{Mr.init(e,t),M.init(e,t)}),Us=/*@__PURE__*/ b(`ZodULID`,(e,t)=>{Nr.init(e,t),M.init(e,t)}),Ws=/*@__PURE__*/ b(`ZodXID`,(e,t)=>{Pr.init(e,t),M.init(e,t)}),Gs=/*@__PURE__*/ b(`ZodKSUID`,(e,t)=>{Fr.init(e,t),M.init(e,t)}),Ks=/*@__PURE__*/ b(`ZodIPv4`,(e,t)=>{Br.init(e,t),M.init(e,t)}),qs=/*@__PURE__*/ b(`ZodIPv6`,(e,t)=>{Ur.init(e,t),M.init(e,t)}),Js=/*@__PURE__*/ b(`ZodCIDRv4`,(e,t)=>{Wr.init(e,t),M.init(e,t)}),Ys=/*@__PURE__*/ b(`ZodCIDRv6`,(e,t)=>{Kr.init(e,t),M.init(e,t)}),Xs=/*@__PURE__*/ b(`ZodBase64`,(e,t)=>{Yr.init(e,t),M.init(e,t)}),Zs=/*@__PURE__*/ b(`ZodBase64URL`,(e,t)=>{Qr.init(e,t),M.init(e,t)}),Qs=/*@__PURE__*/ b(`ZodE164`,(e,t)=>{$r.init(e,t),M.init(e,t)}),$s=/*@__PURE__*/ b(`ZodJWT`,(e,t)=>{ti.init(e,t),M.init(e,t)}),ec=/*@__PURE__*/ b(`ZodNumber`,(e,t)=>{ni.init(e,t),A.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ho(e,t,n,r),e.isFinite=!0},/*@__PURE__*/ Tt({minValue:e=>{let{minimum:t,exclusiveMinimum:n}=O(e);return Math.max(t??-1/0,n??-1/0)},maxValue:e=>{let{maximum:t,exclusiveMaximum:n}=O(e);return Math.min(t??1/0,n??1/0)},isInt:e=>{let{isInt:t,multipleOf:n}=O(e);return!!t||!!n?.some(Number.isSafeInteger)},format:e=>O(e).format??null},{gt(e,t){return this.check(/* @__PURE__ */ Wa(e,t))},gte(e,t){return this.check(/* @__PURE__ */ Ga(e,t))},min(e,t){return this.check(/* @__PURE__ */ Ga(e,t))},lt(e,t){return this.check(/* @__PURE__ */ Ha(e,t))},lte(e,t){return this.check(/* @__PURE__ */ Ua(e,t))},max(e,t){return this.check(/* @__PURE__ */ Ua(e,t))},int(e){return this.check(rc(e))},safe(e){return this.check(rc(e))},positive(e){return this.check(/* @__PURE__ */ Wa(0,e))},nonnegative(e){return this.check(/* @__PURE__ */ Ga(0,e))},negative(e){return this.check(/* @__PURE__ */ Ha(0,e))},nonpositive(e){return this.check(/* @__PURE__ */ Ua(0,e))},multipleOf(e,t){return this.check(/* @__PURE__ */ Ka(e,t))},step(e,t){return this.check(/* @__PURE__ */ Ka(e,t))},finite(){return this}}));function tc(e){return/* @__PURE__ */ La(ec,e)}const nc=/*@__PURE__*/ b(`ZodNumberFormat`,(e,t)=>{ri.init(e,t),ec.init(e,t)});function rc(e){return/* @__PURE__ */ Ra(nc,e)}const ic=/*@__PURE__*/ b(`ZodBoolean`,(e,t)=>{ii.init(e,t),A.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Uo(e,t,n,r)});function ac(e){return/* @__PURE__ */ za(ic,e)}const oc=/*@__PURE__*/ b(`ZodUnknown`,(e,t)=>{ai.init(e,t),A.init(e,t),e._zod.processJSONSchema=(e,t,n)=>void 0});function sc(){return/* @__PURE__ */ Ba(oc)}const cc=/*@__PURE__*/ b(`ZodNever`,(e,t)=>{oi.init(e,t),A.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Wo(e,t,n,r)});function lc(e){return/* @__PURE__ */ Va(cc,e)}const uc=/*@__PURE__*/ b(`ZodArray`,(e,t)=>{Os(),ui.init(e,t),A.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Jo(e,t,n,r),e.element=t.element},{min(e,t){return this.check(/* @__PURE__ */ Ja(e,t))},nonempty(e){return this.check(/* @__PURE__ */ Ja(1,e))},max(e,t){return this.check(/* @__PURE__ */ qa(e,t))},length(e,t){return this.check(/* @__PURE__ */ Ya(e,t))},unwrap(){return this.element}});function dc(e,t){return/* @__PURE__ */ co(uc,e,t)}const fc=/*@__PURE__*/ b(`ZodObject`,(e,t)=>{Os(),gi.init(e,t),A.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Xo(e,t,n,r),jt(e,`shape`,e=>e._zod.def.shape,!1)},{keyof(){return xc(Object.keys(this._zod.def.shape))},catchall(e){return this.clone(_(this._zod.def,{catchall:e}))},passthrough(){return this.clone(_(this._zod.def,{catchall:sc()}))},loose(){return this.clone(_(this._zod.def,{catchall:sc()}))},strict(){return this.clone(_(this._zod.def,{catchall:lc()}))},strip(){return this.clone(_(this._zod.def,{catchall:void 0}))},extend(e){return it(this,e)},safeExtend(e){return ot(this,e)},merge(e){return st(this,e)},pick(e){return tt(this,e)},omit(e){return rt(this,e)},partial(...e){return ct(wc,this,e[0])},exactPartial(...e){return ct(Ec,this,e[0],`exactPartial`)},required(...e){return lt(Pc,this,e[0])}});function N(e,t){return new fc({type:`object`,shape:e,catchall:lc(),...v(t)})}function pc(e,t){return new fc({type:`object`,shape:e,catchall:sc(),...v(t)})}const mc=/*@__PURE__*/ b(`ZodUnion`,(e,t)=>{vi.init(e,t),A.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Zo(e,t,n,r),e.options=t.options});function hc(e,t){return new mc({type:`union`,options:e,...v(t)})}const gc=/*@__PURE__*/ b(`ZodIntersection`,(e,t)=>{yi.init(e,t),A.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Qo(e,t,n,r)});function _c(e,t){return new gc({type:`intersection`,left:e,right:t})}const vc=/*@__PURE__*/ b(`ZodRecord`,(e,t)=>{Os(),Si.init(e,t),A.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ns(e,t,n,r),e.keyType=t.keyType,e.valueType=t.valueType});function yc(e,t,n){return!t||!t._zod?new vc({type:`record`,keyType:j(),valueType:e,...v(t)}):new vc({type:`record`,keyType:e,valueType:t,...v(n)})}const bc=/*@__PURE__*/ b(`ZodEnum`,(e,t)=>{Ci.init(e,t),A.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Go(e,t,n,r),e.enum=t.entries,e.options=[...e._zod.values];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 bc({...t,checks:[],...v(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 bc({...t,checks:[],...v(r),entries:i})}});function xc(e,t){let n=Array.isArray(e)?Object.fromEntries(e.map(e=>[e,e])):e;return new bc({type:`enum`,entries:n,...v(t)})}const Sc=/*@__PURE__*/ b(`ZodTransform`,(e,t)=>{Os(),wi.init(e,t),A.init(e,t),e._zod.processJSONSchema=(t,n,r)=>qo(e,t,n,r),e._zod.parse=(n,r)=>{if(r.direction===`backward`)throw new Rt(e.constructor.name);n.addIssue=r=>{if(typeof r==`string`)n.issues.push(xt(r,n.value,t));else{let t=r;t.fatal&&(t.continue=!1),t.code??=`custom`,`input`in t||(t.input=n.value),t.inst??=e,n.issues.push(xt(t))}};let i=t.transform(n.value,n);return i instanceof Promise?i.then(e=>(n.value=e,n)):(n.value=i,n)}});function Cc(e){return new Sc({type:`transform`,transform:e})}const wc=/*@__PURE__*/ b(`ZodOptional`,(e,t)=>{Ei.init(e,t),A.init(e,t),e._zod.processJSONSchema=(t,n,r)=>fs(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Tc(e){return new wc({type:`optional`,innerType:e})}const Ec=/*@__PURE__*/ b(`ZodExactOptional`,(e,t)=>{Di.init(e,t),A.init(e,t),e._zod.processJSONSchema=(t,n,r)=>fs(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Dc(e){return new Ec({type:`optional`,innerType:e})}const Oc=/*@__PURE__*/ b(`ZodNullable`,(e,t)=>{Oi.init(e,t),A.init(e,t),e._zod.processJSONSchema=(t,n,r)=>rs(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function kc(e){return new Oc({type:`nullable`,innerType:e})}const Ac=/*@__PURE__*/ b(`ZodDefault`,(e,t)=>{ki.init(e,t),A.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ss(e,t,n,r),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap});function jc(e,t){return new Ac({type:`default`,innerType:e,get defaultValue(){return typeof t==`function`?t():qe(t)}})}const Mc=/*@__PURE__*/ b(`ZodPrefault`,(e,t)=>{ji.init(e,t),A.init(e,t),e._zod.processJSONSchema=(t,n,r)=>cs(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Nc(e,t){return new Mc({type:`prefault`,innerType:e,get defaultValue(){return typeof t==`function`?t():qe(t)}})}const Pc=/*@__PURE__*/ b(`ZodNonOptional`,(e,t)=>{Mi.init(e,t),A.init(e,t),e._zod.processJSONSchema=(t,n,r)=>is(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Fc(e,t){return new Pc({type:`nonoptional`,innerType:e,...v(t)})}const Ic=/*@__PURE__*/ b(`ZodCatch`,(e,t)=>{Fi.init(e,t),A.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ls(e,t,n,r),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap});function Lc(e,t){return new Ic({type:`catch`,innerType:e,catchValue:typeof t==`function`?t:Mt(t)})}const Rc=/*@__PURE__*/ b(`ZodPipe`,(e,t)=>{Ii.init(e,t),A.init(e,t),e._zod.processJSONSchema=(t,n,r)=>us(e,t,n,r),e.in=t.in,e.out=t.out});function zc(e,t){return new Rc({type:`pipe`,in:e,out:t})}const Bc=/*@__PURE__*/ b(`ZodPreprocess`,(e,t)=>{Rc.init(e,t),Ri.init(e,t)}),Vc=/*@__PURE__*/ b(`ZodReadonly`,(e,t)=>{zi.init(e,t),A.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ds(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Hc(e){return new Vc({type:`readonly`,innerType:e})}const Uc=/*@__PURE__*/ b(`ZodCustom`,(e,t)=>{Vi.init(e,t),A.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ko(e,t,n,r)});function Wc(e,t={}){return/* @__PURE__ */ lo(Uc,e,t)}function Gc(e,t){return/* @__PURE__ */ uo(e,t)}function Kc(e,t){return new Bc({type:`pipe`,in:Cc(e),out:t})}function qc(e){return/* @__PURE__ */ Na(js,e)}const Jc=[`blobless`,`full`],Yc=[`ssh`,`https`],Xc=/^(?!\.{1,2}$)[^/\\%:]+$/u,Zc=/^[a-z0-9][a-z0-9.-]*(?:_[1-9]\d{0,4})?$/u,Qc=/^(?<amount>[1-9]\d{0,3})(?<unit>[mhd])$/u,$c={d:864e5,h:36e5,m:6e4},el=e=>e!==``&&/^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/u.test(e),tl=e=>{if(e===void 0)return!0;let t=Number(e);return t>=1&&t<=65535},nl=e=>{let[t=``,n]=e.split(`_`);return tl(n)?t.split(`.`).every(e=>el(e)):!1},rl=e=>e.length>0&&e.isWellFormed(),il=j().refine(rl,`must be non-empty text that survives being written to the config`),al=il.refine(Te,`must be a name git accepts for a branch (git check-ref-format --branch)`),ol=e=>{let[t,...n]=e.split(`/`);return t===void 0||n.length<2||!Zc.test(t)||!nl(t)?!1:n.every(e=>Xc.test(e))},sl=e=>Xc.test(e),cl=j().refine(e=>rl(e)&&ol(e),`ref key must be host/path…/repo with safe, non-empty segments`).brand(),ll=j().regex(Qc,`duration must be <n>m, <n>h, or <n>d`).brand(),ul=e=>{let t=Qc.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)*$c[r]},dl=xc(Jc),fl=xc(Yc),pl=il.refine(e=>e.includes(`{version}`),`tag format must contain {version}`),ml=il.refine(e=>{if(e===`.`)return!0;let t=e.split(`/`);return t.length>0&&t.every(e=>Xc.test(e)&&e!==`.`)},`package path must be "." or a normalized relative path without traversal`),hl=/* @__PURE__ */ new Set([`__proto__`,`constructor`,`prototype`]),gl=(e,t,n)=>Kc((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),_l=e=>rl(e)&&!hl.has(e),vl=e=>gl(_l,()=>`package key must be non-empty, storable text, and not "__proto__", "constructor", or "prototype"`,yc(j().min(1),e)),yl=e=>_l(e),bl={clone_mode:`blobless`,git_transport:`https`,sync_ttl:`1h`},xl=N({clone_mode:dl.default(bl.clone_mode),git_transport:fl.default(bl.git_transport),sync_ttl:ll.default(ll.parse(bl.sync_ttl))}),Sl=N((e=>Object.fromEntries(Object.entries(e).map(([e,t])=>[e,t.removeDefault().optional()])))(xl.shape)),Cl=N({name:il,path:ml}),wl=N({description:il,path:ml,tag_format:pl.optional()}),Tl=N({declined_packages:dc(Cl).optional(),default_branch:il,description:il,packages:vl(wl).optional(),tag_format:pl.optional(),url:il,...Sl.shape}),El=pc({cli_version:il,schema_version:tc().int().positive()}),Dl=gl(e=>cl.safeParse(e).success,()=>`ref key must be host/path…/repo with safe, non-empty segments`,yc(j(),Tl)),Ol=N({check:ac().default(!0),notify:ac().default(!0)}),kl=N({meta:El,refs:Dl.default({}),settings:xl,updates:Ol.optional()});
|
|
58
114
|
/*!
|
|
59
115
|
* Copyright (c) Squirrel Chat et al., All rights reserved.
|
|
60
116
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
@@ -82,7 +138,9 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
82
138
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
83
139
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
84
140
|
*/
|
|
85
|
-
|
|
141
|
+
function Al(e,t){let n=e.slice(0,t).split(/\r?\n/);return[n.length,n.pop().length+1]}function jl(e,t,n){let r=e.split(/\r?\n/),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+=`
|
|
142
|
+
`,e===t&&(i+=` `.repeat(a+n+2),i+=`^
|
|
143
|
+
`))}return i}var P=class e extends Error{line;column;codeblock;constructor(e,t){let[n,r]=Al(t.toml,t.ptr),i=jl(t.toml,n,r);super(`Invalid TOML document: ${e}\n\n${i}`,t),this.line=n,this.column=r,this.codeblock=i}static x(t,n,r){throw new e(t,{toml:n.s,ptr:r??n.p})}};
|
|
86
144
|
/*!
|
|
87
145
|
* Copyright (c) Squirrel Chat et al., All rights reserved.
|
|
88
146
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
@@ -110,9 +168,36 @@ let wl=/^(\d{4}-\d{2}-\d{2})?[T ]?(?:(\d{2}):\d{2}(?::\d{2}(?:\.\d+)?)?)?(Z|[-+]
|
|
|
110
168
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
111
169
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
112
170
|
*/
|
|
113
|
-
function
|
|
114
|
-
`,e===
|
|
115
|
-
|
|
171
|
+
function Ml(e){let t=e.p,n=e.s.charCodeAt(e.p++),r=n,i=n===39,a=n===e.s.charCodeAt(e.p)&&n===e.s.charCodeAt(e.p+1);a&&((n=e.s.charCodeAt(e.p+=2))===10?e.p++:n===13&&e.s.charCodeAt(e.p+1)===10&&(e.p+=2));let o=``,s=e.p,c=0;for(;e.p<e.s.length;e.p++)if(n=e.s.charCodeAt(e.p),a&&(n===10||n===13&&e.s.charCodeAt(e.p+1)===10))c&&=3;else if(n<32&&n!==9||n===127)P.x(`control characters are not allowed in strings`,e);else if((!c||c===3)&&n===r&&(!a||e.s.charCodeAt(e.p+1)===r&&e.s.charCodeAt(e.p+2)===r)){if(a&&(e.s.charCodeAt(e.p+3)===r&&e.p++,e.s.charCodeAt(e.p+3)===r&&e.p++),!c){let t=e.s.slice(s,e.p);o=o?o+t:t}return e.p+=a?3:1,o}else if(!c)!i&&n===92&&(o+=e.s.slice(s,s=e.p),c=1);else if(c===1){if(n===120||n===117||n===85){let t=e.p++-1,r=0,i=n===120?2:n===117?4:8;for(let t=0;t<i;t++,e.p++){let t=e.s.charCodeAt(e.p),n=t>=48&&t<=57?t-48:t>=65&&t<=70?t-65+10:t>=97&&t<=102?t-97+10:-1;n<0&&P.x(`invalid non-hex character in unicode escape`,e),r=r<<4|n}(r<0||r>1114111||r>=55296&&r<=57343)&&P.x(`invalid unicode escape`,e,t),o+=String.fromCodePoint(r),s=e.p--,c=0}else a&&(n===32||n===9)?c=2:(n===98?o+=`\b`:n===116?o+=` `:n===110?o+=`
|
|
172
|
+
`:n===102?o+=`\f`:n===114?o+=`\r`:n===101?o+=`\x1B`:n===34?o+=`"`:n===92?o+=`\\`:P.x(`unrecognised escape sequence`,e),s=e.p+1,c=0)}else n!==32&&n!==9&&(c===2&&P.x(`invalid escape: only line-ending whitespace may be escaped`,e,s),c=+(!i&&n===92),s=e.p);P.x(`unfinished string`,e,t)}
|
|
173
|
+
/*!
|
|
174
|
+
* Copyright (c) Squirrel Chat et al., All rights reserved.
|
|
175
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
176
|
+
*
|
|
177
|
+
* Redistribution and use in source and binary forms, with or without
|
|
178
|
+
* modification, are permitted provided that the following conditions are met:
|
|
179
|
+
*
|
|
180
|
+
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
181
|
+
* list of conditions and the following disclaimer.
|
|
182
|
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
183
|
+
* this list of conditions and the following disclaimer in the
|
|
184
|
+
* documentation and/or other materials provided with the distribution.
|
|
185
|
+
* 3. Neither the name of the copyright holder nor the names of its contributors
|
|
186
|
+
* may be used to endorse or promote products derived from this software without
|
|
187
|
+
* specific prior written permission.
|
|
188
|
+
*
|
|
189
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
190
|
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
191
|
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
192
|
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
193
|
+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
194
|
+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
195
|
+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
196
|
+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
197
|
+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
198
|
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
199
|
+
*/
|
|
200
|
+
let Nl=/^(\d{4}-\d{2}-\d{2})?[Tt ]?(?:(\d{2}):\d{2}(?::\d{2}(?:\.\d+)?)?)?(Z|z|[-+]\d{2}:\d{2})?$/i;var Pl=class e extends Date{#e=!1;#t=!1;#n=null;constructor(e,t,n){let r=!0,i=!0,a=`Z`,o;if(typeof e==`string`){if(t)prep:{if(t<3){if(+e.slice(11,13)>23){e=``;break prep}t===2?(a=null,e+=`Z`):(o=e.charCodeAt(e.length-1))!==90&&o!==122&&(a=e.slice(e.length-6)),n&&(e=e.slice(0,10)+`T`+e.slice(11))}else t===4&&(e=+e.slice(0,2)>23?``:`0000-01-01T${e}Z`);r=t!==4,i=t!==3}else{let t=e.match(Nl);t?(t[1]||(r=!1,e=`0000-01-01T${e}`),i=!!t[2],i&&e[10]===` `&&(e=e.replace(` `,`T`)),t[2]&&+t[2]>23?e=``:(a=t[3]||null,!a&&i&&(e+=`Z`))):e=``}}super(e),isNaN(this.getTime())||(this.#e=r,this.#t=i,this.#n=a)}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`||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,(/* @__PURE__ */ 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}};
|
|
116
201
|
/*!
|
|
117
202
|
* Copyright (c) Squirrel Chat et al., All rights reserved.
|
|
118
203
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
@@ -140,8 +225,7 @@ function El(e,t){let n=e.slice(0,t).split(/\r\n|\n|\r/g);return[n.length,n.pop()
|
|
|
140
225
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
141
226
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
142
227
|
*/
|
|
143
|
-
function
|
|
144
|
-
`,t);return e.charCodeAt(n-1)===13&&n--,n}function kl(e){for(;e.p<e.s.length;e.p++){let t=e.s.charCodeAt(e.p);if(t===10)break;if(t===13&&e.s.charCodeAt(e.p+1)===10){e.p++;break}if(t<32&&t!==9||t===127)throw new P(`control characters are not allowed in comments`,{toml:e.s,ptr:e.p})}}function Al(e,t,n){let r;for(;;){for(;(r=e.s.charCodeAt(e.p))===32||r===9||!t&&(r===10||r===13&&e.s.charCodeAt(e.p+1)===10);)e.p++;if(n||r!==35)break;kl(e)}}function jl(e,t,n){let r=e.p;if(!n){r=Ol(e.s,r),e.p=r<0?e.s.length:r;return}for(;e.p<e.s.length;e.p++){let r=e.s.charCodeAt(e.p);if(r===35)kl(e);else if(r===n||r===t)return}throw new P(`cannot find end of structure`,{toml:e.s,ptr:r})}
|
|
228
|
+
function F(e,t=10){return t===16?e>47&&e<58||e>64&&e<71||e>96&&e<103:e>47&&e<48+t}function Fl(e,t){return e===32||e===9||e===10||e===13||t&&(e===t||e===44)||e===35}function Il(e,t){let n=e.p,r=e.s.charCodeAt(e.p);if(r===91||r===123){e.d--||P.x(`document contains excessively nested structures. aborting.`,e);let t=r===91?ql(e):Kl(e);return e.d++,t}return r===34||r===39?Ml(e):r===116?((e.s.charCodeAt(++e.p)!==114||e.s.charCodeAt(++e.p)!==117||e.s.charCodeAt(++e.p)!==101)&&P.x(`invalid value`,e,n),e.p++,!0):r===102?((e.s.charCodeAt(++e.p)!==97||e.s.charCodeAt(++e.p)!==108||e.s.charCodeAt(++e.p)!==115||e.s.charCodeAt(++e.p)!==101)&&P.x(`invalid value`,e,n),e.p++,!1):r===43||r===45?Ll(e,e.p,e.s.charCodeAt(++e.p),44-r,t):e.s.charCodeAt(e.p+4)===45&&e.s.charCodeAt(e.p+7)===45?Bl(e,r,t):e.s.charCodeAt(e.p+2)===58?Vl(e,r,t):Ll(e,e.p,r,0,t)}function Ll(e,t,n,r,i){let a=n,o=0,s=!1;if(a===105)return(e.s.charCodeAt(++e.p)!==110||e.s.charCodeAt(++e.p)!==102)&&P.x(`invalid value`,e,t),e.p++,(r||1)/0;if(a===110)return(e.s.charCodeAt(++e.p)!==97||e.s.charCodeAt(++e.p)!==110)&&P.x(`invalid value`,e,t),e.p++,NaN;if(a===48){if(++e.p>=e.s.length||Fl(a=e.s.charCodeAt(e.p),i))return e.bi===!0?0n:0;if(!r){if(a===120)return Rl(e,t,16,i);if(a===98)return Rl(e,t,2,i);if(a===111)return Rl(e,t,8,i)}a===46?o=2:a===101||a===69?o=4:P.x(`illegal leading zero`,e,t)}else F(a)||P.x(`invalid value`,e,t);for(;++e.p<e.s.length&&(a=e.s.charCodeAt(e.p),!Fl(a,i));)o||=1,a===95?(o&1||P.x(`illegal underscore`,e),o+=11,s=!0):o===1&&a===46?o=2:(o===1||o===3)&&(a===101||a===69)?o=4:o===4&&(a===43||a===45)?o=6:F(a)?o>9?o-=11:o&1||o++:P.x(`illegal character in numeric literal`,e);if(!o){let t=(n-48)*(r||1);return e.bi===!0?BigInt(t):t}o&1||P.x(`unfinished numeric value`,e,t);let c=e.s.slice(t,e.p);return s&&(c=c.replaceAll(`_`,``)),o>1?parseFloat(c):zl(e,c,10,t)}function Rl(e,t,n,r){let i,a=1;for(;++e.p<e.s.length&&(i=e.s.charCodeAt(e.p),!Fl(i,r));)i===95?(a&1&&P.x(`illegal underscore`,e),a=3):F(i,n)?a&1&&a--:P.x(`illegal character in numeric literal`,e);a&1&&P.x(`unfinished numeric value`,e);let o=e.s.slice(t+2,e.p);return a&&(o=o.replaceAll(`_`,``)),zl(e,o,n,t)}function zl(e,t,n,r){if(e.bi!==!0)int:{let i=parseInt(t,n);if(!Number.isSafeInteger(i)){if(e.bi)break int;P.x(`integer value cannot be represented losslessly`,e,r)}return i}return BigInt(n===10?t:(n===2?`0b`:n===8?`0o`:`0x`)+t)}function Bl(e,t,n){let r=e.p++,i;if(!F(t)||!F(e.s.charCodeAt(e.p++))||!F(e.s.charCodeAt(e.p++))||!F(e.s.charCodeAt(e.p++)))return Ll(e,e.p=r,t,0,n);if(e.p+=5,F(e.s.charCodeAt(e.p++))||P.x(`invalid date-time: date part is malformed`,e,r),e.p>=e.s.length||((t=e.s.charCodeAt(e.p))!==32||(i=!0,!F(e.s.charCodeAt(e.p+1))))&&t!==84&&t!==116)return Hl(e,e.s.slice(r,e.p),3,!1,r);if(e.s.charCodeAt(e.p+=3)!==58&&P.x(`invalid date-time: time part is malformed`,e,r),e.s.charCodeAt(e.p+=3)===58&&(e.p+=3),e.s.charCodeAt(e.p)===46)for(;F(e.s.charCodeAt(++e.p)););if(t=e.s.charCodeAt(e.p)){if(t===90||t===122)return Hl(e,e.s.slice(r,++e.p),1,i,r,`[+00:00]`);if(t===43||t===45)return Hl(e,e.s.slice(r,e.p+=6),1,i,r,!e.ld&&`[`+e.s.slice(e.p-6,e.p)+`]`)}return Hl(e,e.s.slice(r,e.p),2,i,r)}function Vl(e,t,n){let r=e.p;if(!F(t)||!F(e.s.charCodeAt(++e.p)))return Ll(e,--e.p,t,0,n);if(e.s.charCodeAt(e.p+=4)===58&&(e.p+=3),e.s.charCodeAt(e.p)===46)for(;F(e.s.charCodeAt(++e.p)););return Hl(e,e.s.slice(r,e.p),4,!1,r)}function Hl(e,t,n,r,i,a){if(e.ld){let a=new Pl(t,n,r);return a.isValid()||P.x(`invalid date`,e,i),a}try{switch(a&&(t+=a),n){case 1:return Temporal.ZonedDateTime.from(t);case 2:return Temporal.PlainDateTime.from(t);case 3:return Temporal.PlainDate.from(t);case 4:return Temporal.PlainTime.from(t)}}catch(t){P.x(t instanceof Error?t.message:``+t,e,i)}}
|
|
145
229
|
/*!
|
|
146
230
|
* Copyright (c) Squirrel Chat et al., All rights reserved.
|
|
147
231
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
@@ -169,8 +253,7 @@ function Ol(e,t=0){let n=e.indexOf(`
|
|
|
169
253
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
170
254
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
171
255
|
*/
|
|
172
|
-
|
|
173
|
-
`;else if(n===102)o+=`\f`;else if(n===114)o+=`\r`;else if(n===101)o+=`\x1B`;else if(n===34)o+=`"`;else if(n===92)o+=`\\`;else throw new P(`unrecognized escape sequence`,{toml:e.s,ptr:e.p});s=e.p+1,c=0}}else if(n!==32&&n!==9){if(c===2)throw new P(`invalid escape: only line-ending whitespace may be escaped`,{toml:e.s,ptr:s});c=+(!i&&n===92),s=e.p}throw new P(`unfinished string`,{toml:e.s,ptr:t})}function Il(e,t,n){let r=e.s.slice(t,n),i=r.indexOf(`#`);return i>0&&(kl({s:r,p:i,d:0}),r=r.slice(0,i)),r.trimEnd()}function Ll(e,t,n){let r=e.p,i={toml:e.s,ptr:r};jl(e,44,n);let a=Il(e,r,e.p);if(!a)throw new P(`incomplete declaration: value expected`,i);if(a===`-inf`)return-1/0;if(a===`inf`||a===`+inf`)return 1/0;if(a===`nan`||a===`+nan`||a===`-nan`)return NaN;if(a===`-0`)return t?0n:0;let o=Ml.test(a);if(o||Nl.test(a)){if(Pl.test(a))throw new P(`leading zeroes are not allowed`,i);a=a.replace(/_/g,``);let e=+a;if(isNaN(e))throw new P(`invalid number`,i);if(o){if((o=!Number.isSafeInteger(e))&&!t)throw new P(`integer value cannot be represented losslessly`,i);(o||t===!0)&&(e=BigInt(a))}return e}let s=new Tl(a);if(!s.isValid())throw new P(`invalid value`,i);return s}
|
|
256
|
+
function Ul(e){for(;e.p<e.s.length;e.p++){let t=e.s.charCodeAt(e.p);if(t===10)break;if(t===13&&e.s.charCodeAt(e.p+1)===10){e.p++;break}(t<32&&t!==9||t===127)&&P.x(`control characters are not allowed in comments`,e)}}function Wl(e,t,n){let r;for(;e.p<e.s.length;){for(;e.p<e.s.length&&((r=e.s.charCodeAt(e.p))===32||r===9||!t&&(r===10||r===13&&e.s.charCodeAt(e.p+1)===10));)e.p++;if(n||r!==35)break;Ul(e)}}
|
|
174
257
|
/*!
|
|
175
258
|
* Copyright (c) Squirrel Chat et al., All rights reserved.
|
|
176
259
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
@@ -198,7 +281,7 @@ let Ml=/^((0x[0-9a-fA-F](_?[0-9a-fA-F])*)|(([+-]|0[ob])?\d(_?\d)*))$/,Nl=/^[+-]?
|
|
|
198
281
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
199
282
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
200
283
|
*/
|
|
201
|
-
function
|
|
284
|
+
function Gl(e,t=61){let n,r=0,i=[],a,o=e.s.charCodeAt(n=e.p);do if(o===t)return r||P.x(`unexpected end of key`,e),r===1&&i.push(e.s.slice(a,e.p)),e.p++,i;else o===46?(r||P.x(`illegal empty bare key`,e),r===1&&i.push(e.s.slice(a,e.p)),r=0):!r&&(o===34||o===39)?(o===e.s.charCodeAt(e.p+1)&&o===e.s.charCodeAt(e.p+2)&&P.x(`illegal quoted key: multiline strings are not allowed`,e),i.push(Ml(e)),r=2,e.p--):o===32||o===9?r===1&&(i.push(e.s.slice(a,e.p)),r=2):r===2||o<48&&o!==45||o>57&&o<65||o>90&&o<97&&o!==95||o>122?P.x(`illegal character in key`,e):r||(r=1,a=e.p);while(o=e.s.charCodeAt(++e.p));P.x(`incomplete key-value: cannot find end of key`,e,n)}function Kl(e){let t=e.p++,n=Object.create(null),r=/* @__PURE__ */ new Set,i;for(;e.p<e.s.length;){if(Wl(e),(i=e.s.charCodeAt(e.p))===125)return e.p++,n;let t,a=n,o=!1,s=e.p,c=Gl(e);for(let n=0;n<c.length;n++){n&&(a=o?a[t]:a[t]=Object.create(null)),t=c[n],(o=Object.hasOwn(a,t))&&(typeof a[t]!=`object`||r.has(a[t]))&&P.x(`trying to redefine an already defined value`,e,s);let i=t===`__proto__`;if(e.uk&&(i||t===`constructor`)){a=e.uk!==1&&P.x(`document contains an unsafe property`,e,s);break}!o&&i&&Object.defineProperty(a,t,{enumerable:!0,configurable:!0,writable:!0})}o&&P.x(`trying to redefine an already defined value`,e,s),Wl(e,!0,!0);let l=Il(e,125);if(a&&typeof(a[t]=l)==`object`&&r.add(l),Wl(e),(i=e.s.charCodeAt(e.p++))===125)return n;i!==44&&P.x(`expected comma or end of structure`,e,e.p-1)}P.x(`unfinished table`,e,t)}function ql(e){let t=e.p++,n=[],r;for(;e.p<e.s.length;){if(Wl(e),(r=e.s.charCodeAt(e.p))===93)return e.p++,n;if(n.push(Il(e,93)),Wl(e),(r=e.s.charCodeAt(e.p++))===93)return n;r!==44&&P.x(`expected comma or end of structure`,e,e.p-1)}P.x(`unfinished array`,e,t)}
|
|
202
285
|
/*!
|
|
203
286
|
* Copyright (c) Squirrel Chat et al., All rights reserved.
|
|
204
287
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
@@ -226,7 +309,7 @@ function Rl(e,t,n){let r=e.p,i=e.s.charCodeAt(r);if(i===91||i===123){if(!e.d--)t
|
|
|
226
309
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
227
310
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
228
311
|
*/
|
|
229
|
-
|
|
312
|
+
function Jl(e,t,n,r,i){let a=n,o=r,s,c=!1,l;for(let n=0;n<t.length;n++){if(n){if(a=c?a[s]:a[s]=Object.create(null),o=(l=o[s]).c,i===0&&(l.t===1||l.t===2))return null;if(l.t===2){let e=a.length-1;a=a[e],o=o[e].c}}if(s=t[n],(c=Object.hasOwn(a,s))&&o[s]?.t===0&&o[s]?.d)return null;if(!c){let r=s===`__proto__`;if(e.uk&&(r||s===`constructor`))return!1;r&&(Object.defineProperty(a,s,{enumerable:!0,configurable:!0,writable:!0}),Object.defineProperty(o,s,{enumerable:!0,configurable:!0,writable:!0})),o[s]={t:n<t.length-1&&i===2?3:i,d:!1,i:0,c:Object.create(null)}}}if(l=o[s],l.t!==i&&(i!==1||l.t!==3)||(i===2&&(l.d||(l.d=!0,a[s]=[]),a[s].push(a=Object.create(null)),l.c[l.i++]=l={t:1,d:!1,i:0,c:Object.create(null)}),l.d))return null;if(l.d=!0,i===1)a=c?a[s]:a[s]=Object.create(null);else if(i===0&&c)return null;return[s,a,l.c]}function Yl(e,t,n){(t===null||e.uk===2)&&P.x(t===null?`trying to redefine an already defined table or value`:`document contains an unsafe property`,e,n)}function Xl(e,t={}){let n={s:e,p:0,d:t.maxDepth??1e3,bi:t.integersAsBigInt??!1,ld:t.useLegacyDate??!0,uk:t.unsafeKeyBehaviour===`throw`?2:+(t.unsafeKeyBehaviour===`drop`)},r=Object.create(null),i=Object.create(null),a,o=!1,s=r,c=i;for(e.charCodeAt(0)===65279&&n.p++,Wl(n);n.p<e.length;){if(e.charCodeAt(n.p)===91){let t=e.charCodeAt(++n.p)===91;a=n.p+=+t,o=!1;let l=Gl(n,93);t&&(e.charCodeAt(n.p)!==93&&P.x(`expected end of table array declaration`,n),n.p++);let u=Jl(n,l,r,i,t?2:1);u?(c=u[2],s=u[1]):(Yl(n,u,a),o=!0)}else{a=n.p;let e=Jl(n,Gl(n),s,c,0);!e&&!o&&Yl(n,e,a),Wl(n,!0,!0);let t=Il(n,void 0);e&&!o&&(e[1][e[0]]=t)}Wl(n,!0),n.p<e.length&&(a=e.charCodeAt(n.p))!==10&&(a!==13||e.charCodeAt(n.p+1)!==10)&&P.x(`each key-value declaration must be followed by an end-of-line`,n),Wl(n)}return r}
|
|
230
313
|
/*!
|
|
231
314
|
* Copyright (c) Squirrel Chat et al., All rights reserved.
|
|
232
315
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
@@ -254,7 +337,13 @@ let zl=/^[a-zA-Z0-9-_]+[ \t]*$/;function Bl(e,t=`=`){let n=e.p,r=n-1,i=[],a=e.s.
|
|
|
254
337
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
255
338
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
256
339
|
*/
|
|
257
|
-
function
|
|
340
|
+
let Zl=/^[a-z0-9-_]+$/i,Ql=!!``.isWellFormed;function $l(e){let t=typeof e;if(t===`object`){if(Array.isArray(e))return`array`;if(typeof e.getUTCDate==`function`&&e instanceof Date)return`date`;if(globalThis.Temporal){if(e.until){if(e instanceof Temporal.ZonedDateTime)return`temporal/tz+uc`;if(e instanceof Temporal.PlainDateTime||e instanceof Temporal.PlainDate)return`temporal/uc`;if(e instanceof Temporal.PlainTime||e instanceof Temporal.Instant)return`temporal`;if(e instanceof Temporal.PlainYearMonth)return`temporal/x`}else if(e.toPlainDate&&e instanceof Temporal.PlainMonthDay||e.negated&&e instanceof Temporal.Duration)return`temporal/x`}}return t}function eu(e){for(let t=0;t<e.length;t++)if($l(e[t])!==`object`)return!1;return e.length!=0}function tu(e){return JSON.stringify(e).replaceAll(``,`\\u007f`)}function nu(e){return tu(Ql?e.toWellFormed():e)}function ru(e){if(Zl.test(e))return e;if(Ql&&!e.isWellFormed())throw RangeError(`key contains illegal lone surrogates`);return tu(e)}function iu(e,t,n,r,i){if(n===0)throw Error(`Could not stringify the object: maximum object depth exceeded`);switch(t){case`number`:if(isNaN(e))return`nan`;if(e===1/0)return`inf`;if(e===-1/0)return`-inf`;if(Number.isInteger(e)&&(r||!Number.isSafeInteger(e)))return e.toFixed(1);case`bigint`:case`boolean`:case`temporal`:return e.toString();case`string`:return nu(e);case`date`:if(isNaN(e.getTime()))throw TypeError(`cannot serialize invalid date`);return e.toISOString();case`object`:return au(e,n,r,i);case`array`:return ou(e,n,r,i);case`temporal/tz+uc`:if(i){let t=e.timeZoneId,n=t.charCodeAt(0);if(n!==43&&n!==45&&(n!==85&&n!==71&&n!==90&&n!==69||t!==`UTC`&&t!==`UCT`&&t!==`Universal`&&t!==`Zulu`&&!t.startsWith(`GMT`)&&t!==`Greenwich`&&!t.startsWith(`Etc/`)))throw TypeError(`Temporal objects with an IANA timezone are not allowed in Temporal strict mode`)}case`temporal/uc`:if(i&&e.calendarId!==`iso8601`)throw TypeError(`Temporal objects with a non-default calendar are not allowed in Temporal strict mode`);return e.toString({calendarName:`never`,timeZoneName:`never`});case`temporal/x`:throw TypeError(`Unsupported `+e[Symbol.toStringTag])}}function au(e,t,n,r){let i=Object.keys(e);if(i.length===0)return`{}`;let a=`{ `;for(let o=0;o<i.length;o++){let s=i[o];o&&(a+=`, `),a+=ru(s)+` = `+iu(e[s],$l(e[s]),t-1,n,r)}return a+` }`}function ou(e,t,n,r){if(e.length===0)return`[]`;let i=`[ `;for(let a=0;a<e.length;a++){if(a&&(i+=`, `),e[a]===null||e[a]===void 0)throw TypeError(`arrays cannot contain null or undefined values`);i+=iu(e[a],$l(e[a]),t-1,n,r)}return i+` ]`}function su(e,t,n,r,i){if(n===0)throw Error(`Could not stringify the object: maximum object depth exceeded`);let a=``;for(let o=0;o<e.length;o++)a+=`${a&&`
|
|
341
|
+
`}[[${t}]]\n`,a+=cu(0,e[o],t,n,r,i);return a}function cu(e,t,n,r,i,a){if(r===0)throw Error(`Could not stringify the object: maximum object depth exceeded`);let o=``,s=``,c=Object.keys(t);for(let e=0;e<c.length;e++){let l=c[e];if(t[l]!==null&&t[l]!==void 0){let e=$l(t[l]);if(e===`symbol`||e===`function`)throw TypeError(`cannot serialize values of type '${e}'`);let c=ru(l);if(e===`array`&&eu(t[l]))s+=(s&&`
|
|
342
|
+
`)+su(t[l],n?`${n}.${c}`:c,r-1,i,a);else if(e===`object`){let e=n?`${n}.${c}`:c;s+=(s&&`
|
|
343
|
+
`)+cu(e,t[l],e,r-1,i,a)}else o+=c,o+=` = `,o+=iu(t[l],e,r,i,a),o+=`
|
|
344
|
+
`}}return e&&(o||!s)&&(o=o?`[${e}]\n${o}`:`[${e}]`),o&&s?`${o}\n${s}`:o||s}function lu(e,{maxDepth:t=1e3,numbersAsFloat:n=!1,strictTemporal:r=!1}={}){if($l(e)!==`object`)throw TypeError(`stringify can only be called with an object`);let i=cu(0,e,``,t,n,r);return i[i.length-1]===`
|
|
345
|
+
`?i:i+`
|
|
346
|
+
`}
|
|
258
347
|
/*!
|
|
259
348
|
* Copyright (c) Squirrel Chat et al., All rights reserved.
|
|
260
349
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
@@ -282,13 +371,7 @@ function Ul(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
|
|
|
282
371
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
283
372
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
284
373
|
*/
|
|
285
|
-
|
|
286
|
-
`}[[${t}]]\n`,i+=eu(0,e[a],t,n,r);return i}function eu(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=Kl(t[c]);if(e===`symbol`||e===`function`)throw TypeError(`cannot serialize values of type '${e}'`);let s=Gl.test(c)?c:Jl(c);if(e===`array`&&ql(t[c]))o+=(o&&`
|
|
287
|
-
`)+$l(t[c],n?`${n}.${s}`:s,r-1,i);else if(e===`object`){let e=n?`${n}.${s}`:s;o+=(o&&`
|
|
288
|
-
`)+eu(e,t[c],e,r-1,i)}else a+=s,a+=` = `,a+=Xl(t[c],e,r,i),a+=`
|
|
289
|
-
`}}return e&&(a||!o)&&(a=a?`[${e}]\n${a}`:`[${e}]`),a&&o?`${a}\n${o}`:a||o}function tu(e,{maxDepth:t=1e3,numbersAsFloat:n=!1}={}){if(Kl(e)!==`object`)throw TypeError(`stringify can only be called with an object`);let r=eu(0,e,``,t,n);return r[r.length-1]===`
|
|
290
|
-
`?r:r+`
|
|
291
|
-
`}const nu=re.O_NOFOLLOW??0,ru=e=>{if(typeof e==`object`&&e&&`code`in e){let{code:t}=e;if(typeof t==`string`)return t}},F=e=>ru(e)===`ENOENT`,iu=re.O_WRONLY|re.O_CREAT|re.O_EXCL|nu,au=async(e,t,n=384)=>{await a(m(e),{mode:448,recursive:!0});let r=`${e}.tmp-${he()}`;await te(r,t,{encoding:`utf8`,flag:iu,mode:n}),await u(r,e)},ou={CONFLICT:5,NOT_FOUND:4,OK:0,UNEXPECTED:1,USAGE:2,VALIDATION:3};var I=class extends Error{code;exitCode;reason;constructor(e,t,n,r){super(n,r),this.code=t,this.exitCode=e,this.name=`RefsError`,r?.reason!==void 0&&(this.reason=r.reason)}};const su=e=>new I(ou.CONFLICT,`conflict`,e),L=(e,t)=>new I(ou.NOT_FOUND,`not_found`,e,t===void 0?void 0:{reason:t}),R=e=>new I(ou.USAGE,`usage`,e),z=e=>new I(ou.VALIDATION,`validation`,e),cu=(e,t,n)=>n&&t!==void 0?`${e}\n${t}`:e,lu=(e,t)=>e instanceof I?{code:e.code,exitCode:e.exitCode,message:cu(e.message,e.stack,t.verbose),...e.reason===void 0?{}:{reason:e.reason}}:e instanceof Error?{code:`unexpected`,exitCode:ou.UNEXPECTED,message:cu(e.message,e.stack,t.verbose)}:{code:`unexpected`,exitCode:ou.UNEXPECTED,message:String(e)},uu=e=>{let t=`line ${String(e.line)}, column ${String(e.column)}`,{codeblock:n,message:r}=e;return n!==``&&!r.endsWith(n)?`could not be parsed (${t})`:`${r.slice(0,r.length-n.length).trim()} (${t})`},du=e=>typeof e==`object`&&!!e&&!Array.isArray(e),fu=(e,t)=>du(e)?e:t,pu=async e=>{try{return await s(e.configPath,`utf8`)}catch(e){throw F(e)?L(`no config found — run: refs init`):e}},mu=(e,t)=>{try{return Wl(e)}catch(e){throw e instanceof P?z(`invalid TOML in ${t}: ${uu(e)}`):e}},hu=e=>typeof e==`number`&&Number.isInteger(e)&&e>=1,gu=e=>{let{meta:t}=e;if(!du(t))return;let n=t.schema_version;if(hu(n))return n},_u=(e,t)=>{let n=gu(e);if(n===void 0)throw z(`config schema version is missing or invalid in ${t} — run: refs migrate`);if(n>1)throw z(`config schema ${n} is newer than this CLI supports — upgrade refs`);if(n<1)throw z(`config schema ${n} is older than expected 1 — run: refs migrate`)},B=async e=>{let t=await pu(e),n=mu(t,e.configPath);_u(n,e.configPath);let r=Cl.safeParse(n);if(!r.success)throw z(S(r.error));return r.data},vu=(e,t)=>{try{Wl(e)}catch{throw z(`refusing to write a config that could not be read back: ${t}`)}return e},yu=async(e,t)=>{let n=Cl.safeParse(t);if(!n.success)throw z(S(n.error));let r=vu(tu(n.data),e.configPath);await au(e.configPath,r)},bu=async e=>{try{return await p(e),!0}catch(e){if(F(e))return!1;throw e}},xu=async(e,t)=>await bu(e.configPath)?`noop`:(await au(e.configPath,`# refs configuration
|
|
374
|
+
const uu=re.O_NOFOLLOW??0,du=e=>{if(typeof e==`object`&&e&&`code`in e){let{code:t}=e;if(typeof t==`string`)return t}},I=e=>du(e)===`ENOENT`,fu=re.O_WRONLY|re.O_CREAT|re.O_EXCL|uu,pu=async(e,t,n=384)=>{await a(m(e),{mode:448,recursive:!0});let r=`${e}.tmp-${he()}`;await te(r,t,{encoding:`utf8`,flag:fu,mode:n}),await u(r,e)},mu={CONFLICT:5,NOT_FOUND:4,OK:0,UNEXPECTED:1,USAGE:2,VALIDATION:3};var L=class extends Error{code;exitCode;reason;constructor(e,t,n,r){super(n,r),this.code=t,this.exitCode=e,this.name=`RefsError`,r?.reason!==void 0&&(this.reason=r.reason)}};const hu=e=>new L(mu.CONFLICT,`conflict`,e),gu=(e,t)=>new L(mu.NOT_FOUND,`not_found`,e,t===void 0?void 0:{reason:t}),R=e=>new L(mu.USAGE,`usage`,e),z=e=>new L(mu.VALIDATION,`validation`,e),_u=(e,t,n)=>n&&t!==void 0?`${e}\n${t}`:e,vu=(e,t)=>e instanceof L?{code:e.code,exitCode:e.exitCode,message:_u(e.message,e.stack,t.verbose),...e.reason===void 0?{}:{reason:e.reason}}:e instanceof Error?{code:`unexpected`,exitCode:mu.UNEXPECTED,message:_u(e.message,e.stack,t.verbose)}:{code:`unexpected`,exitCode:mu.UNEXPECTED,message:String(e)},yu=e=>{let t=`line ${String(e.line)}, column ${String(e.column)}`,{codeblock:n,message:r}=e;return n!==``&&!r.endsWith(n)?`could not be parsed (${t})`:`${r.slice(0,r.length-n.length).trim()} (${t})`},bu=e=>typeof e==`object`&&!!e&&!Array.isArray(e),xu=(e,t)=>bu(e)?e:t,Su=async e=>{try{return await s(e.configPath,`utf8`)}catch(e){throw I(e)?gu(`no config found — run: refs init`):e}},Cu=(e,t)=>{try{return Xl(e)}catch(e){throw e instanceof P?z(`invalid TOML in ${t}: ${yu(e)}`):e}},wu=e=>typeof e==`number`&&Number.isInteger(e)&&e>=1,Tu=e=>{let{meta:t}=e;if(!bu(t))return;let n=t.schema_version;if(wu(n))return n},Eu=(e,t)=>{let n=Tu(e);if(n===void 0)throw z(`config schema version is missing or invalid in ${t} — run: refs migrate`);if(n>1)throw z(`config schema ${n} is newer than this CLI supports — upgrade refs`);if(n<1)throw z(`config schema ${n} is older than expected 1 — run: refs migrate`)},B=async e=>{let t=await Su(e),n=Cu(t,e.configPath);Eu(n,e.configPath);let r=kl.safeParse(n);if(!r.success)throw z(S(r.error));return r.data},Du=(e,t)=>{try{Xl(e)}catch{throw z(`refusing to write a config that could not be read back: ${t}`)}return e},Ou=async(e,t)=>{let n=kl.safeParse(t);if(!n.success)throw z(S(n.error));let r=Du(lu(n.data),e.configPath);await pu(e.configPath,r)},ku=async e=>{try{return await p(e),!0}catch(e){if(I(e))return!1;throw e}},Au=async(e,t)=>await ku(e.configPath)?`noop`:(await pu(e.configPath,`# refs configuration
|
|
292
375
|
#
|
|
293
376
|
# Every global setting under [settings] can also be set per-ref: add the same
|
|
294
377
|
# key directly inside a [refs."host/owner/repo"] table to override it just for
|
|
@@ -319,39 +402,115 @@ sync_ttl = "1h"
|
|
|
319
402
|
# tag_format = "v{version}"
|
|
320
403
|
# # Per-ref overrides of [settings] go in the same table, e.g.:
|
|
321
404
|
# # clone_mode = "full"
|
|
322
|
-
`.replaceAll(`{{CLI_VERSION}}`,t)),`seeded`),V=e=>{let t=fe(e.REFS_HOME??h(ge(),`.kaisers-io`,`refs`));return{cacheDir:h(t,`cache`),configPath:h(t,`config.toml`),hooksDir:h(t,`hooks`),locksDir:h(t,`locks`),root:t,sourcesDir:h(t,`sources`),statePath:h(t,`state.json`),updateCachePath:h(t,`cache`,`update-check.json`)}},
|
|
323
|
-
`));return{ok:!0,patterns:r,unparsed:
|
|
324
|
-
`),
|
|
325
|
-
`));return
|
|
326
|
-
`)[0]??t;return n.length<=200?n:`${n.slice(0,200)}…`}
|
|
327
|
-
`),
|
|
328
|
-
`).map(e=>e.trim()).filter(e=>e!==``),a=r.stdoutTruncated!==!0;return n===void 0?{complete:a,tags:i}:{complete:a&&i.length<=n,tags:i.slice(0,n)}},jf=/\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?/u,Mf=/\d+\.\d+\.\d+/gu,Nf=e=>sl.safeParse(e).success,Pf=e=>{let t=e.match(Mf);return t!==null&&t.length>1},Ff=e=>{let t=jf.exec(e);if(!t||Pf(e))return;let[n]=t,r=e.replace(n,`{version}`);if(Nf(r))return r},If=(e,t,n)=>{let r=e.get(t);r===void 0?e.set(t,{count:1,index:n}):r.count+=1},Lf=e=>{let t=new Map;for(let[n,r]of e.entries()){let e=Ff(r);e&&If(t,e,n)}return t},Rf=(e,t)=>e.count>t.count||e.count===t.count&&e.index<t.index,zf=e=>{let t=[...e.entries()],[n]=t;if(n===void 0)return null;let[r,i]=n;return t.slice(1).reduce(({format:e,data:t},[n,r])=>Rf(r,t)?{data:r,format:n}:{data:t,format:e},{data:i,format:r}).format},Bf=e=>{let t=Lf(e);return zf(t)},Vf=(e,t)=>e.replaceAll(`{version}`,()=>t),Hf=async(e,t,n,r)=>{let i=Vf(n,r);if(!await Df(e,t,i))throw L(`tag '${i}' not found in ${t} — check the version or tag_format`);return i},Uf=/^\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.+-]+)?$/u,Wf=/[0-9.]$/u,Gf=[`@`,`-`,`_`,`/`],Kf=`{version}`,qf=(e,t)=>Gf.some(n=>e===`${t}${n}`||e===`${t}${n}v`),Jf=(e,t)=>qf(e.slice(0,e.length-9),t)&&e.endsWith(Kf),Yf=(e,t)=>t!==void 0&&qf(e,t)?2:+(e===``||e===`v`),Xf=(e,t)=>{if(!e.endsWith(t))return;let n=e.slice(0,e.length-t.length);return Wf.test(n)?void 0:n},Zf=(e,t,n)=>{let r=Xf(e,t);if(r===void 0)return;let i=sl.safeParse(`${r}${Kf}`);if(i.success&&Vf(i.data,t)===e)return{format:i.data,rank:Yf(r,n)}},Qf=e=>{let t=e.filter(e=>e.rank>0),n=t.reduce((e,t)=>Math.max(e,t.rank),0),r=new Set(t.filter(e=>e.rank===n).map(e=>e.format)),[i]=[...r];return r.size===1&&i!==void 0?i:null},$f=(e,t,n)=>t.length>64||!Uf.test(t)?null:Qf(e.map(e=>Zf(e,t,n)).filter(e=>e!==void 0)),ep=e=>e.split(`/`).some(e=>e===`.`||e===`..`),tp=e=>e.includes(`\\`),np=e=>e.includes(`%`),rp=/[\u0000-\u001F\u007F]/u,ip=/^ | $/u,ap=/[?#]/u,op=(e,t)=>`not a supported git url: control character ${`U+${(e.codePointAt(t)??0).toString(16).toUpperCase().padStart(4,`0`)}`} at position ${String(t)}`,sp=(e,t)=>{let n=e.search(rp);if(n!==-1)throw z(op(e,n));if(ip.test(e))throw z(`not a supported git url: leading or trailing space`);if(ap.test(e))throw z(`not a supported git url: query or fragment in ${W(t)}`);cp(e,t),lp(e,t)},cp=(e,t)=>{if(tp(e))throw z(`not a supported git url: backslash not allowed in ${W(t)}`)},lp=(e,t)=>{if(ep(e))throw z(`not a supported git url: path traversal segment in ${W(t)}`)},up=(e,t,n)=>{if(e.protocol!==`file:`&&np(t))throw z(`not a supported git url: percent-encoding not supported in ${W(n)}`)},dp=/\.git$/u,fp=e=>e.replace(dp,``),pp=e=>{let t=0,n=e.length;for(;t<n&&e.charAt(t)===`/`;)t+=1;for(;n>t&&e.charAt(n-1)===`/`;)--n;return e.slice(t,n)},mp=/^git@(?<host>[^:/\s]+):(?<path>[^\s]+)$/u,hp=/^git\+/u,gp={"https:":`443`,"ssh:":`22`},_p=e=>{let t=nl.safeParse(e);if(!t.success)throw z(`not a supported git url: derived key '${W(e)}' is invalid`);return t.data},vp=({host:e,port:t,protocol:n})=>{let r=gp[n];return t===``||t===r?e.toLowerCase():`${e.toLowerCase()}_${t}`},yp=e=>{let t=fp(pp(e.path));return _p(`${vp(e)}/${t}`)},bp=e=>{let t=decodeURIComponent(e).split(`/`).filter(e=>e!==``);if(t.length<2)throw z(`not a supported git url: file url path must have at least 2 segments`);let n=t.at(-2)??``,r=t.at(-1)??``;return _p(`local/${n}/${r}`)},xp=(e,t)=>{try{return new URL(e)}catch{throw z(`not a supported git url: ${W(t)}`)}},Sp=e=>{if(e.password!==``)throw z(`not a supported git url: credentials embedded in url`);if(e.protocol===`https:`&&e.username!==``)throw z(`not a supported git url: credentials embedded in https url`)},Cp=(e,t)=>{if(e.protocol===`file:`){if(!t)throw z(`not a supported git url: unsupported protocol ${e.protocol}`);return bp(e.pathname)}if(e.protocol!==`https:`&&e.protocol!==`ssh:`)throw z(`not a supported git url: unsupported protocol ${e.protocol}`);return Sp(e),yp({host:e.hostname,path:e.pathname,port:e.port,protocol:e.protocol})},wp=(e,t)=>{if(np(e))throw z(`not a supported git url: percent-encoding not supported in ${W(t)}`);if(e.includes(`:`))throw z(`not a supported git url: ambiguous ':' in scp-style path ${W(t)}; use the ssh:// url form instead`);if(e.startsWith(`/`)||e.startsWith(`~`))throw z(`not a supported git url: ambiguous absolute/home-relative scp path in ${W(t)}; use the ssh:// url form instead`)},Tp=(e,t)=>{let n=e.groups?.path??``;return wp(n,t),yp({host:e.groups?.host??``,path:n,port:``,protocol:`ssh:`})},Ep=(e,t)=>{let n=t?.allowFileUrls??!1,r=e.replace(hp,``);sp(r,e);let i=mp.exec(r);if(i?.groups!==void 0)return{cloneUrl:r,key:Tp(i,e)};let a=xp(r,e);return up(a,r,e),{cloneUrl:r,key:Cp(a,n)}},Dp=`.git`,Op=e=>e.endsWith(Dp)?e:`${e}${Dp}`,kp=(e,t)=>`https://${e.toLowerCase()}/${pp(t)}`,Ap=(e,t)=>`git@${e.toLowerCase()}:${Op(pp(t))}`,jp=e=>{if(e===`https:`)return`https`;if(e===`ssh:`)return`ssh`;throw z(`not a supported git url: unsupported protocol ${e}`)},Mp=(e,t,n)=>{let r=gp[e.protocol];if(e.port!==``&&e.port!==r)throw z(`cannot apply git_transport=${t} to ${W(n)}: its non-default port ${e.port} cannot be expressed in the ${t} url form — add the repo with an explicit url instead`)},Np=(e,t)=>t===`https`?kp(e.hostname,e.pathname):Ap(e.hostname,e.pathname),Pp=(e,t,n)=>{let r=Ep(t).key;if(r!==n)throw z(`git_transport transform changed repo identity: '${W(e)}' → '${t}' (key '${n}' → '${r}')`);return t},Fp=(e,t)=>{if(t.transport===`ssh`)return t.cloneUrl;let n=e.groups?.host??``,r=e.groups?.path??``;return Pp(t.cloneUrl,kp(n,r),t.originalKey)},Ip=e=>{let t=xp(e.cloneUrl,e.cloneUrl);return jp(t.protocol)===e.transport?e.cloneUrl:(Mp(t,e.transport,e.cloneUrl),Pp(e.cloneUrl,Np(t,e.transport),e.originalKey))},Lp=(e,t)=>{if(e.startsWith(`file:`))return e;let n={cloneUrl:e,originalKey:Ep(e).key,transport:t},r=mp.exec(e);return r?.groups===void 0?Ip(n):Fp(r,n)},Rp=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/u,zp=(e,t)=>{if(Rp.test(t))return h(e,`lease-${t}`)},Bp=async(e,t)=>{let n=zp(e,t);n!==void 0&&await(await o(n,`w`,384)).close()},Vp=async(e,t)=>{let n=zp(e,t);if(n===void 0)return`gone`;let r=new Date;try{await ee(n,r,r)}catch(e){if(F(e))return`gone`;throw e}return`renewed`},Hp=async(e,t)=>{let n=zp(e,t);if(n===void 0)return{state:`absent`};try{return{mtimeMs:(await p(n)).mtimeMs,state:`ok`}}catch(e){return{state:F(e)?`absent`:`unreadable`}}},Up=`meta.json`,Wp=e=>{try{return process.kill(e,0),!0}catch(e){return ru(e)!==`ESRCH`}},Gp=e=>{try{return JSON.parse(e)}catch{return}},Kp=async e=>{try{return await s(e,`utf8`)}catch{return}},qp=new Set([`ENOENT`,`ENOTDIR`]),Jp=async e=>{try{return{state:`read`,text:await s(e,`utf8`)}}catch(e){let t=ru(e);return{state:t!==void 0&&qp.has(t)?`missing`:`unreadable`}}},Yp=e=>{if(typeof e!=`string`)return;let t=Date.parse(e);if(!Number.isNaN(t))return t},Xp=e=>{if(typeof e!=`object`||!e)return;let{token:t}=e;if(typeof t==`string`)return t},Zp=e=>{if(!(typeof e!=`number`||!Number.isSafeInteger(e)||e<=0||e>2147483647))return e},Qp=e=>{if(typeof e!=`object`||!e)return;let t=e,n=Zp(t.pid),r=Yp(t.acquired_at);if(n===void 0||r===void 0)return;let i=Xp(e);return{acquiredAtMs:r,pid:n,...i===void 0?{}:{token:i}}},$p=async e=>{let t=await Kp(h(e,Up));if(t!==void 0)return Xp(Gp(t))},em=async e=>{let t=await Jp(h(e,Up));if(t.state!==`read`)return{state:t.state};let n=Qp(Gp(t.text));return n===void 0?{state:`malformed`}:{meta:n,state:`valid`}},tm=async e=>{try{return{mtimeMs:(await p(e)).mtimeMs,state:`ok`}}catch(e){return{state:ru(e)===`ENOENT`?`gone`:`unreadable`}}},nm=async(e,t)=>{let n=h(e,Up),r=`${n}.tmp-${he()}`;await te(r,t,{encoding:`utf8`,mode:384}),await u(r,n)},rm=()=>he(),im=async(e,t)=>{await Bp(e,t),await nm(e,JSON.stringify({acquired_at:new Date().toISOString(),pid:process.pid,token:t}))},am=5e3,om=async(e,t,n)=>{if(t===`unreadable`)return{meta:t,observedAtMs:n,pidState:`unknown`,policy:`unknown`,stale:!1};let r=await tm(e);if(r.state===`gone`)return{meta:t,observedAtMs:n,pidState:`unknown`,policy:`none`,stale:!1};if(r.state===`unreadable`)return{meta:t,observedAtMs:n,pidState:`unknown`,policy:`unknown`,stale:!1};let i=n-r.mtimeMs;return{ageMs:i,budgetMs:am,meta:t,observedAtMs:n,pidState:`unknown`,policy:`grace`,stale:i>am}},sm=async(e,t,n)=>{let r=t.token===void 0?{state:`absent`}:await Hp(e,t.token);return r.state===`unreadable`?{policy:`unknown`}:r.state===`absent`?{ageMs:n-t.acquiredAtMs,budgetMs:6e5,policy:`legacy`}:{ageMs:n-r.mtimeMs,budgetMs:12e4,policy:`lease`}},cm=async(e,t)=>{let n=await em(e);if(n.state!==`valid`)return om(e,n.state,t);let{meta:r}=n,i=await sm(e,r,t),a=!Wp(r.pid),o=i.ageMs!==void 0&&i.budgetMs!==void 0&&i.ageMs>i.budgetMs;return{...i,meta:`valid`,observedAtMs:t,pid:r.pid,pidState:a?`definitely-dead`:`present-or-unknown`,stale:a||o,...r.token===void 0?{}:{token:r.token}}},lm=e=>e.meta===`valid`&&e.pidState===`definitely-dead`&&e.token!==void 0,um=async(e,t)=>await $p(e)===t?await Vp(e,t)===`gone`?`lost`:`renewed`:`lost`,dm=new Set([`EEXIST`,`EPERM`,`EACCES`,`EBUSY`]),fm=new Set([`ENOENT`,`EPERM`,`EACCES`,`EBUSY`]),pm=async e=>{try{return await a(e,{mode:448,recursive:!1}),!0}catch(e){let t=ru(e);if(t!==void 0&&dm.has(t))return!1;throw e}},mm=async(e,t)=>{try{return await u(e,t),!0}catch(e){let t=ru(e);if(t!==void 0&&fm.has(t))return!1;throw e}},hm=e=>a(e,{mode:448,recursive:!0}),gm=`.claims`,_m=`.tombstones`,vm=(e,t)=>({lockPath:h(e,t),locksDir:e,name:t}),ym=e=>h(e.locksDir,gm,e.name),bm=e=>h(e.locksDir,_m,he()),xm=async e=>{await a(h(e,gm),{mode:448,recursive:!0}),await a(h(e,_m),{mode:448,recursive:!0})},Sm=e=>pm(e),Cm=async e=>{try{await f(e)}catch{}},wm=async e=>{let t=bm(e);return await mm(e.lockPath,t)?t:void 0},Tm=async e=>{let t=await cm(e.lockPath,Date.now());if(!lm(t)||await $p(e.lockPath)!==t.token)return!1;let n=await wm(e);return n!==void 0&&(await d(n,{force:!0,recursive:!0}),!0)},Em=async e=>{await xm(e.locksDir);let t=ym(e);if(!await Sm(t))return!1;let n=await Tm(e).then(e=>({ok:!0,stolen:e}),e=>({error:e,ok:!1}));if(await Cm(t),!n.ok)throw n.error;return n.stolen},Dm=async e=>{try{return(await c(e,{withFileTypes:!0})).map(e=>({isDir:e.isDirectory(),name:e.name})).toSorted((e,t)=>e.name.localeCompare(t.name))}catch(e){if(F(e))return[];throw e}},Om=async e=>(await Dm(e)).filter(e=>!e.name.startsWith(`.`)),km=async(e,t,n)=>{let r=await cm(h(e,t.name),n);if(r.policy!==`none`)return{diagnosis:r,isDirectory:t.isDir,kind:`lock`,name:t.name}},Am=async(e,t)=>{let n=h(e,gm),r=await Dm(n);return(await Promise.all(r.map(async e=>({diagnosis:await cm(h(n,e.name),t),isDirectory:e.isDir,kind:`claim`,name:e.name})))).filter(e=>e.diagnosis.policy!==`none`)},jm=async e=>{let t=Date.now(),n=await Om(e.locksDir),[r,i]=await Promise.all([Promise.all(n.map(n=>km(e.locksDir,n,t))),Am(e.locksDir,t)]);return[...r.filter(e=>e!==void 0),...i]},Mm=e=>{let t=Math.floor(e/1e3),n=t%60,r=Math.floor(t/60),i=r%60,a=Math.floor(r/60);return a>0?i===0?`${a}h`:`${a}h ${i}m`:r>0?n===0?`${r}m`:`${r}m ${n}s`:`${n}s`},Nm=e=>e.pid===void 0?`owner unknown (metadata ${e.meta})`:e.pidState===`definitely-dead`?`recorded pid ${e.pid} is not running`:`recorded pid ${e.pid} is present (identity not verified)`,Pm={grace:`created`,lease:`lease renewed`,legacy:`acquired`,none:`observed`,unknown:`observed`},Fm={grace:`from creation, while its metadata has not been published`,lease:`from the last renewal`,legacy:`from acquisition (no renewable lease)`,none:``,unknown:``},Im=e=>{let{ageMs:t,budgetMs:n,policy:r}=e;return t===void 0||n===void 0?``:t<0?`, but its recorded time is in the future — check the system clock`:`, ${Pm[r]} ${Mm(t)} ago; its window is ${Mm(n)} ${Fm[r]}`},Lm=(e,t)=>{if(t.policy===`none`)return`lock ${e} could not be acquired before the timeout, but it was released while the failure was being diagnosed. Retry the operation.`;let n=`lock ${e} is held: ${Nm(t)}`;return lm(t)?`${n}, and refs is entitled to reclaim it — it could not do so before the timeout. Retry; if it persists, run refs doctor.`:t.stale?`${n}${Im(t)}. refs does not reclaim this automatically: only a recorded process the operating system reports as gone is reclaimed, and this one is not. Run refs doctor for what to do about it.`:`${n}${Im(t)}. Retry once the other refs command finishes.`},Rm=(e,t)=>{if(t.stopped)return;let n=setTimeout(()=>{t.stopped||(t.inFlight=zm(e,t))},e.intervalMs);n.unref(),t.timer=n},zm=async(e,t)=>{try{if(await e.renew()===`lost`){t.lost=!0,t.stopped=!0;return}}catch{}Rm(e,t)},Bm=e=>{let t={inFlight:Promise.resolve(),lost:!1,stopped:!1};return Rm(e,t),{ownershipLost:()=>t.lost,stop:async()=>{t.stopped=!0,t.timer!==void 0&&clearTimeout(t.timer),await t.inFlight}}},Vm=/^[a-zA-Z0-9][a-zA-Z0-9_.-]*$/u,Hm=async(e,t)=>{try{await im(e,t)}catch(e){if(ru(e)===`ENOENT`)return`retry`;throw e}return t},Um=async(e,t)=>{if(!await pm(e))return;let n=await Hm(e,rm());return n===`retry`?Date.now()>=t?void 0:Um(e,t):n},Wm=async(e,t)=>{if(!await Em(e)){if(Date.now()>=t){let t=await cm(e.lockPath,Date.now());throw su(Lm(e.name,t))}await xe(100)}},Gm=async(e,t)=>{let n=await Um(e.lockPath,t);return n===void 0?(await Wm(e,t),Gm(e,t)):n},Km=async(e,t)=>await $p(e)===t&&(await d(e,{force:!0,recursive:!0}),!0),qm=async e=>{try{return{ok:!0,value:await e()}}catch(e){return{error:e,ok:!1}}},Jm=async(e,t,n,r)=>{await n.stop();let i=await qm(()=>Km(e.lockPath,t));if(!r.ok)throw r.error;if(!i.ok)throw i.error;if(n.ownershipLost()||!i.value)throw su(`lock ${e.name} was lost while the operation was running`);return r.value},Ym=e=>e!==`.`&&e!==`..`&&Vm.test(e),Xm=e=>{if(!Ym(e))throw z(`lock name must not contain "/" or other unsafe characters — only letters, digits, and "_.-" are allowed, and it may not be "." or "..": ${e}`)},G=async(e,t,n,r)=>{Xm(t);let i=vm(e.locksDir,t);await hm(e.locksDir);let a=Date.now()+(r?.timeoutMs??1e4),o=await Gm(i,a),s=Bm({intervalMs:3e4,renew:()=>um(i.lockPath,o)});return Jm(i,o,s,await qm(n))},Zm=sc({directory:j().optional(),url:j().optional()}),Qm=sc({repository:lc([j(),Zm]).optional()}),$m=/^(?:@[a-z0-9-~][a-z0-9._~-]*\/)?[a-z0-9-~][a-z0-9._~-]*$/u,eh=new Set([`node_modules`,`favicon.ico`]),th=e=>L(`package '${e}' has no usable repository field — find the repository and run: refs add <git-url>`),nh=e=>{let[t,n]=e.split(`/`);return n??t??e},rh=e=>{if(e.length>214)throw R(`invalid package name: '${e}' exceeds maximum length of 214 characters`);if(!$m.test(e))throw R(`invalid package name: '${e}' does not match npm naming rules`);let t=nh(e);if(eh.has(t))throw R(`invalid package name: '${e}' uses a reserved name`)},ih=e=>e.replaceAll(`/`,`%2F`),ah=e=>typeof e==`string`?e:e?.url,oh=e=>{if(typeof e==`object`&&e?.directory){let t=cl.safeParse(e.directory);if(t.success)return t.data}},sh=e=>e instanceof Error&&(e.name===`TimeoutError`||e.name===`AbortError`),ch=e=>z(`npm registry did not answer for '${e}' within 10000ms`),lh=async(e,t)=>{try{return await e.json()}catch(e){throw sh(e)?ch(t):z(`invalid npm registry response for '${t}': not parseable JSON`)}},uh=async(e,t)=>{try{return await e(`https://registry.npmjs.org/${ih(t)}`,{signal:AbortSignal.timeout(1e4)})}catch(e){throw sh(e)?ch(t):e}},dh=async(e,t)=>{let n=await uh(e,t);if(n.status===404)throw L(`npm package '${t}' not found`);if(n.status!==200)throw z(`failed to fetch npm package '${t}': status ${n.status}`);let r=await lh(n,t),i=Qm.safeParse(r);if(!i.success)throw z(`invalid npm package response for '${t}'`);return i.data},fh=(e,t)=>{try{return Ep(e)}catch{throw th(t)}},ph=async(e,t)=>{rh(t);let n=await dh(e,t),r=ah(n.repository);if(r===void 0||r===``)throw th(t);let{cloneUrl:i,key:a}=fh(r,t),o=oh(n.repository);return o===void 0?{cloneUrl:i,key:a}:{cloneUrl:i,directory:o,key:a}},mh=(e,t,n)=>{let r=e instanceof RegExp?hh(e,n):e,i=t instanceof RegExp?hh(t,n):t,a=r!==null&&i!=null&&gh(r,i,n);return a&&{start:a[0],end:a[1],pre:n.slice(0,a[0]),body:n.slice(a[0]+r.length,a[1]),post:n.slice(a[1]+i.length)}},hh=(e,t)=>{let n=t.match(e);return n?n[0]:null},gh=(e,t,n)=>{let r,i,a,o,s,c=n.indexOf(e),l=n.indexOf(t,c+1),u=c;if(c>=0&&l>0){if(e===t)return[c,l];for(r=[],a=n.length;u>=0&&!s;){if(u===c)r.push(u),c=n.indexOf(e,u+1);else if(r.length===1){let e=r.pop();e!==void 0&&(s=[e,l])}else i=r.pop(),i!==void 0&&i<a&&(a=i,o=l),l=n.indexOf(t,u+1);u=c<l&&c>=0?c:l}r.length&&o!==void 0&&(s=[a,o])}return s},_h=`\0SLASH`+Math.random()+`\0`,vh=`\0OPEN`+Math.random()+`\0`,yh=`\0CLOSE`+Math.random()+`\0`,bh=`\0COMMA`+Math.random()+`\0`,xh=`\0PERIOD`+Math.random()+`\0`,Sh=new RegExp(_h,`g`),Ch=new RegExp(vh,`g`),wh=new RegExp(yh,`g`),Th=new RegExp(bh,`g`),Eh=new RegExp(xh,`g`),Dh=/\\\\/g,Oh=/\\{/g,kh=/\\}/g,Ah=/\\,/g,jh=/\\\./g;function Mh(e){return isNaN(e)?e.charCodeAt(0):parseInt(e,10)}function Nh(e){return e.replace(Dh,_h).replace(Oh,vh).replace(kh,yh).replace(Ah,bh).replace(jh,xh)}function Ph(e){return e.replace(Sh,`\\`).replace(Ch,`{`).replace(wh,`}`).replace(Th,`,`).replace(Eh,`.`)}function Fh(e){if(!e)return[``];let t=[],n=mh(`{`,`}`,e);if(!n)return e.split(`,`);let{pre:r,body:i,post:a}=n,o=r.split(`,`);o[o.length-1]+=`{`+i+`}`;let s=Fh(a);return a.length&&(o[o.length-1]+=s.shift(),o.push.apply(o,s)),t.push.apply(t,o),t}function Ih(e,t={}){if(!e)return[];let{max:n=1e5,maxLength:r=4e6}=t;return e.slice(0,2)===`{}`&&(e=`\\{\\}`+e.slice(2)),Uh(Nh(e),n,r,!0).map(Ph)}function Lh(e){return`{`+e+`}`}function Rh(e){return/^-?0\d/.test(e)}function zh(e,t){return e<=t}function Bh(e,t){return e>=t}function Vh(e,t,n,r,i,a){let o=[],s=0;for(let c=0;c<e.length;c++)for(let l=0;l<n.length;l++){if(o.length>=r)return o;let u=e[c]+t+n[l];if(!a||u){if(s+u.length>i)return o;o.push(u),s+=u.length}}return o}function Hh(e,t,n,r){let i=e.split(/\.\./),a=[];if(i[0]===void 0||i[1]===void 0)return a;let o=Mh(i[0]),s=Mh(i[1]),c=Math.max(i[0].length,i[1].length),l=i.length===3&&i[2]!==void 0?Math.max(Math.abs(Mh(i[2])),1):1,u=zh;s<o&&(l*=-1,u=Bh);let d=i.some(Rh),f=0;for(let e=o;u(e,s)&&a.length<n;e+=l){let n;if(t)n=String.fromCharCode(e),n===`\\`&&(n=``);else if(n=String(e),d){let t=c-n.length;if(t>0){let r=Array(t+1).join(`0`);n=e<0?`-`+r+n.slice(1):r+n}}if(f+n.length>r)break;a.push(n),f+=n.length}return a}function Uh(e,t,n,r){let i=[``],a=!1,o=!0;for(;;){let s=mh(`{`,`}`,e);if(!s)return Vh(i,e,[``],t,n,a);let c=s.pre;if(/\$$/.test(c)){if(i=Vh(i,c+`{`+s.body+`}`,[``],t,n,a&&!s.post.length),o=!1,!s.post.length)break;e=s.post;continue}let l=/^-?\d+\.\.-?\d+(?:\.\.-?\d+)?$/.test(s.body),u=/^[a-zA-Z]\.\.[a-zA-Z](?:\.\.-?\d+)?$/.test(s.body),d=l||u,f=s.body.indexOf(`,`)>=0;if(!d&&!f){if(s.post.match(/,(?!,).*\}/)){e=s.pre+`{`+s.body+yh+s.post,r=!0;continue}return Vh(i,c+`{`+s.body+`}`+s.post,[``],t,n,a)}o&&=(a=r&&!d,!1);let p;if(d)p=Hh(s.body,u,t,n);else{let r=Fh(s.body);if(r.length===1&&r[0]!==void 0&&(r=Uh(r[0],t,n,!1).map(Lh),r.length===1)){if(i=Vh(i,c+r[0],[``],t,n,a&&!s.post.length),!s.post.length)break;e=s.post;continue}let o=a&&!s.post.length&&!c;for(let e=0;o&&e<i.length;e++)i[e]&&(o=!1);p=[];let l=0;outer:for(let e=0;e<r.length;e++){let i=Uh(r[e],t,n,!1);for(let e=0;e<i.length;e++){let r=i[e];if(!o||r){if(p.length>=t||l+r.length>n)break outer;p.push(r),l+=r.length}}}}if(i=Vh(i,c,p,t,n,a&&!s.post.length),!s.post.length)break;e=s.post}return i}const Wh=e=>{if(typeof e!=`string`)throw TypeError(`invalid pattern`);if(e.length>65536)throw TypeError(`pattern is too long`)},Gh={"[:alnum:]":[`\\p{L}\\p{Nl}\\p{Nd}`,!0],"[:alpha:]":[`\\p{L}\\p{Nl}`,!0],"[:ascii:]":[`\\x00-\\x7f`,!1],"[:blank:]":[`\\p{Zs}\\t`,!0],"[:cntrl:]":[`\\p{Cc}`,!0],"[:digit:]":[`\\p{Nd}`,!0],"[:graph:]":[`\\p{Z}\\p{C}`,!0,!0],"[:lower:]":[`\\p{Ll}`,!0],"[:print:]":[`\\p{C}`,!0],"[:punct:]":[`\\p{P}`,!0],"[:space:]":[`\\p{Z}\\t\\r\\n\\v\\f`,!0],"[:upper:]":[`\\p{Lu}`,!0],"[:word:]":[`\\p{L}\\p{Nl}\\p{Nd}\\p{Pc}`,!0],"[:xdigit:]":[`A-Fa-f0-9`,!1]},Kh=e=>e.replace(/[[\]\\-]/g,`\\$&`),qh=e=>e.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,`\\$&`),Jh=e=>e.join(``),Yh=(e,t)=>{let n=t;if(e.charAt(n)!==`[`)throw Error(`not in a brace expression`);let r=[],i=[],a=n+1,o=!1,s=!1,c=!1,l=!1,u=n,d=``;WHILE:for(;a<e.length;){let t=e.charAt(a);if((t===`!`||t===`^`)&&a===n+1){l=!0,a++;continue}if(t===`]`&&o&&!c){u=a+1;break}if(o=!0,t===`\\`&&!c){c=!0,a++;continue}if(t===`[`&&!c){for(let[t,[o,c,l]]of Object.entries(Gh))if(e.startsWith(t,a)){if(d)return[`$.`,!1,e.length-n,!0];a+=t.length,l?i.push(o):r.push(o),s||=c;continue WHILE}}if(c=!1,d){t>d?r.push(Kh(d)+`-`+Kh(t)):t===d&&r.push(Kh(t)),d=``,a++;continue}if(e.startsWith(`-]`,a+1)){r.push(Kh(t+`-`)),a+=2;continue}if(e.startsWith(`-`,a+1)){d=t,a+=2;continue}r.push(Kh(t)),a++}if(u<a)return[``,!1,0,!1];if(!r.length&&!i.length)return[`$.`,!1,e.length-n,!0];if(i.length===0&&r.length===1&&/^\\?.$/.test(r[0])&&!l){let e=r[0].length===2?r[0].slice(-1):r[0];return[qh(e),!1,u-n,!1]}let f=`[`+(l?`^`:``)+Jh(r)+`]`,p=`[`+(l?``:`^`)+Jh(i)+`]`;return[r.length&&i.length?`(`+f+`|`+p+`)`:r.length?f:p,s,u-n,!0]},Xh=(e,{windowsPathsNoEscape:t=!1,magicalBraces:n=!0}={})=>n?t?e.replace(/\[([^/\\])\]/g,`$1`):e.replace(/((?!\\).|^)\[([^/\\])\]/g,`$1$2`).replace(/\\([^/])/g,`$1`):t?e.replace(/\[([^/\\{}])\]/g,`$1`):e.replace(/((?!\\).|^)\[([^/\\{}])\]/g,`$1$2`).replace(/\\([^/{}])/g,`$1`);var K;const Zh=new Set([`!`,`?`,`+`,`*`,`@`]),Qh=e=>Zh.has(e),$h=e=>Qh(e.type),eg=new Map([[`!`,[`@`]],[`?`,[`?`,`@`]],[`@`,[`@`]],[`*`,[`*`,`+`,`?`,`@`]],[`+`,[`+`,`@`]]]),tg=new Map([[`!`,[`?`]],[`@`,[`?`]],[`+`,[`?`,`*`]]]),ng=new Map([[`!`,[`?`,`@`]],[`?`,[`?`,`@`]],[`@`,[`?`,`@`]],[`*`,[`*`,`+`,`?`,`@`]],[`+`,[`+`,`@`,`?`,`*`]]]),rg=new Map([[`!`,new Map([[`!`,`@`]])],[`?`,new Map([[`*`,`*`],[`+`,`*`]])],[`@`,new Map([[`!`,`!`],[`?`,`?`],[`@`,`@`],[`*`,`*`],[`+`,`+`]])],[`+`,new Map([[`?`,`*`],[`*`,`*`]])]]),ig=`(?!\\.)`,ag=new Set([`[`,`.`]),og=new Set([`..`,`.`]),sg=new Set(`().*{}+?[]^$\\!`),cg=e=>e.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,`\\$&`),lg=`[^/]+?`;let ug=0;var dg=class{type;#e;#t;#n=!1;#r=[];#i;#a;#o;#s=!1;#c;#l;#u=!1;id=++ug;get depth(){return(this.#i?.depth??-1)+1}[Symbol.for(`nodejs.util.inspect.custom`)](){return{"@@type":`AST`,id:this.id,type:this.type,root:this.#e.id,parent:this.#i?.id,depth:this.depth,partsLength:this.#r.length,parts:this.#r}}constructor(e,t,n={}){this.type=e,e&&(this.#t=!0),this.#i=t,this.#e=this.#i?this.#i.#e:this,this.#c=this.#e===this?n:this.#e.#c,this.#o=this.#e===this?[]:this.#e.#o,e===`!`&&!this.#e.#s&&this.#o.push(this),this.#a=this.#i?this.#i.#r.length:0}get hasMagic(){if(this.#t!==void 0)return this.#t;for(let e of this.#r)if(typeof e!=`string`&&(e.type||e.hasMagic))return this.#t=!0;return this.#t}toString(){return this.#l===void 0?this.#l=this.type?this.type+`(`+this.#r.map(e=>String(e)).join(`|`)+`)`:this.#r.map(e=>String(e)).join(``):this.#l}#d(){if(this!==this.#e)throw Error(`should only call on root`);if(this.#s)return this;this.toString(),this.#s=!0;let e;for(;e=this.#o.pop();){if(e.type!==`!`)continue;let t=e,n=t.#i;for(;n;){for(let r=t.#a+1;!n.type&&r<n.#r.length;r++)for(let t of e.#r){if(typeof t==`string`)throw Error(`string part in extglob AST??`);t.copyIn(n.#r[r])}t=n,n=t.#i}}return this}push(...e){for(let t of e)if(t!==``){if(typeof t!=`string`&&!(t instanceof K&&t.#i===this))throw Error(`invalid part: `+t);this.#r.push(t)}}toJSON(){let e=this.type===null?this.#r.slice().map(e=>typeof e==`string`?e:e.toJSON()):[this.type,...this.#r.map(e=>e.toJSON())];return this.isStart()&&!this.type&&e.unshift([]),this.isEnd()&&(this===this.#e||this.#e.#s&&this.#i?.type===`!`)&&e.push({}),e}isStart(){if(this.#e===this)return!0;if(!this.#i?.isStart())return!1;if(this.#a===0)return!0;let e=this.#i;for(let t=0;t<this.#a;t++){let n=e.#r[t];if(!(n instanceof K&&n.type===`!`))return!1}return!0}isEnd(){if(this.#e===this||this.#i?.type===`!`)return!0;if(!this.#i?.isEnd())return!1;if(!this.type)return this.#i?.isEnd();let e=this.#i?this.#i.#r.length:0;return this.#a===e-1}copyIn(e){typeof e==`string`?this.push(e):this.push(e.clone(this))}clone(e){let t=new K(this.type,e);for(let e of this.#r)t.copyIn(e);return t}static#f(e,t,n,r,i){let a=r.maxExtglobRecursion??2,o=!1,s=!1,c=-1,l=!1;if(t.type===null){let u=n,d=``;for(;u<e.length;){let n=e.charAt(u++);if(o||n===`\\`){o=!o,d+=n;continue}if(s){u===c+1?(n===`^`||n===`!`)&&(l=!0):n===`]`&&!(u===c+2&&l)&&(s=!1),d+=n;continue}if(n===`[`){s=!0,c=u,l=!1,d+=n;continue}if(!r.noext&&Qh(n)&&e.charAt(u)===`(`&&i<=a){t.push(d),d=``;let a=new K(n,t);u=K.#f(e,a,u,r,i+1),t.push(a);continue}d+=n}return t.push(d),u}let u=n+1,d=new K(null,t),f=[],p=``;for(;u<e.length;){let n=e.charAt(u++);if(o||n===`\\`){o=!o,p+=n;continue}if(s){u===c+1?(n===`^`||n===`!`)&&(l=!0):n===`]`&&!(u===c+2&&l)&&(s=!1),p+=n;continue}if(n===`[`){s=!0,c=u,l=!1,p+=n;continue}if(!r.noext&&Qh(n)&&e.charAt(u)===`(`&&(i<=a||t&&t.#h(n))){let a=t&&t.#h(n)?0:1;d.push(p),p=``;let o=new K(n,d);d.push(o),u=K.#f(e,o,u,r,i+a);continue}if(n===`|`){d.push(p),p=``,f.push(d),d=new K(null,t);continue}if(n===`)`)return p===``&&t.#r.length===0&&(t.#u=!0),d.push(p),p=``,t.push(...f,d),u;p+=n}return t.type=null,t.#t=void 0,t.#r=[e.substring(n-1)],u}#p(e){return this.#m(e,tg)}#m(e,t=eg){if(!e||typeof e!=`object`||e.type!==null||e.#r.length!==1||this.type===null)return!1;let n=e.#r[0];return!n||typeof n!=`object`||n.type===null?!1:this.#h(n.type,t)}#h(e,t=ng){return!!t.get(this.type)?.includes(e)}#g(e,t){let n=e.#r[0],r=new K(null,n,this.options);r.#r.push(``),n.push(r),this.#_(e,t)}#_(e,t){let n=e.#r[0];this.#r.splice(t,1,...n.#r);for(let e of n.#r)typeof e==`object`&&(e.#i=this);this.#l=void 0}#v(e){return!!rg.get(this.type)?.has(e)}#y(e){if(!e||typeof e!=`object`||e.type!==null||e.#r.length!==1||this.type===null||this.#r.length!==1)return!1;let t=e.#r[0];return!t||typeof t!=`object`||t.type===null?!1:this.#v(t.type)}#b(e){let t=rg.get(this.type),n=e.#r[0],r=t?.get(n.type);if(!r)return!1;this.#r=n.#r;for(let e of this.#r)typeof e==`object`&&(e.#i=this);this.type=r,this.#l=void 0,this.#u=!1}static fromGlob(e,t={}){let n=new K(null,void 0,t);return K.#f(e,n,0,t,0),n}toMMPattern(){if(this!==this.#e)return this.#e.toMMPattern();let e=this.toString(),[t,n,r,i]=this.toRegExpSource();if(!(r||this.#t||this.#c.nocase&&!this.#c.nocaseMagicOnly&&e.toUpperCase()!==e.toLowerCase()))return n;let a=(this.#c.nocase?`i`:``)+(i?`u`:``);return Object.assign(RegExp(`^${t}$`,a),{_src:t,_glob:e})}get options(){return this.#c}toRegExpSource(e){let t=e??!!this.#c.dot;if(this.#e===this&&(this.#x(),this.#d()),!$h(this)){let n=this.isStart()&&this.isEnd()&&!this.#r.some(e=>typeof e!=`string`),r=this.#r.map(t=>{let[r,i,a,o]=typeof t==`string`?K.#C(t,this.#t,n):t.toRegExpSource(e);return this.#t=this.#t||a,this.#n=this.#n||o,r}).join(``),i=``;if(this.isStart()&&typeof this.#r[0]==`string`&&!(this.#r.length===1&&og.has(this.#r[0]))){let n=ag,a=t&&n.has(r.charAt(0))||r.startsWith(`\\.`)&&n.has(r.charAt(2))||r.startsWith(`\\.\\.`)&&n.has(r.charAt(4)),o=!t&&!e&&n.has(r.charAt(0));i=a?`(?!(?:^|/)\\.\\.?(?:$|/))`:o?ig:``}let a=``;return this.isEnd()&&this.#e.#s&&this.#i?.type===`!`&&(a=`(?:$|\\/)`),[i+r+a,Xh(r),this.#t=!!this.#t,this.#n]}let n=this.type===`*`||this.type===`+`,r=this.type===`!`?`(?:(?!(?:`:`(?:`,i=this.#S(t);if(this.isStart()&&this.isEnd()&&!i&&this.type!==`!`){let e=this.toString(),t=this;return t.#r=[e],t.type=null,t.#t=void 0,[e,Xh(this.toString()),!1,!1]}let a=!n||e||t?``:this.#S(!0);a===i&&(a=``),a&&(i=`(?:${i})(?:${a})*?`);let o=``;if(this.type===`!`&&this.#u)o=(this.isStart()&&!t?ig:``)+lg;else{let n=this.type===`!`?`))`+(this.isStart()&&!t&&!e?ig:``)+`[^/]*?)`:this.type===`@`?`)`:this.type===`?`?`)?`:this.type===`+`&&a?`)`:this.type===`*`&&a?`)?`:`)${this.type}`;o=r+i+n}return[o,Xh(i),this.#t=!!this.#t,this.#n]}#x(){if($h(this)){let e=0,t=!1;do{t=!0;for(let e=0;e<this.#r.length;e++){let n=this.#r[e];typeof n==`object`&&(n.#x(),this.#m(n)?(t=!1,this.#_(n,e)):this.#p(n)?(t=!1,this.#g(n,e)):this.#y(n)&&(t=!1,this.#b(n)))}}while(!t&&++e<10)}else for(let e of this.#r)typeof e==`object`&&e.#x();this.#l=void 0}#S(e){return this.#r.map(t=>{if(typeof t==`string`)throw Error(`string type in extglob ast??`);let[n,r,i,a]=t.toRegExpSource(e);return this.#n=this.#n||a,n}).filter(e=>!(this.isStart()&&this.isEnd())||!!e).join(`|`)}static#C(e,t,n=!1){let r=!1,i=``,a=!1,o=!1;for(let s=0;s<e.length;s++){let c=e.charAt(s);if(r){r=!1,i+=(sg.has(c)?`\\`:``)+c;continue}if(c===`*`){if(o)continue;o=!0,i+=n&&/^[*]+$/.test(e)?lg:`[^/]*?`,t=!0;continue}if(o=!1,c===`\\`){s===e.length-1?i+=`\\\\`:r=!0;continue}if(c===`[`){let[n,r,o,c]=Yh(e,s);if(o){i+=n,a||=r,s+=o-1,t||=c;continue}}if(c===`?`){i+=`[^/]`,t=!0;continue}i+=cg(c)}return[i,Xh(e),!!t,a]}};K=dg;const fg=(e,{windowsPathsNoEscape:t=!1,magicalBraces:n=!1}={})=>n?t?e.replace(/[?*()[\]{}]/g,`[$&]`):e.replace(/[?*()[\]\\{}]/g,`\\$&`):t?e.replace(/[?*()[\]]/g,`[$&]`):e.replace(/[?*()[\]\\]/g,`\\$&`),q=(e,t,n={})=>(Wh(t),!n.nocomment&&t.charAt(0)===`#`?!1:new Rg(t,n).match(e)),pg=/^\*+([^+@!?*[(]*)$/,mg=e=>t=>!t.startsWith(`.`)&&t.endsWith(e),hg=e=>t=>t.endsWith(e),gg=e=>(e=e.toLowerCase(),t=>!t.startsWith(`.`)&&t.toLowerCase().endsWith(e)),_g=e=>(e=e.toLowerCase(),t=>t.toLowerCase().endsWith(e)),vg=/^\*+\.\*+$/,yg=e=>!e.startsWith(`.`)&&e.includes(`.`),bg=e=>e!==`.`&&e!==`..`&&e.includes(`.`),xg=/^\.\*+$/,Sg=e=>e!==`.`&&e!==`..`&&e.startsWith(`.`),Cg=/^\*+$/,wg=e=>e.length!==0&&!e.startsWith(`.`),Tg=e=>e.length!==0&&e!==`.`&&e!==`..`,Eg=/^\?+([^+@!?*[(]*)?$/,Dg=([e,t=``])=>{let n=jg([e]);return t?(t=t.toLowerCase(),e=>n(e)&&e.toLowerCase().endsWith(t)):n},Og=([e,t=``])=>{let n=Mg([e]);return t?(t=t.toLowerCase(),e=>n(e)&&e.toLowerCase().endsWith(t)):n},kg=([e,t=``])=>{let n=Mg([e]);return t?e=>n(e)&&e.endsWith(t):n},Ag=([e,t=``])=>{let n=jg([e]);return t?e=>n(e)&&e.endsWith(t):n},jg=([e])=>{let t=e.length;return e=>e.length===t&&!e.startsWith(`.`)},Mg=([e])=>{let t=e.length;return e=>e.length===t&&e!==`.`&&e!==`..`},Ng=typeof process==`object`&&process?typeof process.env==`object`&&process.env&&process.env.__MINIMATCH_TESTING_PLATFORM__||process.platform:`posix`,Pg={win32:{sep:`\\`},posix:{sep:`/`}};q.sep=Ng===`win32`?Pg.win32.sep:Pg.posix.sep;const J=Symbol(`globstar **`);q.GLOBSTAR=J,q.filter=(e,t={})=>n=>q(n,e,t);const Y=(e,t={})=>Object.assign({},e,t);q.defaults=e=>{if(!e||typeof e!=`object`||!Object.keys(e).length)return q;let t=q;return Object.assign((n,r,i={})=>t(n,r,Y(e,i)),{Minimatch:class extends t.Minimatch{constructor(t,n={}){super(t,Y(e,n))}static defaults(n){return t.defaults(Y(e,n)).Minimatch}},AST:class extends t.AST{constructor(t,n,r={}){super(t,n,Y(e,r))}static fromGlob(n,r={}){return t.AST.fromGlob(n,Y(e,r))}},unescape:(n,r={})=>t.unescape(n,Y(e,r)),escape:(n,r={})=>t.escape(n,Y(e,r)),filter:(n,r={})=>t.filter(n,Y(e,r)),defaults:n=>t.defaults(Y(e,n)),makeRe:(n,r={})=>t.makeRe(n,Y(e,r)),braceExpand:(n,r={})=>t.braceExpand(n,Y(e,r)),match:(n,r,i={})=>t.match(n,r,Y(e,i)),sep:t.sep,GLOBSTAR:J})};const Fg=(e,t={})=>(Wh(e),t.nobrace||!/\{(?:(?!\{).)*\}/.test(e)?[e]:Ih(e,{max:t.braceExpandMax}));q.braceExpand=Fg,q.makeRe=(e,t={})=>new Rg(e,t).makeRe(),q.match=(e,t,n={})=>{let r=new Rg(t,n);return e=e.filter(e=>r.match(e)),r.options.nonull&&!e.length&&e.push(t),e};const Ig=/[?*]|[+@!]\(.*?\)|\[|\]/,Lg=e=>e.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,`\\$&`);var Rg=class{options;set;pattern;windowsPathsNoEscape;nonegate;negate;comment;empty;preserveMultipleSlashes;partial;globSet;globParts;nocase;isWindows;platform;windowsNoMagicRoot;maxGlobstarRecursion;regexp;constructor(e,t={}){Wh(e),t||={},this.options=t,this.maxGlobstarRecursion=t.maxGlobstarRecursion??200,this.pattern=e,this.platform=t.platform||Ng,this.isWindows=this.platform===`win32`,this.windowsPathsNoEscape=!!t.windowsPathsNoEscape||t.allowWindowsEscape===!1,this.windowsPathsNoEscape&&(this.pattern=this.pattern.replace(/\\/g,`/`)),this.preserveMultipleSlashes=!!t.preserveMultipleSlashes,this.regexp=null,this.negate=!1,this.nonegate=!!t.nonegate,this.comment=!1,this.empty=!1,this.partial=!!t.partial,this.nocase=!!this.options.nocase,this.windowsNoMagicRoot=t.windowsNoMagicRoot===void 0?!!(this.isWindows&&this.nocase):t.windowsNoMagicRoot,this.globSet=[],this.globParts=[],this.set=[],this.make()}hasMagic(){if(this.options.magicalBraces&&this.set.length>1)return!0;for(let e of this.set)for(let t of e)if(typeof t!=`string`)return!0;return!1}debug(...e){}make(){let e=this.pattern,t=this.options;if(!t.nocomment&&e.charAt(0)===`#`){this.comment=!0;return}if(!e){this.empty=!0;return}this.parseNegate(),this.globSet=[...new Set(this.braceExpand())],t.debug&&(this.debug=(...e)=>console.error(...e)),this.debug(this.pattern,this.globSet);let n=this.globSet.map(e=>this.slashSplit(e));this.globParts=this.preprocess(n),this.debug(this.pattern,this.globParts);let r=this.globParts.map((e,t,n)=>{if(this.isWindows&&this.windowsNoMagicRoot){let t=e[0]===``&&e[1]===``&&(e[2]===`?`||!Ig.test(e[2]))&&!Ig.test(e[3]),n=/^[a-z]:/i.test(e[0]);if(t)return[...e.slice(0,4),...e.slice(4).map(e=>this.parse(e))];if(n)return[e[0],...e.slice(1).map(e=>this.parse(e))]}return e.map(e=>this.parse(e))});if(this.debug(this.pattern,r),this.set=r.filter(e=>e.indexOf(!1)===-1),this.isWindows)for(let e=0;e<this.set.length;e++){let t=this.set[e];t[0]===``&&t[1]===``&&this.globParts[e][2]===`?`&&typeof t[3]==`string`&&/^[a-z]:$/i.test(t[3])&&(t[2]=`?`)}this.debug(this.pattern,this.set)}preprocess(e){if(this.options.noglobstar)for(let t of e)for(let e=0;e<t.length;e++)t[e]===`**`&&(t[e]=`*`);let{optimizationLevel:t=1}=this.options;return t>=2?(e=this.firstPhasePreProcess(e),e=this.secondPhasePreProcess(e)):e=t>=1?this.levelOneOptimize(e):this.adjascentGlobstarOptimize(e),e}adjascentGlobstarOptimize(e){return e.map(e=>{let t=-1;for(;(t=e.indexOf(`**`,t+1))!==-1;){let n=t;for(;e[n+1]===`**`;)n++;n!==t&&e.splice(t,n-t)}return e})}levelOneOptimize(e){return e.map(e=>(e=e.reduce((e,t)=>{let n=e[e.length-1];return t===`**`&&n===`**`?e:t===`..`&&n&&n!==`..`&&n!==`.`&&n!==`**`?(e.pop(),e):(e.push(t),e)},[]),e.length===0?[``]:e))}levelTwoFileOptimize(e){Array.isArray(e)||(e=this.slashSplit(e));let t=!1;do{if(t=!1,!this.preserveMultipleSlashes){for(let n=1;n<e.length-1;n++){let r=e[n];(n!==1||r!==``||e[0]!==``)&&(r===`.`||r===``)&&(t=!0,e.splice(n,1),n--)}e[0]===`.`&&e.length===2&&(e[1]===`.`||e[1]===``)&&(t=!0,e.pop())}let n=0;for(;(n=e.indexOf(`..`,n+1))!==-1;){let r=e[n-1];r&&r!==`.`&&r!==`..`&&r!==`**`&&!(this.isWindows&&/^[a-z]:$/i.test(r))&&(t=!0,e.splice(n-1,2),n-=2)}}while(t);return e.length===0?[``]:e}firstPhasePreProcess(e){let t=!1;do{t=!1;for(let n of e){let r=-1;for(;(r=n.indexOf(`**`,r+1))!==-1;){let i=r;for(;n[i+1]===`**`;)i++;i>r&&n.splice(r+1,i-r);let a=n[r+1],o=n[r+2],s=n[r+3];if(a!==`..`||!o||o===`.`||o===`..`||!s||s===`.`||s===`..`)continue;t=!0,n.splice(r,1);let c=n.slice(0);c[r]=`**`,e.push(c),r--}if(!this.preserveMultipleSlashes){for(let e=1;e<n.length-1;e++){let r=n[e];(e!==1||r!==``||n[0]!==``)&&(r===`.`||r===``)&&(t=!0,n.splice(e,1),e--)}n[0]===`.`&&n.length===2&&(n[1]===`.`||n[1]===``)&&(t=!0,n.pop())}let i=0;for(;(i=n.indexOf(`..`,i+1))!==-1;){let e=n[i-1];if(e&&e!==`.`&&e!==`..`&&e!==`**`){t=!0;let e=i===1&&n[i+1]===`**`?[`.`]:[];n.splice(i-1,2,...e),n.length===0&&n.push(``),i-=2}}}}while(t);return e}secondPhasePreProcess(e){for(let t=0;t<e.length-1;t++)for(let n=t+1;n<e.length;n++){let r=this.partsMatch(e[t],e[n],!this.preserveMultipleSlashes);if(r){e[t]=[],e[n]=r;break}}return e.filter(e=>e.length)}partsMatch(e,t,n=!1){let r=0,i=0,a=[],o=``;for(;r<e.length&&i<t.length;)if(e[r]===t[i])a.push(o===`b`?t[i]:e[r]),r++,i++;else if(n&&e[r]===`**`&&t[i]===e[r+1])a.push(e[r]),r++;else if(n&&t[i]===`**`&&e[r]===t[i+1])a.push(t[i]),i++;else if(e[r]===`*`&&t[i]&&(this.options.dot||!t[i].startsWith(`.`))&&t[i]!==`**`){if(o===`b`)return!1;o=`a`,a.push(e[r]),r++,i++}else if(t[i]===`*`&&e[r]&&(this.options.dot||!e[r].startsWith(`.`))&&e[r]!==`**`){if(o===`a`)return!1;o=`b`,a.push(t[i]),r++,i++}else return!1;return e.length===t.length&&a}parseNegate(){if(this.nonegate)return;let e=this.pattern,t=!1,n=0;for(let r=0;r<e.length&&e.charAt(r)===`!`;r++)t=!t,n++;n&&(this.pattern=e.slice(n)),this.negate=t}matchOne(e,t,n=!1){let r=0,i=0;if(this.isWindows){let n=typeof e[0]==`string`&&/^[a-z]:$/i.test(e[0]),a=!n&&e[0]===``&&e[1]===``&&e[2]===`?`&&/^[a-z]:$/i.test(e[3]),o=typeof t[0]==`string`&&/^[a-z]:$/i.test(t[0]),s=!o&&t[0]===``&&t[1]===``&&t[2]===`?`&&typeof t[3]==`string`&&/^[a-z]:$/i.test(t[3]),c=a?3:n?0:void 0,l=s?3:o?0:void 0;if(typeof c==`number`&&typeof l==`number`){let[n,a]=[e[c],t[l]];n.toLowerCase()===a.toLowerCase()&&(t[l]=n,i=l,r=c)}}let{optimizationLevel:a=1}=this.options;return a>=2&&(e=this.levelTwoFileOptimize(e)),t.includes(J)?this.#e(e,t,n,r,i):this.#n(e,t,n,r,i)}#e(e,t,n,r,i){let a=t.indexOf(J,i),o=t.lastIndexOf(J),[s,c,l]=n?[t.slice(i,a),t.slice(a+1),[]]:[t.slice(i,a),t.slice(a+1,o),t.slice(o+1)];if(s.length){let t=e.slice(r,r+s.length);if(!this.#n(t,s,n,0,0))return!1;r+=s.length,i+=s.length}let u=0;if(l.length){if(l.length+r>e.length)return!1;let t=e.length-l.length;if(this.#n(e,l,n,t,0))u=l.length;else{if(e[e.length-1]!==``||r+l.length===e.length||(t--,!this.#n(e,l,n,t,0)))return!1;u=l.length+1}}if(!c.length){let t=!!u;for(let n=r;n<e.length-u;n++){let r=String(e[n]);if(t=!0,r===`.`||r===`..`||!this.options.dot&&r.startsWith(`.`))return!1}return n||t}let d=[[[],0]],f=d[0],p=0,ee=[0];for(let e of c)e===J?(ee.push(p),f=[[],0],d.push(f)):(f[0].push(e),p++);let te=d.length-1,ne=e.length-u;for(let e of d)e[1]=ne-(ee[te--]+e[0].length);return!!this.#t(e,d,r,0,n,0,!!u)}#t(e,t,n,r,i,a,o){let s=t[r];if(!s){for(let t=n;t<e.length;t++){o=!0;let n=e[t];if(n===`.`||n===`..`||!this.options.dot&&n.startsWith(`.`))return!1}return o}let[c,l]=s;for(;n<=l;){if(this.#n(e.slice(0,n+c.length),c,i,n,0)&&a<this.maxGlobstarRecursion){let s=this.#t(e,t,n+c.length,r+1,i,a+1,o);if(s!==!1)return s}let s=e[n];if(s===`.`||s===`..`||!this.options.dot&&s.startsWith(`.`))return!1;n++}return i||null}#n(e,t,n,r,i){let a,o,s,c;for(a=r,o=i,c=e.length,s=t.length;a<c&&o<s;a++,o++){this.debug(`matchOne loop`);let n=t[o],r=e[a];if(this.debug(t,n,r),n===!1||n===J)return!1;let i;if(typeof n==`string`?(i=r===n,this.debug(`string match`,n,r,i)):(i=n.test(r),this.debug(`pattern match`,n,r,i)),!i)return!1}if(a===c&&o===s)return!0;if(a===c)return n;if(o===s)return a===c-1&&e[a]===``;throw Error(`wtf?`)}braceExpand(){return Fg(this.pattern,this.options)}parse(e){Wh(e);let t=this.options;if(e===`**`)return J;if(e===``)return``;let n,r=null;(n=e.match(Cg))?r=t.dot?Tg:wg:(n=e.match(pg))?r=(t.nocase?t.dot?_g:gg:t.dot?hg:mg)(n[1]):(n=e.match(Eg))?r=(t.nocase?t.dot?Og:Dg:t.dot?kg:Ag)(n):(n=e.match(vg))?r=t.dot?bg:yg:(n=e.match(xg))&&(r=Sg);let i=dg.fromGlob(e,this.options).toMMPattern();return r&&typeof i==`object`&&Reflect.defineProperty(i,"test",{value:r}),i}makeRe(){if(this.regexp||this.regexp===!1)return this.regexp;let e=this.set;if(!e.length)return this.regexp=!1,this.regexp;let t=this.options,n=t.noglobstar?`[^/]*?`:t.dot?`(?:(?!(?:\\/|^)(?:\\.{1,2})($|\\/)).)*?`:`(?:(?!(?:\\/|^)\\.).)*?`,r=new Set(t.nocase?[`i`]:[]),i=e.map(e=>{let t=e.map(e=>{if(e instanceof RegExp)for(let t of e.flags.split(``))r.add(t);return typeof e==`string`?Lg(e):e===J?J:e._src});t.forEach((e,r)=>{let i=t[r+1],a=t[r-1];e===J&&a!==J&&(a===void 0?i!==void 0&&i!==J?t[r+1]=`(?:\\/|`+n+`\\/)?`+i:t[r]=n:i===void 0?t[r-1]=a+`(?:\\/|\\/`+n+`)?`:i!==J&&(t[r-1]=a+`(?:\\/|\\/`+n+`\\/)`+i,t[r+1]=J))});let i=t.filter(e=>e!==J);if(this.partial&&i.length>=1){let e=[];for(let t=1;t<=i.length;t++)e.push(i.slice(0,t).join(`/`));return`(?:`+e.join(`|`)+`)`}return i.join(`/`)}).join(`|`),[a,o]=e.length>1?[`(?:`,`)`]:[``,``];i=`^`+a+i+o+`$`,this.partial&&(i=`^(?:\\/|`+a+i.slice(1,-1)+o+`)$`),this.negate&&(i=`^(?!`+i+`).+$`);try{this.regexp=new RegExp(i,[...r].join(``))}catch{this.regexp=!1}return this.regexp}slashSplit(e){return this.preserveMultipleSlashes?e.split(`/`):this.isWindows&&/^\/\/[^/]+/.test(e)?[``,...e.split(/\/+/)]:e.split(/\/+/)}match(e,t=this.partial){if(this.debug(`match`,e,this.pattern),this.comment)return!1;if(this.empty)return e===``;if(e===`/`&&t)return!0;let n=this.options;this.isWindows&&(e=e.split(`\\`).join(`/`));let r=this.slashSplit(e);this.debug(this.pattern,`split`,r);let i=this.set;this.debug(this.pattern,`set`,i);let a=r[r.length-1];if(!a)for(let e=r.length-2;!a&&e>=0;e--)a=r[e];for(let e of i){let i=r;if(n.matchBase&&e.length===1&&(i=[a]),this.matchOne(i,e,t))return n.flipNegate?!0:!this.negate}return!n.flipNegate&&this.negate}static defaults(e){return q.defaults(e).Minimatch}};q.AST=dg,q.Minimatch=Rg,q.escape=fg,q.unescape=Xh;const zg=/[/\\]/u,Bg={kind:`ignore`},Vg=e=>!ce(e)&&e.split(zg).every(e=>e!==`.`&&e!==`..`),Hg=/^!+/u,Ug=/^\.?\/+/u,Wg=e=>{let t=Hg.exec(e)?.[0]??``;return{body:e.slice(t.length).replace(Ug,``),negated:t.length%2==1}},Gg=e=>Wg(e).negated,Kg=e=>Wg(e).body,qg=/[?[\]{}()]/u,Jg=e=>Vg(e)&&!Gg(e)&&!qg.test(e),Yg=(e,t)=>q(e,t),Xg=e=>e.replaceAll(/\/+/gu,`/`).replace(/\/$/u,``),Zg=e=>{let t=Xg(e).split(`/`),n=t.findIndex(e=>e.includes(`*`));return n===-1?Bg:{baseDir:n===0?`.`:t.slice(0,n).join(`/`),kind:`expand-children`,pattern:Xg(e),suffix:t.slice(n+1).join(`/`)}},Qg=e=>{let t=Xg(e).split(`/`).filter(e=>e.includes(`*`));return t.length<=1&&!t.includes(`**`)},$g=e=>{let t=Xg(e).split(`/`),n=t.findIndex(e=>e.includes(`*`));return n<=0?`.`:t.slice(0,n).join(`/`)},e_=e=>Jg(e)?e.includes(`*`)?Qg(e)?Zg(e):{baseDir:$g(e),kind:`expand-recursive`,pattern:Xg(e)}:{dir:e,kind:`probe-dir`,pattern:e}:Bg,t_=new Set([`candidate_not_inspected`,`scan_budget_exhausted`,`manifest_unreadable`,`unsupported_pattern`,`workspace_declaration_unparsed`,`workspace_dir_unreadable`,`workspace_file_unreadable`]),n_=(e,t)=>t?.name?{name:t.name,path:e}:void 0,r_=e=>{let t=e.map(e=>[e.path,e]),n=[...new Map(t).values()];return n.sort((e,t)=>e.path.localeCompare(t.path)),n},i_=e=>!e.diagnostics.some(e=>t_.has(e.kind)),a_=e=>!e.diagnostics.some(e=>e.kind===`no_workspace_declaration`),o_=(e,t)=>e<t?-1:+(e>t),s_=e=>`path`in e?`${e.kind} ${e.path}`:`file`in e?`${e.kind} ${e.file}`:`pattern`in e?`${e.kind} ${e.pattern}`:e.kind,c_=e=>e.toSorted((e,t)=>o_(s_(e),s_(t))),l_=e=>!ce(e)&&!e.split(/[/\\]/u).includes(`..`),u_=(e,t)=>e.kind===`missing`?{kind:`absent`}:e.kind===`outside`?{kind:`unreadable`,reason:`${t} escapes the checkout`}:{kind:`unreadable`,reason:e.code},d_=async(e,t,n)=>{if(!l_(t))return{kind:`unreadable`,reason:`path escapes the checkout`};let r=await f_(e,t);if(`probe`in r)return r.probe;let i=await p_(r.real);return`reason`in i?{kind:`unreadable`,reason:i.reason}:i.found===n?{kind:`match`}:{found:i.found,kind:`mismatch`}},f_=async(e,t)=>{let n=await H(e,h(e,t));if(n.kind!==`inside`)return{probe:u_(n,`path`)};let r=await H(e,h(n.real,`package.json`));return r.kind===`inside`?{real:r.real}:{probe:u_(r,`manifest`)}},p_=async e=>{try{let t=JSON.parse(await s(e,`utf8`));return{found:Qu(t)}}catch(e){return{reason:e.code??`manifest could not be read or interpreted`}}},m_=(e,t)=>{let n=e.filter(e=>e.name===t).map(e=>e.path);return n.length===0?{kind:`absent`}:n.length===1?{kind:`found`,path:n[0]}:{kind:`ambiguous`,paths:n.toSorted(o_)}},h_=`package.json`,g_=/^\.\/[^\s%?#\\]*$/u,__=async e=>{try{return(await p(e)).isDirectory()?`directory`:`file`}catch{return`unverifiable`}},v_=async(e,t)=>{if(!g_.test(t)||t.includes(`*`))return`not_checked`;let n=h(e,t.slice(2)),r=await H(e,n);return r.kind===`inside`?__(r.real):r.kind===`missing`&&await Uu(e,n)?`absent`:`unverifiable`},y_=async(e,t,n)=>Array.isArray(t)?{alternatives:await Promise.all(t.map(t=>b_(e,t,n+1))),kind:`alternatives`}:{branches:await Promise.all(Object.entries(t).map(async([t,r])=>({condition:t,value:await b_(e,r,n+1)}))),kind:`conditions`},b_=async(e,t,n)=>t===null?{kind:`excluded`}:n>8?{kind:`unsupported`,reason:`nested deeper than this reports on`}:typeof t==`string`?{kind:`target`,observed:await v_(e,t),target:t}:typeof t==`object`?y_(e,t,n):{kind:`unsupported`,reason:`unexpected ${typeof t}`},x_=[`main`,`module`,`types`,`typings`],S_=(e,t)=>{let n=x_.filter(e=>typeof t[e]==`string`);return Promise.all(n.map(async n=>({from:n,subpath:`.`,value:await b_(e,C_(t[n]),0)})))},C_=e=>e.startsWith(`/`)||e.startsWith(`./`)||e.startsWith(`../`)?e:`./${e}`,w_=async(e,t)=>{if(typeof t==`string`||Array.isArray(t))return[{from:`exports`,subpath:`.`,value:await b_(e,t,0)}];if(t===void 0)return[];if(typeof t!=`object`||!t)return[{from:`exports`,subpath:`.`,value:await b_(e,t,0)}];let n=Object.keys(t);return n.length>0&&!n.some(e=>e.startsWith(`.`))?[{from:`exports`,subpath:`.`,value:await b_(e,t,0)}]:Promise.all(Object.entries(t).map(async([t,n])=>({from:`exports`,subpath:t,value:await b_(e,n,0)})))},T_=async(e,t)=>{let n=await H(e,h(e,h_));if(n.kind!==`inside`)return{entries:[],manifest:h_,reason:n.kind,status:`unverifiable`};try{let r=JSON.parse(await s(n.real,`utf8`));return r.name===t?{entries:[...await w_(e,r.exports),...await S_(e,r)],manifest:h_,status:`complete`}:{entries:[],manifest:h_,reason:`manifest no longer names this package`,status:`unverifiable`}}catch(e){return{entries:[],manifest:h_,reason:e.code??`manifest could not be read or interpreted`,status:`unverifiable`}}},E_=vl.partial({description:!0}),D_=N({default_branch:$c,key:nl,tag_format_candidate:sl.nullable(),url:j().min(1)});D_.extend({description:j().default(``),packages:fl(E_)});const O_=D_.extend({description:j().min(1),packages:fl(vl)}),k_=N({effective_clone_mode:al.optional(),head_sha:j().regex(/^[0-9a-f]{40}$/u,`head_sha must be a 40-character lowercase hex string`).optional(),last_error:j().optional(),last_fetched_at:Vc().optional(),pending_proposal_at:Vc().optional()}),A_=N({refs:ul(e=>e.length>0&&!ll.has(e),()=>`state ref key must be non-empty and not "__proto__", "constructor", or "prototype"`,pc(j(),k_)).default({})}),j_=(e,t,n)=>t?.[e]??n[e],M_=async e=>{try{return await s(e.statePath,`utf8`)}catch(e){if(F(e))return;throw e}},N_=e=>{try{return JSON.parse(e)}catch{return}},P_=async e=>{let t=await M_(e);if(t===void 0)return A_.parse({});let n=N_(t);if(n===void 0)return A_.parse({});let r=A_.safeParse(n);return r.success?r.data:A_.parse({})},F_=async(e,t)=>{let n=A_.safeParse(t);if(!n.success)throw z(S(n.error));await au(e.statePath,`${JSON.stringify(n.data,void 0,2)}\n`)},I_=/^\d+\.\d+\.\d+$/u,L_=/^0+(?=\d)/u,R_=(e,t)=>{let n=e.replace(L_,``),r=t.replace(L_,``);return n.length===r.length?n===r?0:n<r?-1:1:n.length<r.length?-1:1},z_=(e,t)=>{if(!I_.test(e)||!I_.test(t))return;let n=e.split(`.`),r=t.split(`.`);return n.map((e,t)=>R_(e,r[t]??``)).find(e=>e!==0)??0},B_=sc({version:j().regex(I_)}),V_=N({checked_at:Vc(),latest_version:j().regex(I_)}),H_=async e=>{try{let t=V_.safeParse(JSON.parse(await s(e.updateCachePath,`utf8`)));return t.success?t.data:void 0}catch{return}},U_=async(e,t)=>{try{await p(e.root),await au(e.updateCachePath,`${JSON.stringify(t,void 0,2)}\n`)}catch{}},W_=(e,t)=>{let n=t-Date.parse(e.checked_at);return n>=0&&n<864e5},G_=async e=>{try{let t=await e(`https://registry.npmjs.org/@kaisers-io%2Frefs/latest`,{signal:AbortSignal.timeout(2e3)});if(t.status!==200)return;let n=B_.safeParse(await t.json());return n.success?n.data.version:void 0}catch{return}},K_=async e=>{let t=await H_(e.home);if(t!==void 0&&W_(t,e.nowMs))return{latest:t.latest_version,refreshed:!1,stale:!1};let n=await G_(e.fetch);return n===void 0?{latest:t?.latest_version,refreshed:!1,stale:!0}:(await U_(e.home,{checked_at:new Date(e.nowMs).toISOString(),latest_version:n}),{latest:n,refreshed:!0,stale:!1})},q_=(e,t)=>{let n=z_(e,t);return n!==void 0&&n<0},J_=(e,t)=>`refs ${t} is available (this is ${e}) — update: npm i -g @kaisers-io/refs@latest`,Y_=e=>{let t=e.REFS_UPDATE_CHECK?.trim();if(t===`0`)return!1;if(t===`1`)return!0},X_=e=>{let t=e.CI?.trim().toLowerCase();return t!==void 0&&t!==``&&t!==`false`&&t!==`0`},Z_={check:!0,notify:!0},Q_=e=>{let t=Y_(e.env);return t===void 0?(e.updates??Z_).check?X_(e.env)?`ci`:`on`:`config`:t?`on`:`env`},$_=e=>Q_(e)===`on`,ev=e=>$_(e)&&(e.updates??Z_).notify,tv=async(e,t)=>{let n=await H(e,h(t,`package.json`));if(n.kind===`inside`)try{let e=JSON.parse(await s(n.real,`utf8`));return{name:Qu(e),version:$u(e)}}catch{return}},nv=async(e,t)=>{let n=await tv(e,h(e,t));if(n===void 0)return{diagnostic:{kind:`manifest_unreadable`,path:t}};let r=n_(t,n);return r!==void 0&&n.version!==void 0?{pkg:r,version:n.version}:r===void 0?{diagnostic:{kind:`manifest_missing_name`,path:t}}:{pkg:r}},rv=e=>Object.fromEntries(e.flatMap(e=>e.pkg===void 0||e.version===void 0?[]:[[e.pkg.path,e.version]])),iv=e=>{let t=[],n=[];for(let r of e)r.diagnostic!==void 0&&t.push(r.diagnostic),r.pkg!==void 0&&n.push(r.pkg);return{diagnostics:t,packages:n,versions:rv(e)}},av=new Set([`ENOENT`,`ENOTDIR`]),ov=async(e,t)=>{let n=await H(e,h(t,`package.json`));if(n.kind===`missing`)return`none`;if(n.kind!==`inside`)return`rejected`;try{return await s(n.real,`utf8`),`manifest`}catch{return`rejected`}},sv=async e=>{try{return{entries:await c(e,{withFileTypes:!0})}}catch(e){return{code:e.code??``}}},cv=e=>Promise.all(e.entries.map(t=>ov(e.repoDir,h(e.fullPath,t.name,e.suffix)))),lv=(e,t,n)=>e.filter((e,r)=>n(t[r])).map(e=>e.name),uv=async e=>{let{baseDir:t,dirs:n,fullPath:r,repoDir:i,suffix:a,symlinks:o}=e,s=e=>ue.join(t===`.`?``:t,e,a),[c,l]=await Promise.all([cv({entries:n,fullPath:r,repoDir:i,suffix:a}),cv({entries:o,fullPath:r,repoDir:i,suffix:a})]);return{diagnostics:[...lv(n,c,e=>e===`rejected`).map(e=>({kind:`manifest_unreadable`,path:s(e)})),...lv(o,l,e=>e!==`none`).map(e=>({kind:`candidate_not_inspected`,path:s(e)}))],dirs:lv(n,c,e=>e===`manifest`).map(e=>s(e))}},dv=async e=>{let t=await nv(e,`.`);return`pkg`in t?[t]:[]},fv=e=>{let t=e.find(e=>e.path===`.`);return t===void 0?[...e]:e.some(e=>e.path!==`.`&&e.name===t.name)?e.filter(e=>e!==t):[...e]},pv=async e=>{let[t]=await dv(e);return t!==void 0&&`pkg`in t?t.pkg:void 0},mv=`package.json`,hv=e=>{let t=Xg(e).split(`/`);return t.includes(`**`)?void 0:t.length},gv=e=>Xg(e).split(`/`).some(e=>e.startsWith(`.`)),_v=e=>e===`.`?0:e.split(`/`).length,vv=e=>{let t=Xg(e),n=new Rg(`${t}/${mv}`),r=new Rg(t);return{couldHold:e=>r.match(e,!0),selects:e=>n.match(ue.join(e,mv))}},yv=e=>({...vv(e),maxDepth:hv(e),selectsHidden:gv(e)}),bv=new Set([`ENOENT`,`ENOTDIR`]),xv=new Set([`.git`,`node_modules`]),Sv=e=>e.some(e=>e.name.toLowerCase()===`package.json`&&!e.isDirectory()),Cv=e=>e.some(e=>e.isSymbolicLink()&&!xv.has(e.name)),wv=async(e,t)=>{let n=await sv(t);return`code`in n?{answer:bv.has(n.code)}:(e.budget.entries-=n.entries.length,e.budget.entries<0||Sv(n.entries)||Cv(n.entries)?{answer:!1}:{entries:n.entries})},Tv=async(e,t,n)=>{if(e.budget.dirs<=0||n>32)return!1;--e.budget.dirs;let r=await wv(e,t);return`answer`in r?r.answer:Ev(e,{dir:t,entries:r.entries},n)},Ev=async(e,t,n)=>{let r=t.entries.filter(e=>e.isDirectory()&&!xv.has(e.name));for(let i of r)if(!await Tv(e,h(t.dir,i.name),n+1))return!1;return!0},Dv=async(e,t)=>{let n=await H(e.repoDir,h(e.repoDir,t));if(n.kind!==`outside`&&n.kind!==`missing`){if(n.kind===`unreadable`){e.diagnostics.push({kind:`candidate_not_inspected`,path:t});return}await Tv(e,n.real,1)||e.diagnostics.push({kind:`candidate_not_inspected`,path:t})}},Ov=()=>({dirs:2e4,entries:2e5}),kv=new Set([`.git`,`node_modules`]),Av=(e,t)=>{e.diagnostics.push({kind:`scan_budget_exhausted`,path:t,pattern:e.pattern})},jv=async(e,t,n)=>{if(!e.selects(t)||n.has(t))return;let r=await ov(e.repoDir,h(e.repoDir,t));r===`manifest`&&e.dirs.push(t),r===`rejected`&&e.diagnostics.push({kind:`manifest_unreadable`,path:t})},Mv=(e,t)=>!e.selectsHidden&&t.excluded.coversSubtree(t.relPath),Nv=async(e,t,n)=>!e.couldHold(n.relPath)||kv.has(t.name)||Mv(e,n)?!1:t.isSymbolicLink()?(Mv(e,n)||await Dv(e,n.relPath),!1):t.isDirectory(),Pv=async(e,t)=>{let n=await sv(h(e.repoDir,t));if(`code`in n){av.has(n.code)||e.diagnostics.push({kind:`workspace_dir_unreadable`,path:t});return}if(e.budget.entries-=n.entries.length,e.budget.entries<0){Av(e,t);return}return n.entries},Fv=async(e,t,n)=>{if(e.budget.dirs<=0){Av(e,t.relPath);return}if(--e.budget.dirs,await jv(e,t.relPath,n),e.maxDepth!==void 0&&_v(t.relPath)>=e.maxDepth)return;let r=await Pv(e,t.relPath);r!==void 0&&await Lv(e,{depth:t.depth,entries:r,relPath:t.relPath},n)},Iv=(e,t)=>ue.join(e===`.`?``:e,t),Lv=async(e,t,n)=>{for(let r of t.entries){let i=Iv(t.relPath,r.name);await Nv(e,r,{excluded:n,relPath:i})&&(t.depth+1>32?Av(e,i):await Fv(e,{depth:t.depth+1,relPath:i},n))}},Rv=async(e,t)=>{let n=await H(e,h(e,t));if(n.kind!==`inside`)return n.kind===`missing`?{diagnostics:[],dirs:[]}:{diagnostics:[{kind:`workspace_dir_unreadable`,path:t}],dirs:[]}},zv=async(e,t,n)=>{let r=await Rv(e,t.baseDir);if(r!==void 0)return r;let i={...yv(t.pattern),budget:n.budget,diagnostics:[],dirs:[],pattern:t.pattern,repoDir:e};return await Fv(i,{depth:1,relPath:t.baseDir},n.excluded),{diagnostics:i.diagnostics,dirs:i.dirs}},Bv=(e,t)=>ue.join(e.baseDir===`.`?``:e.baseDir,t,e.suffix),Vv=(e,t)=>Yg(Bv(t,e.name),t.pattern),Hv=async(e,t)=>{let n=h(e,t),r=await H(e,n);if(r.kind===`missing`)return{result:{diagnostics:[],dirs:[]}};if(r.kind!==`inside`)return{result:{diagnostics:[{kind:`workspace_dir_unreadable`,path:t}],dirs:[]}};let i=await sv(n);return`code`in i?{result:av.has(i.code)?{diagnostics:[],dirs:[]}:{diagnostics:[{kind:`workspace_dir_unreadable`,path:t}],dirs:[]}}:{entries:i.entries}},Uv=async(e,t,n)=>{let{baseDir:r}=t,i=await Hv(e,r);if(`result`in i)return i.result;let a=e=>Vv(e,t)&&!n.has(Bv(t,e.name)),o={entries:i.entries};return uv({baseDir:r,dirs:o.entries.filter(e=>e.isDirectory()&&a(e)),fullPath:h(e,r),repoDir:e,suffix:t.suffix,symlinks:o.entries.filter(e=>e.isSymbolicLink()&&a(e))})},Wv=async(e,t)=>{let n=await ov(e,h(e,t));return n===`manifest`?{diagnostics:[],dirs:[Xg(t)]}:n===`rejected`?{diagnostics:[{kind:`manifest_unreadable`,path:t}],dirs:[]}:{diagnostics:[],dirs:[]}},Gv=(e,t,n)=>{let{excluded:r}=n,i=e_(t.body);return i.kind===`expand-children`?Uv(e,i,r):i.kind===`expand-recursive`?zv(e,i,n):i.kind===`probe-dir`?r.has(Xg(i.dir))?Promise.resolve({diagnostics:[],dirs:[]}):Wv(e,i.dir):Promise.resolve({diagnostics:[{kind:`unsupported_pattern`,pattern:t.declared}],dirs:[]})},Kv=(e,t)=>Yg(Kg(e),Kg(t)),qv=e=>({negations:e.filter(e=>Gg(e)),patterns:e.filter(e=>!Gg(e))}),Jv=e=>{let t=e.reduce((e,t)=>Gg(t)?{negations:[...e.negations,t],patterns:e.patterns}:{negations:e.negations.filter(e=>!Kv(t,e)),patterns:[...e.patterns,t]},{negations:[],patterns:[]});return{negations:t.negations,patterns:t.patterns.filter(e=>!t.negations.some(t=>Kv(e,t)))}},Yv=e=>e.endsWith(`/`)?e:`${e}/`,Xv=(e,t)=>e.some(e=>Yg(Yv(t),Yv(Kg(e)))),Zv=(e,t)=>{let n=Kg(e);return n.endsWith(`/**`)&&Yg(t,n.slice(0,-3))},Qv=e=>({coversSubtree:t=>e.some(e=>Zv(e,t)),has:t=>Xv(e,t)}),$v=e=>{let t=new Set,n=[];for(let r of e)r.dirs.forEach(e=>t.add(e)),n.push(...r.diagnostics);return{diagnostics:n,dirs:[...t]}},ey=async(e,t,n)=>{let{negations:r,patterns:i}=t,a=Qv(r),o=$v(await Promise.all(i.map(t=>Gv(e,{body:Kg(t),declared:t},{budget:n,excluded:a}))));return{diagnostics:o.diagnostics,dirs:o.dirs}},ty=async(e,t)=>{let n=Jv(t.npm),r=qv(t.pnpm),i=Ov(),a=await Promise.all([ey(e,n,i),ey(e,r,i)]);return $v(a)},ny=async e=>{let t=await od(e);if(t.npm.length===0&&t.pnpm.length===0)return{diagnostics:c_([...t.diagnostics,{kind:`no_workspace_declaration`}]),packages:[],versions:{}};let n=await ty(e,t),[r,i]=await Promise.all([dv(e),Promise.all(n.dirs.map(t=>nv(e,t)))]),a=iv([...r,...i]);return{diagnostics:c_([...t.diagnostics,...n.diagnostics,...a.diagnostics]),packages:fv(r_(a.packages)),versions:a.versions}},ry=()=>{},iy={stop:ry,update:ry},ay={frames:[`⠋`,`⠙`,`⠹`,`⠸`,`⠼`,`⠴`,`⠦`,`⠧`,`⠇`,`⠏`],interval:80},oy={frames:[`-`,`\\`,`|`,`/`],interval:130},sy=`\r\x1B[K`,cy={24:`\x1B[38;2;7;210;86m`,4:`\x1B[32m`,8:`\x1B[38;5;41m`},ly=/[^ -~]/gu,uy=(e,t)=>t.isTTY===!0&&e.TERM!==`dumb`&&!X_(e)&&e.REFS_PROGRESS?.trim()!==`0`,dy=new Set([`alacritty`,`rxvt-unicode`,`rxvt-unicode-256color`,`xterm-256color`]),fy=(e,t)=>t===`win32`?!!e.WT_SESSION||!!e.TERMINUS_SUBLIME||e.ConEmuTask===`{cmd::Cmder}`||e.TERM_PROGRAM===`Terminus-Sublime`||e.TERM_PROGRAM===`vscode`||e.TERMINAL_EMULATOR===`JetBrains-JediTerm`||dy.has(e.TERM??``):e.TERM!==`linux`,py=(e,t)=>e.replaceAll(ly,`?`).slice(0,Math.max(0,t)),my=(e,t,n)=>{let r=(e.stream.columns??80)-3,i=cy[e.stream.getColorDepth?.(e.env)??1],a=i===void 0?t:`${i}${t}[39m`;return`${sy}${a} ${py(n,r)}`},hy=e=>{if(!uy(e.env,e.stream))return iy;let{frames:t,interval:n}=fy(e.env,e.platform)?ay:oy,r={drawn:!1,index:0,stopped:!1,text:``},i=()=>{e.stream.write(my(e,t[r.index%t.length]??``,r.text)),r.drawn=!0,r.index+=1},a={},o=()=>{i(),a.ticker=setInterval(i,n).unref()};return{stop:()=>{r.stopped=!0,clearTimeout(a.delay),clearInterval(a.ticker),r.drawn&&=(e.stream.write(sy),!1)},update:e=>{r.stopped||(r.text=e,a.delay??=setTimeout(o,100).unref())}}};var gy=`0.18.0`;const _y=async()=>{let e=[];for await(let t of process.stdin)e.push(Buffer.from(t));return Buffer.concat(e).toString(`utf8`)},vy=()=>{try{return ge()}catch{return``}},yy=()=>({cliVersion:gy,cwd:process.cwd(),env:process.env,errLine:e=>{process.stderr.write(`${e}\n`)},fetcher:(e,t)=>fetch(e,t),homedir:vy(),nodeVersion:process.version,out:e=>{process.stdout.write(`${e}\n`)},readStdin:_y,runner:new Ad,spinner:()=>hy({env:process.env,platform:process.platform,stream:process.stderr})});var by=class extends Error{constructor(e,t,n){super(n),Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name,this.code=t,this.exitCode=e,this.nestedError=void 0}},xy=class extends by{constructor(e){super(1,`commander.invalidArgument`,e),Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name}},Sy=class{constructor(e,t){switch(this.description=t||``,this.variadic=!1,this.parseArg=void 0,this.defaultValue=void 0,this.defaultValueDescription=void 0,this.argChoices=void 0,e[0]){case`<`:this.required=!0,this._name=e.slice(1,-1);break;case`[`:this.required=!1,this._name=e.slice(1,-1);break;default:this.required=!0,this._name=e}this._name.endsWith(`...`)&&(this.variadic=!0,this._name=this._name.slice(0,-3))}name(){return this._name}_collectValue(e,t){return t===this.defaultValue||!Array.isArray(t)?[e]:(t.push(e),t)}default(e,t){return this.defaultValue=e,this.defaultValueDescription=t,this}argParser(e){return this.parseArg=e,this}choices(e){return this.argChoices=e.slice(),this.parseArg=(e,t)=>{if(!this.argChoices.includes(e))throw new xy(`Allowed choices are ${this.argChoices.join(`, `)}.`);return this.variadic?this._collectValue(e,t):e},this}argRequired(){return this.required=!0,this}argOptional(){return this.required=!1,this}};function Cy(e){let t=e.name()+(e.variadic===!0?`...`:``);return e.required?`<`+t+`>`:`[`+t+`]`}var wy=class{constructor(){this.helpWidth=void 0,this.minWidthToWrap=40,this.sortSubcommands=!1,this.sortOptions=!1,this.showGlobalOptions=!1}prepareContext(e){this.helpWidth=this.helpWidth??e.helpWidth??80}visibleCommands(e){let t=e.commands.filter(e=>!e._hidden),n=e._getHelpCommand();return n&&!n._hidden&&t.push(n),this.sortSubcommands&&t.sort((e,t)=>e.name().localeCompare(t.name())),t}compareOptions(e,t){let n=e=>e.short?e.short.replace(/^-/,``):e.long.replace(/^--/,``);return n(e).localeCompare(n(t))}visibleOptions(e){let t=e.options.filter(e=>!e.hidden),n=e._getHelpOption();if(n&&!n.hidden){let r=n.short&&e._findOption(n.short),i=n.long&&e._findOption(n.long);!r&&!i?t.push(n):n.long&&!i?t.push(e.createOption(n.long,n.description)):n.short&&!r&&t.push(e.createOption(n.short,n.description))}return this.sortOptions&&t.sort(this.compareOptions),t}visibleGlobalOptions(e){if(!this.showGlobalOptions)return[];let t=[];for(let n=e.parent;n;n=n.parent){let e=n.options.filter(e=>!e.hidden);t.push(...e)}return this.sortOptions&&t.sort(this.compareOptions),t}visibleArguments(e){return e._argsDescription&&e.registeredArguments.forEach(t=>{t.description=t.description||e._argsDescription[t.name()]||``}),e.registeredArguments.find(e=>e.description)?e.registeredArguments:[]}subcommandTerm(e){let t=e.registeredArguments.map(e=>Cy(e)).join(` `);return e._name+(e._aliases[0]?`|`+e._aliases[0]:``)+(e.options.length?` [options]`:``)+(t?` `+t:``)}optionTerm(e){return e.flags}argumentTerm(e){return e.name()}longestSubcommandTermLength(e,t){return t.visibleCommands(e).reduce((e,n)=>Math.max(e,this.displayWidth(t.styleSubcommandTerm(t.subcommandTerm(n)))),0)}longestOptionTermLength(e,t){return t.visibleOptions(e).reduce((e,n)=>Math.max(e,this.displayWidth(t.styleOptionTerm(t.optionTerm(n)))),0)}longestGlobalOptionTermLength(e,t){return t.visibleGlobalOptions(e).reduce((e,n)=>Math.max(e,this.displayWidth(t.styleOptionTerm(t.optionTerm(n)))),0)}longestArgumentTermLength(e,t){return t.visibleArguments(e).reduce((e,n)=>Math.max(e,this.displayWidth(t.styleArgumentTerm(t.argumentTerm(n)))),0)}commandUsage(e){let t=e._name;e._aliases[0]&&(t=t+`|`+e._aliases[0]);let n=``;for(let t=e.parent;t;t=t.parent)n=t.name()+` `+n;return n+t+` `+e.usage()}commandDescription(e){return e.description()}subcommandDescription(e){return e.summary()||e.description()}optionDescription(e){let t=[];if(e.argChoices&&t.push(`choices: ${e.argChoices.map(e=>JSON.stringify(e)).join(`, `)}`),e.defaultValue!==void 0&&(e.required||e.optional||e.isBoolean()&&typeof e.defaultValue==`boolean`)&&t.push(`default: ${e.defaultValueDescription||JSON.stringify(e.defaultValue)}`),e.presetArg!==void 0&&e.optional&&t.push(`preset: ${JSON.stringify(e.presetArg)}`),e.envVar!==void 0&&t.push(`env: ${e.envVar}`),t.length>0){let n=`(${t.join(`, `)})`;return e.description?`${e.description} ${n}`:n}return e.description}argumentDescription(e){let t=[];if(e.argChoices&&t.push(`choices: ${e.argChoices.map(e=>JSON.stringify(e)).join(`, `)}`),e.defaultValue!==void 0&&t.push(`default: ${e.defaultValueDescription||JSON.stringify(e.defaultValue)}`),t.length>0){let n=`(${t.join(`, `)})`;return e.description?`${e.description} ${n}`:n}return e.description}formatItemList(e,t,n){return t.length===0?[]:[n.styleTitle(e),...t,``]}groupItems(e,t,n){let r=new Map;return e.forEach(e=>{let t=n(e);r.has(t)||r.set(t,[])}),t.forEach(e=>{let t=n(e);r.has(t)||r.set(t,[]),r.get(t).push(e)}),r}formatHelp(e,t){let n=t.padWidth(e,t),r=t.helpWidth??80;function i(e,r){return t.formatItem(e,n,r,t)}let a=[`${t.styleTitle(`Usage:`)} ${t.styleUsage(t.commandUsage(e))}`,``],o=t.commandDescription(e);o.length>0&&(a=a.concat([t.boxWrap(t.styleCommandDescription(o),r),``]));let s=t.visibleArguments(e).map(e=>i(t.styleArgumentTerm(t.argumentTerm(e)),t.styleArgumentDescription(t.argumentDescription(e))));if(a=a.concat(this.formatItemList(`Arguments:`,s,t)),this.groupItems(e.options,t.visibleOptions(e),e=>e.helpGroupHeading??`Options:`).forEach((e,n)=>{let r=e.map(e=>i(t.styleOptionTerm(t.optionTerm(e)),t.styleOptionDescription(t.optionDescription(e))));a=a.concat(this.formatItemList(n,r,t))}),t.showGlobalOptions){let n=t.visibleGlobalOptions(e).map(e=>i(t.styleOptionTerm(t.optionTerm(e)),t.styleOptionDescription(t.optionDescription(e))));a=a.concat(this.formatItemList(`Global Options:`,n,t))}return this.groupItems(e.commands,t.visibleCommands(e),e=>e.helpGroup()||`Commands:`).forEach((e,n)=>{let r=e.map(e=>i(t.styleSubcommandTerm(t.subcommandTerm(e)),t.styleSubcommandDescription(t.subcommandDescription(e))));a=a.concat(this.formatItemList(n,r,t))}),a.join(`
|
|
405
|
+
`.replaceAll(`{{CLI_VERSION}}`,t)),`seeded`),V=e=>{let t=fe(e.REFS_HOME??h(ge(),`.kaisers-io`,`refs`));return{cacheDir:h(t,`cache`),configPath:h(t,`config.toml`),hooksDir:h(t,`hooks`),locksDir:h(t,`locks`),root:t,sourcesDir:h(t,`sources`),statePath:h(t,`state.json`),updateCachePath:h(t,`cache`,`update-check.json`)}},ju=(e,t)=>h(e.sourcesDir,...t.split(`/`)),Mu=e=>`${e.configPath}.bak`,Nu=e=>{let t=[],n=e;for(;!ie(n);){let e=m(n);if(e===n)break;t.unshift(se(n)),n=e}return{ancestor:n,missing:t}},Pu=e=>{let{ancestor:t,missing:n}=Nu(e),r=ae(t);return n.length===0?r:h(r,...n)},Fu=(e,t,n)=>{let r=Pu(e),i=Pu(t),a=de(r,i),o=a===`..`||a.startsWith(`..`+pe);if(a===``||o||ce(a))throw z(`path escapes ${n} (containment violation): ${t}`)},Iu=(e,t)=>{Fu(e.sourcesDir,t,`sources directory`)},Lu=(e,t)=>{let n={...e};for(let[e,r]of Object.entries(t)){let t=n[e];t===void 0?n[e]=r:bu(t)&&bu(r)&&(n[e]=Lu(t,r))}return n},Ru={meta:{},refs:{},settings:{}},zu=async e=>{try{return await Su(e)}catch(e){if(e instanceof L&&e.code===`not_found`)return;throw e}},Bu=e=>{if(e!==void 0&&e>1)throw z(`config schema ${e} is newer than this CLI supports — upgrade refs`)},Vu=async(e,t,n)=>{let r=xu(t.meta,{}),i={...t,meta:{...r,cli_version:n}},a=kl.safeParse(i);if(!a.success){let t=S(a.error);throw z(`config in ${e.configPath} is at the current schema version but does not validate: ${t}`)}r.cli_version!==n&&await pu(e.configPath,lu(i))},Hu=async(e,t,n)=>{await r(e.configPath,Mu(e));let i=Lu(t,Ru),a=xu(i.meta,{}),o={...i,meta:{...a,cli_version:n,schema_version:1}},s=kl.safeParse(o);if(!s.success)throw z(`config in ${e.configPath} is malformed beyond automatic migration (backup preserved at ${Mu(e)}): ${S(s.error)}`);await pu(e.configPath,lu(o))},Uu=async(e,t,n)=>{let r=Cu(t,e.configPath),i=Tu(r);return Bu(i),i===1?(await Vu(e,r,n),`noop`):(await Hu(e,r,n),`migrated`)},Wu=async(e,t)=>{let n=await zu(e);return n===void 0?(await Au(e,t),`seeded`):Uu(e,n,t)},Gu=/* @__PURE__ */ new Set([`ENOENT`,`ENOTDIR`]),Ku=e=>e.code??String(e),qu=async e=>{try{return await i(e),!0}catch{return!1}},Ju=(e,t)=>{let n=de(e,t);return n===``||n!==`..`&&!n.startsWith(`..`+pe)&&!ce(n)},Yu=async e=>{try{return{real:await l(e)}}catch(e){return{code:Ku(e)}}},H=async(e,t)=>{let n=await Yu(e);if(`code`in n)return{code:n.code,kind:`unreadable`};let r=await Yu(t);return`code`in r?Gu.has(r.code)?await qu(t)?{code:r.code,kind:`unreadable`}:{kind:`missing`}:{code:r.code,kind:`unreadable`}:Ju(n.real,r.real)?{kind:`inside`,real:r.real}:{kind:`outside`}},Xu=/* @__PURE__ */ new Set([`/`,pe]),Zu=e=>{let t=le(e).root.length,n=e.length;for(;n>t&&Xu.has(e.charAt(n-1));)--n;return e.slice(0,n)},Qu=async(e,t)=>{let n=Zu(t);for(let t=await H(e,n);;){if(t.kind!==`missing`||m(n)===n)return t.kind===`inside`;n=m(n),t=await H(e,n)}},$u=/^\s*-\s+["']?(?<pattern>[^"'#]+)["']?/u,ed=/^packages:\s*(?:#.*)?$/u,td=e=>typeof e==`object`&&!!e&&!Array.isArray(e),nd=e=>{if(Array.isArray(e))return e.filter(e=>typeof e==`string`);if(!td(e))return[];let{packages:t}=e;return Array.isArray(t)?t.filter(e=>typeof e==`string`):[]},rd=Symbol(`end-of-section`),id=e=>{let t=e.trim();if(t&&!t.startsWith(`-`)&&t.includes(`:`)&&!ed.test(e))return rd;if(!t.startsWith(`-`))return;let n=$u.exec(e)?.groups?.pattern?.trim();if(n)return n},ad=e=>{let t=[];for(let n of e){let e=id(n);if(e===rd)break;e!==void 0&&t.push(e)}return t},od=e=>{let t=e.findIndex(e=>ed.test(e));return t===-1?[]:ad(e.slice(t+1))},sd=e=>{let{name:t}=e;if(typeof t==`string`)return t},cd=e=>{let{version:t}=e;return typeof t==`string`?t:void 0},ld=async(e,t)=>{let n=await H(e,t);if(n.kind===`missing`)return{ok:!0};if(n.kind!==`inside`)return{ok:!1};try{return{content:await s(n.real,`utf8`),ok:!0}}catch{return{ok:!1}}},ud=async(e,t)=>{let n=await ld(e,t);return n.ok?n.content===void 0?{ok:!0,patterns:[]}:dd(n.content):{ok:!1,patterns:[]}},dd=e=>{try{let t=JSON.parse(e);return{ok:!0,patterns:nd(t.workspaces)}}catch{return{ok:!1,patterns:[]}}},fd=/^packages:/mu,pd=(e,t)=>t.length===0&&fd.test(e),md=async(e,t)=>{let n=await ld(e,t);if(!n.ok)return{ok:!1,patterns:[]};if(n.content===void 0)return{ok:!0,patterns:[]};let r=od(n.content.split(`
|
|
406
|
+
`));return{ok:!0,patterns:r,unparsed:pd(n.content,r)}},hd=async e=>{let[t,n]=await Promise.all([ud(e,h(e,`package.json`)),md(e,h(e,`pnpm-workspace.yaml`))]),r=[];return t.ok||r.push({file:`package.json`,kind:`workspace_file_unreadable`}),n.ok||r.push({file:`pnpm-workspace.yaml`,kind:`workspace_file_unreadable`}),n.unparsed===!0&&r.push({file:`pnpm-workspace.yaml`,kind:`workspace_declaration_unparsed`}),{diagnostics:r,npm:t.patterns,pnpm:n.patterns}},gd=/* @__PURE__ */ new Set;let _d=!1;const vd=()=>{for(let e of gd)try{e.kill(`SIGKILL`)}catch{}},yd=[`SIGINT`,`SIGTERM`,`SIGHUP`,`SIGBREAK`],bd=e=>{let t=()=>{vd(),process.removeListener(e,t),process.kill(process.pid,e)};process.on(e,t)},xd=()=>{_d||(_d=!0,yd.forEach(e=>{bd(e)}),process.on(`exit`,vd))},Sd=()=>{let e=[],t=0,n=!1;return{finish:()=>({text:Buffer.concat(e).toString(`utf8`),truncated:n}),push:r=>{if(n)return;let i=67108864-t;r.length<=i?(e.push(r),t+=r.length):(i>0&&e.push(r.subarray(0,i)),n=!0)}}},Cd=(e,t)=>[e.replace(/\r?\n$/u,``),t].filter(e=>e!==``).join(`
|
|
407
|
+
`),wd=(e,t,n)=>{let r=e;return t.truncated&&(r=Cd(r,`refs: stdout exceeded 67108864 bytes, truncated`)),n.truncated&&(r=Cd(r,`refs: stderr exceeded 67108864 bytes, truncated`)),r},Td={clear:()=>{},markedTimedOut:()=>!1},Ed=(e,t)=>{if(t===void 0)return Td;let n=!1,r,i=setTimeout(()=>{n=!0,e.kill(`SIGTERM`),r=setTimeout(()=>{e.kill(`SIGKILL`)},2e3)},t);return{clear:()=>{clearTimeout(i),r!==void 0&&clearTimeout(r)},markedTimedOut:()=>n}},Dd=e=>e===void 0?{}:{cwd:e},Od=(e,t)=>Cd(e,`refs: command timed out after ${String(t)}ms`),kd=(e,t)=>({exitCode:124,stderr:Od(e,t),stdout:``,timedOut:!0}),Ad=(e,t,n)=>{let r=be(e,t,{...Dd(n?.cwd),shell:!1,stdio:[`ignore`,`pipe`,`pipe`]});gd.add(r);let i=Sd(),a=Sd();return r.stdout.on(`data`,e=>{i.push(e)}),r.stderr.on(`data`,e=>{a.push(e)}),{child:r,stderrCollector:a,stdoutCollector:i,timeout:Ed(r,n?.timeoutMs)}},jd=(e,t,n)=>{try{return Ad(e,t,n)}catch(e){return{exitCode:127,stderr:Nd(e),stdout:``}}},Md=e=>!(`child`in e),Nd=e=>e instanceof Error?e.message:String(e),Pd=async e=>{try{let[t]=await ve(e,`close`);return{code:t}}catch(e){return{code:null,errorMessage:Nd(e)}}},Fd=e=>e===null?1:e,Id=e=>e.stdoutTruncated===!0,Ld=(e,t)=>t.truncated?{...e,stdoutTruncated:!0}:e,Rd=e=>e.timedOut?Ld(kd(e.stderr.text,e.timeoutMs),e.stdout):e.errorMessage===void 0?Ld({exitCode:Fd(e.code),stderr:wd(e.stderr.text,e.stdout,e.stderr),stdout:e.stdout.text},e.stdout):Ld({exitCode:127,stderr:Cd(e.stderr.text,e.errorMessage),stdout:e.stdout.text},e.stdout);var zd=class{async run(e,t,n){xd();let r=jd(e,t,n);if(Md(r))return r;let i=await Pd(r.child);return gd.delete(r.child),r.timeout.clear(),Rd({code:i.code,errorMessage:i.errorMessage,stderr:r.stderrCollector.finish(),stdout:r.stdoutCollector.finish(),timedOut:r.timeout.markedTimedOut(),timeoutMs:n?.timeoutMs})}};const Bd=`\0unreadable`,Vd=`pnpm-workspace.yaml`,Hd=async(e,t)=>{let n=await e.run(`git`,[`ls-tree`,`-z`,`--name-only`,t.rev,`--`,t.path],{cwd:t.dir});return n.exitCode===0&&!Id(n)?n.stdout.includes(t.path):void 0},Ud=async(e,t)=>{let n=await Hd(e,t);if(n===void 0)return{kind:`unreadable`};if(!n)return{kind:`absent`};let r=await e.run(`git`,[`show`,`${t.rev}:${t.path}`],{cwd:t.dir});return r.exitCode===0&&!Id(r)?{contents:r.stdout}:{kind:`unreadable`}},Wd=async(e,t,n)=>{let r=await Ud(e,{dir:t.dir,path:`package.json`,rev:n});if(`kind`in r)return r.kind===`absent`?[]:[Bd];try{let e=JSON.parse(r.contents);return nd(e.workspaces)}catch{return[Bd]}},Gd=async(e,t,n)=>{let r=await Ud(e,{dir:t.dir,path:Vd,rev:n});if(`kind`in r)return r.kind===`absent`?[]:[Bd];let{contents:i}=r,a=od(i.split(`
|
|
408
|
+
`));return pd(i,a)?[Bd]:a},Kd=async(e,t,n)=>{let[r,i]=await Promise.all([Wd(e,t,n),Gd(e,t,n)]);return{npm:r,pnpm:i}},qd=(e,t)=>{let n=0;for(let r of t)if(n<e.length&&e[n]===r)n+=1;else if(r.startsWith(`!`))return!1;return n===e.length},Jd=async(e,t)=>{if(!t.touched)return!1;let[n,r]=await Promise.all([Kd(e,t,t.from),Kd(e,t,t.to)]);return!qd(n.npm,r.npm)||!qd(n.pnpm,r.pnpm)},Yd=e=>se(e)===`package.json`,Xd=async(e,t,n)=>{let r=await e.run(`git`,[...n],{cwd:t});return r.exitCode===0&&!Id(r)?r.stdout:void 0},Zd=e=>e.split(`\0`).filter(e=>e.length>0&&Yd(e)),Qd=async(e,t)=>{let n=await Xd(e,t.dir,[`diff`,`--name-only`,`-z`,`--no-renames`,`${t.from}..${t.to}`,`--`,`*package.json`,Vd]);return n===void 0?void 0:n.split(`\0`).filter(e=>e.length>0)},$d=async(e,t)=>{if(t.paths.length===0)return/* @__PURE__ */ new Set;let n=await Xd(e,t.dir,[`ls-tree`,`-r`,`-z`,`--name-only`,t.rev,`--`,...t.paths]);return n===void 0?void 0:new Set(Zd(n))},ef=async(e,t)=>{let n=await Xd(e,t.dir,[`show`,`${t.rev}:${t.path}`]);if(n!==void 0)try{let e=JSON.parse(n);return{name:sd(e)}}catch{return}},tf=async(e,t,n)=>{let r=[];for(let i of n){let n=await ef(e,{dir:t.dir,path:i,rev:t.rev});if(n===void 0)return;n.name!==void 0&&r.push(n.name)}return r},nf={changedDirs:[],namesBefore:[]},rf=(e,t,n)=>Jd(e,{...t,touched:n.some(e=>e===`pnpm-workspace.yaml`||e===`package.json`)}),af=e=>[...new Set(e.map(e=>m(e)))].filter(e=>e!==`.`).toSorted(),of=async(e,t,n)=>{let r=await $d(e,{dir:t.dir,paths:n,rev:t.from});if(r!==void 0)return tf(e,{dir:t.dir,rev:t.from},n.filter(e=>r.has(e)))},sf=async(e,t)=>{if(t.from===t.to)return nf;let n=await Qd(e,t);if(n===void 0||await rf(e,t,n))return;let r=n.filter(e=>Yd(e));if(r.length>200)return;let i=await of(e,t,r);return i===void 0?void 0:{changedDirs:af(r),namesBefore:i}},cf=e=>{let t=e.stderr.trim()||e.stdout.trim()||`exit code ${e.exitCode}`,n=t.split(`
|
|
409
|
+
`)[0]??t;return n.length<=200?n:`${n.slice(0,200)}…`},lf=(e,t)=>t?`restored`:e.oldSha===e.newSha?`fresh`:`updated`,uf=(e,t)=>{let n=[];if(e&&n.push(`checkout had local changes (managed checkouts are read-only) — discarded and restored to the remote state`),t!==void 0&&n.push(t),n.length!==0)return n.join(` | `)},df=e=>{let{branchRenamedTo:t,dirty:n,setHeadWarning:r,shas:i}=e,a={...i,status:lf(i,n)};t!==void 0&&(a.branchRenamedTo=t);let o=uf(n,r);return o!==void 0&&(a.warning=o),a},ff=(e,t,n)=>{let r={dirty:t,shas:n};return e.branchRenamedTo!==void 0&&(r.branchRenamedTo=e.branchRenamedTo),e.warning!==void 0&&(r.setHeadWarning=e.warning),r},U=e=>ie(h(e,`.git`)),pf=e=>`refusing to sync ${e}: not a refs-managed checkout`,mf=async(e,t,n)=>{if(!U(t))throw z(pf(t));let r=await e.run(`git`,[`config`,`--local`,`--get`,`core.hooksPath`],{cwd:t}),i=r.stdout.trim();if(r.exitCode!==0||i===``||i!==n)throw z(pf(t))},hf=/^(?<scheme>[a-z][a-z0-9+.-]*:\/\/)?[\s\S]*@/iu,gf=/(?<scheme>[a-z][a-z0-9+.-]{0,31}:\/\/)[^/\s@]{1,256}@/giu,_f=e=>e.replace(gf,`$<scheme><redacted>@`),vf=/^git@[^:/\s]+:[^\s]+$/u,yf=e=>{try{return new URL(e)}catch{return}},bf=e=>e.password===``&&e.username===`git`&&e.protocol===`ssh:`,xf=e=>{if(vf.test(e))return e;let t=yf(e);return t===void 0?e.includes(`@`)?W(e):e:t.username===``&&t.password===``||bf(t)?e:`${t.protocol}//<redacted>@${t.host}${t.pathname}${t.search}${t.hash}`},W=e=>{let t=e.replace(hf,`$<scheme><redacted>@`);return t.length<=200?t:`${t.slice(0,200)}…`},Sf=e=>{let t=_f(e);return t.length<=2e3?t:`${t.slice(0,2e3)}… (truncated)`},Cf=/filtering not recognized/iu,wf=e=>e===void 0?{}:{cwd:e},Tf=(e,t,n)=>({action:e,args:t,cmd:`git`,...wf(n)}),Ef=async(e,t)=>{let n=await e.run(t.cmd,t.args,wf(t.cwd));if(n.exitCode===0)return n;let r=n.stderr.trim()||n.stdout.trim()||`exit code ${n.exitCode}`;throw z(`${t.action} failed: ${Sf(r)}`)},Df=async(e,t)=>{let n=[`clone`,`-q`,`-c`,`core.hooksPath=${t.hooksDir}`];t.mode===`blobless`&&n.push(`--filter=blob:none`),n.push(`--`,t.cloneUrl,t.dest);let r=await Ef(e,Tf(`git clone`,n));return await Ef(e,Tf(`git config core.hooksPath`,[`config`,`core.hooksPath`,t.hooksDir],t.dest)),t.mode===`blobless`&&Cf.test(r.stderr)?{effectiveMode:`full`,warning:`server did not honour the partial-clone filter (blob:none); fell back to a full clone`}:{effectiveMode:t.mode}},Of=async(e,t)=>{let n=await e.run(`git`,[`symbolic-ref`,`--short`,`refs/remotes/origin/HEAD`],{cwd:t});if(n.exitCode!==0)return;let r=n.stdout.trim();return r.startsWith(`origin/`)?r.slice(7):r},kf=async(e,t)=>{let n=await Of(e,t);if(n!==void 0)return n;await e.run(`git`,[`remote`,`set-head`,`origin`,`--auto`],{cwd:t});let r=await Of(e,t);if(r!==void 0)return r;throw z(`could not detect the default branch for checkout: ${t}`)},Af=async(e,t)=>(await Ef(e,Tf(`git rev-parse HEAD`,[`rev-parse`,`HEAD`],t))).stdout.trim(),jf=async(e,t)=>(await Ef(e,Tf(`git status --porcelain`,[`status`,`--porcelain`],t))).stdout.trim()!==``,Mf=async(e,t)=>{await Ef(e,Tf(`git fetch`,[`fetch`,`--prune`,`--tags`,`origin`],t.dir));let n=await e.run(`git`,[`remote`,`set-head`,`origin`,`--auto`],{cwd:t.dir}),r=await kf(e,t.dir),i={branch:r};return r!==t.defaultBranch&&(i.branchRenamedTo=r),n.exitCode!==0&&(i.warning=`could not refresh origin/HEAD: ${cf(n)}`),i},Nf=e=>[Tf(`git reset --hard HEAD (pre-checkout)`,[`reset`,`--hard`,`HEAD`],e),Tf(`git clean -fd`,[`clean`,`-fd`],e)],Pf=async(e,t)=>{let{branch:n,dir:r,dirty:i}=t,a=[];i&&a.push(...Nf(r)),a.push(Tf(`git checkout -B`,[`checkout`,`-B`,n,`origin/${n}`],r),Tf(`git reset --hard`,[`reset`,`--hard`,`origin/${n}`],r));for(let t of a)await Ef(e,t)},Ff=async(e,t)=>{await mf(e,t.dir,t.hooksDir);let n=await Af(e,t.dir),r=await Mf(e,t),i=await jf(e,t.dir);await Pf(e,{branch:r.branch,dir:t.dir,dirty:i});let a=await Af(e,t.dir);return df(ff(r,i,{newSha:a,oldSha:n}))},If=async(e,t,n)=>(await e.run(`git`,[`show-ref`,`--verify`,`--`,`refs/tags/${n}`],{cwd:t})).exitCode===0,Lf=[`#!/bin/sh`,`echo "refs: this checkout is a managed read-only reference — commits are blocked" >&2`,`exit 1`,``].join(`
|
|
410
|
+
`),Rf=async e=>{await Promise.all([`pre-commit`,`pre-push`].map(async t=>{await pu(h(e.hooksDir,t),Lf,493)}))},zf=async(e,t,n)=>{let r=await Ef(e,Tf(`git tag`,[`tag`,`--sort=-version:refname`],t)),i=r.stdout.split(`
|
|
411
|
+
`).map(e=>e.trim()).filter(e=>e!==``),a=r.stdoutTruncated!==!0;return n===void 0?{complete:a,tags:i}:{complete:a&&i.length<=n,tags:i.slice(0,n)}},Bf=/\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?/u,Vf=/\d+\.\d+\.\d+/gu,Hf=e=>pl.safeParse(e).success,Uf=e=>{let t=e.match(Vf);return t!==null&&t.length>1},Wf=e=>{let t=Bf.exec(e);if(!t||Uf(e))return;let[n]=t,r=e.replace(n,`{version}`);if(Hf(r))return r},Gf=(e,t,n)=>{let r=e.get(t);r===void 0?e.set(t,{count:1,index:n}):r.count+=1},Kf=e=>{let t=/* @__PURE__ */ new Map;for(let[n,r]of e.entries()){let e=Wf(r);e&&Gf(t,e,n)}return t},qf=(e,t)=>e.count>t.count||e.count===t.count&&e.index<t.index,Jf=e=>{let t=[...e.entries()],[n]=t;if(n===void 0)return null;let[r,i]=n;return t.slice(1).reduce(({format:e,data:t},[n,r])=>qf(r,t)?{data:r,format:n}:{data:t,format:e},{data:i,format:r}).format},Yf=e=>{let t=Kf(e);return Jf(t)},Xf=(e,t)=>e.replaceAll(`{version}`,()=>t),Zf=async(e,t,n,r)=>{let i=Xf(n,r);if(!await If(e,t,i))throw gu(`tag '${i}' not found in ${t} — check the version or tag_format`);return i},Qf=/^\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.+-]+)?$/u,$f=/[0-9.]$/u,ep=[`@`,`-`,`_`,`/`],tp=`{version}`,np=(e,t)=>ep.some(n=>e===`${t}${n}`||e===`${t}${n}v`),rp=(e,t)=>np(e.slice(0,e.length-9),t)&&e.endsWith(tp),ip=(e,t)=>t!==void 0&&np(e,t)?2:+(e===``||e===`v`),ap=(e,t)=>{if(!e.endsWith(t))return;let n=e.slice(0,e.length-t.length);return $f.test(n)?void 0:n},op=(e,t,n)=>{let r=ap(e,t);if(r===void 0)return;let i=pl.safeParse(`${r}${tp}`);if(i.success&&Xf(i.data,t)===e)return{format:i.data,rank:ip(r,n)}},sp=e=>{let t=e.filter(e=>e.rank>0),n=t.reduce((e,t)=>Math.max(e,t.rank),0),r=new Set(t.filter(e=>e.rank===n).map(e=>e.format)),[i]=[...r];return r.size===1&&i!==void 0?i:null},cp=(e,t,n)=>t.length>64||!Qf.test(t)?null:sp(e.map(e=>op(e,t,n)).filter(e=>e!==void 0)),lp=e=>e.split(`/`).some(e=>e===`.`||e===`..`),up=e=>e.includes(`\\`),dp=e=>e.includes(`%`),fp=/[\u0000-\u001F\u007F]/u,pp=/^ | $/u,mp=/[?#]/u,hp=(e,t)=>`not a supported git url: control character ${`U+${(e.codePointAt(t)??0).toString(16).toUpperCase().padStart(4,`0`)}`} at position ${String(t)}`,gp=(e,t)=>{let n=e.search(fp);if(n!==-1)throw z(hp(e,n));if(pp.test(e))throw z(`not a supported git url: leading or trailing space`);if(mp.test(e))throw z(`not a supported git url: query or fragment in ${W(t)}`);_p(e,t),vp(e,t)},_p=(e,t)=>{if(up(e))throw z(`not a supported git url: backslash not allowed in ${W(t)}`)},vp=(e,t)=>{if(lp(e))throw z(`not a supported git url: path traversal segment in ${W(t)}`)},yp=(e,t,n)=>{if(e.protocol!==`file:`&&dp(t))throw z(`not a supported git url: percent-encoding not supported in ${W(n)}`)},bp=/\.git$/u,xp=e=>e.replace(bp,``),Sp=e=>{let t=0,n=e.length;for(;t<n&&e.charAt(t)===`/`;)t+=1;for(;n>t&&e.charAt(n-1)===`/`;)--n;return e.slice(t,n)},Cp=/^git@(?<host>[^:/\s]+):(?<path>[^\s]+)$/u,wp=/^git\+/u,Tp={"https:":`443`,"ssh:":`22`},Ep=e=>{let t=cl.safeParse(e);if(!t.success)throw z(`not a supported git url: derived key '${W(e)}' is invalid`);return t.data},Dp=({host:e,port:t,protocol:n})=>{let r=Tp[n];return t===``||t===r?e.toLowerCase():`${e.toLowerCase()}_${t}`},Op=e=>{let t=xp(Sp(e.path));return Ep(`${Dp(e)}/${t}`)},kp=e=>{let t=decodeURIComponent(e).split(`/`).filter(e=>e!==``);if(t.length<2)throw z(`not a supported git url: file url path must have at least 2 segments`);let n=t.at(-2)??``,r=t.at(-1)??``;return Ep(`local/${n}/${r}`)},Ap=(e,t)=>{try{return new URL(e)}catch{throw z(`not a supported git url: ${W(t)}`)}},jp=e=>{if(e.password!==``)throw z(`not a supported git url: credentials embedded in url`);if(e.protocol===`https:`&&e.username!==``)throw z(`not a supported git url: credentials embedded in https url`)},Mp=(e,t)=>{if(e.protocol===`file:`){if(!t)throw z(`not a supported git url: unsupported protocol ${e.protocol}`);return kp(e.pathname)}if(e.protocol!==`https:`&&e.protocol!==`ssh:`)throw z(`not a supported git url: unsupported protocol ${e.protocol}`);return jp(e),Op({host:e.hostname,path:e.pathname,port:e.port,protocol:e.protocol})},Np=(e,t)=>{if(dp(e))throw z(`not a supported git url: percent-encoding not supported in ${W(t)}`);if(e.includes(`:`))throw z(`not a supported git url: ambiguous ':' in scp-style path ${W(t)}; use the ssh:// url form instead`);if(e.startsWith(`/`)||e.startsWith(`~`))throw z(`not a supported git url: ambiguous absolute/home-relative scp path in ${W(t)}; use the ssh:// url form instead`)},Pp=(e,t)=>{let n=e.groups?.path??``;return Np(n,t),Op({host:e.groups?.host??``,path:n,port:``,protocol:`ssh:`})},Fp=(e,t)=>{let n=t?.allowFileUrls??!1,r=e.replace(wp,``);gp(r,e);let i=Cp.exec(r);if(i?.groups!==void 0)return{cloneUrl:r,key:Pp(i,e)};let a=Ap(r,e);return yp(a,r,e),{cloneUrl:r,key:Mp(a,n)}},Ip=`.git`,Lp=e=>e.endsWith(Ip)?e:`${e}${Ip}`,Rp=(e,t)=>`https://${e.toLowerCase()}/${Sp(t)}`,zp=(e,t)=>`git@${e.toLowerCase()}:${Lp(Sp(t))}`,Bp=e=>{if(e===`https:`)return`https`;if(e===`ssh:`)return`ssh`;throw z(`not a supported git url: unsupported protocol ${e}`)},Vp=(e,t,n)=>{let r=Tp[e.protocol];if(e.port!==``&&e.port!==r)throw z(`cannot apply git_transport=${t} to ${W(n)}: its non-default port ${e.port} cannot be expressed in the ${t} url form — add the repo with an explicit url instead`)},Hp=(e,t)=>t===`https`?Rp(e.hostname,e.pathname):zp(e.hostname,e.pathname),Up=(e,t,n)=>{let r=Fp(t).key;if(r!==n)throw z(`git_transport transform changed repo identity: '${W(e)}' → '${t}' (key '${n}' → '${r}')`);return t},Wp=(e,t)=>{if(t.transport===`ssh`)return t.cloneUrl;let n=e.groups?.host??``,r=e.groups?.path??``;return Up(t.cloneUrl,Rp(n,r),t.originalKey)},Gp=e=>{let t=Ap(e.cloneUrl,e.cloneUrl);return Bp(t.protocol)===e.transport?e.cloneUrl:(Vp(t,e.transport,e.cloneUrl),Up(e.cloneUrl,Hp(t,e.transport),e.originalKey))},Kp=(e,t)=>{if(e.startsWith(`file:`))return e;let n={cloneUrl:e,originalKey:Fp(e).key,transport:t},r=Cp.exec(e);return r?.groups===void 0?Gp(n):Wp(r,n)},qp=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/u,Jp=(e,t)=>{if(qp.test(t))return h(e,`lease-${t}`)},Yp=async(e,t)=>{let n=Jp(e,t);
|
|
412
|
+
/* v8 ignore next 3 -- `token` here is always this process's own `randomUUID()`; the guard exists
|
|
413
|
+
for the read path, where the token comes off disk. */
|
|
414
|
+
n!==void 0&&await(await o(n,`w`,384)).close()},Xp=async(e,t)=>{let n=Jp(e,t);
|
|
415
|
+
/* v8 ignore next 3 -- as in `createLeaseSidecar`: the heartbeat only ever renews with the token
|
|
416
|
+
its own acquisition minted. */
|
|
417
|
+
if(n===void 0)return`gone`;let r=/* @__PURE__ */ new Date;try{await ee(n,r,r)}catch(e){if(I(e))return`gone`;throw e}return`renewed`},Zp=async(e,t)=>{let n=Jp(e,t);if(n===void 0)return{state:`absent`};try{return{mtimeMs:(await p(n)).mtimeMs,state:`ok`}}catch(e){return{state:I(e)?`absent`:`unreadable`}}},Qp=`meta.json`,$p=e=>{try{return process.kill(e,0),!0}catch(e){return du(e)!==`ESRCH`}},em=e=>{try{return JSON.parse(e)}catch{return}},tm=async e=>{try{return await s(e,`utf8`)}catch{return}},nm=/* @__PURE__ */ new Set([`ENOENT`,`ENOTDIR`]),rm=async e=>{try{return{state:`read`,text:await s(e,`utf8`)}}catch(e){let t=du(e);return{state:t!==void 0&&nm.has(t)?`missing`:`unreadable`}}},im=e=>{if(typeof e!=`string`)return;let t=Date.parse(e);if(!Number.isNaN(t))return t},am=e=>{if(typeof e!=`object`||!e)return;let{token:t}=e;if(typeof t==`string`)return t},om=e=>{if(!(typeof e!=`number`||!Number.isSafeInteger(e)||e<=0||e>2147483647))return e},sm=e=>{if(typeof e!=`object`||!e)return;let t=e,n=om(t.pid),r=im(t.acquired_at);if(n===void 0||r===void 0)return;let i=am(e);return{acquiredAtMs:r,pid:n,...i===void 0?{}:{token:i}}},cm=async e=>{let t=await tm(h(e,Qp));if(t!==void 0)return am(em(t))},lm=async e=>{let t=await rm(h(e,Qp));if(t.state!==`read`)return{state:t.state};let n=sm(em(t.text));return n===void 0?{state:`malformed`}:{meta:n,state:`valid`}},um=async e=>{try{return{mtimeMs:(await p(e)).mtimeMs,state:`ok`}}catch(e){return{state:du(e)===`ENOENT`?`gone`:`unreadable`}}},dm=async(e,t)=>{let n=h(e,Qp),r=`${n}.tmp-${he()}`;await te(r,t,{encoding:`utf8`,mode:384}),await u(r,n)},fm=()=>he(),pm=async(e,t)=>{await Yp(e,t),await dm(e,JSON.stringify({acquired_at:(/* @__PURE__ */ new Date()).toISOString(),pid:process.pid,token:t}))},mm=5e3,hm=async(e,t,n)=>{if(t===`unreadable`)return{meta:t,observedAtMs:n,pidState:`unknown`,policy:`unknown`,stale:!1};let r=await um(e);if(r.state===`gone`)return{meta:t,observedAtMs:n,pidState:`unknown`,policy:`none`,stale:!1};if(r.state===`unreadable`)return{meta:t,observedAtMs:n,pidState:`unknown`,policy:`unknown`,stale:!1};let i=n-r.mtimeMs;return{ageMs:i,budgetMs:mm,meta:t,observedAtMs:n,pidState:`unknown`,policy:`grace`,stale:i>mm}},gm=async(e,t,n)=>{let r=t.token===void 0?{state:`absent`}:await Zp(e,t.token);return r.state===`unreadable`?{policy:`unknown`}:r.state===`absent`?{ageMs:n-t.acquiredAtMs,budgetMs:6e5,policy:`legacy`}:{ageMs:n-r.mtimeMs,budgetMs:12e4,policy:`lease`}},_m=async(e,t)=>{let n=await lm(e);if(n.state!==`valid`)return hm(e,n.state,t);let{meta:r}=n,i=await gm(e,r,t),a=!$p(r.pid),o=i.ageMs!==void 0&&i.budgetMs!==void 0&&i.ageMs>i.budgetMs;return{...i,meta:`valid`,observedAtMs:t,pid:r.pid,pidState:a?`definitely-dead`:`present-or-unknown`,stale:a||o,...r.token===void 0?{}:{token:r.token}}},vm=e=>e.meta===`valid`&&e.pidState===`definitely-dead`&&e.token!==void 0,ym=async(e,t)=>await cm(e)===t?await Xp(e,t)===`gone`?`lost`:`renewed`:`lost`,bm=/* @__PURE__ */ new Set([`EEXIST`,`EPERM`,`EACCES`,`EBUSY`]),xm=/* @__PURE__ */ new Set([`ENOENT`,`EPERM`,`EACCES`,`EBUSY`]),Sm=async e=>{try{return await a(e,{mode:448,recursive:!1}),!0}catch(e){let t=du(e);if(t!==void 0&&bm.has(t))return!1;throw e}},Cm=async(e,t)=>{try{return await u(e,t),!0}catch(e){let t=du(e);if(t!==void 0&&xm.has(t))return!1;throw e}},wm=e=>a(e,{mode:448,recursive:!0}),Tm=`.claims`,Em=`.tombstones`,Dm=(e,t)=>({lockPath:h(e,t),locksDir:e,name:t}),Om=e=>h(e.locksDir,Tm,e.name),km=e=>h(e.locksDir,Em,he()),Am=async e=>{await a(h(e,Tm),{mode:448,recursive:!0}),await a(h(e,Em),{mode:448,recursive:!0})},jm=e=>Sm(e),Mm=async e=>{try{await f(e)}catch{}},Nm=async e=>{let t=km(e);return await Cm(e.lockPath,t)?t:void 0},Pm=async e=>{let t=await _m(e.lockPath,Date.now());if(!vm(t)||await cm(e.lockPath)!==t.token)return!1;let n=await Nm(e);return n!==void 0&&(await d(n,{force:!0,recursive:!0}),!0)},Fm=async e=>{await Am(e.locksDir);let t=Om(e);if(!await jm(t))return!1;let n=await Pm(e).then(e=>({ok:!0,stolen:e}),e=>({error:e,ok:!1}));if(await Mm(t),!n.ok)throw n.error;return n.stolen},Im=async e=>{try{return(await c(e,{withFileTypes:!0})).map(e=>({isDir:e.isDirectory(),name:e.name})).toSorted((e,t)=>e.name.localeCompare(t.name))}catch(e){if(I(e))return[];throw e}},Lm=async e=>(await Im(e)).filter(e=>!e.name.startsWith(`.`)),Rm=async(e,t,n)=>{let r=await _m(h(e,t.name),n);if(r.policy!==`none`)return{diagnosis:r,isDirectory:t.isDir,kind:`lock`,name:t.name}},zm=async(e,t)=>{let n=h(e,Tm),r=await Im(n);return(await Promise.all(r.map(async e=>({diagnosis:await _m(h(n,e.name),t),isDirectory:e.isDir,kind:`claim`,name:e.name})))).filter(e=>e.diagnosis.policy!==`none`)},Bm=async e=>{let t=Date.now(),n=await Lm(e.locksDir),[r,i]=await Promise.all([Promise.all(n.map(n=>Rm(e.locksDir,n,t))),zm(e.locksDir,t)]);return[...r.filter(e=>e!==void 0),...i]},Vm=e=>{let t=Math.floor(e/1e3),n=t%60,r=Math.floor(t/60),i=r%60,a=Math.floor(r/60);return a>0?i===0?`${a}h`:`${a}h ${i}m`:r>0?n===0?`${r}m`:`${r}m ${n}s`:`${n}s`},Hm=e=>e.pid===void 0?`owner unknown (metadata ${e.meta})`:e.pidState===`definitely-dead`?`recorded pid ${e.pid} is not running`:`recorded pid ${e.pid} is present (identity not verified)`,Um={grace:`created`,lease:`lease renewed`,legacy:`acquired`,none:`observed`,unknown:`observed`},Wm={grace:`from creation, while its metadata has not been published`,lease:`from the last renewal`,legacy:`from acquisition (no renewable lease)`,none:``,unknown:``},Gm=e=>{let{ageMs:t,budgetMs:n,policy:r}=e;return t===void 0||n===void 0?``:t<0?`, but its recorded time is in the future — check the system clock`:`, ${Um[r]} ${Vm(t)} ago; its window is ${Vm(n)} ${Wm[r]}`},Km=(e,t)=>{if(t.policy===`none`)return`lock ${e} could not be acquired before the timeout, but it was released while the failure was being diagnosed. Retry the operation.`;let n=`lock ${e} is held: ${Hm(t)}`;return vm(t)?`${n}, and refs is entitled to reclaim it — it could not do so before the timeout. Retry; if it persists, run refs doctor.`:t.stale?`${n}${Gm(t)}. refs does not reclaim this automatically: only a recorded process the operating system reports as gone is reclaimed, and this one is not. Run refs doctor for what to do about it.`:`${n}${Gm(t)}. Retry once the other refs command finishes.`},qm=(e,t)=>{if(t.stopped)return;let n=setTimeout(()=>{t.stopped||(t.inFlight=Jm(e,t))},e.intervalMs);n.unref(),t.timer=n},Jm=async(e,t)=>{try{if(await e.renew()===`lost`){t.lost=!0,t.stopped=!0;return}}catch{}qm(e,t)},Ym=e=>{let t={inFlight:Promise.resolve(),lost:!1,stopped:!1};return qm(e,t),{ownershipLost:()=>t.lost,stop:async()=>{t.stopped=!0,t.timer!==void 0&&clearTimeout(t.timer),await t.inFlight}}},Xm=/^[a-zA-Z0-9][a-zA-Z0-9_.-]*$/u,Zm=async(e,t)=>{try{await pm(e,t)}catch(e){if(du(e)===`ENOENT`)return`retry`;throw e}return t},Qm=async(e,t)=>{if(!await Sm(e))return;let n=await Zm(e,fm());return n===`retry`?Date.now()>=t?void 0:Qm(e,t):n},$m=async(e,t)=>{if(!await Fm(e)){if(Date.now()>=t){let t=await _m(e.lockPath,Date.now());throw hu(Km(e.name,t))}await xe(100)}},eh=async(e,t)=>{let n=await Qm(e.lockPath,t);return n===void 0?(await $m(e,t),eh(e,t)):n},th=async(e,t)=>await cm(e)===t&&(await d(e,{force:!0,recursive:!0}),!0),nh=async e=>{try{return{ok:!0,value:await e()}}catch(e){return{error:e,ok:!1}}},rh=async(e,t,n,r)=>{await n.stop();let i=await nh(()=>th(e.lockPath,t));if(!r.ok)throw r.error;if(!i.ok)throw i.error;if(n.ownershipLost()||!i.value)throw hu(`lock ${e.name} was lost while the operation was running`);return r.value},ih=e=>e!==`.`&&e!==`..`&&Xm.test(e),ah=e=>{if(!ih(e))throw z(`lock name must not contain "/" or other unsafe characters — only letters, digits, and "_.-" are allowed, and it may not be "." or "..": ${e}`)},G=async(e,t,n,r)=>{ah(t);let i=Dm(e.locksDir,t);await wm(e.locksDir);let a=Date.now()+(r?.timeoutMs??1e4),o=await eh(i,a),s=Ym({intervalMs:3e4,renew:()=>ym(i.lockPath,o)});return rh(i,o,s,await nh(n))},oh=pc({directory:j().optional(),url:j().optional()}),sh=pc({repository:hc([j(),oh]).optional()}),ch=/^(?:@[a-z0-9-~][a-z0-9._~-]*\/)?[a-z0-9-~][a-z0-9._~-]*$/u,lh=/* @__PURE__ */ new Set([`node_modules`,`favicon.ico`]),uh=e=>gu(`package '${e}' has no usable repository field — find the repository and run: refs add <git-url>`),dh=e=>{let[t,n]=e.split(`/`);return n??t??e},fh=e=>{if(e.length>214)throw R(`invalid package name: '${e}' exceeds maximum length of 214 characters`);if(!ch.test(e))throw R(`invalid package name: '${e}' does not match npm naming rules`);let t=dh(e);if(lh.has(t))throw R(`invalid package name: '${e}' uses a reserved name`)},ph=e=>e.replaceAll(`/`,`%2F`),mh=e=>typeof e==`string`?e:e?.url,hh=e=>{if(typeof e==`object`&&e?.directory){let t=ml.safeParse(e.directory);if(t.success)return t.data}},gh=e=>e instanceof Error&&(e.name===`TimeoutError`||e.name===`AbortError`),_h=e=>z(`npm registry did not answer for '${e}' within 10000ms`),vh=async(e,t)=>{try{return await e.json()}catch(e){throw gh(e)?_h(t):z(`invalid npm registry response for '${t}': not parseable JSON`)}},yh=async(e,t)=>{try{return await e(`https://registry.npmjs.org/${ph(t)}`,{signal:AbortSignal.timeout(1e4)})}catch(e){throw gh(e)?_h(t):e}},bh=async(e,t)=>{let n=await yh(e,t);if(n.status===404)throw gu(`npm package '${t}' not found`);if(n.status!==200)throw z(`failed to fetch npm package '${t}': status ${n.status}`);let r=await vh(n,t),i=sh.safeParse(r);if(!i.success)throw z(`invalid npm package response for '${t}'`);return i.data},xh=(e,t)=>{try{return Fp(e)}catch{throw uh(t)}},Sh=async(e,t)=>{fh(t);let n=await bh(e,t),r=mh(n.repository);if(r===void 0||r===``)throw uh(t);let{cloneUrl:i,key:a}=xh(r,t),o=hh(n.repository);return o===void 0?{cloneUrl:i,key:a}:{cloneUrl:i,directory:o,key:a}},Ch=(e,t,n)=>{let r=e instanceof RegExp?wh(e,n):e,i=t instanceof RegExp?wh(t,n):t,a=r!==null&&i!=null&&Th(r,i,n);return a&&{start:a[0],end:a[1],pre:n.slice(0,a[0]),body:n.slice(a[0]+r.length,a[1]),post:n.slice(a[1]+i.length)}},wh=(e,t)=>{let n=t.match(e);return n?n[0]:null},Th=(e,t,n)=>{let r,i,a,o,s,c=n.indexOf(e),l=n.indexOf(t,c+1),u=c;if(c>=0&&l>0){if(e===t)return[c,l];for(r=[],a=n.length;u>=0&&!s;){if(u===c)r.push(u),c=n.indexOf(e,u+1);else if(r.length===1){let e=r.pop();e!==void 0&&(s=[e,l])}else i=r.pop(),i!==void 0&&i<a&&(a=i,o=l),l=n.indexOf(t,u+1);u=c<l&&c>=0?c:l}r.length&&o!==void 0&&(s=[a,o])}return s},Eh=`\0SLASH`+Math.random()+`\0`,Dh=`\0OPEN`+Math.random()+`\0`,Oh=`\0CLOSE`+Math.random()+`\0`,kh=`\0COMMA`+Math.random()+`\0`,Ah=`\0PERIOD`+Math.random()+`\0`,jh=new RegExp(Eh,`g`),Mh=new RegExp(Dh,`g`),Nh=new RegExp(Oh,`g`),Ph=new RegExp(kh,`g`),Fh=new RegExp(Ah,`g`),Ih=/\\\\/g,Lh=/\\{/g,Rh=/\\}/g,zh=/\\,/g,Bh=/\\\./g;function Vh(e){return isNaN(e)?e.charCodeAt(0):parseInt(e,10)}function Hh(e){return e.replace(Ih,Eh).replace(Lh,Dh).replace(Rh,Oh).replace(zh,kh).replace(Bh,Ah)}function Uh(e){return e.replace(jh,`\\`).replace(Mh,`{`).replace(Nh,`}`).replace(Ph,`,`).replace(Fh,`.`)}function Wh(e,t){for(let n=0;n<t.length;n++)e.push(t[n])}function Gh(e){let t=[],n=``;for(;;){let r=Ch(`{`,`}`,e);if(!r){let r=e.split(`,`);return r[0]=n+r[0],Wh(t,r),t}let{pre:i,body:a,post:o}=r,s=i.split(`,`);if(s[0]=n+s[0],s[s.length-1]+=`{`+a+`}`,!o.length)return Wh(t,s),t;n=s.pop(),Wh(t,s),e=o}}function Kh(e,t={}){if(!e)return[];let{max:n=1e5,maxLength:r=4e6,maxDepth:i=1e3,maxRewrites:a=1e3}=t;return e.slice(0,2)===`{}`&&(e=`\\{\\}`+e.slice(2)),$h(Hh(e),n,r,i,0,a,!0).map(Uh)}function qh(e){return`{`+e+`}`}function Jh(e){return/^-?0\d/.test(e)}function Yh(e,t){return e<=t}function Xh(e,t){return e>=t}function Zh(e,t,n,r,i,a){let o=[],s=0;for(let c=0;c<e.length;c++)for(let l=0;l<n.length;l++){if(o.length>=r)return o;let u=e[c]+t+n[l];if(!a||u){if(s+u.length>i)return o;o.push(u),s+=u.length}}return o}function Qh(e,t,n,r){let i=e.split(/\.\./),a=[];
|
|
418
|
+
/* c8 ignore start */
|
|
419
|
+
if(i[0]===void 0||i[1]===void 0)return a;
|
|
420
|
+
/* c8 ignore stop */
|
|
421
|
+
let o=Vh(i[0]),s=Vh(i[1]),c=Math.max(i[0].length,i[1].length),l=i.length===3&&i[2]!==void 0?Math.max(Math.abs(Vh(i[2])),1):1,u=Yh;s<o&&(l*=-1,u=Xh);let d=i.some(Jh),f=0;for(let e=o;u(e,s)&&a.length<n;e+=l){let n;if(t)n=String.fromCharCode(e),n===`\\`&&(n=``);else if(n=String(e),d){let t=c-n.length;if(t>0){let r=Array(t+1).join(`0`);n=e<0?`-`+r+n.slice(1):r+n}}if(f+n.length>r)break;a.push(n),f+=n.length}return a}function $h(e,t,n,r,i,a,o){if(i>r)return[e];let s=[``],c=0,l=!1,u=!0;for(;;){let d=Ch(`{`,`}`,e);if(!d)return Zh(s,e,[``],t,n,l);let f=d.pre;if(/\$$/.test(f)){if(s=Zh(s,f+`{`+d.body+`}`,[``],t,n,l&&!d.post.length),u=!1,!d.post.length)break;e=d.post;continue}let p=/^-?\d+\.\.-?\d+(?:\.\.-?\d+)?$/.test(d.body),ee=/^[a-zA-Z]\.\.[a-zA-Z](?:\.\.-?\d+)?$/.test(d.body),te=p||ee,ne=d.body.indexOf(`,`)>=0;if(!te&&!ne){if(c<a&&d.post.match(/,(?!,).*\}/)){c++,e=d.pre+`{`+d.body+Oh+d.post,o=!0;continue}return Zh(s,f+`{`+d.body+`}`+d.post,[``],t,n,l)}u&&=(l=o&&!te,!1);let re;if(te)re=Qh(d.body,ee,t,n);else{let o=Gh(d.body);if(o.length===1&&o[0]!==void 0&&(o=$h(o[0],t,n,r,i+1,a,!1).map(qh),o.length===1)){if(s=Zh(s,f+o[0],[``],t,n,l&&!d.post.length),!d.post.length)break;e=d.post;continue}let c=l&&!d.post.length&&!f;for(let e=0;c&&e<s.length;e++)s[e]&&(c=!1);re=[];let u=0;outer:for(let e=0;e<o.length;e++){let s=$h(o[e],t,n,r,i+1,a,!1);for(let e=0;e<s.length;e++){let r=s[e];if(!c||r){if(re.length>=t||u+r.length>n)break outer;re.push(r),u+=r.length}}}}if(s=Zh(s,f,re,t,n,l&&!d.post.length),!d.post.length)break;e=d.post}return s}const eg=e=>{if(typeof e!=`string`)throw TypeError(`invalid pattern`);if(e.length>65536)throw TypeError(`pattern is too long`)},tg={"[:alnum:]":[`\\p{L}\\p{Nl}\\p{Nd}`,!0],"[:alpha:]":[`\\p{L}\\p{Nl}`,!0],"[:ascii:]":[`\\x00-\\x7f`,!1],"[:blank:]":[`\\p{Zs}\\t`,!0],"[:cntrl:]":[`\\p{Cc}`,!0],"[:digit:]":[`\\p{Nd}`,!0],"[:graph:]":[`\\p{Z}\\p{C}`,!0,!0],"[:lower:]":[`\\p{Ll}`,!0],"[:print:]":[`\\p{C}`,!0],"[:punct:]":[`\\p{P}`,!0],"[:space:]":[`\\p{Z}\\t\\r\\n\\v\\f`,!0],"[:upper:]":[`\\p{Lu}`,!0],"[:word:]":[`\\p{L}\\p{Nl}\\p{Nd}\\p{Pc}`,!0],"[:xdigit:]":[`A-Fa-f0-9`,!1]},ng=e=>e.replace(/[[\]\\-]/g,`\\$&`),rg=e=>e.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,`\\$&`),ig=e=>e.join(``),ag=(e,t)=>{let n=t;
|
|
422
|
+
/* c8 ignore start */
|
|
423
|
+
if(e.charAt(n)!==`[`)throw Error(`not in a brace expression`);
|
|
424
|
+
/* c8 ignore stop */
|
|
425
|
+
let r=[],i=[],a=n+1,o=!1,s=!1,c=!1,l=!1,u=n,d=``;WHILE:for(;a<e.length;){let t=e.charAt(a);if((t===`!`||t===`^`)&&a===n+1)l=!0,a++;else{if(t===`]`&&o&&!c){u=a+1;break}if(o=!0,t===`\\`&&!c)c=!0,a++;else{if(t===`[`&&!c){for(let[t,[o,c,l]]of Object.entries(tg))if(e.startsWith(t,a)){if(d)return[`$.`,!1,e.length-n,!0];a+=t.length,l?i.push(o):r.push(o),s||=c;continue WHILE}}c=!1,d?(t>d?r.push(ng(d)+`-`+ng(t)):t===d&&r.push(ng(t)),d=``,a++):e.startsWith(`-]`,a+1)?(r.push(ng(t+`-`)),a+=2):e.startsWith(`-`,a+1)?(d=t,a+=2):(r.push(ng(t)),a++)}}}if(u<a)return[``,!1,0,!1];if(!r.length&&!i.length)return[`$.`,!1,e.length-n,!0];if(i.length===0&&r.length===1&&/^\\?.$/.test(r[0])&&!l){let e=r[0].length===2?r[0].slice(-1):r[0];return[rg(e),!1,u-n,!1]}let f=`[`+(l?`^`:``)+ig(r)+`]`,p=`[`+(l?``:`^`)+ig(i)+`]`;return[r.length&&i.length?`(`+f+`|`+p+`)`:r.length?f:p,s,u-n,!0]},og=(e,{windowsPathsNoEscape:t=!1,magicalBraces:n=!0}={})=>n?t?e.replace(/\[([^/\\])\]/g,`$1`):e.replace(/((?!\\).|^)\[([^/\\])\]/g,`$1$2`).replace(/\\([^/])/g,`$1`):t?e.replace(/\[([^/\\{}])\]/g,`$1`):e.replace(/((?!\\).|^)\[([^/\\{}])\]/g,`$1$2`).replace(/\\([^/{}])/g,`$1`);var K;const sg=/* @__PURE__ */ new Set([`!`,`?`,`+`,`*`,`@`]),cg=e=>sg.has(e),lg=e=>cg(e.type),ug=/* @__PURE__ */ new Map([[`!`,[`@`]],[`?`,[`?`,`@`]],[`@`,[`@`]],[`*`,[`*`,`+`,`?`,`@`]],[`+`,[`+`,`@`]]]),dg=/* @__PURE__ */ new Map([[`!`,[`?`]],[`@`,[`?`]],[`+`,[`?`,`*`]]]),fg=/* @__PURE__ */ new Map([[`!`,[`?`,`@`]],[`?`,[`?`,`@`]],[`@`,[`?`,`@`]],[`*`,[`*`,`+`,`?`,`@`]],[`+`,[`+`,`@`,`?`,`*`]]]),pg=/* @__PURE__ */ new Map([[`!`,/* @__PURE__ */ new Map([[`!`,`@`]])],[`?`,/* @__PURE__ */ new Map([[`*`,`*`],[`+`,`*`]])],[`@`,/* @__PURE__ */ new Map([[`!`,`!`],[`?`,`?`],[`@`,`@`],[`*`,`*`],[`+`,`+`]])],[`+`,/* @__PURE__ */ new Map([[`?`,`*`],[`*`,`*`]])]]),mg=`(?!\\.)`,hg=/* @__PURE__ */ new Set([`[`,`.`]),gg=/* @__PURE__ */ new Set([`..`,`.`]),_g=/* @__PURE__ */ new Set(`().*{}+?[]^$\\!`),vg=e=>e.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,`\\$&`),yg=`[^/]+?`;let bg=0;var xg=class{type;#e;#t;#n=!1;#r=[];#i;#a;#o;#s=!1;#c;#l;#u=!1;id=++bg;get depth(){return(this.#i?.depth??-1)+1}[Symbol.for(`nodejs.util.inspect.custom`)](){return{"@@type":`AST`,id:this.id,type:this.type,root:this.#e.id,parent:this.#i?.id,depth:this.depth,partsLength:this.#r.length,parts:this.#r}}constructor(e,t,n={}){this.type=e,e&&(this.#t=!0),this.#i=t,this.#e=this.#i?this.#i.#e:this,this.#c=this.#e===this?n:this.#e.#c,this.#o=this.#e===this?[]:this.#e.#o,e===`!`&&!this.#e.#s&&this.#o.push(this),this.#a=this.#i?this.#i.#r.length:0}get hasMagic(){
|
|
426
|
+
/* c8 ignore start */
|
|
427
|
+
if(this.#t!==void 0)return this.#t;
|
|
428
|
+
/* c8 ignore stop */
|
|
429
|
+
for(let e of this.#r)if(typeof e!=`string`&&(e.type||e.hasMagic))return this.#t=!0;return this.#t}toString(){return this.#l===void 0?this.#l=this.type?this.type+`(`+this.#r.map(e=>String(e)).join(`|`)+`)`:this.#r.map(e=>String(e)).join(``):this.#l}#d(){
|
|
430
|
+
/* c8 ignore start */
|
|
431
|
+
if(this!==this.#e)throw Error(`should only call on root`);if(this.#s)return this;this.toString(),this.#s=!0;let e;for(;e=this.#o.pop();){if(e.type!==`!`)continue;let t=e,n=t.#i;for(;n;){for(let r=t.#a+1;!n.type&&r<n.#r.length;r++)for(let t of e.#r){
|
|
432
|
+
/* c8 ignore start */
|
|
433
|
+
if(typeof t==`string`)throw Error(`string part in extglob AST??`);
|
|
434
|
+
/* c8 ignore stop */
|
|
435
|
+
t.copyIn(n.#r[r])}t=n,n=t.#i}}return this}push(...e){for(let t of e)if(t!==``){
|
|
436
|
+
/* c8 ignore start */
|
|
437
|
+
if(typeof t!=`string`&&!(t instanceof K&&t.#i===this))throw Error(`invalid part: `+t);
|
|
438
|
+
/* c8 ignore stop */
|
|
439
|
+
this.#r.push(t)}}toJSON(){let e=this.type===null?this.#r.slice().map(e=>typeof e==`string`?e:e.toJSON()):[this.type,...this.#r.map(e=>e.toJSON())];return this.isStart()&&!this.type&&e.unshift([]),this.isEnd()&&(this===this.#e||this.#e.#s&&this.#i?.type===`!`)&&e.push({}),e}isStart(){if(this.#e===this)return!0;if(!this.#i?.isStart())return!1;if(this.#a===0)return!0;let e=this.#i;for(let t=0;t<this.#a;t++){let n=e.#r[t];if(!(n instanceof K&&n.type===`!`))return!1}return!0}isEnd(){if(this.#e===this||this.#i?.type===`!`)return!0;if(!this.#i?.isEnd())return!1;if(!this.type)return this.#i?.isEnd();
|
|
440
|
+
/* c8 ignore start */
|
|
441
|
+
let e=this.#i?this.#i.#r.length:0;
|
|
442
|
+
/* c8 ignore stop */
|
|
443
|
+
return this.#a===e-1}copyIn(e){typeof e==`string`?this.push(e):this.push(e.clone(this))}clone(e){let t=new K(this.type,e);for(let e of this.#r)t.copyIn(e);return t}static#f(e,t,n,r,i){let a=r.maxExtglobRecursion??2,o=!1,s=!1,c=-1,l=!1;if(t.type===null){let u=n,d=``;for(;u<e.length;){let n=e.charAt(u++);if(o||n===`\\`)o=!o,d+=n;else if(s)u===c+1?(n===`^`||n===`!`)&&(l=!0):n===`]`&&!(u===c+2&&l)&&(s=!1),d+=n;else if(n===`[`)s=!0,c=u,l=!1,d+=n;else if(!r.noext&&cg(n)&&e.charAt(u)===`(`&&i<=a){t.push(d),d=``;let a=new K(n,t);u=K.#f(e,a,u,r,i+1),t.push(a)}else d+=n}return t.push(d),u}let u=n+1,d=new K(null,t),f=[],p=``;for(;u<e.length;){let n=e.charAt(u++);if(o||n===`\\`)o=!o,p+=n;else if(s)u===c+1?(n===`^`||n===`!`)&&(l=!0):n===`]`&&!(u===c+2&&l)&&(s=!1),p+=n;else if(n===`[`)s=!0,c=u,l=!1,p+=n;else if(!r.noext&&cg(n)&&e.charAt(u)===`(`&&(i<=a||t&&t.#h(n))){let a=t&&t.#h(n)?0:1;d.push(p),p=``;let o=new K(n,d);d.push(o),u=K.#f(e,o,u,r,i+a)}else if(n===`|`)d.push(p),p=``,f.push(d),d=new K(null,t);else{if(n===`)`)return p===``&&t.#r.length===0&&(t.#u=!0),d.push(p),p=``,t.push(...f,d),u;p+=n}}return t.type=null,t.#t=void 0,t.#r=[e.substring(n-1)],u}#p(e){return this.#m(e,dg)}#m(e,t=ug){if(!e||typeof e!=`object`||e.type!==null||e.#r.length!==1||this.type===null)return!1;let n=e.#r[0];return!n||typeof n!=`object`||n.type===null?!1:this.#h(n.type,t)}#h(e,t=fg){return!!t.get(this.type)?.includes(e)}#g(e,t){let n=e.#r[0],r=new K(null,n,this.options);r.#r.push(``),n.push(r),this.#_(e,t)}#_(e,t){let n=e.#r[0];this.#r.splice(t,1,...n.#r);for(let e of n.#r)typeof e==`object`&&(e.#i=this);this.#l=void 0}#v(e){return!!pg.get(this.type)?.has(e)}#y(e){if(!e||typeof e!=`object`||e.type!==null||e.#r.length!==1||this.type===null||this.#r.length!==1)return!1;let t=e.#r[0];return!t||typeof t!=`object`||t.type===null?!1:this.#v(t.type)}#b(e){let t=pg.get(this.type),n=e.#r[0],r=t?.get(n.type);
|
|
444
|
+
/* c8 ignore start - impossible */
|
|
445
|
+
if(!r)return!1;
|
|
446
|
+
/* c8 ignore stop */
|
|
447
|
+
this.#r=n.#r;for(let e of this.#r)typeof e==`object`&&(e.#i=this);this.type=r,this.#l=void 0,this.#u=!1}static fromGlob(e,t={}){let n=new K(null,void 0,t);return K.#f(e,n,0,t,0),n}toMMPattern(){
|
|
448
|
+
/* c8 ignore start */
|
|
449
|
+
if(this!==this.#e)return this.#e.toMMPattern();
|
|
450
|
+
/* c8 ignore stop */
|
|
451
|
+
let e=this.toString(),[t,n,r,i]=this.toRegExpSource();if(!(r||this.#t||this.#c.nocase&&!this.#c.nocaseMagicOnly&&e.toUpperCase()!==e.toLowerCase()))return n;let a=(this.#c.nocase?`i`:``)+(i?`u`:``);return Object.assign(RegExp(`^${t}$`,a),{_src:t,_glob:e})}get options(){return this.#c}toRegExpSource(e){let t=e??!!this.#c.dot;if(this.#e===this&&(this.#x(),this.#d()),!lg(this)){let n=this.isStart()&&this.isEnd()&&!this.#r.some(e=>typeof e!=`string`),r=this.#r.map(t=>{let[r,i,a,o]=typeof t==`string`?K.#C(t,this.#t,n):t.toRegExpSource(e);return this.#t=this.#t||a,this.#n=this.#n||o,r}).join(``),i=``;if(this.isStart()&&typeof this.#r[0]==`string`&&!(this.#r.length===1&&gg.has(this.#r[0]))){let n=hg,a=t&&n.has(r.charAt(0))||r.startsWith(`\\.`)&&n.has(r.charAt(2))||r.startsWith(`\\.\\.`)&&n.has(r.charAt(4)),o=!t&&!e&&n.has(r.charAt(0));i=a?`(?!(?:^|/)\\.\\.?(?:$|/))`:o?mg:``}let a=``;return this.isEnd()&&this.#e.#s&&this.#i?.type===`!`&&(a=`(?:$|\\/)`),[i+r+a,og(r),this.#t=!!this.#t,this.#n]}let n=this.type===`*`||this.type===`+`,r=this.type===`!`?`(?:(?!(?:`:`(?:`,i=this.#S(t);if(this.isStart()&&this.isEnd()&&!i&&this.type!==`!`){let e=this.toString(),t=this;return t.#r=[e],t.type=null,t.#t=void 0,[e,og(this.toString()),!1,!1]}let a=!n||e||t?``:this.#S(!0);a===i&&(a=``),a&&(i=`(?:${i})(?:${a})*?`);let o=``;if(this.type===`!`&&this.#u)o=(this.isStart()&&!t?mg:``)+yg;else{let n=this.type===`!`?`))`+(this.isStart()&&!t&&!e?mg:``)+`[^/]*?)`:this.type===`@`?`)`:this.type===`?`?`)?`:this.type===`+`&&a?`)`:this.type===`*`&&a?`)?`:`)${this.type}`;o=r+i+n}return[o,og(i),this.#t=!!this.#t,this.#n]}#x(){if(lg(this)){let e=0,t=!1;do{t=!0;for(let e=0;e<this.#r.length;e++){let n=this.#r[e];typeof n==`object`&&(n.#x(),this.#m(n)?(t=!1,this.#_(n,e)):this.#p(n)?(t=!1,this.#g(n,e)):this.#y(n)&&(t=!1,this.#b(n)))}}while(!t&&++e<10)}else for(let e of this.#r)typeof e==`object`&&e.#x();this.#l=void 0}#S(e){return this.#r.map(t=>{
|
|
452
|
+
/* c8 ignore start */
|
|
453
|
+
if(typeof t==`string`)throw Error(`string type in extglob ast??`);
|
|
454
|
+
/* c8 ignore stop */
|
|
455
|
+
let[n,r,i,a]=t.toRegExpSource(e);return this.#n=this.#n||a,n}).filter(e=>!(this.isStart()&&this.isEnd())||!!e).join(`|`)}static#C(e,t,n=!1){let r=!1,i=``,a=!1,o=!1;for(let s=0;s<e.length;s++){let c=e.charAt(s);if(r)r=!1,i+=(_g.has(c)?`\\`:``)+c;else if(c===`*`){if(o)continue;o=!0,i+=n&&/^[*]+$/.test(e)?yg:`[^/]*?`,t=!0}else if(o=!1,c===`\\`)s===e.length-1?i+=`\\\\`:r=!0;else{if(c===`[`){let[n,r,o,c]=ag(e,s);if(o){i+=n,a||=r,s+=o-1,t||=c;continue}}c===`?`?(i+=`[^/]`,t=!0):i+=vg(c)}}return[i,og(e),!!t,a]}};K=xg;const Sg=(e,{windowsPathsNoEscape:t=!1,magicalBraces:n=!1}={})=>n?t?e.replace(/[?*()[\]{}]/g,`[$&]`):e.replace(/[?*()[\]\\{}]/g,`\\$&`):t?e.replace(/[?*()[\]]/g,`[$&]`):e.replace(/[?*()[\]\\]/g,`\\$&`),q=(e,t,n={})=>(eg(t),!n.nocomment&&t.charAt(0)===`#`?!1:new Jg(t,n).match(e)),Cg=/^\*+([^+@!?*[(]*)$/,wg=e=>t=>!t.startsWith(`.`)&&t.endsWith(e),Tg=e=>t=>t.endsWith(e),Eg=e=>(e=e.toLowerCase(),t=>!t.startsWith(`.`)&&t.toLowerCase().endsWith(e)),Dg=e=>(e=e.toLowerCase(),t=>t.toLowerCase().endsWith(e)),Og=/^\*+\.\*+$/,kg=e=>!e.startsWith(`.`)&&e.includes(`.`),Ag=e=>e!==`.`&&e!==`..`&&e.includes(`.`),jg=/^\.\*+$/,Mg=e=>e!==`.`&&e!==`..`&&e.startsWith(`.`),Ng=/^\*+$/,Pg=e=>e.length!==0&&!e.startsWith(`.`),Fg=e=>e.length!==0&&e!==`.`&&e!==`..`,Ig=/^\?+([^+@!?*[(]*)?$/,Lg=([e,t=``])=>{let n=Vg([e]);return t?(t=t.toLowerCase(),e=>n(e)&&e.toLowerCase().endsWith(t)):n},Rg=([e,t=``])=>{let n=Hg([e]);return t?(t=t.toLowerCase(),e=>n(e)&&e.toLowerCase().endsWith(t)):n},zg=([e,t=``])=>{let n=Hg([e]);return t?e=>n(e)&&e.endsWith(t):n},Bg=([e,t=``])=>{let n=Vg([e]);return t?e=>n(e)&&e.endsWith(t):n},Vg=([e])=>{let t=e.length;return e=>e.length===t&&!e.startsWith(`.`)},Hg=([e])=>{let t=e.length;return e=>e.length===t&&e!==`.`&&e!==`..`},Ug=typeof process==`object`&&process?typeof process.env==`object`&&process.env&&process.env.__MINIMATCH_TESTING_PLATFORM__||process.platform:`posix`,Wg={win32:{sep:`\\`},posix:{sep:`/`}};q.sep=Ug===`win32`?Wg.win32.sep:Wg.posix.sep;const J=Symbol(`globstar **`);q.GLOBSTAR=J,q.filter=(e,t={})=>n=>q(n,e,t);const Y=(e,t={})=>Object.assign({},e,t);q.defaults=e=>{if(!e||typeof e!=`object`||!Object.keys(e).length)return q;let t=q;return Object.assign((n,r,i={})=>t(n,r,Y(e,i)),{Minimatch:class extends t.Minimatch{constructor(t,n={}){super(t,Y(e,n))}static defaults(n){return t.defaults(Y(e,n)).Minimatch}},AST:class extends t.AST{
|
|
456
|
+
/* c8 ignore start */
|
|
457
|
+
constructor(t,n,r={}){super(t,n,Y(e,r))}
|
|
458
|
+
/* c8 ignore stop */
|
|
459
|
+
static fromGlob(n,r={}){return t.AST.fromGlob(n,Y(e,r))}},unescape:(n,r={})=>t.unescape(n,Y(e,r)),escape:(n,r={})=>t.escape(n,Y(e,r)),filter:(n,r={})=>t.filter(n,Y(e,r)),defaults:n=>t.defaults(Y(e,n)),makeRe:(n,r={})=>t.makeRe(n,Y(e,r)),braceExpand:(n,r={})=>t.braceExpand(n,Y(e,r)),match:(n,r,i={})=>t.match(n,r,Y(e,i)),sep:t.sep,GLOBSTAR:J})};const Gg=(e,t={})=>(eg(e),t.nobrace||!/\{(?:(?!\{).)*\}/.test(e)?[e]:Kh(e,{max:t.braceExpandMax}));q.braceExpand=Gg,q.makeRe=(e,t={})=>new Jg(e,t).makeRe(),q.match=(e,t,n={})=>{let r=new Jg(t,n);return e=e.filter(e=>r.match(e)),r.options.nonull&&!e.length&&e.push(t),e};const Kg=/[?*]|[+@!]\(.*?\)|\[|\]/,qg=e=>e.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,`\\$&`);var Jg=class{options;set;pattern;windowsPathsNoEscape;nonegate;negate;comment;empty;preserveMultipleSlashes;partial;globSet;globParts;nocase;isWindows;platform;windowsNoMagicRoot;maxGlobstarRecursion;regexp;constructor(e,t={}){eg(e),t||={},this.options=t,this.maxGlobstarRecursion=t.maxGlobstarRecursion??200,this.pattern=e,this.platform=t.platform||Ug,this.isWindows=this.platform===`win32`,this.windowsPathsNoEscape=!!t.windowsPathsNoEscape||t.allowWindowsEscape===!1,this.windowsPathsNoEscape&&(this.pattern=this.pattern.replace(/\\/g,`/`)),this.preserveMultipleSlashes=!!t.preserveMultipleSlashes,this.regexp=null,this.negate=!1,this.nonegate=!!t.nonegate,this.comment=!1,this.empty=!1,this.partial=!!t.partial,this.nocase=!!this.options.nocase,this.windowsNoMagicRoot=t.windowsNoMagicRoot===void 0?!!(this.isWindows&&this.nocase):t.windowsNoMagicRoot,this.globSet=[],this.globParts=[],this.set=[],this.make()}hasMagic(){if(this.options.magicalBraces&&this.set.length>1)return!0;for(let e of this.set)for(let t of e)if(typeof t!=`string`)return!0;return!1}debug(...e){}make(){let e=this.pattern,t=this.options;if(!t.nocomment&&e.charAt(0)===`#`){this.comment=!0;return}if(!e){this.empty=!0;return}this.parseNegate(),this.globSet=[...new Set(this.braceExpand())],t.debug&&(this.debug=(...e)=>console.error(...e)),this.debug(this.pattern,this.globSet);let n=this.globSet.map(e=>this.slashSplit(e));this.globParts=this.preprocess(n),this.debug(this.pattern,this.globParts);let r=this.globParts.map((e,t,n)=>{if(this.isWindows&&this.windowsNoMagicRoot){let t=e[0]===``&&e[1]===``&&(e[2]===`?`||!Kg.test(e[2]))&&!Kg.test(e[3]),n=/^[a-z]:/i.test(e[0]);if(t)return[...e.slice(0,4),...e.slice(4).map(e=>this.parse(e))];if(n)return[e[0],...e.slice(1).map(e=>this.parse(e))]}return e.map(e=>this.parse(e))});if(this.debug(this.pattern,r),this.set=r.filter(e=>e.indexOf(!1)===-1),this.isWindows)for(let e=0;e<this.set.length;e++){let t=this.set[e];t[0]===``&&t[1]===``&&this.globParts[e][2]===`?`&&typeof t[3]==`string`&&/^[a-z]:$/i.test(t[3])&&(t[2]=`?`)}this.debug(this.pattern,this.set)}preprocess(e){if(this.options.noglobstar)for(let t of e)for(let e=0;e<t.length;e++)t[e]===`**`&&(t[e]=`*`);let{optimizationLevel:t=1}=this.options;return t>=2?(e=this.firstPhasePreProcess(e),e=this.secondPhasePreProcess(e)):e=t>=1?this.levelOneOptimize(e):this.adjascentGlobstarOptimize(e),e}adjascentGlobstarOptimize(e){return e.map(e=>{let t=-1;for(;(t=e.indexOf(`**`,t+1))!==-1;){let n=t;for(;e[n+1]===`**`;)n++;n!==t&&e.splice(t,n-t)}return e})}levelOneOptimize(e){return e.map(e=>(e=e.reduce((e,t)=>{let n=e[e.length-1];return t===`**`&&n===`**`?e:t===`..`&&n&&n!==`..`&&n!==`.`&&n!==`**`?(e.pop(),e):(e.push(t),e)},[]),e.length===0?[``]:e))}levelTwoFileOptimize(e){Array.isArray(e)||(e=this.slashSplit(e));let t=!1;do{if(t=!1,!this.preserveMultipleSlashes){for(let n=1;n<e.length-1;n++){let r=e[n];(n!==1||r!==``||e[0]!==``)&&(r===`.`||r===``)&&(t=!0,e.splice(n,1),n--)}e[0]===`.`&&e.length===2&&(e[1]===`.`||e[1]===``)&&(t=!0,e.pop())}let n=0;for(;(n=e.indexOf(`..`,n+1))!==-1;){let r=e[n-1];r&&r!==`.`&&r!==`..`&&r!==`**`&&!(this.isWindows&&/^[a-z]:$/i.test(r))&&(t=!0,e.splice(n-1,2),n-=2)}}while(t);return e.length===0?[``]:e}firstPhasePreProcess(e){let t=!1;do{t=!1;for(let n of e){let r=-1;for(;(r=n.indexOf(`**`,r+1))!==-1;){let i=r;for(;n[i+1]===`**`;)i++;i>r&&n.splice(r+1,i-r);let a=n[r+1],o=n[r+2],s=n[r+3];if(a!==`..`||!o||o===`.`||o===`..`||!s||s===`.`||s===`..`)continue;t=!0,n.splice(r,1);let c=n.slice(0);c[r]=`**`,e.push(c),r--}if(!this.preserveMultipleSlashes){for(let e=1;e<n.length-1;e++){let r=n[e];(e!==1||r!==``||n[0]!==``)&&(r===`.`||r===``)&&(t=!0,n.splice(e,1),e--)}n[0]===`.`&&n.length===2&&(n[1]===`.`||n[1]===``)&&(t=!0,n.pop())}let i=0;for(;(i=n.indexOf(`..`,i+1))!==-1;){let e=n[i-1];if(e&&e!==`.`&&e!==`..`&&e!==`**`){t=!0;let e=i===1&&n[i+1]===`**`?[`.`]:[];n.splice(i-1,2,...e),n.length===0&&n.push(``),i-=2}}}}while(t);return e}secondPhasePreProcess(e){for(let t=0;t<e.length-1;t++)for(let n=t+1;n<e.length;n++){let r=this.partsMatch(e[t],e[n],!this.preserveMultipleSlashes);if(r){e[t]=[],e[n]=r;break}}return e.filter(e=>e.length)}partsMatch(e,t,n=!1){let r=0,i=0,a=[],o=``;for(;r<e.length&&i<t.length;)if(e[r]===t[i])a.push(o===`b`?t[i]:e[r]),r++,i++;else if(n&&e[r]===`**`&&t[i]===e[r+1])a.push(e[r]),r++;else if(n&&t[i]===`**`&&e[r]===t[i+1])a.push(t[i]),i++;else if(e[r]===`*`&&t[i]&&(this.options.dot||!t[i].startsWith(`.`))&&t[i]!==`**`){if(o===`b`)return!1;o=`a`,a.push(e[r]),r++,i++}else if(t[i]===`*`&&e[r]&&(this.options.dot||!e[r].startsWith(`.`))&&e[r]!==`**`){if(o===`a`)return!1;o=`b`,a.push(t[i]),r++,i++}else return!1;return e.length===t.length&&a}parseNegate(){if(this.nonegate)return;let e=this.pattern,t=!1,n=0;for(let r=0;r<e.length&&e.charAt(r)===`!`;r++)t=!t,n++;n&&(this.pattern=e.slice(n)),this.negate=t}matchOne(e,t,n=!1){let r=0,i=0;if(this.isWindows){let n=typeof e[0]==`string`&&/^[a-z]:$/i.test(e[0]),a=!n&&e[0]===``&&e[1]===``&&e[2]===`?`&&/^[a-z]:$/i.test(e[3]),o=typeof t[0]==`string`&&/^[a-z]:$/i.test(t[0]),s=!o&&t[0]===``&&t[1]===``&&t[2]===`?`&&typeof t[3]==`string`&&/^[a-z]:$/i.test(t[3]),c=a?3:n?0:void 0,l=s?3:o?0:void 0;if(typeof c==`number`&&typeof l==`number`){let[n,a]=[e[c],t[l]];n.toLowerCase()===a.toLowerCase()&&(t[l]=n,i=l,r=c)}}let{optimizationLevel:a=1}=this.options;return a>=2&&(e=this.levelTwoFileOptimize(e)),t.includes(J)?this.#e(e,t,n,r,i):this.#n(e,t,n,r,i)}#e(e,t,n,r,i){let a=t.indexOf(J,i),o=t.lastIndexOf(J),[s,c,l]=n?[t.slice(i,a),t.slice(a+1),[]]:[t.slice(i,a),t.slice(a+1,o),t.slice(o+1)];if(s.length){let t=e.slice(r,r+s.length);if(!this.#n(t,s,n,0,0))return!1;r+=s.length,i+=s.length}let u=0;if(l.length){if(l.length+r>e.length)return!1;let t=e.length-l.length;if(this.#n(e,l,n,t,0))u=l.length;else{if(e[e.length-1]!==``||r+l.length===e.length||(t--,!this.#n(e,l,n,t,0)))return!1;u=l.length+1}}if(!c.length){let t=!!u;for(let n=r;n<e.length-u;n++){let r=String(e[n]);if(t=!0,r===`.`||r===`..`||!this.options.dot&&r.startsWith(`.`))return!1}return n||t}let d=[[[],0]],f=d[0],p=0,ee=[0];for(let e of c)e===J?(ee.push(p),f=[[],0],d.push(f)):(f[0].push(e),p++);let te=d.length-1,ne=e.length-u;for(let e of d)e[1]=ne-(ee[te--]+e[0].length);return!!this.#t(e,d,r,0,n,0,!!u)}#t(e,t,n,r,i,a,o){let s=t[r];if(!s){for(let t=n;t<e.length;t++){o=!0;let n=e[t];if(n===`.`||n===`..`||!this.options.dot&&n.startsWith(`.`))return!1}return o}let[c,l]=s;for(;n<=l;){if(this.#n(e.slice(0,n+c.length),c,i,n,0)&&a<this.maxGlobstarRecursion){let s=this.#t(e,t,n+c.length,r+1,i,a+1,o);if(s!==!1)return s}let s=e[n];if(s===`.`||s===`..`||!this.options.dot&&s.startsWith(`.`))return!1;n++}return i||null}#n(e,t,n,r,i){let a,o,s,c;for(a=r,o=i,c=e.length,s=t.length;a<c&&o<s;a++,o++){this.debug(`matchOne loop`);let n=t[o],r=e[a];
|
|
460
|
+
/* c8 ignore start */
|
|
461
|
+
if(this.debug(t,n,r),n===!1||n===J)return!1;
|
|
462
|
+
/* c8 ignore stop */
|
|
463
|
+
let i;if(typeof n==`string`?(i=r===n,this.debug(`string match`,n,r,i)):(i=n.test(r),this.debug(`pattern match`,n,r,i)),!i)return!1}if(a===c&&o===s)return!0;if(a===c)return n;if(o===s)return a===c-1&&e[a]===``;throw Error(`wtf?`)
|
|
464
|
+
/* c8 ignore stop */
|
|
465
|
+
}braceExpand(){return Gg(this.pattern,this.options)}parse(e){eg(e);let t=this.options;if(e===`**`)return J;if(e===``)return``;let n,r=null;(n=e.match(Ng))?r=t.dot?Fg:Pg:(n=e.match(Cg))?r=(t.nocase?t.dot?Dg:Eg:t.dot?Tg:wg)(n[1]):(n=e.match(Ig))?r=(t.nocase?t.dot?Rg:Lg:t.dot?zg:Bg)(n):(n=e.match(Og))?r=t.dot?Ag:kg:(n=e.match(jg))&&(r=Mg);let i=xg.fromGlob(e,this.options).toMMPattern();return r&&typeof i==`object`&&Reflect.defineProperty(i,"test",{value:r}),i}makeRe(){if(this.regexp||this.regexp===!1)return this.regexp;let e=this.set;if(!e.length)return this.regexp=!1,this.regexp;let t=this.options,n=t.noglobstar?`[^/]*?`:t.dot?`(?:(?!(?:\\/|^)(?:\\.{1,2})($|\\/)).)*?`:`(?:(?!(?:\\/|^)\\.).)*?`,r=new Set(t.nocase?[`i`]:[]),i=e.map(e=>{let t=e.map(e=>{if(e instanceof RegExp)for(let t of e.flags.split(``))r.add(t);return typeof e==`string`?qg(e):e===J?J:e._src});t.forEach((e,r)=>{let i=t[r+1],a=t[r-1];e===J&&a!==J&&(a===void 0?i!==void 0&&i!==J?t[r+1]=`(?:\\/|`+n+`\\/)?`+i:t[r]=n:i===void 0?t[r-1]=a+`(?:\\/|\\/`+n+`)?`:i!==J&&(t[r-1]=a+`(?:\\/|\\/`+n+`\\/)`+i,t[r+1]=J))});let i=t.filter(e=>e!==J);if(this.partial&&i.length>=1){let e=[];for(let t=1;t<=i.length;t++)e.push(i.slice(0,t).join(`/`));return`(?:`+e.join(`|`)+`)`}return i.join(`/`)}).join(`|`),[a,o]=e.length>1?[`(?:`,`)`]:[``,``];i=`^`+a+i+o+`$`,this.partial&&(i=`^(?:\\/|`+a+i.slice(1,-1)+o+`)$`),this.negate&&(i=`^(?!`+i+`).+$`);try{this.regexp=new RegExp(i,[...r].join(``))}catch{this.regexp=!1}
|
|
466
|
+
/* c8 ignore stop */
|
|
467
|
+
return this.regexp}slashSplit(e){return this.preserveMultipleSlashes?e.split(`/`):this.isWindows&&/^\/\/[^/]+/.test(e)?[``,...e.split(/\/+/)]:e.split(/\/+/)}match(e,t=this.partial){if(this.debug(`match`,e,this.pattern),this.comment)return!1;if(this.empty)return e===``;if(e===`/`&&t)return!0;let n=this.options;this.isWindows&&(e=e.split(`\\`).join(`/`));let r=this.slashSplit(e);this.debug(this.pattern,`split`,r);let i=this.set;this.debug(this.pattern,`set`,i);let a=r[r.length-1];if(!a)for(let e=r.length-2;!a&&e>=0;e--)a=r[e];for(let e of i){let i=r;if(n.matchBase&&e.length===1&&(i=[a]),this.matchOne(i,e,t))return n.flipNegate?!0:!this.negate}return!n.flipNegate&&this.negate}static defaults(e){return q.defaults(e).Minimatch}};q.AST=xg,q.Minimatch=Jg,q.escape=Sg,q.unescape=og;const Yg=/[/\\]/u,Xg={kind:`ignore`},Zg=e=>!ce(e)&&e.split(Yg).every(e=>e!==`.`&&e!==`..`),Qg=/^!+/u,$g=/^\.?\/+/u,e_=e=>{let t=Qg.exec(e)?.[0]??``;return{body:e.slice(t.length).replace($g,``),negated:t.length%2==1}},t_=e=>e_(e).negated,n_=e=>e_(e).body,r_=/[?[\]{}()]/u,i_=e=>Zg(e)&&!t_(e)&&!r_.test(e),a_=(e,t)=>q(e,t),o_=e=>e.replaceAll(/\/+/gu,`/`).replace(/\/$/u,``),s_=e=>{let t=o_(e).split(`/`),n=t.findIndex(e=>e.includes(`*`));return n===-1?Xg:{baseDir:n===0?`.`:t.slice(0,n).join(`/`),kind:`expand-children`,pattern:o_(e),suffix:t.slice(n+1).join(`/`)}},c_=e=>{let t=o_(e).split(`/`).filter(e=>e.includes(`*`));return t.length<=1&&!t.includes(`**`)},l_=e=>{let t=o_(e).split(`/`),n=t.findIndex(e=>e.includes(`*`));return n<=0?`.`:t.slice(0,n).join(`/`)},u_=e=>i_(e)?e.includes(`*`)?c_(e)?s_(e):{baseDir:l_(e),kind:`expand-recursive`,pattern:o_(e)}:{dir:e,kind:`probe-dir`,pattern:e}:Xg,d_=/* @__PURE__ */ new Set([`candidate_not_inspected`,`scan_budget_exhausted`,`manifest_unreadable`,`unsupported_pattern`,`workspace_declaration_unparsed`,`workspace_dir_unreadable`,`workspace_file_unreadable`]),f_=(e,t)=>t?.name?{name:t.name,path:e}:void 0,p_=e=>{let t=e.map(e=>[e.path,e]),n=[...new Map(t).values()];return n.sort((e,t)=>e.path.localeCompare(t.path)),n},m_=e=>!e.diagnostics.some(e=>d_.has(e.kind)),h_=e=>!e.diagnostics.some(e=>e.kind===`no_workspace_declaration`),g_=(e,t)=>e<t?-1:+(e>t),__=e=>`path`in e?`${e.kind} ${e.path}`:`file`in e?`${e.kind} ${e.file}`:`pattern`in e?`${e.kind} ${e.pattern}`:e.kind,v_=e=>e.toSorted((e,t)=>g_(__(e),__(t))),y_=e=>!ce(e)&&!e.split(/[/\\]/u).includes(`..`),b_=(e,t)=>e.kind===`missing`?{kind:`absent`}:e.kind===`outside`?{kind:`unreadable`,reason:`${t} escapes the checkout`}:{kind:`unreadable`,reason:e.code},x_=async(e,t,n)=>{if(!y_(t))return{kind:`unreadable`,reason:`path escapes the checkout`};let r=await S_(e,t);if(`probe`in r)return r.probe;let i=await C_(r.real);return`reason`in i?{kind:`unreadable`,reason:i.reason}:i.found===n?{kind:`match`}:{found:i.found,kind:`mismatch`}},S_=async(e,t)=>{let n=await H(e,h(e,t));if(n.kind!==`inside`)return{probe:b_(n,`path`)};let r=await H(e,h(n.real,`package.json`));return r.kind===`inside`?{real:r.real}:{probe:b_(r,`manifest`)}},C_=async e=>{try{let t=JSON.parse(await s(e,`utf8`));return{found:sd(t)}}catch(e){return{reason:e.code??`manifest could not be read or interpreted`}}},w_=(e,t)=>{let n=e.filter(e=>e.name===t).map(e=>e.path);return n.length===0?{kind:`absent`}:n.length===1?{kind:`found`,path:n[0]}:{kind:`ambiguous`,paths:n.toSorted(g_)}},T_=`package.json`,E_=/^\.\/[^\s%?#\\]*$/u,D_=async e=>{try{return(await p(e)).isDirectory()?`directory`:`file`}catch{return`unverifiable`}},O_=async(e,t)=>{if(!E_.test(t)||t.includes(`*`))return`not_checked`;let n=h(e,t.slice(2)),r=await H(e,n);return r.kind===`inside`?D_(r.real):r.kind===`missing`&&await Qu(e,n)?`absent`:`unverifiable`},k_=async(e,t,n)=>Array.isArray(t)?{alternatives:await Promise.all(t.map(t=>A_(e,t,n+1))),kind:`alternatives`}:{branches:await Promise.all(Object.entries(t).map(async([t,r])=>({condition:t,value:await A_(e,r,n+1)}))),kind:`conditions`},A_=async(e,t,n)=>t===null?{kind:`excluded`}:n>8?{kind:`unsupported`,reason:`nested deeper than this reports on`}:typeof t==`string`?{kind:`target`,observed:await O_(e,t),target:t}:typeof t==`object`?k_(e,t,n):{kind:`unsupported`,reason:`unexpected ${typeof t}`},j_=[`main`,`module`,`types`,`typings`],M_=(e,t)=>{let n=j_.filter(e=>typeof t[e]==`string`);return Promise.all(n.map(async n=>({from:n,subpath:`.`,value:await A_(e,N_(t[n]),0)})))},N_=e=>e.startsWith(`/`)||e.startsWith(`./`)||e.startsWith(`../`)?e:`./${e}`,P_=async(e,t)=>{if(typeof t==`string`||Array.isArray(t))return[{from:`exports`,subpath:`.`,value:await A_(e,t,0)}];if(t===void 0)return[];if(typeof t!=`object`||!t)return[{from:`exports`,subpath:`.`,value:await A_(e,t,0)}];let n=Object.keys(t);return n.length>0&&!n.some(e=>e.startsWith(`.`))?[{from:`exports`,subpath:`.`,value:await A_(e,t,0)}]:Promise.all(Object.entries(t).map(async([t,n])=>({from:`exports`,subpath:t,value:await A_(e,n,0)})))},F_=async(e,t)=>{let n=await H(e,h(e,T_));if(n.kind!==`inside`)return{entries:[],manifest:T_,reason:n.kind,status:`unverifiable`};try{let r=JSON.parse(await s(n.real,`utf8`));return r.name===t?{entries:[...await P_(e,r.exports),...await M_(e,r)],manifest:T_,status:`complete`}:{entries:[],manifest:T_,reason:`manifest no longer names this package`,status:`unverifiable`}}catch(e){return{entries:[],manifest:T_,reason:e.code??`manifest could not be read or interpreted`,status:`unverifiable`}}},I_=wl.partial({description:!0}),L_=N({default_branch:al,key:cl,tag_format_candidate:pl.nullable(),url:j().min(1)});L_.extend({description:j().default(``),packages:vl(I_)});const R_=L_.extend({description:j().min(1),packages:vl(wl)}),z_=N({effective_clone_mode:dl.optional(),head_sha:j().regex(/^[0-9a-f]{40}$/u,`head_sha must be a 40-character lowercase hex string`).optional(),last_error:j().optional(),last_fetched_at:qc().optional(),pending_proposal_at:qc().optional()}),B_=N({refs:gl(e=>e.length>0&&!hl.has(e),()=>`state ref key must be non-empty and not "__proto__", "constructor", or "prototype"`,yc(j(),z_)).default({})}),V_=(e,t,n)=>t?.[e]??n[e],H_=async e=>{try{return await s(e.statePath,`utf8`)}catch(e){if(I(e))return;throw e}},U_=e=>{try{return JSON.parse(e)}catch{return}},W_=async e=>{let t=await H_(e);if(t===void 0)return B_.parse({});let n=U_(t);if(n===void 0)return B_.parse({});let r=B_.safeParse(n);return r.success?r.data:B_.parse({})},G_=async(e,t)=>{let n=B_.safeParse(t);if(!n.success)throw z(S(n.error));await pu(e.statePath,`${JSON.stringify(n.data,void 0,2)}\n`)},K_=/^\d+\.\d+\.\d+$/u,q_=/^0+(?=\d)/u,J_=(e,t)=>{let n=e.replace(q_,``),r=t.replace(q_,``);return n.length===r.length?n===r?0:n<r?-1:1:n.length<r.length?-1:1},Y_=(e,t)=>{if(!K_.test(e)||!K_.test(t))return;let n=e.split(`.`),r=t.split(`.`);return n.map((e,t)=>J_(e,r[t]??``)).find(e=>e!==0)??0},X_=pc({version:j().regex(K_)}),Z_=N({checked_at:qc(),latest_version:j().regex(K_)}),Q_=async e=>{try{let t=Z_.safeParse(JSON.parse(await s(e.updateCachePath,`utf8`)));return t.success?t.data:void 0}catch{return}},$_=async(e,t)=>{try{await p(e.root),await pu(e.updateCachePath,`${JSON.stringify(t,void 0,2)}\n`)}catch{}},ev=(e,t)=>{let n=t-Date.parse(e.checked_at);return n>=0&&n<864e5},tv=async e=>{try{let t=await e(`https://registry.npmjs.org/@kaisers-io%2Frefs/latest`,{signal:AbortSignal.timeout(2e3)});if(t.status!==200)return;let n=X_.safeParse(await t.json());return n.success?n.data.version:void 0}catch{return}},nv=async e=>{let t=await Q_(e.home);if(t!==void 0&&ev(t,e.nowMs))return{latest:t.latest_version,refreshed:!1,stale:!1};let n=await tv(e.fetch);return n===void 0?{latest:t?.latest_version,refreshed:!1,stale:!0}:(await $_(e.home,{checked_at:new Date(e.nowMs).toISOString(),latest_version:n}),{latest:n,refreshed:!0,stale:!1})},rv=(e,t)=>{let n=Y_(e,t);return n!==void 0&&n<0},iv=(e,t)=>`refs ${t} is available (this is ${e}) — update: npm i -g @kaisers-io/refs@latest`,av=e=>{let t=e.REFS_UPDATE_CHECK?.trim();if(t===`0`)return!1;if(t===`1`)return!0},ov=e=>{let t=e.CI?.trim().toLowerCase();return t!==void 0&&t!==``&&t!==`false`&&t!==`0`},sv={check:!0,notify:!0},cv=e=>{let t=av(e.env);return t===void 0?(e.updates??sv).check?ov(e.env)?`ci`:`on`:`config`:t?`on`:`env`},lv=e=>cv(e)===`on`,uv=e=>lv(e)&&(e.updates??sv).notify,dv=async(e,t)=>{let n=await H(e,h(t,`package.json`));if(n.kind===`inside`)try{let e=JSON.parse(await s(n.real,`utf8`));return{name:sd(e),version:cd(e)}}catch{return}},fv=async(e,t)=>{let n=await dv(e,h(e,t));if(n===void 0)return{diagnostic:{kind:`manifest_unreadable`,path:t}};let r=f_(t,n);return r!==void 0&&n.version!==void 0?{pkg:r,version:n.version}:r===void 0?{diagnostic:{kind:`manifest_missing_name`,path:t}}:{pkg:r}},pv=e=>Object.fromEntries(e.flatMap(e=>e.pkg===void 0||e.version===void 0?[]:[[e.pkg.path,e.version]])),mv=e=>{let t=[],n=[];for(let r of e)r.diagnostic!==void 0&&t.push(r.diagnostic),r.pkg!==void 0&&n.push(r.pkg);return{diagnostics:t,packages:n,versions:pv(e)}},hv=/* @__PURE__ */ new Set([`ENOENT`,`ENOTDIR`]),gv=async(e,t)=>{let n=await H(e,h(t,`package.json`));if(n.kind===`missing`)return`none`;if(n.kind!==`inside`)return`rejected`;try{return await s(n.real,`utf8`),`manifest`}catch{return`rejected`}},_v=async e=>{try{return{entries:await c(e,{withFileTypes:!0})}}catch(e){return{code:e.code??``}}},vv=e=>Promise.all(e.entries.map(t=>gv(e.repoDir,h(e.fullPath,t.name,e.suffix)))),yv=(e,t,n)=>e.filter((e,r)=>n(t[r])).map(e=>e.name),bv=async e=>{let{baseDir:t,dirs:n,fullPath:r,repoDir:i,suffix:a,symlinks:o}=e,s=e=>ue.join(t===`.`?``:t,e,a),[c,l]=await Promise.all([vv({entries:n,fullPath:r,repoDir:i,suffix:a}),vv({entries:o,fullPath:r,repoDir:i,suffix:a})]);return{diagnostics:[...yv(n,c,e=>e===`rejected`).map(e=>({kind:`manifest_unreadable`,path:s(e)})),...yv(o,l,e=>e!==`none`).map(e=>({kind:`candidate_not_inspected`,path:s(e)}))],dirs:yv(n,c,e=>e===`manifest`).map(e=>s(e))}},xv=async e=>{let t=await fv(e,`.`);return`pkg`in t?[t]:[]},Sv=e=>{let t=e.find(e=>e.path===`.`);return t===void 0?[...e]:e.some(e=>e.path!==`.`&&e.name===t.name)?e.filter(e=>e!==t):[...e]},Cv=async e=>{let[t]=await xv(e);return t!==void 0&&`pkg`in t?t.pkg:void 0},wv=`package.json`,Tv=e=>{let t=o_(e).split(`/`);return t.includes(`**`)?void 0:t.length},Ev=e=>o_(e).split(`/`).some(e=>e.startsWith(`.`)),Dv=e=>e===`.`?0:e.split(`/`).length,Ov=e=>{let t=o_(e),n=new Jg(`${t}/${wv}`),r=new Jg(t);return{couldHold:e=>r.match(e,!0),selects:e=>n.match(ue.join(e,wv))}},kv=e=>({...Ov(e),maxDepth:Tv(e),selectsHidden:Ev(e)}),Av=/* @__PURE__ */ new Set([`ENOENT`,`ENOTDIR`]),jv=/* @__PURE__ */ new Set([`.git`,`node_modules`]),Mv=e=>e.some(e=>e.name.toLowerCase()===`package.json`&&!e.isDirectory()),Nv=e=>e.some(e=>e.isSymbolicLink()&&!jv.has(e.name)),Pv=async(e,t)=>{let n=await _v(t);return`code`in n?{answer:Av.has(n.code)}:(e.budget.entries-=n.entries.length,e.budget.entries<0||Mv(n.entries)||Nv(n.entries)?{answer:!1}:{entries:n.entries})},Fv=async(e,t,n)=>{if(e.budget.dirs<=0||n>32)return!1;--e.budget.dirs;let r=await Pv(e,t);return`answer`in r?r.answer:Iv(e,{dir:t,entries:r.entries},n)},Iv=async(e,t,n)=>{let r=t.entries.filter(e=>e.isDirectory()&&!jv.has(e.name));for(let i of r)if(!await Fv(e,h(t.dir,i.name),n+1))return!1;return!0},Lv=async(e,t)=>{let n=await H(e.repoDir,h(e.repoDir,t));n.kind!==`outside`&&n.kind!==`missing`&&(n.kind===`unreadable`?e.diagnostics.push({kind:`candidate_not_inspected`,path:t}):await Fv(e,n.real,1)||e.diagnostics.push({kind:`candidate_not_inspected`,path:t}))},Rv=()=>({dirs:2e4,entries:2e5}),zv=/* @__PURE__ */ new Set([`.git`,`node_modules`]),Bv=(e,t)=>{e.diagnostics.push({kind:`scan_budget_exhausted`,path:t,pattern:e.pattern})},Vv=async(e,t,n)=>{if(!e.selects(t)||n.has(t))return;let r=await gv(e.repoDir,h(e.repoDir,t));r===`manifest`&&e.dirs.push(t),r===`rejected`&&e.diagnostics.push({kind:`manifest_unreadable`,path:t})},Hv=(e,t)=>!e.selectsHidden&&t.excluded.coversSubtree(t.relPath),Uv=async(e,t,n)=>!e.couldHold(n.relPath)||zv.has(t.name)||Hv(e,n)?!1:t.isSymbolicLink()?(Hv(e,n)||await Lv(e,n.relPath),!1):t.isDirectory(),Wv=async(e,t)=>{let n=await _v(h(e.repoDir,t));if(`code`in n)hv.has(n.code)||e.diagnostics.push({kind:`workspace_dir_unreadable`,path:t});else if(e.budget.entries-=n.entries.length,e.budget.entries<0)Bv(e,t);else return n.entries},Gv=async(e,t,n)=>{if(e.budget.dirs<=0){Bv(e,t.relPath);return}if(--e.budget.dirs,await Vv(e,t.relPath,n),e.maxDepth!==void 0&&Dv(t.relPath)>=e.maxDepth)return;let r=await Wv(e,t.relPath);r!==void 0&&await qv(e,{depth:t.depth,entries:r,relPath:t.relPath},n)},Kv=(e,t)=>ue.join(e===`.`?``:e,t),qv=async(e,t,n)=>{for(let r of t.entries){let i=Kv(t.relPath,r.name);await Uv(e,r,{excluded:n,relPath:i})&&(t.depth+1>32?Bv(e,i):await Gv(e,{depth:t.depth+1,relPath:i},n))}},Jv=async(e,t)=>{let n=await H(e,h(e,t));if(n.kind!==`inside`)return n.kind===`missing`?{diagnostics:[],dirs:[]}:{diagnostics:[{kind:`workspace_dir_unreadable`,path:t}],dirs:[]}},Yv=async(e,t,n)=>{let r=await Jv(e,t.baseDir);if(r!==void 0)return r;let i={...kv(t.pattern),budget:n.budget,diagnostics:[],dirs:[],pattern:t.pattern,repoDir:e};return await Gv(i,{depth:1,relPath:t.baseDir},n.excluded),{diagnostics:i.diagnostics,dirs:i.dirs}},Xv=(e,t)=>ue.join(e.baseDir===`.`?``:e.baseDir,t,e.suffix),Zv=(e,t)=>a_(Xv(t,e.name),t.pattern),Qv=async(e,t)=>{let n=h(e,t),r=await H(e,n);if(r.kind===`missing`)return{result:{diagnostics:[],dirs:[]}};if(r.kind!==`inside`)return{result:{diagnostics:[{kind:`workspace_dir_unreadable`,path:t}],dirs:[]}};let i=await _v(n);return`code`in i?{result:hv.has(i.code)?{diagnostics:[],dirs:[]}:{diagnostics:[{kind:`workspace_dir_unreadable`,path:t}],dirs:[]}}:{entries:i.entries}},$v=async(e,t,n)=>{let{baseDir:r}=t,i=await Qv(e,r);if(`result`in i)return i.result;let a=e=>Zv(e,t)&&!n.has(Xv(t,e.name)),o={entries:i.entries};return bv({baseDir:r,dirs:o.entries.filter(e=>e.isDirectory()&&a(e)),fullPath:h(e,r),repoDir:e,suffix:t.suffix,symlinks:o.entries.filter(e=>e.isSymbolicLink()&&a(e))})},ey=async(e,t)=>{let n=await gv(e,h(e,t));return n===`manifest`?{diagnostics:[],dirs:[o_(t)]}:n===`rejected`?{diagnostics:[{kind:`manifest_unreadable`,path:t}],dirs:[]}:{diagnostics:[],dirs:[]}},ty=(e,t,n)=>{let{excluded:r}=n,i=u_(t.body);return i.kind===`expand-children`?$v(e,i,r):i.kind===`expand-recursive`?Yv(e,i,n):i.kind===`probe-dir`?r.has(o_(i.dir))?Promise.resolve({diagnostics:[],dirs:[]}):ey(e,i.dir):Promise.resolve({diagnostics:[{kind:`unsupported_pattern`,pattern:t.declared}],dirs:[]})},ny=(e,t)=>a_(n_(e),n_(t)),ry=e=>({negations:e.filter(e=>t_(e)),patterns:e.filter(e=>!t_(e))}),iy=e=>{let t=e.reduce((e,t)=>t_(t)?{negations:[...e.negations,t],patterns:e.patterns}:{negations:e.negations.filter(e=>!ny(t,e)),patterns:[...e.patterns,t]},{negations:[],patterns:[]});return{negations:t.negations,patterns:t.patterns.filter(e=>!t.negations.some(t=>ny(e,t)))}},ay=e=>e.endsWith(`/`)?e:`${e}/`,oy=(e,t)=>e.some(e=>a_(ay(t),ay(n_(e)))),sy=(e,t)=>{let n=n_(e);return n.endsWith(`/**`)&&a_(t,n.slice(0,-3))},cy=e=>({coversSubtree:t=>e.some(e=>sy(e,t)),has:t=>oy(e,t)}),ly=e=>{let t=/* @__PURE__ */ new Set,n=[];for(let r of e)r.dirs.forEach(e=>t.add(e)),n.push(...r.diagnostics);return{diagnostics:n,dirs:[...t]}},uy=async(e,t,n)=>{let{negations:r,patterns:i}=t,a=cy(r),o=ly(await Promise.all(i.map(t=>ty(e,{body:n_(t),declared:t},{budget:n,excluded:a}))));return{diagnostics:o.diagnostics,dirs:o.dirs}},dy=async(e,t)=>{let n=iy(t.npm),r=ry(t.pnpm),i=Rv(),a=await Promise.all([uy(e,n,i),uy(e,r,i)]);return ly(a)},fy=async e=>{let t=await hd(e);if(t.npm.length===0&&t.pnpm.length===0)return{diagnostics:v_([...t.diagnostics,{kind:`no_workspace_declaration`}]),packages:[],versions:{}};let n=await dy(e,t),[r,i]=await Promise.all([xv(e),Promise.all(n.dirs.map(t=>fv(e,t)))]),a=mv([...r,...i]);return{diagnostics:v_([...t.diagnostics,...n.diagnostics,...a.diagnostics]),packages:Sv(p_(a.packages)),versions:a.versions}},py=()=>{},my={stop:py,update:py},hy={frames:[`⠋`,`⠙`,`⠹`,`⠸`,`⠼`,`⠴`,`⠦`,`⠧`,`⠇`,`⠏`],interval:80},gy={frames:[`-`,`\\`,`|`,`/`],interval:130},_y=`\r\x1B[K`,vy={24:`\x1B[38;2;7;210;86m`,4:`\x1B[32m`,8:`\x1B[38;5;41m`},yy=/[^ -~]/gu,by=(e,t)=>t.isTTY===!0&&e.TERM!==`dumb`&&!ov(e)&&e.REFS_PROGRESS?.trim()!==`0`,xy=/* @__PURE__ */ new Set([`alacritty`,`rxvt-unicode`,`rxvt-unicode-256color`,`xterm-256color`]),Sy=(e,t)=>t===`win32`?!!e.WT_SESSION||!!e.TERMINUS_SUBLIME||e.ConEmuTask===`{cmd::Cmder}`||e.TERM_PROGRAM===`Terminus-Sublime`||e.TERM_PROGRAM===`vscode`||e.TERMINAL_EMULATOR===`JetBrains-JediTerm`||xy.has(e.TERM??``):e.TERM!==`linux`,Cy=(e,t)=>e.replaceAll(yy,`?`).slice(0,Math.max(0,t)),wy=(e,t,n)=>{let r=(e.stream.columns??80)-3,i=vy[e.stream.getColorDepth?.(e.env)??1],a=i===void 0?t:`${i}${t}[39m`;return`${_y}${a} ${Cy(n,r)}`},Ty=e=>{if(!by(e.env,e.stream))return my;let{frames:t,interval:n}=Sy(e.env,e.platform)?hy:gy,r={drawn:!1,index:0,stopped:!1,text:``},i=()=>{e.stream.write(wy(e,t[r.index%t.length]??``,r.text)),r.drawn=!0,r.index+=1},a={},o=()=>{i(),a.ticker=setInterval(i,n).unref()};return{stop:()=>{r.stopped=!0,clearTimeout(a.delay),clearInterval(a.ticker),r.drawn&&=(e.stream.write(_y),!1)},update:e=>{r.stopped||(r.text=e,a.delay??=setTimeout(o,100).unref())}}};var Ey=`0.18.2`;const Dy=async()=>{let e=[];for await(let t of process.stdin)e.push(Buffer.from(t));return Buffer.concat(e).toString(`utf8`)},Oy=()=>{try{return ge()}catch{return``}},ky=()=>({cliVersion:Ey,cwd:process.cwd(),env:process.env,errLine:e=>{process.stderr.write(`${e}\n`)},fetcher:(e,t)=>fetch(e,t),homedir:Oy(),nodeVersion:process.version,out:e=>{process.stdout.write(`${e}\n`)},readStdin:Dy,runner:new zd,spinner:()=>Ty({env:process.env,platform:process.platform,stream:process.stderr})});var Ay=class extends Error{constructor(e,t,n){super(n),Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name,this.code=t,this.exitCode=e,this.nestedError=void 0}},jy=class extends Ay{constructor(e){super(1,`commander.invalidArgument`,e),Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name}},My=class{constructor(e,t){switch(this.description=t||``,this.variadic=!1,this.parseArg=void 0,this.defaultValue=void 0,this.defaultValueDescription=void 0,this.argChoices=void 0,e[0]){case`<`:this.required=!0,this._name=e.slice(1,-1);break;case`[`:this.required=!1,this._name=e.slice(1,-1);break;default:this.required=!0,this._name=e}this._name.endsWith(`...`)&&(this.variadic=!0,this._name=this._name.slice(0,-3))}name(){return this._name}_collectValue(e,t){return t===this.defaultValue||!Array.isArray(t)?[e]:(t.push(e),t)}default(e,t){return this.defaultValue=e,this.defaultValueDescription=t,this}argParser(e){return this.parseArg=e,this}choices(e){return this.argChoices=e.slice(),this.parseArg=(e,t)=>{if(!this.argChoices.includes(e))throw new jy(`Allowed choices are ${this.argChoices.join(`, `)}.`);return this.variadic?this._collectValue(e,t):e},this}argRequired(){return this.required=!0,this}argOptional(){return this.required=!1,this}};function Ny(e){let t=e.name()+(e.variadic===!0?`...`:``);return e.required?`<`+t+`>`:`[`+t+`]`}var Py=class{constructor(){this.helpWidth=void 0,this.minWidthToWrap=40,this.sortSubcommands=!1,this.sortOptions=!1,this.showGlobalOptions=!1}prepareContext(e){this.helpWidth=this.helpWidth??e.helpWidth??80}visibleCommands(e){let t=e.commands.filter(e=>!e._hidden),n=e._getHelpCommand();return n&&!n._hidden&&t.push(n),this.sortSubcommands&&t.sort((e,t)=>e.name().localeCompare(t.name())),t}compareOptions(e,t){let n=e=>e.short?e.short.replace(/^-/,``):e.long.replace(/^--/,``);return n(e).localeCompare(n(t))}visibleOptions(e){let t=e.options.filter(e=>!e.hidden),n=e._getHelpOption();if(n&&!n.hidden){let r=n.short&&e._findOption(n.short),i=n.long&&e._findOption(n.long);!r&&!i?t.push(n):n.long&&!i?t.push(e.createOption(n.long,n.description)):n.short&&!r&&t.push(e.createOption(n.short,n.description))}return this.sortOptions&&t.sort(this.compareOptions),t}visibleGlobalOptions(e){if(!this.showGlobalOptions)return[];let t=[];for(let n=e.parent;n;n=n.parent){let e=n.options.filter(e=>!e.hidden);t.push(...e)}return this.sortOptions&&t.sort(this.compareOptions),t}visibleArguments(e){return e._argsDescription&&e.registeredArguments.forEach(t=>{t.description=t.description||e._argsDescription[t.name()]||``}),e.registeredArguments.find(e=>e.description)?e.registeredArguments:[]}subcommandTerm(e){let t=e.registeredArguments.map(e=>Ny(e)).join(` `);return e._name+(e._aliases[0]?`|`+e._aliases[0]:``)+(e.options.length?` [options]`:``)+(t?` `+t:``)}optionTerm(e){return e.flags}argumentTerm(e){return e.name()}longestSubcommandTermLength(e,t){return t.visibleCommands(e).reduce((e,n)=>Math.max(e,this.displayWidth(t.styleSubcommandTerm(t.subcommandTerm(n)))),0)}longestOptionTermLength(e,t){return t.visibleOptions(e).reduce((e,n)=>Math.max(e,this.displayWidth(t.styleOptionTerm(t.optionTerm(n)))),0)}longestGlobalOptionTermLength(e,t){return t.visibleGlobalOptions(e).reduce((e,n)=>Math.max(e,this.displayWidth(t.styleOptionTerm(t.optionTerm(n)))),0)}longestArgumentTermLength(e,t){return t.visibleArguments(e).reduce((e,n)=>Math.max(e,this.displayWidth(t.styleArgumentTerm(t.argumentTerm(n)))),0)}commandUsage(e){let t=e._name;e._aliases[0]&&(t=t+`|`+e._aliases[0]);let n=``;for(let t=e.parent;t;t=t.parent)n=t.name()+` `+n;return n+t+` `+e.usage()}commandDescription(e){return e.description()}subcommandDescription(e){return e.summary()||e.description()}optionDescription(e){let t=[];if(e.argChoices&&t.push(`choices: ${e.argChoices.map(e=>JSON.stringify(e)).join(`, `)}`),e.defaultValue!==void 0&&(e.required||e.optional||e.isBoolean()&&typeof e.defaultValue==`boolean`)&&t.push(`default: ${e.defaultValueDescription||JSON.stringify(e.defaultValue)}`),e.presetArg!==void 0&&e.optional&&t.push(`preset: ${JSON.stringify(e.presetArg)}`),e.envVar!==void 0&&t.push(`env: ${e.envVar}`),t.length>0){let n=`(${t.join(`, `)})`;return e.description?`${e.description} ${n}`:n}return e.description}argumentDescription(e){let t=[];if(e.argChoices&&t.push(`choices: ${e.argChoices.map(e=>JSON.stringify(e)).join(`, `)}`),e.defaultValue!==void 0&&t.push(`default: ${e.defaultValueDescription||JSON.stringify(e.defaultValue)}`),t.length>0){let n=`(${t.join(`, `)})`;return e.description?`${e.description} ${n}`:n}return e.description}formatItemList(e,t,n){return t.length===0?[]:[n.styleTitle(e),...t,``]}groupItems(e,t,n){let r=/* @__PURE__ */ new Map;return e.forEach(e=>{let t=n(e);r.has(t)||r.set(t,[])}),t.forEach(e=>{let t=n(e);r.has(t)||r.set(t,[]),r.get(t).push(e)}),r}formatHelp(e,t){let n=t.padWidth(e,t),r=t.helpWidth??80;function i(e,r){return t.formatItem(e,n,r,t)}let a=[`${t.styleTitle(`Usage:`)} ${t.styleUsage(t.commandUsage(e))}`,``],o=t.commandDescription(e);o.length>0&&(a=a.concat([t.boxWrap(t.styleCommandDescription(o),r),``]));let s=t.visibleArguments(e).map(e=>i(t.styleArgumentTerm(t.argumentTerm(e)),t.styleArgumentDescription(t.argumentDescription(e))));if(a=a.concat(this.formatItemList(`Arguments:`,s,t)),this.groupItems(e.options,t.visibleOptions(e),e=>e.helpGroupHeading??`Options:`).forEach((e,n)=>{let r=e.map(e=>i(t.styleOptionTerm(t.optionTerm(e)),t.styleOptionDescription(t.optionDescription(e))));a=a.concat(this.formatItemList(n,r,t))}),t.showGlobalOptions){let n=t.visibleGlobalOptions(e).map(e=>i(t.styleOptionTerm(t.optionTerm(e)),t.styleOptionDescription(t.optionDescription(e))));a=a.concat(this.formatItemList(`Global Options:`,n,t))}return this.groupItems(e.commands,t.visibleCommands(e),e=>e.helpGroup()||`Commands:`).forEach((e,n)=>{let r=e.map(e=>i(t.styleSubcommandTerm(t.subcommandTerm(e)),t.styleSubcommandDescription(t.subcommandDescription(e))));a=a.concat(this.formatItemList(n,r,t))}),a.join(`
|
|
329
468
|
`)}displayWidth(e){return Se(e).length}styleTitle(e){return e}styleUsage(e){return e.split(` `).map(e=>e===`[options]`?this.styleOptionText(e):e===`[command]`?this.styleSubcommandText(e):e[0]===`[`||e[0]===`<`?this.styleArgumentText(e):this.styleCommandText(e)).join(` `)}styleCommandDescription(e){return this.styleDescriptionText(e)}styleOptionDescription(e){return this.styleDescriptionText(e)}styleSubcommandDescription(e){return this.styleDescriptionText(e)}styleArgumentDescription(e){return this.styleDescriptionText(e)}styleDescriptionText(e){return e}styleOptionTerm(e){return this.styleOptionText(e)}styleSubcommandTerm(e){return e.split(` `).map(e=>e===`[options]`?this.styleOptionText(e):e[0]===`[`||e[0]===`<`?this.styleArgumentText(e):this.styleSubcommandText(e)).join(` `)}styleArgumentTerm(e){return this.styleArgumentText(e)}styleOptionText(e){return e}styleArgumentText(e){return e}styleSubcommandText(e){return e}styleCommandText(e){return e}padWidth(e,t){return Math.max(t.longestOptionTermLength(e,t),t.longestGlobalOptionTermLength(e,t),t.longestSubcommandTermLength(e,t),t.longestArgumentTermLength(e,t))}preformatted(e){return/\n[^\S\r\n]/.test(e)}formatItem(e,t,n,r){let i=` `.repeat(2);if(!n)return i+e;let a=e.padEnd(t+e.length-r.displayWidth(e)),o=(this.helpWidth??80)-t-2-2,s;return s=o<this.minWidthToWrap||r.preformatted(n)?n:r.boxWrap(n,o).replace(/\n/g,`
|
|
330
469
|
`+` `.repeat(t+2)),i+a+` `.repeat(2)+s.replace(/\n/g,`\n${i}`)}boxWrap(e,t){if(t<this.minWidthToWrap)return e;let n=e.split(/\r\n|\n/),r=/[\s]*[^\s]+/g,i=[];return n.forEach(e=>{let n=e.match(r);if(n===null){i.push(``);return}let a=[n.shift()],o=this.displayWidth(a[0]);n.forEach(e=>{let n=this.displayWidth(e);if(o+n<=t){a.push(e),o+=n;return}i.push(a.join(``));let r=e.trimStart();a=[r],o=this.displayWidth(r)}),i.push(a.join(``))}),i.join(`
|
|
331
|
-
`)}},
|
|
470
|
+
`)}},Fy=class{constructor(e,t){this.flags=e,this.description=t||``,this.required=e.includes(`<`),this.optional=e.includes(`[`),this.variadic=/\w\.\.\.[>\]]$/.test(e),this.mandatory=!1;let n=Ry(e);this.short=n.shortFlag,this.long=n.longFlag,this.negate=!1,this.long&&(this.negate=this.long.startsWith(`--no-`)),this.defaultValue=void 0,this.defaultValueDescription=void 0,this.presetArg=void 0,this.envVar=void 0,this.parseArg=void 0,this.hidden=!1,this.argChoices=void 0,this.conflictsWith=[],this.implied=void 0,this.helpGroupHeading=void 0}default(e,t){return this.defaultValue=e,this.defaultValueDescription=t,this}preset(e){return this.presetArg=e,this}conflicts(e){return this.conflictsWith=this.conflictsWith.concat(e),this}implies(e){let t=e;return typeof e==`string`&&(t={[e]:!0}),this.implied=Object.assign(this.implied||{},t),this}env(e){return this.envVar=e,this}argParser(e){return this.parseArg=e,this}makeOptionMandatory(e=!0){return this.mandatory=!!e,this}hideHelp(e=!0){return this.hidden=!!e,this}_collectValue(e,t){return t===this.defaultValue||!Array.isArray(t)?[e]:(t.push(e),t)}choices(e){return this.argChoices=e.slice(),this.parseArg=(e,t)=>{if(!this.argChoices.includes(e))throw new jy(`Allowed choices are ${this.argChoices.join(`, `)}.`);return this.variadic?this._collectValue(e,t):e},this}name(){return this.long?this.long.replace(/^--/,``):this.short.replace(/^-/,``)}attributeName(){return this.negate?Ly(this.name().replace(/^no-/,``)):Ly(this.name())}helpGroup(e){return this.helpGroupHeading=e,this}is(e){return this.short===e||this.long===e}isBoolean(){return!this.required&&!this.optional&&!this.negate}},Iy=class{constructor(e){this.positiveOptions=/* @__PURE__ */ new Map,this.negativeOptions=/* @__PURE__ */ new Map,this.dualOptions=/* @__PURE__ */ new Set,e.forEach(e=>{e.negate?this.negativeOptions.set(e.attributeName(),e):this.positiveOptions.set(e.attributeName(),e)}),this.negativeOptions.forEach((e,t)=>{this.positiveOptions.has(t)&&this.dualOptions.add(t)})}valueFromOption(e,t){let n=t.attributeName();if(!this.dualOptions.has(n))return!0;let r=this.negativeOptions.get(n).presetArg,i=r!==void 0&&r;return t.negate===(i===e)}};function Ly(e){return e.split(`-`).reduce((e,t)=>e+t[0].toUpperCase()+t.slice(1))}function Ry(e){let t,n,r=/^-[^-]$/,i=/^--[^-]/,a=e.split(/[ |,]+/).concat(`guard`);if(r.test(a[0])&&(t=a.shift()),i.test(a[0])&&(n=a.shift()),!t&&r.test(a[0])&&(t=a.shift()),!t&&i.test(a[0])&&(t=n,n=a.shift()),a[0].startsWith(`-`)){let t=a[0],n=`option creation failed due to '${t}' in option flags '${e}'`;throw/^-[^-][^-]/.test(t)?Error(`${n}
|
|
332
471
|
- a short flag is a single dash and a single character
|
|
333
472
|
- either use a single dash and a single character (for a short flag)
|
|
334
473
|
- or use a double dash for a long option (and can have two, like '--ws, --workspace')`):r.test(t)?Error(`${n}
|
|
335
474
|
- too many short flags`):i.test(t)?Error(`${n}
|
|
336
475
|
- too many long flags`):Error(`${n}
|
|
337
|
-
- unrecognised flag format`)}if(t===void 0&&n===void 0)throw Error(`option creation failed due to no flags found in '${e}'.`);return{shortFlag:t,longFlag:n}}function
|
|
338
|
-
- specify the name in Command constructor or using .name()`);return t||={},t.isDefault&&(this._defaultCommandName=e._name),(t.noHelp||t.hidden)&&(e._hidden=!0),this._registerCommand(e),e.parent=this,e._checkForBrokenPassThrough(),this}createArgument(e,t){return new
|
|
339
|
-
Expecting one of '${n.join(`', '`)}'`);return this._lifeCycleHooks[e]?this._lifeCycleHooks[e].push(t):this._lifeCycleHooks[e]=[t],this}exitOverride(e){return this._exitCallback=e||(e=>{if(e.code!==`commander.executeSubCommandAsync`)throw e}),this}_exit(e,t,n){this._exitCallback&&this._exitCallback(new
|
|
340
|
-
- already used by option '${t.flags}'`)}this._initOptionGroup(e),this.options.push(e)}_registerCommand(e){let t=e=>[e.name()].concat(e.aliases()),n=t(e).find(e=>this._findCommand(e));if(n){let r=t(this._findCommand(n)).join(`|`),i=t(e).join(`|`);throw Error(`cannot add command '${i}' as already have command '${r}'`)}this._initCommandGroup(e),this.commands.push(e)}addOption(e){this._registerOption(e);let t=e.name(),n=e.attributeName();e.defaultValue!==void 0&&this.setOptionValueWithSource(n,e.defaultValue,`default`);let r=(t,r,i)=>{t==null&&e.presetArg!==void 0&&(t=e.presetArg);let a=this.getOptionValue(n);t!==null&&e.parseArg?t=this._callParseArg(e,t,a,r):t!==null&&e.variadic&&(t=e._collectValue(t,a)),t??=e.negate?!1:e.isBoolean()||e.optional?!0:``,this.setOptionValueWithSource(n,t,i)};return this.on(`option:`+t,t=>{let n=`error: option '${e.flags}' argument '${t}' is invalid.`;r(t,n,`cli`)}),e.envVar&&this.on(`optionEnv:`+t,t=>{let n=`error: option '${e.flags}' value '${t}' from env '${e.envVar}' is invalid.`;r(t,n,`env`)}),this}_optionEx(e,t,n,r,i){if(typeof t==`object`&&t instanceof
|
|
476
|
+
- unrecognised flag format`)}if(t===void 0&&n===void 0)throw Error(`option creation failed due to no flags found in '${e}'.`);return{shortFlag:t,longFlag:n}}function zy(e,t){if(Math.abs(e.length-t.length)>3)return Math.max(e.length,t.length);let n=[];for(let t=0;t<=e.length;t++)n[t]=[t];for(let e=0;e<=t.length;e++)n[0][e]=e;for(let r=1;r<=t.length;r++)for(let i=1;i<=e.length;i++){let a;a=e[i-1]===t[r-1]?0:1,n[i][r]=Math.min(n[i-1][r]+1,n[i][r-1]+1,n[i-1][r-1]+a),i>1&&r>1&&e[i-1]===t[r-2]&&e[i-2]===t[r-1]&&(n[i][r]=Math.min(n[i][r],n[i-2][r-2]+1))}return n[e.length][t.length]}function By(e,t){if(!t||t.length===0)return``;t=Array.from(new Set(t));let n=e.startsWith(`--`);n&&(e=e.slice(2),t=t.map(e=>e.slice(2)));let r=[],i=3;return t.forEach(t=>{if(t.length<=1)return;let n=zy(e,t),a=Math.max(e.length,t.length);(a-n)/a>.4&&(n<i?(i=n,r=[t]):n===i&&r.push(t))}),r.sort((e,t)=>e.localeCompare(t)),n&&(r=r.map(e=>`--${e}`)),r.length>1?`\n(Did you mean one of ${r.join(`, `)}?)`:r.length===1?`\n(Did you mean ${r[0]}?)`:``}var Vy=class e extends _e{constructor(e){super(),this.commands=[],this.options=[],this.parent=null,this._allowUnknownOption=!1,this._allowExcessArguments=!1,this.registeredArguments=[],this._args=this.registeredArguments,this.args=[],this.rawArgs=[],this.processedArgs=[],this._scriptPath=null,this._name=e||``,this._optionValues={},this._optionValueSources={},this._storeOptionsAsProperties=!1,this._actionHandler=null,this._executableHandler=!1,this._executableFile=null,this._executableDir=null,this._defaultCommandName=null,this._exitCallback=null,this._aliases=[],this._combineFlagAndOptionalValue=!0,this._description=``,this._summary=``,this._argsDescription=void 0,this._enablePositionalOptions=!1,this._passThroughOptions=!1,this._lifeCycleHooks={},this._showHelpAfterError=!1,this._showSuggestionAfterError=!0,this._savedState=null,this._outputConfiguration={writeOut:e=>g.stdout.write(e),writeErr:e=>g.stderr.write(e),outputError:(e,t)=>t(e),getOutHelpWidth:()=>g.stdout.isTTY?g.stdout.columns:void 0,getErrHelpWidth:()=>g.stderr.isTTY?g.stderr.columns:void 0,getOutHasColors:()=>Uy()??(g.stdout.isTTY&&g.stdout.hasColors?.()),getErrHasColors:()=>Uy()??(g.stderr.isTTY&&g.stderr.hasColors?.()),stripColor:e=>Se(e)},this._hidden=!1,this._helpOption=void 0,this._addImplicitHelpCommand=void 0,this._helpCommand=void 0,this._helpConfiguration={},this._helpGroupHeading=void 0,this._defaultCommandGroup=void 0,this._defaultOptionGroup=void 0}copyInheritedSettings(e){return this._outputConfiguration=e._outputConfiguration,this._helpOption=e._helpOption,this._helpCommand=e._helpCommand,this._helpConfiguration=e._helpConfiguration,this._exitCallback=e._exitCallback,this._storeOptionsAsProperties=e._storeOptionsAsProperties,this._combineFlagAndOptionalValue=e._combineFlagAndOptionalValue,this._allowExcessArguments=e._allowExcessArguments,this._enablePositionalOptions=e._enablePositionalOptions,this._showHelpAfterError=e._showHelpAfterError,this._showSuggestionAfterError=e._showSuggestionAfterError,this}_getCommandAndAncestors(){let e=[];for(let t=this;t;t=t.parent)e.push(t);return e}command(e,t,n){let r=t,i=n;typeof r==`object`&&r&&(i=r,r=null),i||={};let[,a,o]=e.match(/([^ ]+) *(.*)/),s=this.createCommand(a);return r&&(s.description(r),s._executableHandler=!0),i.isDefault&&(this._defaultCommandName=s._name),s._hidden=!!(i.noHelp||i.hidden),s._executableFile=i.executableFile||null,o&&s.arguments(o),this._registerCommand(s),s.parent=this,s.copyInheritedSettings(this),r?this:s}createCommand(t){return new e(t)}createHelp(){return Object.assign(new Py,this.configureHelp())}configureHelp(e){return e===void 0?this._helpConfiguration:(this._helpConfiguration=e,this)}configureOutput(e){return e===void 0?this._outputConfiguration:(this._outputConfiguration={...this._outputConfiguration,...e},this)}showHelpAfterError(e=!0){return typeof e!=`string`&&(e=!!e),this._showHelpAfterError=e,this}showSuggestionAfterError(e=!0){return this._showSuggestionAfterError=!!e,this}addCommand(e,t){if(!e._name)throw Error(`Command passed to .addCommand() must have a name
|
|
477
|
+
- specify the name in Command constructor or using .name()`);return t||={},t.isDefault&&(this._defaultCommandName=e._name),(t.noHelp||t.hidden)&&(e._hidden=!0),this._registerCommand(e),e.parent=this,e._checkForBrokenPassThrough(),this}createArgument(e,t){return new My(e,t)}argument(e,t,n,r){let i=this.createArgument(e,t);return typeof n==`function`?i.default(r).argParser(n):i.default(n),this.addArgument(i),this}arguments(e){return e.trim().split(/ +/).forEach(e=>{this.argument(e)}),this}addArgument(e){let t=this.registeredArguments.slice(-1)[0];if(t?.variadic)throw Error(`only the last argument can be variadic '${t.name()}'`);if(e.required&&e.defaultValue!==void 0&&e.parseArg===void 0)throw Error(`a default value for a required argument is never used: '${e.name()}'`);return this.registeredArguments.push(e),this}helpCommand(e,t){if(typeof e==`boolean`)return this._addImplicitHelpCommand=e,e&&this._defaultCommandGroup&&this._initCommandGroup(this._getHelpCommand()),this;let[,n,r]=(e??`help [command]`).match(/([^ ]+) *(.*)/),i=t??`display help for command`,a=this.createCommand(n);return a.helpOption(!1),r&&a.arguments(r),i&&a.description(i),this._addImplicitHelpCommand=!0,this._helpCommand=a,(e||t)&&this._initCommandGroup(a),this}addHelpCommand(e,t){return typeof e==`object`?(this._addImplicitHelpCommand=!0,this._helpCommand=e,this._initCommandGroup(e),this):(this.helpCommand(e,t),this)}_getHelpCommand(){return this._addImplicitHelpCommand??(this.commands.length&&!this._actionHandler&&!this._findCommand(`help`))?(this._helpCommand===void 0&&this.helpCommand(void 0,void 0),this._helpCommand):null}hook(e,t){let n=[`preSubcommand`,`preAction`,`postAction`];if(!n.includes(e))throw Error(`Unexpected value for event passed to hook : '${e}'.
|
|
478
|
+
Expecting one of '${n.join(`', '`)}'`);return this._lifeCycleHooks[e]?this._lifeCycleHooks[e].push(t):this._lifeCycleHooks[e]=[t],this}exitOverride(e){return this._exitCallback=e||(e=>{if(e.code!==`commander.executeSubCommandAsync`)throw e}),this}_exit(e,t,n){this._exitCallback&&this._exitCallback(new Ay(e,t,n)),g.exit(e)}action(e){let t=t=>{let n=this.registeredArguments.length,r=t.slice(0,n);return r[n]=this._storeOptionsAsProperties?this:this.opts(),r.push(this),e.apply(this,r)};return this._actionHandler=t,this}createOption(e,t){return new Fy(e,t)}_callParseArg(e,t,n,r){try{return e.parseArg(t,n)}catch(e){if(e.code===`commander.invalidArgument`){let t=`${r} ${e.message}`;this.error(t,{exitCode:e.exitCode,code:e.code})}throw e}}_registerOption(e){let t=e.short&&this._findOption(e.short)||e.long&&this._findOption(e.long);if(t){let n=e.long&&this._findOption(e.long)?e.long:e.short;throw Error(`Cannot add option '${e.flags}'${this._name&&` to command '${this._name}'`} due to conflicting flag '${n}'
|
|
479
|
+
- already used by option '${t.flags}'`)}this._initOptionGroup(e),this.options.push(e)}_registerCommand(e){let t=e=>[e.name()].concat(e.aliases()),n=t(e).find(e=>this._findCommand(e));if(n){let r=t(this._findCommand(n)).join(`|`),i=t(e).join(`|`);throw Error(`cannot add command '${i}' as already have command '${r}'`)}this._initCommandGroup(e),this.commands.push(e)}addOption(e){this._registerOption(e);let t=e.name(),n=e.attributeName();e.defaultValue!==void 0&&this.setOptionValueWithSource(n,e.defaultValue,`default`);let r=(t,r,i)=>{t==null&&e.presetArg!==void 0&&(t=e.presetArg);let a=this.getOptionValue(n);t!==null&&e.parseArg?t=this._callParseArg(e,t,a,r):t!==null&&e.variadic&&(t=e._collectValue(t,a)),t??=e.negate?!1:e.isBoolean()||e.optional?!0:``,this.setOptionValueWithSource(n,t,i)};return this.on(`option:`+t,t=>{let n=`error: option '${e.flags}' argument '${t}' is invalid.`;r(t,n,`cli`)}),e.envVar&&this.on(`optionEnv:`+t,t=>{let n=`error: option '${e.flags}' value '${t}' from env '${e.envVar}' is invalid.`;r(t,n,`env`)}),this}_optionEx(e,t,n,r,i){if(typeof t==`object`&&t instanceof Fy)throw Error(`To add an Option object use addOption() instead of option() or requiredOption()`);let a=this.createOption(t,n);if(a.makeOptionMandatory(!!e.mandatory),typeof r==`function`)a.default(i).argParser(r);else if(r instanceof RegExp){let e=r;r=(t,n)=>{let r=e.exec(t);return r?r[0]:n},a.default(i).argParser(r)}else a.default(r);return this.addOption(a)}option(e,t,n,r){return this._optionEx({},e,t,n,r)}requiredOption(e,t,n,r){return this._optionEx({mandatory:!0},e,t,n,r)}combineFlagAndOptionalValue(e=!0){return this._combineFlagAndOptionalValue=!!e,this}allowUnknownOption(e=!0){return this._allowUnknownOption=!!e,this}allowExcessArguments(e=!0){return this._allowExcessArguments=!!e,this}enablePositionalOptions(e=!0){return this._enablePositionalOptions=!!e,this}passThroughOptions(e=!0){return this._passThroughOptions=!!e,this._checkForBrokenPassThrough(),this}_checkForBrokenPassThrough(){if(this.parent&&this._passThroughOptions&&!this.parent._enablePositionalOptions)throw Error(`passThroughOptions cannot be used for '${this._name}' without turning on enablePositionalOptions for parent command(s)`)}storeOptionsAsProperties(e=!0){if(this.options.length)throw Error(`call .storeOptionsAsProperties() before adding options`);if(Object.keys(this._optionValues).length)throw Error(`call .storeOptionsAsProperties() before setting option values`);return this._storeOptionsAsProperties=!!e,this}getOptionValue(e){return this._storeOptionsAsProperties?this[e]:this._optionValues[e]}setOptionValue(e,t){return this.setOptionValueWithSource(e,t,void 0)}setOptionValueWithSource(e,t,n){return this._storeOptionsAsProperties?this[e]=t:this._optionValues[e]=t,this._optionValueSources[e]=n,this}getOptionValueSource(e){return this._optionValueSources[e]}getOptionValueSourceWithGlobals(e){let t;return this._getCommandAndAncestors().forEach(n=>{n.getOptionValueSource(e)!==void 0&&(t=n.getOptionValueSource(e))}),t}_prepareUserArgs(e,t){if(e!==void 0&&!Array.isArray(e))throw Error(`first parameter to parse must be array or undefined`);if(t||={},e===void 0&&t.from===void 0){g.versions?.electron&&(t.from=`electron`);let e=g.execArgv??[];(e.includes(`-e`)||e.includes(`--eval`)||e.includes(`-p`)||e.includes(`--print`))&&(t.from=`eval`)}e===void 0&&(e=g.argv),this.rawArgs=e.slice();let n;switch(t.from){case void 0:case`node`:this._scriptPath=e[1],n=e.slice(2);break;case`electron`:g.defaultApp?(this._scriptPath=e[1],n=e.slice(2)):n=e.slice(1);break;case`user`:n=e.slice(0);break;case`eval`:n=e.slice(1);break;default:throw Error(`unexpected parse option { from: '${t.from}' }`)}return!this._name&&this._scriptPath&&this.nameFromFilename(this._scriptPath),this._name=this._name||`program`,n}parse(e,t){this._prepareForParse();let n=this._prepareUserArgs(e,t);return this._parseCommand([],n),this}async parseAsync(e,t){this._prepareForParse();let n=this._prepareUserArgs(e,t);return await this._parseCommand([],n),this}_prepareForParse(){this._savedState===null?(this.options.filter(e=>e.negate&&e.defaultValue===void 0&&this.getOptionValue(e.attributeName())===void 0).forEach(e=>{let t=e.long.replace(/^--no-/,`--`);this._findOption(t)||this.setOptionValueWithSource(e.attributeName(),!0,`default`)}),this.saveStateBeforeParse()):this.restoreStateBeforeParse()}saveStateBeforeParse(){this._savedState={_name:this._name,_optionValues:{...this._optionValues},_optionValueSources:{...this._optionValueSources}}}restoreStateBeforeParse(){if(this._storeOptionsAsProperties)throw Error(`Can not call parse again when storeOptionsAsProperties is true.
|
|
341
480
|
- either make a new Command for each call to parse, or stop storing options as properties`);this._name=this._savedState._name,this._scriptPath=null,this.rawArgs=[],this._optionValues={...this._savedState._optionValues},this._optionValueSources={...this._savedState._optionValueSources},this.args=[],this.processedArgs=[]}_checkForMissingExecutable(e,t,n){if(ne.existsSync(e))return;let r=`'${e}' does not exist
|
|
342
481
|
- if '${n}' is not meant to be an executable command, remove description parameter from '.command()' and use '.description()' instead
|
|
343
482
|
- if the default executable name is not suitable, use the executableFile option to supply a custom name or path
|
|
344
|
-
- ${t?`searched for local subcommand relative to directory '${t}'`:`no directory for search for local subcommand, use .executableDir() to supply a custom directory`}`;throw Error(r)}_executeSubCommand(e,t){t=t.slice();let n=[`.js`,`.ts`,`.tsx`,`.mjs`,`.cjs`];function r(e,t){let r=oe.resolve(e,t);if(ne.existsSync(r))return r;if(n.includes(oe.extname(t)))return;let i=n.find(e=>ne.existsSync(`${r}${e}`));if(i)return`${r}${i}`}this._checkForMissingMandatoryOptions(),this._checkForConflictingOptions();let i=e._executableFile||`${this._name}-${e._name}`,a=this._executableDir||``;if(this._scriptPath){let e;try{e=ne.realpathSync(this._scriptPath)}catch{e=this._scriptPath}a=oe.resolve(oe.dirname(e),a)}if(a){let t=r(a,i);if(!t&&!e._executableFile&&this._scriptPath){let n=oe.basename(this._scriptPath,oe.extname(this._scriptPath));n!==this._name&&(t=r(a,`${n}-${e._name}`))}i=t||i}let o=n.includes(oe.extname(i)),s;g.platform===`win32`?(this._checkForMissingExecutable(i,a,e._name),t.unshift(i),t=
|
|
345
|
-
`),this.outputHelp({error:!0}));let n=t||{},r=n.exitCode||1,i=n.code||`commander.error`;this._exit(r,i,e)}_parseOptionsEnv(){this.options.forEach(e=>{if(e.envVar&&e.envVar in g.env){let t=e.attributeName();(this.getOptionValue(t)===void 0||[`default`,`config`,`env`].includes(this.getOptionValueSource(t)))&&(e.required||e.optional?this.emit(`optionEnv:${e.name()}`,g.env[e.envVar]):this.emit(`optionEnv:${e.name()}`))}})}_parseOptionsImplied(){let e=new
|
|
346
|
-
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
|
|
347
|
-
refs add ${
|
|
483
|
+
- ${t?`searched for local subcommand relative to directory '${t}'`:`no directory for search for local subcommand, use .executableDir() to supply a custom directory`}`;throw Error(r)}_executeSubCommand(e,t){t=t.slice();let n=[`.js`,`.ts`,`.tsx`,`.mjs`,`.cjs`];function r(e,t){let r=oe.resolve(e,t);if(ne.existsSync(r))return r;if(n.includes(oe.extname(t)))return;let i=n.find(e=>ne.existsSync(`${r}${e}`));if(i)return`${r}${i}`}this._checkForMissingMandatoryOptions(),this._checkForConflictingOptions();let i=e._executableFile||`${this._name}-${e._name}`,a=this._executableDir||``;if(this._scriptPath){let e;try{e=ne.realpathSync(this._scriptPath)}catch{e=this._scriptPath}a=oe.resolve(oe.dirname(e),a)}if(a){let t=r(a,i);if(!t&&!e._executableFile&&this._scriptPath){let n=oe.basename(this._scriptPath,oe.extname(this._scriptPath));n!==this._name&&(t=r(a,`${n}-${e._name}`))}i=t||i}let o=n.includes(oe.extname(i)),s;g.platform===`win32`?(this._checkForMissingExecutable(i,a,e._name),t.unshift(i),t=Hy(g.execArgv).concat(t),s=ye.spawn(g.execPath,t,{stdio:`inherit`})):o?(t.unshift(i),t=Hy(g.execArgv).concat(t),s=ye.spawn(g.argv[0],t,{stdio:`inherit`})):s=ye.spawn(i,t,{stdio:`inherit`}),s.killed||[`SIGUSR1`,`SIGUSR2`,`SIGTERM`,`SIGINT`,`SIGHUP`].forEach(e=>{g.on(e,()=>{s.killed===!1&&s.exitCode===null&&s.kill(e)})});let c=this._exitCallback;s.on(`close`,e=>{e??=1,c?c(new Ay(e,`commander.executeSubCommandAsync`,`(close)`)):g.exit(e)}),s.on(`error`,t=>{if(t.code===`ENOENT`)this._checkForMissingExecutable(i,a,e._name);else if(t.code===`EACCES`)throw Error(`'${i}' not executable`);if(!c)g.exit(1);else{let e=new Ay(1,`commander.executeSubCommandAsync`,`(error)`);e.nestedError=t,c(e)}}),this.runningCommand=s}_dispatchSubcommand(e,t,n){let r=this._findCommand(e);r||this.help({error:!0}),r._prepareForParse();let i;return i=this._chainOrCallSubCommandHook(i,r,`preSubcommand`),i=this._chainOrCall(i,()=>{if(r._executableHandler)this._executeSubCommand(r,t.concat(n));else return r._parseCommand(t,n)}),i}_dispatchHelpCommand(e){e||this.help();let t=this._findCommand(e);return t&&!t._executableHandler&&t.help(),this._dispatchSubcommand(e,[],[this._getHelpOption()?.long??this._getHelpOption()?.short??`--help`])}_checkNumberOfArguments(){this.registeredArguments.forEach((e,t)=>{e.required&&this.args[t]==null&&this.missingArgument(e.name())}),!(this.registeredArguments.length>0&&this.registeredArguments[this.registeredArguments.length-1].variadic)&&this.args.length>this.registeredArguments.length&&this._excessArguments(this.args)}_processArguments(){let e=(e,t,n)=>{let r=t;if(t!==null&&e.parseArg){let i=`error: command-argument value '${t}' is invalid for argument '${e.name()}'.`;r=this._callParseArg(e,t,n,i)}return r};this._checkNumberOfArguments();let t=[];this.registeredArguments.forEach((n,r)=>{let i=n.defaultValue;n.variadic?r<this.args.length?(i=this.args.slice(r),n.parseArg&&(i=i.reduce((t,r)=>e(n,r,t),n.defaultValue))):i===void 0&&(i=[]):r<this.args.length&&(i=this.args[r],n.parseArg&&(i=e(n,i,n.defaultValue))),t[r]=i}),this.processedArgs=t}_chainOrCall(e,t){return e?.then&&typeof e.then==`function`?e.then(()=>t()):t()}_chainOrCallHooks(e,t){let n=e,r=[];return this._getCommandAndAncestors().reverse().filter(e=>e._lifeCycleHooks[t]!==void 0).forEach(e=>{e._lifeCycleHooks[t].forEach(t=>{r.push({hookedCommand:e,callback:t})})}),t===`postAction`&&r.reverse(),r.forEach(e=>{n=this._chainOrCall(n,()=>e.callback(e.hookedCommand,this))}),n}_chainOrCallSubCommandHook(e,t,n){let r=e;return this._lifeCycleHooks[n]!==void 0&&this._lifeCycleHooks[n].forEach(e=>{r=this._chainOrCall(r,()=>e(this,t))}),r}_parseCommand(e,t){let n=this.parseOptions(t);if(this._parseOptionsEnv(),this._parseOptionsImplied(),e=e.concat(n.operands),t=n.unknown,this.args=e.concat(t),e&&this._findCommand(e[0]))return this._dispatchSubcommand(e[0],e.slice(1),t);if(this._getHelpCommand()&&e[0]===this._getHelpCommand().name())return this._dispatchHelpCommand(e[1]);if(this._defaultCommandName)return this._outputHelpIfRequested(t),this._dispatchSubcommand(this._defaultCommandName,e,t);this.commands.length&&this.args.length===0&&!this._actionHandler&&!this._defaultCommandName&&this.help({error:!0}),this._outputHelpIfRequested(n.unknown),this._checkForMissingMandatoryOptions(),this._checkForConflictingOptions();let r=()=>{n.unknown.length>0&&this.unknownOption(n.unknown[0])},i=`command:${this.name()}`;if(this._actionHandler){r(),this._processArguments();let n;return n=this._chainOrCallHooks(n,`preAction`),n=this._chainOrCall(n,()=>this._actionHandler(this.processedArgs)),this.parent&&(n=this._chainOrCall(n,()=>{this.parent.emit(i,e,t)})),n=this._chainOrCallHooks(n,`postAction`),n}if(this.parent?.listenerCount(i))r(),this._processArguments(),this.parent.emit(i,e,t);else if(e.length){if(this._findCommand(`*`))return this._dispatchSubcommand(`*`,e,t);this.listenerCount(`command:*`)?this.emit(`command:*`,e,t):this.commands.length?this.unknownCommand():(r(),this._processArguments())}else this.commands.length?(r(),this.help({error:!0})):(r(),this._processArguments())}_findCommand(e){if(e)return this.commands.find(t=>t._name===e||t._aliases.includes(e))}_findOption(e){return this.options.find(t=>t.is(e))}_checkForMissingMandatoryOptions(){this._getCommandAndAncestors().forEach(e=>{e.options.forEach(t=>{t.mandatory&&e.getOptionValue(t.attributeName())===void 0&&e.missingMandatoryOptionValue(t)})})}_checkForConflictingLocalOptions(){let e=this.options.filter(e=>{let t=e.attributeName();return this.getOptionValue(t)!==void 0&&this.getOptionValueSource(t)!=="default"});e.filter(e=>e.conflictsWith.length>0).forEach(t=>{let n=e.find(e=>t.conflictsWith.includes(e.attributeName()));n&&this._conflictingOption(t,n)})}_checkForConflictingOptions(){this._getCommandAndAncestors().forEach(e=>{e._checkForConflictingLocalOptions()})}parseOptions(e){let t=[],n=[],r=t;function i(e){return e.length>1&&e[0]===`-`}let a=e=>/^-(\d+|\d*\.\d+)(e[+-]?\d+)?$/.test(e)?!this._getCommandAndAncestors().some(e=>e.options.map(e=>e.short).some(e=>/^-\d$/.test(e))):!1,o=null,s=null,c=0;for(;c<e.length||s;){let l=s??e[c++];if(s=null,l===`--`){r===n&&r.push(l),r.push(...e.slice(c));break}if(o&&(!i(l)||a(l)))this.emit(`option:${o.name()}`,l);else{if(o=null,i(l)){let t=this._findOption(l);if(t){if(t.required){let n=e[c++];n===void 0&&this.optionMissingArgument(t),this.emit(`option:${t.name()}`,n)}else if(t.optional){let n=null;c<e.length&&(!i(e[c])||a(e[c]))&&(n=e[c++]),this.emit(`option:${t.name()}`,n)}else this.emit(`option:${t.name()}`);o=t.variadic?t:null;continue}}if(l.length>2&&l[0]===`-`&&l[1]!==`-`){let e=this._findOption(`-${l[1]}`);if(e){e.required||e.optional&&this._combineFlagAndOptionalValue?this.emit(`option:${e.name()}`,l.slice(2)):(this.emit(`option:${e.name()}`),s=`-${l.slice(2)}`);continue}}if(/^--[^=]+=/.test(l)){let e=l.indexOf(`=`),t=this._findOption(l.slice(0,e));if(t&&(t.required||t.optional)){this.emit(`option:${t.name()}`,l.slice(e+1));continue}}if(r===t&&i(l)&&!(this.commands.length===0&&a(l))&&(r=n),(this._enablePositionalOptions||this._passThroughOptions)&&t.length===0&&n.length===0){if(this._findCommand(l)){t.push(l),n.push(...e.slice(c));break}if(this._getHelpCommand()&&l===this._getHelpCommand().name()){t.push(l,...e.slice(c));break}if(this._defaultCommandName){n.push(l,...e.slice(c));break}}if(this._passThroughOptions){r.push(l,...e.slice(c));break}r.push(l)}}return{operands:t,unknown:n}}opts(){if(this._storeOptionsAsProperties){let e={},t=this.options.length;for(let n=0;n<t;n++){let t=this.options[n].attributeName();e[t]=t===this._versionOptionName?this._version:this[t]}return e}return this._optionValues}optsWithGlobals(){return this._getCommandAndAncestors().reduce((e,t)=>Object.assign(e,t.opts()),{})}error(e,t){this._outputConfiguration.outputError(`${e}\n`,this._outputConfiguration.writeErr),typeof this._showHelpAfterError==`string`?this._outputConfiguration.writeErr(`${this._showHelpAfterError}\n`):this._showHelpAfterError&&(this._outputConfiguration.writeErr(`
|
|
484
|
+
`),this.outputHelp({error:!0}));let n=t||{},r=n.exitCode||1,i=n.code||`commander.error`;this._exit(r,i,e)}_parseOptionsEnv(){this.options.forEach(e=>{if(e.envVar&&e.envVar in g.env){let t=e.attributeName();(this.getOptionValue(t)===void 0||[`default`,`config`,`env`].includes(this.getOptionValueSource(t)))&&(e.required||e.optional?this.emit(`optionEnv:${e.name()}`,g.env[e.envVar]):this.emit(`optionEnv:${e.name()}`))}})}_parseOptionsImplied(){let e=new Iy(this.options),t=e=>this.getOptionValue(e)!==void 0&&![`default`,`implied`].includes(this.getOptionValueSource(e));this.options.filter(n=>n.implied!==void 0&&t(n.attributeName())&&e.valueFromOption(this.getOptionValue(n.attributeName()),n)).forEach(e=>{Object.keys(e.implied).filter(e=>!t(e)).forEach(t=>{this.setOptionValueWithSource(t,e.implied[t],`implied`)})})}missingArgument(e){let t=`error: missing required argument '${e}'`;this.error(t,{code:`commander.missingArgument`})}optionMissingArgument(e){let t=`error: option '${e.flags}' argument missing`;this.error(t,{code:`commander.optionMissingArgument`})}missingMandatoryOptionValue(e){let t=`error: required option '${e.flags}' not specified`;this.error(t,{code:`commander.missingMandatoryOptionValue`})}_conflictingOption(e,t){let n=e=>{let t=e.attributeName(),n=this.getOptionValue(t),r=this.options.find(e=>e.negate&&t===e.attributeName()),i=this.options.find(e=>!e.negate&&t===e.attributeName());return r&&(r.presetArg===void 0&&n===!1||r.presetArg!==void 0&&n===r.presetArg)?r:i||e},r=e=>{let t=n(e),r=t.attributeName();return this.getOptionValueSource(r)===`env`?`environment variable '${t.envVar}'`:`option '${t.flags}'`},i=`error: ${r(e)} cannot be used with ${r(t)}`;this.error(i,{code:`commander.conflictingOption`})}unknownOption(e){if(this._allowUnknownOption)return;let t=``;if(e.startsWith(`--`)&&this._showSuggestionAfterError){let n=[],r=this;do{let e=r.createHelp().visibleOptions(r).filter(e=>e.long).map(e=>e.long);n=n.concat(e),r=r.parent}while(r&&!r._enablePositionalOptions);t=By(e,n)}let n=`error: unknown option '${e}'${t}`;this.error(n,{code:`commander.unknownOption`})}_excessArguments(e){if(this._allowExcessArguments)return;let t=this.registeredArguments.length,n=t===1?``:`s`,r=e.length,i=`error: too many arguments${this.parent?` for '${this.name()}'`:``}. Expected ${t} argument${n} but got ${r}: ${e.join(`, `)}.`;this.error(i,{code:`commander.excessArguments`})}unknownCommand(){let e=this.args[0],t=``;if(this._showSuggestionAfterError){let n=[];this.createHelp().visibleCommands(this).forEach(e=>{n.push(e.name()),e.alias()&&n.push(e.alias())}),t=By(e,n)}let n=`error: unknown command '${e}'${t}`;this.error(n,{code:`commander.unknownCommand`})}version(e,t,n){if(e===void 0)return this._version;this._version=e,t||=`-V, --version`,n||=`output the version number`;let r=this.createOption(t,n);return this._versionOptionName=r.attributeName(),this._registerOption(r),this.on(`option:`+r.name(),()=>{this._outputConfiguration.writeOut(`${e}\n`),this._exit(0,`commander.version`,e)}),this}description(e,t){return e===void 0&&t===void 0?this._description:(this._description=e,t&&(this._argsDescription=t),this)}summary(e){return e===void 0?this._summary:(this._summary=e,this)}alias(e){if(e===void 0)return this._aliases[0];let t=this;if(this.commands.length!==0&&this.commands[this.commands.length-1]._executableHandler&&(t=this.commands[this.commands.length-1]),e===t._name)throw Error(`Command alias can't be the same as its name`);let n=this.parent?._findCommand(e);if(n){let t=[n.name()].concat(n.aliases()).join(`|`);throw Error(`cannot add alias '${e}' to command '${this.name()}' as already have command '${t}'`)}return t._aliases.push(e),this}aliases(e){return e===void 0?this._aliases:(e.forEach(e=>this.alias(e)),this)}usage(e){if(e===void 0){if(this._usage)return this._usage;let e=this.registeredArguments.map(e=>Ny(e));return[].concat(this.options.length||this._helpOption!==null?`[options]`:[],this.commands.length?`[command]`:[],this.registeredArguments.length?e:[]).join(` `)}return this._usage=e,this}name(e){return e===void 0?this._name:(this._name=e,this)}helpGroup(e){return e===void 0?this._helpGroupHeading??``:(this._helpGroupHeading=e,this)}commandsGroup(e){return e===void 0?this._defaultCommandGroup??``:(this._defaultCommandGroup=e,this)}optionsGroup(e){return e===void 0?this._defaultOptionGroup??``:(this._defaultOptionGroup=e,this)}_initOptionGroup(e){this._defaultOptionGroup&&!e.helpGroupHeading&&e.helpGroup(this._defaultOptionGroup)}_initCommandGroup(e){this._defaultCommandGroup&&!e.helpGroup()&&e.helpGroup(this._defaultCommandGroup)}nameFromFilename(e){return this._name=oe.basename(e,oe.extname(e)),this}executableDir(e){return e===void 0?this._executableDir:(this._executableDir=e,this)}helpInformation(e){let t=this.createHelp(),n=this._getOutputContext(e);t.prepareContext({error:n.error,helpWidth:n.helpWidth,outputHasColors:n.hasColors});let r=t.formatHelp(this,t);return n.hasColors?r:this._outputConfiguration.stripColor(r)}_getOutputContext(e){e||={};let t=!!e.error,n,r,i;return t?(n=e=>this._outputConfiguration.writeErr(e),r=this._outputConfiguration.getErrHasColors(),i=this._outputConfiguration.getErrHelpWidth()):(n=e=>this._outputConfiguration.writeOut(e),r=this._outputConfiguration.getOutHasColors(),i=this._outputConfiguration.getOutHelpWidth()),{error:t,write:e=>(r||(e=this._outputConfiguration.stripColor(e)),n(e)),hasColors:r,helpWidth:i}}outputHelp(e){let t;typeof e==`function`&&(t=e,e=void 0);let n=this._getOutputContext(e),r={error:n.error,write:n.write,command:this};this._getCommandAndAncestors().reverse().forEach(e=>e.emit(`beforeAllHelp`,r)),this.emit(`beforeHelp`,r);let i=this.helpInformation({error:n.error});if(t&&(i=t(i),typeof i!=`string`&&!Buffer.isBuffer(i)))throw Error(`outputHelp callback must return a string or a Buffer`);n.write(i),this._getHelpOption()?.long&&this.emit(this._getHelpOption().long),this.emit(`afterHelp`,r),this._getCommandAndAncestors().forEach(e=>e.emit(`afterAllHelp`,r))}helpOption(e,t){return typeof e==`boolean`?(e?(this._helpOption===null&&(this._helpOption=void 0),this._defaultOptionGroup&&this._initOptionGroup(this._getHelpOption())):this._helpOption=null,this):(this._helpOption=this.createOption(e??`-h, --help`,t??`display help for command`),(e||t)&&this._initOptionGroup(this._helpOption),this)}_getHelpOption(){return this._helpOption===void 0&&this.helpOption(void 0,void 0),this._helpOption}addHelpOption(e){return this._helpOption=e,this._initOptionGroup(e),this}help(e){this.outputHelp(e);let t=Number(g.exitCode??0);t===0&&e&&typeof e!=`function`&&e.error&&(t=1),this._exit(t,`commander.help`,`(outputHelp)`)}addHelpText(e,t){let n=[`beforeAll`,`before`,`after`,`afterAll`];if(!n.includes(e))throw Error(`Unexpected value for position to addHelpText.
|
|
485
|
+
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 Hy(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 Uy(){if(g.env.NO_COLOR||g.env.FORCE_COLOR===`0`||g.env.FORCE_COLOR===`false`)return!1;if(g.env.FORCE_COLOR||g.env.CLICOLOR_FORCE!==void 0)return!0}new Vy;const Wy=[],Gy=/\p{Cc}/gu,Ky=/[^\P{Cc}\n]/gu,qy=e=>e.replaceAll(Gy,`?`),Jy=e=>e.replaceAll(Ky,`?`),Yy=e=>Array.isArray(e)?e:[e],Xy=e=>e===void 0?Wy:[e],Zy=e=>e instanceof Error?e.message:String(e),X=e=>{let t=e.optsWithGlobals();return{json:t.json===!0,verbose:t.verbose===!0}},Z=(e,t,n,r,i)=>{if(t.json){let t={data:r,ok:!0,warnings:i??Wy};e.out(JSON.stringify(t))}else{for(let t of Yy(n))e.out(qy(t));for(let t of i??Wy)e.errLine(qy(`refs: warning: ${t}`))}},Qy=(e,t,n)=>{if(t.json){let t={error:{code:n.code,message:n.message,...n.reason===void 0?{}:{reason:n.reason}},ok:!1};e.out(JSON.stringify(t))}else e.errLine(Jy(`refs: ${n.message}`))},$y=(e,t)=>{e.errLine(qy(`refs: ${t}`))},eb=async(e,t,n)=>{let r=t.json?my:e.spinner();try{return await n(r)}finally{r.stop()}},Q=(e,t,n)=>async()=>{try{await n()}catch(n){let r=vu(n,{verbose:t.verbose});Qy(e,t,r),process.exitCode=r.exitCode}},tb=/\p{Cc}/u,nb=e=>!tb.test(e)&&e.isWellFormed(),rb=e=>`'${e.replaceAll(`'`,String.raw`'\''`)}'`,ib=e=>typeof e==`string`?void 0:e[1],ab=e=>typeof e==`string`?e:`${e[0]}=${rb(e[1])}`,ob=(e,t)=>{if(![...e.map(e=>ib(e)).filter(e=>e!==void 0),...t].every(e=>nb(e)))return;let n=t.some(e=>e.startsWith(`-`))?[`--`]:[];return[`refs edit`,...e.map(e=>ab(e)),...n,...t.map(e=>rb(e))].join(` `)},sb=e=>{let t=typeof e==`string`?[e]:e;return t.every(e=>nb(e))?`rm -rf -- ${t.map(e=>rb(e)).join(` `)}`:void 0},cb=e=>nb(e)?`rmdir -- ${rb(e)}`:void 0,lb=e=>({path:e.path}),ub=e=>e.filter(e=>e.path!==`.`),db=e=>e.find(e=>e.path===`.`),fb=e=>{let t=db(e);return t===void 0?{}:{[t.name]:lb(t)}},pb=(e,t,n)=>{let r=ub(e),i=fb(e);return r.length>0?{...i,...Object.fromEntries(r.map(e=>[e.name,lb(e)]))}:n===void 0?i:{...i,[n]:{path:t??`.`}}},mb=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}},hb=(e,t)=>{let n=Object.entries(e);if(n.length!==0)return Object.fromEntries(n.map(([e,n])=>[e,mb(e===t.rootPackageName?_b(n,t.refDescription):n)]))},gb=(e,t)=>{let[n]=Object.keys(fb(e));if(n!==void 0)return t[n]?.path===`.`?n:void 0},_b=(e,t)=>({...e,description:t}),vb=(e,t)=>Object.keys(e).filter(e=>e!==t).toSorted(),yb=(e,t,n)=>{if(vb(e,n).length===0)return;let r=Object.keys(e).toSorted().map(e=>qy(e)).join(`, `);throw z(`refs add --description cannot describe a package: it has one description, about the repository. Run the two-phase flow instead:
|
|
486
|
+
refs add ${rb(t)} --dry-run --json > proposal.json\nFill in the ref's own description, and one written from its own source for each package below, then:
|
|
348
487
|
refs add --proposal proposal.json
|
|
349
|
-
packages to describe: ${r}`)},
|
|
350
|
-
`)},gx=e=>{let t=O_.safeParse(e);if(!t.success)throw z(hx(t.error));return t.data},_x=async(e,t)=>{let n=await ax(e,t);return gx(lx(ox(n)))},vx=(e,t)=>[`refs add: dry-run proposal ready for '${e}' (checkout: ${t})`,`next: review the proposal, then run refs add --proposal <file> to finalize`],yx=e=>[...By(e.warning),...By(e.detectionWarning)],bx=async(e,t)=>{let n=await ex(e,t),r=V(e.env);await tx(r,n.proposal.key,n.effectiveCloneMode);let i=yx(n);return{data:n.proposal,human:vx(n.proposal.key,n.dest),warnings:i}},xx=e=>[`refs add: '${e}' added to config`],Sx=e=>{let t={default_branch:e.default_branch,description:e.description,key:e.key,url:e.url};e.tag_format_candidate!==null&&(t.tag_format=e.tag_format_candidate);let n=ub(e.packages);return n!==void 0&&(t.packages=n),t},Cx=async(e,t)=>{let n=await _x(e,t),r=V(e.env),i=Su(r,n.key);if(!U(i))throw L(`no checkout found at ${i} — run: refs add <source> --dry-run first`);let a=Sx(n),{entry:o,key:s}=await ix(e,{dest:i,home:r,ref:a});return{data:{entry:o,key:s},human:xx(s),warnings:[]}},wx=(e,t,n)=>{lb(e.proposal.packages,n,e.rootPackageName);let r={default_branch:e.proposal.default_branch,description:t,key:e.proposal.key,url:e.proposal.url};e.proposal.tag_format_candidate!==null&&(r.tag_format=e.proposal.tag_format_candidate);let i=ab(e.proposal.packages,{refDescription:t,...e.rootPackageName===void 0?{}:{rootPackageName:e.rootPackageName}});return i!==void 0&&(r.packages=i),r},Tx=async(e,t,n)=>{let r=await ex(e,t),i=V(e.env);await tx(i,r.proposal.key,r.effectiveCloneMode);let a=wx(r,n,t),o={dest:r.dest,home:i,ref:a};r.effectiveCloneMode!==void 0&&(o.effectiveCloneMode=r.effectiveCloneMode);let{entry:s,key:c}=await ix(e,o);return{data:{entry:s,key:c},human:xx(c),warnings:yx(r)}},Ex=e=>{let t=[e.dryRun,e.proposal!==void 0,e.description!==void 0].filter(Boolean).length;if(t>1)throw R(`refs add: use only one of --dry-run, --proposal, or --description`);if(t===0)throw R(`refs add needs --dry-run, --proposal, or --description`)},Dx=e=>{if(e===void 0||e===``)throw R(`refs add requires <source> (a git url or npm:<package>)`);return e},Ox=(e,t)=>(Ex(t),t.proposal===void 0?t.description===void 0?bx(e,Dx(t.source)):Tx(e,Dx(t.source),t.description):Cx(e,t.proposal)),kx=(e,t)=>{let n={dryRun:t.dryRun===!0};return e!==void 0&&(n.source=e),t.proposal!==void 0&&(n.proposal=t.proposal),t.description!==void 0&&(n.description=t.description),n},Ax=(e,t)=>{e.command(`add`).description(`Add a git reference in two phases: propose (--dry-run), then finalize (--proposal).`).argument(`[source]`,`git url or npm:<package> (omit when finalizing with --proposal)`).option(`--dry-run`,`resolve and clone the source, writing a reviewable proposal`).option(`--proposal <file>`,`finalize from a completed proposal JSON file (- for stdin)`).option(`--description <text>`,`one-shot: dry-run then finalize immediately with this description`).action((e,n,r)=>{let i=X(r);return Q(t,i,async()=>{let r=await Ox(t,kx(e,n));Z(t,i,r.human,r.data,r.warnings)})()})},jx=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`}},Mx=/^v(?<major>\d+)\.(?<minor>\d+)/u,Nx=e=>{let t=Mx.exec(e),n=t?.groups?.major,r=t?.groups?.minor;if(n!==void 0&&r!==void 0)return{major:Number(n),minor:Number(r)}},Px=e=>e===void 0?!1:e.major>24||e.major===24&&e.minor>=2,Fx=e=>{let{nodeVersion:t}=e;return Px(Nx(t))?{detail:t,name:`node`,status:`ok`}:{detail:`${t} does not satisfy the required range >=24.2`,name:`node`,status:`fail`}},Ix=()=>Cl.parse({meta:{cli_version:`0.0.0`,schema_version:1},refs:{},settings:{}}),Lx=async e=>{try{return{config:await B(e)}}catch(e){return{config:Ix(),errorMessage:Vy(e)}}},Rx=e=>e===void 0?{detail:`config is present and matches the current schema`,name:`config`,status:`ok`}:{detail:e,name:`config`,status:`fail`},zx={ci:`update check is off in CI — set REFS_UPDATE_CHECK=1 to run it here anyway`,config:`update check is off ([updates].check = false in config.toml)`,env:`update check is off (REFS_UPDATE_CHECK=0)`},Bx=(e,t,n)=>{if(q_(e,t)){let r=n?` (npm was unreachable just now; this was its last answer)`:``;return{detail:`${J_(e,t)}${r}`,name:`cli-update`,status:`warn`}}return n?{detail:`could not reach npm to check; its last answer was ${t}, which this CLI (${e}) already has`,name:`cli-update`,status:`warn`}:{detail:`this CLI (${e}) is npm's latest published release`,name:`cli-update`,status:`ok`}},Vx=async(e,t)=>{let n=Q_({env:e.env,updates:t.updates});if(n!==`on`)return{detail:zx[n],name:`cli-update`,status:`ok`};let{latest:r,stale:i}=await K_({fetch:e.fetcher,home:V(e.env),nowMs:Date.now()});return r===void 0?{detail:`could not reach npm to learn the latest published version — not a fault of your setup, and nothing else depends on it`,name:`cli-update`,status:`warn`}:Bx(e.cliVersion,r,i)},Hx=(e,t)=>Object.keys(t.refs).map(e=>nl.parse(e)).map(t=>({dest:Su(e,t),key:t})).filter(e=>U(e.dest)),Ux=[`pre-commit`,`pre-push`],Wx=async(t,r)=>{try{return await e(h(t.hooksDir,r),n.X_OK),!0}catch{return!1}},Gx=async e=>{let t=await Promise.all(Ux.map(t=>Wx(e,t)));return Ux.filter((e,n)=>!t[n])},Kx=async e=>{try{return(await c(e.hooksDir)).filter(e=>!Ux.includes(e)).toSorted()}catch(e){if(F(e))return[];throw e}},qx=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},Jx=(e,t)=>`${t.map(e=>`hooks/${e}`).join(`, `)}: not installed by refs — this is the directory git resolves hook names against for every managed checkout, so nothing whose provenance refs cannot account for belongs in it; remove: ${Zy(t.map(t=>h(e,t)))}`,Yx=e=>{let t=[];return e.unexpected.length>0&&t.push(Jx(e.hooksDir,e.unexpected)),e.missingHooks.length>0&&t.push(`${e.missingHooks.map(e=>`hooks/${e}`).join(`, `)} missing or not executable — run: refs init`),e.badKeys.length>0&&t.push(`core.hooksPath not set for: ${e.badKeys.join(`, `)} — run: refs init`),t},Xx=e=>{let t=Yx(e);return t.length>0?{detail:t.join(`; `),name:`hooks-guard`,status:`fail`}:{detail:`${Ux.map(e=>`hooks/${e}`).join(`, `)} present; ${e.checkoutCount} checkout(s) guarded`,name:`hooks-guard`,status:`ok`}},Zx=async(e,t,n)=>{let r=Hx(t,n),[i,a,o]=await Promise.all([Gx(t),Kx(t),Promise.all(r.map(n=>qx(e,t,n.dest)))]),s=r.filter((e,t)=>!o[t]).map(e=>e.key);return Xx({badKeys:s,checkoutCount:r.length,hooksDir:t.hooksDir,missingHooks:i,unexpected:a})},Qx=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}},$x=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`}},eS=async(e,t,n)=>{let r=Hx(t,n),i=await Promise.all(r.map(t=>Qx(e,t)));return $x(i)},tS=async e=>{try{return await P_(e)}catch{return A_.parse({})}},nS=async e=>{try{return(await c(e,{withFileTypes:!0})).filter(e=>e.isDirectory()).map(e=>e.name)}catch(e){if(F(e))return[];throw e}},rS=async(e,t)=>{if(U(e))return[[...t]];let n=await nS(e);return(await Promise.all(n.map(n=>rS(h(e,n),[...t,n])))).flat()},iS=(e,t,n)=>{let r=e.refs[t]?.pending_proposal_at;return r!==void 0&&n-Date.parse(r)<864e5},aS=(e,t,n)=>{if(iS(t,e.key,n))return`${e.key}: pending add`;let r=Zy(e.dest);return r===void 0?`${e.key}: orphan — its path cannot be put into a pasteable command; remove it by hand`:`${e.key}: orphan — remove with: ${r}`},oS=(e,t)=>({dest:h(e.sourcesDir,...t),key:t.join(`/`)}),sS=async(e,t,n)=>{let r=(await rS(e.sourcesDir,[])).map(t=>oS(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=>aS(e,n,i)).join(`; `),name:`orphans`,status:`warn`}},cS=e=>{let t=(e??``).lastIndexOf(`/`);return t===-1?`.`:(e??``).slice(0,t)},lS=e=>{let[t=`.`,...n]=e,r=t.split(`/`),i=r.length;for(let e of n){let t=e.split(`/`),n=0;for(;n<i&&n<t.length&&r[n]===t[n];)n+=1;i=n}return i===0?`.`:r.slice(0,i).join(`/`)},uS=e=>_l.safeParse({name:e.name,path:e.path}).success,dS=(e,t,n)=>Xy([[`--package`,e.name],`--decline`,[`--path`,n]],[t]),fS=(e,t,n)=>Xy([[`--package`,e.name],`--create`,[`--path`,n],[`--description`,`<what it is>`]],[t]),pS=(e,t)=>{let{path:n}=e;if(n===void 0||!uS(e))return{};let r=dS(e,t,n),i=pl(e.name)?fS(e,t,n):void 0;return r===void 0?{}:i===void 0?{decline:r}:{decline:r,register:i}},mS=(e,t)=>{let n=cl.safeParse(e.path);if(!n.success)return{};let r=Xy([[`--package`,e.name]],[t,`path`,n.data]);return r===void 0?{}:{repoint:r}},hS=(e,t)=>{let n=Xy([[`--package`,e.name],`--remove`],[t]);return n===void 0?{}:{unregister:n}},gS=(e,t)=>e.status===`unregistered`?pS(e,t):e.status===`relocated`?mS(e,t):e.status===`missing`?hS(e,t):{},_S=`(unknown)`,vS=`no single-line command can carry these values, so none is offered — 'refs doctor --json' has them exactly`,yS=(e,t)=>{let{decline:n,register:r}=pS(e,t);if(n!==void 0)return r===void 0?`Its name is one the packages table cannot hold, so it cannot be registered — if that is the answer, record it: ${n}`:`To register it (replace the description first): ${r}. If it should not be: ${n}`},bS=(e,t)=>{let n=`${e.name}: declared in this checkout but not registered — it cannot be resolved by name until it is`,{path:r}=e;if(r===void 0)return`${n}. Declared at several paths (${(e.candidates??[]).join(`, `)}) — pick one`;if(!uS(e))return`${n}. Its name or path is one the configuration cannot hold, so there is no command for it — report it and leave it unregistered`;let i=yS(e,t);return i===void 0?`${n}. ${vS} — report it and leave it unregistered`:`${n}. ${i}`},xS=(e,t,n)=>{let r=`${e.name}: moved to ${e.path??_S} — update the entry's path (${n})`,{repoint:i}=gS(e,t);return i===void 0?r:`${r}. To fix it: ${i}`},SS=(e,t,n)=>{let r=`${e.name}: gone from this repo's workspaces (${n}) — repoint the entry if it moved out of them`,{unregister:i}=gS(e,t);return i===void 0?`${r}; ${vS}, so unregister it by hand`:`${r}, or unregister it: ${i}`},CS=(e,t)=>{let n=`configured: ${e.configured_path??_S}`;if(e.status===`relocated`)return xS(e,t,n);if(e.status===`missing`)return SS(e,t,n);if(e.status===`ambiguous`){let t=(e.candidates??[]).join(`, `);return`${e.name}: declared at several paths (${t}) — point the entry at one (${n})`}return`${e.name}: could not be checked — ${e.reason??`(no reason given)`} (${n})`},wS=(e,t)=>e.status===`unregistered`?bS(e,t):CS(e,t),TS=e=>`could not check for unregistered packages — ${e}`,ES=e=>`…and ${e} more finding(s) — act on the ones above (register, repoint or decline) and run the check again to see the rest`,DS=e=>{let t=e.length-10;return t<=0?[...e]:[...e.slice(0,10),ES(t)]},OS=e=>{let t=new Map;for(let n of e){let[e=`.`]=cS(n.path).split(`/`);t.set(e,[...t.get(e)??[],n])}return t},kS=e=>e.path===void 0,AS=(e,t,n)=>{if(e.length<3)return e.map(e=>({candidates:1,dir:n,line:bS(e,t)}));let r=lS(e.map(e=>cS(e.path)));return[{candidates:e.length,dir:r,line:`${r}: ${e.length} unregistered package(s) the configuration does not have`}]},jS=e=>{let t=e.reduce((e,t)=>e+t.candidates,0),n=new Set(e.flatMap(e=>e.dir===void 0?[]:[e.dir])).size;return`…and ${t} more unregistered package(s)${n===0?``:` in ${n} director(ies)`} — 'refs doctor --json' lists every candidate`},MS=(e,t)=>{let n=e.filter(e=>kS(e)).map(e=>({candidates:1,line:bS(e,t)})),r=[...OS(e.filter(e=>!kS(e)))].toSorted(([e],[t])=>e.localeCompare(t)).flatMap(([e,n])=>AS(n,t,e)),i=[...n,...r],a=i.slice(10);return a.length===0?i.map(e=>e.line):[...i.slice(0,10).map(e=>e.line),jS(a)]},NS=(e,t)=>e.reason===void 0?[...DS((e.packages??[]).map(e=>wS(e,t))),...MS(e.discovery??[],t),...e.discovery_incomplete===void 0?[]:[TS(e.discovery_incomplete)]]:[`could not be checked — ${e.reason}`],PS=e=>{let t;return()=>(t??=ny(e),t)},FS=async(e,t,n)=>{let r=await pv(e);if(r===void 0||t.some(e=>e.packageName===r.name))return{issues:[]};let i=await n();if(!i_(i))return{incomplete:Fb(i),issues:[]};let a=m_(i.packages,r.name);return a.kind===`ambiguous`?{issues:[{candidates:a.paths,name:r.name,status:`unregistered`}]}:{issues:a.kind===`found`?[{name:r.name,path:a.path,status:`unregistered`}]:[]}},IS=e=>{let t=new Map;for(let n of e)t.set(n.name,[...t.get(n.name)??[],n.path]);return t},LS=(e,t)=>{let n=new Set(e.changedDirs),r=t.filter(e=>!n.has(e.path)).map(e=>e.name);return new Set([...e.namesBefore,...r])},RS=(e,t)=>t.length===1&&t[0]!==void 0?{name:e,path:t[0],status:`unregistered`}:{candidates:[...t],name:e,status:`unregistered`},zS=async(e,t,n)=>{if(t.kind===`arrivals`&&t.changedDirs.length===0)return{issues:[]};let r=await n();if(!i_(r))return{incomplete:Fb(r),issues:[]};let i=new Set(e.map(e=>e.packageName)),a=r.packages.filter(e=>e.path!==`.`),o=t.kind===`all`?void 0:LS(t,a);return{issues:[...IS(a)].filter(([e])=>!i.has(e)).filter(([e])=>o===void 0||!o.has(e)).map(([e,t])=>RS(e,t)).toSorted((e,t)=>e.name.localeCompare(t.name))}},BS=(e,t)=>{if(t.length===0)return{issues:[...e],suppressed:[]};let n=(e,n)=>t.some(t=>t.name===e&&t.path===n),r=[];return{issues:e.flatMap(e=>{if(e.status!==`unregistered`)return[e];let t=e.path===void 0?e.candidates??[]:[e.path],i=t.filter(t=>!n(e.name,t)),a=t.filter(t=>n(e.name,t));return r.push(...a.map(t=>({name:e.name,path:t}))),i.length===0?[]:[RS(e.name,i)]}),suppressed:r}},VS=e=>e!==`unmaterialized`&&e!==`verified`,HS=new Set([`ambiguous`,`missing`,`relocated`]),US=(e,t={})=>{let{declined:n=[],discoveryIncomplete:r}=t,i=e.filter(e=>e.status!==`unregistered`),a=e.filter(e=>e.status===`unregistered`);return{...n.length===0?{}:{declined:[...n]},...a.length===0?{}:{discovery:a},...r===void 0?{}:{discovery_incomplete:r},...i.length===0?{}:{packages:i},status:WS(i,r)}},WS=(e,t)=>e.some(e=>HS.has(e.status))?`drift`:e.length===0&&t===void 0?`ok`:`unknown`,GS=(e,t)=>({path:e.configuredPath,reason:t,status:`unverifiable`}),KS=(e,t)=>a_(t)?{configuredPath:e.configuredPath,path:null,status:`missing`}:GS(e,`this repo declares no workspaces, so there was nowhere to search`),qS=(e,t)=>t===e.configuredPath,JS=e=>e.packages.filter(e=>e.path!==`.`),YS=(e,t)=>{let n=m_(JS(t),e.packageName);return n.kind===`ambiguous`?{candidates:n.paths,configuredPath:e.configuredPath,path:null,status:`ambiguous`}:i_(t)?n.kind===`absent`?KS(e,t):qS(e,n.path)?GS(e,`the checkout changed while it was being inspected`):{configuredPath:e.configuredPath,path:n.path,status:`relocated`}:GS(e,n.kind===`found`?`workspace detection was incomplete, so the new location is not confirmed unique`:`workspace detection was incomplete`)},XS=e=>{let t=new Map(Object.entries(e??{}));return[...t.keys()].toSorted().flatMap(e=>{let n=t.get(e);return n===void 0?[]:[{configuredPath:n.path,packageName:e}]})},ZS=async(e,t)=>{let n=await d_(e,t.configuredPath,t.packageName);if(n.kind===`match`)return{path:t.configuredPath,status:`verified`};if(n.kind===`unreadable`)return{path:t.configuredPath,reason:n.reason,status:`unverifiable`}},QS=e=>e.flatMap(e=>e.settled===void 0?[]:[{outcome:e.settled,query:e.query}]),$S=async(e,t,n)=>{let r=await Promise.all(t.map(async t=>({query:t,settled:await ZS(e,t)})));if(r.every(e=>e.settled!==void 0))return QS(r);let i=await n();return r.map(e=>({outcome:e.settled??YS(e.query,i),query:e.query}))},eC=e=>{let{outcome:t,query:n}=e;return VS(t.status)?[{...t.candidates===void 0?{}:{candidates:t.candidates},configured_path:n.configuredPath,name:n.packageName,...t.status===`relocated`&&t.path!==null?{path:t.path}:{},...t.reason===void 0?{}:{reason:t.reason},status:t.status}]:[]},tC=(e,t)=>{let n=new Set(e.map(e=>e.name));return[...e,...t.filter(e=>!n.has(e.name))]},nC=async(e,t,n)=>{let r=XS(t.packages),[i]=r;if(i===void 0)return{status:`ok`};let a=PS(e);try{let[i,o,s]=await Promise.all([$S(e,r,a),FS(e,r,a),zS(r,n,a)]),c=BS([...i.flatMap(e=>eC(e)),...tC(o.issues,s.issues)],t.declined_packages??[]);return US(c.issues,{declined:c.suppressed,...(s.incomplete??o.incomplete)===void 0?{}:{discoveryIncomplete:s.incomplete??o.incomplete}})}catch(e){return{reason:Vy(e),status:`unknown`}}},rC=async(e,t,n)=>{try{return await G(e,gb(n.key),()=>nC(n.dest,t.refs[n.key]??{},{kind:`all`}),{timeoutMs:100})}catch(e){if(e instanceof I&&e.code===`conflict`)return{reason:`another refs process is holding this ref`,status:`unknown`};throw e}},iC=e=>e===0?``:` (${e} declined package(s) not reported)`,aC=(e,t)=>e.unhealthy.length===0?`every configured package path resolves in ${t} checkout(s)`:e.unhealthy.join(`; `),oC=(e,t)=>{let{declined:n,discovery:r,findings:i}=e;return{detail:[aC(e,t)+iC(n),...r].join(`; `),...i.length===0?{}:{findings:i},name:`config-drift`,status:e.unhealthy.length===0?`ok`:`warn`}},sC=async(e,t,n)=>{let[r,...i]=n;if(r===void 0)return{declined:0,discovery:[],findings:[],unhealthy:[]};let a=await rC(e,t,r),o=await sC(e,t,i);return lC(o,{key:r.key,report:a})},cC=(e,t)=>({...e,...gS(e,t)}),lC=(e,t)=>{let{key:n,report:r}=t,i=e=>e.map(e=>`${n}: ${e}`),a=r.discovery??[],o=r.packages??[],s=[...o,...a];return{declined:(r.declined??[]).length+e.declined,discovery:[...i(NS({discovery:a,status:`ok`},n)),...e.discovery],findings:s.length===0?e.findings:[{key:n,packages:s.map(e=>cC(e,n))},...e.findings],unhealthy:[...i(NS({...r.discovery_incomplete===void 0?{}:{discovery_incomplete:r.discovery_incomplete},...r.reason===void 0?{}:{reason:r.reason},packages:o,status:r.status},n)),...e.unhealthy]}},uC=async(e,t)=>{let n=Hx(e,t);return oC(await sC(e,t,n),n.length)},dC=`git-exec-surfaces`,fC=/^hook\.(?<label>.+)\.command$/u,pC=/^hook\.(?<label>.+)\.enabled$/u,mC=/^filter\..+\.(?:clean|smudge|process)$/u,hC=new Set([``,`0`,`1`,`false`,`no`,`off`,`on`,`true`,`yes`]),gC=e=>{let t=e.split(`\0`),n=[];for(let e=0;e+1<t.length;e+=2){let r=t[e+1]??``,i=t[e]??``,a=r.indexOf(`
|
|
351
|
-
`),o=a===-1?r:r.slice(0,a),s=a===-1?``:r.slice(a+1);n.push({key:o,scope:i,value:s})}return n},_C=e=>{let t=new Map;for(let n of e){let e=pC.exec(n.key)?.groups?.label;e!==void 0&&t.set(e,n.value!==`false`)}return new Set([...t].filter(([,e])=>!e).map(([e])=>e))},vC=(e,t)=>{if(e.key===`core.fsmonitor`)return!hC.has(e.value.trim().toLowerCase());let n=fC.exec(e.key)?.groups?.label;return n===void 0?mC.test(e.key):!t.has(n)},yC=e=>{let t=gC(e).filter(e=>e.scope!==`local`),n=_C(t),r=t.filter(e=>vC(e,n)).map(e=>e.key);return[...new Set(r)]},bC=e=>({detail:`${e}, so this could not be checked`,name:dC,status:`warn`}),xC=e=>({detail:`${e.join(`, `)}: git runs these itself, and the managed hooks path does not cover them — a configured hook fires on the events refs causes, a filter is selected by a checkout's own .gitattributes, and fsmonitor runs in the worktree. Whether one of them reaches a checkout's content depends on the command, which refs cannot decide for you`,name:dC,status:`warn`}),SC=async(e,t)=>{let n=await e.runner.run(`git`,[`config`,`--list`,`-z`,`--show-scope`],{cwd:t});if(n.exitCode!==0)return bC(`the git configuration could not be read`);if(n.stdoutTruncated===!0)return bC(`the git configuration was too large to read whole`);let r=yC(n.stdout);return r.length===0?{detail:`no configured hook, filter or fsmonitor command outside a checkout`,name:dC,status:`ok`}:xC(r)},CC=`home-modes`,wC=e=>[{expected:448,label:`the refs home`,path:e.root},{expected:448,label:`sources/`,path:e.sourcesDir},{expected:448,label:`locks/`,path:e.locksDir},{expected:448,label:`hooks/`,path:e.hooksDir},{expected:384,label:`config.toml`,path:e.configPath},{expected:384,label:`state.json`,path:e.statePath}],TC=e=>(e&511).toString(8).padStart(3,`0`),EC=e=>e instanceof Error&&`code`in e?String(e.code):`unknown`,DC=async e=>{try{let[t,n]=await Promise.all([p(e),i(e)]);return{kind:`mode`,mode:t.mode&511,symlink:n.isSymbolicLink()}}catch(e){let t=EC(e);return t===`ENOENT`?{kind:`absent`}:{kind:`unreadable`,reason:t}}},OC=async e=>{let t=await DC(e.path);if(t.kind===`absent`)return;if(t.kind===`unreadable`)return{repairable:!1,text:`${e.label} could not be inspected (${t.reason})`};if(!(t.mode&63))return;let n=t.symlink?` — a symlink; fix it where it points`:``;return{repairable:!t.symlink,text:`${e.label} is ${TC(t.mode)} (expected ${TC(e.expected)})${n}`}},kC=e=>e.some(e=>e.repairable)?` — run: refs init`:``,AC=async e=>{if(process.platform===`win32`)return{detail:`not applicable on this platform — the mode bits do not say who may write`,name:CC,status:`ok`};let t=(await Promise.all(wC(e).map(e=>OC(e)))).filter(e=>e!==void 0);return t.length===0?{detail:`no group or other permission bits on anything refs owns`,name:CC,status:`ok`}:{detail:`${t.map(e=>e.text).join(`; `)}${kC(t)}`,name:CC,status:`warn`}},jC=e=>{let{diagnosis:t}=e;return e.kind===`claim`||!e.isDirectory||t.pidState===`definitely-dead`||t.stale||t.meta===`malformed`||t.meta===`unreadable`||t.policy===`unknown`?!1:t.ageMs===void 0||t.ageMs>=0},MC=e=>{let{ageMs:t,budgetMs:n,policy:r}=e;return r===`unknown`?`, state could not be read`:t===void 0||n===void 0?``:t<0?`, recorded time is in the future — check the system clock`:`, ${Mm(t)} into a ${Mm(n)} window`},NC=e=>e.pid===void 0?`owner unknown (metadata ${e.meta})`:e.pidState===`definitely-dead`?`recorded pid ${e.pid} is not running`:`recorded pid ${e.pid} present`,PC=(e,t)=>{let n=h(e.locksDir,gm,t.name),r=t.diagnosis.ageMs===void 0?``:` for ${Mm(t.diagnosis.ageMs)}`,i=Qy(n),a=i===void 0?`remove that directory by hand — its path cannot be put into a pasteable command`:`${FC}: ${i}`;return`steal claim on ${t.name}: present${r}. Stealing this lock is blocked while it is here. A reclaim in progress clears it within a moment; if it stays, ${a}`},FC=`stop every refs process using this home — including suspended ones — and then run`,IC=(e,t)=>{let{diagnosis:n}=t;if(lm(n))return`, reclaimable now`;if(!n.stale&&t.isDirectory)return``;let r=h(e.locksDir,t.name),i=Zy(r);return i===void 0?`, not automatically reclaimable — and its path cannot be put into a pasteable command, so it has to be removed by hand`:`, not automatically reclaimable — if it is genuinely abandoned, ${FC}: ${i}`},LC=(e,t)=>{let{diagnosis:n}=t,r=t.isDirectory?``:`not a directory, `,i=IC(e,t);return`${t.name}: ${r}${NC(n)}${MC(n)}${i}`},RC=async e=>{let t=await jm(e),[n]=t;return n===void 0?{detail:`no locks held`,name:`locks`,status:`ok`}:{detail:t.map(t=>t.kind===`claim`?PC(e,t):LC(e,t)).join(`; `),name:`locks`,status:t.every(e=>jC(e))?`ok`:`warn`}},zC=[`.agents`,`skills`,`refs`,`SKILL.md`],BC=[`skills`,`refs`,`SKILL.md`],VC=[`.claude`,`skills`,`refs`,`SKILL.md`],HC=`npx skills add kaisers-io/refs`,UC=`npm i -g @kaisers-io/refs@latest`,WC=(e,t)=>e===void 0?void 0:{display:t,path:e},GC=e=>{let{dirName:t,env:n,home:r,overrideName:i}=e,a=n[i]?.trim();return a!==void 0&&a.length>0?{display:a,path:a}:WC(r===void 0?void 0:h(r,t),`~/${t}`)},KC=e=>{let t=e.homedir.length>0?e.homedir:void 0;return[{label:`shared ~/.agents`,root:WC(t,`~/.agents`),segments:zC},{label:`Claude Code`,root:GC({dirName:`.claude`,env:e.env,home:t,overrideName:`CLAUDE_CONFIG_DIR`}),segments:BC},{label:`Codex`,root:GC({dirName:`.codex`,env:e.env,home:t,overrideName:`CODEX_HOME`}),segments:BC},{label:`project ./.agents`,root:WC(e.cwd,`./.agents`),segments:zC},{label:`project ./.claude`,root:WC(e.cwd,`./.claude`),segments:VC}].flatMap(({label:e,root:t,segments:n})=>t===void 0?[]:[{display:t.display,label:e,path:h(t.path,...n)}])},qC=async(e,t)=>{try{let n=await l(e);return{label:t,realPath:n,source:await s(n,`utf8`)}}catch{return}},JC=e=>{let t=new Map;for(let n of e)t.has(n.realPath)||t.set(n.realPath,n);return[...t.values()]},YC=/^---\r?\n(?<body>[\s\S]*?)\r?\n---/u,XC=/^\s*cli_version:\s*["']?(?<version>[^"'\s]+)["']?\s*$/mu,ZC=e=>{let t=YC.exec(e)?.groups?.body;if(t!==void 0)return XC.exec(t)?.groups?.version},QC=(e,t)=>{if(e.length>32)return`unknown`;if(e===t)return`match`;let n=z_(e,t);return n===void 0?`unknown`:n===0?`match`:n>0?`cli-older`:`skill-older`},$C={"cli-older":(e,t)=>`the refs skill targets CLI ${e} but this CLI is ${t} — update the CLI: ${UC}`,match:(e,t)=>`the refs skill is installed and matches this CLI (${t})`,"skill-older":(e,t)=>`the refs skill targets CLI ${e} but this CLI is ${t} — update the skill: ${HC}`,unknown:(e,t)=>`the refs skill does not declare a version this CLI (${t}) can compare — reinstall both: ${UC} and ${HC}`},ew=e=>{let{cliVersion:t,label:n,skillVersion:r}=e;if(r===void 0)return{detail:`the refs skill (${n}) predates the version gate — update it: ${HC}`,name:`skill`,status:`warn`};let i=QC(r,t);return{detail:`${n}: ${$C[i](r,t)}`,name:`skill`,status:i===`match`?`ok`:`warn`}},tw=e=>({detail:`refs skill not found in the locations this check knows about (${e.map(e=>e.display).join(`, `)}) — an install anywhere else is invisible here and still works; if it really is missing: ${HC}`,name:`skill`,status:`warn`}),nw=async e=>{let t=KC(e),n=await Promise.all(t.map(e=>qC(e.path,e.label))),r=JC(n.filter(e=>e!==void 0)).map(t=>ew({cliVersion:e.cliVersion,label:t.label,skillVersion:ZC(t.source)}));return r.find(e=>e.status!==`ok`)??r[0]??tw(t)},rw=/^(?<user>[^/\s@]+)@(?<host>[^:/\s]+):/u,iw=e=>e===``?{}:{user:e},aw=e=>e===``?{}:{port:e},ow=e=>{try{let t=new URL(e);return t.protocol===`ssh:`?{host:t.hostname,...iw(t.username),...aw(t.port)}:void 0}catch{return}},sw=e=>{let t=rw.exec(e),n=t?.groups?.host;return n===void 0?ow(e):{host:n,user:t?.groups?.user??`git`}},cw=e=>e.port===void 0?e.host:`${e.host}:${e.port}`,lw=e=>e.user===void 0?cw(e):`${e.user}@${cw(e)}`,uw=e=>{let t=Object.values(e.refs).map(e=>sw(e.url)).filter(e=>e!==void 0),n=new Map;for(let e of t)n.set(lw(e),e);return[...n.values()].toSorted((e,t)=>lw(e).localeCompare(lw(t)))},dw=/Permission denied/u,fw=[/Could not resolve hostname/u,/Connection refused/u,/Host key verification failed/u,/timed out/u],pw=e=>e.user===void 0?e.host:`${e.user}@${e.host}`,mw=e=>{let t=[`-o`,`ConnectTimeout=5`,`-o`,`BatchMode=yes`],n=pw(e);return e.port===void 0?[...t,`-T`,n]:[...t,`-p`,e.port,`-T`,n]},hw=async(e,t,n)=>{let r=lw(t),i=await e.runner.run(`ssh`,mw(t),{timeoutMs:n});return i.timedOut===!0?{host:r,outcome:`timeout`}:dw.test(i.stderr)?{host:r,outcome:`denied`}:fw.some(e=>e.test(i.stderr))?{detail:i.stderr.trim(),host:r,outcome:`connection-warn`}:{host:r,outcome:`ok`}},gw=(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`}},_w=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`}},vw=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`}},yw=e=>({detail:`ssh auth ok for: ${e.map(e=>e.host).join(`, `)}`,name:`ssh-auth`,status:`ok`}),bw=(e,t)=>gw(e,t)??_w(e)??vw(e)??yw(e),xw=async(e,t,n)=>{let r=uw(t);if(r.length===0)return;let i=n?.timeoutMs??1e4,a=await Promise.all(r.map(t=>hw(e,t,i)));return bw(a,i)},Sw=async e=>{try{return await e.run()}catch(t){return{detail:`check crashed: ${Vy(t)}`,name:e.name,status:`fail`}}},Cw={"cli-update":`Checking for a newer refs release`,config:`Checking the config`,"config-drift":`Comparing registered packages with the checkouts`,"dirty-checkouts":`Looking for local changes in checkouts`,git:`Checking Git`,"git-exec-surfaces":`Checking what Git is configured to run`,"hooks-guard":`Checking the checkout protection hooks`,locks:`Checking locks`,node:`Checking Node.js`,orphans:`Looking for orphaned checkouts`,skill:`Checking the installed skill`,"ssh-auth":`Checking SSH authentication`},ww=async(e,t)=>{let[n,...r]=e;if(n===void 0)return[];t.update(Cw[n.name]??`Running the ${n.name} check`);let i=await Sw(n),a=await ww(r,t);return i===void 0?a:[i,...a]},Tw=e=>{let{configLoad:t,ctx:n,home:r,state:i}=e;return[{name:`git`,run:()=>jx(n)},{name:`git-exec-surfaces`,run:()=>SC(n,r.root)},{name:`node`,run:()=>Promise.resolve(Fx(n))},{name:`config`,run:()=>Promise.resolve(Rx(t.errorMessage))},{name:`home-modes`,run:()=>AC(r)},{name:`hooks-guard`,run:()=>Zx(n,r,t.config)},{name:`dirty-checkouts`,run:()=>eS(n,r,t.config)},{name:`config-drift`,run:()=>uC(r,t.config)},{name:`orphans`,run:()=>sS(r,t.config,i)},{name:`locks`,run:()=>RC(r)},{name:`skill`,run:()=>nw(n)},{name:`cli-update`,run:()=>Vx(n,t.config)},{name:`ssh-auth`,run:()=>xw(n,t.config)}]},Ew=async(e,t)=>{t.update(`Reading config and state`);let n=V(e.env),r=await Lx(n),i=await tS(n);return ww(Tw({configLoad:r,ctx:e,home:n,state:i}),t)},Dw={fail:`FAIL`,ok:`OK`,warn:`WARN`},Ow=e=>e.map(e=>`[${Dw[e.status]}] ${e.name}: ${e.detail}`),kw=e=>e.some(e=>e.status===`fail`),Aw=(e,t)=>{e.command(`doctor`).description(`Run environment/integrity checks (git, node, config, hooks, checkouts, drift, locks, ssh).`).action((e,n)=>{let r=X(n);return Q(t,r,async()=>{let e=await Wy(t,r,e=>Ew(t,e));Z(t,r,Ow(e),{checks:e}),kw(e)&&(process.exitCode=ou.UNEXPECTED)})()})},jw=(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},Mw=(e,t)=>{if(!U(e))throw L(`checkout for '${t}' is missing — run: refs sync ${qy(t)}`)},Nw=(e,t,n)=>{let{packages:r}=e,i=r!==void 0&&Object.hasOwn(r,n)?r[n]:void 0;if(i===void 0)throw L(`no package '${n}' registered on ref '${t}'`);return i},Pw=`never`,Fw=(e,t,n)=>e===void 0||n-Date.parse(e)>t,Iw=(e,t)=>`${e} ${t}${e===1?``:`s`} ago`,Lw=(e,t)=>{if(e===void 0)return Pw;let n=t-Date.parse(e);if(Number.isNaN(n))return Pw;let r=Math.floor(n/1e3);if(r<60)return`just now`;let i=Math.floor(r/60);if(i<60)return Iw(i,`minute`);let a=Math.floor(i/60);if(a<24)return Iw(a,`hour`);let o=Math.floor(a/24);return o<365?Iw(o,`day`):Iw(Math.floor(o/365),`year`)},Rw=e=>{let t=Lw(e.lastFetchedAt,e.now),n=[`synced: ${t}`];return e.stale&&t!==Pw&&n.push(`status: stale`),e.missing&&n.push(`missing: checkout not found — run: refs sync`),n},zw=(e,t,n)=>{let r=e.state.refs[t],i=il(j_(`sync_ttl`,n,e.settings)),a=Object.keys(n.packages??{}).toSorted();return{clone_mode:j_(`clone_mode`,n,e.settings),description:n.description,key:t,...r?.last_fetched_at===void 0?{}:{last_fetched_at:r.last_fetched_at},missing:!U(Su(e.home,nl.parse(t))),...e.includePackages?{packages:a}:{},packages_count:a.length,stale:Fw(r?.last_fetched_at,i,e.now)}},Bw=e=>{let t={home:e.home,includePackages:e.includePackages,now:e.now,settings:e.config.settings,state:e.state};return Object.entries(e.config.refs).map(([e,n])=>zw(t,e,n)).toSorted((e,t)=>e.key.localeCompare(t.key))},Vw=async(e,t,n)=>{let r=V(e.env),i=await B(r),a=await P_(r);return Bw({config:i,home:r,includePackages:t,now:n,state:a})},Hw=(e,t)=>[`ref: ${e.key}`,`description: ${e.description}`,...Rw({lastFetchedAt:e.last_fetched_at,missing:e.missing,now:t,stale:e.stale})],Uw=(e,t)=>e.length===0?[`no refs configured — run: refs add <source>`]:e.reduce((e,n,r)=>(r>0&&e.push(``),e.push(...Hw(n,t)),e),[]),Ww=e=>e.split(`/`),Gw=(e,t)=>{let n=Ww(e);if(t.length>n.length)return!1;let r=n.length-t.length;return t.every((e,t)=>e===n[r+t])},Kw=(e,t)=>{if(Object.hasOwn(e.refs,t))return nl.parse(t);let n=Ww(t),r=Object.keys(e.refs).filter(e=>Gw(e,n)).toSorted(),[i]=r;if(i===void 0)throw L(`no ref matches '${t}'`);if(r.length>1)throw R(`'${t}' matches more than one ref: ${r.join(`, `)}`);return nl.parse(i)},qw=(e,t)=>{e.command(`list`).description(`List configured refs with their staleness/missing checkout status.`).option(`--packages`,`include each ref's package names in --json output (off by default)`).action((e,n)=>{let r=X(n);return Q(t,r,async()=>{let n=Date.now(),i=await Vw(t,e.packages===!0,n);Z(t,r,Uw(i,n),i)})()})},Jw=e=>e===void 0?null:e,Yw=(e,t)=>e.name===t.name&&e.path===t.path,Xw=(e,t)=>{let n=(e.declined_packages??[]).filter(e=>!Yw(e,t));if(n.length===0){let{declined_packages:t,...n}=e;return n}return{...e,declined_packages:n}},Zw=(e,t)=>`package '${e.name}' at '${e.path}' is already declined on ref '${t}'`,Qw=(e,t)=>`package '${e.name}' at '${e.path}' is not declined on ref '${t}' — nothing to undo`,$w=(e,t)=>`package '${e}' is registered on ref '${t}' — declining applies to packages the configuration does not have; unregister it first with --remove`,eT=(e,t,n)=>{if(Object.hasOwn(e.packages??{},t.name))throw z($w(t.name,n));let r=e.declined_packages??[];if(r.some(e=>Yw(e,t)))throw z(Zw(t,n));return{...e,declined_packages:[...r,t]}},tT=e=>{if(e.declined)return eT(e.entry,e.record,e.key);if(!(e.entry.declined_packages??[]).some(t=>Yw(t,e.record)))throw z(Qw(e.record,e.key));return Xw(e.entry,e.record)},nT=(e,t)=>{let n=V(e.env);return G(n,`home`,async()=>{let e=await B(n),r=Kw(e,t.query),i=jw(e,r),a=_l.safeParse({name:t.packageName,path:t.path});if(!a.success)throw z(S(a.error));let o=a.data,s=tT({declined:t.declined,entry:i,key:r,record:o});return await yu(n,{...e,refs:{...e.refs,[r]:s}}),{declined:t.declined,field:`declined_packages`,key:r,new:t.declined?o:null,old:t.declined?null:o}})},rT=`packages`,iT=()=>Object.keys(vl.shape).toSorted().join(`, `),aT=e=>`unknown package field '${e}' — valid fields: ${iT()}`,oT=e=>Object.hasOwn(vl.shape,e),sT=(e,t,n)=>{if(!oT(t))throw R(aT(t));let r=e[t],i=vl.safeParse({...e,[t]:n});if(!i.success)throw z(S(i.error));return{field:t,newValue:i.data[t],oldValue:r,updated:i.data}},cT=async e=>{let t=Nw(e.entry,e.key,e.packageName),n=sT(t,e.field,e.value),r={...e.entry,packages:{...e.entry.packages,[e.packageName]:n.updated}};return await yu(e.home,{...e.config,refs:{...e.config.refs,[e.key]:r}}),{field:n.field,key:e.key,new:Jw(n.newValue),old:Jw(n.oldValue)}},lT=(e,t)=>`package '${e}' is already registered on ref '${t}' — edit its fields instead`,uT=(e,t)=>{let n=V(e.env);return G(n,`home`,async()=>{let e=await B(n),r=Kw(e,t.query),i=jw(e,r);if(Object.hasOwn(i.packages??{},t.packageName))throw z(lT(t.packageName,r));let a=yl.safeParse({...Xw(i,{name:t.packageName,path:t.path}),packages:{...i.packages,[t.packageName]:{description:t.description,path:t.path}}});if(!a.success)throw z(S(a.error));return await yu(n,{...e,refs:{...e.refs,[r]:a.data}}),{created:!0,field:rT,key:r,new:{description:t.description,name:t.packageName,path:t.path},old:null}})},dT=(e,t)=>`package '${e}' is not registered on ref '${t}' — nothing to remove`,fT=(e,t)=>{let n=V(e.env);return G(n,`home`,async()=>{let e=await B(n),r=Kw(e,t.query),i=jw(e,r),a=i.packages??{};if(!Object.hasOwn(a,t.packageName))throw z(dT(t.packageName,r));let{[t.packageName]:o,...s}=a,c=Object.keys(s).length===0?pT(i):{...i,packages:s};return await yu(n,{...e,refs:{...e.refs,[r]:c}}),{field:rT,key:r,new:null,old:{description:o?.description??``,name:t.packageName,path:o?.path??``},removed:!0}})},pT=e=>{let{packages:t,...n}=e;return n},mT=e=>e.second===void 0&&e.value===void 0,hT=e=>{let{description:t,path:n}=e.create,{packageName:r}=e;if(r===void 0||t===void 0||n===void 0||!mT(e))throw R(`--create registers a new package: it needs --package <name>, --path <path> and --description <text>, and takes no <field> <value> arguments`);return{description:t,packageName:r,path:n}},gT=e=>{let{packageName:t}=e;if(t===void 0||e.create.path!==void 0||!mT(e)||e.create.description!==void 0)throw R(`--remove unregisters a package: it needs --package <name>, and takes no <field> <value> arguments, no --path and no --description`);return{packageName:t}},_T=e=>{let{packageName:t}=e,{path:n}=e.create;if(t===void 0||n===void 0||!mT(e)||e.create.description!==void 0)throw R(`--decline and --undecline record a decision about one package at one path: each needs --package <name> and --path <path>, and takes no <field> <value> arguments and no --description`);return{packageName:t,path:n}},vT=[`create`,`remove`,`decline`,`undecline`],yT=e=>{let t=vT.filter(t=>e[t]===!0);if(t.length>1)throw R(`use one of --create, --remove, --decline or --undecline: they are different answers about the same package, and running two at once would guess which one was meant`);return t[0]},bT=(e,t,n)=>t===`create`?uT(e,{...hT(n),query:n.first}):t===`remove`?fT(e,{...gT(n),query:n.first}):nT(e,{..._T(n),declined:t===`decline`,query:n.first}),xT=`packages`,ST=()=>Object.keys(yl.shape).filter(e=>e!==xT).toSorted().join(`, `),CT=e=>`unknown ref field '${e}' — valid fields: ${ST()}`,wT=e=>Object.hasOwn(yl.shape,e),TT=(e,t,n)=>`failed to rewrite git remote at ${e} to '${W(t)}': ${n.trim()}`,ET=async(e,t)=>{if(Du(t.home,t.dest),!U(t.dest))return;let n=await e.runner.run(`git`,[`remote`,`set-url`,`--`,`origin`,t.cloneUrl],{cwd:t.dest});if(n.exitCode!==0)throw z(TT(t.dest,t.cloneUrl,n.stderr))},DT=async(e,t)=>{let n=Ep(t.value,{allowFileUrls:_b(e.env)});if(n.key!==t.key)throw z(`new url derives a different key — remove and re-add instead`);let r=Su(t.home,t.key);return await ET(e,{cloneUrl:n.cloneUrl,dest:r,home:t.home}),{...t.entry,url:n.cloneUrl}},OT=(e,t,n)=>{if(t===`default_branch`&&!Te(n))throw z(`'${n}' is not a name git accepts for a branch, so refs could not synchronise this ref`);let r={...e,[t]:n},i=yl.safeParse(r);if(!i.success)throw z(S(i.error));return i.data},kT=(e,t)=>t.field===`url`?DT(e,{entry:t.entry,home:t.home,key:t.key,value:t.value}):Promise.resolve(OT(t.entry,t.field,t.value)),AT=async(e,t)=>{let{field:n}=t;if(n===xT)throw R(`use --package <name> <field> <value>`);if(!wT(n))throw R(CT(n));let r=t.entry[n],i=await kT(e,{entry:t.entry,field:n,home:t.home,key:t.key,value:t.value});return{new:i[n],old:r,updated:i}},jT=(e,t)=>{let n=V(e.env),{field:r,opts:i,query:a,value:o}=t;return G(n,`home`,async()=>{let t=await B(n),s=Kw(t,a),c=jw(t,s);if(i.packageName!==void 0)return cT({config:t,entry:c,field:r,home:n,key:s,packageName:i.packageName,value:o});let l=await AT(e,{entry:c,field:r,home:n,key:s,value:o});return await yu(n,{...t,refs:{...t.refs,[s]:l.updated}}),{field:r,key:s,new:Jw(l.new),old:Jw(l.old)}})},MT=`settings`,NT=[],PT=()=>Object.keys(hl.shape).toSorted().join(`, `),FT=e=>`unknown setting '${e}' — valid settings: ${PT()}`,IT=e=>Object.hasOwn(hl.shape,e),LT=e=>`note: 'settings' addressed the global settings, not ${e} — use the full ref key to edit that ref`,RT=e=>{try{let t=Kw(e,MT);return[LT(`ref '${t}'`)]}catch(e){if(e instanceof I&&e.code===`usage`)return[LT("one of several matching refs — see `refs list`")];if(e instanceof I&&e.code===`not_found`)return NT;throw e}},zT=e=>({data:{field:e.key,key:MT,new:Jw(e.parsed[e.key]),old:Jw(e.old)},warnings:RT(e.config)}),BT=(e,t)=>{let n=V(e.env);return G(n,`home`,async()=>{let e=await B(n);if(!IT(t.key))throw R(FT(t.key));let r=e.settings[t.key],i={...e.settings,[t.key]:t.value},a=hl.safeParse(i);if(!a.success)throw z(S(a.error));return await yu(n,{...e,settings:a.data}),zT({config:e,key:t.key,old:r,parsed:a.data})})},VT=[],HT=e=>{let t={};return e.package!==void 0&&(t.packageName=e.package),t},UT=e=>{if(e.second===void 0||e.value===void 0)throw R(`missing <field> and <value> — see 'refs edit --help'`);return{field:e.second,value:e.value}},WT=(e,t,n)=>{if(t.opts.packageName!==void 0)throw R(`--package is not valid with 'refs edit settings ...' — it only applies to ref/package edits`);return BT(e,n)},GT=async(e,t)=>{if(t.create.description!==void 0||t.create.path!==void 0)throw R(`--path and --description only apply to the package modes — to change one field of a registered package use: refs edit <ref> <field> <value> --package <name>`);let{field:n,value:r}=UT(t);return t.first===`settings`?WT(e,t,{key:n,value:r}):{data:await jT(e,{field:n,opts:t.opts,query:t.first,value:r}),warnings:VT}},KT=async(e,t)=>{let n=yT(t.create);return n===void 0?GT(e,t):{data:await bT(e,n,{create:t.create,first:t.first,packageName:t.opts.packageName,second:t.second,value:t.value}),warnings:VT}},qT=e=>e==null?`(unset)`:String(e),JT=(e,t)=>{let n=t?e.new:e.old,r=t?`declined`:`no longer declining`;return`${e.key}: ${r} '${n.name}' at ${n.path}`},YT=e=>{if(e.created===!0){let t=e.new;return`${e.key}: registered '${t.name}' at ${t.path}`}if(e.removed===!0){let t=e.old;return`${e.key}: unregistered '${t.name}' (was at ${t.path})`}return e.declined===void 0?void 0:JT(e,e.declined)},XT=e=>{let t=YT(e);return t===void 0?[`${e.key}: ${e.field} '${qT(e.old)}' -> '${qT(e.new)}'`]:[t]},ZT=(e,t)=>{e.command(`edit`).description(`Edit one field: 'refs edit settings <key> <value>' for a global setting, or 'refs edit <ref> <field> <value> [--package <name>]' for a ref or package field. With --create, registers a package the config does not have yet; with --remove, unregisters one it has; with --decline, records that a package the checkout declares is deliberately not registered, so drift stops reporting it.`).argument(`<ref-or-settings>`,`a ref key/unique suffix, or the literal 'settings'`).argument(`[field-or-key]`,`field to edit (or, in settings mode, the setting key)`).argument(`[value]`,`the new value`).option(`--package <name>`,`edit this package's field instead of a top-level ref field`).option(`--create`,`register --package as a new package on this ref`).option(`--remove`,`unregister --package from this ref, leaving the checkout alone`).option(`--decline`,`record that --package at --path is deliberately not registered`).option(`--undecline`,`withdraw a decline, so the package is reported again`).option(`--path <path>`,`with --create/--decline/--undecline: the package path, relative to the checkout root`).option(`--description <text>`,`with --create: what the package is`).action((e,n,r,i,a)=>{let o=X(a);return Q(t,o,async()=>{let{data:a,warnings:s}=await KT(t,{create:i,first:e,opts:HT(i),second:n,value:r});Z(t,o,XT(a),a,s)})()})},QT=`Install the agent skill: npx skills add kaisers-io/refs (from a local clone: npx skills add <path-to-this-repo> --skill refs)`,$T={migrated:`migrated`,noop:`unchanged`,seeded:`seeded`},eE=async e=>{await a(e,{mode:448,recursive:!0}),(await i(e)).isSymbolicLink()||await t(e,448)},tE=async e=>{try{await t(e,384)}catch(e){if(!F(e))throw e}},nE=async e=>{for(let t of[e.root,e.sourcesDir,e.locksDir,e.hooksDir])await eE(t);await Promise.all([tE(e.configPath),tE(e.statePath)])},rE=async e=>{let t=V(e.env);return await nE(t),{config:await G(t,`home`,async()=>{let e=await Fu(t,gy);return await kf(t),e}),home:t.root,skill_hint:QT}},iE=(e,t)=>{e.command(`init`).description(`Seed or migrate the refs home directory, its config, and the git hooks guard.`).action((e,n)=>{let r=X(n);return Q(t,r,async()=>{let e=await rE(t);Z(t,r,[`home: ${e.home}`,`config: ${$T[e.config]}`,``,QT],e)})()})},aE=async e=>{let t=V(e.env),n=await G(t,`home`,()=>Fu(t,gy));return n===`migrated`?{backup:Cu(t),result:n}:{backup:null,result:n}},oE=e=>e.result===`migrated`&&e.backup!==null?`config migrated (backup: ${se(e.backup)})`:e.result===`seeded`?`config seeded`:`config up to date`,sE=(e,t)=>{e.command(`migrate`).description(`Migrate the refs config to the current schema, seeding it if absent.`).action((e,n)=>{let r=X(n);return Q(t,r,async()=>{let e=await aE(t);Z(t,r,oE(e),e)})()})},cE=async e=>{try{return await i(e),!0}catch(e){if(F(e))return!1;throw e}},lE=async e=>{try{return await c(e)}catch(e){if(F(e))return;throw e}},uE=async e=>{try{return(await i(e)).isDirectory()}catch(e){if(F(e))return;throw e}},dE=async e=>{let t=await lE(e);if(t===void 0)return!0;if(t.length>0)return!1;try{await f(e)}catch(e){if(!F(e))throw e}return!0},fE=async e=>{let t=await uE(e);return t===void 0?!0:t?dE(e):!1},pE=async(e,t)=>{t!==e.sourcesDir&&await fE(t)&&await pE(e,m(t))},mE=async(e,t)=>await cE(t)?(Du(e,t),await d(t,{force:!0,recursive:!0}),await pE(e,m(t)),{removedCheckout:!0}):{removedCheckout:!1,warning:`checkout was already missing`},hE=(e,t)=>Object.fromEntries(Object.entries(e).filter(([e])=>e!==t)),gE=async(e,t)=>{let n=await B(e),r={...n,refs:hE(n.refs,t)};await yu(e,r);let i=await P_(e),a={...i,refs:hE(i.refs,t)};await F_(e,a)},_E=async(e,t)=>{let n=V(e.env),r=await B(n),i=Kw(r,t),a=Su(n,i),{removedCheckout:o,warning:s}=await G(n,gb(i),()=>mE(n,a));return await G(n,`home`,()=>gE(n,i)),{data:{key:i,removed_checkout:o},warnings:By(s)}},vE=e=>e.removed_checkout?[`removed ${e.key} (checkout deleted)`]:[`removed ${e.key} (checkout was already missing)`],yE=(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. zod`).action((e,n,r)=>{let i=X(r);return Q(t,i,async()=>{let{data:n,warnings:r}=await _E(t,e);Z(t,i,vE(n),n,r)})()})},bE=async e=>{let t=await d_(e.checkoutDir,e.configuredPath,e.packageName);return t.kind===`match`?{path:e.configuredPath,status:`verified`}:t.kind===`unreadable`?{path:e.configuredPath,reason:t.reason,status:`unverifiable`}:xE(e)},xE=async e=>YS(e,await ny(e.checkoutDir)),SE=async e=>{try{return await G(e.home,gb(e.key),()=>bE(e),e.lockTimeoutMs===void 0?void 0:{timeoutMs:e.lockTimeoutMs})}catch(t){if(t instanceof I&&t.code===`conflict`)return{path:e.configuredPath,reason:`could not acquire the ref lock in time`,status:`unverifiable`};throw t}},CE=async e=>{if(!U(e.checkoutDir))return{path:e.configuredPath,status:`unmaterialized`};let t=await d_(e.checkoutDir,e.configuredPath,e.packageName);return t.kind===`match`?{path:e.configuredPath,status:`verified`}:t.kind===`unreadable`?{path:e.configuredPath,reason:t.reason,status:`unverifiable`}:(e.onProbed?.(),SE(e))},wE=(e,t)=>({local_path:null,name:e,path:null,reason:t,status:`unverifiable`}),TE=async e=>{if(!e.checkoutManaged)return wE(e.packageName,e.checkoutReason);let t=await CE(e),n=(t.status===`verified`||t.status===`relocated`)&&t.path!==null?await T_(h(e.checkoutDir,t.path),e.packageName):void 0;return{...t.candidates===void 0?{}:{candidates:t.candidates},...t.configuredPath===void 0?{}:{configured_path:t.configuredPath},...n===void 0?{}:{entry_points:n},local_path:t.path===null?null:h(e.checkoutDir,t.path),name:e.packageName,path:t.path,...t.reason===void 0?{}:{reason:t.reason},status:t.status}},EE=e=>e.kind===`target`?[{observed:e.observed,target:e.target}]:e.kind===`alternatives`?e.alternatives.flatMap(e=>EE(e)):e.kind===`conditions`?e.branches.flatMap(e=>EE(e.value)):[],DE=e=>{if(e.length===0)return[];let t=e.filter(e=>e.observed===`not_checked`||e.observed===`unverifiable`).length,n=e.length-t,r=t===0?``:`, ${t} not inspected`;return n===0?[`entry points: none of the ${e.length} declared target(s) was inspected`]:[`entry points: ${n} declared target(s) absent here${r}`]},OE=e=>{if(e.status!==`complete`)return[`entry points: could not be read (${e.reason??`unknown`})`];let t=e.entries.flatMap(e=>EE(e.value)),n=t.filter(e=>e.observed===`file`||e.observed===`directory`);if(n.length===0)return DE(t);let r=n.slice(0,3).map(e=>e.target),i=n.length-r.length;return[`entry points present: ${r.join(`, `)}${i===0?``:` (+${i} more)`}`]},kE=e=>[`package: ${e.name}`,`package path: ${e.local_path??`(unknown)`}`,...e.status===`verified`?[]:[`package status: ${e.status}`],...e.configured_path===void 0?[]:[`configured path: ${e.configured_path}`],...e.candidates===void 0?[]:[`candidates: ${e.candidates.join(`, `)}`],...e.reason===void 0?[]:[`reason: ${e.reason}`],...e.entry_points===void 0?[]:OE(e.entry_points)],AE=`node_modules`,jE=[`.pnp.cjs`,`.pnp.js`],ME=e=>!ce(e)&&e.split(`/`).every(e=>tl(e)),NE=function*(e){let t=fe(e);for(;;){se(t)!==AE&&(yield h(t,AE));let e=m(t);if(e===t)return;t=e}},PE=async e=>{if(await LE(e)!==`absent`)try{let t=JSON.parse(await s(e,`utf8`)),{name:n,version:r}=typeof t==`object`&&t?t:{};return typeof r!=`string`||r===``?{package_json:e,reason:`manifest_has_no_version`,status:`unverifiable`}:{...typeof n==`string`?{name:n}:{},package_json:e,status:`found`,version:r}}catch{return{package_json:e,reason:`manifest_unreadable`,status:`unverifiable`}}},FE=new Set([`ENOENT`,`ENOTDIR`]),IE=async e=>{try{return(await c(e)).length===0}catch{return!1}},LE=async e=>{try{return await p(e),`present`}catch(e){let t=typeof e==`object`&&e&&`code`in e&&typeof e.code==`string`?e.code:void 0;return t!==void 0&&FE.has(t)?`absent`:`unreadable`}},RE=async e=>{for(let t of NE(e)){let e=m(t);if((await Promise.all(jE.map(t=>LE(h(e,t))))).includes(`present`))return!0}return!1},zE=async e=>{try{return await p(e)}catch(t){if(F(t))return;throw R(`--project could not be read: ${e} (${ru(t)??`unknown`})`)}},BE=async e=>{let t=await zE(e);if(t===void 0)throw R(`--project path does not exist: ${e}`);if(!t.isDirectory())throw R(`--project must be a directory: ${e}`)},VE=async e=>{let t=await LE(e);if(t===`unreadable`)return{reason:`slot_unreadable`,status:`unverifiable`};if(t===`absent`)return;let n=await PE(h(e,`package.json`));return n===void 0?await IE(e)?void 0:{reason:`installed_without_manifest`,status:`unverifiable`}:n},HE=async(e,t)=>{if(!ME(t))return{reason:`unsupported_package_name`,status:`unverifiable`};for(let n of NE(e)){let e=await VE(h(n,...t.split(`/`)));if(e!==void 0)return e}return await RE(e)?{reason:`yarn_pnp`,status:`unsupported_layout`}:{status:`not_materialized`}},UE={'"':`"`,"\\":`\\`,b:`\b`,n:`
|
|
352
|
-
|
|
488
|
+
packages to describe: ${r}`)},bb=e=>{if(Object.keys(e).length!==0)return e},xb=e=>{let t={default_branch:e.default_branch,description:e.description,url:e.url};return e.packages!==void 0&&(t.packages=e.packages),e.tag_format!==void 0&&(t.tag_format=e.tag_format),t},Sb=`ref.`,Cb=`${Sb}_`,wb=`${Cb}_`,Tb=e=>`${wb}${me(`sha256`).update(e,`utf8`).digest(`hex`)}`,Eb=e=>{let t=e.includes(`_`)?`${Cb}${e.replaceAll(`_`,`_u`).replaceAll(`/`,`_s`)}`:`${Sb}${e.replaceAll(`/`,`_`)}`;return Buffer.byteLength(t,`utf8`)<=212&&ih(t)?t:Tb(e)},Db=e=>e.REFS_ALLOW_FILE_URLS===`1`,Ob=(e,t)=>{let n=Fp(t,{allowFileUrls:Db(e.env)});return{cloneUrl:n.cloneUrl,key:n.key}},kb=async(e,t)=>{if(t===``)throw R(`refs add npm: requires a package name, e.g. npm:left-pad`);$y(e,`resolving npm package '${t}'…`);let n=await Sh(e.fetcher,t),r={cloneUrl:n.cloneUrl,key:n.key,npmPkgName:t};return n.directory!==void 0&&(r.npmDirectory=n.directory),r},Ab=(e,t)=>t.startsWith(`npm:`)?kb(e,t.slice(4)):Promise.resolve(Ob(e,t)),jb=(e,t)=>{if(e.npmPkgName===void 0)return e;let n=V_(`git_transport`,void 0,t);return{...e,cloneUrl:Kp(e.cloneUrl,n)}},Mb=e=>`ref '${e}' already exists — use refs edit or refs remove`,Nb=(e,t)=>{if(e.refs[t]!==void 0)throw hu(Mb(t))},Pb=async e=>{try{return await c(e,{withFileTypes:!0})}catch(e){if(I(e))return;throw e}},Fb=e=>e.filter(e=>e.isDirectory()).map(e=>e.name),Ib=async(e,t)=>{let n=await Pb(e);if(n===void 0)return{kind:`stop`};let r=Fb(n);if(r.includes(t))return{kind:`continue`,nextDir:h(e,t)};let i=r.find(e=>e.toLowerCase()===t.toLowerCase());return i===void 0?{kind:`stop`}:{kind:`collision`,name:i}},Lb=async(e,t,n)=>{let[r,...i]=t;if(r===void 0)return;let a=await Ib(e,r);if(a.kind!==`stop`)return a.kind===`collision`?[...n,a.name].join(`/`):Lb(a.nextDir,i,[...n,r])},Rb=[],zb=async(e,t)=>{let n=await Lb(e.sourcesDir,t.split(`/`),Rb);if(n!==void 0)throw hu(`checkout path for '${t}' collides case-insensitively with existing '${n}'`)},Bb=(e,t,n)=>{let r=n.scan.versions[e];return r===void 0?null:cp(n.tags,r,t)},Vb=e=>{let t=e.scan.packages.find(e=>e.path===`.`);if(t===void 0)return e.counted;let n=Bb(`.`,t.name,{scan:e.scan,tags:e.tags});return n===null||rp(n,t.name)?e.counted:n},Hb=e=>e.format===null||e.format===e.refFormat||!rp(e.format,e.name)?e.entry:{...e.entry,tag_format:e.format},Ub=e=>{let t={scan:e.scan,tags:e.tags};return Object.fromEntries(Object.entries(e.packages).map(([n,r])=>[n,Hb({entry:r,format:Bb(r.path,n,t),name:n,refFormat:e.refFormat})]))},Wb=e=>{switch(e.kind){case`candidate_not_inspected`:case`manifest_missing_name`:case`manifest_unreadable`:case`workspace_dir_unreadable`:return e.path;case`workspace_declaration_unparsed`:case`workspace_file_unreadable`:return e.file;case`unsupported_pattern`:return e.pattern;case`scan_budget_exhausted`:return`${e.pattern} at ${e.path}`;case`no_workspace_declaration`:return}},Gb=e=>e.diagnostics.filter(e=>!m_({diagnostics:[e],packages:[],versions:{}})).map(e=>{let t=Wb(e);return t===void 0?e.kind:`${t}: ${e.kind}`}).toSorted().join(`, `),Kb=(e,t,n)=>`checkout at ${e} points at '${W(t)}' — expected '${W(n)}'; remove the checkout directory or run refs remove before retrying`,qb=e=>e.exitCode===0?e.stdout.trim():`(no origin remote)`,Jb=(e,t)=>{try{return Fp(e,{allowFileUrls:t}).key}catch{return}},Yb=async(e,t)=>{let n=await e.run(`git`,[`remote`,`get-url`,`origin`],{cwd:t.dest}),r=qb(n),i=Jb(t.expectedUrl,t.allowFileUrls),a=Jb(r,t.allowFileUrls);if(i===void 0||a!==i)throw hu(Kb(t.dest,r,t.expectedUrl))},Xb=e=>{let t=sb(e);return`checkout at ${e} exists but is not refs-managed — remove it ${t===void 0?`by hand`:`(${t})`} and retry`},Zb=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 hu(Xb(t.dest))},Qb=async(e,t)=>{await a(m(t.dest),{recursive:!0}),$y(e,`cloning ${W(t.cloneUrl)} into ${t.dest}…`);let n=await Df(e.runner,t);return n.warning===void 0?{effectiveMode:n.effectiveMode}:{effectiveMode:n.effectiveMode,warning:n.warning}},$b=async(e,t)=>(Iu(t.home,t.dest),U(t.dest)?(await Yb(e.runner,{allowFileUrls:t.allowFileUrls,dest:t.dest,expectedUrl:t.cloneUrl}),await Zb(e.runner,{dest:t.dest,hooksDir:t.hooksDir}),{}):Qb(e,t)),ex=(e,t)=>`checkout for '${e}' at ${t} is missing or corrupt (git rev-parse HEAD failed) — run: refs remove ${rb(e)}, then refs add <source> --dry-run again`,tx=(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`,nx=async(e,t)=>{await Yb(e,t),await Zb(e,{dest:t.dest,hooksDir:t.hooksDir});let n=await e.run(`git`,[`rev-parse`,`HEAD`],{cwd:t.dest});if(n.exitCode!==0)throw z(ex(t.key,t.dest));let r=n.stdout.trim();if(!z_.shape.head_sha.safeParse(r).success)throw z(tx(t.key,t.dest,r));return r},rx=e=>m_(e)?void 0:`workspace detection could not fully inspect the declared workspaces (${Gb(e)}) — members may be missing from the detected packages; the repository's own workspace declaration is what settles it`,ix=(e,t)=>{let n=pb(e.packages,t.resolved.npmDirectory,t.resolved.npmPkgName),r=Vb({counted:t.countedTagFormat,scan:e,tags:t.tags}),i=Ub({packages:n,refFormat:r,scan:e,tags:t.tags}),a=gb(e.packages,i),o=rx(e);return{defaultBranch:t.defaultBranch,...o===void 0?{}:{detectionWarning:o},packages:i,...a===void 0?{}:{rootPackageName:a},tagFormatCandidate:r}},ax=e=>e.complete?Yf(e.tags):null,ox=async(e,t,n)=>{let r=await kf(e.runner,t),i=await zf(e.runner,t),a=ax(i);$y(e,`detecting workspace packages…`);let o=await fy(t),s=i.complete?i.tags:[];return ix(o,{countedTagFormat:a,defaultBranch:r,resolved:n,tags:s})},sx=(e,t)=>G(t.home,Eb(t.resolved.key),async()=>{let n=await $b(e,{allowFileUrls:Db(e.env),cloneUrl:t.resolved.cloneUrl,dest:t.dest,home:t.home,hooksDir:t.home.hooksDir,mode:t.cloneMode}),r={fields:await ox(e,t.dest,t.resolved)};return n.effectiveMode!==void 0&&(r.effectiveMode=n.effectiveMode),n.warning!==void 0&&(r.warning=n.warning),r}),cx=(e,t)=>{if(!Te(e.defaultBranch))throw z(`this repository's HEAD names a branch git will not accept: ${JSON.stringify(e.defaultBranch)}. refs cannot synchronise a ref with that default branch — the name comes from the repository, so there is nothing to correct in this command.`);return{default_branch:e.defaultBranch,description:``,key:t.key,packages:e.packages,tag_format_candidate:e.tagFormatCandidate,url:t.cloneUrl}},lx=e=>{let{effectiveMode:t,fields:n,warning:r}=e.cloneResult;return{dest:e.dest,proposal:cx(n,e.resolved),...n.detectionWarning===void 0?{}:{detectionWarning:n.detectionWarning},...n.rootPackageName===void 0?{}:{rootPackageName:n.rootPackageName},...t===void 0?{}:{effectiveCloneMode:t},...r===void 0?{}:{warning:r}}},ux=async(e,t)=>{let n=V(e.env),r=await B(n),i=jb(await Ab(e,t),r.settings);Nb(r,i.key),await zb(n,i.key);let a=ju(n,i.key),o=V_(`clone_mode`,void 0,r.settings),s=await sx(e,{cloneMode:o,dest:a,home:n,resolved:i});return lx({cloneResult:s,dest:a,resolved:i})},dx=(e,t,n)=>G(e,`home`,async()=>{let r=await B(e);Nb(r,t);let i=await W_(e),a=i.refs[t],o=n??a?.effective_clone_mode,s={...a,pending_proposal_at:(/* @__PURE__ */ new Date()).toISOString()};o!==void 0&&(s.effective_clone_mode=o),i.refs[t]=s,await G_(e,i)}),fx=(e,t)=>{let n=kl.safeParse(e);if(!n.success)throw z(S(n.error));let r=B_.safeParse(t);if(!r.success)throw z(S(r.error));return{config:n.data,state:r.data}},px=async(e,t)=>{let n=await B(e.home);Nb(n,e.ref.key);let r=xb(e.ref);n.refs[e.ref.key]=r;let i=await W_(e.home);return i.refs[e.ref.key]={effective_clone_mode:e.effectiveCloneMode??i.refs[e.ref.key]?.effective_clone_mode??V_(`clone_mode`,void 0,n.settings),head_sha:t,last_fetched_at:(/* @__PURE__ */ new Date()).toISOString()},{...fx(n,i),entry:r}},mx=async(e,t)=>{let n=Db(e.env),r=await G(t.home,Eb(t.ref.key),()=>(Iu(t.home,t.dest),nx(e.runner,{allowFileUrls:n,dest:t.dest,expectedUrl:t.ref.url,hooksDir:t.home.hooksDir,key:t.ref.key})));return G(t.home,`home`,async()=>{let{config:e,entry:n,state:i}=await px(t,r);return await G_(t.home,i),await Ou(t.home,e),{entry:n,key:t.ref.key}})},hx=(e,t)=>t===`-`?e.readStdin():s(t,`utf8`),gx=e=>{try{return JSON.parse(e)}catch{throw z(`invalid JSON in proposal: the document could not be parsed`)}},_x=e=>typeof e==`object`&&!!e&&!Array.isArray(e),vx=e=>_x(e)&&`ok`in e&&!(`key`in e),yx=e=>{if(!vx(e))return e;if(e.ok===!1)throw z(`proposal file contains a failed refs envelope (ok is false) — re-run the dry-run`);if(_x(e.data))return e.data;throw z(`proposal file is a refs envelope without a usable data object — re-run the dry-run`)},bx=e=>e.code===`unrecognized_keys`,xx=e=>e.path.length===0,Sx=(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}`},Cx=e=>{let t=/* @__PURE__ */ new Map;for(let n of e){let e=Xt(n.path);t.set(e,[...t.get(e)??[],...n.keys])}return[...t.entries()].toSorted(([e],[t])=>e.localeCompare(t)).map(([e,t])=>Sx(e,t))},wx=e=>`✖ invalid proposal: ${e.message}`,Tx=e=>{let t=e.issues.filter(e=>bx(e)),n=e.issues.filter(e=>!bx(e)),r=n.filter(e=>xx(e));if(t.length===0&&r.length===0)return S(e);let i=n.filter(e=>!xx(e)),a=[...Cx(t),...r.map(e=>wx(e))];return i.length>0&&a.push(S({issues:i})),a.join(`
|
|
489
|
+
`)},Ex=e=>{let t=R_.safeParse(e);if(!t.success)throw z(Tx(t.error));return t.data},Dx=async(e,t)=>{let n=await hx(e,t);return Ex(yx(gx(n)))},Ox=(e,t)=>[`refs add: dry-run proposal ready for '${e}' (checkout: ${t})`,`next: review the proposal, then run refs add --proposal <file> to finalize`],kx=e=>[...Xy(e.warning),...Xy(e.detectionWarning)],Ax=async(e,t)=>{let n=await ux(e,t),r=V(e.env);await dx(r,n.proposal.key,n.effectiveCloneMode);let i=kx(n);return{data:n.proposal,human:Ox(n.proposal.key,n.dest),warnings:i}},jx=e=>[`refs add: '${e}' added to config`],Mx=e=>{let t={default_branch:e.default_branch,description:e.description,key:e.key,url:e.url};e.tag_format_candidate!==null&&(t.tag_format=e.tag_format_candidate);let n=bb(e.packages);return n!==void 0&&(t.packages=n),t},Nx=async(e,t)=>{let n=await Dx(e,t),r=V(e.env),i=ju(r,n.key);if(!U(i))throw gu(`no checkout found at ${i} — run: refs add <source> --dry-run first`);let a=Mx(n),{entry:o,key:s}=await mx(e,{dest:i,home:r,ref:a});return{data:{entry:o,key:s},human:jx(s),warnings:[]}},Px=(e,t,n)=>{yb(e.proposal.packages,n,e.rootPackageName);let r={default_branch:e.proposal.default_branch,description:t,key:e.proposal.key,url:e.proposal.url};e.proposal.tag_format_candidate!==null&&(r.tag_format=e.proposal.tag_format_candidate);let i=hb(e.proposal.packages,{refDescription:t,...e.rootPackageName===void 0?{}:{rootPackageName:e.rootPackageName}});return i!==void 0&&(r.packages=i),r},Fx=async(e,t,n)=>{let r=await ux(e,t),i=V(e.env);await dx(i,r.proposal.key,r.effectiveCloneMode);let a=Px(r,n,t),o={dest:r.dest,home:i,ref:a};r.effectiveCloneMode!==void 0&&(o.effectiveCloneMode=r.effectiveCloneMode);let{entry:s,key:c}=await mx(e,o);return{data:{entry:s,key:c},human:jx(c),warnings:kx(r)}},Ix=e=>{let t=[e.dryRun,e.proposal!==void 0,e.description!==void 0].filter(Boolean).length;if(t>1)throw R(`refs add: use only one of --dry-run, --proposal, or --description`);if(t===0)throw R(`refs add needs --dry-run, --proposal, or --description`)},Lx=e=>{if(e===void 0||e===``)throw R(`refs add requires <source> (a git url or npm:<package>)`);return e},Rx=(e,t)=>(Ix(t),t.proposal===void 0?t.description===void 0?Ax(e,Lx(t.source)):Fx(e,Lx(t.source),t.description):Nx(e,t.proposal)),zx=(e,t)=>{let n={dryRun:t.dryRun===!0};return e!==void 0&&(n.source=e),t.proposal!==void 0&&(n.proposal=t.proposal),t.description!==void 0&&(n.description=t.description),n},Bx=(e,t)=>{e.command(`add`).description(`Add a git reference in two phases: propose (--dry-run), then finalize (--proposal).`).argument(`[source]`,`git url or npm:<package> (omit when finalizing with --proposal)`).option(`--dry-run`,`resolve and clone the source, writing a reviewable proposal`).option(`--proposal <file>`,`finalize from a completed proposal JSON file (- for stdin)`).option(`--description <text>`,`one-shot: dry-run then finalize immediately with this description`).action((e,n,r)=>{let i=X(r);return Q(t,i,async()=>{let r=await Rx(t,zx(e,n));Z(t,i,r.human,r.data,r.warnings)})()})},Vx=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`}},Hx=/^v(?<major>\d+)\.(?<minor>\d+)/u,Ux=e=>{let t=Hx.exec(e),n=t?.groups?.major,r=t?.groups?.minor;if(n!==void 0&&r!==void 0)return{major:Number(n),minor:Number(r)}},Wx=e=>e===void 0?!1:e.major>24||e.major===24&&e.minor>=2,Gx=e=>{let{nodeVersion:t}=e;return Wx(Ux(t))?{detail:t,name:`node`,status:`ok`}:{detail:`${t} does not satisfy the required range >=24.2`,name:`node`,status:`fail`}},Kx=()=>kl.parse({meta:{cli_version:`0.0.0`,schema_version:1},refs:{},settings:{}}),qx=async e=>{try{return{config:await B(e)}}catch(e){return{config:Kx(),errorMessage:Zy(e)}}},Jx=e=>e===void 0?{detail:`config is present and matches the current schema`,name:`config`,status:`ok`}:{detail:e,name:`config`,status:`fail`},Yx={ci:`update check is off in CI — set REFS_UPDATE_CHECK=1 to run it here anyway`,config:`update check is off ([updates].check = false in config.toml)`,env:`update check is off (REFS_UPDATE_CHECK=0)`},Xx=(e,t,n)=>{if(rv(e,t)){let r=n?` (npm was unreachable just now; this was its last answer)`:``;return{detail:`${iv(e,t)}${r}`,name:`cli-update`,status:`warn`}}return n?{detail:`could not reach npm to check; its last answer was ${t}, which this CLI (${e}) already has`,name:`cli-update`,status:`warn`}:{detail:`this CLI (${e}) is npm's latest published release`,name:`cli-update`,status:`ok`}},Zx=async(e,t)=>{let n=cv({env:e.env,updates:t.updates});if(n!==`on`)return{detail:Yx[n],name:`cli-update`,status:`ok`};let{latest:r,stale:i}=await nv({fetch:e.fetcher,home:V(e.env),nowMs:Date.now()});return r===void 0?{detail:`could not reach npm to learn the latest published version — not a fault of your setup, and nothing else depends on it`,name:`cli-update`,status:`warn`}:Xx(e.cliVersion,r,i)},Qx=(e,t)=>Object.keys(t.refs).map(e=>cl.parse(e)).map(t=>({dest:ju(e,t),key:t})).filter(e=>U(e.dest)),$x=[`pre-commit`,`pre-push`],eS=async(t,r)=>{try{return await e(h(t.hooksDir,r),n.X_OK),!0}catch{return!1}},tS=async e=>{let t=await Promise.all($x.map(t=>eS(e,t)));return $x.filter((e,n)=>!t[n])},nS=async e=>{try{return(await c(e.hooksDir)).filter(e=>!$x.includes(e)).toSorted()}catch(e){if(I(e))return[];throw e}},rS=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},iS=(e,t)=>`${t.map(e=>`hooks/${e}`).join(`, `)}: not installed by refs — this is the directory git resolves hook names against for every managed checkout, so nothing whose provenance refs cannot account for belongs in it; remove: ${sb(t.map(t=>h(e,t)))}`,aS=e=>{let t=[];return e.unexpected.length>0&&t.push(iS(e.hooksDir,e.unexpected)),e.missingHooks.length>0&&t.push(`${e.missingHooks.map(e=>`hooks/${e}`).join(`, `)} missing or not executable — run: refs init`),e.badKeys.length>0&&t.push(`core.hooksPath not set for: ${e.badKeys.join(`, `)} — run: refs init`),t},oS=e=>{let t=aS(e);return t.length>0?{detail:t.join(`; `),name:`hooks-guard`,status:`fail`}:{detail:`${$x.map(e=>`hooks/${e}`).join(`, `)} present; ${e.checkoutCount} checkout(s) guarded`,name:`hooks-guard`,status:`ok`}},sS=async(e,t,n)=>{let r=Qx(t,n),[i,a,o]=await Promise.all([tS(t),nS(t),Promise.all(r.map(n=>rS(e,t,n.dest)))]),s=r.filter((e,t)=>!o[t]).map(e=>e.key);return oS({badKeys:s,checkoutCount:r.length,hooksDir:t.hooksDir,missingHooks:i,unexpected:a})},cS=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}},lS=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`}},uS=async(e,t,n)=>{let r=Qx(t,n),i=await Promise.all(r.map(t=>cS(e,t)));return lS(i)},dS=async e=>{try{return await W_(e)}catch{return B_.parse({})}},fS=async e=>{try{return(await c(e,{withFileTypes:!0})).filter(e=>e.isDirectory()).map(e=>e.name)}catch(e){if(I(e))return[];throw e}},pS=async(e,t)=>{if(U(e))return[[...t]];let n=await fS(e);return(await Promise.all(n.map(n=>pS(h(e,n),[...t,n])))).flat()},mS=(e,t,n)=>{let r=e.refs[t]?.pending_proposal_at;return r!==void 0&&n-Date.parse(r)<864e5},hS=(e,t,n)=>{if(mS(t,e.key,n))return`${e.key}: pending add`;let r=sb(e.dest);return r===void 0?`${e.key}: orphan — its path cannot be put into a pasteable command; remove it by hand`:`${e.key}: orphan — remove with: ${r}`},gS=(e,t)=>({dest:h(e.sourcesDir,...t),key:t.join(`/`)}),_S=async(e,t,n)=>{let r=(await pS(e.sourcesDir,[])).map(t=>gS(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=>hS(e,n,i)).join(`; `),name:`orphans`,status:`warn`}},vS=e=>{let t=(e??``).lastIndexOf(`/`);return t===-1?`.`:(e??``).slice(0,t)},yS=e=>{let[t=`.`,...n]=e,r=t.split(`/`),i=r.length;for(let e of n){let t=e.split(`/`),n=0;for(;n<i&&n<t.length&&r[n]===t[n];)n+=1;i=n}return i===0?`.`:r.slice(0,i).join(`/`)},bS=e=>Cl.safeParse({name:e.name,path:e.path}).success,xS=(e,t,n)=>ob([[`--package`,e.name],`--decline`,[`--path`,n]],[t]),SS=(e,t,n)=>ob([[`--package`,e.name],`--create`,[`--path`,n],[`--description`,`<what it is>`]],[t]),CS=(e,t)=>{let{path:n}=e;if(n===void 0||!bS(e))return{};let r=xS(e,t,n),i=yl(e.name)?SS(e,t,n):void 0;return r===void 0?{}:i===void 0?{decline:r}:{decline:r,register:i}},wS=(e,t)=>{let n=ml.safeParse(e.path);if(!n.success)return{};let r=ob([[`--package`,e.name]],[t,`path`,n.data]);return r===void 0?{}:{repoint:r}},TS=(e,t)=>{let n=ob([[`--package`,e.name],`--remove`],[t]);return n===void 0?{}:{unregister:n}},ES=(e,t)=>e.status===`unregistered`?CS(e,t):e.status===`relocated`?wS(e,t):e.status===`missing`?TS(e,t):{},DS=`(unknown)`,OS=`no single-line command can carry these values, so none is offered — 'refs doctor --json' has them exactly`,kS=(e,t)=>{let{decline:n,register:r}=CS(e,t);if(n!==void 0)return r===void 0?`Its name is one the packages table cannot hold, so it cannot be registered — if that is the answer, record it: ${n}`:`To register it (replace the description first): ${r}. If it should not be: ${n}`},AS=(e,t)=>{let n=`${e.name}: declared in this checkout but not registered — it cannot be resolved by name until it is`,{path:r}=e;if(r===void 0)return`${n}. Declared at several paths (${(e.candidates??[]).join(`, `)}) — pick one`;if(!bS(e))return`${n}. Its name or path is one the configuration cannot hold, so there is no command for it — report it and leave it unregistered`;let i=kS(e,t);return i===void 0?`${n}. ${OS} — report it and leave it unregistered`:`${n}. ${i}`},jS=(e,t,n)=>{let r=`${e.name}: moved to ${e.path??DS} — update the entry's path (${n})`,{repoint:i}=ES(e,t);return i===void 0?r:`${r}. To fix it: ${i}`},MS=(e,t,n)=>{let r=`${e.name}: gone from this repo's workspaces (${n}) — repoint the entry if it moved out of them`,{unregister:i}=ES(e,t);return i===void 0?`${r}; ${OS}, so unregister it by hand`:`${r}, or unregister it: ${i}`},NS=(e,t)=>{let n=`configured: ${e.configured_path??DS}`;if(e.status===`relocated`)return jS(e,t,n);if(e.status===`missing`)return MS(e,t,n);if(e.status===`ambiguous`){let t=(e.candidates??[]).join(`, `);return`${e.name}: declared at several paths (${t}) — point the entry at one (${n})`}return`${e.name}: could not be checked — ${e.reason??`(no reason given)`} (${n})`},PS=(e,t)=>e.status===`unregistered`?AS(e,t):NS(e,t),FS=e=>`could not check for unregistered packages — ${e}`,IS=e=>`…and ${e} more finding(s) — act on the ones above (register, repoint or decline) and run the check again to see the rest`,LS=e=>{let t=e.length-10;return t<=0?[...e]:[...e.slice(0,10),IS(t)]},RS=e=>{let t=/* @__PURE__ */ new Map;for(let n of e){let[e=`.`]=vS(n.path).split(`/`);t.set(e,[...t.get(e)??[],n])}return t},zS=e=>e.path===void 0,BS=(e,t,n)=>{if(e.length<3)return e.map(e=>({candidates:1,dir:n,line:AS(e,t)}));let r=yS(e.map(e=>vS(e.path)));return[{candidates:e.length,dir:r,line:`${r}: ${e.length} unregistered package(s) the configuration does not have`}]},VS=e=>{let t=e.reduce((e,t)=>e+t.candidates,0),n=new Set(e.flatMap(e=>e.dir===void 0?[]:[e.dir])).size;return`…and ${t} more unregistered package(s)${n===0?``:` in ${n} director(ies)`} — 'refs doctor --json' lists every candidate`},HS=(e,t)=>{let n=e.filter(e=>zS(e)).map(e=>({candidates:1,line:AS(e,t)})),r=[...RS(e.filter(e=>!zS(e)))].toSorted(([e],[t])=>e.localeCompare(t)).flatMap(([e,n])=>BS(n,t,e)),i=[...n,...r],a=i.slice(10);return a.length===0?i.map(e=>e.line):[...i.slice(0,10).map(e=>e.line),VS(a)]},US=(e,t)=>e.reason===void 0?[...LS((e.packages??[]).map(e=>PS(e,t))),...HS(e.discovery??[],t),...e.discovery_incomplete===void 0?[]:[FS(e.discovery_incomplete)]]:[`could not be checked — ${e.reason}`],WS=e=>{let t;return()=>(t??=fy(e),t)},GS=async(e,t,n)=>{let r=await Cv(e);if(r===void 0||t.some(e=>e.packageName===r.name))return{issues:[]};let i=await n();if(!m_(i))return{incomplete:Gb(i),issues:[]};let a=w_(i.packages,r.name);return a.kind===`ambiguous`?{issues:[{candidates:a.paths,name:r.name,status:`unregistered`}]}:{issues:a.kind===`found`?[{name:r.name,path:a.path,status:`unregistered`}]:[]}},KS=e=>{let t=/* @__PURE__ */ new Map;for(let n of e)t.set(n.name,[...t.get(n.name)??[],n.path]);return t},qS=(e,t)=>{let n=new Set(e.changedDirs),r=t.filter(e=>!n.has(e.path)).map(e=>e.name);return/* @__PURE__ */ new Set([...e.namesBefore,...r])},JS=(e,t)=>t.length===1&&t[0]!==void 0?{name:e,path:t[0],status:`unregistered`}:{candidates:[...t],name:e,status:`unregistered`},YS=async(e,t,n)=>{if(t.kind===`arrivals`&&t.changedDirs.length===0)return{issues:[]};let r=await n();if(!m_(r))return{incomplete:Gb(r),issues:[]};let i=new Set(e.map(e=>e.packageName)),a=r.packages.filter(e=>e.path!==`.`),o=t.kind===`all`?void 0:qS(t,a);return{issues:[...KS(a)].filter(([e])=>!i.has(e)).filter(([e])=>o===void 0||!o.has(e)).map(([e,t])=>JS(e,t)).toSorted((e,t)=>e.name.localeCompare(t.name))}},XS=(e,t)=>{if(t.length===0)return{issues:[...e],suppressed:[]};let n=(e,n)=>t.some(t=>t.name===e&&t.path===n),r=[];return{issues:e.flatMap(e=>{if(e.status!==`unregistered`)return[e];let t=e.path===void 0?e.candidates??[]:[e.path],i=t.filter(t=>!n(e.name,t)),a=t.filter(t=>n(e.name,t));return r.push(...a.map(t=>({name:e.name,path:t}))),i.length===0?[]:[JS(e.name,i)]}),suppressed:r}},ZS=e=>e!==`unmaterialized`&&e!==`verified`,QS=/* @__PURE__ */ new Set([`ambiguous`,`missing`,`relocated`]),$S=(e,t={})=>{let{declined:n=[],discoveryIncomplete:r}=t,i=e.filter(e=>e.status!==`unregistered`),a=e.filter(e=>e.status===`unregistered`);return{...n.length===0?{}:{declined:[...n]},...a.length===0?{}:{discovery:a},...r===void 0?{}:{discovery_incomplete:r},...i.length===0?{}:{packages:i},status:eC(i,r)}},eC=(e,t)=>e.some(e=>QS.has(e.status))?`drift`:e.length===0&&t===void 0?`ok`:`unknown`,tC=(e,t)=>({path:e.configuredPath,reason:t,status:`unverifiable`}),nC=(e,t)=>h_(t)?{configuredPath:e.configuredPath,path:null,status:`missing`}:tC(e,`this repo declares no workspaces, so there was nowhere to search`),rC=(e,t)=>t===e.configuredPath,iC=e=>e.packages.filter(e=>e.path!==`.`),aC=(e,t)=>{let n=w_(iC(t),e.packageName);return n.kind===`ambiguous`?{candidates:n.paths,configuredPath:e.configuredPath,path:null,status:`ambiguous`}:m_(t)?n.kind===`absent`?nC(e,t):rC(e,n.path)?tC(e,`the checkout changed while it was being inspected`):{configuredPath:e.configuredPath,path:n.path,status:`relocated`}:tC(e,n.kind===`found`?`workspace detection was incomplete, so the new location is not confirmed unique`:`workspace detection was incomplete`)},oC=e=>{let t=new Map(Object.entries(e??{}));return[...t.keys()].toSorted().flatMap(e=>{let n=t.get(e);return n===void 0?[]:[{configuredPath:n.path,packageName:e}]})},sC=async(e,t)=>{let n=await x_(e,t.configuredPath,t.packageName);if(n.kind===`match`)return{path:t.configuredPath,status:`verified`};if(n.kind===`unreadable`)return{path:t.configuredPath,reason:n.reason,status:`unverifiable`}},cC=e=>e.flatMap(e=>e.settled===void 0?[]:[{outcome:e.settled,query:e.query}]),lC=async(e,t,n)=>{let r=await Promise.all(t.map(async t=>({query:t,settled:await sC(e,t)})));if(r.every(e=>e.settled!==void 0))return cC(r);let i=await n();return r.map(e=>({outcome:e.settled??aC(e.query,i),query:e.query}))},uC=e=>{let{outcome:t,query:n}=e;return ZS(t.status)?[{...t.candidates===void 0?{}:{candidates:t.candidates},configured_path:n.configuredPath,name:n.packageName,...t.status===`relocated`&&t.path!==null?{path:t.path}:{},...t.reason===void 0?{}:{reason:t.reason},status:t.status}]:[]},dC=(e,t)=>{let n=new Set(e.map(e=>e.name));return[...e,...t.filter(e=>!n.has(e.name))]},fC=async(e,t,n)=>{let r=oC(t.packages),[i]=r;if(i===void 0)return{status:`ok`};let a=WS(e);try{let[i,o,s]=await Promise.all([lC(e,r,a),GS(e,r,a),YS(r,n,a)]),c=XS([...i.flatMap(e=>uC(e)),...dC(o.issues,s.issues)],t.declined_packages??[]);return $S(c.issues,{declined:c.suppressed,...(s.incomplete??o.incomplete)===void 0?{}:{discoveryIncomplete:s.incomplete??o.incomplete}})}catch(e){return{reason:Zy(e),status:`unknown`}}},pC=async(e,t,n)=>{try{return await G(e,Eb(n.key),()=>fC(n.dest,t.refs[n.key]??{},{kind:`all`}),{timeoutMs:100})}catch(e){if(e instanceof L&&e.code===`conflict`)return{reason:`another refs process is holding this ref`,status:`unknown`};throw e}},mC=e=>e===0?``:` (${e} declined package(s) not reported)`,hC=(e,t)=>e.unhealthy.length===0?`every configured package path resolves in ${t} checkout(s)`:e.unhealthy.join(`; `),gC=(e,t)=>{let{declined:n,discovery:r,findings:i}=e;return{detail:[hC(e,t)+mC(n),...r].join(`; `),...i.length===0?{}:{findings:i},name:`config-drift`,status:e.unhealthy.length===0?`ok`:`warn`}},_C=async(e,t,n)=>{let[r,...i]=n;if(r===void 0)return{declined:0,discovery:[],findings:[],unhealthy:[]};let a=await pC(e,t,r),o=await _C(e,t,i);return yC(o,{key:r.key,report:a})},vC=(e,t)=>({...e,...ES(e,t)}),yC=(e,t)=>{let{key:n,report:r}=t,i=e=>e.map(e=>`${n}: ${e}`),a=r.discovery??[],o=r.packages??[],s=[...o,...a];return{declined:(r.declined??[]).length+e.declined,discovery:[...i(US({discovery:a,status:`ok`},n)),...e.discovery],findings:s.length===0?e.findings:[{key:n,packages:s.map(e=>vC(e,n))},...e.findings],unhealthy:[...i(US({...r.discovery_incomplete===void 0?{}:{discovery_incomplete:r.discovery_incomplete},...r.reason===void 0?{}:{reason:r.reason},packages:o,status:r.status},n)),...e.unhealthy]}},bC=async(e,t)=>{let n=Qx(e,t);return gC(await _C(e,t,n),n.length)},xC=`git-exec-surfaces`,SC=/^hook\.(?<label>.+)\.command$/u,CC=/^hook\.(?<label>.+)\.enabled$/u,wC=/^filter\..+\.(?:clean|smudge|process)$/u,TC=/* @__PURE__ */ new Set([``,`0`,`1`,`false`,`no`,`off`,`on`,`true`,`yes`]),EC=e=>{let t=e.split(`\0`),n=[];for(let e=0;e+1<t.length;e+=2){
|
|
490
|
+
/* v8 ignore next 2 -- the loop guard already proves both indices are in range; the fallbacks
|
|
491
|
+
exist only because `noUncheckedIndexedAccess` cannot see that. */
|
|
492
|
+
let r=t[e+1]??``,i=t[e]??``,a=r.indexOf(`
|
|
493
|
+
`),o=a===-1?r:r.slice(0,a),s=a===-1?``:r.slice(a+1);n.push({key:o,scope:i,value:s})}return n},DC=e=>{let t=/* @__PURE__ */ new Map;for(let n of e){let e=CC.exec(n.key)?.groups?.label;e!==void 0&&t.set(e,n.value!==`false`)}return new Set([...t].filter(([,e])=>!e).map(([e])=>e))},OC=(e,t)=>{if(e.key===`core.fsmonitor`)return!TC.has(e.value.trim().toLowerCase());let n=SC.exec(e.key)?.groups?.label;return n===void 0?wC.test(e.key):!t.has(n)},kC=e=>{let t=EC(e).filter(e=>e.scope!==`local`),n=DC(t),r=t.filter(e=>OC(e,n)).map(e=>e.key);return[...new Set(r)]},AC=e=>({detail:`${e}, so this could not be checked`,name:xC,status:`warn`}),jC=e=>({detail:`${e.join(`, `)}: git runs these itself, and the managed hooks path does not cover them — a configured hook fires on the events refs causes, a filter is selected by a checkout's own .gitattributes, and fsmonitor runs in the worktree. Whether one of them reaches a checkout's content depends on the command, which refs cannot decide for you`,name:xC,status:`warn`}),MC=async(e,t)=>{let n=await e.runner.run(`git`,[`config`,`--list`,`-z`,`--show-scope`],{cwd:t});if(n.exitCode!==0)return AC(`the git configuration could not be read`);if(n.stdoutTruncated===!0)return AC(`the git configuration was too large to read whole`);let r=kC(n.stdout);return r.length===0?{detail:`no configured hook, filter or fsmonitor command outside a checkout`,name:xC,status:`ok`}:jC(r)},NC=`home-modes`,PC=e=>[{expected:448,label:`the refs home`,path:e.root},{expected:448,label:`sources/`,path:e.sourcesDir},{expected:448,label:`locks/`,path:e.locksDir},{expected:448,label:`hooks/`,path:e.hooksDir},{expected:384,label:`config.toml`,path:e.configPath},{expected:384,label:`state.json`,path:e.statePath}],FC=e=>(e&511).toString(8).padStart(3,`0`),IC=e=>e instanceof Error&&`code`in e?String(e.code):`unknown`,LC=async e=>{try{let[t,n]=await Promise.all([p(e),i(e)]);return{kind:`mode`,mode:t.mode&511,symlink:n.isSymbolicLink()}}catch(e){let t=IC(e);return t===`ENOENT`?{kind:`absent`}:{kind:`unreadable`,reason:t}}},RC=async e=>{let t=await LC(e.path);if(t.kind===`absent`)return;if(t.kind===`unreadable`)return{repairable:!1,text:`${e.label} could not be inspected (${t.reason})`};if(!(t.mode&63))return;let n=t.symlink?` — a symlink; fix it where it points`:``;return{repairable:!t.symlink,text:`${e.label} is ${FC(t.mode)} (expected ${FC(e.expected)})${n}`}},zC=e=>e.some(e=>e.repairable)?` — run: refs init`:``,BC=async e=>{if(process.platform===`win32`)return{detail:`not applicable on this platform — the mode bits do not say who may write`,name:NC,status:`ok`};let t=(await Promise.all(PC(e).map(e=>RC(e)))).filter(e=>e!==void 0);return t.length===0?{detail:`no group or other permission bits on anything refs owns`,name:NC,status:`ok`}:{detail:`${t.map(e=>e.text).join(`; `)}${zC(t)}`,name:NC,status:`warn`}},VC=e=>{let{diagnosis:t}=e;return e.kind===`claim`||!e.isDirectory||t.pidState===`definitely-dead`||t.stale||t.meta===`malformed`||t.meta===`unreadable`||t.policy===`unknown`?!1:t.ageMs===void 0||t.ageMs>=0},HC=e=>{let{ageMs:t,budgetMs:n,policy:r}=e;return r===`unknown`?`, state could not be read`:t===void 0||n===void 0?``:t<0?`, recorded time is in the future — check the system clock`:`, ${Vm(t)} into a ${Vm(n)} window`},UC=e=>e.pid===void 0?`owner unknown (metadata ${e.meta})`:e.pidState===`definitely-dead`?`recorded pid ${e.pid} is not running`:`recorded pid ${e.pid} present`,WC=(e,t)=>{let n=h(e.locksDir,Tm,t.name),r=t.diagnosis.ageMs===void 0?``:` for ${Vm(t.diagnosis.ageMs)}`,i=cb(n),a=i===void 0?`remove that directory by hand — its path cannot be put into a pasteable command`:`${GC}: ${i}`;return`steal claim on ${t.name}: present${r}. Stealing this lock is blocked while it is here. A reclaim in progress clears it within a moment; if it stays, ${a}`},GC=`stop every refs process using this home — including suspended ones — and then run`,KC=(e,t)=>{let{diagnosis:n}=t;if(vm(n))return`, reclaimable now`;if(!n.stale&&t.isDirectory)return``;let r=h(e.locksDir,t.name),i=sb(r);return i===void 0?`, not automatically reclaimable — and its path cannot be put into a pasteable command, so it has to be removed by hand`:`, not automatically reclaimable — if it is genuinely abandoned, ${GC}: ${i}`},qC=(e,t)=>{let{diagnosis:n}=t,r=t.isDirectory?``:`not a directory, `,i=KC(e,t);return`${t.name}: ${r}${UC(n)}${HC(n)}${i}`},JC=async e=>{let t=await Bm(e),[n]=t;return n===void 0?{detail:`no locks held`,name:`locks`,status:`ok`}:{detail:t.map(t=>t.kind===`claim`?WC(e,t):qC(e,t)).join(`; `),name:`locks`,status:t.every(e=>VC(e))?`ok`:`warn`}},YC=[`.agents`,`skills`,`refs`,`SKILL.md`],XC=[`skills`,`refs`,`SKILL.md`],ZC=[`.claude`,`skills`,`refs`,`SKILL.md`],QC=`npx skills add kaisers-io/refs`,$C=`npm i -g @kaisers-io/refs@latest`,ew=(e,t)=>e===void 0?void 0:{display:t,path:e},tw=e=>{let{dirName:t,env:n,home:r,overrideName:i}=e,a=n[i]?.trim();return a!==void 0&&a.length>0?{display:a,path:a}:ew(r===void 0?void 0:h(r,t),`~/${t}`)},nw=e=>{let t=e.homedir.length>0?e.homedir:void 0;return[{label:`shared ~/.agents`,root:ew(t,`~/.agents`),segments:YC},{label:`Claude Code`,root:tw({dirName:`.claude`,env:e.env,home:t,overrideName:`CLAUDE_CONFIG_DIR`}),segments:XC},{label:`Codex`,root:tw({dirName:`.codex`,env:e.env,home:t,overrideName:`CODEX_HOME`}),segments:XC},{label:`project ./.agents`,root:ew(e.cwd,`./.agents`),segments:YC},{label:`project ./.claude`,root:ew(e.cwd,`./.claude`),segments:ZC}].flatMap(({label:e,root:t,segments:n})=>t===void 0?[]:[{display:t.display,label:e,path:h(t.path,...n)}])},rw=async(e,t)=>{try{let n=await l(e);return{label:t,realPath:n,source:await s(n,`utf8`)}}catch{return}},iw=e=>{let t=/* @__PURE__ */ new Map;for(let n of e)t.has(n.realPath)||t.set(n.realPath,n);return[...t.values()]},aw=/^---\r?\n(?<body>[\s\S]*?)\r?\n---/u,ow=/^\s*cli_version:\s*["']?(?<version>[^"'\s]+)["']?\s*$/mu,sw=e=>{let t=aw.exec(e)?.groups?.body;if(t!==void 0)return ow.exec(t)?.groups?.version},cw=(e,t)=>{if(e.length>32)return`unknown`;if(e===t)return`match`;let n=Y_(e,t);return n===void 0?`unknown`:n===0?`match`:n>0?`cli-older`:`skill-older`},lw={"cli-older":(e,t)=>`the refs skill targets CLI ${e} but this CLI is ${t} — update the CLI: ${$C}`,match:(e,t)=>`the refs skill is installed and matches this CLI (${t})`,"skill-older":(e,t)=>`the refs skill targets CLI ${e} but this CLI is ${t} — update the skill: ${QC}`,unknown:(e,t)=>`the refs skill does not declare a version this CLI (${t}) can compare — reinstall both: ${$C} and ${QC}`},uw=e=>{let{cliVersion:t,label:n,skillVersion:r}=e;if(r===void 0)return{detail:`the refs skill (${n}) predates the version gate — update it: ${QC}`,name:`skill`,status:`warn`};let i=cw(r,t);return{detail:`${n}: ${lw[i](r,t)}`,name:`skill`,status:i===`match`?`ok`:`warn`}},dw=e=>({detail:`refs skill not found in the locations this check knows about (${e.map(e=>e.display).join(`, `)}) — an install anywhere else is invisible here and still works; if it really is missing: ${QC}`,name:`skill`,status:`warn`}),fw=async e=>{let t=nw(e),n=await Promise.all(t.map(e=>rw(e.path,e.label))),r=iw(n.filter(e=>e!==void 0)).map(t=>uw({cliVersion:e.cliVersion,label:t.label,skillVersion:sw(t.source)}));return r.find(e=>e.status!==`ok`)??r[0]??dw(t)},pw=/^(?<user>[^/\s@]+)@(?<host>[^:/\s]+):/u,mw=e=>e===``?{}:{user:e},hw=e=>e===``?{}:{port:e},gw=e=>{try{let t=new URL(e);return t.protocol===`ssh:`?{host:t.hostname,...mw(t.username),...hw(t.port)}:void 0}catch{return}},_w=e=>{let t=pw.exec(e),n=t?.groups?.host;return n===void 0?gw(e):{host:n,user:t?.groups?.user??`git`}},vw=e=>e.port===void 0?e.host:`${e.host}:${e.port}`,yw=e=>e.user===void 0?vw(e):`${e.user}@${vw(e)}`,bw=e=>{let t=Object.values(e.refs).map(e=>_w(e.url)).filter(e=>e!==void 0),n=/* @__PURE__ */ new Map;for(let e of t)n.set(yw(e),e);return[...n.values()].toSorted((e,t)=>yw(e).localeCompare(yw(t)))},xw=/Permission denied/u,Sw=[/Could not resolve hostname/u,/Connection refused/u,/Host key verification failed/u,/timed out/u],Cw=e=>e.user===void 0?e.host:`${e.user}@${e.host}`,ww=e=>{let t=[`-o`,`ConnectTimeout=5`,`-o`,`BatchMode=yes`],n=Cw(e);return e.port===void 0?[...t,`-T`,n]:[...t,`-p`,e.port,`-T`,n]},Tw=async(e,t,n)=>{let r=yw(t),i=await e.runner.run(`ssh`,ww(t),{timeoutMs:n});return i.timedOut===!0?{host:r,outcome:`timeout`}:xw.test(i.stderr)?{host:r,outcome:`denied`}:Sw.some(e=>e.test(i.stderr))?{detail:i.stderr.trim(),host:r,outcome:`connection-warn`}:{host:r,outcome:`ok`}},Ew=(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`}},Dw=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`}},Ow=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`}},kw=e=>({detail:`ssh auth ok for: ${e.map(e=>e.host).join(`, `)}`,name:`ssh-auth`,status:`ok`}),Aw=(e,t)=>Ew(e,t)??Dw(e)??Ow(e)??kw(e),jw=async(e,t,n)=>{let r=bw(t);if(r.length===0)return;let i=n?.timeoutMs??1e4,a=await Promise.all(r.map(t=>Tw(e,t,i)));return Aw(a,i)},Mw=async e=>{try{return await e.run()}catch(t){return{detail:`check crashed: ${Zy(t)}`,name:e.name,status:`fail`}}},Nw={"cli-update":`Checking for a newer refs release`,config:`Checking the config`,"config-drift":`Comparing registered packages with the checkouts`,"dirty-checkouts":`Looking for local changes in checkouts`,git:`Checking Git`,"git-exec-surfaces":`Checking what Git is configured to run`,"hooks-guard":`Checking the checkout protection hooks`,locks:`Checking locks`,node:`Checking Node.js`,orphans:`Looking for orphaned checkouts`,skill:`Checking the installed skill`,"ssh-auth":`Checking SSH authentication`},Pw=async(e,t)=>{let[n,...r]=e;if(n===void 0)return[];t.update(Nw[n.name]??`Running the ${n.name} check`);let i=await Mw(n),a=await Pw(r,t);return i===void 0?a:[i,...a]},Fw=e=>{let{configLoad:t,ctx:n,home:r,state:i}=e;return[{name:`git`,run:()=>Vx(n)},{name:`git-exec-surfaces`,run:()=>MC(n,r.root)},{name:`node`,run:()=>Promise.resolve(Gx(n))},{name:`config`,run:()=>Promise.resolve(Jx(t.errorMessage))},{name:`home-modes`,run:()=>BC(r)},{name:`hooks-guard`,run:()=>sS(n,r,t.config)},{name:`dirty-checkouts`,run:()=>uS(n,r,t.config)},{name:`config-drift`,run:()=>bC(r,t.config)},{name:`orphans`,run:()=>_S(r,t.config,i)},{name:`locks`,run:()=>JC(r)},{name:`skill`,run:()=>fw(n)},{name:`cli-update`,run:()=>Zx(n,t.config)},{name:`ssh-auth`,run:()=>jw(n,t.config)}]},Iw=async(e,t)=>{t.update(`Reading config and state`);let n=V(e.env),r=await qx(n),i=await dS(n);return Pw(Fw({configLoad:r,ctx:e,home:n,state:i}),t)},Lw={fail:`FAIL`,ok:`OK`,warn:`WARN`},Rw=e=>e.map(e=>`[${Lw[e.status]}] ${e.name}: ${e.detail}`),zw=e=>e.some(e=>e.status===`fail`),Bw=(e,t)=>{e.command(`doctor`).description(`Run environment/integrity checks (git, node, config, hooks, checkouts, drift, locks, ssh).`).action((e,n)=>{let r=X(n);return Q(t,r,async()=>{let e=await eb(t,r,e=>Iw(t,e));Z(t,r,Rw(e),{checks:e}),zw(e)&&(process.exitCode=mu.UNEXPECTED)})()})},Vw=(e,t)=>{let n=e.refs[t];
|
|
494
|
+
/* v8 ignore next 3 -- per the doc comment above: `matchRefKey`/`routeQuery` only ever produce
|
|
495
|
+
keys present in `config.refs`, so this guard exists purely for `noUncheckedIndexedAccess`. */
|
|
496
|
+
if(n===void 0)throw Error(`internal: matched ref key '${t}' is missing from config.refs`);return n},Hw=(e,t)=>{if(!U(e))throw gu(`checkout for '${t}' is missing — run: refs sync ${rb(t)}`)},Uw=(e,t,n)=>{let{packages:r}=e,i=r!==void 0&&Object.hasOwn(r,n)?r[n]:void 0;if(i===void 0)throw gu(`no package '${n}' registered on ref '${t}'`);return i},Ww=`never`,Gw=(e,t,n)=>e===void 0||n-Date.parse(e)>t,Kw=(e,t)=>`${e} ${t}${e===1?``:`s`} ago`,qw=(e,t)=>{if(e===void 0)return Ww;let n=t-Date.parse(e);if(Number.isNaN(n))return Ww;let r=Math.floor(n/1e3);if(r<60)return`just now`;let i=Math.floor(r/60);if(i<60)return Kw(i,`minute`);let a=Math.floor(i/60);if(a<24)return Kw(a,`hour`);let o=Math.floor(a/24);return o<365?Kw(o,`day`):Kw(Math.floor(o/365),`year`)},Jw=e=>{let t=qw(e.lastFetchedAt,e.now),n=[`synced: ${t}`];return e.stale&&t!==Ww&&n.push(`status: stale`),e.missing&&n.push(`missing: checkout not found — run: refs sync`),n},Yw=(e,t,n)=>{let r=e.state.refs[t],i=ul(V_(`sync_ttl`,n,e.settings)),a=Object.keys(n.packages??{}).toSorted();return{clone_mode:V_(`clone_mode`,n,e.settings),description:n.description,key:t,...r?.last_fetched_at===void 0?{}:{last_fetched_at:r.last_fetched_at},missing:!U(ju(e.home,cl.parse(t))),...e.includePackages?{packages:a}:{},packages_count:a.length,stale:Gw(r?.last_fetched_at,i,e.now)}},Xw=e=>{let t={home:e.home,includePackages:e.includePackages,now:e.now,settings:e.config.settings,state:e.state};return Object.entries(e.config.refs).map(([e,n])=>Yw(t,e,n)).toSorted((e,t)=>e.key.localeCompare(t.key))},Zw=async(e,t,n)=>{let r=V(e.env),i=await B(r),a=await W_(r);return Xw({config:i,home:r,includePackages:t,now:n,state:a})},Qw=(e,t)=>[`ref: ${e.key}`,`description: ${e.description}`,...Jw({lastFetchedAt:e.last_fetched_at,missing:e.missing,now:t,stale:e.stale})],$w=(e,t)=>e.length===0?[`no refs configured — run: refs add <source>`]:e.reduce((e,n,r)=>(r>0&&e.push(``),e.push(...Qw(n,t)),e),[]),eT=e=>e.split(`/`),tT=(e,t)=>{let n=eT(e);if(t.length>n.length)return!1;let r=n.length-t.length;return t.every((e,t)=>e===n[r+t])},nT=(e,t)=>{if(Object.hasOwn(e.refs,t))return cl.parse(t);let n=eT(t),r=Object.keys(e.refs).filter(e=>tT(e,n)).toSorted(),[i]=r;if(i===void 0)throw gu(`no ref matches '${t}'`);if(r.length>1)throw R(`'${t}' matches more than one ref: ${r.join(`, `)}`);return cl.parse(i)},rT=(e,t)=>{e.command(`list`).description(`List configured refs with their staleness/missing checkout status.`).option(`--packages`,`include each ref's package names in --json output (off by default)`).action((e,n)=>{let r=X(n);return Q(t,r,async()=>{let n=Date.now(),i=await Zw(t,e.packages===!0,n);Z(t,r,$w(i,n),i)})()})},iT=e=>e===void 0?null:e,aT=(e,t)=>e.name===t.name&&e.path===t.path,oT=(e,t)=>{let n=(e.declined_packages??[]).filter(e=>!aT(e,t));if(n.length===0){let{declined_packages:t,...n}=e;return n}return{...e,declined_packages:n}},sT=(e,t)=>`package '${e.name}' at '${e.path}' is already declined on ref '${t}'`,cT=(e,t)=>`package '${e.name}' at '${e.path}' is not declined on ref '${t}' — nothing to undo`,lT=(e,t)=>`package '${e}' is registered on ref '${t}' — declining applies to packages the configuration does not have; unregister it first with --remove`,uT=(e,t,n)=>{if(Object.hasOwn(e.packages??{},t.name))throw z(lT(t.name,n));let r=e.declined_packages??[];if(r.some(e=>aT(e,t)))throw z(sT(t,n));return{...e,declined_packages:[...r,t]}},dT=e=>{if(e.declined)return uT(e.entry,e.record,e.key);if(!(e.entry.declined_packages??[]).some(t=>aT(t,e.record)))throw z(cT(e.record,e.key));return oT(e.entry,e.record)},fT=(e,t)=>{let n=V(e.env);return G(n,`home`,async()=>{let e=await B(n),r=nT(e,t.query),i=Vw(e,r),a=Cl.safeParse({name:t.packageName,path:t.path});if(!a.success)throw z(S(a.error));let o=a.data,s=dT({declined:t.declined,entry:i,key:r,record:o});return await Ou(n,{...e,refs:{...e.refs,[r]:s}}),{declined:t.declined,field:`declined_packages`,key:r,new:t.declined?o:null,old:t.declined?null:o}})},pT=`packages`,mT=()=>Object.keys(wl.shape).toSorted().join(`, `),hT=e=>`unknown package field '${e}' — valid fields: ${mT()}`,gT=e=>Object.hasOwn(wl.shape,e),_T=(e,t,n)=>{if(!gT(t))throw R(hT(t));let r=e[t],i=wl.safeParse({...e,[t]:n});if(!i.success)throw z(S(i.error));return{field:t,newValue:i.data[t],oldValue:r,updated:i.data}},vT=async e=>{let t=Uw(e.entry,e.key,e.packageName),n=_T(t,e.field,e.value),r={...e.entry,packages:{...e.entry.packages,[e.packageName]:n.updated}};return await Ou(e.home,{...e.config,refs:{...e.config.refs,[e.key]:r}}),{field:n.field,key:e.key,new:iT(n.newValue),old:iT(n.oldValue)}},yT=(e,t)=>`package '${e}' is already registered on ref '${t}' — edit its fields instead`,bT=(e,t)=>{let n=V(e.env);return G(n,`home`,async()=>{let e=await B(n),r=nT(e,t.query),i=Vw(e,r);if(Object.hasOwn(i.packages??{},t.packageName))throw z(yT(t.packageName,r));let a=Tl.safeParse({...oT(i,{name:t.packageName,path:t.path}),packages:{...i.packages,[t.packageName]:{description:t.description,path:t.path}}});if(!a.success)throw z(S(a.error));return await Ou(n,{...e,refs:{...e.refs,[r]:a.data}}),{created:!0,field:pT,key:r,new:{description:t.description,name:t.packageName,path:t.path},old:null}})},xT=(e,t)=>`package '${e}' is not registered on ref '${t}' — nothing to remove`,ST=(e,t)=>{let n=V(e.env);return G(n,`home`,async()=>{let e=await B(n),r=nT(e,t.query),i=Vw(e,r),a=i.packages??{};if(!Object.hasOwn(a,t.packageName))throw z(xT(t.packageName,r));let{[t.packageName]:o,...s}=a,c=Object.keys(s).length===0?CT(i):{...i,packages:s};return await Ou(n,{...e,refs:{...e.refs,[r]:c}}),{field:pT,key:r,new:null,old:{description:o?.description??``,name:t.packageName,path:o?.path??``},removed:!0}})},CT=e=>{let{packages:t,...n}=e;return n},wT=e=>e.second===void 0&&e.value===void 0,TT=e=>{let{description:t,path:n}=e.create,{packageName:r}=e;if(r===void 0||t===void 0||n===void 0||!wT(e))throw R(`--create registers a new package: it needs --package <name>, --path <path> and --description <text>, and takes no <field> <value> arguments`);return{description:t,packageName:r,path:n}},ET=e=>{let{packageName:t}=e;if(t===void 0||e.create.path!==void 0||!wT(e)||e.create.description!==void 0)throw R(`--remove unregisters a package: it needs --package <name>, and takes no <field> <value> arguments, no --path and no --description`);return{packageName:t}},DT=e=>{let{packageName:t}=e,{path:n}=e.create;if(t===void 0||n===void 0||!wT(e)||e.create.description!==void 0)throw R(`--decline and --undecline record a decision about one package at one path: each needs --package <name> and --path <path>, and takes no <field> <value> arguments and no --description`);return{packageName:t,path:n}},OT=[`create`,`remove`,`decline`,`undecline`],kT=e=>{let t=OT.filter(t=>e[t]===!0);if(t.length>1)throw R(`use one of --create, --remove, --decline or --undecline: they are different answers about the same package, and running two at once would guess which one was meant`);return t[0]},AT=(e,t,n)=>t===`create`?bT(e,{...TT(n),query:n.first}):t===`remove`?ST(e,{...ET(n),query:n.first}):fT(e,{...DT(n),declined:t===`decline`,query:n.first}),jT=`packages`,MT=()=>Object.keys(Tl.shape).filter(e=>e!==jT).toSorted().join(`, `),NT=e=>`unknown ref field '${e}' — valid fields: ${MT()}`,PT=e=>Object.hasOwn(Tl.shape,e),FT=(e,t,n)=>`failed to rewrite git remote at ${e} to '${W(t)}': ${n.trim()}`,IT=async(e,t)=>{if(Iu(t.home,t.dest),!U(t.dest))return;let n=await e.runner.run(`git`,[`remote`,`set-url`,`--`,`origin`,t.cloneUrl],{cwd:t.dest});if(n.exitCode!==0)throw z(FT(t.dest,t.cloneUrl,n.stderr))},LT=async(e,t)=>{let n=Fp(t.value,{allowFileUrls:Db(e.env)});if(n.key!==t.key)throw z(`new url derives a different key — remove and re-add instead`);let r=ju(t.home,t.key);return await IT(e,{cloneUrl:n.cloneUrl,dest:r,home:t.home}),{...t.entry,url:n.cloneUrl}},RT=(e,t,n)=>{if(t===`default_branch`&&!Te(n))throw z(`'${n}' is not a name git accepts for a branch, so refs could not synchronise this ref`);let r={...e,[t]:n},i=Tl.safeParse(r);if(!i.success)throw z(S(i.error));return i.data},zT=(e,t)=>t.field===`url`?LT(e,{entry:t.entry,home:t.home,key:t.key,value:t.value}):Promise.resolve(RT(t.entry,t.field,t.value)),BT=async(e,t)=>{let{field:n}=t;if(n===jT)throw R(`use --package <name> <field> <value>`);if(!PT(n))throw R(NT(n));let r=t.entry[n],i=await zT(e,{entry:t.entry,field:n,home:t.home,key:t.key,value:t.value});return{new:i[n],old:r,updated:i}},VT=(e,t)=>{let n=V(e.env),{field:r,opts:i,query:a,value:o}=t;return G(n,`home`,async()=>{let t=await B(n),s=nT(t,a),c=Vw(t,s);if(i.packageName!==void 0)return vT({config:t,entry:c,field:r,home:n,key:s,packageName:i.packageName,value:o});let l=await BT(e,{entry:c,field:r,home:n,key:s,value:o});return await Ou(n,{...t,refs:{...t.refs,[s]:l.updated}}),{field:r,key:s,new:iT(l.new),old:iT(l.old)}})},HT=`settings`,UT=[],WT=()=>Object.keys(xl.shape).toSorted().join(`, `),GT=e=>`unknown setting '${e}' — valid settings: ${WT()}`,KT=e=>Object.hasOwn(xl.shape,e),qT=e=>`note: 'settings' addressed the global settings, not ${e} — use the full ref key to edit that ref`,JT=e=>{try{let t=nT(e,HT);return[qT(`ref '${t}'`)]}catch(e){if(e instanceof L&&e.code===`usage`)return[qT("one of several matching refs — see `refs list`")];if(e instanceof L&&e.code===`not_found`)return UT;throw e}},YT=e=>({data:{field:e.key,key:HT,new:iT(e.parsed[e.key]),old:iT(e.old)},warnings:JT(e.config)}),XT=(e,t)=>{let n=V(e.env);return G(n,`home`,async()=>{let e=await B(n);if(!KT(t.key))throw R(GT(t.key));let r=e.settings[t.key],i={...e.settings,[t.key]:t.value},a=xl.safeParse(i);if(!a.success)throw z(S(a.error));return await Ou(n,{...e,settings:a.data}),YT({config:e,key:t.key,old:r,parsed:a.data})})},ZT=[],QT=e=>{let t={};return e.package!==void 0&&(t.packageName=e.package),t},$T=e=>{if(e.second===void 0||e.value===void 0)throw R(`missing <field> and <value> — see 'refs edit --help'`);return{field:e.second,value:e.value}},eE=(e,t,n)=>{if(t.opts.packageName!==void 0)throw R(`--package is not valid with 'refs edit settings ...' — it only applies to ref/package edits`);return XT(e,n)},tE=async(e,t)=>{if(t.create.description!==void 0||t.create.path!==void 0)throw R(`--path and --description only apply to the package modes — to change one field of a registered package use: refs edit <ref> <field> <value> --package <name>`);let{field:n,value:r}=$T(t);return t.first===`settings`?eE(e,t,{key:n,value:r}):{data:await VT(e,{field:n,opts:t.opts,query:t.first,value:r}),warnings:ZT}},nE=async(e,t)=>{let n=kT(t.create);return n===void 0?tE(e,t):{data:await AT(e,n,{create:t.create,first:t.first,packageName:t.opts.packageName,second:t.second,value:t.value}),warnings:ZT}},rE=e=>e==null?`(unset)`:String(e),iE=(e,t)=>{let n=t?e.new:e.old,r=t?`declined`:`no longer declining`;return`${e.key}: ${r} '${n.name}' at ${n.path}`},aE=e=>{if(e.created===!0){let t=e.new;return`${e.key}: registered '${t.name}' at ${t.path}`}if(e.removed===!0){let t=e.old;return`${e.key}: unregistered '${t.name}' (was at ${t.path})`}return e.declined===void 0?void 0:iE(e,e.declined)},oE=e=>{let t=aE(e);return t===void 0?[`${e.key}: ${e.field} '${rE(e.old)}' -> '${rE(e.new)}'`]:[t]},sE=(e,t)=>{e.command(`edit`).description(`Edit one field: 'refs edit settings <key> <value>' for a global setting, or 'refs edit <ref> <field> <value> [--package <name>]' for a ref or package field. With --create, registers a package the config does not have yet; with --remove, unregisters one it has; with --decline, records that a package the checkout declares is deliberately not registered, so drift stops reporting it.`).argument(`<ref-or-settings>`,`a ref key/unique suffix, or the literal 'settings'`).argument(`[field-or-key]`,`field to edit (or, in settings mode, the setting key)`).argument(`[value]`,`the new value`).option(`--package <name>`,`edit this package's field instead of a top-level ref field`).option(`--create`,`register --package as a new package on this ref`).option(`--remove`,`unregister --package from this ref, leaving the checkout alone`).option(`--decline`,`record that --package at --path is deliberately not registered`).option(`--undecline`,`withdraw a decline, so the package is reported again`).option(`--path <path>`,`with --create/--decline/--undecline: the package path, relative to the checkout root`).option(`--description <text>`,`with --create: what the package is`).action((e,n,r,i,a)=>{let o=X(a);return Q(t,o,async()=>{let{data:a,warnings:s}=await nE(t,{create:i,first:e,opts:QT(i),second:n,value:r});Z(t,o,oE(a),a,s)})()})},cE=`Install the agent skill: npx skills add kaisers-io/refs (from a local clone: npx skills add <path-to-this-repo> --skill refs)`,lE={migrated:`migrated`,noop:`unchanged`,seeded:`seeded`},uE=async e=>{await a(e,{mode:448,recursive:!0}),(await i(e)).isSymbolicLink()||await t(e,448)},dE=async e=>{try{await t(e,384)}catch(e){if(!I(e))throw e}},fE=async e=>{for(let t of[e.root,e.sourcesDir,e.locksDir,e.hooksDir])await uE(t);await Promise.all([dE(e.configPath),dE(e.statePath)])},pE=async e=>{let t=V(e.env);return await fE(t),{config:await G(t,`home`,async()=>{let e=await Wu(t,Ey);return await Rf(t),e}),home:t.root,skill_hint:cE}},mE=(e,t)=>{e.command(`init`).description(`Seed or migrate the refs home directory, its config, and the git hooks guard.`).action((e,n)=>{let r=X(n);return Q(t,r,async()=>{let e=await pE(t);Z(t,r,[`home: ${e.home}`,`config: ${lE[e.config]}`,``,cE],e)})()})},hE=async e=>{let t=V(e.env),n=await G(t,`home`,()=>Wu(t,Ey));return n===`migrated`?{backup:Mu(t),result:n}:{backup:null,result:n}},gE=e=>e.result===`migrated`&&e.backup!==null?`config migrated (backup: ${se(e.backup)})`:e.result===`seeded`?`config seeded`:`config up to date`,_E=(e,t)=>{e.command(`migrate`).description(`Migrate the refs config to the current schema, seeding it if absent.`).action((e,n)=>{let r=X(n);return Q(t,r,async()=>{let e=await hE(t);Z(t,r,gE(e),e)})()})},vE=async e=>{try{return await i(e),!0}catch(e){if(I(e))return!1;throw e}},yE=async e=>{try{return await c(e)}catch(e){if(I(e))return;throw e}},bE=async e=>{try{return(await i(e)).isDirectory()}catch(e){if(I(e))return;throw e}},xE=async e=>{let t=await yE(e);if(t===void 0)return!0;if(t.length>0)return!1;try{await f(e)}catch(e){if(!I(e))throw e}return!0},SE=async e=>{let t=await bE(e);return t===void 0?!0:t?xE(e):!1},CE=async(e,t)=>{t!==e.sourcesDir&&await SE(t)&&await CE(e,m(t))},wE=async(e,t)=>await vE(t)?(Iu(e,t),await d(t,{force:!0,recursive:!0}),await CE(e,m(t)),{removedCheckout:!0}):{removedCheckout:!1,warning:`checkout was already missing`},TE=(e,t)=>Object.fromEntries(Object.entries(e).filter(([e])=>e!==t)),EE=async(e,t)=>{let n=await B(e),r={...n,refs:TE(n.refs,t)};await Ou(e,r);let i=await W_(e),a={...i,refs:TE(i.refs,t)};await G_(e,a)},DE=async(e,t)=>{let n=V(e.env),r=await B(n),i=nT(r,t),a=ju(n,i),{removedCheckout:o,warning:s}=await G(n,Eb(i),()=>wE(n,a));return await G(n,`home`,()=>EE(n,i)),{data:{key:i,removed_checkout:o},warnings:Xy(s)}},OE=e=>e.removed_checkout?[`removed ${e.key} (checkout deleted)`]:[`removed ${e.key} (checkout was already missing)`],kE=(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. zod`).action((e,n,r)=>{let i=X(r);return Q(t,i,async()=>{let{data:n,warnings:r}=await DE(t,e);Z(t,i,OE(n),n,r)})()})},AE=async e=>{let t=await x_(e.checkoutDir,e.configuredPath,e.packageName);return t.kind===`match`?{path:e.configuredPath,status:`verified`}:t.kind===`unreadable`?{path:e.configuredPath,reason:t.reason,status:`unverifiable`}:jE(e)},jE=async e=>aC(e,await fy(e.checkoutDir)),ME=async e=>{try{return await G(e.home,Eb(e.key),()=>AE(e),e.lockTimeoutMs===void 0?void 0:{timeoutMs:e.lockTimeoutMs})}catch(t){if(t instanceof L&&t.code===`conflict`)return{path:e.configuredPath,reason:`could not acquire the ref lock in time`,status:`unverifiable`};throw t}},NE=async e=>{if(!U(e.checkoutDir))return{path:e.configuredPath,status:`unmaterialized`};let t=await x_(e.checkoutDir,e.configuredPath,e.packageName);return t.kind===`match`?{path:e.configuredPath,status:`verified`}:t.kind===`unreadable`?{path:e.configuredPath,reason:t.reason,status:`unverifiable`}:(e.onProbed?.(),ME(e))},PE=(e,t)=>({local_path:null,name:e,path:null,reason:t,status:`unverifiable`}),FE=async e=>{if(!e.checkoutManaged)return PE(e.packageName,e.checkoutReason);let t=await NE(e),n=(t.status===`verified`||t.status===`relocated`)&&t.path!==null?await F_(h(e.checkoutDir,t.path),e.packageName):void 0;return{...t.candidates===void 0?{}:{candidates:t.candidates},...t.configuredPath===void 0?{}:{configured_path:t.configuredPath},...n===void 0?{}:{entry_points:n},local_path:t.path===null?null:h(e.checkoutDir,t.path),name:e.packageName,path:t.path,...t.reason===void 0?{}:{reason:t.reason},status:t.status}},IE=e=>e.kind===`target`?[{observed:e.observed,target:e.target}]:e.kind===`alternatives`?e.alternatives.flatMap(e=>IE(e)):e.kind===`conditions`?e.branches.flatMap(e=>IE(e.value)):[],LE=e=>{if(e.length===0)return[];let t=e.filter(e=>e.observed===`not_checked`||e.observed===`unverifiable`).length,n=e.length-t,r=t===0?``:`, ${t} not inspected`;return n===0?[`entry points: none of the ${e.length} declared target(s) was inspected`]:[`entry points: ${n} declared target(s) absent here${r}`]},RE=e=>{if(e.status!==`complete`)return[`entry points: could not be read (${e.reason??`unknown`})`];let t=e.entries.flatMap(e=>IE(e.value)),n=t.filter(e=>e.observed===`file`||e.observed===`directory`);if(n.length===0)return LE(t);let r=n.slice(0,3).map(e=>e.target),i=n.length-r.length;return[`entry points present: ${r.join(`, `)}${i===0?``:` (+${i} more)`}`]},zE=e=>[`package: ${e.name}`,`package path: ${e.local_path??`(unknown)`}`,...e.status===`verified`?[]:[`package status: ${e.status}`],...e.configured_path===void 0?[]:[`configured path: ${e.configured_path}`],...e.candidates===void 0?[]:[`candidates: ${e.candidates.join(`, `)}`],...e.reason===void 0?[]:[`reason: ${e.reason}`],...e.entry_points===void 0?[]:RE(e.entry_points)],BE=`node_modules`,VE=[`.pnp.cjs`,`.pnp.js`],HE=e=>!ce(e)&&e.split(`/`).every(e=>sl(e)),UE=function*(e){let t=fe(e);for(;;){se(t)!==BE&&(yield h(t,BE));let e=m(t);if(e===t)return;t=e}},WE=async e=>{if(await qE(e)!==`absent`)try{let t=JSON.parse(await s(e,`utf8`)),{name:n,version:r}=typeof t==`object`&&t?t:{};return typeof r!=`string`||r===``?{package_json:e,reason:`manifest_has_no_version`,status:`unverifiable`}:{...typeof n==`string`?{name:n}:{},package_json:e,status:`found`,version:r}}catch{return{package_json:e,reason:`manifest_unreadable`,status:`unverifiable`}}},GE=/* @__PURE__ */ new Set([`ENOENT`,`ENOTDIR`]),KE=async e=>{try{return(await c(e)).length===0}catch{return!1}},qE=async e=>{try{return await p(e),`present`}catch(e){let t=typeof e==`object`&&e&&`code`in e&&typeof e.code==`string`?e.code:void 0;return t!==void 0&&GE.has(t)?`absent`:`unreadable`}},JE=async e=>{for(let t of UE(e)){let e=m(t);if((await Promise.all(VE.map(t=>qE(h(e,t))))).includes(`present`))return!0}return!1},YE=async e=>{try{return await p(e)}catch(t){if(I(t))return;throw R(`--project could not be read: ${e} (${du(t)??`unknown`})`)}},XE=async e=>{let t=await YE(e);if(t===void 0)throw R(`--project path does not exist: ${e}`);if(!t.isDirectory())throw R(`--project must be a directory: ${e}`)},ZE=async e=>{let t=await qE(e);if(t===`unreadable`)return{reason:`slot_unreadable`,status:`unverifiable`};if(t===`absent`)return;let n=await WE(h(e,`package.json`));return n===void 0?await KE(e)?void 0:{reason:`installed_without_manifest`,status:`unverifiable`}:n},QE=async(e,t)=>{if(!HE(t))return{reason:`unsupported_package_name`,status:`unverifiable`};for(let n of UE(e)){let e=await ZE(h(n,...t.split(`/`)));if(e!==void 0)return e}return await JE(e)?{reason:`yarn_pnp`,status:`unsupported_layout`}:{status:`not_materialized`}},$E={'"':`"`,"\\":`\\`,b:`\b`,n:`
|
|
497
|
+
`,t:` `},eD={'"':`"`,"\\":`\\`},tD=/* @__PURE__ */ new Set([` `,` `]),$=Symbol(`malformed git config`),nD=e=>e!==void 0&&!e.quoted&&tD.has(e.char),rD=e=>{let t=0,n=e.length;for(;t<n&&nD(e[t]);)t+=1;for(;n>t&&nD(e[n-1]);)--n;return e.slice(t,n).map(e=>e.char).join(``)},iD=e=>{let t=[],n=!1;for(let r=0;r<e.length;r+=1){let i=e[r];if(i===`\\`){r+=1;let n=$E[e[r]??``];if(n===void 0)return $;t.push({char:n,quoted:!0})}else if(i===`"`)n=!n;else if(!n&&(i===`#`||i===`;`))return rD(t);else t.push({char:i??``,quoted:n})}return n?$:rD(t)},aD=e=>{let t=``;for(let n=0;n<e.length;n+=1){let r=e[n];if(r===`\\`){n+=1;let r=eD[e[n]??``];if(r===void 0)return $;t+=r}else t+=r??``}return t},oD=/^[ \t]+|[ \t]+$/gu,sD=e=>e.replace(oD,``),cD=/^\[[ \t]*(?<section>[A-Za-z0-9.-]+)[ \t]*(?:"(?<subsection>(?:[^"\\]|\\.)*)")?[ \t]*\]/u,lD=/^(?<name>[A-Za-z][A-Za-z0-9-]*)[ \t]*(?:=[ \t]*(?<value>.*))?$/u,uD=function*(e){let t=``,n=!1,r=!1;for(let i=0;i<e.length;i+=1){let a=e[i];if(a===`
|
|
353
498
|
`)yield t,t=``,n=!1,r=!1;else if(a!==`\r`||e[i+1]!==`
|
|
354
499
|
`){if(r)t+=a;else if(a===`\\`){let n=e[i+1];n===`
|
|
355
500
|
`||n===`\r`&&e[i+2]===`
|
|
356
|
-
`?i+=n===`\r`?2:1:(t+=a+(n??``),i+=1)}else a===`"`?n=!n:!n&&(a===`#`||a===`;`)&&(r=!0),t+=a}}t!==``&&(yield t)},tD=(e,t)=>e.subsection===void 0?`${e.name}.${t.toLowerCase()}`:`${e.name}.${e.subsection}.${t.toLowerCase()}`,nD=(e,t)=>{let n=e.toLowerCase();if(t===void 0)return{name:n};let r=YE(t);return r===$?$:{name:n,subsection:r}},rD=e=>{let t=QE.exec(e),n=t?.groups?.section;if(n===void 0)return;let r=ZE(e.slice(t?.[0].length??0)),i=nD(n,t?.groups?.subsection);return i===$?$:{rest:r,section:i}},iD=e=>e===``||e.startsWith(`#`)||e.startsWith(`;`),aD=e=>{let t=$E.exec(e),n=t?.groups?.name;if(n===void 0)return $;let r=JE(t?.groups?.value??``);return r===$?$:{name:n,value:r}},oD=(e,t)=>{let n=aD(t.line);if(n===$)return`malformed`;let r=tD(t.section,n.name);return t.wanted.includes(r)&&e.set(r,[...e.get(r)??[],n.value]),`ok`},sD=(e,t,n)=>t.rest===``||iD(t.rest)?t.section:oD(e,{line:t.rest,section:t.section,wanted:n})===`malformed`?$:t.section,cD=(e,t)=>{let n=rD(t.line);return n===$?$:n===void 0?t.section===lD||oD(e,t)===`malformed`?$:t.section:sD(e,n,t.wanted)},lD={name:``},uD=(e,t)=>{let n=new Map,r=lD;for(let i of eD(e)){let e=ZE(i),a=iD(e)?r:cD(n,{line:e,section:r,wanted:t});if(a===$)return;r=a}return n},dD=`core.hookspath`,fD=`remote.origin.url`,pD=[dD,fD],mD={status:`managed`},hD={status:`missing`},gD=e=>({reason:e,status:`unmanaged`}),_D=e=>({reason:e,status:`unverifiable`}),vD=new Set([`ENOENT`,`ENOTDIR`]),yD=e=>typeof e==`object`&&e&&`code`in e&&typeof e.code==`string`?e.code:void 0,bD=async e=>{try{return await i(e),`present`}catch(e){let t=yD(e);return t!==void 0&&vD.has(t)?`absent`:`unreadable`}},xD=async e=>{try{let t=await i(h(e,`.git`));return t.isSymbolicLink()?gD(`git_is_symlink`):t.isDirectory()?void 0:gD(`git_is_file`)}catch(e){let t=yD(e);return t!==void 0&&vD.has(t)?gD(`no_git`):_D(`git_unreadable`)}},SD=(e,t)=>{let n=e.get(t);if(n===void 0||n.length!==1)return;let[r]=n;return r===void 0||r===``?void 0:r},CD=(e,t,n)=>{try{return Ep(e,{allowFileUrls:n}).key===Ep(t,{allowFileUrls:n}).key}catch{return!1}},wD=e=>(e.get(dD)?.length??0)>1||(e.get(fD)?.length??0)>1,TD=(e,t)=>{let n=uD(e,pD);return n===void 0?_D(`config_malformed`):wD(n)?_D(`duplicate_config_values`):ED(n,t)},ED=(e,t)=>{if(SD(e,dD)!==t.hooksDir)return gD(`no_refs_marker`);let n=SD(e,fD);return n===void 0?gD(`no_origin`):CD(n,t.expectedUrl,t.allowFileUrls)?mD:gD(`origin_mismatch`)},DD={missing:hD,outside:gD(`outside_sources`),unreadable:_D(`path_unreadable`)},OD=async e=>{let t=await H(e.sourcesDir,e.dest);if(t.kind!==`inside`)return t.kind===`unreadable`?await bD(e.sourcesDir)===`absent`?hD:DD.unreadable:DD[t.kind]},kD=async e=>{let t=await OD(e);if(t!==void 0)return t;let n=await xD(e.dest);if(n!==void 0)return n;try{return TD(await s(h(e.dest,`.git`,`config`),`utf8`),e)}catch{return _D(`config_unreadable`)}},AD=function*(e){let t=e.split(`/`);for(let e=t.length-1;e>=1;--e)yield t.slice(0,e).join(`/`)},jD=(e,t)=>{let n=Object.hasOwn(e,t)?e[t]:void 0;if(n!==void 0)return{entry:n,name:t};for(let n of AD(t)){let t=Object.hasOwn(e,n)?e[n]:void 0;if(t!==void 0)return{entry:t,name:n}}},MD=e=>`no registered package or ref matches '${e}' — this does not establish that the repository is untracked; it may be registered under a different identifier. Run: refs list --json`,ND=e=>`ref '${e}' is not in the active refs configuration — to track it: refs add <url>`,PD=e=>`--ref '${e}' matched no configured ref — pass a full ref key or a unique suffix of one. Run: refs list --json`,FD=/^[a-z][a-z0-9+.-]*:\/\//iu,ID=/^git@[^:/\s]+:[^\s]+$/u,LD=e=>FD.test(e)||ID.test(e),RD=(e,t)=>{try{return Ep(e,t)}catch{if(LD(e))throw z(`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}},zD=(e,t,n)=>{let r=RD(t,n);if(r!==void 0){if(Object.hasOwn(e.refs,r.key))return{key:r.key};throw L(ND(r.key),`ref_not_registered`)}},BD=(e,t)=>{let n=[];for(let r of Object.keys(e.refs).toSorted()){let i=e.refs[r]?.packages,a=i!==void 0&&Object.hasOwn(i,t)?i[t]:void 0;a!==void 0&&n.push({entry:a,key:nl.parse(r)})}return n},VD=(e,t,n)=>`package '${e}' is registered by more than one ref: ${t.join(`, `)} — pick one with: refs resolve ${qy(e)} --ref ${qy(n)}`,HD=(e,t)=>{let n=BD(e,t),[r]=n;if(r!==void 0){if(n.length>1)throw R(VD(t,n.map(e=>e.key),r.key));return r}},UD=(e,t)=>{for(let n of AD(t)){let t=HD(e,n);if(t!==void 0)return{...t,name:n}}},WD=(e,t,n)=>{try{return Kw(e,t)}catch(e){throw e instanceof I&&e.code===`not_found`?L(n,`unmatched_query`):e}},GD=(e,t,n)=>{let r=WD(e,n,PD(n)),i=jD(e.refs[r]?.packages??{},t);if(i===void 0)throw L(LD(t)?`ref '${r}' is tracked but registers no package matching that query — inspect: refs show ${qy(r)} --packages --json`:`ref '${r}' is tracked but registers no package matching '${t}' — inspect: refs show ${qy(r)} --packages --json`,`package_not_registered`);return{key:r,packageMatch:{...i,key:r}}},KD=(e,t,n)=>{let r=zD(e,t,n);if(r!==void 0)return r;let i=HD(e,t);if(i!==void 0)return{key:i.key,packageMatch:{...i,name:t}};let a=UD(e,t);return a===void 0?{key:WD(e,t,MD(t))}:{key:a.key,packageMatch:a}},qD=(e,t,n)=>n.ref===void 0?KD(e,t,n):GD(e,t,n.ref),JD=(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},YD=async(e,t,n)=>{let r=await B(e),i=r.refs[t];i!==void 0&&(r.refs[t]={...i,default_branch:n},await yu(e,r))},XD=(e,t,n)=>G(e,`home`,async()=>{n.branchRenamedTo!==void 0&&await YD(e,t,n.branchRenamedTo);let r=await P_(e);r.refs[t]=JD(r.refs[t],n),await F_(e,r)}),ZD=2e3,QD=e=>{if(e.length<=ZD)return e;let t=e.slice(0,1500),n=e.slice(e.length-500),r=e.length-ZD;return`${t}\n… ${String(r)} characters omitted …\n${n}`},$D=async(e,t,n)=>{try{await G(e,`home`,async()=>{let r=await P_(e);r.refs[t]={...r.refs[t],last_error:QD(n)},await F_(e,r)})}catch{}},eO=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()}}},tO=async(e,t)=>{await e.acquire();try{return await t()}finally{e.release()}},nO=(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`,rO=(e,t,n)=>{if(!k_.shape.head_sha.safeParse(n).success)throw z(nO(e,t,n));return n},iO=(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},aO=async(e,t,n)=>{await a(m(n),{recursive:!0});let r=j_(`clone_mode`,t.ref,t.settings),i=await vf(e.runner,{cloneUrl:t.ref.url,dest:n,hooksDir:t.home.hooksDir,mode:r}),o=await bf(e.runner,n),s=await Kb(e.runner,{allowFileUrls:_b(e.env),dest:n,expectedUrl:t.ref.url,hooksDir:t.home.hooksDir,key:t.key});return iO(t,i,{actualBranch:o,headSha:s})},oO=async(e,t,n)=>{await Vb(e.runner,{dest:n,hooksDir:t.home.hooksDir}),await zb(e.runner,{allowFileUrls:_b(e.env),dest:n,expectedUrl:t.ref.url});let r=await Ef(e.runner,{defaultBranch:t.ref.default_branch,dir:n,hooksDir:t.home.hooksDir}),i={headSha:rO(t.key,n,r.newSha),previousSha:r.oldSha,status:r.status};return r.branchRenamedTo!==void 0&&(i.branchRenamedTo=r.branchRenamedTo),r.warning!==void 0&&(i.warning=r.warning),i},sO=(e,t,n)=>(Du(t.home,n),U(n)?oO(e,t,n):aO(e,t,n)),cO={changedDirs:[],kind:`arrivals`,namesBefore:[]},lO=async(e,t,n)=>{if(n.previousSha===void 0)return cO;let r=await Zd(e.runner,{dir:t,from:n.previousSha,to:n.headSha});return r===void 0?cO:{...r,kind:`arrivals`}},uO=(e,t)=>G(t.home,gb(t.key),async()=>{let n=Su(t.home,t.key),r=await sO(e,t,n),i=await lO(e,n,r);return{...r,structure:await nC(n,t.ref,i)}}),dO=(e,t)=>`Syncing refs: ${e}/${t} done`,fO=(e,t)=>{let n=0;return{finished:()=>{n+=1,e.update(dO(n,t))},started:()=>{e.update(dO(n,t))}}},pO=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(` | `)},mO=(e,t)=>{let n={key:e,status:t.status},r=pO(t);return r!==void 0&&(n.warning=r),t.structure!==void 0&&(n.structure=t.structure),n},hO=async(e,t)=>{try{let n=await uO(e,t);return await XD(t.home,t.key,n),n}catch(e){throw await $D(t.home,t.key,Vy(e)),e}},gO=async(e,t)=>{try{return mO(t.key,await hO(e,t))}catch(e){return{error:Vy(e),key:t.key,status:`failed`}}},_O=(e,t)=>e.status===`rejected`?{error:Vy(e.reason),key:t,status:`failed`}:e.value,vO=async(e,t,n)=>{let r=eO(4),i=n===void 0?void 0:fO(n,t.length);return(await Promise.allSettled(t.map(t=>tO(r,async()=>{i?.started();try{return await gO(e,t)}finally{i?.finished()}})))).map((e,n)=>{let r=t[n];if(r===void 0)throw Error(`internal: sync target at index ${n} is missing`);return _O(e,r.key)})},yO=async e=>{let{packageMatch:t}=e.match;return t===void 0?null:await TE({checkoutDir:e.dest,checkoutManaged:e.checkout.status===`managed`||e.checkout.status===`missing`,checkoutReason:`checkout is ${e.checkout.status}`,configuredPath:t.entry.path,home:e.home,key:e.match.key,packageName:t.name})},bO=(e,t,n)=>qD(t,n.query,{allowFileUrls:_b(e.env),...n.ref===void 0?{}:{ref:n.ref}}),xO=async(e,t)=>{let n=V(e.env),r=await B(n);return{config:r,home:n,match:bO(e,r,t),state:await P_(n)}},SO=async(e,t)=>{if(t===void 0)return;let{packageMatch:n}=e;if(n===void 0)throw R(`--project needs a query that names a package; '${e.key}' resolves to the ref itself`);return await HE(t,n.name)},CO=(e,t)=>{if(e.status!==`managed`&&e.status!==`missing`)throw z(`refusing to sync ${t}: its checkout is ${e.status}${e.reason===void 0?``:` (${e.reason})`} — run: refs doctor`)},wO=async(e,t)=>(await hO(e,{home:t.home,key:t.match.key,ref:jw(t.config,t.match.key),settings:t.config.settings})).status,TO=async(e,t)=>{t.project!==void 0&&await BE(t.project);let n=await xO(e,t),r=await DO(e,n,t);return t.syncIfStale!==!0||!(r.stale||r.missing)?r:(CO(r.checkout,r.key),await EO(e,{key:r.key,opts:t,target:n}))},EO=async(e,t)=>{let{key:n,opts:r}=t,i=await wO(e,t.target),a=await xO(e,r);if(a.match.key!==n)throw su(`configuration changed while resolving '${r.query}' — retry`);return{...await DO(e,a,r),sync:{status:i}}},DO=async(e,t,n)=>{let{config:r,home:i,match:a,state:o}=t,{now:s}=n,c=jw(r,a.key),l=Su(i,a.key),u=il(j_(`sync_ttl`,c,r.settings)),d=o.refs[a.key]?.last_fetched_at,f=await kD({allowFileUrls:_b(e.env),dest:l,expectedUrl:c.url,hooksDir:i.hooksDir,sourcesDir:i.sourcesDir}),p=await SO(a,n.project);return{checkout:f,key:a.key,...d===void 0?{}:{last_fetched_at:d},...p===void 0?{}:{installed:p},local_path:l,missing:f.status===`missing`,package:await yO({checkout:f,dest:l,home:i,match:a}),stale:Fw(d,u,s)}},OO=(e,t)=>{let n=[`ref: ${e.key}`,`path: ${e.local_path}`,...Rw({lastFetchedAt:e.last_fetched_at,missing:e.missing,now:t,stale:e.stale}),...e.checkout.status===`managed`||e.checkout.status===`missing`?[]:[`checkout: ${e.checkout.status}${e.checkout.reason===void 0?``:` (${e.checkout.reason})`}`]];return e.package!==null&&n.push(...kE(e.package)),e.sync!==void 0&&n.push(`sync: ${e.sync.status}`),e.installed!==void 0&&n.push(`installed: ${e.installed.version??`(${e.installed.status})`}`,...e.installed.name===void 0?[]:[`installed name: ${e.installed.name}`],...e.installed.reason===void 0?[]:[`installed reason: ${e.installed.reason}`]),n},kO=(e,t,n)=>({now:t,...n.project===void 0?{}:{project:n.project},query:e,...n.ref===void 0?{}:{ref:n.ref},...n.syncIfStale===!0?{syncIfStale:!0}:{}}),AO=(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`).option(`--ref <ref>`,`resolve the query as a package within this ref (full key or unique suffix)`).option(`--project <dir>`,`report the version this project has installed of the query's package`).option(`--sync-if-stale`,`fetch or clone first when the ref is stale or its checkout is absent`).action((e,n,r)=>{let i=X(r);return Q(t,i,async()=>{let r=Date.now(),a=await TO(t,kO(e,r,n));Z(t,i,OO(a,r),a)})()})},jO={},MO=async(e,t)=>{if(!U(t))return{tags:[]};try{let{tags:n}=await Af(e.runner,t,5);return{tags:n}}catch(e){return{tags:[],warning:`could not list tags: ${Vy(e)}`}}},NO=async(e,t,n,r)=>{let i=V(e.env),a=await B(i),o=Kw(a,t),s=jw(a,o),c=await P_(i),l=Su(i,o),{packages:u,...d}=s,f=n.tags?await MO(e,l):void 0,p=c.refs[o]??jO;return{data:{...d,key:o,local_path:l,missing:!U(l),...n.packages?{packages:u??{}}:{},packages_count:Object.keys(u??{}).length,url:ff(s.url),...f===void 0?{}:{sample_tags:f.tags},stale:Fw(p.last_fetched_at,il(j_(`sync_ttl`,s,a.settings)),r),state:p},warnings:By(f?.warning)}},PO=(e,t)=>{let n=[`ref: ${e.key}`,`description: ${e.description}`,`url: ${e.url}`,`path: ${e.local_path}`,...Rw({lastFetchedAt:e.state.last_fetched_at,missing:e.missing,now:t,stale:e.stale})];return e.sample_tags!==void 0&&e.sample_tags.length>0&&n.push(`tags: ${e.sample_tags.join(`, `)}`),n},FO=(e,t)=>{e.command(`show`).description(`Show a configured ref: entry, state, local path, package count; --packages/--tags add the package map and sample tags to --json.`).argument(`<ref>`,`full ref key or a unique suffix, e.g. zod`).option(`--packages`,`include the ref's full package map in --json output (off by default)`).option(`--tags`,`include sample tags in --json output (human output always probes for them)`).action((e,n,r)=>{let i=X(r);return Q(t,i,async()=>{let r={packages:n.packages===!0,tags:!i.json||n.tags===!0},a=Date.now(),{data:o,warnings:s}=await NO(t,e,r,a);Z(t,i,PO(o,a),o,s)})()})},IO=(e,t,n)=>({home:e,key:n,ref:jw(t,n),settings:t.settings}),LO=(e,t,n)=>n.length===0?Object.keys(t.refs).toSorted().map(n=>IO(e,t,nl.parse(n))):n.map(n=>IO(e,t,Kw(t,n))),RO=(e,t,n)=>{let r=Date.now();return t.filter(t=>{let i=il(j_(`sync_ttl`,t.ref,t.settings)),a=Fw(n.refs[t.key]?.last_fetched_at,i,r),o=!U(Su(e,t.key));return a||o})},zO=async(e,t,n)=>{if(!ev({env:e.env,updates:n.updates}))return[];let{latest:r,refreshed:i}=await K_({fetch:e.fetcher,home:t,nowMs:Date.now()});return!i||r===void 0||!q_(e.cliVersion,r)?[]:[J_(e.cliVersion,r)]},BO=async(e,t,n)=>{if(!n)return t;let r=await P_(e);return RO(e,t,r)},VO=e=>{let{config:t,ctx:n,home:r,scoped:i,spinner:a}=e;if(i.length===0)return Promise.resolve([[],[]]);let o={pending:!0};return Promise.all([(async()=>{let e=await vO(n,i,a);return o.pending&&a.update(`Checking for a newer refs release`),e})(),(async()=>{try{return await zO(n,r,t)}finally{o.pending=!1}})()])},HO=async(e,t,n)=>{n.update(`Reading the config`);let r=V(e.env),i=await B(r),a=LO(r,i,t.refs),o=await BO(r,a,t.staleOnly),[s,c]=await VO({config:i,ctx:e,home:r,scoped:o,spinner:n});return{failedCount:s.filter(e=>e.status===`failed`).length,results:s,warnings:c}},UO=[`updated`,`fresh`,`cloned`,`restored`,`failed`],WO={cloned:`Cloned`,failed:`Failed`,fresh:`Fresh`,restored:`Restored`,updated:`Updated`},GO=e=>{let t={cloned:[],failed:[],fresh:[],restored:[],updated:[]};for(let n of e)t[n.status].push(n);return t},KO=e=>{if(e.status===`failed`)return[` ${e.key}: ${e.error??`unknown error`}`];let t=e.warning===void 0?` ${e.key}`:` ${e.key} (${e.warning})`;return e.structure===void 0?[t]:[t,...NS(e.structure,e.key).map(e=>` ${e}`)]},qO=e=>{let t=GO(e),n=[UO.map(e=>`${WO[e]} (${t[e].length})`).join(` / `)];for(let e of UO)for(let r of t[e])n.push(...KO(r));return n},JO=(e,t)=>({refs:e,staleOnly:t.staleOnly===!0}),YO=(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=X(r);return Q(t,i,async()=>{let r=await Wy(t,i,r=>HO(t,JO(e,n),r));Z(t,i,qO(r.results),{results:r.results},r.warnings),r.failedCount>0&&(process.exitCode=ou.UNEXPECTED)})()})},XO=(e,t,n)=>n===void 0?e.tag_format:Nw(e,t,n).tag_format??e.tag_format,ZO=(e,t,n)=>{if(e!==void 0)return e;let r=n===void 0?`ref '${t}'`:`package '${n}'`,i=Xy(n===void 0?[]:[[`--package`,n]],[t,`tag_format`,`<format>`]),a=i===void 0?`set one on this entry — no single-line command can carry these values, so none is offered`:`set one with: ${i}`;throw z(`${r} has no tag_format configured — inspect the repository's real tags and ${a}`)},QO=async(e,t)=>{let n=V(e.env),r=await B(n),i=Kw(r,t.query),a=jw(r,i),o=ZO(XO(a,i,t.opts.packageName),i,t.opts.packageName),s=Su(n,i);Mw(s,i);let c=await Hf(e.runner,s,o,t.version);return{key:i,ref_path:`refs/tags/${c}`,tag:c,version:t.version}},$O=e=>[`${e.key}@${e.version} -> ${e.tag}`],ek=e=>{let t={};return e.package!==void 0&&(t.packageName=e.package),t},tk=[iE,Ax,ZT,qw,Aw,sE,yE,AO,FO,YO,(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. zod`).argument(`<version>`,`version to resolve, e.g. 4.1.0`).option(`--package <name>`,`resolve against this package's tag_format instead of the ref's`).action((e,n,r,i)=>{let a=X(i);return Q(t,a,async()=>{let i=await QO(t,{opts:ek(r),query:e,version:n});Z(t,a,$O(i),i)})()})}],nk=(e,t)=>{for(let n of tk)n(e,t)},rk=[``,`Examples:`,` $ refs list --json`,` $ refs sync --stale-only --json`,` $ refs resolve zod/mini --json`,``,`Every command accepts --json for structured output and --verbose for stack traces on error.`].join(`
|
|
357
|
-
|
|
501
|
+
`?i+=n===`\r`?2:1:(t+=a+(n??``),i+=1)}else a===`"`?n=!n:!n&&(a===`#`||a===`;`)&&(r=!0),t+=a}}t!==``&&(yield t)},dD=(e,t)=>e.subsection===void 0?`${e.name}.${t.toLowerCase()}`:`${e.name}.${e.subsection}.${t.toLowerCase()}`,fD=(e,t)=>{let n=e.toLowerCase();if(t===void 0)return{name:n};let r=aD(t);return r===$?$:{name:n,subsection:r}},pD=e=>{let t=cD.exec(e),n=t?.groups?.section;if(n===void 0)return;let r=sD(e.slice(t?.[0].length??0)),i=fD(n,t?.groups?.subsection);return i===$?$:{rest:r,section:i}},mD=e=>e===``||e.startsWith(`#`)||e.startsWith(`;`),hD=e=>{let t=lD.exec(e),n=t?.groups?.name;if(n===void 0)return $;let r=iD(t?.groups?.value??``);return r===$?$:{name:n,value:r}},gD=(e,t)=>{let n=hD(t.line);if(n===$)return`malformed`;let r=dD(t.section,n.name);return t.wanted.includes(r)&&e.set(r,[...e.get(r)??[],n.value]),`ok`},_D=(e,t,n)=>t.rest===``||mD(t.rest)?t.section:gD(e,{line:t.rest,section:t.section,wanted:n})===`malformed`?$:t.section,vD=(e,t)=>{let n=pD(t.line);return n===$?$:n===void 0?t.section===yD||gD(e,t)===`malformed`?$:t.section:_D(e,n,t.wanted)},yD={name:``},bD=(e,t)=>{let n=/* @__PURE__ */ new Map,r=yD;for(let i of uD(e)){let e=sD(i),a=mD(e)?r:vD(n,{line:e,section:r,wanted:t});if(a===$)return;r=a}return n},xD=`core.hookspath`,SD=`remote.origin.url`,CD=[xD,SD],wD={status:`managed`},TD={status:`missing`},ED=e=>({reason:e,status:`unmanaged`}),DD=e=>({reason:e,status:`unverifiable`}),OD=/* @__PURE__ */ new Set([`ENOENT`,`ENOTDIR`]),kD=e=>typeof e==`object`&&e&&`code`in e&&typeof e.code==`string`?e.code:void 0,AD=async e=>{try{return await i(e),`present`}catch(e){let t=kD(e);return t!==void 0&&OD.has(t)?`absent`:`unreadable`}},jD=async e=>{try{let t=await i(h(e,`.git`));return t.isSymbolicLink()?ED(`git_is_symlink`):t.isDirectory()?void 0:ED(`git_is_file`)}catch(e){let t=kD(e);return t!==void 0&&OD.has(t)?ED(`no_git`):DD(`git_unreadable`)}},MD=(e,t)=>{let n=e.get(t);if(n===void 0||n.length!==1)return;let[r]=n;return r===void 0||r===``?void 0:r},ND=(e,t,n)=>{try{return Fp(e,{allowFileUrls:n}).key===Fp(t,{allowFileUrls:n}).key}catch{return!1}},PD=e=>(e.get(xD)?.length??0)>1||(e.get(SD)?.length??0)>1,FD=(e,t)=>{let n=bD(e,CD);return n===void 0?DD(`config_malformed`):PD(n)?DD(`duplicate_config_values`):ID(n,t)},ID=(e,t)=>{if(MD(e,xD)!==t.hooksDir)return ED(`no_refs_marker`);let n=MD(e,SD);return n===void 0?ED(`no_origin`):ND(n,t.expectedUrl,t.allowFileUrls)?wD:ED(`origin_mismatch`)},LD={missing:TD,outside:ED(`outside_sources`),unreadable:DD(`path_unreadable`)},RD=async e=>{let t=await H(e.sourcesDir,e.dest);if(t.kind!==`inside`)return t.kind===`unreadable`?await AD(e.sourcesDir)===`absent`?TD:LD.unreadable:LD[t.kind]},zD=async e=>{let t=await RD(e);if(t!==void 0)return t;let n=await jD(e.dest);if(n!==void 0)return n;try{return FD(await s(h(e.dest,`.git`,`config`),`utf8`),e)}catch{return DD(`config_unreadable`)}},BD=function*(e){let t=e.split(`/`);for(let e=t.length-1;e>=1;--e)yield t.slice(0,e).join(`/`)},VD=(e,t)=>{let n=Object.hasOwn(e,t)?e[t]:void 0;if(n!==void 0)return{entry:n,name:t};for(let n of BD(t)){let t=Object.hasOwn(e,n)?e[n]:void 0;if(t!==void 0)return{entry:t,name:n}}},HD=e=>`no registered package or ref matches '${e}' — this does not establish that the repository is untracked; it may be registered under a different identifier. Run: refs list --json`,UD=e=>`ref '${e}' is not in the active refs configuration — to track it: refs add <url>`,WD=e=>`--ref '${e}' matched no configured ref — pass a full ref key or a unique suffix of one. Run: refs list --json`,GD=/^[a-z][a-z0-9+.-]*:\/\//iu,KD=/^git@[^:/\s]+:[^\s]+$/u,qD=e=>GD.test(e)||KD.test(e),JD=(e,t)=>{try{return Fp(e,t)}catch{if(qD(e))throw z(`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}},YD=(e,t,n)=>{let r=JD(t,n);if(r!==void 0){if(Object.hasOwn(e.refs,r.key))return{key:r.key};throw gu(UD(r.key),`ref_not_registered`)}},XD=(e,t)=>{let n=[];for(let r of Object.keys(e.refs).toSorted()){let i=e.refs[r]?.packages,a=i!==void 0&&Object.hasOwn(i,t)?i[t]:void 0;a!==void 0&&n.push({entry:a,key:cl.parse(r)})}return n},ZD=(e,t,n)=>`package '${e}' is registered by more than one ref: ${t.join(`, `)} — pick one with: refs resolve ${rb(e)} --ref ${rb(n)}`,QD=(e,t)=>{let n=XD(e,t),[r]=n;if(r!==void 0){if(n.length>1)throw R(ZD(t,n.map(e=>e.key),r.key));return r}},$D=(e,t)=>{for(let n of BD(t)){let t=QD(e,n);if(t!==void 0)return{...t,name:n}}},eO=(e,t,n)=>{try{return nT(e,t)}catch(e){throw e instanceof L&&e.code===`not_found`?gu(n,`unmatched_query`):e}},tO=(e,t,n)=>{let r=eO(e,n,WD(n)),i=VD(e.refs[r]?.packages??{},t);if(i===void 0)throw gu(qD(t)?`ref '${r}' is tracked but registers no package matching that query — inspect: refs show ${rb(r)} --packages --json`:`ref '${r}' is tracked but registers no package matching '${t}' — inspect: refs show ${rb(r)} --packages --json`,`package_not_registered`);return{key:r,packageMatch:{...i,key:r}}},nO=(e,t,n)=>{let r=YD(e,t,n);if(r!==void 0)return r;let i=QD(e,t);if(i!==void 0)return{key:i.key,packageMatch:{...i,name:t}};let a=$D(e,t);return a===void 0?{key:eO(e,t,HD(t))}:{key:a.key,packageMatch:a}},rO=(e,t,n)=>n.ref===void 0?nO(e,t,n):tO(e,t,n.ref),iO=(e,t)=>{let n={head_sha:t.headSha,last_fetched_at:(/* @__PURE__ */ new Date()).toISOString()},r=t.effectiveCloneMode??e?.effective_clone_mode;return r!==void 0&&(n.effective_clone_mode=r),n},aO=async(e,t,n)=>{let r=await B(e),i=r.refs[t];i!==void 0&&(r.refs[t]={...i,default_branch:n},await Ou(e,r))},oO=(e,t,n)=>G(e,`home`,async()=>{n.branchRenamedTo!==void 0&&await aO(e,t,n.branchRenamedTo);let r=await W_(e);r.refs[t]=iO(r.refs[t],n),await G_(e,r)}),sO=2e3,cO=e=>{if(e.length<=sO)return e;let t=e.slice(0,1500),n=e.slice(e.length-500),r=e.length-sO;return`${t}\n… ${String(r)} characters omitted …\n${n}`},lO=async(e,t,n)=>{try{await G(e,`home`,async()=>{let r=await W_(e);r.refs[t]={...r.refs[t],last_error:cO(n)},await G_(e,r)})}catch{}},uO=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()}}},dO=async(e,t)=>{await e.acquire();try{return await t()}finally{e.release()}},fO=(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`,pO=(e,t,n)=>{if(!z_.shape.head_sha.safeParse(n).success)throw z(fO(e,t,n));return n},mO=(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},hO=async(e,t,n)=>{await a(m(n),{recursive:!0});let r=V_(`clone_mode`,t.ref,t.settings),i=await Df(e.runner,{cloneUrl:t.ref.url,dest:n,hooksDir:t.home.hooksDir,mode:r}),o=await kf(e.runner,n),s=await nx(e.runner,{allowFileUrls:Db(e.env),dest:n,expectedUrl:t.ref.url,hooksDir:t.home.hooksDir,key:t.key});return mO(t,i,{actualBranch:o,headSha:s})},gO=async(e,t,n)=>{await Zb(e.runner,{dest:n,hooksDir:t.home.hooksDir}),await Yb(e.runner,{allowFileUrls:Db(e.env),dest:n,expectedUrl:t.ref.url});let r=await Ff(e.runner,{defaultBranch:t.ref.default_branch,dir:n,hooksDir:t.home.hooksDir}),i={headSha:pO(t.key,n,r.newSha),previousSha:r.oldSha,status:r.status};return r.branchRenamedTo!==void 0&&(i.branchRenamedTo=r.branchRenamedTo),r.warning!==void 0&&(i.warning=r.warning),i},_O=(e,t,n)=>(Iu(t.home,n),U(n)?gO(e,t,n):hO(e,t,n)),vO={changedDirs:[],kind:`arrivals`,namesBefore:[]},yO=async(e,t,n)=>{if(n.previousSha===void 0)return vO;let r=await sf(e.runner,{dir:t,from:n.previousSha,to:n.headSha});return r===void 0?vO:{...r,kind:`arrivals`}},bO=(e,t)=>G(t.home,Eb(t.key),async()=>{let n=ju(t.home,t.key),r=await _O(e,t,n),i=await yO(e,n,r);return{...r,structure:await fC(n,t.ref,i)}}),xO=(e,t)=>`Syncing refs: ${e}/${t} done`,SO=(e,t)=>{let n=0;return{finished:()=>{n+=1,e.update(xO(n,t))},started:()=>{e.update(xO(n,t))}}},CO=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(` | `)},wO=(e,t)=>{let n={key:e,status:t.status},r=CO(t);return r!==void 0&&(n.warning=r),t.structure!==void 0&&(n.structure=t.structure),n},TO=async(e,t)=>{try{let n=await bO(e,t);return await oO(t.home,t.key,n),n}catch(e){throw await lO(t.home,t.key,Zy(e)),e}},EO=async(e,t)=>{try{return wO(t.key,await TO(e,t))}catch(e){return{error:Zy(e),key:t.key,status:`failed`}}},DO=(e,t)=>e.status===`rejected`?{error:Zy(e.reason),key:t,status:`failed`}:e.value,OO=async(e,t,n)=>{let r=uO(4),i=n===void 0?void 0:SO(n,t.length);return(await Promise.allSettled(t.map(t=>dO(r,async()=>{i?.started();try{return await EO(e,t)}finally{i?.finished()}})))).map((e,n)=>{let r=t[n];
|
|
502
|
+
/* v8 ignore next 5 -- `settled` is produced by mapping over `targets`, so it is always the
|
|
503
|
+
same length; this only satisfies `noUncheckedIndexedAccess` and can never actually
|
|
504
|
+
trigger. */
|
|
505
|
+
if(r===void 0)throw Error(`internal: sync target at index ${n} is missing`);return DO(e,r.key)})},kO=async e=>{let{packageMatch:t}=e.match;return t===void 0?null:await FE({checkoutDir:e.dest,checkoutManaged:e.checkout.status===`managed`||e.checkout.status===`missing`,checkoutReason:`checkout is ${e.checkout.status}`,configuredPath:t.entry.path,home:e.home,key:e.match.key,packageName:t.name})},AO=(e,t,n)=>rO(t,n.query,{allowFileUrls:Db(e.env),...n.ref===void 0?{}:{ref:n.ref}}),jO=async(e,t)=>{let n=V(e.env),r=await B(n);return{config:r,home:n,match:AO(e,r,t),state:await W_(n)}},MO=async(e,t)=>{if(t===void 0)return;let{packageMatch:n}=e;if(n===void 0)throw R(`--project needs a query that names a package; '${e.key}' resolves to the ref itself`);return await QE(t,n.name)},NO=(e,t)=>{if(e.status!==`managed`&&e.status!==`missing`)throw z(`refusing to sync ${t}: its checkout is ${e.status}${e.reason===void 0?``:` (${e.reason})`} — run: refs doctor`)},PO=async(e,t)=>(await TO(e,{home:t.home,key:t.match.key,ref:Vw(t.config,t.match.key),settings:t.config.settings})).status,FO=async(e,t)=>{t.project!==void 0&&await XE(t.project);let n=await jO(e,t),r=await LO(e,n,t);return t.syncIfStale!==!0||!(r.stale||r.missing)?r:(NO(r.checkout,r.key),await IO(e,{key:r.key,opts:t,target:n}))},IO=async(e,t)=>{let{key:n,opts:r}=t,i=await PO(e,t.target),a=await jO(e,r);
|
|
506
|
+
/* v8 ignore next 6 -- reachable only under real concurrency: a `refs edit` landing inside the
|
|
507
|
+
sync window, between the two config reads. Provoking it deterministically would mean injecting
|
|
508
|
+
a config rewrite into the middle of a real git operation, which is more machinery than the arm
|
|
509
|
+
is worth; the guard exists so the outcome is a clear conflict rather than a reply describing
|
|
510
|
+
one ref while carrying another's sync status. */
|
|
511
|
+
if(a.match.key!==n)throw hu(`configuration changed while resolving '${r.query}' — retry`);return{...await LO(e,a,r),sync:{status:i}}},LO=async(e,t,n)=>{let{config:r,home:i,match:a,state:o}=t,{now:s}=n,c=Vw(r,a.key),l=ju(i,a.key),u=ul(V_(`sync_ttl`,c,r.settings)),d=o.refs[a.key]?.last_fetched_at,f=await zD({allowFileUrls:Db(e.env),dest:l,expectedUrl:c.url,hooksDir:i.hooksDir,sourcesDir:i.sourcesDir}),p=await MO(a,n.project);return{checkout:f,key:a.key,...d===void 0?{}:{last_fetched_at:d},...p===void 0?{}:{installed:p},local_path:l,missing:f.status===`missing`,package:await kO({checkout:f,dest:l,home:i,match:a}),stale:Gw(d,u,s)}},RO=(e,t)=>{let n=[`ref: ${e.key}`,`path: ${e.local_path}`,...Jw({lastFetchedAt:e.last_fetched_at,missing:e.missing,now:t,stale:e.stale}),...e.checkout.status===`managed`||e.checkout.status===`missing`?[]:[`checkout: ${e.checkout.status}${e.checkout.reason===void 0?``:` (${e.checkout.reason})`}`]];return e.package!==null&&n.push(...zE(e.package)),e.sync!==void 0&&n.push(`sync: ${e.sync.status}`),e.installed!==void 0&&n.push(`installed: ${e.installed.version??`(${e.installed.status})`}`,...e.installed.name===void 0?[]:[`installed name: ${e.installed.name}`],...e.installed.reason===void 0?[]:[`installed reason: ${e.installed.reason}`]),n},zO=(e,t,n)=>({now:t,...n.project===void 0?{}:{project:n.project},query:e,...n.ref===void 0?{}:{ref:n.ref},...n.syncIfStale===!0?{syncIfStale:!0}:{}}),BO=(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`).option(`--ref <ref>`,`resolve the query as a package within this ref (full key or unique suffix)`).option(`--project <dir>`,`report the version this project has installed of the query's package`).option(`--sync-if-stale`,`fetch or clone first when the ref is stale or its checkout is absent`).action((e,n,r)=>{let i=X(r);return Q(t,i,async()=>{let r=Date.now(),a=await FO(t,zO(e,r,n));Z(t,i,RO(a,r),a)})()})},VO={},HO=async(e,t)=>{if(!U(t))return{tags:[]};try{let{tags:n}=await zf(e.runner,t,5);return{tags:n}}catch(e){return{tags:[],warning:`could not list tags: ${Zy(e)}`}}},UO=async(e,t,n,r)=>{let i=V(e.env),a=await B(i),o=nT(a,t),s=Vw(a,o),c=await W_(i),l=ju(i,o),{packages:u,...d}=s,f=n.tags?await HO(e,l):void 0,p=c.refs[o]??VO;return{data:{...d,key:o,local_path:l,missing:!U(l),...n.packages?{packages:u??{}}:{},packages_count:Object.keys(u??{}).length,url:xf(s.url),...f===void 0?{}:{sample_tags:f.tags},stale:Gw(p.last_fetched_at,ul(V_(`sync_ttl`,s,a.settings)),r),state:p},warnings:Xy(f?.warning)}},WO=(e,t)=>{let n=[`ref: ${e.key}`,`description: ${e.description}`,`url: ${e.url}`,`path: ${e.local_path}`,...Jw({lastFetchedAt:e.state.last_fetched_at,missing:e.missing,now:t,stale:e.stale})];return e.sample_tags!==void 0&&e.sample_tags.length>0&&n.push(`tags: ${e.sample_tags.join(`, `)}`),n},GO=(e,t)=>{e.command(`show`).description(`Show a configured ref: entry, state, local path, package count; --packages/--tags add the package map and sample tags to --json.`).argument(`<ref>`,`full ref key or a unique suffix, e.g. zod`).option(`--packages`,`include the ref's full package map in --json output (off by default)`).option(`--tags`,`include sample tags in --json output (human output always probes for them)`).action((e,n,r)=>{let i=X(r);return Q(t,i,async()=>{let r={packages:n.packages===!0,tags:!i.json||n.tags===!0},a=Date.now(),{data:o,warnings:s}=await UO(t,e,r,a);Z(t,i,WO(o,a),o,s)})()})},KO=(e,t,n)=>({home:e,key:n,ref:Vw(t,n),settings:t.settings}),qO=(e,t,n)=>n.length===0?Object.keys(t.refs).toSorted().map(n=>KO(e,t,cl.parse(n))):n.map(n=>KO(e,t,nT(t,n))),JO=(e,t,n)=>{let r=Date.now();return t.filter(t=>{let i=ul(V_(`sync_ttl`,t.ref,t.settings)),a=Gw(n.refs[t.key]?.last_fetched_at,i,r),o=!U(ju(e,t.key));return a||o})},YO=async(e,t,n)=>{if(!uv({env:e.env,updates:n.updates}))return[];let{latest:r,refreshed:i}=await nv({fetch:e.fetcher,home:t,nowMs:Date.now()});return!i||r===void 0||!rv(e.cliVersion,r)?[]:[iv(e.cliVersion,r)]},XO=async(e,t,n)=>{if(!n)return t;let r=await W_(e);return JO(e,t,r)},ZO=e=>{let{config:t,ctx:n,home:r,scoped:i,spinner:a}=e;if(i.length===0)return Promise.resolve([[],[]]);let o={pending:!0};return Promise.all([(async()=>{let e=await OO(n,i,a);return o.pending&&a.update(`Checking for a newer refs release`),e})(),(async()=>{try{return await YO(n,r,t)}finally{o.pending=!1}})()])},QO=async(e,t,n)=>{n.update(`Reading the config`);let r=V(e.env),i=await B(r),a=qO(r,i,t.refs),o=await XO(r,a,t.staleOnly),[s,c]=await ZO({config:i,ctx:e,home:r,scoped:o,spinner:n});return{failedCount:s.filter(e=>e.status===`failed`).length,results:s,warnings:c}},$O=[`updated`,`fresh`,`cloned`,`restored`,`failed`],ek={cloned:`Cloned`,failed:`Failed`,fresh:`Fresh`,restored:`Restored`,updated:`Updated`},tk=e=>{let t={cloned:[],failed:[],fresh:[],restored:[],updated:[]};for(let n of e)t[n.status].push(n);return t},nk=e=>{if(e.status===`failed`)return[` ${e.key}: ${e.error??`unknown error`}`];let t=e.warning===void 0?` ${e.key}`:` ${e.key} (${e.warning})`;return e.structure===void 0?[t]:[t,...US(e.structure,e.key).map(e=>` ${e}`)]},rk=e=>{let t=tk(e),n=[$O.map(e=>`${ek[e]} (${t[e].length})`).join(` / `)];for(let e of $O)for(let r of t[e])n.push(...nk(r));return n},ik=(e,t)=>({refs:e,staleOnly:t.staleOnly===!0}),ak=(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=X(r);return Q(t,i,async()=>{let r=await eb(t,i,r=>QO(t,ik(e,n),r));Z(t,i,rk(r.results),{results:r.results},r.warnings),r.failedCount>0&&(process.exitCode=mu.UNEXPECTED)})()})},ok=(e,t,n)=>n===void 0?e.tag_format:Uw(e,t,n).tag_format??e.tag_format,sk=(e,t,n)=>{if(e!==void 0)return e;let r=n===void 0?`ref '${t}'`:`package '${n}'`,i=ob(n===void 0?[]:[[`--package`,n]],[t,`tag_format`,`<format>`]),a=i===void 0?`set one on this entry — no single-line command can carry these values, so none is offered`:`set one with: ${i}`;throw z(`${r} has no tag_format configured — inspect the repository's real tags and ${a}`)},ck=async(e,t)=>{let n=V(e.env),r=await B(n),i=nT(r,t.query),a=Vw(r,i),o=sk(ok(a,i,t.opts.packageName),i,t.opts.packageName),s=ju(n,i);Hw(s,i);let c=await Zf(e.runner,s,o,t.version);return{key:i,ref_path:`refs/tags/${c}`,tag:c,version:t.version}},lk=e=>[`${e.key}@${e.version} -> ${e.tag}`],uk=e=>{let t={};return e.package!==void 0&&(t.packageName=e.package),t},dk=[mE,Bx,sE,rT,Bw,_E,kE,BO,GO,ak,(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. zod`).argument(`<version>`,`version to resolve, e.g. 4.1.0`).option(`--package <name>`,`resolve against this package's tag_format instead of the ref's`).action((e,n,r,i)=>{let a=X(i);return Q(t,a,async()=>{let i=await ck(t,{opts:uk(r),query:e,version:n});Z(t,a,lk(i),i)})()})}],fk=(e,t)=>{for(let n of dk)n(e,t)},pk=[``,`Examples:`,` $ refs list --json`,` $ refs sync --stale-only --json`,` $ refs resolve zod/mini --json`,``,`Every command accepts --json for structured output and --verbose for stack traces on error.`].join(`
|
|
512
|
+
`),mk=/* @__PURE__ */ new Set([`commander.help`,`commander.helpDisplayed`,`commander.version`]),hk=`--json`,gk=`--verbose`,_k=/\n$/u,vk=/^error: /u,yk=e=>e.replace(vk,``),bk=(e,t)=>{for(let n of e){if(n===`--`)return!1;if(n===t)return!0}return!1},xk=e=>bk(e,hk),Sk=e=>bk(e,gk),Ck=(e,t,n)=>n&&t!==void 0?`${e}\n${t}`:e,wk=e=>{let t=new Vy().name(`refs`).description(`Manage git-based reference checkouts shared across a workspace.`).version(Ey).option(hk,`emit machine-readable JSON on stdout instead of human-readable text`).option(gk,`include stack traces in error output`).allowExcessArguments(!1).exitOverride().configureOutput({outputError:()=>{},writeErr:t=>{e.errLine(t.replace(_k,``))},writeOut:t=>{e.out(t.replace(_k,``))}});return t.addHelpText(`after`,pk),fk(t,e),t},Tk=()=>{process.exitCode=mu.OK},Ek=(e,t,n)=>{let r={code:`usage`,message:Ck(yk(n.message),n.stack,t.verbose)};Qy(e,t,r),process.exitCode=mu.USAGE},Dk=(e,t,n)=>{mk.has(n.code)?Tk():Ek(e,t,n)},Ok=(e,t,n)=>{let r=vu(n,{verbose:t.verbose});Qy(e,t,r),process.exitCode=r.exitCode},kk=async(e,t,n)=>{let r={json:xk(n),verbose:Sk(n)};try{await t.parseAsync(n)}catch(t){if(t instanceof Ay){Dk(e,r,t);return}Ok(e,r,t)}},Ak=(e,t)=>kk(e,wk(e),t);
|
|
513
|
+
/* v8 ignore start -- `import.meta.main` is only true when this file IS the process entrypoint;
|
|
514
|
+
the in-process test runner always imports it as a module, so this branch is exercised solely by
|
|
515
|
+
the spawned-CLI bin-stub tests, whose subprocess execution v8 coverage cannot observe. */
|
|
516
|
+
import.meta.main&&await Ak(ky(),process.argv);export{wk as buildProgram,X as cliOptsOf,qy as displaySafe,Z as emit,Qy as emitError,Zy as errorMessageOf,$y as progress,ky as realContext,fk as registerCommands,Ak as run,kk as runProgram,Xy as warningsFor,eb as withSpinner,Q as wrapAction};
|