@procedures/node 0.2.3 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,72 @@
1
1
  # @procedures/node
2
2
 
3
+ ## 0.4.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 4c51727: The process registry of `@procedures/shell/command` gives the output of a process after a time. `processes.subscribe(id, { output, end })` calls `output` with each new piece of output and its stream, and `end` with the record at the end of the process. `processes.follow(id, { backlog, signal, maxBufferedBytes })` gives the output as an async stream: the kept output without a gap, the new pieces in UTF-8, a `dropped` item for a slow reader, and an `end` item. The end of the process removes each subscriber, and a follow that ends removes its subscriber.
8
+
9
+ `node.logs` has the option `follow` (short `-f`). With it, the result is a stream: the kept output as `output` lines (`lines` limits them), each new line of stdout and stderr, and an `exit` item at the end of the process. The stream ends at the end of the process, at an abort of the caller and when the reader stops. `node.logs` declares `stream: { unbounded: true }`.
10
+
11
+ ### Patch Changes
12
+
13
+ - Updated dependencies [d919678]
14
+ - Updated dependencies [057d69a]
15
+ - Updated dependencies [b2a1a1e]
16
+ - Updated dependencies [057d69a]
17
+ - Updated dependencies [057d69a]
18
+ - Updated dependencies [057d69a]
19
+ - Updated dependencies [057d69a]
20
+ - Updated dependencies [057d69a]
21
+ - Updated dependencies [afd6a19]
22
+ - Updated dependencies [057d69a]
23
+ - Updated dependencies [4c51727]
24
+ - Updated dependencies [4e751da]
25
+ - @procedures/client@0.4.0
26
+ - @procedures/shell@0.4.0
27
+
28
+ ## 0.3.0
29
+
30
+ ### Minor Changes
31
+
32
+ - 04cfef8: `node.logs` (roadmap R44) gives the output of a process that `node.spawn` started: the last 64 KiB of stdout and stderr that the process registry of `client-shell` keeps. With `lines`, it gives only the last lines. With `stripAnsi`, it removes the colors. It works also after the process ended, and it only reads (`reads: ["jobs"]`).
33
+
34
+ ### Patch Changes
35
+
36
+ - Updated dependencies [ddea529]
37
+ - Updated dependencies [b2a3e3a]
38
+ - Updated dependencies [a8c47f1]
39
+ - Updated dependencies [381ce3a]
40
+ - Updated dependencies [0c627f8]
41
+ - Updated dependencies [ae7f05f]
42
+ - Updated dependencies [7873940]
43
+ - Updated dependencies [a70d445]
44
+ - Updated dependencies [bc70357]
45
+ - Updated dependencies [07cc998]
46
+ - Updated dependencies [a6b01a9]
47
+ - Updated dependencies [c799cdd]
48
+ - Updated dependencies [540f8d9]
49
+ - Updated dependencies [b6daaec]
50
+ - Updated dependencies [5b9264e]
51
+ - Updated dependencies [956e88b]
52
+ - Updated dependencies [ff62281]
53
+ - Updated dependencies [d81d0ed]
54
+ - Updated dependencies [aa67cc7]
55
+ - Updated dependencies [061fa22]
56
+ - Updated dependencies [cfb9d69]
57
+ - Updated dependencies [43f7de5]
58
+ - Updated dependencies [b07bb50]
59
+ - Updated dependencies [4a3bfa1]
60
+ - Updated dependencies [bd0b626]
61
+ - Updated dependencies [a6be873]
62
+ - Updated dependencies [fb30718]
63
+ - Updated dependencies [c5528e4]
64
+ - Updated dependencies [fee5d9c]
65
+ - Updated dependencies [21f7743]
66
+ - Updated dependencies [31a0b46]
67
+ - @procedures/client@0.3.0
68
+ - @procedures/shell@0.3.0
69
+
3
70
  ## 0.2.3
4
71
 
5
72
  ### Patch Changes
package/README.md CHANGED
@@ -14,6 +14,7 @@ Node.js process management procedures for the client ecosystem. Provides procedu
14
14
  │ await client.exec(["node", "spawn"], { script: "server.js" }) │
15
15
  │ await client.exec(["node", "kill"], { processId: "abc123" }) │
16
16
  │ await client.exec(["node", "status"], {}) │
17
+ │ await client.exec(["node", "logs"], { processId: "abc123", lines: 50 }) │
17
18
  │ │
18
19
  └─────────────────────────────────┬───────────────────────────────────────────┘
19
20
  │
@@ -62,6 +63,8 @@ pnpm add @procedures/node
62
63
 
63
64
  ## Procedures
64
65
 
66
+ The package has 5 procedures. Its register entry (`import "@procedures/node/register"`) registers them: `node.run`, `node.spawn`, `node.kill`, `node.status`, `node.logs`.
67
+
65
68
  ### node.run
66
69
 
67
70
  Run a Node.js script to completion and return the output.
@@ -217,6 +220,51 @@ for (const proc of result.processes) {
217
220
  | `status` | `"running" \| "stopped"` | Process status |
218
221
  | `startedAt` | `string` | ISO timestamp when started |
219
222
 
223
+ ### node.logs
224
+
225
+ The procedure gives the output of one process that `node.spawn` started. The process registry of `client-shell` reads the output of each process and keeps its end: the last 64 KiB of stdout and stderr together. Thus the procedure gives that end, also after the process ended. The registry keeps the records of the last 50 ended processes.
226
+
227
+ ```typescript
228
+ const { status, exitCode, output } = await client.exec(["node", "logs"], {
229
+ processId: "node-abc123-1",
230
+ lines: 50,
231
+ stripAnsi: true,
232
+ });
233
+ ```
234
+
235
+ The input has these fields:
236
+
237
+ - `processId` (necessary): the process ID that `node.spawn` gave.
238
+ - `lines`: give only the last lines of the output.
239
+ - `stripAnsi`: remove the ANSI escape codes (colors) from the output.
240
+ - `follow`: give a stream of lines (see below).
241
+
242
+ The output has the `processId`, the `status` (`running`, `exited` or `error`), the `exitCode` of an ended process and the `output`.
243
+
244
+ The procedure knows only the processes of its host. The process writes to two pipes, stdout and stderr. Thus `output` has their lines in the order of their arrival. A process that `node.spawn` did not start is an error.
245
+
246
+ #### `follow`: a stream of the lines
247
+
248
+ With `follow: true`, the result is a stream. It uses `processes.follow` of `@procedures/shell/command`.
249
+
250
+ ```typescript
251
+ for await (const item of client.stream(["node", "logs"], { processId, follow: true, lines: 20 })) {
252
+ if (item.type === "exit") break;
253
+ console.log(item.type, item.line);
254
+ }
255
+ ```
256
+
257
+ | Item | Meaning |
258
+ |---|---|
259
+ | `{ type: "output", line }` | A line of the kept output. `lines` limits these lines. The kept output has stdout and stderr together. |
260
+ | `{ type: "stdout" \| "stderr", line }` | A new line of the process, without its line end. |
261
+ | `{ type: "dropped", bytes }` | The reader was slow, and the stream dropped this many bytes of output. |
262
+ | `{ type: "exit", status, exitCode, signal }` | The end of the process. It is the last item. |
263
+
264
+ - The stream ends at the end of the process, at an abort of the caller, and when the reader stops. Each end removes the subscription from the process registry.
265
+ - A line without a line end at the end of the process is the last line of its stream.
266
+ - The procedure declares `stream: { unbounded: true }`, because a process can run without an end.
267
+
220
268
  ## Process Lifecycle
221
269
 
222
270
  ```