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,98 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var WatchableObject = require('./WatchableObject.cjs');
|
|
4
|
+
var TimeableObject = require('./TimeableObject.cjs');
|
|
5
|
+
var R = require('ramda');
|
|
6
|
+
var stream = require('../../stream.cjs');
|
|
7
|
+
var stream_state = require('../../stream/state.cjs');
|
|
8
|
+
|
|
9
|
+
function _interopNamespaceDefault(e) {
|
|
10
|
+
var n = Object.create(null);
|
|
11
|
+
if (e) {
|
|
12
|
+
Object.keys(e).forEach(function (k) {
|
|
13
|
+
if (k !== 'default') {
|
|
14
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
15
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
get: function () { return e[k]; }
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
n.default = e;
|
|
23
|
+
return Object.freeze(n);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
var R__namespace = /*#__PURE__*/_interopNamespaceDefault(R);
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Queue data structure that is iterable, but never can dequeue
|
|
30
|
+
*/
|
|
31
|
+
class BufferQueue extends WatchableObject.WatchableObject {
|
|
32
|
+
constructor(objectMaxSize, expiryPeriod) {
|
|
33
|
+
super(objectMaxSize, expiryPeriod);
|
|
34
|
+
this.tail = 0;
|
|
35
|
+
this.head = 0;
|
|
36
|
+
this.tracker = new TimeableObject.TimeableObject(objectMaxSize, expiryPeriod);
|
|
37
|
+
}
|
|
38
|
+
ingest(stream) {
|
|
39
|
+
return this.ingestStream(stream, (data) => this.enqueue(data));
|
|
40
|
+
}
|
|
41
|
+
streamEntries(ignoreCache = false) {
|
|
42
|
+
let pointer = ignoreCache ? this.tail : 0;
|
|
43
|
+
return new stream.Stream(((signal) => {
|
|
44
|
+
const value = this.get(pointer);
|
|
45
|
+
if (value !== undefined) {
|
|
46
|
+
pointer++;
|
|
47
|
+
return value;
|
|
48
|
+
}
|
|
49
|
+
return new Promise((resolve) => {
|
|
50
|
+
const unsubscribe = this.on(pointer, (v) => {
|
|
51
|
+
pointer++;
|
|
52
|
+
resolve(v);
|
|
53
|
+
}, false);
|
|
54
|
+
signal.onabort = () => {
|
|
55
|
+
unsubscribe();
|
|
56
|
+
resolve(new stream_state.ExecutorState(true));
|
|
57
|
+
};
|
|
58
|
+
});
|
|
59
|
+
}));
|
|
60
|
+
}
|
|
61
|
+
clone() {
|
|
62
|
+
const obj = super.clone();
|
|
63
|
+
obj.head = this.head;
|
|
64
|
+
obj.tail = this.tail;
|
|
65
|
+
obj.tracker = this.tracker;
|
|
66
|
+
return obj;
|
|
67
|
+
}
|
|
68
|
+
enqueue(value, tracker) {
|
|
69
|
+
this.set(this.tail, value);
|
|
70
|
+
if (!R__namespace.isNil(tracker)) {
|
|
71
|
+
this.tracker.set(tracker, this.tail);
|
|
72
|
+
}
|
|
73
|
+
this.tail++;
|
|
74
|
+
if (!this.has(this.head)) {
|
|
75
|
+
this.head++;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
clear() {
|
|
79
|
+
super.clear();
|
|
80
|
+
this.tail = 0;
|
|
81
|
+
this.head = 0;
|
|
82
|
+
this.tracker.clear();
|
|
83
|
+
}
|
|
84
|
+
get empty() {
|
|
85
|
+
return this.tail <= this.head;
|
|
86
|
+
}
|
|
87
|
+
size() {
|
|
88
|
+
return this.tail - this.head;
|
|
89
|
+
}
|
|
90
|
+
peek(index) {
|
|
91
|
+
return this.get(index !== null && index !== void 0 ? index : this.head);
|
|
92
|
+
}
|
|
93
|
+
findIndex(tracker) {
|
|
94
|
+
return this.tracker.get(tracker);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
exports.BufferQueue = BufferQueue;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { WatchableObject } from "./WatchableObject";
|
|
2
|
+
import { Future, WaitPeriod } from "../../future";
|
|
3
|
+
import { Stream } from "../../stream";
|
|
4
|
+
/**
|
|
5
|
+
* Queue data structure that is iterable, but never can dequeue
|
|
6
|
+
*/
|
|
7
|
+
export declare class BufferQueue<T> extends WatchableObject<number, T> {
|
|
8
|
+
private tail;
|
|
9
|
+
private head;
|
|
10
|
+
private readonly tracker;
|
|
11
|
+
constructor(objectMaxSize?: number, expiryPeriod?: WaitPeriod);
|
|
12
|
+
ingest(stream: Stream<T>): Future<void>;
|
|
13
|
+
streamEntries(ignoreCache?: boolean): Stream<T>;
|
|
14
|
+
clone(): BufferQueue<T>;
|
|
15
|
+
enqueue(value: T, tracker?: string | number): void;
|
|
16
|
+
clear(): void;
|
|
17
|
+
get empty(): boolean;
|
|
18
|
+
size(): number;
|
|
19
|
+
peek(index?: number): T;
|
|
20
|
+
findIndex(tracker: string | number): number;
|
|
21
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { WatchableObject } from './WatchableObject.mjs';
|
|
2
|
+
import { TimeableObject } from './TimeableObject.mjs';
|
|
3
|
+
import * as R from 'ramda';
|
|
4
|
+
import { Stream } from '../../stream.mjs';
|
|
5
|
+
import { ExecutorState } from '../../stream/state.mjs';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Queue data structure that is iterable, but never can dequeue
|
|
9
|
+
*/
|
|
10
|
+
class BufferQueue extends WatchableObject {
|
|
11
|
+
constructor(objectMaxSize, expiryPeriod) {
|
|
12
|
+
super(objectMaxSize, expiryPeriod);
|
|
13
|
+
this.tail = 0;
|
|
14
|
+
this.head = 0;
|
|
15
|
+
this.tracker = new TimeableObject(objectMaxSize, expiryPeriod);
|
|
16
|
+
}
|
|
17
|
+
ingest(stream) {
|
|
18
|
+
return this.ingestStream(stream, (data) => this.enqueue(data));
|
|
19
|
+
}
|
|
20
|
+
streamEntries(ignoreCache = false) {
|
|
21
|
+
let pointer = ignoreCache ? this.tail : 0;
|
|
22
|
+
return new Stream(((signal) => {
|
|
23
|
+
const value = this.get(pointer);
|
|
24
|
+
if (value !== undefined) {
|
|
25
|
+
pointer++;
|
|
26
|
+
return value;
|
|
27
|
+
}
|
|
28
|
+
return new Promise((resolve) => {
|
|
29
|
+
const unsubscribe = this.on(pointer, (v) => {
|
|
30
|
+
pointer++;
|
|
31
|
+
resolve(v);
|
|
32
|
+
}, false);
|
|
33
|
+
signal.onabort = () => {
|
|
34
|
+
unsubscribe();
|
|
35
|
+
resolve(new ExecutorState(true));
|
|
36
|
+
};
|
|
37
|
+
});
|
|
38
|
+
}));
|
|
39
|
+
}
|
|
40
|
+
clone() {
|
|
41
|
+
const obj = super.clone();
|
|
42
|
+
obj.head = this.head;
|
|
43
|
+
obj.tail = this.tail;
|
|
44
|
+
obj.tracker = this.tracker;
|
|
45
|
+
return obj;
|
|
46
|
+
}
|
|
47
|
+
enqueue(value, tracker) {
|
|
48
|
+
this.set(this.tail, value);
|
|
49
|
+
if (!R.isNil(tracker)) {
|
|
50
|
+
this.tracker.set(tracker, this.tail);
|
|
51
|
+
}
|
|
52
|
+
this.tail++;
|
|
53
|
+
if (!this.has(this.head)) {
|
|
54
|
+
this.head++;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
clear() {
|
|
58
|
+
super.clear();
|
|
59
|
+
this.tail = 0;
|
|
60
|
+
this.head = 0;
|
|
61
|
+
this.tracker.clear();
|
|
62
|
+
}
|
|
63
|
+
get empty() {
|
|
64
|
+
return this.tail <= this.head;
|
|
65
|
+
}
|
|
66
|
+
size() {
|
|
67
|
+
return this.tail - this.head;
|
|
68
|
+
}
|
|
69
|
+
peek(index) {
|
|
70
|
+
return this.get(index !== null && index !== void 0 ? index : this.head);
|
|
71
|
+
}
|
|
72
|
+
findIndex(tracker) {
|
|
73
|
+
return this.tracker.get(tracker);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export { BufferQueue };
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var R = require('ramda');
|
|
4
|
+
var stream = require('../../stream.cjs');
|
|
5
|
+
|
|
6
|
+
function _interopNamespaceDefault(e) {
|
|
7
|
+
var n = Object.create(null);
|
|
8
|
+
if (e) {
|
|
9
|
+
Object.keys(e).forEach(function (k) {
|
|
10
|
+
if (k !== 'default') {
|
|
11
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
12
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () { return e[k]; }
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
n.default = e;
|
|
20
|
+
return Object.freeze(n);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
var R__namespace = /*#__PURE__*/_interopNamespaceDefault(R);
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Object that is cyclical - has can store M keys, after which new key value pairs added override
|
|
27
|
+
* previous entries.
|
|
28
|
+
*/
|
|
29
|
+
class CyclicalObject {
|
|
30
|
+
constructor(objectMaxSize) {
|
|
31
|
+
this.target = [];
|
|
32
|
+
this.keyMapping = new Map();
|
|
33
|
+
this.pointer = -1;
|
|
34
|
+
this.objectMaxSize = objectMaxSize;
|
|
35
|
+
this.emptySlots = [];
|
|
36
|
+
}
|
|
37
|
+
static from(data) {
|
|
38
|
+
const obj = new this();
|
|
39
|
+
if (data instanceof Map) {
|
|
40
|
+
for (const [k, v] of data.entries()) {
|
|
41
|
+
obj.set(k, v);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
else if (data instanceof Array || Array.isArray(data)) {
|
|
45
|
+
for (const [k, v] of data) {
|
|
46
|
+
obj.set(k, v);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
for (const [k, v] of Object.entries(data)) {
|
|
51
|
+
obj.set(k, v);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return obj;
|
|
55
|
+
}
|
|
56
|
+
get stream() {
|
|
57
|
+
return stream.Stream.of(this.target[Symbol.iterator]());
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Retrieves the value associated with the given key. If not exist, the default response will be returned
|
|
61
|
+
* @param key
|
|
62
|
+
* @param defaultValue
|
|
63
|
+
*/
|
|
64
|
+
get(key, defaultValue = undefined) {
|
|
65
|
+
const index = this.keyMapping.get(key);
|
|
66
|
+
return !R__namespace.isNil(index) ? this.target[index] : defaultValue;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Add the given key value pair to the object. This will overwrite any existing entry that has the same key
|
|
70
|
+
* @param key
|
|
71
|
+
* @param value
|
|
72
|
+
*/
|
|
73
|
+
set(key, value) {
|
|
74
|
+
if (this.objectMaxSize) {
|
|
75
|
+
const index = this.keyMapping.get(key);
|
|
76
|
+
if (!R__namespace.isNil(index)) {
|
|
77
|
+
this.target[index] = value;
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
else if (this.emptySlots.length) {
|
|
81
|
+
const index = this.emptySlots.pop();
|
|
82
|
+
this.target[index] = value;
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
this.pointer = this.objectMaxSize ? (this.pointer + 1) % this.objectMaxSize : this.pointer + 1;
|
|
86
|
+
this.target[this.pointer] = value;
|
|
87
|
+
this.keyMapping.set(key, this.pointer);
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
this.target.push(value);
|
|
91
|
+
this.keyMapping.set(key, this.target.length - 1);
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Removes the value associated with the given key if it exists
|
|
95
|
+
* @param key
|
|
96
|
+
*/
|
|
97
|
+
delete(key) {
|
|
98
|
+
const index = this.keyMapping.get(key);
|
|
99
|
+
if (!R__namespace.isNil(index)) {
|
|
100
|
+
this.emptySlots.push(index);
|
|
101
|
+
this.target[index] = undefined;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Checks if the object has the given key
|
|
106
|
+
* @param key
|
|
107
|
+
*/
|
|
108
|
+
has(key) {
|
|
109
|
+
return this.keyMapping.has(key);
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Iterates over each entry in the object by executing the provided callback on each entry
|
|
113
|
+
* @param callback
|
|
114
|
+
*/
|
|
115
|
+
forEach(callback) {
|
|
116
|
+
Array.from(this.keyMapping.entries()).forEach(([key, index]) => callback(this.target[index], key));
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Wipes all key value pairs
|
|
120
|
+
*/
|
|
121
|
+
clear() {
|
|
122
|
+
this.pointer = -1;
|
|
123
|
+
this.target = this.objectMaxSize ? new Array(this.objectMaxSize) : [];
|
|
124
|
+
this.keyMapping.clear();
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Retrieves all the values from this object
|
|
128
|
+
* @param copy Used to create a copied view of the values
|
|
129
|
+
*/
|
|
130
|
+
values(copy) {
|
|
131
|
+
return copy ? R__namespace.clone(this.target.filter((v) => v !== undefined)) : this.target.filter((v) => v !== undefined);
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Retrieves the keys that are stored in this object
|
|
135
|
+
*/
|
|
136
|
+
keys() {
|
|
137
|
+
return this.keyMapping.keys();
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Retrieves the object size
|
|
141
|
+
*/
|
|
142
|
+
size() {
|
|
143
|
+
return this.pointer > -1 ? this.pointer + 1 : this.keyMapping.size;
|
|
144
|
+
}
|
|
145
|
+
clone() {
|
|
146
|
+
const obj = new (Object.getPrototypeOf(this).constructor)();
|
|
147
|
+
obj.target = R__namespace.clone(this.target);
|
|
148
|
+
obj.pointer = this.pointer;
|
|
149
|
+
obj.objectMaxSize = this.objectMaxSize;
|
|
150
|
+
obj.keyMapping = R__namespace.clone(this.keyMapping);
|
|
151
|
+
return obj;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
exports.CyclicalObject = CyclicalObject;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { Stream } from "../../stream";
|
|
2
|
+
/**
|
|
3
|
+
* Object that is cyclical - has can store M keys, after which new key value pairs added override
|
|
4
|
+
* previous entries.
|
|
5
|
+
*/
|
|
6
|
+
export declare class CyclicalObject<T, K> {
|
|
7
|
+
/**
|
|
8
|
+
* Underlying javascript data structure
|
|
9
|
+
* @private
|
|
10
|
+
*/
|
|
11
|
+
private target;
|
|
12
|
+
private readonly keyMapping;
|
|
13
|
+
/**
|
|
14
|
+
* Pointer to the current index
|
|
15
|
+
* @private
|
|
16
|
+
*/
|
|
17
|
+
private pointer;
|
|
18
|
+
/**
|
|
19
|
+
* Maximum size of this object
|
|
20
|
+
* @private
|
|
21
|
+
*/
|
|
22
|
+
protected readonly objectMaxSize?: number;
|
|
23
|
+
private readonly emptySlots;
|
|
24
|
+
constructor(objectMaxSize?: number);
|
|
25
|
+
static from<T, K>(data: Map<T, K> | Array<[T, K]> | {
|
|
26
|
+
T: K;
|
|
27
|
+
}): CyclicalObject<T, K>;
|
|
28
|
+
get stream(): Stream<K>;
|
|
29
|
+
/**
|
|
30
|
+
* Retrieves the value associated with the given key. If not exist, the default response will be returned
|
|
31
|
+
* @param key
|
|
32
|
+
* @param defaultValue
|
|
33
|
+
*/
|
|
34
|
+
get(key: T, defaultValue?: K | undefined): K;
|
|
35
|
+
/**
|
|
36
|
+
* Add the given key value pair to the object. This will overwrite any existing entry that has the same key
|
|
37
|
+
* @param key
|
|
38
|
+
* @param value
|
|
39
|
+
*/
|
|
40
|
+
set(key: T, value: K): void;
|
|
41
|
+
/**
|
|
42
|
+
* Removes the value associated with the given key if it exists
|
|
43
|
+
* @param key
|
|
44
|
+
*/
|
|
45
|
+
delete(key: T): void;
|
|
46
|
+
/**
|
|
47
|
+
* Checks if the object has the given key
|
|
48
|
+
* @param key
|
|
49
|
+
*/
|
|
50
|
+
has(key: T): boolean;
|
|
51
|
+
/**
|
|
52
|
+
* Iterates over each entry in the object by executing the provided callback on each entry
|
|
53
|
+
* @param callback
|
|
54
|
+
*/
|
|
55
|
+
forEach(callback: (value: K, key: T) => void): void;
|
|
56
|
+
/**
|
|
57
|
+
* Wipes all key value pairs
|
|
58
|
+
*/
|
|
59
|
+
clear(): void;
|
|
60
|
+
/**
|
|
61
|
+
* Retrieves all the values from this object
|
|
62
|
+
* @param copy Used to create a copied view of the values
|
|
63
|
+
*/
|
|
64
|
+
values(copy?: boolean): K[];
|
|
65
|
+
/**
|
|
66
|
+
* Retrieves the keys that are stored in this object
|
|
67
|
+
*/
|
|
68
|
+
keys(): IterableIterator<T>;
|
|
69
|
+
/**
|
|
70
|
+
* Retrieves the object size
|
|
71
|
+
*/
|
|
72
|
+
size(): number;
|
|
73
|
+
clone(): CyclicalObject<T, K>;
|
|
74
|
+
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import * as R from 'ramda';
|
|
2
|
+
import { Stream } from '../../stream.mjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Object that is cyclical - has can store M keys, after which new key value pairs added override
|
|
6
|
+
* previous entries.
|
|
7
|
+
*/
|
|
8
|
+
class CyclicalObject {
|
|
9
|
+
constructor(objectMaxSize) {
|
|
10
|
+
this.target = [];
|
|
11
|
+
this.keyMapping = new Map();
|
|
12
|
+
this.pointer = -1;
|
|
13
|
+
this.objectMaxSize = objectMaxSize;
|
|
14
|
+
this.emptySlots = [];
|
|
15
|
+
}
|
|
16
|
+
static from(data) {
|
|
17
|
+
const obj = new this();
|
|
18
|
+
if (data instanceof Map) {
|
|
19
|
+
for (const [k, v] of data.entries()) {
|
|
20
|
+
obj.set(k, v);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
else if (data instanceof Array || Array.isArray(data)) {
|
|
24
|
+
for (const [k, v] of data) {
|
|
25
|
+
obj.set(k, v);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
for (const [k, v] of Object.entries(data)) {
|
|
30
|
+
obj.set(k, v);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return obj;
|
|
34
|
+
}
|
|
35
|
+
get stream() {
|
|
36
|
+
return Stream.of(this.target[Symbol.iterator]());
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Retrieves the value associated with the given key. If not exist, the default response will be returned
|
|
40
|
+
* @param key
|
|
41
|
+
* @param defaultValue
|
|
42
|
+
*/
|
|
43
|
+
get(key, defaultValue = undefined) {
|
|
44
|
+
const index = this.keyMapping.get(key);
|
|
45
|
+
return !R.isNil(index) ? this.target[index] : defaultValue;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Add the given key value pair to the object. This will overwrite any existing entry that has the same key
|
|
49
|
+
* @param key
|
|
50
|
+
* @param value
|
|
51
|
+
*/
|
|
52
|
+
set(key, value) {
|
|
53
|
+
if (this.objectMaxSize) {
|
|
54
|
+
const index = this.keyMapping.get(key);
|
|
55
|
+
if (!R.isNil(index)) {
|
|
56
|
+
this.target[index] = value;
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
else if (this.emptySlots.length) {
|
|
60
|
+
const index = this.emptySlots.pop();
|
|
61
|
+
this.target[index] = value;
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
this.pointer = this.objectMaxSize ? (this.pointer + 1) % this.objectMaxSize : this.pointer + 1;
|
|
65
|
+
this.target[this.pointer] = value;
|
|
66
|
+
this.keyMapping.set(key, this.pointer);
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
this.target.push(value);
|
|
70
|
+
this.keyMapping.set(key, this.target.length - 1);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Removes the value associated with the given key if it exists
|
|
74
|
+
* @param key
|
|
75
|
+
*/
|
|
76
|
+
delete(key) {
|
|
77
|
+
const index = this.keyMapping.get(key);
|
|
78
|
+
if (!R.isNil(index)) {
|
|
79
|
+
this.emptySlots.push(index);
|
|
80
|
+
this.target[index] = undefined;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Checks if the object has the given key
|
|
85
|
+
* @param key
|
|
86
|
+
*/
|
|
87
|
+
has(key) {
|
|
88
|
+
return this.keyMapping.has(key);
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Iterates over each entry in the object by executing the provided callback on each entry
|
|
92
|
+
* @param callback
|
|
93
|
+
*/
|
|
94
|
+
forEach(callback) {
|
|
95
|
+
Array.from(this.keyMapping.entries()).forEach(([key, index]) => callback(this.target[index], key));
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Wipes all key value pairs
|
|
99
|
+
*/
|
|
100
|
+
clear() {
|
|
101
|
+
this.pointer = -1;
|
|
102
|
+
this.target = this.objectMaxSize ? new Array(this.objectMaxSize) : [];
|
|
103
|
+
this.keyMapping.clear();
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Retrieves all the values from this object
|
|
107
|
+
* @param copy Used to create a copied view of the values
|
|
108
|
+
*/
|
|
109
|
+
values(copy) {
|
|
110
|
+
return copy ? R.clone(this.target.filter((v) => v !== undefined)) : this.target.filter((v) => v !== undefined);
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Retrieves the keys that are stored in this object
|
|
114
|
+
*/
|
|
115
|
+
keys() {
|
|
116
|
+
return this.keyMapping.keys();
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Retrieves the object size
|
|
120
|
+
*/
|
|
121
|
+
size() {
|
|
122
|
+
return this.pointer > -1 ? this.pointer + 1 : this.keyMapping.size;
|
|
123
|
+
}
|
|
124
|
+
clone() {
|
|
125
|
+
const obj = new (Object.getPrototypeOf(this).constructor)();
|
|
126
|
+
obj.target = R.clone(this.target);
|
|
127
|
+
obj.pointer = this.pointer;
|
|
128
|
+
obj.objectMaxSize = this.objectMaxSize;
|
|
129
|
+
obj.keyMapping = R.clone(this.keyMapping);
|
|
130
|
+
return obj;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export { CyclicalObject };
|