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,128 +0,0 @@
1
- import type { AuthSummary } from "./auth-requirements.ts";
2
- import { summarizeAuth } from "./auth-requirements.ts";
3
- import type { AuthScheme } from "./auth-schemes.ts";
4
- import { buildCommandId } from "./command-id.ts";
5
- import type { PlannedOperation } from "./naming.ts";
6
- import type { ParamSpec } from "./params.ts";
7
- import { deriveParamSpecs } from "./params.ts";
8
- import { deriveFlags, derivePositionals } from "./positional.ts";
9
- import type { RequestBodyInfo } from "./request-body.ts";
10
- import { deriveRequestBodyInfo } from "./request-body.ts";
11
- import type { SecurityRequirement } from "./types.ts";
12
-
13
- export type CommandAction = {
14
- id: string;
15
- key: string;
16
- action: string;
17
- // Derived path arguments. These become positionals later.
18
- pathArgs: string[];
19
- method: string;
20
- path: string;
21
- operationId?: string;
22
- tags: string[];
23
- summary?: string;
24
- description?: string;
25
- deprecated?: boolean;
26
- style: PlannedOperation["style"];
27
-
28
- // Derived CLI shape (Phase 1 output; Phase 2 will wire these into commander)
29
- positionals: Array<import("./positional.ts").PositionalArg>;
30
- flags: Array<
31
- Pick<
32
- import("./params.ts").ParamSpec,
33
- | "in"
34
- | "name"
35
- | "flag"
36
- | "required"
37
- | "description"
38
- | "type"
39
- | "format"
40
- | "enum"
41
- | "itemType"
42
- | "itemFormat"
43
- | "itemEnum"
44
- >
45
- >;
46
-
47
- // Full raw params list (useful for debugging and future features)
48
- params: ParamSpec[];
49
-
50
- auth: AuthSummary;
51
- requestBody?: RequestBodyInfo;
52
- requestBodySchema?: import("./types.ts").JsonSchema;
53
- };
54
-
55
- export type CommandResource = {
56
- resource: string;
57
- actions: CommandAction[];
58
- };
59
-
60
- export type CommandModel = {
61
- resources: CommandResource[];
62
- };
63
-
64
- export type BuildCommandModelOptions = {
65
- specId: string;
66
- globalSecurity?: SecurityRequirement[];
67
- authSchemes?: AuthScheme[];
68
- };
69
-
70
- export function buildCommandModel(
71
- planned: PlannedOperation[],
72
- options: BuildCommandModelOptions,
73
- ): CommandModel {
74
- const byResource = new Map<string, CommandAction[]>();
75
-
76
- for (const op of planned) {
77
- const list = byResource.get(op.resource) ?? [];
78
- const params = deriveParamSpecs(op);
79
- const positionals = derivePositionals({ pathArgs: op.pathArgs, params });
80
- const flags = deriveFlags({ pathArgs: op.pathArgs, params });
81
-
82
- list.push({
83
- id: buildCommandId({
84
- specId: options.specId,
85
- resource: op.resource,
86
- action: op.action,
87
- operationKey: op.key,
88
- }),
89
- key: op.key,
90
- action: op.action,
91
- pathArgs: op.pathArgs,
92
- method: op.method,
93
- path: op.path,
94
- operationId: op.operationId,
95
- tags: op.tags,
96
- summary: op.summary,
97
- description: op.description,
98
- deprecated: op.deprecated,
99
- style: op.style,
100
- params,
101
- positionals,
102
- flags: flags.flags,
103
- auth: summarizeAuth(
104
- op.security,
105
- options.globalSecurity,
106
- options.authSchemes ?? [],
107
- ),
108
- requestBody: deriveRequestBodyInfo(op),
109
- requestBodySchema: deriveRequestBodyInfo(op)?.preferredSchema,
110
- });
111
- byResource.set(op.resource, list);
112
- }
113
-
114
- const resources: CommandResource[] = [];
115
-
116
- for (const [resource, actions] of byResource.entries()) {
117
- actions.sort((a, b) => {
118
- if (a.action !== b.action) return a.action.localeCompare(b.action);
119
- if (a.path !== b.path) return a.path.localeCompare(b.path);
120
- return a.method.localeCompare(b.method);
121
- });
122
- resources.push({ resource, actions });
123
- }
124
-
125
- resources.sort((a, b) => a.resource.localeCompare(b.resource));
126
-
127
- return { resources };
128
- }
@@ -1,101 +0,0 @@
1
- import { deriveBinaryName } from "./derive-name.ts";
2
-
3
- export type CompileOptions = {
4
- name?: string;
5
- outfile?: string;
6
- target?: string;
7
- minify?: boolean;
8
- bytecode?: boolean;
9
- dotenv?: boolean; // --no-dotenv sets this to false
10
- bunfig?: boolean; // --no-bunfig sets this to false
11
- define?: string[];
12
- server?: string;
13
- serverVar?: string[];
14
- auth?: string;
15
- };
16
-
17
- function parseKeyValue(input: string): { key: string; value: string } {
18
- const idx = input.indexOf("=");
19
- if (idx === -1)
20
- throw new Error(`Invalid --define '${input}', expected key=value`);
21
- const key = input.slice(0, idx).trim();
22
- const value = input.slice(idx + 1).trim();
23
- if (!key) throw new Error(`Invalid --define '${input}', missing key`);
24
- return { key, value };
25
- }
26
-
27
- export async function compileCommand(
28
- spec: string,
29
- options: CompileOptions,
30
- ): Promise<void> {
31
- // Derive name from spec if not provided
32
- const name = options.name ?? (await deriveBinaryName(spec));
33
- const outfile = options.outfile ?? `./dist/${name}`;
34
-
35
- const target = options.target
36
- ? (options.target as Bun.Build.Target)
37
- : (`bun-${process.platform}-${process.arch}` as Bun.Build.Target);
38
-
39
- // Parse --define pairs
40
- const define: Record<string, string> = {};
41
- if (options.define) {
42
- for (const pair of options.define) {
43
- const { key, value } = parseKeyValue(pair);
44
- define[key] = JSON.stringify(value);
45
- }
46
- }
47
-
48
- // Build command args
49
- const buildArgs = [
50
- "build",
51
- "--compile",
52
- `--outfile=${outfile}`,
53
- `--target=${target}`,
54
- ];
55
-
56
- if (options.minify) buildArgs.push("--minify");
57
- if (options.bytecode) buildArgs.push("--bytecode");
58
-
59
- for (const [k, v] of Object.entries(define)) {
60
- buildArgs.push("--define", `${k}=${v}`);
61
- }
62
-
63
- if (options.dotenv === false) buildArgs.push("--no-compile-autoload-dotenv");
64
- if (options.bunfig === false) buildArgs.push("--no-compile-autoload-bunfig");
65
-
66
- buildArgs.push("./src/compiled.ts");
67
-
68
- // Only set env vars that have actual values - avoid empty strings
69
- // because the macros will embed them and they will override defaults.
70
- const buildEnv: Record<string, string> = {
71
- ...process.env,
72
- SPECLI_SPEC: spec,
73
- SPECLI_NAME: name,
74
- };
75
- if (options.server) buildEnv.SPECLI_SERVER = options.server;
76
- if (options.serverVar?.length)
77
- buildEnv.SPECLI_SERVER_VARS = options.serverVar.join(",");
78
- if (options.auth) buildEnv.SPECLI_AUTH = options.auth;
79
-
80
- const proc = Bun.spawn({
81
- cmd: ["bun", ...buildArgs],
82
- stdout: "pipe",
83
- stderr: "pipe",
84
- env: buildEnv,
85
- });
86
-
87
- const output = await new Response(proc.stdout).text();
88
- const error = await new Response(proc.stderr).text();
89
- const code = await proc.exited;
90
-
91
- if (output) process.stdout.write(output);
92
- if (error) process.stderr.write(error);
93
- if (code !== 0) {
94
- process.exitCode = code;
95
- return;
96
- }
97
-
98
- process.stdout.write(`ok: built ${outfile}\n`);
99
- process.stdout.write(`target: ${target}\n`);
100
- process.stdout.write(`name: ${name}\n`);
101
- }
package/src/cli/crypto.ts DELETED
@@ -1,9 +0,0 @@
1
- export async function sha256Hex(text: string): Promise<string> {
2
- const data = new TextEncoder().encode(text);
3
- const hash = await crypto.subtle.digest("SHA-256", data);
4
- const bytes = new Uint8Array(hash);
5
-
6
- let out = "";
7
- for (const b of bytes) out += b.toString(16).padStart(2, "0");
8
- return out;
9
- }
@@ -1,101 +0,0 @@
1
- const RESERVED_NAMES = [
2
- "exec",
3
- "compile",
4
- "profile",
5
- "auth",
6
- "help",
7
- "version",
8
- ];
9
-
10
- /**
11
- * Derives a clean binary name from an OpenAPI spec.
12
- * Priority:
13
- * 1. info.title (kebab-cased, sanitized)
14
- * 2. Host from spec URL (if URL provided)
15
- * 3. Fallback to "specli"
16
- */
17
- export async function deriveBinaryName(spec: string): Promise<string> {
18
- try {
19
- // Load spec to extract title
20
- const text = await loadSpecText(spec);
21
- const doc = parseSpec(text);
22
-
23
- const title = doc?.info?.title;
24
- if (title && typeof title === "string") {
25
- const name = sanitizeName(title);
26
- if (name) return name;
27
- }
28
- } catch {
29
- // Fall through to URL-based derivation
30
- }
31
-
32
- // Try to derive from URL host
33
- if (/^https?:\/\//i.test(spec)) {
34
- try {
35
- const url = new URL(spec);
36
- const hostParts = url.hostname.split(".");
37
- // Use first meaningful segment (skip www, api prefixes)
38
- const meaningful = hostParts.find(
39
- (p) => p !== "www" && p !== "api" && p.length > 2,
40
- );
41
- if (meaningful) {
42
- const name = sanitizeName(meaningful);
43
- if (name) return name;
44
- }
45
- } catch {
46
- // Invalid URL, fall through
47
- }
48
- }
49
-
50
- // Fallback
51
- return "specli";
52
- }
53
-
54
- async function loadSpecText(spec: string): Promise<string> {
55
- if (/^https?:\/\//i.test(spec)) {
56
- const res = await fetch(spec);
57
- if (!res.ok) throw new Error(`Failed to fetch: ${res.status}`);
58
- return res.text();
59
- }
60
- return Bun.file(spec).text();
61
- }
62
-
63
- function parseSpec(text: string): { info?: { title?: string } } | null {
64
- try {
65
- const trimmed = text.trimStart();
66
- if (trimmed.startsWith("{") || trimmed.startsWith("[")) {
67
- return JSON.parse(text);
68
- }
69
- // Use Bun's YAML parser
70
- const { YAML } = globalThis.Bun ?? {};
71
- if (YAML?.parse) {
72
- return YAML.parse(text) as { info?: { title?: string } };
73
- }
74
- // Fallback: only JSON supported
75
- return null;
76
- } catch {
77
- return null;
78
- }
79
- }
80
-
81
- /**
82
- * Convert title to valid binary name:
83
- * - kebab-case
84
- * - lowercase
85
- * - remove invalid chars
86
- * - max 32 chars
87
- * - avoid reserved names
88
- */
89
- function sanitizeName(input: string): string {
90
- let name = input
91
- .toLowerCase()
92
- .replace(/[^a-z0-9]+/g, "-") // Replace non-alphanumeric with dash
93
- .replace(/^-+|-+$/g, "") // Trim leading/trailing dashes
94
- .slice(0, 32); // Limit length
95
-
96
- if (RESERVED_NAMES.includes(name)) {
97
- name = `${name}-cli`;
98
- }
99
-
100
- return name;
101
- }
package/src/cli/exec.ts DELETED
@@ -1,72 +0,0 @@
1
- import { main } from "./main.ts";
2
-
3
- export type ExecOptions = {
4
- server?: string;
5
- serverVar?: string[];
6
- auth?: string;
7
- bearerToken?: string;
8
- oauthToken?: string;
9
- username?: string;
10
- password?: string;
11
- apiKey?: string;
12
- profile?: string;
13
- json?: boolean;
14
- };
15
-
16
- export async function execCommand(
17
- spec: string,
18
- options: ExecOptions,
19
- commandArgs: string[],
20
- ): Promise<void> {
21
- // commandArgs includes the spec as first element, filter it out
22
- // to get the remaining args (resource, action, etc.)
23
- const remainingArgs = commandArgs.slice(1);
24
-
25
- // Reconstruct argv for main():
26
- // [node, script, --spec, <spec>, ...options, ...remainingArgs]
27
- const argv = [
28
- process.argv[0] ?? "bun",
29
- process.argv[1] ?? "specli",
30
- "--spec",
31
- spec,
32
- ];
33
-
34
- // Add common options back as flags
35
- if (options.server) {
36
- argv.push("--server", options.server);
37
- }
38
- if (options.serverVar) {
39
- for (const v of options.serverVar) {
40
- argv.push("--server-var", v);
41
- }
42
- }
43
- if (options.auth) {
44
- argv.push("--auth", options.auth);
45
- }
46
- if (options.bearerToken) {
47
- argv.push("--bearer-token", options.bearerToken);
48
- }
49
- if (options.oauthToken) {
50
- argv.push("--oauth-token", options.oauthToken);
51
- }
52
- if (options.username) {
53
- argv.push("--username", options.username);
54
- }
55
- if (options.password) {
56
- argv.push("--password", options.password);
57
- }
58
- if (options.apiKey) {
59
- argv.push("--api-key", options.apiKey);
60
- }
61
- if (options.profile) {
62
- argv.push("--profile", options.profile);
63
- }
64
- if (options.json) {
65
- argv.push("--json");
66
- }
67
-
68
- // Append remaining args (subcommand + its args)
69
- argv.push(...remainingArgs);
70
-
71
- await main(argv);
72
- }
package/src/cli/main.ts DELETED
@@ -1,231 +0,0 @@
1
- import { Command } from "commander";
2
-
3
- import { getArgValue, hasAnyArg } from "./runtime/argv.ts";
4
- import { collectRepeatable } from "./runtime/collect.ts";
5
- import { readStdinText } from "./runtime/compat.ts";
6
- import { buildRuntimeContext } from "./runtime/context.ts";
7
- import { addGeneratedCommands } from "./runtime/generated.ts";
8
- import { deleteToken, getToken, setToken } from "./runtime/profile/secrets.ts";
9
- import {
10
- readProfiles,
11
- upsertProfile,
12
- writeProfiles,
13
- } from "./runtime/profile/store.ts";
14
- import { toMinimalSchemaOutput } from "./schema.ts";
15
- import { stableStringify } from "./stable-json.ts";
16
-
17
- type MainOptions = {
18
- embeddedSpecText?: string;
19
- cliName?: string;
20
- server?: string;
21
- serverVars?: string[];
22
- auth?: string;
23
- };
24
-
25
- export async function main(argv: string[], options: MainOptions = {}) {
26
- const program = new Command();
27
-
28
- program
29
- .name(options.cliName ?? "specli")
30
- .description("Generate a CLI from an OpenAPI spec")
31
- .option("--spec <urlOrPath>", "OpenAPI URL or file path")
32
- .option("--server <url>", "Override server/base URL")
33
- .option(
34
- "--server-var <name=value>",
35
- "Server URL template variable (repeatable)",
36
- collectRepeatable,
37
- )
38
- .option("--auth <scheme>", "Select auth scheme by key")
39
- .option("--bearer-token <token>", "Bearer token (Authorization: Bearer)")
40
- .option("--oauth-token <token>", "OAuth token (alias of bearer)")
41
- .option("--username <username>", "Basic auth username")
42
- .option("--password <password>", "Basic auth password")
43
- .option("--api-key <key>", "API key value")
44
- .option("--json", "Machine-readable output")
45
- .showHelpAfterError();
46
-
47
- // If user asks for help and we have no embedded spec and no --spec, show minimal help.
48
- const spec = getArgValue(argv, "--spec");
49
- const wantsHelp = hasAnyArg(argv, ["-h", "--help"]);
50
- if (!spec && !options.embeddedSpecText && wantsHelp) {
51
- program.addHelpText(
52
- "after",
53
- "\nTo see generated commands, run with --spec <url|path>.\n",
54
- );
55
- program.parse(argv);
56
- return;
57
- }
58
-
59
- const ctx = await buildRuntimeContext({
60
- spec,
61
- embeddedSpecText: options.embeddedSpecText,
62
- });
63
-
64
- // Simple auth commands
65
- const defaultProfileName = "default";
66
-
67
- program
68
- .command("login [token]")
69
- .description("Store a bearer token for authentication")
70
- .action(async (tokenArg: string | undefined, _opts, command) => {
71
- const globals = command.optsWithGlobals() as { json?: boolean };
72
-
73
- let token = tokenArg;
74
-
75
- // If no token argument, try to read from stdin (for piping)
76
- if (!token) {
77
- const isTTY = process.stdin.isTTY;
78
- if (isTTY) {
79
- // Interactive mode - prompt user
80
- process.stdout.write("Enter token: ");
81
- const reader = process.stdin;
82
- const chunks: Buffer[] = [];
83
- for await (const chunk of reader) {
84
- chunks.push(chunk);
85
- // Read one line only
86
- if (chunk.includes(10)) break; // newline
87
- }
88
- token = Buffer.concat(chunks).toString().trim();
89
- } else {
90
- // Piped input - use cross-runtime stdin reading
91
- const text = await readStdinText();
92
- token = text.trim();
93
- }
94
- }
95
-
96
- if (!token) {
97
- throw new Error(
98
- "No token provided. Usage: login <token> or echo $TOKEN | login",
99
- );
100
- }
101
-
102
- // Ensure default profile exists
103
- const file = await readProfiles();
104
- if (!file.profiles.find((p) => p.name === defaultProfileName)) {
105
- const updated = upsertProfile(file, { name: defaultProfileName });
106
- await writeProfiles({ ...updated, defaultProfile: defaultProfileName });
107
- } else if (!file.defaultProfile) {
108
- await writeProfiles({ ...file, defaultProfile: defaultProfileName });
109
- }
110
-
111
- await setToken(ctx.loaded.id, defaultProfileName, token);
112
-
113
- if (globals.json) {
114
- process.stdout.write(`${JSON.stringify({ ok: true })}\n`);
115
- return;
116
- }
117
- process.stdout.write("ok: logged in\n");
118
- });
119
-
120
- program
121
- .command("logout")
122
- .description("Clear stored authentication token")
123
- .action(async (_opts, command) => {
124
- const globals = command.optsWithGlobals() as { json?: boolean };
125
-
126
- const deleted = await deleteToken(ctx.loaded.id, defaultProfileName);
127
-
128
- if (globals.json) {
129
- process.stdout.write(`${JSON.stringify({ ok: deleted })}\n`);
130
- return;
131
- }
132
- process.stdout.write(
133
- deleted ? "ok: logged out\n" : "ok: not logged in\n",
134
- );
135
- });
136
-
137
- program
138
- .command("whoami")
139
- .description("Show current authentication status")
140
- .action(async (_opts, command) => {
141
- const globals = command.optsWithGlobals() as { json?: boolean };
142
-
143
- const token = await getToken(ctx.loaded.id, defaultProfileName);
144
- const hasToken = Boolean(token);
145
-
146
- // Mask the token for display (show first 8 and last 4 chars)
147
- let maskedToken: string | null = null;
148
- if (token && token.length > 16) {
149
- maskedToken = `${token.slice(0, 8)}...${token.slice(-4)}`;
150
- } else if (token) {
151
- maskedToken = `${token.slice(0, 4)}...`;
152
- }
153
-
154
- if (globals.json) {
155
- process.stdout.write(
156
- `${JSON.stringify({ authenticated: hasToken, token: maskedToken })}\n`,
157
- );
158
- return;
159
- }
160
-
161
- if (hasToken) {
162
- process.stdout.write(`authenticated: yes\n`);
163
- process.stdout.write(`token: ${maskedToken}\n`);
164
- } else {
165
- process.stdout.write(`authenticated: no\n`);
166
- process.stdout.write(`Run 'login <token>' to authenticate.\n`);
167
- }
168
- });
169
-
170
- program
171
- .command("__schema")
172
- .description("Print indexed operations (machine-readable when --json)")
173
- .option("--pretty", "Pretty-print JSON when used with --json")
174
- .option("--min", "Minimal JSON output (commands + metadata only)")
175
- .action(async (_opts, command) => {
176
- const flags = command.optsWithGlobals() as {
177
- json?: boolean;
178
- pretty?: boolean;
179
- min?: boolean;
180
- };
181
-
182
- if (flags.json) {
183
- const pretty = Boolean(flags.pretty);
184
- const payload = flags.min
185
- ? toMinimalSchemaOutput(ctx.schema)
186
- : ctx.schema;
187
- const text = stableStringify(payload, { space: pretty ? 2 : 0 });
188
- process.stdout.write(`${text}\n`);
189
- return;
190
- }
191
-
192
- process.stdout.write(`${ctx.schema.openapi.title ?? "(untitled)"}\n`);
193
- process.stdout.write(`OpenAPI: ${ctx.schema.openapi.version}\n`);
194
- process.stdout.write(
195
- `Spec: ${ctx.schema.spec.id} (${ctx.schema.spec.source})\n`,
196
- );
197
- process.stdout.write(`Fingerprint: ${ctx.schema.spec.fingerprint}\n`);
198
- process.stdout.write(`Servers: ${ctx.schema.servers.length}\n`);
199
- process.stdout.write(`Auth Schemes: ${ctx.schema.authSchemes.length}\n`);
200
- process.stdout.write(`Operations: ${ctx.schema.operations.length}\n`);
201
-
202
- for (const op of ctx.schema.operations) {
203
- const id = op.operationId ? ` (${op.operationId})` : "";
204
- process.stdout.write(`- ${op.method} ${op.path}${id}\n`);
205
- }
206
-
207
- if (ctx.schema.planned?.length) {
208
- process.stdout.write("\nPlanned commands:\n");
209
- for (const op of ctx.schema.planned) {
210
- const args = op.pathArgs.length
211
- ? ` ${op.pathArgs.map((a) => `<${a}>`).join(" ")}`
212
- : "";
213
- process.stdout.write(`- specli ${op.resource} ${op.action}${args}\n`);
214
- }
215
- }
216
- });
217
-
218
- addGeneratedCommands(program, {
219
- servers: ctx.servers,
220
- authSchemes: ctx.authSchemes,
221
- commands: ctx.commands,
222
- specId: ctx.loaded.id,
223
- embeddedDefaults: {
224
- server: options.server,
225
- serverVars: options.serverVars,
226
- auth: options.auth,
227
- },
228
- });
229
-
230
- await program.parseAsync(argv);
231
- }