specli 0.0.11 → 0.0.13

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 (335) hide show
  1. package/README.md +216 -325
  2. package/bin/cli.sh +27 -0
  3. package/dist/{src/ai → ai}/tools.d.ts +0 -1
  4. package/dist/ai/tools.js +161 -0
  5. package/dist/ai/tools.test.d.ts +1 -0
  6. package/dist/ai/tools.test.js +56 -0
  7. package/dist/{src/cli → cli}/auth-requirements.d.ts +0 -1
  8. package/dist/cli/auth-requirements.js +65 -0
  9. package/dist/cli/auth-requirements.test.d.ts +1 -0
  10. package/dist/cli/auth-requirements.test.js +16 -0
  11. package/dist/{src/cli → cli}/auth-schemes.d.ts +0 -1
  12. package/dist/cli/auth-schemes.js +112 -0
  13. package/dist/cli/auth-schemes.test.d.ts +1 -0
  14. package/dist/cli/auth-schemes.test.js +56 -0
  15. package/dist/{src/cli → cli}/capabilities.d.ts +0 -1
  16. package/dist/cli/capabilities.js +41 -0
  17. package/dist/cli/capabilities.test.d.ts +1 -0
  18. package/dist/cli/capabilities.test.js +84 -0
  19. package/dist/{src/cli → cli}/command-id.d.ts +0 -1
  20. package/dist/cli/command-id.js +8 -0
  21. package/dist/cli/command-id.test.d.ts +1 -0
  22. package/dist/cli/command-id.test.js +27 -0
  23. package/dist/{src/cli → cli}/command-index.d.ts +0 -1
  24. package/dist/cli/command-index.js +9 -0
  25. package/dist/{src/cli → cli}/command-model.d.ts +0 -1
  26. package/dist/cli/command-model.js +53 -0
  27. package/dist/cli/command-model.test.d.ts +1 -0
  28. package/dist/cli/command-model.test.js +40 -0
  29. package/dist/{src/cli → cli}/compile.d.ts +0 -1
  30. package/dist/cli/compile.js +79 -0
  31. package/dist/{src/cli → cli}/crypto.d.ts +0 -1
  32. package/dist/cli/crypto.js +9 -0
  33. package/dist/{src/cli → cli}/derive-name.d.ts +0 -1
  34. package/dist/cli/derive-name.js +96 -0
  35. package/dist/{src/cli → cli}/exec.d.ts +0 -1
  36. package/dist/cli/exec.js +50 -0
  37. package/dist/{src/cli → cli}/main.d.ts +0 -1
  38. package/dist/cli/main.js +177 -0
  39. package/dist/{src/cli → cli}/naming.d.ts +0 -1
  40. package/dist/cli/naming.js +191 -0
  41. package/dist/cli/naming.test.d.ts +1 -0
  42. package/dist/cli/naming.test.js +75 -0
  43. package/dist/{src/cli → cli}/operations.d.ts +0 -1
  44. package/dist/cli/operations.js +100 -0
  45. package/dist/cli/operations.test.d.ts +1 -0
  46. package/dist/cli/operations.test.js +51 -0
  47. package/dist/{src/cli → cli}/params.d.ts +0 -1
  48. package/dist/cli/params.js +36 -0
  49. package/dist/cli/params.test.d.ts +1 -0
  50. package/dist/cli/params.test.js +62 -0
  51. package/dist/{src/cli → cli}/pluralize.d.ts +0 -1
  52. package/dist/cli/pluralize.js +38 -0
  53. package/dist/{src/cli → cli}/positional.d.ts +0 -1
  54. package/dist/cli/positional.js +35 -0
  55. package/dist/cli/positional.test.d.ts +1 -0
  56. package/dist/cli/positional.test.js +60 -0
  57. package/dist/{src/cli → cli}/request-body.d.ts +0 -1
  58. package/dist/cli/request-body.js +44 -0
  59. package/dist/cli/request-body.test.d.ts +1 -0
  60. package/dist/cli/request-body.test.js +31 -0
  61. package/dist/{src/cli → cli}/runtime/argv.d.ts +0 -1
  62. package/dist/cli/runtime/argv.js +15 -0
  63. package/dist/{src/cli → cli}/runtime/auth/resolve.d.ts +0 -1
  64. package/dist/cli/runtime/auth/resolve.js +39 -0
  65. package/dist/{src/cli → cli}/runtime/body-flags.d.ts +0 -1
  66. package/dist/cli/runtime/body-flags.js +117 -0
  67. package/dist/cli/runtime/body-flags.test.d.ts +1 -0
  68. package/dist/cli/runtime/body-flags.test.js +192 -0
  69. package/dist/{src/cli → cli}/runtime/body.d.ts +0 -1
  70. package/dist/cli/runtime/body.js +16 -0
  71. package/dist/{src/cli → cli}/runtime/collect.d.ts +0 -1
  72. package/dist/cli/runtime/collect.js +3 -0
  73. package/dist/{src/cli → cli}/runtime/compat.d.ts +0 -1
  74. package/dist/cli/runtime/compat.js +78 -0
  75. package/dist/{src/cli → cli}/runtime/context.d.ts +0 -1
  76. package/dist/cli/runtime/context.js +44 -0
  77. package/dist/{src/cli → cli}/runtime/execute.d.ts +0 -1
  78. package/dist/cli/runtime/execute.js +106 -0
  79. package/dist/{src/cli → cli}/runtime/generated.d.ts +0 -1
  80. package/dist/cli/runtime/generated.js +168 -0
  81. package/dist/{src/cli → cli}/runtime/headers.d.ts +0 -1
  82. package/dist/cli/runtime/headers.js +30 -0
  83. package/dist/{src/cli → cli}/runtime/index.d.ts +0 -1
  84. package/dist/cli/runtime/index.js +3 -0
  85. package/dist/{src/cli → cli}/runtime/profile/secrets.d.ts +0 -1
  86. package/dist/cli/runtime/profile/secrets.js +53 -0
  87. package/dist/{src/cli → cli}/runtime/profile/store.d.ts +0 -1
  88. package/dist/cli/runtime/profile/store.js +63 -0
  89. package/dist/{src/cli → cli}/runtime/request.d.ts +0 -1
  90. package/dist/cli/runtime/request.js +283 -0
  91. package/dist/cli/runtime/request.test.d.ts +1 -0
  92. package/dist/cli/runtime/request.test.js +332 -0
  93. package/dist/{src/cli → cli}/runtime/server-url.d.ts +0 -1
  94. package/dist/cli/runtime/server-url.js +28 -0
  95. package/dist/{src/cli → cli}/runtime/template.d.ts +0 -1
  96. package/dist/cli/runtime/template.js +22 -0
  97. package/dist/cli/runtime/validate/ajv.d.ts +2 -0
  98. package/dist/cli/runtime/validate/ajv.js +11 -0
  99. package/dist/{src/cli → cli}/runtime/validate/coerce.d.ts +0 -1
  100. package/dist/cli/runtime/validate/coerce.js +63 -0
  101. package/dist/cli/runtime/validate/coerce.test.d.ts +1 -0
  102. package/dist/cli/runtime/validate/coerce.test.js +75 -0
  103. package/dist/{src/cli → cli}/runtime/validate/error.d.ts +0 -1
  104. package/dist/cli/runtime/validate/error.js +19 -0
  105. package/dist/{src/cli → cli}/runtime/validate/index.d.ts +0 -1
  106. package/dist/cli/runtime/validate/index.js +4 -0
  107. package/dist/{src/cli → cli}/runtime/validate/schema.d.ts +0 -1
  108. package/dist/cli/runtime/validate/schema.js +38 -0
  109. package/dist/{src/cli → cli}/schema-shape.d.ts +0 -1
  110. package/dist/cli/schema-shape.js +34 -0
  111. package/dist/{src/cli → cli}/schema.d.ts +0 -1
  112. package/dist/cli/schema.js +31 -0
  113. package/dist/{src/cli → cli}/server.d.ts +0 -1
  114. package/dist/cli/server.js +130 -0
  115. package/dist/cli/server.test.d.ts +1 -0
  116. package/dist/cli/server.test.js +49 -0
  117. package/dist/{src/cli → cli}/spec-id.d.ts +0 -1
  118. package/dist/cli/spec-id.js +8 -0
  119. package/dist/{src/cli → cli}/spec-loader.d.ts +0 -1
  120. package/dist/cli/spec-loader.js +40 -0
  121. package/dist/{src/cli → cli}/stable-json.d.ts +0 -1
  122. package/dist/cli/stable-json.js +29 -0
  123. package/dist/{src/cli → cli}/strings.d.ts +0 -1
  124. package/dist/cli/strings.js +20 -0
  125. package/dist/{src/cli → cli}/types.d.ts +0 -1
  126. package/dist/cli/types.js +3 -0
  127. package/dist/cli.d.ts +0 -1
  128. package/dist/cli.js +51 -2324
  129. package/dist/compiled.d.ts +2 -0
  130. package/{src/compiled.ts → dist/compiled.js} +8 -11
  131. package/dist/macros/env.d.ts +10 -0
  132. package/dist/macros/env.js +22 -0
  133. package/dist/macros/spec.d.ts +5 -0
  134. package/dist/macros/spec.js +16 -0
  135. package/package.json +17 -25
  136. package/bin/specli.js +0 -26
  137. package/cli.ts +0 -77
  138. package/dist/cli.d.ts.map +0 -1
  139. package/dist/cli.js.map +0 -53
  140. package/dist/index.d.ts +0 -2
  141. package/dist/index.d.ts.map +0 -1
  142. package/dist/index.js +0 -2032
  143. package/dist/index.js.map +0 -48
  144. package/dist/src/ai/tools.d.ts.map +0 -1
  145. package/dist/src/ai/tools.js +0 -1656
  146. package/dist/src/ai/tools.js.map +0 -45
  147. package/dist/src/cli/auth-requirements.d.ts.map +0 -1
  148. package/dist/src/cli/auth-requirements.js +0 -66
  149. package/dist/src/cli/auth-requirements.js.map +0 -10
  150. package/dist/src/cli/auth-schemes.d.ts.map +0 -1
  151. package/dist/src/cli/auth-schemes.js +0 -116
  152. package/dist/src/cli/auth-schemes.js.map +0 -11
  153. package/dist/src/cli/capabilities.d.ts.map +0 -1
  154. package/dist/src/cli/capabilities.js +0 -45
  155. package/dist/src/cli/capabilities.js.map +0 -10
  156. package/dist/src/cli/command-id.d.ts.map +0 -1
  157. package/dist/src/cli/command-id.js +0 -18
  158. package/dist/src/cli/command-id.js.map +0 -11
  159. package/dist/src/cli/command-index.d.ts.map +0 -1
  160. package/dist/src/cli/command-index.js +0 -15
  161. package/dist/src/cli/command-index.js.map +0 -10
  162. package/dist/src/cli/command-model.d.ts.map +0 -1
  163. package/dist/src/cli/command-model.js +0 -274
  164. package/dist/src/cli/command-model.js.map +0 -18
  165. package/dist/src/cli/compile.d.ts.map +0 -1
  166. package/dist/src/cli/compile.js +0 -146
  167. package/dist/src/cli/compile.js.map +0 -11
  168. package/dist/src/cli/crypto.d.ts.map +0 -1
  169. package/dist/src/cli/crypto.js +0 -15
  170. package/dist/src/cli/crypto.js.map +0 -10
  171. package/dist/src/cli/derive-name.d.ts.map +0 -1
  172. package/dist/src/cli/derive-name.js +0 -70
  173. package/dist/src/cli/derive-name.js.map +0 -10
  174. package/dist/src/cli/exec.d.ts.map +0 -1
  175. package/dist/src/cli/exec.js +0 -2077
  176. package/dist/src/cli/exec.js.map +0 -49
  177. package/dist/src/cli/main.d.ts.map +0 -1
  178. package/dist/src/cli/main.js +0 -2032
  179. package/dist/src/cli/main.js.map +0 -48
  180. package/dist/src/cli/naming.d.ts.map +0 -1
  181. package/dist/src/cli/naming.js +0 -216
  182. package/dist/src/cli/naming.js.map +0 -12
  183. package/dist/src/cli/operations.d.ts.map +0 -1
  184. package/dist/src/cli/operations.js +0 -103
  185. package/dist/src/cli/operations.js.map +0 -10
  186. package/dist/src/cli/params.d.ts.map +0 -1
  187. package/dist/src/cli/params.js +0 -79
  188. package/dist/src/cli/params.js.map +0 -12
  189. package/dist/src/cli/pluralize.d.ts.map +0 -1
  190. package/dist/src/cli/pluralize.js +0 -43
  191. package/dist/src/cli/pluralize.js.map +0 -10
  192. package/dist/src/cli/positional.d.ts.map +0 -1
  193. package/dist/src/cli/positional.js +0 -39
  194. package/dist/src/cli/positional.js.map +0 -10
  195. package/dist/src/cli/request-body.d.ts.map +0 -1
  196. package/dist/src/cli/request-body.js +0 -82
  197. package/dist/src/cli/request-body.js.map +0 -12
  198. package/dist/src/cli/runtime/argv.d.ts.map +0 -1
  199. package/dist/src/cli/runtime/argv.js +0 -22
  200. package/dist/src/cli/runtime/argv.js.map +0 -10
  201. package/dist/src/cli/runtime/auth/resolve.d.ts.map +0 -1
  202. package/dist/src/cli/runtime/auth/resolve.js +0 -38
  203. package/dist/src/cli/runtime/auth/resolve.js.map +0 -10
  204. package/dist/src/cli/runtime/body-flags.d.ts.map +0 -1
  205. package/dist/src/cli/runtime/body-flags.js +0 -86
  206. package/dist/src/cli/runtime/body-flags.js.map +0 -10
  207. package/dist/src/cli/runtime/body.d.ts.map +0 -1
  208. package/dist/src/cli/runtime/body.js +0 -40
  209. package/dist/src/cli/runtime/body.js.map +0 -11
  210. package/dist/src/cli/runtime/collect.d.ts.map +0 -1
  211. package/dist/src/cli/runtime/collect.js +0 -9
  212. package/dist/src/cli/runtime/collect.js.map +0 -10
  213. package/dist/src/cli/runtime/compat.d.ts.map +0 -1
  214. package/dist/src/cli/runtime/compat.js +0 -62
  215. package/dist/src/cli/runtime/compat.js.map +0 -10
  216. package/dist/src/cli/runtime/context.d.ts.map +0 -1
  217. package/dist/src/cli/runtime/context.js +0 -936
  218. package/dist/src/cli/runtime/context.js.map +0 -32
  219. package/dist/src/cli/runtime/execute.d.ts.map +0 -1
  220. package/dist/src/cli/runtime/execute.js +0 -670
  221. package/dist/src/cli/runtime/execute.js.map +0 -22
  222. package/dist/src/cli/runtime/generated.d.ts.map +0 -1
  223. package/dist/src/cli/runtime/generated.js +0 -869
  224. package/dist/src/cli/runtime/generated.js.map +0 -23
  225. package/dist/src/cli/runtime/headers.d.ts.map +0 -1
  226. package/dist/src/cli/runtime/headers.js +0 -36
  227. package/dist/src/cli/runtime/headers.js.map +0 -10
  228. package/dist/src/cli/runtime/index.d.ts.map +0 -1
  229. package/dist/src/cli/runtime/index.js +0 -1808
  230. package/dist/src/cli/runtime/index.js.map +0 -46
  231. package/dist/src/cli/runtime/profile/secrets.d.ts.map +0 -1
  232. package/dist/src/cli/runtime/profile/secrets.js +0 -51
  233. package/dist/src/cli/runtime/profile/secrets.js.map +0 -11
  234. package/dist/src/cli/runtime/profile/store.d.ts.map +0 -1
  235. package/dist/src/cli/runtime/profile/store.js +0 -102
  236. package/dist/src/cli/runtime/profile/store.js.map +0 -11
  237. package/dist/src/cli/runtime/request.d.ts.map +0 -1
  238. package/dist/src/cli/runtime/request.js +0 -571
  239. package/dist/src/cli/runtime/request.js.map +0 -21
  240. package/dist/src/cli/runtime/server-url.d.ts.map +0 -1
  241. package/dist/src/cli/runtime/server-url.js +0 -55
  242. package/dist/src/cli/runtime/server-url.js.map +0 -11
  243. package/dist/src/cli/runtime/template.d.ts.map +0 -1
  244. package/dist/src/cli/runtime/template.js +0 -29
  245. package/dist/src/cli/runtime/template.js.map +0 -10
  246. package/dist/src/cli/runtime/validate/ajv.d.ts +0 -3
  247. package/dist/src/cli/runtime/validate/ajv.d.ts.map +0 -1
  248. package/dist/src/cli/runtime/validate/ajv.js +0 -17
  249. package/dist/src/cli/runtime/validate/ajv.js.map +0 -10
  250. package/dist/src/cli/runtime/validate/coerce.d.ts.map +0 -1
  251. package/dist/src/cli/runtime/validate/coerce.js +0 -60
  252. package/dist/src/cli/runtime/validate/coerce.js.map +0 -10
  253. package/dist/src/cli/runtime/validate/error.d.ts.map +0 -1
  254. package/dist/src/cli/runtime/validate/error.js +0 -21
  255. package/dist/src/cli/runtime/validate/error.js.map +0 -10
  256. package/dist/src/cli/runtime/validate/index.d.ts.map +0 -1
  257. package/dist/src/cli/runtime/validate/index.js +0 -122
  258. package/dist/src/cli/runtime/validate/index.js.map +0 -13
  259. package/dist/src/cli/runtime/validate/schema.d.ts.map +0 -1
  260. package/dist/src/cli/runtime/validate/schema.js +0 -36
  261. package/dist/src/cli/runtime/validate/schema.js.map +0 -10
  262. package/dist/src/cli/schema-shape.d.ts.map +0 -1
  263. package/dist/src/cli/schema-shape.js +0 -41
  264. package/dist/src/cli/schema-shape.js.map +0 -10
  265. package/dist/src/cli/schema.d.ts.map +0 -1
  266. package/dist/src/cli/schema.js +0 -38
  267. package/dist/src/cli/schema.js.map +0 -10
  268. package/dist/src/cli/server.d.ts.map +0 -1
  269. package/dist/src/cli/server.js +0 -64
  270. package/dist/src/cli/server.js.map +0 -11
  271. package/dist/src/cli/spec-id.d.ts.map +0 -1
  272. package/dist/src/cli/spec-id.js +0 -21
  273. package/dist/src/cli/spec-id.js.map +0 -11
  274. package/dist/src/cli/spec-loader.d.ts.map +0 -1
  275. package/dist/src/cli/spec-loader.js +0 -110
  276. package/dist/src/cli/spec-loader.js.map +0 -15
  277. package/dist/src/cli/stable-json.d.ts.map +0 -1
  278. package/dist/src/cli/stable-json.js +0 -35
  279. package/dist/src/cli/stable-json.js.map +0 -10
  280. package/dist/src/cli/strings.d.ts.map +0 -1
  281. package/dist/src/cli/strings.js +0 -16
  282. package/dist/src/cli/strings.js.map +0 -10
  283. package/dist/src/cli/types.d.ts.map +0 -1
  284. package/dist/src/cli/types.js +0 -9
  285. package/dist/src/cli/types.js.map +0 -10
  286. package/index.ts +0 -1
  287. package/src/ai/tools.ts +0 -211
  288. package/src/cli/auth-requirements.ts +0 -91
  289. package/src/cli/auth-schemes.ts +0 -187
  290. package/src/cli/capabilities.ts +0 -88
  291. package/src/cli/command-id.ts +0 -16
  292. package/src/cli/command-index.ts +0 -19
  293. package/src/cli/command-model.ts +0 -128
  294. package/src/cli/compile.ts +0 -101
  295. package/src/cli/crypto.ts +0 -9
  296. package/src/cli/derive-name.ts +0 -101
  297. package/src/cli/exec.ts +0 -72
  298. package/src/cli/main.ts +0 -231
  299. package/src/cli/naming.ts +0 -224
  300. package/src/cli/operations.ts +0 -152
  301. package/src/cli/params.ts +0 -71
  302. package/src/cli/pluralize.ts +0 -41
  303. package/src/cli/positional.ts +0 -75
  304. package/src/cli/request-body.ts +0 -94
  305. package/src/cli/runtime/argv.ts +0 -14
  306. package/src/cli/runtime/auth/resolve.ts +0 -59
  307. package/src/cli/runtime/body-flags.ts +0 -176
  308. package/src/cli/runtime/body.ts +0 -24
  309. package/src/cli/runtime/collect.ts +0 -6
  310. package/src/cli/runtime/compat.ts +0 -89
  311. package/src/cli/runtime/context.ts +0 -62
  312. package/src/cli/runtime/execute.ts +0 -147
  313. package/src/cli/runtime/generated.ts +0 -242
  314. package/src/cli/runtime/headers.ts +0 -37
  315. package/src/cli/runtime/index.ts +0 -3
  316. package/src/cli/runtime/profile/secrets.ts +0 -83
  317. package/src/cli/runtime/profile/store.ts +0 -100
  318. package/src/cli/runtime/request.ts +0 -390
  319. package/src/cli/runtime/server-url.ts +0 -45
  320. package/src/cli/runtime/template.ts +0 -26
  321. package/src/cli/runtime/validate/ajv.ts +0 -13
  322. package/src/cli/runtime/validate/coerce.ts +0 -71
  323. package/src/cli/runtime/validate/error.ts +0 -29
  324. package/src/cli/runtime/validate/index.ts +0 -4
  325. package/src/cli/runtime/validate/schema.ts +0 -54
  326. package/src/cli/schema-shape.ts +0 -36
  327. package/src/cli/schema.ts +0 -76
  328. package/src/cli/server.ts +0 -88
  329. package/src/cli/spec-id.ts +0 -12
  330. package/src/cli/spec-loader.ts +0 -58
  331. package/src/cli/stable-json.ts +0 -35
  332. package/src/cli/strings.ts +0 -21
  333. package/src/cli/types.ts +0 -59
  334. package/src/macros/env.ts +0 -21
  335. package/src/macros/spec.ts +0 -17
@@ -1,45 +0,0 @@
1
- // src/cli/capabilities.ts
2
- function uniqueSorted(items, compare) {
3
- const out = [...items];
4
- out.sort(compare);
5
- return out.filter((v, i) => i === 0 || compare(out[i - 1], v) !== 0);
6
- }
7
- function hasSecurity(requirements) {
8
- if (!requirements?.length)
9
- return false;
10
- return true;
11
- }
12
- function deriveCapabilities(input) {
13
- const serverHasVars = input.servers.some((s) => s.variableNames.length > 0);
14
- const authKinds = uniqueSorted(input.authSchemes.map((s) => s.kind), (a, b) => a.localeCompare(b));
15
- const hasSecurityRequirements = hasSecurity(input.doc.security) || input.operations.some((op) => hasSecurity(op.security));
16
- const opHasBodies = input.operations.some((op) => Boolean(op.requestBody));
17
- const cmdResources = input.commands?.resources ?? [];
18
- const cmdActions = cmdResources.flatMap((r) => r.actions);
19
- const cmdHasBodies = cmdActions.some((a) => Boolean(a.requestBody));
20
- return {
21
- servers: {
22
- count: input.servers.length,
23
- hasVariables: serverHasVars
24
- },
25
- auth: {
26
- count: input.authSchemes.length,
27
- kinds: authKinds,
28
- hasSecurityRequirements
29
- },
30
- operations: {
31
- count: input.operations.length,
32
- hasRequestBodies: opHasBodies
33
- },
34
- commands: {
35
- countResources: cmdResources.length,
36
- countActions: cmdActions.length,
37
- hasRequestBodies: cmdHasBodies
38
- }
39
- };
40
- }
41
- export {
42
- deriveCapabilities
43
- };
44
-
45
- //# debugId=59EB25C5C8336ED764756E2164756E21
@@ -1,10 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/cli/capabilities.ts"],
4
- "sourcesContent": [
5
- "import type { AuthScheme, AuthSchemeKind } from \"./auth-schemes.ts\";\nimport type { CommandModel } from \"./command-model.ts\";\nimport type { ServerInfo } from \"./server.ts\";\nimport type {\n\tNormalizedOperation,\n\tOpenApiDoc,\n\tSecurityRequirement,\n} from \"./types.ts\";\n\nexport type Capabilities = {\n\tservers: {\n\t\tcount: number;\n\t\thasVariables: boolean;\n\t};\n\tauth: {\n\t\tcount: number;\n\t\tkinds: AuthSchemeKind[];\n\t\thasSecurityRequirements: boolean;\n\t};\n\toperations: {\n\t\tcount: number;\n\t\thasRequestBodies: boolean;\n\t};\n\tcommands: {\n\t\tcountResources: number;\n\t\tcountActions: number;\n\t\thasRequestBodies: boolean;\n\t};\n};\n\nfunction uniqueSorted<T>(items: T[], compare: (a: T, b: T) => number): T[] {\n\tconst out = [...items];\n\tout.sort(compare);\n\treturn out.filter((v, i) => i === 0 || compare(out[i - 1] as T, v) !== 0);\n}\n\nfunction hasSecurity(requirements: SecurityRequirement[] | undefined): boolean {\n\tif (!requirements?.length) return false;\n\n\t// Treat any non-empty array as \"auth exists\", even if it contains `{}` to mean optional.\n\treturn true;\n}\n\nexport function deriveCapabilities(input: {\n\tdoc: OpenApiDoc;\n\tservers: ServerInfo[];\n\tauthSchemes: AuthScheme[];\n\toperations: NormalizedOperation[];\n\tcommands?: CommandModel;\n}): Capabilities {\n\tconst serverHasVars = input.servers.some((s) => s.variableNames.length > 0);\n\n\tconst authKinds = uniqueSorted(\n\t\tinput.authSchemes.map((s) => s.kind),\n\t\t(a, b) => a.localeCompare(b),\n\t);\n\n\tconst hasSecurityRequirements =\n\t\thasSecurity(input.doc.security) ||\n\t\tinput.operations.some((op) => hasSecurity(op.security));\n\n\tconst opHasBodies = input.operations.some((op) => Boolean(op.requestBody));\n\n\tconst cmdResources = input.commands?.resources ?? [];\n\tconst cmdActions = cmdResources.flatMap((r) => r.actions);\n\tconst cmdHasBodies = cmdActions.some((a) => Boolean(a.requestBody));\n\n\treturn {\n\t\tservers: {\n\t\t\tcount: input.servers.length,\n\t\t\thasVariables: serverHasVars,\n\t\t},\n\t\tauth: {\n\t\t\tcount: input.authSchemes.length,\n\t\t\tkinds: authKinds,\n\t\t\thasSecurityRequirements,\n\t\t},\n\t\toperations: {\n\t\t\tcount: input.operations.length,\n\t\t\thasRequestBodies: opHasBodies,\n\t\t},\n\t\tcommands: {\n\t\t\tcountResources: cmdResources.length,\n\t\t\tcountActions: cmdActions.length,\n\t\t\thasRequestBodies: cmdHasBodies,\n\t\t},\n\t};\n}\n"
6
- ],
7
- "mappings": ";A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AgB,aAAa;AAAA,MAC7B,cAAc,WAAW;AAAA,MACzB,kBAAkB;AAAA,IACnB;AAAA,EACD;AAAA;",
8
- "debugId": "59EB25C5C8336ED764756E2164756E21",
9
- "names": []
10
- }
@@ -1 +0,0 @@
1
- {"version":3,"file":"command-id.d.ts","sourceRoot":"","sources":["../../../src/cli/command-id.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,cAAc,GAAG;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,wBAAgB,cAAc,CAAC,KAAK,EAAE,cAAc,GAAG,MAAM,CAM5D"}
@@ -1,18 +0,0 @@
1
- // src/cli/strings.ts
2
- function kebabCase(input) {
3
- const trimmed = input.trim();
4
- if (!trimmed)
5
- return "";
6
- return trimmed.replace(/([a-z0-9])([A-Z])/g, "$1-$2").replace(/[\s_.:/]+/g, "-").replace(/[^a-zA-Z0-9-]/g, "-").replace(/-+/g, "-").replace(/^-|-$/g, "").toLowerCase();
7
- }
8
-
9
- // src/cli/command-id.ts
10
- function buildCommandId(parts) {
11
- const op = kebabCase(parts.operationKey.replace(/\s+/g, "-"));
12
- return `${parts.specId}:${kebabCase(parts.resource)}:${kebabCase(parts.action)}:${op}`;
13
- }
14
- export {
15
- buildCommandId
16
- };
17
-
18
- //# debugId=B762E82FE5939FE664756E2164756E21
@@ -1,11 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/cli/strings.ts", "../../../src/cli/command-id.ts"],
4
- "sourcesContent": [
5
- "export function kebabCase(input: string): string {\n\tconst trimmed = input.trim();\n\tif (!trimmed) return \"\";\n\n\t// Convert spaces/underscores/dots to dashes, split camelCase.\n\treturn trimmed\n\t\t.replace(/([a-z0-9])([A-Z])/g, \"$1-$2\")\n\t\t.replace(/[\\s_.:/]+/g, \"-\")\n\t\t.replace(/[^a-zA-Z0-9-]/g, \"-\")\n\t\t.replace(/-+/g, \"-\")\n\t\t.replace(/^-|-$/g, \"\")\n\t\t.toLowerCase();\n}\n\nexport function titleCase(input: string): string {\n\treturn input\n\t\t.split(/\\s+/g)\n\t\t.filter(Boolean)\n\t\t.map((w) => w[0]?.toUpperCase() + w.slice(1))\n\t\t.join(\" \");\n}\n",
6
- "import { kebabCase } from \"./strings.ts\";\n\nexport type CommandIdParts = {\n\tspecId: string;\n\tresource: string;\n\taction: string;\n\toperationKey: string;\n};\n\nexport function buildCommandId(parts: CommandIdParts): string {\n\t// operationKey is the ultimate disambiguator, but we keep the id readable.\n\t// Example:\n\t// contacts-api:contacts:get:GET-/contacts/{id}\n\tconst op = kebabCase(parts.operationKey.replace(/\\s+/g, \"-\"));\n\treturn `${parts.specId}:${kebabCase(parts.resource)}:${kebabCase(parts.action)}:${op}`;\n}\n"
7
- ],
8
- "mappings": ";AAAO,SAAS,SAAS,CAAC,OAAuB;AAAA,EAChD,MAAM,UAAU,MAAM,KAAK;AAAA,EAC3B,IAAI,CAAC;AAAA,IAAS,OAAO;AAAA,EAGrB,OAAO,QACL,QAAQ,sBAAsB,OAAO,EACrC,QAAQ,cAAc,GAAG,EACzB,QAAQ,kBAAkB,GAAG,EAC7B,QAAQ,OAAO,GAAG,EAClB,QAAQ,UAAU,EAAE,EACpB,YAAY;AAAA;;;ACFR,SAAS,cAAc,CAAC,OAA+B;AAAA,EAI7D,MAAM,KAAK,UAAU,MAAM,aAAa,QAAQ,QAAQ,GAAG,CAAC;AAAA,EAC5D,OAAO,GAAG,MAAM,UAAU,UAAU,MAAM,QAAQ,KAAK,UAAU,MAAM,MAAM,KAAK;AAAA;",
9
- "debugId": "B762E82FE5939FE664756E2164756E21",
10
- "names": []
11
- }
@@ -1 +0,0 @@
1
- {"version":3,"file":"command-index.d.ts","sourceRoot":"","sources":["../../../src/cli/command-index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAEtE,MAAM,MAAM,aAAa,GAAG;IAC3B,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;CACpC,CAAC;AAEF,wBAAgB,kBAAkB,CACjC,QAAQ,EAAE,YAAY,GAAG,SAAS,GAChC,aAAa,CAUf"}
@@ -1,15 +0,0 @@
1
- // src/cli/command-index.ts
2
- function buildCommandsIndex(commands) {
3
- const byId = {};
4
- for (const resource of commands?.resources ?? []) {
5
- for (const action of resource.actions) {
6
- byId[action.id] = action;
7
- }
8
- }
9
- return { byId };
10
- }
11
- export {
12
- buildCommandsIndex
13
- };
14
-
15
- //# debugId=F2735E1A1DCFEBCF64756E2164756E21
@@ -1,10 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/cli/command-index.ts"],
4
- "sourcesContent": [
5
- "import type { CommandAction, CommandModel } from \"./command-model.ts\";\n\nexport type CommandsIndex = {\n\tbyId: Record<string, CommandAction>;\n};\n\nexport function buildCommandsIndex(\n\tcommands: CommandModel | undefined,\n): CommandsIndex {\n\tconst byId: Record<string, CommandAction> = {};\n\n\tfor (const resource of commands?.resources ?? []) {\n\t\tfor (const action of resource.actions) {\n\t\t\tbyId[action.id] = action;\n\t\t}\n\t}\n\n\treturn { byId };\n}\n"
6
- ],
7
- "mappings": ";AAMO,SAAS,kBAAkB,CACjC,UACgB;AAAA,EAChB,MAAM,OAAsC,CAAC;AAAA,EAE7C,WAAW,YAAY,UAAU,aAAa,CAAC,GAAG;AAAA,IACjD,WAAW,UAAU,SAAS,SAAS;AAAA,MACtC,KAAK,OAAO,MAAM;AAAA,IACnB;AAAA,EACD;AAAA,EAEA,OAAO,EAAE,KAAK;AAAA;",
8
- "debugId": "F2735E1A1DCFEBCF64756E2164756E21",
9
- "names": []
10
- }
@@ -1 +0,0 @@
1
- {"version":3,"file":"command-model.d.ts","sourceRoot":"","sources":["../../../src/cli/command-model.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,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eAAe,GAAG;IAC7B,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,aAAa,EAAE,CAAC;CACzB,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG;IAC1B,SAAS,EAAE,eAAe,EAAE,CAAC;CAC7B,CAAC;AAEF,MAAM,MAAM,wBAAwB,GAAG;IACtC,MAAM,EAAE,MAAM,CAAC;IACf,cAAc,CAAC,EAAE,mBAAmB,EAAE,CAAC;IACvC,WAAW,CAAC,EAAE,UAAU,EAAE,CAAC;CAC3B,CAAC;AAEF,wBAAgB,iBAAiB,CAChC,OAAO,EAAE,gBAAgB,EAAE,EAC3B,OAAO,EAAE,wBAAwB,GAC/B,YAAY,CAuDd"}
@@ -1,274 +0,0 @@
1
- // src/cli/auth-requirements.ts
2
- function isSecurityRequirement(value) {
3
- if (!value || typeof value !== "object")
4
- return false;
5
- if (Array.isArray(value))
6
- return false;
7
- for (const [k, v] of Object.entries(value)) {
8
- if (typeof k !== "string")
9
- return false;
10
- if (!Array.isArray(v))
11
- return false;
12
- if (!v.every((s) => typeof s === "string"))
13
- return false;
14
- }
15
- return true;
16
- }
17
- function normalizeSecurity(value) {
18
- if (value == null)
19
- return { requirements: [], source: "none" };
20
- if (!Array.isArray(value))
21
- return { requirements: [], source: "none" };
22
- const reqs = value.filter(isSecurityRequirement);
23
- if (reqs.length === 0)
24
- return { requirements: [], source: "empty" };
25
- return { requirements: reqs, source: "non-empty" };
26
- }
27
- function summarizeAuth(operationSecurity, globalSecurity, knownSchemes) {
28
- const op = normalizeSecurity(operationSecurity);
29
- if (op.source === "non-empty") {
30
- return { alternatives: toAlternatives(op.requirements, knownSchemes) };
31
- }
32
- if (op.source === "empty") {
33
- return { alternatives: [] };
34
- }
35
- const global = normalizeSecurity(globalSecurity);
36
- if (global.source === "non-empty") {
37
- return { alternatives: toAlternatives(global.requirements, knownSchemes) };
38
- }
39
- return { alternatives: [] };
40
- }
41
- function toAlternatives(requirements, knownSchemes) {
42
- const known = new Set(knownSchemes.map((s) => s.key));
43
- return requirements.map((req) => {
44
- const out = [];
45
- for (const [key, scopes] of Object.entries(req)) {
46
- out.push({
47
- key,
48
- scopes: Array.isArray(scopes) ? scopes : []
49
- });
50
- }
51
- out.sort((a, b) => a.key.localeCompare(b.key));
52
- out.sort((a, b) => {
53
- const ak = known.has(a.key) ? 0 : 1;
54
- const bk = known.has(b.key) ? 0 : 1;
55
- if (ak !== bk)
56
- return ak - bk;
57
- return a.key.localeCompare(b.key);
58
- });
59
- return out;
60
- });
61
- }
62
-
63
- // src/cli/strings.ts
64
- function kebabCase(input) {
65
- const trimmed = input.trim();
66
- if (!trimmed)
67
- return "";
68
- return trimmed.replace(/([a-z0-9])([A-Z])/g, "$1-$2").replace(/[\s_.:/]+/g, "-").replace(/[^a-zA-Z0-9-]/g, "-").replace(/-+/g, "-").replace(/^-|-$/g, "").toLowerCase();
69
- }
70
-
71
- // src/cli/command-id.ts
72
- function buildCommandId(parts) {
73
- const op = kebabCase(parts.operationKey.replace(/\s+/g, "-"));
74
- return `${parts.specId}:${kebabCase(parts.resource)}:${kebabCase(parts.action)}:${op}`;
75
- }
76
-
77
- // src/cli/schema-shape.ts
78
- function getSchemaType(schema) {
79
- if (!schema || typeof schema !== "object")
80
- return "unknown";
81
- const t = schema.type;
82
- if (t === "string")
83
- return "string";
84
- if (t === "number")
85
- return "number";
86
- if (t === "integer")
87
- return "integer";
88
- if (t === "boolean")
89
- return "boolean";
90
- if (t === "array")
91
- return "array";
92
- if (t === "object")
93
- return "object";
94
- return "unknown";
95
- }
96
- function getSchemaFormat(schema) {
97
- if (!schema || typeof schema !== "object")
98
- return;
99
- const f = schema.format;
100
- return typeof f === "string" ? f : undefined;
101
- }
102
- function getSchemaEnumStrings(schema) {
103
- if (!schema || typeof schema !== "object")
104
- return;
105
- const e = schema.enum;
106
- if (!Array.isArray(e))
107
- return;
108
- const values = e.filter((v) => typeof v === "string");
109
- return values.length ? values : undefined;
110
- }
111
-
112
- // src/cli/params.ts
113
- function deriveParamSpecs(op) {
114
- const out = [];
115
- for (const p of op.parameters) {
116
- const flag = `--${kebabCase(p.name)}`;
117
- const type = getSchemaType(p.schema);
118
- const schemaObj = p.schema && typeof p.schema === "object" ? p.schema : undefined;
119
- const itemsSchema = schemaObj && type === "array" && typeof schemaObj.items === "object" ? schemaObj.items : undefined;
120
- out.push({
121
- kind: p.in === "path" ? "positional" : "flag",
122
- in: p.in,
123
- name: p.name,
124
- flag,
125
- required: p.required,
126
- description: p.description,
127
- type,
128
- format: getSchemaFormat(p.schema),
129
- enum: getSchemaEnumStrings(p.schema),
130
- itemType: type === "array" ? getSchemaType(itemsSchema) : undefined,
131
- itemFormat: type === "array" ? getSchemaFormat(itemsSchema) : undefined,
132
- itemEnum: type === "array" ? getSchemaEnumStrings(itemsSchema) : undefined,
133
- schema: schemaObj
134
- });
135
- }
136
- out.sort((a, b) => {
137
- if (a.in !== b.in)
138
- return a.in.localeCompare(b.in);
139
- return a.name.localeCompare(b.name);
140
- });
141
- return out;
142
- }
143
-
144
- // src/cli/positional.ts
145
- function derivePositionals(action) {
146
- const byName = new Map;
147
- for (const name of action.pathArgs) {
148
- const p = action.params.find((x) => x.in === "path" && x.name === name);
149
- byName.set(name, {
150
- name,
151
- required: true,
152
- description: p?.description,
153
- type: p?.type ?? "unknown",
154
- format: p?.format,
155
- enum: p?.enum
156
- });
157
- }
158
- return [...byName.values()];
159
- }
160
- function deriveFlags(action) {
161
- return {
162
- flags: action.params.filter((p) => p.kind === "flag").map((p) => ({
163
- in: p.in,
164
- name: p.name,
165
- flag: p.flag,
166
- required: p.required,
167
- description: p.description,
168
- type: p.type,
169
- format: p.format,
170
- enum: p.enum,
171
- itemType: p.itemType,
172
- itemFormat: p.itemFormat,
173
- itemEnum: p.itemEnum
174
- }))
175
- };
176
- }
177
-
178
- // src/cli/types.ts
179
- function isJsonSchema(value) {
180
- return Boolean(value) && typeof value === "object" && !Array.isArray(value);
181
- }
182
-
183
- // src/cli/request-body.ts
184
- function getRequestBody(op) {
185
- return op.requestBody;
186
- }
187
- function deriveRequestBodyInfo(op) {
188
- const rb = getRequestBody(op);
189
- if (!rb)
190
- return;
191
- const content = [];
192
- for (const contentType of rb.contentTypes) {
193
- const schema = rb.schemasByContentType[contentType];
194
- content.push({
195
- contentType,
196
- required: rb.required,
197
- schemaType: getSchemaType(schema),
198
- schemaFormat: getSchemaFormat(schema),
199
- schemaEnum: getSchemaEnumStrings(schema)
200
- });
201
- }
202
- content.sort((a, b) => a.contentType.localeCompare(b.contentType));
203
- const hasJson = content.some((c) => c.contentType.includes("json"));
204
- const hasFormUrlEncoded = content.some((c) => c.contentType === "application/x-www-form-urlencoded");
205
- const hasMultipart = content.some((c) => c.contentType.startsWith("multipart/"));
206
- const bodyFlags = ["--data", "--file"];
207
- const preferredContentType = content.find((c) => c.contentType === "application/json")?.contentType ?? content.find((c) => c.contentType.includes("json"))?.contentType ?? content[0]?.contentType;
208
- const preferredSchema = preferredContentType ? rb.schemasByContentType[preferredContentType] : undefined;
209
- return {
210
- required: rb.required,
211
- content,
212
- hasJson,
213
- hasFormUrlEncoded,
214
- hasMultipart,
215
- bodyFlags,
216
- preferredContentType,
217
- preferredSchema: isJsonSchema(preferredSchema) ? preferredSchema : undefined
218
- };
219
- }
220
-
221
- // src/cli/command-model.ts
222
- function buildCommandModel(planned, options) {
223
- const byResource = new Map;
224
- for (const op of planned) {
225
- const list = byResource.get(op.resource) ?? [];
226
- const params = deriveParamSpecs(op);
227
- const positionals = derivePositionals({ pathArgs: op.pathArgs, params });
228
- const flags = deriveFlags({ pathArgs: op.pathArgs, params });
229
- list.push({
230
- id: buildCommandId({
231
- specId: options.specId,
232
- resource: op.resource,
233
- action: op.action,
234
- operationKey: op.key
235
- }),
236
- key: op.key,
237
- action: op.action,
238
- pathArgs: op.pathArgs,
239
- method: op.method,
240
- path: op.path,
241
- operationId: op.operationId,
242
- tags: op.tags,
243
- summary: op.summary,
244
- description: op.description,
245
- deprecated: op.deprecated,
246
- style: op.style,
247
- params,
248
- positionals,
249
- flags: flags.flags,
250
- auth: summarizeAuth(op.security, options.globalSecurity, options.authSchemes ?? []),
251
- requestBody: deriveRequestBodyInfo(op),
252
- requestBodySchema: deriveRequestBodyInfo(op)?.preferredSchema
253
- });
254
- byResource.set(op.resource, list);
255
- }
256
- const resources = [];
257
- for (const [resource, actions] of byResource.entries()) {
258
- actions.sort((a, b) => {
259
- if (a.action !== b.action)
260
- return a.action.localeCompare(b.action);
261
- if (a.path !== b.path)
262
- return a.path.localeCompare(b.path);
263
- return a.method.localeCompare(b.method);
264
- });
265
- resources.push({ resource, actions });
266
- }
267
- resources.sort((a, b) => a.resource.localeCompare(b.resource));
268
- return { resources };
269
- }
270
- export {
271
- buildCommandModel
272
- };
273
-
274
- //# debugId=45780225ADBA9F6E64756E2164756E21
@@ -1,18 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/cli/auth-requirements.ts", "../../../src/cli/strings.ts", "../../../src/cli/command-id.ts", "../../../src/cli/schema-shape.ts", "../../../src/cli/params.ts", "../../../src/cli/positional.ts", "../../../src/cli/types.ts", "../../../src/cli/request-body.ts", "../../../src/cli/command-model.ts"],
4
- "sourcesContent": [
5
- "import type { AuthScheme } from \"./auth-schemes.ts\";\nimport type { SecurityRequirement } from \"./types.ts\";\n\nexport type AuthRequirement = {\n\tkey: string;\n\tscopes: string[];\n};\n\nexport type AuthSummary = {\n\t// Alternatives: any one of these sets is sufficient.\n\talternatives: AuthRequirement[][];\n};\n\nfunction isSecurityRequirement(value: unknown): value is SecurityRequirement {\n\tif (!value || typeof value !== \"object\") return false;\n\tif (Array.isArray(value)) return false;\n\n\tfor (const [k, v] of Object.entries(value)) {\n\t\tif (typeof k !== \"string\") return false;\n\t\tif (!Array.isArray(v)) return false;\n\t\tif (!v.every((s) => typeof s === \"string\")) return false;\n\t}\n\n\treturn true;\n}\n\nfunction normalizeSecurity(value: unknown): {\n\trequirements: SecurityRequirement[];\n\tsource: \"none\" | \"empty\" | \"non-empty\";\n} {\n\tif (value == null) return { requirements: [], source: \"none\" };\n\tif (!Array.isArray(value)) return { requirements: [], source: \"none\" };\n\n\tconst reqs = value.filter(isSecurityRequirement);\n\tif (reqs.length === 0) return { requirements: [], source: \"empty\" };\n\treturn { requirements: reqs, source: \"non-empty\" };\n}\n\nexport function summarizeAuth(\n\toperationSecurity: unknown,\n\tglobalSecurity: unknown,\n\tknownSchemes: AuthScheme[],\n): AuthSummary {\n\t// Per spec:\n\t// - operation security overrides root\n\t// - empty array [] means \"no auth\"\n\tconst op = normalizeSecurity(operationSecurity);\n\tif (op.source === \"non-empty\") {\n\t\treturn { alternatives: toAlternatives(op.requirements, knownSchemes) };\n\t}\n\tif (op.source === \"empty\") {\n\t\treturn { alternatives: [] };\n\t}\n\n\tconst global = normalizeSecurity(globalSecurity);\n\tif (global.source === \"non-empty\") {\n\t\treturn { alternatives: toAlternatives(global.requirements, knownSchemes) };\n\t}\n\n\treturn { alternatives: [] };\n}\n\nfunction toAlternatives(\n\trequirements: SecurityRequirement[],\n\tknownSchemes: AuthScheme[],\n): AuthRequirement[][] {\n\tconst known = new Set(knownSchemes.map((s) => s.key));\n\n\treturn requirements.map((req) => {\n\t\tconst out: AuthRequirement[] = [];\n\t\tfor (const [key, scopes] of Object.entries(req)) {\n\t\t\tout.push({\n\t\t\t\tkey,\n\t\t\t\tscopes: Array.isArray(scopes) ? scopes : [],\n\t\t\t});\n\t\t}\n\n\t\t// Stable order.\n\t\tout.sort((a, b) => a.key.localeCompare(b.key));\n\n\t\t// Prefer known schemes first.\n\t\tout.sort((a, b) => {\n\t\t\tconst ak = known.has(a.key) ? 0 : 1;\n\t\t\tconst bk = known.has(b.key) ? 0 : 1;\n\t\t\tif (ak !== bk) return ak - bk;\n\t\t\treturn a.key.localeCompare(b.key);\n\t\t});\n\n\t\treturn out;\n\t});\n}\n",
6
- "export function kebabCase(input: string): string {\n\tconst trimmed = input.trim();\n\tif (!trimmed) return \"\";\n\n\t// Convert spaces/underscores/dots to dashes, split camelCase.\n\treturn trimmed\n\t\t.replace(/([a-z0-9])([A-Z])/g, \"$1-$2\")\n\t\t.replace(/[\\s_.:/]+/g, \"-\")\n\t\t.replace(/[^a-zA-Z0-9-]/g, \"-\")\n\t\t.replace(/-+/g, \"-\")\n\t\t.replace(/^-|-$/g, \"\")\n\t\t.toLowerCase();\n}\n\nexport function titleCase(input: string): string {\n\treturn input\n\t\t.split(/\\s+/g)\n\t\t.filter(Boolean)\n\t\t.map((w) => w[0]?.toUpperCase() + w.slice(1))\n\t\t.join(\" \");\n}\n",
7
- "import { kebabCase } from \"./strings.ts\";\n\nexport type CommandIdParts = {\n\tspecId: string;\n\tresource: string;\n\taction: string;\n\toperationKey: string;\n};\n\nexport function buildCommandId(parts: CommandIdParts): string {\n\t// operationKey is the ultimate disambiguator, but we keep the id readable.\n\t// Example:\n\t// contacts-api:contacts:get:GET-/contacts/{id}\n\tconst op = kebabCase(parts.operationKey.replace(/\\s+/g, \"-\"));\n\treturn `${parts.specId}:${kebabCase(parts.resource)}:${kebabCase(parts.action)}:${op}`;\n}\n",
8
- "export type ParamType =\n\t| \"string\"\n\t| \"number\"\n\t| \"integer\"\n\t| \"boolean\"\n\t| \"array\"\n\t| \"object\"\n\t| \"unknown\";\n\nexport function getSchemaType(schema: unknown): ParamType {\n\tif (!schema || typeof schema !== \"object\") return \"unknown\";\n\tconst t = (schema as { type?: unknown }).type;\n\tif (t === \"string\") return \"string\";\n\tif (t === \"number\") return \"number\";\n\tif (t === \"integer\") return \"integer\";\n\tif (t === \"boolean\") return \"boolean\";\n\tif (t === \"array\") return \"array\";\n\tif (t === \"object\") return \"object\";\n\treturn \"unknown\";\n}\n\nexport function getSchemaFormat(schema: unknown): string | undefined {\n\tif (!schema || typeof schema !== \"object\") return undefined;\n\tconst f = (schema as { format?: unknown }).format;\n\treturn typeof f === \"string\" ? f : undefined;\n}\n\nexport function getSchemaEnumStrings(schema: unknown): string[] | undefined {\n\tif (!schema || typeof schema !== \"object\") return undefined;\n\tconst e = (schema as { enum?: unknown }).enum;\n\tif (!Array.isArray(e)) return undefined;\n\n\t// We only surface string enums for now (enough for flag docs + completion).\n\tconst values = e.filter((v) => typeof v === \"string\") as string[];\n\treturn values.length ? values : undefined;\n}\n",
9
- "import {\n\tgetSchemaEnumStrings,\n\tgetSchemaFormat,\n\tgetSchemaType,\n} from \"./schema-shape.ts\";\nimport { kebabCase } from \"./strings.ts\";\nimport type { NormalizedOperation, NormalizedParameter } from \"./types.ts\";\n\nexport type ParamType = import(\"./schema-shape.ts\").ParamType;\n\nexport type ParamSpec = {\n\tkind: \"positional\" | \"flag\";\n\tin: NormalizedParameter[\"in\"];\n\tname: string;\n\tflag: string;\n\trequired: boolean;\n\tdescription?: string;\n\ttype: ParamType;\n\tformat?: string;\n\tenum?: string[];\n\n\t// Arrays\n\titemType?: ParamType;\n\titemFormat?: string;\n\titemEnum?: string[];\n\n\t// Original schema for Ajv validation and future advanced flag expansion.\n\tschema?: import(\"./types.ts\").JsonSchema;\n};\n\nexport function deriveParamSpecs(op: NormalizedOperation): ParamSpec[] {\n\tconst out: ParamSpec[] = [];\n\n\tfor (const p of op.parameters) {\n\t\tconst flag = `--${kebabCase(p.name)}`;\n\t\tconst type = getSchemaType(p.schema);\n\t\tconst schemaObj =\n\t\t\tp.schema && typeof p.schema === \"object\"\n\t\t\t\t? (p.schema as import(\"./types.ts\").JsonSchema)\n\t\t\t\t: undefined;\n\n\t\tconst itemsSchema =\n\t\t\tschemaObj && type === \"array\" && typeof schemaObj.items === \"object\"\n\t\t\t\t? (schemaObj.items as unknown)\n\t\t\t\t: undefined;\n\n\t\tout.push({\n\t\t\tkind: p.in === \"path\" ? \"positional\" : \"flag\",\n\t\t\tin: p.in,\n\t\t\tname: p.name,\n\t\t\tflag,\n\t\t\trequired: p.required,\n\t\t\tdescription: p.description,\n\t\t\ttype,\n\t\t\tformat: getSchemaFormat(p.schema),\n\t\t\tenum: getSchemaEnumStrings(p.schema),\n\t\t\titemType: type === \"array\" ? getSchemaType(itemsSchema) : undefined,\n\t\t\titemFormat: type === \"array\" ? getSchemaFormat(itemsSchema) : undefined,\n\t\t\titemEnum:\n\t\t\t\ttype === \"array\" ? getSchemaEnumStrings(itemsSchema) : undefined,\n\t\t\tschema: schemaObj,\n\t\t});\n\t}\n\n\tout.sort((a, b) => {\n\t\tif (a.in !== b.in) return a.in.localeCompare(b.in);\n\t\treturn a.name.localeCompare(b.name);\n\t});\n\n\treturn out;\n}\n",
10
- "import type { ParamSpec } from \"./params.ts\";\n\nexport type ActionShapeForCli = {\n\tpathArgs: string[];\n\tparams: ParamSpec[];\n};\n\nexport type PositionalArg = {\n\tname: string;\n\trequired: boolean;\n\tdescription?: string;\n\ttype: import(\"./schema-shape.ts\").ParamType;\n\tformat?: string;\n\tenum?: string[];\n};\n\nexport type FlagsIndex = {\n\tflags: Array<\n\t\tPick<\n\t\t\timport(\"./params.ts\").ParamSpec,\n\t\t\t| \"in\"\n\t\t\t| \"name\"\n\t\t\t| \"flag\"\n\t\t\t| \"required\"\n\t\t\t| \"description\"\n\t\t\t| \"type\"\n\t\t\t| \"format\"\n\t\t\t| \"enum\"\n\t\t\t| \"itemType\"\n\t\t\t| \"itemFormat\"\n\t\t\t| \"itemEnum\"\n\t\t>\n\t>;\n};\n\nexport function derivePositionals(action: ActionShapeForCli): PositionalArg[] {\n\tconst byName = new Map<string, PositionalArg>();\n\n\t// Use pathArgs order; match metadata from params when available.\n\tfor (const name of action.pathArgs) {\n\t\tconst p = action.params.find(\n\t\t\t(x: ParamSpec) => x.in === \"path\" && x.name === name,\n\t\t);\n\t\tbyName.set(name, {\n\t\t\tname,\n\t\t\trequired: true,\n\t\t\tdescription: p?.description,\n\t\t\ttype: p?.type ?? \"unknown\",\n\t\t\tformat: p?.format,\n\t\t\tenum: p?.enum,\n\t\t});\n\t}\n\n\treturn [...byName.values()];\n}\n\nexport function deriveFlags(action: ActionShapeForCli): FlagsIndex {\n\treturn {\n\t\tflags: action.params\n\t\t\t.filter((p: ParamSpec) => p.kind === \"flag\")\n\t\t\t.map((p: ParamSpec) => ({\n\t\t\t\tin: p.in,\n\t\t\t\tname: p.name,\n\t\t\t\tflag: p.flag,\n\t\t\t\trequired: p.required,\n\t\t\t\tdescription: p.description,\n\t\t\t\ttype: p.type,\n\t\t\t\tformat: p.format,\n\t\t\t\tenum: p.enum,\n\t\t\t\titemType: p.itemType,\n\t\t\t\titemFormat: p.itemFormat,\n\t\t\t\titemEnum: p.itemEnum,\n\t\t\t})),\n\t};\n}\n",
11
- "export type SpecSource = \"embedded\" | \"file\" | \"url\";\n\nexport type SecurityRequirement = Record<string, string[]>;\n\nexport type OpenApiDoc = {\n\topenapi: string;\n\tinfo?: {\n\t\ttitle?: string;\n\t\tversion?: string;\n\t};\n\tservers?: Array<{ url: string; description?: string; variables?: unknown }>;\n\tsecurity?: SecurityRequirement[];\n\tcomponents?: {\n\t\tsecuritySchemes?: Record<string, unknown>;\n\t};\n\tpaths?: Record<string, unknown>;\n};\n\nexport type NormalizedParameter = {\n\tin: \"path\" | \"query\" | \"header\" | \"cookie\";\n\tname: string;\n\trequired: boolean;\n\tdescription?: string;\n\tschema?: unknown;\n};\n\n// Minimal JSON Schema-like shape for validation and flag expansion.\nexport type JsonSchema = Record<string, unknown>;\n\nexport function isJsonSchema(value: unknown): value is JsonSchema {\n\treturn Boolean(value) && typeof value === \"object\" && !Array.isArray(value);\n}\n\nexport type NormalizedRequestBody = {\n\trequired: boolean;\n\tcontentTypes: string[];\n\tschemasByContentType: Record<string, unknown | undefined>;\n};\n\nexport type NormalizedOperation = {\n\tkey: string;\n\tmethod: string;\n\tpath: string;\n\toperationId?: string;\n\ttags: string[];\n\tsummary?: string;\n\tdescription?: string;\n\tdeprecated?: boolean;\n\tsecurity?: SecurityRequirement[];\n\tparameters: NormalizedParameter[];\n\trequestBody?: NormalizedRequestBody;\n};\n\nexport type LoadedSpec = {\n\tsource: SpecSource;\n\tid: string;\n\tfingerprint: string;\n\tdoc: OpenApiDoc;\n};\n",
12
- "import {\n\tgetSchemaEnumStrings,\n\tgetSchemaFormat,\n\tgetSchemaType,\n} from \"./schema-shape.ts\";\nimport type {\n\tJsonSchema,\n\tNormalizedOperation,\n\tNormalizedRequestBody,\n} from \"./types.ts\";\nimport { isJsonSchema } from \"./types.ts\";\n\nexport type RequestBodyContent = {\n\tcontentType: string;\n\trequired: boolean;\n\tschemaType: import(\"./schema-shape.ts\").ParamType;\n\tschemaFormat?: string;\n\tschemaEnum?: string[];\n};\n\nexport type RequestBodyInfo = {\n\trequired: boolean;\n\tcontent: RequestBodyContent[];\n\t// Convenience flags for later arg generation.\n\thasJson: boolean;\n\thasFormUrlEncoded: boolean;\n\thasMultipart: boolean;\n\n\t// Phase 1 planning: supported generic body inputs.\n\tbodyFlags: string[];\n\tpreferredContentType?: string;\n\n\t// Original JSON Schema (for expanded flags + validation)\n\tpreferredSchema?: JsonSchema;\n};\n\nfunction getRequestBody(\n\top: NormalizedOperation,\n): NormalizedRequestBody | undefined {\n\treturn op.requestBody;\n}\n\nexport function deriveRequestBodyInfo(\n\top: NormalizedOperation,\n): RequestBodyInfo | undefined {\n\tconst rb = getRequestBody(op);\n\tif (!rb) return undefined;\n\n\tconst content: RequestBodyContent[] = [];\n\tfor (const contentType of rb.contentTypes) {\n\t\tconst schema = rb.schemasByContentType[contentType];\n\t\tcontent.push({\n\t\t\tcontentType,\n\t\t\trequired: rb.required,\n\t\t\tschemaType: getSchemaType(schema),\n\t\t\tschemaFormat: getSchemaFormat(schema),\n\t\t\tschemaEnum: getSchemaEnumStrings(schema),\n\t\t});\n\t}\n\n\tcontent.sort((a, b) => a.contentType.localeCompare(b.contentType));\n\n\tconst hasJson = content.some((c) => c.contentType.includes(\"json\"));\n\tconst hasFormUrlEncoded = content.some(\n\t\t(c) => c.contentType === \"application/x-www-form-urlencoded\",\n\t);\n\tconst hasMultipart = content.some((c) =>\n\t\tc.contentType.startsWith(\"multipart/\"),\n\t);\n\n\tconst bodyFlags = [\"--data\", \"--file\"]; // always available when requestBody exists\n\n\tconst preferredContentType =\n\t\tcontent.find((c) => c.contentType === \"application/json\")?.contentType ??\n\t\tcontent.find((c) => c.contentType.includes(\"json\"))?.contentType ??\n\t\tcontent[0]?.contentType;\n\n\tconst preferredSchema = preferredContentType\n\t\t? rb.schemasByContentType[preferredContentType]\n\t\t: undefined;\n\n\treturn {\n\t\trequired: rb.required,\n\t\tcontent,\n\t\thasJson,\n\t\thasFormUrlEncoded,\n\t\thasMultipart,\n\t\tbodyFlags,\n\t\tpreferredContentType,\n\t\tpreferredSchema: isJsonSchema(preferredSchema)\n\t\t\t? preferredSchema\n\t\t\t: undefined,\n\t};\n}\n",
13
- "import type { AuthSummary } from \"./auth-requirements.ts\";\nimport { summarizeAuth } from \"./auth-requirements.ts\";\nimport type { AuthScheme } from \"./auth-schemes.ts\";\nimport { buildCommandId } from \"./command-id.ts\";\nimport type { PlannedOperation } from \"./naming.ts\";\nimport type { ParamSpec } from \"./params.ts\";\nimport { deriveParamSpecs } from \"./params.ts\";\nimport { deriveFlags, derivePositionals } from \"./positional.ts\";\nimport type { RequestBodyInfo } from \"./request-body.ts\";\nimport { deriveRequestBodyInfo } from \"./request-body.ts\";\nimport type { SecurityRequirement } from \"./types.ts\";\n\nexport type CommandAction = {\n\tid: string;\n\tkey: string;\n\taction: string;\n\t// Derived path arguments. These become positionals later.\n\tpathArgs: string[];\n\tmethod: string;\n\tpath: string;\n\toperationId?: string;\n\ttags: string[];\n\tsummary?: string;\n\tdescription?: string;\n\tdeprecated?: boolean;\n\tstyle: PlannedOperation[\"style\"];\n\n\t// Derived CLI shape (Phase 1 output; Phase 2 will wire these into commander)\n\tpositionals: Array<import(\"./positional.ts\").PositionalArg>;\n\tflags: Array<\n\t\tPick<\n\t\t\timport(\"./params.ts\").ParamSpec,\n\t\t\t| \"in\"\n\t\t\t| \"name\"\n\t\t\t| \"flag\"\n\t\t\t| \"required\"\n\t\t\t| \"description\"\n\t\t\t| \"type\"\n\t\t\t| \"format\"\n\t\t\t| \"enum\"\n\t\t\t| \"itemType\"\n\t\t\t| \"itemFormat\"\n\t\t\t| \"itemEnum\"\n\t\t>\n\t>;\n\n\t// Full raw params list (useful for debugging and future features)\n\tparams: ParamSpec[];\n\n\tauth: AuthSummary;\n\trequestBody?: RequestBodyInfo;\n\trequestBodySchema?: import(\"./types.ts\").JsonSchema;\n};\n\nexport type CommandResource = {\n\tresource: string;\n\tactions: CommandAction[];\n};\n\nexport type CommandModel = {\n\tresources: CommandResource[];\n};\n\nexport type BuildCommandModelOptions = {\n\tspecId: string;\n\tglobalSecurity?: SecurityRequirement[];\n\tauthSchemes?: AuthScheme[];\n};\n\nexport function buildCommandModel(\n\tplanned: PlannedOperation[],\n\toptions: BuildCommandModelOptions,\n): CommandModel {\n\tconst byResource = new Map<string, CommandAction[]>();\n\n\tfor (const op of planned) {\n\t\tconst list = byResource.get(op.resource) ?? [];\n\t\tconst params = deriveParamSpecs(op);\n\t\tconst positionals = derivePositionals({ pathArgs: op.pathArgs, params });\n\t\tconst flags = deriveFlags({ pathArgs: op.pathArgs, params });\n\n\t\tlist.push({\n\t\t\tid: buildCommandId({\n\t\t\t\tspecId: options.specId,\n\t\t\t\tresource: op.resource,\n\t\t\t\taction: op.action,\n\t\t\t\toperationKey: op.key,\n\t\t\t}),\n\t\t\tkey: op.key,\n\t\t\taction: op.action,\n\t\t\tpathArgs: op.pathArgs,\n\t\t\tmethod: op.method,\n\t\t\tpath: op.path,\n\t\t\toperationId: op.operationId,\n\t\t\ttags: op.tags,\n\t\t\tsummary: op.summary,\n\t\t\tdescription: op.description,\n\t\t\tdeprecated: op.deprecated,\n\t\t\tstyle: op.style,\n\t\t\tparams,\n\t\t\tpositionals,\n\t\t\tflags: flags.flags,\n\t\t\tauth: summarizeAuth(\n\t\t\t\top.security,\n\t\t\t\toptions.globalSecurity,\n\t\t\t\toptions.authSchemes ?? [],\n\t\t\t),\n\t\t\trequestBody: deriveRequestBodyInfo(op),\n\t\t\trequestBodySchema: deriveRequestBodyInfo(op)?.preferredSchema,\n\t\t});\n\t\tbyResource.set(op.resource, list);\n\t}\n\n\tconst resources: CommandResource[] = [];\n\n\tfor (const [resource, actions] of byResource.entries()) {\n\t\tactions.sort((a, b) => {\n\t\t\tif (a.action !== b.action) return a.action.localeCompare(b.action);\n\t\t\tif (a.path !== b.path) return a.path.localeCompare(b.path);\n\t\t\treturn a.method.localeCompare(b.method);\n\t\t});\n\t\tresources.push({ resource, actions });\n\t}\n\n\tresources.sort((a, b) => a.resource.localeCompare(b.resource));\n\n\treturn { resources };\n}\n"
14
- ],
15
- "mappings": ";AAaA,SAAS,qBAAqB,CAAC,OAA8C;AAAA,EAC5E,IAAI,CAAC,SAAS,OAAO,UAAU;AAAA,IAAU,OAAO;AAAA,EAChD,IAAI,MAAM,QAAQ,KAAK;AAAA,IAAG,OAAO;AAAA,EAEjC,YAAY,GAAG,MAAM,OAAO,QAAQ,KAAK,GAAG;AAAA,IAC3C,IAAI,OAAO,MAAM;AAAA,MAAU,OAAO;AAAA,IAClC,IAAI,CAAC,MAAM,QAAQ,CAAC;AAAA,MAAG,OAAO;AAAA,IAC9B,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,OAAO,MAAM,QAAQ;AAAA,MAAG,OAAO;AAAA,EACpD;AAAA,EAEA,OAAO;AAAA;AAGR,SAAS,iBAAiB,CAAC,OAGzB;AAAA,EACD,IAAI,SAAS;AAAA,IAAM,OAAO,EAAE,cAAc,CAAC,GAAG,QAAQ,OAAO;AAAA,EAC7D,IAAI,CAAC,MAAM,QAAQ,KAAK;AAAA,IAAG,OAAO,EAAE,cAAc,CAAC,GAAG,QAAQ,OAAO;AAAA,EAErE,MAAM,OAAO,MAAM,OAAO,qBAAqB;AAAA,EAC/C,IAAI,KAAK,WAAW;AAAA,IAAG,OAAO,EAAE,cAAc,CAAC,GAAG,QAAQ,QAAQ;AAAA,EAClE,OAAO,EAAE,cAAc,MAAM,QAAQ,YAAY;AAAA;AAG3C,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@ -1 +0,0 @@
1
- {"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../../../src/cli/compile.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,cAAc,GAAG;IAC5B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IACrB,IAAI,CAAC,EAAE,MAAM,CAAC;CACd,CAAC;AAYF,wBAAsB,cAAc,CACnC,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,cAAc,GACrB,OAAO,CAAC,IAAI,CAAC,CAuEf"}
@@ -1,146 +0,0 @@
1
- // src/cli/derive-name.ts
2
- var RESERVED_NAMES = [
3
- "exec",
4
- "compile",
5
- "profile",
6
- "auth",
7
- "help",
8
- "version"
9
- ];
10
- async function deriveBinaryName(spec) {
11
- try {
12
- const text = await loadSpecText(spec);
13
- const doc = parseSpec(text);
14
- const title = doc?.info?.title;
15
- if (title && typeof title === "string") {
16
- const name = sanitizeName(title);
17
- if (name)
18
- return name;
19
- }
20
- } catch {}
21
- if (/^https?:\/\//i.test(spec)) {
22
- try {
23
- const url = new URL(spec);
24
- const hostParts = url.hostname.split(".");
25
- const meaningful = hostParts.find((p) => p !== "www" && p !== "api" && p.length > 2);
26
- if (meaningful) {
27
- const name = sanitizeName(meaningful);
28
- if (name)
29
- return name;
30
- }
31
- } catch {}
32
- }
33
- return "specli";
34
- }
35
- async function loadSpecText(spec) {
36
- if (/^https?:\/\//i.test(spec)) {
37
- const res = await fetch(spec);
38
- if (!res.ok)
39
- throw new Error(`Failed to fetch: ${res.status}`);
40
- return res.text();
41
- }
42
- return Bun.file(spec).text();
43
- }
44
- function parseSpec(text) {
45
- try {
46
- const trimmed = text.trimStart();
47
- if (trimmed.startsWith("{") || trimmed.startsWith("[")) {
48
- return JSON.parse(text);
49
- }
50
- const { YAML } = globalThis.Bun ?? {};
51
- if (YAML?.parse) {
52
- return YAML.parse(text);
53
- }
54
- return null;
55
- } catch {
56
- return null;
57
- }
58
- }
59
- function sanitizeName(input) {
60
- let name = input.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 32);
61
- if (RESERVED_NAMES.includes(name)) {
62
- name = `${name}-cli`;
63
- }
64
- return name;
65
- }
66
-
67
- // src/cli/compile.ts
68
- function parseKeyValue(input) {
69
- const idx = input.indexOf("=");
70
- if (idx === -1)
71
- throw new Error(`Invalid --define '${input}', expected key=value`);
72
- const key = input.slice(0, idx).trim();
73
- const value = input.slice(idx + 1).trim();
74
- if (!key)
75
- throw new Error(`Invalid --define '${input}', missing key`);
76
- return { key, value };
77
- }
78
- async function compileCommand(spec, options) {
79
- const name = options.name ?? await deriveBinaryName(spec);
80
- const outfile = options.outfile ?? `./dist/${name}`;
81
- const target = options.target ? options.target : `bun-${process.platform}-${process.arch}`;
82
- const define = {};
83
- if (options.define) {
84
- for (const pair of options.define) {
85
- const { key, value } = parseKeyValue(pair);
86
- define[key] = JSON.stringify(value);
87
- }
88
- }
89
- const buildArgs = [
90
- "build",
91
- "--compile",
92
- `--outfile=${outfile}`,
93
- `--target=${target}`
94
- ];
95
- if (options.minify)
96
- buildArgs.push("--minify");
97
- if (options.bytecode)
98
- buildArgs.push("--bytecode");
99
- for (const [k, v] of Object.entries(define)) {
100
- buildArgs.push("--define", `${k}=${v}`);
101
- }
102
- if (options.dotenv === false)
103
- buildArgs.push("--no-compile-autoload-dotenv");
104
- if (options.bunfig === false)
105
- buildArgs.push("--no-compile-autoload-bunfig");
106
- buildArgs.push("./src/compiled.ts");
107
- const buildEnv = {
108
- ...process.env,
109
- SPECLI_SPEC: spec,
110
- SPECLI_NAME: name
111
- };
112
- if (options.server)
113
- buildEnv.SPECLI_SERVER = options.server;
114
- if (options.serverVar?.length)
115
- buildEnv.SPECLI_SERVER_VARS = options.serverVar.join(",");
116
- if (options.auth)
117
- buildEnv.SPECLI_AUTH = options.auth;
118
- const proc = Bun.spawn({
119
- cmd: ["bun", ...buildArgs],
120
- stdout: "pipe",
121
- stderr: "pipe",
122
- env: buildEnv
123
- });
124
- const output = await new Response(proc.stdout).text();
125
- const error = await new Response(proc.stderr).text();
126
- const code = await proc.exited;
127
- if (output)
128
- process.stdout.write(output);
129
- if (error)
130
- process.stderr.write(error);
131
- if (code !== 0) {
132
- process.exitCode = code;
133
- return;
134
- }
135
- process.stdout.write(`ok: built ${outfile}
136
- `);
137
- process.stdout.write(`target: ${target}
138
- `);
139
- process.stdout.write(`name: ${name}
140
- `);
141
- }
142
- export {
143
- compileCommand
144
- };
145
-
146
- //# debugId=5EE8B1A40E17B63264756E2164756E21