@toa.io/extensions.realtime 1.0.0-alpha.200 → 1.0.0-alpha.202
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/components/streams/operations/create.js +13 -8
- package/components/streams/operations/create.js.map +1 -1
- package/components/streams/operations/lib/Stream.d.ts +5 -8
- package/components/streams/operations/lib/Stream.js +3 -23
- package/components/streams/operations/lib/Stream.js.map +1 -1
- package/components/streams/operations/tsconfig.tsbuildinfo +1 -1
- package/components/streams/source/create.ts +15 -9
- package/components/streams/source/lib/Stream.ts +6 -35
- package/package.json +3 -3
- package/transpiled/tsconfig.tsbuildinfo +1 -1
|
@@ -16,20 +16,25 @@ class Effect {
|
|
|
16
16
|
}
|
|
17
17
|
async execute(input) {
|
|
18
18
|
const key = input.key;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
let stream;
|
|
20
|
+
if (!this.streams.has(key)) {
|
|
21
|
+
stream = this.createStream(key);
|
|
22
|
+
this.logs.debug('Stream created', { key });
|
|
23
|
+
}
|
|
24
|
+
else
|
|
25
|
+
stream = this.streams.get(key);
|
|
26
|
+
// welcome
|
|
27
|
+
setTimeout(() => stream?.heartbeat(), 1000);
|
|
23
28
|
return stream;
|
|
24
29
|
}
|
|
25
30
|
createStream(key) {
|
|
26
|
-
const stream = new Stream_1.Stream(
|
|
31
|
+
const stream = new Stream_1.Stream();
|
|
27
32
|
this.streams.set(key, stream);
|
|
28
|
-
stream.once('
|
|
29
|
-
this.logs.debug('Stream
|
|
33
|
+
stream.events.once('destroy', () => {
|
|
34
|
+
this.logs.debug('Stream destroyed', { key });
|
|
30
35
|
this.streams.delete(key);
|
|
31
36
|
});
|
|
32
|
-
|
|
37
|
+
return stream;
|
|
33
38
|
}
|
|
34
39
|
}
|
|
35
40
|
exports.Effect = Effect;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create.js","sourceRoot":"","sources":["../source/create.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AA;IACpB,CAAC;IAEM,KAAK,CAAC,OAAO,CAAE,KAAY;QAChC,MAAM,GAAG,GAAG,KAAK,CAAC,GAAG,CAAA;QAErB,IAAI,MAA0B,CAAA;QAE9B,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;YAC3B,MAAM,GAAG,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,CAAA;YAE/B,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,gBAAgB,EAAE,EAAE,GAAG,EAAE,CAAC,CAAA;QAC5C,CAAC;;YACC,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAE,CAAA;QAEjC,UAAU;QACV,UAAU,CAAC,GAAG,EAAE,CAAC,MAAM,EAAE,SAAS,EAAE,EAAE,IAAI,CAAC,CAAA;QAE3C,OAAO,MAAM,CAAA;IACf,CAAC;IAEO,YAAY,CAAE,GAAW;QAC/B,MAAM,MAAM,GAAG,IAAI,eAAM,EAAE,CAAA;QAE3B,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,CAAA;QAE7B,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;AA9CD,wBA8CC"}
|
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
import { EventEmitter, Readable } from 'node:stream';
|
|
3
4
|
export declare class Stream extends Readable {
|
|
4
|
-
|
|
5
|
+
events: EventEmitter<[never]>;
|
|
5
6
|
private interval;
|
|
6
|
-
|
|
7
|
-
constructor(logs: any);
|
|
8
|
-
fork(): PassThrough;
|
|
7
|
+
constructor();
|
|
9
8
|
_read(): void;
|
|
10
9
|
_destroy(error: Error | null, callback: (error?: (Error | null)) => void): void;
|
|
11
|
-
|
|
12
|
-
private increment;
|
|
13
|
-
private decrement;
|
|
10
|
+
heartbeat(stream?: Readable): boolean;
|
|
14
11
|
}
|
|
@@ -3,20 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Stream = void 0;
|
|
4
4
|
const node_stream_1 = require("node:stream");
|
|
5
5
|
class Stream extends node_stream_1.Readable {
|
|
6
|
-
|
|
6
|
+
events = new node_stream_1.EventEmitter();
|
|
7
7
|
interval = null;
|
|
8
|
-
|
|
9
|
-
constructor(logs) {
|
|
8
|
+
constructor() {
|
|
10
9
|
super(objectMode);
|
|
11
|
-
this.logs = logs;
|
|
12
|
-
}
|
|
13
|
-
fork() {
|
|
14
|
-
const through = new node_stream_1.PassThrough(objectMode);
|
|
15
|
-
through.once('close', this.decrement.bind(this));
|
|
16
|
-
this.increment();
|
|
17
|
-
// this.heartbeat(through)
|
|
18
|
-
this.pipe(through);
|
|
19
|
-
return through;
|
|
20
10
|
}
|
|
21
11
|
// has to be here
|
|
22
12
|
_read() {
|
|
@@ -26,7 +16,7 @@ class Stream extends node_stream_1.Readable {
|
|
|
26
16
|
_destroy(error, callback) {
|
|
27
17
|
if (this.interval !== null)
|
|
28
18
|
clearInterval(this.interval);
|
|
29
|
-
this.
|
|
19
|
+
this.events.emit('destroy');
|
|
30
20
|
super._destroy(error, callback);
|
|
31
21
|
}
|
|
32
22
|
heartbeat(stream = this) {
|
|
@@ -37,16 +27,6 @@ class Stream extends node_stream_1.Readable {
|
|
|
37
27
|
}
|
|
38
28
|
return resume;
|
|
39
29
|
}
|
|
40
|
-
increment() {
|
|
41
|
-
this.forks++;
|
|
42
|
-
this.logs.debug('Stream forked', { forks: this.forks });
|
|
43
|
-
}
|
|
44
|
-
decrement() {
|
|
45
|
-
this.forks--;
|
|
46
|
-
this.logs.debug('Stream fork closed', { forks: this.forks });
|
|
47
|
-
if (this.forks === 0)
|
|
48
|
-
this.destroy();
|
|
49
|
-
}
|
|
50
30
|
}
|
|
51
31
|
exports.Stream = Stream;
|
|
52
32
|
const HEARTBEAT_INTERVAL = 16_000; // why?
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Stream.js","sourceRoot":"","sources":["../../source/lib/Stream.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"Stream.js","sourceRoot":"","sources":["../../source/lib/Stream.ts"],"names":[],"mappings":";;;AAAA,6CAAoD;AAEpD,MAAa,MAAO,SAAQ,sBAAQ;IAC3B,MAAM,GAAG,IAAI,0BAAY,EAAE,CAAA;IAE1B,QAAQ,GAA0B,IAAI,CAAA;IAE9C;QACE,KAAK,CAAC,UAAU,CAAC,CAAA;IACnB,CAAC;IAED,iBAAiB;IACD,KAAK;QACnB,IAAI,IAAI,CAAC,QAAQ,KAAK,IAAI;YACxB,IAAI,CAAC,QAAQ,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,SAAS,EAAE,EAAE,kBAAkB,CAAC,CAAA;IAC3E,CAAC;IAEe,QAAQ,CAAE,KAAmB,EAAE,QAA0C;QACvF,IAAI,IAAI,CAAC,QAAQ,KAAK,IAAI;YACxB,aAAa,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;QAE9B,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;QAE3B,KAAK,CAAC,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAA;IACjC,CAAC;IAEM,SAAS,CAAE,SAAmB,IAAI;QACvC,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,CAAA;QAErD,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,QA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