@gadgetinc/ggt 2.2.0 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (127) hide show
  1. package/README.md +26 -1
  2. package/dist/{add-TWLGKL2T.js → add-7MLI3TCY.js} +8 -8
  3. package/dist/add-7MLI3TCY.js.map +7 -0
  4. package/dist/agent-plugin-543K6WBH.js +11 -0
  5. package/dist/agent-plugin-543K6WBH.js.map +7 -0
  6. package/dist/chunk-2HJS3KFB.js +2 -0
  7. package/dist/{chunk-T6UHSWMT.js.map → chunk-2HJS3KFB.js.map} +2 -2
  8. package/dist/{chunk-3OM5WM7E.js → chunk-3WKH3DJL.js} +2 -2
  9. package/dist/chunk-577KP32Z.js +8 -0
  10. package/dist/chunk-577KP32Z.js.map +7 -0
  11. package/dist/{chunk-R6KJLEKY.js → chunk-6FVHOLT7.js} +2 -2
  12. package/dist/chunk-6FVHOLT7.js.map +7 -0
  13. package/dist/{chunk-HCULGPBH.js → chunk-72J7X5LR.js} +2 -2
  14. package/dist/{chunk-HCULGPBH.js.map → chunk-72J7X5LR.js.map} +2 -2
  15. package/dist/{chunk-JG2QCDK2.js → chunk-ALSXPCRD.js} +5 -5
  16. package/dist/{chunk-JG2QCDK2.js.map → chunk-ALSXPCRD.js.map} +4 -4
  17. package/dist/{chunk-SIR6HLN3.js → chunk-CNNOPE5K.js} +22 -22
  18. package/dist/chunk-CNNOPE5K.js.map +7 -0
  19. package/dist/chunk-ETKWDO4V.js +2 -0
  20. package/dist/chunk-ETKWDO4V.js.map +7 -0
  21. package/dist/{chunk-DR4CXBD6.js → chunk-F6BGQ4LG.js} +2 -2
  22. package/dist/{chunk-DR4CXBD6.js.map → chunk-F6BGQ4LG.js.map} +2 -2
  23. package/dist/{chunk-SVWK2NXG.js → chunk-FE5O5VX4.js} +2 -2
  24. package/dist/chunk-FE5O5VX4.js.map +7 -0
  25. package/dist/{chunk-F255O64V.js → chunk-GZTHIOXS.js} +2 -2
  26. package/dist/chunk-GZTHIOXS.js.map +7 -0
  27. package/dist/chunk-IQSZEOYY.js +283 -0
  28. package/dist/{chunk-442CSROP.js.map → chunk-IQSZEOYY.js.map} +4 -4
  29. package/dist/chunk-N5FFICAP.js +9 -0
  30. package/dist/chunk-N5FFICAP.js.map +7 -0
  31. package/dist/chunk-TGCJ6TMW.js +10 -0
  32. package/dist/chunk-TGCJ6TMW.js.map +7 -0
  33. package/dist/{chunk-XC4F2TLW.js → chunk-ULJYEUQG.js} +19 -19
  34. package/dist/chunk-ULJYEUQG.js.map +7 -0
  35. package/dist/{chunk-2742UPMB.js → chunk-UVVKKUYG.js} +2 -2
  36. package/dist/chunk-UVVKKUYG.js.map +7 -0
  37. package/dist/{chunk-WB6O2V5D.js → chunk-WZ2PO6H2.js} +2 -2
  38. package/dist/{chunk-OUIZQC4D.js → chunk-X4XSYLCE.js} +2 -2
  39. package/dist/{chunk-OUIZQC4D.js.map → chunk-X4XSYLCE.js.map} +2 -2
  40. package/dist/{configure-UJS7V2JX.js → configure-PYRXYNGZ.js} +2 -2
  41. package/dist/configure-PYRXYNGZ.js.map +7 -0
  42. package/dist/{debugger-QN2MCLBL.js → debugger-VKLUEWIN.js} +2 -2
  43. package/dist/debugger-VKLUEWIN.js.map +7 -0
  44. package/dist/{deploy-J74PHPQA.js → deploy-JCREEGBA.js} +3 -3
  45. package/dist/deploy-JCREEGBA.js.map +7 -0
  46. package/dist/{dev-GGUSOOYP.js → dev-Y2GLI7EH.js} +3 -3
  47. package/dist/{dev-GGUSOOYP.js.map → dev-Y2GLI7EH.js.map} +3 -3
  48. package/dist/env-5OPHX3MC.js +135 -0
  49. package/dist/env-5OPHX3MC.js.map +7 -0
  50. package/dist/esm-3JVXH7DT.js +37 -0
  51. package/dist/esm-3JVXH7DT.js.map +7 -0
  52. package/dist/{eval-L6WHUFLU.js → eval-LZPZ6PBQ.js} +3 -3
  53. package/dist/{eval-L6WHUFLU.js.map → eval-LZPZ6PBQ.js.map} +2 -2
  54. package/dist/ggt-KUAF6WUA.js +45 -0
  55. package/dist/ggt-KUAF6WUA.js.map +7 -0
  56. package/dist/{list-756D46N5.js → list-IANT7SNF.js} +2 -2
  57. package/dist/list-IANT7SNF.js.map +7 -0
  58. package/dist/login-TYRZLN5S.js +2 -0
  59. package/dist/{logout-LQABTJFD.js → logout-P75XYYZ6.js} +2 -2
  60. package/dist/logout-P75XYYZ6.js.map +7 -0
  61. package/dist/{logs-AQZB272X.js → logs-SBMD6JSR.js} +2 -2
  62. package/dist/logs-SBMD6JSR.js.map +7 -0
  63. package/dist/main.js +1 -1
  64. package/dist/{open-OMZWPQ66.js → open-JPAMII4K.js} +2 -2
  65. package/dist/open-JPAMII4K.js.map +7 -0
  66. package/dist/problems-EZRSHLZT.js +14 -0
  67. package/dist/problems-EZRSHLZT.js.map +7 -0
  68. package/dist/{pull-XYCYN7QN.js → pull-R3PMBVOT.js} +2 -2
  69. package/dist/pull-R3PMBVOT.js.map +7 -0
  70. package/dist/push-5XEEESQQ.js +2 -0
  71. package/dist/{status-PWAXNK5G.js → status-RJN5ES6S.js} +2 -2
  72. package/dist/status-RJN5ES6S.js.map +7 -0
  73. package/dist/update-X7YS3MNH.js +2 -0
  74. package/dist/{var-N4WGGJXZ.js → var-PC6KQUPF.js} +4 -4
  75. package/dist/var-PC6KQUPF.js.map +7 -0
  76. package/dist/{version-AJKSJJDC.js → version-GZJOU2CV.js} +2 -2
  77. package/dist/version-GZJOU2CV.js.map +7 -0
  78. package/dist/{whoami-KJYDSQSD.js → whoami-GKPGPZ3B.js} +2 -2
  79. package/dist/whoami-GKPGPZ3B.js.map +7 -0
  80. package/package.json +6 -6
  81. package/dist/add-TWLGKL2T.js.map +0 -7
  82. package/dist/agent-plugin-TN24O7FB.js +0 -10
  83. package/dist/agent-plugin-TN24O7FB.js.map +0 -7
  84. package/dist/chunk-2742UPMB.js.map +0 -7
  85. package/dist/chunk-442CSROP.js +0 -66
  86. package/dist/chunk-F255O64V.js.map +0 -7
  87. package/dist/chunk-JKZNSRLU.js +0 -8
  88. package/dist/chunk-JKZNSRLU.js.map +0 -7
  89. package/dist/chunk-JYE5LLIF.js +0 -9
  90. package/dist/chunk-JYE5LLIF.js.map +0 -7
  91. package/dist/chunk-MW6MXMSN.js +0 -2
  92. package/dist/chunk-MW6MXMSN.js.map +0 -7
  93. package/dist/chunk-R6KJLEKY.js.map +0 -7
  94. package/dist/chunk-SIR6HLN3.js.map +0 -7
  95. package/dist/chunk-SVWK2NXG.js.map +0 -7
  96. package/dist/chunk-T6UHSWMT.js +0 -2
  97. package/dist/chunk-XC4F2TLW.js.map +0 -7
  98. package/dist/chunk-YFUOXDPK.js +0 -10
  99. package/dist/chunk-YFUOXDPK.js.map +0 -7
  100. package/dist/chunk-ZSREFZXV.js +0 -211
  101. package/dist/chunk-ZSREFZXV.js.map +0 -7
  102. package/dist/configure-UJS7V2JX.js.map +0 -7
  103. package/dist/debugger-QN2MCLBL.js.map +0 -7
  104. package/dist/deploy-J74PHPQA.js.map +0 -7
  105. package/dist/esm-D77XRR65.js +0 -38
  106. package/dist/esm-D77XRR65.js.map +0 -7
  107. package/dist/ggt-5XNRJZSW.js +0 -44
  108. package/dist/ggt-5XNRJZSW.js.map +0 -7
  109. package/dist/list-756D46N5.js.map +0 -7
  110. package/dist/login-GMWQRH7V.js +0 -2
  111. package/dist/logout-LQABTJFD.js.map +0 -7
  112. package/dist/logs-AQZB272X.js.map +0 -7
  113. package/dist/open-OMZWPQ66.js.map +0 -7
  114. package/dist/problems-FZJKH52E.js +0 -14
  115. package/dist/problems-FZJKH52E.js.map +0 -7
  116. package/dist/pull-XYCYN7QN.js.map +0 -7
  117. package/dist/push-3QM7ZFTC.js +0 -2
  118. package/dist/status-PWAXNK5G.js.map +0 -7
  119. package/dist/update-QIQFJFRQ.js +0 -2
  120. package/dist/var-N4WGGJXZ.js.map +0 -7
  121. package/dist/version-AJKSJJDC.js.map +0 -7
  122. package/dist/whoami-KJYDSQSD.js.map +0 -7
  123. /package/dist/{chunk-3OM5WM7E.js.map → chunk-3WKH3DJL.js.map} +0 -0
  124. /package/dist/{chunk-WB6O2V5D.js.map → chunk-WZ2PO6H2.js.map} +0 -0
  125. /package/dist/{login-GMWQRH7V.js.map → login-TYRZLN5S.js.map} +0 -0
  126. /package/dist/{push-3QM7ZFTC.js.map → push-5XEEESQQ.js.map} +0 -0
  127. /package/dist/{update-QIQFJFRQ.js.map → update-X7YS3MNH.js.map} +0 -0
@@ -0,0 +1,2 @@
1
+ import{aa as a,p as g}from"./chunk-IQSZEOYY.js";import{ea as i}from"./chunk-ALSXPCRD.js";import{a as o,h as t}from"./chunk-7DYQUG5M.js";t();var N=o((n,s,{onError:l})=>{let m=a(n.environment),u=Object.entries(i).filter(([e,r])=>r>=s["--log-level"]).map(([e])=>e.toLowerCase()).join("|");return n.subscribe({subscription:g,variables:o(()=>({query:`{environment_id="${n.environment.id}"} | json | level=~"${u}"${s["--my-logs"]?' | source="user"':""}`,start:new Date}),"variables"),onError:l,onData:o(({logsSearchV2:e})=>{for(let r of e.data.messages){let c=JSON.parse(r[1]),{msg:p,name:d,level:v,...E}=c;m(v,d,p,{...E},new Date(Number(r[0])/1e6))}},"onData")})},"subscribeToEnvironmentLogs");export{N as a};
2
+ //# sourceMappingURL=chunk-ETKWDO4V.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/services/logs/subscribeToEnvironmentLogs.ts"],
4
+ "sourcesContent": ["import type { Edit, EditSubscription } from \"../app/edit/edit.js\";\nimport { ENVIRONMENT_LOGS_SUBSCRIPTION } from \"../app/edit/operation.js\";\nimport type { Fields } from \"../output/log/field.js\";\nimport { Level } from \"../output/log/level.js\";\nimport { type LoggingArgsResult, createEnvironmentStructuredLogger } from \"../output/log/structured.js\";\n\n/**\n * Start a subscription to the environment's server side logs and print them to the console.\n */\nexport const subscribeToEnvironmentLogs = (\n edit: Edit,\n args: LoggingArgsResult,\n {\n onError,\n }: {\n onError: (error: unknown) => void;\n },\n): EditSubscription<ENVIRONMENT_LOGS_SUBSCRIPTION> => {\n const logger = createEnvironmentStructuredLogger(edit.environment);\n\n const includedLevels = Object.entries(Level)\n .filter(([_, value]) => {\n return value >= args[\"--log-level\"];\n })\n .map(([key]) => key.toLowerCase())\n .join(\"|\");\n\n return edit.subscribe({\n subscription: ENVIRONMENT_LOGS_SUBSCRIPTION,\n variables: () => ({\n query: `{environment_id=\"${edit.environment.id}\"} | json | level=~\"${includedLevels}\"${args[\"--my-logs\"] ? ' | source=\"user\"' : \"\"}`,\n start: new Date(),\n }),\n onError,\n onData: ({ logsSearchV2 }) => {\n for (const log of logsSearchV2.data[\"messages\"] as [string, string][]) {\n const message: unknown = JSON.parse(log[1]);\n const { msg, name, level, ...fields } = message as Record<string, unknown>;\n\n logger(\n level as string,\n name as string,\n msg as Lowercase<string>,\n {\n ...fields,\n } as Fields,\n new Date(Number(log[0]) / 1_000_000),\n );\n }\n },\n });\n};\n"],
5
+ "mappings": "wIAAAA,IASO,IAAMC,EAA6BC,EAAA,CACxCC,EACAC,EACA,CACE,QAAAC,CACF,IAGoD,CACpD,IAAMC,EAASC,EAAkCJ,EAAK,WAAW,EAE3DK,EAAiB,OAAO,QAAQC,CAAK,EACxC,OAAO,CAAC,CAACC,EAAGC,CAAK,IACTA,GAASP,EAAK,aAAa,CACnC,EACA,IAAI,CAAC,CAACQ,CAAG,IAAMA,EAAI,YAAY,CAAC,EAChC,KAAK,GAAG,EAEX,OAAOT,EAAK,UAAU,CACpB,aAAcU,EACd,UAAWX,EAAA,KAAO,CAChB,MAAO,oBAAoBC,EAAK,YAAY,EAAE,uBAAuBK,CAAc,IAAIJ,EAAK,WAAW,EAAI,mBAAqB,EAAE,GAClI,MAAO,IAAI,IACb,GAHW,aAIX,QAAAC,EACA,OAAQH,EAAA,CAAC,CAAE,aAAAY,CAAa,IAAM,CAC5B,QAAWC,KAAOD,EAAa,KAAK,SAAmC,CACrE,IAAME,EAAmB,KAAK,MAAMD,EAAI,CAAC,CAAC,EACpC,CAAE,IAAAE,EAAK,KAAAC,EAAM,MAAAC,EAAO,GAAGC,CAAO,EAAIJ,EAExCV,EACEa,EACAD,EACAD,EACA,CACE,GAAGG,CACL,EACA,IAAI,KAAK,OAAOL,EAAI,CAAC,CAAC,EAAI,GAAS,CACrC,CACF,CACF,EAfQ,SAgBV,CAAC,CACH,EA1C0C",
6
+ "names": ["init_cjs", "subscribeToEnvironmentLogs", "__name", "edit", "args", "onError", "logger", "createEnvironmentStructuredLogger", "includedLevels", "Level", "_", "value", "key", "ENVIRONMENT_LOGS_SUBSCRIPTION", "logsSearchV2", "log", "message", "msg", "name", "level", "fields"]
7
+ }
@@ -1,4 +1,4 @@
1
- import{c as a,d as y,e as w}from"./chunk-HCULGPBH.js";import{X as C,b as n,ma as u,pa as f,sa as x,ta as p}from"./chunk-JG2QCDK2.js";import{a as h,h as b}from"./chunk-7DYQUG5M.js";b();import $ from"node:assert";import m from"node:process";var q=h(o=>(o=C(o,{ensureEmptyLineAbove:!0}),u.isInteractive||(p(o.content),p(JSON.stringify(o.choices??o.groupedChoices,void 0,2)),p({ensureEmptyLineAbove:!0,content:"Aborting because ggt is not running in an interactive terminal."}),m.exit(1)),new Promise(e=>{let t=new g({formatChoice:h(s=>s,"formatChoice"),formatSelection:h(s=>s,"formatSelection"),...o});t.on("submit",e),t.on("exit",()=>m.exit(0)),t.on("abort",()=>m.exit(0))})),"select"),g=class extends y{static{h(this,"Select")}cursor=0;optionsPerPage=10;options;currentChoices;groupedChoicesTitleIndexMap=new Map;searchable;input="";allChoices;allGroupedChoices;constructor(e){super(),this.options=C(e,{formatChoice:h(t=>t,"formatChoice"),formatSelection:h(t=>t,"formatSelection"),...e}),this.searchable=this.options.searchable??!1,this.options.choices?(this.currentChoices=this.options.choices,this.allChoices=[...this.options.choices]):(this.currentChoices=this.options.groupedChoices.flatMap(([t,s])=>s),this.allChoices=[...this.currentChoices],this.allGroupedChoices=this.options.groupedChoices,this.rebuildGroupTitleIndexMap()),this.render()}rebuildGroupTitleIndexMap(){if(this.groupedChoicesTitleIndexMap.clear(),!this.allGroupedChoices)return;let e=this.input.toLowerCase(),t=0;for(let[s,r]of this.allGroupedChoices){let c=e?r.filter(i=>i.toLowerCase().includes(e)):r;for(let i=0;i<c.length;i++)i===0&&this.groupedChoicesTitleIndexMap.set(t,s),t++}}refilter(){let e=this.input.toLowerCase();this.allGroupedChoices?(e?this.currentChoices=this.allGroupedChoices.flatMap(([t,s])=>s.filter(r=>r.toLowerCase().includes(e))):this.currentChoices=this.allGroupedChoices.flatMap(([t,s])=>s),this.rebuildGroupTitleIndexMap()):e?this.currentChoices=this.allChoices.filter(t=>t.toLowerCase().includes(e)):this.currentChoices=[...this.allChoices],this.cursor=0,this.render()}get selection(){let e=this.currentChoices[this.cursor];return $(e,`choices[${this.cursor}] is not defined`),e}moveCursor(e){this.cursor=e,this.fire()}reset(){this.moveCursor(0),this.fire(),this.render()}exit(){if(this.searchable&&this.input.length>0){this.input="",this.refilter();return}this.bell()}abort(){this.done=this.aborted=!0,this.fire(),this.render("Cancel (Ctrl+C)"),this.close()}submit(){if(this.currentChoices.length===0){this.bell();return}this.done=!0,this.aborted=!1,this.value=this.selection,this.fire(),this.render(),this.close()}delete(){if(!this.searchable||this.input.length===0){this.bell();return}this.input=this.input.slice(0,-1),this.refilter()}first(){this.currentChoices.length!==0&&(this.moveCursor(0),this.render())}last(){this.currentChoices.length!==0&&(this.moveCursor(this.currentChoices.length-1),this.render())}up(){this.currentChoices.length!==0&&(this.cursor===0?this.moveCursor(this.currentChoices.length-1):this.moveCursor(this.cursor-1),this.render())}down(){this.currentChoices.length!==0&&(this.cursor===this.currentChoices.length-1?this.moveCursor(0):this.moveCursor(this.cursor+1),this.render())}next(){this.currentChoices.length!==0&&(this.moveCursor((this.cursor+1)%this.currentChoices.length),this.render())}_(e,t){if(this.searchable&&e){if(e===" "&&this.input.length===0){this.submit();return}this.input+=e,this.refilter();return}if(e===" "){this.submit();return}}render(e){if(this.closed)return;super.render();let t=this.options.content;if(this.done){u.persistPrompt(x({...this.options,content:`${t.trimEnd()} ${this.options.formatChoice(e??this.selection)}`}));return}if(this.searchable?(t+=` ${n.gray("Type to filter, arrow keys to move")}
1
+ import{c as a,d as y,e as w}from"./chunk-72J7X5LR.js";import{X as C,b as n,ma as u,pa as f,sa as x,ta as p}from"./chunk-ALSXPCRD.js";import{a as h,h as b}from"./chunk-7DYQUG5M.js";b();import $ from"node:assert";import m from"node:process";var q=h(o=>(o=C(o,{ensureEmptyLineAbove:!0}),u.isInteractive||(p(o.content),p(JSON.stringify(o.choices??o.groupedChoices,void 0,2)),p({ensureEmptyLineAbove:!0,content:"Aborting because ggt is not running in an interactive terminal."}),m.exit(1)),new Promise(e=>{let t=new g({formatChoice:h(s=>s,"formatChoice"),formatSelection:h(s=>s,"formatSelection"),...o});t.on("submit",e),t.on("exit",()=>m.exit(0)),t.on("abort",()=>m.exit(0))})),"select"),g=class extends y{static{h(this,"Select")}cursor=0;optionsPerPage=10;options;currentChoices;groupedChoicesTitleIndexMap=new Map;searchable;input="";allChoices;allGroupedChoices;constructor(e){super(),this.options=C(e,{formatChoice:h(t=>t,"formatChoice"),formatSelection:h(t=>t,"formatSelection"),...e}),this.searchable=this.options.searchable??!1,this.options.choices?(this.currentChoices=this.options.choices,this.allChoices=[...this.options.choices]):(this.currentChoices=this.options.groupedChoices.flatMap(([t,s])=>s),this.allChoices=[...this.currentChoices],this.allGroupedChoices=this.options.groupedChoices,this.rebuildGroupTitleIndexMap()),this.render()}rebuildGroupTitleIndexMap(){if(this.groupedChoicesTitleIndexMap.clear(),!this.allGroupedChoices)return;let e=this.input.toLowerCase(),t=0;for(let[s,r]of this.allGroupedChoices){let c=e?r.filter(i=>i.toLowerCase().includes(e)):r;for(let i=0;i<c.length;i++)i===0&&this.groupedChoicesTitleIndexMap.set(t,s),t++}}refilter(){let e=this.input.toLowerCase();this.allGroupedChoices?(e?this.currentChoices=this.allGroupedChoices.flatMap(([t,s])=>s.filter(r=>r.toLowerCase().includes(e))):this.currentChoices=this.allGroupedChoices.flatMap(([t,s])=>s),this.rebuildGroupTitleIndexMap()):e?this.currentChoices=this.allChoices.filter(t=>t.toLowerCase().includes(e)):this.currentChoices=[...this.allChoices],this.cursor=0,this.render()}get selection(){let e=this.currentChoices[this.cursor];return $(e,`choices[${this.cursor}] is not defined`),e}moveCursor(e){this.cursor=e,this.fire()}reset(){this.moveCursor(0),this.fire(),this.render()}exit(){if(this.searchable&&this.input.length>0){this.input="",this.refilter();return}this.bell()}abort(){this.done=this.aborted=!0,this.fire(),this.render("Cancel (Ctrl+C)"),this.close()}submit(){if(this.currentChoices.length===0){this.bell();return}this.done=!0,this.aborted=!1,this.value=this.selection,this.fire(),this.render(),this.close()}delete(){if(!this.searchable||this.input.length===0){this.bell();return}this.input=this.input.slice(0,-1),this.refilter()}first(){this.currentChoices.length!==0&&(this.moveCursor(0),this.render())}last(){this.currentChoices.length!==0&&(this.moveCursor(this.currentChoices.length-1),this.render())}up(){this.currentChoices.length!==0&&(this.cursor===0?this.moveCursor(this.currentChoices.length-1):this.moveCursor(this.cursor-1),this.render())}down(){this.currentChoices.length!==0&&(this.cursor===this.currentChoices.length-1?this.moveCursor(0):this.moveCursor(this.cursor+1),this.render())}next(){this.currentChoices.length!==0&&(this.moveCursor((this.cursor+1)%this.currentChoices.length),this.render())}_(e,t){if(this.searchable&&e){if(e===" "&&this.input.length===0){this.submit();return}this.input+=e,this.refilter();return}if(e===" "){this.submit();return}}render(e){if(this.closed)return;super.render();let t=this.options.content;if(this.done){u.persistPrompt(x({...this.options,content:`${t.trimEnd()} ${this.options.formatChoice(e??this.selection)}`}));return}if(this.searchable?(t+=` ${n.gray("Type to filter, arrow keys to move")}
2
2
  `,t+=`${n.gray(">")} ${this.input}
3
3
 
4
4
  `):t+=` ${n.gray("Use arrow keys to move")}
@@ -8,4 +8,4 @@ import{c as a,d as y,e as w}from"./chunk-HCULGPBH.js";import{X as C,b as n,ma as
8
8
  `),s+=`${n.grey(this.groupedChoicesTitleIndexMap.get(i))}
9
9
  `),s+=`${l}${d}
10
10
  `}this.options.indent&&(s=f(s,this.options.indent)),u.updatePrompt(t+s)}};export{q as a};
11
- //# sourceMappingURL=chunk-DR4CXBD6.js.map
11
+ //# sourceMappingURL=chunk-F6BGQ4LG.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/services/output/select.ts"],
4
- "sourcesContent": ["import chalk from \"chalk\";\nimport indentString from \"indent-string\";\nimport assert from \"node:assert\";\nimport process from \"node:process\";\n\nimport type { XOR } from \"../util/types.js\";\n\nimport { defaults } from \"../util/object.js\";\nimport { output } from \"./output.js\";\nimport { println } from \"./print.js\";\nimport { entriesToDisplay, Prompt, type StdinKey } from \"./prompt.js\";\nimport { sprintln, type SprintOptionsWithContent } from \"./sprint.js\";\nimport { symbol } from \"./symbols.js\";\n\ntype BaseSelectOptions<Choice extends string> = SprintOptionsWithContent & {\n formatChoice?: (choice: Choice) => string;\n formatSelection?: (choice: Choice) => string;\n searchable?: boolean;\n};\n\ntype FlatChoices<Choice extends string> = {\n choices: Choice[];\n};\n\ntype GroupedChoices<Choice extends string> = {\n groupedChoices: [string, Choice[]][];\n};\n\nexport type SelectOptions<Choice extends string> = BaseSelectOptions<Choice> & XOR<FlatChoices<Choice>, GroupedChoices<Choice>>;\n\nexport type select = typeof select;\n\nexport const select = <Choice extends string>(options: SelectOptions<Choice>): Promise<Choice> => {\n options = defaults(options, {\n ensureEmptyLineAbove: true,\n });\n\n if (!output.isInteractive) {\n println(options.content);\n println(JSON.stringify(options.choices ?? options.groupedChoices, undefined, 2));\n println({ ensureEmptyLineAbove: true, content: \"Aborting because ggt is not running in an interactive terminal.\" });\n process.exit(1);\n }\n\n return new Promise((resolve) => {\n const sel = new Select({\n formatChoice: (choice) => choice,\n formatSelection: (choice) => choice,\n ...options,\n });\n sel.on(\"submit\", resolve);\n sel.on(\"exit\", () => process.exit(0));\n sel.on(\"abort\", () => process.exit(0));\n });\n};\n\n/**\n * Inspired by `prompts`:\n * https://github.com/terkelg/prompts/blob/e0519913ec4fcc6746bb3d97d8cd0960c3f3ffde/lib/elements/select.js\n *\n * MIT License\n *\n * Copyright (c) 2018 Terkel Gjervig Nielsen\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\nclass Select<Choice extends string> extends Prompt {\n cursor = 0;\n optionsPerPage = 10;\n options;\n currentChoices: Choice[];\n groupedChoicesTitleIndexMap = new Map<number, string>();\n\n // search state\n searchable: boolean;\n input = \"\";\n allChoices: Choice[];\n allGroupedChoices?: [string, Choice[]][];\n\n constructor(options: SelectOptions<Choice>) {\n super();\n\n this.options = defaults(options, {\n formatChoice: (choice) => choice,\n formatSelection: (choice) => choice,\n ...options,\n });\n\n this.searchable = this.options.searchable ?? false;\n\n if (this.options.choices) {\n this.currentChoices = this.options.choices;\n this.allChoices = [...this.options.choices];\n } else {\n this.currentChoices = this.options.groupedChoices.flatMap(([_, choices]) => choices);\n this.allChoices = [...this.currentChoices];\n this.allGroupedChoices = this.options.groupedChoices;\n this.rebuildGroupTitleIndexMap();\n }\n\n this.render();\n }\n\n private rebuildGroupTitleIndexMap(): void {\n this.groupedChoicesTitleIndexMap.clear();\n\n if (!this.allGroupedChoices) {\n return;\n }\n\n // build the map from the current filtered choices\n const query = this.input.toLowerCase();\n let currentIndex = 0;\n\n for (const [title, choices] of this.allGroupedChoices) {\n const filtered = query ? choices.filter((c) => c.toLowerCase().includes(query)) : choices;\n\n for (let i = 0; i < filtered.length; i++) {\n if (i === 0) {\n this.groupedChoicesTitleIndexMap.set(currentIndex, title);\n }\n currentIndex++;\n }\n }\n }\n\n private refilter(): void {\n const query = this.input.toLowerCase();\n\n if (this.allGroupedChoices) {\n if (query) {\n this.currentChoices = this.allGroupedChoices.flatMap(([_, choices]) =>\n choices.filter((c) => c.toLowerCase().includes(query)),\n ) as Choice[];\n } else {\n this.currentChoices = this.allGroupedChoices.flatMap(([_, choices]) => choices) as Choice[];\n }\n this.rebuildGroupTitleIndexMap();\n } else {\n if (query) {\n this.currentChoices = this.allChoices.filter((c) => c.toLowerCase().includes(query));\n } else {\n this.currentChoices = [...this.allChoices];\n }\n }\n\n this.cursor = 0;\n this.render();\n }\n\n get selection(): Choice {\n const choice = this.currentChoices[this.cursor];\n assert(choice, `choices[${this.cursor}] is not defined`);\n return choice;\n }\n\n moveCursor(n: number): void {\n this.cursor = n;\n this.fire();\n }\n\n reset(): void {\n this.moveCursor(0);\n this.fire();\n this.render();\n }\n\n exit(): void {\n if (this.searchable && this.input.length > 0) {\n this.input = \"\";\n this.refilter();\n return;\n }\n this.bell();\n }\n\n abort(): void {\n this.done = this.aborted = true;\n this.fire();\n this.render(\"Cancel (Ctrl+C)\" as Choice);\n this.close();\n }\n\n submit(): void {\n if (this.currentChoices.length === 0) {\n this.bell();\n return;\n }\n this.done = true;\n this.aborted = false;\n this.value = this.selection;\n this.fire();\n this.render();\n this.close();\n }\n\n delete(): void {\n if (!this.searchable || this.input.length === 0) {\n this.bell();\n return;\n }\n this.input = this.input.slice(0, -1);\n this.refilter();\n }\n\n first(): void {\n if (this.currentChoices.length === 0) {\n return;\n }\n this.moveCursor(0);\n this.render();\n }\n\n last(): void {\n if (this.currentChoices.length === 0) {\n return;\n }\n this.moveCursor(this.currentChoices.length - 1);\n this.render();\n }\n\n up(): void {\n if (this.currentChoices.length === 0) {\n return;\n }\n if (this.cursor === 0) {\n this.moveCursor(this.currentChoices.length - 1);\n } else {\n this.moveCursor(this.cursor - 1);\n }\n this.render();\n }\n\n down(): void {\n if (this.currentChoices.length === 0) {\n return;\n }\n if (this.cursor === this.currentChoices.length - 1) {\n this.moveCursor(0);\n } else {\n this.moveCursor(this.cursor + 1);\n }\n this.render();\n }\n\n next(): void {\n if (this.currentChoices.length === 0) {\n return;\n }\n this.moveCursor((this.cursor + 1) % this.currentChoices.length);\n this.render();\n }\n\n override _(char: string, _key: StdinKey): void {\n if (this.searchable && char) {\n if (char === \" \" && this.input.length === 0) {\n this.submit();\n return;\n }\n this.input += char;\n this.refilter();\n return;\n }\n\n if (char === \" \") {\n this.submit();\n return;\n }\n }\n\n override render(selection?: Choice): void {\n if (this.closed) {\n return;\n }\n\n super.render();\n\n let question = this.options.content;\n if (this.done) {\n output.persistPrompt(\n sprintln({\n ...this.options,\n content: `${question.trimEnd()} ${this.options.formatChoice(selection ?? this.selection)}`,\n }),\n );\n return;\n }\n\n if (this.searchable) {\n question += ` ${chalk.gray(\"Type to filter, arrow keys to move\")}\\n`;\n question += `${chalk.gray(\">\")} ${this.input}\\n\\n`;\n } else {\n question += ` ${chalk.gray(\"Use arrow keys to move\")}\\n\\n`;\n }\n\n if (this.currentChoices.length === 0) {\n let noMatches = chalk.gray(\"No matches found\") + \"\\n\";\n if (this.options.indent) {\n noMatches = indentString(noMatches, this.options.indent);\n }\n output.updatePrompt(question + noMatches);\n return;\n }\n\n let choices = \"\";\n const { startIndex, endIndex } = entriesToDisplay(this.cursor, this.currentChoices.length, this.optionsPerPage);\n for (let index = startIndex; index < endIndex; index++) {\n // determine whether to display \"more choices\" indicators\n let prefix: string;\n if (this.cursor === index) {\n prefix = `${symbol.arrowRight} `;\n } else if (index === startIndex && startIndex > 0) {\n prefix = `${symbol.arrowUp} `;\n } else if (index === endIndex - 1 && endIndex < this.currentChoices.length) {\n prefix = `${symbol.arrowDown} `;\n } else {\n prefix = \" \";\n }\n\n const choice_ = this.currentChoices[index];\n assert(choice_, `choices[${index}] is not defined`);\n\n let choice = this.options.formatChoice(choice_);\n if (this.cursor === index) {\n choice = chalk.blue.underline(choice);\n }\n\n if (this.groupedChoicesTitleIndexMap.has(index)) {\n if (index !== startIndex) {\n choices += \"\\n\";\n }\n\n choices += `${chalk.grey(this.groupedChoicesTitleIndexMap.get(index))}\\n`;\n }\n choices += `${prefix}${choice}\\n`;\n }\n\n if (this.options.indent) {\n choices = indentString(choices, this.options.indent);\n }\n\n output.updatePrompt(question + choices);\n }\n}\n"],
5
- "mappings": "oLAAAA,IAEA,OAAOC,MAAY,cACnB,OAAOC,MAAa,eA6Bb,IAAMC,EAASC,EAAwBC,IAC5CA,EAAUC,EAASD,EAAS,CAC1B,qBAAsB,EACxB,CAAC,EAEIE,EAAO,gBACVC,EAAQH,EAAQ,OAAO,EACvBG,EAAQ,KAAK,UAAUH,EAAQ,SAAWA,EAAQ,eAAgB,OAAW,CAAC,CAAC,EAC/EG,EAAQ,CAAE,qBAAsB,GAAM,QAAS,iEAAkE,CAAC,EAClHC,EAAQ,KAAK,CAAC,GAGT,IAAI,QAASC,GAAY,CAC9B,IAAMC,EAAM,IAAIC,EAAO,CACrB,aAAcR,EAACS,GAAWA,EAAZ,gBACd,gBAAiBT,EAACS,GAAWA,EAAZ,mBACjB,GAAGR,CACL,CAAC,EACDM,EAAI,GAAG,SAAUD,CAAO,EACxBC,EAAI,GAAG,OAAQ,IAAMF,EAAQ,KAAK,CAAC,CAAC,EACpCE,EAAI,GAAG,QAAS,IAAMF,EAAQ,KAAK,CAA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GAE5CF,GAAY,IAAIE,EAAM,KAAK,wBAAwB,CAAC;AAAA;AAAA,EAGlD,KAAK,eAAe,SAAW,EAAG,CACpC,IAAIC,EAAYD,EAAM,KAAK,kBAAkB,EAAI;AAAA,EAC7C,KAAK,QAAQ,SACfC,EAAYC,EAAaD,EAAW,KAAK,QAAQ,MAAM,GAEzDvB,EAAO,aAAaoB,EAAWG,CAAS,EACxC,MACF,CAEA,IAAId,EAAU,GACR,CAAE,WAAAgB,EAAY,SAAAC,CAAS,EAAIC,EAAiB,KAAK,OAAQ,KAAK,eAAe,OAAQ,KAAK,cAAc,EAC9G,QAASC,EAAQH,EAAYG,EAAQF,EAAUE,IAAS,CAEtD,IAAIC,EACA,KAAK,SAAWD,EAClBC,EAAS,GAAGC,EAAO,UAAU,IACpBF,IAAUH,GAAcA,EAAa,EAC9CI,EAAS,GAAGC,EAAO,OAAO,IACjBF,IAAUF,EAAW,GAAKA,EAAW,KAAK,eAAe,OAClEG,EAAS,GAAGC,EAAO,SAAS,IAE5BD,EAAS,KAGX,IAAME,EAAU,KAAK,eAAeH,CAAK,EACzCb,EAAOgB,EAAS,WAAWH,CAAK,kBAAkB,EAElD,IAAItB,EAAS,KAAK,QAAQ,aAAayB,CAAO,EAC1C,KAAK,SAAWH,IAClBtB,EAASgB,EAAM,KAAK,UAAUhB,CAAM,GAGlC,KAAK,4BAA4B,IAAIsB,CAAK,IACxCA,IAAUH,IACZhB,GAAW;AAAA,GAGbA,GAAW,GAAGa,EAAM,KAAK,KAAK,4BAA4B,IAAIM,CAAK,CAAC,CAAC;AAAA,GAEvEnB,GAAW,GAAGoB,CAAM,GAAGvB,CAAM;AAAA,CAC/B,CAEI,KAAK,QAAQ,SACfG,EAAUe,EAAaf,EAAS,KAAK,QAAQ,MAAM,GAGrDT,EAAO,aAAaoB,EAAWX,CAAO,CACxC,CACF",
4
+ "sourcesContent": ["import assert from \"node:assert\";\nimport process from \"node:process\";\n\nimport chalk from \"chalk\";\nimport indentString from \"indent-string\";\n\nimport { defaults } from \"../util/object.js\";\nimport type { XOR } from \"../util/types.js\";\nimport { output } from \"./output.js\";\nimport { println } from \"./print.js\";\nimport { entriesToDisplay, Prompt, type StdinKey } from \"./prompt.js\";\nimport { sprintln, type SprintOptionsWithContent } from \"./sprint.js\";\nimport { symbol } from \"./symbols.js\";\n\ntype BaseSelectOptions<Choice extends string> = SprintOptionsWithContent & {\n formatChoice?: (choice: Choice) => string;\n formatSelection?: (choice: Choice) => string;\n searchable?: boolean;\n};\n\ntype FlatChoices<Choice extends string> = {\n choices: Choice[];\n};\n\ntype GroupedChoices<Choice extends string> = {\n groupedChoices: [string, Choice[]][];\n};\n\nexport type SelectOptions<Choice extends string> = BaseSelectOptions<Choice> & XOR<FlatChoices<Choice>, GroupedChoices<Choice>>;\n\nexport type select = typeof select;\n\nexport const select = <Choice extends string>(options: SelectOptions<Choice>): Promise<Choice> => {\n options = defaults(options, {\n ensureEmptyLineAbove: true,\n });\n\n if (!output.isInteractive) {\n println(options.content);\n println(JSON.stringify(options.choices ?? options.groupedChoices, undefined, 2));\n println({ ensureEmptyLineAbove: true, content: \"Aborting because ggt is not running in an interactive terminal.\" });\n process.exit(1);\n }\n\n return new Promise((resolve) => {\n const sel = new Select({\n formatChoice: (choice) => choice,\n formatSelection: (choice) => choice,\n ...options,\n });\n sel.on(\"submit\", resolve);\n sel.on(\"exit\", () => process.exit(0));\n sel.on(\"abort\", () => process.exit(0));\n });\n};\n\n/**\n * Inspired by `prompts`:\n * https://github.com/terkelg/prompts/blob/e0519913ec4fcc6746bb3d97d8cd0960c3f3ffde/lib/elements/select.js\n *\n * MIT License\n *\n * Copyright (c) 2018 Terkel Gjervig Nielsen\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\nclass Select<Choice extends string> extends Prompt {\n cursor = 0;\n optionsPerPage = 10;\n options;\n currentChoices: Choice[];\n groupedChoicesTitleIndexMap = new Map<number, string>();\n\n // search state\n searchable: boolean;\n input = \"\";\n allChoices: Choice[];\n allGroupedChoices?: [string, Choice[]][];\n\n constructor(options: SelectOptions<Choice>) {\n super();\n\n this.options = defaults(options, {\n formatChoice: (choice) => choice,\n formatSelection: (choice) => choice,\n ...options,\n });\n\n this.searchable = this.options.searchable ?? false;\n\n if (this.options.choices) {\n this.currentChoices = this.options.choices;\n this.allChoices = [...this.options.choices];\n } else {\n this.currentChoices = this.options.groupedChoices.flatMap(([_, choices]) => choices);\n this.allChoices = [...this.currentChoices];\n this.allGroupedChoices = this.options.groupedChoices;\n this.rebuildGroupTitleIndexMap();\n }\n\n this.render();\n }\n\n private rebuildGroupTitleIndexMap(): void {\n this.groupedChoicesTitleIndexMap.clear();\n\n if (!this.allGroupedChoices) {\n return;\n }\n\n // build the map from the current filtered choices\n const query = this.input.toLowerCase();\n let currentIndex = 0;\n\n for (const [title, choices] of this.allGroupedChoices) {\n const filtered = query ? choices.filter((c) => c.toLowerCase().includes(query)) : choices;\n\n for (let i = 0; i < filtered.length; i++) {\n if (i === 0) {\n this.groupedChoicesTitleIndexMap.set(currentIndex, title);\n }\n currentIndex++;\n }\n }\n }\n\n private refilter(): void {\n const query = this.input.toLowerCase();\n\n if (this.allGroupedChoices) {\n if (query) {\n this.currentChoices = this.allGroupedChoices.flatMap(([_, choices]) =>\n choices.filter((c) => c.toLowerCase().includes(query)),\n ) as Choice[];\n } else {\n this.currentChoices = this.allGroupedChoices.flatMap(([_, choices]) => choices) as Choice[];\n }\n this.rebuildGroupTitleIndexMap();\n } else {\n if (query) {\n this.currentChoices = this.allChoices.filter((c) => c.toLowerCase().includes(query));\n } else {\n this.currentChoices = [...this.allChoices];\n }\n }\n\n this.cursor = 0;\n this.render();\n }\n\n get selection(): Choice {\n const choice = this.currentChoices[this.cursor];\n assert(choice, `choices[${this.cursor}] is not defined`);\n return choice;\n }\n\n moveCursor(n: number): void {\n this.cursor = n;\n this.fire();\n }\n\n reset(): void {\n this.moveCursor(0);\n this.fire();\n this.render();\n }\n\n exit(): void {\n if (this.searchable && this.input.length > 0) {\n this.input = \"\";\n this.refilter();\n return;\n }\n this.bell();\n }\n\n abort(): void {\n this.done = this.aborted = true;\n this.fire();\n this.render(\"Cancel (Ctrl+C)\" as Choice);\n this.close();\n }\n\n submit(): void {\n if (this.currentChoices.length === 0) {\n this.bell();\n return;\n }\n this.done = true;\n this.aborted = false;\n this.value = this.selection;\n this.fire();\n this.render();\n this.close();\n }\n\n delete(): void {\n if (!this.searchable || this.input.length === 0) {\n this.bell();\n return;\n }\n this.input = this.input.slice(0, -1);\n this.refilter();\n }\n\n first(): void {\n if (this.currentChoices.length === 0) {\n return;\n }\n this.moveCursor(0);\n this.render();\n }\n\n last(): void {\n if (this.currentChoices.length === 0) {\n return;\n }\n this.moveCursor(this.currentChoices.length - 1);\n this.render();\n }\n\n up(): void {\n if (this.currentChoices.length === 0) {\n return;\n }\n if (this.cursor === 0) {\n this.moveCursor(this.currentChoices.length - 1);\n } else {\n this.moveCursor(this.cursor - 1);\n }\n this.render();\n }\n\n down(): void {\n if (this.currentChoices.length === 0) {\n return;\n }\n if (this.cursor === this.currentChoices.length - 1) {\n this.moveCursor(0);\n } else {\n this.moveCursor(this.cursor + 1);\n }\n this.render();\n }\n\n next(): void {\n if (this.currentChoices.length === 0) {\n return;\n }\n this.moveCursor((this.cursor + 1) % this.currentChoices.length);\n this.render();\n }\n\n override _(char: string, _key: StdinKey): void {\n if (this.searchable && char) {\n if (char === \" \" && this.input.length === 0) {\n this.submit();\n return;\n }\n this.input += char;\n this.refilter();\n return;\n }\n\n if (char === \" \") {\n this.submit();\n return;\n }\n }\n\n override render(selection?: Choice): void {\n if (this.closed) {\n return;\n }\n\n super.render();\n\n let question = this.options.content;\n if (this.done) {\n output.persistPrompt(\n sprintln({\n ...this.options,\n content: `${question.trimEnd()} ${this.options.formatChoice(selection ?? this.selection)}`,\n }),\n );\n return;\n }\n\n if (this.searchable) {\n question += ` ${chalk.gray(\"Type to filter, arrow keys to move\")}\\n`;\n question += `${chalk.gray(\">\")} ${this.input}\\n\\n`;\n } else {\n question += ` ${chalk.gray(\"Use arrow keys to move\")}\\n\\n`;\n }\n\n if (this.currentChoices.length === 0) {\n let noMatches = chalk.gray(\"No matches found\") + \"\\n\";\n if (this.options.indent) {\n noMatches = indentString(noMatches, this.options.indent);\n }\n output.updatePrompt(question + noMatches);\n return;\n }\n\n let choices = \"\";\n const { startIndex, endIndex } = entriesToDisplay(this.cursor, this.currentChoices.length, this.optionsPerPage);\n for (let index = startIndex; index < endIndex; index++) {\n // determine whether to display \"more choices\" indicators\n let prefix: string;\n if (this.cursor === index) {\n prefix = `${symbol.arrowRight} `;\n } else if (index === startIndex && startIndex > 0) {\n prefix = `${symbol.arrowUp} `;\n } else if (index === endIndex - 1 && endIndex < this.currentChoices.length) {\n prefix = `${symbol.arrowDown} `;\n } else {\n prefix = \" \";\n }\n\n const choice_ = this.currentChoices[index];\n assert(choice_, `choices[${index}] is not defined`);\n\n let choice = this.options.formatChoice(choice_);\n if (this.cursor === index) {\n choice = chalk.blue.underline(choice);\n }\n\n if (this.groupedChoicesTitleIndexMap.has(index)) {\n if (index !== startIndex) {\n choices += \"\\n\";\n }\n\n choices += `${chalk.grey(this.groupedChoicesTitleIndexMap.get(index))}\\n`;\n }\n choices += `${prefix}${choice}\\n`;\n }\n\n if (this.options.indent) {\n choices = indentString(choices, this.options.indent);\n }\n\n output.updatePrompt(question + choices);\n }\n}\n"],
5
+ "mappings": "oLAAAA,IAAA,OAAOC,MAAY,cACnB,OAAOC,MAAa,eA+Bb,IAAMC,EAASC,EAAwBC,IAC5CA,EAAUC,EAASD,EAAS,CAC1B,qBAAsB,EACxB,CAAC,EAEIE,EAAO,gBACVC,EAAQH,EAAQ,OAAO,EACvBG,EAAQ,KAAK,UAAUH,EAAQ,SAAWA,EAAQ,eAAgB,OAAW,CAAC,CAAC,EAC/EG,EAAQ,CAAE,qBAAsB,GAAM,QAAS,iEAAkE,CAAC,EAClHC,EAAQ,KAAK,CAAC,GAGT,IAAI,QAASC,GAAY,CAC9B,IAAMC,EAAM,IAAIC,EAAO,CACrB,aAAcR,EAACS,GAAWA,EAAZ,gBACd,gBAAiBT,EAACS,GAAWA,EAAZ,mBACjB,GAAGR,CACL,CAAC,EACDM,EAAI,GAAG,SAAUD,CAAO,EACxBC,EAAI,GAAG,OAAQ,IAAMF,EAAQ,KAAK,CAAC,CAAC,EACpCE,EAAI,GAAG,QAAS,IAAMF,EAAQ,KAAK,CAAC,CAAC,CACvC,CAAC,GArBmB,UAkDhBG,EAAN,cAA4CE,CAAO,CAlFnD,MAkFmD,CAAAV,EAAA,eACjD,OAAS,EACT,eAAiB,GACjB,QACA,eACA,4BAA8B,IAAI,IAGlC,WACA,MAAQ,GACR,WACA,kBAEA,YAAYC,EAAgC,CAC1C,MAAM,EAEN,KAAK,QAAUC,EAASD,EAAS,CAC/B,aAAcD,EAACS,GAAWA,EAAZ,gBACd,gBAAiBT,EAACS,GAAWA,EAAZ,mBACjB,GAAGR,CACL,CAAC,EAED,KAAK,WAAa,KAAK,QAAQ,YA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K,cAAc,EAC9G,QAASC,EAAQH,EAAYG,EAAQF,EAAUE,IAAS,CAEtD,IAAIC,EACA,KAAK,SAAWD,EAClBC,EAAS,GAAGC,EAAO,UAAU,IACpBF,IAAUH,GAAcA,EAAa,EAC9CI,EAAS,GAAGC,EAAO,OAAO,IACjBF,IAAUF,EAAW,GAAKA,EAAW,KAAK,eAAe,OAClEG,EAAS,GAAGC,EAAO,SAAS,IAE5BD,EAAS,KAGX,IAAME,EAAU,KAAK,eAAeH,CAAK,EACzCb,EAAOgB,EAAS,WAAWH,CAAK,kBAAkB,EAElD,IAAItB,EAAS,KAAK,QAAQ,aAAayB,CAAO,EAC1C,KAAK,SAAWH,IAClBtB,EAASgB,EAAM,KAAK,UAAUhB,CAAM,GAGlC,KAAK,4BAA4B,IAAIsB,CAAK,IACxCA,IAAUH,IACZhB,GAAW;AAAA,GAGbA,GAAW,GAAGa,EAAM,KAAK,KAAK,4BAA4B,IAAIM,CAAK,CAAC,CAAC;AAAA,GAEvEnB,GAAW,GAAGoB,CAAM,GAAGvB,CAAM;AAAA,CAC/B,CAEI,KAAK,QAAQ,SACfG,EAAUe,EAAaf,EAAS,KAAK,QAAQ,MAAM,GAGrDT,EAAO,aAAaoB,EAAWX,CAAO,CACxC,CACF",
6
6
  "names": ["init_cjs", "assert", "process", "select", "__name", "options", "defaults", "output", "println", "process", "resolve", "sel", "Select", "choice", "Prompt", "_", "choices", "query", "currentIndex", "title", "filtered", "c", "assert", "n", "char", "_key", "selection", "question", "sprintln", "source_default", "noMatches", "indentString", "startIndex", "endIndex", "entriesToDisplay", "index", "prefix", "symbol", "choice_"]
7
7
  }
@@ -1,2 +1,2 @@
1
- import{a as l}from"./chunk-DR4CXBD6.js";import{c as g}from"./chunk-OUIZQC4D.js";import{K as d,ha as i,ma as c,ta as r}from"./chunk-JG2QCDK2.js";import{a as s,f as p,h as u}from"./chunk-7DYQUG5M.js";u();var f=p(d(),1);var D=s(async t=>{let o=i.defaultsConfigFile,e;if(await l({ensureEmptyLineAbove:!0,choices:["default","configure"],content:"Default configuration from Gadget or configure manually"})==="configure"){let n=await l({ensureEmptyLineAbove:!0,choices:["enable","disable"],content:"Automatically send crash reports and telemetry to Gadget"}),m=await l({ensureEmptyLineAbove:!0,choices:["disable","enable"],content:"ggt output as JSON"});e={telemetry:n==="enable",json:m==="enable"}}else e={telemetry:!0,json:!1};return await f.default.outputJSON(o,e).then(()=>{r("Default arguments were saved.")},n=>{t.log.error("failed to write config",{error:n.message})}),e},"promptDefaultsConfig"),x=s(async(t,o)=>{let e=i.defaultsConfigFile,a;try{a=await f.default.readJSON(e)}catch(n){g(n),c.isInteractive&&o?(r("No ggt defaults were found to have been configured. Please answer the prompts to configure your defaults."),a=await D(t),r("To update these options later, see `ggt configure`.")):a={}}return a},"loadDefaultsConfig"),v=s(async t=>{let o=i.defaultsConfigFile;await f.default.outputJSON(o,{}).then(()=>{r("Default arguments were saved.")},e=>{t.log.error("failed to write config",{error:e.message})})},"clearDefaultsConfig");export{D as a,x as b,v as c};
2
- //# sourceMappingURL=chunk-SVWK2NXG.js.map
1
+ import{a as l}from"./chunk-F6BGQ4LG.js";import{c as g}from"./chunk-X4XSYLCE.js";import{K as d,ha as i,ma as c,ta as r}from"./chunk-ALSXPCRD.js";import{a as s,f as p,h as u}from"./chunk-7DYQUG5M.js";u();var f=p(d(),1);var D=s(async t=>{let o=i.defaultsConfigFile,e;if(await l({ensureEmptyLineAbove:!0,choices:["default","configure"],content:"Default configuration from Gadget or configure manually"})==="configure"){let n=await l({ensureEmptyLineAbove:!0,choices:["enable","disable"],content:"Automatically send crash reports and telemetry to Gadget"}),m=await l({ensureEmptyLineAbove:!0,choices:["disable","enable"],content:"ggt output as JSON"});e={telemetry:n==="enable",json:m==="enable"}}else e={telemetry:!0,json:!1};return await f.default.outputJSON(o,e).then(()=>{r("Default arguments were saved.")},n=>{t.log.error("failed to write config",{error:n.message})}),e},"promptDefaultsConfig"),x=s(async(t,o)=>{let e=i.defaultsConfigFile,a;try{a=await f.default.readJSON(e)}catch(n){g(n),c.isInteractive&&o?(r("No ggt defaults were found to have been configured. Please answer the prompts to configure your defaults."),a=await D(t),r("To update these options later, see `ggt configure`.")):a={}}return a},"loadDefaultsConfig"),v=s(async t=>{let o=i.defaultsConfigFile;await f.default.outputJSON(o,{}).then(()=>{r("Default arguments were saved.")},e=>{t.log.error("failed to write config",{error:e.message})})},"clearDefaultsConfig");export{D as a,x as b,v as c};
2
+ //# sourceMappingURL=chunk-FE5O5VX4.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/services/config/defaults.ts"],
4
+ "sourcesContent": ["import fs from \"fs-extra\";\n\nimport type { Context } from \"../command/context.js\";\nimport { swallowEnoent } from \"../filesync/directory.js\";\nimport { output } from \"../output/output.js\";\nimport { println } from \"../output/print.js\";\nimport { select } from \"../output/select.js\";\nimport { config } from \"./config.js\";\n\nexport type DefaultsConfigData = {\n telemetry?: boolean;\n json?: boolean;\n};\n\nexport const promptDefaultsConfig = async (ctx: Context): Promise<DefaultsConfigData> => {\n const path = config.defaultsConfigFile;\n let selections: DefaultsConfigData;\n\n const defaultSelection = await select({\n ensureEmptyLineAbove: true,\n choices: [\"default\", \"configure\"],\n content: \"Default configuration from Gadget or configure manually\",\n });\n\n if (defaultSelection === \"configure\") {\n const telemetrySelection = await select({\n ensureEmptyLineAbove: true,\n choices: [\"enable\", \"disable\"],\n content: \"Automatically send crash reports and telemetry to Gadget\",\n });\n\n const jsonSelection = await select({\n ensureEmptyLineAbove: true,\n choices: [\"disable\", \"enable\"],\n content: \"ggt output as JSON\",\n });\n\n selections = {\n telemetry: telemetrySelection === \"enable\",\n json: jsonSelection === \"enable\",\n };\n } else {\n /* === \"default\" */\n selections = {\n telemetry: true,\n json: false,\n };\n }\n\n await fs.outputJSON(path, selections).then(\n () => {\n println(\"Default arguments were saved.\");\n },\n (err: unknown) => {\n ctx.log.error(\"failed to write config\", { error: (err as Error).message });\n },\n );\n\n return selections;\n};\n\nexport const loadDefaultsConfig = async (ctx: Context, promptIfMissing: boolean): Promise<DefaultsConfigData> => {\n const configFilePath = config.defaultsConfigFile;\n\n let configData: null | DefaultsConfigData;\n\n try {\n configData = (await fs.readJSON(configFilePath)) as DefaultsConfigData;\n } catch (error) {\n swallowEnoent(error);\n\n /* If there's no config defaults, and it isn't interactive, we can just move on. */\n if (output.isInteractive && promptIfMissing) {\n println(\"No ggt defaults were found to have been configured. Please answer the prompts to configure your defaults.\");\n configData = await promptDefaultsConfig(ctx);\n println(\"To update these options later, see `ggt configure`.\");\n } else {\n configData = {};\n }\n }\n\n return configData;\n};\n\nexport const clearDefaultsConfig = async (ctx: Context): Promise<void> => {\n const path = config.defaultsConfigFile;\n await fs.outputJSON(path, {}).then(\n () => {\n println(\"Default arguments were saved.\");\n },\n (err: unknown) => {\n ctx.log.error(\"failed to write config\", { error: (err as Error).message });\n },\n );\n};\n"],
5
+ "mappings": "sMAAAA,IAAA,IAAAC,EAAe,SAcR,IAAMC,EAAuBC,EAAA,MAAOC,GAA8C,CACvF,IAAMC,EAAOC,EAAO,mBAChBC,EAQJ,GANyB,MAAMC,EAAO,CACpC,qBAAsB,GACtB,QAAS,CAAC,UAAW,WAAW,EAChC,QAAS,yDACX,CAAC,IAEwB,YAAa,CACpC,IAAMC,EAAqB,MAAMD,EAAO,CACtC,qBAAsB,GACtB,QAAS,CAAC,SAAU,SAAS,EAC7B,QAAS,0DACX,CAAC,EAEKE,EAAgB,MAAMF,EAAO,CACjC,qBAAsB,GACtB,QAAS,CAAC,UAAW,QAAQ,EAC7B,QAAS,oBACX,CAAC,EAEDD,EAAa,CACX,UAAWE,IAAuB,SAClC,KAAMC,IAAkB,QAC1B,CACF,MAEEH,EAAa,CACX,UAAW,GACX,KAAM,EACR,EAGF,aAAM,EAAAI,QAAG,WAAWN,EAAME,CAAU,EAAE,KACpC,IAAM,CACJK,EAAQ,+BAA+B,CACzC,EACCC,GAAiB,CAChBT,EAAI,IAAI,MAAM,yBAA0B,CAAE,MAAQS,EAAc,OAAQ,CAAC,CAC3E,CACF,EAEON,CACT,EA7CoC,wBA+CvBO,EAAqBX,EAAA,MAAOC,EAAcW,IAA0D,CAC/G,IAAMC,EAAiBV,EAAO,mBAE1BW,EAEJ,GAAI,CACFA,EAAc,MAAM,EAAAN,QAAG,SAASK,CAAc,CAChD,OAASE,EAAO,CACdC,EAAcD,CAAK,EAGfE,EAAO,eAAiBL,GAC1BH,EAAQ,2GAA2G,EACnHK,EAAa,MAAMf,EAAqBE,CAAG,EAC3CQ,EAAQ,qDAAqD,GAE7DK,EAAa,CAAC,CAElB,CAEA,OAAOA,CACT,EArBkC,sBAuBrBI,EAAsBlB,EAAA,MAAOC,GAAgC,CACxE,IAAMC,EAAOC,EAAO,mBACpB,MAAM,EAAAK,QAAG,WAAWN,EAAM,CAAC,CAAC,EAAE,KAC5B,IAAM,CACJO,EAAQ,+BAA+B,CACzC,EACCC,GAAiB,CAChBT,EAAI,IAAI,MAAM,yBAA0B,CAAE,MAAQS,EAAc,OAAQ,CAAC,CAC3E,CACF,CACF,EAVmC",
6
+ "names": ["init_cjs", "import_fs_extra", "promptDefaultsConfig", "__name", "ctx", "path", "config", "selections", "select", "telemetrySelection", "jsonSelection", "fs", "println", "err", "loadDefaultsConfig", "promptIfMissing", "configFilePath", "configData", "error", "swallowEnoent", "output", "clearDefaultsConfig"]
7
+ }
@@ -1,2 +1,2 @@
1
- import{c as d}from"./chunk-OUIZQC4D.js";import{K as f,aa as r,ia as n}from"./chunk-JG2QCDK2.js";import{a as s,f as g,h as i}from"./chunk-7DYQUG5M.js";i();var t=g(f(),1);var m=r(e=>{if(process.env.GGT_SESSION)return e.log.debug("reading session from env"),process.env.GGT_SESSION;try{return e.log.debug("reading session from disk"),t.default.readFileSync(n("session.txt"),"utf8")}catch(o){d(o);return}}),c=s((e,o)=>{m.clear(),process.env.GGT_SESSION&&(e.log.debug("writing session to env",{session:!!o}),process.env.GGT_SESSION=o),e.log.debug("writing session to disk",{session:!!o,path:n("session.txt")}),o?t.default.outputFileSync(n("session.txt"),o):t.default.removeSync(n("session.txt"))},"writeSession"),a=r(e=>(e.log.debug("reading token from env"),process.env.GGT_TOKEN));export{m as a,c as b,a as c};
2
- //# sourceMappingURL=chunk-F255O64V.js.map
1
+ import{c as d}from"./chunk-X4XSYLCE.js";import{K as f,aa as r,ia as n}from"./chunk-ALSXPCRD.js";import{a as s,f as g,h as i}from"./chunk-7DYQUG5M.js";i();var t=g(f(),1);var m=r(e=>{if(process.env.GGT_SESSION)return e.log.debug("reading session from env"),process.env.GGT_SESSION;try{return e.log.debug("reading session from disk"),t.default.readFileSync(n("session.txt"),"utf8")}catch(o){d(o);return}}),c=s((e,o)=>{m.clear(),process.env.GGT_SESSION&&(e.log.debug("writing session to env",{session:!!o}),process.env.GGT_SESSION=o),e.log.debug("writing session to disk",{session:!!o,path:n("session.txt")}),o?t.default.outputFileSync(n("session.txt"),o):t.default.removeSync(n("session.txt"))},"writeSession"),a=r(e=>(e.log.debug("reading token from env"),process.env.GGT_TOKEN));export{m as a,c as b,a as c};
2
+ //# sourceMappingURL=chunk-GZTHIOXS.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/services/user/session.ts"],
4
+ "sourcesContent": ["import fs from \"fs-extra\";\n\nimport type { Context } from \"../command/context.js\";\nimport { configPath } from \"../config/config.js\";\nimport { swallowEnoent } from \"../filesync/directory.js\";\nimport { memo } from \"../util/function.js\";\n\n/**\n * Reads the session from either the environment variable `GGT_SESSION`\n * or from the `session.txt` file in the config directory.\n *\n * @returns The session string if found, otherwise undefined.\n */\nexport const readSession = memo((ctx: Context): string | undefined => {\n if (process.env[\"GGT_SESSION\"]) {\n ctx.log.debug(\"reading session from env\");\n return process.env[\"GGT_SESSION\"];\n }\n\n try {\n ctx.log.debug(\"reading session from disk\");\n return fs.readFileSync(configPath(\"session.txt\"), \"utf8\");\n } catch (error) {\n swallowEnoent(error);\n return undefined;\n }\n});\n\n/**\n * Writes the session to disk in the `session.txt` file in the config.\n *\n * @param ctx - The context object.\n * @param session - The session to write to disk.\n */\nexport const writeSession = (ctx: Context, session: string | undefined): void => {\n readSession.clear();\n\n if (process.env[\"GGT_SESSION\"]) {\n ctx.log.debug(\"writing session to env\", { session: Boolean(session) });\n process.env[\"GGT_SESSION\"] = session;\n }\n\n ctx.log.debug(\"writing session to disk\", { session: Boolean(session), path: configPath(\"session.txt\") });\n\n if (session) {\n fs.outputFileSync(configPath(\"session.txt\"), session);\n } else {\n fs.removeSync(configPath(\"session.txt\"));\n }\n};\n\nexport const readToken = memo((ctx: Context): string | undefined => {\n ctx.log.debug(\"reading token from env\");\n return process.env[\"GGT_TOKEN\"];\n});\n"],
5
+ "mappings": "sJAAAA,IAAA,IAAAC,EAAe,SAaR,IAAMC,EAAcC,EAAMC,GAAqC,CACpE,GAAI,QAAQ,IAAI,YACd,OAAAA,EAAI,IAAI,MAAM,0BAA0B,EACjC,QAAQ,IAAI,YAGrB,GAAI,CACF,OAAAA,EAAI,IAAI,MAAM,2BAA2B,EAClC,EAAAC,QAAG,aAAaC,EAAW,aAAa,EAAG,MAAM,CAC1D,OAASC,EAAO,CACdC,EAAcD,CAAK,EACnB,MACF,CACF,CAAC,EAQYE,EAAeC,EAAA,CAACN,EAAcO,IAAsC,CAC/ET,EAAY,MAAM,EAEd,QAAQ,IAAI,cACdE,EAAI,IAAI,MAAM,yBAA0B,CAAE,QAAS,EAAQO,CAAS,CAAC,EACrE,QAAQ,IAAI,YAAiBA,GAG/BP,EAAI,IAAI,MAAM,0BAA2B,CAAE,QAAS,EAAQO,EAAU,KAAML,EAAW,aAAa,CAAE,CAAC,EAEnGK,EACF,EAAAN,QAAG,eAAeC,EAAW,aAAa,EAAGK,CAAO,EAEpD,EAAAN,QAAG,WAAWC,EAAW,aAAa,CAAC,CAE3C,EAf4B,gBAiBfM,EAAYT,EAAMC,IAC7BA,EAAI,IAAI,MAAM,wBAAwB,EAC/B,QAAQ,IAAI,UACpB",
6
+ "names": ["init_cjs", "import_fs_extra", "readSession", "memo", "ctx", "fs", "configPath", "error", "swallowEnoent", "writeSession", "__name", "session", "readToken"]
7
+ }