gingersnap 0.22.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/_virtual/_tslib.cjs +102 -0
- package/_virtual/_tslib.mjs +93 -0
- package/data/AtomicValue.d.ts +15 -0
- package/data/bus.cjs +179 -0
- package/data/bus.d.ts +72 -0
- package/data/bus.mjs +177 -0
- package/data/decoders/index.d.ts +4 -0
- package/data/decoders/json.cjs +12 -0
- package/data/decoders/json.d.ts +7 -0
- package/data/decoders/json.mjs +10 -0
- package/data/decoders/msgpack.cjs +14 -0
- package/data/decoders/msgpack.d.ts +7 -0
- package/data/decoders/msgpack.mjs +12 -0
- package/data/decoders/protobuf.d.ts +13 -0
- package/data/decoders/string.cjs +12 -0
- package/data/decoders/string.d.ts +7 -0
- package/data/decoders/string.mjs +10 -0
- package/data/decoders/type.d.ts +7 -0
- package/data/decoders.cjs +11 -0
- package/data/decoders.mjs +3 -0
- package/data/model/credentials.cjs +114 -0
- package/data/model/credentials.d.ts +61 -0
- package/data/model/credentials.mjs +109 -0
- package/data/model/extra.cjs +88 -0
- package/data/model/extra.d.ts +5 -0
- package/data/model/extra.mjs +66 -0
- package/data/model/index.d.ts +6 -0
- package/data/model/model.cjs +541 -0
- package/data/model/model.d.ts +207 -0
- package/data/model/model.mjs +518 -0
- package/data/model/plugin.cjs +96 -0
- package/data/model/plugin.d.ts +38 -0
- package/data/model/plugin.mjs +72 -0
- package/data/model/property.cjs +310 -0
- package/data/model/property.d.ts +83 -0
- package/data/model/property.mjs +278 -0
- package/data/model/types.cjs +32 -0
- package/data/model/types.d.ts +28 -0
- package/data/model/types.mjs +32 -0
- package/data/model.cjs +43 -0
- package/data/model.mjs +6 -0
- package/data/signal.cjs +47 -0
- package/data/signal.d.ts +17 -0
- package/data/signal.mjs +45 -0
- package/data/store/index.d.ts +4 -0
- package/data/store/json.cjs +58 -0
- package/data/store/json.d.ts +18 -0
- package/data/store/json.mjs +56 -0
- package/data/store/manager.cjs +206 -0
- package/data/store/manager.d.ts +44 -0
- package/data/store/manager.mjs +203 -0
- package/data/store/web.cjs +92 -0
- package/data/store/web.d.ts +25 -0
- package/data/store/web.mjs +89 -0
- package/data/value.cjs +66 -0
- package/data/value.mjs +64 -0
- package/data-structures/array/CyclicalList.cjs +57 -0
- package/data-structures/array/CyclicalList.d.ts +12 -0
- package/data-structures/array/CyclicalList.mjs +55 -0
- package/data-structures/array/Pair.cjs +30 -0
- package/data-structures/array/Pair.d.ts +17 -0
- package/data-structures/array/Pair.mjs +27 -0
- package/data-structures/array/Stack.cjs +96 -0
- package/data-structures/array/Stack.d.ts +41 -0
- package/data-structures/array/Stack.mjs +94 -0
- package/data-structures/array/Triple.cjs +34 -0
- package/data-structures/array/Triple.d.ts +19 -0
- package/data-structures/array/Triple.mjs +31 -0
- package/data-structures/array/Tuple.d.ts +8 -0
- package/data-structures/array/index.d.ts +5 -0
- package/data-structures/array.cjs +15 -0
- package/data-structures/array.mjs +4 -0
- package/data-structures/object/BufferQueue.cjs +98 -0
- package/data-structures/object/BufferQueue.d.ts +21 -0
- package/data-structures/object/BufferQueue.mjs +77 -0
- package/data-structures/object/CyclicalObject.cjs +155 -0
- package/data-structures/object/CyclicalObject.d.ts +74 -0
- package/data-structures/object/CyclicalObject.mjs +134 -0
- package/data-structures/object/Queue.cjs +178 -0
- package/data-structures/object/Queue.d.ts +31 -0
- package/data-structures/object/Queue.mjs +176 -0
- package/data-structures/object/SimpleQueue.cjs +53 -0
- package/data-structures/object/SimpleQueue.d.ts +13 -0
- package/data-structures/object/SimpleQueue.mjs +51 -0
- package/data-structures/object/TimeableObject.cjs +73 -0
- package/data-structures/object/TimeableObject.d.ts +30 -0
- package/data-structures/object/TimeableObject.mjs +71 -0
- package/data-structures/object/WaitableObject.cjs +61 -0
- package/data-structures/object/WaitableObject.d.ts +29 -0
- package/data-structures/object/WaitableObject.mjs +59 -0
- package/data-structures/object/WatchableObject.cjs +251 -0
- package/data-structures/object/WatchableObject.d.ts +88 -0
- package/data-structures/object/WatchableObject.mjs +230 -0
- package/data-structures/object/index.d.ts +7 -0
- package/data-structures/object.cjs +23 -0
- package/data-structures/object.mjs +7 -0
- package/errors/AbortError.cjs +9 -0
- package/errors/AbortError.d.ts +5 -0
- package/errors/AbortError.mjs +7 -0
- package/errors/CallExecutionError.cjs +13 -0
- package/errors/CallExecutionError.d.ts +7 -0
- package/errors/CallExecutionError.mjs +11 -0
- package/errors/FutureCancelled.cjs +11 -0
- package/errors/FutureCancelled.d.ts +6 -0
- package/errors/FutureCancelled.mjs +9 -0
- package/errors/FutureError.cjs +11 -0
- package/errors/FutureError.d.ts +6 -0
- package/errors/FutureError.mjs +9 -0
- package/errors/IllegalArgumentsError.cjs +13 -0
- package/errors/IllegalArgumentsError.d.ts +7 -0
- package/errors/IllegalArgumentsError.mjs +11 -0
- package/errors/IllegalOperationError.cjs +6 -0
- package/errors/IllegalOperationError.d.ts +2 -0
- package/errors/IllegalOperationError.mjs +4 -0
- package/errors/InvalidType.cjs +6 -0
- package/errors/InvalidType.d.ts +2 -0
- package/errors/InvalidType.mjs +4 -0
- package/errors/InvalidValue.cjs +11 -0
- package/errors/InvalidValue.d.ts +4 -0
- package/errors/InvalidValue.mjs +9 -0
- package/errors/MissingArgumentsError.cjs +13 -0
- package/errors/MissingArgumentsError.d.ts +7 -0
- package/errors/MissingArgumentsError.mjs +11 -0
- package/errors/NetworkError.cjs +13 -0
- package/errors/NetworkError.d.ts +8 -0
- package/errors/NetworkError.mjs +11 -0
- package/errors/NoSuchElement.cjs +6 -0
- package/errors/NoSuchElement.d.ts +2 -0
- package/errors/NoSuchElement.mjs +4 -0
- package/errors/NotImplemented.cjs +9 -0
- package/errors/NotImplemented.d.ts +5 -0
- package/errors/NotImplemented.mjs +7 -0
- package/errors/ParsingError.cjs +10 -0
- package/errors/ParsingError.d.ts +5 -0
- package/errors/ParsingError.mjs +8 -0
- package/errors/QueueEmptyError.cjs +6 -0
- package/errors/QueueEmptyError.d.ts +2 -0
- package/errors/QueueEmptyError.mjs +4 -0
- package/errors/QueueFullError.cjs +6 -0
- package/errors/QueueFullError.d.ts +2 -0
- package/errors/QueueFullError.mjs +4 -0
- package/errors/StackEmptyError.cjs +6 -0
- package/errors/StackEmptyError.d.ts +2 -0
- package/errors/StackEmptyError.mjs +4 -0
- package/errors/StackFullError.cjs +6 -0
- package/errors/StackFullError.d.ts +2 -0
- package/errors/StackFullError.mjs +4 -0
- package/errors/StreamEnded.cjs +6 -0
- package/errors/StreamEnded.d.ts +2 -0
- package/errors/StreamEnded.mjs +4 -0
- package/errors/TimeoutError.cjs +11 -0
- package/errors/TimeoutError.d.ts +6 -0
- package/errors/TimeoutError.mjs +9 -0
- package/errors/ValueDestroyedError.cjs +6 -0
- package/errors/ValueDestroyedError.d.ts +2 -0
- package/errors/ValueDestroyedError.mjs +4 -0
- package/errors/VerificationError.cjs +9 -0
- package/errors/VerificationError.d.ts +5 -0
- package/errors/VerificationError.mjs +7 -0
- package/errors/index.d.ts +18 -0
- package/errors.cjs +41 -0
- package/errors.mjs +18 -0
- package/files.cjs +201 -0
- package/files.d.ts +31 -0
- package/files.mjs +180 -0
- package/functools/index.d.ts +31 -0
- package/functools.cjs +371 -0
- package/functools.mjs +334 -0
- package/future/future.cjs +570 -0
- package/future/future.d.ts +208 -0
- package/future/future.mjs +548 -0
- package/future/group.cjs +180 -0
- package/future/group.d.ts +82 -0
- package/future/group.mjs +159 -0
- package/future/index.d.ts +3 -0
- package/future/result.cjs +19 -0
- package/future/result.d.ts +18 -0
- package/future/result.mjs +17 -0
- package/future.cjs +11 -0
- package/future.mjs +3 -0
- package/managers/context.d.ts +8 -0
- package/managers/index.d.ts +1 -0
- package/managers.cjs +2 -0
- package/managers.mjs +1 -0
- package/mocks.cjs +301 -0
- package/mocks.d.ts +125 -0
- package/mocks.mjs +293 -0
- package/networking/EventSourceService.cjs +104 -0
- package/networking/EventSourceService.d.ts +11 -0
- package/networking/EventSourceService.mjs +83 -0
- package/networking/NetworkService.cjs +394 -0
- package/networking/NetworkService.d.ts +97 -0
- package/networking/NetworkService.mjs +373 -0
- package/networking/SocketService.cjs +218 -0
- package/networking/SocketService.d.ts +23 -0
- package/networking/SocketService.mjs +197 -0
- package/networking/decorators/index.d.ts +4 -0
- package/networking/decorators/options.cjs +289 -0
- package/networking/decorators/options.d.ts +148 -0
- package/networking/decorators/options.mjs +242 -0
- package/networking/decorators/requests.cjs +80 -0
- package/networking/decorators/requests.d.ts +34 -0
- package/networking/decorators/requests.mjs +52 -0
- package/networking/decorators/socket.cjs +81 -0
- package/networking/decorators/socket.d.ts +13 -0
- package/networking/decorators/socket.mjs +51 -0
- package/networking/http.cjs +69 -0
- package/networking/http.d.ts +66 -0
- package/networking/http.mjs +69 -0
- package/networking/index.d.ts +39 -0
- package/networking/request.cjs +18 -0
- package/networking/request.d.ts +9 -0
- package/networking/request.mjs +16 -0
- package/networking/types.cjs +37 -0
- package/networking/types.d.ts +132 -0
- package/networking/types.mjs +35 -0
- package/networking.cjs +91 -0
- package/networking.mjs +33 -0
- package/package.json +1 -0
- package/reflection/injector.cjs +43 -0
- package/reflection/injector.d.ts +3 -0
- package/reflection/injector.mjs +40 -0
- package/socket.cjs +239 -0
- package/socket.d.ts +65 -0
- package/socket.mjs +237 -0
- package/store.cjs +12 -0
- package/store.mjs +3 -0
- package/stream/call.cjs +157 -0
- package/stream/call.d.ts +66 -0
- package/stream/call.mjs +154 -0
- package/stream/collector.cjs +217 -0
- package/stream/collector.d.ts +14 -0
- package/stream/collector.mjs +215 -0
- package/stream/index.d.ts +257 -0
- package/stream/observable.cjs +110 -0
- package/stream/observable.d.ts +65 -0
- package/stream/observable.mjs +106 -0
- package/stream/state.cjs +10 -0
- package/stream/state.d.ts +5 -0
- package/stream/state.mjs +8 -0
- package/stream.cjs +1153 -0
- package/stream.mjs +1132 -0
- package/synchronize.cjs +106 -0
- package/synchronize.d.ts +54 -0
- package/synchronize.mjs +103 -0
- package/typing/types.d.ts +24 -0
- package/typing.cjs +2 -0
- package/typing.mjs +1 -0
- package/utils/parser.cjs +37 -0
- package/utils/parser.d.ts +7 -0
- package/utils/parser.mjs +16 -0
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/******************************************************************************
|
|
4
|
+
Copyright (c) Microsoft Corporation.
|
|
5
|
+
|
|
6
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
7
|
+
purpose with or without fee is hereby granted.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
10
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
11
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
12
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
13
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
14
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
15
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
16
|
+
***************************************************************************** */
|
|
17
|
+
/* global Reflect, Promise, SuppressedError, Symbol */
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
function __rest(s, e) {
|
|
21
|
+
var t = {};
|
|
22
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
23
|
+
t[p] = s[p];
|
|
24
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
25
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
26
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
27
|
+
t[p[i]] = s[p[i]];
|
|
28
|
+
}
|
|
29
|
+
return t;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function __decorate(decorators, target, key, desc) {
|
|
33
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
34
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
35
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
36
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function __metadata(metadataKey, metadataValue) {
|
|
40
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
44
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
45
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
46
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
47
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
48
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
49
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function __values(o) {
|
|
54
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
55
|
+
if (m) return m.call(o);
|
|
56
|
+
if (o && typeof o.length === "number") return {
|
|
57
|
+
next: function () {
|
|
58
|
+
if (o && i >= o.length) o = void 0;
|
|
59
|
+
return { value: o && o[i++], done: !o };
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function __await(v) {
|
|
66
|
+
return this instanceof __await ? (this.v = v, this) : new __await(v);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function __asyncGenerator(thisArg, _arguments, generator) {
|
|
70
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
71
|
+
var g = generator.apply(thisArg, _arguments || []), i, q = [];
|
|
72
|
+
return i = {}, verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function () { return this; }, i;
|
|
73
|
+
function awaitReturn(f) { return function (v) { return Promise.resolve(v).then(f, reject); }; }
|
|
74
|
+
function verb(n, f) { if (g[n]) { i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; if (f) i[n] = f(i[n]); } }
|
|
75
|
+
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
|
|
76
|
+
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
|
|
77
|
+
function fulfill(value) { resume("next", value); }
|
|
78
|
+
function reject(value) { resume("throw", value); }
|
|
79
|
+
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function __asyncValues(o) {
|
|
83
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
84
|
+
var m = o[Symbol.asyncIterator], i;
|
|
85
|
+
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
|
86
|
+
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
|
87
|
+
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
91
|
+
var e = new Error(message);
|
|
92
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
exports.__asyncGenerator = __asyncGenerator;
|
|
96
|
+
exports.__asyncValues = __asyncValues;
|
|
97
|
+
exports.__await = __await;
|
|
98
|
+
exports.__awaiter = __awaiter;
|
|
99
|
+
exports.__decorate = __decorate;
|
|
100
|
+
exports.__metadata = __metadata;
|
|
101
|
+
exports.__rest = __rest;
|
|
102
|
+
exports.__values = __values;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/******************************************************************************
|
|
2
|
+
Copyright (c) Microsoft Corporation.
|
|
3
|
+
|
|
4
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
5
|
+
purpose with or without fee is hereby granted.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
8
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
9
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
10
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
11
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
12
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
13
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
14
|
+
***************************************************************************** */
|
|
15
|
+
/* global Reflect, Promise, SuppressedError, Symbol */
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
function __rest(s, e) {
|
|
19
|
+
var t = {};
|
|
20
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
21
|
+
t[p] = s[p];
|
|
22
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
23
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
24
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
25
|
+
t[p[i]] = s[p[i]];
|
|
26
|
+
}
|
|
27
|
+
return t;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function __decorate(decorators, target, key, desc) {
|
|
31
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
32
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
33
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
34
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function __metadata(metadataKey, metadataValue) {
|
|
38
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
42
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
43
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
44
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
45
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
46
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
47
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function __values(o) {
|
|
52
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
53
|
+
if (m) return m.call(o);
|
|
54
|
+
if (o && typeof o.length === "number") return {
|
|
55
|
+
next: function () {
|
|
56
|
+
if (o && i >= o.length) o = void 0;
|
|
57
|
+
return { value: o && o[i++], done: !o };
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function __await(v) {
|
|
64
|
+
return this instanceof __await ? (this.v = v, this) : new __await(v);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function __asyncGenerator(thisArg, _arguments, generator) {
|
|
68
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
69
|
+
var g = generator.apply(thisArg, _arguments || []), i, q = [];
|
|
70
|
+
return i = {}, verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function () { return this; }, i;
|
|
71
|
+
function awaitReturn(f) { return function (v) { return Promise.resolve(v).then(f, reject); }; }
|
|
72
|
+
function verb(n, f) { if (g[n]) { i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; if (f) i[n] = f(i[n]); } }
|
|
73
|
+
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
|
|
74
|
+
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
|
|
75
|
+
function fulfill(value) { resume("next", value); }
|
|
76
|
+
function reject(value) { resume("throw", value); }
|
|
77
|
+
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function __asyncValues(o) {
|
|
81
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
82
|
+
var m = o[Symbol.asyncIterator], i;
|
|
83
|
+
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
|
84
|
+
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
|
85
|
+
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
89
|
+
var e = new Error(message);
|
|
90
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
export { __asyncGenerator, __asyncValues, __await, __awaiter, __decorate, __metadata, __rest, __values };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Future } from "../future";
|
|
2
|
+
import { Stream } from "../stream";
|
|
3
|
+
export declare class AtomicValue<T> {
|
|
4
|
+
private value;
|
|
5
|
+
private closed;
|
|
6
|
+
private readonly setEvt;
|
|
7
|
+
private readonly setLock;
|
|
8
|
+
constructor();
|
|
9
|
+
set(value: T): Future<void>;
|
|
10
|
+
get(): Future<T>;
|
|
11
|
+
pop(): Future<T>;
|
|
12
|
+
destroy(): void;
|
|
13
|
+
get stream(): Stream<T>;
|
|
14
|
+
private read;
|
|
15
|
+
}
|
package/data/bus.cjs
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var stream_observable = require('../stream/observable.cjs');
|
|
4
|
+
var future = require('../future/future.cjs');
|
|
5
|
+
require('ramda');
|
|
6
|
+
var stream = require('../stream.cjs');
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* A controller than manages exchanging data between various consumers
|
|
10
|
+
*/
|
|
11
|
+
class DataBus extends stream_observable.Observable {
|
|
12
|
+
constructor() {
|
|
13
|
+
super();
|
|
14
|
+
this.observables = new Map();
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Used inside a WebWorker to accept incoming Observable, that grants
|
|
18
|
+
* connection to a DataBus
|
|
19
|
+
*/
|
|
20
|
+
static workerJoin() {
|
|
21
|
+
return future.Future.of((resolve, _, signal) => {
|
|
22
|
+
const listener = (evt) => {
|
|
23
|
+
if (evt.data.command === "__join_data_bus__") {
|
|
24
|
+
resolve(new stream_observable.ObservableMessagePort(evt.ports[0]));
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
signal.onabort = () => self.removeEventListener("message", listener);
|
|
28
|
+
self.addEventListener("message", listener, { once: true });
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Redirects incoming messages from a particular consumer to one or more other
|
|
33
|
+
* consumers
|
|
34
|
+
* @param topic used to listen to specific incoming message
|
|
35
|
+
* @param consumer the consumer to republish data to. to send to all consumers, set value to '*'
|
|
36
|
+
* @param topicTransformer allows changing the topic of the incoming data that should be republished (optional)
|
|
37
|
+
* @param bufferSize
|
|
38
|
+
* @param expiryPeriod
|
|
39
|
+
*/
|
|
40
|
+
republish(topic, consumer, topicTransformer = (v) => v, bufferSize = undefined, expiryPeriod = undefined) {
|
|
41
|
+
return this.subscribe(topic, bufferSize, expiryPeriod)
|
|
42
|
+
.map(({ topic: consumerTopic, data }) => this.publish(`${consumer}.${topicTransformer(consumerTopic)}`, data))
|
|
43
|
+
.consume()
|
|
44
|
+
.schedule();
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Dispatches message to specific consumers listen on the given topic
|
|
48
|
+
* Format is [consumer/s].[topic]
|
|
49
|
+
* E.g 1: jobs.submission, where a consumer is named 'jobs' and is listening for
|
|
50
|
+
* messages on the topic 'submission'
|
|
51
|
+
*
|
|
52
|
+
* E.g 2: *.submission, where any consumer that is listening for messages on the
|
|
53
|
+
* topic 'submission'
|
|
54
|
+
*
|
|
55
|
+
* E.g 3: [users,admins].signup where consumer named 'users' and consumer named
|
|
56
|
+
* 'admins' is listening for messages on the topic 'signup'
|
|
57
|
+
*
|
|
58
|
+
* @param topic
|
|
59
|
+
* @param data
|
|
60
|
+
*/
|
|
61
|
+
publish(topic, data) {
|
|
62
|
+
if (topic.startsWith("*.")) {
|
|
63
|
+
this.observables.forEach((observable) => observable.publish(topic.substring(2), data));
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
const [consumer, realTopic] = topic.split(".", 2);
|
|
67
|
+
const observables = [];
|
|
68
|
+
if (consumer.startsWith("[") && consumer.endsWith("]")) {
|
|
69
|
+
observables.push(...consumer
|
|
70
|
+
.substring(1, consumer.length - 1)
|
|
71
|
+
.split(",")
|
|
72
|
+
.map((v) => {
|
|
73
|
+
const observable = this.observables.get(v.trim());
|
|
74
|
+
if (!observable) {
|
|
75
|
+
throw new Error(`Invalid observer ${v}`);
|
|
76
|
+
}
|
|
77
|
+
return observable;
|
|
78
|
+
}));
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
const observable = this.observables.get(consumer);
|
|
82
|
+
if (!observable) {
|
|
83
|
+
throw new Error(`Invalid observer ${consumer}`);
|
|
84
|
+
}
|
|
85
|
+
observables.push(observable);
|
|
86
|
+
}
|
|
87
|
+
observables.forEach((observable) => observable.publish(realTopic, data));
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Subscribes to incoming messages on the given topic, where topic represents
|
|
92
|
+
* [consumer/s].topic
|
|
93
|
+
* @param topic
|
|
94
|
+
* @param bufferSize
|
|
95
|
+
* @param expiryPeriod
|
|
96
|
+
*/
|
|
97
|
+
subscribe(topic, bufferSize, expiryPeriod) {
|
|
98
|
+
if (typeof topic === "string") {
|
|
99
|
+
if (topic.startsWith("*.")) {
|
|
100
|
+
return stream.Stream.merge(Array.from(this.observables.values()).map((observable) => observable.subscribe(topic.substring(2), bufferSize, expiryPeriod)));
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
const [consumer, realTopic] = topic.split(".", 2);
|
|
104
|
+
const observables = [];
|
|
105
|
+
if (consumer.startsWith("[") && consumer.endsWith("]")) {
|
|
106
|
+
observables.push(...consumer
|
|
107
|
+
.substring(1, consumer.length - 1)
|
|
108
|
+
.split(",")
|
|
109
|
+
.map((v) => {
|
|
110
|
+
const observable = this.observables.get(v);
|
|
111
|
+
if (!observable) {
|
|
112
|
+
throw new Error(`Invalid observer ${v}`);
|
|
113
|
+
}
|
|
114
|
+
return observable;
|
|
115
|
+
}));
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
const observable = this.observables.get(consumer);
|
|
119
|
+
if (!observable) {
|
|
120
|
+
throw new Error(`Invalid observer ${consumer}`);
|
|
121
|
+
}
|
|
122
|
+
observables.push(observable);
|
|
123
|
+
}
|
|
124
|
+
return stream.Stream.merge(Array.from(observables.values()).map((observable) => observable.subscribe(realTopic, bufferSize, expiryPeriod)));
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return stream.Stream.merge(Array.from(this.observables.entries()).map(([key, observable]) => observable
|
|
128
|
+
.subscribe("*", bufferSize, expiryPeriod)
|
|
129
|
+
.filter(({ topic: subTopic }) => topic.test(`${key}.${subTopic}`))));
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Registers a WebWorker as a consumer. The worker needs to accept the connection
|
|
133
|
+
* by calling DataBus.workerJoin()
|
|
134
|
+
* @param worker
|
|
135
|
+
* @param name
|
|
136
|
+
* @param workerBufferSize
|
|
137
|
+
*/
|
|
138
|
+
connectWorker(worker, name, workerBufferSize = undefined) {
|
|
139
|
+
if (name.includes(".")) {
|
|
140
|
+
throw new Error("period cannot exist in consumer name");
|
|
141
|
+
}
|
|
142
|
+
if (this.observables.has(name)) {
|
|
143
|
+
throw new Error("worker already added");
|
|
144
|
+
}
|
|
145
|
+
const { port1, port2 } = new MessageChannel();
|
|
146
|
+
worker.postMessage({
|
|
147
|
+
command: "__join_data_bus__",
|
|
148
|
+
workerName: name,
|
|
149
|
+
}, [port2]);
|
|
150
|
+
const observable = new stream_observable.ObservableMessagePort(port1);
|
|
151
|
+
this.observables.set(name, observable);
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Provides a consumer with a connection to the data bus, where the consumer
|
|
155
|
+
* can dispatch messages and respond to other data
|
|
156
|
+
* @param name name required for consumer to receive incoming messages. Will be
|
|
157
|
+
* used as a part of the topics when message is being dispatched
|
|
158
|
+
*/
|
|
159
|
+
connectConsumer(name) {
|
|
160
|
+
if (name.includes(".")) {
|
|
161
|
+
throw new Error("period cannot exist in consumer name");
|
|
162
|
+
}
|
|
163
|
+
if (this.observables.has(name)) {
|
|
164
|
+
throw new Error("consumer already added");
|
|
165
|
+
}
|
|
166
|
+
const observable = new stream_observable.ObservableEventTarget();
|
|
167
|
+
this.observables.set(name, observable);
|
|
168
|
+
return observable;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Disconnects the given consumer from receiving messages from the bus
|
|
172
|
+
* @param name
|
|
173
|
+
*/
|
|
174
|
+
disconnectConsumer(name) {
|
|
175
|
+
this.observables.delete(name);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
exports.DataBus = DataBus;
|
package/data/bus.d.ts
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { Observable } from "../stream/observable";
|
|
2
|
+
import { Future, WaitPeriod } from "../future";
|
|
3
|
+
import { Stream } from "../stream";
|
|
4
|
+
/**
|
|
5
|
+
* A controller than manages exchanging data between various consumers
|
|
6
|
+
*/
|
|
7
|
+
export declare class DataBus<T = any> extends Observable<T> {
|
|
8
|
+
private readonly observables;
|
|
9
|
+
constructor();
|
|
10
|
+
/**
|
|
11
|
+
* Used inside a WebWorker to accept incoming Observable, that grants
|
|
12
|
+
* connection to a DataBus
|
|
13
|
+
*/
|
|
14
|
+
static workerJoin<T>(): Future<Observable<T>>;
|
|
15
|
+
/**
|
|
16
|
+
* Redirects incoming messages from a particular consumer to one or more other
|
|
17
|
+
* consumers
|
|
18
|
+
* @param topic used to listen to specific incoming message
|
|
19
|
+
* @param consumer the consumer to republish data to. to send to all consumers, set value to '*'
|
|
20
|
+
* @param topicTransformer allows changing the topic of the incoming data that should be republished (optional)
|
|
21
|
+
* @param bufferSize
|
|
22
|
+
* @param expiryPeriod
|
|
23
|
+
*/
|
|
24
|
+
republish(topic: string, consumer: string, topicTransformer?: (v: string) => string, bufferSize?: number | undefined, expiryPeriod?: WaitPeriod | undefined): Future<void>;
|
|
25
|
+
/**
|
|
26
|
+
* Dispatches message to specific consumers listen on the given topic
|
|
27
|
+
* Format is [consumer/s].[topic]
|
|
28
|
+
* E.g 1: jobs.submission, where a consumer is named 'jobs' and is listening for
|
|
29
|
+
* messages on the topic 'submission'
|
|
30
|
+
*
|
|
31
|
+
* E.g 2: *.submission, where any consumer that is listening for messages on the
|
|
32
|
+
* topic 'submission'
|
|
33
|
+
*
|
|
34
|
+
* E.g 3: [users,admins].signup where consumer named 'users' and consumer named
|
|
35
|
+
* 'admins' is listening for messages on the topic 'signup'
|
|
36
|
+
*
|
|
37
|
+
* @param topic
|
|
38
|
+
* @param data
|
|
39
|
+
*/
|
|
40
|
+
publish(topic: string, data: T): void;
|
|
41
|
+
/**
|
|
42
|
+
* Subscribes to incoming messages on the given topic, where topic represents
|
|
43
|
+
* [consumer/s].topic
|
|
44
|
+
* @param topic
|
|
45
|
+
* @param bufferSize
|
|
46
|
+
* @param expiryPeriod
|
|
47
|
+
*/
|
|
48
|
+
subscribe(topic: string | RegExp, bufferSize?: number, expiryPeriod?: WaitPeriod): Stream<{
|
|
49
|
+
topic: string;
|
|
50
|
+
data: T;
|
|
51
|
+
}>;
|
|
52
|
+
/**
|
|
53
|
+
* Registers a WebWorker as a consumer. The worker needs to accept the connection
|
|
54
|
+
* by calling DataBus.workerJoin()
|
|
55
|
+
* @param worker
|
|
56
|
+
* @param name
|
|
57
|
+
* @param workerBufferSize
|
|
58
|
+
*/
|
|
59
|
+
connectWorker(worker: Worker, name: string, workerBufferSize?: number | undefined): void;
|
|
60
|
+
/**
|
|
61
|
+
* Provides a consumer with a connection to the data bus, where the consumer
|
|
62
|
+
* can dispatch messages and respond to other data
|
|
63
|
+
* @param name name required for consumer to receive incoming messages. Will be
|
|
64
|
+
* used as a part of the topics when message is being dispatched
|
|
65
|
+
*/
|
|
66
|
+
connectConsumer(name: string): Observable<T>;
|
|
67
|
+
/**
|
|
68
|
+
* Disconnects the given consumer from receiving messages from the bus
|
|
69
|
+
* @param name
|
|
70
|
+
*/
|
|
71
|
+
disconnectConsumer(name: string): void;
|
|
72
|
+
}
|
package/data/bus.mjs
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { Observable, ObservableMessagePort, ObservableEventTarget } from '../stream/observable.mjs';
|
|
2
|
+
import { Future } from '../future/future.mjs';
|
|
3
|
+
import 'ramda';
|
|
4
|
+
import { Stream } from '../stream.mjs';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A controller than manages exchanging data between various consumers
|
|
8
|
+
*/
|
|
9
|
+
class DataBus extends Observable {
|
|
10
|
+
constructor() {
|
|
11
|
+
super();
|
|
12
|
+
this.observables = new Map();
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Used inside a WebWorker to accept incoming Observable, that grants
|
|
16
|
+
* connection to a DataBus
|
|
17
|
+
*/
|
|
18
|
+
static workerJoin() {
|
|
19
|
+
return Future.of((resolve, _, signal) => {
|
|
20
|
+
const listener = (evt) => {
|
|
21
|
+
if (evt.data.command === "__join_data_bus__") {
|
|
22
|
+
resolve(new ObservableMessagePort(evt.ports[0]));
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
signal.onabort = () => self.removeEventListener("message", listener);
|
|
26
|
+
self.addEventListener("message", listener, { once: true });
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Redirects incoming messages from a particular consumer to one or more other
|
|
31
|
+
* consumers
|
|
32
|
+
* @param topic used to listen to specific incoming message
|
|
33
|
+
* @param consumer the consumer to republish data to. to send to all consumers, set value to '*'
|
|
34
|
+
* @param topicTransformer allows changing the topic of the incoming data that should be republished (optional)
|
|
35
|
+
* @param bufferSize
|
|
36
|
+
* @param expiryPeriod
|
|
37
|
+
*/
|
|
38
|
+
republish(topic, consumer, topicTransformer = (v) => v, bufferSize = undefined, expiryPeriod = undefined) {
|
|
39
|
+
return this.subscribe(topic, bufferSize, expiryPeriod)
|
|
40
|
+
.map(({ topic: consumerTopic, data }) => this.publish(`${consumer}.${topicTransformer(consumerTopic)}`, data))
|
|
41
|
+
.consume()
|
|
42
|
+
.schedule();
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Dispatches message to specific consumers listen on the given topic
|
|
46
|
+
* Format is [consumer/s].[topic]
|
|
47
|
+
* E.g 1: jobs.submission, where a consumer is named 'jobs' and is listening for
|
|
48
|
+
* messages on the topic 'submission'
|
|
49
|
+
*
|
|
50
|
+
* E.g 2: *.submission, where any consumer that is listening for messages on the
|
|
51
|
+
* topic 'submission'
|
|
52
|
+
*
|
|
53
|
+
* E.g 3: [users,admins].signup where consumer named 'users' and consumer named
|
|
54
|
+
* 'admins' is listening for messages on the topic 'signup'
|
|
55
|
+
*
|
|
56
|
+
* @param topic
|
|
57
|
+
* @param data
|
|
58
|
+
*/
|
|
59
|
+
publish(topic, data) {
|
|
60
|
+
if (topic.startsWith("*.")) {
|
|
61
|
+
this.observables.forEach((observable) => observable.publish(topic.substring(2), data));
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
const [consumer, realTopic] = topic.split(".", 2);
|
|
65
|
+
const observables = [];
|
|
66
|
+
if (consumer.startsWith("[") && consumer.endsWith("]")) {
|
|
67
|
+
observables.push(...consumer
|
|
68
|
+
.substring(1, consumer.length - 1)
|
|
69
|
+
.split(",")
|
|
70
|
+
.map((v) => {
|
|
71
|
+
const observable = this.observables.get(v.trim());
|
|
72
|
+
if (!observable) {
|
|
73
|
+
throw new Error(`Invalid observer ${v}`);
|
|
74
|
+
}
|
|
75
|
+
return observable;
|
|
76
|
+
}));
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
const observable = this.observables.get(consumer);
|
|
80
|
+
if (!observable) {
|
|
81
|
+
throw new Error(`Invalid observer ${consumer}`);
|
|
82
|
+
}
|
|
83
|
+
observables.push(observable);
|
|
84
|
+
}
|
|
85
|
+
observables.forEach((observable) => observable.publish(realTopic, data));
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Subscribes to incoming messages on the given topic, where topic represents
|
|
90
|
+
* [consumer/s].topic
|
|
91
|
+
* @param topic
|
|
92
|
+
* @param bufferSize
|
|
93
|
+
* @param expiryPeriod
|
|
94
|
+
*/
|
|
95
|
+
subscribe(topic, bufferSize, expiryPeriod) {
|
|
96
|
+
if (typeof topic === "string") {
|
|
97
|
+
if (topic.startsWith("*.")) {
|
|
98
|
+
return Stream.merge(Array.from(this.observables.values()).map((observable) => observable.subscribe(topic.substring(2), bufferSize, expiryPeriod)));
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
const [consumer, realTopic] = topic.split(".", 2);
|
|
102
|
+
const observables = [];
|
|
103
|
+
if (consumer.startsWith("[") && consumer.endsWith("]")) {
|
|
104
|
+
observables.push(...consumer
|
|
105
|
+
.substring(1, consumer.length - 1)
|
|
106
|
+
.split(",")
|
|
107
|
+
.map((v) => {
|
|
108
|
+
const observable = this.observables.get(v);
|
|
109
|
+
if (!observable) {
|
|
110
|
+
throw new Error(`Invalid observer ${v}`);
|
|
111
|
+
}
|
|
112
|
+
return observable;
|
|
113
|
+
}));
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
const observable = this.observables.get(consumer);
|
|
117
|
+
if (!observable) {
|
|
118
|
+
throw new Error(`Invalid observer ${consumer}`);
|
|
119
|
+
}
|
|
120
|
+
observables.push(observable);
|
|
121
|
+
}
|
|
122
|
+
return Stream.merge(Array.from(observables.values()).map((observable) => observable.subscribe(realTopic, bufferSize, expiryPeriod)));
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return Stream.merge(Array.from(this.observables.entries()).map(([key, observable]) => observable
|
|
126
|
+
.subscribe("*", bufferSize, expiryPeriod)
|
|
127
|
+
.filter(({ topic: subTopic }) => topic.test(`${key}.${subTopic}`))));
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Registers a WebWorker as a consumer. The worker needs to accept the connection
|
|
131
|
+
* by calling DataBus.workerJoin()
|
|
132
|
+
* @param worker
|
|
133
|
+
* @param name
|
|
134
|
+
* @param workerBufferSize
|
|
135
|
+
*/
|
|
136
|
+
connectWorker(worker, name, workerBufferSize = undefined) {
|
|
137
|
+
if (name.includes(".")) {
|
|
138
|
+
throw new Error("period cannot exist in consumer name");
|
|
139
|
+
}
|
|
140
|
+
if (this.observables.has(name)) {
|
|
141
|
+
throw new Error("worker already added");
|
|
142
|
+
}
|
|
143
|
+
const { port1, port2 } = new MessageChannel();
|
|
144
|
+
worker.postMessage({
|
|
145
|
+
command: "__join_data_bus__",
|
|
146
|
+
workerName: name,
|
|
147
|
+
}, [port2]);
|
|
148
|
+
const observable = new ObservableMessagePort(port1);
|
|
149
|
+
this.observables.set(name, observable);
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Provides a consumer with a connection to the data bus, where the consumer
|
|
153
|
+
* can dispatch messages and respond to other data
|
|
154
|
+
* @param name name required for consumer to receive incoming messages. Will be
|
|
155
|
+
* used as a part of the topics when message is being dispatched
|
|
156
|
+
*/
|
|
157
|
+
connectConsumer(name) {
|
|
158
|
+
if (name.includes(".")) {
|
|
159
|
+
throw new Error("period cannot exist in consumer name");
|
|
160
|
+
}
|
|
161
|
+
if (this.observables.has(name)) {
|
|
162
|
+
throw new Error("consumer already added");
|
|
163
|
+
}
|
|
164
|
+
const observable = new ObservableEventTarget();
|
|
165
|
+
this.observables.set(name, observable);
|
|
166
|
+
return observable;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Disconnects the given consumer from receiving messages from the bus
|
|
170
|
+
* @param name
|
|
171
|
+
*/
|
|
172
|
+
disconnectConsumer(name) {
|
|
173
|
+
this.observables.delete(name);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
export { DataBus };
|