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,215 @@
1
+ import { __awaiter, __asyncValues } from '../_virtual/_tslib.mjs';
2
+ import { Future } from '../future/future.mjs';
3
+ import 'ramda';
4
+ import '../stream.mjs';
5
+ import { Stack } from '../data-structures/array/Stack.mjs';
6
+ import '../data-structures/object/WatchableObject.mjs';
7
+ import 'object-hash';
8
+ import 'uuid';
9
+ import { AbortError } from '../errors/AbortError.mjs';
10
+ import { SimpleQueue } from '../data-structures/object/SimpleQueue.mjs';
11
+
12
+ class Collectors {
13
+ static read(functor) {
14
+ return (stream) => stream.forEach(functor);
15
+ }
16
+ static asList() {
17
+ return (stream) => {
18
+ return Future.of((resolve, reject, signal) => __awaiter(this, void 0, void 0, function* () {
19
+ var _a, e_1, _b, _c;
20
+ const collection = [];
21
+ try {
22
+ for (var _d = true, stream_1 = __asyncValues(stream), stream_1_1; stream_1_1 = yield stream_1.next(), _a = stream_1_1.done, !_a;) {
23
+ _c = stream_1_1.value;
24
+ _d = false;
25
+ try {
26
+ const value = _c;
27
+ collection.push(value);
28
+ if (signal.aborted) {
29
+ reject(new AbortError());
30
+ break;
31
+ }
32
+ }
33
+ finally {
34
+ _d = true;
35
+ }
36
+ }
37
+ }
38
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
39
+ finally {
40
+ try {
41
+ if (!_d && !_a && (_b = stream_1.return)) yield _b.call(stream_1);
42
+ }
43
+ finally { if (e_1) throw e_1.error; }
44
+ }
45
+ resolve(collection);
46
+ }));
47
+ };
48
+ }
49
+ static asSet() {
50
+ return (stream) => {
51
+ return Future.of((resolve, reject, signal) => __awaiter(this, void 0, void 0, function* () {
52
+ var _a, e_2, _b, _c;
53
+ const collection = new Set();
54
+ try {
55
+ for (var _d = true, stream_2 = __asyncValues(stream), stream_2_1; stream_2_1 = yield stream_2.next(), _a = stream_2_1.done, !_a;) {
56
+ _c = stream_2_1.value;
57
+ _d = false;
58
+ try {
59
+ const value = _c;
60
+ collection.add(value);
61
+ if (signal.aborted) {
62
+ reject(new AbortError());
63
+ break;
64
+ }
65
+ }
66
+ finally {
67
+ _d = true;
68
+ }
69
+ }
70
+ }
71
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
72
+ finally {
73
+ try {
74
+ if (!_d && !_a && (_b = stream_2.return)) yield _b.call(stream_2);
75
+ }
76
+ finally { if (e_2) throw e_2.error; }
77
+ }
78
+ resolve(collection);
79
+ }));
80
+ };
81
+ }
82
+ static joining(delimiter = "") {
83
+ return (stream) => {
84
+ return Future.of((resolve, reject, signal) => __awaiter(this, void 0, void 0, function* () {
85
+ let data = "";
86
+ let value;
87
+ const iterator = stream[Symbol.asyncIterator]();
88
+ value = yield iterator.next();
89
+ if (!value.done) {
90
+ do {
91
+ const nextValue = yield iterator.next();
92
+ if (!nextValue.done) {
93
+ data += value.value + delimiter;
94
+ value = nextValue;
95
+ }
96
+ else
97
+ break;
98
+ } while (!signal.aborted);
99
+ }
100
+ if (signal.aborted) {
101
+ reject(new AbortError());
102
+ return;
103
+ }
104
+ if (value.value !== undefined && value.value !== null) {
105
+ data += value.value;
106
+ }
107
+ resolve(data);
108
+ }));
109
+ };
110
+ }
111
+ static asStack(maxSize = undefined) {
112
+ return (stream) => {
113
+ return Future.of((resolve, reject, signal) => __awaiter(this, void 0, void 0, function* () {
114
+ var _a, e_3, _b, _c;
115
+ const collection = new Stack(maxSize);
116
+ try {
117
+ for (var _d = true, stream_3 = __asyncValues(stream), stream_3_1; stream_3_1 = yield stream_3.next(), _a = stream_3_1.done, !_a;) {
118
+ _c = stream_3_1.value;
119
+ _d = false;
120
+ try {
121
+ const value = _c;
122
+ collection.push(value);
123
+ if (collection.full) {
124
+ break;
125
+ }
126
+ else if (signal.aborted) {
127
+ reject(new AbortError());
128
+ break;
129
+ }
130
+ }
131
+ finally {
132
+ _d = true;
133
+ }
134
+ }
135
+ }
136
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
137
+ finally {
138
+ try {
139
+ if (!_d && !_a && (_b = stream_3.return)) yield _b.call(stream_3);
140
+ }
141
+ finally { if (e_3) throw e_3.error; }
142
+ }
143
+ resolve(collection);
144
+ }));
145
+ };
146
+ }
147
+ static asQueue() {
148
+ return (stream) => {
149
+ return Future.of((resolve, reject, signal) => __awaiter(this, void 0, void 0, function* () {
150
+ var _a, e_4, _b, _c;
151
+ const collection = new SimpleQueue();
152
+ try {
153
+ for (var _d = true, stream_4 = __asyncValues(stream), stream_4_1; stream_4_1 = yield stream_4.next(), _a = stream_4_1.done, !_a;) {
154
+ _c = stream_4_1.value;
155
+ _d = false;
156
+ try {
157
+ const value = _c;
158
+ collection.enqueue(value);
159
+ if (signal.aborted) {
160
+ reject(new AbortError());
161
+ break;
162
+ }
163
+ }
164
+ finally {
165
+ _d = true;
166
+ }
167
+ }
168
+ }
169
+ catch (e_4_1) { e_4 = { error: e_4_1 }; }
170
+ finally {
171
+ try {
172
+ if (!_d && !_a && (_b = stream_4.return)) yield _b.call(stream_4);
173
+ }
174
+ finally { if (e_4) throw e_4.error; }
175
+ }
176
+ resolve(collection);
177
+ }));
178
+ };
179
+ }
180
+ static counting() {
181
+ return (stream) => {
182
+ return Future.of((resolve, reject, signal) => __awaiter(this, void 0, void 0, function* () {
183
+ var _a, e_5, _b, _c;
184
+ let total = 0;
185
+ try {
186
+ for (var _d = true, stream_5 = __asyncValues(stream), stream_5_1; stream_5_1 = yield stream_5.next(), _a = stream_5_1.done, !_a;) {
187
+ _c = stream_5_1.value;
188
+ _d = false;
189
+ try {
190
+ const _ = _c;
191
+ total++;
192
+ if (signal.aborted) {
193
+ reject(new AbortError());
194
+ break;
195
+ }
196
+ }
197
+ finally {
198
+ _d = true;
199
+ }
200
+ }
201
+ }
202
+ catch (e_5_1) { e_5 = { error: e_5_1 }; }
203
+ finally {
204
+ try {
205
+ if (!_d && !_a && (_b = stream_5.return)) yield _b.call(stream_5);
206
+ }
207
+ finally { if (e_5) throw e_5.error; }
208
+ }
209
+ resolve(total);
210
+ }));
211
+ };
212
+ }
213
+ }
214
+
215
+ export { Collectors };
@@ -0,0 +1,257 @@
1
+ import { AnyDataType, Flattened, InferErrorResult, InferStreamResult } from "../typing/types";
2
+ import { Future, WaitPeriod } from "../future";
3
+ import { ExecutorState } from "./state";
4
+ import { Collector } from "./collector";
5
+ declare enum ActionType {
6
+ TRANSFORM = 0,
7
+ FILTER = 1,
8
+ LIMIT = 2,
9
+ UNPACK = 3,
10
+ PACK = 4,
11
+ CATCH = 5
12
+ }
13
+ export declare enum State {
14
+ MATCHED = 0,
15
+ CONTINUE = 1,
16
+ DONE = 2
17
+ }
18
+ interface LimitResult<T> {
19
+ value?: T;
20
+ done: boolean;
21
+ }
22
+ type ActionFunctor<T> = (v: T) => T | null | Promise<T> | LimitResult<T> | Promise<LimitResult<T>> | Stream<T>;
23
+ export type Executor = (v: AbortSignal) => Promise<any> | Future<any> | AnyDataType | ExecutorState<any> | Stream<any>;
24
+ /**
25
+ * Handles a continuous supply of data that can be transformed and manipulated using a chain of actions
26
+ */
27
+ export declare class Stream<T> implements AsyncGenerator<T> {
28
+ protected executed: boolean;
29
+ protected actions: Array<{
30
+ type: ActionType;
31
+ functor: ActionFunctor<T>;
32
+ }>;
33
+ protected cancelHooks: Set<() => any>;
34
+ protected completionHooks: Set<() => any>;
35
+ protected completionHookInvoked: boolean;
36
+ protected done: boolean;
37
+ protected backlog: Array<{
38
+ records: T[] | Stream<T>;
39
+ actionStream: number;
40
+ }>;
41
+ private canRunExecutor;
42
+ private readonly runLock;
43
+ /**
44
+ * AbortController used to cancel http request created by the callback
45
+ * @private
46
+ */
47
+ private controller;
48
+ /**
49
+ * Callback function that executes a network request. Function should accept an AbortSignal as argument,
50
+ * and return AnyDataType upon completion
51
+ * @private
52
+ */
53
+ protected executor: Executor;
54
+ private concurrencyLimit;
55
+ private sourceStream?;
56
+ constructor(executor: Executor);
57
+ /**
58
+ * Used to provide setup logic that should only be invoked once, when stream
59
+ * is starting. This setup logic must provide the actual data required, which
60
+ * can come from a Stream or Future
61
+ * @param supplier
62
+ */
63
+ static seed<T>(supplier: () => Stream<T> | Future<T>): Stream<T>;
64
+ /**
65
+ * Streams the next available result from a list of futures, until all future completes. If any future fails, then the
66
+ * stream will throw an error
67
+ * @param futures
68
+ */
69
+ static asCompleted(futures: Array<Future<any>>): Stream<unknown>;
70
+ /**
71
+ * Stream the next available result from the list of streams. If any stream fails, then this merged stream also fails.
72
+ * @param streams
73
+ */
74
+ static merge<K extends Array<Stream<any>>>(streams: K): Stream<InferStreamResult<K[number]>>;
75
+ /**
76
+ * Aggregates the results from multiple streams
77
+ * @param streams
78
+ */
79
+ static zip<K extends Array<Stream<any>>>(streams: K): Stream<Array<InferStreamResult<K[number]>>>;
80
+ /**
81
+ * Converts the provided value to a stream
82
+ * @param value
83
+ */
84
+ static of<K>(value: AsyncIterable<K> | Iterable<K> | ((v: AbortSignal) => AsyncGenerator<K, any, any>) | AsyncGenerator<K> | AsyncGeneratorFunction | Future<K> | ReadableStream<K>): Stream<K>;
85
+ /**
86
+ * Stream that never gives a result
87
+ */
88
+ static forever(): Stream<null>;
89
+ get isParallel(): Stream<T>;
90
+ /**
91
+ * Gets a future of the next value on the stream, if any.
92
+ */
93
+ get future(): Future<T>;
94
+ get readableStream(): ReadableStream<T>;
95
+ /**
96
+ * Cancel the stream on the given signal
97
+ * @param signal
98
+ */
99
+ cancelOnSignal(signal: AbortSignal): this;
100
+ parallel(concurrentlyLimit?: number): Stream<T>;
101
+ /**
102
+ * Transforms each data on the stream using the callback provided
103
+ * @param callback
104
+ */
105
+ map<K>(callback: (v: T) => K | Promise<K> | Future<K> | Stream<K>): Stream<InferStreamResult<K>>;
106
+ /**
107
+ * Filters data on the stream using the callback provided
108
+ * @param callback
109
+ */
110
+ filter(callback: (v: T) => boolean | Promise<boolean> | Future<boolean>): Stream<T>;
111
+ reduce<K, V>(initialData: K, functor: (v: T, prev: K | V) => V, exhaustive?: boolean): Stream<V>;
112
+ reduceWhile<K, V>(predicate: (v: T) => boolean, initialData: K, functor: (v: T, prev: K | V) => V, exhaustive?: boolean): Stream<V>;
113
+ /**
114
+ * Retrieves the first value from the stream as a new stream. Important Note: the original stream cannot be executed
115
+ * before head() is invoked, otherwise the stream returned by head() will throw an error, as the first value was
116
+ * already consumed elsewhere
117
+ */
118
+ head(): Stream<T>;
119
+ /**
120
+ * Returns a new stream that exhausts the original stream, yielding the last value received before the original
121
+ * stream ended
122
+ */
123
+ tail(): Stream<T>;
124
+ /**
125
+ * group data on the stream into separate slices
126
+ * E.g. Stream yielding 1,2,3,4,5,6 with chunk of 2 => [1,2], [3,4], [5,6]
127
+ * @param value chunk size or function that indicates when to split
128
+ * @param keepSplitCriteria if value provided was a function, this parameter is used to determine if the data used
129
+ * for the split criteria should be added to the chunk, if false then the data will be added to the next chunk
130
+ */
131
+ chunk(value: number | ((v: T) => boolean), keepSplitCriteria?: boolean): Stream<T[]>;
132
+ /**
133
+ * Clones the stream
134
+ * @param withSignals should the abort signals of the original stream trigger the cloned stream cancellation
135
+ */
136
+ clone(withSignals?: boolean): Stream<T>;
137
+ /**
138
+ * Register hook that is only ever called if stream was cancelled
139
+ * @param hook
140
+ */
141
+ onCancellation(hook: () => any): this;
142
+ removeCancelHook(hook: () => any): this;
143
+ /**
144
+ * Register hook that is called once the stream completes, cancelled or fails
145
+ * @param hook
146
+ */
147
+ onCompletion(hook: () => any): this;
148
+ removeCompletionHook(hook: () => any): this;
149
+ /**
150
+ * Cancels the stream
151
+ * @param reason
152
+ */
153
+ cancel(reason?: any): void;
154
+ /**
155
+ * Limits the number of times the stream can yield a value
156
+ * @param count
157
+ */
158
+ take(count: number): Stream<T>;
159
+ /**
160
+ * Process stream data while predicate is true
161
+ * @param predicate
162
+ */
163
+ takeWhile(predicate: (v: T) => boolean): Stream<T>;
164
+ /**
165
+ * Drop stream data until predicate is no longer true
166
+ * @param predicate
167
+ */
168
+ skipWhile(predicate: (v: T) => boolean): Stream<T>;
169
+ /**
170
+ * Removes duplicates from the stream based on the key extractor functor provided
171
+ * @param uniqKeyExtractor
172
+ * @param expiryPeriod
173
+ */
174
+ dropRepeats(uniqKeyExtractor: (v: T) => string, expiryPeriod?: WaitPeriod | undefined): Stream<T>;
175
+ /**
176
+ * Allows the stream to yield only 1 value
177
+ */
178
+ once(): Stream<T>;
179
+ /**
180
+ * Skips the first X records on the stream
181
+ * @param count
182
+ */
183
+ skip(count: number): this;
184
+ /**
185
+ * Applies rate limiting to the speed at which the data is made available on the stream
186
+ * @param period
187
+ */
188
+ throttleBy(period: WaitPeriod): this;
189
+ /**
190
+ * Flattens any nested structure from the data arriving on the stream
191
+ */
192
+ flatten(): Stream<Flattened<T>>;
193
+ /**
194
+ * Runs the stream in the background, collecting and buffering the results for the next chain in the stream. This
195
+ * allows the stream to run concurrently without waiting on single emitted values sequentially
196
+ * @param maxSize
197
+ */
198
+ buffer(maxSize?: number): Stream<T>;
199
+ /**
200
+ * Process stream values in the background, thereby yielding the latest value if the collector of the stream is too
201
+ * slow (i.e. values that are not read by collector before new value flows in the stream, will be dropped)
202
+ */
203
+ conflate(): Stream<T>;
204
+ /**
205
+ * If the stream receives an error, handle that error with the given callback. If callback doesn't throw an error,
206
+ * then the stream will recover and resume with the result provided by the callback
207
+ * @param callback
208
+ */
209
+ catch<K>(callback: (v: Error) => K | null | undefined): Stream<InferErrorResult<K, T> | T>;
210
+ /**
211
+ * Consumes the entire stream and store the data in an array. Future is immediately executed
212
+ */
213
+ collect<K>(collector: Collector<K, T>): Future<K>;
214
+ /**
215
+ * Continuously exhaust the stream until the stream ends or the limit is reached. No result will be provided at
216
+ * the end. Future is immediately executed
217
+ * @param limit
218
+ */
219
+ consume(limit?: number): Future<void>;
220
+ /**
221
+ * Iterates over the stream of values, used as a collector. Future is immediately executed
222
+ * @param callback
223
+ */
224
+ forEach(callback: (v: T) => void | Future<void>): Future<void>;
225
+ /**
226
+ * Runs the stream only once. After this call, the stream is closed. Future is immediately executed
227
+ */
228
+ execute(): Future<T>;
229
+ join(): Stream<T>;
230
+ [Symbol.asyncIterator](): AsyncGenerator<T, any, unknown>;
231
+ next(...args: [] | [unknown]): Promise<IteratorResult<T, any>>;
232
+ return(value: any): Promise<IteratorResult<T, any>>;
233
+ return(value?: any): Promise<IteratorResult<T, any>>;
234
+ throw(e: any): Promise<IteratorResult<T, any>>;
235
+ throw(e?: any): Promise<IteratorResult<T, any>>;
236
+ protected __execute__(preProcessor?: <T>(a: T) => T | Promise<T>): Future<{
237
+ state: State;
238
+ value?: T;
239
+ }>;
240
+ protected processor(index: number, traversableActions: Array<{
241
+ type: ActionType;
242
+ functor: ActionFunctor<T>;
243
+ }>, record: any, preProcessor: <T>(a: T) => T | Promise<T>, signal: AbortSignal): Future<{
244
+ state: State;
245
+ value?: T | undefined;
246
+ }>;
247
+ private internalIterator;
248
+ private checkBacklog;
249
+ private internalNext;
250
+ private invokeCompletionHooks;
251
+ private processError;
252
+ private findAndExecuteMostRecentPacker;
253
+ private yieldTrueResult;
254
+ private forwardExecute;
255
+ private collectResult;
256
+ }
257
+ export {};
@@ -0,0 +1,110 @@
1
+ 'use strict';
2
+
3
+ var stream = require('../stream.cjs');
4
+ var future = require('../future/future.cjs');
5
+ require('ramda');
6
+ require('../data-structures/object/WatchableObject.cjs');
7
+ require('object-hash');
8
+ require('uuid');
9
+ var Queue = require('../data-structures/object/Queue.cjs');
10
+ var signal = require('../data/signal.cjs');
11
+
12
+ /**
13
+ * Provides a Publisher-Subscriber service around an event stream
14
+ */
15
+ class Observable {
16
+ signal(topic) {
17
+ return new signal.Signal(this.subscribe(topic).map((v) => v.data));
18
+ }
19
+ /**
20
+ * Pull data off a stream and publishes it
21
+ * @param topic topic used to dispatch data to subscribers
22
+ * @param stream any data stream
23
+ */
24
+ publishFromStream(topic, stream) {
25
+ return stream
26
+ .map((data) => this.publish(topic, data))
27
+ .consume()
28
+ .schedule();
29
+ }
30
+ /**
31
+ * Provides a Request-Reply model by sending data over the given topic, and
32
+ * await a response over the second topic provided.
33
+ * @param reqTopic
34
+ * @param replyTopic
35
+ * @param data
36
+ * @param timeout how long to wait for a response, defaults to 15 seconds
37
+ */
38
+ request(reqTopic, replyTopic, data, timeout = { seconds: 15 }) {
39
+ this.publish(reqTopic, data);
40
+ return future.Future.waitFor(this.subscribe(replyTopic, 2).future, timeout).thenApply(({ value }) => value.data);
41
+ }
42
+ }
43
+ /**
44
+ * Provides Publisher-Subscriber service around an EventTarget
45
+ */
46
+ class ObservableEventTarget extends Observable {
47
+ constructor() {
48
+ super();
49
+ this.__internal__ = new EventTarget();
50
+ }
51
+ publish(topic, data) {
52
+ this.__internal__.dispatchEvent(new CustomEvent(topic, { detail: { topic, data } }));
53
+ this.__internal__.dispatchEvent(new CustomEvent("*", { detail: { topic, data } }));
54
+ }
55
+ subscribe(topic, bufferSize = undefined, expiryPeriod = undefined) {
56
+ const queue = new Queue.Queue(bufferSize, expiryPeriod);
57
+ const listener = typeof topic === "string"
58
+ ? (evt) => queue.enqueue(evt.detail)
59
+ : (evt) => {
60
+ if (topic.test(evt.detail.topic)) {
61
+ queue.enqueue(evt.detail);
62
+ }
63
+ };
64
+ const listeningTopic = typeof topic === "string" ? topic : "*";
65
+ return stream.Stream.seed(() => {
66
+ this.__internal__.addEventListener(listeningTopic, listener);
67
+ return queue.streamEntries;
68
+ }).onCompletion(() => {
69
+ this.__internal__.removeEventListener(listeningTopic, listener);
70
+ queue.clear();
71
+ });
72
+ }
73
+ }
74
+ /**
75
+ * Provides Publisher-Subscriber service around a MessagePort
76
+ */
77
+ class ObservableMessagePort extends Observable {
78
+ constructor(messagePort) {
79
+ super();
80
+ this.messagePort = messagePort;
81
+ }
82
+ publish(topic, data) {
83
+ this.messagePort.postMessage({ topic, data });
84
+ }
85
+ subscribe(topic, bufferSize = undefined, expiryPeriod = undefined) {
86
+ const queue = new Queue.Queue(bufferSize, expiryPeriod);
87
+ const listener = typeof topic === "string"
88
+ ? (evt) => {
89
+ if (topic === "*" || evt.data.topic === topic) {
90
+ queue.enqueue(evt.data);
91
+ }
92
+ }
93
+ : (evt) => {
94
+ if (topic.test(evt.data.topic)) {
95
+ queue.enqueue(evt.data);
96
+ }
97
+ };
98
+ return stream.Stream.seed(() => {
99
+ this.messagePort.addEventListener("message", listener);
100
+ return queue.streamEntries;
101
+ }).onCompletion(() => {
102
+ this.messagePort.removeEventListener("message", listener);
103
+ queue.clear();
104
+ });
105
+ }
106
+ }
107
+
108
+ exports.Observable = Observable;
109
+ exports.ObservableEventTarget = ObservableEventTarget;
110
+ exports.ObservableMessagePort = ObservableMessagePort;
@@ -0,0 +1,65 @@
1
+ import { Stream } from "./index";
2
+ import { Future, WaitPeriod } from "../future";
3
+ import { Signal } from "../data/signal";
4
+ /**
5
+ * Provides a Publisher-Subscriber service around an event stream
6
+ */
7
+ export declare abstract class Observable<T> {
8
+ /**
9
+ * Dispatches data to all subscribers listening on the provided topic
10
+ * @param topic
11
+ * @param data
12
+ */
13
+ abstract publish(topic: string, data: T): void;
14
+ /**
15
+ * Monitor for incoming data on the provided topic. If topic is '*', then
16
+ * will subscribe to all incoming data
17
+ * @param topic
18
+ * @param bufferSize
19
+ * @param expiryPeriod
20
+ */
21
+ abstract subscribe(topic: string | RegExp, bufferSize?: number, expiryPeriod?: WaitPeriod): Stream<{
22
+ topic: string;
23
+ data: T;
24
+ }>;
25
+ signal(topic: string | RegExp): Signal<T>;
26
+ /**
27
+ * Pull data off a stream and publishes it
28
+ * @param topic topic used to dispatch data to subscribers
29
+ * @param stream any data stream
30
+ */
31
+ publishFromStream(topic: string, stream: Stream<T>): Future<void>;
32
+ /**
33
+ * Provides a Request-Reply model by sending data over the given topic, and
34
+ * await a response over the second topic provided.
35
+ * @param reqTopic
36
+ * @param replyTopic
37
+ * @param data
38
+ * @param timeout how long to wait for a response, defaults to 15 seconds
39
+ */
40
+ request(reqTopic: string, replyTopic: string, data: T, timeout?: WaitPeriod): Future<T>;
41
+ }
42
+ /**
43
+ * Provides Publisher-Subscriber service around an EventTarget
44
+ */
45
+ export declare class ObservableEventTarget<T> extends Observable<T> {
46
+ private readonly __internal__;
47
+ constructor();
48
+ publish(topic: string, data: T): void;
49
+ subscribe(topic: string | RegExp, bufferSize?: number | undefined, expiryPeriod?: WaitPeriod | undefined): Stream<{
50
+ topic: string;
51
+ data: T;
52
+ }>;
53
+ }
54
+ /**
55
+ * Provides Publisher-Subscriber service around a MessagePort
56
+ */
57
+ export declare class ObservableMessagePort<T> extends Observable<T> {
58
+ private readonly messagePort;
59
+ constructor(messagePort: MessagePort);
60
+ publish(topic: string, data: T): void;
61
+ subscribe(topic: string | RegExp, bufferSize?: number | undefined, expiryPeriod?: WaitPeriod | undefined): Stream<{
62
+ topic: string;
63
+ data: T;
64
+ }>;
65
+ }