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,61 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var TimeableObject = require('./TimeableObject.cjs');
|
|
4
|
+
var future = require('../../future/future.cjs');
|
|
5
|
+
require('ramda');
|
|
6
|
+
require('../../stream.cjs');
|
|
7
|
+
var uuid = require('uuid');
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Object that allows you to wait until property exists, and perform some action on them
|
|
11
|
+
*/
|
|
12
|
+
class WaitableObject extends TimeableObject.TimeableObject {
|
|
13
|
+
constructor(objectMaxSize, expiryPeriod) {
|
|
14
|
+
super(objectMaxSize, expiryPeriod);
|
|
15
|
+
this.listeners = new Map();
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Retrieves the value at the given path once it exists
|
|
19
|
+
* @param key path
|
|
20
|
+
* @param abort signal to cancel waiting on result
|
|
21
|
+
*/
|
|
22
|
+
await(key, abort) {
|
|
23
|
+
if (this.has(key)) {
|
|
24
|
+
return future.Future.completed(super.get(key));
|
|
25
|
+
}
|
|
26
|
+
const guid = uuid.v4();
|
|
27
|
+
return new future.Future((resolve, reject, signal) => {
|
|
28
|
+
this.listeners.set(guid, [key, resolve, false]);
|
|
29
|
+
signal.onabort = () => {
|
|
30
|
+
this.listeners.delete(guid);
|
|
31
|
+
};
|
|
32
|
+
}, abort);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Retrieves the value at the given key once it exists, or the value changes
|
|
36
|
+
* @param key path
|
|
37
|
+
* @param callback callback function that is trigger once value exist or is changed
|
|
38
|
+
* @param multiCall
|
|
39
|
+
* @returns unsubscribe function
|
|
40
|
+
*/
|
|
41
|
+
on(key, callback, multiCall = true) {
|
|
42
|
+
const guid = uuid.v4();
|
|
43
|
+
this.listeners.set(guid, [key, callback, multiCall]);
|
|
44
|
+
return () => this.listeners.delete(guid);
|
|
45
|
+
}
|
|
46
|
+
set(key, value, expiryPeriod) {
|
|
47
|
+
super.set(key, value, expiryPeriod);
|
|
48
|
+
for (const [guid, [k, callback, multiCall]] of this.listeners.entries()) {
|
|
49
|
+
if (k !== key)
|
|
50
|
+
continue;
|
|
51
|
+
callback(value);
|
|
52
|
+
if (!multiCall)
|
|
53
|
+
this.listeners.delete(guid);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
clone() {
|
|
57
|
+
return super.clone();
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
exports.WaitableObject = WaitableObject;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { TimeableObject } from "./TimeableObject";
|
|
2
|
+
import { Future, WaitPeriod } from "../../future";
|
|
3
|
+
/**
|
|
4
|
+
* Object that allows you to wait until property exists, and perform some action on them
|
|
5
|
+
*/
|
|
6
|
+
export declare class WaitableObject<T, K> extends TimeableObject<T, K> {
|
|
7
|
+
/**
|
|
8
|
+
* Listeners that are waiting for the value at a specific path to exist or updated
|
|
9
|
+
* @private
|
|
10
|
+
*/
|
|
11
|
+
private readonly listeners;
|
|
12
|
+
constructor(objectMaxSize?: number, expiryPeriod?: WaitPeriod);
|
|
13
|
+
/**
|
|
14
|
+
* Retrieves the value at the given path once it exists
|
|
15
|
+
* @param key path
|
|
16
|
+
* @param abort signal to cancel waiting on result
|
|
17
|
+
*/
|
|
18
|
+
await(key: T, abort?: AbortSignal): Future<K>;
|
|
19
|
+
/**
|
|
20
|
+
* Retrieves the value at the given key once it exists, or the value changes
|
|
21
|
+
* @param key path
|
|
22
|
+
* @param callback callback function that is trigger once value exist or is changed
|
|
23
|
+
* @param multiCall
|
|
24
|
+
* @returns unsubscribe function
|
|
25
|
+
*/
|
|
26
|
+
on(key: T, callback: (value: K) => void, multiCall?: boolean): () => boolean;
|
|
27
|
+
set(key: T, value: K, expiryPeriod?: WaitPeriod): void;
|
|
28
|
+
clone(): any;
|
|
29
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { TimeableObject } from './TimeableObject.mjs';
|
|
2
|
+
import { Future } from '../../future/future.mjs';
|
|
3
|
+
import 'ramda';
|
|
4
|
+
import '../../stream.mjs';
|
|
5
|
+
import { v4 } from 'uuid';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Object that allows you to wait until property exists, and perform some action on them
|
|
9
|
+
*/
|
|
10
|
+
class WaitableObject extends TimeableObject {
|
|
11
|
+
constructor(objectMaxSize, expiryPeriod) {
|
|
12
|
+
super(objectMaxSize, expiryPeriod);
|
|
13
|
+
this.listeners = new Map();
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Retrieves the value at the given path once it exists
|
|
17
|
+
* @param key path
|
|
18
|
+
* @param abort signal to cancel waiting on result
|
|
19
|
+
*/
|
|
20
|
+
await(key, abort) {
|
|
21
|
+
if (this.has(key)) {
|
|
22
|
+
return Future.completed(super.get(key));
|
|
23
|
+
}
|
|
24
|
+
const guid = v4();
|
|
25
|
+
return new Future((resolve, reject, signal) => {
|
|
26
|
+
this.listeners.set(guid, [key, resolve, false]);
|
|
27
|
+
signal.onabort = () => {
|
|
28
|
+
this.listeners.delete(guid);
|
|
29
|
+
};
|
|
30
|
+
}, abort);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Retrieves the value at the given key once it exists, or the value changes
|
|
34
|
+
* @param key path
|
|
35
|
+
* @param callback callback function that is trigger once value exist or is changed
|
|
36
|
+
* @param multiCall
|
|
37
|
+
* @returns unsubscribe function
|
|
38
|
+
*/
|
|
39
|
+
on(key, callback, multiCall = true) {
|
|
40
|
+
const guid = v4();
|
|
41
|
+
this.listeners.set(guid, [key, callback, multiCall]);
|
|
42
|
+
return () => this.listeners.delete(guid);
|
|
43
|
+
}
|
|
44
|
+
set(key, value, expiryPeriod) {
|
|
45
|
+
super.set(key, value, expiryPeriod);
|
|
46
|
+
for (const [guid, [k, callback, multiCall]] of this.listeners.entries()) {
|
|
47
|
+
if (k !== key)
|
|
48
|
+
continue;
|
|
49
|
+
callback(value);
|
|
50
|
+
if (!multiCall)
|
|
51
|
+
this.listeners.delete(guid);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
clone() {
|
|
55
|
+
return super.clone();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export { WaitableObject };
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var _tslib = require('../../_virtual/_tslib.cjs');
|
|
4
|
+
var WaitableObject = require('./WaitableObject.cjs');
|
|
5
|
+
var future = require('../../future/future.cjs');
|
|
6
|
+
var R = require('ramda');
|
|
7
|
+
var synchronize = require('../../synchronize.cjs');
|
|
8
|
+
var stream = require('../../stream.cjs');
|
|
9
|
+
var stream_state = require('../../stream/state.cjs');
|
|
10
|
+
var SimpleQueue = require('./SimpleQueue.cjs');
|
|
11
|
+
|
|
12
|
+
function _interopNamespaceDefault(e) {
|
|
13
|
+
var n = Object.create(null);
|
|
14
|
+
if (e) {
|
|
15
|
+
Object.keys(e).forEach(function (k) {
|
|
16
|
+
if (k !== 'default') {
|
|
17
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
18
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () { return e[k]; }
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
n.default = e;
|
|
26
|
+
return Object.freeze(n);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
var R__namespace = /*#__PURE__*/_interopNamespaceDefault(R);
|
|
30
|
+
|
|
31
|
+
exports.WatchableObjectOperations = void 0;
|
|
32
|
+
(function (WatchableObjectOperations) {
|
|
33
|
+
WatchableObjectOperations[WatchableObjectOperations["DELETE"] = 0] = "DELETE";
|
|
34
|
+
WatchableObjectOperations[WatchableObjectOperations["GET"] = 1] = "GET";
|
|
35
|
+
WatchableObjectOperations[WatchableObjectOperations["SET"] = 2] = "SET";
|
|
36
|
+
WatchableObjectOperations[WatchableObjectOperations["CLEAR"] = 3] = "CLEAR";
|
|
37
|
+
WatchableObjectOperations[WatchableObjectOperations["VALUES"] = 4] = "VALUES";
|
|
38
|
+
})(exports.WatchableObjectOperations || (exports.WatchableObjectOperations = {}));
|
|
39
|
+
class WatchableObject extends WaitableObject.WaitableObject {
|
|
40
|
+
constructor(objectMaxSize, expiryPeriod) {
|
|
41
|
+
super(objectMaxSize, expiryPeriod);
|
|
42
|
+
this.getListeners = [];
|
|
43
|
+
this.setListeners = [];
|
|
44
|
+
this.deleteListeners = [];
|
|
45
|
+
this.clearListeners = [];
|
|
46
|
+
this.valuesListeners = [];
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Ingest data from the given stream into the queue. The future returned is
|
|
50
|
+
* already scheduled to execute in the background. However, you can cancel
|
|
51
|
+
* ingestion at anytime by cancelling the returned future
|
|
52
|
+
*
|
|
53
|
+
* Important Note:
|
|
54
|
+
* - Cancelling the ingestion does not kill the stream, only stops
|
|
55
|
+
* monitoring the stream for incoming data
|
|
56
|
+
* - If ingestion is cancelled and data had been retrieved at that period, the
|
|
57
|
+
* data will discarded
|
|
58
|
+
* @param stream input data stream
|
|
59
|
+
* @param keyExtractor used to get the key for storing the incoming data
|
|
60
|
+
*/
|
|
61
|
+
ingest(stream, keyExtractor) {
|
|
62
|
+
return this.ingestStream(stream, (data) => this.set(keyExtractor(data), data));
|
|
63
|
+
}
|
|
64
|
+
clone() {
|
|
65
|
+
return super.clone();
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Stream of changes made to the object via SET, DELETE or CLEAR commands
|
|
69
|
+
*/
|
|
70
|
+
changeStream() {
|
|
71
|
+
const evt = new synchronize.FutureEvent();
|
|
72
|
+
const queue = new SimpleQueue.SimpleQueue();
|
|
73
|
+
const cancelSet = this.onSet((key, oldValue, newValue) => {
|
|
74
|
+
queue.enqueue({
|
|
75
|
+
type: exports.WatchableObjectOperations.SET,
|
|
76
|
+
key,
|
|
77
|
+
oldValue,
|
|
78
|
+
newValue,
|
|
79
|
+
});
|
|
80
|
+
evt.set();
|
|
81
|
+
});
|
|
82
|
+
const cancelDelete = this.onDelete((key, oldValue) => {
|
|
83
|
+
queue.enqueue({
|
|
84
|
+
type: exports.WatchableObjectOperations.DELETE,
|
|
85
|
+
key,
|
|
86
|
+
oldValue,
|
|
87
|
+
});
|
|
88
|
+
evt.set();
|
|
89
|
+
});
|
|
90
|
+
const cancelClear = this.onClear(() => {
|
|
91
|
+
queue.enqueue({
|
|
92
|
+
type: exports.WatchableObjectOperations.CLEAR,
|
|
93
|
+
key: "*",
|
|
94
|
+
});
|
|
95
|
+
evt.set();
|
|
96
|
+
});
|
|
97
|
+
const cleanup = R__namespace.once(() => {
|
|
98
|
+
cancelClear();
|
|
99
|
+
cancelSet();
|
|
100
|
+
cancelDelete();
|
|
101
|
+
});
|
|
102
|
+
return new stream.Stream((signal) => _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
103
|
+
signal.onabort = cleanup;
|
|
104
|
+
while (queue.empty && !signal.aborted) {
|
|
105
|
+
yield evt.wait();
|
|
106
|
+
evt.clear();
|
|
107
|
+
}
|
|
108
|
+
if (signal.aborted) {
|
|
109
|
+
return new stream_state.ExecutorState(true);
|
|
110
|
+
}
|
|
111
|
+
return queue.dequeue();
|
|
112
|
+
}));
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Listens whenever a value is retrieved from this object
|
|
116
|
+
* @param listener
|
|
117
|
+
* @returns unsubscribe function
|
|
118
|
+
*/
|
|
119
|
+
onGet(listener) {
|
|
120
|
+
this.getListeners.push(listener);
|
|
121
|
+
return () => {
|
|
122
|
+
this.getListeners = this.getListeners.filter((v) => v !== listener);
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Listens whenever a property is added or updated on this object
|
|
127
|
+
* @param listener
|
|
128
|
+
* @returns unsubscribe function
|
|
129
|
+
*/
|
|
130
|
+
onSet(listener) {
|
|
131
|
+
this.setListeners.push(listener);
|
|
132
|
+
return () => {
|
|
133
|
+
this.setListeners = this.setListeners.filter((v) => v !== listener);
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Listens whenever a property is deleted from this object
|
|
138
|
+
* @param listener
|
|
139
|
+
* @returns unsubscribe function
|
|
140
|
+
*/
|
|
141
|
+
onDelete(listener) {
|
|
142
|
+
this.deleteListeners.push(listener);
|
|
143
|
+
return () => {
|
|
144
|
+
this.deleteListeners = this.deleteListeners.filter((v) => v !== listener);
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Listens whenever this object is wiped clean
|
|
149
|
+
* @param listener
|
|
150
|
+
* @returns unsubscribe function
|
|
151
|
+
*/
|
|
152
|
+
onClear(listener) {
|
|
153
|
+
this.clearListeners.push(listener);
|
|
154
|
+
return () => {
|
|
155
|
+
this.clearListeners = this.clearListeners.filter((v) => v !== listener);
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Listens whenever the values() method is invoked on this object
|
|
160
|
+
* @param listener
|
|
161
|
+
* @returns unsubscribe function
|
|
162
|
+
*/
|
|
163
|
+
onValues(listener) {
|
|
164
|
+
this.valuesListeners.push(listener);
|
|
165
|
+
return () => {
|
|
166
|
+
this.valuesListeners = this.valuesListeners.filter((v) => v !== listener);
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
get(key, defaultValue) {
|
|
170
|
+
future.Future.sleep(1)
|
|
171
|
+
.thenApply(() => this.getListeners.forEach((listener) => listener(key)))
|
|
172
|
+
.run();
|
|
173
|
+
return super.get(key, defaultValue);
|
|
174
|
+
}
|
|
175
|
+
set(key, value, expiryPeriod) {
|
|
176
|
+
const oldValue = this.get(key);
|
|
177
|
+
super.set(key, value, expiryPeriod);
|
|
178
|
+
this.setListeners.forEach((listener) => listener(key, oldValue, value));
|
|
179
|
+
}
|
|
180
|
+
delete(key) {
|
|
181
|
+
const oldValue = this.get(key);
|
|
182
|
+
super.delete(key);
|
|
183
|
+
if (oldValue !== undefined)
|
|
184
|
+
this.deleteListeners.forEach((listener) => listener(key, oldValue));
|
|
185
|
+
}
|
|
186
|
+
clear() {
|
|
187
|
+
super.clear();
|
|
188
|
+
this.clearListeners.forEach((listener) => listener());
|
|
189
|
+
}
|
|
190
|
+
await(key, abort) {
|
|
191
|
+
return super.await(key, abort).thenApply((value) => {
|
|
192
|
+
future.Future.sleep(1)
|
|
193
|
+
.thenApply(() => this.getListeners.forEach((listener) => listener(key)))
|
|
194
|
+
.run();
|
|
195
|
+
return value.value;
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
on(key, callback, multiCall = true) {
|
|
199
|
+
return super.on(key, (v) => {
|
|
200
|
+
future.Future.sleep(1)
|
|
201
|
+
.thenApply(() => this.getListeners.forEach((listener) => listener(key)))
|
|
202
|
+
.run();
|
|
203
|
+
callback(v);
|
|
204
|
+
}, multiCall);
|
|
205
|
+
}
|
|
206
|
+
values(copy) {
|
|
207
|
+
future.Future.sleep(1)
|
|
208
|
+
.thenApply(() => this.valuesListeners.forEach((listener) => listener()))
|
|
209
|
+
.run();
|
|
210
|
+
return super.values(copy);
|
|
211
|
+
}
|
|
212
|
+
ingestStream(stream, handler) {
|
|
213
|
+
return future.Future.of((_, __, signal) => _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
214
|
+
var _a, e_1, _b, _c;
|
|
215
|
+
try {
|
|
216
|
+
for (var _d = true, stream_1 = _tslib.__asyncValues(stream), stream_1_1; stream_1_1 = yield stream_1.next(), _a = stream_1_1.done, !_a;) {
|
|
217
|
+
_c = stream_1_1.value;
|
|
218
|
+
_d = false;
|
|
219
|
+
try {
|
|
220
|
+
const data = _c;
|
|
221
|
+
while (!signal.aborted && this.objectMaxSize && this.size() === this.objectMaxSize) {
|
|
222
|
+
yield future.Future.of((resolve, _, signal) => {
|
|
223
|
+
const cancel = this.onDelete(() => {
|
|
224
|
+
cancel();
|
|
225
|
+
resolve(null);
|
|
226
|
+
});
|
|
227
|
+
signal.onabort = cancel;
|
|
228
|
+
}).registerSignal(signal);
|
|
229
|
+
}
|
|
230
|
+
if (signal.aborted) {
|
|
231
|
+
break;
|
|
232
|
+
}
|
|
233
|
+
handler(data);
|
|
234
|
+
}
|
|
235
|
+
finally {
|
|
236
|
+
_d = true;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
241
|
+
finally {
|
|
242
|
+
try {
|
|
243
|
+
if (!_d && !_a && (_b = stream_1.return)) yield _b.call(stream_1);
|
|
244
|
+
}
|
|
245
|
+
finally { if (e_1) throw e_1.error; }
|
|
246
|
+
}
|
|
247
|
+
})).schedule();
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
exports.WatchableObject = WatchableObject;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { WaitableObject } from "./WaitableObject";
|
|
2
|
+
import { Future, WaitPeriod } from "../../future";
|
|
3
|
+
import { Stream } from "../../stream";
|
|
4
|
+
type GetListener<T> = (property: T) => void;
|
|
5
|
+
type SetListener<T, K> = (property: T, oldValue: K | undefined, newValue: K) => void | Promise<void>;
|
|
6
|
+
type DeleteListener<T, K> = (property: T, oldValue: K | undefined) => void;
|
|
7
|
+
export interface WatchableChange<T, K> {
|
|
8
|
+
type: WatchableObjectOperations.SET | WatchableObjectOperations.CLEAR | WatchableObjectOperations.DELETE;
|
|
9
|
+
oldValue?: K;
|
|
10
|
+
newValue?: K;
|
|
11
|
+
key: T;
|
|
12
|
+
}
|
|
13
|
+
export interface Configuration {
|
|
14
|
+
entryThreshold: number;
|
|
15
|
+
}
|
|
16
|
+
export declare enum WatchableObjectOperations {
|
|
17
|
+
DELETE = 0,
|
|
18
|
+
GET = 1,
|
|
19
|
+
SET = 2,
|
|
20
|
+
CLEAR = 3,
|
|
21
|
+
VALUES = 4
|
|
22
|
+
}
|
|
23
|
+
export declare class WatchableObject<T, K> extends WaitableObject<T, K> {
|
|
24
|
+
private getListeners;
|
|
25
|
+
private setListeners;
|
|
26
|
+
private deleteListeners;
|
|
27
|
+
private clearListeners;
|
|
28
|
+
private valuesListeners;
|
|
29
|
+
constructor(objectMaxSize?: number, expiryPeriod?: WaitPeriod);
|
|
30
|
+
/**
|
|
31
|
+
* Ingest data from the given stream into the queue. The future returned is
|
|
32
|
+
* already scheduled to execute in the background. However, you can cancel
|
|
33
|
+
* ingestion at anytime by cancelling the returned future
|
|
34
|
+
*
|
|
35
|
+
* Important Note:
|
|
36
|
+
* - Cancelling the ingestion does not kill the stream, only stops
|
|
37
|
+
* monitoring the stream for incoming data
|
|
38
|
+
* - If ingestion is cancelled and data had been retrieved at that period, the
|
|
39
|
+
* data will discarded
|
|
40
|
+
* @param stream input data stream
|
|
41
|
+
* @param keyExtractor used to get the key for storing the incoming data
|
|
42
|
+
*/
|
|
43
|
+
ingest(stream: Stream<K>, keyExtractor: (v: K) => T): Future<void>;
|
|
44
|
+
clone(): WatchableObject<T, K>;
|
|
45
|
+
/**
|
|
46
|
+
* Stream of changes made to the object via SET, DELETE or CLEAR commands
|
|
47
|
+
*/
|
|
48
|
+
changeStream(): Stream<WatchableChange<T, K>>;
|
|
49
|
+
/**
|
|
50
|
+
* Listens whenever a value is retrieved from this object
|
|
51
|
+
* @param listener
|
|
52
|
+
* @returns unsubscribe function
|
|
53
|
+
*/
|
|
54
|
+
onGet(listener: GetListener<T>): () => void;
|
|
55
|
+
/**
|
|
56
|
+
* Listens whenever a property is added or updated on this object
|
|
57
|
+
* @param listener
|
|
58
|
+
* @returns unsubscribe function
|
|
59
|
+
*/
|
|
60
|
+
onSet(listener: SetListener<T, K>): () => void;
|
|
61
|
+
/**
|
|
62
|
+
* Listens whenever a property is deleted from this object
|
|
63
|
+
* @param listener
|
|
64
|
+
* @returns unsubscribe function
|
|
65
|
+
*/
|
|
66
|
+
onDelete(listener: DeleteListener<T, K>): () => void;
|
|
67
|
+
/**
|
|
68
|
+
* Listens whenever this object is wiped clean
|
|
69
|
+
* @param listener
|
|
70
|
+
* @returns unsubscribe function
|
|
71
|
+
*/
|
|
72
|
+
onClear(listener: () => void): () => void;
|
|
73
|
+
/**
|
|
74
|
+
* Listens whenever the values() method is invoked on this object
|
|
75
|
+
* @param listener
|
|
76
|
+
* @returns unsubscribe function
|
|
77
|
+
*/
|
|
78
|
+
onValues(listener: () => void): () => void;
|
|
79
|
+
get(key: T, defaultValue?: K | undefined): K;
|
|
80
|
+
set(key: T, value: K, expiryPeriod?: WaitPeriod): void;
|
|
81
|
+
delete(key: T): void;
|
|
82
|
+
clear(): void;
|
|
83
|
+
await(key: T, abort?: AbortSignal): Future<K>;
|
|
84
|
+
on(key: T, callback: (value: K) => void, multiCall?: boolean): () => boolean;
|
|
85
|
+
values(copy?: boolean): K[];
|
|
86
|
+
protected ingestStream(stream: Stream<K>, handler: (v: K) => void): Future<void>;
|
|
87
|
+
}
|
|
88
|
+
export {};
|