icore 1.0.18 → 1.0.19

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.
package/CHANGELOG.md CHANGED
@@ -17,10 +17,12 @@ verified against git tags.
17
17
  ### Added
18
18
 
19
19
  - Added `TerminalApp.runPrepared(...)` for running prepared commands through terminal rendering and output.
20
+ - Added `TerminalApp.writePreparedOutput(...)` for rendering and writing already obtained terminal output.
20
21
 
21
22
  ### Changed
22
23
 
23
24
  - Changed `createTerminalApp` typing to accept command registries with void and prepared payloads.
25
+ - Changed `createTerminalApp` typing to allow custom command results when consumers run prepared commands themselves.
24
26
  - Updated testing instructions to use `yarn build` and `yarn test`.
25
27
 
26
28
  ## [1.0.16]
@@ -15,10 +15,10 @@ import { type Presentation, type PresentationResult } from '../presentation/faca
15
15
  import { type PresentationFormat } from '../presentation/format-options';
16
16
  import { type Output } from '../output/facade';
17
17
  /**
18
- * Supported handler result shapes for the terminal app boundary.
18
+ * Supported terminal output shapes for the terminal app boundary.
19
19
  *
20
- * Domain commands may return ready text, streaming text, a presentation view,
21
- * or no output. Other result shapes are rejected before writing to stdout.
20
+ * Terminal output may be ready text, streaming text, a presentation view, or
21
+ * no output. Other result shapes are rejected before writing to stdout.
22
22
  */
23
23
  export type TerminalCommandOutput = string | AsyncIterable<string> | PresentationResult | undefined;
24
24
  type BivariantCallback<TInput, TOutput> = {
@@ -30,7 +30,7 @@ type TerminalCommandDefinition = {
30
30
  metadata?: unknown;
31
31
  allowExtraPositionals?: boolean;
32
32
  prepare?: BivariantCallback<PreparedCommandInput, unknown | Promise<unknown>>;
33
- handle: BivariantCallback<TerminalCommandInput, TerminalCommandOutput | Promise<TerminalCommandOutput>>;
33
+ handle: BivariantCallback<TerminalCommandInput, unknown | Promise<unknown>>;
34
34
  };
35
35
  type PreparedCommandInput = {
36
36
  options: Record<string, unknown>;
@@ -58,6 +58,13 @@ export type TerminalApp<TCommands extends readonly TerminalCommandDefinition[]>
58
58
  prepare(args: readonly string[], options?: CommandResolutionOptions): Promise<PreparedCommand<TCommands[number]>>;
59
59
  /** Runs an already prepared command through terminal rendering and output. */
60
60
  runPrepared(prepared: PreparedCommand<TCommands[number]>, context: CommandContext<TCommands[number]>): Promise<number>;
61
+ /**
62
+ * Renders and writes already obtained terminal output.
63
+ *
64
+ * String output is written exactly as provided; add a trailing newline in the
65
+ * command result when line output is desired.
66
+ */
67
+ writePreparedOutput(prepared: PreparedCommand<TCommands[number]>, output: TerminalCommandOutput): Promise<void>;
61
68
  /** Returns a process-style exit code. */
62
69
  run(args: readonly string[], context: CommandContext<TCommands[number]>, options?: CommandResolutionOptions): Promise<number>;
63
70
  };
@@ -27,11 +27,14 @@ function createTerminalApp(options) {
27
27
  const presentation = options.presentation ?? (0, facade_1.createPresentation)();
28
28
  const output = options.output ?? (0, facade_2.createOutput)();
29
29
  const resolveFormat = options.resolveFormat ?? resolvePreparedFormat;
30
+ async function writePreparedOutput(prepared, terminalOutput) {
31
+ const format = resolveFormat(prepared);
32
+ await writeTerminalOutput(terminalOutput, format, presentation, output);
33
+ }
30
34
  async function runPrepared(prepared, context) {
31
35
  try {
32
36
  const result = await options.commands.run(prepared, context);
33
- const format = resolveFormat(prepared);
34
- await writeTerminalOutput(result, format, presentation, output);
37
+ await writeTerminalOutput(result, resolveFormat(prepared), presentation, output);
35
38
  return 0;
36
39
  }
37
40
  catch (error) {
@@ -47,6 +50,7 @@ function createTerminalApp(options) {
47
50
  return options.commands.prepare(args, commandOptions);
48
51
  },
49
52
  runPrepared,
53
+ writePreparedOutput,
50
54
  async run(args, context, commandOptions) {
51
55
  try {
52
56
  const prepared = await options.commands.prepare(args, commandOptions);
@@ -104,6 +104,43 @@ finally {
104
104
  Resource creation and cleanup stay application-owned. The terminal app only
105
105
  runs the prepared command and applies the same output behavior as `app.run(...)`.
106
106
 
107
+ ## Write Prepared Output
108
+
109
+ Use `app.writePreparedOutput(...)` when the application needs to inspect the raw
110
+ command result before terminal output is written.
111
+
112
+ ```ts
113
+ const prepared = await app.prepare([
114
+ 'jobs',
115
+ 'run',
116
+ '--job-id',
117
+ 'job-42'
118
+ ], {
119
+ strict: true
120
+ });
121
+
122
+ const context = await createContext(prepared);
123
+
124
+ try {
125
+ const result = await app.commands.run(prepared, context);
126
+
127
+ if (isShutdownHandle(result)) {
128
+ installShutdownHooks(result);
129
+
130
+ return;
131
+ }
132
+
133
+ await app.writePreparedOutput(prepared, result);
134
+ }
135
+ finally {
136
+ await cleanup(context);
137
+ }
138
+ ```
139
+
140
+ Only terminal output belongs here: ready text, streaming text, presentation
141
+ results, or no output. Strings are written exactly as provided; include `\n`
142
+ when line output is desired.
143
+
107
144
  ## Prepare From A Registry
108
145
 
109
146
  `prepareCommandFromArgs(...)` is the standalone primitive behind
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "icore",
3
- "version": "1.0.18",
3
+ "version": "1.0.19",
4
4
  "description": "Declarative command line interface and terminal presentation mechanics for Node.js",
5
5
  "keywords": [
6
6
  "command-line",
package/readme.md CHANGED
@@ -81,7 +81,8 @@ without taking ownership of application behavior.
81
81
  The checked TypeScript contract lives in [`src/terminal/app.ts`](src/terminal/app.ts).
82
82
 
83
83
  The method returns an application object with `prepare(args)`,
84
- `runPrepared(prepared, context)`, and `run(args, context)`.
84
+ `writePreparedOutput(prepared, output)`, `runPrepared(prepared, context)`, and
85
+ `run(args, context)`.
85
86
 
86
87
  Construction inputs:
87
88
 
@@ -97,6 +98,8 @@ Returned app methods:
97
98
 
98
99
  - `app.prepare(args, options?)` delegates to
99
100
  [`commands.prepare(args, options?)`](#commandsprepareargs-options);
101
+ - `app.writePreparedOutput(prepared, output)` renders and writes already
102
+ obtained terminal output without running the command;
100
103
  - `app.runPrepared(prepared, context)` runs an already prepared command, then
101
104
  renders and writes terminal output;
102
105
  - `app.run(args, context, options?)` prepares the command, delegates command
@@ -118,10 +121,15 @@ const exitCode = await app.run(args, context, {
118
121
  });
119
122
  ```
120
123
 
121
- Command handlers keep ownership of application work. The terminal app only
122
- accepts terminal-ready results: text, streaming text, presentation results, or
123
- no output. Application DTO mapping, config loading, network clients, and domain
124
- behavior stay in the consuming application.
124
+ Command handlers keep ownership of application work. Terminal output methods
125
+ accept terminal-ready results: text, streaming text, presentation results, or no
126
+ output. If a command returns an application lifecycle object, run it with
127
+ `app.commands.run(...)`, inspect or map the result, then pass only terminal
128
+ output to `app.writePreparedOutput(...)`. Application DTO mapping, config
129
+ loading, network clients, and domain behavior stay in the consuming application.
130
+
131
+ String output is written exactly as provided. Return `\n` from the command when
132
+ line output is desired.
125
133
 
126
134
  ### `createCommand()`
127
135