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
package/data/value.cjs
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var _tslib = require('../_virtual/_tslib.cjs');
|
|
4
|
+
var future = require('../future/future.cjs');
|
|
5
|
+
require('ramda');
|
|
6
|
+
var synchronize = require('../synchronize.cjs');
|
|
7
|
+
var stream = require('../stream.cjs');
|
|
8
|
+
var stream_state = require('../stream/state.cjs');
|
|
9
|
+
var ValueDestroyedError = require('../errors/ValueDestroyedError.cjs');
|
|
10
|
+
|
|
11
|
+
class AtomicValue {
|
|
12
|
+
constructor() {
|
|
13
|
+
this.setEvt = new synchronize.FutureEvent();
|
|
14
|
+
this.setLock = new synchronize.Lock();
|
|
15
|
+
this.closed = false;
|
|
16
|
+
}
|
|
17
|
+
set(value) {
|
|
18
|
+
return this.setLock.with(() => _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
19
|
+
if (this.closed) {
|
|
20
|
+
throw new ValueDestroyedError.ValueDestroyedError();
|
|
21
|
+
}
|
|
22
|
+
this.value = value;
|
|
23
|
+
this.setEvt.set();
|
|
24
|
+
}));
|
|
25
|
+
}
|
|
26
|
+
get() {
|
|
27
|
+
return this.read(false);
|
|
28
|
+
}
|
|
29
|
+
pop() {
|
|
30
|
+
return this.read(true);
|
|
31
|
+
}
|
|
32
|
+
destroy() {
|
|
33
|
+
this.closed = true;
|
|
34
|
+
}
|
|
35
|
+
get stream() {
|
|
36
|
+
return new stream.Stream((signal) => this.pop()
|
|
37
|
+
.catch((error) => {
|
|
38
|
+
if (error instanceof ValueDestroyedError.ValueDestroyedError) {
|
|
39
|
+
return new stream_state.ExecutorState(true);
|
|
40
|
+
}
|
|
41
|
+
throw error;
|
|
42
|
+
})
|
|
43
|
+
.registerSignal(signal));
|
|
44
|
+
}
|
|
45
|
+
read(removeValue) {
|
|
46
|
+
return future.Future.of((resolve, reject, signal) => _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
47
|
+
while (this.value === undefined && !this.closed) {
|
|
48
|
+
this.setEvt.clear();
|
|
49
|
+
yield this.setEvt.wait().registerSignal(signal);
|
|
50
|
+
}
|
|
51
|
+
if (this.closed && this.value === undefined) {
|
|
52
|
+
return reject(new ValueDestroyedError.ValueDestroyedError());
|
|
53
|
+
}
|
|
54
|
+
const value = this.value;
|
|
55
|
+
if (removeValue) {
|
|
56
|
+
this.value = undefined;
|
|
57
|
+
}
|
|
58
|
+
resolve(value);
|
|
59
|
+
if (this.closed) {
|
|
60
|
+
return reject(new ValueDestroyedError.ValueDestroyedError());
|
|
61
|
+
}
|
|
62
|
+
}));
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
exports.AtomicValue = AtomicValue;
|
package/data/value.mjs
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { __awaiter } from '../_virtual/_tslib.mjs';
|
|
2
|
+
import { Future } from '../future/future.mjs';
|
|
3
|
+
import 'ramda';
|
|
4
|
+
import { FutureEvent, Lock } from '../synchronize.mjs';
|
|
5
|
+
import { Stream } from '../stream.mjs';
|
|
6
|
+
import { ExecutorState } from '../stream/state.mjs';
|
|
7
|
+
import { ValueDestroyedError } from '../errors/ValueDestroyedError.mjs';
|
|
8
|
+
|
|
9
|
+
class AtomicValue {
|
|
10
|
+
constructor() {
|
|
11
|
+
this.setEvt = new FutureEvent();
|
|
12
|
+
this.setLock = new Lock();
|
|
13
|
+
this.closed = false;
|
|
14
|
+
}
|
|
15
|
+
set(value) {
|
|
16
|
+
return this.setLock.with(() => __awaiter(this, void 0, void 0, function* () {
|
|
17
|
+
if (this.closed) {
|
|
18
|
+
throw new ValueDestroyedError();
|
|
19
|
+
}
|
|
20
|
+
this.value = value;
|
|
21
|
+
this.setEvt.set();
|
|
22
|
+
}));
|
|
23
|
+
}
|
|
24
|
+
get() {
|
|
25
|
+
return this.read(false);
|
|
26
|
+
}
|
|
27
|
+
pop() {
|
|
28
|
+
return this.read(true);
|
|
29
|
+
}
|
|
30
|
+
destroy() {
|
|
31
|
+
this.closed = true;
|
|
32
|
+
}
|
|
33
|
+
get stream() {
|
|
34
|
+
return new Stream((signal) => this.pop()
|
|
35
|
+
.catch((error) => {
|
|
36
|
+
if (error instanceof ValueDestroyedError) {
|
|
37
|
+
return new ExecutorState(true);
|
|
38
|
+
}
|
|
39
|
+
throw error;
|
|
40
|
+
})
|
|
41
|
+
.registerSignal(signal));
|
|
42
|
+
}
|
|
43
|
+
read(removeValue) {
|
|
44
|
+
return Future.of((resolve, reject, signal) => __awaiter(this, void 0, void 0, function* () {
|
|
45
|
+
while (this.value === undefined && !this.closed) {
|
|
46
|
+
this.setEvt.clear();
|
|
47
|
+
yield this.setEvt.wait().registerSignal(signal);
|
|
48
|
+
}
|
|
49
|
+
if (this.closed && this.value === undefined) {
|
|
50
|
+
return reject(new ValueDestroyedError());
|
|
51
|
+
}
|
|
52
|
+
const value = this.value;
|
|
53
|
+
if (removeValue) {
|
|
54
|
+
this.value = undefined;
|
|
55
|
+
}
|
|
56
|
+
resolve(value);
|
|
57
|
+
if (this.closed) {
|
|
58
|
+
return reject(new ValueDestroyedError());
|
|
59
|
+
}
|
|
60
|
+
}));
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export { AtomicValue };
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var stream = require('../../stream.cjs');
|
|
4
|
+
|
|
5
|
+
class CyclicalList extends Array {
|
|
6
|
+
constructor(maxSize) {
|
|
7
|
+
super();
|
|
8
|
+
this.pointer = this.length - 1;
|
|
9
|
+
this.maxSize = maxSize;
|
|
10
|
+
if (maxSize) {
|
|
11
|
+
this.push = (...items) => {
|
|
12
|
+
for (const item of items) {
|
|
13
|
+
this.pointer = (this.pointer + 1) % maxSize;
|
|
14
|
+
this[this.pointer] = item;
|
|
15
|
+
}
|
|
16
|
+
return this.pointer < maxSize ? this.pointer : maxSize;
|
|
17
|
+
};
|
|
18
|
+
this.pop = () => {
|
|
19
|
+
this.pointer--;
|
|
20
|
+
if (this.pointer < -1) {
|
|
21
|
+
this.pointer = -1;
|
|
22
|
+
}
|
|
23
|
+
return super.pop();
|
|
24
|
+
};
|
|
25
|
+
this.shift = () => {
|
|
26
|
+
this.pointer--;
|
|
27
|
+
if (this.pointer < -1) {
|
|
28
|
+
this.pointer = -1;
|
|
29
|
+
}
|
|
30
|
+
return super.shift();
|
|
31
|
+
};
|
|
32
|
+
this.unshift = (...items) => {
|
|
33
|
+
for (let i = items.length - 1; i >= 0; i--) {
|
|
34
|
+
const item = items[i];
|
|
35
|
+
if (this.length >= maxSize) {
|
|
36
|
+
this.pop();
|
|
37
|
+
}
|
|
38
|
+
this.pointer++;
|
|
39
|
+
this.unshift(item);
|
|
40
|
+
}
|
|
41
|
+
return this.length;
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
static from(items) {
|
|
46
|
+
const list = new this(items.length);
|
|
47
|
+
for (const item of items) {
|
|
48
|
+
list.push(item);
|
|
49
|
+
}
|
|
50
|
+
return list;
|
|
51
|
+
}
|
|
52
|
+
get stream() {
|
|
53
|
+
return stream.Stream.of(this);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
exports.CyclicalList = CyclicalList;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Stream } from "../../stream";
|
|
2
|
+
export declare class CyclicalList<T> extends Array<T> {
|
|
3
|
+
/**
|
|
4
|
+
* Pointer to the current index
|
|
5
|
+
* @private
|
|
6
|
+
*/
|
|
7
|
+
protected pointer: number;
|
|
8
|
+
protected readonly maxSize?: number;
|
|
9
|
+
constructor(maxSize?: number);
|
|
10
|
+
static from<T>(items: T[]): CyclicalList<T>;
|
|
11
|
+
get stream(): Stream<T>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { Stream } from '../../stream.mjs';
|
|
2
|
+
|
|
3
|
+
class CyclicalList extends Array {
|
|
4
|
+
constructor(maxSize) {
|
|
5
|
+
super();
|
|
6
|
+
this.pointer = this.length - 1;
|
|
7
|
+
this.maxSize = maxSize;
|
|
8
|
+
if (maxSize) {
|
|
9
|
+
this.push = (...items) => {
|
|
10
|
+
for (const item of items) {
|
|
11
|
+
this.pointer = (this.pointer + 1) % maxSize;
|
|
12
|
+
this[this.pointer] = item;
|
|
13
|
+
}
|
|
14
|
+
return this.pointer < maxSize ? this.pointer : maxSize;
|
|
15
|
+
};
|
|
16
|
+
this.pop = () => {
|
|
17
|
+
this.pointer--;
|
|
18
|
+
if (this.pointer < -1) {
|
|
19
|
+
this.pointer = -1;
|
|
20
|
+
}
|
|
21
|
+
return super.pop();
|
|
22
|
+
};
|
|
23
|
+
this.shift = () => {
|
|
24
|
+
this.pointer--;
|
|
25
|
+
if (this.pointer < -1) {
|
|
26
|
+
this.pointer = -1;
|
|
27
|
+
}
|
|
28
|
+
return super.shift();
|
|
29
|
+
};
|
|
30
|
+
this.unshift = (...items) => {
|
|
31
|
+
for (let i = items.length - 1; i >= 0; i--) {
|
|
32
|
+
const item = items[i];
|
|
33
|
+
if (this.length >= maxSize) {
|
|
34
|
+
this.pop();
|
|
35
|
+
}
|
|
36
|
+
this.pointer++;
|
|
37
|
+
this.unshift(item);
|
|
38
|
+
}
|
|
39
|
+
return this.length;
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
static from(items) {
|
|
44
|
+
const list = new this(items.length);
|
|
45
|
+
for (const item of items) {
|
|
46
|
+
list.push(item);
|
|
47
|
+
}
|
|
48
|
+
return list;
|
|
49
|
+
}
|
|
50
|
+
get stream() {
|
|
51
|
+
return Stream.of(this);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export { CyclicalList };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* An immutable tuple of 2 values
|
|
5
|
+
*/
|
|
6
|
+
class Pair {
|
|
7
|
+
constructor(_first, _second) {
|
|
8
|
+
this._first = _first;
|
|
9
|
+
this._second = _second;
|
|
10
|
+
}
|
|
11
|
+
get first() {
|
|
12
|
+
return this._first;
|
|
13
|
+
}
|
|
14
|
+
get second() {
|
|
15
|
+
return this._second;
|
|
16
|
+
}
|
|
17
|
+
get last() {
|
|
18
|
+
return this.second;
|
|
19
|
+
}
|
|
20
|
+
get values() {
|
|
21
|
+
return [this._first, this._second];
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Creates an immutable tuple of 2 values
|
|
26
|
+
*/
|
|
27
|
+
const pair = (first, second) => new Pair(first, second);
|
|
28
|
+
|
|
29
|
+
exports.Pair = Pair;
|
|
30
|
+
exports.pair = pair;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Tuple } from "./Tuple";
|
|
2
|
+
/**
|
|
3
|
+
* An immutable tuple of 2 values
|
|
4
|
+
*/
|
|
5
|
+
export declare class Pair<T, V> implements Tuple<T, V> {
|
|
6
|
+
private readonly _first;
|
|
7
|
+
private readonly _second;
|
|
8
|
+
constructor(_first: T, _second: V);
|
|
9
|
+
get first(): T;
|
|
10
|
+
get second(): V;
|
|
11
|
+
get last(): V;
|
|
12
|
+
get values(): [T, V];
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Creates an immutable tuple of 2 values
|
|
16
|
+
*/
|
|
17
|
+
export declare const pair: <T, V>(first: T, second: V) => Pair<T, V>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An immutable tuple of 2 values
|
|
3
|
+
*/
|
|
4
|
+
class Pair {
|
|
5
|
+
constructor(_first, _second) {
|
|
6
|
+
this._first = _first;
|
|
7
|
+
this._second = _second;
|
|
8
|
+
}
|
|
9
|
+
get first() {
|
|
10
|
+
return this._first;
|
|
11
|
+
}
|
|
12
|
+
get second() {
|
|
13
|
+
return this._second;
|
|
14
|
+
}
|
|
15
|
+
get last() {
|
|
16
|
+
return this.second;
|
|
17
|
+
}
|
|
18
|
+
get values() {
|
|
19
|
+
return [this._first, this._second];
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Creates an immutable tuple of 2 values
|
|
24
|
+
*/
|
|
25
|
+
const pair = (first, second) => new Pair(first, second);
|
|
26
|
+
|
|
27
|
+
export { Pair, pair };
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var CyclicalList = require('./CyclicalList.cjs');
|
|
4
|
+
var NotImplemented = require('../../errors/NotImplemented.cjs');
|
|
5
|
+
var StackEmptyError = require('../../errors/StackEmptyError.cjs');
|
|
6
|
+
var StackFullError = require('../../errors/StackFullError.cjs');
|
|
7
|
+
var synchronize = require('../../synchronize.cjs');
|
|
8
|
+
var stream = require('../../stream.cjs');
|
|
9
|
+
var future = require('../../future/future.cjs');
|
|
10
|
+
require('ramda');
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Stack data structure for Last In First Out operation (LIFO)
|
|
14
|
+
*/
|
|
15
|
+
class Stack extends CyclicalList.CyclicalList {
|
|
16
|
+
constructor(maxSize) {
|
|
17
|
+
super(maxSize);
|
|
18
|
+
this.totalEntries = 0;
|
|
19
|
+
this.evt = new synchronize.FutureEvent();
|
|
20
|
+
}
|
|
21
|
+
unshift(...items) {
|
|
22
|
+
throw new NotImplemented.NotImplemented();
|
|
23
|
+
}
|
|
24
|
+
shift() {
|
|
25
|
+
throw new NotImplemented.NotImplemented();
|
|
26
|
+
}
|
|
27
|
+
get stream() {
|
|
28
|
+
return new stream.Stream((v) => this.awaitPop(v));
|
|
29
|
+
}
|
|
30
|
+
push(...items) {
|
|
31
|
+
this.evt.set();
|
|
32
|
+
this.totalEntries++;
|
|
33
|
+
if (this.maxSize && this.totalEntries > this.maxSize) {
|
|
34
|
+
throw new StackFullError.StackFullError();
|
|
35
|
+
}
|
|
36
|
+
return super.push(...items);
|
|
37
|
+
}
|
|
38
|
+
pop() {
|
|
39
|
+
if (this.length === 0)
|
|
40
|
+
throw new StackEmptyError.StackEmptyError();
|
|
41
|
+
this.evt.clear();
|
|
42
|
+
this.totalEntries--;
|
|
43
|
+
return super.pop();
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Awaits a value being available on the stack to retrieve it
|
|
47
|
+
* @param abortSignal
|
|
48
|
+
*/
|
|
49
|
+
awaitPop(abortSignal) {
|
|
50
|
+
if (this.size() === 0) {
|
|
51
|
+
const future = this.evt.wait();
|
|
52
|
+
if (abortSignal)
|
|
53
|
+
future.registerSignal(abortSignal);
|
|
54
|
+
return future.then((v) => {
|
|
55
|
+
if (this.size() > 0)
|
|
56
|
+
return this.pop();
|
|
57
|
+
return this.awaitPop(v.signal);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
return future.Future.completed(this.pop());
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Retrieves the last item added to the stack
|
|
64
|
+
*/
|
|
65
|
+
peek() {
|
|
66
|
+
return this[this.pointer];
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Checks if the stack is empty
|
|
70
|
+
*/
|
|
71
|
+
get empty() {
|
|
72
|
+
return this.totalEntries === 0;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Checks if the stack is full
|
|
76
|
+
*/
|
|
77
|
+
get full() {
|
|
78
|
+
return this.size() === this.maxSize;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Retrieves the current stack size
|
|
82
|
+
*/
|
|
83
|
+
size() {
|
|
84
|
+
return this.totalEntries;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Empty the stack
|
|
88
|
+
*/
|
|
89
|
+
clear() {
|
|
90
|
+
while (!this.empty) {
|
|
91
|
+
this.pop();
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
exports.Stack = Stack;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { CyclicalList } from "./CyclicalList";
|
|
2
|
+
import { Stream } from "../../stream";
|
|
3
|
+
import { Future } from "../../future";
|
|
4
|
+
/**
|
|
5
|
+
* Stack data structure for Last In First Out operation (LIFO)
|
|
6
|
+
*/
|
|
7
|
+
export declare class Stack<T> extends CyclicalList<T> {
|
|
8
|
+
private readonly evt;
|
|
9
|
+
private totalEntries;
|
|
10
|
+
constructor(maxSize?: number);
|
|
11
|
+
unshift(...items: any[]): number;
|
|
12
|
+
shift(): T | undefined;
|
|
13
|
+
get stream(): Stream<T>;
|
|
14
|
+
push(...items: any[]): number;
|
|
15
|
+
pop(): T;
|
|
16
|
+
/**
|
|
17
|
+
* Awaits a value being available on the stack to retrieve it
|
|
18
|
+
* @param abortSignal
|
|
19
|
+
*/
|
|
20
|
+
awaitPop(abortSignal?: AbortSignal): Future<T>;
|
|
21
|
+
/**
|
|
22
|
+
* Retrieves the last item added to the stack
|
|
23
|
+
*/
|
|
24
|
+
peek(): T;
|
|
25
|
+
/**
|
|
26
|
+
* Checks if the stack is empty
|
|
27
|
+
*/
|
|
28
|
+
get empty(): boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Checks if the stack is full
|
|
31
|
+
*/
|
|
32
|
+
get full(): boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Retrieves the current stack size
|
|
35
|
+
*/
|
|
36
|
+
size(): number;
|
|
37
|
+
/**
|
|
38
|
+
* Empty the stack
|
|
39
|
+
*/
|
|
40
|
+
clear(): void;
|
|
41
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { CyclicalList } from './CyclicalList.mjs';
|
|
2
|
+
import { NotImplemented } from '../../errors/NotImplemented.mjs';
|
|
3
|
+
import { StackEmptyError } from '../../errors/StackEmptyError.mjs';
|
|
4
|
+
import { StackFullError } from '../../errors/StackFullError.mjs';
|
|
5
|
+
import { FutureEvent } from '../../synchronize.mjs';
|
|
6
|
+
import { Stream } from '../../stream.mjs';
|
|
7
|
+
import { Future } from '../../future/future.mjs';
|
|
8
|
+
import 'ramda';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Stack data structure for Last In First Out operation (LIFO)
|
|
12
|
+
*/
|
|
13
|
+
class Stack extends CyclicalList {
|
|
14
|
+
constructor(maxSize) {
|
|
15
|
+
super(maxSize);
|
|
16
|
+
this.totalEntries = 0;
|
|
17
|
+
this.evt = new FutureEvent();
|
|
18
|
+
}
|
|
19
|
+
unshift(...items) {
|
|
20
|
+
throw new NotImplemented();
|
|
21
|
+
}
|
|
22
|
+
shift() {
|
|
23
|
+
throw new NotImplemented();
|
|
24
|
+
}
|
|
25
|
+
get stream() {
|
|
26
|
+
return new Stream((v) => this.awaitPop(v));
|
|
27
|
+
}
|
|
28
|
+
push(...items) {
|
|
29
|
+
this.evt.set();
|
|
30
|
+
this.totalEntries++;
|
|
31
|
+
if (this.maxSize && this.totalEntries > this.maxSize) {
|
|
32
|
+
throw new StackFullError();
|
|
33
|
+
}
|
|
34
|
+
return super.push(...items);
|
|
35
|
+
}
|
|
36
|
+
pop() {
|
|
37
|
+
if (this.length === 0)
|
|
38
|
+
throw new StackEmptyError();
|
|
39
|
+
this.evt.clear();
|
|
40
|
+
this.totalEntries--;
|
|
41
|
+
return super.pop();
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Awaits a value being available on the stack to retrieve it
|
|
45
|
+
* @param abortSignal
|
|
46
|
+
*/
|
|
47
|
+
awaitPop(abortSignal) {
|
|
48
|
+
if (this.size() === 0) {
|
|
49
|
+
const future = this.evt.wait();
|
|
50
|
+
if (abortSignal)
|
|
51
|
+
future.registerSignal(abortSignal);
|
|
52
|
+
return future.then((v) => {
|
|
53
|
+
if (this.size() > 0)
|
|
54
|
+
return this.pop();
|
|
55
|
+
return this.awaitPop(v.signal);
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
return Future.completed(this.pop());
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Retrieves the last item added to the stack
|
|
62
|
+
*/
|
|
63
|
+
peek() {
|
|
64
|
+
return this[this.pointer];
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Checks if the stack is empty
|
|
68
|
+
*/
|
|
69
|
+
get empty() {
|
|
70
|
+
return this.totalEntries === 0;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Checks if the stack is full
|
|
74
|
+
*/
|
|
75
|
+
get full() {
|
|
76
|
+
return this.size() === this.maxSize;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Retrieves the current stack size
|
|
80
|
+
*/
|
|
81
|
+
size() {
|
|
82
|
+
return this.totalEntries;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Empty the stack
|
|
86
|
+
*/
|
|
87
|
+
clear() {
|
|
88
|
+
while (!this.empty) {
|
|
89
|
+
this.pop();
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export { Stack };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* An immutable tuple of 3 values
|
|
5
|
+
*/
|
|
6
|
+
class Triple {
|
|
7
|
+
constructor(_first, _second, _third) {
|
|
8
|
+
this._first = _first;
|
|
9
|
+
this._second = _second;
|
|
10
|
+
this._third = _third;
|
|
11
|
+
}
|
|
12
|
+
get first() {
|
|
13
|
+
return this._first;
|
|
14
|
+
}
|
|
15
|
+
get second() {
|
|
16
|
+
return this._second;
|
|
17
|
+
}
|
|
18
|
+
get third() {
|
|
19
|
+
return this._third;
|
|
20
|
+
}
|
|
21
|
+
get last() {
|
|
22
|
+
return this.third;
|
|
23
|
+
}
|
|
24
|
+
get values() {
|
|
25
|
+
return [this._first, this._second, this._third];
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Creates an immutable tuple of 3 values
|
|
30
|
+
*/
|
|
31
|
+
const triple = (first, second, third) => new Triple(first, second, third);
|
|
32
|
+
|
|
33
|
+
exports.Triple = Triple;
|
|
34
|
+
exports.triple = triple;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Tuple } from "./Tuple";
|
|
2
|
+
/**
|
|
3
|
+
* An immutable tuple of 3 values
|
|
4
|
+
*/
|
|
5
|
+
export declare class Triple<T, V, K> implements Tuple<T, K> {
|
|
6
|
+
private readonly _first;
|
|
7
|
+
private readonly _second;
|
|
8
|
+
private readonly _third;
|
|
9
|
+
constructor(_first: T, _second: V, _third: K);
|
|
10
|
+
get first(): T;
|
|
11
|
+
get second(): V;
|
|
12
|
+
get third(): K;
|
|
13
|
+
get last(): K;
|
|
14
|
+
get values(): [T, V, K];
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Creates an immutable tuple of 3 values
|
|
18
|
+
*/
|
|
19
|
+
export declare const triple: <T, V, K>(first: T, second: V, third: K) => Triple<T, V, K>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An immutable tuple of 3 values
|
|
3
|
+
*/
|
|
4
|
+
class Triple {
|
|
5
|
+
constructor(_first, _second, _third) {
|
|
6
|
+
this._first = _first;
|
|
7
|
+
this._second = _second;
|
|
8
|
+
this._third = _third;
|
|
9
|
+
}
|
|
10
|
+
get first() {
|
|
11
|
+
return this._first;
|
|
12
|
+
}
|
|
13
|
+
get second() {
|
|
14
|
+
return this._second;
|
|
15
|
+
}
|
|
16
|
+
get third() {
|
|
17
|
+
return this._third;
|
|
18
|
+
}
|
|
19
|
+
get last() {
|
|
20
|
+
return this.third;
|
|
21
|
+
}
|
|
22
|
+
get values() {
|
|
23
|
+
return [this._first, this._second, this._third];
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Creates an immutable tuple of 3 values
|
|
28
|
+
*/
|
|
29
|
+
const triple = (first, second, third) => new Triple(first, second, third);
|
|
30
|
+
|
|
31
|
+
export { Triple, triple };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var CyclicalList = require('./array/CyclicalList.cjs');
|
|
4
|
+
var Stack = require('./array/Stack.cjs');
|
|
5
|
+
var Pair = require('./array/Pair.cjs');
|
|
6
|
+
var Triple = require('./array/Triple.cjs');
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
exports.CyclicalList = CyclicalList.CyclicalList;
|
|
11
|
+
exports.Stack = Stack.Stack;
|
|
12
|
+
exports.Pair = Pair.Pair;
|
|
13
|
+
exports.pair = Pair.pair;
|
|
14
|
+
exports.Triple = Triple.Triple;
|
|
15
|
+
exports.triple = Triple.triple;
|