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.
Files changed (251) hide show
  1. package/_virtual/_tslib.cjs +102 -0
  2. package/_virtual/_tslib.mjs +93 -0
  3. package/data/AtomicValue.d.ts +15 -0
  4. package/data/bus.cjs +179 -0
  5. package/data/bus.d.ts +72 -0
  6. package/data/bus.mjs +177 -0
  7. package/data/decoders/index.d.ts +4 -0
  8. package/data/decoders/json.cjs +12 -0
  9. package/data/decoders/json.d.ts +7 -0
  10. package/data/decoders/json.mjs +10 -0
  11. package/data/decoders/msgpack.cjs +14 -0
  12. package/data/decoders/msgpack.d.ts +7 -0
  13. package/data/decoders/msgpack.mjs +12 -0
  14. package/data/decoders/protobuf.d.ts +13 -0
  15. package/data/decoders/string.cjs +12 -0
  16. package/data/decoders/string.d.ts +7 -0
  17. package/data/decoders/string.mjs +10 -0
  18. package/data/decoders/type.d.ts +7 -0
  19. package/data/decoders.cjs +11 -0
  20. package/data/decoders.mjs +3 -0
  21. package/data/model/credentials.cjs +114 -0
  22. package/data/model/credentials.d.ts +61 -0
  23. package/data/model/credentials.mjs +109 -0
  24. package/data/model/extra.cjs +88 -0
  25. package/data/model/extra.d.ts +5 -0
  26. package/data/model/extra.mjs +66 -0
  27. package/data/model/index.d.ts +6 -0
  28. package/data/model/model.cjs +541 -0
  29. package/data/model/model.d.ts +207 -0
  30. package/data/model/model.mjs +518 -0
  31. package/data/model/plugin.cjs +96 -0
  32. package/data/model/plugin.d.ts +38 -0
  33. package/data/model/plugin.mjs +72 -0
  34. package/data/model/property.cjs +310 -0
  35. package/data/model/property.d.ts +83 -0
  36. package/data/model/property.mjs +278 -0
  37. package/data/model/types.cjs +32 -0
  38. package/data/model/types.d.ts +28 -0
  39. package/data/model/types.mjs +32 -0
  40. package/data/model.cjs +43 -0
  41. package/data/model.mjs +6 -0
  42. package/data/signal.cjs +47 -0
  43. package/data/signal.d.ts +17 -0
  44. package/data/signal.mjs +45 -0
  45. package/data/store/index.d.ts +4 -0
  46. package/data/store/json.cjs +58 -0
  47. package/data/store/json.d.ts +18 -0
  48. package/data/store/json.mjs +56 -0
  49. package/data/store/manager.cjs +206 -0
  50. package/data/store/manager.d.ts +44 -0
  51. package/data/store/manager.mjs +203 -0
  52. package/data/store/web.cjs +92 -0
  53. package/data/store/web.d.ts +25 -0
  54. package/data/store/web.mjs +89 -0
  55. package/data/value.cjs +66 -0
  56. package/data/value.mjs +64 -0
  57. package/data-structures/array/CyclicalList.cjs +57 -0
  58. package/data-structures/array/CyclicalList.d.ts +12 -0
  59. package/data-structures/array/CyclicalList.mjs +55 -0
  60. package/data-structures/array/Pair.cjs +30 -0
  61. package/data-structures/array/Pair.d.ts +17 -0
  62. package/data-structures/array/Pair.mjs +27 -0
  63. package/data-structures/array/Stack.cjs +96 -0
  64. package/data-structures/array/Stack.d.ts +41 -0
  65. package/data-structures/array/Stack.mjs +94 -0
  66. package/data-structures/array/Triple.cjs +34 -0
  67. package/data-structures/array/Triple.d.ts +19 -0
  68. package/data-structures/array/Triple.mjs +31 -0
  69. package/data-structures/array/Tuple.d.ts +8 -0
  70. package/data-structures/array/index.d.ts +5 -0
  71. package/data-structures/array.cjs +15 -0
  72. package/data-structures/array.mjs +4 -0
  73. package/data-structures/object/BufferQueue.cjs +98 -0
  74. package/data-structures/object/BufferQueue.d.ts +21 -0
  75. package/data-structures/object/BufferQueue.mjs +77 -0
  76. package/data-structures/object/CyclicalObject.cjs +155 -0
  77. package/data-structures/object/CyclicalObject.d.ts +74 -0
  78. package/data-structures/object/CyclicalObject.mjs +134 -0
  79. package/data-structures/object/Queue.cjs +178 -0
  80. package/data-structures/object/Queue.d.ts +31 -0
  81. package/data-structures/object/Queue.mjs +176 -0
  82. package/data-structures/object/SimpleQueue.cjs +53 -0
  83. package/data-structures/object/SimpleQueue.d.ts +13 -0
  84. package/data-structures/object/SimpleQueue.mjs +51 -0
  85. package/data-structures/object/TimeableObject.cjs +73 -0
  86. package/data-structures/object/TimeableObject.d.ts +30 -0
  87. package/data-structures/object/TimeableObject.mjs +71 -0
  88. package/data-structures/object/WaitableObject.cjs +61 -0
  89. package/data-structures/object/WaitableObject.d.ts +29 -0
  90. package/data-structures/object/WaitableObject.mjs +59 -0
  91. package/data-structures/object/WatchableObject.cjs +251 -0
  92. package/data-structures/object/WatchableObject.d.ts +88 -0
  93. package/data-structures/object/WatchableObject.mjs +230 -0
  94. package/data-structures/object/index.d.ts +7 -0
  95. package/data-structures/object.cjs +23 -0
  96. package/data-structures/object.mjs +7 -0
  97. package/errors/AbortError.cjs +9 -0
  98. package/errors/AbortError.d.ts +5 -0
  99. package/errors/AbortError.mjs +7 -0
  100. package/errors/CallExecutionError.cjs +13 -0
  101. package/errors/CallExecutionError.d.ts +7 -0
  102. package/errors/CallExecutionError.mjs +11 -0
  103. package/errors/FutureCancelled.cjs +11 -0
  104. package/errors/FutureCancelled.d.ts +6 -0
  105. package/errors/FutureCancelled.mjs +9 -0
  106. package/errors/FutureError.cjs +11 -0
  107. package/errors/FutureError.d.ts +6 -0
  108. package/errors/FutureError.mjs +9 -0
  109. package/errors/IllegalArgumentsError.cjs +13 -0
  110. package/errors/IllegalArgumentsError.d.ts +7 -0
  111. package/errors/IllegalArgumentsError.mjs +11 -0
  112. package/errors/IllegalOperationError.cjs +6 -0
  113. package/errors/IllegalOperationError.d.ts +2 -0
  114. package/errors/IllegalOperationError.mjs +4 -0
  115. package/errors/InvalidType.cjs +6 -0
  116. package/errors/InvalidType.d.ts +2 -0
  117. package/errors/InvalidType.mjs +4 -0
  118. package/errors/InvalidValue.cjs +11 -0
  119. package/errors/InvalidValue.d.ts +4 -0
  120. package/errors/InvalidValue.mjs +9 -0
  121. package/errors/MissingArgumentsError.cjs +13 -0
  122. package/errors/MissingArgumentsError.d.ts +7 -0
  123. package/errors/MissingArgumentsError.mjs +11 -0
  124. package/errors/NetworkError.cjs +13 -0
  125. package/errors/NetworkError.d.ts +8 -0
  126. package/errors/NetworkError.mjs +11 -0
  127. package/errors/NoSuchElement.cjs +6 -0
  128. package/errors/NoSuchElement.d.ts +2 -0
  129. package/errors/NoSuchElement.mjs +4 -0
  130. package/errors/NotImplemented.cjs +9 -0
  131. package/errors/NotImplemented.d.ts +5 -0
  132. package/errors/NotImplemented.mjs +7 -0
  133. package/errors/ParsingError.cjs +10 -0
  134. package/errors/ParsingError.d.ts +5 -0
  135. package/errors/ParsingError.mjs +8 -0
  136. package/errors/QueueEmptyError.cjs +6 -0
  137. package/errors/QueueEmptyError.d.ts +2 -0
  138. package/errors/QueueEmptyError.mjs +4 -0
  139. package/errors/QueueFullError.cjs +6 -0
  140. package/errors/QueueFullError.d.ts +2 -0
  141. package/errors/QueueFullError.mjs +4 -0
  142. package/errors/StackEmptyError.cjs +6 -0
  143. package/errors/StackEmptyError.d.ts +2 -0
  144. package/errors/StackEmptyError.mjs +4 -0
  145. package/errors/StackFullError.cjs +6 -0
  146. package/errors/StackFullError.d.ts +2 -0
  147. package/errors/StackFullError.mjs +4 -0
  148. package/errors/StreamEnded.cjs +6 -0
  149. package/errors/StreamEnded.d.ts +2 -0
  150. package/errors/StreamEnded.mjs +4 -0
  151. package/errors/TimeoutError.cjs +11 -0
  152. package/errors/TimeoutError.d.ts +6 -0
  153. package/errors/TimeoutError.mjs +9 -0
  154. package/errors/ValueDestroyedError.cjs +6 -0
  155. package/errors/ValueDestroyedError.d.ts +2 -0
  156. package/errors/ValueDestroyedError.mjs +4 -0
  157. package/errors/VerificationError.cjs +9 -0
  158. package/errors/VerificationError.d.ts +5 -0
  159. package/errors/VerificationError.mjs +7 -0
  160. package/errors/index.d.ts +18 -0
  161. package/errors.cjs +41 -0
  162. package/errors.mjs +18 -0
  163. package/files.cjs +201 -0
  164. package/files.d.ts +31 -0
  165. package/files.mjs +180 -0
  166. package/functools/index.d.ts +31 -0
  167. package/functools.cjs +371 -0
  168. package/functools.mjs +334 -0
  169. package/future/future.cjs +570 -0
  170. package/future/future.d.ts +208 -0
  171. package/future/future.mjs +548 -0
  172. package/future/group.cjs +180 -0
  173. package/future/group.d.ts +82 -0
  174. package/future/group.mjs +159 -0
  175. package/future/index.d.ts +3 -0
  176. package/future/result.cjs +19 -0
  177. package/future/result.d.ts +18 -0
  178. package/future/result.mjs +17 -0
  179. package/future.cjs +11 -0
  180. package/future.mjs +3 -0
  181. package/managers/context.d.ts +8 -0
  182. package/managers/index.d.ts +1 -0
  183. package/managers.cjs +2 -0
  184. package/managers.mjs +1 -0
  185. package/mocks.cjs +301 -0
  186. package/mocks.d.ts +125 -0
  187. package/mocks.mjs +293 -0
  188. package/networking/EventSourceService.cjs +104 -0
  189. package/networking/EventSourceService.d.ts +11 -0
  190. package/networking/EventSourceService.mjs +83 -0
  191. package/networking/NetworkService.cjs +394 -0
  192. package/networking/NetworkService.d.ts +97 -0
  193. package/networking/NetworkService.mjs +373 -0
  194. package/networking/SocketService.cjs +218 -0
  195. package/networking/SocketService.d.ts +23 -0
  196. package/networking/SocketService.mjs +197 -0
  197. package/networking/decorators/index.d.ts +4 -0
  198. package/networking/decorators/options.cjs +289 -0
  199. package/networking/decorators/options.d.ts +148 -0
  200. package/networking/decorators/options.mjs +242 -0
  201. package/networking/decorators/requests.cjs +80 -0
  202. package/networking/decorators/requests.d.ts +34 -0
  203. package/networking/decorators/requests.mjs +52 -0
  204. package/networking/decorators/socket.cjs +81 -0
  205. package/networking/decorators/socket.d.ts +13 -0
  206. package/networking/decorators/socket.mjs +51 -0
  207. package/networking/http.cjs +69 -0
  208. package/networking/http.d.ts +66 -0
  209. package/networking/http.mjs +69 -0
  210. package/networking/index.d.ts +39 -0
  211. package/networking/request.cjs +18 -0
  212. package/networking/request.d.ts +9 -0
  213. package/networking/request.mjs +16 -0
  214. package/networking/types.cjs +37 -0
  215. package/networking/types.d.ts +132 -0
  216. package/networking/types.mjs +35 -0
  217. package/networking.cjs +91 -0
  218. package/networking.mjs +33 -0
  219. package/package.json +1 -0
  220. package/reflection/injector.cjs +43 -0
  221. package/reflection/injector.d.ts +3 -0
  222. package/reflection/injector.mjs +40 -0
  223. package/socket.cjs +239 -0
  224. package/socket.d.ts +65 -0
  225. package/socket.mjs +237 -0
  226. package/store.cjs +12 -0
  227. package/store.mjs +3 -0
  228. package/stream/call.cjs +157 -0
  229. package/stream/call.d.ts +66 -0
  230. package/stream/call.mjs +154 -0
  231. package/stream/collector.cjs +217 -0
  232. package/stream/collector.d.ts +14 -0
  233. package/stream/collector.mjs +215 -0
  234. package/stream/index.d.ts +257 -0
  235. package/stream/observable.cjs +110 -0
  236. package/stream/observable.d.ts +65 -0
  237. package/stream/observable.mjs +106 -0
  238. package/stream/state.cjs +10 -0
  239. package/stream/state.d.ts +5 -0
  240. package/stream/state.mjs +8 -0
  241. package/stream.cjs +1153 -0
  242. package/stream.mjs +1132 -0
  243. package/synchronize.cjs +106 -0
  244. package/synchronize.d.ts +54 -0
  245. package/synchronize.mjs +103 -0
  246. package/typing/types.d.ts +24 -0
  247. package/typing.cjs +2 -0
  248. package/typing.mjs +1 -0
  249. package/utils/parser.cjs +37 -0
  250. package/utils/parser.d.ts +7 -0
  251. 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 };