nipa-cli 0.1.5 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +50 -10
- package/dist/nipa.js +102 -90
- package/package.json +1 -1
package/dist/nipa.js
CHANGED
|
@@ -1,71 +1,71 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{createRequire as
|
|
3
|
-
`),
|
|
4
|
-
`)},
|
|
2
|
+
import{createRequire as $y}from"node:module";var fy=Object.create;var{getPrototypeOf:hy,defineProperty:Jo,getOwnPropertyNames:gy}=Object;var ic=Object.prototype.hasOwnProperty;function yy(e){return this[e]}var by,xy,Mt=(e,t,r)=>{var n=e!=null&&typeof e==="object";if(n){var o=t?by??=new WeakMap:xy??=new WeakMap,s=o.get(e);if(s)return s}r=e!=null?fy(hy(e)):{};let i=t||!e||!e.__esModule||!ic.call(e,"default")?Jo(r,"default",{value:e,enumerable:!0}):r;if(e&&typeof e==="object"||typeof e==="function"){for(let a of gy(e))if(!ic.call(i,a))Jo(i,a,{get:yy.bind(e,a),enumerable:!0})}if(n)o.set(e,i);return i};var qo=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var wy=(e)=>e;function _y(e,t){this[e]=wy.bind(null,t)}var vy=(e,t)=>{for(var r in t)Jo(e,r,{get:t[r],enumerable:!0,configurable:!0,set:_y.bind(t,r)})};var ac=$y(import.meta.url);var dr=qo(function(Mk,Yo){var fn=process||{},cc=fn.argv||[],mn=fn.env||{},ky=!(!!mn.NO_COLOR||cc.includes("--no-color"))&&(!!mn.FORCE_COLOR||cc.includes("--color")||fn.platform==="win32"||(fn.stdout||{}).isTTY&&mn.TERM!=="dumb"||!!mn.CI),Py=(e,t,r=e)=>(n)=>{let o=""+n,s=o.indexOf(t,e.length);return~s?e+Cy(o,t,r,s)+t:e+o+t},Cy=(e,t,r,n)=>{let o="",s=0;do o+=e.substring(s,n)+r,s=n+t.length,n=e.indexOf(t,s);while(~n);return o+e.substring(s)},lc=(e=ky)=>{let t=e?Py:()=>String;return{isColorSupported:e,reset:t("\x1B[0m","\x1B[0m"),bold:t("\x1B[1m","\x1B[22m","\x1B[22m\x1B[1m"),dim:t("\x1B[2m","\x1B[22m","\x1B[22m\x1B[2m"),italic:t("\x1B[3m","\x1B[23m"),underline:t("\x1B[4m","\x1B[24m"),inverse:t("\x1B[7m","\x1B[27m"),hidden:t("\x1B[8m","\x1B[28m"),strikethrough:t("\x1B[9m","\x1B[29m"),black:t("\x1B[30m","\x1B[39m"),red:t("\x1B[31m","\x1B[39m"),green:t("\x1B[32m","\x1B[39m"),yellow:t("\x1B[33m","\x1B[39m"),blue:t("\x1B[34m","\x1B[39m"),magenta:t("\x1B[35m","\x1B[39m"),cyan:t("\x1B[36m","\x1B[39m"),white:t("\x1B[37m","\x1B[39m"),gray:t("\x1B[90m","\x1B[39m"),bgBlack:t("\x1B[40m","\x1B[49m"),bgRed:t("\x1B[41m","\x1B[49m"),bgGreen:t("\x1B[42m","\x1B[49m"),bgYellow:t("\x1B[43m","\x1B[49m"),bgBlue:t("\x1B[44m","\x1B[49m"),bgMagenta:t("\x1B[45m","\x1B[49m"),bgCyan:t("\x1B[46m","\x1B[49m"),bgWhite:t("\x1B[47m","\x1B[49m"),blackBright:t("\x1B[90m","\x1B[39m"),redBright:t("\x1B[91m","\x1B[39m"),greenBright:t("\x1B[92m","\x1B[39m"),yellowBright:t("\x1B[93m","\x1B[39m"),blueBright:t("\x1B[94m","\x1B[39m"),magentaBright:t("\x1B[95m","\x1B[39m"),cyanBright:t("\x1B[96m","\x1B[39m"),whiteBright:t("\x1B[97m","\x1B[39m"),bgBlackBright:t("\x1B[100m","\x1B[49m"),bgRedBright:t("\x1B[101m","\x1B[49m"),bgGreenBright:t("\x1B[102m","\x1B[49m"),bgYellowBright:t("\x1B[103m","\x1B[49m"),bgBlueBright:t("\x1B[104m","\x1B[49m"),bgMagentaBright:t("\x1B[105m","\x1B[49m"),bgCyanBright:t("\x1B[106m","\x1B[49m"),bgWhiteBright:t("\x1B[107m","\x1B[49m")}};Yo.exports=lc();Yo.exports.createColors=lc});var Pc=qo(function(kP,kc){kc.exports=qy;function Jy(e){let t={defaultWidth:0,output:process.stdout,tty:ac("tty")};if(!e)return t;return Object.keys(t).forEach(function(r){if(!e[r])e[r]=t[r]}),e}function qy(e){let t=Jy(e);if(t.output.getWindowSize)return t.output.getWindowSize()[0]||t.defaultWidth;if(t.tty.getWindowSize)return t.tty.getWindowSize()[1]||t.defaultWidth;if(t.output.columns)return t.output.columns;if(process.env.CLI_WIDTH){let r=parseInt(process.env.CLI_WIDTH,10);if(!isNaN(r)&&r!==0)return r}return t.defaultWidth}});var Kc=qo(function(ZP,Gc){var pb=ac("stream");class Bc extends pb{#r=null;constructor(e={}){super(e);this.writable=this.readable=!0,this.muted=!1,this.on("pipe",this._onpipe),this.replace=e.replace,this._prompt=e.prompt||null,this._hadControl=!1}#t(e,t){if(this._dest)return this._dest[e];if(this._src)return this._src[e];return t}#e(e,...t){if(typeof this._dest?.[e]==="function")this._dest[e](...t);if(typeof this._src?.[e]==="function")this._src[e](...t)}get isTTY(){if(this.#r!==null)return this.#r;return this.#t("isTTY",!1)}set isTTY(e){this.#r=e}get rows(){return this.#t("rows")}get columns(){return this.#t("columns")}mute(){this.muted=!0}unmute(){this.muted=!1}_onpipe(e){this._src=e}pipe(e,t){return this._dest=e,super.pipe(e,t)}pause(){if(this._src)return this._src.pause()}resume(){if(this._src)return this._src.resume()}write(e){if(this.muted){if(!this.replace)return!0;if(e.match(/^\u001b/)){if(e.indexOf(this._prompt)===0)e=e.slice(this._prompt.length),e=e.replace(/./g,this.replace),e=this._prompt+e;return this._hadControl=!0,this.emit("data",e)}else{if(this._prompt&&this._hadControl&&e.indexOf(this._prompt)===0)this._hadControl=!1,this.emit("data",this._prompt),e=e.slice(this._prompt.length);e=e.toString().replace(/./g,this.replace)}}this.emit("data",e)}end(e){if(this.muted)if(e&&this.replace)e=e.toString().replace(/./g,this.replace);else e=null;if(e)this.emit("data",e);this.emit("end")}destroy(...e){return this.#e("destroy",...e)}destroySoon(...e){return this.#e("destroySoon",...e)}close(...e){return this.#e("close",...e)}}Gc.exports=Bc});var dt={name:"nipa-cli",version:"0.1.6",description:"The command-line interface for Nipa Cloud",keywords:["cli","keystone","mfa","nipa-cloud","openstack","terraform","totp"],homepage:"https://github.com/PunGrumpy/nipa#readme",bugs:{url:"https://github.com/PunGrumpy/nipa/issues"},license:"MIT",author:{name:"Noppakorn Kaewsalabnil",url:"https://www.pungrumpy.com"},repository:{type:"git",url:"git+https://github.com/PunGrumpy/nipa.git",directory:"packages/cli"},bin:{nipa:"dist/nipa.js"},files:["dist/nipa.js","README.md","LICENSE"],type:"module",publishConfig:{access:"public"},scripts:{dev:"bun src/index.ts",build:"bun build src/index.ts --compile --minify --outfile dist/nipa","build:npm":"bun build src/index.ts --target=node --minify --outfile dist/nipa.js","build:release":"bun scripts/build-release.ts",test:"bun test",typecheck:"tsc --noEmit","check:package":"bun run build:npm && publint",prepack:"bun run build:npm"},devDependencies:{"@inquirer/confirm":"6.3.2","@inquirer/input":"5.1.6","@inquirer/password":"5.2.2","@inquirer/select":"5.2.5","@types/bun":"1.4.2",picocolors:"1.1.1",typescript:"6.0.3",zod:"4.6.5"},preferGlobal:!0,engines:{node:">=22.13.0"}};var Ye=Mt(dr(),1);var N={description:"Print JSON",long:"json",value:{kind:"none"}},mr={description:"Don't ask for confirmation",long:"yes",short:"y",value:{kind:"none"}},Xo={description:"Use this profile (or set NIPA_PROFILE)",long:"profile",short:"P",value:{kind:"profile"}},Qo={description:"Show help",long:"help",short:"h",value:{kind:"none"}},$e=[Xo,{description:"Log each HTTP request (or set NIPA_DEBUG=1)",long:"debug",short:"d",value:{kind:"none"}},{description:"Turn off colors (or set NO_COLOR=1)",long:"no-color",value:{kind:"none"}},Qo,{description:"Show the version",long:"version",short:"v",value:{kind:"none"}}];var uc=["servers","flavors","images","networks","volumes","security-groups","load-balancers","databases"],xe=(e)=>[e.name,...e.aliases??[]],Se=(e)=>e.short?[`--${e.long}`,`-${e.short}`]:[`--${e.long}`],fr=(e)=>{switch(e.kind){case"none":return"";case"text":return` <${e.name}>`;case"choice":return` <${e.choices.join("|")}>`;case"project":return" <project>";case"profile":return" <name>";default:return e}},es=(e)=>e.length===1?e[0]:e[1],hr=(e)=>e.sections.flatMap((t)=>t.commands);var ts=" ",Ey=80,gr=(e,t)=>e.map(([r,n])=>`${ts}${r.padEnd(t)} ${n}`).join(`
|
|
3
|
+
`),pc=(e)=>Math.max(0,...e.map(([t])=>t.length)),dc=(e,t)=>{let r=[],n="";for(let o of e.split(" "))if(n&&t.length+n.length+1+o.length>Ey)r.push(n),n=o;else n=n?`${n} ${o}`:o;return r.push(n),r.map((o)=>`${t}${o}`).join(`
|
|
4
|
+
`)},zy=(e)=>{switch(e.arity){case"one":return`<${e.name}>`;case"optional":return`[${e.name}]`;case"rest":return`[${e.name}...]`;default:return e.arity}},Iy=(e)=>{let[t,...r]=e;if(!t)return[];if(r.length===0&&t.value.kind==="none")return[`[--${t.long}]`];return["[options]"]},Ay=(e)=>{switch(e.kind){case"program":case"openstack":return"<args...>";case"command":return"<command> [args...]";default:return e}},mc=(e)=>{switch(e.kind){case"leaf":return[...e.args.map(zy),...Iy(e.flags)].join(" ");case"group":return`[${e.subcommands.map((t)=>t.name).join("|")}]`;case"passthrough":return Ay(e.target);default:return e}},hn=(e)=>`nipa ${e.map((t)=>t.name).join(" ")}`,yr=(e)=>{let t=mc(es(e));return t?`${hn(e)} ${t}`:hn(e)},Ty=(e)=>{switch(e.kind){case"leaf":return e.flags;case"group":{let t=e.subcommands.flatMap((r)=>r.flags);return t.filter((r,n)=>t.findIndex((o)=>o.long===r.long)===n)}case"passthrough":return[];default:return e}},fc=(e)=>[`${e.short?`-${e.short}, `:" "}--${e.long}${fr(e.value)}`,e.description],rs=(e)=>{let t=mc(e);return[t?`${e.name} ${t}`:e.name,e.summary]},kt=(e,t)=>` ${Ye.default.dim(`${e}:`)}
|
|
5
5
|
|
|
6
6
|
${t}
|
|
7
|
-
`,
|
|
8
|
-
${
|
|
7
|
+
`,hc=(e)=>e.map((t)=>`${ts}${Ye.default.dim(t.description)}
|
|
8
|
+
${ts}${Ye.default.cyan("$")} ${t.command}`).join(`
|
|
9
9
|
|
|
10
|
-
`),
|
|
11
|
-
`)},
|
|
12
|
-
`)};var Vm=["emacs","vim"],Wm=new Set(Vm);function Km(e){return Wm.has(e)}function oi(){let e=process.env.INQUIRER_KEYBINDINGS;if(!e)return[];return Array.from(new Set(e.toLowerCase().split(/[\s,]+/).filter(Km)))}var Lt=(e,t=[])=>e.name==="up"||t.includes("vim")&&e.name==="k"||t.includes("emacs")&&e.ctrl&&e.name==="p",wr=(e,t=[])=>e.name==="down"||t.includes("vim")&&e.name==="j"||t.includes("emacs")&&e.ctrl&&e.name==="n";var Zt=(e)=>e.name==="backspace",Dt=(e)=>e.name==="tab",Fn=(e)=>"1234567890".includes(e.name),Re=(e)=>e.name==="enter"||e.name==="return";class Mn extends Error{name="AbortPromptError";message="Prompt was aborted";constructor(e){super();this.cause=e?.cause}}class Bn extends Error{name="CancelPromptError";message="Prompt was canceled"}class vr extends Error{name="ExitPromptError"}class Gn extends Error{name="HookError"}class Nt extends Error{name="ValidationError"}import{AsyncResource as Ym}from"node:async_hooks";import{AsyncLocalStorage as Jm,AsyncResource as Hm}from"node:async_hooks";var si=new Jm;function qm(e){return{rl:e,hooks:[],hooksCleanup:[],hooksEffect:[],index:0,handleChange(){}}}function ii(e,t){let r=qm(e);return si.run(r,()=>{function n(o){r.handleChange=()=>{r.index=0,o()},r.handleChange()}return t(n)})}function rt(){let e=si.getStore();if(!e)throw new Gn("[Inquirer] Hook functions can only be called from within a prompt");return e}function Vn(){return rt().rl}function Wn(e){let t=(...r)=>{let n=rt(),o=!1,s=n.handleChange;n.handleChange=()=>{o=!0};let i=e(...r);if(o)s();return n.handleChange=s,i};return Hm.bind(t)}function ht(e){let t=rt(),{index:r}=t,n={get(){return t.hooks[r]},set(s){t.hooks[r]=s},initialized:r in t.hooks},o=e(n);return t.index++,o}function ai(){rt().handleChange()}var Ut={queue(e){let t=rt(),{index:r}=t;t.hooksEffect.push(()=>{t.hooksCleanup[r]?.();let n=e(Vn());if(n!=null&&typeof n!=="function")throw new Nt("useEffect return value must be a cleanup function or nothing.");t.hooksCleanup[r]=n})},run(){let e=rt();Wn(()=>{e.hooksEffect.forEach((t)=>{t()}),e.hooksEffect.length=0})()},clearAll(){let e=rt();e.hooksCleanup.forEach((t)=>{t?.()}),e.hooksEffect.length=0,e.hooksCleanup.length=0}};function Xm(e){return typeof e==="function"}function Qm(e){return typeof e==="function"}function N(e){return ht((t)=>{let r=Ym.bind(function(s){let i=t.get(),a=Qm(s)?s(i):s;if(!Object.is(i,a))t.set(a),ai()});if(t.initialized)return[t.get(),r];let n=Xm(e)?e():e;return t.set(n),[n,r]})}function Le(e,t){ht((r)=>{let n=r.get();if(!Array.isArray(n)||t.some((s,i)=>!Object.is(s,n[i])))Ut.queue(e);r.set(t)})}import{styleText as ye}from"node:util";import xe from"node:process";function ef(){if(!xe.platform.startsWith("win"))return xe.env.TERM!=="linux";return Boolean(xe.env.CI)||Boolean(xe.env.WT_SESSION)||Boolean(xe.env.TERMINUS_SUBLIME)||xe.env.ConEmuTask==="{cmd::Cmder}"||xe.env.TERM_PROGRAM==="Terminus-Sublime"||xe.env.TERM_PROGRAM==="vscode"||xe.env.TERM==="xterm-256color"||xe.env.TERM==="alacritty"||xe.env.TERMINAL_EMULATOR==="JetBrains-JediTerm"}var ci={circleQuestionMark:"(?)",questionMarkPrefix:"(?)",square:"█",squareDarkShade:"▓",squareMediumShade:"▒",squareLightShade:"░",squareTop:"▀",squareBottom:"▄",squareLeft:"▌",squareRight:"▐",squareCenter:"■",bullet:"●",dot:"․",ellipsis:"…",pointerSmall:"›",triangleUp:"▲",triangleUpSmall:"▴",triangleDown:"▼",triangleDownSmall:"▾",triangleLeftSmall:"◂",triangleRightSmall:"▸",home:"⌂",heart:"♥",musicNote:"♪",musicNoteBeamed:"♫",arrowUp:"↑",arrowDown:"↓",arrowLeft:"←",arrowRight:"→",arrowLeftRight:"↔",arrowUpDown:"↕",almostEqual:"≈",notEqual:"≠",lessOrEqual:"≤",greaterOrEqual:"≥",identical:"≡",infinity:"∞",subscriptZero:"₀",subscriptOne:"₁",subscriptTwo:"₂",subscriptThree:"₃",subscriptFour:"₄",subscriptFive:"₅",subscriptSix:"₆",subscriptSeven:"₇",subscriptEight:"₈",subscriptNine:"₉",oneHalf:"½",oneThird:"⅓",oneQuarter:"¼",oneFifth:"⅕",oneSixth:"⅙",oneEighth:"⅛",twoThirds:"⅔",twoFifths:"⅖",threeQuarters:"¾",threeFifths:"⅗",threeEighths:"⅜",fourFifths:"⅘",fiveSixths:"⅚",fiveEighths:"⅝",sevenEighths:"⅞",line:"─",lineBold:"━",lineDouble:"═",lineDashed0:"┄",lineDashed1:"┅",lineDashed2:"┈",lineDashed3:"┉",lineDashed4:"╌",lineDashed5:"╍",lineDashed6:"╴",lineDashed7:"╶",lineDashed8:"╸",lineDashed9:"╺",lineDashed10:"╼",lineDashed11:"╾",lineDashed12:"−",lineDashed13:"–",lineDashed14:"‐",lineDashed15:"⁃",lineVertical:"│",lineVerticalBold:"┃",lineVerticalDouble:"║",lineVerticalDashed0:"┆",lineVerticalDashed1:"┇",lineVerticalDashed2:"┊",lineVerticalDashed3:"┋",lineVerticalDashed4:"╎",lineVerticalDashed5:"╏",lineVerticalDashed6:"╵",lineVerticalDashed7:"╷",lineVerticalDashed8:"╹",lineVerticalDashed9:"╻",lineVerticalDashed10:"╽",lineVerticalDashed11:"╿",lineDownLeft:"┐",lineDownLeftArc:"╮",lineDownBoldLeftBold:"┓",lineDownBoldLeft:"┒",lineDownLeftBold:"┑",lineDownDoubleLeftDouble:"╗",lineDownDoubleLeft:"╖",lineDownLeftDouble:"╕",lineDownRight:"┌",lineDownRightArc:"╭",lineDownBoldRightBold:"┏",lineDownBoldRight:"┎",lineDownRightBold:"┍",lineDownDoubleRightDouble:"╔",lineDownDoubleRight:"╓",lineDownRightDouble:"╒",lineUpLeft:"┘",lineUpLeftArc:"╯",lineUpBoldLeftBold:"┛",lineUpBoldLeft:"┚",lineUpLeftBold:"┙",lineUpDoubleLeftDouble:"╝",lineUpDoubleLeft:"╜",lineUpLeftDouble:"╛",lineUpRight:"└",lineUpRightArc:"╰",lineUpBoldRightBold:"┗",lineUpBoldRight:"┖",lineUpRightBold:"┕",lineUpDoubleRightDouble:"╚",lineUpDoubleRight:"╙",lineUpRightDouble:"╘",lineUpDownLeft:"┤",lineUpBoldDownBoldLeftBold:"┫",lineUpBoldDownBoldLeft:"┨",lineUpDownLeftBold:"┥",lineUpBoldDownLeftBold:"┩",lineUpDownBoldLeftBold:"┪",lineUpDownBoldLeft:"┧",lineUpBoldDownLeft:"┦",lineUpDoubleDownDoubleLeftDouble:"╣",lineUpDoubleDownDoubleLeft:"╢",lineUpDownLeftDouble:"╡",lineUpDownRight:"├",lineUpBoldDownBoldRightBold:"┣",lineUpBoldDownBoldRight:"┠",lineUpDownRightBold:"┝",lineUpBoldDownRightBold:"┡",lineUpDownBoldRightBold:"┢",lineUpDownBoldRight:"┟",lineUpBoldDownRight:"┞",lineUpDoubleDownDoubleRightDouble:"╠",lineUpDoubleDownDoubleRight:"╟",lineUpDownRightDouble:"╞",lineDownLeftRight:"┬",lineDownBoldLeftBoldRightBold:"┳",lineDownLeftBoldRightBold:"┯",lineDownBoldLeftRight:"┰",lineDownBoldLeftBoldRight:"┱",lineDownBoldLeftRightBold:"┲",lineDownLeftRightBold:"┮",lineDownLeftBoldRight:"┭",lineDownDoubleLeftDoubleRightDouble:"╦",lineDownDoubleLeftRight:"╥",lineDownLeftDoubleRightDouble:"╤",lineUpLeftRight:"┴",lineUpBoldLeftBoldRightBold:"┻",lineUpLeftBoldRightBold:"┷",lineUpBoldLeftRight:"┸",lineUpBoldLeftBoldRight:"┹",lineUpBoldLeftRightBold:"┺",lineUpLeftRightBold:"┶",lineUpLeftBoldRight:"┵",lineUpDoubleLeftDoubleRightDouble:"╩",lineUpDoubleLeftRight:"╨",lineUpLeftDoubleRightDouble:"╧",lineUpDownLeftRight:"┼",lineUpBoldDownBoldLeftBoldRightBold:"╋",lineUpDownBoldLeftBoldRightBold:"╈",lineUpBoldDownLeftBoldRightBold:"╇",lineUpBoldDownBoldLeftRightBold:"╊",lineUpBoldDownBoldLeftBoldRight:"╉",lineUpBoldDownLeftRight:"╀",lineUpDownBoldLeftRight:"╁",lineUpDownLeftBoldRight:"┽",lineUpDownLeftRightBold:"┾",lineUpBoldDownBoldLeftRight:"╂",lineUpDownLeftBoldRightBold:"┿",lineUpBoldDownLeftBoldRight:"╃",lineUpBoldDownLeftRightBold:"╄",lineUpDownBoldLeftBoldRight:"╅",lineUpDownBoldLeftRightBold:"╆",lineUpDoubleDownDoubleLeftDoubleRightDouble:"╬",lineUpDoubleDownDoubleLeftRight:"╫",lineUpDownLeftDoubleRightDouble:"╪",lineCross:"╳",lineBackslash:"╲",lineSlash:"╱"},ui={tick:"✔",info:"ℹ",warning:"⚠",cross:"✘",squareSmall:"◻",squareSmallFilled:"◼",circle:"◯",circleFilled:"◉",circleDotted:"◌",circleDouble:"◎",circleCircle:"ⓞ",circleCross:"ⓧ",circlePipe:"Ⓘ",radioOn:"◉",radioOff:"◯",checkboxOn:"☒",checkboxOff:"☐",checkboxCircleOn:"ⓧ",checkboxCircleOff:"Ⓘ",pointer:"❯",triangleUpOutline:"△",triangleLeft:"◀",triangleRight:"▶",lozenge:"◆",lozengeOutline:"◇",hamburger:"☰",smiley:"㋡",mustache:"෴",star:"★",play:"▶",nodejs:"⬢",oneSeventh:"⅐",oneNinth:"⅑",oneTenth:"⅒"},tf={tick:"√",info:"i",warning:"‼",cross:"×",squareSmall:"□",squareSmallFilled:"■",circle:"( )",circleFilled:"(*)",circleDotted:"( )",circleDouble:"( )",circleCircle:"(○)",circleCross:"(×)",circlePipe:"(│)",radioOn:"(*)",radioOff:"( )",checkboxOn:"[×]",checkboxOff:"[ ]",checkboxCircleOn:"(×)",checkboxCircleOff:"( )",pointer:">",triangleUpOutline:"∆",triangleLeft:"◄",triangleRight:"►",lozenge:"♦",lozengeOutline:"◊",hamburger:"≡",smiley:"☺",mustache:"┌─┐",star:"✶",play:"►",nodejs:"♦",oneSeventh:"1/7",oneNinth:"1/9",oneTenth:"1/10"},rf={...ci,...ui},nf={...ci,...tf},of=ef(),sf=of?rf:nf,gt=sf,I_=Object.entries(ui);var af={prefix:{idle:ye("blue","?"),done:ye("green",gt.tick)},spinner:{interval:80,frames:["⠋","⠙","⠹","⠸","⠼","⠴","⠦","⠧","⠇","⠏"].map((e)=>ye("yellow",e))},keybindings:[],style:{answer:(e)=>ye("cyan",e),message:(e)=>ye("bold",e),error:(e)=>ye("red",`> ${e}`),defaultAnswer:(e)=>ye("dim",`(${e})`),help:(e)=>ye("dim",e),highlight:(e)=>ye("cyan",e),key:(e)=>ye("cyan",ye("bold",`<${e}>`))}};function li(){return{...af,keybindings:oi()}}function pi(e){if(typeof e!=="object"||e===null)return!1;let t=e;while(Object.getPrototypeOf(t)!==null)t=Object.getPrototypeOf(t);return Object.getPrototypeOf(e)===t}function di(...e){let t={};for(let r of e)for(let[n,o]of Object.entries(r)){let s=t[n];t[n]=pi(s)&&pi(o)?di(s,o):o}return t}function _e(...e){let t=[li(),...e.filter((r)=>r!=null)];return di(...t)}function Ze({status:e="idle",theme:t}){let[r,n]=N(!1),[o,s]=N(0),{prefix:i,spinner:a}=_e(t);if(Le(()=>{if(e==="loading"){let u,l=-1,p=setTimeout(()=>{n(!0),u=setInterval(()=>{l=l+1,s(l%a.frames.length)},a.interval)},300);return()=>{clearTimeout(p),clearInterval(u)}}else n(!1)},[e]),r)return a.frames[o];return typeof i==="string"?i:i[e==="loading"?"idle":e]??i.idle}function Ft(e,t){return ht((r)=>{let n=r.get();if(!r.initialized||n.dependencies.length!==t.length||n.dependencies.some((o,s)=>o!==t[s])){let o=e();return r.set({value:o,dependencies:t}),o}return n.value})}function nt(e){return N({current:e})[0]}function De(e){let t=nt(e);t.current=e,Le((r)=>{let n=!1,o=Wn((s,i)=>{if(n)return;t.current(i,r)});return r.input.on("keypress",o),()=>{n=!0,r.input.removeListener("keypress",o)}},[])}var Ii=mt(fi(),1);var hi=(()=>{let e=/[\uD800-\uDBFF][\uDC00-\uDFFF]/g;return(t)=>{let r=0;e.lastIndex=0;while(e.test(t))r+=1;return t.length-r}})(),gi=(e)=>e===12288||e>=65281&&e<=65376||e>=65504&&e<=65510,xi=(e)=>e===8987||e===9001||e>=12272&&e<=12287||e>=12289&&e<=12350||e>=12441&&e<=12543||e>=12549&&e<=12591||e>=12593&&e<=12686||e>=12688&&e<=12771||e>=12783&&e<=12830||e>=12832&&e<=12871||e>=12880&&e<=19903||e>=65040&&e<=65049||e>=65072&&e<=65106||e>=65108&&e<=65126||e>=65128&&e<=65131||e>=127488&&e<=127490||e>=127504&&e<=127547||e>=127552&&e<=127560||e>=131072&&e<=196605||e>=196608&&e<=262141;var lf=/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]|\u001b\]8;[^;]*;.*?(?:\u0007|\u001b\u005c)/y,pf=/[\x00-\x08\x0A-\x1F\x7F-\x9F]{1,1000}/y,yi=/(?:(?![\uFF61-\uFF9F\uFF00-\uFFEF])[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}\p{Script=Tangut}]){1,1000}/yu,df=/\t{1,1000}/y,_i=/[\u{1F1E6}-\u{1F1FF}]{2}|\u{1F3F4}[\u{E0061}-\u{E007A}]{2}[\u{E0030}-\u{E0039}\u{E0061}-\u{E007A}]{1,3}\u{E007F}|(?:\p{Emoji}\uFE0F\u20E3?|\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation})(?:\u200D(?:\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation}|\p{Emoji}\uFE0F\u20E3?))*/yu,mf=/(?:[\x20-\x7E\xA0-\xFF](?!\uFE0F)){1,1000}/y,ff=/\p{M}+/gu,hf={limit:1/0,ellipsis:""},bi=(e,t={},r={})=>{let n=t.limit??1/0,o=t.ellipsis??"",s=t?.ellipsisWidth??(o?bi(o,hf,r).width:0),i=0,a=r.controlWidth??0,c=r.tabWidth??8,u=r.emojiWidth??2,l=2,p=r.regularWidth??1,d=r.wideWidth??2,m=[[mf,p],[lf,0],[pf,a],[df,c],[_i,u],[yi,d]],f=0,g=0,x=e.length,y=0,w=!1,k=x,I=Math.max(0,n-s),_=0,S=0,O=0,W=0;e:while(!0){if(S>_||g>=x&&g>f){let C=e.slice(_,S)||e.slice(f,g);y=0;for(let A of C.replaceAll(ff,"")){let B=A.codePointAt(0)||0;if(gi(B))W=2;else if(xi(B))W=d;else W=p;if(O+W>I)k=Math.min(k,Math.max(_,f)+y);if(O+W>n){w=!0;break e}y+=A.length,O+=W}_=S=0}if(g>=x)break e;for(let C=0,A=m.length;C<A;C++){let[B,K]=m[C];if(B.lastIndex=g,B.test(e)){if(y=B===yi?hi(e.slice(g,B.lastIndex)):B===_i?1:B.lastIndex-g,W=y*K,O+W>I)k=Math.min(k,g+Math.floor((I-O)/K));if(O+W>n){w=!0;break e}O+=W,_=f,S=g,g=f=B.lastIndex;continue e}}g+=1}return{width:w?I:O,index:w?k:x,truncated:w,ellipsed:w&&n>=s}},wi=bi;var gf={limit:1/0,ellipsis:"",ellipsisWidth:0},xf=(e,t={})=>wi(e,gf,t).width,Ne=xf;var $r="\x1B",ki="",yf=39,Jn="\x07",zi="[",_f="]",Ei="m",Hn=`${_f}8;;`,vi=new RegExp(`(?:\\${zi}(?<code>\\d+)m|\\${Hn}(?<uri>.*)${Jn})`,"y"),$i=(e)=>{if(e>=30&&e<=37)return 39;if(e>=90&&e<=97)return 39;if(e>=40&&e<=47)return 49;if(e>=100&&e<=107)return 49;if(e===1||e===2)return 22;if(e===3)return 23;if(e===4)return 24;if(e===7)return 27;if(e===8)return 28;if(e===9)return 29;if(e===0)return 0;return},Si=(e)=>`${$r}${zi}${e}${Ei}`,Pi=(e)=>`${$r}${Hn}${e}${Jn}`,Kn=(e,t,r)=>{let n=t[Symbol.iterator](),o=!1,s=!1,i=e.at(-1),a=i===void 0?0:Ne(i),c=n.next(),u=n.next(),l=0;while(!c.done){let p=c.value,d=Ne(p);if(a+d<=r)e[e.length-1]+=p;else e.push(p),a=0;if(p===$r||p===ki)o=!0,s=t.startsWith(Hn,l+1);if(o){if(s){if(p===Jn)o=!1,s=!1}else if(p===Ei)o=!1}else if(a+=d,a===r&&!u.done)e.push(""),a=0;c=u,u=n.next(),l+=p.length}if(i=e.at(-1),!a&&i!==void 0&&i.length&&e.length>1)e[e.length-2]+=e.pop()},bf=(e)=>{let t=e.split(" "),r=t.length;while(r){if(Ne(t[r-1]))break;r--}if(r===t.length)return e;return t.slice(0,r).join(" ")+t.slice(r).join("")},wf=(e,t,r={})=>{if(r.trim!==!1&&e.trim()==="")return"";let n="",o,s,i=e.split(" "),a=[""],c=0;for(let p=0;p<i.length;p++){let d=i[p];if(r.trim!==!1){let f=a.at(-1)??"",g=f.trimStart();if(f.length!==g.length)a[a.length-1]=g,c=Ne(g)}if(p!==0){if(c>=t&&(r.wordWrap===!1||r.trim===!1))a.push(""),c=0;if(c||r.trim===!1)a[a.length-1]+=" ",c++}let m=Ne(d);if(r.hard&&m>t){let f=t-c,g=1+Math.floor((m-f-1)/t);if(Math.floor((m-1)/t)<g)a.push("");Kn(a,d,t),c=Ne(a.at(-1)??"");continue}if(c+m>t&&c&&m){if(r.wordWrap===!1&&c<t){Kn(a,d,t),c=Ne(a.at(-1)??"");continue}a.push(""),c=0}if(c+m>t&&r.wordWrap===!1){Kn(a,d,t),c=Ne(a.at(-1)??"");continue}a[a.length-1]+=d,c+=m}if(r.trim!==!1)a=a.map((p)=>bf(p));let u=a.join(`
|
|
13
|
-
`),
|
|
14
|
-
`){if(s)n+=
|
|
15
|
-
`){if(o
|
|
16
|
-
`)}function
|
|
17
|
-
`).flatMap((r)=>
|
|
10
|
+
`),gn=$e.map(fc),ns=(e)=>{let{program:t}=e,r=t.sections.flatMap((i)=>i.commands.map(rs)),n=pc([...r,...gn]),o=t.sections.map((i)=>kt(i.title,gr(i.commands.map(rs),n))),s=Ye.default.dim(`v${e.version}`);return["",` ${Ye.default.bold("nipa")} ${s}`,"",dc(t.summary," "),"",` ${Ye.default.dim("Usage:")} nipa [options] <command>`,"",...o,kt("Global options",gr(gn,n)),kt("Examples",hc(t.examples)),` Run ${Ye.default.bold("nipa <command> --help")} for a command's options.`,""].join(`
|
|
11
|
+
`)},yn=(e)=>{let t=es(e),r=t.kind==="group"?t.subcommands.map(rs):[],n=Ty(t).map(fc),o=pc([...r,...n,...gn]),s=["",` ${Ye.default.dim("Usage:")} ${yr(e)}`,"",dc(t.description??t.summary," "),""];if(r.length>0)s.push(kt("Subcommands",gr(r,o)));if(n.length>0)s.push(kt("Options",gr(n,o)));if(s.push(kt("Global options",gr(gn,o))),t.examples?.length)s.push(kt("Examples",hc(t.examples)));return s.join(`
|
|
12
|
+
`)};var Ry=["emacs","vim"],jy=new Set(Ry);function Oy(e){return jy.has(e)}function gc(){let e=process.env.INQUIRER_KEYBINDINGS;if(!e)return[];return Array.from(new Set(e.toLowerCase().split(/[\s,]+/).filter(Oy)))}var br=(e,t=[])=>e.name==="up"||t.includes("vim")&&e.name==="k"||t.includes("emacs")&&e.ctrl&&e.name==="p",bn=(e,t=[])=>e.name==="down"||t.includes("vim")&&e.name==="j"||t.includes("emacs")&&e.ctrl&&e.name==="n";var xr=(e)=>e.name==="backspace",wr=(e)=>e.name==="tab",os=(e)=>"1234567890".includes(e.name),Xe=(e)=>e.name==="enter"||e.name==="return";class ss extends Error{name="AbortPromptError";message="Prompt was aborted";constructor(e){super();this.cause=e?.cause}}class is extends Error{name="CancelPromptError";message="Prompt was canceled"}class xn extends Error{name="ExitPromptError"}class as extends Error{name="HookError"}class _r extends Error{name="ValidationError"}import{AsyncResource as Zy}from"node:async_hooks";import{AsyncLocalStorage as Ly,AsyncResource as Dy}from"node:async_hooks";var yc=new Ly;function Ny(e){return{rl:e,hooks:[],hooksCleanup:[],hooksEffect:[],index:0,handleChange(){}}}function bc(e,t){let r=Ny(e);return yc.run(r,()=>{function n(o){r.handleChange=()=>{r.index=0,o()},r.handleChange()}return t(n)})}function Pt(){let e=yc.getStore();if(!e)throw new as("[Inquirer] Hook functions can only be called from within a prompt");return e}function cs(){return Pt().rl}function ls(e){let t=(...r)=>{let n=Pt(),o=!1,s=n.handleChange;n.handleChange=()=>{o=!0};let i=e(...r);if(o)s();return n.handleChange=s,i};return Dy.bind(t)}function Bt(e){let t=Pt(),{index:r}=t,n={get(){return t.hooks[r]},set(s){t.hooks[r]=s},initialized:r in t.hooks},o=e(n);return t.index++,o}function xc(){Pt().handleChange()}var vr={queue(e){let t=Pt(),{index:r}=t;t.hooksEffect.push(()=>{t.hooksCleanup[r]?.();let n=e(cs());if(n!=null&&typeof n!=="function")throw new _r("useEffect return value must be a cleanup function or nothing.");t.hooksCleanup[r]=n})},run(){let e=Pt();ls(()=>{e.hooksEffect.forEach((t)=>{t()}),e.hooksEffect.length=0})()},clearAll(){let e=Pt();e.hooksCleanup.forEach((t)=>{t?.()}),e.hooksEffect.length=0,e.hooksCleanup.length=0}};function Uy(e){return typeof e==="function"}function Fy(e){return typeof e==="function"}function J(e){return Bt((t)=>{let r=Zy.bind(function(s){let i=t.get(),a=Fy(s)?s(i):s;if(!Object.is(i,a))t.set(a),xc()});if(t.initialized)return[t.get(),r];let n=Uy(e)?e():e;return t.set(n),[n,r]})}function Qe(e,t){Bt((r)=>{let n=r.get();if(!Array.isArray(n)||t.some((s,i)=>!Object.is(s,n[i])))vr.queue(e);r.set(t)})}import{styleText as je}from"node:util";import Re from"node:process";function My(){if(!Re.platform.startsWith("win"))return Re.env.TERM!=="linux";return Boolean(Re.env.CI)||Boolean(Re.env.WT_SESSION)||Boolean(Re.env.TERMINUS_SUBLIME)||Re.env.ConEmuTask==="{cmd::Cmder}"||Re.env.TERM_PROGRAM==="Terminus-Sublime"||Re.env.TERM_PROGRAM==="vscode"||Re.env.TERM==="xterm-256color"||Re.env.TERM==="alacritty"||Re.env.TERMINAL_EMULATOR==="JetBrains-JediTerm"}var wc={circleQuestionMark:"(?)",questionMarkPrefix:"(?)",square:"█",squareDarkShade:"▓",squareMediumShade:"▒",squareLightShade:"░",squareTop:"▀",squareBottom:"▄",squareLeft:"▌",squareRight:"▐",squareCenter:"■",bullet:"●",dot:"․",ellipsis:"…",pointerSmall:"›",triangleUp:"▲",triangleUpSmall:"▴",triangleDown:"▼",triangleDownSmall:"▾",triangleLeftSmall:"◂",triangleRightSmall:"▸",home:"⌂",heart:"♥",musicNote:"♪",musicNoteBeamed:"♫",arrowUp:"↑",arrowDown:"↓",arrowLeft:"←",arrowRight:"→",arrowLeftRight:"↔",arrowUpDown:"↕",almostEqual:"≈",notEqual:"≠",lessOrEqual:"≤",greaterOrEqual:"≥",identical:"≡",infinity:"∞",subscriptZero:"₀",subscriptOne:"₁",subscriptTwo:"₂",subscriptThree:"₃",subscriptFour:"₄",subscriptFive:"₅",subscriptSix:"₆",subscriptSeven:"₇",subscriptEight:"₈",subscriptNine:"₉",oneHalf:"½",oneThird:"⅓",oneQuarter:"¼",oneFifth:"⅕",oneSixth:"⅙",oneEighth:"⅛",twoThirds:"⅔",twoFifths:"⅖",threeQuarters:"¾",threeFifths:"⅗",threeEighths:"⅜",fourFifths:"⅘",fiveSixths:"⅚",fiveEighths:"⅝",sevenEighths:"⅞",line:"─",lineBold:"━",lineDouble:"═",lineDashed0:"┄",lineDashed1:"┅",lineDashed2:"┈",lineDashed3:"┉",lineDashed4:"╌",lineDashed5:"╍",lineDashed6:"╴",lineDashed7:"╶",lineDashed8:"╸",lineDashed9:"╺",lineDashed10:"╼",lineDashed11:"╾",lineDashed12:"−",lineDashed13:"–",lineDashed14:"‐",lineDashed15:"⁃",lineVertical:"│",lineVerticalBold:"┃",lineVerticalDouble:"║",lineVerticalDashed0:"┆",lineVerticalDashed1:"┇",lineVerticalDashed2:"┊",lineVerticalDashed3:"┋",lineVerticalDashed4:"╎",lineVerticalDashed5:"╏",lineVerticalDashed6:"╵",lineVerticalDashed7:"╷",lineVerticalDashed8:"╹",lineVerticalDashed9:"╻",lineVerticalDashed10:"╽",lineVerticalDashed11:"╿",lineDownLeft:"┐",lineDownLeftArc:"╮",lineDownBoldLeftBold:"┓",lineDownBoldLeft:"┒",lineDownLeftBold:"┑",lineDownDoubleLeftDouble:"╗",lineDownDoubleLeft:"╖",lineDownLeftDouble:"╕",lineDownRight:"┌",lineDownRightArc:"╭",lineDownBoldRightBold:"┏",lineDownBoldRight:"┎",lineDownRightBold:"┍",lineDownDoubleRightDouble:"╔",lineDownDoubleRight:"╓",lineDownRightDouble:"╒",lineUpLeft:"┘",lineUpLeftArc:"╯",lineUpBoldLeftBold:"┛",lineUpBoldLeft:"┚",lineUpLeftBold:"┙",lineUpDoubleLeftDouble:"╝",lineUpDoubleLeft:"╜",lineUpLeftDouble:"╛",lineUpRight:"└",lineUpRightArc:"╰",lineUpBoldRightBold:"┗",lineUpBoldRight:"┖",lineUpRightBold:"┕",lineUpDoubleRightDouble:"╚",lineUpDoubleRight:"╙",lineUpRightDouble:"╘",lineUpDownLeft:"┤",lineUpBoldDownBoldLeftBold:"┫",lineUpBoldDownBoldLeft:"┨",lineUpDownLeftBold:"┥",lineUpBoldDownLeftBold:"┩",lineUpDownBoldLeftBold:"┪",lineUpDownBoldLeft:"┧",lineUpBoldDownLeft:"┦",lineUpDoubleDownDoubleLeftDouble:"╣",lineUpDoubleDownDoubleLeft:"╢",lineUpDownLeftDouble:"╡",lineUpDownRight:"├",lineUpBoldDownBoldRightBold:"┣",lineUpBoldDownBoldRight:"┠",lineUpDownRightBold:"┝",lineUpBoldDownRightBold:"┡",lineUpDownBoldRightBold:"┢",lineUpDownBoldRight:"┟",lineUpBoldDownRight:"┞",lineUpDoubleDownDoubleRightDouble:"╠",lineUpDoubleDownDoubleRight:"╟",lineUpDownRightDouble:"╞",lineDownLeftRight:"┬",lineDownBoldLeftBoldRightBold:"┳",lineDownLeftBoldRightBold:"┯",lineDownBoldLeftRight:"┰",lineDownBoldLeftBoldRight:"┱",lineDownBoldLeftRightBold:"┲",lineDownLeftRightBold:"┮",lineDownLeftBoldRight:"┭",lineDownDoubleLeftDoubleRightDouble:"╦",lineDownDoubleLeftRight:"╥",lineDownLeftDoubleRightDouble:"╤",lineUpLeftRight:"┴",lineUpBoldLeftBoldRightBold:"┻",lineUpLeftBoldRightBold:"┷",lineUpBoldLeftRight:"┸",lineUpBoldLeftBoldRight:"┹",lineUpBoldLeftRightBold:"┺",lineUpLeftRightBold:"┶",lineUpLeftBoldRight:"┵",lineUpDoubleLeftDoubleRightDouble:"╩",lineUpDoubleLeftRight:"╨",lineUpLeftDoubleRightDouble:"╧",lineUpDownLeftRight:"┼",lineUpBoldDownBoldLeftBoldRightBold:"╋",lineUpDownBoldLeftBoldRightBold:"╈",lineUpBoldDownLeftBoldRightBold:"╇",lineUpBoldDownBoldLeftRightBold:"╊",lineUpBoldDownBoldLeftBoldRight:"╉",lineUpBoldDownLeftRight:"╀",lineUpDownBoldLeftRight:"╁",lineUpDownLeftBoldRight:"┽",lineUpDownLeftRightBold:"┾",lineUpBoldDownBoldLeftRight:"╂",lineUpDownLeftBoldRightBold:"┿",lineUpBoldDownLeftBoldRight:"╃",lineUpBoldDownLeftRightBold:"╄",lineUpDownBoldLeftBoldRight:"╅",lineUpDownBoldLeftRightBold:"╆",lineUpDoubleDownDoubleLeftDoubleRightDouble:"╬",lineUpDoubleDownDoubleLeftRight:"╫",lineUpDownLeftDoubleRightDouble:"╪",lineCross:"╳",lineBackslash:"╲",lineSlash:"╱"},_c={tick:"✔",info:"ℹ",warning:"⚠",cross:"✘",squareSmall:"◻",squareSmallFilled:"◼",circle:"◯",circleFilled:"◉",circleDotted:"◌",circleDouble:"◎",circleCircle:"ⓞ",circleCross:"ⓧ",circlePipe:"Ⓘ",radioOn:"◉",radioOff:"◯",checkboxOn:"☒",checkboxOff:"☐",checkboxCircleOn:"ⓧ",checkboxCircleOff:"Ⓘ",pointer:"❯",triangleUpOutline:"△",triangleLeft:"◀",triangleRight:"▶",lozenge:"◆",lozengeOutline:"◇",hamburger:"☰",smiley:"㋡",mustache:"෴",star:"★",play:"▶",nodejs:"⬢",oneSeventh:"⅐",oneNinth:"⅑",oneTenth:"⅒"},By={tick:"√",info:"i",warning:"‼",cross:"×",squareSmall:"□",squareSmallFilled:"■",circle:"( )",circleFilled:"(*)",circleDotted:"( )",circleDouble:"( )",circleCircle:"(○)",circleCross:"(×)",circlePipe:"(│)",radioOn:"(*)",radioOff:"( )",checkboxOn:"[×]",checkboxOff:"[ ]",checkboxCircleOn:"(×)",checkboxCircleOff:"( )",pointer:">",triangleUpOutline:"∆",triangleLeft:"◄",triangleRight:"►",lozenge:"♦",lozengeOutline:"◊",hamburger:"≡",smiley:"☺",mustache:"┌─┐",star:"✶",play:"►",nodejs:"♦",oneSeventh:"1/7",oneNinth:"1/9",oneTenth:"1/10"},Gy={...wc,..._c},Ky={...wc,...By},Vy=My(),Wy=Vy?Gy:Ky,Gt=Wy,sP=Object.entries(_c);var Hy={prefix:{idle:je("blue","?"),done:je("green",Gt.tick)},spinner:{interval:80,frames:["⠋","⠙","⠹","⠸","⠼","⠴","⠦","⠧","⠇","⠏"].map((e)=>je("yellow",e))},keybindings:[],style:{answer:(e)=>je("cyan",e),message:(e)=>je("bold",e),error:(e)=>je("red",`> ${e}`),defaultAnswer:(e)=>je("dim",`(${e})`),help:(e)=>je("dim",e),highlight:(e)=>je("cyan",e),key:(e)=>je("cyan",je("bold",`<${e}>`))}};function vc(){return{...Hy,keybindings:gc()}}function $c(e){if(typeof e!=="object"||e===null)return!1;let t=e;while(Object.getPrototypeOf(t)!==null)t=Object.getPrototypeOf(t);return Object.getPrototypeOf(e)===t}function Sc(...e){let t={};for(let r of e)for(let[n,o]of Object.entries(r)){let s=t[n];t[n]=$c(s)&&$c(o)?Sc(s,o):o}return t}function Oe(...e){let t=[vc(),...e.filter((r)=>r!=null)];return Sc(...t)}function et({status:e="idle",theme:t}){let[r,n]=J(!1),[o,s]=J(0),{prefix:i,spinner:a}=Oe(t);if(Qe(()=>{if(e==="loading"){let l,u=-1,p=setTimeout(()=>{n(!0),l=setInterval(()=>{u=u+1,s(u%a.frames.length)},a.interval)},300);return()=>{clearTimeout(p),clearInterval(l)}}else n(!1)},[e]),r)return a.frames[o];return typeof i==="string"?i:i[e==="loading"?"idle":e]??i.idle}function $r(e,t){return Bt((r)=>{let n=r.get();if(!r.initialized||n.dependencies.length!==t.length||n.dependencies.some((o,s)=>o!==t[s])){let o=e();return r.set({value:o,dependencies:t}),o}return n.value})}function Ct(e){return J({current:e})[0]}function tt(e){let t=Ct(e);t.current=e,Qe((r)=>{let n=!1,o=ls((s,i)=>{if(n)return;t.current(i,r)});return r.input.on("keypress",o),()=>{n=!0,r.input.removeListener("keypress",o)}},[])}var Mc=Mt(Pc(),1);var Cc=(()=>{let e=/[\uD800-\uDBFF][\uDC00-\uDFFF]/g;return(t)=>{let r=0;e.lastIndex=0;while(e.test(t))r+=1;return t.length-r}})(),Ec=(e)=>e===12288||e>=65281&&e<=65376||e>=65504&&e<=65510,zc=(e)=>e===8987||e===9001||e>=12272&&e<=12287||e>=12289&&e<=12350||e>=12441&&e<=12543||e>=12549&&e<=12591||e>=12593&&e<=12686||e>=12688&&e<=12771||e>=12783&&e<=12830||e>=12832&&e<=12871||e>=12880&&e<=19903||e>=65040&&e<=65049||e>=65072&&e<=65106||e>=65108&&e<=65126||e>=65128&&e<=65131||e>=127488&&e<=127490||e>=127504&&e<=127547||e>=127552&&e<=127560||e>=131072&&e<=196605||e>=196608&&e<=262141;var Yy=/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]|\u001b\]8;[^;]*;.*?(?:\u0007|\u001b\u005c)/y,Xy=/[\x00-\x08\x0A-\x1F\x7F-\x9F]{1,1000}/y,Ic=/(?:(?![\uFF61-\uFF9F\uFF00-\uFFEF])[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}\p{Script=Tangut}]){1,1000}/yu,Qy=/\t{1,1000}/y,Ac=/[\u{1F1E6}-\u{1F1FF}]{2}|\u{1F3F4}[\u{E0061}-\u{E007A}]{2}[\u{E0030}-\u{E0039}\u{E0061}-\u{E007A}]{1,3}\u{E007F}|(?:\p{Emoji}\uFE0F\u20E3?|\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation})(?:\u200D(?:\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation}|\p{Emoji}\uFE0F\u20E3?))*/yu,eb=/(?:[\x20-\x7E\xA0-\xFF](?!\uFE0F)){1,1000}/y,tb=/\p{M}+/gu,rb={limit:1/0,ellipsis:""},Tc=(e,t={},r={})=>{let n=t.limit??1/0,o=t.ellipsis??"",s=t?.ellipsisWidth??(o?Tc(o,rb,r).width:0),i=0,a=r.controlWidth??0,c=r.tabWidth??8,l=r.emojiWidth??2,u=2,p=r.regularWidth??1,d=r.wideWidth??2,f=[[eb,p],[Yy,0],[Xy,a],[Qy,c],[Ac,l],[Ic,d]],h=0,y=0,b=e.length,_=0,P=!1,O=b,D=Math.max(0,n-s),S=0,T=0,U=0,ce=0;e:while(!0){if(T>S||y>=b&&y>h){let L=e.slice(S,T)||e.slice(h,y);_=0;for(let F of L.replaceAll(tb,"")){let ne=F.codePointAt(0)||0;if(Ec(ne))ce=2;else if(zc(ne))ce=d;else ce=p;if(U+ce>D)O=Math.min(O,Math.max(S,h)+_);if(U+ce>n){P=!0;break e}_+=F.length,U+=ce}S=T=0}if(y>=b)break e;for(let L=0,F=f.length;L<F;L++){let[ne,le]=f[L];if(ne.lastIndex=y,ne.test(e)){if(_=ne===Ic?Cc(e.slice(y,ne.lastIndex)):ne===Ac?1:ne.lastIndex-y,ce=_*le,U+ce>D)O=Math.min(O,y+Math.floor((D-U)/le));if(U+ce>n){P=!0;break e}U+=ce,S=h,T=y,y=h=ne.lastIndex;continue e}}y+=1}return{width:P?D:U,index:P?O:b,truncated:P,ellipsed:P&&n>=s}},Rc=Tc;var nb={limit:1/0,ellipsis:"",ellipsisWidth:0},ob=(e,t={})=>Rc(e,nb,t).width,rt=ob;var wn="\x1B",Nc="",sb=39,ps="\x07",Zc="[",ib="]",Uc="m",ds=`${ib}8;;`,jc=new RegExp(`(?:\\${Zc}(?<code>\\d+)m|\\${ds}(?<uri>.*)${ps})`,"y"),Oc=(e)=>{if(e>=30&&e<=37)return 39;if(e>=90&&e<=97)return 39;if(e>=40&&e<=47)return 49;if(e>=100&&e<=107)return 49;if(e===1||e===2)return 22;if(e===3)return 23;if(e===4)return 24;if(e===7)return 27;if(e===8)return 28;if(e===9)return 29;if(e===0)return 0;return},Lc=(e)=>`${wn}${Zc}${e}${Uc}`,Dc=(e)=>`${wn}${ds}${e}${ps}`,us=(e,t,r)=>{let n=t[Symbol.iterator](),o=!1,s=!1,i=e.at(-1),a=i===void 0?0:rt(i),c=n.next(),l=n.next(),u=0;while(!c.done){let p=c.value,d=rt(p);if(a+d<=r)e[e.length-1]+=p;else e.push(p),a=0;if(p===wn||p===Nc)o=!0,s=t.startsWith(ds,u+1);if(o){if(s){if(p===ps)o=!1,s=!1}else if(p===Uc)o=!1}else if(a+=d,a===r&&!l.done)e.push(""),a=0;c=l,l=n.next(),u+=p.length}if(i=e.at(-1),!a&&i!==void 0&&i.length&&e.length>1)e[e.length-2]+=e.pop()},ab=(e)=>{let t=e.split(" "),r=t.length;while(r){if(rt(t[r-1]))break;r--}if(r===t.length)return e;return t.slice(0,r).join(" ")+t.slice(r).join("")},cb=(e,t,r={})=>{if(r.trim!==!1&&e.trim()==="")return"";let n="",o,s,i=e.split(" "),a=[""],c=0;for(let p=0;p<i.length;p++){let d=i[p];if(r.trim!==!1){let h=a.at(-1)??"",y=h.trimStart();if(h.length!==y.length)a[a.length-1]=y,c=rt(y)}if(p!==0){if(c>=t&&(r.wordWrap===!1||r.trim===!1))a.push(""),c=0;if(c||r.trim===!1)a[a.length-1]+=" ",c++}let f=rt(d);if(r.hard&&f>t){let h=t-c,y=1+Math.floor((f-h-1)/t);if(Math.floor((f-1)/t)<y)a.push("");us(a,d,t),c=rt(a.at(-1)??"");continue}if(c+f>t&&c&&f){if(r.wordWrap===!1&&c<t){us(a,d,t),c=rt(a.at(-1)??"");continue}a.push(""),c=0}if(c+f>t&&r.wordWrap===!1){us(a,d,t),c=rt(a.at(-1)??"");continue}a[a.length-1]+=d,c+=f}if(r.trim!==!1)a=a.map((p)=>ab(p));let l=a.join(`
|
|
13
|
+
`),u=!1;for(let p=0;p<l.length;p++){let d=l[p];if(n+=d,!u){if(u=d>="\uD800"&&d<="\uDBFF",u)continue}else u=!1;if(d===wn||d===Nc){jc.lastIndex=p+1;let h=jc.exec(l)?.groups;if(h?.code!==void 0){let y=Number.parseFloat(h.code);o=y===sb?void 0:y}else if(h?.uri!==void 0)s=h.uri.length===0?void 0:h.uri}if(l[p+1]===`
|
|
14
|
+
`){if(s)n+=Dc("");let f=o?Oc(o):void 0;if(o&&f)n+=Lc(f)}else if(d===`
|
|
15
|
+
`){if(o&&Oc(o))n+=Lc(o);if(s)n+=Dc(s)}}return n},lb=/\r?\n/;function Fc(e,t,r){return String(e).normalize().split(lb).map((n)=>cb(n,t,r)).join(`
|
|
16
|
+
`)}function Sr(e,t){return e.split(`
|
|
17
|
+
`).flatMap((r)=>Fc(r,t,{trim:!1,wordWrap:!1}).split(`
|
|
18
18
|
`).map((n)=>n.trimEnd())).join(`
|
|
19
|
-
`)}function
|
|
20
|
-
`)}),c=a.reduce((
|
|
21
|
-
`)}var
|
|
22
|
-
`).length,
|
|
23
|
-
`).pop()??"";class
|
|
19
|
+
`)}function _n(){return Mc.default({defaultWidth:80,output:cs().output})}function ub({active:e,renderedItems:t,pageSize:r,loop:n}){let o=Ct({lastPointer:e,lastActive:void 0}),{lastPointer:s,lastActive:i}=o.current,a=Math.floor(r/2),c=t.reduce((p,d)=>p+d.length,0),l=t.slice(0,e).reduce((p,d)=>p+d.length,0),u=l;if(c>r)if(n){if(u=s,i!=null&&i<e&&e-i<r)u=Math.min(a,Math.abs(e-i)===1?Math.min(s+(t[i]?.length??0),Math.max(l,s)):s+e-i)}else{let p=t.slice(e).reduce((d,f)=>d+f.length,0);u=p<r-a?r-p:Math.min(l,a)}return o.current.lastPointer=u,o.current.lastActive=e,u}function ms({items:e,active:t,renderItem:r,pageSize:n,loop:o=!0}){let s=_n(),i=(_)=>(_%e.length+e.length)%e.length,a=e.map((_,P)=>{if(_==null)return[];return Sr(r({item:_,index:P,isActive:P===t}),s).split(`
|
|
20
|
+
`)}),c=a.reduce((_,P)=>_+P.length,0),l=(_)=>a[_]??[],u=ub({active:t,renderedItems:a,pageSize:n,loop:o}),p=l(t).slice(0,n),d=u+p.length<=n?u:n-p.length,f=Array.from({length:n});f.splice(d,p.length,...p);let h=new Set([t]),y=d+p.length,b=i(t+1);while(y<n&&!h.has(b)&&(o&&c>n?b!==t:b>t)){let P=l(b).slice(0,n-y);f.splice(y,P.length,...P),h.add(b),y+=P.length,b=i(b+1)}y=d-1,b=i(t-1);while(y>=0&&!h.has(b)&&(o&&c>n?b!==t:b<t)){let _=l(b),P=_.slice(Math.max(0,_.length-y-1));f.splice(y-P.length+1,P.length,...P),h.add(b),y-=P.length,b=i(b-1)}return f.filter((_)=>typeof _==="string").join(`
|
|
21
|
+
`)}var el=Mt(Kc(),1);import*as Qc from"node:readline";import{AsyncResource as gb}from"node:async_hooks";var Et=[];Et.push("SIGHUP","SIGINT","SIGTERM");if(process.platform!=="win32")Et.push("SIGALRM","SIGABRT","SIGVTALRM","SIGXCPU","SIGXFSZ","SIGUSR2","SIGTRAP","SIGSYS","SIGQUIT","SIGIOT");if(process.platform==="linux")Et.push("SIGIO","SIGPOLL","SIGPWR","SIGSTKFLT");var vn=(e)=>!!e&&typeof e==="object"&&typeof e.removeListener==="function"&&typeof e.emit==="function"&&typeof e.reallyExit==="function"&&typeof e.listeners==="function"&&typeof e.kill==="function"&&typeof e.pid==="number"&&typeof e.on==="function",fs=Symbol.for("signal-exit emitter"),hs=globalThis,db=Object.defineProperty.bind(Object);class Vc{emitted={afterExit:!1,exit:!1};listeners={afterExit:[],exit:[]};count=0;id=Math.random();constructor(){if(hs[fs])return hs[fs];db(hs,fs,{value:this,writable:!1,enumerable:!1,configurable:!1})}on(e,t){this.listeners[e].push(t)}removeListener(e,t){let r=this.listeners[e],n=r.indexOf(t);if(n===-1)return;if(n===0&&r.length===1)r.length=0;else r.splice(n,1)}emit(e,t,r){if(this.emitted[e])return!1;this.emitted[e]=!0;let n=!1;for(let o of this.listeners[e])n=o(t,r)===!0||n;if(e==="exit")n=this.emit("afterExit",t,r)||n;return n}}class ys{}var mb=(e)=>({onExit(t,r){return e.onExit(t,r)},load(){return e.load()},unload(){return e.unload()}});class Wc extends ys{onExit(){return()=>{}}load(){}unload(){}}class Hc extends ys{#r=gs.platform==="win32"?"SIGINT":"SIGHUP";#t=new Vc;#e;#s;#i;#o={};#n=!1;constructor(e){super();this.#e=e,this.#o={};for(let t of Et)this.#o[t]=()=>{let r=this.#e.listeners(t),{count:n}=this.#t,o=e;if(typeof o.__signal_exit_emitter__==="object"&&typeof o.__signal_exit_emitter__.count==="number")n+=o.__signal_exit_emitter__.count;if(r.length===n){this.unload();let s=this.#t.emit("exit",null,t),i=t==="SIGHUP"?this.#r:t;if(!s)e.kill(e.pid,i)}};this.#i=e.reallyExit,this.#s=e.emit}onExit(e,t){if(!vn(this.#e))return()=>{};if(this.#n===!1)this.load();let r=t?.alwaysLast?"afterExit":"exit";return this.#t.on(r,e),()=>{if(this.#t.removeListener(r,e),this.#t.listeners.exit.length===0&&this.#t.listeners.afterExit.length===0)this.unload()}}load(){if(this.#n)return;this.#n=!0,this.#t.count+=1;for(let e of Et)try{let t=this.#o[e];if(t)this.#e.on(e,t)}catch(t){}this.#e.emit=(e,...t)=>this.#c(e,...t),this.#e.reallyExit=(e)=>this.#a(e)}unload(){if(!this.#n)return;this.#n=!1,Et.forEach((e)=>{let t=this.#o[e];if(!t)throw Error("Listener not defined for signal: "+e);try{this.#e.removeListener(e,t)}catch(r){}}),this.#e.emit=this.#s,this.#e.reallyExit=this.#i,this.#t.count-=1}#a(e){if(!vn(this.#e))return 0;return this.#e.exitCode=e||0,this.#t.emit("exit",this.#e.exitCode,null),this.#i.call(this.#e,this.#e.exitCode)}#c(e,...t){let r=this.#s;if(e==="exit"&&vn(this.#e)){if(typeof t[0]==="number")this.#e.exitCode=t[0];let n=r.call(this.#e,e,...t);return this.#t.emit("exit",this.#e.exitCode,null),n}else return r.call(this.#e,e,...t)}}var gs=globalThis.process,{onExit:Jc,load:MP,unload:BP}=mb(vn(gs)?new Hc(gs):new Wc);import{stripVTControlCharacters as fb}from"node:util";var bs="\x1B[G",$n="\x1B[?25l",Yc="\x1B[?25h",xs=(e=1)=>e>0?`\x1B[${e}A`:"",ws=(e=1)=>e>0?`\x1B[${e}B`:"",_s=(e,t)=>{if(typeof t==="number"&&!Number.isNaN(t))return`\x1B[${t+1};${e+1}H`;return`\x1B[${e+1}G`},qc="\x1B[2K",vs=(e)=>e>0?(qc+xs(1)).repeat(e-1)+qc+bs:"";var Xc=(e)=>e.split(`
|
|
22
|
+
`).length,hb=(e)=>e.split(`
|
|
23
|
+
`).pop()??"";class Sn{height=0;extraLinesUnderPrompt=0;cursorPos;rl;constructor(e){this.rl=e,this.cursorPos=e.getCursorPos()}write(e){this.rl.output.unmute(),this.rl.output.write(e),this.rl.output.mute()}render(e,t=""){let r=hb(e),n=fb(r),o=n;if(this.rl.line.length>0)o=o.slice(0,-this.rl.line.length);this.rl.setPrompt(o),this.cursorPos=this.rl.getCursorPos();let s=_n();if(e=Sr(e,s),t=Sr(t,s),n.length%s===0)e+=`
|
|
24
24
|
`;let i=e+(t?`
|
|
25
|
-
`+t:""),c=Math.floor(n.length/s)-this.cursorPos.rows+(t?
|
|
26
|
-
`,t+=
|
|
27
|
-
at ${
|
|
28
|
-
`);return[
|
|
29
|
-
`).trimEnd()}${
|
|
30
|
-
`)},
|
|
25
|
+
`+t:""),c=Math.floor(n.length/s)-this.cursorPos.rows+(t?Xc(t):0);if(c>0)i+=xs(c);i+=_s(this.cursorPos.cols),this.write(ws(this.extraLinesUnderPrompt)+vs(this.height)+i),this.extraLinesUnderPrompt=c,this.height=Xc(i)}checkCursorPos(){let e=this.rl.getCursorPos();if(e.cols!==this.cursorPos.cols)this.write(_s(e.cols)),this.cursorPos=e}done({clearContent:e}){this.rl.setPrompt("");let t=ws(this.extraLinesUnderPrompt);t+=e?vs(this.height):`
|
|
26
|
+
`,t+=bs,t+=Yc,this.write(t),this.rl.close()}}class $s extends Promise{static withResolver(){let e,t;return{promise:new Promise((n,o)=>{e=n,t=o}),resolve:e,reject:t}}}import yb from"node:path";var bb=globalThis.setImmediate;function kn(e,t,r){if("on"in e)return e.on(t,r),()=>e.removeListener(t,r);return e.addEventListener(t,r),()=>e.removeEventListener(t,r)}function xb(){let e=Error.prepareStackTrace,t=[];try{Error.prepareStackTrace=(r,n)=>{let o=n.slice(1);return t=o,o},Error().stack}catch{return t}return Error.prepareStackTrace=e,t}function nt(e){let t=xb();return(n,o={})=>{let{input:s=process.stdin,signal:i}=o,a=new Set,c=new el.default;c.pipe(o.output??process.stdout);let l=Qc.createInterface({terminal:!0,input:s,output:c});c.mute();let u=new Sn(l),{promise:p,resolve:d,reject:f}=$s.withResolver();return bc(l,(h)=>{let y=gb.bind(()=>vr.clearAll()),b=(S)=>{try{y(),S()}catch(T){f(T)}},_=(S)=>b(()=>d(S)),P=(S)=>b(()=>f(S)),O=Object.assign(p.finally(()=>{a.forEach((S)=>S()),u.done({clearContent:Boolean(o.clearPromptOnDone)}),c.end()}).then(()=>p),{cancel:()=>P(new is)});if(i){let S=()=>P(new ss({cause:i.reason}));if(i.aborted)return S(),O;a.add(kn(i,"abort",S))}a.add(Jc((S,T)=>{P(new xn(`User force closed the prompt with ${S} ${T}`))})),a.add(kn(l,"SIGINT",()=>P(new xn("User force closed the prompt with SIGINT")))),a.add(kn(l,"close",y));let D=()=>{a.add(kn(l.input,"keypress",()=>u.checkCursorPos()));let S=null;h(()=>{let T=!1;try{let U=e(n,(F)=>{if(T)_(F);else S={value:F}});if(U===void 0){let F=t[1]?.getFileName();if(F&&!F.startsWith("file://"))F=yb.resolve(F);throw Error(`Prompt functions must return a string.
|
|
27
|
+
at ${F}`)}let[ce,L]=typeof U==="string"?[U]:U;u.render(ce,L),vr.run()}catch(U){P(U)}if(T=!0,S!==null){let{value:U}=S;S=null,_(U)}})};if("readableFlowing"in s)bb(D);else D();return O})}}import{styleText as wb}from"node:util";class Me{separator=wb("dim",Array.from({length:15}).join(Gt.line));type="separator";constructor(e){if(e)this.separator=e}static isSeparator(e){return Boolean(e&&typeof e==="object"&&"type"in e&&e.type==="separator")}}import{styleText as _b}from"node:util";var vb={keywords:{yes:"Yes",no:"No"},style:{confirmDefault:(e)=>{let t=e[0]??"";if(t.toLowerCase()===t.toUpperCase())return _b("cyan",e);return t.toUpperCase()+e.slice(1)}}},tl=nt((e,t)=>{let[r,n]=J("idle"),[o,s]=J(""),i=Oe(vb,e.theme),a=et({status:r,theme:i}),{yes:c,no:l}=i.keywords,u=(c[0]??"").toLowerCase(),p=(l[0]??"").toLowerCase(),d=e.default===!1?`${u}/${i.style.confirmDefault(p)}`:`${i.style.confirmDefault(u)}/${p}`;function f(O){return O?c:l}let{transformer:h=f}=e;function y(O,D){let S=O.trim().toLowerCase();if(S==="")return D!==!1;if(c.toLowerCase().startsWith(S))return!0;if(l.toLowerCase().startsWith(S))return!1;return D!==!1}tt((O,D)=>{if(r!=="idle")return;if(Xe(O)){let S=y(o,e.default);s(h(S)),n("done"),t(S)}else if(wr(O)){let S=f(!y(o,e.default));D.clearLine(0),D.write(S),s(S)}else s(D.line)});let b=o,_="";if(r==="done")b=i.style.answer(o);else _=` ${i.style.defaultAnswer(d)}`;let P=i.style.message(e.message,r);return`${a} ${P}${_} ${b}`});var $b={validationFailureMode:"keep"},rl=nt((e,t)=>{let{prefill:r="tab"}=e,n=Oe($b,e.theme),[o,s]=J("idle"),[i,a]=J(String(e.default??"")),[c,l]=J(),[u,p]=J(""),d=et({status:o,theme:n});async function f(P){let{required:O,pattern:D,patternError:S="Invalid input"}=e;if(O&&!P)return"You must provide a value";if(D&&!D.test(P))return S;if(typeof e.validate==="function")return await e.validate(P)||"You must provide a valid value";return!0}tt(async(P,O)=>{if(o!=="idle")return;if(Xe(P)){let D=u||i;s("loading");let S=await f(D);if(S===!0)p(D),s("done"),t(D);else{if(n.validationFailureMode==="clear")p("");else O.write(u);l(S),s("idle")}}else if(xr(P)&&!u)a("");else if(wr(P)&&!u)a(""),O.clearLine(0),O.write(i),p(i);else p(O.line),l(void 0)}),Qe((P)=>{if(r==="editable"&&i)P.write(i),p(i)},[]);let h=n.style.message(e.message,o),y=u;if(typeof e.transformer==="function")y=e.transformer(u,{isFinal:o==="done"});else if(o==="done")y=n.style.answer(u);let b;if(i&&o!=="done"&&!u)b=n.style.defaultAnswer(i);let _="";if(c)_=n.style.error(c);return[[d,h,b,y].filter((P)=>P!==void 0).join(" "),_]});import{styleText as Ss}from"node:util";var Sb={style:{maskedText:"[input is masked]",keysHelpTip:(e)=>e.map(([t,r])=>`${Ss("bold",t)} ${Ss("dim",r)}`).join(Ss("dim"," • "))}},nl=nt((e,t)=>{let{toggleMask:r=!0,validate:n=()=>!0}=e,o=Oe(Sb,e.theme),[s,i]=J("idle"),[a,c]=J(),[l,u]=J(""),[p,d]=J(!1),f=et({status:s,theme:o});tt(async(O,D)=>{if(s!=="idle")return;if(Xe(O)){let S=l;i("loading");let T=await n(S);if(T===!0)u(S),i("done"),t(S);else D.write(l),c(T||"You must provide a valid value"),i("idle")}else if(r&&O.ctrl&&O.name==="t")d((S)=>!S);else u(D.line),c(void 0)});let h=o.style.message(e.message,s),y=r&&p&&s==="idle",b="";if(y)b=l;else if(e.mask)b=(typeof e.mask==="string"?e.mask:"*").repeat(l.length);else if(s!=="done")b=o.style.help(o.style.maskedText);if(s==="done")b=o.style.answer(b);else if(!e.mask)b+=$n;let _=[f,h,b].filter(Boolean).join(" "),P=[a?o.style.error(a):"",r&&s==="idle"?o.style.keysHelpTip([["ctrl+t","toggle visibility"]]):""].filter(Boolean).join(`
|
|
28
|
+
`);return[_,P]});import{styleText as kr}from"node:util";var kb={icon:{cursor:Gt.pointer},style:{disabled:(e)=>kr("dim",e),description:(e)=>kr("cyan",e),keysHelpTip:(e)=>e.map(([t,r])=>`${kr("bold",t)} ${kr("dim",r)}`).join(kr("dim"," • "))},i18n:{disabledError:"This option is disabled and cannot be selected."},indexMode:"hidden"};function ks(e){return!Me.isSeparator(e)&&!e.disabled}function Ps(e){return!Me.isSeparator(e)}function Pb(e){return e.map((t)=>{if(Me.isSeparator(t))return t;if(typeof t!=="object"||t===null||!("value"in t)){let o=String(t);return{value:t,name:o,short:o,disabled:!1}}let r=t.name??String(t.value),n={value:t.value,name:r,short:t.short??r,disabled:t.disabled??!1};if(t.description)n.description=t.description;return n})}var ol=nt((e,t)=>{let{loop:r=!0,pageSize:n=7}=e,o=Oe(kb,e.theme),{keybindings:s}=o,[i,a]=J("idle"),c=et({status:i,theme:o}),l=Ct(),u=!s.includes("vim"),p=$r(()=>Pb(e.choices),[e.choices]),d=$r(()=>{let L=p.findIndex(Ps),F=p.findLastIndex(Ps);if(L===-1)throw new _r("[select prompt] No selectable choices. All choices are disabled.");return{first:L,last:F}},[p]),f=$r(()=>{if(!("default"in e))return-1;return p.findIndex((L)=>ks(L)&&L.value===e.default)},[e.default,p]),[h,y]=J(f===-1?d.first:f),b=p[h];if(b==null||Me.isSeparator(b))throw Error("Active index does not point to a choice");let[_,P]=J();tt((L,F)=>{if(clearTimeout(l.current),_)P(void 0);if(Xe(L))if(b.disabled)P(o.i18n.disabledError);else a("done"),t(b.value);else if(br(L,s)||bn(L,s)){if(F.clearLine(0),r||br(L,s)&&h!==d.first||bn(L,s)&&h!==d.last){let ne=br(L,s)?-1:1,le=h;do le=(le+ne+p.length)%p.length;while(!Ps(p[le]));y(le)}}else if(os(L)&&!Number.isNaN(Number(F.line))){let ne=Number(F.line)-1,le=-1,Te=p.findIndex((pr)=>{if(Me.isSeparator(pr))return!1;return le++,le===ne}),Ho=p[Te];if(Ho!=null&&ks(Ho))y(Te);l.current=setTimeout(()=>{F.clearLine(0)},700)}else if(xr(L))F.clearLine(0);else if(u){let ne=F.line.toLowerCase(),le=p.findIndex((Te)=>{if(Me.isSeparator(Te)||!ks(Te))return!1;return Te.name.toLowerCase().startsWith(ne)});if(le!==-1)y(le);l.current=setTimeout(()=>{F.clearLine(0)},700)}}),Qe(()=>()=>{clearTimeout(l.current)},[]);let O=o.style.message(e.message,i),D=o.style.keysHelpTip([["↑↓","navigate"],["⏎","select"]]),S=0,T=ms({items:p,active:h,renderItem({item:L,isActive:F,index:ne}){if(Me.isSeparator(L))return S++,` ${L.separator}`;let le=F?o.icon.cursor:" ",Te=o.indexMode==="number"?`${ne+1-S}. `:"";if(L.disabled){let pr=typeof L.disabled==="string"?L.disabled:"(disabled)",my=F?o.icon.cursor:"-";return o.style.disabled(`${my} ${Te}${L.name} ${pr}`)}return(F?o.style.highlight:(pr)=>pr)(`${le} ${Te}${L.name}`)},pageSize:n,loop:r});if(i==="done")return[c,O,o.style.answer(b.short)].filter(Boolean).join(" ");let{description:U}=b;return`${[[c,O].filter(Boolean).join(" "),T," ",U?o.style.description(U):"",_?o.style.error(_):"",D].filter(Boolean).join(`
|
|
29
|
+
`).trimEnd()}${$n}`});var Le=Mt(dr(),1);class E extends Error{hint;exitCode;constructor(e,t={}){super(e);this.name="CliError",this.hint=t.hint,this.exitCode=t.exitCode??1}}var Z=(e,t)=>new E(e,{exitCode:2,hint:t}),R=(e)=>e<1000?`${Math.round(e)}ms`:`${Math.round(e/1000)}s`,Cb=[["d",86400000],["h",3600000],["m",60000],["s",1000]],V=(e)=>{let t=Math.max(0,e);for(let[r,n]of Cb)if(t>=n)return`${Math.round(t/n)}${r}`;return`${Math.round(t)}ms`},Pr=(e)=>`${Number((e/1024).toFixed(1))} GB`,ke=(e,t)=>`${e} ${t}${e===1?"":"s"}`,al=(e)=>e.charAt(0).toUpperCase()+e.slice(1),zt=(e)=>{let t=e.at(-1)??"",r=e.slice(0,-1);return r.length===0?t:`${r.join(", ")} and ${t}`},Kt=(e)=>{let t=Math.max(0,Math.floor(e/60000)),r=Math.floor(t/60);return r>0?`${r}h ${t%60}m`:`${t}m`},oe=(e)=>{process.stderr.write(`${e}
|
|
30
|
+
`)},w=(e)=>{oe(`${Le.default.dim(">")} ${e}`)},Q=(e,t)=>{let r=t===void 0?"":`[${R(t)}]`,n=r?` ${Le.default.dim(r)}`:"";oe(`${Le.default.cyan("> Success!")} ${e}${n}`)},G=(e)=>{oe(`${Le.default.bold(Le.default.yellow("> NOTE:"))} ${e}`)},cl=(e)=>{if(oe(`${Le.default.bold(Le.default.red("Error:"))} ${e.message}`),e.hint)oe(`${Le.default.dim(">")} ${e.hint}`)},sl=["⠋","⠙","⠹","⠸","⠼","⠴","⠦","⠧","⠇","⠏"],Eb=300,zb="\r\x1B[2K",I=async(e,t)=>{if(!process.stderr.isTTY)return t();let r=0,n=!1,o,s=()=>{n=!0;let a=sl[r%sl.length]??"";r+=1,process.stderr.write(`\r${Le.default.dim(a)} ${e}`)},i=setTimeout(()=>{s(),o=setInterval(s,80)},Eb);try{return await t()}finally{if(clearTimeout(i),clearInterval(o),n)process.stderr.write(zb)}},Pn=async(e)=>{try{return await e()}catch(t){if(t instanceof Error&&t.name==="ExitPromptError")throw new E("Canceled",{exitCode:130});throw t}},ll=(e)=>{let t={output:e.stderr};return{choice:(r)=>Pn(()=>ol(r,t)),confirm:(r)=>Pn(()=>tl(r,t)),interactive:e.stdin.isTTY===!0&&e.stderr.isTTY===!0,secret:(r)=>Pn(()=>nl({mask:"*",message:r},t)),text:(r)=>Pn(()=>rl({...r,required:r.required??!0},t))}},ul=(e)=>({isTTY:e.isTTY===!0,json:(t)=>{e.write(`${JSON.stringify(t,null,2)}
|
|
31
31
|
`)},line:(t)=>{e.write(`${t}
|
|
32
|
-
`)},write:(t)=>{e.write(t)}}),{bold:P,cyan:Bf,dim:H,gray:We,green:Ir,red:Xi,yellow:Qi}=be.default,Gf=" ".repeat(5),Vf=(e)=>P(Bf(e)),ke=(e)=>{let{headings:t,marks:r,rows:n}=e,o=t.map((i,a)=>Math.max(i.length,...n.map((c)=>c[a]?.text.length??0))),s=(i)=>i.map((a,c)=>{let l=c===i.length-1?a.text:a.text.padEnd(o[c]??0);return a.paint?a.paint(l):l}).join(Gf);ie(""),ie(` ${s(t.map((i)=>({paint:Vf,text:i})))}`);for(let[i,a]of n.entries())ie(`${r?.[i]??" "} ${s(a)}`);ie("")};var ra=(e)=>new Map(e.flatMap((t)=>se(t).map((r)=>[r,t]))),mo=(e)=>`Use one of: ${e.join(", ")}.`,na=(e,t)=>{if(e.value.kind==="choice"&&!e.value.choices.includes(t))throw Z(`unknown ${e.long} "${t}"`,mo(e.value.choices));return t},ea=(e)=>{let{flag:t,hints:r,name:n,next:o}=e;if(o===void 0||o.startsWith("-"))throw Z(`${n} needs${Ot(t.value)}`,`Usage: ${r.usage}`);return na(t,o)},oa=(e)=>{let{hints:t,index:r,next:n,word:o}=e;if(o.startsWith("--")){let l=o.indexOf("="),p=l===-1?o:o.slice(0,l),d=r.get(p);if(!d)return;if(d.value.kind==="none"){if(l!==-1)throw Z(`${p} doesn't take a value`,`Usage: ${t.usage}`);return{options:[{flag:d,value:!0}],used:1}}if(l!==-1)return{options:[{flag:d,value:na(d,o.slice(l+1))}],used:1};return{options:[{flag:d,value:ea({flag:d,hints:t,name:p,next:n})}],used:2}}let s=[...o].slice(1),a=s.map((l)=>r.get(`-${l}`)).filter((l)=>l!==void 0);if(a.length!==s.length)return;let c=[],u=1;for(let[l,p]of a.entries())if(p.value.kind==="none")c.push({flag:p,value:!0});else if(l===a.length-1)c.push({flag:p,value:ea({flag:p,hints:t,name:`-${s[l]}`,next:n})}),u=2;else throw Z(`-${s[l]} needs${Ot(p.value)}`,`Usage: ${t.usage}`);return{options:c,used:u}},po=(e,t)=>{let r=e.flatMap((n)=>{let o=t.get(n.long);return o===void 0?[]:[[n.long,o]]});return Object.fromEntries(r)},Wf={command:"nipa",usage:"nipa [options] <command>"},Kf=ra(oe),ta=(e)=>{let{at:t,words:r}=e,n=r[t];if(n===void 0||n==="--"||n==="-"||!n.startsWith("-"))return;let o=oa({hints:Wf,index:Kf,next:r[t+1],word:n});if(!o&&e.unknown==="reject")throw Z(`unknown option "${n}"`,"Run `nipa --help` to see the options.");return o},fo=(e)=>{let{unknown:t,words:r}=e,n=new Map,o=0;for(let s=ta({at:o,unknown:t,words:r});s!==void 0;s=ta({at:o,unknown:t,words:r})){for(let{flag:i,value:a}of s.options)n.set(i.long,a);o+=s.used}return{globals:po(oe,n),rest:r.slice(o)}},sa=(e)=>{let t=e.indexOf("--"),r=t===-1?e:e.slice(0,t),n=new Set(se(Ln));return r.some((o)=>n.has(o))},Jf=(e)=>{let{flags:t,hints:r,words:n}=e,o=ra([...t,...oe]),s=new Set(t.map((l)=>l.long)),i=new Map,a=new Map,c=[],u=0;while(u<n.length){let l=n[u]??"";if(l==="--"){c.push(...n.slice(u+1));break}if(l.startsWith("-")&&l!=="-"){let p=oa({hints:r,index:o,next:n[u+1],word:l});if(!p)throw Z(`unknown option "${l}"`,`Run \`${r.command} --help\` to see the options.`);for(let{flag:d,value:m}of p.options)(s.has(d.long)?i:a).set(d.long,m);u+=p.used}else c.push(l),u+=1}return{globals:a,own:i,positionals:c}},lo=(e,t)=>{if(e.value.kind==="choice"&&!e.value.choices.includes(t))throw Z(`unknown ${e.name} "${t}"`,mo(e.value.choices));return t},Hf=(e)=>{let t=[...e.positionals],r=e.args.map((o)=>{switch(o.arity){case"one":{let s=t.shift();if(s===void 0)throw Z(`missing <${o.name}>`,o.value.kind==="choice"?mo(o.value.choices):`Usage: ${e.hints.usage}`);return[o.name,lo(o,s)]}case"optional":{let s=t.shift();return[o.name,s===void 0?void 0:lo(o,s)]}case"rest":return[o.name,t.splice(0).map((s)=>lo(o,s))];default:return o.arity}}),[n]=t;if(n!==void 0)throw Z(`unexpected argument "${n}"`,`Usage: ${e.hints.usage}`);return Object.fromEntries(r)},ia=(e)=>{let{path:t,spec:r,words:n}=e,o={command:yr(t),usage:Rt(t)},s=Jf({flags:r.flags,hints:o,words:n});return{globals:po(oe,s.globals),input:{args:Hf({args:r.args,hints:o,positionals:s.positionals}),flags:po(r.flags,s.own)}}};var L=(e)=>({...e,kind:"leaf"}),ze=(e)=>({...e,kind:"group"}),yt=(e)=>({...e,kind:"passthrough"}),j=(e,t)=>({kind:"leaf",prepare:({path:r,words:n})=>{let o=ia({path:r,spec:e,words:n});return{globals:o.globals,run:(s)=>t({...o.input,client:s})}},spec:e}),Ee=(e,t)=>{let r=Object.values(t),n=new Map(r.flatMap((o)=>X(o.spec).map((s)=>[s,o])));return{fallback:t[e.default],kind:"group",spec:e,subcommands:n}},qf=(e,t)=>{let{target:r}=e;switch(r.kind){case"program":return{args:t,command:r.program};case"openstack":return{args:t,command:"openstack"};case"command":{let[n,...o]=t;if(n===void 0)throw Z("missing <command>",`Usage: ${Rt([e])}`);return{args:o,command:n}}default:return r}},_t=(e,t)=>({kind:"passthrough",run:({client:r,words:n})=>t({...qf(e,n),client:r}),spec:e}),aa=(e)=>e.spec,Tr=(e)=>({examples:e.examples,hidden:e.hidden.map(aa),sections:e.sections.map((t)=>({commands:t.commands.map(aa),title:t.title})),summary:e.summary});function Wt(e){let t=Object.values(e).filter((n)=>typeof n==="number");return Object.entries(e).filter(([n,o])=>t.indexOf(+n)===-1).map(([n,o])=>o)}function go(e,t="|"){return e.map((r)=>_o(r)).join(t)}function Kt(e,t){if(typeof t==="bigint")return t.toString();return t}class ca{constructor(e){this._getter=e,this._value=void 0}get value(){let e=this._getter;if(e!==void 0)this._value=e(),this._getter=void 0;return this._value}}function Or(e){return new ca(e)}function ua(e){return e===null||e===void 0}function Ar(e){let t=e.startsWith("^")?1:0,r=e.endsWith("$")?e.length-1:e.length;return e.slice(t,r)}function la(e,t){let r=e/t,n=Math.round(r),o=4*Number.EPSILON*Math.max(Math.abs(r),1);if(Math.abs(r-n)<o)return 0;return r-n}function ve(e,t,r){Object.defineProperty(e,t,{value:r,writable:!0,enumerable:!0,configurable:!0})}function jr(e){let t=Object.getOwnPropertyDescriptor(e,"shape");return t?.get?t.get.raw:t?.value}function Fe(e){return jr(e._zod.def)??e._zod.def.shape}function pa(e,t,r){Object.defineProperty(e,t,{get(){let n=r();return ve(this,t,n),n},enumerable:!0,configurable:!0})}function da(e,t,r){if(t in e)ve(e,t,r);else e[t]=r}function st(e,t,r,n){let o=Fe(t);for(let s of r){let i=Object.getOwnPropertyDescriptor(o,s);if(!i.enumerable)continue;if(i.get)pa(e,s,()=>{let a=t._zod.def.shape[s];return n?n(a,s):a});else da(e,s,n?n(i.value,s):i.value)}}function Yf(e,t){for(let r of Reflect.ownKeys(t)){let n=Object.getOwnPropertyDescriptor(t,r);if(!n.enumerable)continue;if(n.get)pa(e,r,()=>t[r]);else da(e,r,n.value)}}function ae(...e){let t={};for(let r of e){let n=Object.getOwnPropertyDescriptors(r);Object.assign(t,n)}return Object.defineProperties({},t)}function ma(e){return JSON.stringify(e)}function fa(e){return e.toLowerCase().trim().replace(/[^\w\s-]/g,"").replace(/[\s_-]+/g,"-").replace(/^-+|-+$/g,"")}var xo="captureStackTrace"in Error?Error.captureStackTrace:(...e)=>{};function Vt(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}var ha=Or(()=>{if(ee.jitless)return!1;if(typeof navigator<"u"&&navigator?.userAgent?.includes("Cloudflare"))return!1;try{return new Function(""),!0}catch(e){return!1}});function it(e){if(Vt(e)===!1)return!1;let t=e.constructor;if(t===void 0)return!0;if(typeof t!=="function")return!0;let r=t.prototype;if(Vt(r)===!1)return!1;if(Object.prototype.hasOwnProperty.call(r,"isPrototypeOf")===!1)return!1;return!0}function yo(e){if(it(e))return{...e};if(Array.isArray(e))return[...e];if(e instanceof Map)return new Map(e);if(e instanceof Set)return new Set(e);return e}var ga=new Set(["string","number","symbol"]);function bt(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function $e(e,t,r){let n=new e._zod.constr(t??e._zod.def);if(!t||r?.parent)n._zod.parent=e;return n}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}if(delete t.message,typeof t.error==="string")return{...t,error:()=>t.error};return t}function _o(e){if(typeof e==="bigint")return e.toString()+"n";if(typeof e==="string")return`"${e}"`;return`${e}`}function xa(e){return Object.keys(e).filter((t)=>e[t]._zod.optin!==void 0&&e[t]._zod.optout==="optional")}var Rr=(()=>({safeint:[Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER],int32:[-2147483648,2147483647],uint32:[0,4294967295],float32:[-340282346638528860000000000000000000000,340282346638528860000000000000000000000],float64:[-Number.MAX_VALUE,Number.MAX_VALUE]}))(),bo={int64:[BigInt("-9223372036854775808"),BigInt("9223372036854775807")],uint64:[BigInt(0),BigInt("18446744073709551615")]};function Xf(e,t){let r=e._zod.def,n=r.checks;if(n&&n.length>0)throw Error(".pick() cannot be used on object schemas containing refinements");let s={};return st(s,e,Lr(e,t)),$e(e,ae(r,{shape:s,checks:[]}))}function Lr(e,t){let r=Fe(e),n=[];for(let o of Reflect.ownKeys(t)){if(!Object.getOwnPropertyDescriptor(r,o)?.enumerable)throw Error(`Unrecognized key: "${String(o)}"`);if(t[o])n.push(o)}return n}function Qf(e,t){let r=e._zod.def,n=r.checks;if(n&&n.length>0)throw Error(".omit() cannot be used on object schemas containing refinements");let s=new Set(Lr(e,t)),i={};return st(i,e,Reflect.ownKeys(Fe(e)).filter((a)=>!s.has(a))),$e(e,ae(r,{shape:i,checks:[]}))}function eh(e,t){if(!it(t))throw Error("Invalid input to extend: expected a plain object");let r=e._zod.def.checks;if(r&&r.length>0){let o=Fe(e);for(let s of Reflect.ownKeys(t))if(Object.getOwnPropertyDescriptor(o,s)!==void 0)throw Error("Cannot overwrite keys on object schemas containing refinements. Use `.safeExtend()` instead.")}return $e(e,ae(e._zod.def,{shape:ya(e,t)}))}function ya(e,t){let r={};return st(r,e,Reflect.ownKeys(Fe(e))),Yf(r,t),r}function th(e,t){if(!it(t))throw Error("Invalid input to safeExtend: expected a plain object");return $e(e,ae(e._zod.def,{shape:ya(e,t)}))}function rh(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 r={};st(r,e,Reflect.ownKeys(Fe(e))),st(r,t,Reflect.ownKeys(Fe(t)));let n=ae(e._zod.def,{shape:r,get catchall(){return t._zod.def.catchall},checks:t._zod.def.checks??[]});return $e(e,n)}function _a(e,t,r,n="partial"){let s=t._zod.def.checks;if(s&&s.length>0)throw Error(`.${n}() cannot be used on object schemas containing refinements`);let a=r?new Set(Lr(t,r)):void 0,c={};return st(c,t,Reflect.ownKeys(Fe(t)),e&&((u,l)=>a&&!a.has(l)?u:new e({type:"optional",innerType:u}))),$e(t,ae(t._zod.def,{shape:c,checks:[]}))}function nh(e,t,r){let n=r?new Set(Lr(t,r)):void 0,o={};return st(o,t,Reflect.ownKeys(Fe(t)),(s,i)=>n&&!n.has(i)?s:new e({type:"nonoptional",innerType:s})),$e(t,ae(t._zod.def,{shape:o}))}function Ce(e,t=0){if(e.aborted===!0)return!0;for(let r=t;r<e.issues.length;r++)if(e.issues[r]?.continue!==!0)return!0;return!1}function ba(e,t=0){if(e.aborted===!0)return!0;for(let r=t;r<e.issues.length;r++)if(e.issues[r]?.continue===!1)return!0;return!1}function Je(e,t){return t.map((r)=>{var n;return(n=r).path??(n.path=[]),r.path.unshift(e),r})}function Gt(e){return typeof e==="string"?e:e?.message}function wo(e,t,r){var n;for(let o=t;o<e.length;o++)(n=e[o]).schema??(n.schema=r)}function Ie(e,t,r){var n;let o=e.inst?._zod?.traits;if(o?.has("$ZodType"))if(o.has("$ZodCheck"))(n=e).schema??(n.schema=e.inst);else e.schema=e.inst;let s=e.schema!==e.inst?e.schema?._zod.def?.error:void 0,i=e.message?e.message:Gt(e.inst?._zod.def?.error?.(e))??Gt(s?.(e))??Gt(t?.error?.(e))??Gt(r.customError?.(e))??Gt(r.localeError?.(e))??"Invalid input",a={};for(let c of Object.keys(e)){if(c==="inst"||c==="schema"||c==="continue"||c==="input"||c==="__proto__")continue;a[c]=e[c]}if(a.path??(a.path=[]),a.message=i,t?.reportInput)a.input=e.input;return a}var oh=/[\uD800-\uDBFF]/;function Zr(e){let t=e.length;if(!oh.test(e))return t;let r=t;for(let n=0;n<t-1;n++)if((e.charCodeAt(n)&64512)===55296&&(e.charCodeAt(n+1)&64512)===56320)r--,n++;return r}function Dr(e){if(Array.isArray(e))return"array";if(typeof e==="string")return"string";return"unknown"}function wa(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 r=e;if(r&&Object.getPrototypeOf(r)!==Object.prototype&&"constructor"in r&&r.constructor)return r.constructor.name}}return t}function at(...e){let[t,r,n]=e;if(typeof t==="string")return{message:t,code:"custom",input:r,inst:n};return{...t}}function va(e,t){for(let r in t){let n=Object.getOwnPropertyDescriptor(t,r);if(n.get)Object.defineProperty(e,r,{...n,enumerable:!1});else sh(e,r,n.value)}}function Me(e,t,r,n=!0){return Object.defineProperty(e,t,{configurable:!0,writable:!0,enumerable:n,value:r}),r}function Nr(e,t,r){return Me(e,t,r,!1)}function $a(e,t){for(let r in e){let n=e[r];Object.defineProperty(t,r,{configurable:!0,enumerable:!0,get(){return Me(this,r,n(this))},set(o){Me(this,r,o)}})}return t}function sh(e,t,r){Object.defineProperty(e,t,{configurable:!0,get(){return this==null?r:Me(this,t,r.bind(this))},set(n){Me(this,t,n)}})}function ih(e,t){let r=Object.getPrototypeOf(e);return t in r?void 0:r}var ho,Ke=!1,ah={configurable:!0,get(){Ke=!0;return}};function R(e,t,r){let n=Object.getPrototypeOf(e._zod);if(t in n&&ho!==e._zod){ho=void 0;return}ho=e._zod,Object.defineProperty(n,t,{configurable:!0,get(){Object.defineProperty(this,t,ah);let o=Ke;Ke=!1;try{let s=r(this);if(Ke)delete this[t];else Object.defineProperty(this,t,{configurable:!0,writable:!0,value:s});return Ke=Ke||o,s}catch(s){throw delete this[t],Ke=Ke||o,s}},set(o){Object.defineProperty(this,t,{configurable:!0,writable:!0,value:o})}})}function ch(e,t,r,n){let o=ih(e,t);if(!o)return;Object.defineProperty(o,t,{configurable:!0,get(){let s={configurable:!0,writable:!0,enumerable:n,value:void 0};return Object.defineProperty(this,t,s),s.value=r(this),Object.defineProperty(this,t,s),s.value},set(s){Object.defineProperty(this,t,{configurable:!0,writable:!0,enumerable:n,value:s})}})}var uh="~constantCatch";function Sa(e){let t=()=>e;return t[uh]=!0,t}var Pa;var vo={value:void 0,enumerable:!1},ka="captureStackTrace"in Error?Error:null;function lh(e){let t=ka;if(t){let r=t.stackTraceLimit;if(typeof r==="number"){try{t.stackTraceLimit=0}catch{return ka=null,new e}try{return new e}finally{t.stackTraceLimit=r}}}return new e}function h(e,t,r,n){let o={};function s(d){this.def=d,this.constr=p,this.traits=new Set}s.prototype=o;let i=r,a=i&&new WeakSet;function c(d,m){if(!d._zod){vo.value=new s(m);try{Object.defineProperty(d,"_zod",vo)}finally{vo.value=void 0}}else if(d._zod.traits.has(e))return;if(d._zod.traits.add(e),t(d,m),a){let g=Object.getPrototypeOf(d),x=d._zod.constr.prototype,y=g;while(y&&y!==x)y=Object.getPrototypeOf(y);let w=y??g;if(!a.has(w))a.add(w),va(w,i)}let f=p.prototype;for(let g in f){if(!Object.prototype.hasOwnProperty.call(f,g))continue;if(!(g in d))d[g]=f[g].bind(d)}}let u=n?.Parent??Object;class l extends u{}Object.defineProperty(l,"name",{value:e});function p(d){let m=n?.Parent?lh(l):this;c(m,d);let f=m._zod.deferred;if(f){for(let x of f)x();m._zod.deferred=void 0}let g=globalThis.__zod_globalConfig?.postProcessor;if(g)g(m);return m}return Object.defineProperty(p,"init",{value:c}),Object.defineProperty(p,Symbol.hasInstance,{value:(d)=>{if(n?.Parent&&d instanceof n.Parent)return!0;return d?._zod?.traits?.has(e)}}),Object.defineProperty(p,"name",{value:e}),p}class Te extends Error{constructor(){super("Encountered Promise during synchronous parse. Use .parseAsync() instead.")}}class Jt extends Error{constructor(e){super(`Encountered unidirectional transform during encode: ${e}`);this.name="ZodEncodeError"}}(Pa=globalThis).__zod_globalConfig??(Pa.__zod_globalConfig={});var ee=globalThis.__zod_globalConfig;function te(e){if(e)Object.assign(ee,e);return ee}function ph(){let e=this._zod;return e.message??(e.message=JSON.stringify(e.def,Kt,2)),e.message}function dh(e){this._zod.message=e}var mh={get:ph,set:dh,enumerable:!0,configurable:!0},So={value:void 0,enumerable:!1},za=new WeakSet([Object.prototype,Error.prototype]),Ea=(e,t)=>{e.name="$ZodError",So.value=t,Object.defineProperty(e,"issues",So),So.value=void 0,Object.defineProperty(e,"message",mh);let r=Object.getPrototypeOf(e);if(!za.has(r))za.add(r),Object.defineProperty(r,"toString",{configurable:!0,enumerable:!1,get(){let n=()=>this.message;return Object.defineProperty(this,"toString",{value:n,configurable:!0,writable:!0}),n},set(n){Object.defineProperty(this,"toString",{value:n,configurable:!0,writable:!0})}})},Ca=h("$ZodError",Ea),kw=h("$ZodError",Ea,void 0,{Parent:Error});function fh(e,t,r){if(!Object.prototype.hasOwnProperty.call(e,t))if(t==="__proto__")Object.defineProperty(e,t,{value:r(),writable:!0,enumerable:!0,configurable:!0});else e[t]=r();return e[t]}function Po(e,t=(r)=>r.message){let r={},n=[];for(let o of e.issues)if(o.path.length>0)fh(r,o.path[0],()=>[]).push(t(o));else n.push(t(o));return{formErrors:n,fieldErrors:r}}function ko(e,t=(r)=>r.message){let r={_errors:[]},n=(o,s=[])=>{for(let i of o.issues)if(i.code==="invalid_union"&&i.errors.length)i.errors.map((a)=>n({issues:a},[...s,...i.path]));else if(i.code==="invalid_key")n({issues:i.issues},[...s,...i.path]);else if(i.code==="invalid_element")n({issues:i.issues},[...s,...i.path]);else{let a=[...s,...i.path];if(a.length===0)r._errors.push(t(i));else{let c=r,u=0;while(u<a.length){let l=a[u],p=u===a.length-1;if(l==="_errors"){if(p)c._errors.push(t(i));u++;continue}if(!Object.prototype.hasOwnProperty.call(c,l))Object.defineProperty(c,l,{value:{_errors:[]},enumerable:!0,writable:!0,configurable:!0});let d=c[l];if(p)d._errors.push(t(i));c=d,u++}}}};return n(e),r}function hh(e){let t=[],r=e.map((n)=>typeof n==="object"?n.key:n);for(let n of r)if(typeof n==="number")t.push(`[${n}]`);else if(typeof n==="symbol")t.push(`[${JSON.stringify(String(n))}]`);else if(/[^\w$]/.test(n))t.push(`[${JSON.stringify(n)}]`);else{if(t.length)t.push(".");t.push(n)}return t.join("")}function Ht(e){let t=[],r=[...e.issues].sort((n,o)=>(n.path??[]).length-(o.path??[]).length);for(let n of r)if(t.push(`✖ ${n.message}`),n.path?.length)t.push(` → at ${hh(n.path)}`);return t.join(`
|
|
33
|
-
`)}function Ur(e,t){return{callee:t?.callee??e,Err:t?.Err}}var Fr=(e)=>{let t=(r,n,o,s)=>{let i=o?{...o,async:!1}:{async:!1},a=r._zod.run({value:n,issues:[]},i);if(a instanceof Promise)throw new Te;if(a.issues.length){let c=new(s?.Err??e)(a.issues.map((u)=>Ie(u,i,te())));throw xo(c,s?.callee??t),c}return a.value};return t};var Mr=(e)=>{let t=async(r,n,o,s)=>{let i=o?{...o,async:!0}:{async:!0},a=r._zod.run({value:n,issues:[]},i);if(a instanceof Promise)a=await a;if(a.issues.length){let c=new(s?.Err??e)(a.issues.map((u)=>Ie(u,i,te())));throw xo(c,s?.callee??t),c}return a.value};return t};var Br=(e)=>(t,r,n)=>{let o=n?{...n,async:!1}:{async:!1},s=t._zod.run({value:r,issues:[]},o);if(s instanceof Promise)throw new Te;return s.issues.length?Ia(e,s.issues,o):{success:!0,data:s.value}};function Ia(e,t,r){let n;return{success:!1,get error(){if(!n)n=new e(t.map((o)=>Ie(o,r,te()))),t=void 0,r=void 0;return n},set error(o){n=o,t=void 0,r=void 0}}}var Gr=(e)=>async(t,r,n)=>{let o=n?{...n,async:!0}:{async:!0},s=t._zod.run({value:r,issues:[]},o);if(s instanceof Promise)s=await s;return s.issues.length?Ia(e,s.issues,o):{success:!0,data:s.value}};var gh=Symbol.for("zod.compile.invalid"),xh=Symbol.for("zod.compile.fallback"),zo=(e,t,r)=>{let n=e._zod.bag.validator;if(n!==void 0){if(n(t)!==gh)return!0;if(n.definite===!0&&r===void 0)return!1}return yh(e,t,r)};function yh(e,t,r){let n=r?{...r,async:!1,abortEarly:!0}:{async:!1,abortEarly:!0},o=e._zod.bag.fallbackRun,s;if(o)n[xh]=!0,s=o({value:t,issues:[]},n);else s=e._zod.run({value:t,issues:[]},n);if(s instanceof Promise)throw new Te;return s.issues.length===0}var Eo=async(e,t,r)=>{let n=r?{...r,async:!0,abortEarly:!0}:{async:!0,abortEarly:!0},o=e._zod.run({value:t,issues:[]},n);if(o instanceof Promise)o=await o;return o.issues.length===0},Ta=(e)=>{let t=Fr(e),r=(n,o,s,i)=>{let a=s?{...s,direction:"backward"}:{direction:"backward"};return t(n,o,a,Ur(r,i))};return r};var Oa=(e)=>{let t=Fr(e),r=(n,o,s,i)=>t(n,o,s,Ur(r,i));return r};var Aa=(e)=>{let t=Mr(e),r=async(n,o,s,i)=>{let a=s?{...s,direction:"backward"}:{direction:"backward"};return await t(n,o,a,Ur(r,i))};return r};var ja=(e)=>{let t=Mr(e),r=async(n,o,s,i)=>await t(n,o,s,Ur(r,i));return r};var Ra=(e)=>(t,r,n)=>{let o=n?{...n,direction:"backward"}:{direction:"backward"};return Br(e)(t,r,o)};var La=(e)=>(t,r,n)=>Br(e)(t,r,n);var Za=(e)=>async(t,r,n)=>{let o=n?{...n,direction:"backward"}:{direction:"backward"};return Gr(e)(t,r,o)};var Da=(e)=>async(t,r,n)=>Gr(e)(t,r,n);var Na=/^[cC][0-9a-z]{6,}$/,Ua=/^[0-9a-z]+$/,Fa=/^[0-7][0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{25}$/,Ma=/^[0-9a-vA-V]{20}$/,Ba=/^[A-Za-z0-9]{27}$/,Ga=/^[a-zA-Z0-9_-]{21}$/;function Va(e){return new RegExp(`^[a-zA-Z0-9_-]{${e}}$`)}var Wa=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/;var Ka=/^([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})$/,Io=(e)=>{if(!e)return/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/;return new 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})$`)};var Ja=/^(?:[A-Za-z0-9_'+\-]+\.)*[A-Za-z0-9_'+\-]*[A-Za-z0-9_+-]@(?:[A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/;var _h="^(?=[\\s\\S]*[\\p{Extended_Pictographic}\\p{Regional_Indicator}\\u20E3])[\\p{Extended_Pictographic}\\p{Emoji_Component}]+$";function Ha(){return new RegExp(_h,"u")}var qa=/^(?:(?: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])$/,Ya=/^(([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}|:))$/;var Xa=/^((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])$/,Qa=/^(([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])$/,ec=/^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/,tc=/^(?:[A-Za-z0-9_-]{4})*(?:[A-Za-z0-9_-]{2,3})?$/;var rc=/^https?$/,nc=/^\+[1-9]\d{6,14}$/;var oc="(?:(?:\\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 bh(e){return new RegExp(`^${e}$`)}var sc=bh(oc);function Co(e){return typeof e.precision==="number"?e.precision===-1?"(?:[01]\\d|2[0-3]):[0-5]\\d":e.precision===0?"(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d":`(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d\\.\\d{${e.precision}}`:e.seconds?"(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?":"(?:[01]\\d|2[0-3]):[0-5]\\d(?::[0-5]\\d(?:\\.\\d+)?)?"}function ic(e){return new RegExp(`^${Co(e)}$`)}function ac(e){let t=["Z"];if(e.offset)t.push("([+-](?:[01]\\d|2[0-3]):[0-5]\\d)");let r=`${Co({precision:e.precision,seconds:!0})}(?:${t.join("|")})`,n=e.local?`${r}|${Co({precision:e.precision})}`:r;return new RegExp(`^${oc}T(?:${n})$`)}var cc=/^[\s\S]{0,}$/;var To=/^-?\d+$/,qt=/^-?\d+(?:\.\d+)?$/,uc=/^(?:true|false)$/i;var lc=/^[^A-Z]*$/,pc=/^[^a-z]*$/;var J=h("$ZodCheck",(e,t)=>{var r;e._zod??(e._zod={}),e._zod.def=t,(r=e._zod).onattach??(r.onattach=[])});var Oo=(e)=>{let t=e.value;return!ua(t)&&t.length!==void 0},Vr={number:"number",bigint:"bigint",object:"date"},Ao=h("$ZodCheckLessThan",(e,t)=>{J.init(e,t);let r=Vr[typeof t.value];e._zod.check=(n)=>{if(t.inclusive?n.value<=t.value:n.value<t.value)return;n.issues.push({origin:Vr[typeof n.value]??r,code:"too_big",maximum:typeof t.value==="object"?t.value.getTime():t.value,input:n.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),jo=h("$ZodCheckGreaterThan",(e,t)=>{J.init(e,t);let r=Vr[typeof t.value];e._zod.check=(n)=>{if(t.inclusive?n.value>=t.value:n.value>t.value)return;n.issues.push({origin:Vr[typeof n.value]??r,code:"too_small",minimum:typeof t.value==="object"?t.value.getTime():t.value,input:n.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),dc=h("$ZodCheckMultipleOf",(e,t)=>{J.init(e,t),e._zod.check=(r)=>{if(typeof r.value!==typeof t.value)throw Error("Cannot mix number and bigint in multiple_of check.");if(typeof r.value==="bigint"?t.value!==BigInt(0)&&r.value%t.value===BigInt(0):la(r.value,t.value)===0)return;r.issues.push({origin:typeof r.value,code:"not_multiple_of",divisor:t.value,input:r.value,inst:e,continue:!t.abort})}}),mc=h("$ZodCheckNumberFormat",(e,t)=>{J.init(e,t),t.format=t.format||"float64";let r=t.format?.includes("int"),n=r?"int":"number",[o,s]=Rr[t.format];e._zod.check=(i)=>{let a=i.value;if(r){if(!Number.isInteger(a)){i.issues.push({expected:n,format:t.format,code:"invalid_type",continue:!1,input:a,inst:e});return}if(!Number.isSafeInteger(a)){if(a>0)i.issues.push({input:a,code:"too_big",maximum:Number.MAX_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:e,origin:n,inclusive:!0,continue:!t.abort});else i.issues.push({input:a,code:"too_small",minimum:Number.MIN_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:e,origin:n,inclusive:!0,continue:!t.abort});return}}if(a<o)i.issues.push({origin:"number",input:a,code:"too_small",minimum:o,inclusive:!0,inst:e,continue:!t.abort});if(a>s)i.issues.push({origin:"number",input:a,code:"too_big",maximum:s,inclusive:!0,inst:e,continue:!t.abort})}});var fc=h("$ZodCheckMaxLength",(e,t)=>{var r;J.init(e,t),(r=e._zod.def).when??(r.when=Oo),e._zod.check=(n)=>{let o=n.value,s=o.length;if((typeof o==="string"&&s>t.maximum?Zr(o):s)<=t.maximum)return;let a=Dr(o);n.issues.push({origin:a,code:"too_big",maximum:t.maximum,inclusive:!0,input:o,inst:e,continue:!t.abort})}}),hc=h("$ZodCheckMinLength",(e,t)=>{var r;J.init(e,t),(r=e._zod.def).when??(r.when=Oo),e._zod.check=(n)=>{let o=n.value,s=o.length;if((typeof o==="string"&&s>=t.minimum&&s<t.minimum*2?Zr(o):s)>=t.minimum)return;let a=Dr(o);n.issues.push({origin:a,code:"too_small",minimum:t.minimum,inclusive:!0,input:o,inst:e,continue:!t.abort})}}),gc=h("$ZodCheckLengthEquals",(e,t)=>{var r;J.init(e,t),(r=e._zod.def).when??(r.when=Oo),e._zod.check=(n)=>{let o=n.value,s=o.length,i=typeof o==="string"&&s>=t.length&&s<=t.length*2?Zr(o):s;if(i===t.length)return;let a=Dr(o),c=i>t.length;n.issues.push({origin:a,...c?{code:"too_big",maximum:t.length}:{code:"too_small",minimum:t.length},inclusive:!0,exact:!0,input:n.value,inst:e,continue:!t.abort})}}),Yt=h("$ZodCheckStringFormat",(e,t)=>{var r,n;if(J.init(e,t),t.pattern)(r=e._zod).check??(r.check=(o)=>{if(t.pattern.lastIndex=0,t.pattern.test(o.value))return;o.issues.push({origin:"string",code:"invalid_format",format:t.format,input:o.value,...t.pattern?{pattern:t.pattern.toString()}:{},inst:e,continue:!t.abort})});else(n=e._zod).check??(n.check=()=>{})}),xc=h("$ZodCheckRegex",(e,t)=>{Yt.init(e,t),e._zod.check=(r)=>{if(t.pattern.lastIndex=0,t.pattern.test(r.value))return;r.issues.push({origin:"string",code:"invalid_format",format:"regex",input:r.value,pattern:t.pattern.toString(),inst:e,continue:!t.abort})}}),yc=h("$ZodCheckLowerCase",(e,t)=>{t.pattern??(t.pattern=lc),Yt.init(e,t)}),_c=h("$ZodCheckUpperCase",(e,t)=>{t.pattern??(t.pattern=pc),Yt.init(e,t)}),bc=h("$ZodCheckIncludes",(e,t)=>{J.init(e,t);let r=bt(t.includes),n=new RegExp(typeof t.position==="number"?`^.{${t.position},}${r}`:r);t.pattern=n,e._zod.check=(o)=>{if(o.value.includes(t.includes,t.position))return;o.issues.push({origin:"string",code:"invalid_format",format:"includes",includes:t.includes,input:o.value,inst:e,continue:!t.abort})}}),wc=h("$ZodCheckStartsWith",(e,t)=>{J.init(e,t);let r=new RegExp(`^${bt(t.prefix)}.*`);t.pattern??(t.pattern=r),e._zod.check=(n)=>{if(n.value.startsWith(t.prefix))return;n.issues.push({origin:"string",code:"invalid_format",format:"starts_with",prefix:t.prefix,input:n.value,inst:e,continue:!t.abort})}}),vc=h("$ZodCheckEndsWith",(e,t)=>{J.init(e,t);let r=new RegExp(`.*${bt(t.suffix)}$`);t.pattern??(t.pattern=r),e._zod.check=(n)=>{if(n.value.endsWith(t.suffix))return;n.issues.push({origin:"string",code:"invalid_format",format:"ends_with",suffix:t.suffix,input:n.value,inst:e,continue:!t.abort})}});var $c=h("$ZodCheckOverwrite",(e,t)=>{J.init(e,t),e._zod.check=(r)=>{r.value=t.tx(r.value)}});class Ro{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-=1}}write(e){if(typeof e==="function"){e(this,{execution:"sync"}),e(this,{execution:"async"});return}let r=e.split(`
|
|
32
|
+
`)},write:(t)=>{e.write(t)}}),{bold:x,cyan:Es,dim:A,gray:K,green:Vt,red:Pe,yellow:mt}=Le.default,De=(e,t)=>({paint:()=>`${e}${A(t)}`,text:`${e}${t}`}),Cn=(e)=>{let t=[];if(e.vcpus!==null)t.push(ke(e.vcpus,"vCPU"));if(e.ramMb!==null)t.push(`${Pr(e.ramMb)} RAM`);return t.length===0?{text:e.flavor}:De(e.flavor,` (${t.join(", ")})`)},Cs=" ".repeat(5),pl=(e)=>x(Es(e)),M=(e)=>{let{headings:t,marks:r,rows:n}=e,o=t.map((i,a)=>Math.max(i.length,...n.map((c)=>c[a]?.text.length??0))),s=(i)=>i.map((a,c)=>{let u=c===i.length-1?a.text:a.text.padEnd(o[c]??0);return a.paint?a.paint(u):u}).join(Cs);oe(""),oe(` ${s(t.map((i)=>({paint:pl,text:i})))}`);for(let[i,a]of n.entries())oe(`${r?.[i]??" "} ${s(a)}`);oe("")},il=(e)=>e.paint?.(e.text)??e.text,ft=(e)=>{let t=Math.max(...e.map((n)=>n.label.length)),r=" ".repeat(2+t)+Cs;oe("");for(let{label:n,lines:o}of e){let[s={text:"-"},...i]=o,a=` ${pl(n.padEnd(t))}${Cs}`;oe(`${a}${il(s)}`);for(let c of i)oe(`${r}${il(c)}`)}oe("")};var fl=(e)=>new Map(e.flatMap((t)=>Se(t).map((r)=>[r,t]))),As=(e)=>`Use one of: ${e.join(", ")}.`,hl=(e,t)=>{if(e.value.kind==="choice"&&!e.value.choices.includes(t))throw Z(`unknown ${e.long} "${t}"`,As(e.value.choices));return t},dl=(e)=>{let{flag:t,hints:r,name:n,next:o}=e;if(o===void 0||o.startsWith("-"))throw Z(`${n} needs${fr(t.value)}`,`Usage: ${r.usage}`);return hl(t,o)},gl=(e)=>{let{hints:t,index:r,next:n,word:o}=e;if(o.startsWith("--")){let u=o.indexOf("="),p=u===-1?o:o.slice(0,u),d=r.get(p);if(!d)return;if(d.value.kind==="none"){if(u!==-1)throw Z(`${p} doesn't take a value`,`Usage: ${t.usage}`);return{options:[{flag:d,value:!0}],used:1}}if(u!==-1)return{options:[{flag:d,value:hl(d,o.slice(u+1))}],used:1};return{options:[{flag:d,value:dl({flag:d,hints:t,name:p,next:n})}],used:2}}let s=[...o].slice(1),a=s.map((u)=>r.get(`-${u}`)).filter((u)=>u!==void 0);if(a.length!==s.length)return;let c=[],l=1;for(let[u,p]of a.entries())if(p.value.kind==="none")c.push({flag:p,value:!0});else if(u===a.length-1)c.push({flag:p,value:dl({flag:p,hints:t,name:`-${s[u]}`,next:n})}),l=2;else throw Z(`-${s[u]} needs${fr(p.value)}`,`Usage: ${t.usage}`);return{options:c,used:l}},Is=(e,t)=>{let r=e.flatMap((n)=>{let o=t.get(n.long);return o===void 0?[]:[[n.long,o]]});return Object.fromEntries(r)},Ib={command:"nipa",usage:"nipa [options] <command>"},Ab=fl($e),ml=(e)=>{let{at:t,words:r}=e,n=r[t];if(n===void 0||n==="--"||n==="-"||!n.startsWith("-"))return;let o=gl({hints:Ib,index:Ab,next:r[t+1],word:n});if(!o&&e.unknown==="reject")throw Z(`unknown option "${n}"`,"Run `nipa --help` to see the options.");return o},Ts=(e)=>{let{unknown:t,words:r}=e,n=new Map,o=0;for(let s=ml({at:o,unknown:t,words:r});s!==void 0;s=ml({at:o,unknown:t,words:r})){for(let{flag:i,value:a}of s.options)n.set(i.long,a);o+=s.used}return{globals:Is($e,n),rest:r.slice(o)}},yl=(e)=>{let t=e.indexOf("--"),r=t===-1?e:e.slice(0,t),n=new Set(Se(Qo));return r.some((o)=>n.has(o))},Tb=(e)=>{let{flags:t,hints:r,words:n}=e,o=fl([...t,...$e]),s=new Set(t.map((u)=>u.long)),i=new Map,a=new Map,c=[],l=0;while(l<n.length){let u=n[l]??"";if(u==="--"){c.push(...n.slice(l+1));break}if(u.startsWith("-")&&u!=="-"){let p=gl({hints:r,index:o,next:n[l+1],word:u});if(!p)throw Z(`unknown option "${u}"`,`Run \`${r.command} --help\` to see the options.`);for(let{flag:d,value:f}of p.options)(s.has(d.long)?i:a).set(d.long,f);l+=p.used}else c.push(u),l+=1}return{globals:a,own:i,positionals:c}},zs=(e,t)=>{if(e.value.kind==="choice"&&!e.value.choices.includes(t))throw Z(`unknown ${e.name} "${t}"`,As(e.value.choices));return t},Rb=(e)=>{let t=[...e.positionals],r=e.args.map((o)=>{switch(o.arity){case"one":{let s=t.shift();if(s===void 0)throw Z(`missing <${o.name}>`,o.value.kind==="choice"?As(o.value.choices):`Usage: ${e.hints.usage}`);return[o.name,zs(o,s)]}case"optional":{let s=t.shift();return[o.name,s===void 0?void 0:zs(o,s)]}case"rest":return[o.name,t.splice(0).map((s)=>zs(o,s))];default:return o.arity}}),[n]=t;if(n!==void 0)throw Z(`unexpected argument "${n}"`,`Usage: ${e.hints.usage}`);return Object.fromEntries(r)},bl=(e)=>{let{path:t,spec:r,words:n}=e,o={command:hn(t),usage:yr(t)},s=Tb({flags:r.flags,hints:o,words:n});return{globals:Is($e,s.globals),input:{args:Rb({args:r.args,hints:o,positionals:s.positionals}),flags:Is(r.flags,s.own)}}};var z=(e)=>({...e,kind:"leaf"}),ee=(e)=>({...e,kind:"group"}),Wt=(e)=>({...e,kind:"passthrough"}),k=(e,t)=>({kind:"leaf",prepare:({path:r,words:n})=>{let o=bl({path:r,spec:e,words:n});return{globals:o.globals,run:(s)=>t({...o.input,client:s})}},spec:e}),te=(e,t)=>{let r=Object.values(t),n=new Map(r.flatMap((o)=>xe(o.spec).map((s)=>[s,o])));return{fallback:t[e.default],kind:"group",spec:e,subcommands:n}},jb=(e,t)=>{let{target:r}=e;switch(r.kind){case"program":return{args:t,command:r.program};case"openstack":return{args:t,command:"openstack"};case"command":{let[n,...o]=t;if(n===void 0)throw Z("missing <command>",`Usage: ${yr([e])}`);return{args:o,command:n}}default:return r}},Ht=(e,t)=>({kind:"passthrough",run:({client:r,words:n})=>t({...jb(e,n),client:r}),spec:e}),xl=(e)=>e.spec,En=(e)=>({examples:e.examples,hidden:e.hidden.map(xl),sections:e.sections.map((t)=>({commands:t.commands.map(xl),title:t.title})),summary:e.summary});function zr(e){let t=Object.values(e).filter((n)=>typeof n==="number");return Object.entries(e).filter(([n,o])=>t.indexOf(+n)===-1).map(([n,o])=>o)}function js(e,t="|"){return e.map((r)=>Ds(r)).join(t)}function Ir(e,t){if(typeof t==="bigint")return t.toString();return t}class wl{constructor(e){this._getter=e,this._value=void 0}get value(){let e=this._getter;if(e!==void 0)this._value=e(),this._getter=void 0;return this._value}}function zn(e){return new wl(e)}function _l(e){return e===null||e===void 0}function In(e){let t=e.startsWith("^")?1:0,r=e.endsWith("$")?e.length-1:e.length;return e.slice(t,r)}function vl(e,t){let r=e/t,n=Math.round(r),o=4*Number.EPSILON*Math.max(Math.abs(r),1);if(Math.abs(r-n)<o)return 0;return r-n}function Ne(e,t,r){Object.defineProperty(e,t,{value:r,writable:!0,enumerable:!0,configurable:!0})}function An(e){let t=Object.getOwnPropertyDescriptor(e,"shape");return t?.get?t.get.raw:t?.value}function ot(e){return An(e._zod.def)??e._zod.def.shape}function $l(e,t,r){Object.defineProperty(e,t,{get(){let n=r();return Ne(this,t,n),n},enumerable:!0,configurable:!0})}function Sl(e,t,r){if(t in e)Ne(e,t,r);else e[t]=r}function It(e,t,r,n){let o=ot(t);for(let s of r){let i=Object.getOwnPropertyDescriptor(o,s);if(!i.enumerable)continue;if(i.get)$l(e,s,()=>{let a=t._zod.def.shape[s];return n?n(a,s):a});else Sl(e,s,n?n(i.value,s):i.value)}}function Ob(e,t){for(let r of Reflect.ownKeys(t)){let n=Object.getOwnPropertyDescriptor(t,r);if(!n.enumerable)continue;if(n.get)$l(e,r,()=>t[r]);else Sl(e,r,n.value)}}function Ce(...e){let t={};for(let r of e){let n=Object.getOwnPropertyDescriptors(r);Object.assign(t,n)}return Object.defineProperties({},t)}function kl(e){return JSON.stringify(e)}function Pl(e){return e.toLowerCase().trim().replace(/[^\w\s-]/g,"").replace(/[\s_-]+/g,"-").replace(/^-+|-+$/g,"")}var Os="captureStackTrace"in Error?Error.captureStackTrace:(...e)=>{};function Er(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}var Cl=zn(()=>{if(we.jitless)return!1;if(typeof navigator<"u"&&navigator?.userAgent?.includes("Cloudflare"))return!1;try{return new Function(""),!0}catch(e){return!1}});function At(e){if(Er(e)===!1)return!1;let t=e.constructor;if(t===void 0)return!0;if(typeof t!=="function")return!0;let r=t.prototype;if(Er(r)===!1)return!1;if(Object.prototype.hasOwnProperty.call(r,"isPrototypeOf")===!1)return!1;return!0}function Ls(e){if(At(e))return{...e};if(Array.isArray(e))return[...e];if(e instanceof Map)return new Map(e);if(e instanceof Set)return new Set(e);return e}var El=new Set(["string","number","symbol"]);function Jt(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Ze(e,t,r){let n=new e._zod.constr(t??e._zod.def);if(!t||r?.parent)n._zod.parent=e;return n}function C(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}if(delete t.message,typeof t.error==="string")return{...t,error:()=>t.error};return t}function Ds(e){if(typeof e==="bigint")return e.toString()+"n";if(typeof e==="string")return`"${e}"`;return`${e}`}function zl(e){return Object.keys(e).filter((t)=>e[t]._zod.optin!==void 0&&e[t]._zod.optout==="optional")}var Tn=(()=>({safeint:[Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER],int32:[-2147483648,2147483647],uint32:[0,4294967295],float32:[-340282346638528860000000000000000000000,340282346638528860000000000000000000000],float64:[-Number.MAX_VALUE,Number.MAX_VALUE]}))(),Ns={int64:[BigInt("-9223372036854775808"),BigInt("9223372036854775807")],uint64:[BigInt(0),BigInt("18446744073709551615")]};function Lb(e,t){let r=e._zod.def,n=r.checks;if(n&&n.length>0)throw Error(".pick() cannot be used on object schemas containing refinements");let s={};return It(s,e,Rn(e,t)),Ze(e,Ce(r,{shape:s,checks:[]}))}function Rn(e,t){let r=ot(e),n=[];for(let o of Reflect.ownKeys(t)){if(!Object.getOwnPropertyDescriptor(r,o)?.enumerable)throw Error(`Unrecognized key: "${String(o)}"`);if(t[o])n.push(o)}return n}function Db(e,t){let r=e._zod.def,n=r.checks;if(n&&n.length>0)throw Error(".omit() cannot be used on object schemas containing refinements");let s=new Set(Rn(e,t)),i={};return It(i,e,Reflect.ownKeys(ot(e)).filter((a)=>!s.has(a))),Ze(e,Ce(r,{shape:i,checks:[]}))}function Nb(e,t){if(!At(t))throw Error("Invalid input to extend: expected a plain object");let r=e._zod.def.checks;if(r&&r.length>0){let o=ot(e);for(let s of Reflect.ownKeys(t))if(Object.getOwnPropertyDescriptor(o,s)!==void 0)throw Error("Cannot overwrite keys on object schemas containing refinements. Use `.safeExtend()` instead.")}return Ze(e,Ce(e._zod.def,{shape:Il(e,t)}))}function Il(e,t){let r={};return It(r,e,Reflect.ownKeys(ot(e))),Ob(r,t),r}function Zb(e,t){if(!At(t))throw Error("Invalid input to safeExtend: expected a plain object");return Ze(e,Ce(e._zod.def,{shape:Il(e,t)}))}function Ub(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 r={};It(r,e,Reflect.ownKeys(ot(e))),It(r,t,Reflect.ownKeys(ot(t)));let n=Ce(e._zod.def,{shape:r,get catchall(){return t._zod.def.catchall},checks:t._zod.def.checks??[]});return Ze(e,n)}function Al(e,t,r,n="partial"){let s=t._zod.def.checks;if(s&&s.length>0)throw Error(`.${n}() cannot be used on object schemas containing refinements`);let a=r?new Set(Rn(t,r)):void 0,c={};return It(c,t,Reflect.ownKeys(ot(t)),e&&((l,u)=>a&&!a.has(u)?l:new e({type:"optional",innerType:l}))),Ze(t,Ce(t._zod.def,{shape:c,checks:[]}))}function Fb(e,t,r){let n=r?new Set(Rn(t,r)):void 0,o={};return It(o,t,Reflect.ownKeys(ot(t)),(s,i)=>n&&!n.has(i)?s:new e({type:"nonoptional",innerType:s})),Ze(t,Ce(t._zod.def,{shape:o}))}function Be(e,t=0){if(e.aborted===!0)return!0;for(let r=t;r<e.issues.length;r++)if(e.issues[r]?.continue!==!0)return!0;return!1}function Tl(e,t=0){if(e.aborted===!0)return!0;for(let r=t;r<e.issues.length;r++)if(e.issues[r]?.continue===!1)return!0;return!1}function gt(e,t){return t.map((r)=>{var n;return(n=r).path??(n.path=[]),r.path.unshift(e),r})}function Cr(e){return typeof e==="string"?e:e?.message}function Zs(e,t,r){var n;for(let o=t;o<e.length;o++)(n=e[o]).schema??(n.schema=r)}function Ge(e,t,r){var n;let o=e.inst?._zod?.traits;if(o?.has("$ZodType"))if(o.has("$ZodCheck"))(n=e).schema??(n.schema=e.inst);else e.schema=e.inst;let s=e.schema!==e.inst?e.schema?._zod.def?.error:void 0,i=e.message?e.message:Cr(e.inst?._zod.def?.error?.(e))??Cr(s?.(e))??Cr(t?.error?.(e))??Cr(r.customError?.(e))??Cr(r.localeError?.(e))??"Invalid input",a={};for(let c of Object.keys(e)){if(c==="inst"||c==="schema"||c==="continue"||c==="input"||c==="__proto__")continue;a[c]=e[c]}if(a.path??(a.path=[]),a.message=i,t?.reportInput)a.input=e.input;return a}var Mb=/[\uD800-\uDBFF]/;function jn(e){let t=e.length;if(!Mb.test(e))return t;let r=t;for(let n=0;n<t-1;n++)if((e.charCodeAt(n)&64512)===55296&&(e.charCodeAt(n+1)&64512)===56320)r--,n++;return r}function On(e){if(Array.isArray(e))return"array";if(typeof e==="string")return"string";return"unknown"}function Rl(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 r=e;if(r&&Object.getPrototypeOf(r)!==Object.prototype&&"constructor"in r&&r.constructor)return r.constructor.name}}return t}function Tt(...e){let[t,r,n]=e;if(typeof t==="string")return{message:t,code:"custom",input:r,inst:n};return{...t}}function jl(e,t){for(let r in t){let n=Object.getOwnPropertyDescriptor(t,r);if(n.get)Object.defineProperty(e,r,{...n,enumerable:!1});else Bb(e,r,n.value)}}function st(e,t,r,n=!0){return Object.defineProperty(e,t,{configurable:!0,writable:!0,enumerable:n,value:r}),r}function Ln(e,t,r){return st(e,t,r,!1)}function Ol(e,t){for(let r in e){let n=e[r];Object.defineProperty(t,r,{configurable:!0,enumerable:!0,get(){return st(this,r,n(this))},set(o){st(this,r,o)}})}return t}function Bb(e,t,r){Object.defineProperty(e,t,{configurable:!0,get(){return this==null?r:st(this,t,r.bind(this))},set(n){st(this,t,n)}})}function Gb(e,t){let r=Object.getPrototypeOf(e);return t in r?void 0:r}var Rs,ht=!1,Kb={configurable:!0,get(){ht=!0;return}};function B(e,t,r){let n=Object.getPrototypeOf(e._zod);if(t in n&&Rs!==e._zod){Rs=void 0;return}Rs=e._zod,Object.defineProperty(n,t,{configurable:!0,get(){Object.defineProperty(this,t,Kb);let o=ht;ht=!1;try{let s=r(this);if(ht)delete this[t];else Object.defineProperty(this,t,{configurable:!0,writable:!0,value:s});return ht=ht||o,s}catch(s){throw delete this[t],ht=ht||o,s}},set(o){Object.defineProperty(this,t,{configurable:!0,writable:!0,value:o})}})}function Vb(e,t,r,n){let o=Gb(e,t);if(!o)return;Object.defineProperty(o,t,{configurable:!0,get(){let s={configurable:!0,writable:!0,enumerable:n,value:void 0};return Object.defineProperty(this,t,s),s.value=r(this),Object.defineProperty(this,t,s),s.value},set(s){Object.defineProperty(this,t,{configurable:!0,writable:!0,enumerable:n,value:s})}})}var Wb="~constantCatch";function Ll(e){let t=()=>e;return t[Wb]=!0,t}var Dl;var Us={value:void 0,enumerable:!1},Nl="captureStackTrace"in Error?Error:null;function Hb(e){let t=Nl;if(t){let r=t.stackTraceLimit;if(typeof r==="number"){try{t.stackTraceLimit=0}catch{return Nl=null,new e}try{return new e}finally{t.stackTraceLimit=r}}}return new e}function g(e,t,r,n){let o={};function s(d){this.def=d,this.constr=p,this.traits=new Set}s.prototype=o;let i=r,a=i&&new WeakSet;function c(d,f){if(!d._zod){Us.value=new s(f);try{Object.defineProperty(d,"_zod",Us)}finally{Us.value=void 0}}else if(d._zod.traits.has(e))return;if(d._zod.traits.add(e),t(d,f),a){let y=Object.getPrototypeOf(d),b=d._zod.constr.prototype,_=y;while(_&&_!==b)_=Object.getPrototypeOf(_);let P=_??y;if(!a.has(P))a.add(P),jl(P,i)}let h=p.prototype;for(let y in h){if(!Object.prototype.hasOwnProperty.call(h,y))continue;if(!(y in d))d[y]=h[y].bind(d)}}let l=n?.Parent??Object;class u extends l{}Object.defineProperty(u,"name",{value:e});function p(d){let f=n?.Parent?Hb(u):this;c(f,d);let h=f._zod.deferred;if(h){for(let b of h)b();f._zod.deferred=void 0}let y=globalThis.__zod_globalConfig?.postProcessor;if(y)y(f);return f}return Object.defineProperty(p,"init",{value:c}),Object.defineProperty(p,Symbol.hasInstance,{value:(d)=>{if(n?.Parent&&d instanceof n.Parent)return!0;return d?._zod?.traits?.has(e)}}),Object.defineProperty(p,"name",{value:e}),p}class Ke extends Error{constructor(){super("Encountered Promise during synchronous parse. Use .parseAsync() instead.")}}class Ar extends Error{constructor(e){super(`Encountered unidirectional transform during encode: ${e}`);this.name="ZodEncodeError"}}(Dl=globalThis).__zod_globalConfig??(Dl.__zod_globalConfig={});var we=globalThis.__zod_globalConfig;function _e(e){if(e)Object.assign(we,e);return we}function Jb(){let e=this._zod;return e.message??(e.message=JSON.stringify(e.def,Ir,2)),e.message}function qb(e){this._zod.message=e}var Yb={get:Jb,set:qb,enumerable:!0,configurable:!0},Ms={value:void 0,enumerable:!1},Zl=new WeakSet([Object.prototype,Error.prototype]),Ul=(e,t)=>{e.name="$ZodError",Ms.value=t,Object.defineProperty(e,"issues",Ms),Ms.value=void 0,Object.defineProperty(e,"message",Yb);let r=Object.getPrototypeOf(e);if(!Zl.has(r))Zl.add(r),Object.defineProperty(r,"toString",{configurable:!0,enumerable:!1,get(){let n=()=>this.message;return Object.defineProperty(this,"toString",{value:n,configurable:!0,writable:!0}),n},set(n){Object.defineProperty(this,"toString",{value:n,configurable:!0,writable:!0})}})},Fl=g("$ZodError",Ul),t0=g("$ZodError",Ul,void 0,{Parent:Error});function Xb(e,t,r){if(!Object.prototype.hasOwnProperty.call(e,t))if(t==="__proto__")Object.defineProperty(e,t,{value:r(),writable:!0,enumerable:!0,configurable:!0});else e[t]=r();return e[t]}function Bs(e,t=(r)=>r.message){let r={},n=[];for(let o of e.issues)if(o.path.length>0)Xb(r,o.path[0],()=>[]).push(t(o));else n.push(t(o));return{formErrors:n,fieldErrors:r}}function Gs(e,t=(r)=>r.message){let r={_errors:[]},n=(o,s=[])=>{for(let i of o.issues)if(i.code==="invalid_union"&&i.errors.length)i.errors.map((a)=>n({issues:a},[...s,...i.path]));else if(i.code==="invalid_key")n({issues:i.issues},[...s,...i.path]);else if(i.code==="invalid_element")n({issues:i.issues},[...s,...i.path]);else{let a=[...s,...i.path];if(a.length===0)r._errors.push(t(i));else{let c=r,l=0;while(l<a.length){let u=a[l],p=l===a.length-1;if(u==="_errors"){if(p)c._errors.push(t(i));l++;continue}if(!Object.prototype.hasOwnProperty.call(c,u))Object.defineProperty(c,u,{value:{_errors:[]},enumerable:!0,writable:!0,configurable:!0});let d=c[u];if(p)d._errors.push(t(i));c=d,l++}}}};return n(e),r}function Qb(e){let t=[],r=e.map((n)=>typeof n==="object"?n.key:n);for(let n of r)if(typeof n==="number")t.push(`[${n}]`);else if(typeof n==="symbol")t.push(`[${JSON.stringify(String(n))}]`);else if(/[^\w$]/.test(n))t.push(`[${JSON.stringify(n)}]`);else{if(t.length)t.push(".");t.push(n)}return t.join("")}function qt(e){let t=[],r=[...e.issues].sort((n,o)=>(n.path??[]).length-(o.path??[]).length);for(let n of r)if(t.push(`✖ ${n.message}`),n.path?.length)t.push(` → at ${Qb(n.path)}`);return t.join(`
|
|
33
|
+
`)}function Dn(e,t){return{callee:t?.callee??e,Err:t?.Err}}var Nn=(e)=>{let t=(r,n,o,s)=>{let i=o?{...o,async:!1}:{async:!1},a=r._zod.run({value:n,issues:[]},i);if(a instanceof Promise)throw new Ke;if(a.issues.length){let c=new(s?.Err??e)(a.issues.map((l)=>Ge(l,i,_e())));throw Os(c,s?.callee??t),c}return a.value};return t};var Zn=(e)=>{let t=async(r,n,o,s)=>{let i=o?{...o,async:!0}:{async:!0},a=r._zod.run({value:n,issues:[]},i);if(a instanceof Promise)a=await a;if(a.issues.length){let c=new(s?.Err??e)(a.issues.map((l)=>Ge(l,i,_e())));throw Os(c,s?.callee??t),c}return a.value};return t};var Un=(e)=>(t,r,n)=>{let o=n?{...n,async:!1}:{async:!1},s=t._zod.run({value:r,issues:[]},o);if(s instanceof Promise)throw new Ke;return s.issues.length?Ml(e,s.issues,o):{success:!0,data:s.value}};function Ml(e,t,r){let n;return{success:!1,get error(){if(!n)n=new e(t.map((o)=>Ge(o,r,_e()))),t=void 0,r=void 0;return n},set error(o){n=o,t=void 0,r=void 0}}}var Fn=(e)=>async(t,r,n)=>{let o=n?{...n,async:!0}:{async:!0},s=t._zod.run({value:r,issues:[]},o);if(s instanceof Promise)s=await s;return s.issues.length?Ml(e,s.issues,o):{success:!0,data:s.value}};var ex=Symbol.for("zod.compile.invalid"),tx=Symbol.for("zod.compile.fallback"),Ks=(e,t,r)=>{let n=e._zod.bag.validator;if(n!==void 0){if(n(t)!==ex)return!0;if(n.definite===!0&&r===void 0)return!1}return rx(e,t,r)};function rx(e,t,r){let n=r?{...r,async:!1,abortEarly:!0}:{async:!1,abortEarly:!0},o=e._zod.bag.fallbackRun,s;if(o)n[tx]=!0,s=o({value:t,issues:[]},n);else s=e._zod.run({value:t,issues:[]},n);if(s instanceof Promise)throw new Ke;return s.issues.length===0}var Vs=async(e,t,r)=>{let n=r?{...r,async:!0,abortEarly:!0}:{async:!0,abortEarly:!0},o=e._zod.run({value:t,issues:[]},n);if(o instanceof Promise)o=await o;return o.issues.length===0},Bl=(e)=>{let t=Nn(e),r=(n,o,s,i)=>{let a=s?{...s,direction:"backward"}:{direction:"backward"};return t(n,o,a,Dn(r,i))};return r};var Gl=(e)=>{let t=Nn(e),r=(n,o,s,i)=>t(n,o,s,Dn(r,i));return r};var Kl=(e)=>{let t=Zn(e),r=async(n,o,s,i)=>{let a=s?{...s,direction:"backward"}:{direction:"backward"};return await t(n,o,a,Dn(r,i))};return r};var Vl=(e)=>{let t=Zn(e),r=async(n,o,s,i)=>await t(n,o,s,Dn(r,i));return r};var Wl=(e)=>(t,r,n)=>{let o=n?{...n,direction:"backward"}:{direction:"backward"};return Un(e)(t,r,o)};var Hl=(e)=>(t,r,n)=>Un(e)(t,r,n);var Jl=(e)=>async(t,r,n)=>{let o=n?{...n,direction:"backward"}:{direction:"backward"};return Fn(e)(t,r,o)};var ql=(e)=>async(t,r,n)=>Fn(e)(t,r,n);var Yl=/^[cC][0-9a-z]{6,}$/,Xl=/^[0-9a-z]+$/,Ql=/^[0-7][0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{25}$/,eu=/^[0-9a-vA-V]{20}$/,tu=/^[A-Za-z0-9]{27}$/,ru=/^[a-zA-Z0-9_-]{21}$/;function nu(e){return new RegExp(`^[a-zA-Z0-9_-]{${e}}$`)}var ou=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/;var su=/^([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})$/,Hs=(e)=>{if(!e)return/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/;return new 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})$`)};var iu=/^(?:[A-Za-z0-9_'+\-]+\.)*[A-Za-z0-9_'+\-]*[A-Za-z0-9_+-]@(?:[A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/;var nx="^(?=[\\s\\S]*[\\p{Extended_Pictographic}\\p{Regional_Indicator}\\u20E3])[\\p{Extended_Pictographic}\\p{Emoji_Component}]+$";function au(){return new RegExp(nx,"u")}var cu=/^(?:(?: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])$/,lu=/^(([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}|:))$/;var uu=/^((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])$/,pu=/^(([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])$/,du=/^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/,mu=/^(?:[A-Za-z0-9_-]{4})*(?:[A-Za-z0-9_-]{2,3})?$/;var fu=/^https?$/,hu=/^\+[1-9]\d{6,14}$/;var gu="(?:(?:\\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 ox(e){return new RegExp(`^${e}$`)}var yu=ox(gu);function Ws(e){return typeof e.precision==="number"?e.precision===-1?"(?:[01]\\d|2[0-3]):[0-5]\\d":e.precision===0?"(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d":`(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d\\.\\d{${e.precision}}`:e.seconds?"(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?":"(?:[01]\\d|2[0-3]):[0-5]\\d(?::[0-5]\\d(?:\\.\\d+)?)?"}function bu(e){return new RegExp(`^${Ws(e)}$`)}function xu(e){let t=["Z"];if(e.offset)t.push("([+-](?:[01]\\d|2[0-3]):[0-5]\\d)");let r=`${Ws({precision:e.precision,seconds:!0})}(?:${t.join("|")})`,n=e.local?`${r}|${Ws({precision:e.precision})}`:r;return new RegExp(`^${gu}T(?:${n})$`)}var wu=/^[\s\S]{0,}$/;var Js=/^-?\d+$/,Tr=/^-?\d+(?:\.\d+)?$/,_u=/^(?:true|false)$/i;var vu=/^[^A-Z]*$/,$u=/^[^a-z]*$/;var ue=g("$ZodCheck",(e,t)=>{var r;e._zod??(e._zod={}),e._zod.def=t,(r=e._zod).onattach??(r.onattach=[])});var qs=(e)=>{let t=e.value;return!_l(t)&&t.length!==void 0},Mn={number:"number",bigint:"bigint",object:"date"},Ys=g("$ZodCheckLessThan",(e,t)=>{ue.init(e,t);let r=Mn[typeof t.value];e._zod.check=(n)=>{if(t.inclusive?n.value<=t.value:n.value<t.value)return;n.issues.push({origin:Mn[typeof n.value]??r,code:"too_big",maximum:typeof t.value==="object"?t.value.getTime():t.value,input:n.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),Xs=g("$ZodCheckGreaterThan",(e,t)=>{ue.init(e,t);let r=Mn[typeof t.value];e._zod.check=(n)=>{if(t.inclusive?n.value>=t.value:n.value>t.value)return;n.issues.push({origin:Mn[typeof n.value]??r,code:"too_small",minimum:typeof t.value==="object"?t.value.getTime():t.value,input:n.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),Su=g("$ZodCheckMultipleOf",(e,t)=>{ue.init(e,t),e._zod.check=(r)=>{if(typeof r.value!==typeof t.value)throw Error("Cannot mix number and bigint in multiple_of check.");if(typeof r.value==="bigint"?t.value!==BigInt(0)&&r.value%t.value===BigInt(0):vl(r.value,t.value)===0)return;r.issues.push({origin:typeof r.value,code:"not_multiple_of",divisor:t.value,input:r.value,inst:e,continue:!t.abort})}}),ku=g("$ZodCheckNumberFormat",(e,t)=>{ue.init(e,t),t.format=t.format||"float64";let r=t.format?.includes("int"),n=r?"int":"number",[o,s]=Tn[t.format];e._zod.check=(i)=>{let a=i.value;if(r){if(!Number.isInteger(a)){i.issues.push({expected:n,format:t.format,code:"invalid_type",continue:!1,input:a,inst:e});return}if(!Number.isSafeInteger(a)){if(a>0)i.issues.push({input:a,code:"too_big",maximum:Number.MAX_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:e,origin:n,inclusive:!0,continue:!t.abort});else i.issues.push({input:a,code:"too_small",minimum:Number.MIN_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:e,origin:n,inclusive:!0,continue:!t.abort});return}}if(a<o)i.issues.push({origin:"number",input:a,code:"too_small",minimum:o,inclusive:!0,inst:e,continue:!t.abort});if(a>s)i.issues.push({origin:"number",input:a,code:"too_big",maximum:s,inclusive:!0,inst:e,continue:!t.abort})}});var Pu=g("$ZodCheckMaxLength",(e,t)=>{var r;ue.init(e,t),(r=e._zod.def).when??(r.when=qs),e._zod.check=(n)=>{let o=n.value,s=o.length;if((typeof o==="string"&&s>t.maximum?jn(o):s)<=t.maximum)return;let a=On(o);n.issues.push({origin:a,code:"too_big",maximum:t.maximum,inclusive:!0,input:o,inst:e,continue:!t.abort})}}),Cu=g("$ZodCheckMinLength",(e,t)=>{var r;ue.init(e,t),(r=e._zod.def).when??(r.when=qs),e._zod.check=(n)=>{let o=n.value,s=o.length;if((typeof o==="string"&&s>=t.minimum&&s<t.minimum*2?jn(o):s)>=t.minimum)return;let a=On(o);n.issues.push({origin:a,code:"too_small",minimum:t.minimum,inclusive:!0,input:o,inst:e,continue:!t.abort})}}),Eu=g("$ZodCheckLengthEquals",(e,t)=>{var r;ue.init(e,t),(r=e._zod.def).when??(r.when=qs),e._zod.check=(n)=>{let o=n.value,s=o.length,i=typeof o==="string"&&s>=t.length&&s<=t.length*2?jn(o):s;if(i===t.length)return;let a=On(o),c=i>t.length;n.issues.push({origin:a,...c?{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=g("$ZodCheckStringFormat",(e,t)=>{var r,n;if(ue.init(e,t),t.pattern)(r=e._zod).check??(r.check=(o)=>{if(t.pattern.lastIndex=0,t.pattern.test(o.value))return;o.issues.push({origin:"string",code:"invalid_format",format:t.format,input:o.value,...t.pattern?{pattern:t.pattern.toString()}:{},inst:e,continue:!t.abort})});else(n=e._zod).check??(n.check=()=>{})}),zu=g("$ZodCheckRegex",(e,t)=>{Rr.init(e,t),e._zod.check=(r)=>{if(t.pattern.lastIndex=0,t.pattern.test(r.value))return;r.issues.push({origin:"string",code:"invalid_format",format:"regex",input:r.value,pattern:t.pattern.toString(),inst:e,continue:!t.abort})}}),Iu=g("$ZodCheckLowerCase",(e,t)=>{t.pattern??(t.pattern=vu),Rr.init(e,t)}),Au=g("$ZodCheckUpperCase",(e,t)=>{t.pattern??(t.pattern=$u),Rr.init(e,t)}),Tu=g("$ZodCheckIncludes",(e,t)=>{ue.init(e,t);let r=Jt(t.includes),n=new RegExp(typeof t.position==="number"?`^.{${t.position},}${r}`:r);t.pattern=n,e._zod.check=(o)=>{if(o.value.includes(t.includes,t.position))return;o.issues.push({origin:"string",code:"invalid_format",format:"includes",includes:t.includes,input:o.value,inst:e,continue:!t.abort})}}),Ru=g("$ZodCheckStartsWith",(e,t)=>{ue.init(e,t);let r=new RegExp(`^${Jt(t.prefix)}.*`);t.pattern??(t.pattern=r),e._zod.check=(n)=>{if(n.value.startsWith(t.prefix))return;n.issues.push({origin:"string",code:"invalid_format",format:"starts_with",prefix:t.prefix,input:n.value,inst:e,continue:!t.abort})}}),ju=g("$ZodCheckEndsWith",(e,t)=>{ue.init(e,t);let r=new RegExp(`.*${Jt(t.suffix)}$`);t.pattern??(t.pattern=r),e._zod.check=(n)=>{if(n.value.endsWith(t.suffix))return;n.issues.push({origin:"string",code:"invalid_format",format:"ends_with",suffix:t.suffix,input:n.value,inst:e,continue:!t.abort})}});var Ou=g("$ZodCheckOverwrite",(e,t)=>{ue.init(e,t),e._zod.check=(r)=>{r.value=t.tx(r.value)}});class Qs{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-=1}}write(e){if(typeof e==="function"){e(this,{execution:"sync"}),e(this,{execution:"async"});return}let r=e.split(`
|
|
34
34
|
`).filter((s)=>s),n=Math.min(...r.map((s)=>s.length-s.trimStart().length)),o=r.map((s)=>s.slice(n)).map((s)=>" ".repeat(this.indent*2)+s);for(let s of o)this.content.push(s)}compile(){let e=Function,t=this?.content??[""];return new e(...Object.keys(this.closed),`return function (${this.args.join(", ")}) {
|
|
35
35
|
${t.join(`
|
|
36
36
|
`)}
|
|
37
|
-
};`)(...Object.values(this.closed))}}var Pc={major:4,minor:6,patch:5};var U=h("$ZodType",(e,t)=>{var r;e??(e={}),e._zod.def=t,e._zod.bag=e._zod.bag||{},e._zod.version=Pc;let n=e._zod.def.checks,o=e._zod.traits.has("$ZodCheck")?[e,...n??[]]:n?.length?[...n]:[];for(let s of o)for(let i of s._zod.onattach)i(e);if(o.length===0)(r=e._zod).deferred??(r.deferred=[]),e._zod.deferred?.push(()=>{e._zod.run=e._zod.parse});else{let s=(a,c,u)=>{if(a.memo)return a;let l=Ce(a),p;for(let d of c){if(d._zod.def.when){if(ba(a))continue;if(!d._zod.def.when(a))continue}else if(l)continue;let m=a.issues.length,f=d._zod.check(a);if(f instanceof Promise&&u?.async===!1)throw new Te;if(p||f instanceof Promise)p=(p??Promise.resolve()).then(async()=>{if(await f,a.issues.length===m)return;if(wo(a.issues,m,e),!l)l=Ce(a,m)});else{if(a.issues.length===m)continue;if(wo(a.issues,m,e),!l)l=Ce(a,m)}}if(p)return p.then(()=>a);return a},i=(a,c,u)=>{if(Ce(a))return a.aborted=!0,a;let l=s(c,o,u);if(l instanceof Promise){if(u.async===!1)throw new Te;return l.then((p)=>e._zod.parse(p,u))}return e._zod.parse(l,u)};e._zod.run=(a,c)=>{if(c.skipChecks)return e._zod.parse(a,c);if(c.direction==="backward"){let l=e._zod.parse({value:a.value,issues:[]},{...c,skipChecks:!0});if(l instanceof Promise)return l.then((p)=>i(p,a,c));return i(l,a,c)}let u=e._zod.parse(a,c);if(u instanceof Promise){if(c.async===!1)throw new Te;return u.then((l)=>s(l,o,c))}return s(u,o,c)}}},{get "~standard"(){return Nr(this,"~standard",Zo(this))},set "~standard"(e){Me(this,"~standard",e)}}),Lc=(e,t)=>e.issues.length?{issues:e.issues.map((r)=>Ie(r,t,te()))}:{value:e.value};async function wh(e,t){let r={async:!0};return Lc(await e._zod.run({value:t,issues:[]},r),r)}function Zo(e){return{validate:(t)=>{let r={async:!1};try{let n=e._zod.run({value:t,issues:[]},r);if(!(n instanceof Promise))return Lc(n,r)}catch(n){}return wh(e,t)},vendor:"zod",version:1}}var Hr=h("$ZodString",(e,t)=>{U.init(e,t),e._zod.pattern=t.pattern??cc,e._zod.parse=(r,n)=>{if(t.coerce)try{r.value=String(r.value)}catch(o){}if(typeof r.value==="string")return r;return r.issues.push({expected:"string",code:"invalid_type",input:r.value,inst:e}),r}}),D=h("$ZodStringFormat",(e,t)=>{Yt.init(e,t),Hr.init(e,t)}),Zc=h("$ZodGUID",(e,t)=>{t.pattern??(t.pattern=Ka),D.init(e,t)}),Dc=h("$ZodUUID",(e,t)=>{if(t.version){let n={v1:1,v2:2,v3:3,v4:4,v5:5,v6:6,v7:7,v8:8}[t.version];if(n===void 0)throw Error(`Invalid UUID version: "${t.version}"`);t.pattern??(t.pattern=Io(n))}else t.pattern??(t.pattern=Io());D.init(e,t)}),Nc=h("$ZodEmail",(e,t)=>{t.pattern??(t.pattern=Ja),D.init(e,t)}),Uc=1,Kr=2;function Fc(e){try{if(typeof URL<"u"&&typeof URL.canParse==="function")return URL.canParse(e);return new URL(e),!0}catch{return!1}}function vh(e,t){if(!("normalize"in t)&&!("hostname"in t)&&!("protocol"in t))return Fc(e)||Kr;return $h(e,t)}function $h(e,t){if(!t.normalize&&t.protocol?.source===rc.source&&!/^https?:\/\//i.test(e))return Uc;try{if(typeof URL<"u"){let r=URL;if(typeof r.parse==="function")return r.parse(e)??Kr}return new URL(e)}catch{return Kr}}var Sh=/[\t\n\r]/g;function kc(e){return e.replace(Sh,"")}function Ph(e,t){return t.lastIndex=0,t.test(e.hostname)}function kh(e,t){return t.lastIndex=0,t.test(e.protocol.endsWith(":")?e.protocol.slice(0,-1):e.protocol)}var Mc=h("$ZodURL",(e,t)=>{D.init(e,t),e._zod.check=(r)=>{try{let n=r.value.trim(),o=vh(n,t);if(o===Uc){r.issues.push({code:"invalid_format",format:"url",note:"Invalid URL format",input:r.value,inst:e,continue:!t.abort});return}if(o===Kr){r.issues.push({code:"invalid_format",format:"url",input:r.value,inst:e,continue:!t.abort});return}if(o===!0){r.value=kc(n);return}if(t.hostname&&!Ph(o,t.hostname))r.issues.push({code:"invalid_format",format:"url",note:"Invalid hostname",pattern:t.hostname.source,input:r.value,inst:e,continue:!t.abort});if(t.protocol&&!kh(o,t.protocol))r.issues.push({code:"invalid_format",format:"url",note:"Invalid protocol",pattern:t.protocol.source,input:r.value,inst:e,continue:!t.abort});r.value=t.normalize?o.href:kc(n);return}catch(n){r.issues.push({code:"invalid_format",format:"url",input:r.value,inst:e,continue:!t.abort})}}}),Bc=h("$ZodEmoji",(e,t)=>{t.pattern??(t.pattern=Ha()),D.init(e,t)}),Gc=h("$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.pattern=t.length===void 0?Ga:Va(t.length)),D.init(e,t)}),Vc=h("$ZodCUID",(e,t)=>{t.pattern??(t.pattern=Na),D.init(e,t)}),Wc=h("$ZodCUID2",(e,t)=>{t.pattern??(t.pattern=Ua),D.init(e,t)}),Kc=h("$ZodULID",(e,t)=>{t.pattern??(t.pattern=Fa),D.init(e,t)}),Jc=h("$ZodXID",(e,t)=>{t.pattern??(t.pattern=Ma),D.init(e,t)}),Hc=h("$ZodKSUID",(e,t)=>{t.pattern??(t.pattern=Ba),D.init(e,t)}),qc=h("$ZodISODateTime",(e,t)=>{t.pattern??(t.pattern=ac(t)),D.init(e,t)}),Yc=h("$ZodISODate",(e,t)=>{t.pattern??(t.pattern=sc),D.init(e,t)}),Xc=h("$ZodISOTime",(e,t)=>{t.pattern??(t.pattern=ic(t)),D.init(e,t)}),Qc=h("$ZodISODuration",(e,t)=>{t.pattern??(t.pattern=Wa),D.init(e,t)}),eu=h("$ZodIPv4",(e,t)=>{t.pattern??(t.pattern=qa),D.init(e,t)}),zh=/^[0-9a-fA-F:.]+$/;function tu(e){if(!zh.test(e))return!1;return Fc(`http://[${e}]`)}var ru=h("$ZodIPv6",(e,t)=>{t.pattern??(t.pattern=Ya),D.init(e,t),e._zod.check=(r)=>{if(!tu(r.value))r.issues.push({code:"invalid_format",format:"ipv6",input:r.value,inst:e,continue:!t.abort})}});var nu=h("$ZodCIDRv4",(e,t)=>{t.pattern??(t.pattern=Xa),D.init(e,t)});function Eh(e){let t=e.split("/");if(t.length!==2)return!1;let[r,n]=t;if(!n)return!1;let o=Number(n);if(`${o}`!==n)return!1;if(o<0||o>128)return!1;return tu(r)}var ou=h("$ZodCIDRv6",(e,t)=>{t.pattern??(t.pattern=Qa),D.init(e,t),e._zod.check=(r)=>{if(!Eh(r.value))r.issues.push({code:"invalid_format",format:"cidrv6",input:r.value,inst:e,continue:!t.abort})}});function su(e){if(e==="")return!0;if(/\s/.test(e))return!1;if(e.length%4!==0)return!1;try{return atob(e),!0}catch{return!1}}var Do=/^[0-9a-zA-Z+/]*={0,2}$/,iu=h("$ZodBase64",(e,t)=>{t.pattern??(t.pattern=Do),D.init(e,t),e._zod.check=(r)=>{if(su(r.value))return;r.issues.push({code:"invalid_format",format:"base64",input:r.value,inst:e,continue:!t.abort})}}),qr=/^[A-Za-z0-9_-]*$/;function Ch(e){if(!qr.test(e))return!1;let t=e.replace(/[-_]/g,(n)=>n==="-"?"+":"/"),r=t.padEnd(Math.ceil(t.length/4)*4,"=");return su(r)}var au=h("$ZodBase64URL",(e,t)=>{t.pattern??(t.pattern=qr),D.init(e,t),e._zod.check=(r)=>{if(Ch(r.value))return;r.issues.push({code:"invalid_format",format:"base64url",input:r.value,inst:e,continue:!t.abort})}}),cu=h("$ZodE164",(e,t)=>{t.pattern??(t.pattern=nc),D.init(e,t)});function Ih(e,t=null){try{let r=e.split(".");if(r.length!==3)return!1;let[n]=r;if(!n)return!1;let o=JSON.parse(atob(n));if("typ"in o&&o?.typ!=="JWT")return!1;if(!o.alg)return!1;if(t&&(!("alg"in o)||o.alg!==t))return!1;return!0}catch{return!1}}var uu=h("$ZodJWT",(e,t)=>{D.init(e,t),e._zod.check=(r)=>{if(Ih(r.value,t.alg))return;r.issues.push({code:"invalid_format",format:"jwt",input:r.value,inst:e,continue:!t.abort})}});var No=h("$ZodNumber",(e,t)=>{U.init(e,t),e._zod.pattern=qt,e._zod.parse=(r,n)=>{if(t.coerce)try{r.value=Number(r.value)}catch(i){}let o=r.value;if(typeof o==="number"&&!Number.isNaN(o)&&Number.isFinite(o))return r;let s=typeof o==="number"?Number.isNaN(o)?"NaN":!Number.isFinite(o)?String(o):void 0:void 0;return r.issues.push({expected:"number",code:"invalid_type",input:o,inst:e,...s?{received:s}:{}}),r}}),lu=h("$ZodNumberFormat",(e,t)=>{mc.init(e,t),No.init(e,t)}),pu=h("$ZodBoolean",(e,t)=>{U.init(e,t),e._zod.pattern=uc,e._zod.parse=(r,n)=>{if(t.coerce)try{r.value=Boolean(r.value)}catch(s){}let o=r.value;if(typeof o==="boolean")return r;return r.issues.push({expected:"boolean",code:"invalid_type",input:o,inst:e}),r}});var du=h("$ZodUnknown",(e,t)=>{U.init(e,t),e._zod.parse=(r)=>r}),mu=h("$ZodNever",(e,t)=>{U.init(e,t),e._zod.parse=(r,n)=>(r.issues.push({expected:"never",code:"invalid_type",input:r.value,inst:e}),r)});function zc(e,t,r){if(e.issues.length)t.issues.push(...Je(r,e.issues));t.value[r]=e.value}var fu=h("$ZodArray",(e,t)=>{U.init(e,t);let r=ee.memoizer;r?.attach(e),e._zod.parse=(n,o)=>{let s=n.value;if(!Array.isArray(s))return n.issues.push({expected:"array",code:"invalid_type",input:s,inst:e}),n;n.value=r?r.alloc(e,n,Array(s.length),o):Array(s.length);let i=[],a=o?.abortEarly;for(let c=0;c<s.length;c++){let u=s[c],l=t.element._zod.run({value:u,issues:[]},o);if(l instanceof Promise)i.push(l.then((p)=>zc(p,n,c)));else if(zc(l,n,c),a&&l.issues.length!==0&&Ce(l))break}if(i.length)return Promise.all(i).then(()=>n);return n}});function Jr(e,t,r,n,o,s){let i=r in n,a=s==="optional";if(!i&&a&&o==="optional")return;if(e.issues.length){if(o!==void 0&&a&&!i)return;t.issues.push(...Je(r,e.issues))}if(!i&&o===void 0){if(!e.issues.length)t.issues.push({code:"invalid_type",expected:"nonoptional",input:void 0,path:[r]});return}if(e.value===void 0){if(i||o==="defaulted"&&!a)t.value[r]=void 0}else t.value[r]=e.value}var Th=[];function hu(e){let t=Object.keys(e.shape),r=Object.getOwnPropertySymbols(e.shape),n=r.length?r:Th,o=n.length?[...t,...n]:t;for(let i of o)if(!e.shape?.[i]?._zod?.traits?.has("$ZodType"))throw Error(`Invalid element at key "${String(i)}": expected a Zod schema`);let s=xa(e.shape);return{...e,allKeys:o,symbolKeys:n,keySet:new Set(t),numKeys:t.length,optionalKeys:new Set(s)}}function gu(e,t,r,n,o,s,i){let a=[],c=o.keySet,u=o.catchall._zod,l=u.def.type,{optin:p,optout:d}=u,m=0;for(let f in t){if(i&&r.issues.length!==m){if(Ce(r,m))break;m=r.issues.length}if(c.has(f))continue;if(f==="__proto__"){if(l==="never")a.push(f);continue}if(l==="never"){a.push(f);continue}let g=u.run({value:t[f],issues:[]},n);if(g instanceof Promise)e.push(g.then((x)=>Jr(x,r,f,t,p,d)));else Jr(g,r,f,t,p,d)}if(a.length)r.issues.push({code:"unrecognized_keys",keys:a,input:t,inst:s,continue:!0});if(!e.length)return r;return Promise.all(e).then(()=>r)}var Oh=h("$ZodObject",(e,t)=>{U.init(e,t);let r=Object.getOwnPropertyDescriptor(t,"shape"),n=r?.get?r.get.raw:t.shape??{};if(n){let u=()=>{let l={...n};return Object.defineProperty(t,"shape",{value:l}),u.raw=l,l};u.raw=n,Object.defineProperty(t,"shape",{get:u})}let o=Or(()=>hu(t));R(e,"propValues",(u)=>{let l=u.def.shape,p={};for(let d in l){let m=l[d]._zod;if(m.values){if(!Object.prototype.hasOwnProperty.call(p,d))ve(p,d,new Set);for(let f of m.values)p[d].add(f);if(m.optin!==void 0)p[d].add(void 0)}}return p});let s=Vt,i=t.catchall,a,c=ee.memoizer;c?.attach(e),e._zod.parse=(u,l)=>{a??(a=o.value);let p=u.value;if(!s(p))return u.issues.push({expected:"object",code:"invalid_type",input:p,inst:e}),u;u.value=c?c.alloc(e,u,{},l):{};let d=[],m=a.shape,f=l?.abortEarly,g=u.issues.length;for(let x of a.allKeys){if(f&&u.issues.length!==g){if(Ce(u,g))break;g=u.issues.length}if(x==="__proto__")continue;let y=m[x],w=y._zod.optin,k=y._zod.optout,I=y._zod.run({value:p[x],issues:[]},l);if(I instanceof Promise)d.push(I.then((_)=>Jr(_,u,x,p,w,k)));else Jr(I,u,x,p,w,k)}if(!i)return d.length?Promise.all(d).then(()=>u):u;return gu(d,p,u,l,o.value,e,f===!0)}}),xu=h("$ZodObjectJIT",(e,t)=>{Oh.init(e,t);let r=e._zod.parse,n=Or(()=>hu(t)),o=ee.memoizer,s=(m)=>{let f=n.value,g=f.symbolKeys,x=new Ro(["payload","ctx"],{shape:m,inst:e,memo:o,syms:g}),y=(_)=>`shape[${_}]._zod.run({ value: input[${_}], issues: [] }, ctx)`,w=(_,S)=>`
|
|
38
|
-
let ${
|
|
39
|
-
for (let i = 0; i < ${
|
|
40
|
-
const iss = ${
|
|
41
|
-
iss.path = iss.path ? [${
|
|
37
|
+
};`)(...Object.values(this.closed))}}var Du={major:4,minor:6,patch:5};var q=g("$ZodType",(e,t)=>{var r;e??(e={}),e._zod.def=t,e._zod.bag=e._zod.bag||{},e._zod.version=Du;let n=e._zod.def.checks,o=e._zod.traits.has("$ZodCheck")?[e,...n??[]]:n?.length?[...n]:[];for(let s of o)for(let i of s._zod.onattach)i(e);if(o.length===0)(r=e._zod).deferred??(r.deferred=[]),e._zod.deferred?.push(()=>{e._zod.run=e._zod.parse});else{let s=(a,c,l)=>{if(a.memo)return a;let u=Be(a),p;for(let d of c){if(d._zod.def.when){if(Tl(a))continue;if(!d._zod.def.when(a))continue}else if(u)continue;let f=a.issues.length,h=d._zod.check(a);if(h instanceof Promise&&l?.async===!1)throw new Ke;if(p||h instanceof Promise)p=(p??Promise.resolve()).then(async()=>{if(await h,a.issues.length===f)return;if(Zs(a.issues,f,e),!u)u=Be(a,f)});else{if(a.issues.length===f)continue;if(Zs(a.issues,f,e),!u)u=Be(a,f)}}if(p)return p.then(()=>a);return a},i=(a,c,l)=>{if(Be(a))return a.aborted=!0,a;let u=s(c,o,l);if(u instanceof Promise){if(l.async===!1)throw new Ke;return u.then((p)=>e._zod.parse(p,l))}return e._zod.parse(u,l)};e._zod.run=(a,c)=>{if(c.skipChecks)return e._zod.parse(a,c);if(c.direction==="backward"){let u=e._zod.parse({value:a.value,issues:[]},{...c,skipChecks:!0});if(u instanceof Promise)return u.then((p)=>i(p,a,c));return i(u,a,c)}let l=e._zod.parse(a,c);if(l instanceof Promise){if(c.async===!1)throw new Ke;return l.then((u)=>s(u,o,c))}return s(l,o,c)}}},{get "~standard"(){return Ln(this,"~standard",ti(this))},set "~standard"(e){st(this,"~standard",e)}}),Hu=(e,t)=>e.issues.length?{issues:e.issues.map((r)=>Ge(r,t,_e()))}:{value:e.value};async function sx(e,t){let r={async:!0};return Hu(await e._zod.run({value:t,issues:[]},r),r)}function ti(e){return{validate:(t)=>{let r={async:!1};try{let n=e._zod.run({value:t,issues:[]},r);if(!(n instanceof Promise))return Hu(n,r)}catch(n){}return sx(e,t)},vendor:"zod",version:1}}var Vn=g("$ZodString",(e,t)=>{q.init(e,t),e._zod.pattern=t.pattern??wu,e._zod.parse=(r,n)=>{if(t.coerce)try{r.value=String(r.value)}catch(o){}if(typeof r.value==="string")return r;return r.issues.push({expected:"string",code:"invalid_type",input:r.value,inst:e}),r}}),W=g("$ZodStringFormat",(e,t)=>{Rr.init(e,t),Vn.init(e,t)}),Ju=g("$ZodGUID",(e,t)=>{t.pattern??(t.pattern=su),W.init(e,t)}),qu=g("$ZodUUID",(e,t)=>{if(t.version){let n={v1:1,v2:2,v3:3,v4:4,v5:5,v6:6,v7:7,v8:8}[t.version];if(n===void 0)throw Error(`Invalid UUID version: "${t.version}"`);t.pattern??(t.pattern=Hs(n))}else t.pattern??(t.pattern=Hs());W.init(e,t)}),Yu=g("$ZodEmail",(e,t)=>{t.pattern??(t.pattern=iu),W.init(e,t)}),Xu=1,Gn=2;function Qu(e){try{if(typeof URL<"u"&&typeof URL.canParse==="function")return URL.canParse(e);return new URL(e),!0}catch{return!1}}function ix(e,t){if(!("normalize"in t)&&!("hostname"in t)&&!("protocol"in t))return Qu(e)||Gn;return ax(e,t)}function ax(e,t){if(!t.normalize&&t.protocol?.source===fu.source&&!/^https?:\/\//i.test(e))return Xu;try{if(typeof URL<"u"){let r=URL;if(typeof r.parse==="function")return r.parse(e)??Gn}return new URL(e)}catch{return Gn}}var cx=/[\t\n\r]/g;function Nu(e){return e.replace(cx,"")}function lx(e,t){return t.lastIndex=0,t.test(e.hostname)}function ux(e,t){return t.lastIndex=0,t.test(e.protocol.endsWith(":")?e.protocol.slice(0,-1):e.protocol)}var ep=g("$ZodURL",(e,t)=>{W.init(e,t),e._zod.check=(r)=>{try{let n=r.value.trim(),o=ix(n,t);if(o===Xu){r.issues.push({code:"invalid_format",format:"url",note:"Invalid URL format",input:r.value,inst:e,continue:!t.abort});return}if(o===Gn){r.issues.push({code:"invalid_format",format:"url",input:r.value,inst:e,continue:!t.abort});return}if(o===!0){r.value=Nu(n);return}if(t.hostname&&!lx(o,t.hostname))r.issues.push({code:"invalid_format",format:"url",note:"Invalid hostname",pattern:t.hostname.source,input:r.value,inst:e,continue:!t.abort});if(t.protocol&&!ux(o,t.protocol))r.issues.push({code:"invalid_format",format:"url",note:"Invalid protocol",pattern:t.protocol.source,input:r.value,inst:e,continue:!t.abort});r.value=t.normalize?o.href:Nu(n);return}catch(n){r.issues.push({code:"invalid_format",format:"url",input:r.value,inst:e,continue:!t.abort})}}}),tp=g("$ZodEmoji",(e,t)=>{t.pattern??(t.pattern=au()),W.init(e,t)}),rp=g("$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.pattern=t.length===void 0?ru:nu(t.length)),W.init(e,t)}),np=g("$ZodCUID",(e,t)=>{t.pattern??(t.pattern=Yl),W.init(e,t)}),op=g("$ZodCUID2",(e,t)=>{t.pattern??(t.pattern=Xl),W.init(e,t)}),sp=g("$ZodULID",(e,t)=>{t.pattern??(t.pattern=Ql),W.init(e,t)}),ip=g("$ZodXID",(e,t)=>{t.pattern??(t.pattern=eu),W.init(e,t)}),ap=g("$ZodKSUID",(e,t)=>{t.pattern??(t.pattern=tu),W.init(e,t)}),cp=g("$ZodISODateTime",(e,t)=>{t.pattern??(t.pattern=xu(t)),W.init(e,t)}),lp=g("$ZodISODate",(e,t)=>{t.pattern??(t.pattern=yu),W.init(e,t)}),up=g("$ZodISOTime",(e,t)=>{t.pattern??(t.pattern=bu(t)),W.init(e,t)}),pp=g("$ZodISODuration",(e,t)=>{t.pattern??(t.pattern=ou),W.init(e,t)}),dp=g("$ZodIPv4",(e,t)=>{t.pattern??(t.pattern=cu),W.init(e,t)}),px=/^[0-9a-fA-F:.]+$/;function mp(e){if(!px.test(e))return!1;return Qu(`http://[${e}]`)}var fp=g("$ZodIPv6",(e,t)=>{t.pattern??(t.pattern=lu),W.init(e,t),e._zod.check=(r)=>{if(!mp(r.value))r.issues.push({code:"invalid_format",format:"ipv6",input:r.value,inst:e,continue:!t.abort})}});var hp=g("$ZodCIDRv4",(e,t)=>{t.pattern??(t.pattern=uu),W.init(e,t)});function dx(e){let t=e.split("/");if(t.length!==2)return!1;let[r,n]=t;if(!n)return!1;let o=Number(n);if(`${o}`!==n)return!1;if(o<0||o>128)return!1;return mp(r)}var gp=g("$ZodCIDRv6",(e,t)=>{t.pattern??(t.pattern=pu),W.init(e,t),e._zod.check=(r)=>{if(!dx(r.value))r.issues.push({code:"invalid_format",format:"cidrv6",input:r.value,inst:e,continue:!t.abort})}});function yp(e){if(e==="")return!0;if(/\s/.test(e))return!1;if(e.length%4!==0)return!1;try{return atob(e),!0}catch{return!1}}var ri=/^[0-9a-zA-Z+/]*={0,2}$/,bp=g("$ZodBase64",(e,t)=>{t.pattern??(t.pattern=ri),W.init(e,t),e._zod.check=(r)=>{if(yp(r.value))return;r.issues.push({code:"invalid_format",format:"base64",input:r.value,inst:e,continue:!t.abort})}}),Wn=/^[A-Za-z0-9_-]*$/;function mx(e){if(!Wn.test(e))return!1;let t=e.replace(/[-_]/g,(n)=>n==="-"?"+":"/"),r=t.padEnd(Math.ceil(t.length/4)*4,"=");return yp(r)}var xp=g("$ZodBase64URL",(e,t)=>{t.pattern??(t.pattern=Wn),W.init(e,t),e._zod.check=(r)=>{if(mx(r.value))return;r.issues.push({code:"invalid_format",format:"base64url",input:r.value,inst:e,continue:!t.abort})}}),wp=g("$ZodE164",(e,t)=>{t.pattern??(t.pattern=hu),W.init(e,t)});function fx(e,t=null){try{let r=e.split(".");if(r.length!==3)return!1;let[n]=r;if(!n)return!1;let o=JSON.parse(atob(n));if("typ"in o&&o?.typ!=="JWT")return!1;if(!o.alg)return!1;if(t&&(!("alg"in o)||o.alg!==t))return!1;return!0}catch{return!1}}var _p=g("$ZodJWT",(e,t)=>{W.init(e,t),e._zod.check=(r)=>{if(fx(r.value,t.alg))return;r.issues.push({code:"invalid_format",format:"jwt",input:r.value,inst:e,continue:!t.abort})}});var ni=g("$ZodNumber",(e,t)=>{q.init(e,t),e._zod.pattern=Tr,e._zod.parse=(r,n)=>{if(t.coerce)try{r.value=Number(r.value)}catch(i){}let o=r.value;if(typeof o==="number"&&!Number.isNaN(o)&&Number.isFinite(o))return r;let s=typeof o==="number"?Number.isNaN(o)?"NaN":!Number.isFinite(o)?String(o):void 0:void 0;return r.issues.push({expected:"number",code:"invalid_type",input:o,inst:e,...s?{received:s}:{}}),r}}),vp=g("$ZodNumberFormat",(e,t)=>{ku.init(e,t),ni.init(e,t)}),$p=g("$ZodBoolean",(e,t)=>{q.init(e,t),e._zod.pattern=_u,e._zod.parse=(r,n)=>{if(t.coerce)try{r.value=Boolean(r.value)}catch(s){}let o=r.value;if(typeof o==="boolean")return r;return r.issues.push({expected:"boolean",code:"invalid_type",input:o,inst:e}),r}});var Sp=g("$ZodUnknown",(e,t)=>{q.init(e,t),e._zod.parse=(r)=>r}),kp=g("$ZodNever",(e,t)=>{q.init(e,t),e._zod.parse=(r,n)=>(r.issues.push({expected:"never",code:"invalid_type",input:r.value,inst:e}),r)});function Zu(e,t,r){if(e.issues.length)t.issues.push(...gt(r,e.issues));t.value[r]=e.value}var Pp=g("$ZodArray",(e,t)=>{q.init(e,t);let r=we.memoizer;r?.attach(e),e._zod.parse=(n,o)=>{let s=n.value;if(!Array.isArray(s))return n.issues.push({expected:"array",code:"invalid_type",input:s,inst:e}),n;n.value=r?r.alloc(e,n,Array(s.length),o):Array(s.length);let i=[],a=o?.abortEarly;for(let c=0;c<s.length;c++){let l=s[c],u=t.element._zod.run({value:l,issues:[]},o);if(u instanceof Promise)i.push(u.then((p)=>Zu(p,n,c)));else if(Zu(u,n,c),a&&u.issues.length!==0&&Be(u))break}if(i.length)return Promise.all(i).then(()=>n);return n}});function Kn(e,t,r,n,o,s){let i=r in n,a=s==="optional";if(!i&&a&&o==="optional")return;if(e.issues.length){if(o!==void 0&&a&&!i)return;t.issues.push(...gt(r,e.issues))}if(!i&&o===void 0){if(!e.issues.length)t.issues.push({code:"invalid_type",expected:"nonoptional",input:void 0,path:[r]});return}if(e.value===void 0){if(i||o==="defaulted"&&!a)t.value[r]=void 0}else t.value[r]=e.value}var hx=[];function Cp(e){let t=Object.keys(e.shape),r=Object.getOwnPropertySymbols(e.shape),n=r.length?r:hx,o=n.length?[...t,...n]:t;for(let i of o)if(!e.shape?.[i]?._zod?.traits?.has("$ZodType"))throw Error(`Invalid element at key "${String(i)}": expected a Zod schema`);let s=zl(e.shape);return{...e,allKeys:o,symbolKeys:n,keySet:new Set(t),numKeys:t.length,optionalKeys:new Set(s)}}function Ep(e,t,r,n,o,s,i){let a=[],c=o.keySet,l=o.catchall._zod,u=l.def.type,{optin:p,optout:d}=l,f=0;for(let h in t){if(i&&r.issues.length!==f){if(Be(r,f))break;f=r.issues.length}if(c.has(h))continue;if(h==="__proto__"){if(u==="never")a.push(h);continue}if(u==="never"){a.push(h);continue}let y=l.run({value:t[h],issues:[]},n);if(y instanceof Promise)e.push(y.then((b)=>Kn(b,r,h,t,p,d)));else Kn(y,r,h,t,p,d)}if(a.length)r.issues.push({code:"unrecognized_keys",keys:a,input:t,inst:s,continue:!0});if(!e.length)return r;return Promise.all(e).then(()=>r)}var gx=g("$ZodObject",(e,t)=>{q.init(e,t);let r=Object.getOwnPropertyDescriptor(t,"shape"),n=r?.get?r.get.raw:t.shape??{};if(n){let l=()=>{let u={...n};return Object.defineProperty(t,"shape",{value:u}),l.raw=u,u};l.raw=n,Object.defineProperty(t,"shape",{get:l})}let o=zn(()=>Cp(t));B(e,"propValues",(l)=>{let u=l.def.shape,p={};for(let d in u){let f=u[d]._zod;if(f.values){if(!Object.prototype.hasOwnProperty.call(p,d))Ne(p,d,new Set);for(let h of f.values)p[d].add(h);if(f.optin!==void 0)p[d].add(void 0)}}return p});let s=Er,i=t.catchall,a,c=we.memoizer;c?.attach(e),e._zod.parse=(l,u)=>{a??(a=o.value);let p=l.value;if(!s(p))return l.issues.push({expected:"object",code:"invalid_type",input:p,inst:e}),l;l.value=c?c.alloc(e,l,{},u):{};let d=[],f=a.shape,h=u?.abortEarly,y=l.issues.length;for(let b of a.allKeys){if(h&&l.issues.length!==y){if(Be(l,y))break;y=l.issues.length}if(b==="__proto__")continue;let _=f[b],P=_._zod.optin,O=_._zod.optout,D=_._zod.run({value:p[b],issues:[]},u);if(D instanceof Promise)d.push(D.then((S)=>Kn(S,l,b,p,P,O)));else Kn(D,l,b,p,P,O)}if(!i)return d.length?Promise.all(d).then(()=>l):l;return Ep(d,p,l,u,o.value,e,h===!0)}}),zp=g("$ZodObjectJIT",(e,t)=>{gx.init(e,t);let r=e._zod.parse,n=zn(()=>Cp(t)),o=we.memoizer,s=(f)=>{let h=n.value,y=h.symbolKeys,b=new Qs(["payload","ctx"],{shape:f,inst:e,memo:o,syms:y}),_=(S)=>`shape[${S}]._zod.run({ value: input[${S}], issues: [] }, ctx)`,P=(S,T)=>`
|
|
38
|
+
let ${S}_ab = false;
|
|
39
|
+
for (let i = 0; i < ${S}.issues.length; i++) {
|
|
40
|
+
const iss = ${S}.issues[i];
|
|
41
|
+
iss.path = iss.path ? [${T}, ...iss.path] : [${T}];
|
|
42
42
|
payload.issues.push(iss);
|
|
43
|
-
if (iss.continue !== true) ${
|
|
43
|
+
if (iss.continue !== true) ${S}_ab = true;
|
|
44
44
|
}
|
|
45
|
-
if (${
|
|
45
|
+
if (${S}_ab && ctx && ctx.abortEarly) {
|
|
46
46
|
payload.value = newResult;
|
|
47
47
|
return payload;
|
|
48
|
-
}`;
|
|
49
|
-
const ${
|
|
50
|
-
if (!${
|
|
51
|
-
if (${
|
|
48
|
+
}`;b.write("const input = payload.value;");let O=Object.create(null),D=0;for(let S of h.allKeys)O[S]=`key_${D++}`;b.write(o?"const newResult = memo.alloc(inst, payload, {}, ctx);":"const newResult = {};");for(let S of h.allKeys){if(S==="__proto__")continue;let T=O[S],U=typeof S==="symbol"?`syms[${y.indexOf(S)}]`:kl(S),ce=`${U} in input`,L=f[S],F=L?._zod?.optin,ne=F!==void 0,le=L?._zod?.optout==="optional";if(b.write(`const ${T} = ${_(U)};`),ne&&le){let Te=F==="optional"?`${T}_present`:`${T}.value !== undefined || ${T}_present`;b.write(`
|
|
49
|
+
const ${T}_present = ${ce};
|
|
50
|
+
if (!${T}.issues.length || ${T}_present) {
|
|
51
|
+
if (${T}.issues.length) {${P(T,U)}
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
if (${
|
|
55
|
-
newResult[${
|
|
54
|
+
if (${Te}) {
|
|
55
|
+
newResult[${U}] = ${T}.value;
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
`)}else if(!
|
|
60
|
-
const ${
|
|
61
|
-
if (${
|
|
59
|
+
`)}else if(!ne)b.write(`
|
|
60
|
+
const ${T}_present = ${ce};
|
|
61
|
+
if (${T}.issues.length) {${P(T,U)}
|
|
62
62
|
}
|
|
63
|
-
if (!${
|
|
63
|
+
if (!${T}_present && !${T}.issues.length) {
|
|
64
64
|
payload.issues.push({
|
|
65
65
|
code: "invalid_type",
|
|
66
66
|
expected: "nonoptional",
|
|
67
67
|
input: undefined,
|
|
68
|
-
path: [${
|
|
68
|
+
path: [${U}]
|
|
69
69
|
});
|
|
70
70
|
if (ctx && ctx.abortEarly) {
|
|
71
71
|
payload.value = newResult;
|
|
@@ -73,27 +73,30 @@ ${t.join(`
|
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
-
if (${
|
|
77
|
-
newResult[${
|
|
76
|
+
if (${T}_present) {
|
|
77
|
+
newResult[${U}] = ${T}.value;
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
-
`);else if(
|
|
81
|
-
if (${
|
|
80
|
+
`);else if(b.write(`
|
|
81
|
+
if (${T}.issues.length) {${P(T,U)}
|
|
82
82
|
}
|
|
83
|
-
`),
|
|
84
|
-
if (${
|
|
85
|
-
newResult[${
|
|
83
|
+
`),F==="defaulted")b.write(`newResult[${U}] = ${T}.value;`);else b.write(`
|
|
84
|
+
if (${T}.value !== undefined || ${ce}) {
|
|
85
|
+
newResult[${U}] = ${T}.value;
|
|
86
86
|
}
|
|
87
|
-
`)}return x.write("payload.value = newResult;"),x.write("return payload;"),x.compile()},i,a=Vt,c=!ee.jitless,l=c&&ha.value,p=t.catchall,d;e._zod.parse=(m,f)=>{d??(d=n.value);let g=m.value;if(!a(g))return m.issues.push({expected:"object",code:"invalid_type",input:g,inst:e}),m;if(c&&l&&f?.async===!1&&f.jitless!==!0){if(!i)i=s(t.shape);if(m=i(m,f),!p)return m;return gu([],g,m,f,d,e,f?.abortEarly===!0)}return r(m,f)}});function Ec(e,t,r,n){for(let s of e)if(s.issues.length===0)return t.value=s.value,t;let o=e.filter((s)=>!Ce(s));if(o.length===1)return t.value=o[0].value,o[0];return t.issues.push({code:"invalid_union",input:t.value,inst:r,errors:e.map((s)=>s.issues.map((i)=>Ie(i,n,te())))}),t}var yu=h("$ZodUnion",(e,t)=>{U.init(e,t),R(e,"optin",(n)=>n.def.options.some((o)=>o._zod.optin==="defaulted")?"defaulted":n.def.options.some((o)=>o._zod.optin!==void 0)?"optional":void 0),R(e,"optout",(n)=>n.def.options.some((o)=>o._zod.optout==="optional")?"optional":void 0),R(e,"values",(n)=>{if(n.def.options.every((o)=>o._zod.values))return new Set(n.def.options.flatMap((o)=>Array.from(o._zod.values)));return}),R(e,"pattern",(n)=>{if(n.def.options.every((o)=>o._zod.pattern)){let o=n.def.options.map((s)=>s._zod.pattern);return new RegExp(`^(${o.map((s)=>Ar(s.source)).join("|")})$`)}return});let r=t.options.length===1?t.options[0]._zod.run:null;e._zod.parse=(n,o)=>{if(r)return r(n,o);let s=!1,i=[];for(let a of t.options){let c=a._zod.run({value:n.value,issues:[]},o);if(c instanceof Promise)i.push(c),s=!0;else{if(c.issues.length===0)return c;i.push(c)}}if(!s)return Ec(i,n,e,o);return Promise.all(i).then((a)=>Ec(a,n,e,o))}});var _u=h("$ZodIntersection",(e,t)=>{U.init(e,t),e._zod.parse=(r,n)=>{let o=r.value,s=t.left._zod.run({value:o,issues:[]},n),i=t.right._zod.run({value:o,issues:[]},n);if(s instanceof Promise||i instanceof Promise)return Promise.all([s,i]).then(([c,u])=>Cc(r,c,u));return Cc(r,s,i)}});function Lo(e,t){if(e===t)return{valid:!0,data:e};if(e instanceof Date&&t instanceof Date&&+e===+t)return{valid:!0,data:e};if(it(e)&&it(t)){let r=Object.keys(t),n=Object.keys(e).filter((s)=>r.indexOf(s)!==-1),o={...e,...t};if(Object.prototype.hasOwnProperty.call(o,"__proto__"))delete o.__proto__;for(let s of n){if(s==="__proto__")continue;let i=Lo(e[s],t[s]);if(!i.valid)return{valid:!1,mergeErrorPath:[s,...i.mergeErrorPath]};o[s]=i.data}return{valid:!0,data:o}}if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return{valid:!1,mergeErrorPath:[]};let r=[];for(let n=0;n<e.length;n++){let o=e[n],s=t[n],i=Lo(o,s);if(!i.valid)return{valid:!1,mergeErrorPath:[n,...i.mergeErrorPath]};r.push(i.data)}return{valid:!0,data:r}}return{valid:!1,mergeErrorPath:[]}}function Cc(e,t,r){let n=new Map,o,s=new Map,i=(u,l)=>{let p;if(u.code==="unrecognized_keys"&&!u.path?.length)o??(o=u),p=u.keys;else if(u.code==="invalid_key"&&u.origin==="record"&&u.path?.length===1){let d=String(u.path[0]);if(!s.has(d))s.set(d,u);p=[d]}else return!1;for(let d of p){if(!n.has(d))n.set(d,{});n.get(d)[l]=!0}return!0};for(let u of t.issues)if(!i(u,"l"))e.issues.push(u);for(let u of r.issues)if(!i(u,"r"))e.issues.push(u);let a=[...n].filter(([,u])=>u.l&&u.r).map(([u])=>u);if(a.length){let u=o?a.filter((l)=>o.keys.includes(l)):[];if(u.length)e.issues.push({...o,keys:u});for(let l of a)if(!u.includes(l)&&s.has(l))e.issues.push(s.get(l))}let c=Lo(t.value,r.value);if(!c.valid){if(Ce(e))return e;throw Error(`Unmergable intersection. Error path: ${JSON.stringify(c.mergeErrorPath)}`)}return e.value=c.data,e}var bu=h("$ZodRecord",(e,t)=>{U.init(e,t);let r=ee.memoizer;r?.attach(e),e._zod.parse=(n,o)=>{let s=n.value;if(!it(s))return n.issues.push({expected:"record",code:"invalid_type",input:s,inst:e}),n;let i=[],a=t.keyType._zod.values;if(a&&!t.partial){n.value=r?r.alloc(e,n,{},o):{};let c=new Set;for(let l of a)if(typeof l==="string"||typeof l==="number"||typeof l==="symbol"){if(c.add(typeof l==="number"?l.toString():l),l==="__proto__")continue;let p=t.keyType._zod.run({value:l,issues:[]},o);if(p instanceof Promise)throw Error("Async schemas not supported in object keys currently");if(p.issues.length){n.issues.push({code:"invalid_key",origin:"record",issues:p.issues.map((f)=>Ie(f,o,te())),input:l,path:[l],inst:e});continue}let d=p.value;if(d==="__proto__")continue;let m=t.valueType._zod.run({value:s[l],issues:[]},o);if(m instanceof Promise)i.push(m.then((f)=>{if(f.issues.length)n.issues.push(...Je(l,f.issues));n.value[d]=f.value}));else{if(m.issues.length)n.issues.push(...Je(l,m.issues));n.value[d]=m.value}}let u;for(let l in s)if(!c.has(l))if(t.mode==="loose"){if(l==="__proto__")continue;n.value[l]=s[l]}else u=u??[],u.push(l);if(u&&u.length>0)n.issues.push({code:"unrecognized_keys",input:s,inst:e,keys:u,continue:!0})}else{n.value=r?r.alloc(e,n,{},o):{};let c;for(let u of Reflect.ownKeys(s)){if(u==="__proto__")continue;if(!Object.prototype.propertyIsEnumerable.call(s,u))continue;let l=t.keyType._zod.run({value:u,issues:[]},o);if(l instanceof Promise)throw Error("Async schemas not supported in object keys currently");if(typeof u==="string"&&qt.test(u)&&l.issues.length){let f=t.keyType._zod.run({value:Number(u),issues:[]},o);if(f instanceof Promise)throw Error("Async schemas not supported in object keys currently");if(f.issues.length===0)l=f}if(l.issues.length){if(t.mode==="loose")n.value[u]=s[u];else if(a)c=c??[],c.push(u);else n.issues.push({code:"invalid_key",origin:"record",issues:l.issues.map((f)=>Ie(f,o,te())),input:u,path:[u],inst:e});continue}let d=l.value;if(d==="__proto__")continue;let m=t.valueType._zod.run({value:s[u],issues:[]},o);if(m instanceof Promise)i.push(m.then((f)=>{if(f.issues.length)n.issues.push(...Je(u,f.issues));n.value[d]=f.value}));else{if(m.issues.length)n.issues.push(...Je(u,m.issues));n.value[d]=m.value}}if(c&&c.length>0)n.issues.push({code:"unrecognized_keys",input:s,inst:e,keys:c,continue:!0})}if(i.length)return Promise.all(i).then(()=>n);return n}});var wu=h("$ZodEnum",(e,t)=>{U.init(e,t);let r=Wt(t.entries),n=new Set(r);e._zod.values=n,R(e,"pattern",(o)=>{let s=Wt(o.def.entries).filter((i)=>ga.has(typeof i));return new RegExp(s.length?`^(${s.map((i)=>bt(i.toString())).join("|")})$`:"^[^\\s\\S]$")}),e._zod.parse=(o,s)=>{let i=o.value;if(n.has(i))return o;return o.issues.push({code:"invalid_value",values:r,input:i,inst:e}),o}});var vu=h("$ZodTransform",(e,t)=>{U.init(e,t),e._zod.optin="optional",ee.memoizer?.guard(e),e._zod.parse=(r,n)=>{if(n.direction==="backward")throw new Jt(e.constructor.name);let o=t.transform(r.value,r);if(n.async)return(o instanceof Promise?o:Promise.resolve(o)).then((i)=>(r.value=i,r));if(o instanceof Promise)throw new Te;return r.value=o,r}});function Ic(e,t){return e.value=t.issues.length?void 0:t.value,e}var Uo=h("$ZodOptional",(e,t)=>{U.init(e,t),R(e,"optin",(r)=>r.def.innerType._zod.optin==="defaulted"?"defaulted":"optional"),e._zod.optout="optional",R(e,"values",(r)=>{let n=r.def.innerType._zod.values;return n?new Set([...n,void 0]):void 0}),R(e,"pattern",(r)=>{let n=r.def.innerType._zod.pattern;return n?new RegExp(`^(${Ar(n.source)})?$`):void 0}),e._zod.parse=(r,n)=>{if(r.value===void 0){if(t.innerType._zod.optin!=="defaulted")return r;let o=t.innerType._zod.run({value:r.value,issues:[]},n);if(o instanceof Promise)return o.then((s)=>Ic(r,s));return Ic(r,o)}return t.innerType._zod.run(r,n)}}),$u=h("$ZodExactOptional",(e,t)=>{Uo.init(e,t),R(e,"values",(r)=>r.def.innerType._zod.values),R(e,"pattern",(r)=>r.def.innerType._zod.pattern),e._zod.parse=(r,n)=>t.innerType._zod.run(r,n)}),Su=h("$ZodNullable",(e,t)=>{U.init(e,t),R(e,"optin",(r)=>r.def.innerType._zod.optin),R(e,"optout",(r)=>r.def.innerType._zod.optout),R(e,"pattern",(r)=>{let n=r.def.innerType._zod.pattern;return n?new RegExp(`^(${Ar(n.source)}|null)$`):void 0}),R(e,"values",(r)=>r.def.innerType._zod.values?new Set([...r.def.innerType._zod.values,null]):void 0),e._zod.parse=(r,n)=>{if(r.value===null)return r;return t.innerType._zod.run(r,n)}}),Pu=h("$ZodDefault",(e,t)=>{U.init(e,t),e._zod.optin="defaulted",R(e,"values",(r)=>r.def.innerType._zod.values),e._zod.parse=(r,n)=>{if(n.direction==="backward")return t.innerType._zod.run(r,n);if(r.value===void 0)return r.value=t.defaultValue,r;let o=t.innerType._zod.run(r,n);if(o instanceof Promise)return o.then((s)=>Tc(s,t));return Tc(o,t)}});function Tc(e,t){if(e.value===void 0)e.value=t.defaultValue;return e}var ku=h("$ZodPrefault",(e,t)=>{U.init(e,t),e._zod.optin="defaulted",R(e,"values",(r)=>r.def.innerType._zod.values),e._zod.parse=(r,n)=>{if(n.direction==="backward")return t.innerType._zod.run(r,n);if(r.value===void 0)r.value=t.defaultValue;return t.innerType._zod.run(r,n)}}),zu=h("$ZodNonOptional",(e,t)=>{U.init(e,t),R(e,"values",(r)=>{let n=r.def.innerType._zod.values;return n?new Set([...n].filter((o)=>o!==void 0)):void 0}),e._zod.parse=(r,n)=>{let o=t.innerType._zod.run(r,n);if(o instanceof Promise)return o.then((s)=>Oc(s,e));return Oc(o,e)}});function Oc(e,t){if(!e.issues.length&&e.value===void 0)e.issues.push({code:"invalid_type",expected:"nonoptional",input:e.value,inst:t});return e}function Ac(e,t,r,n){if(!t.issues.length){if(e.value=t.value,t.memo)e.memo=!0;return e}return e.value=r.catchValue({...t,value:e.value,error:{issues:t.issues.map((o)=>Ie(o,n,te()))},input:e.value}),e}var Eu=h("$ZodCatch",(e,t)=>{U.init(e,t),R(e,"optin",(r)=>r.def.innerType._zod.optin==="defaulted"?"defaulted":"optional"),R(e,"optout",(r)=>r.def.innerType._zod.optout),R(e,"values",(r)=>r.def.innerType._zod.values),e._zod.parse=(r,n)=>{if(n.direction==="backward")return t.innerType._zod.run(r,n);let o=t.innerType._zod.run({value:r.value,issues:[]},n);if(o instanceof Promise)return o.then((s)=>Ac(r,s,t,n));return Ac(r,o,t,n)}});var Cu=h("$ZodPipe",(e,t)=>{U.init(e,t),R(e,"values",(r)=>r.def.in._zod.values),R(e,"optin",(r)=>r.def.in._zod.optin),R(e,"optout",(r)=>r.def.out._zod.optout),R(e,"propValues",(r)=>r.def.in._zod.propValues),e._zod.parse=(r,n)=>{if(n.direction==="backward"){let s=t.out._zod.run(r,n);if(s instanceof Promise)return s.then((i)=>Wr(i,t.in,n));return Wr(s,t.in,n)}let o=t.in._zod.run(r,n);if(o instanceof Promise)return o.then((s)=>Wr(s,t.out,n));return Wr(o,t.out,n)}});function Wr(e,t,r){if(e.issues.some((n)=>n.code!=="unrecognized_keys"))return e.aborted=!0,e;return t._zod.run({value:e.value,issues:e.issues},r)}var Iu=h("$ZodReadonly",(e,t)=>{U.init(e,t),R(e,"propValues",(r)=>r.def.innerType._zod.propValues),R(e,"values",(r)=>r.def.innerType._zod.values),R(e,"optin",(r)=>r.def.innerType?._zod?.optin),R(e,"optout",(r)=>r.def.innerType?._zod?.optout),e._zod.parse=(r,n)=>{if(n.direction==="backward")return t.innerType._zod.run(r,n);let o=t.innerType._zod.run(r,n);if(o instanceof Promise)return o.then(jc);return jc(o)}});function jc(e){if(!e.memo)e.value=Object.freeze(e.value);return e}var Tu=h("$ZodCustom",(e,t)=>{J.init(e,t),U.init(e,t),e._zod.parse=(r,n)=>r,e._zod.check=(r)=>{let n=r.value,o=t.fn(n);if(o instanceof Promise)return o.then((s)=>Rc(s,r,n,e));Rc(o,r,n,e);return}});function Rc(e,t,r,n){if(!e){let o={code:"custom",input:r,inst:n,path:[...n._zod.def.path??[]],continue:!n._zod.def.abort};if(n._zod.def.params)o.params=n._zod.def.params;t.issues.push(at(o))}}class Au extends Error{constructor(){super("Cannot parse a reference cycle that closes through a transform");this.name="ZodCyclicError"}}var Mo="~memo",Ou=[];function ju(e){return e!==null&&typeof e==="object"}function Fo(e){return e.map((t)=>t.path?{...t,path:t.path.slice()}:{...t})}var Ru=new WeakMap,Xt=0,Qr=1,Qt=2;function en(e,t,r){let n=Ru.get(e);if(n!==void 0)return n?Qt:Xt;if(t.has(e))return Qt;t.add(e);let o=Xt,s=(l)=>{if(o!==Qt&&l?._zod){let p=en(l,t,r);if(p>o)o=p}},i=(l,p)=>{let d=Xt;for(let m of Reflect.ownKeys(l)){let f=Object.getOwnPropertyDescriptor(l,m);if(p&&!f.enumerable)continue;let g=f.get?Qr:f.value?._zod?en(f.value,t,r):Xt;if(g>d)d=g}return d},a=(l)=>{if(l>o)o=l},c=e._zod.def,u=c.type;switch(u){case"object":{let l=jr(c);a(l?i(l,!0):Qr),s(c.catchall);break}case"array":s(c.element);break;case"tuple":for(let l of c.items)s(l);s(c.rest);break;case"record":case"map":s(c.keyType),s(c.valueType);break;case"set":s(c.valueType);break;case"union":for(let l of c.options)s(l);break;case"intersection":s(c.left),s(c.right);break;case"optional":case"nullable":case"default":case"prefault":case"catch":case"readonly":case"nonoptional":case"promise":case"success":s(c.innerType);break;case"pipe":s(c.in),s(c.out);break;case"function":s(c.input),s(c.output);break;case"lazy":{let l=c._cachedInner??(r?e._zod.innerType:void 0);a(l?en(l,t,!1):Qr);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 l in c){let p=Object.getOwnPropertyDescriptor(c,l);if(!p||p.get)continue;let d=p.value;if(!d||typeof d!=="object")continue;if(d._zod)s(d);else if(Array.isArray(d))for(let m of d)s(m)}}return t.delete(e),Ah(e,o)}function Ah(e,t){if(t!==Qr)Ru.set(e,t===Qt);return t}function jh(e,t){let r=e.buckets.get(t);if(!r)r=new WeakMap,e.buckets.set(t,r);return r}var Yr,Xr=[],Rh={alloc(e,t,r){let n=Yr;if(!n)return r;Yr=void 0;let o={value:r,issues:null};return n.set(t.value,o),Xr.push(o),r},guard(e){var t;(t=e._zod).deferred??(t.deferred=[]),e._zod.deferred.push(()=>{let r=e._zod.parse,n=(o,s)=>{if(s.direction!=="backward"&&Lh(s,o.value))throw new Au;return r(o,s)};if(e._zod.parse=n,e._zod.run===r)e._zod.run=n})},attach(e){var t;let r,n=!1,o,s;(t=e._zod).deferred??(t.deferred=[]),e._zod.deferred.push(()=>{let i=e._zod.parse,a=(c,u)=>{if(r===void 0){let y=en(e,new Set,!1);if(y===Xt){if(e._zod.parse=i,e._zod.run===a)e._zod.run=i;return i(c,u)}if(y===Qt||n)r=!0;else n=!0}let l=c.value;if(!ju(l))return i(c,u);let p=u[Mo];if(!p)p={buckets:new WeakMap,backEdges:void 0},u[Mo]=p;let d;if(o===u)d=s;else d=jh(p,e),o=u,s=d;let m=d.get(l);if(m){if(c.value=m.value,m.issues){if(m.issues.length)c.issues.push(...Fo(m.issues))}else c.memo=!0,p.backEdges??(p.backEdges=new WeakSet),p.backEdges.add(m.value);return c}Yr=d;let f=Xr.length,g=i(c,u);Yr=void 0;let x=Xr.length>f?Xr.pop():void 0;if(g instanceof Promise)return g.then((y)=>{if(x)x.issues=y.issues.length?Fo(y.issues):Ou;return y});if(x)x.issues=g.issues.length?Fo(g.issues):Ou;return g};if(e._zod.parse=a,e._zod.run===i)e._zod.run=a})}};function Bo(){return Rh}function Lh(e,t){let r=e[Mo]?.backEdges;return r!==void 0&&ju(t)&&r.has(t)}var Zh=()=>{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(s){return e[s]??null}let r={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"},n={nan:"NaN"};function o(s,i){if(s==="number"&&typeof i==="number"&&!Number.isFinite(i))return String(i);return n[s]??s}return(s)=>{switch(s.code){case"invalid_type":{let i=o(s.expected),a=wa(s.input),c=o(a,s.input);return`Invalid input: expected ${i}, received ${c}`}case"invalid_value":if(s.values.length===1)return`Invalid input: expected ${_o(s.values[0])}`;return`Invalid option: expected one of ${go(s.values,"|")}`;case"too_big":{let i=s.exact?"exactly ":s.inclusive?"<=":"<",a=t(s.origin);if(a)return`Too big: expected ${s.origin??"value"} to have ${i}${s.maximum.toString()} ${a.unit??"elements"}`;return`Too big: expected ${s.origin??"value"} to be ${i}${s.maximum.toString()}`}case"too_small":{let i=s.exact?"exactly ":s.inclusive?">=":">",a=t(s.origin);if(a)return`Too small: expected ${s.origin} to have ${i}${s.minimum.toString()} ${a.unit}`;return`Too small: expected ${s.origin} to be ${i}${s.minimum.toString()}`}case"invalid_format":{let i=s;if(i.format==="starts_with")return`Invalid string: must start with "${i.prefix}"`;if(i.format==="ends_with")return`Invalid string: must end with "${i.suffix}"`;if(i.format==="includes")return`Invalid string: must include "${i.includes}"`;if(i.format==="regex")return`Invalid string: must match pattern ${i.pattern}`;return`Invalid ${r[i.format]??s.format}`}case"not_multiple_of":return`Invalid number: must be a multiple of ${s.divisor}`;case"unrecognized_keys":return`Unrecognized key${s.keys.length>1?"s":""}: ${go(s.keys,", ")}`;case"invalid_key":return`Invalid key in ${s.origin}`;case"invalid_union":if(s.options&&Array.isArray(s.options)&&s.options.length>0)return`Invalid discriminator value. Expected ${s.options.map((a)=>`'${a}'`).join(" | ")}`;if(s.inclusive===!1)return"Invalid input: more than one option matched";return"Invalid input";case"invalid_element":return`Invalid value in ${s.origin}`;default:return"Invalid input"}}};function Go(){return{localeError:Zh()}}var Lu;class Zu{constructor(){this._map=new WeakMap,this._idmap=new Map}add(e,...t){let r=t[0];if(this._map.set(e,r),r&&typeof r==="object"&&"id"in r)this._idmap.set(r.id,e);return this}clear(){return this._map=new WeakMap,this._idmap=new Map,this}remove(e){let t=this._map.get(e);if(t&&typeof t==="object"&&"id"in t)this._idmap.delete(t.id);return this._map.delete(e),this}get(e){let t=e._zod.parent;if(t){let r={...this.get(t)??{}};delete r.id;let n={...r,...this._map.get(e)};return Object.keys(n).length?n:void 0}return this._map.get(e)}has(e){return this._map.has(e)}}function Du(){return new Zu}(Lu=globalThis).__zod_globalRegistry??(Lu.__zod_globalRegistry=Du());var He=globalThis.__zod_globalRegistry;function Nu(e){if(e.checks)e.checks=[...e.checks];return e}function Uu(e,t){return new e(Nu({type:"string",...v(t)}))}function Fu(e,t){return new e({type:"string",format:"email",check:"string_format",abort:!1,...v(t)})}function Mu(e,t){return new e({type:"string",format:"guid",check:"string_format",abort:!1,...v(t)})}function Bu(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,...v(t)})}function Gu(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v4",...v(t)})}function Vu(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v6",...v(t)})}function Wu(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v7",...v(t)})}function Vo(e,t){return new e({type:"string",format:"url",check:"string_format",abort:!1,...v(t)})}function Ku(e,t){return new e({type:"string",format:"emoji",check:"string_format",abort:!1,...v(t)})}function Ju(e,t){return new e({type:"string",format:"nanoid",check:"string_format",abort:!1,...v(t)})}function Hu(e,t){return new e({type:"string",format:"cuid",check:"string_format",abort:!1,...v(t)})}function qu(e,t){return new e({type:"string",format:"cuid2",check:"string_format",abort:!1,...v(t)})}function Yu(e,t){return new e({type:"string",format:"ulid",check:"string_format",abort:!1,...v(t)})}function Xu(e,t){return new e({type:"string",format:"xid",check:"string_format",abort:!1,...v(t)})}function Qu(e,t){return new e({type:"string",format:"ksuid",check:"string_format",abort:!1,...v(t)})}function el(e,t){return new e({type:"string",format:"ipv4",check:"string_format",abort:!1,...v(t)})}function tl(e,t){return new e({type:"string",format:"ipv6",check:"string_format",abort:!1,...v(t)})}function rl(e,t){return new e({type:"string",format:"cidrv4",check:"string_format",abort:!1,...v(t)})}function nl(e,t){return new e({type:"string",format:"cidrv6",check:"string_format",abort:!1,...v(t)})}function ol(e,t){return new e({type:"string",format:"base64",check:"string_format",abort:!1,...v(t)})}function sl(e,t){return new e({type:"string",format:"base64url",check:"string_format",abort:!1,...v(t)})}function il(e,t){return new e({type:"string",format:"e164",check:"string_format",abort:!1,...v(t)})}function al(e,t){return new e({type:"string",format:"jwt",check:"string_format",abort:!1,...v(t)})}function tn(e,t){return new e({type:"string",format:"datetime",check:"string_format",offset:!1,local:!1,precision:null,...v(t)})}function rn(e,t){return new e({type:"string",format:"date",check:"string_format",...v(t)})}function nn(e,t){return new e({type:"string",format:"time",check:"string_format",precision:null,...v(t)})}function on(e,t){return new e({type:"string",format:"duration",check:"string_format",...v(t)})}function cl(e,t){return new e(Nu({type:"number",checks:[],...v(t)}))}function ul(e,t){return new e({type:"number",check:"number_format",abort:!1,format:"safeint",...v(t)})}function ll(e,t){return new e({type:"boolean",...v(t)})}function pl(e){return new e({type:"unknown"})}function dl(e,t){return new e({type:"never",...v(t)})}function sn(e,t){return new Ao({check:"less_than",...v(t),value:e,inclusive:!1})}function er(e,t){return new Ao({check:"less_than",...v(t),value:e,inclusive:!0})}function an(e,t){return new jo({check:"greater_than",...v(t),value:e,inclusive:!1})}function tr(e,t){return new jo({check:"greater_than",...v(t),value:e,inclusive:!0})}function cn(e,t){return new dc({check:"multiple_of",...v(t),value:e})}function un(e,t){return new fc({check:"max_length",...v(t),maximum:e})}function vt(e,t){return new hc({check:"min_length",...v(t),minimum:e})}function ln(e,t){return new gc({check:"length_equals",...v(t),length:e})}function Wo(e,t){return new xc({check:"string_format",format:"regex",...v(t),pattern:e})}function Ko(e){return new yc({check:"string_format",format:"lowercase",...v(e)})}function Jo(e){return new _c({check:"string_format",format:"uppercase",...v(e)})}function Ho(e,t){return new bc({check:"string_format",format:"includes",...v(t),includes:e})}function qo(e,t){return new wc({check:"string_format",format:"starts_with",...v(t),prefix:e})}function Yo(e,t){return new vc({check:"string_format",format:"ends_with",...v(t),suffix:e})}function qe(e){return new $c({check:"overwrite",tx:e})}function Xo(e){return qe((t)=>t.normalize(e))}function Qo(){return qe((e)=>e.trim())}function es(){return qe((e)=>e.toLowerCase())}function ts(){return qe((e)=>e.toUpperCase())}function rs(){return qe((e)=>fa(e))}function ml(e,t,r){return new e({type:"array",element:t,...v(r)})}function fl(e,t,r){return new e({type:"custom",check:"custom",fn:t,...v(r)})}function hl(e,t){let r=Dh((n)=>(n.addIssue=(o)=>{if(typeof o==="string")n.issues.push(at(o,n.value,r._zod.def));else{let s=o;if(s.fatal)s.continue=!1;if(s.code??(s.code="custom"),!("input"in s))s.input=n.value;s.inst??(s.inst=r),s.continue??(s.continue=!r._zod.def.abort),n.issues.push(at(s))}},e(n.value,n)),t);return r}function Dh(e,t){let r=new J({check:"custom",...v(t)});return r._zod.check=e,r}function rr(e,...t){for(let r of t)for(let n of Reflect.ownKeys(r))if(Object.prototype.propertyIsEnumerable.call(r,n))ve(e,n,r[n]);return e}function os(e){let t=e?.target??"draft-2020-12";if(t==="draft-4")t="draft-04";if(t==="draft-7")t="draft-07";return{processors:e.processors??{},metadataRegistry:e?.metadata??He,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 ct(e,t,r,n,o){let s=typeof t.unrepresentable==="function"?t.unrepresentable({zodSchema:e,path:n.path,message:o}):t.unrepresentable;if(s==="any")return!1;if(s===void 0||s==="throw")throw Error(o);return Object.assign(r,s),!0}function V(e,t,r={path:[],schemaPath:[]}){var n;let o=e._zod.def,s=t.seen.get(e);if(s){if(s.count++,r.schemaPath.includes(e))s.cycle=r.path;return s.schema}let i={schema:{},count:1,cycle:void 0,path:r.path};t.seen.set(e,i),t.sharedDefsExtractedFor=void 0,t.sharedEmitDoneFor=void 0;let a=e._zod.toJSONSchema?.();if(a)i.schema=a;else{let l={...r,schemaPath:[...r.schemaPath,e],path:r.path};if(e._zod.processJSONSchema)e._zod.processJSONSchema(t,i.schema,l);else{let d=i.schema,m=t.processors[o.type];if(!m)throw Error(`[toJSONSchema]: Non-representable type encountered: ${o.type}`);m(e,t,d,l)}let p=e._zod.parent;if(p){if(!i.ref)i.ref=p;V(p,t,l),t.seen.get(p).isParent=!0}}let c=t.metadataRegistry.get(e);if(c)rr(i.schema,c);if(t.io==="input"&&Y(e))delete i.schema.examples,delete i.schema.default;if(t.io==="input"&&"_prefault"in i.schema)(n=i.schema).default??(n.default=i.schema._prefault);return delete i.schema._prefault,t.seen.get(e).schema}function gl(e){return e.replace(/~/g,"~0").replace(/\//g,"~1")}function ss(e,t){let r=e.seen.get(t);if(!r)throw Error("Unprocessed schema. This is a bug in Zod.");if(e.external&&e.sharedDefsExtractedFor===e.external)return;let n=new Map;for(let i of e.seen.entries()){let a=e.metadataRegistry.get(i[0])?.id;if(a){let c=n.get(a);if(c&&c!==i[0])throw Error(`Duplicate schema id "${a}" detected during JSON Schema conversion. Two different schemas cannot share the same id when converted together.`);n.set(a,i[0])}}let o=(i)=>{let a=e.target==="draft-2020-12"?"$defs":"definitions";if(e.external){let p=e.external.registry.get(i[0])?.id,d=e.external.uri??((f)=>f);if(p)return{ref:d(p)};let m=i[1].defId??i[1].schema.id??`schema${e.counter++}`;return i[1].defId=m,{defId:m,ref:`${d("__shared")}#/${a}/${gl(m)}`}}let c="#",u=`${c}/${a}/`;if(i[1]===r&&!i[1].schema.id)return{ref:c};let l=i[1].schema.id??`__schema${e.counter++}`;return{defId:l,ref:u+gl(l)}},s=(i)=>{if(i[1].schema.$ref)return;let a=i[1],{ref:c,defId:u}=o(i);if(a.def={...a.schema},u)a.defId=u;let l=a.schema;for(let p in l)delete l[p];l.$ref=c};if(e.cycles==="throw")for(let i of e.seen.entries()){let a=i[1];if(a.cycle)throw Error(`Cycle detected: #/${a.cycle?.join("/")}/<root>
|
|
87
|
+
`)}return b.write("payload.value = newResult;"),b.write("return payload;"),b.compile()},i,a=Er,c=!we.jitless,u=c&&Cl.value,p=t.catchall,d;e._zod.parse=(f,h)=>{d??(d=n.value);let y=f.value;if(!a(y))return f.issues.push({expected:"object",code:"invalid_type",input:y,inst:e}),f;if(c&&u&&h?.async===!1&&h.jitless!==!0){if(!i)i=s(t.shape);if(f=i(f,h),!p)return f;return Ep([],y,f,h,d,e,h?.abortEarly===!0)}return r(f,h)}});function Uu(e,t,r,n){for(let s of e)if(s.issues.length===0)return t.value=s.value,t;let o=e.filter((s)=>!Be(s));if(o.length===1)return t.value=o[0].value,o[0];return t.issues.push({code:"invalid_union",input:t.value,inst:r,errors:e.map((s)=>s.issues.map((i)=>Ge(i,n,_e())))}),t}var Ip=g("$ZodUnion",(e,t)=>{q.init(e,t),B(e,"optin",(n)=>n.def.options.some((o)=>o._zod.optin==="defaulted")?"defaulted":n.def.options.some((o)=>o._zod.optin!==void 0)?"optional":void 0),B(e,"optout",(n)=>n.def.options.some((o)=>o._zod.optout==="optional")?"optional":void 0),B(e,"values",(n)=>{if(n.def.options.every((o)=>o._zod.values))return new Set(n.def.options.flatMap((o)=>Array.from(o._zod.values)));return}),B(e,"pattern",(n)=>{if(n.def.options.every((o)=>o._zod.pattern)){let o=n.def.options.map((s)=>s._zod.pattern);return new RegExp(`^(${o.map((s)=>In(s.source)).join("|")})$`)}return});let r=t.options.length===1?t.options[0]._zod.run:null;e._zod.parse=(n,o)=>{if(r)return r(n,o);let s=!1,i=[];for(let a of t.options){let c=a._zod.run({value:n.value,issues:[]},o);if(c instanceof Promise)i.push(c),s=!0;else{if(c.issues.length===0)return c;i.push(c)}}if(!s)return Uu(i,n,e,o);return Promise.all(i).then((a)=>Uu(a,n,e,o))}});var Ap=g("$ZodIntersection",(e,t)=>{q.init(e,t),e._zod.parse=(r,n)=>{let o=r.value,s=t.left._zod.run({value:o,issues:[]},n),i=t.right._zod.run({value:o,issues:[]},n);if(s instanceof Promise||i instanceof Promise)return Promise.all([s,i]).then(([c,l])=>Fu(r,c,l));return Fu(r,s,i)}});function ei(e,t){if(e===t)return{valid:!0,data:e};if(e instanceof Date&&t instanceof Date&&+e===+t)return{valid:!0,data:e};if(At(e)&&At(t)){let r=Object.keys(t),n=Object.keys(e).filter((s)=>r.indexOf(s)!==-1),o={...e,...t};if(Object.prototype.hasOwnProperty.call(o,"__proto__"))delete o.__proto__;for(let s of n){if(s==="__proto__")continue;let i=ei(e[s],t[s]);if(!i.valid)return{valid:!1,mergeErrorPath:[s,...i.mergeErrorPath]};o[s]=i.data}return{valid:!0,data:o}}if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return{valid:!1,mergeErrorPath:[]};let r=[];for(let n=0;n<e.length;n++){let o=e[n],s=t[n],i=ei(o,s);if(!i.valid)return{valid:!1,mergeErrorPath:[n,...i.mergeErrorPath]};r.push(i.data)}return{valid:!0,data:r}}return{valid:!1,mergeErrorPath:[]}}function Fu(e,t,r){let n=new Map,o,s=new Map,i=(l,u)=>{let p;if(l.code==="unrecognized_keys"&&!l.path?.length)o??(o=l),p=l.keys;else if(l.code==="invalid_key"&&l.origin==="record"&&l.path?.length===1){let d=String(l.path[0]);if(!s.has(d))s.set(d,l);p=[d]}else return!1;for(let d of p){if(!n.has(d))n.set(d,{});n.get(d)[u]=!0}return!0};for(let l of t.issues)if(!i(l,"l"))e.issues.push(l);for(let l of r.issues)if(!i(l,"r"))e.issues.push(l);let a=[...n].filter(([,l])=>l.l&&l.r).map(([l])=>l);if(a.length){let l=o?a.filter((u)=>o.keys.includes(u)):[];if(l.length)e.issues.push({...o,keys:l});for(let u of a)if(!l.includes(u)&&s.has(u))e.issues.push(s.get(u))}let c=ei(t.value,r.value);if(!c.valid){if(Be(e))return e;throw Error(`Unmergable intersection. Error path: ${JSON.stringify(c.mergeErrorPath)}`)}return e.value=c.data,e}var Tp=g("$ZodRecord",(e,t)=>{q.init(e,t);let r=we.memoizer;r?.attach(e),e._zod.parse=(n,o)=>{let s=n.value;if(!At(s))return n.issues.push({expected:"record",code:"invalid_type",input:s,inst:e}),n;let i=[],a=t.keyType._zod.values;if(a&&!t.partial){n.value=r?r.alloc(e,n,{},o):{};let c=new Set;for(let u of a)if(typeof u==="string"||typeof u==="number"||typeof u==="symbol"){if(c.add(typeof u==="number"?u.toString():u),u==="__proto__")continue;let p=t.keyType._zod.run({value:u,issues:[]},o);if(p instanceof Promise)throw Error("Async schemas not supported in object keys currently");if(p.issues.length){n.issues.push({code:"invalid_key",origin:"record",issues:p.issues.map((h)=>Ge(h,o,_e())),input:u,path:[u],inst:e});continue}let d=p.value;if(d==="__proto__")continue;let f=t.valueType._zod.run({value:s[u],issues:[]},o);if(f instanceof Promise)i.push(f.then((h)=>{if(h.issues.length)n.issues.push(...gt(u,h.issues));n.value[d]=h.value}));else{if(f.issues.length)n.issues.push(...gt(u,f.issues));n.value[d]=f.value}}let l;for(let u in s)if(!c.has(u))if(t.mode==="loose"){if(u==="__proto__")continue;n.value[u]=s[u]}else l=l??[],l.push(u);if(l&&l.length>0)n.issues.push({code:"unrecognized_keys",input:s,inst:e,keys:l,continue:!0})}else{n.value=r?r.alloc(e,n,{},o):{};let c;for(let l of Reflect.ownKeys(s)){if(l==="__proto__")continue;if(!Object.prototype.propertyIsEnumerable.call(s,l))continue;let u=t.keyType._zod.run({value:l,issues:[]},o);if(u instanceof Promise)throw Error("Async schemas not supported in object keys currently");if(typeof l==="string"&&Tr.test(l)&&u.issues.length){let h=t.keyType._zod.run({value:Number(l),issues:[]},o);if(h instanceof Promise)throw Error("Async schemas not supported in object keys currently");if(h.issues.length===0)u=h}if(u.issues.length){if(t.mode==="loose")n.value[l]=s[l];else if(a)c=c??[],c.push(l);else n.issues.push({code:"invalid_key",origin:"record",issues:u.issues.map((h)=>Ge(h,o,_e())),input:l,path:[l],inst:e});continue}let d=u.value;if(d==="__proto__")continue;let f=t.valueType._zod.run({value:s[l],issues:[]},o);if(f instanceof Promise)i.push(f.then((h)=>{if(h.issues.length)n.issues.push(...gt(l,h.issues));n.value[d]=h.value}));else{if(f.issues.length)n.issues.push(...gt(l,f.issues));n.value[d]=f.value}}if(c&&c.length>0)n.issues.push({code:"unrecognized_keys",input:s,inst:e,keys:c,continue:!0})}if(i.length)return Promise.all(i).then(()=>n);return n}});var Rp=g("$ZodEnum",(e,t)=>{q.init(e,t);let r=zr(t.entries),n=new Set(r);e._zod.values=n,B(e,"pattern",(o)=>{let s=zr(o.def.entries).filter((i)=>El.has(typeof i));return new RegExp(s.length?`^(${s.map((i)=>Jt(i.toString())).join("|")})$`:"^[^\\s\\S]$")}),e._zod.parse=(o,s)=>{let i=o.value;if(n.has(i))return o;return o.issues.push({code:"invalid_value",values:r,input:i,inst:e}),o}});var jp=g("$ZodTransform",(e,t)=>{q.init(e,t),e._zod.optin="optional",we.memoizer?.guard(e),e._zod.parse=(r,n)=>{if(n.direction==="backward")throw new Ar(e.constructor.name);let o=t.transform(r.value,r);if(n.async)return(o instanceof Promise?o:Promise.resolve(o)).then((i)=>(r.value=i,r));if(o instanceof Promise)throw new Ke;return r.value=o,r}});function Mu(e,t){return e.value=t.issues.length?void 0:t.value,e}var oi=g("$ZodOptional",(e,t)=>{q.init(e,t),B(e,"optin",(r)=>r.def.innerType._zod.optin==="defaulted"?"defaulted":"optional"),e._zod.optout="optional",B(e,"values",(r)=>{let n=r.def.innerType._zod.values;return n?new Set([...n,void 0]):void 0}),B(e,"pattern",(r)=>{let n=r.def.innerType._zod.pattern;return n?new RegExp(`^(${In(n.source)})?$`):void 0}),e._zod.parse=(r,n)=>{if(r.value===void 0){if(t.innerType._zod.optin!=="defaulted")return r;let o=t.innerType._zod.run({value:r.value,issues:[]},n);if(o instanceof Promise)return o.then((s)=>Mu(r,s));return Mu(r,o)}return t.innerType._zod.run(r,n)}}),Op=g("$ZodExactOptional",(e,t)=>{oi.init(e,t),B(e,"values",(r)=>r.def.innerType._zod.values),B(e,"pattern",(r)=>r.def.innerType._zod.pattern),e._zod.parse=(r,n)=>t.innerType._zod.run(r,n)}),Lp=g("$ZodNullable",(e,t)=>{q.init(e,t),B(e,"optin",(r)=>r.def.innerType._zod.optin),B(e,"optout",(r)=>r.def.innerType._zod.optout),B(e,"pattern",(r)=>{let n=r.def.innerType._zod.pattern;return n?new RegExp(`^(${In(n.source)}|null)$`):void 0}),B(e,"values",(r)=>r.def.innerType._zod.values?new Set([...r.def.innerType._zod.values,null]):void 0),e._zod.parse=(r,n)=>{if(r.value===null)return r;return t.innerType._zod.run(r,n)}}),Dp=g("$ZodDefault",(e,t)=>{q.init(e,t),e._zod.optin="defaulted",B(e,"values",(r)=>r.def.innerType._zod.values),e._zod.parse=(r,n)=>{if(n.direction==="backward")return t.innerType._zod.run(r,n);if(r.value===void 0)return r.value=t.defaultValue,r;let o=t.innerType._zod.run(r,n);if(o instanceof Promise)return o.then((s)=>Bu(s,t));return Bu(o,t)}});function Bu(e,t){if(e.value===void 0)e.value=t.defaultValue;return e}var Np=g("$ZodPrefault",(e,t)=>{q.init(e,t),e._zod.optin="defaulted",B(e,"values",(r)=>r.def.innerType._zod.values),e._zod.parse=(r,n)=>{if(n.direction==="backward")return t.innerType._zod.run(r,n);if(r.value===void 0)r.value=t.defaultValue;return t.innerType._zod.run(r,n)}}),Zp=g("$ZodNonOptional",(e,t)=>{q.init(e,t),B(e,"values",(r)=>{let n=r.def.innerType._zod.values;return n?new Set([...n].filter((o)=>o!==void 0)):void 0}),e._zod.parse=(r,n)=>{let o=t.innerType._zod.run(r,n);if(o instanceof Promise)return o.then((s)=>Gu(s,e));return Gu(o,e)}});function Gu(e,t){if(!e.issues.length&&e.value===void 0)e.issues.push({code:"invalid_type",expected:"nonoptional",input:e.value,inst:t});return e}function Ku(e,t,r,n){if(!t.issues.length){if(e.value=t.value,t.memo)e.memo=!0;return e}return e.value=r.catchValue({...t,value:e.value,error:{issues:t.issues.map((o)=>Ge(o,n,_e()))},input:e.value}),e}var Up=g("$ZodCatch",(e,t)=>{q.init(e,t),B(e,"optin",(r)=>r.def.innerType._zod.optin==="defaulted"?"defaulted":"optional"),B(e,"optout",(r)=>r.def.innerType._zod.optout),B(e,"values",(r)=>r.def.innerType._zod.values),e._zod.parse=(r,n)=>{if(n.direction==="backward")return t.innerType._zod.run(r,n);let o=t.innerType._zod.run({value:r.value,issues:[]},n);if(o instanceof Promise)return o.then((s)=>Ku(r,s,t,n));return Ku(r,o,t,n)}});var Fp=g("$ZodPipe",(e,t)=>{q.init(e,t),B(e,"values",(r)=>r.def.in._zod.values),B(e,"optin",(r)=>r.def.in._zod.optin),B(e,"optout",(r)=>r.def.out._zod.optout),B(e,"propValues",(r)=>r.def.in._zod.propValues),e._zod.parse=(r,n)=>{if(n.direction==="backward"){let s=t.out._zod.run(r,n);if(s instanceof Promise)return s.then((i)=>Bn(i,t.in,n));return Bn(s,t.in,n)}let o=t.in._zod.run(r,n);if(o instanceof Promise)return o.then((s)=>Bn(s,t.out,n));return Bn(o,t.out,n)}});function Bn(e,t,r){if(e.issues.some((n)=>n.code!=="unrecognized_keys"))return e.aborted=!0,e;return t._zod.run({value:e.value,issues:e.issues},r)}var Mp=g("$ZodReadonly",(e,t)=>{q.init(e,t),B(e,"propValues",(r)=>r.def.innerType._zod.propValues),B(e,"values",(r)=>r.def.innerType._zod.values),B(e,"optin",(r)=>r.def.innerType?._zod?.optin),B(e,"optout",(r)=>r.def.innerType?._zod?.optout),e._zod.parse=(r,n)=>{if(n.direction==="backward")return t.innerType._zod.run(r,n);let o=t.innerType._zod.run(r,n);if(o instanceof Promise)return o.then(Vu);return Vu(o)}});function Vu(e){if(!e.memo)e.value=Object.freeze(e.value);return e}var Bp=g("$ZodCustom",(e,t)=>{ue.init(e,t),q.init(e,t),e._zod.parse=(r,n)=>r,e._zod.check=(r)=>{let n=r.value,o=t.fn(n);if(o instanceof Promise)return o.then((s)=>Wu(s,r,n,e));Wu(o,r,n,e);return}});function Wu(e,t,r,n){if(!e){let o={code:"custom",input:r,inst:n,path:[...n._zod.def.path??[]],continue:!n._zod.def.abort};if(n._zod.def.params)o.params=n._zod.def.params;t.issues.push(Tt(o))}}class Kp extends Error{constructor(){super("Cannot parse a reference cycle that closes through a transform");this.name="ZodCyclicError"}}var ii="~memo",Gp=[];function Vp(e){return e!==null&&typeof e==="object"}function si(e){return e.map((t)=>t.path?{...t,path:t.path.slice()}:{...t})}var Wp=new WeakMap,jr=0,qn=1,Or=2;function Yn(e,t,r){let n=Wp.get(e);if(n!==void 0)return n?Or:jr;if(t.has(e))return Or;t.add(e);let o=jr,s=(u)=>{if(o!==Or&&u?._zod){let p=Yn(u,t,r);if(p>o)o=p}},i=(u,p)=>{let d=jr;for(let f of Reflect.ownKeys(u)){let h=Object.getOwnPropertyDescriptor(u,f);if(p&&!h.enumerable)continue;let y=h.get?qn:h.value?._zod?Yn(h.value,t,r):jr;if(y>d)d=y}return d},a=(u)=>{if(u>o)o=u},c=e._zod.def,l=c.type;switch(l){case"object":{let u=An(c);a(u?i(u,!0):qn),s(c.catchall);break}case"array":s(c.element);break;case"tuple":for(let u of c.items)s(u);s(c.rest);break;case"record":case"map":s(c.keyType),s(c.valueType);break;case"set":s(c.valueType);break;case"union":for(let u of c.options)s(u);break;case"intersection":s(c.left),s(c.right);break;case"optional":case"nullable":case"default":case"prefault":case"catch":case"readonly":case"nonoptional":case"promise":case"success":s(c.innerType);break;case"pipe":s(c.in),s(c.out);break;case"function":s(c.input),s(c.output);break;case"lazy":{let u=c._cachedInner??(r?e._zod.innerType:void 0);a(u?Yn(u,t,!1):qn);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 u in c){let p=Object.getOwnPropertyDescriptor(c,u);if(!p||p.get)continue;let d=p.value;if(!d||typeof d!=="object")continue;if(d._zod)s(d);else if(Array.isArray(d))for(let f of d)s(f)}}return t.delete(e),yx(e,o)}function yx(e,t){if(t!==qn)Wp.set(e,t===Or);return t}function bx(e,t){let r=e.buckets.get(t);if(!r)r=new WeakMap,e.buckets.set(t,r);return r}var Hn,Jn=[],xx={alloc(e,t,r){let n=Hn;if(!n)return r;Hn=void 0;let o={value:r,issues:null};return n.set(t.value,o),Jn.push(o),r},guard(e){var t;(t=e._zod).deferred??(t.deferred=[]),e._zod.deferred.push(()=>{let r=e._zod.parse,n=(o,s)=>{if(s.direction!=="backward"&&wx(s,o.value))throw new Kp;return r(o,s)};if(e._zod.parse=n,e._zod.run===r)e._zod.run=n})},attach(e){var t;let r,n=!1,o,s;(t=e._zod).deferred??(t.deferred=[]),e._zod.deferred.push(()=>{let i=e._zod.parse,a=(c,l)=>{if(r===void 0){let _=Yn(e,new Set,!1);if(_===jr){if(e._zod.parse=i,e._zod.run===a)e._zod.run=i;return i(c,l)}if(_===Or||n)r=!0;else n=!0}let u=c.value;if(!Vp(u))return i(c,l);let p=l[ii];if(!p)p={buckets:new WeakMap,backEdges:void 0},l[ii]=p;let d;if(o===l)d=s;else d=bx(p,e),o=l,s=d;let f=d.get(u);if(f){if(c.value=f.value,f.issues){if(f.issues.length)c.issues.push(...si(f.issues))}else c.memo=!0,p.backEdges??(p.backEdges=new WeakSet),p.backEdges.add(f.value);return c}Hn=d;let h=Jn.length,y=i(c,l);Hn=void 0;let b=Jn.length>h?Jn.pop():void 0;if(y instanceof Promise)return y.then((_)=>{if(b)b.issues=_.issues.length?si(_.issues):Gp;return _});if(b)b.issues=y.issues.length?si(y.issues):Gp;return y};if(e._zod.parse=a,e._zod.run===i)e._zod.run=a})}};function ai(){return xx}function wx(e,t){let r=e[ii]?.backEdges;return r!==void 0&&Vp(t)&&r.has(t)}var _x=()=>{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(s){return e[s]??null}let r={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"},n={nan:"NaN"};function o(s,i){if(s==="number"&&typeof i==="number"&&!Number.isFinite(i))return String(i);return n[s]??s}return(s)=>{switch(s.code){case"invalid_type":{let i=o(s.expected),a=Rl(s.input),c=o(a,s.input);return`Invalid input: expected ${i}, received ${c}`}case"invalid_value":if(s.values.length===1)return`Invalid input: expected ${Ds(s.values[0])}`;return`Invalid option: expected one of ${js(s.values,"|")}`;case"too_big":{let i=s.exact?"exactly ":s.inclusive?"<=":"<",a=t(s.origin);if(a)return`Too big: expected ${s.origin??"value"} to have ${i}${s.maximum.toString()} ${a.unit??"elements"}`;return`Too big: expected ${s.origin??"value"} to be ${i}${s.maximum.toString()}`}case"too_small":{let i=s.exact?"exactly ":s.inclusive?">=":">",a=t(s.origin);if(a)return`Too small: expected ${s.origin} to have ${i}${s.minimum.toString()} ${a.unit}`;return`Too small: expected ${s.origin} to be ${i}${s.minimum.toString()}`}case"invalid_format":{let i=s;if(i.format==="starts_with")return`Invalid string: must start with "${i.prefix}"`;if(i.format==="ends_with")return`Invalid string: must end with "${i.suffix}"`;if(i.format==="includes")return`Invalid string: must include "${i.includes}"`;if(i.format==="regex")return`Invalid string: must match pattern ${i.pattern}`;return`Invalid ${r[i.format]??s.format}`}case"not_multiple_of":return`Invalid number: must be a multiple of ${s.divisor}`;case"unrecognized_keys":return`Unrecognized key${s.keys.length>1?"s":""}: ${js(s.keys,", ")}`;case"invalid_key":return`Invalid key in ${s.origin}`;case"invalid_union":if(s.options&&Array.isArray(s.options)&&s.options.length>0)return`Invalid discriminator value. Expected ${s.options.map((a)=>`'${a}'`).join(" | ")}`;if(s.inclusive===!1)return"Invalid input: more than one option matched";return"Invalid input";case"invalid_element":return`Invalid value in ${s.origin}`;default:return"Invalid input"}}};function ci(){return{localeError:_x()}}var Hp;class Jp{constructor(){this._map=new WeakMap,this._idmap=new Map}add(e,...t){let r=t[0];if(this._map.set(e,r),r&&typeof r==="object"&&"id"in r)this._idmap.set(r.id,e);return this}clear(){return this._map=new WeakMap,this._idmap=new Map,this}remove(e){let t=this._map.get(e);if(t&&typeof t==="object"&&"id"in t)this._idmap.delete(t.id);return this._map.delete(e),this}get(e){let t=e._zod.parent;if(t){let r={...this.get(t)??{}};delete r.id;let n={...r,...this._map.get(e)};return Object.keys(n).length?n:void 0}return this._map.get(e)}has(e){return this._map.has(e)}}function qp(){return new Jp}(Hp=globalThis).__zod_globalRegistry??(Hp.__zod_globalRegistry=qp());var yt=globalThis.__zod_globalRegistry;function Yp(e){if(e.checks)e.checks=[...e.checks];return e}function Xp(e,t){return new e(Yp({type:"string",...C(t)}))}function Qp(e,t){return new e({type:"string",format:"email",check:"string_format",abort:!1,...C(t)})}function ed(e,t){return new e({type:"string",format:"guid",check:"string_format",abort:!1,...C(t)})}function td(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,...C(t)})}function rd(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v4",...C(t)})}function nd(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v6",...C(t)})}function od(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v7",...C(t)})}function li(e,t){return new e({type:"string",format:"url",check:"string_format",abort:!1,...C(t)})}function sd(e,t){return new e({type:"string",format:"emoji",check:"string_format",abort:!1,...C(t)})}function id(e,t){return new e({type:"string",format:"nanoid",check:"string_format",abort:!1,...C(t)})}function ad(e,t){return new e({type:"string",format:"cuid",check:"string_format",abort:!1,...C(t)})}function cd(e,t){return new e({type:"string",format:"cuid2",check:"string_format",abort:!1,...C(t)})}function ld(e,t){return new e({type:"string",format:"ulid",check:"string_format",abort:!1,...C(t)})}function ud(e,t){return new e({type:"string",format:"xid",check:"string_format",abort:!1,...C(t)})}function pd(e,t){return new e({type:"string",format:"ksuid",check:"string_format",abort:!1,...C(t)})}function dd(e,t){return new e({type:"string",format:"ipv4",check:"string_format",abort:!1,...C(t)})}function md(e,t){return new e({type:"string",format:"ipv6",check:"string_format",abort:!1,...C(t)})}function fd(e,t){return new e({type:"string",format:"cidrv4",check:"string_format",abort:!1,...C(t)})}function hd(e,t){return new e({type:"string",format:"cidrv6",check:"string_format",abort:!1,...C(t)})}function gd(e,t){return new e({type:"string",format:"base64",check:"string_format",abort:!1,...C(t)})}function yd(e,t){return new e({type:"string",format:"base64url",check:"string_format",abort:!1,...C(t)})}function bd(e,t){return new e({type:"string",format:"e164",check:"string_format",abort:!1,...C(t)})}function xd(e,t){return new e({type:"string",format:"jwt",check:"string_format",abort:!1,...C(t)})}function Xn(e,t){return new e({type:"string",format:"datetime",check:"string_format",offset:!1,local:!1,precision:null,...C(t)})}function Qn(e,t){return new e({type:"string",format:"date",check:"string_format",...C(t)})}function eo(e,t){return new e({type:"string",format:"time",check:"string_format",precision:null,...C(t)})}function to(e,t){return new e({type:"string",format:"duration",check:"string_format",...C(t)})}function wd(e,t){return new e(Yp({type:"number",checks:[],...C(t)}))}function _d(e,t){return new e({type:"number",check:"number_format",abort:!1,format:"safeint",...C(t)})}function vd(e,t){return new e({type:"boolean",...C(t)})}function $d(e){return new e({type:"unknown"})}function Sd(e,t){return new e({type:"never",...C(t)})}function ro(e,t){return new Ys({check:"less_than",...C(t),value:e,inclusive:!1})}function Lr(e,t){return new Ys({check:"less_than",...C(t),value:e,inclusive:!0})}function no(e,t){return new Xs({check:"greater_than",...C(t),value:e,inclusive:!1})}function Dr(e,t){return new Xs({check:"greater_than",...C(t),value:e,inclusive:!0})}function oo(e,t){return new Su({check:"multiple_of",...C(t),value:e})}function so(e,t){return new Pu({check:"max_length",...C(t),maximum:e})}function Xt(e,t){return new Cu({check:"min_length",...C(t),minimum:e})}function io(e,t){return new Eu({check:"length_equals",...C(t),length:e})}function ui(e,t){return new zu({check:"string_format",format:"regex",...C(t),pattern:e})}function pi(e){return new Iu({check:"string_format",format:"lowercase",...C(e)})}function di(e){return new Au({check:"string_format",format:"uppercase",...C(e)})}function mi(e,t){return new Tu({check:"string_format",format:"includes",...C(t),includes:e})}function fi(e,t){return new Ru({check:"string_format",format:"starts_with",...C(t),prefix:e})}function hi(e,t){return new ju({check:"string_format",format:"ends_with",...C(t),suffix:e})}function bt(e){return new Ou({check:"overwrite",tx:e})}function gi(e){return bt((t)=>t.normalize(e))}function yi(){return bt((e)=>e.trim())}function bi(){return bt((e)=>e.toLowerCase())}function xi(){return bt((e)=>e.toUpperCase())}function wi(){return bt((e)=>Pl(e))}function kd(e,t,r){return new e({type:"array",element:t,...C(r)})}function Pd(e,t,r){return new e({type:"custom",check:"custom",fn:t,...C(r)})}function Cd(e,t){let r=vx((n)=>(n.addIssue=(o)=>{if(typeof o==="string")n.issues.push(Tt(o,n.value,r._zod.def));else{let s=o;if(s.fatal)s.continue=!1;if(s.code??(s.code="custom"),!("input"in s))s.input=n.value;s.inst??(s.inst=r),s.continue??(s.continue=!r._zod.def.abort),n.issues.push(Tt(s))}},e(n.value,n)),t);return r}function vx(e,t){let r=new ue({check:"custom",...C(t)});return r._zod.check=e,r}function Nr(e,...t){for(let r of t)for(let n of Reflect.ownKeys(r))if(Object.prototype.propertyIsEnumerable.call(r,n))Ne(e,n,r[n]);return e}function vi(e){let t=e?.target??"draft-2020-12";if(t==="draft-4")t="draft-04";if(t==="draft-7")t="draft-07";return{processors:e.processors??{},metadataRegistry:e?.metadata??yt,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 Rt(e,t,r,n,o){let s=typeof t.unrepresentable==="function"?t.unrepresentable({zodSchema:e,path:n.path,message:o}):t.unrepresentable;if(s==="any")return!1;if(s===void 0||s==="throw")throw Error(o);return Object.assign(r,s),!0}function se(e,t,r={path:[],schemaPath:[]}){var n;let o=e._zod.def,s=t.seen.get(e);if(s){if(s.count++,r.schemaPath.includes(e))s.cycle=r.path;return s.schema}let i={schema:{},count:1,cycle:void 0,path:r.path};t.seen.set(e,i),t.sharedDefsExtractedFor=void 0,t.sharedEmitDoneFor=void 0;let a=e._zod.toJSONSchema?.();if(a)i.schema=a;else{let u={...r,schemaPath:[...r.schemaPath,e],path:r.path};if(e._zod.processJSONSchema)e._zod.processJSONSchema(t,i.schema,u);else{let d=i.schema,f=t.processors[o.type];if(!f)throw Error(`[toJSONSchema]: Non-representable type encountered: ${o.type}`);f(e,t,d,u)}let p=e._zod.parent;if(p){if(!i.ref)i.ref=p;se(p,t,u),t.seen.get(p).isParent=!0}}let c=t.metadataRegistry.get(e);if(c)Nr(i.schema,c);if(t.io==="input"&&he(e))delete i.schema.examples,delete i.schema.default;if(t.io==="input"&&"_prefault"in i.schema)(n=i.schema).default??(n.default=i.schema._prefault);return delete i.schema._prefault,t.seen.get(e).schema}function Ed(e){return e.replace(/~/g,"~0").replace(/\//g,"~1")}function $i(e,t){let r=e.seen.get(t);if(!r)throw Error("Unprocessed schema. This is a bug in Zod.");if(e.external&&e.sharedDefsExtractedFor===e.external)return;let n=new Map;for(let i of e.seen.entries()){let a=e.metadataRegistry.get(i[0])?.id;if(a){let c=n.get(a);if(c&&c!==i[0])throw Error(`Duplicate schema id "${a}" detected during JSON Schema conversion. Two different schemas cannot share the same id when converted together.`);n.set(a,i[0])}}let o=(i)=>{let a=e.target==="draft-2020-12"?"$defs":"definitions";if(e.external){let p=e.external.registry.get(i[0])?.id,d=e.external.uri??((h)=>h);if(p)return{ref:d(p)};let f=i[1].defId??i[1].schema.id??`schema${e.counter++}`;return i[1].defId=f,{defId:f,ref:`${d("__shared")}#/${a}/${Ed(f)}`}}let c="#",l=`${c}/${a}/`;if(i[1]===r&&!i[1].schema.id)return{ref:c};let u=i[1].schema.id??`__schema${e.counter++}`;return{defId:u,ref:l+Ed(u)}},s=(i)=>{if(i[1].schema.$ref)return;let a=i[1],{ref:c,defId:l}=o(i);if(a.def={...a.schema},l)a.defId=l;let u=a.schema;for(let p in u)delete u[p];u.$ref=c};if(e.cycles==="throw")for(let i of e.seen.entries()){let a=i[1];if(a.cycle)throw Error(`Cycle detected: #/${a.cycle?.join("/")}/<root>
|
|
88
88
|
|
|
89
|
-
Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`)}for(let i of e.seen.entries()){let a=i[1];if(t===i[0]){s(i);continue}if(e.external){let u=e.external.registry.get(i[0])?.id;if(t!==i[0]&&u){s(i);continue}}if(e.metadataRegistry.get(i[0])?.id){s(i);continue}if(a.cycle){s(i);continue}if(a.count>1){if(e.reused==="ref")s(i)}}if(e.external)e.sharedDefsExtractedFor=e.external}function _l(e){let t=e.anyOf;if(!Array.isArray(t)||t.length===0||e.type!==void 0)return;let r=[];for(let n of t){if(!n||typeof n!=="object")return;_l(n);let o=Object.keys(n);if(o.length!==1||o[0]!=="type")return;let s=n.type;for(let i of Array.isArray(s)?s:[s]){if(typeof i!=="string")return;if(!r.includes(i))r.push(i)}}delete e.anyOf,e.type=r.length===1?r[0]:r}var bl=new Set(["type","properties","required","additionalProperties"]),xl=["oneOf","anyOf"];function yl(e){let t=e.additionalProperties;if(t===void 0||t===!1||typeof t!=="object"||t===null)return null;return Object.keys(t).length?t:null}function ns(e){let t=[];for(let s of e){if(typeof s!=="object"||s.type!=="object")return null;for(let i in s)if(!bl.has(i))return null;t.push(s)}let r={},n=new Set;for(let s of t){for(let i in s.properties){if(Object.prototype.hasOwnProperty.call(r,i))continue;let a=[];for(let u of t){let l=u.properties?.[i]??yl(u);if(l===null||l===void 0)continue;if(!a.some((p)=>JSON.stringify(p)===JSON.stringify(l)))a.push(l)}let c=a.length===1?a[0]:ns(a)??{allOf:a};ve(r,i,c)}for(let i of s.required??[])n.add(i)}let o={type:"object",properties:r};if(n.size)o.required=[...n];if(t.every((s)=>s.additionalProperties===!1))o.additionalProperties=!1;else{let s=[];for(let i of t){let a=yl(i);if(a&&!s.some((c)=>JSON.stringify(c)===JSON.stringify(a)))s.push(a)}if(s.length===1)o.additionalProperties=s[0];else if(s.length>1)o.additionalProperties={allOf:s}}return o}function Nh(e){let t=e.allOf;if(!Array.isArray(t)||t.length<2)return;for(let o of bl)if(o in e)return;let r=t.filter((o)=>xl.some((s)=>Array.isArray(o[s]))),n=null;if(!r.length)n=ns(t);else{let o=r[0],s=xl.find((c)=>Array.isArray(o[c]));if(Object.keys(o).length!==1)return;let i=t.filter((c)=>c!==o),a=o[s].map((c)=>ns([...i,c]));if(a.some((c)=>!c))return;n={[s]:a}}if(!n)return;delete e.allOf,rr(e,n)}function is(e,t){let r=e.seen.get(t);if(!r)throw Error("Unprocessed schema. This is a bug in Zod.");let n=(a)=>{let c=e.seen.get(a);if(c.ref===null)return;let u=c.def??c.schema,l={...u},p=c.ref;if(c.ref=null,p){n(p);let m=e.seen.get(p),f=m.schema;if(f.$ref&&(e.target==="draft-07"||e.target==="draft-04"||e.target==="openapi-3.0"))u.allOf=u.allOf??[],u.allOf.push(f);else rr(u,f);if(rr(u,l),a._zod.parent===p)for(let x in u){if(x==="$ref"||x==="allOf")continue;if(!(x in l))delete u[x]}if(f.$ref&&m.def)for(let x in u){if(x==="$ref"||x==="allOf")continue;if(x in m.def&&JSON.stringify(u[x])===JSON.stringify(m.def[x]))delete u[x]}}let d=a._zod.parent;if(d&&d!==p){n(d);let m=e.seen.get(d);if(m?.schema.$ref){if(u.$ref=m.schema.$ref,m.def)for(let f in u){if(f==="$ref"||f==="allOf")continue;if(f in m.def&&JSON.stringify(u[f])===JSON.stringify(m.def[f]))delete u[f]}}}e.override({zodSchema:a,jsonSchema:u,path:c.path??[]})};if(!e.external||e.sharedEmitDoneFor!==e.external){for(let a of[...e.seen.entries()].reverse())n(a[0]);if(e.target!=="openapi-3.0")for(let a of e.seen.entries())_l(a[1].def??a[1].schema);for(let a of e.deferred)a();if(e.intersections.length){let a=new Map;for(let c of e.seen.values())for(let u of[c.schema,c.def]){let l=u?.allOf;if(!Array.isArray(l))continue;let p=a.get(l);if(p)p.push(u);else a.set(l,[u])}for(let c of e.intersections)for(let u of a.get(c)??[])Nh(u)}}let o={};if(e.target==="draft-2020-12")o.$schema="https://json-schema.org/draft/2020-12/schema";else if(e.target==="draft-07")o.$schema="http://json-schema.org/draft-07/schema#";else if(e.target==="draft-04")o.$schema="http://json-schema.org/draft-04/schema#";else if(e.target==="openapi-3.0");if(e.external?.uri){let a=e.external.registry.get(t)?.id;if(!a)throw Error("Schema is missing an `id` property");o.$id=e.external.uri(a)}rr(o,r.defId?r.schema:r.def??r.schema);let s=e.metadataRegistry.get(t)?.id;if(s!==void 0&&o.id===s)delete o.id;let i=e.external?.defs??{};if(!e.external||e.sharedEmitDoneFor!==e.external)for(let a of e.seen.entries()){let c=a[1];if(c.def&&c.defId){if(c.def.id===c.defId)delete c.def.id;ve(i,c.defId,c.def)}}if(e.external)e.sharedEmitDoneFor=e.external;if(e.external);else if(Object.keys(i).length>0)if(e.target==="draft-2020-12")o.$defs=i;else o.definitions=i;try{let a=JSON.parse(JSON.stringify(o));return Object.defineProperty(a,"~standard",{value:{...t["~standard"],jsonSchema:{input:nr(t,"input",e.processors),output:nr(t,"output",e.processors)}},enumerable:!1,writable:!1}),a}catch(a){throw Error("Error converting schema to JSON.")}}function Y(e,t){let r=t??{seen:new Set};if(r.seen.has(e))return!1;r.seen.add(e);let n=e._zod.def;if(n.type==="transform")return!0;if(n.type==="array")return Y(n.element,r);if(n.type==="set")return Y(n.valueType,r);if(n.type==="lazy")return Y(n.getter(),r);if(n.type==="promise"||n.type==="optional"||n.type==="nonoptional"||n.type==="nullable"||n.type==="readonly"||n.type==="default"||n.type==="prefault"||n.type==="catch")return Y(n.innerType,r);if(n.type==="intersection")return Y(n.left,r)||Y(n.right,r);if(n.type==="record"||n.type==="map")return Y(n.keyType,r)||Y(n.valueType,r);if(n.type==="pipe"){if(e._zod.traits.has("$ZodCodec"))return!0;return Y(n.in,r)||Y(n.out,r)}if(n.type==="object"){for(let o in n.shape)if(Y(n.shape[o],r))return!0;return!1}if(n.type==="union"){for(let o of n.options)if(Y(o,r))return!0;return!1}if(n.type==="tuple"){for(let o of n.items)if(Y(o,r))return!0;if(n.rest&&Y(n.rest,r))return!0;return!1}return!1}var wl=(e,t={})=>(r)=>{let n=os({...r,processors:t});return V(e,n),ss(n,e),is(n,e)},nr=(e,t,r={})=>(n)=>{let{libraryOptions:o,target:s}=n??{},i=os({...o??{},target:s,io:t,processors:r});return V(e,i),ss(i,e),is(i,e)};var $t=(e,t,r)=>{if(e[t]===void 0||r>e[t])e[t]=r},St=(e,t,r)=>{if(e[t]===void 0||r<e[t])e[t]=r},vl=(e,t)=>{$t(e,"minimum",t),St(e,"maximum",t)},kl=(e,t)=>{if(e.multipleOf??(e.multipleOf=[]),!e.multipleOf.includes(t))e.multipleOf.push(t)},zl=(e,t)=>{e.patterns??(e.patterns=new Set),e.patterns.add(t)},El=(e,t)=>{e.mime=e.mime?e.mime.filter((r)=>t.includes(r)):[...t]},Cl=(e,t)=>{if(e.format=t,t.includes("int"))e.isInt=!0},$l=(e,t)=>$t(e,"minimum",t.minimum),Sl=(e,t)=>St(e,"maximum",t.maximum),Pl=(e)=>(t,r)=>{Cl(t,r.format);let[n,o]=e[r.format];$t(t,"minimum",n),St(t,"maximum",o)},Uh={greater_than:(e,t)=>$t(e,t.inclusive?"minimum":"exclusiveMinimum",t.value),less_than:(e,t)=>St(e,t.inclusive?"maximum":"exclusiveMaximum",t.value),multiple_of:(e,t)=>kl(e,t.value),number_format:Pl(Rr),bigint_format:Pl(bo),min_length:$l,max_length:Sl,length_equals:(e,t)=>vl(e,t.length),min_size:$l,max_size:Sl,size_equals:(e,t)=>vl(e,t.size),string_format:(e,t)=>{if(Cl(e,t.format),t.pattern)zl(e,t.pattern);if(t.format==="base64"||t.format==="base64url")e.contentEncoding=t.format;if(t.local||t.precision===-1)e.laxFormat=!0},mime_type:(e,t)=>El(e,t.mime)};function de(e){let t={},r=e._zod.def,n=e._zod.traits.has("$ZodCheck")?[e,...r.checks??[]]:r.checks??[];for(let s of n)Uh[s._zod.def.check]?.(t,s._zod.def);let o=e._zod.bag;if(o.minimum!==void 0)$t(t,"minimum",o.minimum);if(o.exclusiveMinimum!==void 0)$t(t,"exclusiveMinimum",o.exclusiveMinimum);if(o.maximum!==void 0)St(t,"maximum",o.maximum);if(o.exclusiveMaximum!==void 0)St(t,"exclusiveMaximum",o.exclusiveMaximum);if(o.multipleOf!==void 0)kl(t,o.multipleOf);if(o.format!==void 0){if(t.format??(t.format=o.format),o.format.includes("int"))t.isInt=!0}if(o.mime)El(t,o.mime);for(let s of o.patterns??[])zl(t,s);return t}var Fh={guid:"uuid",url:"uri",datetime:"date-time",json_string:"json-string",regex:""},Mh=new Map([[Do,ec],[qr,tc]]),Il=(e)=>Mh.get(e)??e,Tl=(e,t,r,n)=>{let o=r;o.type="string";let{minimum:s,maximum:i,format:a,patterns:c,contentEncoding:u,laxFormat:l}=de(e);if(typeof s==="number")o.minLength=s;if(typeof i==="number")o.maxLength=i;if(a){if(o.format=Fh[a]??a,o.format==="")delete o.format;if(a==="time"||l)delete o.format}if(u)o.contentEncoding=u;if(c&&c.size>0){let p=[...c].map(Il);if(p.length===1)o.pattern=p[0].source;else if(p.length>1)o.allOf=[...p.map((d)=>({...t.target==="draft-07"||t.target==="draft-04"||t.target==="openapi-3.0"?{type:"string"}:{},pattern:d.source}))]}},Ol=(e,t,r,n)=>{let o=r,{minimum:s,maximum:i,multipleOf:a,exclusiveMaximum:c,exclusiveMinimum:u,isInt:l}=de(e);o.type=l?"integer":"number";let p=typeof u==="number"&&u>=(s??Number.NEGATIVE_INFINITY),d=typeof c==="number"&&c<=(i??Number.POSITIVE_INFINITY),m=t.target==="draft-04"||t.target==="openapi-3.0";if(p)if(m)o.minimum=u,o.exclusiveMinimum=!0;else o.exclusiveMinimum=u;else if(typeof s==="number")o.minimum=s;if(d)if(m)o.maximum=c,o.exclusiveMaximum=!0;else o.exclusiveMaximum=c;else if(typeof i==="number")o.maximum=i;if(a){let f=new Set;for(let y of a)if(Number.isFinite(y)&&y!==0)f.add(Math.abs(y));else ct(e,t,o,n,`A multipleOf divisor of ${y} cannot be represented in JSON Schema`);let[g,...x]=f;if(g!==void 0)o.multipleOf=g;if(x.length)o.allOf=[...o.allOf??[],...x.map((y)=>({multipleOf:y}))]}},Al=(e,t,r,n)=>{r.type="boolean"};var jl=(e,t,r,n)=>{r.not={}};var Rl=(e,t,r,n)=>{};var Ll=(e,t,r,n)=>{let o=e._zod.def,s=Wt(o.entries);if(s.length===0){r.not={};return}if(s.every((i)=>typeof i==="number"))r.type="number";if(s.every((i)=>typeof i==="string"))r.type="string";r.enum=s};var Zl=(e,t,r,n)=>{ct(e,t,r,n,"Custom types cannot be represented in JSON Schema")};var Dl=(e,t,r,n)=>{ct(e,t,r,n,"Transforms cannot be represented in JSON Schema")};var Nl=(e,t,r,n)=>{let o=r,s=e._zod.def,{minimum:i,maximum:a}=de(e);if(typeof i==="number")o.minItems=i;if(typeof a==="number")o.maxItems=a;o.type="array",o.items=V(s.element,t,{...n,path:[...n.path,"items"]})};function pn(e){let t=e._zod.def;if(t.type==="pipe"&&t.in._zod.traits.has("$ZodTransform"))return pn(t.out);if(t.type==="catch")return pn(t.innerType);return e._zod.optin}var Ul=(e,t,r,n)=>{let o=r,s=e._zod.def,i=s.shape;if(Object.getOwnPropertySymbols(i).length&&ct(e,t,o,n,"Symbol keys cannot be represented in JSON Schema"))return;o.type="object",o.properties={};for(let u in i)ve(o.properties,u,V(i[u],t,{...n,path:[...n.path,"properties",u]}));let c=[];for(let u of Object.keys(i)){let l=s.shape[u];if(t.io==="input"?pn(l)===void 0:l._zod.optout===void 0)c.push(u)}if(c.length>0)o.required=c;if(s.catchall?._zod.def.type==="never")o.additionalProperties=!1;else if(!s.catchall){if(t.io==="output")o.additionalProperties=!1}else if(s.catchall)o.additionalProperties=V(s.catchall,t,{...n,path:[...n.path,"additionalProperties"]})},Fl=(e,t,r,n)=>{let o=e._zod.def,s=o.inclusive===!1,i=o.options.map((a,c)=>V(a,t,{...n,path:[...n.path,s?"oneOf":"anyOf",c]}));if(s)r.oneOf=i;else r.anyOf=i},Ml=(e,t,r,n)=>{let o=e._zod.def,s=V(o.left,t,{...n,path:[...n.path,"allOf",0]}),i=V(o.right,t,{...n,path:[...n.path,"allOf",1]}),a=(u)=>("allOf"in u)&&Object.keys(u).length===1,c=[...a(s)?s.allOf:[s],...a(i)?i.allOf:[i]];r.allOf=c,t.intersections.push(c)};function as(e,t,r){if(t.$ref){if(r.has(t))return t;r.add(t);let f=e.get(t)?.def;if(!f)return t;let g=as(e,f,r);return g===f?t:g}for(let f of["anyOf","oneOf"]){let g=t[f];if(!Array.isArray(g))continue;let x=g.map((y)=>as(e,y,r));if(x.some((y,w)=>y!==g[w]))t={...t,[f]:x}}let n=Array.isArray(t.type)?t.type:[t.type],o=!n.includes("string")&&n.some((f)=>f==="number"||f==="integer"),s=t.enum??(t.const!==void 0?[t.const]:void 0);if(!o&&!s?.some((f)=>typeof f==="number"))return t;let{minimum:i,maximum:a,exclusiveMinimum:c,exclusiveMaximum:u,multipleOf:l,format:p,id:d,...m}=t;if(m.enum)m.enum=m.enum.map((f)=>typeof f==="number"?String(f):f);else if(typeof m.const==="number")m.const=String(m.const);if(!o)return m;if(m.type="string",!s)m.pattern=(n.includes("number")?qt:To).source;return m}var cs=new WeakMap;function Bh(e){let t=new Map;for(let n of e.seen.values())if(n.def&&!t.has(n.schema))t.set(n.schema,n);let r=new Map;for(let n of cs.get(e)??[]){let o=e.seen.get(n),s=(o?.def??o?.schema)?.propertyNames;if(!s||s===!0||r.has(s))continue;let i=as(t,s,new Set);if(i!==s)r.set(s,i)}if(!r.size)return;for(let n of e.seen.values())for(let o of[n.schema,n.def]){let s=o&&r.get(o.propertyNames);if(s)o.propertyNames=s}}var Bl=(e,t,r,n)=>{let o=r,s=e._zod.def;o.type="object";let i=s.keyType,a=de(i).patterns;if(s.mode==="loose"&&a&&a.size>0){let l=V(s.valueType,t,{...n,path:[...n.path,"patternProperties","*"]});o.patternProperties={};for(let p of a)ve(o.patternProperties,Il(p).source,l)}else{if(t.target==="draft-07"||t.target==="draft-2020-12"){o.propertyNames=V(s.keyType,t,{...n,path:[...n.path,"propertyNames"]});let l=cs.get(t);if(!l)l=[],cs.set(t,l),t.deferred.push(()=>Bh(t));l.push(e)}o.additionalProperties=V(s.valueType,t,{...n,path:[...n.path,"additionalProperties"]})}let c=i._zod.values,u=t.io==="input"&&pn(s.valueType)!==void 0;if(c&&!s.partial&&!u){let l=[...c].filter((p)=>typeof p==="string"||typeof p==="number");if(l.length>0)o.required=l.map(String)}},Gl=(e,t,r,n)=>{let o=e._zod.def,s=V(o.innerType,t,n),i=t.seen.get(e);if(t.target==="openapi-3.0")i.ref=o.innerType,r.nullable=!0;else r.anyOf=[s,{type:"null"}]},Vl=(e,t,r,n)=>{let o=e._zod.def;V(o.innerType,t,n);let s=t.seen.get(e);s.ref=o.innerType},us=Symbol();function Wl(e,t,r,n,o){let s=!1,i=JSON.stringify(e,(a,c)=>{if(typeof c!=="bigint")return c;return s=!0,null});if(!s)return JSON.parse(i);return ct(t,r,n,o,"BigInt defaults cannot be represented in JSON Schema"),us}var Kl=(e,t,r,n)=>{let o=e._zod.def;V(o.innerType,t,n);let s=t.seen.get(e);s.ref=o.innerType;let i=Wl(o.defaultValue,e,t,r,n);if(i!==us)r.default=i},Jl=(e,t,r,n)=>{let o=e._zod.def;V(o.innerType,t,n);let s=t.seen.get(e);if(s.ref=o.innerType,t.io!=="input")return;let i=Wl(o.defaultValue,e,t,r,n);if(i!==us)r._prefault=i},Hl=(e,t,r,n)=>{let o=e._zod.def;V(o.innerType,t,n);let s=t.seen.get(e);s.ref=o.innerType;let i;try{i=o.catchValue(void 0)}catch{ct(e,t,r,n,"Dynamic catch values are not supported in JSON Schema");return}r.default=i},ql=(e,t,r,n)=>{let o=e._zod.def,s=o.in._zod.traits.has("$ZodTransform"),i=t.io==="input"?s?o.out:o.in:o.out;V(i,t,n);let a=t.seen.get(e);a.ref=i},Yl=(e,t,r,n)=>{let o=e._zod.def;V(o.innerType,t,n);let s=t.seen.get(e);s.ref=o.innerType,r.readOnly=!0};var ls=(e,t,r,n)=>{let o=e._zod.def;V(o.innerType,t,n);let s=t.seen.get(e);s.ref=o.innerType};var Xl=new WeakSet([Object.prototype,Error.prototype]);function dn(e,t,r){Object.defineProperty(e,t,{configurable:!0,enumerable:!1,get(){let n=r(this);return Object.defineProperty(this,t,{value:n,configurable:!0,writable:!0}),n},set(n){Object.defineProperty(this,t,{value:n,configurable:!0,writable:!0})}})}var Xh=(e,t)=>{Ca.init(e,t),e.name="ZodError";let r=Object.getPrototypeOf(e);if(Xl.has(r))return;Xl.add(r),dn(r,"format",(n)=>(o)=>ko(n,o)),dn(r,"flatten",(n)=>(o)=>Po(n,o)),dn(r,"addIssue",(n)=>(o)=>{n.issues.push(o),n.message=JSON.stringify(n.issues,Kt,2)}),dn(r,"addIssues",(n)=>(o)=>{n.issues.push(...o),n.message=JSON.stringify(n.issues,Kt,2)}),Object.defineProperty(r,"isEmpty",{configurable:!0,enumerable:!1,get(){return this.issues.length===0}})};var ce=h("ZodError",Xh,void 0,{Parent:Error});var Ql=Fr(ce),ep=Mr(ce),tp=Br(ce),rp=Gr(ce),np=Ta(ce),op=Oa(ce),sp=Aa(ce),ip=ja(ce),ap=Ra(ce),cp=La(ce),up=Za(ce),lp=Da(ce);function eg(){if(!ee.localeError)te(Go())}function fn(){if(!ee.memoizer)te({memoizer:Bo()})}var M=h("ZodType",(e,t)=>(eg(),U.init(e,t),e.def=t,e.type=t.type,e),{check(...e){let t=this.def;return this.clone(ae(t,{checks:[...t.checks??[],...e.map((r)=>typeof r==="function"?{_zod:{check:r,def:{check:"custom"},onattach:[]}}:r)]}),{parent:!0})},with(...e){return this.check(...e)},clone(e,t){return $e(this,e,t)},brand(){return this},register(e,t){return e.add(this,t),this},refine(e,t){return this.check(Kg(e,t))},superRefine(e,t){return this.check(Jg(e,t))},overwrite(e){return this.check(qe(e))},optional(){return dp(this)},exactOptional(){return jg(this)},nullable(){return mp(this)},nullish(){return dp(mp(this))},nonoptional(e){return Ug(this,e)},array(){return me(this)},or(e){return fs([this,e])},and(e){return Ig(this,e)},transform(e){return fp(this,Ag(e))},default(e){return Zg(this,e)},prefault(e){return Ng(this,e)},catch(e){return Mg(this,e)},pipe(e){return fp(this,e)},readonly(){return Vg(this)},describe(e){let t=this.clone();return He.add(t,{description:e}),t},meta(...e){if(e.length===0)return He.get(this);let t=this.clone();return He.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 Nr(this,"~standard",{...Zo(this),jsonSchema:{input:nr(this,"input"),output:nr(this,"output")}})},set "~standard"(e){Me(this,"~standard",e)},parse:function e(t,r){return Ql(this,t,r,{callee:e})},parseAsync:async function e(t,r){return await ep(this,t,r,{callee:e})},safeParse(e,t){return tp(this,e,t)},async safeParseAsync(e,t){return rp(this,e,t)},get spa(){return this?.safeParseAsync},set spa(e){Me(this,"spa",e)},validate(e,t){return zo(this,e,t)},validateAsync(e,t){return Eo(this,e,t)},encode:function e(t,r){return np(this,t,r,{callee:e})},decode:function e(t,r){return op(this,t,r,{callee:e})},encodeAsync:async function e(t,r){return await sp(this,t,r,{callee:e})},decodeAsync:async function e(t,r){return await ip(this,t,r,{callee:e})},safeEncode(e,t){return ap(this,e,t)},safeDecode(e,t){return cp(this,e,t)},async safeEncodeAsync(e,t){return up(this,e,t)},async safeDecodeAsync(e,t){return lp(this,e,t)},toJSONSchema(e){return wl(this,{})(e)},get description(){return He.get(this)?.description},get _def(){return this._zod.def}}),hp=h("_ZodString",(e,t)=>{Hr.init(e,t),M.init(e,t),e._zod.processJSONSchema=(r,n,o)=>Tl(e,r,n,o)},$a({format:(e)=>de(e).format??null,minLength:(e)=>de(e).minimum??null,maxLength:(e)=>de(e).maximum??null},{regex(...e){return this.check(Wo(...e))},includes(...e){return this.check(Ho(...e))},startsWith(...e){return this.check(qo(...e))},endsWith(...e){return this.check(Yo(...e))},min(...e){return this.check(vt(...e))},max(...e){return this.check(un(...e))},length(...e){return this.check(ln(...e))},nonempty(...e){return this.check(vt(1,...e))},lowercase(e){return this.check(Ko(e))},uppercase(e){return this.check(Jo(e))},trim(){return this.check(Qo())},normalize(...e){return this.check(Xo(...e))},toLowerCase(){return this.check(es())},toUpperCase(){return this.check(ts())},slugify(){return this.check(rs())}})),tg=h("ZodString",(e,t)=>{Hr.init(e,t),hp.init(e,t)},{email(e){return this.check(Fu(rg,e))},url(e){return this.check(Vo(gp,e))},jwt(e){return this.check(al(_g,e))},emoji(e){return this.check(Ku(sg,e))},guid(e){return this.check(Mu(ng,e))},uuid(e){return this.check(Bu(mn,e))},uuidv4(e){return this.check(Gu(mn,e))},uuidv6(e){return this.check(Vu(mn,e))},uuidv7(e){return this.check(Wu(mn,e))},nanoid(e){return this.check(Ju(ig,e))},cuid(e){return this.check(Hu(ag,e))},cuid2(e){return this.check(qu(cg,e))},ulid(e){return this.check(Yu(ug,e))},base64(e){return this.check(ol(gg,e))},base64url(e){return this.check(sl(xg,e))},xid(e){return this.check(Xu(lg,e))},ksuid(e){return this.check(Qu(pg,e))},ipv4(e){return this.check(el(dg,e))},ipv6(e){return this.check(tl(mg,e))},cidrv4(e){return this.check(rl(fg,e))},cidrv6(e){return this.check(nl(hg,e))},e164(e){return this.check(il(yg,e))},datetime(e){return this.check(tn(sr,e))},date(e){return this.check(rn(ir,e))},time(e){return this.check(nn(ar,e))},duration(e){return this.check(on(cr,e))}});function b(e){return Uu(tg,e)}var F=h("ZodStringFormat",(e,t)=>{D.init(e,t),hp.init(e,t)}),sr=h("ZodISODateTime",(e,t)=>{qc.init(e,t),F.init(e,t)}),ir=h("ZodISODate",(e,t)=>{Yc.init(e,t),F.init(e,t)}),ar=h("ZodISOTime",(e,t)=>{Xc.init(e,t),F.init(e,t)}),cr=h("ZodISODuration",(e,t)=>{Qc.init(e,t),F.init(e,t)}),rg=h("ZodEmail",(e,t)=>{Nc.init(e,t),F.init(e,t)});var ng=h("ZodGUID",(e,t)=>{Zc.init(e,t),F.init(e,t)});var mn=h("ZodUUID",(e,t)=>{Dc.init(e,t),F.init(e,t)});var gp=h("ZodURL",(e,t)=>{Mc.init(e,t),F.init(e,t)});function og(e){return Vo(gp,e)}var sg=h("ZodEmoji",(e,t)=>{Bc.init(e,t),F.init(e,t)});var ig=h("ZodNanoID",(e,t)=>{Gc.init(e,t),F.init(e,t)});var ag=h("ZodCUID",(e,t)=>{Vc.init(e,t),F.init(e,t)});var cg=h("ZodCUID2",(e,t)=>{Wc.init(e,t),F.init(e,t)});var ug=h("ZodULID",(e,t)=>{Kc.init(e,t),F.init(e,t)});var lg=h("ZodXID",(e,t)=>{Jc.init(e,t),F.init(e,t)});var pg=h("ZodKSUID",(e,t)=>{Hc.init(e,t),F.init(e,t)});var dg=h("ZodIPv4",(e,t)=>{eu.init(e,t),F.init(e,t)});var mg=h("ZodIPv6",(e,t)=>{ru.init(e,t),F.init(e,t)});var fg=h("ZodCIDRv4",(e,t)=>{nu.init(e,t),F.init(e,t)});var hg=h("ZodCIDRv6",(e,t)=>{ou.init(e,t),F.init(e,t)});var gg=h("ZodBase64",(e,t)=>{iu.init(e,t),F.init(e,t)});var xg=h("ZodBase64URL",(e,t)=>{au.init(e,t),F.init(e,t)});var yg=h("ZodE164",(e,t)=>{cu.init(e,t),F.init(e,t)});var _g=h("ZodJWT",(e,t)=>{uu.init(e,t),F.init(e,t)});var xp=h("ZodNumber",(e,t)=>{No.init(e,t),M.init(e,t),e._zod.processJSONSchema=(r,n,o)=>Ol(e,r,n,o),e.isFinite=!0},$a({minValue:(e)=>{let{minimum:t,exclusiveMinimum:r}=de(e);return Math.max(t??Number.NEGATIVE_INFINITY,r??Number.NEGATIVE_INFINITY)},maxValue:(e)=>{let{maximum:t,exclusiveMaximum:r}=de(e);return Math.min(t??Number.POSITIVE_INFINITY,r??Number.POSITIVE_INFINITY)},isInt:(e)=>{let{isInt:t,multipleOf:r}=de(e);return!!t||!!r?.some(Number.isSafeInteger)},format:(e)=>de(e).format??null},{gt(e,t){return this.check(an(e,t))},gte(e,t){return this.check(tr(e,t))},min(e,t){return this.check(tr(e,t))},lt(e,t){return this.check(sn(e,t))},lte(e,t){return this.check(er(e,t))},max(e,t){return this.check(er(e,t))},int(e){return this.check(pp(e))},safe(e){return this.check(pp(e))},positive(e){return this.check(an(0,e))},nonnegative(e){return this.check(tr(0,e))},negative(e){return this.check(sn(0,e))},nonpositive(e){return this.check(er(0,e))},multipleOf(e,t){return this.check(cn(e,t))},step(e,t){return this.check(cn(e,t))},finite(){return this}}));function yp(e){return cl(xp,e)}var bg=h("ZodNumberFormat",(e,t)=>{lu.init(e,t),xp.init(e,t)});function pp(e){return ul(bg,e)}var wg=h("ZodBoolean",(e,t)=>{pu.init(e,t),M.init(e,t),e._zod.processJSONSchema=(r,n,o)=>Al(e,r,n,o)});function vg(e){return ll(wg,e)}var $g=h("ZodUnknown",(e,t)=>{du.init(e,t),M.init(e,t),e._zod.processJSONSchema=(r,n,o)=>Rl(e,r,n,o)});function ps(){return pl($g)}var Sg=h("ZodNever",(e,t)=>{mu.init(e,t),M.init(e,t),e._zod.processJSONSchema=(r,n,o)=>jl(e,r,n,o)});function Pg(e){return dl(Sg,e)}var kg=h("ZodArray",(e,t)=>{fn(),fu.init(e,t),M.init(e,t),e._zod.processJSONSchema=(r,n,o)=>Nl(e,r,n,o),e.element=t.element},{min(e,t){return this.check(vt(e,t))},nonempty(e){return this.check(vt(1,e))},max(e,t){return this.check(un(e,t))},length(e,t){return this.check(ln(e,t))},unwrap(){return this.element}});function me(e,t){return ml(kg,e,t)}var zg=h("ZodObject",(e,t)=>{fn(),xu.init(e,t),M.init(e,t),e._zod.processJSONSchema=(r,n,o)=>Ul(e,r,n,o),ch(e,"shape",(r)=>r._zod.def.shape,!1)},{keyof(){return _p(Object.keys(this._zod.def.shape))},catchall(e){return this.clone(ae(this._zod.def,{catchall:e}))},passthrough(){return this.clone(ae(this._zod.def,{catchall:ps()}))},loose(){return this.clone(ae(this._zod.def,{catchall:ps()}))},strict(){return this.clone(ae(this._zod.def,{catchall:Pg()}))},strip(){return this.clone(ae(this._zod.def,{catchall:void 0}))},extend(e){return eh(this,e)},safeExtend(e){return th(this,e)},merge(e){return rh(this,e)},pick(e){return Xf(this,e)},omit(e){return Qf(this,e)},partial(...e){return _a(bp,this,e[0])},exactPartial(...e){return _a(wp,this,e[0],"exactPartial")},required(...e){return nh(vp,this,e[0])}});function z(e,t){let r={type:"object",shape:e??{},...v(t)};return new zg(r)}var Eg=h("ZodUnion",(e,t)=>{yu.init(e,t),M.init(e,t),e._zod.processJSONSchema=(r,n,o)=>Fl(e,r,n,o),e.options=t.options});function fs(e,t){return new Eg({type:"union",options:e,...v(t)})}var Cg=h("ZodIntersection",(e,t)=>{_u.init(e,t),M.init(e,t),e._zod.processJSONSchema=(r,n,o)=>Ml(e,r,n,o)});function Ig(e,t){return new Cg({type:"intersection",left:e,right:t})}var ds=h("ZodRecord",(e,t)=>{fn(),bu.init(e,t),M.init(e,t),e._zod.processJSONSchema=(r,n,o)=>Bl(e,r,n,o),e.keyType=t.keyType,e.valueType=t.valueType});function hs(e,t,r){if(!t||!t._zod)return new ds({type:"record",keyType:b(),valueType:e,...v(t)});return new ds({type:"record",keyType:e,valueType:t,...v(r)})}function Tg(e,t,r){return new ds({type:"record",keyType:e,valueType:t,...v(r),partial:!0})}var ms=h("ZodEnum",(e,t)=>{wu.init(e,t),M.init(e,t),e._zod.processJSONSchema=(n,o,s)=>Ll(e,n,o,s),e.enum=t.entries,e.options=[...e._zod.values];let r=new Set(Object.keys(t.entries));e.extract=(n,o)=>{let s={};for(let i of n)if(r.has(i))s[i]=t.entries[i];else throw Error(`Key ${i} not found in enum`);return new ms({...t,checks:[],...v(o),entries:s})},e.exclude=(n,o)=>{let s={...t.entries};for(let i of n)if(r.has(i))delete s[i];else throw Error(`Key ${i} not found in enum`);return new ms({...t,checks:[],...v(o),entries:s})}});function _p(e,t){let r=Array.isArray(e)?Object.fromEntries(e.map((n)=>[n,n])):e;return new ms({type:"enum",entries:r,...v(t)})}var Og=h("ZodTransform",(e,t)=>{fn(),vu.init(e,t),M.init(e,t),e._zod.processJSONSchema=(r,n,o)=>Dl(e,r,n,o),e._zod.parse=(r,n)=>{if(n.direction==="backward")throw new Jt(e.constructor.name);r.addIssue=(s)=>{if(typeof s==="string")r.issues.push(at(s,r.value,t));else{let i=s;if(i.fatal)i.continue=!1;if(i.code??(i.code="custom"),!("input"in i))i.input=r.value;i.inst??(i.inst=e),r.issues.push(at(i))}};let o=t.transform(r.value,r);if(o instanceof Promise)return o.then((s)=>(r.value=s,r));return r.value=o,r}});function Ag(e){return new Og({type:"transform",transform:e})}var bp=h("ZodOptional",(e,t)=>{Uo.init(e,t),M.init(e,t),e._zod.processJSONSchema=(r,n,o)=>ls(e,r,n,o),e.unwrap=()=>e._zod.def.innerType});function dp(e){return new bp({type:"optional",innerType:e})}var wp=h("ZodExactOptional",(e,t)=>{$u.init(e,t),M.init(e,t),e._zod.processJSONSchema=(r,n,o)=>ls(e,r,n,o),e.unwrap=()=>e._zod.def.innerType});function jg(e){return new wp({type:"optional",innerType:e})}var Rg=h("ZodNullable",(e,t)=>{Su.init(e,t),M.init(e,t),e._zod.processJSONSchema=(r,n,o)=>Gl(e,r,n,o),e.unwrap=()=>e._zod.def.innerType});function mp(e){return new Rg({type:"nullable",innerType:e})}var Lg=h("ZodDefault",(e,t)=>{Pu.init(e,t),M.init(e,t),e._zod.processJSONSchema=(r,n,o)=>Kl(e,r,n,o),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap});function Zg(e,t){return new Lg({type:"default",innerType:e,get defaultValue(){return typeof t==="function"?t():yo(t)}})}var Dg=h("ZodPrefault",(e,t)=>{ku.init(e,t),M.init(e,t),e._zod.processJSONSchema=(r,n,o)=>Jl(e,r,n,o),e.unwrap=()=>e._zod.def.innerType});function Ng(e,t){return new Dg({type:"prefault",innerType:e,get defaultValue(){return typeof t==="function"?t():yo(t)}})}var vp=h("ZodNonOptional",(e,t)=>{zu.init(e,t),M.init(e,t),e._zod.processJSONSchema=(r,n,o)=>Vl(e,r,n,o),e.unwrap=()=>e._zod.def.innerType});function Ug(e,t){return new vp({type:"nonoptional",innerType:e,...v(t)})}var Fg=h("ZodCatch",(e,t)=>{Eu.init(e,t),M.init(e,t),e._zod.processJSONSchema=(r,n,o)=>Hl(e,r,n,o),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap});function Mg(e,t){return new Fg({type:"catch",innerType:e,catchValue:typeof t==="function"?t:Sa(t)})}var Bg=h("ZodPipe",(e,t)=>{Cu.init(e,t),M.init(e,t),e._zod.processJSONSchema=(r,n,o)=>ql(e,r,n,o),e.in=t.in,e.out=t.out});function fp(e,t){return new Bg({type:"pipe",in:e,out:t})}var Gg=h("ZodReadonly",(e,t)=>{Iu.init(e,t),M.init(e,t),e._zod.processJSONSchema=(r,n,o)=>Yl(e,r,n,o),e.unwrap=()=>e._zod.def.innerType});function Vg(e){return new Gg({type:"readonly",innerType:e})}var Wg=h("ZodCustom",(e,t)=>{Tu.init(e,t),M.init(e,t),e._zod.processJSONSchema=(r,n,o)=>Zl(e,r,n,o)});function Kg(e,t={}){return fl(Wg,e,t)}function Jg(e,t){return hl(e,t)}var hn={};jm(hn,{ZodISODate:()=>ir,ZodISODateTime:()=>sr,ZodISODuration:()=>cr,ZodISOTime:()=>ar,date:()=>qg,datetime:()=>Hg,duration:()=>Xg,time:()=>Yg});function Hg(e){return tn(sr,e)}function qg(e){return rn(ir,e)}function Yg(e){return nn(ar,e)}function Xg(e){return on(cr,e)}var $p=mt(Tt(),1);var gs=()=>process.env.NIPA_DEBUG==="1",Pt=(e)=>{if(gs())ie($p.default.dim(`> [debug] [${new Date().toISOString()}] ${e}`))};class kt extends Error{url;constructor(e,t){super(`can't reach ${new URL(e).host}: ${t}`);this.name="NetworkError",this.url=e}}var Sp=(e)=>e.cause instanceof Error?`${e.message} (${Sp(e.cause)})`:e.message,Oe=async(e,t={})=>{let r=t.method??"GET",n=performance.now();Pt(`${r} ${e}`);let o;try{o=await fetch(e,t)}catch(s){throw new kt(e,s instanceof Error?Sp(s):String(s))}return Pt(`${o.status} ${r} ${e} [${we(performance.now()-n)}]`),o};var xs=z({domainId:b().optional(),id:b(),name:b()});class ue extends Error{status;constructor(e,t){super(e);this.name="KeystoneError",this.status=t}}var gn=(e)=>{let t=e;while(t.endsWith("/"))t=t.slice(0,-1);if(t.endsWith("/v3"))t=t.slice(0,-3);return`${t}/v3`},ys=(e,t)=>t?{auth:{identity:e,scope:{project:{id:t}}}}:{auth:{identity:e}},kp=(e)=>({domain:{name:e.userDomain},name:e.username}),Qg=(e,t)=>ys({methods:["password"],password:{user:{...kp(e),password:t}}},e.projectId),ex=(e,t)=>ys({methods:["totp"],totp:{user:{...kp(e),passcode:t}}},e.projectId),tx=(e,t)=>ys({methods:["token"],token:{id:e}},t),rx=z({error:z({message:b().optional()}).optional(),receipt:z({}).loose().optional(),required_auth_methods:me(me(b())).optional()}),zp=async(e)=>{try{let t=rx.safeParse(JSON.parse(await e.text()));return t.success?t.data:{}}catch{return{}}},Ep=(e)=>e.length>0?`this account needs ${e.map((t)=>t.join(" + ")).join(" or ")} to log in`:"this account's MFA rules don't allow this login method",nx=(e)=>{let{body:t,status:r}=e;if(t.receipt)return Ep(t.required_auth_methods??[]);if(r===401)return e.unauthorized;return t.error?.message??`Keystone returned HTTP ${r}`},ur=async(e,t)=>{let r=await zp(e);throw new ue(nx({body:r,status:e.status,unauthorized:t}),e.status)},ox=z({token:z({expires_at:b(),project:z({domain:z({id:b()}).optional(),id:b(),name:b()}).optional(),user:z({id:b(),name:b()})})}),sx=(e,t)=>{let{expires_at:r,project:n,user:o}=t.token;return{expiresAt:r,project:n&&{domainId:n.domain?.id,id:n.id,name:n.name},user:o,value:e}},Cp="Openstack-Auth-Receipt",_s=(e,t,r)=>{let n=new Headers({"Content-Type":"application/json"});if(r!==void 0)n.set(Cp,r);return Oe(`${gn(e)}/auth/tokens`,{body:JSON.stringify(t),headers:n,method:"POST"})},bs=async(e)=>{let t=e.headers.get("X-Subject-Token");if(!t)throw new ue("Keystone didn't return a token",e.status);let r=ox.safeParse(await e.json());if(!r.success)throw new ue(`unexpected token response: ${Ht(r.error)}`,e.status);return sx(t,r.data)},Ip=async(e,t)=>{let r=await _s(e.authUrl,Qg(e,t));if(r.ok)return{kind:"token",token:await bs(r)};let n=r.headers.get(Cp);if(r.status===401&&n){let s=(await zp(r)).required_auth_methods;if(!s||s.some((i)=>i.includes("totp")))return{kind:"mfa",receipt:n};throw new ue(Ep(s),r.status)}return ur(r,"wrong email or password")},Tp=async(e)=>{let{account:t,passcode:r,receipt:n}=e,o=await _s(t.authUrl,ex(t,r),n);return o.ok?bs(o):ur(o,"wrong OTP code")},ws="the session expired or was revoked",xn=async(e)=>{let t=await _s(e.authUrl,tx(e.token,e.projectId));return t.ok?bs(t):ur(t,ws)},ix=z({projects:me(z({domain_id:b().optional(),enabled:vg().optional(),id:b(),name:b()}))}),ax=(e)=>e.projects.filter((t)=>t.enabled!==!1).map((t)=>({domainId:t.domain_id,id:t.id,name:t.name})).toSorted((t,r)=>t.name.localeCompare(r.name)),zt=async({authUrl:e,token:t})=>{let r=await Oe(`${gn(e)}/auth/projects`,{headers:{"X-Auth-Token":t}});if(!r.ok)return ur(r,ws);let n=ix.safeParse(await r.json());if(!n.success)throw new ue(`unexpected project list: ${Ht(n.error)}`,r.status);return ax(n.data)},yn=async({authUrl:e,token:t})=>{let r=await Oe(`${gn(e)}/auth/tokens`,{headers:{"X-Auth-Token":t,"X-Subject-Token":t},method:"DELETE"});if(!(r.ok||r.status===401||r.status===404))await ur(r,ws)},Pp=z({version:z({id:b(),status:b()})}),Op=async(e)=>{let t=gn(e),r=await Oe(t,{signal:AbortSignal.timeout(1e4)}),n;try{n=Pp.safeParse(await r.json())}catch{n=Pp.safeParse(null)}if(!(r.ok&&n.success))throw new ue(`${t} doesn't answer like Keystone v3 (HTTP ${r.status})`,r.status);return n.data.version.id};import{spawn as kx}from"node:child_process";import{once as zx}from"node:events";import{stat as Ex}from"node:fs/promises";import{text as Cx}from"node:stream/consumers";import{accessSync as cx,constants as ux}from"node:fs";import{homedir as lx}from"node:os";import lr from"node:path";var Ap=(e)=>{try{return cx(e,ux.X_OK),!0}catch{return!1}},px=(e)=>process.platform==="win32"?[...(process.env.PATHEXT??".EXE;.CMD;.BAT").split(";").map((t)=>`${e}${t}`),e]:[e],_n=(e)=>{if(e.includes("/")||e.includes(lr.sep)){let r=lr.resolve(e);return Ap(r)?r:void 0}return[...(process.env.PATH??"").split(lr.delimiter).filter(Boolean),lr.join(lx(),".local","bin")].flatMap((r)=>px(lr.join(r,e))).find(Ap)},bn=(e)=>({OS_AUTH_TYPE:"v3token",OS_AUTH_URL:e.profile.authUrl,OS_IDENTITY_API_VERSION:"3",OS_INTERFACE:"public",OS_PROJECT_DOMAIN_ID:e.session.project.domainId??"",OS_PROJECT_ID:e.session.project.id,OS_PROJECT_NAME:e.session.project.name,OS_REGION_NAME:e.profile.region,OS_TOKEN:e.session.token}),Rp=(e,t)=>({...Object.fromEntries(Object.entries(e).filter(([r])=>!r.startsWith("OS_"))),...t}),vs=["bash","zsh","fish"],dx=(e)=>vs.some((t)=>t===e),jp=(e,t)=>`'${t==="fish"?e.replaceAll("\\","\\\\").replaceAll("'","\\'"):e.replaceAll("'","'\\''")}'`,Lp=(e,t)=>Object.entries(e).map(([r,n])=>t==="fish"?`set -gx ${r} ${jp(n,t)}`:`export ${r}=${jp(n,t)}`).join(`
|
|
90
|
-
`),Zp=(e)=>{let t=e?.split("/").at(-1)??"";return dx(t)?t:"bash"};import{chmod as hx,mkdir as Bp,readFile as Gp,rm as gx,writeFile as Vp}from"node:fs/promises";import{homedir as Wp}from"node:os";import ut from"node:path";class Ye extends Error{status;constructor(e,t){super(e);this.name="ApiError",this.status=t}}var mx=z({message:b()}),Dp=async(e)=>{try{let t=mx.safeParse(JSON.parse(await e.text()));return t.success?t.data.message:void 0}catch{return}},fx=async(e,t)=>{try{return t.safeParse(await e.json())}catch{return t.safeParse(null)}},Np=(e)=>{let t=e;while(t.endsWith("/"))t=t.slice(0,-1);return t},pr=(e)=>{let{origin:t,pathname:r}=new URL(e),n=Np(r);return n===""?`${t}/api`:`${t}${n}`},Up=async(e)=>{let t=await Oe(`${e}/v3/instances`,{headers:{Accept:"application/json"},signal:AbortSignal.timeout(1e4)}),r=await Dp(t);if(t.status!==401||r===void 0)throw new Ye(`${e} doesn't answer like the Space API (HTTP ${t.status})`,t.status)},Fp=(e)=>{let t=Np(e.url);return{get:async(r,n)=>{let o=await Oe(`${t}${r}`,{headers:{Accept:"application/json","Project-Id":e.projectId,Region:e.region,"X-Auth-Token":e.token}});if(!o.ok){let i=await Dp(o)??`the Space API returned HTTP ${o.status}`;throw new Ye(i,o.status)}if(!o.headers.get("Content-Type")?.includes("json"))throw new E(`${t} doesn't answer like the Space API`,{hint:"Check the profile's `spaceUrl` with `nipa profile ls --json`. It's the portal URL with /api, such as https://space.nipa.cloud/api."});let s=await fx(o,n);if(!s.success)throw new Ye(`unexpected Space API response: ${Ht(s.error)}`,o.status);return s.data}}};var re="prod",q={authUrl:"https://identity-api.nipa.cloud/v3",region:"NCP-TH",spaceUrl:"https://space.nipa.cloud/api",userDomain:"nipacloud"},Mp=og({protocol:/^https?$/u}),Be=z({authUrl:Mp,project:xs.optional(),region:b().min(1),spaceUrl:Mp.optional(),userDomain:b().min(1),username:b().optional()}),Ss=/^[a-z][\da-z-]{0,31}$/u,xx=hs(b().regex(Ss),Be),yx=(e)=>{let{spaceUrl:t,...r}=e;if(e.authUrl===q.authUrl)return{...r,spaceUrl:pr(t??q.spaceUrl)};if(t===void 0||t===q.spaceUrl)return r;return{...r,spaceUrl:pr(t)}},Ps=(e)=>({[re]:q,...Object.fromEntries(Object.entries(e).map(([t,r])=>[t,yx(r)]))}),_x=z({currentProfile:b().default(re),profiles:xx.default({})}).strict().transform((e)=>({...e,profiles:Ps(e.profiles)})),bx=Be.extend({authUrl:Be.shape.authUrl.default(q.authUrl),region:Be.shape.region.default(q.region),userDomain:Be.shape.userDomain.default(q.userDomain)}).transform((e)=>({currentProfile:re,profiles:Ps({[re]:e})})),wx=fs([_x,bx]),Kp=z({expiresAt:hn.datetime({offset:!0}),project:xs,token:b().min(1),user:z({id:b(),name:b()})}),vx=hs(b(),Kp),$x=fs([z({sessions:vx}).strict().transform((e)=>e.sessions),Kp.transform((e)=>({[re]:e}))]);class dr extends Error{constructor(e){super(e);this.name="StoreError"}}var Sx=60000,ks=(e=process.env)=>e.NIPA_CONFIG_DIR??ut.join(e.XDG_CONFIG_HOME??ut.join(Wp(),".config"),"nipa"),Jp=()=>ut.join(ks(),"config.json"),wn=()=>ut.join(ks(),"auth.json"),$s=(e,t=process.env)=>ut.join(t.XDG_CACHE_HOME??ut.join(Wp(),".cache"),"nipa",e),lt=async(e,t)=>{try{let r=await Gp($s(e),"utf-8"),n=t.safeParse(JSON.parse(r));return n.success?n.data:void 0}catch{return}},pt=async(e,t)=>{await Bp(ut.dirname($s(e)),{recursive:!0}),await Vp($s(e),`${JSON.stringify(t)}
|
|
91
|
-
`)},
|
|
92
|
-
`,{mode:384}),await
|
|
93
|
-
`)
|
|
94
|
-
`);return
|
|
89
|
+
Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`)}for(let i of e.seen.entries()){let a=i[1];if(t===i[0]){s(i);continue}if(e.external){let l=e.external.registry.get(i[0])?.id;if(t!==i[0]&&l){s(i);continue}}if(e.metadataRegistry.get(i[0])?.id){s(i);continue}if(a.cycle){s(i);continue}if(a.count>1){if(e.reused==="ref")s(i)}}if(e.external)e.sharedDefsExtractedFor=e.external}function Ad(e){let t=e.anyOf;if(!Array.isArray(t)||t.length===0||e.type!==void 0)return;let r=[];for(let n of t){if(!n||typeof n!=="object")return;Ad(n);let o=Object.keys(n);if(o.length!==1||o[0]!=="type")return;let s=n.type;for(let i of Array.isArray(s)?s:[s]){if(typeof i!=="string")return;if(!r.includes(i))r.push(i)}}delete e.anyOf,e.type=r.length===1?r[0]:r}var Td=new Set(["type","properties","required","additionalProperties"]),zd=["oneOf","anyOf"];function Id(e){let t=e.additionalProperties;if(t===void 0||t===!1||typeof t!=="object"||t===null)return null;return Object.keys(t).length?t:null}function _i(e){let t=[];for(let s of e){if(typeof s!=="object"||s.type!=="object")return null;for(let i in s)if(!Td.has(i))return null;t.push(s)}let r={},n=new Set;for(let s of t){for(let i in s.properties){if(Object.prototype.hasOwnProperty.call(r,i))continue;let a=[];for(let l of t){let u=l.properties?.[i]??Id(l);if(u===null||u===void 0)continue;if(!a.some((p)=>JSON.stringify(p)===JSON.stringify(u)))a.push(u)}let c=a.length===1?a[0]:_i(a)??{allOf:a};Ne(r,i,c)}for(let i of s.required??[])n.add(i)}let o={type:"object",properties:r};if(n.size)o.required=[...n];if(t.every((s)=>s.additionalProperties===!1))o.additionalProperties=!1;else{let s=[];for(let i of t){let a=Id(i);if(a&&!s.some((c)=>JSON.stringify(c)===JSON.stringify(a)))s.push(a)}if(s.length===1)o.additionalProperties=s[0];else if(s.length>1)o.additionalProperties={allOf:s}}return o}function $x(e){let t=e.allOf;if(!Array.isArray(t)||t.length<2)return;for(let o of Td)if(o in e)return;let r=t.filter((o)=>zd.some((s)=>Array.isArray(o[s]))),n=null;if(!r.length)n=_i(t);else{let o=r[0],s=zd.find((c)=>Array.isArray(o[c]));if(Object.keys(o).length!==1)return;let i=t.filter((c)=>c!==o),a=o[s].map((c)=>_i([...i,c]));if(a.some((c)=>!c))return;n={[s]:a}}if(!n)return;delete e.allOf,Nr(e,n)}function Si(e,t){let r=e.seen.get(t);if(!r)throw Error("Unprocessed schema. This is a bug in Zod.");let n=(a)=>{let c=e.seen.get(a);if(c.ref===null)return;let l=c.def??c.schema,u={...l},p=c.ref;if(c.ref=null,p){n(p);let f=e.seen.get(p),h=f.schema;if(h.$ref&&(e.target==="draft-07"||e.target==="draft-04"||e.target==="openapi-3.0"))l.allOf=l.allOf??[],l.allOf.push(h);else Nr(l,h);if(Nr(l,u),a._zod.parent===p)for(let b in l){if(b==="$ref"||b==="allOf")continue;if(!(b in u))delete l[b]}if(h.$ref&&f.def)for(let b in l){if(b==="$ref"||b==="allOf")continue;if(b in f.def&&JSON.stringify(l[b])===JSON.stringify(f.def[b]))delete l[b]}}let d=a._zod.parent;if(d&&d!==p){n(d);let f=e.seen.get(d);if(f?.schema.$ref){if(l.$ref=f.schema.$ref,f.def)for(let h in l){if(h==="$ref"||h==="allOf")continue;if(h in f.def&&JSON.stringify(l[h])===JSON.stringify(f.def[h]))delete l[h]}}}e.override({zodSchema:a,jsonSchema:l,path:c.path??[]})};if(!e.external||e.sharedEmitDoneFor!==e.external){for(let a of[...e.seen.entries()].reverse())n(a[0]);if(e.target!=="openapi-3.0")for(let a of e.seen.entries())Ad(a[1].def??a[1].schema);for(let a of e.deferred)a();if(e.intersections.length){let a=new Map;for(let c of e.seen.values())for(let l of[c.schema,c.def]){let u=l?.allOf;if(!Array.isArray(u))continue;let p=a.get(u);if(p)p.push(l);else a.set(u,[l])}for(let c of e.intersections)for(let l of a.get(c)??[])$x(l)}}let o={};if(e.target==="draft-2020-12")o.$schema="https://json-schema.org/draft/2020-12/schema";else if(e.target==="draft-07")o.$schema="http://json-schema.org/draft-07/schema#";else if(e.target==="draft-04")o.$schema="http://json-schema.org/draft-04/schema#";else if(e.target==="openapi-3.0");if(e.external?.uri){let a=e.external.registry.get(t)?.id;if(!a)throw Error("Schema is missing an `id` property");o.$id=e.external.uri(a)}Nr(o,r.defId?r.schema:r.def??r.schema);let s=e.metadataRegistry.get(t)?.id;if(s!==void 0&&o.id===s)delete o.id;let i=e.external?.defs??{};if(!e.external||e.sharedEmitDoneFor!==e.external)for(let a of e.seen.entries()){let c=a[1];if(c.def&&c.defId){if(c.def.id===c.defId)delete c.def.id;Ne(i,c.defId,c.def)}}if(e.external)e.sharedEmitDoneFor=e.external;if(e.external);else if(Object.keys(i).length>0)if(e.target==="draft-2020-12")o.$defs=i;else o.definitions=i;try{let a=JSON.parse(JSON.stringify(o));return Object.defineProperty(a,"~standard",{value:{...t["~standard"],jsonSchema:{input:Zr(t,"input",e.processors),output:Zr(t,"output",e.processors)}},enumerable:!1,writable:!1}),a}catch(a){throw Error("Error converting schema to JSON.")}}function he(e,t){let r=t??{seen:new Set};if(r.seen.has(e))return!1;r.seen.add(e);let n=e._zod.def;if(n.type==="transform")return!0;if(n.type==="array")return he(n.element,r);if(n.type==="set")return he(n.valueType,r);if(n.type==="lazy")return he(n.getter(),r);if(n.type==="promise"||n.type==="optional"||n.type==="nonoptional"||n.type==="nullable"||n.type==="readonly"||n.type==="default"||n.type==="prefault"||n.type==="catch")return he(n.innerType,r);if(n.type==="intersection")return he(n.left,r)||he(n.right,r);if(n.type==="record"||n.type==="map")return he(n.keyType,r)||he(n.valueType,r);if(n.type==="pipe"){if(e._zod.traits.has("$ZodCodec"))return!0;return he(n.in,r)||he(n.out,r)}if(n.type==="object"){for(let o in n.shape)if(he(n.shape[o],r))return!0;return!1}if(n.type==="union"){for(let o of n.options)if(he(o,r))return!0;return!1}if(n.type==="tuple"){for(let o of n.items)if(he(o,r))return!0;if(n.rest&&he(n.rest,r))return!0;return!1}return!1}var Rd=(e,t={})=>(r)=>{let n=vi({...r,processors:t});return se(e,n),$i(n,e),Si(n,e)},Zr=(e,t,r={})=>(n)=>{let{libraryOptions:o,target:s}=n??{},i=vi({...o??{},target:s,io:t,processors:r});return se(e,i),$i(i,e),Si(i,e)};var Qt=(e,t,r)=>{if(e[t]===void 0||r>e[t])e[t]=r},er=(e,t,r)=>{if(e[t]===void 0||r<e[t])e[t]=r},jd=(e,t)=>{Qt(e,"minimum",t),er(e,"maximum",t)},Nd=(e,t)=>{if(e.multipleOf??(e.multipleOf=[]),!e.multipleOf.includes(t))e.multipleOf.push(t)},Zd=(e,t)=>{e.patterns??(e.patterns=new Set),e.patterns.add(t)},Ud=(e,t)=>{e.mime=e.mime?e.mime.filter((r)=>t.includes(r)):[...t]},Fd=(e,t)=>{if(e.format=t,t.includes("int"))e.isInt=!0},Od=(e,t)=>Qt(e,"minimum",t.minimum),Ld=(e,t)=>er(e,"maximum",t.maximum),Dd=(e)=>(t,r)=>{Fd(t,r.format);let[n,o]=e[r.format];Qt(t,"minimum",n),er(t,"maximum",o)},Sx={greater_than:(e,t)=>Qt(e,t.inclusive?"minimum":"exclusiveMinimum",t.value),less_than:(e,t)=>er(e,t.inclusive?"maximum":"exclusiveMaximum",t.value),multiple_of:(e,t)=>Nd(e,t.value),number_format:Dd(Tn),bigint_format:Dd(Ns),min_length:Od,max_length:Ld,length_equals:(e,t)=>jd(e,t.length),min_size:Od,max_size:Ld,size_equals:(e,t)=>jd(e,t.size),string_format:(e,t)=>{if(Fd(e,t.format),t.pattern)Zd(e,t.pattern);if(t.format==="base64"||t.format==="base64url")e.contentEncoding=t.format;if(t.local||t.precision===-1)e.laxFormat=!0},mime_type:(e,t)=>Ud(e,t.mime)};function Ie(e){let t={},r=e._zod.def,n=e._zod.traits.has("$ZodCheck")?[e,...r.checks??[]]:r.checks??[];for(let s of n)Sx[s._zod.def.check]?.(t,s._zod.def);let o=e._zod.bag;if(o.minimum!==void 0)Qt(t,"minimum",o.minimum);if(o.exclusiveMinimum!==void 0)Qt(t,"exclusiveMinimum",o.exclusiveMinimum);if(o.maximum!==void 0)er(t,"maximum",o.maximum);if(o.exclusiveMaximum!==void 0)er(t,"exclusiveMaximum",o.exclusiveMaximum);if(o.multipleOf!==void 0)Nd(t,o.multipleOf);if(o.format!==void 0){if(t.format??(t.format=o.format),o.format.includes("int"))t.isInt=!0}if(o.mime)Ud(t,o.mime);for(let s of o.patterns??[])Zd(t,s);return t}var kx={guid:"uuid",url:"uri",datetime:"date-time",json_string:"json-string",regex:""},Px=new Map([[ri,du],[Wn,mu]]),Md=(e)=>Px.get(e)??e,Bd=(e,t,r,n)=>{let o=r;o.type="string";let{minimum:s,maximum:i,format:a,patterns:c,contentEncoding:l,laxFormat:u}=Ie(e);if(typeof s==="number")o.minLength=s;if(typeof i==="number")o.maxLength=i;if(a){if(o.format=kx[a]??a,o.format==="")delete o.format;if(a==="time"||u)delete o.format}if(l)o.contentEncoding=l;if(c&&c.size>0){let p=[...c].map(Md);if(p.length===1)o.pattern=p[0].source;else if(p.length>1)o.allOf=[...p.map((d)=>({...t.target==="draft-07"||t.target==="draft-04"||t.target==="openapi-3.0"?{type:"string"}:{},pattern:d.source}))]}},Gd=(e,t,r,n)=>{let o=r,{minimum:s,maximum:i,multipleOf:a,exclusiveMaximum:c,exclusiveMinimum:l,isInt:u}=Ie(e);o.type=u?"integer":"number";let p=typeof l==="number"&&l>=(s??Number.NEGATIVE_INFINITY),d=typeof c==="number"&&c<=(i??Number.POSITIVE_INFINITY),f=t.target==="draft-04"||t.target==="openapi-3.0";if(p)if(f)o.minimum=l,o.exclusiveMinimum=!0;else o.exclusiveMinimum=l;else if(typeof s==="number")o.minimum=s;if(d)if(f)o.maximum=c,o.exclusiveMaximum=!0;else o.exclusiveMaximum=c;else if(typeof i==="number")o.maximum=i;if(a){let h=new Set;for(let _ of a)if(Number.isFinite(_)&&_!==0)h.add(Math.abs(_));else Rt(e,t,o,n,`A multipleOf divisor of ${_} cannot be represented in JSON Schema`);let[y,...b]=h;if(y!==void 0)o.multipleOf=y;if(b.length)o.allOf=[...o.allOf??[],...b.map((_)=>({multipleOf:_}))]}},Kd=(e,t,r,n)=>{r.type="boolean"};var Vd=(e,t,r,n)=>{r.not={}};var Wd=(e,t,r,n)=>{};var Hd=(e,t,r,n)=>{let o=e._zod.def,s=zr(o.entries);if(s.length===0){r.not={};return}if(s.every((i)=>typeof i==="number"))r.type="number";if(s.every((i)=>typeof i==="string"))r.type="string";r.enum=s};var Jd=(e,t,r,n)=>{Rt(e,t,r,n,"Custom types cannot be represented in JSON Schema")};var qd=(e,t,r,n)=>{Rt(e,t,r,n,"Transforms cannot be represented in JSON Schema")};var Yd=(e,t,r,n)=>{let o=r,s=e._zod.def,{minimum:i,maximum:a}=Ie(e);if(typeof i==="number")o.minItems=i;if(typeof a==="number")o.maxItems=a;o.type="array",o.items=se(s.element,t,{...n,path:[...n.path,"items"]})};function ao(e){let t=e._zod.def;if(t.type==="pipe"&&t.in._zod.traits.has("$ZodTransform"))return ao(t.out);if(t.type==="catch")return ao(t.innerType);return e._zod.optin}var Xd=(e,t,r,n)=>{let o=r,s=e._zod.def,i=s.shape;if(Object.getOwnPropertySymbols(i).length&&Rt(e,t,o,n,"Symbol keys cannot be represented in JSON Schema"))return;o.type="object",o.properties={};for(let l in i)Ne(o.properties,l,se(i[l],t,{...n,path:[...n.path,"properties",l]}));let c=[];for(let l of Object.keys(i)){let u=s.shape[l];if(t.io==="input"?ao(u)===void 0:u._zod.optout===void 0)c.push(l)}if(c.length>0)o.required=c;if(s.catchall?._zod.def.type==="never")o.additionalProperties=!1;else if(!s.catchall){if(t.io==="output")o.additionalProperties=!1}else if(s.catchall)o.additionalProperties=se(s.catchall,t,{...n,path:[...n.path,"additionalProperties"]})},Qd=(e,t,r,n)=>{let o=e._zod.def,s=o.inclusive===!1,i=o.options.map((a,c)=>se(a,t,{...n,path:[...n.path,s?"oneOf":"anyOf",c]}));if(s)r.oneOf=i;else r.anyOf=i},em=(e,t,r,n)=>{let o=e._zod.def,s=se(o.left,t,{...n,path:[...n.path,"allOf",0]}),i=se(o.right,t,{...n,path:[...n.path,"allOf",1]}),a=(l)=>("allOf"in l)&&Object.keys(l).length===1,c=[...a(s)?s.allOf:[s],...a(i)?i.allOf:[i]];r.allOf=c,t.intersections.push(c)};function ki(e,t,r){if(t.$ref){if(r.has(t))return t;r.add(t);let h=e.get(t)?.def;if(!h)return t;let y=ki(e,h,r);return y===h?t:y}for(let h of["anyOf","oneOf"]){let y=t[h];if(!Array.isArray(y))continue;let b=y.map((_)=>ki(e,_,r));if(b.some((_,P)=>_!==y[P]))t={...t,[h]:b}}let n=Array.isArray(t.type)?t.type:[t.type],o=!n.includes("string")&&n.some((h)=>h==="number"||h==="integer"),s=t.enum??(t.const!==void 0?[t.const]:void 0);if(!o&&!s?.some((h)=>typeof h==="number"))return t;let{minimum:i,maximum:a,exclusiveMinimum:c,exclusiveMaximum:l,multipleOf:u,format:p,id:d,...f}=t;if(f.enum)f.enum=f.enum.map((h)=>typeof h==="number"?String(h):h);else if(typeof f.const==="number")f.const=String(f.const);if(!o)return f;if(f.type="string",!s)f.pattern=(n.includes("number")?Tr:Js).source;return f}var Pi=new WeakMap;function Cx(e){let t=new Map;for(let n of e.seen.values())if(n.def&&!t.has(n.schema))t.set(n.schema,n);let r=new Map;for(let n of Pi.get(e)??[]){let o=e.seen.get(n),s=(o?.def??o?.schema)?.propertyNames;if(!s||s===!0||r.has(s))continue;let i=ki(t,s,new Set);if(i!==s)r.set(s,i)}if(!r.size)return;for(let n of e.seen.values())for(let o of[n.schema,n.def]){let s=o&&r.get(o.propertyNames);if(s)o.propertyNames=s}}var tm=(e,t,r,n)=>{let o=r,s=e._zod.def;o.type="object";let i=s.keyType,a=Ie(i).patterns;if(s.mode==="loose"&&a&&a.size>0){let u=se(s.valueType,t,{...n,path:[...n.path,"patternProperties","*"]});o.patternProperties={};for(let p of a)Ne(o.patternProperties,Md(p).source,u)}else{if(t.target==="draft-07"||t.target==="draft-2020-12"){o.propertyNames=se(s.keyType,t,{...n,path:[...n.path,"propertyNames"]});let u=Pi.get(t);if(!u)u=[],Pi.set(t,u),t.deferred.push(()=>Cx(t));u.push(e)}o.additionalProperties=se(s.valueType,t,{...n,path:[...n.path,"additionalProperties"]})}let c=i._zod.values,l=t.io==="input"&&ao(s.valueType)!==void 0;if(c&&!s.partial&&!l){let u=[...c].filter((p)=>typeof p==="string"||typeof p==="number");if(u.length>0)o.required=u.map(String)}},rm=(e,t,r,n)=>{let o=e._zod.def,s=se(o.innerType,t,n),i=t.seen.get(e);if(t.target==="openapi-3.0")i.ref=o.innerType,r.nullable=!0;else r.anyOf=[s,{type:"null"}]},nm=(e,t,r,n)=>{let o=e._zod.def;se(o.innerType,t,n);let s=t.seen.get(e);s.ref=o.innerType},Ci=Symbol();function om(e,t,r,n,o){let s=!1,i=JSON.stringify(e,(a,c)=>{if(typeof c!=="bigint")return c;return s=!0,null});if(!s)return JSON.parse(i);return Rt(t,r,n,o,"BigInt defaults cannot be represented in JSON Schema"),Ci}var sm=(e,t,r,n)=>{let o=e._zod.def;se(o.innerType,t,n);let s=t.seen.get(e);s.ref=o.innerType;let i=om(o.defaultValue,e,t,r,n);if(i!==Ci)r.default=i},im=(e,t,r,n)=>{let o=e._zod.def;se(o.innerType,t,n);let s=t.seen.get(e);if(s.ref=o.innerType,t.io!=="input")return;let i=om(o.defaultValue,e,t,r,n);if(i!==Ci)r._prefault=i},am=(e,t,r,n)=>{let o=e._zod.def;se(o.innerType,t,n);let s=t.seen.get(e);s.ref=o.innerType;let i;try{i=o.catchValue(void 0)}catch{Rt(e,t,r,n,"Dynamic catch values are not supported in JSON Schema");return}r.default=i},cm=(e,t,r,n)=>{let o=e._zod.def,s=o.in._zod.traits.has("$ZodTransform"),i=t.io==="input"?s?o.out:o.in:o.out;se(i,t,n);let a=t.seen.get(e);a.ref=i},lm=(e,t,r,n)=>{let o=e._zod.def;se(o.innerType,t,n);let s=t.seen.get(e);s.ref=o.innerType,r.readOnly=!0};var Ei=(e,t,r,n)=>{let o=e._zod.def;se(o.innerType,t,n);let s=t.seen.get(e);s.ref=o.innerType};var um=new WeakSet([Object.prototype,Error.prototype]);function co(e,t,r){Object.defineProperty(e,t,{configurable:!0,enumerable:!1,get(){let n=r(this);return Object.defineProperty(this,t,{value:n,configurable:!0,writable:!0}),n},set(n){Object.defineProperty(this,t,{value:n,configurable:!0,writable:!0})}})}var Lx=(e,t)=>{Fl.init(e,t),e.name="ZodError";let r=Object.getPrototypeOf(e);if(um.has(r))return;um.add(r),co(r,"format",(n)=>(o)=>Gs(n,o)),co(r,"flatten",(n)=>(o)=>Bs(n,o)),co(r,"addIssue",(n)=>(o)=>{n.issues.push(o),n.message=JSON.stringify(n.issues,Ir,2)}),co(r,"addIssues",(n)=>(o)=>{n.issues.push(...o),n.message=JSON.stringify(n.issues,Ir,2)}),Object.defineProperty(r,"isEmpty",{configurable:!0,enumerable:!1,get(){return this.issues.length===0}})};var Ee=g("ZodError",Lx,void 0,{Parent:Error});var pm=Nn(Ee),dm=Zn(Ee),mm=Un(Ee),fm=Fn(Ee),hm=Bl(Ee),gm=Gl(Ee),ym=Kl(Ee),bm=Vl(Ee),xm=Wl(Ee),wm=Hl(Ee),_m=Jl(Ee),vm=ql(Ee);function Nx(){if(!we.localeError)_e(ci())}function uo(){if(!we.memoizer)_e({memoizer:ai()})}var re=g("ZodType",(e,t)=>(Nx(),q.init(e,t),e.def=t,e.type=t.type,e),{check(...e){let t=this.def;return this.clone(Ce(t,{checks:[...t.checks??[],...e.map((r)=>typeof r==="function"?{_zod:{check:r,def:{check:"custom"},onattach:[]}}:r)]}),{parent:!0})},with(...e){return this.check(...e)},clone(e,t){return Ze(this,e,t)},brand(){return this},register(e,t){return e.add(this,t),this},refine(e,t){return this.check(Iw(e,t))},superRefine(e,t){return this.check(Aw(e,t))},overwrite(e){return this.check(bt(e))},optional(){return Sm(this)},exactOptional(){return yw(this)},nullable(){return km(this)},nullish(){return Sm(km(this))},nonoptional(e){return $w(this,e)},array(){return j(this)},or(e){return Ti([this,e])},and(e){return mw(this,e)},transform(e){return Pm(this,gw(e))},default(e){return ww(this,e)},prefault(e){return vw(this,e)},catch(e){return kw(this,e)},pipe(e){return Pm(this,e)},readonly(){return Ew(this)},describe(e){let t=this.clone();return yt.add(t,{description:e}),t},meta(...e){if(e.length===0)return yt.get(this);let t=this.clone();return yt.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 Ln(this,"~standard",{...ti(this),jsonSchema:{input:Zr(this,"input"),output:Zr(this,"output")}})},set "~standard"(e){st(this,"~standard",e)},parse:function e(t,r){return pm(this,t,r,{callee:e})},parseAsync:async function e(t,r){return await dm(this,t,r,{callee:e})},safeParse(e,t){return mm(this,e,t)},async safeParseAsync(e,t){return fm(this,e,t)},get spa(){return this?.safeParseAsync},set spa(e){st(this,"spa",e)},validate(e,t){return Ks(this,e,t)},validateAsync(e,t){return Vs(this,e,t)},encode:function e(t,r){return hm(this,t,r,{callee:e})},decode:function e(t,r){return gm(this,t,r,{callee:e})},encodeAsync:async function e(t,r){return await ym(this,t,r,{callee:e})},decodeAsync:async function e(t,r){return await bm(this,t,r,{callee:e})},safeEncode(e,t){return xm(this,e,t)},safeDecode(e,t){return wm(this,e,t)},async safeEncodeAsync(e,t){return _m(this,e,t)},async safeDecodeAsync(e,t){return vm(this,e,t)},toJSONSchema(e){return Rd(this,{})(e)},get description(){return yt.get(this)?.description},get _def(){return this._zod.def}}),Cm=g("_ZodString",(e,t)=>{Vn.init(e,t),re.init(e,t),e._zod.processJSONSchema=(r,n,o)=>Bd(e,r,n,o)},Ol({format:(e)=>Ie(e).format??null,minLength:(e)=>Ie(e).minimum??null,maxLength:(e)=>Ie(e).maximum??null},{regex(...e){return this.check(ui(...e))},includes(...e){return this.check(mi(...e))},startsWith(...e){return this.check(fi(...e))},endsWith(...e){return this.check(hi(...e))},min(...e){return this.check(Xt(...e))},max(...e){return this.check(so(...e))},length(...e){return this.check(io(...e))},nonempty(...e){return this.check(Xt(1,...e))},lowercase(e){return this.check(pi(e))},uppercase(e){return this.check(di(e))},trim(){return this.check(yi())},normalize(...e){return this.check(gi(...e))},toLowerCase(){return this.check(bi())},toUpperCase(){return this.check(xi())},slugify(){return this.check(wi())}})),Zx=g("ZodString",(e,t)=>{Vn.init(e,t),Cm.init(e,t)},{email(e){return this.check(Qp(Ux,e))},url(e){return this.check(li(Em,e))},jwt(e){return this.check(xd(nw,e))},emoji(e){return this.check(sd(Bx,e))},guid(e){return this.check(ed(Fx,e))},uuid(e){return this.check(td(lo,e))},uuidv4(e){return this.check(rd(lo,e))},uuidv6(e){return this.check(nd(lo,e))},uuidv7(e){return this.check(od(lo,e))},nanoid(e){return this.check(id(Gx,e))},cuid(e){return this.check(ad(Kx,e))},cuid2(e){return this.check(cd(Vx,e))},ulid(e){return this.check(ld(Wx,e))},base64(e){return this.check(gd(ew,e))},base64url(e){return this.check(yd(tw,e))},xid(e){return this.check(ud(Hx,e))},ksuid(e){return this.check(pd(Jx,e))},ipv4(e){return this.check(dd(qx,e))},ipv6(e){return this.check(md(Yx,e))},cidrv4(e){return this.check(fd(Xx,e))},cidrv6(e){return this.check(hd(Qx,e))},e164(e){return this.check(bd(rw,e))},datetime(e){return this.check(Xn(Fr,e))},date(e){return this.check(Qn(Mr,e))},time(e){return this.check(eo(Br,e))},duration(e){return this.check(to(Gr,e))}});function m(e){return Xp(Zx,e)}var Y=g("ZodStringFormat",(e,t)=>{W.init(e,t),Cm.init(e,t)}),Fr=g("ZodISODateTime",(e,t)=>{cp.init(e,t),Y.init(e,t)}),Mr=g("ZodISODate",(e,t)=>{lp.init(e,t),Y.init(e,t)}),Br=g("ZodISOTime",(e,t)=>{up.init(e,t),Y.init(e,t)}),Gr=g("ZodISODuration",(e,t)=>{pp.init(e,t),Y.init(e,t)}),Ux=g("ZodEmail",(e,t)=>{Yu.init(e,t),Y.init(e,t)});var Fx=g("ZodGUID",(e,t)=>{Ju.init(e,t),Y.init(e,t)});var lo=g("ZodUUID",(e,t)=>{qu.init(e,t),Y.init(e,t)});var Em=g("ZodURL",(e,t)=>{ep.init(e,t),Y.init(e,t)});function Mx(e){return li(Em,e)}var Bx=g("ZodEmoji",(e,t)=>{tp.init(e,t),Y.init(e,t)});var Gx=g("ZodNanoID",(e,t)=>{rp.init(e,t),Y.init(e,t)});var Kx=g("ZodCUID",(e,t)=>{np.init(e,t),Y.init(e,t)});var Vx=g("ZodCUID2",(e,t)=>{op.init(e,t),Y.init(e,t)});var Wx=g("ZodULID",(e,t)=>{sp.init(e,t),Y.init(e,t)});var Hx=g("ZodXID",(e,t)=>{ip.init(e,t),Y.init(e,t)});var Jx=g("ZodKSUID",(e,t)=>{ap.init(e,t),Y.init(e,t)});var qx=g("ZodIPv4",(e,t)=>{dp.init(e,t),Y.init(e,t)});var Yx=g("ZodIPv6",(e,t)=>{fp.init(e,t),Y.init(e,t)});var Xx=g("ZodCIDRv4",(e,t)=>{hp.init(e,t),Y.init(e,t)});var Qx=g("ZodCIDRv6",(e,t)=>{gp.init(e,t),Y.init(e,t)});var ew=g("ZodBase64",(e,t)=>{bp.init(e,t),Y.init(e,t)});var tw=g("ZodBase64URL",(e,t)=>{xp.init(e,t),Y.init(e,t)});var rw=g("ZodE164",(e,t)=>{wp.init(e,t),Y.init(e,t)});var nw=g("ZodJWT",(e,t)=>{_p.init(e,t),Y.init(e,t)});var zm=g("ZodNumber",(e,t)=>{ni.init(e,t),re.init(e,t),e._zod.processJSONSchema=(r,n,o)=>Gd(e,r,n,o),e.isFinite=!0},Ol({minValue:(e)=>{let{minimum:t,exclusiveMinimum:r}=Ie(e);return Math.max(t??Number.NEGATIVE_INFINITY,r??Number.NEGATIVE_INFINITY)},maxValue:(e)=>{let{maximum:t,exclusiveMaximum:r}=Ie(e);return Math.min(t??Number.POSITIVE_INFINITY,r??Number.POSITIVE_INFINITY)},isInt:(e)=>{let{isInt:t,multipleOf:r}=Ie(e);return!!t||!!r?.some(Number.isSafeInteger)},format:(e)=>Ie(e).format??null},{gt(e,t){return this.check(no(e,t))},gte(e,t){return this.check(Dr(e,t))},min(e,t){return this.check(Dr(e,t))},lt(e,t){return this.check(ro(e,t))},lte(e,t){return this.check(Lr(e,t))},max(e,t){return this.check(Lr(e,t))},int(e){return this.check($m(e))},safe(e){return this.check($m(e))},positive(e){return this.check(no(0,e))},nonnegative(e){return this.check(Dr(0,e))},negative(e){return this.check(ro(0,e))},nonpositive(e){return this.check(Lr(0,e))},multipleOf(e,t){return this.check(oo(e,t))},step(e,t){return this.check(oo(e,t))},finite(){return this}}));function X(e){return wd(zm,e)}var ow=g("ZodNumberFormat",(e,t)=>{vp.init(e,t),zm.init(e,t)});function $m(e){return _d(ow,e)}var sw=g("ZodBoolean",(e,t)=>{$p.init(e,t),re.init(e,t),e._zod.processJSONSchema=(r,n,o)=>Kd(e,r,n,o)});function tr(e){return vd(sw,e)}var iw=g("ZodUnknown",(e,t)=>{Sp.init(e,t),re.init(e,t),e._zod.processJSONSchema=(r,n,o)=>Wd(e,r,n,o)});function zi(){return $d(iw)}var aw=g("ZodNever",(e,t)=>{kp.init(e,t),re.init(e,t),e._zod.processJSONSchema=(r,n,o)=>Vd(e,r,n,o)});function cw(e){return Sd(aw,e)}var lw=g("ZodArray",(e,t)=>{uo(),Pp.init(e,t),re.init(e,t),e._zod.processJSONSchema=(r,n,o)=>Yd(e,r,n,o),e.element=t.element},{min(e,t){return this.check(Xt(e,t))},nonempty(e){return this.check(Xt(1,e))},max(e,t){return this.check(so(e,t))},length(e,t){return this.check(io(e,t))},unwrap(){return this.element}});function j(e,t){return kd(lw,e,t)}var uw=g("ZodObject",(e,t)=>{uo(),zp.init(e,t),re.init(e,t),e._zod.processJSONSchema=(r,n,o)=>Xd(e,r,n,o),Vb(e,"shape",(r)=>r._zod.def.shape,!1)},{keyof(){return Im(Object.keys(this._zod.def.shape))},catchall(e){return this.clone(Ce(this._zod.def,{catchall:e}))},passthrough(){return this.clone(Ce(this._zod.def,{catchall:zi()}))},loose(){return this.clone(Ce(this._zod.def,{catchall:zi()}))},strict(){return this.clone(Ce(this._zod.def,{catchall:cw()}))},strip(){return this.clone(Ce(this._zod.def,{catchall:void 0}))},extend(e){return Nb(this,e)},safeExtend(e){return Zb(this,e)},merge(e){return Ub(this,e)},pick(e){return Lb(this,e)},omit(e){return Db(this,e)},partial(...e){return Al(Am,this,e[0])},exactPartial(...e){return Al(Tm,this,e[0],"exactPartial")},required(...e){return Fb(Rm,this,e[0])}});function v(e,t){let r={type:"object",shape:e??{},...C(t)};return new uw(r)}var pw=g("ZodUnion",(e,t)=>{Ip.init(e,t),re.init(e,t),e._zod.processJSONSchema=(r,n,o)=>Qd(e,r,n,o),e.options=t.options});function Ti(e,t){return new pw({type:"union",options:e,...C(t)})}var dw=g("ZodIntersection",(e,t)=>{Ap.init(e,t),re.init(e,t),e._zod.processJSONSchema=(r,n,o)=>em(e,r,n,o)});function mw(e,t){return new dw({type:"intersection",left:e,right:t})}var Ii=g("ZodRecord",(e,t)=>{uo(),Tp.init(e,t),re.init(e,t),e._zod.processJSONSchema=(r,n,o)=>tm(e,r,n,o),e.keyType=t.keyType,e.valueType=t.valueType});function Kr(e,t,r){if(!t||!t._zod)return new Ii({type:"record",keyType:m(),valueType:e,...C(t)});return new Ii({type:"record",keyType:e,valueType:t,...C(r)})}function fw(e,t,r){return new Ii({type:"record",keyType:e,valueType:t,...C(r),partial:!0})}var Ai=g("ZodEnum",(e,t)=>{Rp.init(e,t),re.init(e,t),e._zod.processJSONSchema=(n,o,s)=>Hd(e,n,o,s),e.enum=t.entries,e.options=[...e._zod.values];let r=new Set(Object.keys(t.entries));e.extract=(n,o)=>{let s={};for(let i of n)if(r.has(i))s[i]=t.entries[i];else throw Error(`Key ${i} not found in enum`);return new Ai({...t,checks:[],...C(o),entries:s})},e.exclude=(n,o)=>{let s={...t.entries};for(let i of n)if(r.has(i))delete s[i];else throw Error(`Key ${i} not found in enum`);return new Ai({...t,checks:[],...C(o),entries:s})}});function Im(e,t){let r=Array.isArray(e)?Object.fromEntries(e.map((n)=>[n,n])):e;return new Ai({type:"enum",entries:r,...C(t)})}var hw=g("ZodTransform",(e,t)=>{uo(),jp.init(e,t),re.init(e,t),e._zod.processJSONSchema=(r,n,o)=>qd(e,r,n,o),e._zod.parse=(r,n)=>{if(n.direction==="backward")throw new Ar(e.constructor.name);r.addIssue=(s)=>{if(typeof s==="string")r.issues.push(Tt(s,r.value,t));else{let i=s;if(i.fatal)i.continue=!1;if(i.code??(i.code="custom"),!("input"in i))i.input=r.value;i.inst??(i.inst=e),r.issues.push(Tt(i))}};let o=t.transform(r.value,r);if(o instanceof Promise)return o.then((s)=>(r.value=s,r));return r.value=o,r}});function gw(e){return new hw({type:"transform",transform:e})}var Am=g("ZodOptional",(e,t)=>{oi.init(e,t),re.init(e,t),e._zod.processJSONSchema=(r,n,o)=>Ei(e,r,n,o),e.unwrap=()=>e._zod.def.innerType});function Sm(e){return new Am({type:"optional",innerType:e})}var Tm=g("ZodExactOptional",(e,t)=>{Op.init(e,t),re.init(e,t),e._zod.processJSONSchema=(r,n,o)=>Ei(e,r,n,o),e.unwrap=()=>e._zod.def.innerType});function yw(e){return new Tm({type:"optional",innerType:e})}var bw=g("ZodNullable",(e,t)=>{Lp.init(e,t),re.init(e,t),e._zod.processJSONSchema=(r,n,o)=>rm(e,r,n,o),e.unwrap=()=>e._zod.def.innerType});function km(e){return new bw({type:"nullable",innerType:e})}var xw=g("ZodDefault",(e,t)=>{Dp.init(e,t),re.init(e,t),e._zod.processJSONSchema=(r,n,o)=>sm(e,r,n,o),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap});function ww(e,t){return new xw({type:"default",innerType:e,get defaultValue(){return typeof t==="function"?t():Ls(t)}})}var _w=g("ZodPrefault",(e,t)=>{Np.init(e,t),re.init(e,t),e._zod.processJSONSchema=(r,n,o)=>im(e,r,n,o),e.unwrap=()=>e._zod.def.innerType});function vw(e,t){return new _w({type:"prefault",innerType:e,get defaultValue(){return typeof t==="function"?t():Ls(t)}})}var Rm=g("ZodNonOptional",(e,t)=>{Zp.init(e,t),re.init(e,t),e._zod.processJSONSchema=(r,n,o)=>nm(e,r,n,o),e.unwrap=()=>e._zod.def.innerType});function $w(e,t){return new Rm({type:"nonoptional",innerType:e,...C(t)})}var Sw=g("ZodCatch",(e,t)=>{Up.init(e,t),re.init(e,t),e._zod.processJSONSchema=(r,n,o)=>am(e,r,n,o),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap});function kw(e,t){return new Sw({type:"catch",innerType:e,catchValue:typeof t==="function"?t:Ll(t)})}var Pw=g("ZodPipe",(e,t)=>{Fp.init(e,t),re.init(e,t),e._zod.processJSONSchema=(r,n,o)=>cm(e,r,n,o),e.in=t.in,e.out=t.out});function Pm(e,t){return new Pw({type:"pipe",in:e,out:t})}var Cw=g("ZodReadonly",(e,t)=>{Mp.init(e,t),re.init(e,t),e._zod.processJSONSchema=(r,n,o)=>lm(e,r,n,o),e.unwrap=()=>e._zod.def.innerType});function Ew(e){return new Cw({type:"readonly",innerType:e})}var zw=g("ZodCustom",(e,t)=>{Bp.init(e,t),re.init(e,t),e._zod.processJSONSchema=(r,n,o)=>Jd(e,r,n,o)});function Iw(e,t={}){return Pd(zw,e,t)}function Aw(e,t){return Cd(e,t)}var po={};vy(po,{ZodISODate:()=>Mr,ZodISODateTime:()=>Fr,ZodISODuration:()=>Gr,ZodISOTime:()=>Br,date:()=>Rw,datetime:()=>Tw,duration:()=>Ow,time:()=>jw});function Tw(e){return Xn(Fr,e)}function Rw(e){return Qn(Mr,e)}function jw(e){return eo(Br,e)}function Ow(e){return to(Gr,e)}var jm=Mt(dr(),1);var Ri=()=>process.env.NIPA_DEBUG==="1",rr=(e)=>{if(Ri())oe(jm.default.dim(`> [debug] [${new Date().toISOString()}] ${e}`))};class it extends Error{url;constructor(e,t){super(`can't reach ${new URL(e).host}: ${t}`);this.name="NetworkError",this.url=e}}var Om=(e)=>e.cause instanceof Error?`${e.message} (${Om(e.cause)})`:e.message,Ve=async(e,t={})=>{let r=t.method??"GET",n=performance.now();rr(`${r} ${e}`);let o;try{o=await fetch(e,t)}catch(s){throw new it(e,s instanceof Error?Om(s):String(s))}return rr(`${o.status} ${r} ${e} [${R(performance.now()-n)}]`),o};var Vr=v({domainId:m().optional(),id:m(),name:m()});class ae extends Error{status;constructor(e,t){super(e);this.name="KeystoneError",this.status=t}}var mo=(e)=>{let t=e;while(t.endsWith("/"))t=t.slice(0,-1);if(t.endsWith("/v3"))t=t.slice(0,-3);return`${t}/v3`},ji=(e,t)=>t?{auth:{identity:e,scope:{project:{id:t}}}}:{auth:{identity:e}},Dm=(e)=>({domain:{name:e.userDomain},name:e.username}),Lw=(e,t)=>ji({methods:["password"],password:{user:{...Dm(e),password:t}}},e.projectId),Dw=(e,t)=>ji({methods:["totp"],totp:{user:{...Dm(e),passcode:t}}},e.projectId),Nw=(e,t)=>ji({methods:["token"],token:{id:e}},t),Zw=v({error:v({message:m().optional()}).optional(),receipt:v({}).loose().optional(),required_auth_methods:j(j(m())).optional()}),Nm=async(e)=>{try{let t=Zw.safeParse(JSON.parse(await e.text()));return t.success?t.data:{}}catch{return{}}},Zm=(e)=>e.length>0?`this account needs ${e.map((t)=>t.join(" + ")).join(" or ")} to log in`:"this account's MFA rules don't allow this login method",Uw=(e)=>{let{body:t,status:r}=e;if(t.receipt)return Zm(t.required_auth_methods??[]);if(r===401)return e.unauthorized;return t.error?.message??`Keystone returned HTTP ${r}`},Wr=async(e,t)=>{let r=await Nm(e);throw new ae(Uw({body:r,status:e.status,unauthorized:t}),e.status)},Fw=v({token:v({expires_at:m(),project:v({domain:v({id:m()}).optional(),id:m(),name:m()}).optional(),user:v({id:m(),name:m()})})}),Mw=(e,t)=>{let{expires_at:r,project:n,user:o}=t.token;return{expiresAt:r,project:n&&{domainId:n.domain?.id,id:n.id,name:n.name},user:o,value:e}},Um="Openstack-Auth-Receipt",Oi=(e,t,r)=>{let n=new Headers({"Content-Type":"application/json"});if(r!==void 0)n.set(Um,r);return Ve(`${mo(e)}/auth/tokens`,{body:JSON.stringify(t),headers:n,method:"POST"})},Li=async(e)=>{let t=e.headers.get("X-Subject-Token");if(!t)throw new ae("Keystone didn't return a token",e.status);let r=Fw.safeParse(await e.json());if(!r.success)throw new ae(`unexpected token response: ${qt(r.error)}`,e.status);return Mw(t,r.data)},Fm=async(e,t)=>{let r=await Oi(e.authUrl,Lw(e,t));if(r.ok)return{kind:"token",token:await Li(r)};let n=r.headers.get(Um);if(r.status===401&&n){let s=(await Nm(r)).required_auth_methods;if(!s||s.some((i)=>i.includes("totp")))return{kind:"mfa",receipt:n};throw new ae(Zm(s),r.status)}return Wr(r,"wrong email or password")},Mm=async(e)=>{let{account:t,passcode:r,receipt:n}=e,o=await Oi(t.authUrl,Dw(t,r),n);return o.ok?Li(o):Wr(o,"wrong OTP code")},Di="the session expired or was revoked",Hr=async(e)=>{let t=await Oi(e.authUrl,Nw(e.token,e.projectId));return t.ok?Li(t):Wr(t,Di)},Bw=v({projects:j(v({domain_id:m().optional(),enabled:tr().optional(),id:m(),name:m()}))}),Gw=(e)=>e.projects.filter((t)=>t.enabled!==!1).map((t)=>({domainId:t.domain_id,id:t.id,name:t.name})).toSorted((t,r)=>t.name.localeCompare(r.name)),Ue=async({authUrl:e,signal:t,token:r})=>{let n=await Ve(`${mo(e)}/auth/projects`,{headers:{"X-Auth-Token":r},signal:t});if(!n.ok)return Wr(n,Di);let o=Bw.safeParse(await n.json());if(!o.success)throw new ae(`unexpected project list: ${qt(o.error)}`,n.status);return Gw(o.data)},fo=async({authUrl:e,token:t})=>{let r=await Ve(`${mo(e)}/auth/tokens`,{headers:{"X-Auth-Token":t,"X-Subject-Token":t},method:"DELETE"});if(!(r.ok||r.status===401||r.status===404))await Wr(r,Di)},Lm=v({version:v({id:m(),status:m()})}),ho=async(e)=>{let t=mo(e),r=await Ve(t,{signal:AbortSignal.timeout(1e4)}),n;try{n=Lm.safeParse(await r.json())}catch{n=Lm.safeParse(null)}if(!(r.ok&&n.success))throw new ae(`${t} doesn't answer like Keystone v3 (HTTP ${r.status})`,r.status);return n.data.version.id};import{setTimeout as Hw}from"node:timers/promises";class ge extends Error{status;constructor(e,t){super(e);this.name="ApiError",this.status=t}}var Kw=v({message:m()}),Gm=async(e)=>{try{let t=Kw.safeParse(JSON.parse(await e.text()));return t.success?t.data.message:void 0}catch{return}},Vw=(e,t)=>{try{return t.safeParse(JSON.parse(e))}catch{return t.safeParse(null)}},Bm=(e,t,r)=>{let n=Vw(e,t);if(!n.success)throw new ge(`unexpected Space API response: ${qt(n.error)}`,r);return n.data},Ni=(e)=>{let t=e;while(t.endsWith("/"))t=t.slice(0,-1);return t},Jr=(e)=>{let{origin:t,pathname:r}=new URL(e),n=Ni(r);return n===""?`${t}/api`:`${t}${n}`},Km=(e)=>{let{origin:t,pathname:r}=new URL(e),n=Ni(r);return n.endsWith("/api")?`${t}${n.slice(0,-4)}`:t},go=async(e)=>{let t=await Ve(`${e}/v3/instances`,{headers:{Accept:"application/json"},signal:AbortSignal.timeout(1e4)}),r=await Gm(t);if(t.status!==401||r===void 0)throw new ge(`${e} doesn't answer like the Space API (HTTP ${t.status})`,t.status)},Ww=/(?:Z|[+-]\d{2}:?\d{2})$/iu,xt=(e)=>Ww.test(e)?e:`${e}Z`,yo=(e)=>{let t=Ni(e.url),r=async(o,s)=>{let i=await Ve(`${t}${o}`,{headers:{Accept:"application/json","Project-Id":e.projectId,Region:e.region,"X-Auth-Token":e.token},method:s,signal:e.signal});if(!i.ok){let a=await Gm(i)??`the Space API returned HTTP ${i.status}`;throw new ge(a,i.status)}return i},n=async(o)=>{let s=await r(o,"GET");if(!s.headers.get("Content-Type")?.includes("json"))throw new E(`${t} doesn't answer like the Space API`,{hint:"Check the profile's `spaceUrl` with `nipa profile ls --json`. It's the portal URL with /api, such as https://space.nipa.cloud/api."});return s};return{get:async(o,s)=>{let i=await n(o);return Bm(await i.text(),s,i.status)},getLines:async(o,s)=>{let i=await n(o);return(await i.text()).split(`
|
|
90
|
+
`).filter((l)=>l.trim()).map((l)=>Bm(l,s,i.status))},post:async(o)=>{await r(o,"POST")}}};var Vm=v({address:m()}),Jw=v({kube_version:m().optional(),magnum_cluster_id:m().optional(),magnum_role:m().optional()}),qw=v({attached_as:m().nullish(),id:m(),name:m().nullish(),size:X(),volume_type:m().nullish()}),Yw=v({"OS-EXT-AZ:availability_zone":m().nullish(),created:m(),external_ips:j(Vm),flavor:v({name:m(),ram:X().optional(),vcpus:X().optional()}),id:m(),internal_ips:j(Vm),metadata:Jw.optional(),name:m(),security_groups:j(m()).optional(),status:m(),volumes:j(qw).optional()}),Xw=v({instances:j(Yw)}),Wm=(e,t)=>({address:e.address,type:t,version:e.address.includes(":")?6:4}),Qw=(e={})=>e.magnum_cluster_id===void 0?null:{clusterId:e.magnum_cluster_id,role:e.magnum_role??null,version:e.kube_version??null},e_=(e)=>({attachedAs:e.attached_as??null,id:e.id,name:e.name??null,sizeGb:e.size,type:e.volume_type??null}),t_=(e)=>({addresses:[...e.internal_ips.map((t)=>Wm(t,"fixed")),...e.external_ips.map((t)=>Wm(t,"floating"))],createdAt:e.created,flavor:e.flavor.name,id:e.id,kubernetes:Qw(e.metadata),name:e.name,ramMb:e.flavor.ram??null,securityGroups:e.security_groups??[],status:e.status,vcpus:e.flavor.vcpus??null,volumes:(e.volumes??[]).map(e_),zone:e["OS-EXT-AZ:availability_zone"]??null}),We=async(e)=>(await e.get("/v3/instances",Xw)).instances.map(t_),r_=v({instance:v({locked:tr().nullish(),status:m(),task_state:m().nullable()})}),Zi=async(e,t)=>{let{instance:r}=await e.get(`/v4/instances/${t}`,r_);return{locked:r.locked??null,status:r.status,taskState:r.task_state}},Ui=(e,t,r)=>e.post(`/v4/instances/${t}/action/${r}`),Hm=(e)=>{let t=e.sleep??Hw,r=e.now??Date.now,n=r()+e.timeoutMs,o=async()=>{let s=await Zi(e.space,e.id);if(s.status==="ERROR")return{kind:"error"};if(s.status===e.status&&s.taskState===null)return{kind:"done"};if(r()>=n)return{kind:"timeout",state:s};return await t(e.intervalMs),o()};return o()},n_=v({logs:m()}),Jm=async(e,t)=>{try{return{kind:"log",text:(await e.get(`/v4/instances/${t}/logs`,n_)).logs}}catch(r){if(r instanceof ge&&r.status===406)return{kind:"none"};throw r}},o_=v({action:m(),id:m(),remark:m().nullish(),started_at:m(),user_name:m().nullish()}),s_=v({action_histories:j(o_)}),bo=(e)=>e.remark==="Error",xo=async(e,t)=>(await e.get(`/v4/instances/${t}/action_histories`,s_)).action_histories.map((o)=>({action:o.action,remark:o.remark??null,requestId:o.id,startedAt:xt(o.started_at),user:o.user_name??null})).toSorted((o,s)=>Date.parse(s.startedAt)-Date.parse(o.startedAt));var i_=v({allowed_cidrs:j(m()).nullish(),availability_zone:m().nullish(),datastore_type:m(),datastore_version:m(),external_ip_address:m().nullish(),id:m(),instance_status:m(),ip_address:m(),machine_type:v({name:m(),ram:X().nullish(),vcpus:X().nullish()}),operating_status:m(),service_status_updated:m().nullish(),volume_size:X()}),a_=v({created_at:m(),id:m(),name:m(),primary:i_.nullish()}),c_=v({database_clusters:j(a_)}),l_=v({database_instances:j(v({database_cluster_id:m().nullish(),id:m(),instance_status:m(),ip_address:m().nullish(),name:m(),operating_status:m().nullish()}))}),u_=Kr(m(),v({name:m(),published:X().nullish(),status:m()})),p_=v({database_backups:j(v({created_at:m(),database_instance_id:m(),id:m(),name:m(),size:X().nullish(),status:m()}))}),d_=new Map([["mariadb",3306],["mongodb",27017],["mysql",3306],["percona",3306],["postgresql",5432],["redis",6379]]),m_=(e)=>({address:e.ip_address,allowedCidrs:e.allowed_cidrs??[],engine:e.datastore_type,externalAddress:e.external_ip_address||null,flavor:e.machine_type.name,health:e.operating_status,healthCheckedAt:e.service_status_updated??null,id:e.id,ramMb:e.machine_type.ram??null,status:e.instance_status,storageGb:e.volume_size,vcpus:e.machine_type.vcpus??null,version:e.datastore_version,zone:e.availability_zone||null}),f_=(e)=>({createdAt:e.created_at,id:e.id,name:e.name,primary:e.primary?m_(e.primary):null}),wo=async(e)=>(await e.get("/v4/database/clusters?include_primary=true&include_machine_type=true",c_)).database_clusters.map(f_).toSorted((r,n)=>Date.parse(n.createdAt)-Date.parse(r.createdAt)),h_=async(e,t,r)=>(await e.get(`/v4/databases?database_cluster_id=${encodeURIComponent(t.id)}`,l_)).database_instances.filter((o)=>o.database_cluster_id===t.id&&o.id!==r).map((o)=>({address:o.ip_address||null,health:o.operating_status??"UNKNOWN",id:o.id,name:o.name,status:o.instance_status})),g_=new Set(["DISABLED","UNAVAILABLE"]),y_=async(e,t)=>{let r=await e.get(`/v4/database/${encodeURIComponent(t)}/logs`,u_);return Object.values(r).map((n)=>({enabled:!g_.has(n.status.toUpperCase()),name:n.name,publishedBytes:n.published??0,status:n.status}))},b_=async(e,t)=>(await e.get(`/v4/database/backups?database_instance_id=${encodeURIComponent(t)}`,p_)).database_backups.filter((n)=>n.database_instance_id===t).map((n)=>({createdAt:xt(n.created_at),id:n.id,name:n.name,sizeGb:n.size??null,status:n.status})).toSorted((n,o)=>Date.parse(o.createdAt)-Date.parse(n.createdAt)),Fi=(e)=>e.status==="fulfilled"?e.value:null,qm=async(e,t)=>{let{primary:r}=t;if(!r)return{...t,backups:[],defaultPort:null,logs:[],replicas:[]};let[n,o,s]=await Promise.allSettled([h_(e,t,r.id),y_(e,r.id),b_(e,r.id)]);return{...t,backups:Fi(s),defaultPort:d_.get(r.engine.toLowerCase())??null,logs:Fi(o),replicas:Fi(n)}};var x_=v({availability_zone:m(),external_ip_address:m(),id:m(),internal_ip_address:m().nullable(),name:m(),status:m()}),w_=v({external_ips:j(x_)}),__=(e)=>({address:e.external_ip_address,id:e.id,internalAddress:e.internal_ip_address,name:e.name,status:e.status,zone:e.availability_zone}),_o=async(e)=>(await e.get("/v4/external_ips",w_)).external_ips.map(__);var v_=v({created_at:m(),id:m(),listeners:j(zi()),name:m(),operating_status:m(),provisioning_status:m(),vip_address:m()}),$_=v({loadbalancers:j(v_)}),S_=(e)=>({address:e.vip_address,createdAt:e.created_at,health:e.operating_status,id:e.id,listeners:e.listeners.length,name:e.name,status:e.provisioning_status}),vo=async(e)=>(await e.get("/v4/loadbalancers",$_)).loadbalancers.map(S_).toSorted((r,n)=>Date.parse(n.createdAt)-Date.parse(r.createdAt)),Yr=v({id:m(),operating_status:m(),provisioning_status:m()}),k_=v({loadbalancer:Yr.extend({created_at:m(),external_ip_id:m().nullish(),flavor_id:m().nullish(),name:m(),vip_address:m()})}),P_=v({listeners:j(Yr.extend({allowed_cidrs:j(m()).nullish(),backend_group_id:m().nullish(),name:m().nullish(),protocol:m(),protocol_port:X()}))}),C_=Yr.extend({delay:X(),max_retries:X(),timeout:X(),type:m()}),E_=v({backend_groups:j(Yr.extend({healthcheck:C_.nullish(),lb_algorithm:m(),name:m().nullish(),protocol:m()}))}),z_=v({members:j(Yr.extend({address:m(),backup:tr().nullish(),name:m().nullish(),protocol_port:X(),weight:X().nullish()}))}),I_=v({loadbalancer_flavors:j(v({id:m(),name:m()}))}),qr=(e)=>({health:e.operating_status,id:e.id,status:e.provisioning_status}),A_=async(e,t)=>(await e.get(`${t}/members`,z_)).members.map((n)=>({...qr(n),address:n.address,backup:n.backup??!1,name:n.name??null,port:n.protocol_port,weight:n.weight??null})),T_=async(e,t)=>{if(!t)return null;return(await _o(e)).find((n)=>n.id===t)?.address??null},R_=async(e,t)=>{if(!t)return null;let{loadbalancer_flavors:r}=await e.get("/v4/loadbalancerflavors",I_);return r.find((n)=>n.id===t)?.name??t},Ym=(e)=>e.status==="fulfilled"?e.value:null,Qm=async(e,t)=>{let r=`/v4/loadbalancers/${encodeURIComponent(t)}`,[n,o,s]=await Promise.all([e.get(r,k_),e.get(`${r}/listeners`,P_),e.get(`${r}/backend_groups`,E_)]),i=n.loadbalancer,[a,c]=await Promise.all([Promise.all(s.backend_groups.map((p)=>A_(e,`${r}/backend_groups/${p.id}`))),Promise.allSettled([R_(e,i.flavor_id),T_(e,i.external_ip_id)])]),[l,u]=c;return{...qr(i),address:i.vip_address,backendGroups:s.backend_groups.map((p,d)=>({...qr(p),algorithm:p.lb_algorithm,healthCheck:p.healthcheck?{...qr(p.healthcheck),delaySeconds:p.healthcheck.delay,maxRetries:p.healthcheck.max_retries,timeoutSeconds:p.healthcheck.timeout,type:p.healthcheck.type}:null,members:a[d]??[],name:p.name??null,protocol:p.protocol})),createdAt:i.created_at,externalAddress:Ym(u),flavor:Ym(l),listenerDetails:o.listeners.map((p)=>({...qr(p),allowedCidrs:p.allowed_cidrs??[],backendGroupId:p.backend_group_id??null,name:p.name??null,port:p.protocol_port,protocol:p.protocol})),name:i.name}},j_=new Set(["ONLINE","NO_MONITOR"]),wt=(e)=>e.status==="ACTIVE"&&j_.has(e.health),O_=new Set(["OFFLINE","DRAINING"]),Gi=(e)=>e.backup&&e.status==="ACTIVE"&&O_.has(e.health),Xm=["listener","listeners"],Mi=["is unhealthy","are unhealthy"],Bi=(e)=>e.filter((t)=>!wt(t)).length,L_=({failing:e,noun:t,predicate:r,total:n})=>{if(n===1)return`the ${t[0]} ${r[0]}`;let[o,s]=r;return`${e} of ${n} ${t[1]} ${e===1?o:s}`},D_=(e)=>{if(wt(e)||e.members.length===0)return!1;if(e.healthCheck&&!wt(e.healthCheck))return!1;return!e.members.some((t)=>!(wt(t)||Gi(t)))},N_=(e)=>`Backup member ${e.name??e.id} is ${e.health.toLowerCase()} until the other members go down`,ef=(e)=>{let{backendGroups:t,listenerDetails:r}=e,n=new Map(t.map((p)=>[p.id,p.members.length])),o=r.filter((p)=>!n.get(p.backendGroupId??"")),s=t.flatMap((p)=>p.healthCheck??[]),i=t.flatMap((p)=>p.members),a=i.filter((p)=>!Gi(p)),l=[{failing:Bi(r),noun:Xm,predicate:Mi,total:r.length},{failing:o.length,noun:Xm,predicate:["has no members to send traffic to","have no members to send traffic to"],total:r.length},{failing:t.filter(D_).length,noun:["backend group","backend groups"],predicate:Mi,total:t.length},{failing:Bi(s),noun:["health check","health checks"],predicate:Mi,total:s.length},{failing:Bi(a),noun:["member","members"],predicate:["is down","are down"],total:i.length}].filter((p)=>p.failing>0).map(L_);if(r.length===0)l.unshift("the load balancer has no listeners");else if(l.length===0&&!wt(e))l.push("the load balancer is unhealthy");let u=i.filter(Gi).map(N_);if(l.length===0)return{details:u,healthy:!0,verdict:"All listeners and members are healthy"};return{details:u,healthy:!1,verdict:al(zt(l))}};var Z_=v({availability_zone:m().optional(),created_at:m(),external_network:tr(),id:m(),name:m(),shared:tr(),status:m()}),U_=v({networks:j(Z_)}),F_=(e)=>({createdAt:xt(e.created_at),external:e.external_network,id:e.id,name:e.name,shared:e.shared,status:e.status,zone:e.availability_zone||null}),$o=async(e)=>(await e.get("/v4/networks",U_)).networks.map(F_).toSorted((r,n)=>Date.parse(n.createdAt)-Date.parse(r.createdAt)),M_=v({device_id:m(),fixed_ips:j(v({ip_address:m()})),security_groups:j(m()).nullish()}),B_=v({ports:j(M_)}),tf=async(e)=>(await e.get("/v2/ports",B_)).ports.map((r)=>({addresses:r.fixed_ips.map((n)=>n.ip_address),deviceId:r.device_id,securityGroupIds:r.security_groups??[]}));var G_=v({direction:m(),ethertype:m(),id:m(),port_range_max:X().nullable(),port_range_min:X().nullable(),protocol:m().nullable(),remote_group_id:m().nullable(),remote_ip_prefix:m().nullable()}),K_=v({created_at:m(),description:m().nullable(),id:m(),name:m(),security_group_rules:j(G_)}),V_=v({security_groups:j(K_)}),W_=(e)=>({direction:e.direction,ethertype:e.ethertype,id:e.id,portMax:e.port_range_max,portMin:e.port_range_min,protocol:e.protocol,remoteGroupId:e.remote_group_id,remoteIpPrefix:e.remote_ip_prefix}),H_=(e)=>({createdAt:xt(e.created_at),description:e.description||null,id:e.id,name:e.name,rules:e.security_group_rules.map(W_)}),nr=async(e)=>(await e.get("/v4/security_groups",V_)).security_groups.map(H_).toSorted((r,n)=>Date.parse(n.createdAt)-Date.parse(r.createdAt));var J_=v({device:m(),serverId:m()}),q_=v({attachments:j(J_),availability_zone:m(),bootable:m(),created_at:m(),id:m(),name:m(),size:X(),status:m(),volume_type:m().nullable()}),Y_=v({volumes:j(q_)}),X_=(e)=>({attachments:e.attachments,bootable:e.bootable==="true",createdAt:e.created_at,id:e.id,name:e.name,sizeGb:e.size,status:e.status,type:e.volume_type,zone:e.availability_zone}),Xr=async(e)=>(await e.get("/v4/volumes",Y_)).volumes.map(X_).toSorted((r,n)=>Date.parse(n.createdAt)-Date.parse(r.createdAt));var Qr={list:We,lsCommand:"nipa server ls",noun:"server",plural:"servers"},So={list:Xr,lsCommand:"nipa volume ls",noun:"volume",plural:"volumes"},ko={list:$o,lsCommand:"nipa network ls",noun:"network",plural:"networks"},or={list:nr,lsCommand:"nipa sg ls",noun:"security group",plural:"security groups"},sr={list:vo,lsCommand:"nipa lb ls",noun:"load balancer",plural:"load balancers"},ir={list:wo,lsCommand:"nipa db ls",noun:"database",plural:"databases"},at=async(e)=>{let{kind:t,projectName:r,ref:n}=e,o=await I(`Loading the ${t.plural} in ${r}…`,()=>t.list(e.space)),s=o.filter((c)=>c.id===n),[i,...a]=s.length>0?s:o.filter((c)=>c.name===n);if(!i)throw new E(`no ${t.noun} named or with ID "${n}" in ${r}`,{hint:`Run \`${t.lsCommand}\` to see your ${t.plural}.`});if(a.length>0){let c=[i,...a].map((l)=>l.id).join(", ");throw new E(`${a.length+1} ${t.plural} in ${r} are named "${n}"`,{hint:`Name one by its ID instead: ${c}.`})}return i},_t=(e)=>at({...e,kind:Qr});import{chmod as Q_,mkdir as nf,readFile as of,rm as ev,writeFile as sf}from"node:fs/promises";import{homedir as af}from"node:os";import jt from"node:path";var fe="prod",me={authUrl:"https://identity-api.nipa.cloud/v3",region:"NCP-TH",spaceUrl:"https://space.nipa.cloud/api",userDomain:"nipacloud"},rf=Mx({protocol:/^https?$/u}),ct=v({authUrl:rf,project:Vr.optional(),region:m().min(1),spaceUrl:rf.optional(),userDomain:m().min(1),username:m().optional()}),Vi=/^[a-z][\da-z-]{0,31}$/u,tv=Kr(m().regex(Vi),ct),rv=(e)=>{let{spaceUrl:t,...r}=e;if(e.authUrl===me.authUrl)return{...r,spaceUrl:Jr(t??me.spaceUrl)};if(t===void 0||t===me.spaceUrl)return r;return{...r,spaceUrl:Jr(t)}},Wi=(e)=>({[fe]:me,...Object.fromEntries(Object.entries(e).map(([t,r])=>[t,rv(r)]))}),nv=v({currentProfile:m().default(fe),profiles:tv.default({})}).strict().transform((e)=>({...e,profiles:Wi(e.profiles)})),ov=ct.extend({authUrl:ct.shape.authUrl.default(me.authUrl),region:ct.shape.region.default(me.region),userDomain:ct.shape.userDomain.default(me.userDomain)}).transform((e)=>({currentProfile:fe,profiles:Wi({[fe]:e})})),sv=Ti([nv,ov]),cf=v({expiresAt:po.datetime({offset:!0}),project:Vr,token:m().min(1),user:v({id:m(),name:m()})}),iv=Kr(m(),cf),av=Ti([v({sessions:iv}).strict().transform((e)=>e.sessions),cf.transform((e)=>({[fe]:e}))]);class Ot extends Error{constructor(e){super(e);this.name="StoreError"}}var cv=60000,Hi=(e=process.env)=>e.NIPA_CONFIG_DIR??jt.join(e.XDG_CONFIG_HOME??jt.join(af(),".config"),"nipa"),Ji=()=>jt.join(Hi(),"config.json"),en=()=>jt.join(Hi(),"auth.json"),lf=()=>[Ji(),en()],Ki=(e,t=process.env)=>jt.join(t.XDG_CACHE_HOME??jt.join(af(),".cache"),"nipa",e),He=async(e,t)=>{try{let r=await of(Ki(e),"utf-8"),n=t.safeParse(JSON.parse(r));return n.success?n.data:void 0}catch{return}},lt=async(e,t)=>{await nf(jt.dirname(Ki(e)),{recursive:!0}),await sf(Ki(e),`${JSON.stringify(t)}
|
|
91
|
+
`)},lv=async(e)=>{try{return await of(e,"utf-8")}catch(t){if(t instanceof Error&&"code"in t&&t.code==="ENOENT")return;throw t}},uf=async(e,t)=>{let r=await lv(e);if(r===void 0)return;let n;try{n=JSON.parse(r)}catch{throw new Ot(`${e} isn't valid JSON`)}let o=t.safeParse(n);if(!o.success)throw new Ot(`${e}: ${qt(o.error)}`);return o.data},qi=async(e,t)=>{await nf(Hi(),{mode:448,recursive:!0}),await sf(e,`${JSON.stringify(t,null,2)}
|
|
92
|
+
`,{mode:384}),await Q_(e,384)},ve=async()=>await uf(Ji(),sv)??{currentProfile:fe,profiles:Wi({})},vt=(e)=>qi(Ji(),e),Yi=async()=>await uf(en(),av)??{},pe=async(e)=>(await Yi())[e],pf=async(e)=>{let t=await Yi();await qi(en(),{sessions:{...t,[e.profile]:e.session}})},Po=async(e)=>{let t=await Yi(),r=Object.fromEntries(Object.entries(t).filter(([n])=>n!==e));if(Object.keys(r).length===0){await ev(en(),{force:!0});return}await qi(en(),{sessions:r})},Lt=(e,t=Date.now())=>Date.parse(e.expiresAt)-t,de=(e,t=Date.now())=>e!==void 0&&Lt(e,t)>cv;var df="names.json",uv=60000,Xi=v({name:m()}),pv=v({machine_types:j(Xi)}),dv=v({owned_images:j(Xi)}),mv=v({public_images:j(v({images:j(Xi)}))}),ut=(e)=>e.map((t)=>t.name).filter((t)=>t!==""),fv=async(e,t)=>{switch(t){case"servers":return ut(await Qr.list(e));case"volumes":return ut(await So.list(e));case"networks":return ut(await ko.list(e));case"security-groups":return ut(await or.list(e));case"load-balancers":return ut(await sr.list(e));case"databases":return ut(await ir.list(e));case"flavors":{let r=await e.get("/v4/machine_types",pv);return ut(r.machine_types)}case"images":{let[r,n]=await Promise.all([e.get("/v4/public_images",mv),e.get("/v4/images?table=owned_image",dv)]);return[...r.public_images.flatMap((o)=>ut(o.images)),...ut(n.owned_images)]}default:return t}},hv=Kr(m(),v({at:X(),names:j(m())})),mf=async(e)=>{let t=e.now??Date.now(),r=`${e.scope}:${e.kind}`,n=await He(df,hv)??{},o=n[r];if(o&&t-o.at<uv)return o.names;let s=await fv(await e.connect(),e.kind);return await lt(df,{...n,[r]:{at:t,names:s}}),s};import{spawn as _v}from"node:child_process";import{once as vv}from"node:events";import{stat as $v}from"node:fs/promises";import{text as Sv}from"node:stream/consumers";import{accessSync as gv,constants as yv}from"node:fs";import{homedir as bv}from"node:os";import tn from"node:path";var ff=(e)=>{try{return gv(e,yv.X_OK),!0}catch{return!1}},xv=(e)=>process.platform==="win32"?[...(process.env.PATHEXT??".EXE;.CMD;.BAT").split(";").map((t)=>`${e}${t}`),e]:[e],pt=(e)=>{if(e.includes("/")||e.includes(tn.sep)){let r=tn.resolve(e);return ff(r)?r:void 0}return[...(process.env.PATH??"").split(tn.delimiter).filter(Boolean),tn.join(bv(),".local","bin")].flatMap((r)=>xv(tn.join(r,e))).find(ff)},Co=(e)=>({OS_AUTH_TYPE:"v3token",OS_AUTH_URL:e.profile.authUrl,OS_IDENTITY_API_VERSION:"3",OS_INTERFACE:"public",OS_PROJECT_DOMAIN_ID:e.session.project.domainId??"",OS_PROJECT_ID:e.session.project.id,OS_PROJECT_NAME:e.session.project.name,OS_REGION_NAME:e.profile.region,OS_TOKEN:e.session.token}),gf=(e,t)=>({...Object.fromEntries(Object.entries(e).filter(([r])=>!r.startsWith("OS_"))),...t}),Qi=["bash","zsh","fish"],wv=(e)=>Qi.some((t)=>t===e),hf=(e,t)=>`'${t==="fish"?e.replaceAll("\\","\\\\").replaceAll("'","\\'"):e.replaceAll("'","'\\''")}'`,yf=(e,t)=>Object.entries(e).map(([r,n])=>t==="fish"?`set -gx ${r} ${hf(n,t)}`:`export ${r}=${hf(n,t)}`).join(`
|
|
93
|
+
`),bf=(e)=>{let t=e?.split("/").at(-1)??"";return wv(t)?t:"bash"};var xf="openstack.json",kv=20000,Pv=Kr(m(),j(m())),Cv=v({bin:m(),mtimeMs:X(),table:Pv}),Ev=/^\s*cmds(?:_(?<key>\S+))?='(?<words>[^']*)'$/u,zv=(e)=>Object.fromEntries(e.split(`
|
|
94
|
+
`).flatMap((t)=>{let r=Ev.exec(t)?.groups;if(!r)return[];let n=r.words?.split(" ").filter(Boolean)??[];return[[r.key??"",n]]})),Iv=(e,t)=>{let r=t.at(-1)??"",n="";for(let s of t.slice(0,-1)){let i=(n?`${n}_${s}`:s).replaceAll("-","_");if(s.startsWith("-")||!Object.hasOwn(e,i))break;n=i}let o=e[n]??[];if(r.startsWith("-"))return o.filter((s)=>s.startsWith(r));return o.filter((s)=>s.startsWith(r)&&!s.startsWith("-")&&!s.includes("_"))},Av=async(e)=>{let{mtimeMs:t}=await $v(e),r=await He(xf,Cv);if(r?.bin===e&&r.mtimeMs===t)return r.table;let n=_v(e,["complete","--shell","none"],{stdio:["ignore","pipe","ignore"],timeout:kv}),[o]=await Promise.all([Sv(n.stdout),vv(n,"close")]);if(n.exitCode!==0)return;let s=zv(o);return await lt(xf,{bin:e,mtimeMs:t,table:s}),s},wf=async(e)=>{let t=pt("openstack");if(!t)return[];let r=await Av(t);return r?Iv(r,e):[]},Tv=["console log show","console url show","server delete","server lock","server pause","server reboot","server rescue","server resume","server show","server shelve","server ssh","server start","server stop","server suspend","server unlock","server unpause","server unrescue","server unshelve"].map((e)=>e.split(" ")),Rv=new Map([["--flavor","flavors"],["--image","images"],["--network","networks"]]),_f=(e)=>{let t=e.at(-2)??"";if(t.startsWith("-"))return Rv.get(t);if((e.at(-1)??"").startsWith("-"))return;return Tv.some((n)=>e.length>n.length&&n.every((o,s)=>e[s]===o))?"servers":void 0};import{spawn as jv}from"node:child_process";import{once as Ov}from"node:events";import{text as Lv}from"node:stream/consumers";var Dt=async(e,t,r="")=>{let n=jv(e,t,{stdio:["pipe","pipe","ignore"]});n.stdin.end(r);let[o]=await Promise.all([Lv(n.stdout),Ov(n,"close")]);return{code:n.exitCode,stdout:o}},vf=(e)=>`nipa-cli/${new URL(e.authUrl).host}`,$f=(e,t)=>new E(`the ${e} didn't save your password`,{hint:`${t}, or log in without \`--remember\`.`}),ea=(e)=>["-s",vf(e),"-a",e.username],Dv=(e)=>({name:"macOS Keychain",read:async(r)=>{let{code:n,stdout:o}=await Dt(e,["find-generic-password",...ea(r),"-w"]);return n===0?Buffer.from(o.trim(),"base64").toString("utf-8"):void 0},remove:async(r)=>{let{code:n}=await Dt(e,["delete-generic-password",...ea(r)]);return n===0},save:async(r,n)=>{let o=Buffer.from(n,"utf-8").toString("base64"),s=Buffer.from(o,"ascii").toString("hex"),i=["add-generic-password","-U",...ea(r),"-X",s],{code:a}=await Dt(e,["-i"],`${i.join(" ")}
|
|
95
|
+
`);if(a!==0)throw $f("macOS Keychain","Check that your login keychain is unlocked")}}),Eo=(e)=>["service",vf(e),"account",e.username],Nv=(e)=>({name:"secret service",read:async(r)=>{let{code:n,stdout:o}=await Dt(e,["lookup",...Eo(r)]);return n===0&&o!==""?o:void 0},remove:async(r)=>{let n=await Dt(e,["lookup",...Eo(r)]);return await Dt(e,["clear",...Eo(r)]),n.code===0},save:async(r,n)=>{let s=["store",`--label=${`nipa password for ${r.username}`}`,...Eo(r)],{code:i}=await Dt(e,s,n);if(i!==0)throw $f("secret service","Check that a secret service, such as GNOME Keyring, is running")}}),zo=(e=process.platform)=>{if(e==="darwin"){let t=pt("security");return t?Dv(t):void 0}if(e==="linux"){let t=pt("secret-tool");return t?Nv(t):void 0}return},Sf=(e=process.platform)=>{let t=zo(e);if(t)return t;let r=e==="linux"?"Install secret-tool, such as with `sudo apt install libsecret-tools`, or log in without `--remember`.":"Log in without `--remember`. nipa saves passwords on macOS and Linux.";throw new E(`nipa can't save your password on ${e}`,{hint:r})},Io=(e)=>{let t=zo();if(!(t&&e.username))return Promise.resolve(!1);return t.remove({authUrl:e.authUrl,username:e.username})};import{mkdir as Zv,readFile as Uv,rm as Fv,rmdir as Mv,writeFile as Bv}from"node:fs/promises";import nn from"node:path";var Gv=".nipa",Kv="project.json",Vv=v({profile:m(),project:Vr}),kf=(e)=>nn.join(e,Gv,Kv);class rn extends E{constructor(e,t){super(`${e} ${t}`,{hint:"Fix the file, or run `nipa unlink` and `nipa link` again."});this.name="LinkError"}}var Wv=async(e)=>{let t;try{t=await Uv(e,"utf-8")}catch(o){if(o instanceof Error&&"code"in o&&o.code==="ENOENT")return;throw o}let r;try{r=JSON.parse(t)}catch{throw new rn(e,"isn't valid JSON")}let n=Vv.safeParse(r);if(!n.success)throw new rn(e,`isn't a nipa link: ${qt(n.error)}`);return n.data},Nt=async(e=process.cwd())=>{let t=kf(e),r=await Wv(t);if(r)return{file:t,link:r};let n=nn.dirname(e);return n===e?void 0:Nt(n)},Pf=async(e)=>{let t=kf(e.dir);return await Zv(nn.dirname(t),{recursive:!0}),await Bv(t,`${JSON.stringify(e.link,null,2)}
|
|
96
|
+
`),t},Cf=async(e)=>{await Fv(e,{force:!0});try{await Mv(nn.dirname(e))}catch{}},ye=(e,t=process.cwd())=>nn.relative(t,e);var ta=async(e)=>{let{link:t}=e,r=await ve(),n=[["flag",e.override],["env",process.env.NIPA_PROFILE],["link",t?.link.profile]],[o,s]=n.find((c)=>c[1]!==void 0)??["config",r.currentProfile],i=r.profiles[s];if(!i){let c=Object.keys(r.profiles).join(", "),l=t?.link.profile===s?` in ${ye(t.file)}`:"";throw new E(`no profile named "${s}"${l}`,{hint:`Your profiles: ${c}. Add one with \`nipa profile add ${s}\`.`})}let a=t?.link.profile===s?t:void 0;return{config:r,link:a,name:s,profile:i,source:o}},Je=(e)=>e===fe?"nipa login":`nipa login -P ${e}`,Ao=(e)=>{if(e.name!==fe){let t=A(`(${new URL(e.profile.authUrl).host})`);w(`Using profile ${x(e.name)} ${t}`)}},Hv=/^\d{6}$/u,Ef=/^[\da-f]{32}$/u,Jv=3,qv=(e)=>({email:(t)=>e.text({default:t,message:"Email",validate:(r)=>r.includes("@")||"Enter the email you log in to the portal with"}),otp:(t)=>e.text({message:t===1?"OTP code":"Next OTP code",validate:(r)=>Hv.test(r)||"Enter the 6-digit code from your authenticator app"}),password:()=>e.secret("Password"),projectId:()=>e.text({message:"Project ID",validate:(t)=>Ef.test(t)||"Enter the 32-character ID, as in OS_PROJECT_ID in your openrc file"})}),zf=(e)=>{let{projects:t,wanted:r}=e,n=t.find((o)=>o.id===r||o.name===r);if(!n)throw new E(`no project named or with ID "${r}"`,{hint:`Your projects: ${t.map((o)=>o.name).join(", ")}`});return n},To=(e)=>(t)=>e.prompts.choice({choices:t.map((r)=>({description:r.id,name:r.id===e.current.id?`${r.name} ${x("(current)")}`:r.name,value:r})),default:t.find((r)=>r.id===e.current.id),message:e.message}),Ro=(e)=>{let{projects:t,wanted:r}=e;if(r)return Promise.resolve(zf({projects:t,wanted:r}));let[n,...o]=t;if(!n)throw new E("your account has no projects you can use");return o.length===0?Promise.resolve(n):e.ask(t)},on=(e,t)=>({expiresAt:e.expiresAt,project:e.project??t,token:e.value,user:e.user}),If=async(e)=>{let t=await e.ask(e.attempt);try{return await I("Checking the code…",()=>Mm({account:e.account,passcode:t,receipt:e.receipt}))}catch(r){if(!(r instanceof ae&&r.status===401)||e.attempt===Jv)throw r;return w("That code didn't work. Each code works once, so wait for the next one."),If({...e,attempt:e.attempt+1})}},Yv=async(e)=>{let t=e.username??e.profile.username;if(!(t&&e.keychain))return;let r=await e.keychain.read({authUrl:e.profile.authUrl,username:t});return r===void 0?void 0:{password:r,username:t}},Xv=async(e)=>{let{account:t,keychain:r,prompts:n,remembered:o}=e,s=async(i)=>({answer:await I("Checking your password…",()=>Fm(t,i)),password:i});if(o===void 0||!r)return s(await n.password());w(`Using the password saved in the ${r.name}`);try{return await s(o)}catch(i){if(!(i instanceof ae&&i.status===401))throw i;return await r.remove(t),w("The saved password didn't work, so nipa deleted it."),s(await n.password())}},Qv=async(e)=>{let{keychain:t,profile:r,prompts:n,wantedProject:o}=e,s=await Yv({keychain:t,profile:r,username:e.username}),i=s?.username??e.username??await n.email(r.username),a=o!==void 0&&Ef.test(o)?o:void 0,c=a??r.project?.id??await n.projectId(),l={authUrl:r.authUrl,projectId:c,userDomain:r.userDomain,username:i},{answer:u,password:p}=await Xv({account:l,keychain:t,prompts:n,remembered:s?.password}),d=u.kind==="token"?u.token:await If({account:l,ask:n.otp,attempt:1,receipt:u.receipt});if(!d.project)throw new ae(`Keystone returned a token without project ${c}`,0);if(e.remember&&t)await t.save(l,p);let f=a?void 0:o;if(f===void 0||d.project.name===f)return on(d,d.project);let h=await I("Loading your projects…",()=>Ue({authUrl:r.authUrl,token:d.value})),y=zf({projects:h,wanted:f}),b=await I(`Switching to ${y.name}…`,()=>Hr({authUrl:r.authUrl,projectId:y.id,token:d.value}));return on(b,y)},ra=async(e)=>{let{active:t,session:r}=e,n={...t.profile,project:r.project,username:r.user.name};await vt({...t.config,profiles:{...t.config.profiles,[t.name]:n}}),await pf({profile:t.name,session:r})},na=async(e)=>{let{active:t,prompts:r}=e;if(!r.interactive)throw new E("`nipa login` needs a terminal to ask for your password",{hint:"Run it in a terminal, then run this command again."});let n=e.remember?Sf():zo(),o=A(`(${new URL(t.profile.authUrl).host})`);w(`Logging in to ${x(t.name)} ${o}`);let s=await Qv({keychain:n,profile:t.profile,prompts:qv(r),remember:e.remember,username:e.username,wantedProject:e.wantedProject});await ra({active:t,session:s});let i=x(s.user.name);if(Q(`Logged in as ${i}, project ${x(s.project.name)}`),e.remember&&n)w(`Saved your password in the ${n.name}, so the next login asks only for an OTP code.`);return s},oa=1800000,e$=(e)=>{let t=Lt(e.session);if(t<oa)G(`Your ${e.profile} session expires in ${Kt(t)}. Run \`${Je(e.profile)}\` to start a new one.`)},t$=async(e)=>{let{active:t,prompts:r}=e,n=await pe(t.name);if(de(n))return e$({profile:t.name,session:n}),n;let o=`Run \`${Je(t.name)}\`.`;if(!r.interactive)throw n?new E(`your ${t.name} session expired`,{hint:o}):new E(`you aren't logged in to ${t.name}`,{hint:o});return w(n?"Your session expired.":"You aren't logged in yet."),na({active:t,prompts:r})},r$=async(e)=>{let{active:t,session:r}=e,{file:n,link:o}=e.link,s;try{s=await I(`Switching to ${o.project.name}…`,()=>Hr({authUrl:t.profile.authUrl,projectId:o.project.id,token:r.token}))}catch(i){if(i instanceof ae&&i.status===401)throw new E(`can't use project ${o.project.name}, which ${ye(n)} links to`,{hint:`Run \`nipa link\` to pick another project. If Keystone revoked your session, run \`${Je(t.name)}\`.`});throw i}return w(`Using project ${x(o.project.name)} from ${A(ye(n))}`),on(s,o.project)},sn=async(e)=>{let{active:t,prompts:r}=e,n=await t$({active:t,prompts:r}),o=e.linked===!1?void 0:t.link;if(!o||o.link.project.id===n.project.id)return{active:t,session:n};return{active:t,session:await r$({active:t,link:o,session:n})}},n$=(e)=>async(t)=>{try{return await t()}catch(r){if((r instanceof ge||r instanceof ae?r.status:void 0)===401)throw new E(`your ${e} session expired or was revoked`,{hint:`Run \`${Je(e)}\`.`});throw r}},sa=(e)=>new E(`the ${e.name} profile has no Space API URL`,{hint:`Remove it with \`nipa profile rm ${e.name}\`, then add it again with \`--space-url\` and its Space portal URL. \`nipa -P ${e.name} os server list\` works without one.`}),an=(e)=>{let{spaceUrl:t}=e.profile;if(!t)throw sa(e);return t},jo=(e)=>{let{active:t,session:r}=e.signedIn,n=n$(t.name),o=yo({projectId:r.project.id,region:t.profile.region,token:r.token,url:e.spaceUrl}),s=(i)=>n(async()=>{try{return await i()}catch(a){if(a instanceof it)throw new E(a.message,{hint:"Check your network connection, or the profile's Space API URL."});throw a}});return{active:t,session:r,space:{get:(i,a)=>s(()=>o.get(i,a)),getLines:(i,a)=>s(()=>o.getLines(i,a)),post:(i)=>s(()=>o.post(i))}}};var Af=["bash","zsh","fish","pwsh"],Tf=["projects","profiles","openstack",...uc],Zt=(e)=>`nipa __complete ${e}`,Ut=Se(Xo),o$=(e)=>e.filter((t)=>t.kind==="passthrough").flatMap((t)=>xe(t)),ia=(e)=>[...e.flags,...$e],Lo=(e)=>{let t=e.args.findIndex((n)=>n.value.kind!=="text"),r=e.args[t];return r?{arg:r,position:t+1}:void 0},s$=(e)=>{switch(e.kind){case"none":return;case"text":return"return";case"choice":return`_nipa_reply ${e.choices.join(" ")}; return`;case"project":return`_nipa_reply "$(${Zt("projects")} 2>/dev/null)"; return`;case"profile":return`_nipa_reply "$(${Zt("profiles")} 2>/dev/null)"; return`;default:return e}},i$=(e)=>{switch(e.kind){case"text":return;case"project":return`_nipa_reply "$(${Zt("projects")} 2>/dev/null)"`;case"profile":return`_nipa_reply "$(${Zt("profiles")} 2>/dev/null)"`;case"resource":return`_nipa_reply "$(${Zt(e.resource)} 2>/dev/null)"`;case"choice":return`_nipa_reply ${e.choices.join(" ")}`;default:return e}},a$=(e)=>{switch(e.kind){case"program":return`COMP_WORDS[i]=${e.program}; _nipa_offset "$i"`;case"command":return'_nipa_offset "$((i + 1))"';case"openstack":return'_nipa_reply "$(nipa __complete openstack -- "${COMP_WORDS[@]:i+1:COMP_CWORD-i}" 2>/dev/null)"';default:return e}},Rf=(e,t)=>{let r=" ".repeat(t*2+2),n=[];if(e.kind==="group"){let s=e.subcommands;n.push(`if [[ $COMP_CWORD -eq $((i + 1)) ]]; then _nipa_reply ${s.map((i)=>i.name).join(" ")}; return; fi`,"case ${COMP_WORDS[i + 1]} in",...s.map((i)=>Rf(i,t+1)),"esac")}else if(e.kind==="passthrough")n.push(a$(e.target));else{let s=ia(e),i=s.flatMap((u)=>{let p=s$(u.value);return p===void 0?[]:[` ${Se(u).join("|")}) ${p} ;;`]});if(i.length>0)n.push('case "$prev" in',...i,"esac");let a=s.flatMap(Se).join(" ");n.push(`if [[ $cur == -* ]]; then _nipa_reply ${a}; return; fi`);let c=Lo(e),l=c&&i$(c.arg.value);if(l)n.push(l)}let o=n.map((s)=>`${r} ${s}`).join(`
|
|
97
|
+
`);return`${r}${xe(e).join("|")})
|
|
95
98
|
${o}
|
|
96
|
-
${r} ;;`},
|
|
99
|
+
${r} ;;`},c$=(e)=>{let t=hr(e),r=t.map((o)=>o.name).join(" "),n=$e.flatMap(Se).join(" ");return`# nipa completion for bash
|
|
97
100
|
# Load it from ~/.bashrc: eval "$(nipa completion bash)"
|
|
98
101
|
|
|
99
102
|
# One word per line, so project names with spaces stay whole.
|
|
@@ -117,32 +120,32 @@ _nipa() {
|
|
|
117
120
|
local i=1 command=""
|
|
118
121
|
while [[ $i -lt $COMP_CWORD ]]; do
|
|
119
122
|
case \${COMP_WORDS[i]} in
|
|
120
|
-
${
|
|
123
|
+
${Ut.join("|")}) ((i += 2)) ;;
|
|
121
124
|
-*) ((i += 1)) ;;
|
|
122
125
|
*) command=\${COMP_WORDS[i]}; break ;;
|
|
123
126
|
esac
|
|
124
127
|
done
|
|
125
128
|
if [[ -z $command ]]; then
|
|
126
129
|
case $prev in
|
|
127
|
-
${
|
|
130
|
+
${Ut.join("|")}) _nipa_reply "$(${Zt("profiles")} 2>/dev/null)"; return ;;
|
|
128
131
|
esac
|
|
129
132
|
if [[ $cur == -* ]]; then _nipa_reply ${n}; else _nipa_reply ${r}; fi
|
|
130
133
|
return
|
|
131
134
|
fi
|
|
132
135
|
case $command in
|
|
133
|
-
${t.map((o)=>
|
|
136
|
+
${t.map((o)=>Rf(o,0)).join(`
|
|
134
137
|
`)}
|
|
135
138
|
esac
|
|
136
139
|
}
|
|
137
140
|
complete -o default -F _nipa nipa
|
|
138
|
-
`}
|
|
141
|
+
`},Oo=(e)=>e.replaceAll("'","'\\''").replaceAll(":","\\:"),l$=(e)=>{let{value:t}=e;switch(t.kind){case"none":return"";case"text":return`:${t.name}: `;case"choice":return`:${e.long}:(${t.choices.join(" ")})`;case"project":return":project:{_nipa_dynamic projects project}";case"profile":return":profile:{_nipa_dynamic profiles profile}";default:return t}},u$=(e)=>{let t=Se(e),r=t.length>1?`(${t.join(" ")})`:"",n=t.length>1?`{${t.join(",")}}`:t[0];return`'${r}'${n}'[${Oo(e.description)}]${l$(e)}'`},p$=({arg:e,position:t})=>{let{value:r}=e;switch(r.kind){case"project":return`'${t}:project:{_nipa_dynamic projects project}'`;case"profile":return`'${t}:profile:{_nipa_dynamic profiles profile}'`;case"resource":return`'${t}:${e.name}:{_nipa_dynamic ${r.resource} ${e.name}}'`;case"choice":return`'${t}:${e.name}:(${r.choices.join(" ")})'`;case"text":return"";default:return r}},d$=(e,t)=>{switch(e.kind){case"program":return`${t} words[1]=${e.program}; _normal`;case"command":return`${t} shift words; (( CURRENT-- )); _normal`;case"openstack":return`${t} _nipa_openstack`;default:return e}},jf=(e,t)=>{if(e.kind==="group"){let o=e.subcommands,s=o.map((a)=>`'${a.name}:${Oo(a.summary)}'`).join(" "),i=o.map((a)=>{let c=jf(a,`${t} `);return`${t} ${xe(a).join("|")})
|
|
139
142
|
${c}
|
|
140
143
|
${t} ;;`}).join(`
|
|
141
144
|
`);return[`${t} if (( CURRENT == 2 )); then`,`${t} local -a subcommands; subcommands=(${s})`,`${t} _describe -t subcommands '${e.name} subcommand' subcommands; return`,`${t} fi`,`${t} shift words; (( CURRENT-- ))`,`${t} case $words[1] in`,i,`${t} esac`].join(`
|
|
142
|
-
`)}if(e.kind==="passthrough")return
|
|
143
|
-
`),n
|
|
144
|
-
`),o=t.map((s)=>` ${
|
|
145
|
-
${
|
|
145
|
+
`)}if(e.kind==="passthrough")return d$(e.target,t);let r=Lo(e),n=[...ia(e).map(u$),r?p$(r):""];return`${t} _arguments -s ${n.filter(Boolean).join(" ")}`},m$=(e)=>{let t=hr(e),r=t.map((s)=>` '${s.name}:${Oo(s.summary)}'`).join(`
|
|
146
|
+
`),n=$e.flatMap((s)=>Se(s).map((i)=>` '${i}:${Oo(s.description)}'`)).join(`
|
|
147
|
+
`),o=t.map((s)=>` ${xe(s).join("|")})
|
|
148
|
+
${jf(s," ")}
|
|
146
149
|
;;`).join(`
|
|
147
150
|
`);return`#compdef nipa
|
|
148
151
|
# nipa completion for zsh
|
|
@@ -165,13 +168,13 @@ _nipa() {
|
|
|
165
168
|
local i=2 command=""
|
|
166
169
|
while (( i < CURRENT )); do
|
|
167
170
|
case $words[i] in
|
|
168
|
-
${
|
|
171
|
+
${Ut.join("|")}) (( i += 2 )) ;;
|
|
169
172
|
-*) (( i += 1 )) ;;
|
|
170
173
|
*) command=$words[i]; break ;;
|
|
171
174
|
esac
|
|
172
175
|
done
|
|
173
176
|
if [[ -z $command ]]; then
|
|
174
|
-
if [[ $words[CURRENT-1] == (${
|
|
177
|
+
if [[ $words[CURRENT-1] == (${Ut.join("|")}) ]]; then
|
|
175
178
|
_nipa_dynamic profiles profile
|
|
176
179
|
elif [[ $PREFIX == -* ]]; then
|
|
177
180
|
local -a globals; globals=(
|
|
@@ -198,7 +201,7 @@ if [[ $zsh_eval_context[-1] == loadautofunc ]]; then
|
|
|
198
201
|
else
|
|
199
202
|
compdef _nipa nipa
|
|
200
203
|
fi
|
|
201
|
-
`}
|
|
204
|
+
`},$t=(e)=>`'${e.replaceAll("\\","\\\\").replaceAll("'","\\'")}'`,cn=(e)=>`'(${Zt(e)} 2>/dev/null)'`,f$=(e)=>{switch(e.kind){case"none":return"";case"text":return" --exclusive";case"choice":return` --exclusive -a ${$t(e.choices.join(" "))}`;case"project":return` --exclusive -a ${cn("projects")}`;case"profile":return` --exclusive -a ${cn("profiles")}`;default:return e}},h$=(e)=>{switch(e.kind){case"text":return;case"project":return cn("projects");case"profile":return cn("profiles");case"resource":return cn(e.resource);case"choice":return $t(e.choices.join(" "));default:return e}},g$=(e)=>{switch(e.kind){case"program":return`'(__nipa_complete_as ${e.program})'`;case"command":return"'(__nipa_complete_as)'";case"openstack":return"'(__nipa_openstack)'";default:return e}},y$=(e)=>{if(e.kind==="passthrough")return g$(e.target);let t=Lo(e);return t&&h$(t.arg.value)},Of=(e,t)=>{let r=e.short?` -s ${e.short}`:"";return`complete -c nipa -n ${$t(t)}${r} -l ${e.long}${f$(e.value)} -d ${$t(e.description)}`},Lf=(e,t)=>{let r=`__nipa_using ${xe(t??e).join(" ")}`,n=t?`${r}; and __fish_seen_subcommand_from ${xe(e).join(" ")}`:r;if(e.kind==="group"){let c=e.subcommands,l=`${n}; and not __fish_seen_subcommand_from ${c.flatMap((u)=>xe(u)).join(" ")}`;return[...c.map((u)=>`complete -c nipa -n ${$t(l)} -a ${u.name} -d ${$t(u.summary)}`),...c.flatMap((u)=>Lf(u,e))]}let s=(e.kind==="leaf"?e.flags:[]).map((c)=>Of(c,n)),i=y$(e),a=i?[`complete -c nipa -n ${$t(n)} -a ${i}`]:[];return[...s,...a]},b$=(e)=>{let t=hr(e),r=[...t,...e.hidden],n=`not __nipa_using ${o$(r).join(" ")}`,o=t.map((s)=>`complete -c nipa -n __nipa_needs_command -a ${s.name} -d ${$t(s.summary)}`);return`# nipa completion for fish
|
|
202
205
|
# Save it: nipa completion fish > ~/.config/fish/completions/nipa.fish
|
|
203
206
|
|
|
204
207
|
function __nipa_command_index
|
|
@@ -206,7 +209,7 @@ function __nipa_command_index
|
|
|
206
209
|
set -l i 2
|
|
207
210
|
while test $i -le (count $tokens)
|
|
208
211
|
switch $tokens[$i]
|
|
209
|
-
case ${
|
|
212
|
+
case ${Ut.join(" ")}
|
|
210
213
|
set i (math $i + 2)
|
|
211
214
|
case '-*'
|
|
212
215
|
set i (math $i + 1)
|
|
@@ -247,21 +250,21 @@ function __nipa_openstack
|
|
|
247
250
|
end
|
|
248
251
|
|
|
249
252
|
complete -c nipa -f
|
|
250
|
-
${
|
|
253
|
+
${$e.map((s)=>Of(s,n)).join(`
|
|
251
254
|
`)}
|
|
252
255
|
${o.join(`
|
|
253
256
|
`)}
|
|
254
|
-
${t.flatMap((s)=>
|
|
257
|
+
${t.flatMap((s)=>Lf(s)).join(`
|
|
255
258
|
`)}
|
|
256
|
-
`},
|
|
259
|
+
`},ln=(e)=>`'${e.replaceAll("'","''")}'`,qe=(e)=>`@(${e.map(ln).join(", ")})`,x$=(e)=>{switch(e.kind){case"none":case"text":return;case"choice":return qe(e.choices);case"project":return"(Dynamic projects)";case"profile":return"(Dynamic profiles)";default:return e}},w$=(e)=>{switch(e.kind){case"text":return;case"project":return"(Dynamic projects)";case"profile":return"(Dynamic profiles)";case"resource":return`(Dynamic ${e.resource})`;case"choice":return qe(e.choices);default:return e}},_$=(e)=>{switch(e.kind){case"openstack":return"(Openstack ($c + 1))";case"program":case"command":return;default:return e}},Df=(e,t)=>{if(e.kind==="group"){let i=e.subcommands,a=i.map((l)=>`${ln(l.name)} = ${ln(l.summary)}`).join("; "),c=i.map((l)=>{let u=Df(l,`${t} `);return`${t} { $_ -in ${qe(xe(l))} } {
|
|
257
260
|
${t} $c += 1
|
|
258
|
-
${
|
|
261
|
+
${u}
|
|
259
262
|
${t} }`}).join(`
|
|
260
|
-
`);return[`${t} if ($index -eq $c + 1) { return Complete ${
|
|
261
|
-
`)}if(e.kind==="passthrough"){let i=
|
|
262
|
-
`)},
|
|
263
|
-
`),n=t.map((o)=>` { $_ -in ${
|
|
264
|
-
${
|
|
263
|
+
`);return[`${t} if ($index -eq $c + 1) { return Complete ${qe(i.map((l)=>l.name))} @{ ${a} } }`,`${t} switch ($words[$c + 1]) {`,c,`${t} }`].join(`
|
|
264
|
+
`)}if(e.kind==="passthrough"){let i=_$(e.target);return i?`${t} return Complete ${i}`:`${t} return`}let r=ia(e),n=r.flatMap((i)=>{let a=x$(i.value);return a===void 0?[]:[`if ($prev -in ${qe(Se(i))}) { return Complete ${a} }`]});n.push(`if ($wordToComplete -like '-*') { return Complete ${qe(r.flatMap(Se))} }`);let o=Lo(e),s=o&&w$(o.arg.value);if(s)n.push(`Complete ${s}`);return n.map((i)=>`${t} ${i}`).join(`
|
|
265
|
+
`)},v$=(e)=>{let t=hr(e),r=t.map((o)=>` ${ln(o.name)} = ${ln(o.summary)}`).join(`
|
|
266
|
+
`),n=t.map((o)=>` { $_ -in ${qe(xe(o))} } {
|
|
267
|
+
${Df(o," ")}
|
|
265
268
|
}`).join(`
|
|
266
269
|
`);return`# nipa completion for PowerShell
|
|
267
270
|
# Load it from your $PROFILE: nipa completion pwsh | Out-String | Invoke-Expression
|
|
@@ -288,23 +291,32 @@ ${r}
|
|
|
288
291
|
$c = 1
|
|
289
292
|
$command = $null
|
|
290
293
|
while ($c -lt $index) {
|
|
291
|
-
if ($words[$c] -in ${
|
|
294
|
+
if ($words[$c] -in ${qe(Ut)}) { $c += 2 }
|
|
292
295
|
elseif ($words[$c] -like '-*') { $c += 1 }
|
|
293
296
|
else { $command = $words[$c]; break }
|
|
294
297
|
}
|
|
295
298
|
if (-not $command) {
|
|
296
|
-
if ($prev -in ${
|
|
297
|
-
if ($wordToComplete -like '-*') { return Complete ${
|
|
299
|
+
if ($prev -in ${qe(Ut)}) { return Complete (Dynamic profiles) }
|
|
300
|
+
if ($wordToComplete -like '-*') { return Complete ${qe($e.flatMap(Se))} }
|
|
298
301
|
return Complete ([string[]]$commands.Keys) $commands
|
|
299
302
|
}
|
|
300
303
|
switch ($command) {
|
|
301
304
|
${n}
|
|
302
305
|
}
|
|
303
306
|
}
|
|
304
|
-
`},
|
|
305
|
-
`).join("")),0});import{mkdir as
|
|
306
|
-
`));return 0});var
|
|
307
|
-
`));return
|
|
308
|
-
`));return 0});var jd=Ee(Td,{ls:Ad});var Rd=async(e)=>{let t=await fe(),r=e.override??process.env.NIPA_PROFILE??t.currentProfile,n=t.profiles[r];if(!n){let o=Object.keys(t.profiles).join(", ");throw new E(`no profile named "${r}"`,{hint:`Your profiles: ${o}. Add one with \`nipa profile add ${r}\`.`})}return{config:t,name:r,profile:n}},Cn=(e)=>e===re?"nipa login":`nipa login -P ${e}`,Ld=(e)=>{if(e.name!==re){let t=H(`(${new URL(e.profile.authUrl).host})`);T(`Using profile ${P(e.name)} ${t}`)}},Ay=/^\d{6}$/u,Zd=/^[\da-f]{32}$/u,jy=3,Ry=(e)=>({email:(t)=>e.text({default:t,message:"Email",validate:(r)=>r.includes("@")||"Enter the email you log in to the portal with"}),otp:(t)=>e.text({message:t===1?"OTP code":"Next OTP code",validate:(r)=>Ay.test(r)||"Enter the 6-digit code from your authenticator app"}),password:()=>e.secret("Password"),projectId:()=>e.text({message:"Project ID",validate:(t)=>Zd.test(t)||"Enter the 32-character ID, as in OS_PROJECT_ID in your openrc file"})}),Dd=(e)=>{let{projects:t,wanted:r}=e,n=t.find((o)=>o.id===r||o.name===r);if(!n)throw new E(`no project named or with ID "${r}"`,{hint:`Your projects: ${t.map((o)=>o.name).join(", ")}`});return n},Nd=(e)=>{let{projects:t,wanted:r}=e;if(r)return Promise.resolve(Dd({projects:t,wanted:r}));let[n,...o]=t;if(!n)throw new E("your account has no projects you can use");return o.length===0?Promise.resolve(n):e.ask(t)},En=(e,t)=>({expiresAt:e.expiresAt,project:e.project??t,token:e.value,user:e.user}),Ud=async(e)=>{let t=await e.ask(e.attempt);try{return await G("Checking the code…",()=>Tp({account:e.account,passcode:t,receipt:e.receipt}))}catch(r){if(!(r instanceof ue&&r.status===401)||e.attempt===jy)throw r;return T("That code didn't work. Each code works once, so wait for the next one."),Ud({...e,attempt:e.attempt+1})}},Ly=async(e)=>{let{profile:t,prompts:r,wantedProject:n}=e,o=e.username??await r.email(t.username),s=n!==void 0&&Zd.test(n)?n:void 0,i=s??t.project?.id??await r.projectId(),a=await r.password(),c={authUrl:t.authUrl,projectId:i,userDomain:t.userDomain,username:o},u=await G("Checking your password…",()=>Ip(c,a)),l=u.kind==="token"?u.token:await Ud({account:c,ask:r.otp,attempt:1,receipt:u.receipt});if(!l.project)throw new ue(`Keystone returned a token without project ${i}`,0);let p=s?void 0:n;if(p===void 0||l.project.name===p)return En(l,l.project);let d=await G("Loading your projects…",()=>zt({authUrl:t.authUrl,token:l.value})),m=Dd({projects:d,wanted:p}),f=await G(`Switching to ${m.name}…`,()=>xn({authUrl:t.authUrl,projectId:m.id,token:l.value}));return En(f,m)},Zs=async(e)=>{let{active:t,session:r}=e,n={...t.profile,project:r.project,username:r.user.name};await Xe({...t.config,profiles:{...t.config.profiles,[t.name]:n}}),await qp({profile:t.name,session:r})},Ds=async(e)=>{let{active:t,prompts:r}=e;if(!r.interactive)throw new E("`nipa login` needs a terminal to ask for your password",{hint:"Run it in a terminal, then run this command again."});let n=H(`(${new URL(t.profile.authUrl).host})`);T(`Logging in to ${P(t.name)} ${n}`);let o=await Ly({profile:t.profile,prompts:Ry(r),username:e.username,wantedProject:e.wantedProject});await Zs({active:t,session:o});let s=P(o.user.name);return Q(`Logged in as ${s}, project ${P(o.project.name)}`),o},Fd=async(e)=>{let{active:t,prompts:r}=e,n=await he(t.name);if(ne(n))return{active:t,session:n};let o=`Run \`${Cn(t.name)}\`.`;if(!r.interactive)throw n?new E(`your ${t.name} session expired`,{hint:o}):new E(`you aren't logged in to ${t.name}`,{hint:o});return T(n?"Your session expired.":"You aren't logged in yet."),{active:t,session:await Ds({active:t,prompts:r})}},Zy=(e)=>async(t)=>{try{return await t()}catch(r){if((r instanceof Ye||r instanceof ue?r.status:void 0)===401)throw new E(`your ${e} session expired or was revoked`,{hint:`Run \`${Cn(e)}\`.`});throw r}},Md=(e)=>{let{spaceUrl:t}=e.profile;if(!t)throw new E(`the ${e.name} profile has no Space API URL`,{hint:`Remove it with \`nipa profile rm ${e.name}\`, then add it again with \`--space-url\` and its Space portal URL. \`nipa -P ${e.name} os server list\` works without one.`});return t},Bd=(e)=>{let{active:t,session:r}=e.signedIn,n=Zy(t.name),o=Fp({projectId:r.project.id,region:t.profile.region,token:r.token,url:e.spaceUrl});return{active:t,session:r,space:{get:(s,i)=>n(async()=>{try{return await o.get(s,i)}catch(a){if(a instanceof kt)throw new E(a.message,{hint:"Check your network connection, or the profile's Space API URL."});throw a}})}}};var Gd=L({args:[],description:"Asks for your email and password, then for an OTP code when your account uses MFA. nipa saves a token for the current profile, scoped to a project, and reuses it until it expires.",examples:[{command:"nipa login",description:"Log in to the current profile"},{command:"nipa -P staging login",description:"Log in to the staging profile"}],flags:[{description:"Log in as this user instead of the last one",long:"username",short:"u",value:{kind:"text",name:"email"}},{description:"Use this project instead of the last one",long:"project",short:"p",value:{kind:"project"}}],name:"login",summary:"Log in with your password and an OTP code"});var Vd=j(Gd,async({client:e,flags:t})=>(await Ds({active:await e.profile(),prompts:e.prompts,username:t.username,wantedProject:t.project}),0));var Wd=L({args:[],description:"Revokes the current profile's token and deletes its session. nipa keeps your email and last project for the next login.",flags:[],name:"logout",summary:"Revoke the token and forget the session"});var Kd=j(Wd,async({client:e})=>{let t=await e.profile(),r=await he(t.name);if(!r)return Ve(`Not logged in to ${t.name}, so \`nipa logout\` did nothing`),0;if(ne(r))try{await G("Logging out…",()=>yn({authUrl:t.profile.authUrl,token:r.token}))}catch{}return await vn(t.name),Q(`Logged out of ${P(t.name)}`),0});var Jd=yt({aliases:["openstack"],description:"Runs `openstack <args...>` with the session. It's the same as `nipa exec openstack <args...>`.",examples:[{command:"nipa os volume list",description:"List the volumes in your project"}],name:"os",summary:"Run openstack with the session",target:{kind:"openstack"}});var Hd=_t(Jd,({args:e,client:t,command:r})=>Ct({args:e,command:r,signIn:t.cloud}));var Ns=L({args:[],flags:[le],name:"ls",summary:"List your profiles and who is logged in to each"}),Us=L({args:[{arity:"optional",name:"name",value:{kind:"text"}}],flags:[{description:"Keystone URL, ending in /v3",long:"auth-url",value:{kind:"text",name:"url"}},{description:"User domain (default: nipacloud)",long:"user-domain",value:{kind:"text",name:"domain"}},{description:"Region (default: NCP-TH)",long:"region",value:{kind:"text",name:"region"}},{description:"Space portal URL, such as https://space.nipa.cloud (default: production's for production's Keystone)",long:"space-url",value:{kind:"text",name:"url"}},{description:"Make it the current profile",long:"use",value:{kind:"none"}}],name:"add",summary:"Add a profile, asking for missing values"}),Fs=L({args:[{arity:"optional",name:"name",value:{kind:"profile"}}],flags:[],name:"use",summary:"Make a profile the current one"}),Ms=L({args:[{arity:"one",name:"name",value:{kind:"profile"}}],flags:[{...Xs,description:"Remove it without asking"}],name:"rm",summary:"Remove a profile and log out of it"}),qd=ze({default:"ls",description:"A profile is a Keystone URL, user domain, region and Space API URL with its own session. nipa starts with prod, which is Nipa Cloud production. Add a profile for staging or any other Keystone, then use it with `nipa profile use <name>` or `-P <name>`.",examples:[{command:"nipa profile add staging --auth-url https://keystone.example.com/v3",description:"Add a staging profile"},{command:"nipa profile use staging",description:"Make staging the current profile"}],name:"profile",subcommands:[Ns,Us,Fs,Ms],summary:"Manage Keystone profiles, such as staging"});var Dy=(e)=>(t)=>{if(!Ss.test(t))return"Use lowercase letters, digits and hyphens, starting with a letter";return e.profiles[t]?`A profile named ${t} already exists`:!0},Yd=(e)=>Be.shape.authUrl.safeParse(e).success||"Enter an http or https URL, such as https://keystone.example.com/v3",Qd="Enter the http or https URL of the Space portal, such as https://space.nipa.cloud",Ny=async(e)=>{if(e.flag!==void 0)return e.flag;if(e.authUrl===q.authUrl)return q.spaceUrl;if(!e.prompts.interactive)return;let t=await e.prompts.text({message:"Space portal URL (Enter to skip)",required:!1,validate:(r)=>r===""||Be.shape.authUrl.safeParse(r).success||Qd});return t===""?void 0:t},Xd=(e)=>{if(e.value!==void 0)return Promise.resolve(e.value);if(!e.prompts.interactive)throw Z(`missing ${e.flag}`,"Pass every value as a flag when there is no terminal.");return e.ask()},em=j(Us,async({args:e,client:t,flags:r})=>{let{prompts:n}=t,o=await fe(),s=Dy(o),i=await Xd({ask:()=>n.text({message:"Profile name",validate:s}),flag:"<name>",prompts:n,value:e.name}),a=s(i);if(a!==!0)throw Z(`can't add profile "${i}"`,a);let c=await Xd({ask:()=>n.text({message:"Keystone URL",validate:Yd}),flag:"--auth-url",prompts:n,value:r["auth-url"]}),u=Yd(c);if(u!==!0)throw Z(`invalid --auth-url "${c}"`,u);let l=r["user-domain"]??(n.interactive?await n.text({default:q.userDomain,message:"User domain"}):q.userDomain),p=r.region??(n.interactive?await n.text({default:q.region,message:"Region"}):q.region),d=await Ny({authUrl:c,flag:r["space-url"],prompts:n});if(d!==void 0&&!Be.shape.authUrl.safeParse(d).success)throw Z(`invalid --space-url "${d}"`,Qd);let m=d===void 0?void 0:pr(d),f=performance.now(),g=await G(`Checking ${c}…`,()=>Op(c));if(m!==void 0)await G(`Checking ${m}…`,()=>Up(m));let x={authUrl:c,region:p,spaceUrl:m,userDomain:l},y=r.use??(n.interactive&&await n.confirm({default:!0,message:`Use ${i} now?`}));await Xe({currentProfile:y?i:o.currentProfile,profiles:{...o.profiles,[i]:x}});let w=m===void 0?"":`, Space API ${new URL(m).host}`;if(Q(`Added profile ${P(i)} (Keystone ${g}${w})`,performance.now()-f),m===void 0)Ve(`${i} has no Space API URL, so \`nipa server ls\` and the other resource commands don't work with it. Pass \`--space-url\` with its Space portal URL when you add it.`);return T(y?`Now using ${P(i)}. Run \`nipa login\` to log in to it.`:`Run \`nipa login -P ${i}\` to log in to it.`),0});var tm=j(Ns,async({client:e,flags:t})=>{let r=await fe(),n=Object.keys(r.profiles).toSorted(),o=await Promise.all(n.map((i)=>he(i)));if(t.json)return e.stdout.json(n.map((i,a)=>{let c=o[a];return{current:i===r.currentProfile,loggedIn:ne(c),name:i,...r.profiles[i],user:ne(c)?c.user.name:void 0}})),0;let s=n.map((i,a)=>{let c=r.profiles[i]??q,u=o[a],l=ne(u)?`${u.user.name} (${u.project.name})`:"-";return[i,new URL(c.authUrl).host,c.region,l].map((p)=>({text:p}))});return T(`${n.length} ${n.length===1?"profile":"profiles"}`),ke({headings:["Name","Keystone","Region","Logged in as"],marks:n.map((i)=>i===r.currentProfile?Ir("✔"):" "),rows:s}),0});var rm=j(Ms,async({args:e,client:t,flags:r})=>{let{name:n}=e,o=await fe(),s=o.profiles[n];if(!s)throw new E(`no profile named "${n}"`);if(n===re)throw new E(`can't remove ${re}`,{hint:"nipa always has the Nipa Cloud production profile."});if(!r.yes){if(!t.prompts.interactive)throw Z(`removing ${n} needs confirmation`,"Add --yes to remove it without asking.");if(!await t.prompts.confirm({default:!1,message:`Remove profile ${n} and log out of it?`}))throw new E("Canceled",{exitCode:130})}let i=await he(n);if(ne(i))try{await yn({authUrl:s.authUrl,token:i.token})}catch{}await vn(n);let a=Object.fromEntries(Object.entries(o.profiles).filter(([u])=>u!==n)),c=o.currentProfile===n;if(await Xe({currentProfile:c?re:o.currentProfile,profiles:a}),Q(`Removed profile ${P(n)}`),c)T(`Now using ${P(re)}`);return 0});var nm=j(Fs,async({args:e,client:t})=>{let r=await fe(),n=Object.keys(r.profiles).toSorted(),{name:o}=e;if(o===void 0){if(!t.prompts.interactive)throw Z("missing <name>",`Your profiles: ${n.join(", ")}`);o=await t.prompts.choice({choices:n.map((s)=>({name:s===r.currentProfile?`${s} ${P("(current)")}`:s,value:s})),default:r.currentProfile,message:"Use profile:"})}if(!r.profiles[o])throw new E(`no profile named "${o}"`,{hint:`Your profiles: ${n.join(", ")}`});if(o===r.currentProfile)return Ve(`You're already using ${P(o)}`),0;return await Xe({...r,currentProfile:o}),Q(`Now using profile ${P(o)}`),0});var om=Ee(qd,{add:em,ls:tm,rm,use:nm});var Bs="List the servers in your project",Gs=L({aliases:["list"],args:[],flags:[le],name:"ls",summary:Bs}),sm=ze({aliases:["servers"],default:"ls",description:"Lists the servers in your project with their status, address, flavor and age. nipa calls the Space API, the one the Nipa Cloud Space portal uses, so you don't need the OpenStack client.",examples:[{command:"nipa server ls",description:Bs},{command:"nipa server ls --json | jq -r '.servers[].name'",description:"Print each server's name"}],name:"server",subcommands:[Gs],summary:Bs});var im=z({address:b()}),Uy=z({magnum_cluster_id:b().optional(),magnum_role:b().optional()}),Fy=z({created:b(),external_ips:me(im),flavor:z({name:b()}),id:b(),internal_ips:me(im),metadata:Uy.optional(),name:b(),status:b()}),My=z({instances:me(Fy)}),am=(e,t)=>({address:e.address,type:t,version:e.address.includes(":")?6:4}),By=(e={})=>e.magnum_cluster_id===void 0?null:{clusterId:e.magnum_cluster_id,role:e.magnum_role??null},Gy=(e)=>({addresses:[...e.internal_ips.map((t)=>am(t,"fixed")),...e.external_ips.map((t)=>am(t,"floating"))],createdAt:e.created,flavor:e.flavor.name,id:e.id,kubernetes:By(e.metadata),name:e.name,status:e.status}),cm=async(e)=>(await e.get("/v3/instances",My)).instances.map(Gy);var um=(e)=>{let t=e.addresses.filter((n)=>n.version===4);return(t.find((n)=>n.type==="floating")??t[0]??e.addresses[0])?.address},lm=(e)=>{if(!e.kubernetes)return{text:e.name};let t=e.kubernetes.role??"node";return{paint:(r)=>`${e.name}${H(r.slice(e.name.length))}`,text:`${e.name} (Kubernetes ${t})`}};var Vy=(e,t)=>{ke({headings:["Name","Status","Address","Flavor","Age"],rows:e.map((r)=>[lm(r),Ge(r.status),{text:um(r)??"-"},{text:r.flavor},{paint:We,text:xt(t-Date.parse(r.createdAt))}])})},pm=j(Gs,async({client:e,flags:t})=>{let{active:r,session:n,space:o}=await e.cloud(),{project:s}=n,i=performance.now(),a=await G(`Loading the servers in ${s.name}…`,()=>cm(o));if(t.json)return e.stdout.json({profile:r.name,project:s,servers:a}),0;let c=H(`[${we(performance.now()-i)}]`);if(a.length===0)return T(`No servers in ${P(s.name)} ${c}`),0;if(T(`Servers in ${P(s.name)} ${c}`),Vy(a,Date.now()),!e.stdout.isTTY)e.stdout.line(a.map((u)=>u.id).join(`
|
|
309
|
-
`));return 0});var
|
|
310
|
-
`)},
|
|
307
|
+
`},Do=(e)=>{let{program:t,shell:r}=e;switch(r){case"bash":return c$(t);case"zsh":return m$(t);case"fish":return b$(t);case"pwsh":return v$(t);default:return r}};var Nf=z({args:[{arity:"one",name:"kind",value:{choices:Tf,kind:"choice"}},{arity:"rest",name:"words",value:{kind:"text"}}],flags:[],name:"__complete",summary:"Print values for the completion scripts",updateNotice:!1});var $$=async(e)=>{let t=await e.profile(),r=await pe(t.name);if(!de(r))return[];return(await Ue({authUrl:t.profile.authUrl,token:r.token})).map((o)=>o.name)},Zf=async(e,t)=>{let r=await e.profile(),n=await pe(r.name),{spaceUrl:o}=r.profile;if(!(de(n)&&o))return[];let s=r.link?.link.project??n.project;return mf({connect:async()=>{let i=await sn({active:r,prompts:{...e.prompts,interactive:!1}});return jo({signedIn:i,spaceUrl:o}).space},kind:t,scope:`${r.name}:${s.id}`})},S$=async(e,t)=>{let r=_f(t);if(!r)return wf(t);let n=t.at(-1)??"";return(await Zf(e,r)).filter((s)=>s.startsWith(n))},k$=async(e)=>{let{client:t,kind:r,words:n}=e;switch(r){case"projects":return await $$(t);case"profiles":{let o=await ve();return Object.keys(o.profiles).toSorted()}case"openstack":return await S$(t,n);default:return await Zf(t,r)}},Uf=k(Nf,async({args:e,client:t})=>{let r=await k$({client:t,kind:e.kind,words:e.words});return t.stdout.write(r.map((n)=>`${n}
|
|
308
|
+
`).join("")),0});import{mkdir as P$,readFile as C$,writeFile as E$}from"node:fs/promises";import{homedir as z$}from"node:os";import St from"node:path";var Ff=Im(["bash","zsh","fish"]),No="completion.json",I$=v({path:m(),version:m()}),Mf=fw(Ff,I$),Bf=(e=process.env)=>{let t=St.basename(e.SHELL??"");switch(t){case"bash":case"zsh":case"fish":case"pwsh":return t;default:return}},un=(e)=>e.HOME??z$(),A$=(e,t=process.env)=>{switch(e){case"zsh":return St.join(t.ZDOTDIR??un(t),".zfunc","_nipa");case"bash":{let r=t.XDG_DATA_HOME??St.join(un(t),".local","share");return St.join(r,"bash-completion","completions","nipa")}case"fish":{let r=t.XDG_CONFIG_HOME??St.join(un(t),".config");return St.join(r,"fish","completions","nipa.fish")}default:return e}},Gf=(e,t=process.env)=>{let r=un(t);return e.startsWith(`${r}/`)?`~${e.slice(r.length)}`:e},Kf=async(e=process.env)=>{let t=St.join(e.ZDOTDIR??un(e),".zshrc");try{return(await C$(t,"utf-8")).includes(".zfunc")}catch{return!1}},Vf=async(e)=>{await P$(St.dirname(e.file),{recursive:!0}),await E$(e.file,Do({program:e.program,shell:e.shell}))},Wf=async(e)=>{let t=A$(e.shell);await Vf({file:t,program:e.program,shell:e.shell});let r=await He(No,Mf)??{};return await lt(No,{...r,[e.shell]:{path:t,version:e.version}}),t},T$=async(e)=>{let t=await He(No,Mf);if(!t)return;let r=Ff.options.flatMap((o)=>{let s=t[o];return s&&s.version!==e.version?[{file:s.path,shell:o}]:[]});if(r.length===0)return;await Promise.all(r.map(({file:o,shell:s})=>Vf({file:o,program:e.program,shell:s})));let n=r.map(({file:o,shell:s})=>[s,{path:o,version:e.version}]);await lt(No,{...t,...Object.fromEntries(n)})},Hf=async(e)=>{try{await T$(e)}catch(t){rr(`can't refresh the completion scripts: ${t instanceof Error?t.message:String(t)}`)}};var Jf=z({args:[{arity:"optional",name:"shell",value:{choices:Af,kind:"choice"}}],description:"Prints the tab completion script for bash, zsh, fish or PowerShell. Without a shell, nipa uses the one in $SHELL. Load the script from your shell's startup file, or save it with --install where the shell loads it, and nipa rewrites it when nipa updates.",examples:[{command:`echo 'eval "$(nipa completion zsh)"' >> ~/.zshrc`,description:"Load it each time zsh starts"},{command:"nipa completion --install",description:"Save it for the shell in $SHELL"}],flags:[{description:"Save it where the shell loads it, instead of printing it",long:"install",value:{kind:"none"}}],name:"completion",summary:"Print or install the tab completion script for your shell",updateNotice:!1});var qf=k(Jf,async({args:e,client:t,flags:r})=>{let n=e.shell??Bf();if(!n)throw Z("missing <shell>","Pass bash, zsh, fish or pwsh, such as `nipa completion zsh`.");if(!r.install)return t.stdout.write(Do({program:t.program,shell:n})),0;if(n==="pwsh")throw Z("can't install the completion for pwsh","PowerShell has no completion folder. Add `nipa completion pwsh | Out-String | Invoke-Expression` to your $PROFILE.");let o=await Wf({program:t.program,shell:n,version:dt.version});if(Q(`Installed the ${n} completion in ${Gf(o)}`),n==="zsh"&&!await Kf())w("Add `fpath=(~/.zfunc $fpath)` to ~/.zshrc before `compinit`, then open a new terminal.");else if(n==="bash")w("Open a new terminal to use it. It needs the bash-completion package.");else w("Open a new terminal to use it.");return 0});var Yf="List the databases in your project",aa=z({aliases:["list"],args:[],flags:[N],name:"ls",summary:Yf}),ca=z({args:[{arity:"one",name:"database",value:{kind:"resource",resource:"databases"}}],flags:[N],name:"inspect",summary:"Show a database's health, address, replicas, logs and backups"}),Xf=ee({aliases:["database","databases"],default:"ls",description:"Lists and inspects the database clusters in your project. These are Nipa Cloud's managed databases, which `nipa server ls` doesn't show. Name a database by its name or ID. `inspect` shows its status and health, where to connect, the ranges allowed to connect, its replicas, logs and recent backups, and ends with whether it's healthy.",examples:[{command:"nipa db ls",description:Yf},{command:"nipa db inspect orders",description:"Check whether orders is healthy and where to connect"},{command:"nipa db ls --json | jq -r '.databases[].name'",description:"Print each database's name"}],name:"db",subcommands:[aa,ca],summary:"List and inspect your databases"});var R$=new Set(["ACTIVE","AVAILABLE","COMPLETED","HEALTHY","IN-USE","ONLINE"]),j$=new Set(["DEGRADED","FAILED","OFFLINE","UNKNOWN"]),O$=new Set(["ATTACHING","BACKING-UP","BUILD","BUILDING","CREATING","DELETING","DETACHING","DOWNLOADING","EXTENDING","HARD_REBOOT","MIGRATING","NEW","PASSWORD","REBOOT","REBUILD","RESCUE","RESERVED","RESIZE","RESTORING-BACKUP","RETYPING","REVERT_RESIZE","UPLOADING","VERIFY_RESIZE"]),la=(e)=>{let t=e.toUpperCase();return j$.has(t)||t.startsWith("ERROR")||t.endsWith("FAILED")},L$=(e)=>{let t=e.toUpperCase();if(R$.has(t))return Vt;if(la(e))return Pe;if(O$.has(t)||t.startsWith("PENDING_"))return mt;return K},Fe=(e)=>{let t=e.toLowerCase().replaceAll(/[_-]/gu," ");return`${t.charAt(0).toUpperCase()}${t.slice(1)}`},H=(e)=>{let t=L$(e);return{paint:(r)=>`${t("●")}${r.slice(1)}`,text:`● ${Fe(e)}`}};var Qf=(e)=>e.toUpperCase()==="ACTIVE",eh=(e)=>e.toUpperCase()==="HEALTHY",th=(e)=>{let{primary:t}=e;if(!t)return[{field:"primary",name:null,part:"cluster",value:null}];let r=[];if(!Qf(t.status))r.push({field:"status",name:null,part:"primary",value:t.status});if(!eh(t.health))r.push({field:"health",name:null,part:"primary",value:t.health});for(let o of e.replicas??[])if(!Qf(o.status))r.push({field:"status",name:o.name,part:"replica",value:o.status});else if(!eh(o.health))r.push({field:"health",name:o.name,part:"replica",value:o.health});let[n]=e.backups??[];if(n&&la(n.status))r.push({field:"status",name:n.name,part:"backup",value:n.status});return r},rh=(e)=>{if(e.part==="cluster")return"the cluster has no primary yet";if(e.part==="backup"){let r=Fe(e.value??"");return r==="Failed"?`the latest backup, ${e.name}, failed`:`the latest backup, ${e.name}, is ${r}`}return`${e.part==="primary"?"the primary":e.name}'s ${e.field} is ${Fe(e.value??"")}`};var nh=5,da=(e,t)=>`${V(t-Date.parse(e))} ago`,pa=(e,t)=>t===null?e:`${e}:${t}`,ma=(e,t,r)=>{let n=H(e),o=n.paint?.(n.text)??n.text,s=t?` ${t}`:"";return{paint:()=>`${o}${s}${A(r)}`,text:`${n.text}${s}${r}`}},D$=(e,t)=>e.healthCheckedAt?ma(e.health,"",` (checked ${da(e.healthCheckedAt,t)})`):H(e.health),N$=(e,t)=>{let r={text:pa(e.address,t)};if(!e.externalAddress)return[r];let n=pa(e.externalAddress,t);return[De(n," (external)"),r]},Z$=(e)=>{let t=[e.status.toLowerCase()];if(e.publishedBytes>0){let r=Number((e.publishedBytes/1024/1024).toFixed(1));t.push(`${r} MB`)}return De(Fe(e.name),` (${t.join(", ")})`)},U$=(e,t)=>{let n=[...e.sizeGb===null?[]:[`${Number(e.sizeGb.toFixed(2))} GB`],da(e.createdAt,t)].join(", ");return ma(e.status,e.name,` (${n})`)},ua={paint:A,text:"Unavailable"},F$=(e)=>ma(e.status,e.name,e.address?` (${e.address})`:""),M$=(e)=>e.length===0?[{text:"None"}]:e.map(F$),B$=(e,t)=>{if(e.length===0)return[{text:"None"}];let r=e.slice(0,nh).map((o)=>U$(o,t)),n=e.length-nh;if(n>0)r.push({paint:A,text:`and ${n} more in --json`});return r},G$=(e,t,r)=>[{label:"Engine",lines:[{text:`${t.engine} ${t.version}`}]},{label:"Status",lines:[H(t.status)]},{label:"Health",lines:[D$(t,r)]},{label:"Flavor",lines:[Cn(t)]},{label:"Storage",lines:[{text:`${t.storageGb} GB`}]},{label:"Zone",lines:t.zone?[{text:t.zone}]:[]},{label:"Address",lines:N$(t,e.defaultPort)},{label:"Allowed CIDRs",lines:t.allowedCidrs.length===0?[{text:"None set"}]:t.allowedCidrs.map((n)=>({text:n}))},{label:"Replicas",lines:e.replicas?M$(e.replicas):[ua]},{label:"Logs",lines:e.logs?.map(Z$)??[ua]},{label:"Backups",lines:e.backups?B$(e.backups,r):[ua]}],K$=(e)=>["replicas","logs","backups"].filter((t)=>e[t]===null),V$=(e,t)=>[{label:"ID",lines:[{text:e.id}]},...e.primary?G$(e,e.primary,t):[{label:"Status",lines:[]}],{label:"Created",lines:[{paint:K,text:da(e.createdAt,t)}]}],W$=(e,t)=>{let r=x(e.name),n=K$(e);if(n.length>0)G(`The Space API didn't answer for the ${zt(n)} of ${r}, so the verdict leaves them out. Run the command again, or with --debug to see the requests.`);if(t.length>0){G(`${r} needs attention: ${zt(t.map(rh))}.`);return}let{primary:o}=e;if(o){let s=pa(o.externalAddress??o.address,e.defaultPort);w(`${r} is healthy. Connect to it at ${x(s)}.`)}},oh=k(ca,async({args:e,client:t,flags:r})=>{let{active:n,session:o,space:s}=await t.cloud(),{project:i}=o,a=performance.now(),c=await at({kind:ir,projectName:i.name,ref:e.database,space:s}),l=await I(`Loading the replicas, logs and backups of ${c.name}…`,()=>qm(s,c)),u=th(l);if(r.json)return t.stdout.json({database:{...l,problems:u},profile:n.name,project:i}),0;let p=A(`[${R(performance.now()-a)}]`);if(w(`Database ${x(l.name)} in ${x(i.name)} ${p}`),ft(V$(l,Date.now())),W$(l,u),!t.stdout.isTTY)t.stdout.line(l.id);return 0});var H$=(e,t)=>{M({headings:["Name","Engine","Status","Address","Flavor","Age"],rows:e.map(({createdAt:r,name:n,primary:o})=>[{text:n},{text:o?`${o.engine} ${o.version}`:"-"},o?H(o.status):{text:"-"},{text:o?o.externalAddress??o.address:"-"},{text:o?.flavor??"-"},{paint:K,text:V(t-Date.parse(r))}])})},sh=k(aa,async({client:e,flags:t})=>{let{active:r,session:n,space:o}=await e.cloud(),{project:s}=n,i=performance.now(),a=await I(`Loading the databases in ${s.name}…`,()=>wo(o));if(t.json)return e.stdout.json({databases:a,profile:r.name,project:s}),0;let c=A(`[${R(performance.now()-i)}]`);if(a.length===0)return w(`No databases in ${x(s.name)} ${c}`),0;if(w(`Databases in ${x(s.name)} ${c}`),H$(a,Date.now()),!e.stdout.isTTY)e.stdout.line(a.map((l)=>l.id).join(`
|
|
309
|
+
`));return 0});var ih=te(Xf,{inspect:oh,ls:sh});var J$="Run it again with --debug to see each request.",Zo=(e)=>{if(e instanceof E)return e;if(e instanceof ae||e instanceof ge){let t=e.status===0||e.status>=500;return new E(e.message,{hint:t&&!Ri()?J$:void 0})}if(e instanceof it)return new E(e.message,{hint:"Check the Keystone URL with `nipa profile ls`, or your network connection."});if(e instanceof Ot)return new E(e.message,{hint:"Fix the file, or delete it and run `nipa login` again."});return};var be=(e)=>({status:"pass",summary:e}),pn=(e,t)=>({hint:t,status:"warn",summary:e}),Ae=(e,t)=>({hint:t,status:"fail",summary:e}),q$=(e)=>({status:"skip",summary:e}),Ft=(e)=>`${e.charAt(0).toUpperCase()}${e.slice(1)}`,Y$=(e)=>e?.status==="pass"||e?.status==="warn",X$=async(e)=>{try{return await e()}catch(t){let r=t instanceof Error?Zo(t):void 0;if(!r)throw t;return Ae(Ft(r.message),r.hint)}},ah=async(e,t)=>{let r=e.checks[t.length];if(!r)return[...t];let n=new Map(t.map((c)=>[c.id,c])),o=r.needs?.find((c)=>!Y$(n.get(c))),s=e.checks.find((c)=>c.id===o)?.title??o,a={...o===void 0?await X$(()=>r.run(e.context,n)):q$(`Skipped because ${s} didn't pass`),id:r.id,title:r.title};return e.onReport?.(a),ah(e,[...t,a])},ch=(e)=>ah(e,[]),Q$=[["pass","passed"],["warn","warning"],["fail","failed"],["skip","skipped"]],lh=(e)=>Q$.flatMap(([t,r])=>{let n=e.filter((o)=>o===t).length;if(n===0)return[];return t==="warn"?[ke(n,r)]:[`${n} ${r}`]}).join(", ");import{existsSync as mS}from"node:fs";import{homedir as fS}from"node:os";import ba from"node:path";var eS=v({cpu_policy:m().nullish(),id:m(),name:m(),ram:X(),resource:m().nullish(),type:m().nullish(),vcpus:X()}),tS=v({machine_types:j(eS)}),rS=(e)=>({cpuPolicy:e.cpu_policy??null,id:e.id,name:e.name,ramMb:e.ram,type:e.type??null,vcpus:e.vcpus}),nS=(e,t)=>e.vcpus-t.vcpus||e.ramMb-t.ramMb||e.name.localeCompare(t.name),Uo=async(e)=>(await e.get("/v4/machine_types",tS)).machine_types.filter((r)=>r.resource!=="dbaas").map(rS).toSorted(nS);import{spawn as oS}from"node:child_process";import{once as sS}from"node:events";import{constants as uh}from"node:os";var fa=new Map([["openstack","Install it with `pipx install python-openstackclient`."],["terraform","Install it with `brew install hashicorp/tap/terraform`."]]),ar=async({args:e,command:t,signIn:r})=>{let n=pt(t);if(!n)throw new E(`command not found: ${t}`,{exitCode:127,hint:fa.get(t)});let{active:o,session:s}=await r(),i=oS(n,e,{env:gf(process.env,Co({profile:o.profile,session:s})),stdio:"inherit"}),a=!1,c=()=>{a=!0},l=()=>i.kill("SIGTERM");process.on("SIGINT",c),process.on("SIGTERM",l),await sS(i,"exit"),process.off("SIGINT",c),process.off("SIGTERM",l);let{exitCode:u,signalCode:p}=i;if(p)return 128+uh.signals[p];return a&&u===0?128+uh.signals.SIGINT:u??1};var Fo=Mt(dr(),1);var iS="https://github.com/PunGrumpy/nipa/releases",aS="https://api.github.com/repos/PunGrumpy/nipa/releases/latest",cS=86400000,dh=v({checkedAt:po.datetime(),latest:m()}),ha="update.json",lS=v({tag_name:m()}),ph=(e)=>e.replace(/^v/u,"").split("-")[0]?.split(".").map(Number)??[],mh=(e,t)=>{let r=ph(e),n=ph(t);for(let o=0;o<Math.max(r.length,n.length);o+=1){let s=(r[o]??0)-(n[o]??0);if(s!==0)return s>0}return!1},uS=(e)=>e.isTTY&&e.version!=="0.0.0"&&!e.env.CI&&!e.env.NIPA_NO_UPDATE_CHECK,pS=async()=>{try{let e=await Ve(aS,{signal:AbortSignal.timeout(1500)}),t=lS.safeParse(await e.json());return t.success?t.data.tag_name.replace(/^v/u,""):void 0}catch(e){rr(`update check failed: ${e instanceof Error?e.message:String(e)}`);return}},ga=(e)=>`${iS}/tag/v${e}`,fh=async(e)=>{let t=await He(ha,dh);return t&&mh(t.latest,e)?t.latest:void 0},dS=(e,t)=>{let r=ga(e),n=Fo.default.dim(`v${t}`),o=Fo.default.green(`v${e}`),s=[`Update available! ${n} ≫ ${o}`,`Release notes: ${Fo.default.cyan(r)}`],i=[`Update available! v${t} ≫ v${e}`,`Release notes: ${r}`],a=Math.max(...i.map((l)=>l.length)),c=(l,u)=>` │ ${l}${" ".repeat(a-u.length)} │`;return["",` ╭${"─".repeat(a+4)}╮`,...s.map((l,u)=>c(l,i[u]??l)),` ╰${"─".repeat(a+4)}╯`,""].join(`
|
|
310
|
+
`)},hh=async(e)=>{if(!uS({env:process.env,isTTY:process.stderr.isTTY===!0,version:e}))return;let t=await He(ha,dh);if(t&&mh(t.latest,e))oe(dS(t.latest,e));if(t&&Date.now()-Date.parse(t.checkedAt)<cS)return;let r=await pS();if(r){let n={checkedAt:new Date().toISOString(),latest:r};await lt(ha,n)}};var hS=(e)=>{let t=fS();return e.startsWith(`${t}${ba.sep}`)?`~${e.slice(t.length)}`:e},xa=async(e)=>{let t=performance.now(),r=await e();return{elapsed:R(performance.now()-t),value:r}},wa=(e)=>new URL(e).host,gh=1e4,gS=async()=>{try{await Promise.all([ve(),pe(fe)])}catch(o){if(o instanceof Ot)return Ae(Ft(o.message),"Fix the file, or delete it and run `nipa login` again.");throw o}let e=lf(),t=hS(ba.dirname(e[0]??"")),r=e.filter((o)=>mS(o));if(r.length===0)return be(`No files in ${t} yet, so nipa uses prod`);let n=r.map((o)=>ba.basename(o)).join(" and ");return be(`${n} in ${t} ${r.length===1?"is":"are"} valid`)},yS={config:()=>"the current profile",env:()=>"from NIPA_PROFILE",flag:()=>"from --profile",link:(e)=>`from ${e.link?ye(e.link.file):"the folder's link"}`},bS=async(e)=>{let t=await e.profile(),r=wa(t.profile.authUrl);return be(`${t.name} (${r}), ${yS[t.source](t)}`)},xS=async(e)=>{let{profile:t}=await e.profile();try{let{elapsed:r,value:n}=await xa(()=>ho(t.authUrl));return be(`${wa(t.authUrl)} answers as Keystone ${n} [${r}]`)}catch(r){if(r instanceof it||r instanceof ae)return Ae(Ft(r.message),"Check the Keystone URL with `nipa profile ls`, or your network connection.");throw r}},wS=async(e)=>{let t=await e.profile(),r=t.profile.spaceUrl;if(!r){let{hint:n,message:o}=sa(t);return pn(Ft(o),n)}try{let{elapsed:n}=await xa(()=>go(r));return be(`${wa(r)} answers as the Space API [${n}]`)}catch(n){if(n instanceof it)return Ae(Ft(n.message),"Check your network connection, or the profile's Space API URL.");if(n instanceof ge)return Ae(Ft(n.message),"Check the profile's `spaceUrl` with `nipa profile ls --json`. It's the portal URL with /api, such as https://space.nipa.cloud/api.");throw n}},_S=async(e)=>{let{name:t}=await e.profile(),r=await e.session(),n=`Run \`${Je(t)}\`.`;if(!r)return Ae(`You aren't logged in to ${t}`,n);if(!de(r))return Ae(`Your ${t} session expired`,n);let o=Lt(r),s=`Logged in as ${r.user.name} to ${r.project.name}, expires in ${Kt(o)}`;return o<oa?pn(s,`Run \`${Je(t)}\` to start a new one.`):be(s)},vS=async(e,t)=>{let r=await e.profile(),n=await e.session();if(!n)return Ae(`You aren't logged in to ${r.name}`);let o=`Run \`${Je(r.name)}\`.`,{spaceUrl:s}=r.profile,i=s&&t.get("space")?.status==="pass";try{let{elapsed:a}=await xa(async()=>{if(await Ue({authUrl:r.profile.authUrl,signal:AbortSignal.timeout(gh),token:n.token}),i)await Uo(yo({projectId:n.project.id,region:r.profile.region,signal:AbortSignal.timeout(gh),token:n.token,url:s}))});return be(`${i?"Keystone and the Space API accept":"Keystone accepts"} the token [${a}]`)}catch(a){if(a instanceof ae&&a.status===401)return Ae("Keystone refuses the token, so it was revoked",o);if(a instanceof ge&&a.status===401)return Ae("The Space API refuses the token that Keystone accepts","The Space API may belong to another Keystone. Check the profile's `authUrl` and `spaceUrl` with `nipa profile ls --json`.");throw a}},$S=async(e,t)=>{let r=await Nt();if(!r)return be("This folder isn't linked");let n=await e.profile(),o=ye(r.file),{profile:s,project:i}=r.link;if(s!==n.name)return be(`${o} links ${s}, which this run doesn't use`);let a=await e.session();if(!a||t.get("token")?.status!=="pass")return be(`${o} links ${i.name}`);if(i.id===a.project.id)return be(`${o} links ${i.name}, the session's project`);return(await Ue({authUrl:n.profile.authUrl,token:a.token})).some((l)=>l.id===i.id)?be(`${o} links ${i.name}, so commands here switch to it for each run`):Ae(`${o} links ${i.name}, which your account can't use`,"Run `nipa link` to pick another project.")},yh=[{command:"openstack",runner:"nipa os"},{command:"terraform",runner:"nipa tf"}],ya=(e)=>e.join(" and "),SS=()=>{let e=yh.filter(({command:o})=>!pt(o));if(e.length===0)return Promise.resolve(be(`Found ${ya(yh.map(({command:o})=>o))}`));let t=ya(e.map(({command:o})=>o)),r=ya(e.map(({runner:o})=>`\`${o}\``)),n=e.map(({command:o})=>fa.get(o)).join(" ");return Promise.resolve(pn(`Can't find ${t}, so ${r} won't run`,n))},kS=async(e)=>{let t=await fh(e.version);if(!t)return be(`You have nipa ${e.version}`);return pn(`nipa ${t} is out, and you have ${e.version}`,`Run \`npm install -g nipa-cli\`, or download it from ${ga(t)}.`)},_a=[{id:"config",run:gS,title:"Config files"},{id:"profile",needs:["config"],run:bS,title:"Profile"},{id:"keystone",needs:["profile"],run:xS,title:"Keystone"},{id:"space",needs:["profile"],run:wS,title:"Space API"},{id:"session",needs:["profile"],run:_S,title:"Session"},{id:"token",needs:["keystone","session"],run:vS,title:"Token"},{id:"link",needs:["profile"],run:$S,title:"Linked folder"},{id:"tools",run:SS,title:"Tools"},{id:"update",run:kS,title:"Update"}];var bh=z({args:[],description:"Checks the config files, the profile, Keystone, the Space API, the session and its token, the folder's link, openstack and terraform, and the last update check, then says how to fix each problem. It changes nothing and never asks for a password. It exits with code 1 when a check fails.",examples:[{command:"nipa doctor",description:"Check the current profile"},{command:"nipa -P staging doctor --json",description:"Check the staging profile and print JSON"}],flags:[N],name:"doctor",summary:"Check your setup and say what to fix",updateNotice:!1});var PS={fail:{glyph:"✖",paint:Pe},pass:{glyph:"✔",paint:Vt},skip:{glyph:"-",paint:A},warn:{glyph:"!",paint:mt}},xh=Math.max(..._a.map((e)=>e.title.length)),wh=" ",CS=(e)=>{let{glyph:t,paint:r}=PS[e.status],n=x(e.title.padEnd(xh)),o=e.status==="skip"?A(e.summary):e.summary;if(oe(`${r(t)} ${n}${wh}${o}`),"hint"in e&&e.hint){let s=" ".repeat(2+xh+wh.length);oe(`${s}${A(">")} ${e.hint}`)}},_h=k(bh,async({client:e,flags:t})=>{let r=e.profileWithoutBrokenLink,n={profile:r,session:async()=>{let s=await r();return pe(s.name)},version:dt.version},o=await ch({checks:_a,context:n,onReport:t.json?void 0:CS});if(t.json){let i=o.some((a)=>a.id==="profile"&&a.status==="pass")?await r():void 0;e.stdout.json({checks:o.map((a)=>({hint:"hint"in a&&a.hint||null,id:a.id,status:a.status,summary:a.summary,title:a.title})),profile:i?.name??null})}else oe(""),w(lh(o.map((s)=>s.status)));return o.some((s)=>s.status==="fail")?1:0});var vh=z({args:[],description:'Prints the session\'s OS_* variables as shell commands. Load them with `eval "$(nipa env)"` in bash or zsh, or with `nipa env | source` in fish.',flags:[{description:"Shell syntax to print (default: from $SHELL)",long:"shell",value:{choices:Qi,kind:"choice"}}],name:"env",summary:"Print the OS_* variables for your shell"});var $h=k(vh,async({client:e,flags:t})=>{let r=t.shell??bf(process.env.SHELL),{active:n,session:o}=await e.session();return e.stdout.line(yf(Co({profile:n.profile,session:o}),r)),0});var Sh=Wt({description:"Runs a command with the session's OS_* variables. nipa removes any OS_* variable already in your shell first, so a stale OS_PASSWORD from an old openrc can't override the token. nipa exits with the command's exit code.",examples:[{command:"nipa exec ansible-playbook site.yml",description:"Run an Ansible playbook"}],name:"exec",summary:"Run any command with the session",target:{kind:"command"}});var kh=Ht(Sh,({args:e,client:t,command:r})=>ar({args:e,command:r,signIn:t.cloud}));var va="List the flavors a server can have",$a=z({aliases:["list"],args:[],flags:[N],name:"ls",summary:va}),Ph=ee({aliases:["flavors","machine-types"],default:"ls",description:"Lists the flavors a server can have, smallest first, with their vCPUs, RAM and type. The Space portal calls them machine types. The ones only database clusters use don't show.",examples:[{command:"nipa flavor ls",description:va},{command:"nipa flavor ls --json | jq -r '.flavors[] | select(.vcpus == 4) | .name'",description:"Print the flavors with 4 vCPUs"}],name:"flavor",subcommands:[$a],summary:va});var ES=(e)=>{M({headings:["Name","vCPUs","RAM","Type"],rows:e.map((t)=>[{text:t.name},{text:String(t.vcpus)},{text:Pr(t.ramMb)},{text:t.type??"-"}])})},Ch=k($a,async({client:e,flags:t})=>{let{active:r,session:n,space:o}=await e.cloud(),{project:s}=n,i=performance.now(),a=await I(`Loading the flavors in ${s.name}…`,()=>Uo(o));if(t.json)return e.stdout.json({flavors:a,profile:r.name,project:s}),0;let c=A(`[${R(performance.now()-i)}]`);if(a.length===0)return w(`No flavors in ${x(s.name)} ${c}`),0;if(w(`Flavors in ${x(s.name)} ${c}`),ES(a),!e.stdout.isTTY)e.stdout.line(a.map((l)=>l.name).join(`
|
|
311
|
+
`));return 0});var Eh=te(Ph,{ls:Ch});var Sa="List the external IPs in your project",ka=z({aliases:["list"],args:[],flags:[N],name:"ls",summary:Sa}),zh=ee({aliases:["ips"],default:"ls",description:"Lists the external IPs in your project with their status, the internal IP each one forwards to, zone and name. An IP without an internal IP isn't attached to anything.",examples:[{command:"nipa ip ls",description:Sa},{command:"nipa ip ls --json | jq -r '.ips[] | select(.internalAddress == null) | .address'",description:"Print the IPs that aren't attached"}],name:"ip",subcommands:[ka],summary:Sa});var zS=(e)=>{M({headings:["Address","Status","Internal IP","Zone","Name"],rows:e.map((t)=>[{text:t.address},H(t.status),{text:t.internalAddress??"-"},{text:t.zone},{text:t.name}])})},Ih=k(ka,async({client:e,flags:t})=>{let{active:r,session:n,space:o}=await e.cloud(),{project:s}=n,i=performance.now(),a=await I(`Loading the external IPs in ${s.name}…`,()=>_o(o));if(t.json)return e.stdout.json({ips:a,profile:r.name,project:s}),0;let c=A(`[${R(performance.now()-i)}]`);if(a.length===0)return w(`No external IPs in ${x(s.name)} ${c}`),0;if(w(`External IPs in ${x(s.name)} ${c}`),zS(a),!e.stdout.isTTY)e.stdout.line(a.map((l)=>l.address).join(`
|
|
312
|
+
`));return 0});var Ah=te(zh,{ls:Ih});var Pa="List the Kubernetes clusters in your project",Ca=z({aliases:["list"],args:[],flags:[N],name:"ls",summary:Pa}),Th=ee({aliases:["kubernetes","coe"],default:"ls",description:"Lists the Kubernetes clusters in your project with their Kubernetes version, nodes, active node count and age. The Space API has no Kubernetes endpoint, and `nipa os coe` can't find Magnum on Nipa Cloud production, so nipa finds each cluster through the servers Magnum made for it. A cluster without servers doesn't show.",examples:[{command:"nipa k8s ls",description:Pa},{command:"nipa k8s ls --json | jq -r '.clusters[0].nodes[].name'",description:"Print the node names of the newest cluster"}],name:"k8s",subcommands:[Ca],summary:Pa});var IS=(e,t)=>{let r=Number(t.role==="master")-Number(e.role==="master");return r===0?e.name.localeCompare(t.name):r},AS=(e)=>{let t=new Map;for(let r of e){if(!r.kubernetes)continue;let{clusterId:n,role:o,version:s}=r.kubernetes,i=t.get(n)??{createdAt:r.createdAt,id:n,nodes:[],version:null};if(i.nodes.push({id:r.id,name:r.name,role:o,status:r.status}),i.version??=s,Date.parse(r.createdAt)<Date.parse(i.createdAt))i.createdAt=r.createdAt;t.set(n,i)}return[...t.values()].map((r)=>({...r,nodes:r.nodes.toSorted(IS)})).toSorted((r,n)=>Date.parse(n.createdAt)-Date.parse(r.createdAt))},Rh=async(e)=>AS(await We(e));var TS=(e)=>{let t=new Map;for(let r of e.nodes){let n=r.role??"node";t.set(n,(t.get(n)??0)+1)}return[...t].map(([r,n])=>ke(n,r)).join(", ")},RS=(e)=>`${e.nodes.filter((r)=>r.status==="ACTIVE").length} of ${e.nodes.length}`,jS=(e,t)=>{M({headings:["Cluster","Version","Nodes","Active","Age"],rows:e.map((r)=>[{text:r.id},{text:r.version??"-"},{text:TS(r)},{text:RS(r)},{paint:K,text:V(t-Date.parse(r.createdAt))}])})},jh=k(Ca,async({client:e,flags:t})=>{let{active:r,session:n,space:o}=await e.cloud(),{project:s}=n,i=performance.now(),a=await I(`Loading the Kubernetes clusters in ${s.name}…`,()=>Rh(o));if(t.json)return e.stdout.json({clusters:a,profile:r.name,project:s}),0;let c=A(`[${R(performance.now()-i)}]`);if(a.length===0)return w(`No Kubernetes clusters in ${x(s.name)} ${c}`),0;if(w(`Kubernetes clusters in ${x(s.name)} ${c}`),jS(a,Date.now()),!e.stdout.isTTY)e.stdout.line(a.map((l)=>l.id).join(`
|
|
313
|
+
`));return 0});var Oh=te(Th,{ls:jh});var Lh="List the load balancers in your project",Ea=z({aliases:["list"],args:[],flags:[N],name:"ls",summary:Lh}),za=z({args:[{arity:"one",name:"lb",value:{kind:"resource",resource:"load-balancers"}}],flags:[N],name:"inspect",summary:"Show a load balancer's listeners, backend groups and members"}),Dh=ee({aliases:["loadbalancer","loadbalancers"],default:"ls",description:"Lists and inspects the load balancers in your project. Name a load balancer by its name or ID. `inspect` shows each listener, backend group and member with its status, and ends with what stops the load balancer from serving, such as a listener in error or members that are down.",examples:[{command:"nipa lb ls",description:Lh},{command:"nipa lb inspect web-lb",description:"Show why web-lb isn't serving"},{command:"nipa lb ls --json | jq -r '.loadBalancers[].address'",description:"Print each load balancer's virtual IP"}],name:"lb",subcommands:[Ea,za],summary:"List and inspect your load balancers"});var Ia="Backend group",Aa=(e,t)=>({paint:wt(e)?void 0:Pe,text:t??e.id}),Ta=(e)=>[H(e.status),H(e.health)],OS=(e,t)=>{let r=`${V(t-Date.parse(e.createdAt))} ago`;return[{label:"ID",lines:[{text:e.id}]},{label:"Status",lines:[H(e.status)]},{label:"Health",lines:[H(e.health)]},{label:"Address",lines:[{text:e.address}]},{label:"External IP",lines:e.externalAddress?[{text:e.externalAddress}]:[]},{label:"Flavor",lines:e.flavor?[{text:e.flavor}]:[]},{label:"Created",lines:[{paint:K,text:r}]}]},LS=(e,t)=>{let r=(n)=>{let o=t.find((s)=>s.id===n);return o?o.name??o.id:"-"};w(ke(e.length,"listener")),M({headings:["Listener","Port","Status","Health","Allowed CIDRs",Ia],rows:e.map((n)=>[Aa(n,n.name),{text:`${n.protocol}:${n.port}`},...Ta(n),{text:n.allowedCidrs.join(", ")||"Any"},{text:r(n.backendGroupId)}])})},DS=(e)=>{if(!e)return{text:"-"};let t=e.maxRetries===1?"retry":"retries",r=`${e.type} every ${e.delaySeconds}s, ${e.timeoutSeconds}s timeout, ${e.maxRetries} ${t}`;if(wt(e))return{text:r};let n=`${Fe(e.status)}, ${Fe(e.health)}`;return{paint:Pe,text:`${r} (${n})`}},NS=(e)=>{w(ke(e.length,"backend group")),M({headings:[Ia,"Algorithm","Status","Health","Members","Health check"],rows:e.map((t)=>[Aa(t,t.name),{text:t.algorithm},...Ta(t),{text:String(t.members.length)},DS(t.healthCheck)])})},ZS=(e)=>{let t=e.flatMap((r)=>r.members.map((n)=>({group:r,member:n})));w(ke(t.length,"member")),M({headings:["Member","Address",Ia,"Weight","Backup","Status","Health"],rows:t.map(({group:r,member:n})=>[Aa(n,n.name),{text:`${n.address}:${n.port}`},{text:r.name??r.id},{text:n.weight===null?"-":String(n.weight)},{text:n.backup?"Yes":"No"},...Ta(n)])})},Nh=k(za,async({args:e,client:t,flags:r})=>{let{active:n,session:o,space:s}=await t.cloud(),{project:i}=o,a=performance.now(),{id:c,name:l}=await at({kind:sr,projectName:i.name,ref:e.lb,space:s}),u=await I(`Loading ${l}'s listeners and members…`,()=>Qm(s,c));if(r.json)return t.stdout.json({loadBalancer:u,profile:n.name,project:i}),0;let p=A(`[${R(performance.now()-a)}]`);if(w(`Load balancer ${x(l)} in ${x(i.name)} ${p}`),ft(OS(u,Date.now())),u.listenerDetails.length>0)LS(u.listenerDetails,u.backendGroups);let d=u.backendGroups;if(d.length>0)NS(d);if(d.some((b)=>b.members.length>0))ZS(d);let{details:f,healthy:h,verdict:y}=ef(u);(h?w:G)(`${y}.`);for(let b of f)w(`${b}.`);if(!t.stdout.isTTY)t.stdout.line(c);return 0});var US=(e,t)=>{M({headings:["Name","Status","Health","Address","Listeners","Age"],rows:e.map((r)=>[{text:r.name},H(r.status),H(r.health),{text:r.address},{text:String(r.listeners)},{paint:K,text:V(t-Date.parse(r.createdAt))}])})},Zh=k(Ea,async({client:e,flags:t})=>{let{active:r,session:n,space:o}=await e.cloud(),{project:s}=n,i=performance.now(),a=await I(`Loading the load balancers in ${s.name}…`,()=>vo(o));if(t.json)return e.stdout.json({loadBalancers:a,profile:r.name,project:s}),0;let c=A(`[${R(performance.now()-i)}]`);if(a.length===0)return w(`No load balancers in ${x(s.name)} ${c}`),0;if(w(`Load balancers in ${x(s.name)} ${c}`),US(a,Date.now()),!e.stdout.isTTY)e.stdout.line(a.map((l)=>l.id).join(`
|
|
314
|
+
`));return 0});var Uh=te(Dh,{inspect:Nh,ls:Zh});import Mh from"node:path";var Fh=z({args:[{arity:"optional",name:"project",value:{kind:"project"}}],description:"Links this folder to a project, by name or ID, like the Vercel CLI's `vercel link`. nipa saves the profile and the project in .nipa/project.json, and every command in this folder and the folders below it uses them, without changing the project other folders use. Without a project, nipa lists your projects to pick from.",examples:[{command:"nipa -P staging link Prototype",description:"Use staging's Prototype project in this folder"},{command:"nipa tf plan",description:"Run terraform with the linked project"}],flags:[],name:"link",summary:"Use a project in this folder"});var Bh=k(Fh,async({args:e,client:t})=>{let{project:r}=e,{active:n,session:o}=await t.savedSession(),s=await I("Loading your projects…",()=>Ue({authUrl:n.profile.authUrl,token:o.token}));if(r===void 0&&!t.prompts.interactive)throw new E("tell nipa which project to link",{exitCode:2,hint:`Run \`nipa link <project>\`. Your projects: ${s.map((d)=>d.name).join(", ")}`});let i=process.cwd(),a=n.link?.link.project??o.project,c=await Ro({ask:To({current:a,message:"Link to:",prompts:t.prompts}),projects:s,wanted:r});if(n.link&&Mh.dirname(Mh.dirname(n.link.file))===i&&n.link?.link.project.id===c.id)return G(`This folder is already linked to ${x(c.name)}`),0;let u=await Pf({dir:i,link:{profile:n.name,project:c}}),p=A(`(${n.name})`);return Q(`Linked ${ye(u)} to ${x(c.name)} ${p}`),w(`Commands in this folder now use ${c.name}. Run \`nipa unlink\` to stop.`),0});var Gh=z({args:[],description:"Asks for your email and password, then for an OTP code when your account uses MFA. nipa saves a token for the current profile, scoped to a project, and reuses it until Keystone expires it after 24 hours. With `--remember`, nipa saves your password in the macOS Keychain or Linux's secret service, and later logins ask only for an OTP code. `nipa logout` deletes it.",examples:[{command:"nipa login",description:"Log in to the current profile"},{command:"nipa -P staging login",description:"Log in to the staging profile"},{command:"nipa login --remember",description:"Log in, and ask only for an OTP code next time"}],flags:[{description:"Log in as this user instead of the last one",long:"username",short:"u",value:{kind:"text",name:"email"}},{description:"Use this project instead of the last one",long:"project",short:"p",value:{kind:"project"}},{description:"Save your password in the OS keychain for the next login",long:"remember",value:{kind:"none"}}],name:"login",summary:"Log in with your password and an OTP code"});var Kh=k(Gh,async({client:e,flags:t})=>(await na({active:await e.profile(),prompts:e.prompts,remember:t.remember,username:t.username,wantedProject:t.project}),0));var Vh=z({args:[],description:"Revokes the current profile's token and deletes its session. nipa keeps your email and last project for the next login.",flags:[],name:"logout",summary:"Revoke the token and forget the session"});var Wh=k(Vh,async({client:e})=>{let t=await e.profile(),r=await pe(t.name),n=await Io(t.profile);if(r){if(de(r))try{await I("Logging out…",()=>fo({authUrl:t.profile.authUrl,token:r.token}))}catch{}if(await Po(t.name),Q(`Logged out of ${x(t.name)}`),n)w("Deleted your saved password.")}else if(n)Q(`Deleted your saved password for ${x(t.name)}`);else G(`Not logged in to ${t.name}, so \`nipa logout\` did nothing`);return 0});var Ra="List the networks in your project",ja=z({aliases:["list"],args:[],flags:[N],name:"ls",summary:Ra}),Hh=ee({aliases:["networks"],default:"ls",description:"Lists the networks your project can use with their status, type, zone and age. A VPC network is one of your project's private networks, and an external network is a shared pool of external IPs.",examples:[{command:"nipa network ls",description:Ra},{command:"nipa network ls --json | jq -r '.networks[] | select(.external | not) | .name'",description:"Print the names of your VPC networks"}],name:"network",subcommands:[ja],summary:Ra});var FS=(e,t)=>{M({headings:["Name","Status","Type","Zone","Age"],rows:e.map((r)=>[{text:r.name},H(r.status),{text:r.external?"external":"VPC"},{text:r.zone??"-"},{paint:K,text:V(t-Date.parse(r.createdAt))}])})},Jh=k(ja,async({client:e,flags:t})=>{let{active:r,session:n,space:o}=await e.cloud(),{project:s}=n,i=performance.now(),a=await I(`Loading the networks in ${s.name}…`,()=>$o(o));if(t.json)return e.stdout.json({networks:a,profile:r.name,project:s}),0;let c=A(`[${R(performance.now()-i)}]`);if(a.length===0)return w(`No networks in ${x(s.name)} ${c}`),0;if(w(`Networks in ${x(s.name)} ${c}`),FS(a,Date.now()),!e.stdout.isTTY)e.stdout.line(a.map((l)=>l.id).join(`
|
|
315
|
+
`));return 0});var qh=te(Hh,{ls:Jh});import{spawn as MS}from"node:child_process";import{once as BS}from"node:events";var GS=(e,t)=>{switch(e){case"darwin":return{args:[t],command:"open"};case"win32":return{args:["/c","start",'""',t.replaceAll("&","^&")],command:"cmd",verbatim:!0};default:return{args:[t],command:"xdg-open"}}},KS=async({args:e,command:t,verbatim:r})=>{let n=MS(t,e,{detached:!0,stdio:"ignore",windowsVerbatimArguments:r});await BS(n,"spawn"),n.unref()},Yh=async(e,t={})=>{let r=GS(t.platform??process.platform,e),n=t.launch??KS;try{await n(r)}catch{throw new E(`couldn't open a browser with ${r.command}`,{hint:"Open the URL above in your browser, or add `--url` to print only the URL."})}};var VS=["server","volume","network","sg","lb","db"],Xh=z({args:[{arity:"optional",name:"resource",value:{choices:VS,kind:"choice"}},{arity:"optional",name:"name",value:{kind:"text"}}],description:"Opens the Nipa Cloud Space portal of the profile this run uses, like the Vercel CLI's `vercel open`. Name a kind of resource, `server`, `volume`, `network`, `sg`, `lb` or `db`, to open its list, and a name or ID after it to open that resource's page, which needs a session. The portal keeps its own login and opens the project you last used in it, so a link can't pick the project. When the output goes to a pipe, or with `--url`, nipa prints only the URL and doesn't open a browser.",examples:[{command:"nipa open",description:"Open the Space portal"},{command:"nipa open server web-1",description:"Open web-1's page"},{command:"nipa open lb",description:"Open the list of load balancers"},{command:"nipa open db orders --url",description:"Print the orders database's URL"}],flags:[{description:"Print the URL instead of opening a browser",long:"url",value:{kind:"none"}}],name:"open",summary:"Open the Space portal in your browser"});var cr=(e,t,r)=>({find:async(n)=>{let o=await at({...n,kind:t});return{name:o.name||o.id,path:r(o)}},list:e}),Oa={db:cr("/sql_databases",ir,(e)=>`/sql_databases/${e.id}/overview`),lb:cr("/load_balancers",sr,(e)=>`/load_balancers/${e.id}/details`),network:cr("/networks",ko,(e)=>`/networks/${e.id}`),server:cr("/compute_instances",Qr,(e)=>`/compute_instances/${e.id}/overview`),sg:cr("/security_group",or,(e)=>`/security_group/${e.id}`),volume:cr("/volumes",So,(e)=>`/volumes?search=${encodeURIComponent(e.name||e.id)}`)},Qh="/project";var WS=async(e,t,r)=>{if(t!==void 0&&r!==void 0){let{active:s,session:i,space:a}=await e.cloud(),c=i.project.name;return{path:(await Oa[t].find({projectName:c,ref:r,space:a})).path,projectName:c,spaceUrl:an(s)}}let n=await e.profile(),o=an(n);return Ao(n),{path:t===void 0?Qh:Oa[t].list,projectName:n.link?.link.project.name??n.profile.project?.name,spaceUrl:o}},eg=k(Xh,async({args:e,client:t,flags:r})=>{let n=await WS(t,e.resource,e.name),o=`${Km(n.spaceUrl)}${n.path}`;if(r.url||!t.stdout.isTTY)return t.stdout.line(o),0;if(w(`Opening ${Es(o)}`),await Yh(o),n.projectName)w(`The portal opens the project you last used in it. Switch to ${x(n.projectName)} there if it shows another one.`);return 0});var tg=Wt({aliases:["openstack"],description:"Runs `openstack <args...>` with the session. It's the same as `nipa exec openstack <args...>`.",examples:[{command:"nipa os volume list",description:"List the volumes in your project"}],name:"os",summary:"Run openstack with the session",target:{kind:"openstack"}});var rg=Ht(tg,({args:e,client:t,command:r})=>ar({args:e,command:r,signIn:t.cloud}));var La=z({args:[],flags:[N],name:"ls",summary:"List your profiles and who is logged in to each"}),Da=z({args:[{arity:"optional",name:"name",value:{kind:"text"}}],flags:[{description:"Keystone URL, ending in /v3",long:"auth-url",value:{kind:"text",name:"url"}},{description:"User domain (default: nipacloud)",long:"user-domain",value:{kind:"text",name:"domain"}},{description:"Region (default: NCP-TH)",long:"region",value:{kind:"text",name:"region"}},{description:"Space portal URL, such as https://space.nipa.cloud (default: production's for production's Keystone)",long:"space-url",value:{kind:"text",name:"url"}},{description:"Make it the current profile",long:"use",value:{kind:"none"}}],name:"add",summary:"Add a profile, asking for missing values"}),Na=z({args:[{arity:"optional",name:"name",value:{kind:"profile"}}],flags:[],name:"use",summary:"Make a profile the current one"}),Za=z({args:[{arity:"one",name:"name",value:{kind:"profile"}}],flags:[{...mr,description:"Remove it without asking"}],name:"rm",summary:"Remove a profile and log out of it"}),ng=ee({default:"ls",description:"A profile is a Keystone URL, user domain, region and Space API URL with its own session. nipa starts with prod, which is Nipa Cloud production. Add a profile for staging or any other Keystone, then use it with `nipa profile use <name>` or `-P <name>`.",examples:[{command:"nipa profile add staging --auth-url https://keystone.example.com/v3",description:"Add a staging profile"},{command:"nipa profile use staging",description:"Make staging the current profile"}],name:"profile",subcommands:[La,Da,Na,Za],summary:"Manage Keystone profiles, such as staging"});var HS=(e)=>(t)=>{if(!Vi.test(t))return"Use lowercase letters, digits and hyphens, starting with a letter";return e.profiles[t]?`A profile named ${t} already exists`:!0},og=(e)=>ct.shape.authUrl.safeParse(e).success||"Enter an http or https URL, such as https://keystone.example.com/v3",ig="Enter the http or https URL of the Space portal, such as https://space.nipa.cloud",JS=async(e)=>{if(e.flag!==void 0)return e.flag;if(e.authUrl===me.authUrl)return me.spaceUrl;if(!e.prompts.interactive)return;let t=await e.prompts.text({message:"Space portal URL (Enter to skip)",required:!1,validate:(r)=>r===""||ct.shape.authUrl.safeParse(r).success||ig});return t===""?void 0:t},sg=(e)=>{if(e.value!==void 0)return Promise.resolve(e.value);if(!e.prompts.interactive)throw Z(`missing ${e.flag}`,"Pass every value as a flag when there is no terminal.");return e.ask()},ag=k(Da,async({args:e,client:t,flags:r})=>{let{prompts:n}=t,o=await ve(),s=HS(o),i=await sg({ask:()=>n.text({message:"Profile name",validate:s}),flag:"<name>",prompts:n,value:e.name}),a=s(i);if(a!==!0)throw Z(`can't add profile "${i}"`,a);let c=await sg({ask:()=>n.text({message:"Keystone URL",validate:og}),flag:"--auth-url",prompts:n,value:r["auth-url"]}),l=og(c);if(l!==!0)throw Z(`invalid --auth-url "${c}"`,l);let u=r["user-domain"]??(n.interactive?await n.text({default:me.userDomain,message:"User domain"}):me.userDomain),p=r.region??(n.interactive?await n.text({default:me.region,message:"Region"}):me.region),d=await JS({authUrl:c,flag:r["space-url"],prompts:n});if(d!==void 0&&!ct.shape.authUrl.safeParse(d).success)throw Z(`invalid --space-url "${d}"`,ig);let f=d===void 0?void 0:Jr(d),h=performance.now(),y=await I(`Checking ${c}…`,()=>ho(c));if(f!==void 0)await I(`Checking ${f}…`,()=>go(f));let b={authUrl:c,region:p,spaceUrl:f,userDomain:u},_=r.use??(n.interactive&&await n.confirm({default:!0,message:`Use ${i} now?`}));await vt({currentProfile:_?i:o.currentProfile,profiles:{...o.profiles,[i]:b}});let P=f===void 0?"":`, Space API ${new URL(f).host}`;if(Q(`Added profile ${x(i)} (Keystone ${y}${P})`,performance.now()-h),f===void 0)G(`${i} has no Space API URL, so \`nipa server ls\` and the other resource commands don't work with it. Pass \`--space-url\` with its Space portal URL when you add it.`);return w(_?`Now using ${x(i)}. Run \`nipa login\` to log in to it.`:`Run \`nipa login -P ${i}\` to log in to it.`),0});var cg=k(La,async({client:e,flags:t})=>{let r=await ve(),n=Object.keys(r.profiles).toSorted(),o=await Promise.all(n.map((i)=>pe(i)));if(t.json)return e.stdout.json(n.map((i,a)=>{let c=o[a];return{current:i===r.currentProfile,loggedIn:de(c),name:i,...r.profiles[i],user:de(c)?c.user.name:void 0}})),0;let s=n.map((i,a)=>{let c=r.profiles[i]??me,l=o[a],u=de(l)?`${l.user.name} (${l.project.name})`:"-";return[i,new URL(c.authUrl).host,c.region,u].map((p)=>({text:p}))});return w(`${n.length} ${n.length===1?"profile":"profiles"}`),M({headings:["Name","Keystone","Region","Logged in as"],marks:n.map((i)=>i===r.currentProfile?Vt("✔"):" "),rows:s}),0});var lg=k(Za,async({args:e,client:t,flags:r})=>{let{name:n}=e,o=await ve(),s=o.profiles[n];if(!s)throw new E(`no profile named "${n}"`);if(n===fe)throw new E(`can't remove ${fe}`,{hint:"nipa always has the Nipa Cloud production profile."});if(!r.yes){if(!t.prompts.interactive)throw Z(`removing ${n} needs confirmation`,"Add --yes to remove it without asking.");if(!await t.prompts.confirm({default:!1,message:`Remove profile ${n} and log out of it?`}))throw new E("Canceled",{exitCode:130})}let i=await pe(n);if(de(i))try{await fo({authUrl:s.authUrl,token:i.token})}catch{}await Po(n),await Io(s);let a=Object.fromEntries(Object.entries(o.profiles).filter(([l])=>l!==n)),c=o.currentProfile===n;if(await vt({currentProfile:c?fe:o.currentProfile,profiles:a}),Q(`Removed profile ${x(n)}`),c)w(`Now using ${x(fe)}`);return 0});var ug=k(Na,async({args:e,client:t})=>{let r=await ve(),n=Object.keys(r.profiles).toSorted(),{name:o}=e;if(o===void 0){if(!t.prompts.interactive)throw Z("missing <name>",`Your profiles: ${n.join(", ")}`);o=await t.prompts.choice({choices:n.map((s)=>({name:s===r.currentProfile?`${s} ${x("(current)")}`:s,value:s})),default:r.currentProfile,message:"Use profile:"})}if(!r.profiles[o])throw new E(`no profile named "${o}"`,{hint:`Your profiles: ${n.join(", ")}`});if(o===r.currentProfile)return G(`You're already using ${x(o)}`),0;return await vt({...r,currentProfile:o}),Q(`Now using profile ${x(o)}`),0});var pg=te(ng,{add:ag,ls:cg,rm:lg,use:ug});var Ua="Show how much of each quota your project uses",Fa=z({aliases:["list"],args:[],flags:[N],name:"ls",summary:Ua}),dg=ee({aliases:["quotas","limits"],default:"ls",description:"Shows each quota of your project, such as servers, vCPUs and RAM, with how much it uses, its limit, and the percent used. A quota at 80% or more is near its limit. One at 100% is at its limit, so creating one more of that resource fails. The command exits 0 either way. When the output goes to a pipe, nipa prints one tab-separated line per quota: its group and name, such as `compute/ram`, the amount used, the limit or `unlimited`, and the unit, such as `MB`, or `-` for a count.",examples:[{command:"nipa quota",description:Ua},{command:"nipa quota --json | jq '.quotas[] | select(.limit != null and .used >= .limit)'",description:"Print the quotas at their limit"}],name:"quota",subcommands:[Fa],summary:Ua});var qS=v({group:m(),limit:X(),name:m(),unit:m().nullish(),unlimited:tr(),usage:X()}),YS=(e)=>({group:e.group,limit:e.unlimited?null:e.limit,name:e.name,unit:e.unit??null,used:e.usage}),mg=async(e)=>(await e.getLines("/v4/limits",qS)).map(YS);var Ko=new Map([["compute",{label:"Compute",names:[["instances","Servers"],["cores","vCPUs"],["ram","RAM"],["key_pairs","Key pairs"]]}],["storage",{label:"Block storage",names:[["volumes","Volumes"],["volume_size","Volume size"],["snapshots","Snapshots"],["backups","Backups"]]}],["network",{label:"Network",names:[["network","Networks"],["router","Routers"],["port","Ports"],["floatingip","External IPs"],["security_group","Security groups"],["security_group_rule","Security group rules"]]}],["loadBalancer",{label:"Load balancers",names:[["load_balancer","Load balancers"],["listener","Listeners"],["pool","Pools"]]}],["sqlDatabase",{label:"Databases",names:[["database_instances","Databases"],["ram","RAM"],["volume_size","Storage"],["backups","Backups"]]}],["container",{label:"Kubernetes",names:[["kubernetes_cluster","Clusters"]]}],["objectStorage",{label:"Object storage",names:[["storage_size","Storage"],["objects","Objects"]]}],["internetNatGateway",{label:"NAT gateways",names:[["ing_instance","Gateways"],["ing_reserved_ip","Reserved IPs"]]}]]),XS=[...Ko.keys()],QS=/[_\s]+|(?<=[a-z\d])(?=[A-Z])/u,gg=(e)=>{let t=e.split(QS).join(" ").toLowerCase();return t.charAt(0).toUpperCase()+t.slice(1)},yg=(e)=>Ko.get(e)?.label??gg(e),fg=(e)=>Ko.get(e)?.names.map(([t])=>t)??[],bg=(e)=>Ko.get(e.group)?.names.find(([t])=>t===e.name)?.[1]??gg(e.name),Mo=(e,t)=>{let r=e.indexOf(t);return r===-1?e.length:r},ek=(e)=>{let t=[...XS];for(let{group:r}of e)if(!t.includes(r))t.push(r);return t},xg=(e)=>{let t=ek(e);return e.toSorted((r,n)=>Mo(t,r.group)-Mo(t,n.group)||Mo(fg(r.group),r.name)-Mo(fg(n.group),n.name))},hg=["B","KB","MB","GB","TB"],tk=(e)=>{let t=Math.min(hg.length-1,Math.floor(Math.log(Math.max(e,1))/Math.log(1024)));return`${Number((e/1024**t).toFixed(1))} ${hg[t]}`},rk=new Map([["Bytes",tk],["GB",(e)=>`${e} GB`],["MB",Pr]]),Ma=(e,t)=>{if(t===null)return String(e);return rk.get(t)?.(e)??`${e} ${t}`},nk=0.8,Go=(e)=>{if(e.limit===null)return"ok";if(e.used>=e.limit)return"full";return e.used>=e.limit*nk?"near":"ok"},wg={full:Pe,near:mt},_g=(e)=>{if(e.limit===null)return"-";if(e.limit===0)return"100%";return`${Math.floor(e.used*100/e.limit)}%`},Bo=(e)=>e===1?"is":"are",vg=(e)=>{let t=e.filter((n)=>Go(n)==="full").length,r=e.filter((n)=>Go(n)==="near").length;if(t>0&&r>0)return`${ke(t,"quota")} ${Bo(t)} at the limit, and ${r} ${Bo(r)} near it.`;if(t>0)return`${ke(t,"quota")} ${Bo(t)} at the limit.`;if(r>0)return`${ke(r,"quota")} ${Bo(r)} near the limit.`;return null},$g=(e)=>[`${e.group}/${e.name}`,e.used,e.limit??"unlimited",e.unit??"-"].join("\t");var ok=(e)=>{M({headings:["Group","Quota","Used","Limit","%"],rows:e.map((t,r)=>{let n=wg[Go(t)];return[{text:e[r-1]?.group!==t.group?yg(t.group):""},{text:bg(t)},{paint:n,text:Ma(t.used,t.unit)},{text:t.limit===null?"unlimited":Ma(t.limit,t.unit)},{paint:n,text:_g(t)}]})})},Sg=k(Fa,async({client:e,flags:t})=>{let{active:r,session:n,space:o}=await e.cloud(),{project:s}=n,i=performance.now(),a=xg(await I(`Loading the quotas of ${s.name}…`,()=>mg(o)));if(t.json)return e.stdout.json({profile:r.name,project:s,quotas:a}),0;let c=A(`[${R(performance.now()-i)}]`);if(a.length===0)return w(`No quotas for ${x(s.name)} ${c}`),0;w(`Quotas of ${x(s.name)} ${c}`),ok(a);let l=vg(a);if(l)G(l);if(!e.stdout.isTTY)e.stdout.line(a.map($g).join(`
|
|
316
|
+
`));return 0});var kg=te(dg,{ls:Sg});var Pg="List the servers in your project",lr={arity:"one",name:"server",value:{kind:"resource",resource:"servers"}},Ba=[{description:"Return once the Space API takes the action, without waiting",long:"no-wait",value:{kind:"none"}},{description:"How long to wait, such as 90s or 10m (default: 5m)",long:"timeout",value:{kind:"text",name:"duration"}}],Ga=z({aliases:["list"],args:[],flags:[N],name:"ls",summary:Pg}),Ka=z({args:[lr],flags:[N],name:"inspect",summary:"Show a server's flavor, addresses, volumes and security groups"}),Va=z({args:[lr],flags:[{description:"Print only the last n lines",long:"tail",short:"n",value:{kind:"text",name:"n"}},N],name:"logs",summary:"Print a server's console log"}),Wa=z({aliases:["events"],args:[lr],flags:[N],name:"history",summary:"List what was done to a server, newest first"}),Ha=z({args:[lr],flags:[...Ba],name:"start",summary:"Start a stopped server"}),Ja=z({args:[lr],flags:[mr,...Ba],name:"stop",summary:"Stop a server"}),qa=z({aliases:["reboot"],args:[lr],flags:[mr,...Ba],name:"restart",summary:"Restart a server"}),Cg=ee({aliases:["servers"],default:"ls",description:"Lists, inspects, starts, stops and restarts the servers in your project, and shows what was done to a server and its console log. Name a server by its name or ID. `logs` prints the last 100 lines of the console log, which is what the Space API sends. nipa calls the Space API, the one the Nipa Cloud Space portal uses, so you don't need the OpenStack client. start, stop and restart wait until the server finishes, for 5 minutes or `--timeout`. `--no-wait` returns once the Space API takes the action.",examples:[{command:"nipa server ls",description:Pg},{command:"nipa server inspect web-1",description:"Show web-1's addresses, volumes and security groups"},{command:"nipa server history web-1",description:"List web-1's actions, such as a create that failed"},{command:"nipa server logs web-1 --tail 20",description:"Print the last 20 lines of web-1's console log"},{command:"nipa server stop web-1 --yes",description:"Stop web-1 without asking"},{command:"nipa server start web-1 --no-wait",description:"Start web-1 without waiting for it"},{command:"nipa server ls --json | jq -r '.servers[].name'",description:"Print each server's name"}],name:"server",subcommands:[Ga,Ka,Wa,Va,Ha,Ja,qa],summary:"List, inspect, start, stop and restart your servers, and read their history and logs"});var sk=(e,t)=>{M({headings:["Age","Action","User","Result","Request ID"],rows:e.map((r)=>[{paint:K,text:V(t-Date.parse(r.startedAt))},{text:r.action},{text:r.user??"-"},bo(r)?{paint:Pe,text:r.remark??""}:{text:r.remark??"-"},{paint:A,text:r.requestId}])})},Eg=k(Wa,async({args:e,client:t,flags:r})=>{let{active:n,session:o,space:s}=await t.cloud(),{project:i}=o,a=performance.now(),c=await _t({projectName:i.name,ref:e.server,space:s}),l=await I(`Loading ${c.name}'s history…`,()=>xo(s,c.id));if(r.json)return t.stdout.json({actions:l,profile:n.name,project:i,server:{id:c.id,name:c.name}}),0;let u=A(`[${R(performance.now()-a)}]`),p=`${x(c.name)} in ${x(i.name)}`;if(l.length===0)return w(`No actions on ${p} ${u}`),0;if(w(`Actions on ${p} ${u}`),sk(l,Date.now()),!t.stdout.isTTY)t.stdout.line(l.map((d)=>d.requestId).join(`
|
|
317
|
+
`));return 0});var zg=(e)=>{let t=e.addresses.filter((n)=>n.version===4);return(t.find((n)=>n.type==="floating")??t[0]??e.addresses[0])?.address},Vo=(e)=>{if(!e.kubernetes)return{text:e.name};let t=e.kubernetes.role??"node";return{paint:(r)=>`${e.name}${A(r.slice(e.name.length))}`,text:`${e.name} (Kubernetes ${t})`}},Ig=(e)=>{let t=e.addresses.filter((n)=>n.type==="floating"),r=e.addresses.filter((n)=>n.type==="fixed");return[...t.map((n)=>De(n.address," (external)")),...r.map((n)=>({text:n.address}))]},ik=(e)=>{let r=[[`${e.sizeGb} GB`,e.type].filter(Boolean).join(" "),e.attachedAs].filter(Boolean).join(", ");return De(e.name??e.id,` (${r})`)},Ag=(e)=>e.volumes.map(ik);var ak=(e,t)=>{let r=bo(e),n=r?`${e.action} failed`:e.action,o=r||e.remark===null?"":` (${e.remark})`,s=e.user===null?"":` by ${e.user}`,i=V(t-Date.parse(e.startedAt));return{paint:r?(a)=>`${Pe(n)}${a.slice(n.length)}`:void 0,text:`${n}${o} ${i} ago${s}`}},Tg=(e)=>{if(e.status==="fulfilled")return{ok:!0,value:e.value};let{reason:t}=e;return{ok:!1,reason:t instanceof Error?t.message:String(t)}},Ya={paint:A,text:"unavailable"},ck=(e)=>{let{actions:t,now:r,server:n,state:o}=e,s=[{label:"ID",lines:[{text:n.id}]},{label:"Status",lines:[H(n.status)]}];if(!o.ok)s.push({label:"Task",lines:[Ya]},{label:"Locked",lines:[Ya]});else if(o.value.taskState!==null)s.push({label:"Task",lines:[{text:o.value.taskState}]});if(o.ok&&o.value.locked===!0)s.push({label:"Locked",lines:[{text:"yes"}]});let i=t.ok?t.value[0]:void 0;if(!t.ok)s.push({label:"Last action",lines:[Ya]});else if(i)s.push({label:"Last action",lines:[ak(i,r)]});if(s.push({label:"Flavor",lines:[Cn(n)]},{label:"Zone",lines:n.zone?[{text:n.zone}]:[]},{label:"Addresses",lines:Ig(n)},{label:"Volumes",lines:Ag(n)},{label:"Security groups",lines:n.securityGroups.map((c)=>({text:c}))}),n.kubernetes){let{clusterId:c,role:l}=n.kubernetes;s.push({label:"Kubernetes",lines:[De(l??"node",` (cluster ${c})`)]})}let a=`${V(r-Date.parse(n.createdAt))} ago`;return s.push({label:"Created",lines:[{paint:K,text:a}]}),s},Rg=k(Ka,async({args:e,client:t,flags:r})=>{let{active:n,session:o,space:s}=await t.cloud(),{project:i}=o,a=performance.now(),c=await _t({projectName:i.name,ref:e.server,space:s}),[l,u]=await I(`Loading ${c.name}'s state…`,()=>Promise.allSettled([Zi(s,c.id),xo(s,c.id)])),p=Tg(l),d=Tg(u),f=()=>{let y=[["state",p],["actions",d]];for(let[b,_]of y)if(!_.ok)w(`Couldn't load ${c.name}'s ${b}: ${_.reason}. Run the command again, or add \`--debug\` to see the request.`)};if(r.json)return f(),t.stdout.json({profile:n.name,project:i,server:{...c,lastAction:d.ok?d.value[0]??null:null,locked:p.ok?p.value.locked:null,taskState:p.ok?p.value.taskState:null}}),0;let h=A(`[${R(performance.now()-a)}]`);if(w(`Server ${x(c.name)} in ${x(i.name)} ${h}`),ft(ck({actions:d,now:Date.now(),server:c,state:p})),f(),c.status==="ERROR")w(`Run \`nipa server history ${e.server}\` to see what failed, and \`nipa server logs ${e.server}\` for its console log.`);if(!t.stdout.isTTY)t.stdout.line(c.id);return 0});var lk=(e)=>{let t=Number(e);if(!/^\d+$/u.test(e)||t===0)throw Z(`"${e}" isn't a number of lines`,"Write it as a whole number above 0, such as `--tail 50`.");return t},uk=(e,t)=>{if(t===void 0)return e;let r=e.split(`
|
|
318
|
+
`);if(r.at(-1)==="")r.pop();return r.slice(-t).map((n)=>`${n}
|
|
319
|
+
`).join("")},jg=k(Va,async({args:e,client:t,flags:r})=>{let n=r.tail===void 0?void 0:lk(r.tail),{active:o,session:s,space:i}=await t.cloud(),{project:a}=s,c=performance.now(),l=await _t({projectName:a.name,ref:e.server,space:i}),u=await I(`Loading ${l.name}'s console log…`,()=>Jm(i,l.id));if(u.kind==="none")throw new E(`${l.name} has no console log yet`,{hint:`A server has one once it boots, so this one most likely never booted. Run \`nipa server history ${e.server}\` to see what failed.`});let p=uk(u.text,n);if(r.json)return t.stdout.json({logs:p,profile:o.name,project:a,server:{id:l.id,name:l.name}}),0;let d=A(`[${R(performance.now()-c)}]`);if(p==="")return w(`${x(l.name)}'s console log is empty ${d}`),0;return w(`Console log of ${x(l.name)} in ${x(a.name)} ${d}`),t.stdout.write(p),0});var pk=(e,t)=>{M({headings:["Name","Status","Address","Flavor","Age"],rows:e.map((r)=>[Vo(r),H(r.status),{text:zg(r)??"-"},{text:r.flavor},{paint:K,text:V(t-Date.parse(r.createdAt))}])})},Og=k(Ga,async({client:e,flags:t})=>{let{active:r,session:n,space:o}=await e.cloud(),{project:s}=n,i=performance.now(),a=await I(`Loading the servers in ${s.name}…`,()=>We(o));if(t.json)return e.stdout.json({profile:r.name,project:s,servers:a}),0;let c=A(`[${R(performance.now()-i)}]`);if(a.length===0)return w(`No servers in ${x(s.name)} ${c}`),0;if(w(`Servers in ${x(s.name)} ${c}`),pk(a,Date.now()),!e.stdout.isTTY)e.stdout.line(a.map((l)=>l.id).join(`
|
|
320
|
+
`));return 0});var dk="5m",mk=2000,fk=(e)=>{let t=/^(?<count>\d+)(?<unit>[hms])$/u.exec(e)?.groups,r=Number(t?.count);switch(t?.unit){case"h":return r*3600000;case"m":return r*60000;case"s":return r*1000;default:throw Z(`"${e}" isn't a duration`,"Write it as a number and a unit, such as `--timeout 90s` or `--timeout 10m`.")}},Lg={restart:{confirm:!0,doing:"Restarting",done:"Restarted",status:"ACTIVE"},start:{confirm:!1,doing:"Starting",done:"Started",status:"ACTIVE"},stop:{confirm:!0,doing:"Stopping",done:"Stopped",status:"SHUTOFF"}},hk=async(e)=>{let{action:t,client:r,server:n}=e;if(!r.prompts.interactive)throw Z(`${Lg[t].doing.toLowerCase()} ${n.name} needs confirmation`,`Add \`--yes\` to ${t} it without asking.`);let o=`${t.charAt(0).toUpperCase()}${t.slice(1)}`;if(!await r.prompts.confirm({default:!1,message:`${o} server ${Vo(n).text} in ${e.projectName}?`}))throw new E("Canceled",{exitCode:130})},Xa=async(e)=>{let{action:t,client:r,flags:n}=e,o=Lg[t];if(n["no-wait"]&&n.timeout!==void 0)throw Z("--no-wait and --timeout don't go together","Drop `--timeout`, or drop `--no-wait` to wait for the server.");let s=n.timeout??dk,i=fk(s),{session:a,space:c}=await r.cloud(),l=a.project.name,u=await _t({projectName:l,ref:e.ref,space:c}),p=x(u.name);if(t==="restart"&&u.status==="SHUTOFF")throw new E(`${u.name} is stopped`,{hint:`Run \`nipa server start ${u.name}\` to start it.`});if(t!=="restart"&&u.status===o.status)return G(`${p} is already ${t==="stop"?"stopped":"running"}`),0;if(o.confirm&&!n.yes)await hk({action:t,client:r,projectName:l,server:u});let d=performance.now(),f=`\`nipa server inspect ${u.name}\``;if(n["no-wait"])return await I(`Asking to ${t} ${u.name}…`,()=>Ui(c,u.id,t)),Q(`Asked to ${t} ${p} in ${x(l)}`,performance.now()-d),w(`Run ${f} to check on it.`),0;let h=await I(`${o.doing} ${u.name}…`,async()=>{await Ui(c,u.id,t);try{return await Hm({id:u.id,intervalMs:mk,space:c,status:o.status,timeoutMs:i})}catch(y){if(y instanceof E||y instanceof ge)throw new E(y.message,{hint:`nipa asked to ${t} ${u.name} before this failed. Run ${f} to check it.`});throw y}});if(h.kind==="error")throw new E(`${u.name} went into an error state`,{hint:`Run ${f}, or check the server in the Space portal.`});if(h.kind==="timeout"){let y=Fe(h.state.status);throw new E(`${u.name} is still ${y} after ${s}`,{hint:`Run ${f} to check it again, or wait longer with \`--timeout\`.`})}return Q(`${o.done} ${p} in ${x(l)}`,performance.now()-d),0},Dg=k(Ha,({args:e,client:t,flags:r})=>Xa({action:"start",client:t,flags:r,ref:e.server})),Ng=k(Ja,({args:e,client:t,flags:r})=>Xa({action:"stop",client:t,flags:r,ref:e.server})),Zg=k(qa,({args:e,client:t,flags:r})=>Xa({action:"restart",client:t,flags:r,ref:e.server}));var Ug=te(Cg,{history:Eg,inspect:Rg,logs:jg,ls:Og,restart:Zg,start:Dg,stop:Ng});var Fg="List the security groups in your project",Qa=z({aliases:["list"],args:[],flags:[N],name:"ls",summary:Fg}),ec=z({args:[{arity:"one",name:"group",value:{kind:"resource",resource:"security-groups"}}],flags:[N],name:"inspect",summary:"Show a security group's rules and the servers that use it"}),Mg=ee({aliases:["security-group","security-groups"],default:"ls",description:"Lists and inspects the security groups in your project. Name a group by its name or ID. `nipa sg inspect` shows a group's inbound and outbound rules and the servers that use it, found through the network ports in your project, so a server in another project doesn't show. It notes when a rule opens SSH, RDP or a database port to the internet. `--json` prints each rule's direction, protocol, ports and remote, and `exposed`, true for such a rule.",examples:[{command:"nipa sg ls",description:Fg},{command:"nipa sg inspect web",description:"Show the rules of the web security group and its servers"},{command:"nipa sg inspect web --json | jq -r '.securityGroup.servers[].name'",description:"Print the name of each server that uses web"}],name:"sg",subcommands:[Qa,ec],summary:"List and inspect your security groups"});var gk=new Set(["icmp","icmpv6","ipv6-icmp"]),yk=new Map([["1","icmp"],["6","tcp"],["17","udp"],["58","ipv6-icmp"]]),bk=(e)=>e===null||e==="any"?null:yk.get(e)??e,xk=new Set(["0.0.0.0/0","::/0"]),wk=65535,_k=(e,t)=>{let{portMax:r,portMin:n}=t;if(e===null||n===null)return{kind:"any"};if(gk.has(e))return{code:r,kind:"icmp",type:n};let o=r??n;return n<=1&&o>=wk?{kind:"any"}:{from:n,kind:"range",to:o}},vk=(e,t)=>{if(e.remoteGroupId){let r=e.remoteGroupId;return{id:r,kind:"group",name:t.get(r)??null}}return e.remoteIpPrefix?{cidr:e.remoteIpPrefix,kind:"cidr"}:{kind:"any"}},rc=(e,t)=>{let r=bk(e.protocol);return{direction:e.direction,ethertype:e.ethertype,ports:_k(r,e),protocol:r,remote:vk(e,t)}},$k=(e)=>{switch(e.kind){case"any":return"any";case"range":return e.from===e.to?String(e.from):`${e.from}-${e.to}`;case"icmp":{let t=e.code===null?"":` code ${e.code}`;return`type ${e.type}${t}`}default:return e}},tc=(e)=>{switch(e.kind){case"any":return"any";case"cidr":return e.cidr;case"group":return`group ${e.name??e.id}`;default:return e}},Gg=(e)=>[{text:e.protocol??"any"},{text:$k(e.ports)},{text:tc(e.remote)},{text:e.ethertype}],Bg=(e)=>{switch(e.kind){case"range":return e.from;case"icmp":return e.type;default:return-1}},Kg=(e,t)=>Bg(e.ports)-Bg(t.ports)||(e.protocol??"").localeCompare(t.protocol??"")||e.ethertype.localeCompare(t.ethertype)||tc(e.remote).localeCompare(tc(t.remote)),Vg=[{name:"SSH",port:22},{name:"MySQL",port:3306},{name:"RDP",port:3389},{name:"PostgreSQL",port:5432},{name:"Redis",port:6379},{name:"MongoDB",port:27017}],Sk=(e)=>e.kind==="any"||e.kind==="cidr"&&xk.has(e.cidr),kk=(e)=>e.direction==="ingress"&&Sk(e.remote)&&(e.protocol===null||e.protocol==="tcp"),Wg=(e,t)=>e.kind==="any"||e.kind==="range"&&e.from<=t&&t<=e.to,Wo=(e)=>kk(e)&&Vg.some(({port:t})=>Wg(e.ports,t)),Hg=(e)=>{let t=e.filter(Wo);if(t.some((o)=>o.ports.kind==="any"))return"Every port is open to the internet.";let r=Vg.filter(({port:o})=>t.some((s)=>Wg(s.ports,o))).map(({name:o,port:s})=>`${o} (${s})`);if(r.length===0)return;let n=r.length===1?"is":"are";return`${zt(r)} ${n} open to the internet.`};var Pk=(e,t,r)=>r.flatMap((n)=>{let o=t.filter((s)=>s.deviceId===n.id&&s.securityGroupIds.includes(e));return o.length>0?[{addresses:o.flatMap((s)=>s.addresses),id:n.id,name:n.name}]:[]}),Ck=(e)=>De(e.name,` (${e.addresses.length>0?e.addresses.join(", "):"-"})`),Ek=[{direction:"ingress",empty:"No inbound rules, so this group lets no traffic in.",remote:"Source",title:"Inbound rules"},{direction:"egress",empty:"No outbound rules, so this group lets no traffic out.",remote:"Destination",title:"Outbound rules"}],zk=(e,t)=>{let r=e.rules.map((n)=>rc(n,t)).toSorted(Kg);for(let{direction:n,empty:o,remote:s,title:i}of Ek){let a=r.filter((l)=>l.direction===n);if(a.length===0){w(o);continue}w(i),M({headings:["Protocol","Ports",s,"Ethertype"],marks:a.map((l)=>Wo(l)?mt("!"):" "),rows:a.map(Gg)});let c=Hg(a);if(c)G(c)}},Jg=k(ec,async({args:e,client:t,flags:r})=>{let{active:n,session:o,space:s}=await t.cloud(),{project:i}=o,a=performance.now(),c=nr(s),l=await at({kind:{...or,list:()=>c},projectName:i.name,ref:e.group,space:s}),[u,p]=await I(`Loading the servers in ${i.name}…`,()=>Promise.all([tf(s),We(s)])),d=await c,f=new Map(d.map((_)=>[_.id,_.name])),h=Pk(l.id,u,p);if(r.json){let _=l.rules.map((P)=>({...P,exposed:Wo(rc(P,f)),remoteGroupName:P.remoteGroupId?f.get(P.remoteGroupId)??null:null}));return t.stdout.json({profile:n.name,project:i,securityGroup:{...l,rules:_,servers:h}}),0}let y=A(`[${R(performance.now()-a)}]`);w(`Security group ${x(l.name)} in ${x(i.name)} ${y}`);let b=`${V(Date.now()-Date.parse(l.createdAt))} ago`;if(ft([{label:"ID",lines:[{text:l.id}]},{label:"Description",lines:l.description?[{text:l.description}]:[]},{label:"Servers",lines:h.map(Ck)},{label:"Created",lines:[{paint:K,text:b}]}]),zk(l,f),!t.stdout.isTTY)t.stdout.line(l.id);return 0});var qg=(e,t)=>e.rules.filter((r)=>r.direction===t).length,Ik=(e,t)=>{M({headings:["Name","Inbound","Outbound","Age","Description"],rows:e.map((r)=>[{text:r.name},{text:String(qg(r,"ingress"))},{text:String(qg(r,"egress"))},{paint:K,text:V(t-Date.parse(r.createdAt))},{text:r.description??"-"}])})},Yg=k(Qa,async({client:e,flags:t})=>{let{active:r,session:n,space:o}=await e.cloud(),{project:s}=n,i=performance.now(),a=await I(`Loading the security groups in ${s.name}…`,()=>nr(o));if(t.json)return e.stdout.json({profile:r.name,project:s,securityGroups:a}),0;let c=A(`[${R(performance.now()-i)}]`);if(a.length===0)return w(`No security groups in ${x(s.name)} ${c}`),0;if(w(`Security groups in ${x(s.name)} ${c}`),Ik(a,Date.now()),!e.stdout.isTTY)e.stdout.line(a.map((l)=>l.id).join(`
|
|
321
|
+
`));return 0});var Xg=te(Mg,{inspect:Jg,ls:Yg});var Qg=z({args:[{arity:"optional",name:"project",value:{kind:"project"}}],description:"Scopes the session to another project, by name or ID, without a password or OTP code. Without a project, nipa lists your projects to pick from.",flags:[],name:"switch",summary:"Use another project"});var ey=k(Qg,async({args:e,client:t})=>{let{project:r}=e,{active:n,session:o}=await t.savedSession(),{authUrl:s}=n.profile,i=await I("Loading your projects…",()=>Ue({authUrl:s,token:o.token}));if(r===void 0&&!t.prompts.interactive)throw new E("tell nipa which project to use",{exitCode:2,hint:`Run \`nipa switch <project>\`. Your projects: ${i.map((p)=>p.name).join(", ")}`});let a=await Ro({ask:To({current:o.project,message:"Switch to:",prompts:t.prompts}),projects:i,wanted:r});if(a.id===o.project.id)return G(`You're already using ${x(a.name)}`),0;let c=performance.now(),l=await I(`Switching to ${a.name}…`,()=>Hr({authUrl:s,projectId:a.id,token:o.token}));await ra({active:n,session:on(l,a)}),Q(`Switched to ${x(a.name)}`,performance.now()-c);let u=n.link;if(u&&u.link.project.id!==a.id)G(`Commands in this folder still use ${x(u.link.project.name)}, from ${ye(u.file)}. Run \`nipa unlink\` to use ${a.name} here too.`);return 0});var ty=Wt({aliases:["terraform"],description:"Runs `terraform <args...>` with the session. It's the same as `nipa exec terraform <args...>`.",examples:[{command:"nipa -P staging tf plan",description:"Plan against the staging profile"}],name:"tf",summary:"Run terraform with the session",target:{kind:"program",program:"terraform"}});var ry=Ht(ty,({args:e,client:t,command:r})=>ar({args:e,command:r,signIn:t.cloud}));var ny=z({args:[],description:"Deletes the .nipa/project.json that links this folder, or the closest folder above it, so commands here use the current profile and project again.",flags:[],name:"unlink",summary:"Stop using a linked project in this folder"});var oy=k(ny,async()=>{let e=await Nt();if(!e)return G("This folder isn't linked to a project"),0;return await Cf(e.file),Q(`Unlinked ${ye(e.file)} from ${x(e.link.project.name)}`),0});var nc="List the volumes in your project",oc=z({aliases:["list"],args:[],flags:[N],name:"ls",summary:nc}),sy=ee({aliases:["volumes"],default:"ls",description:"Lists the block storage volumes in your project with their status, size, type, the server each one is attached to, and age.",examples:[{command:"nipa volume ls",description:nc},{command:`nipa volume ls --json | jq -r '.volumes[] | select(.status == "available") | .id'`,description:"Print the volumes that no server uses"}],name:"volume",subcommands:[oc],summary:nc});var Ak=(e)=>{let{now:t,serverNames:r,volumes:n}=e;M({headings:["Name","Status","Size","Type","Server","Age"],rows:n.map((o)=>{let s=o.attachments.map(({serverId:i})=>r.get(i)??i);return[{text:o.name||"-"},H(o.status),{text:`${o.sizeGb} GB`},{text:o.type??"-"},{text:s.length>0?s.join(", "):"-"},{paint:K,text:V(t-Date.parse(o.createdAt))}]})})},iy=k(oc,async({client:e,flags:t})=>{let{active:r,session:n,space:o}=await e.cloud(),{project:s}=n,i=performance.now(),a=`Loading the volumes in ${s.name}…`;if(t.json){let p=await I(a,()=>Xr(o));return e.stdout.json({profile:r.name,project:s,volumes:p}),0}let[c,l]=await I(a,()=>Promise.all([Xr(o),We(o)])),u=A(`[${R(performance.now()-i)}]`);if(c.length===0)return w(`No volumes in ${x(s.name)} ${u}`),0;if(w(`Volumes in ${x(s.name)} ${u}`),Ak({now:Date.now(),serverNames:new Map(l.map((p)=>[p.id,p.name])),volumes:c}),!e.stdout.isTTY)e.stdout.line(c.map((p)=>p.id).join(`
|
|
322
|
+
`));return 0});var ay=te(sy,{ls:iy});var cy=z({args:[],description:"Prints your user, profile, project and when the session expires. When the output goes to a pipe, nipa prints only your user name.",flags:[N],name:"whoami",summary:"Show who you're logged in as"});var ly=k(cy,async({client:e,flags:t})=>{let r=await e.profile(),n=await pe(r.name);if(!de(n)){if(t.json)e.stdout.line(JSON.stringify({loggedIn:!1,profile:r.name}));throw new E(`you aren't logged in to ${r.name}`,{hint:`Run \`${Je(r.name)}\`.`})}if(t.json)return e.stdout.json({authUrl:r.profile.authUrl,expiresAt:n.expiresAt,link:r.link?{file:r.link.file,project:r.link.link.project}:null,loggedIn:!0,profile:r.name,project:n.project,region:r.profile.region,user:n.user}),0;if(!e.stdout.isTTY)return e.stdout.line(n.user.name),0;let{host:o}=new URL(r.profile.authUrl),s=Kt(Lt(n));w(`Logged in as ${x(n.user.name)}`);let i=A(`(${o}, ${r.profile.region})`),a=A(`(${n.project.id})`);if(w(`Profile: ${x(r.name)} ${i}`),w(`Project: ${x(n.project.name)} ${a}`),r.link&&r.link.link.project.id!==n.project.id){let{file:c,link:l}=r.link,u=A(`(${ye(c)})`);w(`This folder uses ${x(l.project.name)} ${u}`)}return w(`The session expires in ${s}`),0});var sc={examples:[{command:"nipa login",description:"Log in and pick a project"},{command:"nipa server ls",description:"List the servers in your project"},{command:"nipa os volume list",description:"Run any openstack command with the session"},{command:"nipa -P staging tf plan",description:"Run terraform against the staging profile"}],hidden:[Uf],sections:[{commands:[Kh,Wh,ly,ey,Bh,oy],title:"Session"},{commands:[Ug,Eh,ay,qh,Xg,Ah,Uh,Oh,ih,kg,eg],title:"Resources"},{commands:[rg,ry,kh,$h],title:"Run tools"},{commands:[pg,_h,qf],title:"Setup"}],summary:"Log in to Nipa Cloud once, then list your servers, volumes, networks, security groups, external IPs, load balancers, Kubernetes clusters, databases and quotas, open them in the Space portal, or run openstack and terraform with the session."};var ur=(e)=>{let t;return()=>(t??=e(),t)},uy=(e)=>{let{globals:t,program:r}=e;if(t.debug)process.env.NIPA_DEBUG="1";let n=ll({stderr:process.stderr,stdin:process.stdin}),o=ur(()=>Nt()),s=ur(async()=>ta({link:await o(),override:t.profile})),i=ur(async()=>{try{return await s()}catch(u){if(!(u instanceof rn))throw u;return ta({override:t.profile})}}),a=ur(async()=>sn({active:await s(),prompts:n})),c=ur(async()=>sn({active:await s(),linked:!1,prompts:n}));return{cloud:ur(async()=>{let u=await s(),p=an(u);return Ao(u),jo({signedIn:await a(),spaceUrl:p})}),profile:s,profileWithoutBrokenLink:i,program:r,prompts:n,savedSession:c,session:a,stdout:ul(process.stdout)}};var dn=(e)=>({kind:"print",text:e}),py=(e,t)=>({exitCode:e,kind:"ran",updateNotice:t.every((r)=>r.updateNotice!==!1)}),Tk=(e)=>new Map([...e.sections.flatMap((t)=>t.commands),...e.hidden].flatMap((t)=>xe(t.spec).map((r)=>[r,t]))),Rk=(e)=>{let t=e.at(-1)??"",r=e.slice(0,-1);return r.length===0?t:`${r.join(", ")} or ${t}`},jk=(e,t)=>Z(`unknown subcommand "${e.spec.name} ${t}"`,`Use ${Rk(e.spec.subcommands.map((r)=>r.name))}.`),Ok=(e,t)=>{let{rest:r}=Ts({unknown:"stop",words:t}),[n]=r;if(n===void 0||n.startsWith("-"))return{kind:"leaf",leaf:e.fallback,path:[e.spec],words:t};let o=e.subcommands.get(n);if(!o)return{group:e,kind:"unknown",word:n};return{kind:"leaf",leaf:o,path:[e.spec,o.spec],words:t.toSpliced(t.length-r.length,1)}},Lk=(e,t)=>{let[r,n]=t,o=r===void 0?void 0:e.get(r);if(!o)return;let s=o.kind==="group"&&n!==void 0?o.subcommands.get(n):void 0;return o.kind==="group"&&s?[o.spec,s.spec]:[o.spec]},Dk=(e,t)=>{let r=Array.from({length:t.length+1},(n,o)=>o);for(let n=1;n<=e.length;n+=1){let o=[n];for(let s=1;s<=t.length;s+=1){let i=e[n-1]===t[s-1]?0:1;o[s]=Math.min((r[s]??0)+1,(o[s-1]??0)+1,(r[s-1]??0)+i)}r=o}return r[t.length]??0},Nk=(e)=>{let[t]=e.program.sections.flatMap((n)=>n.commands).map((n)=>({name:n.name,score:Dk(e.word,n.name)})).toSorted((n,o)=>n.score-o.score),r=t&&t.score<=2?`Did you mean \`nipa ${t.name}\`?`:"Run `nipa --help` to see the commands.";return new E(`unknown command "${e.word}"`,{exitCode:2,hint:r})},dy=async(e)=>{let t=En(e.program),r=Tk(e.program),n=Ts({unknown:"reject",words:e.argv});if(n.globals.version)return dn(e.version);let[o,...s]=n.rest;if(o===void 0)return dn(ns({program:t,version:e.version}));if(o==="help"){let p=Lk(r,s);return dn(p?yn(p):ns({program:t,version:e.version}))}let i=r.get(o);if(!i)throw Nk({program:t,word:o});if(i.kind==="passthrough"){if(n.globals.help)return dn(yn([i.spec]));let p=e.createClient({globals:n.globals,program:t});return py(await i.run({client:p,words:s}),[i.spec])}let a=i.kind==="group"?Ok(i,s):{kind:"leaf",leaf:i,path:[i.spec],words:s};if(n.globals.help||yl(s))return dn(yn(a.kind==="leaf"?a.path:[i.spec]));if(a.kind==="unknown")throw jk(a.group,a.word);let c=a.leaf.prepare({path:a.path,words:a.words}),l={...n.globals,...c.globals},u=e.createClient({globals:l,program:t});return py(await c.run(u),a.path)};try{let e=await dy({argv:process.argv.slice(2),createClient:uy,program:sc,version:dt.version});switch(e.kind){case"print":{console.log(e.text),process.exitCode=0;break}case"ran":{if(process.exitCode=e.exitCode,e.updateNotice)await Hf({program:En(sc),version:dt.version}),await hh(dt.version);break}default:throw Error(`unknown outcome ${String(e)}`)}}catch(e){let t=e instanceof Error?Zo(e):void 0;if(!t)throw e;cl(t),process.exitCode=t.exitCode}
|