homebridge-plugin-utils 1.35.0 → 2.0.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/README.md +130 -2
- package/build/eslint-plugin/README.md +164 -0
- package/build/eslint-plugin/config.mjs +308 -0
- package/build/eslint-plugin/index.mjs +7 -0
- package/build/eslint-plugin/plugin.mjs +46 -0
- package/build/eslint-plugin/rules/blank-line-after-open-brace.mjs +137 -0
- package/build/eslint-plugin/rules/blank-line-after-open-brace.test.mjs +112 -0
- package/build/eslint-plugin/rules/comment-style.mjs +190 -0
- package/build/eslint-plugin/rules/comment-style.test.mjs +190 -0
- package/build/eslint-plugin/rules/enforce-node-protocol.mjs +114 -0
- package/build/eslint-plugin/rules/enforce-node-protocol.test.mjs +116 -0
- package/build/eslint-plugin/rules/paren-comparisons-in-logical.mjs +94 -0
- package/build/eslint-plugin/rules/paren-comparisons-in-logical.test.mjs +107 -0
- package/build/eslint-plugin/rules/split-type-imports.mjs +354 -0
- package/build/eslint-plugin/rules/split-type-imports.test.mjs +268 -0
- package/build/eslint-plugin/test-setup.mjs +21 -0
- package/build/fs-ops.mjs +184 -0
- package/build/tsconfig.json +18 -3
- package/dist/backpressure.d.ts +94 -45
- package/dist/backpressure.js +229 -93
- package/dist/backpressure.js.map +1 -1
- package/dist/cli/index.d.ts +95 -0
- package/dist/cli/index.js +355 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/clock-double.d.ts +93 -0
- package/dist/clock-double.js +141 -0
- package/dist/clock-double.js.map +1 -0
- package/dist/clock.d.ts +39 -0
- package/dist/clock.js +34 -0
- package/dist/clock.js.map +1 -0
- package/dist/eslint-plugin/config.d.mts +193 -0
- package/dist/eslint-plugin/index.d.mts +2 -0
- package/dist/eslint-plugin/plugin.d.mts +87 -0
- package/dist/eslint-plugin/rules/blank-line-after-open-brace.d.mts +19 -0
- package/dist/eslint-plugin/rules/comment-style.d.mts +15 -0
- package/dist/eslint-plugin/rules/enforce-node-protocol.d.mts +18 -0
- package/dist/eslint-plugin/rules/paren-comparisons-in-logical.d.mts +15 -0
- package/dist/eslint-plugin/rules/split-type-imports.d.mts +16 -0
- package/dist/featureOptions-docs.d.ts +96 -0
- package/dist/featureOptions-docs.js +193 -0
- package/dist/featureOptions-docs.js.map +1 -0
- package/dist/featureOptions.d.ts +674 -0
- package/dist/featureOptions.js +870 -0
- package/dist/featureOptions.js.map +1 -0
- package/dist/ffmpeg/codecs.d.ts +256 -72
- package/dist/ffmpeg/codecs.js +477 -262
- package/dist/ffmpeg/codecs.js.map +1 -1
- package/dist/ffmpeg/dgram-util.d.ts +46 -0
- package/dist/ffmpeg/dgram-util.js +38 -0
- package/dist/ffmpeg/dgram-util.js.map +1 -0
- package/dist/ffmpeg/exec.d.ts +83 -64
- package/dist/ffmpeg/exec.js +77 -86
- package/dist/ffmpeg/exec.js.map +1 -1
- package/dist/ffmpeg/fmp4.d.ts +49 -2
- package/dist/ffmpeg/fmp4.js +47 -11
- package/dist/ffmpeg/fmp4.js.map +1 -1
- package/dist/ffmpeg/hap-enums.d.ts +214 -0
- package/dist/ffmpeg/hap-enums.js +92 -0
- package/dist/ffmpeg/hap-enums.js.map +1 -0
- package/dist/ffmpeg/index.d.ts +16 -9
- package/dist/ffmpeg/index.js +6 -0
- package/dist/ffmpeg/index.js.map +1 -1
- package/dist/ffmpeg/mp4-assembler.d.ts +120 -0
- package/dist/ffmpeg/mp4-assembler.js +387 -0
- package/dist/ffmpeg/mp4-assembler.js.map +1 -0
- package/dist/ffmpeg/mp4-parser.d.ts +94 -0
- package/dist/ffmpeg/mp4-parser.js +130 -0
- package/dist/ffmpeg/mp4-parser.js.map +1 -0
- package/dist/ffmpeg/options.d.ts +62 -149
- package/dist/ffmpeg/options.js +608 -499
- package/dist/ffmpeg/options.js.map +1 -1
- package/dist/ffmpeg/process.d.ts +142 -96
- package/dist/ffmpeg/process.js +406 -278
- package/dist/ffmpeg/process.js.map +1 -1
- package/dist/ffmpeg/record.d.ts +302 -188
- package/dist/ffmpeg/record.js +408 -567
- package/dist/ffmpeg/record.js.map +1 -1
- package/dist/ffmpeg/recording-process-double.d.ts +144 -0
- package/dist/ffmpeg/recording-process-double.js +168 -0
- package/dist/ffmpeg/recording-process-double.js.map +1 -0
- package/dist/ffmpeg/rtp-parser.d.ts +70 -0
- package/dist/ffmpeg/rtp-parser.js +77 -0
- package/dist/ffmpeg/rtp-parser.js.map +1 -0
- package/dist/ffmpeg/rtp.d.ts +198 -141
- package/dist/ffmpeg/rtp.js +473 -251
- package/dist/ffmpeg/rtp.js.map +1 -1
- package/dist/ffmpeg/settings.d.ts +5 -2
- package/dist/ffmpeg/settings.js +20 -5
- package/dist/ffmpeg/settings.js.map +1 -1
- package/dist/ffmpeg/stream.d.ts +57 -107
- package/dist/ffmpeg/stream.js +121 -150
- package/dist/ffmpeg/stream.js.map +1 -1
- package/dist/formatters.d.ts +106 -0
- package/dist/formatters.js +174 -0
- package/dist/formatters.js.map +1 -0
- package/dist/homebridge-enums.d.ts +30 -0
- package/dist/homebridge-enums.js +17 -0
- package/dist/homebridge-enums.js.map +1 -0
- package/dist/index.d.ts +12 -6
- package/dist/index.js +7 -2
- package/dist/index.js.map +1 -1
- package/dist/logclient/auth.d.ts +114 -0
- package/dist/logclient/auth.js +199 -0
- package/dist/logclient/auth.js.map +1 -0
- package/dist/logclient/cli-run.d.ts +76 -0
- package/dist/logclient/cli-run.js +639 -0
- package/dist/logclient/cli-run.js.map +1 -0
- package/dist/logclient/cli.d.ts +3 -0
- package/dist/logclient/cli.js +97 -0
- package/dist/logclient/cli.js.map +1 -0
- package/dist/logclient/client.d.ts +145 -0
- package/dist/logclient/client.js +600 -0
- package/dist/logclient/client.js.map +1 -0
- package/dist/logclient/config.d.ts +173 -0
- package/dist/logclient/config.js +199 -0
- package/dist/logclient/config.js.map +1 -0
- package/dist/logclient/endpoints.d.ts +54 -0
- package/dist/logclient/endpoints.js +73 -0
- package/dist/logclient/endpoints.js.map +1 -0
- package/dist/logclient/filter.d.ts +45 -0
- package/dist/logclient/filter.js +51 -0
- package/dist/logclient/filter.js.map +1 -0
- package/dist/logclient/frame.d.ts +93 -0
- package/dist/logclient/frame.js +203 -0
- package/dist/logclient/frame.js.map +1 -0
- package/dist/logclient/index.d.ts +31 -0
- package/dist/logclient/index.js +12 -0
- package/dist/logclient/index.js.map +1 -0
- package/dist/logclient/parser.d.ts +211 -0
- package/dist/logclient/parser.js +393 -0
- package/dist/logclient/parser.js.map +1 -0
- package/dist/logclient/rest.d.ts +41 -0
- package/dist/logclient/rest.js +111 -0
- package/dist/logclient/rest.js.map +1 -0
- package/dist/logclient/settings.d.ts +15 -0
- package/dist/logclient/settings.js +64 -0
- package/dist/logclient/settings.js.map +1 -0
- package/dist/logclient/socket-double.d.ts +201 -0
- package/dist/logclient/socket-double.js +384 -0
- package/dist/logclient/socket-double.js.map +1 -0
- package/dist/logclient/socket.d.ts +257 -0
- package/dist/logclient/socket.js +620 -0
- package/dist/logclient/socket.js.map +1 -0
- package/dist/logclient/stitch.d.ts +83 -0
- package/dist/logclient/stitch.js +146 -0
- package/dist/logclient/stitch.js.map +1 -0
- package/dist/logclient/time-expression.d.ts +42 -0
- package/dist/logclient/time-expression.js +181 -0
- package/dist/logclient/time-expression.js.map +1 -0
- package/dist/logclient/time-window.d.ts +38 -0
- package/dist/logclient/time-window.js +53 -0
- package/dist/logclient/time-window.js.map +1 -0
- package/dist/logclient/types.d.ts +107 -0
- package/dist/logclient/types.js +6 -0
- package/dist/logclient/types.js.map +1 -0
- package/dist/mqttClient.d.ts +287 -0
- package/dist/mqttClient.js +433 -0
- package/dist/mqttClient.js.map +1 -0
- package/dist/service.d.ts +64 -15
- package/dist/service.js +93 -66
- package/dist/service.js.map +1 -1
- package/dist/ui/featureOptions.js +870 -0
- package/dist/ui/featureOptions.js.map +1 -0
- package/dist/ui/formatters.js +174 -0
- package/dist/ui/formatters.js.map +1 -0
- package/dist/ui/pluginConfigSession.mjs +141 -0
- package/dist/ui/webUi-featureOptions/categoryState.mjs +135 -0
- package/dist/ui/webUi-featureOptions/effects/keyboard.mjs +61 -0
- package/dist/ui/webUi-featureOptions/effects/persist.mjs +226 -0
- package/dist/ui/webUi-featureOptions/effects/theme.mjs +398 -0
- package/dist/ui/webUi-featureOptions/effects/tokens.mjs +152 -0
- package/dist/ui/webUi-featureOptions/rendering.mjs +431 -0
- package/dist/ui/webUi-featureOptions/selectors.mjs +360 -0
- package/dist/ui/webUi-featureOptions/state.mjs +319 -0
- package/dist/ui/webUi-featureOptions/store.mjs +181 -0
- package/dist/ui/webUi-featureOptions/utils.mjs +200 -0
- package/dist/ui/webUi-featureOptions/views/connectionError.mjs +152 -0
- package/dist/ui/webUi-featureOptions/views/deviceInfo.mjs +80 -0
- package/dist/ui/webUi-featureOptions/views/header.mjs +77 -0
- package/dist/ui/webUi-featureOptions/views/nav.mjs +327 -0
- package/dist/ui/webUi-featureOptions/views/options.mjs +521 -0
- package/dist/ui/webUi-featureOptions/views/search.mjs +395 -0
- package/dist/ui/webUi-featureOptions.mjs +677 -0
- package/dist/ui/webUi.mjs +192 -87
- package/dist/util.d.ts +602 -45
- package/dist/util.js +783 -78
- package/dist/util.js.map +1 -1
- package/package.json +33 -15
- package/build/eslint-rules.mjs +0 -511
- package/dist/featureoptions.d.ts +0 -264
- package/dist/featureoptions.js +0 -480
- package/dist/featureoptions.js.map +0 -1
- package/dist/mqttclient.d.ts +0 -178
- package/dist/mqttclient.js +0 -310
- package/dist/mqttclient.js.map +0 -1
- package/dist/ui/featureoptions.js +0 -480
- package/dist/ui/featureoptions.js.map +0 -1
- package/dist/ui/webUi-featureoptions.mjs +0 -3765
package/dist/backpressure.js
CHANGED
|
@@ -1,136 +1,272 @@
|
|
|
1
1
|
/* Copyright(C) 2017-2026, HJD (https://github.com/hjdhjd). All rights reserved.
|
|
2
2
|
*
|
|
3
|
-
* backpressure.ts:
|
|
3
|
+
* backpressure.ts: Signal-driven, backpressure-aware write queue for Node.js writable streams.
|
|
4
4
|
*/
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
6
|
+
* AsyncDisposable write queue that serializes Buffer writes onto a Node {@link Writable}, respects backpressure via the stream's `drain` event, and composes into the
|
|
7
|
+
* library's `AbortSignal`-driven lifecycle so a parent signal can tear the writer down uniformly with every other HBPU resource class.
|
|
7
8
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
9
|
+
* Primary use case: feeding fMP4 segments from a livestream event source into an FFmpeg process's stdin, where the downstream may not consume as fast as the upstream
|
|
10
|
+
* produces.
|
|
11
|
+
*
|
|
12
|
+
* @module
|
|
13
|
+
*/
|
|
14
|
+
import { HbpuAbortError, composeSignals, onAbort } from "./util.js";
|
|
15
|
+
import { once } from "node:events";
|
|
16
|
+
/**
|
|
17
|
+
* Thrown synchronously by {@link BackpressureWriter.write} when the pending queue is already at the configured {@link BackpressureWriterInit.highWaterMark} and
|
|
18
|
+
* accepting the new chunk would push it over.
|
|
19
|
+
*
|
|
20
|
+
* Separate from the "writer has aborted" and "underlying stream is dead" failure modes so callers can discriminate backpressure-overflow (back off and retry later)
|
|
21
|
+
* from terminal failures (give up or escalate) by type rather than by inspecting error message text.
|
|
22
|
+
*
|
|
23
|
+
* @category Utilities
|
|
24
|
+
*/
|
|
25
|
+
export class BackpressureOverflowError extends Error {
|
|
26
|
+
name = "BackpressureOverflowError";
|
|
27
|
+
constructor(message = "BackpressureWriter: queue depth exceeds configured highWaterMark.") {
|
|
28
|
+
super(message);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Rejected by an individual {@link BackpressureWriter.write} promise when the provider returned a {@link Writable} whose `writable` flag is `false` (the stream has
|
|
33
|
+
* ended or been destroyed). The writer itself remains alive - a later stream replacement via the provider may revive the pipeline - so this is a per-write rejection,
|
|
34
|
+
* not a terminal writer error.
|
|
35
|
+
*
|
|
36
|
+
* @category Utilities
|
|
37
|
+
*/
|
|
38
|
+
export class BackpressureClosedStreamError extends Error {
|
|
39
|
+
name = "BackpressureClosedStreamError";
|
|
40
|
+
constructor(message = "BackpressureWriter: underlying stream is not writable.") {
|
|
41
|
+
super(message);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* AsyncDisposable backpressure-aware write queue for Node {@link Writable} streams.
|
|
46
|
+
*
|
|
47
|
+
* Each call to {@link BackpressureWriter.write} returns a Promise that resolves once the chunk has been written (and any triggered backpressure has drained) or rejects
|
|
48
|
+
* if the writer aborts mid-write. Concurrent writes serialize through an internal FIFO queue; ordering matches call order. The stream itself is resolved lazily through
|
|
49
|
+
* a caller-supplied provider on each drain turn, so the writer may outlive any particular stream instance - the provider is consulted per chunk, and a `null` return is
|
|
50
|
+
* a signal to drop the chunk (the associated write promise still resolves, treating the drop as a success from the caller's perspective).
|
|
10
51
|
*
|
|
11
52
|
* @example
|
|
12
53
|
*
|
|
13
54
|
* ```ts
|
|
14
|
-
*
|
|
15
|
-
* const writer = new BackpressureWriter(() => ffmpegProcess.stdin ?? null);
|
|
55
|
+
* import { BackpressureWriter } from "homebridge-plugin-utils";
|
|
16
56
|
*
|
|
17
|
-
*
|
|
18
|
-
* livestream.on("segment", (segment) => writer.write(segment));
|
|
57
|
+
* await using writer = new BackpressureWriter(() => ffmpegProcess.stdin ?? null, { signal: session.signal });
|
|
19
58
|
*
|
|
20
|
-
* //
|
|
21
|
-
* writer.
|
|
59
|
+
* // Each write awaits its own flush; concurrent writes queue behind prior ones.
|
|
60
|
+
* await writer.write(segmentOne);
|
|
61
|
+
* await writer.write(segmentTwo);
|
|
22
62
|
* ```
|
|
23
63
|
*
|
|
24
64
|
* @category Utilities
|
|
25
65
|
*/
|
|
26
66
|
export class BackpressureWriter {
|
|
27
|
-
drainListener;
|
|
28
|
-
drainStream;
|
|
29
|
-
getStream;
|
|
30
|
-
isClosed;
|
|
31
|
-
isWriting;
|
|
32
|
-
onWrite;
|
|
33
|
-
queue;
|
|
34
67
|
/**
|
|
35
|
-
*
|
|
68
|
+
* The composed abort signal representing this writer's lifetime. Aborts exactly once when {@link BackpressureWriter.abort} is called, when the parent signal fires,
|
|
69
|
+
* or when the underlying stream surfaces an error that invalidates the writer; `signal.reason` names the cause.
|
|
70
|
+
*/
|
|
71
|
+
signal;
|
|
72
|
+
// The private AbortController whose signal is composed into `this.signal`. Owning the controller internally keeps teardown reachable from any handler - drain-wait
|
|
73
|
+
// cancellation, stream-error escalation, explicit abort - without giving callers a handle to the raw controller.
|
|
74
|
+
#controller;
|
|
75
|
+
// Optional queue-depth ceiling. When undefined, the queue is unbounded and the only memory discipline is whatever the caller imposes by awaiting prior writes before
|
|
76
|
+
// issuing new ones.
|
|
77
|
+
#highWaterMark;
|
|
78
|
+
// Caller-provided resolver for the target stream. Evaluated lazily on each drain-loop iteration so the writer can survive stream replacement across FFmpeg process
|
|
79
|
+
// restarts, and so callers can bind the writer to a stream that does not yet exist at construction time.
|
|
80
|
+
#streamProvider;
|
|
81
|
+
// FIFO queue of pending writes. Each entry pairs the buffer with its resolver so the drain loop can settle the caller's promise at the same point it consumes the
|
|
82
|
+
// chunk. The drain loop peeks `queue[0]` during the write (so queue.length reflects total pending, including the in-flight entry) and shifts the entry off only
|
|
83
|
+
// after it has fully flushed or failed.
|
|
84
|
+
#queue = [];
|
|
85
|
+
// The active drain-loop promise, if any. Held so `[Symbol.asyncDispose]` can await actual completion before returning, so `await using` callers are guaranteed no
|
|
86
|
+
// stream interaction is still in flight by the time the surrounding scope exits.
|
|
87
|
+
#drainTask;
|
|
88
|
+
// True while the drain loop is active (set at entry, cleared in the loop's `finally`). Used by `write()` to decide whether to spawn a new drain - the flag flips
|
|
89
|
+
// back to false the moment the loop exits, whether synchronously (queue emptied in one pass, no backpressure) or asynchronously (after a drain wait or abort) - so
|
|
90
|
+
// a subsequent `write()` that arrives right after an empty-queue exit correctly re-spawns the loop rather than being stranded by a stale drain-task reference.
|
|
91
|
+
#processing = false;
|
|
92
|
+
/**
|
|
93
|
+
* Construct a new backpressure-aware writer.
|
|
36
94
|
*
|
|
37
|
-
* @param
|
|
38
|
-
*
|
|
39
|
-
* arrow function: `() => stream`.
|
|
40
|
-
* @param onWrite - Optional. A callback invoked after each segment is successfully written to the underlying stream. Useful for tracking write statistics.
|
|
95
|
+
* @param streamProvider - A function that returns the current writable stream, or `null` to drop incoming chunks. Evaluated lazily on each drain-loop iteration.
|
|
96
|
+
* @param init - Optional init options. See {@link BackpressureWriterInit}.
|
|
41
97
|
*
|
|
42
98
|
* @example
|
|
43
99
|
*
|
|
44
100
|
* ```ts
|
|
45
|
-
*
|
|
46
|
-
* const writer = new BackpressureWriter(() => this.ffmpegProcess?.stdin ?? null, () => segmentCount++);
|
|
47
|
-
*
|
|
48
|
-
* // Static stream...wrap in an arrow function.
|
|
49
|
-
* const writer = new BackpressureWriter(() => stream);
|
|
101
|
+
* await using writer = new BackpressureWriter(() => this.ffmpegProcess?.stdin ?? null, { highWaterMark: 64, signal: session.signal });
|
|
50
102
|
* ```
|
|
51
103
|
*/
|
|
52
|
-
constructor(
|
|
53
|
-
this
|
|
54
|
-
this
|
|
55
|
-
this
|
|
56
|
-
this.
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
104
|
+
constructor(streamProvider, init = {}) {
|
|
105
|
+
this.#streamProvider = streamProvider;
|
|
106
|
+
this.#highWaterMark = init.highWaterMark;
|
|
107
|
+
this.#controller = new AbortController();
|
|
108
|
+
this.signal = composeSignals(init.signal, this.#controller.signal);
|
|
109
|
+
// Single teardown convergence point. `onAbort` registers the one-shot teardown handler AND handles the pre-aborted-signal edge case where `addEventListener`
|
|
110
|
+
// would otherwise skip the handler. Rejects every pending entry - including the in-flight entry when the drain loop is parked on
|
|
111
|
+
// `events.once(stream, "drain", { signal })`. The drain loop's catch branch may also reject the in-flight resolver under the same abort; promise resolvers are
|
|
112
|
+
// idempotent after first settlement, so the second call is a no-op. Rejecting from here unconditionally is load-bearing in the stream-error escalation path,
|
|
113
|
+
// where the drain loop shifts the in-flight entry before calling `this.#controller.abort(...)` - by the time the listener runs, only the queued entries remain
|
|
114
|
+
// in the queue, and leaving any of them unrejected would orphan the caller's promise.
|
|
115
|
+
onAbort(this.signal, () => this.#teardown());
|
|
60
116
|
}
|
|
61
117
|
/**
|
|
62
|
-
*
|
|
63
|
-
*
|
|
118
|
+
* Enqueue `chunk` for writing. Concurrent calls serialize in FIFO order via the internal queue.
|
|
119
|
+
*
|
|
120
|
+
* @param chunk - The buffer to write.
|
|
64
121
|
*
|
|
65
|
-
* @
|
|
122
|
+
* @returns A promise that resolves when the chunk has been flushed to the underlying stream (including any required drain wait), or immediately if the provider
|
|
123
|
+
* returned `null` at dispatch time (drop semantics). The promise rejects in the following cases:
|
|
66
124
|
*
|
|
67
|
-
*
|
|
125
|
+
* - `this.signal.reason` - the writer aborted before or during the write.
|
|
126
|
+
* - {@link BackpressureOverflowError} (thrown synchronously) - `highWaterMark` is configured and the queue depth already equals or exceeds it.
|
|
127
|
+
* - {@link BackpressureClosedStreamError} - the provider returned a stream whose `writable` flag is `false`. The writer itself stays alive for a potential later
|
|
128
|
+
* stream replacement.
|
|
129
|
+
*
|
|
130
|
+
* @throws {@link BackpressureOverflowError} when `highWaterMark` is exceeded.
|
|
131
|
+
*/
|
|
132
|
+
async write(chunk) {
|
|
133
|
+
// Pre-aborted short-circuit: a write issued after teardown has nothing live to attach to. Rejecting with the signal's reason keeps semantics uniform with the
|
|
134
|
+
// mid-write abort path - callers discriminate on `signal.reason` / `isHbpuAbortReason` in either case.
|
|
135
|
+
if (this.signal.aborted) {
|
|
136
|
+
throw this.signal.reason;
|
|
137
|
+
}
|
|
138
|
+
// Queue-overflow fail-fast. Rejecting synchronously lets upstream producers apply their own pacing rather than silently accumulating unbounded backlog. A
|
|
139
|
+
// dedicated {@link BackpressureOverflowError} class (not an `HbpuAbortError`) is thrown here because the writer itself is still healthy - the caller supplied too
|
|
140
|
+
// much work, not the system asking for teardown - and consumers who care about the distinction can `instanceof`-check rather than match on message text.
|
|
141
|
+
if ((this.#highWaterMark !== undefined) && (this.#queue.length >= this.#highWaterMark)) {
|
|
142
|
+
throw new BackpressureOverflowError();
|
|
143
|
+
}
|
|
144
|
+
const resolvers = Promise.withResolvers();
|
|
145
|
+
this.#queue.push({ chunk, resolvers });
|
|
146
|
+
// Spin up the drain loop when nothing is already processing. We key off the `#processing` flag rather than `#drainTask` because an async function's body runs
|
|
147
|
+
// synchronously until its first `await`: a no-backpressure drain completes before `write()` returns, leaving `#drainTask` set to a resolved-but-not-yet-cleared
|
|
148
|
+
// promise that would falsely gate subsequent writes. `#processing` is flipped true at the top of `#drain` and false in its `finally`, so checking it gives us a
|
|
149
|
+
// truthful "is a drain currently running?" answer with no chained-promise races.
|
|
150
|
+
if (!this.#processing) {
|
|
151
|
+
this.#drainTask = this.#drain();
|
|
152
|
+
}
|
|
153
|
+
return resolvers.promise;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Abort the writer and tear it down. Defaults to `HbpuAbortError("shutdown")` when no reason is supplied; explicit reasons pass through unchanged.
|
|
157
|
+
*
|
|
158
|
+
* Safe to call more than once: subsequent calls are no-ops because the underlying signal only aborts once. Every queued write rejects with the signal's reason; any
|
|
159
|
+
* in-flight drain wait rejects with the signal's reason as well, and that rejection propagates out of the in-flight `write()` promise.
|
|
160
|
+
*
|
|
161
|
+
* @param reason - Optional abort reason. Typically an {@link HbpuAbortError}; platform errors (`TimeoutError`, `AbortError`) also interoperate by convention.
|
|
68
162
|
*/
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
if (!stream?.writable) {
|
|
73
|
-
return false;
|
|
163
|
+
abort(reason) {
|
|
164
|
+
if (this.aborted) {
|
|
165
|
+
return;
|
|
74
166
|
}
|
|
75
|
-
|
|
76
|
-
this.queue.push(data);
|
|
77
|
-
this.processQueue();
|
|
78
|
-
return true;
|
|
167
|
+
this.#controller.abort(reason ?? new HbpuAbortError("shutdown"));
|
|
79
168
|
}
|
|
80
169
|
/**
|
|
81
|
-
*
|
|
82
|
-
*
|
|
170
|
+
* `AsyncDisposable` implementation. Aborts the writer (defaulting to `"shutdown"`) and awaits actual drain-loop completion before returning, so callers using
|
|
171
|
+
* `await using` are guaranteed every pending write has settled by the time the surrounding scope exits.
|
|
172
|
+
*
|
|
173
|
+
* @returns A promise that resolves once the drain loop has fully exited.
|
|
83
174
|
*/
|
|
84
|
-
|
|
85
|
-
this.
|
|
86
|
-
this
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
this.drainStream.off("drain", this.drainListener);
|
|
91
|
-
this.drainListener = null;
|
|
92
|
-
this.drainStream = null;
|
|
175
|
+
async [Symbol.asyncDispose]() {
|
|
176
|
+
this.abort();
|
|
177
|
+
if (this.#drainTask) {
|
|
178
|
+
// Drain failures are already observed through the individual write promises; swallow here so `await using` does not surface cleanup-side errors the caller has
|
|
179
|
+
// no way to react to.
|
|
180
|
+
await this.#drainTask.catch(() => { });
|
|
93
181
|
}
|
|
94
182
|
}
|
|
95
183
|
/**
|
|
96
|
-
*
|
|
184
|
+
* `true` once `this.signal` has aborted. Derived from the signal; no independent state.
|
|
185
|
+
*/
|
|
186
|
+
get aborted() {
|
|
187
|
+
return this.signal.aborted;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Total number of entries in the pending-write queue, including the in-flight entry (if the drain loop is parked on `events.once(stream, "drain", { signal })`).
|
|
191
|
+
* Matches the depth that the configured `highWaterMark` is compared against, so adaptive producers watching this value see the same accounting the writer uses
|
|
192
|
+
* internally.
|
|
97
193
|
*/
|
|
98
194
|
get pending() {
|
|
99
|
-
return this
|
|
195
|
+
return this.#queue.length;
|
|
100
196
|
}
|
|
101
|
-
//
|
|
102
|
-
//
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
this
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
197
|
+
// Drain loop. Iterates the queue, writing each chunk through the provider's current stream, honoring backpressure via `events.once(stream, "drain", { signal })`.
|
|
198
|
+
// Runs until the queue is empty or the signal aborts; every in-flight write is settled before exit (resolved on successful write, rejected via drain-abort on
|
|
199
|
+
// teardown). Note the peek-then-shift pattern: the entry stays at `queue[0]` while the write is in flight, so `queue.length` reflects the true pending count
|
|
200
|
+
// (including the in-flight entry) and `highWaterMark` checks in `write()` work uniformly whether the drain is idle or mid-wait.
|
|
201
|
+
async #drain() {
|
|
202
|
+
this.#processing = true;
|
|
203
|
+
try {
|
|
204
|
+
while ((this.#queue.length > 0) && !this.signal.aborted) {
|
|
205
|
+
const entry = this.#queue[0];
|
|
206
|
+
// `length`-guarded peek: the loop condition just checked non-empty, so we always have an entry. `noUncheckedIndexedAccess` widens the indexed access to
|
|
207
|
+
// `PendingWrite | undefined`; the null check below narrows for the compiler without changing runtime semantics.
|
|
208
|
+
if (!entry) {
|
|
209
|
+
break;
|
|
210
|
+
}
|
|
211
|
+
// Re-evaluate the stream on every iteration. The provider is free to return a different instance across turns (stream replacement across restarts) or `null`
|
|
212
|
+
// (no live stream right now - drop the chunk). Both cases are expected in HBUP's pipeline and are handled here without surfacing as errors to the caller.
|
|
213
|
+
const stream = this.#streamProvider();
|
|
214
|
+
if (!stream) {
|
|
215
|
+
// Drop semantics: the provider explicitly said "no stream." The write promise resolves so the caller can continue without branching on a per-write return;
|
|
216
|
+
// the surrounding session is responsible for deciding whether the lack of a stream is itself a fault.
|
|
217
|
+
this.#queue.shift();
|
|
218
|
+
entry.resolvers.resolve();
|
|
219
|
+
continue;
|
|
220
|
+
}
|
|
221
|
+
if (!stream.writable) {
|
|
222
|
+
// Stream exists but has ended. Reject this specific write with a {@link BackpressureClosedStreamError} and let the caller decide whether to escalate - we
|
|
223
|
+
// do not abort the writer here, because a later stream replacement (via the provider) may revive the pipeline.
|
|
224
|
+
this.#queue.shift();
|
|
225
|
+
entry.resolvers.reject(new BackpressureClosedStreamError());
|
|
226
|
+
continue;
|
|
227
|
+
}
|
|
228
|
+
try {
|
|
229
|
+
// `stream.write()` returns `false` when the high-water mark has been breached; the write is still queued by Node, but we must wait for `drain` before
|
|
230
|
+
// pushing more bytes or we risk unbounded growth of Node's internal write buffer in process memory. `events.once` with `{ signal }` ties the wait to the
|
|
231
|
+
// writer's lifetime so an abort during drain rejects the wait with the signal's reason rather than hanging.
|
|
232
|
+
if (!stream.write(entry.chunk)) {
|
|
233
|
+
// eslint-disable-next-line no-await-in-loop
|
|
234
|
+
await once(stream, "drain", { signal: this.signal });
|
|
235
|
+
}
|
|
236
|
+
this.#queue.shift();
|
|
237
|
+
entry.resolvers.resolve();
|
|
238
|
+
}
|
|
239
|
+
catch (error) {
|
|
240
|
+
// Two rejection shapes land here. (a) Our signal aborted mid-drain: `once` rejects with `signal.reason`; we surface that to the caller and exit the loop
|
|
241
|
+
// because teardown is already in flight. (b) The stream emitted an error via some path `events.once` exposes: the write that triggered the error cannot
|
|
242
|
+
// complete, so we reject this caller and abort the writer with `"failed"` so no subsequent write tries to reuse a broken stream silently.
|
|
243
|
+
this.#queue.shift();
|
|
244
|
+
if (this.aborted) {
|
|
245
|
+
entry.resolvers.reject(this.signal.reason);
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
entry.resolvers.reject(error);
|
|
249
|
+
this.#controller.abort(new HbpuAbortError("failed", { cause: error }));
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
130
252
|
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
this
|
|
253
|
+
}
|
|
254
|
+
finally {
|
|
255
|
+
this.#processing = false;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
// Teardown convergence point, fired exactly once when `this.signal` aborts. Rejects every pending entry with the signal's reason, regardless of whether the drain
|
|
259
|
+
// loop is currently processing. Promise resolvers are idempotent after first settlement, so if the drain loop's catch branch also rejects the in-flight resolver
|
|
260
|
+
// (e.g., when `events.once(..., { signal })` rejects on the same abort), the second call is a no-op. Draining the queue unconditionally here prevents the
|
|
261
|
+
// stream-error escalation path from orphaning queued resolvers - `#drain`'s catch shifts the in-flight entry and then calls `this.#controller.abort(...)`, which
|
|
262
|
+
// fires this listener synchronously while the remaining queued entries are still in the queue.
|
|
263
|
+
#teardown() {
|
|
264
|
+
// `signal.reason` is typed `any` in the DOM lib. The `: unknown` annotation narrows it to `unknown` for the `@typescript-eslint/no-unsafe-assignment` rule, which
|
|
265
|
+
// surfaces stray `any` values on assignment. `unknown` flows through `resolvers.reject()` unchanged - reject accepts any value.
|
|
266
|
+
const reason = this.signal.reason;
|
|
267
|
+
const pending = this.#queue.splice(0);
|
|
268
|
+
for (const entry of pending) {
|
|
269
|
+
entry.resolvers.reject(reason);
|
|
134
270
|
}
|
|
135
271
|
}
|
|
136
272
|
}
|
package/dist/backpressure.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"backpressure.js","sourceRoot":"","sources":["../src/backpressure.ts"],"names":[],"mappings":"AAAA;;;GAGG;
|
|
1
|
+
{"version":3,"file":"backpressure.js","sourceRoot":"","sources":["../src/backpressure.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;GAQG;AACH,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGpE,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAEnC;;;;;;;;GAQG;AACH,MAAM,OAAO,yBAA0B,SAAQ,KAAK;IAEzB,IAAI,GAAG,2BAAoC,CAAC;IAErE,YAAmB,OAAO,GAAG,mEAAmE;QAE9F,KAAK,CAAC,OAAO,CAAC,CAAC;IACjB,CAAC;CACF;AAED;;;;;;GAMG;AACH,MAA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CAAC;QACjC,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import type { renderFeatureOptionsReference, spliceMarkedRegion } from "../featureOptions-docs.ts";
|
|
3
|
+
/**
|
|
4
|
+
* Usage banner shown on no command or an unknown command. Kept as an exported constant so tests assert against its text without
|
|
5
|
+
* coupling to formatting details and so README documentation can reference it via import rather than duplicate.
|
|
6
|
+
*/
|
|
7
|
+
export declare const USAGE: string;
|
|
8
|
+
/**
|
|
9
|
+
* Mirror HBPU's compiled browser-side webUI into a plugin's homebridge-ui/public/lib directory under a content-hashed, version-named subdirectory. The subdir name
|
|
10
|
+
* combines the package's semver version with a short content hash of `dist/ui/` (e.g., `2.0.0-abc1234567890def`), so the browser's HTTP cache invalidates
|
|
11
|
+
* structurally on any content change rather than via per-file query-string hacks: the plugin's `index.html` reads the small manifest written alongside, then
|
|
12
|
+
* injects a trailing-slash importmap entry that prefixes every `./lib/` import with the hashed-versioned path. Transitive imports inherit the prefix through
|
|
13
|
+
* relative-URL resolution, so cache-busting reaches files the importmap never names.
|
|
14
|
+
*
|
|
15
|
+
* The content hash is the load-bearing piece for the maintainer-iteration use case. A semver-only subdir name would stay constant across the maintainer's
|
|
16
|
+
* edit/rebuild/test cycle (version doesn't bump on every save), and the browser would happily serve cached copies of the stale URLs. Hashing the tree means any
|
|
17
|
+
* source change produces a different subdir name, which produces different URLs, which forces fresh fetches. Same code path serves the published-release case: a
|
|
18
|
+
* release ships with a fixed hash, and every consumer fetching it sees the same URL space and caches aggressively within it.
|
|
19
|
+
*
|
|
20
|
+
* Operates idempotently. A re-run against unchanged source content produces the same subdir name + same contents + same manifest. Stale prior-build subdirs are
|
|
21
|
+
* removed in the same pass; non-version-shaped entries in the destination are left untouched so a plugin's own files (assets, sibling tooling, README copies)
|
|
22
|
+
* survive across runs.
|
|
23
|
+
*
|
|
24
|
+
* @param args
|
|
25
|
+
* @param args.dest - The plugin's destination directory (typically `homebridge-ui/public/lib`). Created if missing.
|
|
26
|
+
* @param args.sourceRoot - Path to HBPU's package root (the directory containing `package.json` and `dist/`). The entry block resolves this from the CLI's own
|
|
27
|
+
* real path; tests pass a tmpdir populated with a synthetic HBPU layout.
|
|
28
|
+
*
|
|
29
|
+
* @throws When the source has not been built (`dist/ui/` missing), the source `package.json` lacks a `version` field, or the source `dist/ui` path exists but is not a
|
|
30
|
+
* directory.
|
|
31
|
+
*/
|
|
32
|
+
export declare function prepareUi({ dest, sourceRoot }: {
|
|
33
|
+
dest: string;
|
|
34
|
+
sourceRoot: string;
|
|
35
|
+
}): Promise<void>;
|
|
36
|
+
/**
|
|
37
|
+
* Regenerate a plugin's Feature Options reference by projecting its live catalog through HBPU's shared renderer and splicing the result into the plugin's doc, in
|
|
38
|
+
* place between the shared `FEATURE OPTIONS:BEGIN` / `END` markers. This centralizes the read/splice/atomic-write orchestration so a plugin's `build-docs` script
|
|
39
|
+
* only needs a single line invoking this subcommand instead of a bespoke `*-gendocs.ts` shim.
|
|
40
|
+
*
|
|
41
|
+
* Pure-by-injection on `render` and `splice`: the renderer and the splice helper are passed in rather than imported statically, so this function is unit-testable
|
|
42
|
+
* against the real `featureOptions-docs.ts` exports without a built `dist/`, and the CLI's single-file no-static-relative-import discipline is preserved (the dispatch
|
|
43
|
+
* site reaches the renderer through a computed dynamic import). The catalog is loaded by dynamic import of its absolute path resolved to a `file:` URL, since a bare
|
|
44
|
+
* absolute path is not a valid ESM specifier on every platform. The module's required exports are validated up front so a mis-shaped catalog fails with a
|
|
45
|
+
* diagnostic naming the offending module and export rather than a downstream type error inside the renderer.
|
|
46
|
+
*
|
|
47
|
+
* The same catalog module may OPTIONALLY export scope hooks - `describeCategoryScope` and `describeOptionScope` - that the renderer threads through to contribute
|
|
48
|
+
* plugin-private scope prose (a device-scope line under a category heading, a suffix on an option's description cell). These are the annotated-plugin extension point
|
|
49
|
+
* (Protect/Access); a zero-config plugin (ratgdo) exports neither and documents every option unconditionally. Each hook is validated INDEPENDENTLY: if a module exports
|
|
50
|
+
* one under either name it MUST be a function, else this throws a framed diagnostic naming the module and the offending export; an absent hook is simply omitted, and
|
|
51
|
+
* the renderer already treats an absent hook as "omit cleanly". Because the hooks arrive through the dynamic-imported catalog namespace (never a static relative
|
|
52
|
+
* import), they preserve the bin's symlink-safe load-time edge discipline exactly as the catalog arrays do.
|
|
53
|
+
*
|
|
54
|
+
* The write is atomic: the new contents are staged in a sibling `.tmp` file and renamed over the doc. The rename is atomic on a single filesystem, so a crash
|
|
55
|
+
* mid-write can never leave a half-spliced doc behind - the file is either the prior content or the complete new content, never a truncated splice.
|
|
56
|
+
*
|
|
57
|
+
* @param args
|
|
58
|
+
* @param args.catalogModulePath - Absolute path to the plugin's compiled catalog module exporting `featureOptionCategories` (an array) and `featureOptions` (an
|
|
59
|
+
* object). Resolved to a `file:` URL before the dynamic import.
|
|
60
|
+
* @param args.docPath - Absolute path to the doc whose marked region is replaced (typically the plugin's `docs/FeatureOptions.md`).
|
|
61
|
+
* @param args.render - The injected {@link renderFeatureOptionsReference} from `featureOptions-docs.ts`.
|
|
62
|
+
* @param args.splice - The injected {@link spliceMarkedRegion} from `featureOptions-docs.ts`.
|
|
63
|
+
*
|
|
64
|
+
* @throws When the catalog module lacks `featureOptionCategories` (or it is not an array) or `featureOptions` (or it is not a non-null object), when it exports a
|
|
65
|
+
* present-but-non-function `describeCategoryScope` or `describeOptionScope`, and propagates the splice's own framed errors when the doc's marker pair is absent
|
|
66
|
+
* or ambiguous.
|
|
67
|
+
*/
|
|
68
|
+
export declare function prepareDocs({ catalogModulePath, docPath, render, splice }: {
|
|
69
|
+
catalogModulePath: string;
|
|
70
|
+
docPath: string;
|
|
71
|
+
render: typeof renderFeatureOptionsReference;
|
|
72
|
+
splice: typeof spliceMarkedRegion;
|
|
73
|
+
}): Promise<void>;
|
|
74
|
+
/**
|
|
75
|
+
* Run the CLI against a synthetic argv vector. Returns the process exit code that the entry block propagates. Pure-by-injection: takes its `cwd`, `stderr`, and
|
|
76
|
+
* `sourceRoot` as arguments rather than reading them from globals, so tests exercise the full dispatch path against a captured stderr, a tmpdir source root, and a
|
|
77
|
+
* tmpdir working directory without ever touching `process.exit` or the real filesystem outside the tmpdir scope.
|
|
78
|
+
*
|
|
79
|
+
* @param args
|
|
80
|
+
* @param args.argv - Positional and flag arguments (typically `process.argv.slice(2)`).
|
|
81
|
+
* @param args.cwd - The working directory that relative subcommand path arguments resolve against. Production passes `process.cwd()`; tests pass a tmpdir.
|
|
82
|
+
* @param args.sourceRoot - Path to HBPU's package root (resolved from the CLI's real path by the entry block; tests pass a tmpdir).
|
|
83
|
+
* @param args.stderr - Stream-like sink for usage and error output. Production passes `process.stderr`; tests pass a captured-output collector.
|
|
84
|
+
*
|
|
85
|
+
* @returns The exit code: `0` on success or on an explicit no-arg invocation showing the usage banner, `1` on misuse or subcommand failure.
|
|
86
|
+
*/
|
|
87
|
+
export declare function runCli({ argv, cwd, sourceRoot, stderr }: {
|
|
88
|
+
argv: readonly string[];
|
|
89
|
+
cwd: string;
|
|
90
|
+
sourceRoot: string;
|
|
91
|
+
stderr: {
|
|
92
|
+
write: (chunk: string) => unknown;
|
|
93
|
+
};
|
|
94
|
+
}): Promise<number>;
|
|
95
|
+
//# sourceMappingURL=index.d.ts.map
|