@hotmeshio/hotmesh 0.4.0 → 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +39 -14
- package/build/modules/enums.d.ts +110 -0
- package/build/modules/enums.js +134 -0
- package/build/modules/errors.d.ts +124 -0
- package/build/modules/errors.js +191 -0
- package/build/modules/key.d.ts +66 -0
- package/build/modules/key.js +190 -0
- package/build/modules/storage.d.ts +3 -0
- package/build/modules/storage.js +5 -0
- package/build/modules/utils.d.ts +119 -0
- package/build/modules/utils.js +374 -0
- package/build/package.json +1 -1
- package/build/services/activities/activity.d.ts +104 -0
- package/build/services/activities/activity.js +549 -0
- package/build/services/activities/await.d.ts +12 -0
- package/build/services/activities/await.js +114 -0
- package/build/services/activities/cycle.d.ts +19 -0
- package/build/services/activities/cycle.js +112 -0
- package/build/services/activities/hook.d.ts +27 -0
- package/build/services/activities/hook.js +168 -0
- package/build/services/activities/index.d.ts +19 -0
- package/build/services/activities/index.js +20 -0
- package/build/services/activities/interrupt.d.ts +16 -0
- package/build/services/activities/interrupt.js +158 -0
- package/build/services/activities/signal.d.ts +20 -0
- package/build/services/activities/signal.js +134 -0
- package/build/services/activities/trigger.d.ts +37 -0
- package/build/services/activities/trigger.js +246 -0
- package/build/services/activities/worker.d.ts +12 -0
- package/build/services/activities/worker.js +106 -0
- package/build/services/collator/index.d.ts +111 -0
- package/build/services/collator/index.js +293 -0
- package/build/services/compiler/deployer.d.ts +40 -0
- package/build/services/compiler/deployer.js +488 -0
- package/build/services/compiler/index.d.ts +32 -0
- package/build/services/compiler/index.js +112 -0
- package/build/services/compiler/validator.d.ts +34 -0
- package/build/services/compiler/validator.js +147 -0
- package/build/services/connector/factory.d.ts +22 -0
- package/build/services/connector/factory.js +99 -0
- package/build/services/connector/index.d.ts +30 -0
- package/build/services/connector/index.js +54 -0
- package/build/services/connector/providers/ioredis.d.ts +9 -0
- package/build/services/connector/providers/ioredis.js +26 -0
- package/build/services/connector/providers/nats.d.ts +9 -0
- package/build/services/connector/providers/nats.js +34 -0
- package/build/services/connector/providers/postgres.d.ts +20 -0
- package/build/services/connector/providers/postgres.js +102 -0
- package/build/services/connector/providers/redis.d.ts +9 -0
- package/build/services/connector/providers/redis.js +38 -0
- package/build/services/engine/index.d.ts +264 -0
- package/build/services/engine/index.js +761 -0
- package/build/services/exporter/index.d.ts +44 -0
- package/build/services/exporter/index.js +126 -0
- package/build/services/hotmesh/index.d.ts +483 -0
- package/build/services/hotmesh/index.js +622 -0
- package/build/services/logger/index.d.ts +16 -0
- package/build/services/logger/index.js +54 -0
- package/build/services/mapper/index.d.ts +28 -0
- package/build/services/mapper/index.js +81 -0
- package/build/services/memflow/client.d.ts +108 -0
- package/build/services/memflow/client.js +372 -0
- package/build/services/memflow/connection.d.ts +23 -0
- package/build/services/memflow/connection.js +33 -0
- package/build/services/memflow/context.d.ts +143 -0
- package/build/services/memflow/context.js +299 -0
- package/build/services/memflow/exporter.d.ts +51 -0
- package/build/services/memflow/exporter.js +215 -0
- package/build/services/memflow/handle.d.ts +90 -0
- package/build/services/memflow/handle.js +176 -0
- package/build/services/memflow/index.d.ts +116 -0
- package/build/services/memflow/index.js +122 -0
- package/build/services/memflow/schemas/factory.d.ts +29 -0
- package/build/services/memflow/schemas/factory.js +2492 -0
- package/build/services/memflow/search.d.ts +142 -0
- package/build/services/memflow/search.js +320 -0
- package/build/services/memflow/worker.d.ts +124 -0
- package/build/services/memflow/worker.js +514 -0
- package/build/services/memflow/workflow/all.d.ts +7 -0
- package/build/services/memflow/workflow/all.js +15 -0
- package/build/services/memflow/workflow/common.d.ts +20 -0
- package/build/services/memflow/workflow/common.js +47 -0
- package/build/services/memflow/workflow/context.d.ts +6 -0
- package/build/services/memflow/workflow/context.js +45 -0
- package/build/services/memflow/workflow/contextMethods.d.ts +14 -0
- package/build/services/memflow/workflow/contextMethods.js +33 -0
- package/build/services/memflow/workflow/didRun.d.ts +7 -0
- package/build/services/memflow/workflow/didRun.js +22 -0
- package/build/services/memflow/workflow/emit.d.ts +11 -0
- package/build/services/memflow/workflow/emit.js +29 -0
- package/build/services/memflow/workflow/enrich.d.ts +9 -0
- package/build/services/memflow/workflow/enrich.js +17 -0
- package/build/services/memflow/workflow/execChild.d.ts +18 -0
- package/build/services/memflow/workflow/execChild.js +102 -0
- package/build/services/memflow/workflow/execHook.d.ts +65 -0
- package/build/services/memflow/workflow/execHook.js +73 -0
- package/build/services/memflow/workflow/hook.d.ts +9 -0
- package/build/services/memflow/workflow/hook.js +56 -0
- package/build/services/memflow/workflow/index.d.ts +74 -0
- package/build/services/memflow/workflow/index.js +87 -0
- package/build/services/memflow/workflow/interrupt.d.ts +9 -0
- package/build/services/memflow/workflow/interrupt.js +24 -0
- package/build/services/memflow/workflow/isSideEffectAllowed.d.ts +10 -0
- package/build/services/memflow/workflow/isSideEffectAllowed.js +33 -0
- package/build/services/memflow/workflow/proxyActivities.d.ts +20 -0
- package/build/services/memflow/workflow/proxyActivities.js +97 -0
- package/build/services/memflow/workflow/random.d.ts +6 -0
- package/build/services/memflow/workflow/random.js +16 -0
- package/build/services/memflow/workflow/searchMethods.d.ts +6 -0
- package/build/services/memflow/workflow/searchMethods.js +25 -0
- package/build/services/memflow/workflow/signal.d.ts +29 -0
- package/build/services/memflow/workflow/signal.js +50 -0
- package/build/services/memflow/workflow/sleepFor.d.ts +24 -0
- package/build/services/memflow/workflow/sleepFor.js +51 -0
- package/build/services/memflow/workflow/trace.d.ts +14 -0
- package/build/services/memflow/workflow/trace.js +33 -0
- package/build/services/memflow/workflow/waitFor.d.ts +29 -0
- package/build/services/memflow/workflow/waitFor.js +56 -0
- package/build/services/meshcall/index.d.ts +194 -0
- package/build/services/meshcall/index.js +452 -0
- package/build/services/meshcall/schemas/factory.d.ts +9 -0
- package/build/services/meshcall/schemas/factory.js +189 -0
- package/build/services/meshdata/index.d.ts +795 -0
- package/build/services/meshdata/index.js +1235 -0
- package/build/services/meshos/index.d.ts +293 -0
- package/build/services/meshos/index.js +547 -0
- package/build/services/pipe/functions/array.d.ts +17 -0
- package/build/services/pipe/functions/array.js +74 -0
- package/build/services/pipe/functions/bitwise.d.ts +9 -0
- package/build/services/pipe/functions/bitwise.js +24 -0
- package/build/services/pipe/functions/conditional.d.ts +13 -0
- package/build/services/pipe/functions/conditional.js +36 -0
- package/build/services/pipe/functions/cron.d.ts +12 -0
- package/build/services/pipe/functions/cron.js +40 -0
- package/build/services/pipe/functions/date.d.ts +58 -0
- package/build/services/pipe/functions/date.js +171 -0
- package/build/services/pipe/functions/index.d.ts +29 -0
- package/build/services/pipe/functions/index.js +30 -0
- package/build/services/pipe/functions/json.d.ts +5 -0
- package/build/services/pipe/functions/json.js +12 -0
- package/build/services/pipe/functions/logical.d.ts +5 -0
- package/build/services/pipe/functions/logical.js +12 -0
- package/build/services/pipe/functions/math.d.ts +42 -0
- package/build/services/pipe/functions/math.js +184 -0
- package/build/services/pipe/functions/number.d.ts +21 -0
- package/build/services/pipe/functions/number.js +60 -0
- package/build/services/pipe/functions/object.d.ts +25 -0
- package/build/services/pipe/functions/object.js +81 -0
- package/build/services/pipe/functions/string.d.ts +23 -0
- package/build/services/pipe/functions/string.js +69 -0
- package/build/services/pipe/functions/symbol.d.ts +12 -0
- package/build/services/pipe/functions/symbol.js +33 -0
- package/build/services/pipe/functions/unary.d.ts +7 -0
- package/build/services/pipe/functions/unary.js +18 -0
- package/build/services/pipe/index.d.ts +48 -0
- package/build/services/pipe/index.js +242 -0
- package/build/services/quorum/index.d.ts +90 -0
- package/build/services/quorum/index.js +263 -0
- package/build/services/reporter/index.d.ts +50 -0
- package/build/services/reporter/index.js +348 -0
- package/build/services/router/config/index.d.ts +11 -0
- package/build/services/router/config/index.js +36 -0
- package/build/services/router/consumption/index.d.ts +34 -0
- package/build/services/router/consumption/index.js +395 -0
- package/build/services/router/error-handling/index.d.ts +8 -0
- package/build/services/router/error-handling/index.js +98 -0
- package/build/services/router/index.d.ts +57 -0
- package/build/services/router/index.js +121 -0
- package/build/services/router/lifecycle/index.d.ts +27 -0
- package/build/services/router/lifecycle/index.js +80 -0
- package/build/services/router/telemetry/index.d.ts +11 -0
- package/build/services/router/telemetry/index.js +32 -0
- package/build/services/router/throttling/index.d.ts +23 -0
- package/build/services/router/throttling/index.js +76 -0
- package/build/services/search/factory.d.ts +7 -0
- package/build/services/search/factory.js +24 -0
- package/build/services/search/index.d.ts +23 -0
- package/build/services/search/index.js +10 -0
- package/build/services/search/providers/postgres/postgres.d.ts +25 -0
- package/build/services/search/providers/postgres/postgres.js +149 -0
- package/build/services/search/providers/redis/ioredis.d.ts +19 -0
- package/build/services/search/providers/redis/ioredis.js +121 -0
- package/build/services/search/providers/redis/redis.d.ts +19 -0
- package/build/services/search/providers/redis/redis.js +134 -0
- package/build/services/serializer/index.d.ts +42 -0
- package/build/services/serializer/index.js +282 -0
- package/build/services/store/cache.d.ts +67 -0
- package/build/services/store/cache.js +128 -0
- package/build/services/store/factory.d.ts +8 -0
- package/build/services/store/factory.js +24 -0
- package/build/services/store/index.d.ts +89 -0
- package/build/services/store/index.js +9 -0
- package/build/services/store/providers/postgres/kvsql.d.ts +168 -0
- package/build/services/store/providers/postgres/kvsql.js +198 -0
- package/build/services/store/providers/postgres/kvtables.d.ts +20 -0
- package/build/services/store/providers/postgres/kvtables.js +441 -0
- package/build/services/store/providers/postgres/kvtransaction.d.ts +36 -0
- package/build/services/store/providers/postgres/kvtransaction.js +248 -0
- package/build/services/store/providers/postgres/kvtypes/hash.d.ts +60 -0
- package/build/services/store/providers/postgres/kvtypes/hash.js +1287 -0
- package/build/services/store/providers/postgres/kvtypes/list.d.ts +33 -0
- package/build/services/store/providers/postgres/kvtypes/list.js +194 -0
- package/build/services/store/providers/postgres/kvtypes/string.d.ts +20 -0
- package/build/services/store/providers/postgres/kvtypes/string.js +115 -0
- package/build/services/store/providers/postgres/kvtypes/zset.d.ts +41 -0
- package/build/services/store/providers/postgres/kvtypes/zset.js +214 -0
- package/build/services/store/providers/postgres/postgres.d.ts +178 -0
- package/build/services/store/providers/postgres/postgres.js +1244 -0
- package/build/services/store/providers/redis/_base.d.ts +137 -0
- package/build/services/store/providers/redis/_base.js +980 -0
- package/build/services/store/providers/redis/ioredis.d.ts +20 -0
- package/build/services/store/providers/redis/ioredis.js +180 -0
- package/build/services/store/providers/redis/redis.d.ts +18 -0
- package/build/services/store/providers/redis/redis.js +199 -0
- package/build/services/store/providers/store-initializable.d.ts +5 -0
- package/build/services/store/providers/store-initializable.js +2 -0
- package/build/services/stream/factory.d.ts +8 -0
- package/build/services/stream/factory.js +37 -0
- package/build/services/stream/index.d.ts +69 -0
- package/build/services/stream/index.js +11 -0
- package/build/services/stream/providers/nats/nats.d.ts +60 -0
- package/build/services/stream/providers/nats/nats.js +225 -0
- package/build/services/stream/providers/postgres/kvtables.d.ts +3 -0
- package/build/services/stream/providers/postgres/kvtables.js +146 -0
- package/build/services/stream/providers/postgres/postgres.d.ts +107 -0
- package/build/services/stream/providers/postgres/postgres.js +519 -0
- package/build/services/stream/providers/redis/ioredis.d.ts +61 -0
- package/build/services/stream/providers/redis/ioredis.js +272 -0
- package/build/services/stream/providers/redis/redis.d.ts +61 -0
- package/build/services/stream/providers/redis/redis.js +305 -0
- package/build/services/stream/providers/stream-initializable.d.ts +4 -0
- package/build/services/stream/providers/stream-initializable.js +2 -0
- package/build/services/sub/factory.d.ts +7 -0
- package/build/services/sub/factory.js +29 -0
- package/build/services/sub/index.d.ts +22 -0
- package/build/services/sub/index.js +10 -0
- package/build/services/sub/providers/nats/nats.d.ts +19 -0
- package/build/services/sub/providers/nats/nats.js +105 -0
- package/build/services/sub/providers/postgres/postgres.d.ts +19 -0
- package/build/services/sub/providers/postgres/postgres.js +92 -0
- package/build/services/sub/providers/redis/ioredis.d.ts +17 -0
- package/build/services/sub/providers/redis/ioredis.js +81 -0
- package/build/services/sub/providers/redis/redis.d.ts +17 -0
- package/build/services/sub/providers/redis/redis.js +72 -0
- package/build/services/task/index.d.ts +48 -0
- package/build/services/task/index.js +253 -0
- package/build/services/telemetry/index.d.ts +52 -0
- package/build/services/telemetry/index.js +306 -0
- package/build/services/worker/index.d.ts +77 -0
- package/build/services/worker/index.js +197 -0
- package/package.json +1 -1
- package/.github/ISSUE_TEMPLATE/bug_report.md +0 -38
- package/.github/ISSUE_TEMPLATE/feature_request.md +0 -20
- package/typedoc.json +0 -47
- package/types/activity.ts +0 -268
- package/types/app.ts +0 -20
- package/types/async.ts +0 -6
- package/types/cache.ts +0 -1
- package/types/collator.ts +0 -9
- package/types/error.ts +0 -56
- package/types/exporter.ts +0 -102
- package/types/hook.ts +0 -44
- package/types/hotmesh.ts +0 -314
- package/types/index.ts +0 -306
- package/types/job.ts +0 -233
- package/types/logger.ts +0 -8
- package/types/manifest.ts +0 -70
- package/types/map.ts +0 -5
- package/types/memflow.ts +0 -645
- package/types/meshcall.ts +0 -235
- package/types/meshdata.ts +0 -278
- package/types/ms.d.ts +0 -7
- package/types/nats.ts +0 -270
- package/types/pipe.ts +0 -90
- package/types/postgres.ts +0 -114
- package/types/provider.ts +0 -161
- package/types/quorum.ts +0 -167
- package/types/redis.ts +0 -404
- package/types/serializer.ts +0 -40
- package/types/stats.ts +0 -117
- package/types/stream.ts +0 -231
- package/types/task.ts +0 -7
- package/types/telemetry.ts +0 -16
- package/types/transition.ts +0 -20
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.interrupt = void 0;
|
|
4
|
+
const common_1 = require("./common");
|
|
5
|
+
const context_1 = require("./context");
|
|
6
|
+
const isSideEffectAllowed_1 = require("./isSideEffectAllowed");
|
|
7
|
+
/**
|
|
8
|
+
* Interrupts a running job by sending an interruption request.
|
|
9
|
+
*
|
|
10
|
+
* @param {string} jobId - The ID of the job to interrupt.
|
|
11
|
+
* @param {JobInterruptOptions} options - Additional interruption options.
|
|
12
|
+
* @returns {Promise<string|void>} Result of the interruption, if any.
|
|
13
|
+
*/
|
|
14
|
+
async function interrupt(jobId, options = {}) {
|
|
15
|
+
const { workflowTopic, connection, namespace } = (0, context_1.getContext)();
|
|
16
|
+
const hotMeshClient = await common_1.WorkerService.getHotMesh(workflowTopic, {
|
|
17
|
+
connection,
|
|
18
|
+
namespace,
|
|
19
|
+
});
|
|
20
|
+
if (await (0, isSideEffectAllowed_1.isSideEffectAllowed)(hotMeshClient, 'interrupt')) {
|
|
21
|
+
return await hotMeshClient.interrupt(`${hotMeshClient.appId}.execute`, jobId, options);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.interrupt = interrupt;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { HotMesh } from './common';
|
|
2
|
+
/**
|
|
3
|
+
* Checks if a side-effect is allowed to run. This ensures certain actions
|
|
4
|
+
* are executed exactly once.
|
|
5
|
+
* @private
|
|
6
|
+
* @param {HotMesh} hotMeshClient - The HotMesh client.
|
|
7
|
+
* @param {string} prefix - A unique prefix representing the action (e.g., 'trace', 'emit', etc.)
|
|
8
|
+
* @returns {Promise<boolean>} True if the side effect can run, false otherwise.
|
|
9
|
+
*/
|
|
10
|
+
export declare function isSideEffectAllowed(hotMeshClient: HotMesh, prefix: string): Promise<boolean>;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isSideEffectAllowed = void 0;
|
|
4
|
+
const common_1 = require("./common");
|
|
5
|
+
/**
|
|
6
|
+
* Checks if a side-effect is allowed to run. This ensures certain actions
|
|
7
|
+
* are executed exactly once.
|
|
8
|
+
* @private
|
|
9
|
+
* @param {HotMesh} hotMeshClient - The HotMesh client.
|
|
10
|
+
* @param {string} prefix - A unique prefix representing the action (e.g., 'trace', 'emit', etc.)
|
|
11
|
+
* @returns {Promise<boolean>} True if the side effect can run, false otherwise.
|
|
12
|
+
*/
|
|
13
|
+
async function isSideEffectAllowed(hotMeshClient, prefix) {
|
|
14
|
+
const store = common_1.asyncLocalStorage.getStore();
|
|
15
|
+
const workflowId = store.get('workflowId');
|
|
16
|
+
const workflowDimension = store.get('workflowDimension') ?? '';
|
|
17
|
+
const COUNTER = store.get('counter');
|
|
18
|
+
const execIndex = COUNTER.counter = COUNTER.counter + 1;
|
|
19
|
+
const sessionId = `-${prefix}${workflowDimension}-${execIndex}-`;
|
|
20
|
+
const replay = store.get('replay');
|
|
21
|
+
if (sessionId in replay) {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
const keyParams = {
|
|
25
|
+
appId: hotMeshClient.appId,
|
|
26
|
+
jobId: workflowId,
|
|
27
|
+
};
|
|
28
|
+
const workflowGuid = common_1.KeyService.mintKey(hotMeshClient.namespace, common_1.KeyType.JOB_STATE, keyParams);
|
|
29
|
+
const searchClient = hotMeshClient.engine.search;
|
|
30
|
+
const guidValue = await searchClient.incrementFieldByFloat(workflowGuid, sessionId, 1);
|
|
31
|
+
return guidValue === 1;
|
|
32
|
+
}
|
|
33
|
+
exports.isSideEffectAllowed = isSideEffectAllowed;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ActivityConfig, ProxyType, MemFlowProxyErrorType } from './common';
|
|
2
|
+
import { getContext } from './context';
|
|
3
|
+
/**
|
|
4
|
+
* Constructs payload for spawning a proxyActivity job.
|
|
5
|
+
* @private
|
|
6
|
+
*/
|
|
7
|
+
declare function getProxyInterruptPayload(context: ReturnType<typeof getContext>, activityName: string, execIndex: number, args: any[], options?: ActivityConfig): MemFlowProxyErrorType;
|
|
8
|
+
/**
|
|
9
|
+
* Wraps a single activity in a proxy, orchestrating its execution and replay.
|
|
10
|
+
* @private
|
|
11
|
+
*/
|
|
12
|
+
declare function wrapActivity<T>(activityName: string, options?: ActivityConfig): T;
|
|
13
|
+
/**
|
|
14
|
+
* Provides a proxy for defined activities, ensuring deterministic replay and retry.
|
|
15
|
+
* @template ACT
|
|
16
|
+
* @param {ActivityConfig} [options] - Optional activity config (includes retryPolicy).
|
|
17
|
+
* @returns {ProxyType<ACT>} A proxy to call activities as if local, but durably managed by the workflow.
|
|
18
|
+
*/
|
|
19
|
+
export declare function proxyActivities<ACT>(options?: ActivityConfig): ProxyType<ACT>;
|
|
20
|
+
export { wrapActivity, getProxyInterruptPayload };
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getProxyInterruptPayload = exports.wrapActivity = exports.proxyActivities = void 0;
|
|
4
|
+
const common_1 = require("./common");
|
|
5
|
+
const context_1 = require("./context");
|
|
6
|
+
const didRun_1 = require("./didRun");
|
|
7
|
+
/**
|
|
8
|
+
* Constructs payload for spawning a proxyActivity job.
|
|
9
|
+
* @private
|
|
10
|
+
*/
|
|
11
|
+
function getProxyInterruptPayload(context, activityName, execIndex, args, options) {
|
|
12
|
+
const { workflowDimension, workflowId, originJobId, workflowTopic, expire } = context;
|
|
13
|
+
const activityTopic = `${workflowTopic}-activity`;
|
|
14
|
+
const activityJobId = `-${workflowId}-$${activityName}${workflowDimension}-${execIndex}`;
|
|
15
|
+
let maximumInterval;
|
|
16
|
+
if (options?.retryPolicy?.maximumInterval) {
|
|
17
|
+
maximumInterval = (0, common_1.s)(options.retryPolicy.maximumInterval);
|
|
18
|
+
}
|
|
19
|
+
return {
|
|
20
|
+
arguments: args,
|
|
21
|
+
workflowDimension,
|
|
22
|
+
index: execIndex,
|
|
23
|
+
originJobId: originJobId || workflowId,
|
|
24
|
+
parentWorkflowId: workflowId,
|
|
25
|
+
workflowId: activityJobId,
|
|
26
|
+
workflowTopic: activityTopic,
|
|
27
|
+
activityName,
|
|
28
|
+
expire: options?.expire ?? expire,
|
|
29
|
+
backoffCoefficient: options?.retryPolicy?.backoffCoefficient ?? undefined,
|
|
30
|
+
maximumAttempts: options?.retryPolicy?.maximumAttempts ?? undefined,
|
|
31
|
+
maximumInterval: maximumInterval ?? undefined,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
exports.getProxyInterruptPayload = getProxyInterruptPayload;
|
|
35
|
+
/**
|
|
36
|
+
* Wraps a single activity in a proxy, orchestrating its execution and replay.
|
|
37
|
+
* @private
|
|
38
|
+
*/
|
|
39
|
+
function wrapActivity(activityName, options) {
|
|
40
|
+
return async function (...args) {
|
|
41
|
+
const [didRunAlready, execIndex, result] = await (0, didRun_1.didRun)('proxy');
|
|
42
|
+
if (didRunAlready) {
|
|
43
|
+
if (result?.$error) {
|
|
44
|
+
if (options?.retryPolicy?.throwOnError !== false) {
|
|
45
|
+
const code = result.$error.code;
|
|
46
|
+
const message = result.$error.message;
|
|
47
|
+
const stack = result.$error.stack;
|
|
48
|
+
if (code === common_1.HMSH_CODE_MEMFLOW_FATAL) {
|
|
49
|
+
throw new common_1.MemFlowFatalError(message, stack);
|
|
50
|
+
}
|
|
51
|
+
else if (code === common_1.HMSH_CODE_MEMFLOW_MAXED) {
|
|
52
|
+
throw new common_1.MemFlowMaxedError(message, stack);
|
|
53
|
+
}
|
|
54
|
+
else if (code === common_1.HMSH_CODE_MEMFLOW_TIMEOUT) {
|
|
55
|
+
throw new common_1.MemFlowTimeoutError(message, stack);
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
// Non-fatal error
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return result.$error;
|
|
62
|
+
}
|
|
63
|
+
return result.data;
|
|
64
|
+
}
|
|
65
|
+
const context = (0, context_1.getContext)();
|
|
66
|
+
const { interruptionRegistry } = context;
|
|
67
|
+
const interruptionMessage = getProxyInterruptPayload(context, activityName, execIndex, args, options);
|
|
68
|
+
interruptionRegistry.push({
|
|
69
|
+
code: common_1.HMSH_CODE_MEMFLOW_PROXY,
|
|
70
|
+
...interruptionMessage,
|
|
71
|
+
});
|
|
72
|
+
await (0, common_1.sleepImmediate)();
|
|
73
|
+
throw new common_1.MemFlowProxyError(interruptionMessage);
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
exports.wrapActivity = wrapActivity;
|
|
77
|
+
/**
|
|
78
|
+
* Provides a proxy for defined activities, ensuring deterministic replay and retry.
|
|
79
|
+
* @template ACT
|
|
80
|
+
* @param {ActivityConfig} [options] - Optional activity config (includes retryPolicy).
|
|
81
|
+
* @returns {ProxyType<ACT>} A proxy to call activities as if local, but durably managed by the workflow.
|
|
82
|
+
*/
|
|
83
|
+
function proxyActivities(options) {
|
|
84
|
+
if (options?.activities) {
|
|
85
|
+
common_1.WorkerService.registerActivities(options.activities);
|
|
86
|
+
}
|
|
87
|
+
const proxy = {};
|
|
88
|
+
const keys = Object.keys(common_1.WorkerService.activityRegistry);
|
|
89
|
+
if (keys.length) {
|
|
90
|
+
keys.forEach((key) => {
|
|
91
|
+
const activityFunction = common_1.WorkerService.activityRegistry[key];
|
|
92
|
+
proxy[key] = wrapActivity(key, options);
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
return proxy;
|
|
96
|
+
}
|
|
97
|
+
exports.proxyActivities = proxyActivities;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns a deterministic random number between 0 and 1. The number is derived from the
|
|
3
|
+
* current execution index, ensuring deterministic replay.
|
|
4
|
+
* @returns {number} A deterministic pseudo-random number between 0 and 1.
|
|
5
|
+
*/
|
|
6
|
+
export declare function random(): number;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.random = void 0;
|
|
4
|
+
const common_1 = require("./common");
|
|
5
|
+
/**
|
|
6
|
+
* Returns a deterministic random number between 0 and 1. The number is derived from the
|
|
7
|
+
* current execution index, ensuring deterministic replay.
|
|
8
|
+
* @returns {number} A deterministic pseudo-random number between 0 and 1.
|
|
9
|
+
*/
|
|
10
|
+
function random() {
|
|
11
|
+
const store = common_1.asyncLocalStorage.getStore();
|
|
12
|
+
const COUNTER = store.get('counter');
|
|
13
|
+
const seed = COUNTER.counter = COUNTER.counter + 1;
|
|
14
|
+
return (0, common_1.deterministicRandom)(seed);
|
|
15
|
+
}
|
|
16
|
+
exports.random = random;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.search = void 0;
|
|
4
|
+
const common_1 = require("./common");
|
|
5
|
+
/**
|
|
6
|
+
* Returns a search session handle for interacting with the workflow's HASH storage.
|
|
7
|
+
* @returns {Promise<Search>} A search session for workflow data.
|
|
8
|
+
*/
|
|
9
|
+
async function search() {
|
|
10
|
+
const store = common_1.asyncLocalStorage.getStore();
|
|
11
|
+
const workflowId = store.get('workflowId');
|
|
12
|
+
const workflowDimension = store.get('workflowDimension') ?? '';
|
|
13
|
+
const workflowTopic = store.get('workflowTopic');
|
|
14
|
+
const connection = store.get('connection');
|
|
15
|
+
const namespace = store.get('namespace');
|
|
16
|
+
const COUNTER = store.get('counter');
|
|
17
|
+
const execIndex = COUNTER.counter = COUNTER.counter + 1;
|
|
18
|
+
const hotMeshClient = await common_1.WorkerService.getHotMesh(workflowTopic, {
|
|
19
|
+
connection,
|
|
20
|
+
namespace,
|
|
21
|
+
});
|
|
22
|
+
const searchSessionId = `-search${workflowDimension}-${execIndex}`;
|
|
23
|
+
return new common_1.Search(workflowId, hotMeshClient, searchSessionId);
|
|
24
|
+
}
|
|
25
|
+
exports.search = search;
|
|
@@ -0,0 +1,29 @@
|
|
|
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>;
|
|
@@ -0,0 +1,50 @@
|
|
|
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;
|
|
@@ -0,0 +1,24 @@
|
|
|
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>;
|
|
@@ -0,0 +1,51 @@
|
|
|
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
|
+
...interruptionMessage,
|
|
47
|
+
});
|
|
48
|
+
await (0, common_1.sleepImmediate)();
|
|
49
|
+
throw new common_1.MemFlowSleepError(interruptionMessage);
|
|
50
|
+
}
|
|
51
|
+
exports.sleepFor = sleepFor;
|
|
@@ -0,0 +1,14 @@
|
|
|
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>;
|
|
@@ -0,0 +1,33 @@
|
|
|
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;
|
|
@@ -0,0 +1,29 @@
|
|
|
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>;
|
|
@@ -0,0 +1,56 @@
|
|
|
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
|
+
};
|
|
49
|
+
interruptionRegistry.push({
|
|
50
|
+
code: common_1.HMSH_CODE_MEMFLOW_WAIT,
|
|
51
|
+
...interruptionMessage,
|
|
52
|
+
});
|
|
53
|
+
await (0, common_1.sleepImmediate)();
|
|
54
|
+
throw new common_1.MemFlowWaitForError(interruptionMessage);
|
|
55
|
+
}
|
|
56
|
+
exports.waitFor = waitFor;
|