@hotmeshio/hotmesh 0.8.0 → 0.10.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 (164) hide show
  1. package/README.md +178 -43
  2. package/build/index.d.ts +12 -11
  3. package/build/index.js +15 -13
  4. package/build/modules/enums.d.ts +23 -34
  5. package/build/modules/enums.js +26 -38
  6. package/build/modules/errors.d.ts +16 -16
  7. package/build/modules/errors.js +37 -37
  8. package/build/package.json +63 -67
  9. package/build/services/activities/activity.d.ts +58 -7
  10. package/build/services/activities/activity.js +67 -38
  11. package/build/services/activities/await.d.ts +101 -0
  12. package/build/services/activities/await.js +101 -0
  13. package/build/services/activities/cycle.d.ts +82 -0
  14. package/build/services/activities/cycle.js +86 -8
  15. package/build/services/activities/hook.d.ts +139 -1
  16. package/build/services/activities/hook.js +140 -2
  17. package/build/services/activities/interrupt.d.ts +112 -0
  18. package/build/services/activities/interrupt.js +118 -5
  19. package/build/services/activities/signal.d.ts +108 -3
  20. package/build/services/activities/signal.js +113 -8
  21. package/build/services/activities/trigger.d.ts +56 -4
  22. package/build/services/activities/trigger.js +119 -35
  23. package/build/services/activities/worker.d.ts +107 -0
  24. package/build/services/activities/worker.js +107 -0
  25. package/build/services/collator/index.d.ts +3 -15
  26. package/build/services/collator/index.js +7 -34
  27. package/build/services/dba/index.d.ts +171 -0
  28. package/build/services/dba/index.js +280 -0
  29. package/build/services/{memflow → durable}/client.d.ts +3 -3
  30. package/build/services/{memflow → durable}/client.js +15 -15
  31. package/build/services/{memflow → durable}/connection.d.ts +2 -2
  32. package/build/services/{memflow → durable}/connection.js +1 -1
  33. package/build/services/{memflow → durable}/exporter.d.ts +6 -6
  34. package/build/services/{memflow → durable}/exporter.js +2 -2
  35. package/build/services/{memflow → durable}/handle.d.ts +4 -4
  36. package/build/services/{memflow → durable}/handle.js +3 -3
  37. package/build/services/{memflow → durable}/index.d.ts +126 -34
  38. package/build/services/{memflow → durable}/index.js +146 -50
  39. package/build/services/{memflow → durable}/interceptor.d.ts +45 -22
  40. package/build/services/{memflow → durable}/interceptor.js +54 -21
  41. package/build/services/{memflow → durable}/schemas/factory.d.ts +4 -4
  42. package/build/services/{memflow → durable}/schemas/factory.js +5 -5
  43. package/build/services/{memflow → durable}/search.d.ts +1 -1
  44. package/build/services/{memflow → durable}/search.js +4 -4
  45. package/build/services/{memflow → durable}/worker.d.ts +11 -11
  46. package/build/services/{memflow → durable}/worker.js +61 -60
  47. package/build/services/durable/workflow/all.d.ts +32 -0
  48. package/build/services/durable/workflow/all.js +40 -0
  49. package/build/services/{memflow → durable}/workflow/common.d.ts +5 -5
  50. package/build/services/durable/workflow/common.js +47 -0
  51. package/build/services/durable/workflow/context.d.ts +49 -0
  52. package/build/services/durable/workflow/context.js +88 -0
  53. package/build/services/durable/workflow/didRun.d.ts +27 -0
  54. package/build/services/durable/workflow/didRun.js +42 -0
  55. package/build/services/durable/workflow/emit.d.ts +50 -0
  56. package/build/services/durable/workflow/emit.js +68 -0
  57. package/build/services/durable/workflow/enrich.d.ts +37 -0
  58. package/build/services/durable/workflow/enrich.js +45 -0
  59. package/build/services/durable/workflow/entityMethods.d.ts +61 -0
  60. package/build/services/durable/workflow/entityMethods.js +80 -0
  61. package/build/services/durable/workflow/execChild.d.ts +106 -0
  62. package/build/services/durable/workflow/execChild.js +194 -0
  63. package/build/services/durable/workflow/execHook.d.ts +80 -0
  64. package/build/services/durable/workflow/execHook.js +97 -0
  65. package/build/services/durable/workflow/execHookBatch.d.ts +107 -0
  66. package/build/services/durable/workflow/execHookBatch.js +129 -0
  67. package/build/services/durable/workflow/hook.d.ts +74 -0
  68. package/build/services/durable/workflow/hook.js +123 -0
  69. package/build/services/durable/workflow/index.d.ts +129 -0
  70. package/build/services/{memflow → durable}/workflow/index.js +66 -11
  71. package/build/services/durable/workflow/interrupt.d.ts +55 -0
  72. package/build/services/durable/workflow/interrupt.js +70 -0
  73. package/build/services/durable/workflow/interruption.d.ts +61 -0
  74. package/build/services/durable/workflow/interruption.js +76 -0
  75. package/build/services/durable/workflow/isSideEffectAllowed.d.ts +27 -0
  76. package/build/services/{memflow → durable}/workflow/isSideEffectAllowed.js +21 -4
  77. package/build/services/durable/workflow/proxyActivities.d.ts +119 -0
  78. package/build/services/durable/workflow/proxyActivities.js +214 -0
  79. package/build/services/durable/workflow/random.d.ts +36 -0
  80. package/build/services/durable/workflow/random.js +46 -0
  81. package/build/services/durable/workflow/searchMethods.d.ts +53 -0
  82. package/build/services/durable/workflow/searchMethods.js +72 -0
  83. package/build/services/durable/workflow/signal.d.ts +58 -0
  84. package/build/services/durable/workflow/signal.js +79 -0
  85. package/build/services/durable/workflow/sleepFor.d.ts +63 -0
  86. package/build/services/durable/workflow/sleepFor.js +91 -0
  87. package/build/services/durable/workflow/trace.d.ts +47 -0
  88. package/build/services/durable/workflow/trace.js +66 -0
  89. package/build/services/durable/workflow/waitFor.d.ts +66 -0
  90. package/build/services/durable/workflow/waitFor.js +93 -0
  91. package/build/services/engine/index.d.ts +18 -2
  92. package/build/services/engine/index.js +14 -4
  93. package/build/services/exporter/index.d.ts +2 -0
  94. package/build/services/exporter/index.js +1 -0
  95. package/build/services/hotmesh/index.d.ts +471 -236
  96. package/build/services/hotmesh/index.js +473 -238
  97. package/build/services/store/index.d.ts +1 -1
  98. package/build/services/store/providers/postgres/postgres.d.ts +1 -1
  99. package/build/services/store/providers/postgres/postgres.js +4 -3
  100. package/build/services/telemetry/index.js +6 -0
  101. package/build/services/{meshcall → virtual}/index.d.ts +29 -29
  102. package/build/services/{meshcall → virtual}/index.js +49 -49
  103. package/build/services/{meshcall → virtual}/schemas/factory.d.ts +1 -1
  104. package/build/services/{meshcall → virtual}/schemas/factory.js +1 -1
  105. package/build/types/activity.d.ts +1 -1
  106. package/build/types/dba.d.ts +64 -0
  107. package/build/types/{memflow.d.ts → durable.d.ts} +75 -19
  108. package/build/types/error.d.ts +5 -5
  109. package/build/types/exporter.d.ts +1 -1
  110. package/build/types/hotmesh.d.ts +1 -1
  111. package/build/types/index.d.ts +5 -4
  112. package/build/types/job.d.ts +1 -1
  113. package/build/types/quorum.d.ts +2 -2
  114. package/build/types/{meshcall.d.ts → virtual.d.ts} +15 -15
  115. package/build/types/virtual.js +2 -0
  116. package/index.ts +15 -13
  117. package/package.json +63 -67
  118. package/vitest.config.ts +17 -0
  119. package/.claude/settings.local.json +0 -7
  120. package/build/services/memflow/workflow/all.d.ts +0 -7
  121. package/build/services/memflow/workflow/all.js +0 -15
  122. package/build/services/memflow/workflow/common.js +0 -47
  123. package/build/services/memflow/workflow/context.d.ts +0 -6
  124. package/build/services/memflow/workflow/context.js +0 -45
  125. package/build/services/memflow/workflow/didRun.d.ts +0 -7
  126. package/build/services/memflow/workflow/didRun.js +0 -22
  127. package/build/services/memflow/workflow/emit.d.ts +0 -11
  128. package/build/services/memflow/workflow/emit.js +0 -29
  129. package/build/services/memflow/workflow/enrich.d.ts +0 -9
  130. package/build/services/memflow/workflow/enrich.js +0 -17
  131. package/build/services/memflow/workflow/entityMethods.d.ts +0 -14
  132. package/build/services/memflow/workflow/entityMethods.js +0 -33
  133. package/build/services/memflow/workflow/execChild.d.ts +0 -18
  134. package/build/services/memflow/workflow/execChild.js +0 -106
  135. package/build/services/memflow/workflow/execHook.d.ts +0 -65
  136. package/build/services/memflow/workflow/execHook.js +0 -83
  137. package/build/services/memflow/workflow/execHookBatch.d.ts +0 -54
  138. package/build/services/memflow/workflow/execHookBatch.js +0 -77
  139. package/build/services/memflow/workflow/hook.d.ts +0 -9
  140. package/build/services/memflow/workflow/hook.js +0 -58
  141. package/build/services/memflow/workflow/index.d.ts +0 -74
  142. package/build/services/memflow/workflow/interrupt.d.ts +0 -9
  143. package/build/services/memflow/workflow/interrupt.js +0 -24
  144. package/build/services/memflow/workflow/interruption.d.ts +0 -28
  145. package/build/services/memflow/workflow/interruption.js +0 -43
  146. package/build/services/memflow/workflow/isSideEffectAllowed.d.ts +0 -10
  147. package/build/services/memflow/workflow/proxyActivities.d.ts +0 -91
  148. package/build/services/memflow/workflow/proxyActivities.js +0 -176
  149. package/build/services/memflow/workflow/random.d.ts +0 -6
  150. package/build/services/memflow/workflow/random.js +0 -16
  151. package/build/services/memflow/workflow/searchMethods.d.ts +0 -6
  152. package/build/services/memflow/workflow/searchMethods.js +0 -25
  153. package/build/services/memflow/workflow/signal.d.ts +0 -29
  154. package/build/services/memflow/workflow/signal.js +0 -50
  155. package/build/services/memflow/workflow/sleepFor.d.ts +0 -24
  156. package/build/services/memflow/workflow/sleepFor.js +0 -52
  157. package/build/services/memflow/workflow/trace.d.ts +0 -14
  158. package/build/services/memflow/workflow/trace.js +0 -33
  159. package/build/services/memflow/workflow/waitFor.d.ts +0 -29
  160. package/build/services/memflow/workflow/waitFor.js +0 -56
  161. /package/build/services/{memflow → durable}/entity.d.ts +0 -0
  162. /package/build/services/{memflow → durable}/entity.js +0 -0
  163. /package/build/types/{memflow.js → dba.js} +0 -0
  164. /package/build/types/{meshcall.js → durable.js} +0 -0
@@ -1,29 +0,0 @@
1
- /**
2
- * Sends a signal payload to any paused workflow thread awaiting this signal.
3
- * This method is commonly used to coordinate between workflows, hook functions,
4
- * and external events.
5
- *
6
- * @example
7
- * // Basic usage - send a simple signal with data
8
- * await MemFlow.workflow.signal('signal-id', { name: 'WarmMash' });
9
- *
10
- * @example
11
- * // Hook function signaling completion
12
- * export async function exampleHook(name: string): Promise<void> {
13
- * const result = await processData(name);
14
- * await MemFlow.workflow.signal('hook-complete', { data: result });
15
- * }
16
- *
17
- * @example
18
- * // Signal with complex data structure
19
- * await MemFlow.workflow.signal('process-complete', {
20
- * status: 'success',
21
- * data: { id: 123, name: 'test' },
22
- * timestamp: new Date().toISOString()
23
- * });
24
- *
25
- * @param {string} signalId - Unique signal identifier that matches a waitFor() call.
26
- * @param {Record<any, any>} data - The payload to send with the signal.
27
- * @returns {Promise<string>} The resulting hook/stream ID.
28
- */
29
- export declare function signal(signalId: string, data: Record<any, any>): Promise<string>;
@@ -1,50 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.signal = void 0;
4
- const common_1 = require("./common");
5
- const isSideEffectAllowed_1 = require("./isSideEffectAllowed");
6
- /**
7
- * Sends a signal payload to any paused workflow thread awaiting this signal.
8
- * This method is commonly used to coordinate between workflows, hook functions,
9
- * and external events.
10
- *
11
- * @example
12
- * // Basic usage - send a simple signal with data
13
- * await MemFlow.workflow.signal('signal-id', { name: 'WarmMash' });
14
- *
15
- * @example
16
- * // Hook function signaling completion
17
- * export async function exampleHook(name: string): Promise<void> {
18
- * const result = await processData(name);
19
- * await MemFlow.workflow.signal('hook-complete', { data: result });
20
- * }
21
- *
22
- * @example
23
- * // Signal with complex data structure
24
- * await MemFlow.workflow.signal('process-complete', {
25
- * status: 'success',
26
- * data: { id: 123, name: 'test' },
27
- * timestamp: new Date().toISOString()
28
- * });
29
- *
30
- * @param {string} signalId - Unique signal identifier that matches a waitFor() call.
31
- * @param {Record<any, any>} data - The payload to send with the signal.
32
- * @returns {Promise<string>} The resulting hook/stream ID.
33
- */
34
- async function signal(signalId, data) {
35
- const store = common_1.asyncLocalStorage.getStore();
36
- const workflowTopic = store.get('workflowTopic');
37
- const connection = store.get('connection');
38
- const namespace = store.get('namespace');
39
- const hotMeshClient = await common_1.WorkerService.getHotMesh(workflowTopic, {
40
- connection,
41
- namespace,
42
- });
43
- if (await (0, isSideEffectAllowed_1.isSideEffectAllowed)(hotMeshClient, 'signal')) {
44
- return await hotMeshClient.hook(`${namespace}.wfs.signal`, {
45
- id: signalId,
46
- data,
47
- });
48
- }
49
- }
50
- exports.signal = signal;
@@ -1,24 +0,0 @@
1
- /**
2
- * Sleeps the workflow for a specified duration, deterministically.
3
- * On replay, it will not actually sleep again, but resume after sleep.
4
- *
5
- * @example
6
- * // Basic usage - sleep for a specific duration
7
- * await MemFlow.workflow.sleepFor('2 seconds');
8
- *
9
- * @example
10
- * // Using with Promise.all for parallel operations
11
- * const [greeting, timeInSeconds] = await Promise.all([
12
- * someActivity(name),
13
- * MemFlow.workflow.sleepFor('1 second')
14
- * ]);
15
- *
16
- * @example
17
- * // Multiple sequential sleeps
18
- * await MemFlow.workflow.sleepFor('1 seconds'); // First pause
19
- * await MemFlow.workflow.sleepFor('2 seconds'); // Second pause
20
- *
21
- * @param {string} duration - A human-readable duration string (e.g., '1m', '2 hours', '30 seconds').
22
- * @returns {Promise<number>} The resolved duration in seconds.
23
- */
24
- export declare function sleepFor(duration: string): Promise<number>;
@@ -1,52 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.sleepFor = void 0;
4
- const common_1 = require("./common");
5
- const didRun_1 = require("./didRun");
6
- /**
7
- * Sleeps the workflow for a specified duration, deterministically.
8
- * On replay, it will not actually sleep again, but resume after sleep.
9
- *
10
- * @example
11
- * // Basic usage - sleep for a specific duration
12
- * await MemFlow.workflow.sleepFor('2 seconds');
13
- *
14
- * @example
15
- * // Using with Promise.all for parallel operations
16
- * const [greeting, timeInSeconds] = await Promise.all([
17
- * someActivity(name),
18
- * MemFlow.workflow.sleepFor('1 second')
19
- * ]);
20
- *
21
- * @example
22
- * // Multiple sequential sleeps
23
- * await MemFlow.workflow.sleepFor('1 seconds'); // First pause
24
- * await MemFlow.workflow.sleepFor('2 seconds'); // Second pause
25
- *
26
- * @param {string} duration - A human-readable duration string (e.g., '1m', '2 hours', '30 seconds').
27
- * @returns {Promise<number>} The resolved duration in seconds.
28
- */
29
- async function sleepFor(duration) {
30
- const [didRunAlready, execIndex, result] = await (0, didRun_1.didRun)('sleep');
31
- if (didRunAlready) {
32
- return result.duration;
33
- }
34
- const store = common_1.asyncLocalStorage.getStore();
35
- const interruptionRegistry = store.get('interruptionRegistry');
36
- const workflowId = store.get('workflowId');
37
- const workflowDimension = store.get('workflowDimension') ?? '';
38
- const interruptionMessage = {
39
- workflowId,
40
- duration: (0, common_1.s)(duration),
41
- index: execIndex,
42
- workflowDimension,
43
- };
44
- interruptionRegistry.push({
45
- code: common_1.HMSH_CODE_MEMFLOW_SLEEP,
46
- type: 'MemFlowSleepError',
47
- ...interruptionMessage,
48
- });
49
- await (0, common_1.sleepImmediate)();
50
- throw new common_1.MemFlowSleepError(interruptionMessage);
51
- }
52
- exports.sleepFor = sleepFor;
@@ -1,14 +0,0 @@
1
- import { StringScalarType } from './common';
2
- /**
3
- * Executes a distributed trace, outputting the provided attributes
4
- * to the telemetry sink (e.g. OpenTelemetry).
5
- *
6
- * This trace will only run once per workflow execution by default.
7
- *
8
- * @param {StringScalarType} attributes - Key-value attributes to attach to the trace.
9
- * @param {{ once: boolean }} [config={ once: true }] - If `once` is true, trace only runs once.
10
- * @returns {Promise<boolean>} True if tracing succeeded, otherwise false.
11
- */
12
- export declare function trace(attributes: StringScalarType, config?: {
13
- once: boolean;
14
- }): Promise<boolean>;
@@ -1,33 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.trace = void 0;
4
- const common_1 = require("./common");
5
- const context_1 = require("./context");
6
- const isSideEffectAllowed_1 = require("./isSideEffectAllowed");
7
- /**
8
- * Executes a distributed trace, outputting the provided attributes
9
- * to the telemetry sink (e.g. OpenTelemetry).
10
- *
11
- * This trace will only run once per workflow execution by default.
12
- *
13
- * @param {StringScalarType} attributes - Key-value attributes to attach to the trace.
14
- * @param {{ once: boolean }} [config={ once: true }] - If `once` is true, trace only runs once.
15
- * @returns {Promise<boolean>} True if tracing succeeded, otherwise false.
16
- */
17
- async function trace(attributes, config = { once: true }) {
18
- const store = common_1.asyncLocalStorage.getStore();
19
- const workflowTopic = store.get('workflowTopic');
20
- const connection = store.get('connection');
21
- const namespace = store.get('namespace');
22
- const hotMeshClient = await common_1.WorkerService.getHotMesh(workflowTopic, {
23
- connection,
24
- namespace,
25
- });
26
- const { raw, COUNTER } = (0, context_1.getContext)();
27
- const { trc: traceId, spn: spanId, aid: activityId } = raw.metadata;
28
- if (!config.once || await (0, isSideEffectAllowed_1.isSideEffectAllowed)(hotMeshClient, 'trace')) {
29
- return await common_1.TelemetryService.traceActivity(namespace, attributes, activityId, traceId, spanId, COUNTER.counter);
30
- }
31
- return true;
32
- }
33
- exports.trace = trace;
@@ -1,29 +0,0 @@
1
- /**
2
- * Pauses the workflow until a signal with the given `signalId` is received.
3
- * This method is commonly used to coordinate between the main workflow and hook functions,
4
- * or to wait for external events.
5
- *
6
- * @example
7
- * // Basic usage - wait for a single signal
8
- * const payload = await MemFlow.workflow.waitFor<PayloadType>('abcdefg');
9
- *
10
- * @example
11
- * // Wait for multiple signals in parallel
12
- * const [signal1, signal2] = await Promise.all([
13
- * MemFlow.workflow.waitFor<Record<string, any>>('signal1'),
14
- * MemFlow.workflow.waitFor<Record<string, any>>('signal2')
15
- * ]);
16
- *
17
- * @example
18
- * // Typical pattern with hook functions
19
- * // In main workflow:
20
- * await MemFlow.workflow.waitFor<ResponseType>('hook-complete');
21
- *
22
- * // In hook function:
23
- * await MemFlow.workflow.signal('hook-complete', { data: result });
24
- *
25
- * @template T - The type of data expected in the signal payload
26
- * @param {string} signalId - A unique signal identifier shared by the sender and receiver.
27
- * @returns {Promise<T>} The data payload associated with the received signal.
28
- */
29
- export declare function waitFor<T>(signalId: string): Promise<T>;
@@ -1,56 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.waitFor = void 0;
4
- const common_1 = require("./common");
5
- const didRun_1 = require("./didRun");
6
- /**
7
- * Pauses the workflow until a signal with the given `signalId` is received.
8
- * This method is commonly used to coordinate between the main workflow and hook functions,
9
- * or to wait for external events.
10
- *
11
- * @example
12
- * // Basic usage - wait for a single signal
13
- * const payload = await MemFlow.workflow.waitFor<PayloadType>('abcdefg');
14
- *
15
- * @example
16
- * // Wait for multiple signals in parallel
17
- * const [signal1, signal2] = await Promise.all([
18
- * MemFlow.workflow.waitFor<Record<string, any>>('signal1'),
19
- * MemFlow.workflow.waitFor<Record<string, any>>('signal2')
20
- * ]);
21
- *
22
- * @example
23
- * // Typical pattern with hook functions
24
- * // In main workflow:
25
- * await MemFlow.workflow.waitFor<ResponseType>('hook-complete');
26
- *
27
- * // In hook function:
28
- * await MemFlow.workflow.signal('hook-complete', { data: result });
29
- *
30
- * @template T - The type of data expected in the signal payload
31
- * @param {string} signalId - A unique signal identifier shared by the sender and receiver.
32
- * @returns {Promise<T>} The data payload associated with the received signal.
33
- */
34
- async function waitFor(signalId) {
35
- const [didRunAlready, execIndex, result] = await (0, didRun_1.didRun)('wait');
36
- if (didRunAlready) {
37
- return result.data.data;
38
- }
39
- const store = common_1.asyncLocalStorage.getStore();
40
- const interruptionRegistry = store.get('interruptionRegistry');
41
- const workflowId = store.get('workflowId');
42
- const workflowDimension = store.get('workflowDimension') ?? '';
43
- const interruptionMessage = {
44
- workflowId,
45
- signalId,
46
- index: execIndex,
47
- workflowDimension,
48
- type: 'MemFlowWaitForError',
49
- code: common_1.HMSH_CODE_MEMFLOW_WAIT,
50
- };
51
- interruptionRegistry.push(interruptionMessage);
52
- await (0, common_1.sleepImmediate)();
53
- //if you are seeing this error in the logs, you might have forgotten to `await waitFor(...)`
54
- throw new common_1.MemFlowWaitForError(interruptionMessage);
55
- }
56
- exports.waitFor = waitFor;
File without changes
File without changes
File without changes
File without changes