@toa.io/extensions.realtime 1.0.0-alpha.28 → 1.0.0-alpha.282

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 (87) hide show
  1. package/CHANGELOG.md +323 -0
  2. package/components/realtime.streams/manifest.toa.yaml +44 -0
  3. package/components/{streams → realtime.streams}/operations/create.d.ts +6 -3
  4. package/components/realtime.streams/operations/create.js +65 -0
  5. package/components/realtime.streams/operations/create.js.map +1 -0
  6. package/components/realtime.streams/operations/lib/Stash.d.ts +21 -0
  7. package/components/realtime.streams/operations/lib/Stash.js +86 -0
  8. package/components/realtime.streams/operations/lib/Stash.js.map +1 -0
  9. package/components/realtime.streams/operations/lib/Stream.d.ts +13 -0
  10. package/components/realtime.streams/operations/lib/Stream.js +43 -0
  11. package/components/realtime.streams/operations/lib/Stream.js.map +1 -0
  12. package/components/realtime.streams/operations/lib/index.d.ts +2 -0
  13. package/components/realtime.streams/operations/lib/index.js +3 -0
  14. package/components/realtime.streams/operations/lib/index.js.map +1 -0
  15. package/components/realtime.streams/operations/lib/types.d.ts +22 -0
  16. package/components/realtime.streams/operations/lib/types.js +2 -0
  17. package/components/realtime.streams/operations/lib/types.js.map +1 -0
  18. package/components/{streams → realtime.streams}/operations/push.d.ts +1 -1
  19. package/components/realtime.streams/operations/push.js +10 -0
  20. package/components/realtime.streams/operations/push.js.map +1 -0
  21. package/components/realtime.streams/source/create.ts +97 -0
  22. package/components/realtime.streams/source/lib/Stash.ts +133 -0
  23. package/components/realtime.streams/source/lib/Stream.ts +56 -0
  24. package/components/realtime.streams/source/lib/index.ts +2 -0
  25. package/components/realtime.streams/source/lib/types.ts +24 -0
  26. package/components/realtime.streams/source/push.ts +12 -0
  27. package/components/{streams → realtime.streams}/tsconfig.json +1 -0
  28. package/components/realtime.streams/tsconfig.tsbuildinfo +1 -0
  29. package/{components/context.toa.yaml → context.toa.yaml} +0 -1
  30. package/cucumber.mjs +5 -0
  31. package/features/static.feature +120 -0
  32. package/features/steps/Components.ts +14 -14
  33. package/features/steps/Realtime.ts +14 -18
  34. package/features/steps/Streams.ts +51 -13
  35. package/features/steps/components/messages/manifest.toa.yaml +37 -6
  36. package/features/steps/config.ts +8 -0
  37. package/package.json +8 -7
  38. package/readme.md +33 -7
  39. package/source/Composition.ts +24 -13
  40. package/source/Factory.ts +11 -13
  41. package/source/Realtime.ts +41 -13
  42. package/source/Receiver.ts +86 -0
  43. package/source/Routes.ts +14 -37
  44. package/source/extension.ts +82 -0
  45. package/source/index.ts +2 -1
  46. package/transpiled/Composition.d.ts +10 -4
  47. package/transpiled/Composition.js +21 -20
  48. package/transpiled/Composition.js.map +1 -1
  49. package/transpiled/Factory.d.ts +4 -4
  50. package/transpiled/Factory.js +13 -18
  51. package/transpiled/Factory.js.map +1 -1
  52. package/transpiled/Realtime.d.ts +3 -2
  53. package/transpiled/Realtime.js +36 -11
  54. package/transpiled/Realtime.js.map +1 -1
  55. package/transpiled/Receiver.d.ts +25 -0
  56. package/transpiled/Receiver.js +55 -0
  57. package/transpiled/Receiver.js.map +1 -0
  58. package/transpiled/Routes.d.ts +5 -10
  59. package/transpiled/Routes.js +14 -31
  60. package/transpiled/Routes.js.map +1 -1
  61. package/transpiled/extension.d.ts +19 -0
  62. package/transpiled/extension.js +48 -0
  63. package/transpiled/extension.js.map +1 -0
  64. package/transpiled/index.d.ts +2 -1
  65. package/transpiled/index.js +2 -5
  66. package/transpiled/index.js.map +1 -1
  67. package/tsconfig.json +2 -1
  68. package/tsconfig.tsbuildinfo +1 -0
  69. package/components/streams/manifest.toa.yaml +0 -21
  70. package/components/streams/operations/create.js +0 -29
  71. package/components/streams/operations/create.js.map +0 -1
  72. package/components/streams/operations/lib/stream.d.ts +0 -10
  73. package/components/streams/operations/lib/stream.js +0 -31
  74. package/components/streams/operations/lib/stream.js.map +0 -1
  75. package/components/streams/operations/push.js +0 -8
  76. package/components/streams/operations/push.js.map +0 -1
  77. package/components/streams/operations/tsconfig.tsbuildinfo +0 -1
  78. package/components/streams/operations/types.d.ts +0 -11
  79. package/components/streams/operations/types.js +0 -3
  80. package/components/streams/operations/types.js.map +0 -1
  81. package/components/streams/source/create.ts +0 -38
  82. package/components/streams/source/lib/stream.ts +0 -37
  83. package/components/streams/source/push.ts +0 -5
  84. package/components/streams/source/types.ts +0 -13
  85. package/cucumber.js +0 -8
  86. package/stage/streams.test.ts +0 -128
  87. package/transpiled/tsconfig.tsbuildinfo +0 -1
package/CHANGELOG.md ADDED
@@ -0,0 +1,323 @@
1
+ # Change Log
2
+
3
+ All notable changes to this project will be documented in this file.
4
+ See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
+
6
+ # [1.0.0-alpha.282](https://github.com/toa-io/toa/compare/v1.0.0-alpha.281...v1.0.0-alpha.282) (2026-09-03)
7
+
8
+ ### Bug Fixes
9
+
10
+ * **boot:** declare host, and build extensions with it in the step definitions ([915d957](https://github.com/toa-io/toa/commit/915d9571823358f8fca6fe19ef3aabd1b62e5605))
11
+
12
+ ### Features
13
+
14
+ * **core:** a Host for extensions ([6315eac](https://github.com/toa-io/toa/commit/6315eac1e9fb05be472272de06385c54ad5934ce))
15
+
16
+
17
+ # [1.0.0-alpha.278](https://github.com/toa-io/toa/compare/v1.0.0-alpha.277...v1.0.0-alpha.278) (2026-09-03)
18
+
19
+ **Note:** Version bump only for package @toa.io/extensions.realtime
20
+
21
+
22
+
23
+
24
+
25
+ # [1.0.0-alpha.277](https://github.com/toa-io/toa/compare/v1.0.0-alpha.276...v1.0.0-alpha.277) (2026-09-03)
26
+
27
+ ### Bug Fixes
28
+
29
+ * drop the build output that landed beside the sources ([a724f69](https://github.com/toa-io/toa/commit/a724f6921190e5c9d945e33c6035bb12d832e5c8))
30
+ * settle what the module loader made asynchronous ([d4ab9df](https://github.com/toa-io/toa/commit/d4ab9dfb09e382da311dba08f52214e7645f4a6c))
31
+ * what the loader resolves, and what it will not ([1b8a02f](https://github.com/toa-io/toa/commit/1b8a02ff0a5e0f18ee62e3f71bc81116f86f9af1))
32
+
33
+
34
+ # [1.0.0-alpha.274](https://github.com/toa-io/toa/compare/v1.0.0-alpha.273...v1.0.0-alpha.274) (2026-09-02)
35
+
36
+
37
+ * Configuration is served by a component, followed live, and kept per epoch (#1017) ([b05997d](https://github.com/toa-io/toa/commit/b05997d3adb784f238a222cb46878b23859339a2)), closes [#1017](https://github.com/toa-io/toa/issues/1017)
38
+
39
+
40
+ ### BREAKING CHANGES
41
+
42
+ * a secret configuration value is an object, not a string;
43
+ read it with `unwrap()`.
44
+
45
+ Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
46
+
47
+ * test(configuration): wait for the second round rather than assume it
48
+
49
+ Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
50
+
51
+ * refactor(configuration)!: read a secret with its own unwrap
52
+
53
+ Component code depends on no Toa package, so a secret is read as
54
+ `context.configuration.apiKey.unwrap()` and the helper in `@toa.io/generic`
55
+ goes. A value a component reads as a secret is therefore given as a reference:
56
+ `identity.basic` no longer defaults `pepper` to `''`, the development context
57
+ and the feature harness give the token keys, the federation client secret and
58
+ the signing key as references, and the harness has a step for the secrets a
59
+ scenario refers to. CONTRIBUTING states the rule.
60
+ * `identity.basic` `pepper` has no default; a value read as a
61
+ secret must be given as a `$NAME` reference.
62
+
63
+ Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
64
+
65
+ * feat(configuration): list the configurations
66
+
67
+ `configuration.values.list` returns every component's configuration for its
68
+ deployed epoch, by component name, and `GET /configuration/values/` serves it
69
+ behind `system:configuration:get`.
70
+
71
+ Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
72
+
73
+ * fix(exposition): write a value in YAML the way its toJSON says
74
+
75
+ A redacted secret in a reply was dumped as an empty object; it is written as
76
+ `<REDACTED>`, as JSON and msgpack already write it.
77
+
78
+ Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
79
+
80
+ * test(configuration): a secret is an object, and stays redacted in a reply
81
+
82
+ A component with `{ a: 1, b: $SECRET_B }` returns its configuration as
83
+ `{ a: 1, b: '<REDACTED>' }` and the secret itself through `unwrap()`. The reply
84
+ step also accepts a reply as a caller across a process boundary receives it,
85
+ since a call within the process hands the object over as it is.
86
+
87
+ Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
88
+
89
+ * chore(schemas): bump the dependencies
90
+
91
+ ajv 8.18.0 to 8.20.0, ajv-formats 2.1.1 to 3.0.1, better-ajv-errors 1.2.0
92
+ to 2.0.3, fast-glob 3.2.12 to 3.3.3 and js-yaml 4.3.1 to 5.4.1 — the version
93
+ exposition already uses. The three majors keep the CommonJS entry points this
94
+ library calls: ajv-formats as a function, better-ajv-errors as .default, and
95
+ js-yaml's load.
96
+
97
+ Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
98
+
99
+ * feat(configuration)!: serve the schema with the value
100
+
101
+ GET /configuration/values/:component/ answers { configuration, schema, epoch }
102
+ where it answered with the configuration alone, and list carries the schema of
103
+ every component. Nothing reads a configuration without needing to know what it
104
+ is checked against, and the schema was only ever on the values service.
105
+
106
+ An epoch the deployment does not know has no schema; the value stored for it
107
+ is still returned.
108
+
109
+ Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
110
+
111
+ * feat(configuration): publish a configuration UI
112
+
113
+ The values service serves a page at /.configuration on port 8003, out of the
114
+ directory ui builds: the configured components, a screen per component showing
115
+ what it holds now, and a dialog creating the next one. Reading needs
116
+ system:configuration:get and creating needs system:configuration:create.
117
+
118
+ A configuration is immutable, so the dialog opens on the current value and what
119
+ is left out of it is left out of the component. The editor takes YAML, the
120
+ schema is applied before anything is sent, and a secret is a reference the page
121
+ never shows.
122
+
123
+ The page is always published: the annotation is the per-component values map
124
+ and has nowhere to carry a switch.
125
+
126
+ Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
127
+
128
+ * feat(introspection): link a component to its configuration
129
+
130
+ A card carrying @toa.io/extensions.configuration reads that extension as a link
131
+ to the configuration UI rather than as a name, and configuration joins the
132
+ namespaces the runtime provides, so its components band under System.
133
+
134
+ Deployed, both pages sit behind the same ingress and the path alone is right;
135
+ locally each console has its own port.
136
+
137
+ Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
138
+
139
+ * feat(introspection): scroll the map, zoom with a modifier
140
+
141
+ The map was grabbed to move and zoomed with a bare wheel, which is neither what
142
+ a page does nor what the wheel does anywhere else. A plain scroll now pans on
143
+ both axes and the wheel scales only with the modifier held — a trackpad pinch
144
+ arrives as one of those on every platform.
145
+
146
+ A card's own scrollable box keeps its wheel, in both paths.
147
+
148
+ Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
149
+
150
+ * refactor(introspection): centre the filter in the header
151
+
152
+ The sides take equal space, which is what leaves the filter between them.
153
+ Neither side may shrink under what it holds, or the tabs run out from under
154
+ their side and across the filter, and the filter across the sign-out button;
155
+ the title gives way instead.
156
+
157
+ Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
158
+
159
+ * fix(configuration): connect the UI to the values service
160
+
161
+ The page was declared as a dependency from inside `open`, and a connector connects
162
+ what it depends on before `open` runs — so the server was constructed and never
163
+ listened. Nothing caught it: the UI feature builds the server itself.
164
+
165
+ Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
166
+
167
+ * feat(configuration)!: reserve resources in the annotation
168
+
169
+ The values service deploys like any other and must state what it may take, but the
170
+ annotation is a map of component ids and had nowhere to put it — so `toa env` failed
171
+ for every context using configuration unless it declared a context-wide `resources`.
172
+
173
+ `resources` is now the service's own, read the way `introspection` and `realtime` read
174
+ theirs. A component actually named `resources` is written `default.resources`, which is
175
+ what its id is anyway.
176
+
177
+ Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
178
+
179
+ * feat(configuration): follow the system colour scheme
180
+
181
+ The dark tokens were behind a `.dark` class nothing sets, and the `dark:` variant was
182
+ pointed at that class too — so a component's own dark styling never applied either.
183
+ Both now key off `prefers-color-scheme`, and `color-scheme` hands the native chrome
184
+ the same answer.
185
+
186
+ Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
187
+
188
+ * feat(introspection): follow the system colour scheme
189
+
190
+ The dark tokens were behind a `.dark` class nothing sets, and the `dark:` variant was
191
+ pointed at that class too — so a component's own dark styling never applied either.
192
+ Both now key off `prefers-color-scheme`, and `color-scheme` hands the native chrome
193
+ the same answer.
194
+
195
+ Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
196
+
197
+ * feat(configuration): present a change as an edit of what is there
198
+
199
+ A configuration is immutable and creating one replaces the whole of it, but the dialog
200
+ opens on the current value and the page never shows an older one — so what the reader
201
+ does is edit. The words follow: Edit rather than New, Update rather than Create, and
202
+ the paragraph explaining the model goes, along with the field's label, which the title
203
+ above it already said.
204
+
205
+ The editor also stayed as wide as its longest line — `field-sizing: content` sizes to
206
+ content, and no `max-width` clamps that — so a long value painted outside the dialog.
207
+ It is fixed now, the dialog takes the width the screen has rather than a fixed step,
208
+ and the band held for errors no longer leaves a gap when there are none.
209
+
210
+ Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
211
+
212
+ * feat(configuration): mark a component that keeps a secret
213
+
214
+ A key after the name on the row, wherever the configuration holds a reference, however
215
+ deep. The predicate reads the same lines the value screen renders, so the two cannot
216
+ disagree about what counts as a secret.
217
+
218
+ Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
219
+
220
+ * feat(configuration): lead back to the list from the title
221
+
222
+ Every address ends in a slash, so the way up is the address itself on the list and one
223
+ level above it on a component's screen — which holds wherever the page is mounted.
224
+
225
+ Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
226
+
227
+
228
+
229
+
230
+
231
+ # [1.0.0-alpha.273](https://github.com/toa-io/toa/compare/v1.0.0-alpha.272...v1.0.0-alpha.273) (2026-09-02)
232
+
233
+
234
+ ### Bug Fixes
235
+
236
+ * **exposition:** green the feature suite ([67c25ad](https://github.com/toa-io/toa/commit/67c25ad627db3b3779b09405c5a3c319ecd47722))
237
+ * **realtime:** green the feature suite ([6b4650b](https://github.com/toa-io/toa/commit/6b4650bad9e1d53dabd0b7775966694bdb05f236))
238
+
239
+
240
+
241
+
242
+
243
+ # [1.0.0-alpha.272](https://github.com/toa-io/toa/compare/v1.0.0-alpha.271...v1.0.0-alpha.272) (2026-09-01)
244
+
245
+ **Note:** Version bump only for package @toa.io/extensions.realtime
246
+
247
+
248
+
249
+
250
+
251
+ # [1.0.0-alpha.270](https://github.com/toa-io/toa/compare/v1.0.0-alpha.269...v1.0.0-alpha.270) (2026-08-31)
252
+
253
+ **Note:** Version bump only for package @toa.io/extensions.realtime
254
+
255
+
256
+
257
+
258
+
259
+ # [1.0.0-alpha.266](https://github.com/toa-io/toa/compare/v1.0.0-alpha.265...v1.0.0-alpha.266) (2026-08-29)
260
+
261
+ **Note:** Version bump only for package @toa.io/extensions.realtime
262
+
263
+
264
+
265
+
266
+
267
+ # [1.0.0-alpha.265](https://github.com/toa-io/toa/compare/v1.0.0-alpha.264...v1.0.0-alpha.265) (2026-08-29)
268
+
269
+ **Note:** Version bump only for package @toa.io/extensions.realtime
270
+
271
+
272
+
273
+
274
+
275
+ # [1.0.0-alpha.264](https://github.com/toa-io/toa/compare/v1.0.0-alpha.263...v1.0.0-alpha.264) (2026-08-29)
276
+
277
+ **Note:** Version bump only for package @toa.io/extensions.realtime
278
+
279
+
280
+
281
+
282
+
283
+ # [1.0.0-alpha.263](https://github.com/toa-io/toa/compare/v1.0.0-alpha.262...v1.0.0-alpha.263) (2026-08-29)
284
+
285
+ **Note:** Version bump only for package @toa.io/extensions.realtime
286
+
287
+
288
+
289
+
290
+
291
+ # [1.0.0-alpha.262](https://github.com/toa-io/toa/compare/v1.0.0-alpha.261...v1.0.0-alpha.262) (2026-08-28)
292
+
293
+
294
+ ### Features
295
+
296
+ * **core:** identify the origin of a call with `request.source` ([9da6b66](https://github.com/toa-io/toa/commit/9da6b66df852690351a1e82c7b8cc176fd89774a))
297
+
298
+
299
+
300
+
301
+
302
+ # [1.0.0-alpha.259](https://github.com/toa-io/toa/compare/v1.0.0-alpha.258...v1.0.0-alpha.259) (2026-08-24)
303
+
304
+ **Note:** Version bump only for package @toa.io/extensions.realtime
305
+
306
+
307
+
308
+
309
+
310
+ # [1.0.0-alpha.257](https://github.com/toa-io/toa/compare/v1.0.0-alpha.256...v1.0.0-alpha.257) (2026-08-24)
311
+
312
+ **Note:** Version bump only for package @toa.io/extensions.realtime
313
+
314
+
315
+
316
+
317
+
318
+ # [1.0.0-alpha.256](https://github.com/toa-io/toa/compare/v1.0.0-alpha.255...v1.0.0-alpha.256) (2026-08-23)
319
+
320
+
321
+ ### Features
322
+
323
+ * add toa mono and discover components at components/* ([787a111](https://github.com/toa-io/toa/commit/787a111c8f83e56ebc734801c97106c585d034ea))
@@ -0,0 +1,44 @@
1
+ namespace: realtime
2
+ name: streams
3
+
4
+ operations:
5
+ create:
6
+ input:
7
+ properties:
8
+ key:
9
+ type: string
10
+ token:
11
+ type: string
12
+ type: object
13
+ push:
14
+ bindings: ~ # only for internal use
15
+ input:
16
+ properties:
17
+ data: {}
18
+ key:
19
+ type: string
20
+ event:
21
+ type: string
22
+ type: object
23
+ required:
24
+ - key
25
+ - event
26
+
27
+ configuration:
28
+ schema:
29
+ properties:
30
+ maxlen:
31
+ type: number
32
+ default: 1000
33
+ expire:
34
+ type: number
35
+ default: 300
36
+ type: object
37
+
38
+ state: ~
39
+ stash: ~
40
+
41
+ exposition:
42
+ /:key:
43
+ auth:id: key
44
+ GET: create
@@ -1,14 +1,17 @@
1
- /// <reference types="node" />
2
1
  import { type Readable } from 'node:stream';
3
2
  import { type Operation } from '@toa.io/types';
4
- import { type Context } from './types';
3
+ import { type Context } from './lib/types.js';
5
4
  export declare class Effect implements Operation {
6
5
  private readonly streams;
6
+ private stash;
7
+ private logs;
7
8
  mount(context: Context): void;
8
- execute(input: Input, context: Context): Promise<Readable>;
9
+ unmount(): void;
10
+ execute(input: Input): Promise<Readable>;
9
11
  private createStream;
10
12
  }
11
13
  interface Input {
12
14
  key: string;
15
+ token?: string;
13
16
  }
14
17
  export {};
@@ -0,0 +1,65 @@
1
+ import { Stream, Stash } from './lib/index.js';
2
+ export class Effect {
3
+ streams = new Map();
4
+ stash;
5
+ logs;
6
+ mount(context) {
7
+ context.state.streams = this.streams;
8
+ context.state.stash = new Stash(context.stash, context.configuration, context.logs);
9
+ this.logs = context.logs;
10
+ this.stash = context.state.stash;
11
+ }
12
+ unmount() {
13
+ this.logs.info('Destroying streams', { count: this.streams.size });
14
+ // closed, not destroyed: destroying a stream that is still piped to a response
15
+ // makes end-of-stream report a premature close, which reaches no one and takes
16
+ // the process down.
17
+ for (const stream of this.streams.values())
18
+ stream.close();
19
+ }
20
+ async execute(input) {
21
+ const key = input.key;
22
+ if (!this.streams.has(key)) {
23
+ const stream = this.createStream(key);
24
+ this.streams.set(key, stream);
25
+ this.logs.debug('Stream created', { key });
26
+ }
27
+ // welcome
28
+ setTimeout(() => this.streams.get(key)?.heartbeat(), 1000);
29
+ if (input.token === undefined)
30
+ void this.stash.connect(key).then((token) => {
31
+ if (token instanceof Error)
32
+ this.logs.error('Failed to connect to stash', { key, error: token });
33
+ else
34
+ this.streams.get(key)?.push({ event: 'token', data: token });
35
+ });
36
+ else
37
+ void this.stash.pop(key, input.token).then((result) => {
38
+ if (result === null)
39
+ return;
40
+ if ('code' in result && result.code === 'NO_RESULTS')
41
+ return;
42
+ if (result instanceof Error) {
43
+ this.logs.error('Failed to pop from stash', { key, error: result });
44
+ return;
45
+ }
46
+ const stream = this.streams.get(key);
47
+ if (stream === undefined)
48
+ return;
49
+ const [token, events] = result;
50
+ for (const event of events)
51
+ stream.push({ event: event.event, data: event.data });
52
+ stream.push({ event: 'token', data: token });
53
+ });
54
+ return this.streams.get(key);
55
+ }
56
+ createStream(key) {
57
+ const stream = new Stream();
58
+ stream.events.once('destroy', () => {
59
+ this.logs.debug('Stream destroyed', { key });
60
+ this.streams.delete(key);
61
+ });
62
+ return stream;
63
+ }
64
+ }
65
+ //# sourceMappingURL=create.js.map
@@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,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,GAAG,MAAM,CAAA;gBAE9B,KAAK,MAAM,KAAK,IAAI,MAAiB;oBACnC,MAAM,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,CAAC,CAAA;gBAEvD,MAAM,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAA;YAC9C,CAAC,CAAC,CAAA;QAEJ,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAE,CAAA;IAC/B,CAAC;IAEO,YAAY,CAAE,GAAW;QAC/B,MAAM,MAAM,GAAG,IAAI,MAAM,EAAE,CAAA;QAE3B,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,EAAE,GAAG,EAAE;YACjC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,kBAAkB,EAAE,EAAE,GAAG,EAAE,CAAC,CAAA;YAC5C,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;QAC1B,CAAC,CAAC,CAAA;QAEF,OAAO,MAAM,CAAA;IACf,CAAC;CACF"}
@@ -0,0 +1,21 @@
1
+ export declare class Stash {
2
+ private readonly stash;
3
+ private readonly configuration;
4
+ private readonly logs;
5
+ constructor(stash: any, configuration: Configuration, logs: any);
6
+ connect(key: string): Promise<string | Error>;
7
+ push(key: string, event: string, data: unknown): Promise<string | Error>;
8
+ pop(key: string, token: string): Promise<[string, Event[]] | null | Error>;
9
+ private xadd;
10
+ private encode;
11
+ private decode;
12
+ }
13
+ interface Configuration {
14
+ maxlen: number;
15
+ expire: number;
16
+ }
17
+ interface Event {
18
+ event: string;
19
+ data: unknown;
20
+ }
21
+ export {};
@@ -0,0 +1,86 @@
1
+ export class Stash {
2
+ stash;
3
+ configuration;
4
+ logs;
5
+ constructor(stash, configuration, logs) {
6
+ this.stash = stash;
7
+ this.configuration = configuration;
8
+ this.logs = logs;
9
+ }
10
+ async connect(key) {
11
+ return await this.xadd(key, 'connect');
12
+ }
13
+ async push(key, event, data) {
14
+ return await this.xadd(key, event, data);
15
+ }
16
+ async pop(key, token) {
17
+ const stamp = this.decode(token);
18
+ const results = await this.stash
19
+ .xread('STREAMS', key, stamp)
20
+ .catch((error) => error);
21
+ if (results === null)
22
+ return ERR_NO_RESULTS;
23
+ if (results instanceof Error)
24
+ return results;
25
+ const items = entries(results);
26
+ if (items === null)
27
+ return null;
28
+ const events = [];
29
+ let lastStamp = null;
30
+ for (const item of items) {
31
+ const [, event, , json] = item[1];
32
+ lastStamp = item[0];
33
+ const data = json === undefined ? undefined : JSON.parse(json);
34
+ if (data === undefined)
35
+ this.logs.debug('Undefined event payload', { key, event });
36
+ events.push({ event, data });
37
+ }
38
+ if (lastStamp === null)
39
+ return null;
40
+ return [this.encode(lastStamp), events];
41
+ }
42
+ async xadd(key, event, data) {
43
+ const args = ['MAXLEN', '~', this.configuration.maxlen, '*', 'type', event];
44
+ if (data !== undefined)
45
+ args.push('data', JSON.stringify(data));
46
+ const results = await this.stash
47
+ .multi()
48
+ .xadd(key, ...args)
49
+ .expire(key, this.configuration.expire)
50
+ .exec()
51
+ .catch((error) => error);
52
+ if (results === null)
53
+ return ERR_NO_RESULTS;
54
+ if (results instanceof Error)
55
+ return results;
56
+ const [[error, stamp]] = results;
57
+ if (error !== null)
58
+ return error;
59
+ return this.encode(stamp);
60
+ }
61
+ encode(token) {
62
+ return Buffer.from(token).toString('base64url');
63
+ }
64
+ decode(token) {
65
+ return Buffer.from(token, 'base64url').toString();
66
+ }
67
+ }
68
+ /**
69
+ * `xread` answers with an array of `[stream, entries]` pairs over RESP2 and with an
70
+ * object keyed by stream name over RESP3. One stream is read, so either way it is the
71
+ * first, and an empty answer means nothing has been added since the token.
72
+ */
73
+ function entries(results) {
74
+ if (Array.isArray(results))
75
+ return results.length === 0 ? null : results[0][1];
76
+ if (typeof results === 'object' && results !== null) {
77
+ const streams = Object.values(results);
78
+ return streams.length === 0 ? null : streams[0];
79
+ }
80
+ return null;
81
+ }
82
+ class NoResultsError extends Error {
83
+ code = 'NO_RESULTS';
84
+ }
85
+ const ERR_NO_RESULTS = new NoResultsError();
86
+ //# sourceMappingURL=Stash.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Stash.js","sourceRoot":"","sources":["../../source/lib/Stash.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,KAAK;IACC,KAAK,CAAO;IACZ,aAAa,CAAe;IAC5B,IAAI,CAAK;IAE1B,YAAoB,KAAU,EAAE,aAA4B,EAAE,IAAS;QACrE,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;QAClB,IAAI,CAAC,aAAa,GAAG,aAAa,CAAA;QAClC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;IAClB,CAAC;IAEM,KAAK,CAAC,OAAO,CAAE,GAAW;QAC/B,OAAO,MAAM,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,SAAS,CAAC,CAAA;IACxC,CAAC;IAEM,KAAK,CAAC,IAAI,CAAE,GAAW,EAAE,KAAa,EAAE,IAAa;QAC1D,OAAO,MAAM,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,KAAK,EAAE,IAAI,CAAC,CAAA;IAC1C,CAAC;IAEM,KAAK,CAAC,GAAG,CAAE,GAAW,EAAE,KAAa;QAC1C,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;QAEhC,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,KAAK;aAC7B,KAAK,CAAC,SAAS,EAAE,GAAG,EAAE,KAAK,CAAC;aAC5B,KAAK,CAAC,CAAC,KAAY,EAAE,EAAE,CAAC,KAAK,CAAC,CAAA;QAEjC,IAAI,OAAO,KAAK,IAAI;YAClB,OAAO,cAAc,CAAA;QAEvB,IAAI,OAAO,YAAY,KAAK;YAC1B,OAAO,OAAO,CAAA;Q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,CAAC,CAAC,CAAC,CAAA;IACjD,CAAC;IAED,OAAO,IAAI,CAAA;AACb,CAAC;AAcD,MAAM,cAAe,SAAQ,KAAK;IAChB,IAAI,GAAG,YAAY,CAAA;CACpC;AAED,MAAM,cAAc,GAAG,IAAI,cAAc,EAAE,CAAA"}
@@ -0,0 +1,13 @@
1
+ import { EventEmitter } from 'node:events';
2
+ import { Readable } from 'node:stream';
3
+ export declare class Stream extends Readable {
4
+ events: EventEmitter<any>;
5
+ private interval;
6
+ private ended;
7
+ constructor();
8
+ _read(): void;
9
+ _destroy(error: Error | null, callback: (error?: (Error | null)) => void): void;
10
+ /** Ends the stream: whoever reads it gets EOF rather than a broken pipe. */
11
+ close(): void;
12
+ heartbeat(stream?: Readable): boolean;
13
+ }
@@ -0,0 +1,43 @@
1
+ import { EventEmitter } from 'node:events';
2
+ import { Readable } from 'node:stream';
3
+ export class Stream extends Readable {
4
+ events = new EventEmitter();
5
+ interval = null;
6
+ ended = false;
7
+ constructor() {
8
+ super(objectMode);
9
+ }
10
+ // has to be here
11
+ _read() {
12
+ if (this.interval === null)
13
+ this.interval = setInterval(() => this.heartbeat(), HEARTBEAT_INTERVAL);
14
+ }
15
+ _destroy(error, callback) {
16
+ if (this.interval !== null)
17
+ clearInterval(this.interval);
18
+ this.events.emit('destroy');
19
+ super._destroy(error, callback);
20
+ }
21
+ /** Ends the stream: whoever reads it gets EOF rather than a broken pipe. */
22
+ close() {
23
+ this.ended = true;
24
+ if (this.interval !== null) {
25
+ clearInterval(this.interval);
26
+ this.interval = null;
27
+ }
28
+ this.push(null);
29
+ }
30
+ heartbeat(stream = this) {
31
+ if (this.ended)
32
+ return false;
33
+ const resume = stream.push('heartbeat ' + Date.now());
34
+ if (!resume && this.interval !== null) {
35
+ clearInterval(this.interval);
36
+ this.interval = null;
37
+ }
38
+ return resume;
39
+ }
40
+ }
41
+ const HEARTBEAT_INTERVAL = 16_000; // why?
42
+ const objectMode = { objectMode: true };
43
+ //# sourceMappingURL=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AA;QAE5B,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,CAAA;QAErD,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,QAAQ,KAAK,IAAI,EAAE,CAAC;YACtC,aAAa,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;YAC5B,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAA;QACtB,CAAC;QAED,OAAO,MAAM,CAAA;IACf,CAAC;CACF;AAED,MAAM,kBAAkB,GAAG,MAAM,CAAA,CAAC,OAAO;AACzC,MAAM,UAAU,GAAG,EAAE,UAAU,EAAE,IAAI,EAAE,CAAA"}
@@ -0,0 +1,2 @@
1
+ export { Stash } from './Stash.js';
2
+ export { Stream } from './Stream.js';
@@ -0,0 +1,3 @@
1
+ export { Stash } from './Stash.js';
2
+ export { Stream } from './Stream.js';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/lib/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAClC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA"}
@@ -0,0 +1,22 @@
1
+ import { type Stream } from './Stream.js';
2
+ import { type Stash } from './Stash.js';
3
+ export interface Context {
4
+ stash: any;
5
+ state: {
6
+ streams: Map<string, Stream>;
7
+ stash: Stash;
8
+ };
9
+ logs: {
10
+ info: (m: string, att?: object) => void;
11
+ error: (m: string, att?: object) => void;
12
+ };
13
+ configuration: {
14
+ maxlen: number;
15
+ expire: number;
16
+ };
17
+ }
18
+ export interface PushInput {
19
+ key: string;
20
+ event: string;
21
+ data: unknown;
22
+ }