@jonloucks/concurrency-ts 0.4.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 (174) hide show
  1. package/README.md +248 -0
  2. package/api/Completable.d.ts +51 -0
  3. package/api/Completable.d.ts.map +1 -0
  4. package/api/Completable.js +11 -0
  5. package/api/Completable.js.map +1 -0
  6. package/api/CompletableFactory.d.ts +29 -0
  7. package/api/CompletableFactory.d.ts.map +1 -0
  8. package/api/CompletableFactory.js +19 -0
  9. package/api/CompletableFactory.js.map +1 -0
  10. package/api/Completion.d.ts +18 -0
  11. package/api/Completion.d.ts.map +1 -0
  12. package/api/Completion.js +2 -0
  13. package/api/Completion.js.map +1 -0
  14. package/api/CompletionNotify.d.ts +23 -0
  15. package/api/CompletionNotify.d.ts.map +1 -0
  16. package/api/CompletionNotify.js +11 -0
  17. package/api/CompletionNotify.js.map +1 -0
  18. package/api/CompletionState.d.ts +35 -0
  19. package/api/CompletionState.d.ts.map +1 -0
  20. package/api/CompletionState.js +64 -0
  21. package/api/CompletionState.js.map +1 -0
  22. package/api/Concurrency.d.ts +90 -0
  23. package/api/Concurrency.d.ts.map +1 -0
  24. package/api/Concurrency.js +19 -0
  25. package/api/Concurrency.js.map +1 -0
  26. package/api/ConcurrencyException.d.ts +27 -0
  27. package/api/ConcurrencyException.d.ts.map +1 -0
  28. package/api/ConcurrencyException.js +53 -0
  29. package/api/ConcurrencyException.js.map +1 -0
  30. package/api/ConcurrencyFactory.d.ts +41 -0
  31. package/api/ConcurrencyFactory.d.ts.map +1 -0
  32. package/api/ConcurrencyFactory.js +19 -0
  33. package/api/ConcurrencyFactory.js.map +1 -0
  34. package/api/IsCompleted.d.ts +20 -0
  35. package/api/IsCompleted.d.ts.map +1 -0
  36. package/api/IsCompleted.js +11 -0
  37. package/api/IsCompleted.js.map +1 -0
  38. package/api/OnCompletion.d.ts +23 -0
  39. package/api/OnCompletion.d.ts.map +1 -0
  40. package/api/OnCompletion.js +12 -0
  41. package/api/OnCompletion.js.map +1 -0
  42. package/api/Rule.d.ts +28 -0
  43. package/api/Rule.d.ts.map +1 -0
  44. package/api/Rule.js +11 -0
  45. package/api/Rule.js.map +1 -0
  46. package/api/StateMachine.d.ts +95 -0
  47. package/api/StateMachine.d.ts.map +1 -0
  48. package/api/StateMachine.js +13 -0
  49. package/api/StateMachine.js.map +1 -0
  50. package/api/StateMachineFactory.d.ts +29 -0
  51. package/api/StateMachineFactory.d.ts.map +1 -0
  52. package/api/StateMachineFactory.js +19 -0
  53. package/api/StateMachineFactory.js.map +1 -0
  54. package/api/TimeoutException.d.ts +21 -0
  55. package/api/TimeoutException.d.ts.map +1 -0
  56. package/api/TimeoutException.js +27 -0
  57. package/api/TimeoutException.js.map +1 -0
  58. package/api/Transition.d.ts +44 -0
  59. package/api/Transition.d.ts.map +1 -0
  60. package/api/Transition.js +11 -0
  61. package/api/Transition.js.map +1 -0
  62. package/api/Types.d.ts +27 -0
  63. package/api/Types.d.ts.map +1 -0
  64. package/api/Types.js +28 -0
  65. package/api/Types.js.map +1 -0
  66. package/api/Waitable.d.ts +39 -0
  67. package/api/Waitable.d.ts.map +1 -0
  68. package/api/Waitable.js +17 -0
  69. package/api/Waitable.js.map +1 -0
  70. package/api/WaitableConsumer.d.ts +54 -0
  71. package/api/WaitableConsumer.d.ts.map +1 -0
  72. package/api/WaitableConsumer.js +11 -0
  73. package/api/WaitableConsumer.js.map +1 -0
  74. package/api/WaitableFactory.d.ts +29 -0
  75. package/api/WaitableFactory.d.ts.map +1 -0
  76. package/api/WaitableFactory.js +19 -0
  77. package/api/WaitableFactory.js.map +1 -0
  78. package/api/WaitableNotify.d.ts +31 -0
  79. package/api/WaitableNotify.d.ts.map +1 -0
  80. package/api/WaitableNotify.js +12 -0
  81. package/api/WaitableNotify.js.map +1 -0
  82. package/api/WaitableSupplier.d.ts +53 -0
  83. package/api/WaitableSupplier.d.ts.map +1 -0
  84. package/api/WaitableSupplier.js +11 -0
  85. package/api/WaitableSupplier.js.map +1 -0
  86. package/auxiliary/Checks.d.ts +116 -0
  87. package/auxiliary/Checks.d.ts.map +1 -0
  88. package/auxiliary/Checks.js +145 -0
  89. package/auxiliary/Checks.js.map +1 -0
  90. package/auxiliary/Consumer.d.ts +45 -0
  91. package/auxiliary/Consumer.d.ts.map +1 -0
  92. package/auxiliary/Consumer.js +45 -0
  93. package/auxiliary/Consumer.js.map +1 -0
  94. package/auxiliary/Predicate.d.ts +55 -0
  95. package/auxiliary/Predicate.d.ts.map +1 -0
  96. package/auxiliary/Predicate.js +73 -0
  97. package/auxiliary/Predicate.js.map +1 -0
  98. package/auxiliary/Supplier.d.ts +52 -0
  99. package/auxiliary/Supplier.d.ts.map +1 -0
  100. package/auxiliary/Supplier.js +67 -0
  101. package/auxiliary/Supplier.js.map +1 -0
  102. package/impl/Completable.impl.d.ts +10 -0
  103. package/impl/Completable.impl.d.ts.map +1 -0
  104. package/impl/Completable.impl.js +136 -0
  105. package/impl/Completable.impl.js.map +1 -0
  106. package/impl/CompletableFactory.impl.d.ts +9 -0
  107. package/impl/CompletableFactory.impl.d.ts.map +1 -0
  108. package/impl/CompletableFactory.impl.js +42 -0
  109. package/impl/CompletableFactory.impl.js.map +1 -0
  110. package/impl/CompleteLater.impl.d.ts +12 -0
  111. package/impl/CompleteLater.impl.d.ts.map +1 -0
  112. package/impl/CompleteLater.impl.js +31 -0
  113. package/impl/CompleteLater.impl.js.map +1 -0
  114. package/impl/CompleteNow.impl.d.ts +14 -0
  115. package/impl/CompleteNow.impl.d.ts.map +1 -0
  116. package/impl/CompleteNow.impl.js +33 -0
  117. package/impl/CompleteNow.impl.js.map +1 -0
  118. package/impl/Concurrency.impl.d.ts +9 -0
  119. package/impl/Concurrency.impl.d.ts.map +1 -0
  120. package/impl/Concurrency.impl.js +84 -0
  121. package/impl/Concurrency.impl.js.map +1 -0
  122. package/impl/ConcurrencyFactory.impl.d.ts +10 -0
  123. package/impl/ConcurrencyFactory.impl.d.ts.map +1 -0
  124. package/impl/ConcurrencyFactory.impl.js +74 -0
  125. package/impl/ConcurrencyFactory.impl.js.map +1 -0
  126. package/impl/ConcurrencyWrapper.impl.d.ts +13 -0
  127. package/impl/ConcurrencyWrapper.impl.d.ts.map +1 -0
  128. package/impl/ConcurrencyWrapper.impl.js +85 -0
  129. package/impl/ConcurrencyWrapper.impl.js.map +1 -0
  130. package/impl/Events.d.ts +25 -0
  131. package/impl/Events.d.ts.map +1 -0
  132. package/impl/Events.impl.d.ts +11 -0
  133. package/impl/Events.impl.d.ts.map +1 -0
  134. package/impl/Events.impl.js +63 -0
  135. package/impl/Events.impl.js.map +1 -0
  136. package/impl/Events.js +3 -0
  137. package/impl/Events.js.map +1 -0
  138. package/impl/ExposedPromise.d.ts +26 -0
  139. package/impl/ExposedPromise.d.ts.map +1 -0
  140. package/impl/ExposedPromise.impl.d.ts +9 -0
  141. package/impl/ExposedPromise.impl.d.ts.map +1 -0
  142. package/impl/ExposedPromise.impl.js +41 -0
  143. package/impl/ExposedPromise.impl.js.map +1 -0
  144. package/impl/ExposedPromise.js +2 -0
  145. package/impl/ExposedPromise.js.map +1 -0
  146. package/impl/Internal.impl.d.ts +35 -0
  147. package/impl/Internal.impl.d.ts.map +1 -0
  148. package/impl/Internal.impl.js +90 -0
  149. package/impl/Internal.impl.js.map +1 -0
  150. package/impl/StateMachine.impl.d.ts +9 -0
  151. package/impl/StateMachine.impl.d.ts.map +1 -0
  152. package/impl/StateMachine.impl.js +184 -0
  153. package/impl/StateMachine.impl.js.map +1 -0
  154. package/impl/StateMachineFactory.impl.d.ts +9 -0
  155. package/impl/StateMachineFactory.impl.d.ts.map +1 -0
  156. package/impl/StateMachineFactory.impl.js +43 -0
  157. package/impl/StateMachineFactory.impl.js.map +1 -0
  158. package/impl/Waitable.impl.d.ts +8 -0
  159. package/impl/Waitable.impl.d.ts.map +1 -0
  160. package/impl/Waitable.impl.js +212 -0
  161. package/impl/Waitable.impl.js.map +1 -0
  162. package/impl/WaitableFactory.impl.d.ts +9 -0
  163. package/impl/WaitableFactory.impl.d.ts.map +1 -0
  164. package/impl/WaitableFactory.impl.js +42 -0
  165. package/impl/WaitableFactory.impl.js.map +1 -0
  166. package/index.d.ts +25 -0
  167. package/index.d.ts.map +1 -0
  168. package/index.js +33 -0
  169. package/index.js.map +1 -0
  170. package/package.json +88 -0
  171. package/version.d.ts +3 -0
  172. package/version.d.ts.map +1 -0
  173. package/version.js +4 -0
  174. package/version.js.map +1 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Events.js","sourceRoot":"","sources":["../../src/impl/Events.ts"],"names":[],"mappings":"AA6BC,CAAC"}
@@ -0,0 +1,26 @@
1
+ /**
2
+ * An ExposedPromise is a Promise with exposed resolve and reject methods.
3
+ *
4
+ * @param <T> the type of promise value
5
+ */
6
+ export interface ExposedPromise<T> {
7
+ /**
8
+ * Get the underlying Promise
9
+ *
10
+ * @return the Promise
11
+ */
12
+ getPromise(): Promise<T>;
13
+ /**
14
+ * Resolve the Promise with the given value
15
+ *
16
+ * @param value the value to resolve the Promise with
17
+ */
18
+ resolve(value: T | PromiseLike<T>): void;
19
+ /**
20
+ * Reject the Promise with the given reason
21
+ *
22
+ * @param reason the reason to reject the Promise with
23
+ */
24
+ reject(reason?: unknown): void;
25
+ }
26
+ //# sourceMappingURL=ExposedPromise.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ExposedPromise.d.ts","sourceRoot":"","sources":["../../src/impl/ExposedPromise.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,WAAW,cAAc,CAAC,CAAC;IAE/B;;;;OAIG;IACH,UAAU,IAAI,OAAO,CAAC,CAAC,CAAC,CAAC;IAEzB;;;;OAIG;IACH,OAAO,CAAC,KAAK,EAAE,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;IAEzC;;;;OAIG;IACH,MAAM,CAAC,MAAM,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;CAChC"}
@@ -0,0 +1,9 @@
1
+ import { ExposedPromise } from "./ExposedPromise.js";
2
+ /**
3
+ * Create a new ExposedPromise
4
+ *
5
+ * @return the new ExposedPromise
6
+ * @param <T> the type of promise value
7
+ */
8
+ export declare function create<T>(): ExposedPromise<T>;
9
+ //# sourceMappingURL=ExposedPromise.impl.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ExposedPromise.impl.d.ts","sourceRoot":"","sources":["../../src/impl/ExposedPromise.impl.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAErD;;;;;GAKG;AACH,wBAAgB,MAAM,CAAC,CAAC,KAAK,cAAc,CAAC,CAAC,CAAC,CAE7C"}
@@ -0,0 +1,41 @@
1
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
2
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
3
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
4
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5
+ };
6
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
7
+ if (kind === "m") throw new TypeError("Private method is not writable");
8
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
9
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
10
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
11
+ };
12
+ var _ExposedPromiseImpl_promise;
13
+ /**
14
+ * Create a new ExposedPromise
15
+ *
16
+ * @return the new ExposedPromise
17
+ * @param <T> the type of promise value
18
+ */
19
+ export function create() {
20
+ return ExposedPromiseImpl.internalCreate();
21
+ }
22
+ // ---- Implementation details below ----
23
+ class ExposedPromiseImpl {
24
+ getPromise() {
25
+ return __classPrivateFieldGet(this, _ExposedPromiseImpl_promise, "f");
26
+ }
27
+ static internalCreate() {
28
+ return new ExposedPromiseImpl();
29
+ }
30
+ constructor() {
31
+ _ExposedPromiseImpl_promise.set(this, void 0);
32
+ __classPrivateFieldSet(this, _ExposedPromiseImpl_promise, new Promise((resolve, reject) => {
33
+ // Capture the resolve and reject functions from the Promise constructor
34
+ this.resolve = resolve;
35
+ this.reject = reject;
36
+ }), "f");
37
+ // The resolve and reject methods can now be called from outside the constructor scope
38
+ }
39
+ }
40
+ _ExposedPromiseImpl_promise = new WeakMap();
41
+ //# sourceMappingURL=ExposedPromise.impl.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ExposedPromise.impl.js","sourceRoot":"","sources":["../../src/impl/ExposedPromise.impl.ts"],"names":[],"mappings":";;;;;;;;;;;;AAEA;;;;;GAKG;AACH,MAAM,UAAU,MAAM;IACpB,OAAO,kBAAkB,CAAC,cAAc,EAAK,CAAC;AAChD,CAAC;AAED,yCAAyC;AAEzC,MAAM,kBAAkB;IAEtB,UAAU;QACR,OAAO,uBAAA,IAAI,mCAAS,CAAC;IACvB,CAAC;IAMD,MAAM,CAAC,cAAc;QACnB,OAAO,IAAI,kBAAkB,EAAK,CAAA;IACpC,CAAC;IAED;QAQS,8CAAqB;QAP5B,uBAAA,IAAI,+BAAY,IAAI,OAAO,CAAI,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACjD,wEAAwE;YACxE,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;YACvB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACvB,CAAC,CAAC,MAAA,CAAC;QACH,sFAAsF;IACxF,CAAC;CAEF"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=ExposedPromise.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ExposedPromise.js","sourceRoot":"","sources":["../../src/impl/ExposedPromise.ts"],"names":[],"mappings":""}
@@ -0,0 +1,35 @@
1
+ import { Duration, RequiredType } from "@jonloucks/concurrency-ts/api/Types";
2
+ import { Contracts } from "@jonloucks/contracts-ts";
3
+ /**
4
+ * Helper functions for internal implementations.
5
+ */
6
+ export declare const Internal: {
7
+ /**
8
+ * Resolves the contracts to use from the provided configurations.
9
+ * Returns the first config with present contracts, or CONTRACTS as default.
10
+ * @param configs the configurations to resolve from (in priority order)
11
+ * @return the resolved contracts
12
+ */
13
+ resolveContracts(...configs: Array<{
14
+ contracts?: Contracts;
15
+ } | undefined>): RequiredType<Contracts>;
16
+ /**
17
+ * Throws an AggregateError with the provided message and list of errors.
18
+ * If only one error is provided, it throws that error directly.
19
+ *
20
+ * @param message the message for the AggregateError
21
+ * @param errorList the list of errors to include
22
+ */
23
+ throwAggregateError(message: string, ...errorList: unknown[]): never;
24
+ /**
25
+ * Wraps a promise with a timeout. If the promise does not settle within the specified duration,
26
+ * it rejects with a TimeoutException.
27
+ *
28
+ * @param promise the promise to wrap
29
+ * @param timeout the timeout duration
30
+ * @param errorMessage optional error message for the TimeoutException
31
+ * @return a promise that rejects with TimeoutException if the original promise does not settle in time
32
+ */
33
+ wrapPromiseWithTimeout<T>(promise: Promise<T>, timeout?: Duration, errorMessage?: string): Promise<T>;
34
+ };
35
+ //# sourceMappingURL=Internal.impl.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Internal.impl.d.ts","sourceRoot":"","sources":["../../src/impl/Internal.impl.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAA0B,YAAY,EAAE,MAAM,qCAAqC,CAAC;AACrG,OAAO,EAAa,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAG/D;;GAEG;AACH,eAAO,MAAM,QAAQ;IAEnB;;;;;OAKG;iCAC0B,KAAK,CAAC;QAAE,SAAS,CAAC,EAAE,SAAS,CAAA;KAAE,GAAE,SAAS,CAAC,GAAG,YAAY,CAAC,SAAS,CAAC;IASlG;;;;;;OAMG;iCAC0B,MAAM,gBAAgB,OAAO,EAAE,GAAG,KAAK;IA2BpE;;;;;;;;OAQG;2BAC0B,CAAC,WAAW,OAAO,CAAC,CAAC,CAAC,YAAY,QAAQ,iBAAiB,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC;CAyB5G,CAAA"}
@@ -0,0 +1,90 @@
1
+ import { ConcurrencyException } from "@jonloucks/concurrency-ts/api/ConcurrencyException";
2
+ import { TimeoutException } from "@jonloucks/concurrency-ts/api/TimeoutException";
3
+ import { isPresent, MAX_TIMEOUT } from "@jonloucks/concurrency-ts/api/Types";
4
+ import { CONTRACTS } from "@jonloucks/contracts-ts";
5
+ import { illegalCheck } from "@jonloucks/contracts-ts/auxiliary/Checks";
6
+ /**
7
+ * Helper functions for internal implementations.
8
+ */
9
+ export const Internal = {
10
+ /**
11
+ * Resolves the contracts to use from the provided configurations.
12
+ * Returns the first config with present contracts, or CONTRACTS as default.
13
+ * @param configs the configurations to resolve from (in priority order)
14
+ * @return the resolved contracts
15
+ */
16
+ resolveContracts(...configs) {
17
+ for (const config of configs) {
18
+ if (isPresent(config) && isPresent(config?.contracts)) {
19
+ return config.contracts;
20
+ }
21
+ }
22
+ return CONTRACTS;
23
+ },
24
+ /**
25
+ * Throws an AggregateError with the provided message and list of errors.
26
+ * If only one error is provided, it throws that error directly.
27
+ *
28
+ * @param message the message for the AggregateError
29
+ * @param errorList the list of errors to include
30
+ */
31
+ throwAggregateError(message, ...errorList) {
32
+ if (errorList.length === 1) {
33
+ throw errorList[0];
34
+ }
35
+ else {
36
+ const errorToString = (error) => {
37
+ if (error === null) {
38
+ return "null";
39
+ }
40
+ else if (error === undefined) {
41
+ return "undefined";
42
+ }
43
+ else if (error instanceof Error) {
44
+ return error.message;
45
+ }
46
+ else if (typeof error === "string" || typeof error === "number" || typeof error === "boolean") {
47
+ return String(error);
48
+ }
49
+ else {
50
+ return JSON.stringify(error);
51
+ }
52
+ };
53
+ // Map each error object to its message property
54
+ const messages = errorList.map(error => `- ${errorToString(error)}`);
55
+ // Join the messages with a newline separator
56
+ const messagesJoined = messages.join('\n');
57
+ throw new ConcurrencyException(message + "\n" + messagesJoined);
58
+ }
59
+ },
60
+ /**
61
+ * Wraps a promise with a timeout. If the promise does not settle within the specified duration,
62
+ * it rejects with a TimeoutException.
63
+ *
64
+ * @param promise the promise to wrap
65
+ * @param timeout the timeout duration
66
+ * @param errorMessage optional error message for the TimeoutException
67
+ * @return a promise that rejects with TimeoutException if the original promise does not settle in time
68
+ */
69
+ async wrapPromiseWithTimeout(promise, timeout, errorMessage) {
70
+ // Create a promise that rejects after the specified time
71
+ const milliSeconds = timeout?.milliSeconds ?? MAX_TIMEOUT.milliSeconds;
72
+ const validMilliSeconds = illegalCheck(milliSeconds, milliSeconds < 0, "Timeout duration must be non-negative.");
73
+ if (validMilliSeconds === MAX_TIMEOUT.milliSeconds || validMilliSeconds === Infinity) {
74
+ return promise;
75
+ }
76
+ const timeoutPromise = new Promise((_, reject) => {
77
+ const delay = Math.max(10, validMilliSeconds);
78
+ const timeoutId = setTimeout(() => {
79
+ reject(new TimeoutException(errorMessage || `Promise timed out after ${validMilliSeconds} ms`));
80
+ }, delay);
81
+ // Clear the timeout if the original promise resolves or rejects first
82
+ promise.finally(() => {
83
+ clearTimeout(timeoutId);
84
+ });
85
+ });
86
+ // Race the original promise against the timeout promise
87
+ return Promise.race([promise, timeoutPromise]);
88
+ }
89
+ };
90
+ //# sourceMappingURL=Internal.impl.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Internal.impl.js","sourceRoot":"","sources":["../../src/impl/Internal.impl.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,oDAAoD,CAAC;AAC1F,OAAO,EAAE,gBAAgB,EAAE,MAAM,gDAAgD,CAAC;AAClF,OAAO,EAAY,SAAS,EAAE,WAAW,EAAgB,MAAM,qCAAqC,CAAC;AACrG,OAAO,EAAE,SAAS,EAAa,MAAM,yBAAyB,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,MAAM,0CAA0C,CAA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";
2
+ import { RequiredType } from "@jonloucks/concurrency-ts/api/Types";
3
+ /**
4
+ * Create a new StateMachine
5
+ *
6
+ * @return the new StateMachine
7
+ */
8
+ export declare function create<T>(config: RequiredType<Config<T>>): StateMachine<T>;
9
+ //# sourceMappingURL=StateMachine.impl.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StateMachine.impl.d.ts","sourceRoot":"","sources":["../../src/impl/StateMachine.impl.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,4CAA4C,CAAC;AAElF,OAAO,EAAqC,YAAY,EAAE,MAAM,qCAAqC,CAAC;AAStG;;;;GAIG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAE1E"}
@@ -0,0 +1,184 @@
1
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
2
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
3
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
4
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5
+ };
6
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
7
+ if (kind === "m") throw new TypeError("Private method is not writable");
8
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
9
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
10
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
11
+ };
12
+ var _StateMachineImpl_stateToRulesLookup, _StateMachineImpl_currentState, _StateMachineImpl_isCompleted;
13
+ import { ConcurrencyException } from "@jonloucks/concurrency-ts/api/ConcurrencyException";
14
+ import { isPresent } from "@jonloucks/concurrency-ts/api/Types";
15
+ import { eventCheck, illegalCheck, initialValueCheck, presentCheck, ruleCheck, rulesCheck, stateCheck } from "@jonloucks/concurrency-ts/auxiliary/Checks";
16
+ import { create as createWaitable } from "./Waitable.impl.js";
17
+ /**
18
+ * Create a new StateMachine
19
+ *
20
+ * @return the new StateMachine
21
+ */
22
+ export function create(config) {
23
+ return StateMachineImpl.internalCreate(config);
24
+ }
25
+ // ---- Implementation details below ----
26
+ class StateMachineImpl {
27
+ // Statemachine.open
28
+ open() {
29
+ return __classPrivateFieldGet(this, _StateMachineImpl_currentState, "f").open();
30
+ }
31
+ // IsCompleted.
32
+ isCompleted() {
33
+ return __classPrivateFieldGet(this, _StateMachineImpl_isCompleted, "f");
34
+ }
35
+ // StateMachine.setState implementation
36
+ setState(event, state) {
37
+ if (this.isTransitionAllowed(event, stateCheck(state))) {
38
+ __classPrivateFieldGet(this, _StateMachineImpl_currentState, "f").consume(state);
39
+ this.updateIsCompleted(state);
40
+ return true;
41
+ }
42
+ return false;
43
+ }
44
+ // StateMachine.getState implementation
45
+ getState() {
46
+ return this.supply();
47
+ }
48
+ // StateMachine.hasState implementation
49
+ hasState(state) {
50
+ return __classPrivateFieldGet(this, _StateMachineImpl_stateToRulesLookup, "f").has(stateCheck(state));
51
+ }
52
+ // StateMachine.isTransitionAllowed implementation
53
+ isTransitionAllowed(event, state) {
54
+ const validEvent = eventCheck(event);
55
+ const toState = stateCheck(state);
56
+ const fromState = this.getState();
57
+ if (this.hasState(toState) && fromState !== toState) {
58
+ const rules = __classPrivateFieldGet(this, _StateMachineImpl_stateToRulesLookup, "f").get(fromState);
59
+ if (isPresent(rules) && rules.size > 0) {
60
+ return Array.from(rules).every((r) => r.canTransition(validEvent, toState));
61
+ }
62
+ return true;
63
+ }
64
+ return false;
65
+ }
66
+ // StateMachine.transition implementation
67
+ transition(transition) {
68
+ const t = this.transitionCheck(transition);
69
+ if (this.isAllowed(t)) {
70
+ try {
71
+ return this.handleSuccess(t);
72
+ }
73
+ catch (thrown) {
74
+ return this.handleError(t, thrown);
75
+ }
76
+ }
77
+ else {
78
+ return this.handleFailure(t);
79
+ }
80
+ }
81
+ // StateMachine.supply implementations
82
+ supply() {
83
+ return __classPrivateFieldGet(this, _StateMachineImpl_currentState, "f").supply();
84
+ }
85
+ // StateMachine.supplyIf implementation
86
+ supplyIf(predicate) {
87
+ return __classPrivateFieldGet(this, _StateMachineImpl_currentState, "f").supplyIf(predicate);
88
+ }
89
+ // StateMachine.supplyWhen implementation
90
+ async supplyWhen(predicate, timeout) {
91
+ return __classPrivateFieldGet(this, _StateMachineImpl_currentState, "f").supplyWhen(predicate, timeout);
92
+ }
93
+ // StateMachine.notifyWhile implementation
94
+ notifyWhile(predicate, listener) {
95
+ return __classPrivateFieldGet(this, _StateMachineImpl_currentState, "f").notifyWhile(predicate, listener);
96
+ }
97
+ static internalCreate(config) {
98
+ return new StateMachineImpl(config);
99
+ }
100
+ addStateAndRules(state, rules) {
101
+ const validState = stateCheck(state);
102
+ const validRules = rulesCheck(rules);
103
+ const knownRules = this.getStateRules(validState);
104
+ validRules.forEach(rule => knownRules.add(ruleCheck(rule)));
105
+ }
106
+ getStateRules(state) {
107
+ if (!__classPrivateFieldGet(this, _StateMachineImpl_stateToRulesLookup, "f").has(state)) {
108
+ __classPrivateFieldGet(this, _StateMachineImpl_stateToRulesLookup, "f").set(state, new Set());
109
+ }
110
+ return __classPrivateFieldGet(this, _StateMachineImpl_stateToRulesLookup, "f").get(state);
111
+ }
112
+ transitionCheck(transition) {
113
+ const validTransition = presentCheck(transition, "Transition must be present.");
114
+ this.existsCheck(validTransition.successState);
115
+ eventCheck(validTransition.event);
116
+ return validTransition;
117
+ }
118
+ isAllowed(transition) {
119
+ return this.isTransitionAllowed(transition.event, transition.successState);
120
+ }
121
+ handleSuccess(transition) {
122
+ const value = transition.getSuccessValue?.();
123
+ this.setState(transition.event, transition.successState);
124
+ return value;
125
+ }
126
+ handleFailure(transition) {
127
+ this.setOptionalState(transition.failedState, transition.event);
128
+ const value = transition.getFailedValue?.();
129
+ if (isPresent(value)) {
130
+ return value;
131
+ }
132
+ else {
133
+ throw new ConcurrencyException("Illegal state transition from " + String(this.getState()) +
134
+ " to " + String(transition.successState) + ".");
135
+ }
136
+ }
137
+ handleError(transition, thrown) {
138
+ this.setOptionalState(transition.errorState, transition.event);
139
+ const value = transition.getErrorValue?.();
140
+ if (isPresent(value)) {
141
+ return value;
142
+ }
143
+ else {
144
+ throw ConcurrencyException.rethrow(thrown);
145
+ }
146
+ }
147
+ setOptionalState(optional, event) {
148
+ if (isPresent(optional)) {
149
+ this.setState(event, optional);
150
+ }
151
+ }
152
+ existsCheck(state) {
153
+ const validState = stateCheck(state);
154
+ return illegalCheck(validState, !this.hasState(validState), "State must be known.");
155
+ }
156
+ updateIsCompleted(state) {
157
+ const rules = __classPrivateFieldGet(this, _StateMachineImpl_stateToRulesLookup, "f").get(state);
158
+ if (isPresent(rules) && rules.size > 0) {
159
+ for (const rule of rules) {
160
+ if (rule.isTerminal) {
161
+ __classPrivateFieldSet(this, _StateMachineImpl_isCompleted, true, "f");
162
+ return;
163
+ }
164
+ }
165
+ }
166
+ }
167
+ constructor(config) {
168
+ _StateMachineImpl_stateToRulesLookup.set(this, new Map());
169
+ _StateMachineImpl_currentState.set(this, void 0);
170
+ _StateMachineImpl_isCompleted.set(this, false);
171
+ const validConfig = config ?? {};
172
+ const initialState = initialValueCheck(validConfig.initialValue);
173
+ __classPrivateFieldSet(this, _StateMachineImpl_currentState, createWaitable({ initialValue: initialState }), "f");
174
+ this.addStateAndRules(initialState, []);
175
+ if (isPresent(validConfig.states) && validConfig.states.length > 0) {
176
+ validConfig.states.forEach(state => {
177
+ this.addStateAndRules(state, validConfig.getStateRules?.(state) ?? []);
178
+ });
179
+ }
180
+ }
181
+ }
182
+ _StateMachineImpl_stateToRulesLookup = new WeakMap(), _StateMachineImpl_currentState = new WeakMap(), _StateMachineImpl_isCompleted = new WeakMap();
183
+ ;
184
+ //# sourceMappingURL=StateMachine.impl.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StateMachine.impl.js","sourceRoot":"","sources":["../../src/impl/StateMachine.impl.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,oDAAoD,CAAC;AAI1F,OAAO,EAAY,SAAS,EAA8B,MAAM,qCAAqC,CAAC;AAEtG,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,iBAAiB,EAAE,YAAY,EAAE,SAAS,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,4CAA4C,CAAC;AAK1J,OAAO,EAAE,MAAM,IAAI,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAE9D;;;;GAIG;AACH,MAAM,UAAU,MAAM,CAAI,MAA+B;IACvD,OAAO,gBAAgB,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;AACjD,CAAC;AAED,yCAAyC;AAEzC,MAAM,gBAAgB;IAEpB,oBAAoB;IACpB,IAAI;QACF,OAAO,uBAAA,IAAI,sCAAc,CAAC,IAAI,EAAE,CAAC;IACnC,CAAC;IAED,eAAe;IACf,WAAW;QACT,OAAO,uBAAA,IAAI,qCAAa,CAAC;IAC3B,CAAC;IAED,uCAAuC;IACvC,QAAQ,CAAC,KAAa,EAAE,KAAQ;QAC9B,IAAI,IAAI,CAAC,mBAAmB,CAAC,KAAK,EAAE,UAAU,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC;YACvD,uBAAA,IAAI,sCAAc,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;YAClC,IAAI,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAC;YAC9B,OAAO,IAAI,CAAC;QACd,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,uCAAuC;IACvC,QAAQ;QACN,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC;IACvB,CAAC;IAED,uCAAuC;IACvC,QAAQ,CAAC,KAAQ;QACf,OAAO,u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AI,kCAAiB,cAAc,CAAI,EAAE,YAAY,EAAE,YAAY,EAAE,CAAC,MAAA,CAAC;QACvE,IAAI,CAAC,gBAAgB,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC;QACxC,IAAI,SAAS,CAAC,WAAW,CAAC,MAAM,CAAC,IAAI,WAAW,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACnE,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;gBACjC,IAAI,CAAC,gBAAgB,CAAC,KAAK,EAAE,WAAW,CAAC,aAAa,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC;YACzE,CAAC,CAAC,CAAC;QACL,CAAC;IACH,CAAC;CAKF;;AAAA,CAAC"}
@@ -0,0 +1,9 @@
1
+ import { StateMachineFactory } from "@jonloucks/concurrency-ts/api/StateMachineFactory";
2
+ import { Config as ConcurrencyConfig } from "@jonloucks/concurrency-ts/api/Concurrency";
3
+ /**
4
+ * Create a new StateMachineFactory
5
+ *
6
+ * @return the new StateMachineFactory
7
+ */
8
+ export declare function create(config?: ConcurrencyConfig): StateMachineFactory;
9
+ //# sourceMappingURL=StateMachineFactory.impl.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StateMachineFactory.impl.d.ts","sourceRoot":"","sources":["../../src/impl/StateMachineFactory.impl.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,mDAAmD,CAAC;AAGxF,OAAO,EAAE,MAAM,IAAI,iBAAiB,EAAE,MAAM,2CAA2C,CAAC;AAMxF;;;;GAIG;AACH,wBAAgB,MAAM,CAAC,MAAM,CAAC,EAAE,iBAAiB,GAAG,mBAAmB,CAEtE"}
@@ -0,0 +1,43 @@
1
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
2
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
3
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
4
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5
+ };
6
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
7
+ if (kind === "m") throw new TypeError("Private method is not writable");
8
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
9
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
10
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
11
+ };
12
+ var _StateMachineFactoryImpl_concurrencyConfig;
13
+ import { presentCheck } from "@jonloucks/concurrency-ts/auxiliary/Checks";
14
+ import { create as createStateMachineImpl } from "./StateMachine.impl.js";
15
+ import { Internal } from "./Internal.impl.js";
16
+ /**
17
+ * Create a new StateMachineFactory
18
+ *
19
+ * @return the new StateMachineFactory
20
+ */
21
+ export function create(config) {
22
+ return StateMachineFactoryImpl.internalCreate(config);
23
+ }
24
+ // ---- Implementation details below ----
25
+ class StateMachineFactoryImpl {
26
+ createStateMachine(config) {
27
+ const validConfig = presentCheck(config, "Config must be present.");
28
+ const contracts = Internal.resolveContracts(validConfig, __classPrivateFieldGet(this, _StateMachineFactoryImpl_concurrencyConfig, "f"));
29
+ const finalConfig = { ...validConfig, contracts: contracts };
30
+ return createStateMachineImpl(finalConfig);
31
+ }
32
+ static internalCreate(config) {
33
+ return new StateMachineFactoryImpl(config);
34
+ }
35
+ constructor(config) {
36
+ _StateMachineFactoryImpl_concurrencyConfig.set(this, void 0);
37
+ const contracts = Internal.resolveContracts(config);
38
+ __classPrivateFieldSet(this, _StateMachineFactoryImpl_concurrencyConfig, { ...config, contracts: contracts }, "f");
39
+ }
40
+ }
41
+ _StateMachineFactoryImpl_concurrencyConfig = new WeakMap();
42
+ ;
43
+ //# sourceMappingURL=StateMachineFactory.impl.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StateMachineFactory.impl.js","sourceRoot":"","sources":["../../src/impl/StateMachineFactory.impl.ts"],"names":[],"mappings":";;;;;;;;;;;;AAKA,OAAO,EAAE,YAAY,EAAE,MAAM,4CAA4C,CAAC;AAE1E,OAAO,EAAE,MAAM,IAAI,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AAC1E,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAE9C;;;;GAIG;AACH,MAAM,UAAU,MAAM,CAAC,MAA0B;IAC/C,OAAO,uBAAuB,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;AACxD,CAAC;AAED,yCAAyC;AAEzC,MAAM,uBAAuB;IAC3B,kBAAkB,CAAI,MAA6B;QACjD,MAAM,WAAW,GAA0B,YAAY,CAAC,MAAM,EAAE,yBAAyB,CAAC,CAAC;QAC3F,MAAM,SAAS,GAAc,QAAQ,CAAC,gBAAgB,CAAC,WAAW,EAAE,uBAAA,IAAI,kDAAmB,CAAC,CAAC;QAC7F,MAAM,WAAW,GAA0B,EAAE,GAAG,WAAW,EAAE,SAAS,EAAE,SAAS,EAAE,CAAC;QACpF,OAAO,sBAAsB,CAAC,WAAW,CAAC,CAAC;IAC7C,CAAC;IAED,MAAM,CAAC,cAAc,CAAC,MAA0B;QAC9C,OAAO,IAAI,uBAAuB,CAAC,MAAM,CAAC,CAAC;IAC7C,CAAC;IAED,YAAoB,MAA0B;QAKrC,6DAAuC;QAJ9C,MAAM,SAAS,GAAc,QAAQ,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC;QAC/D,uBAAA,IAAI,8CAAsB,EAAE,GAAG,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,MAAA,CAAC;IAChE,CAAC;CAGF;;AAAA,CAAC"}
@@ -0,0 +1,8 @@
1
+ import { Config, Waitable } from "@jonloucks/concurrency-ts/api/Waitable";
2
+ /**
3
+ * Create a new Waitable
4
+ *
5
+ * @return the new Waitable
6
+ */
7
+ export declare function create<T>(config?: Config<T>): Waitable<T>;
8
+ //# sourceMappingURL=Waitable.impl.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Waitable.impl.d.ts","sourceRoot":"","sources":["../../src/impl/Waitable.impl.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,wCAAwC,CAAC;AAY1E;;;;GAIG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAEzD"}