unifi-protect 5.4.2 → 5.4.3

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 (68) hide show
  1. package/README.md +28 -1
  2. package/dist/client/client.d.ts +8 -5
  3. package/dist/client/client.d.ts.map +1 -1
  4. package/dist/client/client.js +13 -8
  5. package/dist/client/client.js.map +1 -1
  6. package/dist/client/connection.d.ts +9 -6
  7. package/dist/client/connection.d.ts.map +1 -1
  8. package/dist/client/connection.js +17 -7
  9. package/dist/client/connection.js.map +1 -1
  10. package/dist/devices/device.js.map +1 -1
  11. package/dist/errors.d.ts +3 -2
  12. package/dist/errors.d.ts.map +1 -1
  13. package/dist/errors.js +3 -2
  14. package/dist/errors.js.map +1 -1
  15. package/dist/event-bus.d.ts +28 -8
  16. package/dist/event-bus.d.ts.map +1 -1
  17. package/dist/event-bus.js +70 -15
  18. package/dist/event-bus.js.map +1 -1
  19. package/dist/schema-manifest.json +1 -1
  20. package/dist/testing.d.ts +3 -0
  21. package/dist/testing.d.ts.map +1 -0
  22. package/dist/testing.js +7 -0
  23. package/dist/testing.js.map +1 -0
  24. package/dist/transport/events-stream.d.ts +7 -5
  25. package/dist/transport/events-stream.d.ts.map +1 -1
  26. package/dist/transport/events-stream.js +19 -13
  27. package/dist/transport/events-stream.js.map +1 -1
  28. package/dist/transport/http.d.ts +16 -12
  29. package/dist/transport/http.d.ts.map +1 -1
  30. package/dist/transport/http.js +43 -16
  31. package/dist/transport/http.js.map +1 -1
  32. package/dist/transport/livestream-session.d.ts +5 -3
  33. package/dist/transport/livestream-session.d.ts.map +1 -1
  34. package/dist/transport/livestream-session.js +8 -4
  35. package/dist/transport/livestream-session.js.map +1 -1
  36. package/dist/transport/talkback-session-double.d.ts +129 -0
  37. package/dist/transport/talkback-session-double.d.ts.map +1 -0
  38. package/dist/transport/talkback-session-double.js +187 -0
  39. package/dist/transport/talkback-session-double.js.map +1 -0
  40. package/dist/util/cli/commands/camera-talkback.js.map +1 -1
  41. package/dist/util/cli/commands/capture.js.map +1 -1
  42. package/dist/util/cli/commands/decode.js.map +1 -1
  43. package/dist/util/cli/commands/doctor.js.map +1 -1
  44. package/dist/util/cli/commands/watch-events.js.map +1 -1
  45. package/dist/util/cli/commands/watch-livestream.js.map +1 -1
  46. package/dist/util/cli/commands/watch-raw.js.map +1 -1
  47. package/dist/util/cli/commands/watch-state.js.map +1 -1
  48. package/dist/util/cli/shared.js.map +1 -1
  49. package/package.json +10 -6
  50. package/src/client/client.ts +16 -10
  51. package/src/client/connection.ts +23 -9
  52. package/src/devices/device.ts +1 -1
  53. package/src/errors.ts +3 -2
  54. package/src/event-bus.ts +87 -17
  55. package/src/testing.ts +7 -0
  56. package/src/transport/events-stream.ts +22 -14
  57. package/src/transport/http.ts +53 -16
  58. package/src/transport/livestream-session.ts +8 -4
  59. package/src/transport/talkback-session-double.ts +317 -0
  60. package/src/util/cli/commands/camera-talkback.ts +1 -1
  61. package/src/util/cli/commands/capture.ts +2 -2
  62. package/src/util/cli/commands/decode.ts +1 -1
  63. package/src/util/cli/commands/doctor.ts +2 -2
  64. package/src/util/cli/commands/watch-events.ts +1 -1
  65. package/src/util/cli/commands/watch-livestream.ts +1 -1
  66. package/src/util/cli/commands/watch-raw.ts +1 -1
  67. package/src/util/cli/commands/watch-state.ts +4 -4
  68. package/src/util/cli/shared.ts +2 -2
@@ -1,7 +1,7 @@
1
1
  import type { ProtectLogging } from "./logging.ts";
2
2
  /**
3
- * Options accepted by the event-bus `stream` rail. Carries the abort signal that terminates the iteration; further keys are reserved for a future backpressure policy.
4
- * The default behavior is unbounded, matching the livestream-subscription rule (a subscriber receives every emission until it aborts or stops iterating).
3
+ * Options accepted by the event-bus `stream` rail: the abort signal that terminates the iteration. The queue is unbounded, matching the livestream-subscription rule (a
4
+ * subscriber receives every emission until it aborts, stops iterating, or the owner of the events closes).
5
5
  *
6
6
  * @category Events
7
7
  */
@@ -31,6 +31,10 @@ export interface StreamOptions {
31
31
  * and logs a throw at error level through the logger the bus was built with, the host's own, and the listeners after it still run. The {@link once} and
32
32
  * {@link stream} rails need no such guard, because their consumers run on a later microtask, outside the emit.
33
33
  *
34
+ * Closing the bus is terminal, and each host closes its own once it has made its last emission. Every open stream ends cleanly after delivering what was emitted
35
+ * before the close, every pending wait rejects with the reason the host closed with, and every callback is released; from then on a new stream ends at once, a new
36
+ * wait rejects at once with that same reason, and a callback registers nothing.
37
+ *
34
38
  * `EventMap` keys are the event names; each value is the tuple of arguments that event carries (e.g., `{ throttleEntered: []; packet: [event: TypedEvent] }`).
35
39
  *
36
40
  * @typeParam EventMap - A record mapping each event name to the readonly tuple of arguments emitted with it.
@@ -48,18 +52,20 @@ export declare class EventBus<EventMap extends Record<keyof EventMap, readonly u
48
52
  * Long-lived notification subscription. Registers `handler` for `event` and returns a `Disposable` whose disposal detaches it.
49
53
  *
50
54
  * Prefer `using sub = bus.on("event", handler);` so the listener is removed automatically when the binding leaves scope. Where a `using` declaration does not fit,
51
- * call `sub[Symbol.dispose]()` explicitly. Disposing twice is safe - the second `off` is a no-op.
55
+ * call `sub[Symbol.dispose]()` explicitly. Disposing twice is safe - the second `off` is a no-op. A close releases every listener, and on a closed bus nothing is
56
+ * registered, since nothing will ever be emitted to it.
52
57
  *
53
58
  * @param event - The event name to listen for.
54
- * @param handler - Invoked with the event's argument tuple on every emission until the returned handle is disposed. A throw from it is logged at error level and
55
- * reaches neither the emitter nor the listeners after it.
59
+ * @param handler - Invoked with the event's argument tuple on every emission until the returned handle is disposed or the bus closes. A throw from it is logged at
60
+ * error level and reaches neither the emitter nor the listeners after it.
56
61
  *
57
62
  * @returns A `Disposable` that removes this listener when disposed.
58
63
  */
59
64
  on<K extends keyof EventMap & string>(event: K, handler: (...args: EventMap[K]) => void): Disposable;
60
65
  /**
61
66
  * One-shot wait for the next emission of `event`. Resolves with the event's argument tuple. Cancellable: if `opts.signal` aborts before the event fires, the
62
- * promise rejects with the signal's abort reason (an `AbortError` by default).
67
+ * promise rejects with an `AbortError` whose `cause` is the signal's reason. If the bus closes first, the promise rejects with the reason it closed with, as does a
68
+ * wait begun on a closed bus, so a wait that is never awaited needs a rejection handler.
63
69
  *
64
70
  * @param event - The event name to await.
65
71
  * @param opts - Optional abort signal that cancels the wait.
@@ -70,8 +76,10 @@ export declare class EventBus<EventMap extends Record<keyof EventMap, readonly u
70
76
  signal?: AbortSignal;
71
77
  }): Promise<EventMap[K]>;
72
78
  /**
73
- * Backpressure-aware async iterable of every subsequent emission of `event`, until `opts.signal` aborts or the consumer stops iterating. Each yielded value is the
74
- * event's argument tuple. The queue is unbounded by default - a slow consumer accumulates pending emissions rather than dropping them.
79
+ * Async iterable of every subsequent emission of `event`, until `opts.signal` aborts, the consumer stops iterating, or the bus closes. Each yielded value is the
80
+ * event's argument tuple. The queue is unbounded - a slow consumer accumulates pending emissions rather than dropping them. A close ends the iteration cleanly once
81
+ * every emission made before it has been delivered, and a stream begun on a closed bus ends at once; an abort rejects the iteration with an `AbortError` whose
82
+ * `cause` is the signal's reason.
75
83
  *
76
84
  * @param event - The event name to stream.
77
85
  * @param opts - Optional abort signal that terminates the iteration.
@@ -79,6 +87,18 @@ export declare class EventBus<EventMap extends Record<keyof EventMap, readonly u
79
87
  * @returns An async iterable yielding the argument tuple of each emission.
80
88
  */
81
89
  stream<K extends keyof EventMap & string>(event: K, opts?: StreamOptions): AsyncIterable<EventMap[K]>;
90
+ /**
91
+ * Close the bus for good. Every open stream ends once it has delivered what was emitted before the close, every pending wait rejects with `reason`, and every
92
+ * callback is released; from then on a new stream ends at once, a new wait rejects with the same `reason`, a callback registers nothing, and an emit reaches no
93
+ * listener. A no-op on repeat, so the first reason stands.
94
+ *
95
+ * This method is package-internal: the host closes its own bus once it has made its last emission.
96
+ *
97
+ * @param reason - What ended the host, the error every pending and later wait rejects with.
98
+ *
99
+ * @internal
100
+ */
101
+ close(reason: Error): void;
82
102
  /**
83
103
  * Emit `event` with its argument tuple, synchronously invoking every active listener (callbacks, pending `once` waiters, open `stream` iterators).
84
104
  *
@@ -1 +1 @@
1
- {"version":3,"file":"event-bus.d.ts","sourceRoot":"","sources":["../src/event-bus.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAEnD;;;;;GAKG;AACH,MAAM,WAAW,aAAa;IAE5B,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AASD;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAIH,qBAAa,QAAQ,CAAC,QAAQ,SAAS,MAAM,CAAC,MAAM,QAAQ,EAAE,SAAS,OAAO,EAAE,CAAC;;IAM/E;;;OAGG;gBACS,GAAG,EAAE,cAAc;IAU/B;;;;;;;;;;;OAWG;IACH,EAAE,CAAC,CAAC,SAAS,MAAM,QAAQ,GAAG,MAAM,EAAE,KAAK,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,GAAG,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC,KAAK,IAAI,GAAG,UAAU;IA0BpG;;;;;;;;OAQG;IACG,IAAI,CAAC,CAAC,SAAS,MAAM,QAAQ,GAAG,MAAM,EAAE,KAAK,EAAE,CAAC,EAAE,IAAI,GAAE;QAAE,MAAM,CAAC,EAAE,WAAW,CAAA;KAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;IAUlH;;;;;;;;OAQG;IACH,MAAM,CAAC,CAAC,SAAS,MAAM,QAAQ,GAAG,MAAM,EAAE,KAAK,EAAE,CAAC,EAAE,IAAI,GAAE,aAAkB,GAAG,aAAa,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;IAOzG;;;;;;;;;;;;OAYG;IACH,IAAI,CAAC,CAAC,SAAS,MAAM,QAAQ,GAAG,MAAM,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,OAAO;CAIjF"}
1
+ {"version":3,"file":"event-bus.d.ts","sourceRoot":"","sources":["../src/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3
  * event-bus.ts: A typed, three-rail event facade composing node:events.EventEmitter.
4
4
  */
5
- import { EventEmitter, once as nextEmission, on as subscribeIterator } from "node:events";
5
+ import { EventEmitter, on as subscribeIterator } from "node:events";
6
6
  // Every public event name is namespaced with this prefix before it reaches the composed EventEmitter. node:events special-cases three event names - `error` (emitting
7
7
  // it with no listener throws synchronously, and it rejects any open `events.on()` async iterator of *other* events), `newListener`, and `removeListener` - and that
8
8
  // special-casing would otherwise leak straight through this facade, which exists precisely to insulate consumers from EventEmitter's semantics. By translating, say,
9
9
  // `error` to `ufp:event:error` at the single boundary below, the underlying emitter never sees a literal `error`, so a typed `error` rail behaves like any other rail:
10
10
  // it never throws on a missing listener and never cross-rejects a sibling stream. The prefix is internal and never observable; consumers always use the bare name.
11
11
  const EVENT_NAME_PREFIX = "ufp:event:";
12
+ // The event a close emits to end every open stream. It lies outside the EVENT_NAME_PREFIX namespace, so no rail's name can ever collide with it.
13
+ const CLOSE_EVENT = "ufp:close";
14
+ // The options every stream registers with: the close event that ends its iteration. A stream with no signal passes this one object, so it allocates nothing beyond
15
+ // node's own iterator, and a stream with a signal passes a copy that adds it.
16
+ const CLOSE_OPTIONS = { close: [CLOSE_EVENT] };
17
+ // The stream a closed bus hands out. It has nothing to yield, so a `for await` over it ends on its first step, and it registers nothing on the emitter.
18
+ async function* endedStream() {
19
+ // A closed bus has nothing more to deliver.
20
+ }
12
21
  /**
13
22
  * A typed facade over `node:events.EventEmitter` that exposes a fixed set of subscription shapes - the canonical contract every event-producing subsystem in this
14
23
  * library presents (`Transport`, `EventStream`, `ConnectionMonitor`, `LivestreamSession`, `ProtectClient`).
@@ -32,6 +41,10 @@ const EVENT_NAME_PREFIX = "ufp:event:";
32
41
  * and logs a throw at error level through the logger the bus was built with, the host's own, and the listeners after it still run. The {@link once} and
33
42
  * {@link stream} rails need no such guard, because their consumers run on a later microtask, outside the emit.
34
43
  *
44
+ * Closing the bus is terminal, and each host closes its own once it has made its last emission. Every open stream ends cleanly after delivering what was emitted
45
+ * before the close, every pending wait rejects with the reason the host closed with, and every callback is released; from then on a new stream ends at once, a new
46
+ * wait rejects at once with that same reason, and a callback registers nothing.
47
+ *
35
48
  * `EventMap` keys are the event names; each value is the tuple of arguments that event carries (e.g., `{ throttleEntered: []; packet: [event: TypedEvent] }`).
36
49
  *
37
50
  * @typeParam EventMap - A record mapping each event name to the readonly tuple of arguments emitted with it.
@@ -45,6 +58,9 @@ export class EventBus {
45
58
  // The composed emitter. Private so the inherited EventEmitter surface never escapes; the only way in or out is through the facade's subscription rails plus emit.
46
59
  #emitter = new EventEmitter();
47
60
  #log;
61
+ // The reason the bus closed with, null while it is open, which is the bus's whole closed state. It is typed as the value a throw carries, because once throws it as
62
+ // it stands, while close admits nothing but an Error.
63
+ #closeReason = null;
48
64
  /**
49
65
  * @param log - The host subsystem's logger, which records a listener's throw. Required rather than defaulted, so a throw is recorded wherever the host records
50
66
  * everything else.
@@ -60,15 +76,21 @@ export class EventBus {
60
76
  * Long-lived notification subscription. Registers `handler` for `event` and returns a `Disposable` whose disposal detaches it.
61
77
  *
62
78
  * Prefer `using sub = bus.on("event", handler);` so the listener is removed automatically when the binding leaves scope. Where a `using` declaration does not fit,
63
- * call `sub[Symbol.dispose]()` explicitly. Disposing twice is safe - the second `off` is a no-op.
79
+ * call `sub[Symbol.dispose]()` explicitly. Disposing twice is safe - the second `off` is a no-op. A close releases every listener, and on a closed bus nothing is
80
+ * registered, since nothing will ever be emitted to it.
64
81
  *
65
82
  * @param event - The event name to listen for.
66
- * @param handler - Invoked with the event's argument tuple on every emission until the returned handle is disposed. A throw from it is logged at error level and
67
- * reaches neither the emitter nor the listeners after it.
83
+ * @param handler - Invoked with the event's argument tuple on every emission until the returned handle is disposed or the bus closes. A throw from it is logged at
84
+ * error level and reaches neither the emitter nor the listeners after it.
68
85
  *
69
86
  * @returns A `Disposable` that removes this listener when disposed.
70
87
  */
71
88
  on(event, handler) {
89
+ // A closed bus registers nothing: a handler left on the emitter would run for an emit the closed bus must answer as having no listener, so the handle returned
90
+ // here has nothing to detach.
91
+ if (this.#closeReason !== null) {
92
+ return { [Symbol.dispose]: () => undefined };
93
+ }
72
94
  /* We register a forwarding wrapper rather than the handler itself so the `args` boundary cast lives in one place and `off` has a stable reference to remove. The
73
95
  * emitter is untyped, so the cast from `unknown[]` to the event's argument tuple is the single unavoidable boundary cast - everything above it is fully typed.
74
96
  *
@@ -89,7 +111,8 @@ export class EventBus {
89
111
  }
90
112
  /**
91
113
  * One-shot wait for the next emission of `event`. Resolves with the event's argument tuple. Cancellable: if `opts.signal` aborts before the event fires, the
92
- * promise rejects with the signal's abort reason (an `AbortError` by default).
114
+ * promise rejects with an `AbortError` whose `cause` is the signal's reason. If the bus closes first, the promise rejects with the reason it closed with, as does a
115
+ * wait begun on a closed bus, so a wait that is never awaited needs a rejection handler.
93
116
  *
94
117
  * @param event - The event name to await.
95
118
  * @param opts - Optional abort signal that cancels the wait.
@@ -97,15 +120,18 @@ export class EventBus {
97
120
  * @returns A promise resolving to the argument tuple of the next emission.
98
121
  */
99
122
  async once(event, opts = {}) {
100
- // node:events' `once` already implements the signal-cancellable, single-shot semantics we want; resolving to the argument array is exactly our tuple shape. We
101
- // forward the options object only when a signal is present, mirroring node:events' own default of omitting the options object entirely rather than allocating
102
- // one that carries no signal.
103
- const args = await nextEmission(this.#emitter, EVENT_NAME_PREFIX + event, opts.signal ? { signal: opts.signal } : undefined);
104
- return args;
123
+ // The wait is the first item of a stream, so it registers, aborts and ends exactly as a stream does, and leaving the loop releases the stream's listeners. A stream
124
+ // ends without an item only when the bus closes, so falling out of the loop is the close, and the wait rejects with the reason the bus closed with.
125
+ for await (const args of this.stream(event, opts)) {
126
+ return args;
127
+ }
128
+ throw this.#closeReason;
105
129
  }
106
130
  /**
107
- * Backpressure-aware async iterable of every subsequent emission of `event`, until `opts.signal` aborts or the consumer stops iterating. Each yielded value is the
108
- * event's argument tuple. The queue is unbounded by default - a slow consumer accumulates pending emissions rather than dropping them.
131
+ * Async iterable of every subsequent emission of `event`, until `opts.signal` aborts, the consumer stops iterating, or the bus closes. Each yielded value is the
132
+ * event's argument tuple. The queue is unbounded - a slow consumer accumulates pending emissions rather than dropping them. A close ends the iteration cleanly once
133
+ * every emission made before it has been delivered, and a stream begun on a closed bus ends at once; an abort rejects the iteration with an `AbortError` whose
134
+ * `cause` is the signal's reason.
109
135
  *
110
136
  * @param event - The event name to stream.
111
137
  * @param opts - Optional abort signal that terminates the iteration.
@@ -113,9 +139,38 @@ export class EventBus {
113
139
  * @returns An async iterable yielding the argument tuple of each emission.
114
140
  */
115
141
  stream(event, opts = {}) {
116
- // node:events' `on` returns an async iterator that buffers emissions and rejects with the abort reason when the signal fires - precisely our stream contract,
117
- // which the firehose sugar smooths into a clean return. The yielded values are the argument arrays, which are our tuple type at the boundary.
118
- return subscribeIterator(this.#emitter, EVENT_NAME_PREFIX + event, opts.signal ? { signal: opts.signal } : undefined);
142
+ /* The caller's signal is read before the closed state, so a signal that has already aborted keeps its meaning on a closed bus: node's `on` throws its
143
+ * `AbortError` before registering anything, as it does on an open bus. A closed bus otherwise hands out a stream that has already ended.
144
+ *
145
+ * node:events' `on` returns an async iterator that registers here, before anything is awaited, so an emission made before the first step is buffered rather than
146
+ * lost. It rejects with an `AbortError` when the signal fires, which the firehose sugar smooths into a clean return, and the close event ends it cleanly: its
147
+ * listeners and its hold on the signal come off at the close, and it yields what it had buffered before it reports done. The yielded values are the argument
148
+ * arrays, which are our tuple type at the boundary.
149
+ */
150
+ if ((opts.signal?.aborted !== true) && (this.#closeReason !== null)) {
151
+ return endedStream();
152
+ }
153
+ return subscribeIterator(this.#emitter, EVENT_NAME_PREFIX + event, opts.signal ? { ...CLOSE_OPTIONS, signal: opts.signal } : CLOSE_OPTIONS);
154
+ }
155
+ /**
156
+ * Close the bus for good. Every open stream ends once it has delivered what was emitted before the close, every pending wait rejects with `reason`, and every
157
+ * callback is released; from then on a new stream ends at once, a new wait rejects with the same `reason`, a callback registers nothing, and an emit reaches no
158
+ * listener. A no-op on repeat, so the first reason stands.
159
+ *
160
+ * This method is package-internal: the host closes its own bus once it has made its last emission.
161
+ *
162
+ * @param reason - What ended the host, the error every pending and later wait rejects with.
163
+ *
164
+ * @internal
165
+ */
166
+ close(reason) {
167
+ if (this.#closeReason !== null) {
168
+ return;
169
+ }
170
+ // The close event ends every open stream, and the removal that follows releases every callback and anything else the emitter still holds.
171
+ this.#closeReason = reason;
172
+ this.#emitter.emit(CLOSE_EVENT);
173
+ this.#emitter.removeAllListeners();
119
174
  }
120
175
  /**
121
176
  * Emit `event` with its argument tuple, synchronously invoking every active listener (callbacks, pending `once` waiters, open `stream` iterators).
@@ -1 +1 @@
1
- {"version":3,"file":"event-bus.js","sourceRoot":"","sources":["../src/event-bus.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,YAAY,EAAE,IAAI,IAAI,YAAY,EAAE,EAAE,IAAI,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAc1F,sKAAsK;AACtK,oKAAoK;AACpK,qKAAqK;AACrK,uKAAuK;AACvK,mKAAmK;AACnK,MAAM,iBAAiB,GAAG,YAAY,CAAC;AAEvC;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,gKAAgK;AAChK,qKAAqK;AACrK,0IAA0I;AAC1I,MAAM,OAAO,QAAQ;IAEnB,kKAAkK;IACzJ,QAAQ,GAAG,IAAI,YAAY,EAAE,CAAC;IAC9B,IAAI,CAAiB;IAE9B;;;OAGG;IACH,YAAY,GAAmB;QAE7B,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC;QAEhB,8JAA8J;QAC9J,gKAAgK;QAChK,0JAA0J;QAC1J,IAAI,CAAC,QAAQ,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC;IACnC,CAAC;IAED;;;;;;;;;;;OAWG;IACH,EAAE,CAAoC,KAAQ,EAAE,OAAuC;QAErF;;;;;WAKG;QACH,MAAM,QAAQ,GAAG,CAAC,GAAG,IAAe,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