@hotmeshio/hotmesh 0.4.1 → 0.4.3

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 (38) hide show
  1. package/README.md +114 -51
  2. package/build/index.d.ts +2 -1
  3. package/build/index.js +3 -1
  4. package/build/package.json +3 -2
  5. package/build/services/activities/trigger.d.ts +1 -1
  6. package/build/services/activities/trigger.js +3 -3
  7. package/build/services/memflow/client.js +2 -1
  8. package/build/services/memflow/{context.d.ts → entity.d.ts} +34 -34
  9. package/build/services/memflow/{context.js → entity.js} +40 -40
  10. package/build/services/memflow/index.d.ts +2 -2
  11. package/build/services/memflow/index.js +2 -2
  12. package/build/services/memflow/workflow/common.d.ts +2 -2
  13. package/build/services/memflow/workflow/common.js +3 -3
  14. package/build/services/memflow/workflow/entityMethods.d.ts +14 -0
  15. package/build/services/memflow/workflow/{contextMethods.js → entityMethods.js} +11 -11
  16. package/build/services/memflow/workflow/index.d.ts +2 -2
  17. package/build/services/memflow/workflow/index.js +2 -2
  18. package/build/services/memflow/workflow/signal.d.ts +23 -1
  19. package/build/services/memflow/workflow/signal.js +23 -1
  20. package/build/services/memflow/workflow/sleepFor.d.ts +17 -1
  21. package/build/services/memflow/workflow/sleepFor.js +17 -1
  22. package/build/services/memflow/workflow/waitFor.d.ts +22 -1
  23. package/build/services/memflow/workflow/waitFor.js +22 -1
  24. package/build/services/store/index.d.ts +1 -1
  25. package/build/services/store/providers/postgres/kvsql.d.ts +1 -1
  26. package/build/services/store/providers/postgres/kvtypes/hash.d.ts +1 -1
  27. package/build/services/store/providers/postgres/kvtypes/hash.js +8 -8
  28. package/build/services/store/providers/postgres/postgres.d.ts +34 -1
  29. package/build/services/store/providers/postgres/postgres.js +211 -2
  30. package/build/services/store/providers/redis/_base.d.ts +1 -1
  31. package/build/services/store/providers/redis/_base.js +1 -1
  32. package/build/services/task/index.d.ts +12 -0
  33. package/build/services/task/index.js +47 -0
  34. package/build/types/job.d.ts +7 -0
  35. package/build/types/provider.d.ts +1 -0
  36. package/index.ts +2 -2
  37. package/package.json +4 -3
  38. package/build/services/memflow/workflow/contextMethods.d.ts +0 -14
@@ -1,29 +1,29 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Context = void 0;
3
+ exports.Entity = void 0;
4
4
  const key_1 = require("../../modules/key");
5
5
  const storage_1 = require("../../modules/storage");
6
6
  /**
7
- * The Context module provides methods for reading and writing
8
- * JSONB data to a workflow's context. The instance methods
7
+ * The Entity module provides methods for reading and writing
8
+ * JSONB data to a workflow's entity. The instance methods
9
9
  * exposed by this class are available for use from within
10
10
  * a running workflow.
11
11
  *
12
12
  * @example
13
13
  * ```typescript
14
- * //contextWorkflow.ts
14
+ * //entityWorkflow.ts
15
15
  * import { workflow } from '@hotmeshio/hotmesh';
16
16
  *
17
- * export async function contextExample(): Promise<void> {
18
- * const context = await workflow.context();
19
- * await context.set({ user: { id: 123 } });
20
- * await context.merge({ user: { name: "John" } });
21
- * const user = await context.get("user");
17
+ * export async function entityExample(): Promise<void> {
18
+ * const entity = await workflow.entity();
19
+ * await entity.set({ user: { id: 123 } });
20
+ * await entity.merge({ user: { name: "John" } });
21
+ * const user = await entity.get("user");
22
22
  * // user = { id: 123, name: "John" }
23
23
  * }
24
24
  * ```
25
25
  */
26
- class Context {
26
+ class Entity {
27
27
  /**
28
28
  * @private
29
29
  */
@@ -53,11 +53,11 @@ class Context {
53
53
  return `${this.searchSessionId}-${this.searchSessionIndex++}-`;
54
54
  }
55
55
  /**
56
- * Sets the entire context object. This replaces any existing context.
56
+ * Sets the entire entity object. This replaces any existing entity.
57
57
  *
58
58
  * @example
59
- * const context = await workflow.context();
60
- * await context.set({ user: { id: 123, name: "John" } });
59
+ * const entity = await workflow.entity();
60
+ * await entity.set({ user: { id: 123, name: "John" } });
61
61
  */
62
62
  async set(value) {
63
63
  const ssGuid = this.getSearchSessionGuid();
@@ -66,7 +66,7 @@ class Context {
66
66
  if (ssGuid in replay) {
67
67
  return JSON.parse(replay[ssGuid]);
68
68
  }
69
- // Use single transactional call to update context and store replay value
69
+ // Use single transactional call to update entity and store replay value
70
70
  const result = await this.search.updateContext(this.jobId, {
71
71
  '@context': JSON.stringify(value),
72
72
  [ssGuid]: '', // Pass replay ID to hash module for transactional replay storage
@@ -74,11 +74,11 @@ class Context {
74
74
  return result || value;
75
75
  }
76
76
  /**
77
- * Deep merges the provided object with the existing context
77
+ * Deep merges the provided object with the existing entity
78
78
  *
79
79
  * @example
80
- * const context = await workflow.context();
81
- * await context.merge({ user: { email: "john@example.com" } });
80
+ * const entity = await workflow.entity();
81
+ * await entity.merge({ user: { email: "john@example.com" } });
82
82
  */
83
83
  async merge(value) {
84
84
  const ssGuid = this.getSearchSessionGuid();
@@ -95,29 +95,29 @@ class Context {
95
95
  return newContext;
96
96
  }
97
97
  /**
98
- * Gets a value from the context by path
98
+ * Gets a value from the entity by path
99
99
  *
100
100
  * @example
101
- * const context = await workflow.context();
102
- * const user = await context.get("user");
103
- * const email = await context.get("user.email");
101
+ * const entity = await workflow.entity();
102
+ * const user = await entity.get("user");
103
+ * const email = await entity.get("user.email");
104
104
  */
105
105
  async get(path) {
106
106
  const ssGuid = this.getSearchSessionGuid();
107
107
  const store = storage_1.asyncLocalStorage.getStore();
108
108
  const replay = store?.get('replay') ?? {};
109
109
  if (ssGuid in replay) {
110
- // Replay cache stores the already-extracted value, not full context
110
+ // Replay cache stores the already-extracted value, not full entity
111
111
  return JSON.parse(replay[ssGuid]);
112
112
  }
113
113
  let value;
114
114
  if (!path) {
115
- // No path - fetch entire context with replay storage
115
+ // No path - fetch entire entity with replay storage
116
116
  const result = await this.search.updateContext(this.jobId, {
117
117
  '@context:get': '',
118
118
  [ssGuid]: '', // Pass replay ID to hash module
119
119
  });
120
- // setFields returns the actual context value for @context:get operations
120
+ // setFields returns the actual entity value for @context:get operations
121
121
  value = result || {};
122
122
  }
123
123
  else {
@@ -132,11 +132,11 @@ class Context {
132
132
  return value;
133
133
  }
134
134
  /**
135
- * Deletes a value from the context by path
135
+ * Deletes a value from the entity by path
136
136
  *
137
137
  * @example
138
- * const context = await workflow.context();
139
- * await context.delete("user.email");
138
+ * const entity = await workflow.entity();
139
+ * await entity.delete("user.email");
140
140
  */
141
141
  async delete(path) {
142
142
  const ssGuid = this.getSearchSessionGuid();
@@ -156,8 +156,8 @@ class Context {
156
156
  * Appends a value to an array at the specified path
157
157
  *
158
158
  * @example
159
- * const context = await workflow.context();
160
- * await context.append("items", { id: 1, name: "New Item" });
159
+ * const entity = await workflow.entity();
160
+ * await entity.append("items", { id: 1, name: "New Item" });
161
161
  */
162
162
  async append(path, value) {
163
163
  const ssGuid = this.getSearchSessionGuid();
@@ -177,8 +177,8 @@ class Context {
177
177
  * Prepends a value to an array at the specified path
178
178
  *
179
179
  * @example
180
- * const context = await workflow.context();
181
- * await context.prepend("items", { id: 0, name: "First Item" });
180
+ * const entity = await workflow.entity();
181
+ * await entity.prepend("items", { id: 0, name: "First Item" });
182
182
  */
183
183
  async prepend(path, value) {
184
184
  const ssGuid = this.getSearchSessionGuid();
@@ -198,8 +198,8 @@ class Context {
198
198
  * Removes an item from an array at the specified path and index
199
199
  *
200
200
  * @example
201
- * const context = await workflow.context();
202
- * await context.remove("items", 0); // Remove first item
201
+ * const entity = await workflow.entity();
202
+ * await entity.remove("items", 0); // Remove first item
203
203
  */
204
204
  async remove(path, index) {
205
205
  const ssGuid = this.getSearchSessionGuid();
@@ -219,8 +219,8 @@ class Context {
219
219
  * Increments a numeric value at the specified path
220
220
  *
221
221
  * @example
222
- * const context = await workflow.context();
223
- * await context.increment("counter", 5);
222
+ * const entity = await workflow.entity();
223
+ * await entity.increment("counter", 5);
224
224
  */
225
225
  async increment(path, value = 1) {
226
226
  const ssGuid = this.getSearchSessionGuid();
@@ -240,8 +240,8 @@ class Context {
240
240
  * Toggles a boolean value at the specified path
241
241
  *
242
242
  * @example
243
- * const context = await workflow.context();
244
- * await context.toggle("settings.enabled");
243
+ * const entity = await workflow.entity();
244
+ * await entity.toggle("settings.enabled");
245
245
  */
246
246
  async toggle(path) {
247
247
  const ssGuid = this.getSearchSessionGuid();
@@ -261,8 +261,8 @@ class Context {
261
261
  * Sets a value at the specified path only if it doesn't already exist
262
262
  *
263
263
  * @example
264
- * const context = await workflow.context();
265
- * await context.setIfNotExists("user.id", 123);
264
+ * const entity = await workflow.entity();
265
+ * await entity.setIfNotExists("user.id", 123);
266
266
  */
267
267
  async setIfNotExists(path, value) {
268
268
  const ssGuid = this.getSearchSessionGuid();
@@ -296,4 +296,4 @@ class Context {
296
296
  return output;
297
297
  }
298
298
  }
299
- exports.Context = Context;
299
+ exports.Entity = Entity;
@@ -2,7 +2,7 @@ import { ContextType } from '../../types/memflow';
2
2
  import { ClientService } from './client';
3
3
  import { ConnectionService } from './connection';
4
4
  import { Search } from './search';
5
- import { Context } from './context';
5
+ import { Entity } from './entity';
6
6
  import { WorkerService } from './worker';
7
7
  import { WorkflowService } from './workflow';
8
8
  import { WorkflowHandleService } from './handle';
@@ -86,7 +86,7 @@ declare class MemFlowClass {
86
86
  /**
87
87
  * @private
88
88
  */
89
- static Context: typeof Context;
89
+ static Entity: typeof Entity;
90
90
  /**
91
91
  * The Handle provides methods to interact with a running
92
92
  * workflow. This includes exporting the workflow, sending signals, and
@@ -5,7 +5,7 @@ const hotmesh_1 = require("../hotmesh");
5
5
  const client_1 = require("./client");
6
6
  const connection_1 = require("./connection");
7
7
  const search_1 = require("./search");
8
- const context_1 = require("./context");
8
+ const entity_1 = require("./entity");
9
9
  const worker_1 = require("./worker");
10
10
  const workflow_1 = require("./workflow");
11
11
  const handle_1 = require("./handle");
@@ -100,7 +100,7 @@ MemFlowClass.Search = search_1.Search;
100
100
  /**
101
101
  * @private
102
102
  */
103
- MemFlowClass.Context = context_1.Context;
103
+ MemFlowClass.Entity = entity_1.Entity;
104
104
  /**
105
105
  * The Handle provides methods to interact with a running
106
106
  * workflow. This includes exporting the workflow, sending signals, and
@@ -15,6 +15,6 @@ import { QuorumMessage } from '../../../types';
15
15
  import { UserMessage } from '../../../types/quorum';
16
16
  import { Search } from '../search';
17
17
  import { WorkerService } from '../worker';
18
- import { Context } from '../context';
18
+ import { Entity } from '../entity';
19
19
  import { ExecHookOptions } from './execHook';
20
- export { MemFlowChildError, MemFlowFatalError, MemFlowMaxedError, MemFlowProxyError, MemFlowRetryError, MemFlowSleepError, MemFlowTimeoutError, MemFlowWaitForError, KeyService, KeyType, asyncLocalStorage, deterministicRandom, guid, s, sleepImmediate, HotMesh, SerializerService, ActivityConfig, ChildResponseType, HookOptions, ExecHookOptions, ProxyResponseType, ProxyType, WorkflowContext, WorkflowOptions, JobInterruptOptions, StreamCode, StreamStatus, StringAnyType, StringScalarType, StringStringType, HMSH_CODE_MEMFLOW_CHILD, HMSH_CODE_MEMFLOW_FATAL, HMSH_CODE_MEMFLOW_MAXED, HMSH_CODE_MEMFLOW_PROXY, HMSH_CODE_MEMFLOW_SLEEP, HMSH_CODE_MEMFLOW_TIMEOUT, HMSH_CODE_MEMFLOW_WAIT, HMSH_MEMFLOW_EXP_BACKOFF, HMSH_MEMFLOW_MAX_ATTEMPTS, HMSH_MEMFLOW_MAX_INTERVAL, MemFlowChildErrorType, MemFlowProxyErrorType, TelemetryService, QuorumMessage, UserMessage, Search, WorkerService, Context, };
20
+ export { MemFlowChildError, MemFlowFatalError, MemFlowMaxedError, MemFlowProxyError, MemFlowRetryError, MemFlowSleepError, MemFlowTimeoutError, MemFlowWaitForError, KeyService, KeyType, asyncLocalStorage, deterministicRandom, guid, s, sleepImmediate, HotMesh, SerializerService, ActivityConfig, ChildResponseType, HookOptions, ExecHookOptions, ProxyResponseType, ProxyType, WorkflowContext, WorkflowOptions, JobInterruptOptions, StreamCode, StreamStatus, StringAnyType, StringScalarType, StringStringType, HMSH_CODE_MEMFLOW_CHILD, HMSH_CODE_MEMFLOW_FATAL, HMSH_CODE_MEMFLOW_MAXED, HMSH_CODE_MEMFLOW_PROXY, HMSH_CODE_MEMFLOW_SLEEP, HMSH_CODE_MEMFLOW_TIMEOUT, HMSH_CODE_MEMFLOW_WAIT, HMSH_MEMFLOW_EXP_BACKOFF, HMSH_MEMFLOW_MAX_ATTEMPTS, HMSH_MEMFLOW_MAX_INTERVAL, MemFlowChildErrorType, MemFlowProxyErrorType, TelemetryService, QuorumMessage, UserMessage, Search, WorkerService, Entity, };
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Context = exports.WorkerService = exports.Search = exports.TelemetryService = exports.HMSH_MEMFLOW_MAX_INTERVAL = exports.HMSH_MEMFLOW_MAX_ATTEMPTS = exports.HMSH_MEMFLOW_EXP_BACKOFF = exports.HMSH_CODE_MEMFLOW_WAIT = exports.HMSH_CODE_MEMFLOW_TIMEOUT = exports.HMSH_CODE_MEMFLOW_SLEEP = exports.HMSH_CODE_MEMFLOW_PROXY = exports.HMSH_CODE_MEMFLOW_MAXED = exports.HMSH_CODE_MEMFLOW_FATAL = exports.HMSH_CODE_MEMFLOW_CHILD = exports.StreamStatus = exports.SerializerService = exports.HotMesh = exports.sleepImmediate = exports.s = exports.guid = exports.deterministicRandom = exports.asyncLocalStorage = exports.KeyType = exports.KeyService = exports.MemFlowWaitForError = exports.MemFlowTimeoutError = exports.MemFlowSleepError = exports.MemFlowRetryError = exports.MemFlowProxyError = exports.MemFlowMaxedError = exports.MemFlowFatalError = exports.MemFlowChildError = void 0;
3
+ exports.Entity = exports.WorkerService = exports.Search = exports.TelemetryService = exports.HMSH_MEMFLOW_MAX_INTERVAL = exports.HMSH_MEMFLOW_MAX_ATTEMPTS = exports.HMSH_MEMFLOW_EXP_BACKOFF = exports.HMSH_CODE_MEMFLOW_WAIT = exports.HMSH_CODE_MEMFLOW_TIMEOUT = exports.HMSH_CODE_MEMFLOW_SLEEP = exports.HMSH_CODE_MEMFLOW_PROXY = exports.HMSH_CODE_MEMFLOW_MAXED = exports.HMSH_CODE_MEMFLOW_FATAL = exports.HMSH_CODE_MEMFLOW_CHILD = exports.StreamStatus = exports.SerializerService = exports.HotMesh = exports.sleepImmediate = exports.s = exports.guid = exports.deterministicRandom = exports.asyncLocalStorage = exports.KeyType = exports.KeyService = exports.MemFlowWaitForError = exports.MemFlowTimeoutError = exports.MemFlowSleepError = exports.MemFlowRetryError = exports.MemFlowProxyError = exports.MemFlowMaxedError = exports.MemFlowFatalError = exports.MemFlowChildError = void 0;
4
4
  const errors_1 = require("../../../modules/errors");
5
5
  Object.defineProperty(exports, "MemFlowChildError", { enumerable: true, get: function () { return errors_1.MemFlowChildError; } });
6
6
  Object.defineProperty(exports, "MemFlowFatalError", { enumerable: true, get: function () { return errors_1.MemFlowFatalError; } });
@@ -43,5 +43,5 @@ const search_1 = require("../search");
43
43
  Object.defineProperty(exports, "Search", { enumerable: true, get: function () { return search_1.Search; } });
44
44
  const worker_1 = require("../worker");
45
45
  Object.defineProperty(exports, "WorkerService", { enumerable: true, get: function () { return worker_1.WorkerService; } });
46
- const context_1 = require("../context");
47
- Object.defineProperty(exports, "Context", { enumerable: true, get: function () { return context_1.Context; } });
46
+ const entity_1 = require("../entity");
47
+ Object.defineProperty(exports, "Entity", { enumerable: true, get: function () { return entity_1.Entity; } });
@@ -0,0 +1,14 @@
1
+ import { Entity } from './common';
2
+ /**
3
+ * Returns an entity session handle for interacting with the workflow's JSONB entity storage.
4
+ * @returns {Promise<Entity>} An entity session for workflow data.
5
+ *
6
+ * @example
7
+ * ```typescript
8
+ * const entity = await workflow.entity();
9
+ * await entity.set({ user: { id: 123 } });
10
+ * await entity.merge({ user: { name: "John" } });
11
+ * const user = await entity.get("user");
12
+ * ```
13
+ */
14
+ export declare function entity(): Promise<Entity>;
@@ -1,20 +1,20 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.context = void 0;
3
+ exports.entity = void 0;
4
4
  const common_1 = require("./common");
5
5
  /**
6
- * Returns a context session handle for interacting with the workflow's JSONB context storage.
7
- * @returns {Promise<Context>} A context session for workflow data.
6
+ * Returns an entity session handle for interacting with the workflow's JSONB entity storage.
7
+ * @returns {Promise<Entity>} An entity session for workflow data.
8
8
  *
9
9
  * @example
10
10
  * ```typescript
11
- * const context = await workflow.context();
12
- * await context.set({ user: { id: 123 } });
13
- * await context.merge({ user: { name: "John" } });
14
- * const user = await context.get("user");
11
+ * const entity = await workflow.entity();
12
+ * await entity.set({ user: { id: 123 } });
13
+ * await entity.merge({ user: { name: "John" } });
14
+ * const user = await entity.get("user");
15
15
  * ```
16
16
  */
17
- async function context() {
17
+ async function entity() {
18
18
  const store = common_1.asyncLocalStorage.getStore();
19
19
  const workflowId = store.get('workflowId');
20
20
  const workflowDimension = store.get('workflowDimension') ?? '';
@@ -27,7 +27,7 @@ async function context() {
27
27
  connection,
28
28
  namespace,
29
29
  });
30
- const contextSessionId = `-context${workflowDimension}-${execIndex}`;
31
- return new common_1.Context(workflowId, hotMeshClient, contextSessionId);
30
+ const entitySessionId = `-entity${workflowDimension}-${execIndex}`;
31
+ return new common_1.Entity(workflowId, hotMeshClient, entitySessionId);
32
32
  }
33
- exports.context = context;
33
+ exports.entity = entity;
@@ -16,7 +16,7 @@ import { all } from './all';
16
16
  import { sleepFor } from './sleepFor';
17
17
  import { waitFor } from './waitFor';
18
18
  import { HotMesh } from './common';
19
- import { context } from './contextMethods';
19
+ import { entity } from './entityMethods';
20
20
  /**
21
21
  * The WorkflowService class provides a set of static methods to be used within a workflow function.
22
22
  * These methods ensure deterministic replay, persistence of state, and error handling across
@@ -58,7 +58,7 @@ export declare class WorkflowService {
58
58
  static execHook: typeof execHook;
59
59
  static proxyActivities: typeof proxyActivities;
60
60
  static search: typeof search;
61
- static context: typeof context;
61
+ static entity: typeof entity;
62
62
  static random: typeof random;
63
63
  static signal: typeof signal;
64
64
  static hook: typeof hook;
@@ -19,7 +19,7 @@ const all_1 = require("./all");
19
19
  const sleepFor_1 = require("./sleepFor");
20
20
  const waitFor_1 = require("./waitFor");
21
21
  const common_1 = require("./common");
22
- const contextMethods_1 = require("./contextMethods");
22
+ const entityMethods_1 = require("./entityMethods");
23
23
  /**
24
24
  * The WorkflowService class provides a set of static methods to be used within a workflow function.
25
25
  * These methods ensure deterministic replay, persistence of state, and error handling across
@@ -76,7 +76,7 @@ WorkflowService.startChild = execChild_1.startChild;
76
76
  WorkflowService.execHook = execHook_1.execHook;
77
77
  WorkflowService.proxyActivities = proxyActivities_1.proxyActivities;
78
78
  WorkflowService.search = searchMethods_1.search;
79
- WorkflowService.context = contextMethods_1.context;
79
+ WorkflowService.entity = entityMethods_1.entity;
80
80
  WorkflowService.random = random_1.random;
81
81
  WorkflowService.signal = signal_1.signal;
82
82
  WorkflowService.hook = hook_1.hook;
@@ -1,6 +1,28 @@
1
1
  /**
2
2
  * Sends a signal payload to any paused workflow thread awaiting this signal.
3
- * @param {string} signalId - Unique signal identifier.
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.
4
26
  * @param {Record<any, any>} data - The payload to send with the signal.
5
27
  * @returns {Promise<string>} The resulting hook/stream ID.
6
28
  */
@@ -5,7 +5,29 @@ const common_1 = require("./common");
5
5
  const isSideEffectAllowed_1 = require("./isSideEffectAllowed");
6
6
  /**
7
7
  * Sends a signal payload to any paused workflow thread awaiting this signal.
8
- * @param {string} signalId - Unique signal identifier.
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.
9
31
  * @param {Record<any, any>} data - The payload to send with the signal.
10
32
  * @returns {Promise<string>} The resulting hook/stream ID.
11
33
  */
@@ -2,7 +2,23 @@
2
2
  * Sleeps the workflow for a specified duration, deterministically.
3
3
  * On replay, it will not actually sleep again, but resume after sleep.
4
4
  *
5
- * @param {string} duration - A human-readable duration string (e.g., '1m', '2 hours').
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').
6
22
  * @returns {Promise<number>} The resolved duration in seconds.
7
23
  */
8
24
  export declare function sleepFor(duration: string): Promise<number>;
@@ -7,7 +7,23 @@ const didRun_1 = require("./didRun");
7
7
  * Sleeps the workflow for a specified duration, deterministically.
8
8
  * On replay, it will not actually sleep again, but resume after sleep.
9
9
  *
10
- * @param {string} duration - A human-readable duration string (e.g., '1m', '2 hours').
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').
11
27
  * @returns {Promise<number>} The resolved duration in seconds.
12
28
  */
13
29
  async function sleepFor(duration) {
@@ -1,7 +1,28 @@
1
1
  /**
2
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.
3
5
  *
4
- * @template T
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
5
26
  * @param {string} signalId - A unique signal identifier shared by the sender and receiver.
6
27
  * @returns {Promise<T>} The data payload associated with the received signal.
7
28
  */
@@ -5,8 +5,29 @@ const common_1 = require("./common");
5
5
  const didRun_1 = require("./didRun");
6
6
  /**
7
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.
8
10
  *
9
- * @template T
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
10
31
  * @param {string} signalId - A unique signal identifier shared by the sender and receiver.
11
32
  * @returns {Promise<T>} The data payload associated with the received signal.
12
33
  */
@@ -40,7 +40,7 @@ declare abstract class StoreService<Provider extends ProviderClient, Transaction
40
40
  abstract getJobIds(indexKeys: string[], idRange: [number, number]): Promise<IdsData>;
41
41
  abstract setStatus(collationKeyStatus: number, jobId: string, appId: string, transaction?: TransactionProvider): Promise<any>;
42
42
  abstract getStatus(jobId: string, appId: string): Promise<number>;
43
- abstract setStateNX(jobId: string, appId: string, status?: number): Promise<boolean>;
43
+ abstract setStateNX(jobId: string, appId: string, status?: number, entity?: string): Promise<boolean>;
44
44
  abstract setState(state: StringAnyType, status: number | null, jobId: string, symbolNames: string[], dIds: StringStringType, transaction?: TransactionProvider): Promise<string>;
45
45
  abstract getQueryState(jobId: string, fields: string[]): Promise<StringAnyType>;
46
46
  abstract getState(jobId: string, consumes: Consumes, dIds: StringStringType): Promise<[StringAnyType, number] | undefined>;
@@ -52,7 +52,7 @@ export declare class KVSQL {
52
52
  sql: string;
53
53
  params: any[];
54
54
  };
55
- hsetnx: (key: string, field: string, value: string, multi?: ProviderTransaction) => Promise<number>;
55
+ hsetnx: (key: string, field: string, value: string, multi?: ProviderTransaction, entity?: string) => Promise<number>;
56
56
  hget: (key: string, field: string, multi?: ProviderTransaction) => Promise<string>;
57
57
  _hget: (key: string, field: string) => {
58
58
  sql: string;
@@ -2,7 +2,7 @@ import { PostgresJobEnumType } from '../../../../../types/postgres';
2
2
  import { HScanResult, HSetOptions, ProviderTransaction } from '../../../../../types/provider';
3
3
  import type { KVSQL } from '../kvsql';
4
4
  export declare const hashModule: (context: KVSQL) => {
5
- hsetnx(key: string, field: string, value: string, multi?: ProviderTransaction): Promise<number>;
5
+ hsetnx(key: string, field: string, value: string, multi?: ProviderTransaction, entity?: string): Promise<number>;
6
6
  hset(key: string, fields: Record<string, string>, options?: HSetOptions, multi?: ProviderTransaction): Promise<number | any>;
7
7
  /**
8
8
  * Derives the enumerated `type` value based on the field name when
@@ -2,8 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.hashModule = void 0;
4
4
  const hashModule = (context) => ({
5
- async hsetnx(key, field, value, multi) {
6
- const { sql, params } = this._hset(key, { [field]: value }, { nx: true });
5
+ async hsetnx(key, field, value, multi, entity) {
6
+ const { sql, params } = this._hset(key, { [field]: value }, { nx: true, entity });
7
7
  if (multi) {
8
8
  multi.addCommand(sql, params, 'number');
9
9
  return Promise.resolve(0);
@@ -97,25 +97,25 @@ const hashModule = (context) => ({
97
97
  if (options?.nx) {
98
98
  // Use WHERE NOT EXISTS to enforce nx
99
99
  sql = `
100
- INSERT INTO ${targetTable} (id, key, status)
101
- SELECT gen_random_uuid(), $1, $2
100
+ INSERT INTO ${targetTable} (id, key, status, entity)
101
+ SELECT gen_random_uuid(), $1, $2, $3
102
102
  WHERE NOT EXISTS (
103
103
  SELECT 1 FROM ${targetTable}
104
104
  WHERE key = $1 AND is_live
105
105
  )
106
106
  RETURNING 1 as count
107
107
  `;
108
- params.push(key, fields[':']);
108
+ params.push(key, fields[':'], options?.entity ?? null);
109
109
  }
110
110
  else {
111
111
  // Update existing job or insert new one
112
112
  sql = `
113
- INSERT INTO ${targetTable} (id, key, status)
114
- VALUES (gen_random_uuid(), $1, $2)
113
+ INSERT INTO ${targetTable} (id, key, status, entity)
114
+ VALUES (gen_random_uuid(), $1, $2, $3)
115
115
  ON CONFLICT (key) WHERE is_live DO UPDATE SET status = EXCLUDED.status
116
116
  RETURNING 1 as count
117
117
  `;
118
- params.push(key, fields[':']);
118
+ params.push(key, fields[':'], options?.entity ?? null);
119
119
  }
120
120
  }
121
121
  else if (isJobsTable && '@context' in fields) {