pax8-cta 0.1.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 (224) hide show
  1. package/LICENSE +200 -0
  2. package/README.md +659 -0
  3. package/demo-data/solutions/ProductQADemo_1_0_0_2_managed.zip +0 -0
  4. package/dist/commands/analyze.d.ts +28 -0
  5. package/dist/commands/analyze.d.ts.map +1 -0
  6. package/dist/commands/analyze.js +571 -0
  7. package/dist/commands/analyze.js.map +1 -0
  8. package/dist/commands/auth.d.ts +18 -0
  9. package/dist/commands/auth.d.ts.map +1 -0
  10. package/dist/commands/auth.js +171 -0
  11. package/dist/commands/auth.js.map +1 -0
  12. package/dist/commands/config.d.ts +34 -0
  13. package/dist/commands/config.d.ts.map +1 -0
  14. package/dist/commands/config.js +299 -0
  15. package/dist/commands/config.js.map +1 -0
  16. package/dist/commands/demo.d.ts +33 -0
  17. package/dist/commands/demo.d.ts.map +1 -0
  18. package/dist/commands/demo.js +362 -0
  19. package/dist/commands/demo.js.map +1 -0
  20. package/dist/commands/deploy.d.ts +18 -0
  21. package/dist/commands/deploy.d.ts.map +1 -0
  22. package/dist/commands/deploy.js +1186 -0
  23. package/dist/commands/deploy.js.map +1 -0
  24. package/dist/commands/deployments/helpers.d.ts +68 -0
  25. package/dist/commands/deployments/helpers.d.ts.map +1 -0
  26. package/dist/commands/deployments/helpers.js +414 -0
  27. package/dist/commands/deployments/helpers.js.map +1 -0
  28. package/dist/commands/deployments/index.d.ts +24 -0
  29. package/dist/commands/deployments/index.d.ts.map +1 -0
  30. package/dist/commands/deployments/index.js +47 -0
  31. package/dist/commands/deployments/index.js.map +1 -0
  32. package/dist/commands/deployments/list.d.ts +18 -0
  33. package/dist/commands/deployments/list.d.ts.map +1 -0
  34. package/dist/commands/deployments/list.js +97 -0
  35. package/dist/commands/deployments/list.js.map +1 -0
  36. package/dist/commands/deployments/show.d.ts +18 -0
  37. package/dist/commands/deployments/show.d.ts.map +1 -0
  38. package/dist/commands/deployments/show.js +81 -0
  39. package/dist/commands/deployments/show.js.map +1 -0
  40. package/dist/commands/deployments/undo.d.ts +18 -0
  41. package/dist/commands/deployments/undo.d.ts.map +1 -0
  42. package/dist/commands/deployments/undo.js +295 -0
  43. package/dist/commands/deployments/undo.js.map +1 -0
  44. package/dist/commands/export.d.ts +18 -0
  45. package/dist/commands/export.d.ts.map +1 -0
  46. package/dist/commands/export.js +133 -0
  47. package/dist/commands/export.js.map +1 -0
  48. package/dist/commands/import.d.ts +18 -0
  49. package/dist/commands/import.d.ts.map +1 -0
  50. package/dist/commands/import.js +129 -0
  51. package/dist/commands/import.js.map +1 -0
  52. package/dist/commands/init-config.d.ts +26 -0
  53. package/dist/commands/init-config.d.ts.map +1 -0
  54. package/dist/commands/init-config.js +123 -0
  55. package/dist/commands/init-config.js.map +1 -0
  56. package/dist/commands/init-validation.d.ts +47 -0
  57. package/dist/commands/init-validation.d.ts.map +1 -0
  58. package/dist/commands/init-validation.js +339 -0
  59. package/dist/commands/init-validation.js.map +1 -0
  60. package/dist/commands/init-wizard.d.ts +25 -0
  61. package/dist/commands/init-wizard.d.ts.map +1 -0
  62. package/dist/commands/init-wizard.js +433 -0
  63. package/dist/commands/init-wizard.js.map +1 -0
  64. package/dist/commands/init.d.ts +18 -0
  65. package/dist/commands/init.d.ts.map +1 -0
  66. package/dist/commands/init.js +46 -0
  67. package/dist/commands/init.js.map +1 -0
  68. package/dist/commands/resolve-url.d.ts +18 -0
  69. package/dist/commands/resolve-url.d.ts.map +1 -0
  70. package/dist/commands/resolve-url.js +126 -0
  71. package/dist/commands/resolve-url.js.map +1 -0
  72. package/dist/commands/setup.d.ts +18 -0
  73. package/dist/commands/setup.d.ts.map +1 -0
  74. package/dist/commands/setup.js +239 -0
  75. package/dist/commands/setup.js.map +1 -0
  76. package/dist/commands/solutions/drift-analysis.d.ts +73 -0
  77. package/dist/commands/solutions/drift-analysis.d.ts.map +1 -0
  78. package/dist/commands/solutions/drift-analysis.js +416 -0
  79. package/dist/commands/solutions/drift-analysis.js.map +1 -0
  80. package/dist/commands/solutions/drift.d.ts +32 -0
  81. package/dist/commands/solutions/drift.d.ts.map +1 -0
  82. package/dist/commands/solutions/drift.js +641 -0
  83. package/dist/commands/solutions/drift.js.map +1 -0
  84. package/dist/commands/solutions/fix-planner.d.ts +48 -0
  85. package/dist/commands/solutions/fix-planner.d.ts.map +1 -0
  86. package/dist/commands/solutions/fix-planner.js +43 -0
  87. package/dist/commands/solutions/fix-planner.js.map +1 -0
  88. package/dist/commands/solutions/helpers.d.ts +35 -0
  89. package/dist/commands/solutions/helpers.d.ts.map +1 -0
  90. package/dist/commands/solutions/helpers.js +54 -0
  91. package/dist/commands/solutions/helpers.js.map +1 -0
  92. package/dist/commands/solutions/index.d.ts +18 -0
  93. package/dist/commands/solutions/index.d.ts.map +1 -0
  94. package/dist/commands/solutions/index.js +30 -0
  95. package/dist/commands/solutions/index.js.map +1 -0
  96. package/dist/commands/solutions/list.d.ts +18 -0
  97. package/dist/commands/solutions/list.d.ts.map +1 -0
  98. package/dist/commands/solutions/list.js +174 -0
  99. package/dist/commands/solutions/list.js.map +1 -0
  100. package/dist/commands/solutions/remove.d.ts +18 -0
  101. package/dist/commands/solutions/remove.d.ts.map +1 -0
  102. package/dist/commands/solutions/remove.js +137 -0
  103. package/dist/commands/solutions/remove.js.map +1 -0
  104. package/dist/commands/solutions/risk-calculator.d.ts +33 -0
  105. package/dist/commands/solutions/risk-calculator.d.ts.map +1 -0
  106. package/dist/commands/solutions/risk-calculator.js +79 -0
  107. package/dist/commands/solutions/risk-calculator.js.map +1 -0
  108. package/dist/commands/solutions/show.d.ts +18 -0
  109. package/dist/commands/solutions/show.d.ts.map +1 -0
  110. package/dist/commands/solutions/show.js +165 -0
  111. package/dist/commands/solutions/show.js.map +1 -0
  112. package/dist/commands/status.d.ts +18 -0
  113. package/dist/commands/status.d.ts.map +1 -0
  114. package/dist/commands/status.js +573 -0
  115. package/dist/commands/status.js.map +1 -0
  116. package/dist/commands/telemetry.d.ts +18 -0
  117. package/dist/commands/telemetry.d.ts.map +1 -0
  118. package/dist/commands/telemetry.js +85 -0
  119. package/dist/commands/telemetry.js.map +1 -0
  120. package/dist/commands/tenants/health.d.ts +18 -0
  121. package/dist/commands/tenants/health.d.ts.map +1 -0
  122. package/dist/commands/tenants/health.js +172 -0
  123. package/dist/commands/tenants/health.js.map +1 -0
  124. package/dist/commands/tenants/helpers.d.ts +44 -0
  125. package/dist/commands/tenants/helpers.d.ts.map +1 -0
  126. package/dist/commands/tenants/helpers.js +72 -0
  127. package/dist/commands/tenants/helpers.js.map +1 -0
  128. package/dist/commands/tenants/index.d.ts +19 -0
  129. package/dist/commands/tenants/index.d.ts.map +1 -0
  130. package/dist/commands/tenants/index.js +39 -0
  131. package/dist/commands/tenants/index.js.map +1 -0
  132. package/dist/commands/tenants/inspect.d.ts +18 -0
  133. package/dist/commands/tenants/inspect.d.ts.map +1 -0
  134. package/dist/commands/tenants/inspect.js +176 -0
  135. package/dist/commands/tenants/inspect.js.map +1 -0
  136. package/dist/commands/tenants/list.d.ts +18 -0
  137. package/dist/commands/tenants/list.d.ts.map +1 -0
  138. package/dist/commands/tenants/list.js +144 -0
  139. package/dist/commands/tenants/list.js.map +1 -0
  140. package/dist/commands/tenants/manage.d.ts +20 -0
  141. package/dist/commands/tenants/manage.d.ts.map +1 -0
  142. package/dist/commands/tenants/manage.js +206 -0
  143. package/dist/commands/tenants/manage.js.map +1 -0
  144. package/dist/commands/tenants/show.d.ts +18 -0
  145. package/dist/commands/tenants/show.d.ts.map +1 -0
  146. package/dist/commands/tenants/show.js +191 -0
  147. package/dist/commands/tenants/show.js.map +1 -0
  148. package/dist/commands/validate.d.ts +18 -0
  149. package/dist/commands/validate.d.ts.map +1 -0
  150. package/dist/commands/validate.js +536 -0
  151. package/dist/commands/validate.js.map +1 -0
  152. package/dist/index.d.ts +19 -0
  153. package/dist/index.d.ts.map +1 -0
  154. package/dist/index.js +258 -0
  155. package/dist/index.js.map +1 -0
  156. package/dist/lib/auth.d.ts +51 -0
  157. package/dist/lib/auth.d.ts.map +1 -0
  158. package/dist/lib/auth.js +153 -0
  159. package/dist/lib/auth.js.map +1 -0
  160. package/dist/lib/banner.d.ts +19 -0
  161. package/dist/lib/banner.d.ts.map +1 -0
  162. package/dist/lib/banner.js +78 -0
  163. package/dist/lib/banner.js.map +1 -0
  164. package/dist/lib/command-wrapper.d.ts +56 -0
  165. package/dist/lib/command-wrapper.d.ts.map +1 -0
  166. package/dist/lib/command-wrapper.js +71 -0
  167. package/dist/lib/command-wrapper.js.map +1 -0
  168. package/dist/lib/credentials.d.ts +56 -0
  169. package/dist/lib/credentials.d.ts.map +1 -0
  170. package/dist/lib/credentials.js +146 -0
  171. package/dist/lib/credentials.js.map +1 -0
  172. package/dist/lib/demo-banner.d.ts +15 -0
  173. package/dist/lib/demo-banner.d.ts.map +1 -0
  174. package/dist/lib/demo-banner.js +33 -0
  175. package/dist/lib/demo-banner.js.map +1 -0
  176. package/dist/lib/error-handler.d.ts +51 -0
  177. package/dist/lib/error-handler.d.ts.map +1 -0
  178. package/dist/lib/error-handler.js +458 -0
  179. package/dist/lib/error-handler.js.map +1 -0
  180. package/dist/lib/errors.d.ts +61 -0
  181. package/dist/lib/errors.d.ts.map +1 -0
  182. package/dist/lib/errors.js +168 -0
  183. package/dist/lib/errors.js.map +1 -0
  184. package/dist/lib/formatters.d.ts +55 -0
  185. package/dist/lib/formatters.d.ts.map +1 -0
  186. package/dist/lib/formatters.js +163 -0
  187. package/dist/lib/formatters.js.map +1 -0
  188. package/dist/lib/graph-client.d.ts +74 -0
  189. package/dist/lib/graph-client.d.ts.map +1 -0
  190. package/dist/lib/graph-client.js +231 -0
  191. package/dist/lib/graph-client.js.map +1 -0
  192. package/dist/lib/input.d.ts +22 -0
  193. package/dist/lib/input.d.ts.map +1 -0
  194. package/dist/lib/input.js +120 -0
  195. package/dist/lib/input.js.map +1 -0
  196. package/dist/lib/interactive-wizard.d.ts +26 -0
  197. package/dist/lib/interactive-wizard.d.ts.map +1 -0
  198. package/dist/lib/interactive-wizard.js +550 -0
  199. package/dist/lib/interactive-wizard.js.map +1 -0
  200. package/dist/lib/oss-surface.d.ts +21 -0
  201. package/dist/lib/oss-surface.d.ts.map +1 -0
  202. package/dist/lib/oss-surface.js +29 -0
  203. package/dist/lib/oss-surface.js.map +1 -0
  204. package/dist/lib/output.d.ts +74 -0
  205. package/dist/lib/output.d.ts.map +1 -0
  206. package/dist/lib/output.js +156 -0
  207. package/dist/lib/output.js.map +1 -0
  208. package/dist/lib/picker.d.ts +75 -0
  209. package/dist/lib/picker.d.ts.map +1 -0
  210. package/dist/lib/picker.js +115 -0
  211. package/dist/lib/picker.js.map +1 -0
  212. package/dist/lib/repl.d.ts +19 -0
  213. package/dist/lib/repl.d.ts.map +1 -0
  214. package/dist/lib/repl.js +158 -0
  215. package/dist/lib/repl.js.map +1 -0
  216. package/dist/lib/spinner.d.ts +41 -0
  217. package/dist/lib/spinner.d.ts.map +1 -0
  218. package/dist/lib/spinner.js +126 -0
  219. package/dist/lib/spinner.js.map +1 -0
  220. package/dist/lib/telemetry.d.ts +96 -0
  221. package/dist/lib/telemetry.d.ts.map +1 -0
  222. package/dist/lib/telemetry.js +367 -0
  223. package/dist/lib/telemetry.js.map +1 -0
  224. package/package.json +68 -0
@@ -0,0 +1,74 @@
1
+ /**
2
+ * Copyright 2024 Pax8, Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ export type OutputFormat = "table" | "json" | "csv" | "quiet" | "ids-only";
17
+ export interface Column<T> {
18
+ /** Property key on T to read the raw value from */
19
+ key: keyof T & string;
20
+ /** Column header displayed in table output */
21
+ header: string;
22
+ /**
23
+ * Optional formatter applied to the cell value before rendering.
24
+ * Receives the raw value and the full row. Must return a string.
25
+ * For table output the returned string may contain ANSI codes.
26
+ * For JSON output the raw value (not this formatter's result) is used.
27
+ */
28
+ format?: (value: unknown, row: T) => string;
29
+ }
30
+ /**
31
+ * Returns "table" when stdout is an interactive TTY, otherwise "json".
32
+ * Downstream callers (LLM agents, shell pipelines) therefore receive clean
33
+ * JSON without needing to pass --json explicitly.
34
+ *
35
+ * This reads from the `PAX8_CTA_DEFAULT_FORMAT` environment variable which
36
+ * is set by the CLI entry point (`src/index.ts`) based on `process.stdout.isTTY`.
37
+ * Reading the env var rather than `isTTY` directly means unit tests (which run
38
+ * in a non-TTY vitest worker) still default to "table" unless the CLI binary
39
+ * is explicitly invoked as a subprocess.
40
+ *
41
+ * Always returns "quiet" when quiet mode is active, overriding TTY detection.
42
+ */
43
+ export declare function getDefaultFormat(): OutputFormat;
44
+ /**
45
+ * Resolve the effective output format from command option flags.
46
+ *
47
+ * Precedence (highest → lowest):
48
+ * 1. quiet mode (--quiet flag or PAX8_CTA_QUIET env var) — silent wins.
49
+ * If both --quiet and --json are set, --quiet takes effect.
50
+ * 2. --ids-only flag (mutually exclusive with --json/--csv; root program guards this)
51
+ * 3. --json flag
52
+ * 4. TTY-aware default from getDefaultFormat()
53
+ */
54
+ export declare function resolveFormat(opts: {
55
+ json?: boolean;
56
+ quiet?: boolean;
57
+ idsOnly?: boolean;
58
+ }): OutputFormat;
59
+ /**
60
+ * Render rows in the requested format.
61
+ *
62
+ * @param rows - Array of data objects to render.
63
+ * @param opts.format - Output format. Defaults to `getDefaultFormat()`.
64
+ * @param opts.columns - Column definitions (header + key + optional formatter).
65
+ * @param opts.idKey - Key whose value is used for "ids-only" format.
66
+ *
67
+ * @throws Error for "csv" (reserved for a future issue).
68
+ */
69
+ export declare function output<T extends object>(rows: T[], opts: {
70
+ format?: OutputFormat;
71
+ columns: Column<T>[];
72
+ idKey?: keyof T & string;
73
+ }): void;
74
+ //# sourceMappingURL=output.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"output.d.ts","sourceRoot":"","sources":["../../src/lib/output.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAoBH,MAAM,MAAM,YAAY,GAAG,OAAO,GAAG,MAAM,GAAG,KAAK,GAAG,OAAO,GAAG,UAAU,CAAC;AAE3E,MAAM,WAAW,MAAM,CAAC,CAAC;IACvB,mDAAmD;IACnD,GAAG,EAAE,MAAM,CAAC,GAAG,MAAM,CAAC;IACtB,8CAA8C;IAC9C,MAAM,EAAE,MAAM,CAAC;IACf;;;;;OAKG;IACH,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,KAAK,MAAM,CAAC;CAC7C;AAMD;;;;;;;;;;;;GAYG;AACH,wBAAgB,gBAAgB,IAAI,YAAY,CAU/C;AAED;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE;IAClC,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,GAAG,YAAY,CAMf;AAMD;;;;;;;;;GASG;AACH,wBAAgB,MAAM,CAAC,CAAC,SAAS,MAAM,EACrC,IAAI,EAAE,CAAC,EAAE,EACT,IAAI,EAAE;IACJ,MAAM,CAAC,EAAE,YAAY,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC,GAAG,MAAM,CAAC;CAC1B,GACA,IAAI,CA6BN"}
@@ -0,0 +1,156 @@
1
+ /**
2
+ * Copyright 2024 Pax8, Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ /**
17
+ * TTY-aware output helper for pax8-cta CLI commands.
18
+ *
19
+ * - When stdout is a TTY (interactive terminal): defaults to "table"
20
+ * - When stdout is piped (subprocess / LLM agent): defaults to "json"
21
+ *
22
+ * Commands should resolve their format via:
23
+ * const fmt = (opts.json && "json") || (opts.quiet && "quiet") || getDefaultFormat();
24
+ * output(rows, { format: fmt, columns });
25
+ */
26
+ import Table from "cli-table3";
27
+ import { isQuietMode } from "./spinner.js";
28
+ // ============================================================================
29
+ // Format detection
30
+ // ============================================================================
31
+ /**
32
+ * Returns "table" when stdout is an interactive TTY, otherwise "json".
33
+ * Downstream callers (LLM agents, shell pipelines) therefore receive clean
34
+ * JSON without needing to pass --json explicitly.
35
+ *
36
+ * This reads from the `PAX8_CTA_DEFAULT_FORMAT` environment variable which
37
+ * is set by the CLI entry point (`src/index.ts`) based on `process.stdout.isTTY`.
38
+ * Reading the env var rather than `isTTY` directly means unit tests (which run
39
+ * in a non-TTY vitest worker) still default to "table" unless the CLI binary
40
+ * is explicitly invoked as a subprocess.
41
+ *
42
+ * Always returns "quiet" when quiet mode is active, overriding TTY detection.
43
+ */
44
+ export function getDefaultFormat() {
45
+ // Quiet mode wins over all TTY/env-based defaults.
46
+ if (isQuietMode())
47
+ return "quiet";
48
+ if (process.env.PAX8_CTA_DEFAULT_FORMAT === "json")
49
+ return "json";
50
+ if (process.env.PAX8_CTA_DEFAULT_FORMAT === "table")
51
+ return "table";
52
+ // Fallback: "table" is the safe default when called in-process (unit tests,
53
+ // programmatic use). The CLI entry point (src/index.ts) sets
54
+ // PAX8_CTA_DEFAULT_FORMAT based on isTTY before any commands run, so
55
+ // subprocess invocations that pipe stdout automatically get "json".
56
+ return "table";
57
+ }
58
+ /**
59
+ * Resolve the effective output format from command option flags.
60
+ *
61
+ * Precedence (highest → lowest):
62
+ * 1. quiet mode (--quiet flag or PAX8_CTA_QUIET env var) — silent wins.
63
+ * If both --quiet and --json are set, --quiet takes effect.
64
+ * 2. --ids-only flag (mutually exclusive with --json/--csv; root program guards this)
65
+ * 3. --json flag
66
+ * 4. TTY-aware default from getDefaultFormat()
67
+ */
68
+ export function resolveFormat(opts) {
69
+ // --quiet (or env-based quiet) wins over --json. Silent wins.
70
+ if (opts.quiet || isQuietMode())
71
+ return "quiet";
72
+ if (opts.idsOnly)
73
+ return "ids-only";
74
+ if (opts.json)
75
+ return "json";
76
+ return getDefaultFormat();
77
+ }
78
+ // ============================================================================
79
+ // Core output function
80
+ // ============================================================================
81
+ /**
82
+ * Render rows in the requested format.
83
+ *
84
+ * @param rows - Array of data objects to render.
85
+ * @param opts.format - Output format. Defaults to `getDefaultFormat()`.
86
+ * @param opts.columns - Column definitions (header + key + optional formatter).
87
+ * @param opts.idKey - Key whose value is used for "ids-only" format.
88
+ *
89
+ * @throws Error for "csv" (reserved for a future issue).
90
+ */
91
+ export function output(rows, opts) {
92
+ const format = opts.format ?? getDefaultFormat();
93
+ switch (format) {
94
+ case "json":
95
+ outputJson(rows);
96
+ break;
97
+ case "table":
98
+ outputTable(rows, opts.columns);
99
+ break;
100
+ case "quiet":
101
+ // Produce no output — caller is responsible for any success messaging
102
+ break;
103
+ case "csv":
104
+ throw new Error("--csv not yet implemented (see #346 in the issue tracker)");
105
+ case "ids-only":
106
+ outputIdsOnly(rows, opts.idKey, opts.columns);
107
+ break;
108
+ default: {
109
+ // TypeScript exhaustive check
110
+ const _never = format;
111
+ throw new Error(`Unknown output format: ${_never}`);
112
+ }
113
+ }
114
+ }
115
+ // ============================================================================
116
+ // Internal renderers
117
+ // ============================================================================
118
+ function outputJson(rows) {
119
+ console.log(JSON.stringify(rows, null, 2));
120
+ }
121
+ /**
122
+ * Print one ID per line to stdout — no headers, no chrome, no colors.
123
+ *
124
+ * Resolution order for the id field:
125
+ * 1. opts.idKey if provided
126
+ * 2. A column whose key is "id"
127
+ * 3. Error — caller must set idKey or add an "id" column
128
+ */
129
+ function outputIdsOnly(rows, idKey, columns) {
130
+ // Resolve the key to use
131
+ const key = idKey ??
132
+ columns.find((c) => c.key === "id")?.key ??
133
+ (() => {
134
+ throw new Error("ids-only format: no id key found. " +
135
+ 'Either pass idKey to output() or add a column with key "id". ' +
136
+ 'Example: output(rows, { format: "ids-only", columns, idKey: "tenantId" })');
137
+ })();
138
+ for (const row of rows) {
139
+ const value = row[key];
140
+ process.stdout.write((value == null ? "" : String(value)) + "\n");
141
+ }
142
+ }
143
+ function outputTable(rows, columns) {
144
+ const table = new Table({
145
+ head: columns.map((c) => c.header),
146
+ style: { head: ["cyan"] },
147
+ });
148
+ for (const row of rows) {
149
+ table.push(columns.map((col) => {
150
+ const raw = row[col.key];
151
+ return col.format ? col.format(raw, row) : raw == null ? "" : String(raw);
152
+ }));
153
+ }
154
+ console.log(table.toString());
155
+ }
156
+ //# sourceMappingURL=output.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"output.js","sourceRoot":"","sources":["../../src/lib/output.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH;;;;;;;;;GASG;AAEH,OAAO,KAAK,MAAM,YAAY,CAAC;AAC/B,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAsB3C,+EAA+E;AAC/E,mBAAmB;AACnB,+EAA+E;AAE/E;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,gBAAgB;IAC9B,mDAAmD;IACnD,IAAI,WAAW,EAAE;QAAE,OAAO,OAAO,CAAC;IAClC,IAAI,OAAO,CAAC,GAAG,CAAC,uBAAuB,KAAK,MAAM;QAAE,OAAO,MAAM,CAAC;IAClE,IAAI,OAAO,CAAC,GAAG,CAAC,uB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GAAG,CAAC,GAAG,CAAC,CAAC;YACzB,OAAO,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QAC5E,CAAC,CAAC,CACH,CAAC;IACJ,CAAC;IAED,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC;AAChC,CAAC"}
@@ -0,0 +1,75 @@
1
+ /**
2
+ * Copyright 2024 Pax8, Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ export interface InteractivePromptOptions {
17
+ /** Caller passed `--json`. */
18
+ json?: boolean;
19
+ /** Caller passed `--quiet`. */
20
+ quiet?: boolean;
21
+ }
22
+ /**
23
+ * True when we can safely prompt the user for input.
24
+ *
25
+ * Returns false when:
26
+ * - `--json` is set (we'd corrupt the JSON output)
27
+ * - `--quiet` is set (or `PAX8_CTA_QUIET` env)
28
+ * - stdout or stdin isn't a TTY (piped, redirected, CI, etc.)
29
+ */
30
+ export declare function isInteractivePrompt(opts?: InteractivePromptOptions): boolean;
31
+ export interface PickFromListOptions<T> {
32
+ /** Header line printed before the numbered list (e.g. "Pick a tenant:"). */
33
+ prompt: string;
34
+ /** How to render each item; defaults to `String(item)`. */
35
+ label?: (item: T) => string;
36
+ /** Optional secondary hint shown in gray after the label (e.g. tags). */
37
+ hint?: (item: T) => string | undefined;
38
+ /**
39
+ * Whether to prompt at all. Defaults to `isInteractivePrompt()` —
40
+ * callers who already have an opts bag should pass that bag in via
41
+ * `isInteractivePrompt(opts)` so `--json`/`--quiet` are respected.
42
+ */
43
+ isInteractive?: boolean;
44
+ /** Label for the "skip" option (item 0). Defaults to "skip". */
45
+ skipLabel?: string;
46
+ }
47
+ /**
48
+ * Render a numbered list and return the chosen item.
49
+ *
50
+ * Returns `undefined` for any non-selection: empty list, non-interactive
51
+ * environment, user picked `0`, hit Enter without typing, or typed
52
+ * something that isn't a valid number in range.
53
+ *
54
+ * If the list has exactly one item we still prompt — but as a y/n confirm,
55
+ * because picking #1 from a list of 1 is just confirming a default.
56
+ */
57
+ export declare function pickFromList<T>(items: T[], opts: PickFromListOptions<T>): Promise<T | undefined>;
58
+ /**
59
+ * Yes/no prompt. Returns `true` only for `y` or `yes` (case-insensitive).
60
+ * Anything else — including blank input — is `false`, so the safe default
61
+ * is always "no".
62
+ */
63
+ export declare function confirm(prompt: string): Promise<boolean>;
64
+ /**
65
+ * Quote a value for shell-friendly display (e.g. `running: deploy ...`).
66
+ * Wraps in double quotes when the value contains whitespace.
67
+ */
68
+ export declare function quoteIfNeeded(value: string): string;
69
+ /**
70
+ * Print "running: <command>" so the user learns the flag form they could
71
+ * have typed directly. Caller is responsible for actually running the
72
+ * command — this just echoes it.
73
+ */
74
+ export declare function printRunningCommand(parts: string[]): void;
75
+ //# sourceMappingURL=picker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"picker.d.ts","sourceRoot":"","sources":["../../src/lib/picker.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAkBH,MAAM,WAAW,wBAAwB;IACvC,8BAA8B;IAC9B,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,+BAA+B;IAC/B,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,GAAE,wBAA6B,GAAG,OAAO,CAOhF;AAED,MAAM,WAAW,mBAAmB,CAAC,CAAC;IACpC,4EAA4E;IAC5E,MAAM,EAAE,MAAM,CAAC;IACf,2DAA2D;IAC3D,KAAK,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,MAAM,CAAC;IAC5B,yEAAyE;IACzE,IAAI,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,MAAM,GAAG,SAAS,CAAC;IACvC;;;;OAIG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,gEAAgE;IAChE,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;;;;GASG;AACH,wBAAsB,YAAY,CAAC,CAAC,EAClC,KAAK,EAAE,CAAC,EAAE,EACV,IAAI,EAAE,mBAAmB,CAAC,CAAC,CAAC,GAC3B,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC,CA+BxB;AAED;;;;GAIG;AACH,wBAAsB,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAG9D;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAEnD;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,IAAI,CAGzD"}
@@ -0,0 +1,115 @@
1
+ /**
2
+ * Copyright 2024 Pax8, Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ /**
17
+ * Shared interactive picker helpers.
18
+ *
19
+ * When a CLI command needs an arg the user didn't provide, we want to drop
20
+ * into a small numbered picker — but ONLY when we know we're talking to a
21
+ * real human in a terminal. Scripts, pipelines, and `--json` / `--quiet`
22
+ * callers must never hang waiting on stdin.
23
+ *
24
+ * These helpers consolidate the TTY/flag check and the prompt-rendering
25
+ * logic that started life inline in `analyze.ts`.
26
+ */
27
+ import chalk from "chalk";
28
+ import { question } from "./input.js";
29
+ import { isQuietMode } from "./spinner.js";
30
+ /**
31
+ * True when we can safely prompt the user for input.
32
+ *
33
+ * Returns false when:
34
+ * - `--json` is set (we'd corrupt the JSON output)
35
+ * - `--quiet` is set (or `PAX8_CTA_QUIET` env)
36
+ * - stdout or stdin isn't a TTY (piped, redirected, CI, etc.)
37
+ */
38
+ export function isInteractivePrompt(opts = {}) {
39
+ if (opts.json)
40
+ return false;
41
+ if (opts.quiet)
42
+ return false;
43
+ if (isQuietMode())
44
+ return false;
45
+ if (!process.stdout.isTTY)
46
+ return false;
47
+ if (!process.stdin.isTTY)
48
+ return false;
49
+ return true;
50
+ }
51
+ /**
52
+ * Render a numbered list and return the chosen item.
53
+ *
54
+ * Returns `undefined` for any non-selection: empty list, non-interactive
55
+ * environment, user picked `0`, hit Enter without typing, or typed
56
+ * something that isn't a valid number in range.
57
+ *
58
+ * If the list has exactly one item we still prompt — but as a y/n confirm,
59
+ * because picking #1 from a list of 1 is just confirming a default.
60
+ */
61
+ export async function pickFromList(items, opts) {
62
+ if (items.length === 0)
63
+ return undefined;
64
+ const interactive = opts.isInteractive ?? isInteractivePrompt();
65
+ if (!interactive)
66
+ return undefined;
67
+ const labelOf = opts.label ?? ((item) => String(item));
68
+ const hintOf = opts.hint ?? (() => undefined);
69
+ if (items.length === 1) {
70
+ const only = items[0];
71
+ const hint = hintOf(only);
72
+ const suffix = hint ? chalk.gray(` [${hint}]`) : "";
73
+ const ok = await confirm(`${opts.prompt} ${chalk.bold(labelOf(only))}${suffix}? [y/N] `);
74
+ return ok ? only : undefined;
75
+ }
76
+ console.log(chalk.cyan(opts.prompt));
77
+ items.forEach((item, i) => {
78
+ const hint = hintOf(item);
79
+ const hintText = hint ? chalk.gray(` [${hint}]`) : "";
80
+ console.log(` ${i + 1}) ${labelOf(item)}${hintText}`);
81
+ });
82
+ console.log(chalk.gray(` 0) ${opts.skipLabel ?? "skip"}`));
83
+ const answer = await question(chalk.cyan("> "));
84
+ const choice = parseInt(answer.trim(), 10);
85
+ if (!Number.isInteger(choice) || choice < 1 || choice > items.length) {
86
+ return undefined;
87
+ }
88
+ return items[choice - 1];
89
+ }
90
+ /**
91
+ * Yes/no prompt. Returns `true` only for `y` or `yes` (case-insensitive).
92
+ * Anything else — including blank input — is `false`, so the safe default
93
+ * is always "no".
94
+ */
95
+ export async function confirm(prompt) {
96
+ const answer = await question(prompt);
97
+ return /^(y|yes)$/i.test(answer.trim());
98
+ }
99
+ /**
100
+ * Quote a value for shell-friendly display (e.g. `running: deploy ...`).
101
+ * Wraps in double quotes when the value contains whitespace.
102
+ */
103
+ export function quoteIfNeeded(value) {
104
+ return /\s/.test(value) ? `"${value}"` : value;
105
+ }
106
+ /**
107
+ * Print "running: <command>" so the user learns the flag form they could
108
+ * have typed directly. Caller is responsible for actually running the
109
+ * command — this just echoes it.
110
+ */
111
+ export function printRunningCommand(parts) {
112
+ const formatted = parts.map(quoteIfNeeded).join(" ");
113
+ console.log(chalk.gray(`\nrunning: ${formatted}\n`));
114
+ }
115
+ //# sourceMappingURL=picker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"picker.js","sourceRoot":"","sources":["../../src/lib/picker.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAS3C;;;;;;;GAOG;AACH,MAAM,UAAU,mBAAmB,CAAC,OAAiC,EAAE;IACrE,IAAI,IAAI,CAA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YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;AAC1C,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,aAAa,CAAC,KAAa;IACzC,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC;AACjD,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CAAC,KAAe;IACjD,MAAM,SAAS,GAAG,KAAK,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACrD,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,cAAc,SAAS,IAAI,CAAC,CAAC,CAAC;AACvD,CAAC"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Copyright 2024 Pax8, Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import type { Command } from "commander";
17
+ export declare function startRepl(createProgram: () => Command): Promise<void>;
18
+ export declare function parseCommandLine(input: string): string[];
19
+ //# sourceMappingURL=repl.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"repl.d.ts","sourceRoot":"","sources":["../../src/lib/repl.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAUzC,wBAAsB,SAAS,CAAC,aAAa,EAAE,MAAM,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CA0F3E;AA2BD,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CA8BxD"}
@@ -0,0 +1,158 @@
1
+ /**
2
+ * Copyright 2024 Pax8, Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import chalk from "chalk";
17
+ import { question, closeInput } from "./input.js";
18
+ import { setReplMode } from "./spinner.js";
19
+ class ReplExitIntercepted extends Error {
20
+ code;
21
+ constructor(code) {
22
+ super(`process.exit(${code}) intercepted`);
23
+ this.code = code;
24
+ }
25
+ }
26
+ export async function startRepl(createProgram) {
27
+ setReplMode(true);
28
+ console.log();
29
+ console.log(chalk.gray("Interactive mode - Type 'help' for commands or 'exit' to quit"));
30
+ console.log();
31
+ while (true) {
32
+ const line = await question(chalk.cyan("pax8-cta> "));
33
+ const input = line.trim();
34
+ if (!input) {
35
+ continue;
36
+ }
37
+ if (input === "exit" || input === "quit") {
38
+ console.log(chalk.gray("Goodbye!"));
39
+ closeInput();
40
+ break;
41
+ }
42
+ try {
43
+ // Parse the input as commander arguments
44
+ const args = parseCommandLine(input);
45
+ // Tolerate shell-style invocations: muscle memory from running
46
+ // `pax8-cta foo bar` outside the REPL shouldn't surface as an error.
47
+ if (args[0] === "pax8-cta") {
48
+ args.shift();
49
+ }
50
+ // Create a fresh program instance for this command
51
+ const program = createProgram();
52
+ // Subcommand instances are module-level singletons, so Commander's
53
+ // parsed option/arg state from a previous REPL iteration leaks into
54
+ // the next parse. Clear it before each command runs.
55
+ resetCommandState(program);
56
+ // Prevent commander from calling process.exit() on help/errors.
57
+ // exitOverride must be set on all subcommands too.
58
+ program.exitOverride();
59
+ for (const cmd of program.commands) {
60
+ cmd.exitOverride();
61
+ for (const sub of cmd.commands) {
62
+ sub.exitOverride();
63
+ }
64
+ }
65
+ // Intercept process.exit() so command error handlers don't kill the REPL
66
+ const originalExit = process.exit;
67
+ process.exit = ((code) => {
68
+ throw new ReplExitIntercepted(code ?? 0);
69
+ });
70
+ try {
71
+ await program.parseAsync(args, { from: "user" });
72
+ }
73
+ finally {
74
+ process.exit = originalExit;
75
+ }
76
+ }
77
+ catch (error) {
78
+ if (error instanceof ReplExitIntercepted) {
79
+ // Command called process.exit() — already printed its own error, just continue
80
+ console.log();
81
+ continue;
82
+ }
83
+ if (error instanceof Error && "code" in error) {
84
+ const commanderError = error;
85
+ if (commanderError.code === "commander.unknownCommand" ||
86
+ commanderError.code === "commander.unknownOption") {
87
+ console.error(chalk.red(`Unknown command: ${input}`));
88
+ console.log(chalk.gray("Type 'help' to see available commands"));
89
+ }
90
+ else if (commanderError.code === "commander.help" ||
91
+ commanderError.code === "commander.helpDisplayed") {
92
+ // Help was displayed, do nothing
93
+ }
94
+ else if (commanderError.code === "commander.version") {
95
+ // Version was displayed, do nothing
96
+ }
97
+ else {
98
+ console.error(chalk.red(commanderError.message));
99
+ }
100
+ }
101
+ else {
102
+ console.error(chalk.red(error instanceof Error ? error.message : String(error)));
103
+ }
104
+ }
105
+ console.log();
106
+ }
107
+ }
108
+ function resetCommandState(cmd) {
109
+ // Commander stores parsed values on the Command instance; with shared
110
+ // subcommand singletons, those values persist across parseAsync calls.
111
+ // Cast through unknown to reach the private fields without `any`.
112
+ const internal = cmd;
113
+ internal._optionValues = {};
114
+ internal.processedArgs = [];
115
+ // Re-apply Commander option defaults. Wiping _optionValues drops not just
116
+ // user-set values but also the defaults that were applied at .option() time,
117
+ // so options like `-c, --config <path>` arrive as undefined inside actions
118
+ // unless we restore them here.
119
+ for (const opt of internal.options) {
120
+ if (opt.defaultValue !== undefined) {
121
+ internal._optionValues[opt.attributeName()] = opt.defaultValue;
122
+ }
123
+ }
124
+ for (const sub of cmd.commands) {
125
+ resetCommandState(sub);
126
+ }
127
+ }
128
+ export function parseCommandLine(input) {
129
+ const args = [];
130
+ let current = "";
131
+ let inQuotes = false;
132
+ let quoteChar = "";
133
+ for (let i = 0; i < input.length; i++) {
134
+ const char = input[i];
135
+ if ((char === '"' || char === "'") && !inQuotes) {
136
+ inQuotes = true;
137
+ quoteChar = char;
138
+ }
139
+ else if (char === quoteChar && inQuotes) {
140
+ inQuotes = false;
141
+ quoteChar = "";
142
+ }
143
+ else if (char === " " && !inQuotes) {
144
+ if (current) {
145
+ args.push(current);
146
+ current = "";
147
+ }
148
+ }
149
+ else {
150
+ current += char;
151
+ }
152
+ }
153
+ if (current) {
154
+ args.push(current);
155
+ }
156
+ return args;
157
+ }
158
+ //# sourceMappingURL=repl.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"repl.js","sourceRoot":"","sources":["../../src/lib/repl.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C,MAAM,mBAAoB,SAAQ,KAAK;IAClB;IAAnB,YAAmB,IAAY;QAC7B,KAAK,CAAC,gBAAgB,IAAI,eAAe,CAAC,CAAC;QAD1B,SAAI,GAAJ,IAAI,CAAQ;IAE/B,CAAC;CACF;AAED,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,aAA4B;IAC1D,WAAW,CAAC,IAAI,CAAC,CAAC;IAClB,OAAO,CAAC,GAAG,EAAE,CAAC;IACd,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,+DAA+D,CAAC,CAAC,CAAC;IACzF,OAAO,CAAC,GAAG,EAAE,CAAC;IAEd,OAAO,IAAI,E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