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,178 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var _tslib = require('../../_virtual/_tslib.cjs');
|
|
4
|
+
var WatchableObject = require('./WatchableObject.cjs');
|
|
5
|
+
var FutureCancelled = require('../../errors/FutureCancelled.cjs');
|
|
6
|
+
var QueueEmptyError = require('../../errors/QueueEmptyError.cjs');
|
|
7
|
+
var future = require('../../future/future.cjs');
|
|
8
|
+
require('ramda');
|
|
9
|
+
var synchronize = require('../../synchronize.cjs');
|
|
10
|
+
var stream = require('../../stream.cjs');
|
|
11
|
+
var QueueFullError = require('../../errors/QueueFullError.cjs');
|
|
12
|
+
var ValueDestroyedError = require('../../errors/ValueDestroyedError.cjs');
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Queue data structure for First In First Out operation (FIFO)
|
|
16
|
+
*/
|
|
17
|
+
class Queue extends WatchableObject.WatchableObject {
|
|
18
|
+
constructor(objectMaxSize, expiryPeriod) {
|
|
19
|
+
super(objectMaxSize, expiryPeriod);
|
|
20
|
+
this.tail = 0;
|
|
21
|
+
this.head = 0;
|
|
22
|
+
this.closedSignal = new AbortController().signal;
|
|
23
|
+
this.closed = false;
|
|
24
|
+
this.dequeueEvt = new synchronize.FutureEvent();
|
|
25
|
+
}
|
|
26
|
+
get streamEntries() {
|
|
27
|
+
return stream.Stream.of(this.asyncIterator);
|
|
28
|
+
}
|
|
29
|
+
close() {
|
|
30
|
+
this.closed = true;
|
|
31
|
+
this.closedSignal.dispatchEvent(new CustomEvent("abort"));
|
|
32
|
+
this.closedSignal = AbortSignal.abort();
|
|
33
|
+
}
|
|
34
|
+
clone() {
|
|
35
|
+
const obj = super.clone();
|
|
36
|
+
obj.head = this.head;
|
|
37
|
+
obj.tail = this.tail;
|
|
38
|
+
return obj;
|
|
39
|
+
}
|
|
40
|
+
ingest(stream) {
|
|
41
|
+
return this.ingestStream(stream, (data) => this.enqueue(data));
|
|
42
|
+
}
|
|
43
|
+
enqueue(value) {
|
|
44
|
+
if (this.objectMaxSize && this.size() >= this.objectMaxSize) {
|
|
45
|
+
throw new QueueFullError.QueueFullError();
|
|
46
|
+
}
|
|
47
|
+
else if (this.closed) {
|
|
48
|
+
throw new ValueDestroyedError.ValueDestroyedError();
|
|
49
|
+
}
|
|
50
|
+
this.set(this.tail, value);
|
|
51
|
+
this.tail++;
|
|
52
|
+
}
|
|
53
|
+
awaitEnqueue(value) {
|
|
54
|
+
return future.Future.of((resolve, reject, signal) => _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
55
|
+
while (this.objectMaxSize && this.size() >= this.objectMaxSize) {
|
|
56
|
+
this.dequeueEvt.clear();
|
|
57
|
+
yield this.dequeueEvt.wait().registerSignal(signal).registerSignal(this.closedSignal);
|
|
58
|
+
}
|
|
59
|
+
this.set(this.tail, value);
|
|
60
|
+
this.tail++;
|
|
61
|
+
resolve();
|
|
62
|
+
}));
|
|
63
|
+
}
|
|
64
|
+
dequeue() {
|
|
65
|
+
if (this.closed) {
|
|
66
|
+
throw new ValueDestroyedError.ValueDestroyedError();
|
|
67
|
+
}
|
|
68
|
+
const value = this.get(this.head);
|
|
69
|
+
if (value !== undefined && value !== null) {
|
|
70
|
+
this.delete(this.head);
|
|
71
|
+
this.head++;
|
|
72
|
+
this.dequeueEvt.set();
|
|
73
|
+
return value;
|
|
74
|
+
}
|
|
75
|
+
throw new QueueEmptyError.QueueEmptyError();
|
|
76
|
+
}
|
|
77
|
+
awaitDequeue(abortSignal) {
|
|
78
|
+
if (this.empty && !this.closed) {
|
|
79
|
+
return this.await(this.head, abortSignal)
|
|
80
|
+
.registerSignal(this.closedSignal)
|
|
81
|
+
.thenApply((v) => {
|
|
82
|
+
this.delete(this.head);
|
|
83
|
+
this.head++;
|
|
84
|
+
this.dequeueEvt.set();
|
|
85
|
+
return v.value;
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
try {
|
|
89
|
+
return future.Future.completed(this.dequeue());
|
|
90
|
+
}
|
|
91
|
+
catch (e) {
|
|
92
|
+
return future.Future.exceptionally(e);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
awaitEmpty() {
|
|
96
|
+
return future.Future.of((resolve, reject, signal) => _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
97
|
+
while (!this.closed && !this.empty) {
|
|
98
|
+
this.dequeueEvt.clear();
|
|
99
|
+
yield this.dequeueEvt.wait();
|
|
100
|
+
}
|
|
101
|
+
if (this.closed) {
|
|
102
|
+
return reject(new ValueDestroyedError.ValueDestroyedError());
|
|
103
|
+
}
|
|
104
|
+
resolve();
|
|
105
|
+
}));
|
|
106
|
+
}
|
|
107
|
+
get asyncIterator() {
|
|
108
|
+
const self = this;
|
|
109
|
+
const generator = {
|
|
110
|
+
[Symbol.asyncIterator]() {
|
|
111
|
+
return generator;
|
|
112
|
+
},
|
|
113
|
+
return(value) {
|
|
114
|
+
return value;
|
|
115
|
+
},
|
|
116
|
+
throw(e) {
|
|
117
|
+
throw e;
|
|
118
|
+
},
|
|
119
|
+
next(...args) {
|
|
120
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
121
|
+
try {
|
|
122
|
+
return {
|
|
123
|
+
done: false,
|
|
124
|
+
value: yield self.awaitDequeue(),
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
catch (e) {
|
|
128
|
+
if (e instanceof ValueDestroyedError.ValueDestroyedError) {
|
|
129
|
+
throw new FutureCancelled.FutureCancelled();
|
|
130
|
+
}
|
|
131
|
+
throw e;
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
},
|
|
135
|
+
};
|
|
136
|
+
return generator;
|
|
137
|
+
}
|
|
138
|
+
clear() {
|
|
139
|
+
if (this.closed) {
|
|
140
|
+
throw new ValueDestroyedError.ValueDestroyedError();
|
|
141
|
+
}
|
|
142
|
+
super.clear();
|
|
143
|
+
this.tail = 0;
|
|
144
|
+
this.head = 0;
|
|
145
|
+
}
|
|
146
|
+
get empty() {
|
|
147
|
+
return this.tail <= this.head;
|
|
148
|
+
}
|
|
149
|
+
size() {
|
|
150
|
+
return this.tail - this.head;
|
|
151
|
+
}
|
|
152
|
+
peek() {
|
|
153
|
+
if (this.closed) {
|
|
154
|
+
throw new ValueDestroyedError.ValueDestroyedError();
|
|
155
|
+
}
|
|
156
|
+
return this.get(this.head);
|
|
157
|
+
}
|
|
158
|
+
next(...args) {
|
|
159
|
+
if (!this.empty) {
|
|
160
|
+
return {
|
|
161
|
+
done: false,
|
|
162
|
+
value: this.dequeue(),
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
return {
|
|
166
|
+
done: true,
|
|
167
|
+
value: undefined,
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
return(value) {
|
|
171
|
+
return this.next();
|
|
172
|
+
}
|
|
173
|
+
throw(e) {
|
|
174
|
+
throw e;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
exports.Queue = Queue;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { WatchableObject } from "./WatchableObject";
|
|
2
|
+
import { Future, WaitPeriod } from "../../future";
|
|
3
|
+
import { Stream } from "../../stream";
|
|
4
|
+
/**
|
|
5
|
+
* Queue data structure for First In First Out operation (FIFO)
|
|
6
|
+
*/
|
|
7
|
+
export declare class Queue<T> extends WatchableObject<number, T> implements Iterator<T> {
|
|
8
|
+
private tail;
|
|
9
|
+
private head;
|
|
10
|
+
private closedSignal;
|
|
11
|
+
private closed;
|
|
12
|
+
private readonly dequeueEvt;
|
|
13
|
+
constructor(objectMaxSize?: number, expiryPeriod?: WaitPeriod);
|
|
14
|
+
get streamEntries(): Stream<T>;
|
|
15
|
+
close(): void;
|
|
16
|
+
clone(): Queue<T>;
|
|
17
|
+
ingest(stream: Stream<T>): Future<void>;
|
|
18
|
+
enqueue(value: T): void;
|
|
19
|
+
awaitEnqueue(value: T): Future<void>;
|
|
20
|
+
dequeue(): T;
|
|
21
|
+
awaitDequeue(abortSignal?: AbortSignal): Future<T>;
|
|
22
|
+
awaitEmpty(): Future<void>;
|
|
23
|
+
get asyncIterator(): AsyncGenerator<T>;
|
|
24
|
+
clear(): void;
|
|
25
|
+
get empty(): boolean;
|
|
26
|
+
size(): number;
|
|
27
|
+
peek(): T;
|
|
28
|
+
next(...args: [] | [undefined]): IteratorResult<T, any>;
|
|
29
|
+
return?(value?: any): IteratorResult<T, any>;
|
|
30
|
+
throw?(e?: any): IteratorResult<T, any>;
|
|
31
|
+
}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { __awaiter } from '../../_virtual/_tslib.mjs';
|
|
2
|
+
import { WatchableObject } from './WatchableObject.mjs';
|
|
3
|
+
import { FutureCancelled } from '../../errors/FutureCancelled.mjs';
|
|
4
|
+
import { QueueEmptyError } from '../../errors/QueueEmptyError.mjs';
|
|
5
|
+
import { Future } from '../../future/future.mjs';
|
|
6
|
+
import 'ramda';
|
|
7
|
+
import { FutureEvent } from '../../synchronize.mjs';
|
|
8
|
+
import { Stream } from '../../stream.mjs';
|
|
9
|
+
import { QueueFullError } from '../../errors/QueueFullError.mjs';
|
|
10
|
+
import { ValueDestroyedError } from '../../errors/ValueDestroyedError.mjs';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Queue data structure for First In First Out operation (FIFO)
|
|
14
|
+
*/
|
|
15
|
+
class Queue extends WatchableObject {
|
|
16
|
+
constructor(objectMaxSize, expiryPeriod) {
|
|
17
|
+
super(objectMaxSize, expiryPeriod);
|
|
18
|
+
this.tail = 0;
|
|
19
|
+
this.head = 0;
|
|
20
|
+
this.closedSignal = new AbortController().signal;
|
|
21
|
+
this.closed = false;
|
|
22
|
+
this.dequeueEvt = new FutureEvent();
|
|
23
|
+
}
|
|
24
|
+
get streamEntries() {
|
|
25
|
+
return Stream.of(this.asyncIterator);
|
|
26
|
+
}
|
|
27
|
+
close() {
|
|
28
|
+
this.closed = true;
|
|
29
|
+
this.closedSignal.dispatchEvent(new CustomEvent("abort"));
|
|
30
|
+
this.closedSignal = AbortSignal.abort();
|
|
31
|
+
}
|
|
32
|
+
clone() {
|
|
33
|
+
const obj = super.clone();
|
|
34
|
+
obj.head = this.head;
|
|
35
|
+
obj.tail = this.tail;
|
|
36
|
+
return obj;
|
|
37
|
+
}
|
|
38
|
+
ingest(stream) {
|
|
39
|
+
return this.ingestStream(stream, (data) => this.enqueue(data));
|
|
40
|
+
}
|
|
41
|
+
enqueue(value) {
|
|
42
|
+
if (this.objectMaxSize && this.size() >= this.objectMaxSize) {
|
|
43
|
+
throw new QueueFullError();
|
|
44
|
+
}
|
|
45
|
+
else if (this.closed) {
|
|
46
|
+
throw new ValueDestroyedError();
|
|
47
|
+
}
|
|
48
|
+
this.set(this.tail, value);
|
|
49
|
+
this.tail++;
|
|
50
|
+
}
|
|
51
|
+
awaitEnqueue(value) {
|
|
52
|
+
return Future.of((resolve, reject, signal) => __awaiter(this, void 0, void 0, function* () {
|
|
53
|
+
while (this.objectMaxSize && this.size() >= this.objectMaxSize) {
|
|
54
|
+
this.dequeueEvt.clear();
|
|
55
|
+
yield this.dequeueEvt.wait().registerSignal(signal).registerSignal(this.closedSignal);
|
|
56
|
+
}
|
|
57
|
+
this.set(this.tail, value);
|
|
58
|
+
this.tail++;
|
|
59
|
+
resolve();
|
|
60
|
+
}));
|
|
61
|
+
}
|
|
62
|
+
dequeue() {
|
|
63
|
+
if (this.closed) {
|
|
64
|
+
throw new ValueDestroyedError();
|
|
65
|
+
}
|
|
66
|
+
const value = this.get(this.head);
|
|
67
|
+
if (value !== undefined && value !== null) {
|
|
68
|
+
this.delete(this.head);
|
|
69
|
+
this.head++;
|
|
70
|
+
this.dequeueEvt.set();
|
|
71
|
+
return value;
|
|
72
|
+
}
|
|
73
|
+
throw new QueueEmptyError();
|
|
74
|
+
}
|
|
75
|
+
awaitDequeue(abortSignal) {
|
|
76
|
+
if (this.empty && !this.closed) {
|
|
77
|
+
return this.await(this.head, abortSignal)
|
|
78
|
+
.registerSignal(this.closedSignal)
|
|
79
|
+
.thenApply((v) => {
|
|
80
|
+
this.delete(this.head);
|
|
81
|
+
this.head++;
|
|
82
|
+
this.dequeueEvt.set();
|
|
83
|
+
return v.value;
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
try {
|
|
87
|
+
return Future.completed(this.dequeue());
|
|
88
|
+
}
|
|
89
|
+
catch (e) {
|
|
90
|
+
return Future.exceptionally(e);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
awaitEmpty() {
|
|
94
|
+
return Future.of((resolve, reject, signal) => __awaiter(this, void 0, void 0, function* () {
|
|
95
|
+
while (!this.closed && !this.empty) {
|
|
96
|
+
this.dequeueEvt.clear();
|
|
97
|
+
yield this.dequeueEvt.wait();
|
|
98
|
+
}
|
|
99
|
+
if (this.closed) {
|
|
100
|
+
return reject(new ValueDestroyedError());
|
|
101
|
+
}
|
|
102
|
+
resolve();
|
|
103
|
+
}));
|
|
104
|
+
}
|
|
105
|
+
get asyncIterator() {
|
|
106
|
+
const self = this;
|
|
107
|
+
const generator = {
|
|
108
|
+
[Symbol.asyncIterator]() {
|
|
109
|
+
return generator;
|
|
110
|
+
},
|
|
111
|
+
return(value) {
|
|
112
|
+
return value;
|
|
113
|
+
},
|
|
114
|
+
throw(e) {
|
|
115
|
+
throw e;
|
|
116
|
+
},
|
|
117
|
+
next(...args) {
|
|
118
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
119
|
+
try {
|
|
120
|
+
return {
|
|
121
|
+
done: false,
|
|
122
|
+
value: yield self.awaitDequeue(),
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
catch (e) {
|
|
126
|
+
if (e instanceof ValueDestroyedError) {
|
|
127
|
+
throw new FutureCancelled();
|
|
128
|
+
}
|
|
129
|
+
throw e;
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
},
|
|
133
|
+
};
|
|
134
|
+
return generator;
|
|
135
|
+
}
|
|
136
|
+
clear() {
|
|
137
|
+
if (this.closed) {
|
|
138
|
+
throw new ValueDestroyedError();
|
|
139
|
+
}
|
|
140
|
+
super.clear();
|
|
141
|
+
this.tail = 0;
|
|
142
|
+
this.head = 0;
|
|
143
|
+
}
|
|
144
|
+
get empty() {
|
|
145
|
+
return this.tail <= this.head;
|
|
146
|
+
}
|
|
147
|
+
size() {
|
|
148
|
+
return this.tail - this.head;
|
|
149
|
+
}
|
|
150
|
+
peek() {
|
|
151
|
+
if (this.closed) {
|
|
152
|
+
throw new ValueDestroyedError();
|
|
153
|
+
}
|
|
154
|
+
return this.get(this.head);
|
|
155
|
+
}
|
|
156
|
+
next(...args) {
|
|
157
|
+
if (!this.empty) {
|
|
158
|
+
return {
|
|
159
|
+
done: false,
|
|
160
|
+
value: this.dequeue(),
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
return {
|
|
164
|
+
done: true,
|
|
165
|
+
value: undefined,
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
return(value) {
|
|
169
|
+
return this.next();
|
|
170
|
+
}
|
|
171
|
+
throw(e) {
|
|
172
|
+
throw e;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export { Queue };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var QueueEmptyError = require('../../errors/QueueEmptyError.cjs');
|
|
4
|
+
|
|
5
|
+
class SimpleQueue {
|
|
6
|
+
constructor() {
|
|
7
|
+
this.items = new Map();
|
|
8
|
+
this.head = 0;
|
|
9
|
+
this.tail = 0;
|
|
10
|
+
}
|
|
11
|
+
enqueue(element) {
|
|
12
|
+
this.items.set(this.tail, element);
|
|
13
|
+
this.tail++;
|
|
14
|
+
}
|
|
15
|
+
forEach(callback) {
|
|
16
|
+
while (!this.empty) {
|
|
17
|
+
const result = this.dequeue();
|
|
18
|
+
if (result === undefined)
|
|
19
|
+
return;
|
|
20
|
+
callback(result);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
dequeue() {
|
|
24
|
+
if (this.empty) {
|
|
25
|
+
throw new QueueEmptyError.QueueEmptyError();
|
|
26
|
+
}
|
|
27
|
+
const item = this.items.get(this.head);
|
|
28
|
+
this.items.delete(this.head);
|
|
29
|
+
this.head++;
|
|
30
|
+
return item;
|
|
31
|
+
}
|
|
32
|
+
peek() {
|
|
33
|
+
if (this.empty) {
|
|
34
|
+
throw new QueueEmptyError.QueueEmptyError();
|
|
35
|
+
}
|
|
36
|
+
return this.items.get(this.head);
|
|
37
|
+
}
|
|
38
|
+
size() {
|
|
39
|
+
return this.tail - this.head;
|
|
40
|
+
}
|
|
41
|
+
get empty() {
|
|
42
|
+
return this.size() === 0;
|
|
43
|
+
}
|
|
44
|
+
clone() {
|
|
45
|
+
const obj = new SimpleQueue();
|
|
46
|
+
obj.items = new Map(this.items);
|
|
47
|
+
obj.tail = this.tail;
|
|
48
|
+
obj.head = this.head;
|
|
49
|
+
return obj;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
exports.SimpleQueue = SimpleQueue;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare class SimpleQueue<T> {
|
|
2
|
+
private items;
|
|
3
|
+
private head;
|
|
4
|
+
private tail;
|
|
5
|
+
constructor();
|
|
6
|
+
enqueue(element: T): void;
|
|
7
|
+
forEach(callback: (v: T) => void): void;
|
|
8
|
+
dequeue(): T;
|
|
9
|
+
peek(): T;
|
|
10
|
+
size(): number;
|
|
11
|
+
get empty(): boolean;
|
|
12
|
+
clone(): SimpleQueue<T>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { QueueEmptyError } from '../../errors/QueueEmptyError.mjs';
|
|
2
|
+
|
|
3
|
+
class SimpleQueue {
|
|
4
|
+
constructor() {
|
|
5
|
+
this.items = new Map();
|
|
6
|
+
this.head = 0;
|
|
7
|
+
this.tail = 0;
|
|
8
|
+
}
|
|
9
|
+
enqueue(element) {
|
|
10
|
+
this.items.set(this.tail, element);
|
|
11
|
+
this.tail++;
|
|
12
|
+
}
|
|
13
|
+
forEach(callback) {
|
|
14
|
+
while (!this.empty) {
|
|
15
|
+
const result = this.dequeue();
|
|
16
|
+
if (result === undefined)
|
|
17
|
+
return;
|
|
18
|
+
callback(result);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
dequeue() {
|
|
22
|
+
if (this.empty) {
|
|
23
|
+
throw new QueueEmptyError();
|
|
24
|
+
}
|
|
25
|
+
const item = this.items.get(this.head);
|
|
26
|
+
this.items.delete(this.head);
|
|
27
|
+
this.head++;
|
|
28
|
+
return item;
|
|
29
|
+
}
|
|
30
|
+
peek() {
|
|
31
|
+
if (this.empty) {
|
|
32
|
+
throw new QueueEmptyError();
|
|
33
|
+
}
|
|
34
|
+
return this.items.get(this.head);
|
|
35
|
+
}
|
|
36
|
+
size() {
|
|
37
|
+
return this.tail - this.head;
|
|
38
|
+
}
|
|
39
|
+
get empty() {
|
|
40
|
+
return this.size() === 0;
|
|
41
|
+
}
|
|
42
|
+
clone() {
|
|
43
|
+
const obj = new SimpleQueue();
|
|
44
|
+
obj.items = new Map(this.items);
|
|
45
|
+
obj.tail = this.tail;
|
|
46
|
+
obj.head = this.head;
|
|
47
|
+
return obj;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export { SimpleQueue };
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var hash = require('object-hash');
|
|
4
|
+
var CyclicalObject = require('./CyclicalObject.cjs');
|
|
5
|
+
var future = require('../../future/future.cjs');
|
|
6
|
+
require('ramda');
|
|
7
|
+
require('../../stream.cjs');
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Object that has key value pairs that can expire
|
|
11
|
+
*/
|
|
12
|
+
class TimeableObject extends CyclicalObject.CyclicalObject {
|
|
13
|
+
constructor(objectMaxSize, expiryPeriod) {
|
|
14
|
+
super(objectMaxSize);
|
|
15
|
+
this.timers = new Map();
|
|
16
|
+
this.expiryPeriod = expiryPeriod;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Sets the value for the given key
|
|
20
|
+
* @param key
|
|
21
|
+
* @param value dat to be stored
|
|
22
|
+
* @param expiryPeriod When should this value expire
|
|
23
|
+
*/
|
|
24
|
+
set(key, value, expiryPeriod) {
|
|
25
|
+
var _a;
|
|
26
|
+
const hashedKey = this.computeHash(key);
|
|
27
|
+
const timer = this.timers.get(hashedKey);
|
|
28
|
+
timer === null || timer === void 0 ? void 0 : timer.cancel();
|
|
29
|
+
super.set(key, value);
|
|
30
|
+
if (expiryPeriod !== null && expiryPeriod !== void 0 ? expiryPeriod : this.expiryPeriod) {
|
|
31
|
+
this.timers.set(hashedKey, future.Future.sleep((_a = expiryPeriod !== null && expiryPeriod !== void 0 ? expiryPeriod : this.expiryPeriod) !== null && _a !== void 0 ? _a : 0)
|
|
32
|
+
.thenApply(() => this.delete(key))
|
|
33
|
+
.schedule());
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
get(key, defaultValue = undefined) {
|
|
37
|
+
var _a;
|
|
38
|
+
const result = super.get(key, defaultValue);
|
|
39
|
+
if (result !== undefined) {
|
|
40
|
+
if (this.expiryPeriod) {
|
|
41
|
+
const hashedKey = this.computeHash(key);
|
|
42
|
+
const timer = this.timers.get(hashedKey);
|
|
43
|
+
timer === null || timer === void 0 ? void 0 : timer.cancel();
|
|
44
|
+
this.timers.set(hashedKey, future.Future.sleep((_a = this.expiryPeriod) !== null && _a !== void 0 ? _a : 0)
|
|
45
|
+
.thenApply(() => this.delete(key))
|
|
46
|
+
.schedule());
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return result;
|
|
50
|
+
}
|
|
51
|
+
delete(key) {
|
|
52
|
+
const hashedKey = this.computeHash(key);
|
|
53
|
+
const timer = this.timers.get(hashedKey);
|
|
54
|
+
timer === null || timer === void 0 ? void 0 : timer.cancel();
|
|
55
|
+
this.timers.delete(hashedKey);
|
|
56
|
+
super.delete(key);
|
|
57
|
+
}
|
|
58
|
+
clear() {
|
|
59
|
+
this.timers.forEach((future) => future.cancel());
|
|
60
|
+
this.timers.clear();
|
|
61
|
+
super.clear();
|
|
62
|
+
}
|
|
63
|
+
clone() {
|
|
64
|
+
const obj = super.clone();
|
|
65
|
+
obj.expiryPeriod = this.expiryPeriod;
|
|
66
|
+
return obj;
|
|
67
|
+
}
|
|
68
|
+
computeHash(key) {
|
|
69
|
+
return typeof key === "string" ? key : hash.sha1(String(key));
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
exports.TimeableObject = TimeableObject;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { CyclicalObject } from "./CyclicalObject";
|
|
2
|
+
import { WaitPeriod } from "../../future";
|
|
3
|
+
/**
|
|
4
|
+
* Object that has key value pairs that can expire
|
|
5
|
+
*/
|
|
6
|
+
export declare class TimeableObject<T, K> extends CyclicalObject<T, K> {
|
|
7
|
+
/**
|
|
8
|
+
* default expiration time for each added key value pair
|
|
9
|
+
* @private
|
|
10
|
+
*/
|
|
11
|
+
protected expiryPeriod?: WaitPeriod;
|
|
12
|
+
/**
|
|
13
|
+
* mapping of timings for each key value pair
|
|
14
|
+
* @private
|
|
15
|
+
*/
|
|
16
|
+
private readonly timers;
|
|
17
|
+
constructor(objectMaxSize?: number, expiryPeriod?: WaitPeriod);
|
|
18
|
+
/**
|
|
19
|
+
* Sets the value for the given key
|
|
20
|
+
* @param key
|
|
21
|
+
* @param value dat to be stored
|
|
22
|
+
* @param expiryPeriod When should this value expire
|
|
23
|
+
*/
|
|
24
|
+
set(key: T, value: K, expiryPeriod?: WaitPeriod): void;
|
|
25
|
+
get(key: T, defaultValue?: K | undefined): K | undefined;
|
|
26
|
+
delete(key: T): void;
|
|
27
|
+
clear(): void;
|
|
28
|
+
clone(): TimeableObject<T, K>;
|
|
29
|
+
protected computeHash(key: T): string;
|
|
30
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import hash from 'object-hash';
|
|
2
|
+
import { CyclicalObject } from './CyclicalObject.mjs';
|
|
3
|
+
import { Future } from '../../future/future.mjs';
|
|
4
|
+
import 'ramda';
|
|
5
|
+
import '../../stream.mjs';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Object that has key value pairs that can expire
|
|
9
|
+
*/
|
|
10
|
+
class TimeableObject extends CyclicalObject {
|
|
11
|
+
constructor(objectMaxSize, expiryPeriod) {
|
|
12
|
+
super(objectMaxSize);
|
|
13
|
+
this.timers = new Map();
|
|
14
|
+
this.expiryPeriod = expiryPeriod;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Sets the value for the given key
|
|
18
|
+
* @param key
|
|
19
|
+
* @param value dat to be stored
|
|
20
|
+
* @param expiryPeriod When should this value expire
|
|
21
|
+
*/
|
|
22
|
+
set(key, value, expiryPeriod) {
|
|
23
|
+
var _a;
|
|
24
|
+
const hashedKey = this.computeHash(key);
|
|
25
|
+
const timer = this.timers.get(hashedKey);
|
|
26
|
+
timer === null || timer === void 0 ? void 0 : timer.cancel();
|
|
27
|
+
super.set(key, value);
|
|
28
|
+
if (expiryPeriod !== null && expiryPeriod !== void 0 ? expiryPeriod : this.expiryPeriod) {
|
|
29
|
+
this.timers.set(hashedKey, Future.sleep((_a = expiryPeriod !== null && expiryPeriod !== void 0 ? expiryPeriod : this.expiryPeriod) !== null && _a !== void 0 ? _a : 0)
|
|
30
|
+
.thenApply(() => this.delete(key))
|
|
31
|
+
.schedule());
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
get(key, defaultValue = undefined) {
|
|
35
|
+
var _a;
|
|
36
|
+
const result = super.get(key, defaultValue);
|
|
37
|
+
if (result !== undefined) {
|
|
38
|
+
if (this.expiryPeriod) {
|
|
39
|
+
const hashedKey = this.computeHash(key);
|
|
40
|
+
const timer = this.timers.get(hashedKey);
|
|
41
|
+
timer === null || timer === void 0 ? void 0 : timer.cancel();
|
|
42
|
+
this.timers.set(hashedKey, Future.sleep((_a = this.expiryPeriod) !== null && _a !== void 0 ? _a : 0)
|
|
43
|
+
.thenApply(() => this.delete(key))
|
|
44
|
+
.schedule());
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return result;
|
|
48
|
+
}
|
|
49
|
+
delete(key) {
|
|
50
|
+
const hashedKey = this.computeHash(key);
|
|
51
|
+
const timer = this.timers.get(hashedKey);
|
|
52
|
+
timer === null || timer === void 0 ? void 0 : timer.cancel();
|
|
53
|
+
this.timers.delete(hashedKey);
|
|
54
|
+
super.delete(key);
|
|
55
|
+
}
|
|
56
|
+
clear() {
|
|
57
|
+
this.timers.forEach((future) => future.cancel());
|
|
58
|
+
this.timers.clear();
|
|
59
|
+
super.clear();
|
|
60
|
+
}
|
|
61
|
+
clone() {
|
|
62
|
+
const obj = super.clone();
|
|
63
|
+
obj.expiryPeriod = this.expiryPeriod;
|
|
64
|
+
return obj;
|
|
65
|
+
}
|
|
66
|
+
computeHash(key) {
|
|
67
|
+
return typeof key === "string" ? key : hash.sha1(String(key));
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export { TimeableObject };
|