@c9up/ream 0.1.25 → 0.1.27

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 (302) hide show
  1. package/README.md +65 -0
  2. package/dist/ConfigLoader.d.ts +46 -5
  3. package/dist/ConfigLoader.d.ts.map +1 -1
  4. package/dist/ConfigLoader.js +60 -9
  5. package/dist/ConfigLoader.js.map +1 -1
  6. package/dist/HttpKernel.d.ts.map +1 -1
  7. package/dist/HttpKernel.js +46 -6
  8. package/dist/HttpKernel.js.map +1 -1
  9. package/dist/Ignitor.d.ts +115 -7
  10. package/dist/Ignitor.d.ts.map +1 -1
  11. package/dist/Ignitor.js +254 -40
  12. package/dist/Ignitor.js.map +1 -1
  13. package/dist/console/BaseCommand.d.ts +217 -0
  14. package/dist/console/BaseCommand.d.ts.map +1 -0
  15. package/dist/console/BaseCommand.js +340 -0
  16. package/dist/console/BaseCommand.js.map +1 -0
  17. package/dist/console/Console.d.ts +86 -0
  18. package/dist/console/Console.d.ts.map +1 -0
  19. package/dist/console/Console.js +134 -0
  20. package/dist/console/Console.js.map +1 -0
  21. package/dist/console/ExceptionHandler.d.ts +28 -0
  22. package/dist/console/ExceptionHandler.d.ts.map +1 -0
  23. package/dist/console/ExceptionHandler.js +76 -0
  24. package/dist/console/ExceptionHandler.js.map +1 -0
  25. package/dist/console/HelpCommand.d.ts +16 -0
  26. package/dist/console/HelpCommand.d.ts.map +1 -0
  27. package/dist/console/HelpCommand.js +40 -0
  28. package/dist/console/HelpCommand.js.map +1 -0
  29. package/dist/console/IndexGenerator.d.ts +24 -0
  30. package/dist/console/IndexGenerator.d.ts.map +1 -0
  31. package/dist/console/IndexGenerator.js +65 -0
  32. package/dist/console/IndexGenerator.js.map +1 -0
  33. package/dist/console/Kernel.d.ts +298 -0
  34. package/dist/console/Kernel.d.ts.map +1 -0
  35. package/dist/console/Kernel.js +1120 -0
  36. package/dist/console/Kernel.js.map +1 -0
  37. package/dist/console/ListCommand.d.ts +18 -0
  38. package/dist/console/ListCommand.d.ts.map +1 -0
  39. package/dist/console/ListCommand.js +60 -0
  40. package/dist/console/ListCommand.js.map +1 -0
  41. package/dist/console/assertions.d.ts +20 -0
  42. package/dist/console/assertions.d.ts.map +1 -0
  43. package/dist/console/assertions.js +84 -0
  44. package/dist/console/assertions.js.map +1 -0
  45. package/dist/console/cliui.d.ts +248 -0
  46. package/dist/console/cliui.d.ts.map +1 -0
  47. package/dist/console/cliui.js +587 -0
  48. package/dist/console/cliui.js.map +1 -0
  49. package/dist/console/decorators.d.ts +90 -0
  50. package/dist/console/decorators.d.ts.map +1 -0
  51. package/dist/console/decorators.js +142 -0
  52. package/dist/console/decorators.js.map +1 -0
  53. package/dist/console/index.d.ts +32 -0
  54. package/dist/console/index.d.ts.map +1 -0
  55. package/dist/console/index.js +24 -0
  56. package/dist/console/index.js.map +1 -0
  57. package/dist/console/loaders.d.ts +52 -0
  58. package/dist/console/loaders.d.ts.map +1 -0
  59. package/dist/console/loaders.js +131 -0
  60. package/dist/console/loaders.js.map +1 -0
  61. package/dist/console/parser.d.ts +86 -0
  62. package/dist/console/parser.d.ts.map +1 -0
  63. package/dist/console/parser.js +440 -0
  64. package/dist/console/parser.js.map +1 -0
  65. package/dist/console/prompts.d.ts +124 -0
  66. package/dist/console/prompts.d.ts.map +1 -0
  67. package/dist/console/prompts.js +356 -0
  68. package/dist/console/prompts.js.map +1 -0
  69. package/dist/console/tracing.d.ts +17 -0
  70. package/dist/console/tracing.d.ts.map +1 -0
  71. package/dist/console/tracing.js +11 -0
  72. package/dist/console/tracing.js.map +1 -0
  73. package/dist/console/types.d.ts +255 -0
  74. package/dist/console/types.d.ts.map +1 -0
  75. package/dist/console/types.js +25 -0
  76. package/dist/console/types.js.map +1 -0
  77. package/dist/console/ui.d.ts +20 -0
  78. package/dist/console/ui.d.ts.map +1 -0
  79. package/dist/console/ui.js +31 -0
  80. package/dist/console/ui.js.map +1 -0
  81. package/dist/console/utils.d.ts +27 -0
  82. package/dist/console/utils.d.ts.map +1 -0
  83. package/dist/console/utils.js +56 -0
  84. package/dist/console/utils.js.map +1 -0
  85. package/dist/container/Container.d.ts +23 -3
  86. package/dist/container/Container.d.ts.map +1 -1
  87. package/dist/container/Container.js +177 -70
  88. package/dist/container/Container.js.map +1 -1
  89. package/dist/container/types.d.ts +14 -2
  90. package/dist/container/types.d.ts.map +1 -1
  91. package/dist/decorators/Service.d.ts +7 -0
  92. package/dist/decorators/Service.d.ts.map +1 -1
  93. package/dist/decorators/Service.js +23 -3
  94. package/dist/decorators/Service.js.map +1 -1
  95. package/dist/env/Env.d.ts +29 -4
  96. package/dist/env/Env.d.ts.map +1 -1
  97. package/dist/env/Env.js +27 -4
  98. package/dist/env/Env.js.map +1 -1
  99. package/dist/env/Secret.d.ts +11 -0
  100. package/dist/env/Secret.d.ts.map +1 -0
  101. package/dist/env/Secret.js +36 -0
  102. package/dist/env/Secret.js.map +1 -0
  103. package/dist/env/interpolate.d.ts +26 -0
  104. package/dist/env/interpolate.d.ts.map +1 -0
  105. package/dist/env/interpolate.js +48 -0
  106. package/dist/env/interpolate.js.map +1 -0
  107. package/dist/env/loadEnvFiles.d.ts.map +1 -1
  108. package/dist/env/loadEnvFiles.js +14 -4
  109. package/dist/env/loadEnvFiles.js.map +1 -1
  110. package/dist/env/schema.d.ts +23 -6
  111. package/dist/env/schema.d.ts.map +1 -1
  112. package/dist/env/schema.js +67 -33
  113. package/dist/env/schema.js.map +1 -1
  114. package/dist/errors/ReamError.d.ts +25 -0
  115. package/dist/errors/ReamError.d.ts.map +1 -1
  116. package/dist/errors/ReamError.js +5 -0
  117. package/dist/errors/ReamError.js.map +1 -1
  118. package/dist/errors/prettyPrintError.d.ts +9 -0
  119. package/dist/errors/prettyPrintError.d.ts.map +1 -0
  120. package/dist/errors/prettyPrintError.js +22 -0
  121. package/dist/errors/prettyPrintError.js.map +1 -0
  122. package/dist/events/Emitter.d.ts +1 -1
  123. package/dist/events/Emitter.d.ts.map +1 -1
  124. package/dist/events/Emitter.js +1 -1
  125. package/dist/events/Emitter.js.map +1 -1
  126. package/dist/events/EventsProvider.d.ts +2 -2
  127. package/dist/events/EventsProvider.d.ts.map +1 -1
  128. package/dist/events/EventsProvider.js +3 -3
  129. package/dist/events/EventsProvider.js.map +1 -1
  130. package/dist/graphql/GraphQLEngine.d.ts +1 -1
  131. package/dist/graphql/GraphQLEngine.d.ts.map +1 -1
  132. package/dist/graphql/GraphQLEngine.js +2 -2
  133. package/dist/graphql/GraphQLEngine.js.map +1 -1
  134. package/dist/graphql/GraphQLProvider.d.ts.map +1 -1
  135. package/dist/graphql/GraphQLProvider.js +7 -3
  136. package/dist/graphql/GraphQLProvider.js.map +1 -1
  137. package/dist/http/Exception.d.ts +63 -1
  138. package/dist/http/Exception.d.ts.map +1 -1
  139. package/dist/http/Exception.js +185 -48
  140. package/dist/http/Exception.js.map +1 -1
  141. package/dist/http/HttpContext.d.ts +53 -7
  142. package/dist/http/HttpContext.d.ts.map +1 -1
  143. package/dist/http/HttpContext.js +56 -15
  144. package/dist/http/HttpContext.js.map +1 -1
  145. package/dist/http/RedirectBuilder.d.ts.map +1 -1
  146. package/dist/http/RedirectBuilder.js +4 -1
  147. package/dist/http/RedirectBuilder.js.map +1 -1
  148. package/dist/http/Request.d.ts +141 -10
  149. package/dist/http/Request.d.ts.map +1 -1
  150. package/dist/http/Request.js +244 -34
  151. package/dist/http/Request.js.map +1 -1
  152. package/dist/http/Response.d.ts +176 -9
  153. package/dist/http/Response.d.ts.map +1 -1
  154. package/dist/http/Response.js +404 -16
  155. package/dist/http/Response.js.map +1 -1
  156. package/dist/index.d.ts +19 -8
  157. package/dist/index.d.ts.map +1 -1
  158. package/dist/index.js +20 -5
  159. package/dist/index.js.map +1 -1
  160. package/dist/middleware/Pipeline.d.ts +29 -8
  161. package/dist/middleware/Pipeline.d.ts.map +1 -1
  162. package/dist/middleware/Pipeline.js +40 -2
  163. package/dist/middleware/Pipeline.js.map +1 -1
  164. package/dist/openapi/OpenApiProvider.js +4 -4
  165. package/dist/openapi/OpenApiProvider.js.map +1 -1
  166. package/dist/router/Router.d.ts +223 -31
  167. package/dist/router/Router.d.ts.map +1 -1
  168. package/dist/router/Router.js +520 -102
  169. package/dist/router/Router.js.map +1 -1
  170. package/dist/rpc/RpcProvider.d.ts +1 -0
  171. package/dist/rpc/RpcProvider.d.ts.map +1 -1
  172. package/dist/rpc/RpcProvider.js +7 -3
  173. package/dist/rpc/RpcProvider.js.map +1 -1
  174. package/dist/rpc/RpcRouter.d.ts +2 -2
  175. package/dist/rpc/RpcRouter.d.ts.map +1 -1
  176. package/dist/rpc/RpcRouter.js +17 -5
  177. package/dist/rpc/RpcRouter.js.map +1 -1
  178. package/dist/scheduler/ScheduleProvider.d.ts.map +1 -1
  179. package/dist/scheduler/ScheduleProvider.js +7 -15
  180. package/dist/scheduler/ScheduleProvider.js.map +1 -1
  181. package/dist/server/Server.d.ts +17 -4
  182. package/dist/server/Server.d.ts.map +1 -1
  183. package/dist/server/Server.js +41 -7
  184. package/dist/server/Server.js.map +1 -1
  185. package/dist/services/app.d.ts +1 -1
  186. package/dist/services/app.js +1 -1
  187. package/dist/services/console.d.ts +21 -0
  188. package/dist/services/console.d.ts.map +1 -0
  189. package/dist/services/console.js +35 -0
  190. package/dist/services/console.js.map +1 -0
  191. package/dist/session/SessionMiddleware.js +3 -3
  192. package/dist/session/SessionMiddleware.js.map +1 -1
  193. package/dist/storage/StaticProvider.js +1 -1
  194. package/dist/storage/StaticProvider.js.map +1 -1
  195. package/dist/testing/ApiResponse.d.ts +218 -0
  196. package/dist/testing/ApiResponse.d.ts.map +1 -0
  197. package/dist/testing/ApiResponse.js +576 -0
  198. package/dist/testing/ApiResponse.js.map +1 -0
  199. package/dist/testing/RequestBuilder.d.ts +155 -35
  200. package/dist/testing/RequestBuilder.d.ts.map +1 -1
  201. package/dist/testing/RequestBuilder.js +455 -109
  202. package/dist/testing/RequestBuilder.js.map +1 -1
  203. package/dist/testing/TestClient.d.ts +53 -37
  204. package/dist/testing/TestClient.d.ts.map +1 -1
  205. package/dist/testing/TestClient.js +84 -52
  206. package/dist/testing/TestClient.js.map +1 -1
  207. package/dist/utils/Macroable.d.ts +30 -0
  208. package/dist/utils/Macroable.d.ts.map +1 -0
  209. package/dist/utils/Macroable.js +43 -0
  210. package/dist/utils/Macroable.js.map +1 -0
  211. package/dist/utils/inflect.d.ts +17 -0
  212. package/dist/utils/inflect.d.ts.map +1 -0
  213. package/dist/utils/inflect.js +32 -0
  214. package/dist/utils/inflect.js.map +1 -0
  215. package/dist/utils/objectPath.d.ts +57 -0
  216. package/dist/utils/objectPath.d.ts.map +1 -0
  217. package/dist/utils/objectPath.js +141 -0
  218. package/dist/utils/objectPath.js.map +1 -0
  219. package/events.darwin-arm64.node +0 -0
  220. package/events.darwin-x64.node +0 -0
  221. package/events.linux-arm64-gnu.node +0 -0
  222. package/events.linux-x64-gnu.node +0 -0
  223. package/events.win32-x64-msvc.node +0 -0
  224. package/index.darwin-arm64.node +0 -0
  225. package/index.darwin-x64.node +0 -0
  226. package/index.linux-arm64-gnu.node +0 -0
  227. package/index.linux-x64-gnu.node +0 -0
  228. package/index.win32-x64-msvc.node +0 -0
  229. package/package.json +20 -2
  230. package/scheduler.darwin-arm64.node +0 -0
  231. package/scheduler.darwin-x64.node +0 -0
  232. package/scheduler.linux-arm64-gnu.node +0 -0
  233. package/scheduler.linux-x64-gnu.node +0 -0
  234. package/scheduler.win32-x64-msvc.node +0 -0
  235. package/src/ConfigLoader.ts +72 -9
  236. package/src/HttpKernel.ts +53 -15
  237. package/src/Ignitor.ts +364 -45
  238. package/src/console/BaseCommand.ts +467 -0
  239. package/src/console/Console.ts +174 -0
  240. package/src/console/ExceptionHandler.ts +91 -0
  241. package/src/console/HelpCommand.ts +37 -0
  242. package/src/console/IndexGenerator.ts +79 -0
  243. package/src/console/Kernel.ts +1382 -0
  244. package/src/console/ListCommand.ts +55 -0
  245. package/src/console/assertions.ts +114 -0
  246. package/src/console/cliui.ts +756 -0
  247. package/src/console/decorators.ts +199 -0
  248. package/src/console/index.ts +67 -0
  249. package/src/console/loaders.ts +145 -0
  250. package/src/console/parser.ts +598 -0
  251. package/src/console/prompts.ts +548 -0
  252. package/src/console/tracing.ts +22 -0
  253. package/src/console/types.ts +280 -0
  254. package/src/console/ui.ts +37 -0
  255. package/src/console/utils.ts +69 -0
  256. package/src/container/Container.ts +198 -72
  257. package/src/container/types.ts +15 -2
  258. package/src/decorators/Service.ts +28 -3
  259. package/src/env/Env.ts +49 -5
  260. package/src/env/Secret.ts +41 -0
  261. package/src/env/interpolate.ts +54 -0
  262. package/src/env/loadEnvFiles.ts +12 -4
  263. package/src/env/schema.ts +109 -35
  264. package/src/errors/ReamError.ts +31 -0
  265. package/src/errors/prettyPrintError.ts +20 -0
  266. package/src/events/Emitter.ts +2 -2
  267. package/src/events/EventsProvider.ts +5 -5
  268. package/src/graphql/GraphQLEngine.ts +4 -4
  269. package/src/graphql/GraphQLProvider.ts +7 -3
  270. package/src/http/Exception.ts +214 -37
  271. package/src/http/HttpContext.ts +87 -18
  272. package/src/http/RedirectBuilder.ts +4 -1
  273. package/src/http/Request.ts +264 -34
  274. package/src/http/Response.ts +478 -27
  275. package/src/index.ts +41 -6
  276. package/src/middleware/Pipeline.ts +77 -6
  277. package/src/openapi/OpenApiProvider.ts +4 -4
  278. package/src/router/Router.ts +631 -113
  279. package/src/rpc/RpcProvider.ts +6 -2
  280. package/src/rpc/RpcRouter.ts +22 -7
  281. package/src/scheduler/ScheduleProvider.ts +7 -15
  282. package/src/server/Server.ts +49 -10
  283. package/src/services/app.ts +1 -1
  284. package/src/services/console.ts +42 -0
  285. package/src/session/SessionMiddleware.ts +4 -4
  286. package/src/storage/StaticProvider.ts +1 -1
  287. package/src/testing/ApiResponse.ts +691 -0
  288. package/src/testing/RequestBuilder.ts +577 -137
  289. package/src/testing/TestClient.ts +110 -77
  290. package/src/utils/Macroable.ts +54 -0
  291. package/src/utils/inflect.ts +29 -0
  292. package/src/utils/objectPath.ts +142 -0
  293. package/dist/console/CommandRunner.d.ts +0 -18
  294. package/dist/console/CommandRunner.d.ts.map +0 -1
  295. package/dist/console/CommandRunner.js +0 -65
  296. package/dist/console/CommandRunner.js.map +0 -1
  297. package/dist/decorators/Lazy.d.ts +0 -19
  298. package/dist/decorators/Lazy.d.ts.map +0 -1
  299. package/dist/decorators/Lazy.js +0 -53
  300. package/dist/decorators/Lazy.js.map +0 -1
  301. package/src/console/CommandRunner.ts +0 -82
  302. package/src/decorators/Lazy.ts +0 -57
@@ -0,0 +1,217 @@
1
+ /**
2
+ * BaseCommand — the class application commands extend (Console parity).
3
+ *
4
+ * Everything the kernel needs sits on the STATIC side (`commandName`,
5
+ * `description`, `options`, and the `args` / `flags` metadata written by the
6
+ * decorators), so extending this class is a convenience, not a requirement:
7
+ * it supplies `this.logger`, `this.prompt`, `this.app` and the `exitCode`
8
+ * contract. Packages that must not depend on `@c9up/ream` declare the same
9
+ * statics on a plain class instead.
10
+ *
11
+ * export default class Provision extends BaseCommand {
12
+ * static commandName = 'provision'
13
+ * static description = 'Create the owner account'
14
+ * static options: CommandOptions = { startApp: true }
15
+ *
16
+ * @flags.string({ description: 'Owner email', required: true })
17
+ * declare email: string
18
+ *
19
+ * async run() {
20
+ * const users = await this.app.container.resolve('users')
21
+ * await users.createOwner(this.email)
22
+ * this.logger.success(`Owner created: ${this.email}`)
23
+ * }
24
+ * }
25
+ */
26
+ import type { Application } from '../Application.js';
27
+ import type { Colors, Logger, Ui } from './cliui.js';
28
+ import type { Kernel } from './Kernel.js';
29
+ import type { Prompt } from './prompts.js';
30
+ import type { ArgumentMetaData, ArgumentsParserOptions, CommandOptions, CommandSnapshot, FlagMetaData, FlagsParserOptions, ParsedInput, SerializedCommand } from './types.js';
31
+ export declare abstract class BaseCommand {
32
+ /** Name typed on the command line, e.g. `provision` or `make:controller`. */
33
+ static commandName: string;
34
+ /** One-line summary shown by `list`. */
35
+ static description: string;
36
+ /**
37
+ * Alternative names this command answers to (Console `static aliases`). Unlike
38
+ * `commandsAliases` in the rc file, these travel with the command itself.
39
+ */
40
+ static aliases: readonly string[];
41
+ /** Longer text shown under the usage line by `<command> --help`. */
42
+ static help?: string | string[];
43
+ static options: CommandOptions;
44
+ /**
45
+ * Written by the `@args` / `@flags` decorators. Declared here so a subclass
46
+ * that uses neither still satisfies the dispatch contract, and so the
47
+ * decorators have an inherited list to copy from.
48
+ */
49
+ static args: readonly ArgumentMetaData[];
50
+ static flags: readonly FlagMetaData[];
51
+ /**
52
+ * Assigned by the kernel before `run()`. Declared with `declare` so no class
53
+ * field is emitted — under `target: ES2022` a real field would be
54
+ * re-initialised to `undefined` at construction and wipe the assignment.
55
+ */
56
+ logger: Logger;
57
+ /** Tables, stickers, instructions, tasks — and the raw-mode switch. */
58
+ ui: Ui;
59
+ /** Chainable ANSI helpers: `this.colors.green('DONE')`. */
60
+ colors: Colors;
61
+ prompt: Prompt;
62
+ /**
63
+ * The booted application. Only meaningful when the command sets
64
+ * `options.startApp` — otherwise the kernel never boots, and reading this is
65
+ * a programming error the kernel reports rather than a silent `undefined`.
66
+ */
67
+ app: Application;
68
+ /**
69
+ * The kernel that dispatched this command (Console parity).
70
+ *
71
+ * Assigned for every command, booted app or not: it is the registry, and a
72
+ * command that inspects or lists its siblings — `list` is the built-in
73
+ * example — has nowhere else to read them from.
74
+ */
75
+ kernel: Kernel;
76
+ /**
77
+ * Every parsed input, as Console exposes it: `this.parsed.args` /
78
+ * `this.parsed.flags`. The declared ones are also assigned to their
79
+ * properties; this is the whole picture, including flags accepted through
80
+ * `allowUnknownFlags`.
81
+ */
82
+ parsed: ParsedInput;
83
+ /** Set it to make the process exit non-zero without throwing. */
84
+ exitCode?: number;
85
+ /** What `run()` returned — filled by the kernel (Console `command.result`). */
86
+ result?: unknown;
87
+ /**
88
+ * The error thrown by `prepare` / `interact` / `run`, assigned before
89
+ * `completed()` runs so the hook can inspect it (Console parity).
90
+ */
91
+ error?: unknown;
92
+ /** Assigned by the kernel — see {@link terminate}. */
93
+ protected onTerminate?: () => void | Promise<void>;
94
+ /**
95
+ * Lifecycle hooks, run in this order around `run()`: `prepare`, `interact`,
96
+ * `run`, then `completed` — which runs even when one of the earlier stages
97
+ * threw. Returning `true` from `completed()` marks the error handled, so the
98
+ * kernel stops propagating it.
99
+ */
100
+ prepare?(...args: never[]): void | Promise<void>;
101
+ interact?(...args: never[]): void | Promise<void>;
102
+ completed?(...args: never[]): boolean | void | Promise<boolean | void>;
103
+ /**
104
+ * Shut down a `staysAlive` command. Without it a long-running command has no
105
+ * way to hand control back — the kernel deliberately does not tear the app
106
+ * down for those.
107
+ */
108
+ terminate(): Promise<void>;
109
+ /** Has {@link boot} run for THIS class — not for one of its ancestors. */
110
+ static booted: boolean;
111
+ /**
112
+ * Give this class its OWN copy of the inherited static declarations
113
+ * (Console `boot`).
114
+ *
115
+ * Without it, `Child.args.push(...)` would append to the array the parent
116
+ * declared, and every command in the hierarchy would share one list. Called
117
+ * by everything that reads or writes those statics, so it is normally
118
+ * invisible; it is public because ported Console code calls it directly.
119
+ */
120
+ static boot(): void;
121
+ /**
122
+ * Declare an argument without a decorator (Console `defineArgument`).
123
+ *
124
+ * The decorators are the ergonomic form, but a command built at runtime — or
125
+ * one in a package that must not import the framework — needs a plain call.
126
+ */
127
+ static defineArgument(name: string, options?: Partial<ArgumentMetaData>): void;
128
+ /** Declare a flag without a decorator (Console `defineFlag`). */
129
+ static defineFlag(name: string, options?: Partial<FlagMetaData>): void;
130
+ /**
131
+ * The command's metadata as plain data (Console `serialize`).
132
+ *
133
+ * What `ream list --json` and any tooling reads, without having to know how
134
+ * the decorators stored it.
135
+ */
136
+ static serialize(): SerializedCommand;
137
+ /**
138
+ * How this command's inputs are parsed, grouped by type (Console
139
+ * `getParserOptions`).
140
+ *
141
+ * Ream's parser reads the declarations directly, so nothing internal calls
142
+ * this; it exists because Console code inspects the shape — and it is derived
143
+ * from the same metadata, so it cannot describe something the parser would
144
+ * not do.
145
+ */
146
+ static getParserOptions(options?: Partial<FlagsParserOptions>): {
147
+ flagsParserOptions: FlagsParserOptions;
148
+ argumentsParserOptions: ArgumentsParserOptions[];
149
+ };
150
+ /**
151
+ * Check a parsed input against this command's declarations (Console `validate`).
152
+ *
153
+ * The parser enforces the same rules while parsing, so calling this on its
154
+ * output always passes. It is here for the case Console documents: an input built
155
+ * by hand, which has never been through a parser.
156
+ *
157
+ * Positional values are accepted as a list (Console's shape) or keyed by property
158
+ * name (what `this.parsed.args` holds), so the same call works from both.
159
+ */
160
+ static validate(parsed: {
161
+ args: readonly unknown[] | Record<string, unknown>;
162
+ flags?: Record<string, unknown>;
163
+ unknownFlags?: readonly string[];
164
+ }): void;
165
+ /**
166
+ * Assign the parsed values to their properties (Console `hydrate`).
167
+ *
168
+ * Idempotent: the kernel calls it before `run()`, and a ported command may
169
+ * call it again without the values being recomputed.
170
+ */
171
+ hydrate(): void;
172
+ /** Set once {@link hydrate} has run. */
173
+ protected hydrated: boolean;
174
+ /**
175
+ * Hydrate, then run — Console's instance-level `exec()`.
176
+ *
177
+ * Deliberately NOT the kernel's `exec()`: this one runs `run()` alone and
178
+ * rethrows, while the kernel drives the whole lifecycle (`prepare`,
179
+ * `interact`, `completed`) and reports the failure on the command instead.
180
+ */
181
+ exec(): Promise<unknown>;
182
+ /** The statics, readable from the instance (Console parity). */
183
+ get commandName(): string;
184
+ get options(): CommandOptions;
185
+ get args(): readonly ArgumentMetaData[];
186
+ get flags(): readonly FlagMetaData[];
187
+ /**
188
+ * A snapshot of THIS execution (Console `toJSON`): what the command received and
189
+ * what it produced.
190
+ *
191
+ * Distinct from the static {@link serialize}, which describes the command's
192
+ * contract. Returning the metadata here would drop `exitCode`, `result` and
193
+ * `error` — exactly what a test or an integration reads after running it.
194
+ */
195
+ toJSON(): CommandSnapshot;
196
+ /**
197
+ * Was this command the one invoked on the command line, rather than one
198
+ * another command called through `consoleApp.exec()`? Assigned by the kernel.
199
+ */
200
+ isMain: boolean;
201
+ abstract run(...args: never[]): unknown;
202
+ /** The command finished with exit code 0. */
203
+ assertSucceeded(): void;
204
+ /** The command finished with a non-zero exit code. */
205
+ assertFailed(): void;
206
+ assertExitCode(expected: number): void;
207
+ assertNotExitCode(unexpected: number): void;
208
+ /**
209
+ * A line equal to `message` was logged. Pass a stream to require it went
210
+ * there — a warning belongs on stderr, and asserting that is the point.
211
+ */
212
+ assertLog(message: string, stream?: 'stdout' | 'stderr'): void;
213
+ assertLogMatches(pattern: RegExp, stream?: 'stdout' | 'stderr'): void;
214
+ /** Every expected row was rendered — the header counts as one (Console). */
215
+ assertTableRows(expected: readonly (readonly string[])[]): void;
216
+ }
217
+ //# sourceMappingURL=BaseCommand.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BaseCommand.d.ts","sourceRoot":"","sources":["../../src/console/BaseCommand.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAEpD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,YAAY,CAAA;AAEpD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAEzC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAC1C,OAAO,KAAK,EACV,gBAAgB,EAChB,sBAAsB,EACtB,cAAc,EACd,eAAe,EACf,YAAY,EACZ,kBAAkB,EAClB,WAAW,EACX,iBAAiB,EAClB,MAAM,YAAY,CAAA;AAEnB,8BAAsB,WAAW;IAC/B,6EAA6E;IAC7E,MAAM,CAAC,WAAW,SAAK;IAEvB,wCAAwC;IACxC,MAAM,CAAC,WAAW,SAAK;IAEvB;;;OAGG;IACH,MAAM,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAK;IAEtC,oEAAoE;IACpE,MAAM,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,EAA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KAAK,EAAE,GAAG,OAAO;IAUvC,6CAA6C;IAC7C,eAAe,IAAI,IAAI;IAIvB,sDAAsD;IACtD,YAAY,IAAI,IAAI;IAIpB,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI;IAItC,iBAAiB,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI;IAI3C;;;OAGG;IACH,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,QAAQ,GAAG,QAAQ,GAAG,IAAI;IAI9D,gBAAgB,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,QAAQ,GAAG,QAAQ,GAAG,IAAI;IAIrE,4EAA4E;IAC5E,eAAe,CAAC,QAAQ,EAAE,SAAS,CAAC,SAAS,MAAM,EAAE,CAAC,EAAE,GAAG,IAAI;CAGhE"}
@@ -0,0 +1,340 @@
1
+ /**
2
+ * BaseCommand — the class application commands extend (Console parity).
3
+ *
4
+ * Everything the kernel needs sits on the STATIC side (`commandName`,
5
+ * `description`, `options`, and the `args` / `flags` metadata written by the
6
+ * decorators), so extending this class is a convenience, not a requirement:
7
+ * it supplies `this.logger`, `this.prompt`, `this.app` and the `exitCode`
8
+ * contract. Packages that must not depend on `@c9up/ream` declare the same
9
+ * statics on a plain class instead.
10
+ *
11
+ * export default class Provision extends BaseCommand {
12
+ * static commandName = 'provision'
13
+ * static description = 'Create the owner account'
14
+ * static options: CommandOptions = { startApp: true }
15
+ *
16
+ * @flags.string({ description: 'Owner email', required: true })
17
+ * declare email: string
18
+ *
19
+ * async run() {
20
+ * const users = await this.app.container.resolve('users')
21
+ * await users.createOwner(this.email)
22
+ * this.logger.success(`Owner created: ${this.email}`)
23
+ * }
24
+ * }
25
+ */
26
+ import { createAssertions } from './assertions.js';
27
+ import { assertArgumentOrder, buildArgument, buildFlag } from './decorators.js';
28
+ import { assignParsedValues, validateParsed } from './parser.js';
29
+ export class BaseCommand {
30
+ /** Name typed on the command line, e.g. `provision` or `make:controller`. */
31
+ static commandName = '';
32
+ /** One-line summary shown by `list`. */
33
+ static description = '';
34
+ /**
35
+ * Alternative names this command answers to (Console `static aliases`). Unlike
36
+ * `commandsAliases` in the rc file, these travel with the command itself.
37
+ */
38
+ static aliases = [];
39
+ /** Longer text shown under the usage line by `<command> --help`. */
40
+ static help;
41
+ static options = {};
42
+ /**
43
+ * Written by the `@args` / `@flags` decorators. Declared here so a subclass
44
+ * that uses neither still satisfies the dispatch contract, and so the
45
+ * decorators have an inherited list to copy from.
46
+ */
47
+ static args = [];
48
+ static flags = [];
49
+ /** Set it to make the process exit non-zero without throwing. */
50
+ exitCode;
51
+ /** What `run()` returned — filled by the kernel (Console `command.result`). */
52
+ result;
53
+ /**
54
+ * The error thrown by `prepare` / `interact` / `run`, assigned before
55
+ * `completed()` runs so the hook can inspect it (Console parity).
56
+ */
57
+ error;
58
+ /**
59
+ * Shut down a `staysAlive` command. Without it a long-running command has no
60
+ * way to hand control back — the kernel deliberately does not tear the app
61
+ * down for those.
62
+ */
63
+ async terminate() {
64
+ await this.onTerminate?.();
65
+ }
66
+ /** Has {@link boot} run for THIS class — not for one of its ancestors. */
67
+ static booted = false;
68
+ /**
69
+ * Give this class its OWN copy of the inherited static declarations
70
+ * (Console `boot`).
71
+ *
72
+ * Without it, `Child.args.push(...)` would append to the array the parent
73
+ * declared, and every command in the hierarchy would share one list. Called
74
+ * by everything that reads or writes those statics, so it is normally
75
+ * invisible; it is public because ported Console code calls it directly.
76
+ */
77
+ static boot() {
78
+ if (Object.hasOwn(this, 'booted') && this.booted === true)
79
+ return;
80
+ this.booted = true;
81
+ // Only the mutable declarations are copied. Console also re-assigns the scalar
82
+ // statics (name, description, help); for a string, an own copy and an
83
+ // inherited one are indistinguishable — the line would read as a bug.
84
+ this.args = [...this.args];
85
+ this.flags = [...this.flags];
86
+ this.aliases = [...this.aliases];
87
+ this.options = { staysAlive: false, allowUnknownFlags: false, ...this.options };
88
+ }
89
+ /**
90
+ * Declare an argument without a decorator (Console `defineArgument`).
91
+ *
92
+ * The decorators are the ergonomic form, but a command built at runtime — or
93
+ * one in a package that must not import the framework — needs a plain call.
94
+ */
95
+ static defineArgument(name, options = {}) {
96
+ this.boot();
97
+ const list = [...this.args];
98
+ // Built by the same function the decorators use: a field added on one path
99
+ // and forgotten on the other is a silent divergence, not a compile error.
100
+ const argument = buildArgument(name, options);
101
+ // Console's two ordering rules, shared with the decorators — see
102
+ // `assertArgumentOrder`. They are not pedantry: a spread argument eats the
103
+ // tail, so nothing after it can ever be filled, and a required argument
104
+ // behind an optional one can only be reached by passing the optional one,
105
+ // which makes "required" a lie.
106
+ assertArgumentOrder(list, argument);
107
+ list.push(argument);
108
+ this.args = list;
109
+ }
110
+ /** Declare a flag without a decorator (Console `defineFlag`). */
111
+ static defineFlag(name, options = {}) {
112
+ this.boot();
113
+ const list = [...this.flags];
114
+ list.push(buildFlag(name, options));
115
+ this.flags = list;
116
+ }
117
+ /**
118
+ * The command's metadata as plain data (Console `serialize`).
119
+ *
120
+ * What `ream list --json` and any tooling reads, without having to know how
121
+ * the decorators stored it.
122
+ */
123
+ static serialize() {
124
+ this.boot();
125
+ // `parse` is a function: keeping it would make this object look JSON-safe
126
+ // while quietly losing a field the moment it is stringified.
127
+ const withoutParse = (entry) => {
128
+ const { parse: _dropped, ...rest } = entry;
129
+ return rest;
130
+ };
131
+ const colon = this.commandName.indexOf(':');
132
+ return {
133
+ commandName: this.commandName,
134
+ namespace: colon === -1 ? null : this.commandName.slice(0, colon),
135
+ description: this.description,
136
+ help: this.help,
137
+ aliases: [...this.aliases],
138
+ options: { ...this.options },
139
+ args: this.args.map(withoutParse),
140
+ flags: this.flags.map(withoutParse),
141
+ };
142
+ }
143
+ /**
144
+ * How this command's inputs are parsed, grouped by type (Console
145
+ * `getParserOptions`).
146
+ *
147
+ * Ream's parser reads the declarations directly, so nothing internal calls
148
+ * this; it exists because Console code inspects the shape — and it is derived
149
+ * from the same metadata, so it cannot describe something the parser would
150
+ * not do.
151
+ */
152
+ static getParserOptions(options) {
153
+ this.boot();
154
+ const flagsParserOptions = {
155
+ all: [],
156
+ string: [],
157
+ boolean: [],
158
+ number: [],
159
+ array: [],
160
+ alias: {},
161
+ count: [],
162
+ coerce: {},
163
+ default: {},
164
+ ...options,
165
+ };
166
+ for (const flag of this.flags) {
167
+ flagsParserOptions.all.push(flag.flagName);
168
+ if (flag.alias.length > 0)
169
+ flagsParserOptions.alias[flag.flagName] = [...flag.alias];
170
+ if (flag.parse !== undefined) {
171
+ flagsParserOptions.coerce[flag.flagName] = flag.parse;
172
+ }
173
+ if (flag.default !== undefined)
174
+ flagsParserOptions.default[flag.flagName] = flag.default;
175
+ flagsParserOptions[flag.type].push(flag.flagName);
176
+ }
177
+ return {
178
+ flagsParserOptions,
179
+ argumentsParserOptions: this.args.map((arg) => ({
180
+ type: arg.type,
181
+ default: arg.default,
182
+ parse: arg.parse,
183
+ })),
184
+ };
185
+ }
186
+ /**
187
+ * Check a parsed input against this command's declarations (Console `validate`).
188
+ *
189
+ * The parser enforces the same rules while parsing, so calling this on its
190
+ * output always passes. It is here for the case Console documents: an input built
191
+ * by hand, which has never been through a parser.
192
+ *
193
+ * Positional values are accepted as a list (Console's shape) or keyed by property
194
+ * name (what `this.parsed.args` holds), so the same call works from both.
195
+ */
196
+ static validate(parsed) {
197
+ this.boot();
198
+ // The kernel applies the same rules between parsing and running — see
199
+ // `validateParsed`. One implementation, so a hand-built input is held to
200
+ // exactly what the command line is held to.
201
+ validateParsed(parsed, {
202
+ args: this.args,
203
+ flags: this.flags,
204
+ allowUnknownFlags: this.options.allowUnknownFlags,
205
+ commandName: this.commandName,
206
+ });
207
+ }
208
+ /**
209
+ * Assign the parsed values to their properties (Console `hydrate`).
210
+ *
211
+ * Idempotent: the kernel calls it before `run()`, and a ported command may
212
+ * call it again without the values being recomputed.
213
+ */
214
+ hydrate() {
215
+ if (this.hydrated)
216
+ return;
217
+ const commandClass = Object.getPrototypeOf(this).constructor;
218
+ if (!isDeclaring(commandClass)) {
219
+ throw new Error('hydrate() requires a command class carrying the static contract');
220
+ }
221
+ // One hydration path, shared with the kernel — see `assignParsedValues`.
222
+ // By declaration, not by copying the parsed bag: positionals are read BY
223
+ // POSITION and flags by their CLI name, so `this.name` is filled whichever
224
+ // shape the input came in.
225
+ assignParsedValues(this, commandClass.args, commandClass.flags, this.parsed);
226
+ this.hydrated = true;
227
+ }
228
+ /** Set once {@link hydrate} has run. */
229
+ hydrated = false;
230
+ /**
231
+ * Hydrate, then run — Console's instance-level `exec()`.
232
+ *
233
+ * Deliberately NOT the kernel's `exec()`: this one runs `run()` alone and
234
+ * rethrows, while the kernel drives the whole lifecycle (`prepare`,
235
+ * `interact`, `completed`) and reports the failure on the command instead.
236
+ */
237
+ async exec() {
238
+ this.hydrate();
239
+ try {
240
+ this.result = await this.run();
241
+ this.exitCode = this.exitCode ?? 0;
242
+ return this.result;
243
+ }
244
+ catch (error) {
245
+ this.error = error;
246
+ this.exitCode = this.exitCode ?? 1;
247
+ throw error;
248
+ }
249
+ }
250
+ /** The statics, readable from the instance (Console parity). */
251
+ get commandName() {
252
+ return Object.getPrototypeOf(this).constructor.commandName;
253
+ }
254
+ get options() {
255
+ return Object.getPrototypeOf(this).constructor.options;
256
+ }
257
+ get args() {
258
+ return Object.getPrototypeOf(this).constructor.args;
259
+ }
260
+ get flags() {
261
+ return Object.getPrototypeOf(this).constructor.flags;
262
+ }
263
+ /**
264
+ * A snapshot of THIS execution (Console `toJSON`): what the command received and
265
+ * what it produced.
266
+ *
267
+ * Distinct from the static {@link serialize}, which describes the command's
268
+ * contract. Returning the metadata here would drop `exitCode`, `result` and
269
+ * `error` — exactly what a test or an integration reads after running it.
270
+ */
271
+ toJSON() {
272
+ // Not named `constructor`: that shadows the global and biome rejects it.
273
+ const commandClass = Object.getPrototypeOf(this).constructor;
274
+ if (!isSerializable(commandClass)) {
275
+ throw new Error('toJSON() requires a command class carrying the static contract');
276
+ }
277
+ const meta = commandClass.serialize();
278
+ return {
279
+ commandName: meta.commandName,
280
+ options: meta.options,
281
+ // Positional VALUES as a list (Console's shape); flags stay keyed.
282
+ args: [...(this.parsed?.args ?? [])],
283
+ flags: this.parsed?.flags ?? {},
284
+ error: this.error,
285
+ result: this.result,
286
+ exitCode: this.exitCode,
287
+ };
288
+ }
289
+ // ─── Test assertions (Console parity) ───────────────────────────
290
+ //
291
+ // They live on the command because that is where a test holds the result,
292
+ // but the implementation is the kernel's: a command the kernel ran carries
293
+ // assertions ATTACHED by it (a class declared structurally never extends
294
+ // this one), and two copies of "did the table print this row?" is how the
295
+ // two answers end up disagreeing — which is exactly what happened.
296
+ /** The command finished with exit code 0. */
297
+ assertSucceeded() {
298
+ createAssertions(this, this.ui).assertSucceeded();
299
+ }
300
+ /** The command finished with a non-zero exit code. */
301
+ assertFailed() {
302
+ createAssertions(this, this.ui).assertFailed();
303
+ }
304
+ assertExitCode(expected) {
305
+ createAssertions(this, this.ui).assertExitCode(expected);
306
+ }
307
+ assertNotExitCode(unexpected) {
308
+ createAssertions(this, this.ui).assertNotExitCode(unexpected);
309
+ }
310
+ /**
311
+ * A line equal to `message` was logged. Pass a stream to require it went
312
+ * there — a warning belongs on stderr, and asserting that is the point.
313
+ */
314
+ assertLog(message, stream) {
315
+ createAssertions(this, this.ui).assertLog(message, stream);
316
+ }
317
+ assertLogMatches(pattern, stream) {
318
+ createAssertions(this, this.ui).assertLogMatches(pattern, stream);
319
+ }
320
+ /** Every expected row was rendered — the header counts as one (Console). */
321
+ assertTableRows(expected) {
322
+ createAssertions(this, this.ui).assertTableRows(expected);
323
+ }
324
+ }
325
+ /**
326
+ * The class carries the declarations `hydrate()` reads. Checked rather than
327
+ * assumed: a command may be declared structurally, and reading `args` off
328
+ * something that has none would silently hydrate nothing.
329
+ */
330
+ function isDeclaring(value) {
331
+ return (typeof value === 'function' &&
332
+ Array.isArray(Reflect.get(value, 'args')) &&
333
+ Array.isArray(Reflect.get(value, 'flags')));
334
+ }
335
+ function isSerializable(value) {
336
+ return (typeof value === 'function' &&
337
+ 'serialize' in value &&
338
+ typeof Reflect.get(value, 'serialize') === 'function');
339
+ }
340
+ //# sourceMappingURL=BaseCommand.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BaseCommand.js","sourceRoot":"","sources":["../../src/console/BaseCommand.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAGH,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAElD,OAAO,EAAE,mBAAmB,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAE/E,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAahE,MAAM,OAAgB,WAAW;IAC/B,6EAA6E;IAC7E,MAAM,CAAC,WAAW,GAAG,EAAE,CAAA;IAEvB,wCAAwC;IACxC,MAAM,CAAC,WAAW,GAAG,EAAE,CAAA;IAEvB;;;OAGG;IACH,MAAM,CAAC,OAAO,GAAsB,EAAE,CAAA;IAEtC,oEAAoE;IACpE,MAAM,CAAC,IAAI,CAAoB;IAE/B,MAAM,CAAC,OAAO,GAAmB,EAAE,CAAA;IAEnC;;;;OAIG;IACH,MAAM,CAAC,IAAI,GAAgC,EAAE,CAAA;IAC7C,MAAM,CAAC,KAAK,GAA4B,EAAE,CAAA;IAsC1C,iEAAiE;IACjE,QAAQ,CAAS;IAEjB,+EAA+E;IAC/E,MAAM,CAAU;IAEhB;;;OAGG;IACH,KAAK,CAAU;IAkBf;;;;OAIG;IACH,KAAK,CAAC,SAAS;QACb,MAAM,IAAI,CAAC,WAAW,EAAE,EAAE,CAAA;IAC5B,CAAC;IAED,0EAA0E;IAC1E,MAAM,CAAC,MAAM,GAAG,KAAK,CAAA;IAErB;;;;;;;;OAQG;IACH,MAAM,CAAC,IAAI;QACT,IAAI,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,QAAQ,CAAC,IAAI,IAAI,CAAC,MAAM,KAAK,IAAI;YAAE,OA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,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,WAAW,CAAC,KAAK,UAAU,CACtD,CAAA;AACH,CAAC"}
@@ -0,0 +1,86 @@
1
+ /**
2
+ * `consoleApp` — the programmatic face of the console.
3
+ *
4
+ * The CLI is not the only caller: a test wants to run a command and inspect the
5
+ * result, a controller may want to trigger one, a script may want to check a
6
+ * command exists before calling it. Spawning a process for that is both slow
7
+ * and untestable.
8
+ *
9
+ * import consoleApp from '@c9up/ream/services/console'
10
+ *
11
+ * const command = await consoleApp.exec('make:controller', ['user', '--resource'])
12
+ * command.exitCode // 0 on success, 1 on an unhandled failure
13
+ * command.result // whatever run() returned
14
+ * command.error // the failure, when one survived completed()
15
+ */
16
+ import type { Ui } from './cliui.js';
17
+ import type { Kernel, KernelState } from './Kernel.js';
18
+ import type { CommandClass, CommandInstance, ExecutedCommand, SerializedCommand } from './types.js';
19
+ export interface ConsoleOptions {
20
+ kernel: Kernel;
21
+ /**
22
+ * Loads the application's commands into the kernel. Called once, on first
23
+ * use — discovery reads the filesystem and imports modules, which is too much
24
+ * to do at every `hasCommand()`.
25
+ */
26
+ load: () => Promise<void>;
27
+ }
28
+ export declare class Console {
29
+ #private;
30
+ constructor(options: ConsoleOptions);
31
+ /**
32
+ * Load the commands if that has not happened yet.
33
+ *
34
+ * Idempotent, and safe under concurrent calls: the in-flight promise is
35
+ * shared, so two parallel `exec()` calls do not each import every command.
36
+ */
37
+ boot(): Promise<void>;
38
+ /** Run a command and return it, carrying `exitCode`, `result` and `error`. */
39
+ exec(commandName: string, argv?: readonly string[], options?: {
40
+ ui?: Ui;
41
+ }): Promise<ExecutedCommand>;
42
+ /**
43
+ * Does a command (or alias) by this name exist?
44
+ *
45
+ * Synchronous, as in Console — `await consoleApp.boot()` then `if (consoleApp.hasCommand(…))`.
46
+ * An async version would be a trap: a Promise is always truthy, so Adonis
47
+ * code copied over would take every branch.
48
+ *
49
+ * Calling it before `boot()` throws rather than answering `false`: an
50
+ * unloaded registry cannot tell "no such command" from "not looked yet", and
51
+ * a silent `false` is exactly the failure this signature exists to avoid.
52
+ */
53
+ hasCommand(name: string): boolean;
54
+ /** The metadata of every registered command. Requires {@link boot} too. */
55
+ getCommands(): SerializedCommand[];
56
+ /**
57
+ * The rest of Console's introspection surface, relayed as-is.
58
+ *
59
+ * All of it reads the registry, so all of it needs {@link boot} first —
60
+ * answering from an empty registry would be worse than the error, since
61
+ * "no such command" and "commands not loaded yet" are indistinguishable to
62
+ * the caller.
63
+ */
64
+ getCommand(commandName: string): SerializedCommand | null;
65
+ getNamespaceCommands(namespace?: string): SerializedCommand[];
66
+ getNamespaces(): string[];
67
+ getAliases(): string[];
68
+ getAliasCommand(alias: string): SerializedCommand | null;
69
+ getCommandAliases(commandName: string): string[];
70
+ getCommandSuggestions(name: string): string[];
71
+ getNamespaceSuggestions(name: string): string[];
72
+ /** The kernel's lifecycle stage — Console `getState()`. */
73
+ getState(): KernelState;
74
+ /** The command run when none is named. */
75
+ getDefaultCommand(): CommandClass;
76
+ /** The command invoked from the command line, once it has been built. */
77
+ getMainCommand(): CommandInstance | undefined;
78
+ /**
79
+ * Resolve a command class by name or alias, throwing when there is none.
80
+ * Loads the commands first, like {@link exec}.
81
+ */
82
+ find(commandName: string): Promise<CommandClass>;
83
+ /** The underlying kernel, for anything the façade does not cover. */
84
+ get kernel(): Kernel;
85
+ }
86
+ //# sourceMappingURL=Console.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Console.d.ts","sourceRoot":"","sources":["../../src/console/Console.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,YAAY,CAAA;AACpC,OAAO,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AACtD,OAAO,KAAK,EAAE,YAAY,EAAE,eAAe,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAEnG,MAAM,WAAW,cAAc;IAC7B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