@hotmeshio/hotmesh 0.1.6 → 0.1.8

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 CHANGED
@@ -295,31 +295,31 @@ const hotMesh = await HotMesh.init({
295
295
  ```
296
296
 
297
297
  ### Observability
298
- Workflows and activities are run according to the rules you define, offering [Graph-Oriented](https://github.com/hotmeshio/sdk-typescript/blob/main/docs/system_lifecycle.md#telemetry) telemetry insights into your legacy function executions.
298
+ Workflows and activities are run according to the rules you define, offering [Graph-Oriented](https://github.com/hotmeshio/sdk-typescript/tree/main/docs/system_lifecycle.md#telemetry) telemetry insights into your legacy function executions.
299
299
 
300
300
  ## FAQ
301
- Refer to the [FAQ](https://github.com/hotmeshio/sdk-typescript/blob/main/docs/faq.md) for terminology, definitions, and an exploration of how HotMesh facilitates orchestration use cases.
301
+ Refer to the [FAQ](https://github.com/hotmeshio/sdk-typescript/tree/main/docs/faq.md) for terminology, definitions, and an exploration of how HotMesh facilitates orchestration use cases.
302
302
 
303
303
  ## Quick Start
304
- Refer to the [Quick Start](https://github.com/hotmeshio/sdk-typescript/blob/main/docs/quickstart.md) for sample YAML workflows you can copy, paste, and modify to get started.
304
+ Refer to the [Quick Start](https://github.com/hotmeshio/sdk-typescript/tree/main/docs/quickstart.md) for sample YAML workflows you can copy, paste, and modify to get started.
305
305
 
306
306
  ## Developer Guide
307
- For more details on the complete development process, including information about schemas, APIs, and deployment, consult the [Developer Guide](https://github.com/hotmeshio/sdk-typescript/blob/main/docs/developer_guide.md).
307
+ For more details on the complete development process, including information about schemas, APIs, and deployment, consult the [Developer Guide](https://github.com/hotmeshio/sdk-typescript/tree/main/docs/developer_guide.md).
308
308
 
309
309
  ## Model Driven Development
310
- [Model Driven Development](https://github.com/hotmeshio/sdk-typescript/blob/main/docs/model_driven_development.md) is an established strategy for managing process-oriented tasks. Check out this guide to understand its foundational principles.
310
+ [Model Driven Development](https://github.com/hotmeshio/sdk-typescript/tree/main/docs/model_driven_development.md) is an established strategy for managing process-oriented tasks. Check out this guide to understand its foundational principles.
311
311
 
312
312
  ## Data Mapping
313
- Exchanging data between activities is central to HotMesh. For detailed information on supported functions and the functional mapping syntax (@pipes), see the [Data Mapping Overview](https://github.com/hotmeshio/sdk-typescript/blob/main/docs/data_mapping.md).
313
+ Exchanging data between activities is central to HotMesh. For detailed information on supported functions and the functional mapping syntax (@pipes), see the [Data Mapping Overview](https://github.com/hotmeshio/sdk-typescript/tree/main/docs/data_mapping.md).
314
314
 
315
315
  ## Composition
316
- While the simplest graphs are linear, detailing a consistent sequence of non-cyclical activities, graphs can be layered to represent intricate business scenarios. Some can even be designed to accommodate long-lasting workflows that span months. For more details, check out the [Composable Workflow Guide](https://github.com/hotmeshio/sdk-typescript/blob/main/docs/composable_workflow.md).
316
+ While the simplest graphs are linear, detailing a consistent sequence of non-cyclical activities, graphs can be layered to represent intricate business scenarios. Some can even be designed to accommodate long-lasting workflows that span months. For more details, check out the [Composable Workflow Guide](https://github.com/hotmeshio/sdk-typescript/tree/main/docs/composable_workflow.md).
317
317
 
318
318
  ## System Lifecycle
319
- Gain insight into HotMesh's monitoring, exception handling, and alarm configurations via the [System Lifecycle Guide](https://github.com/hotmeshio/sdk-typescript/blob/main/docs/system_lifecycle.md).
319
+ Gain insight into HotMesh's monitoring, exception handling, and alarm configurations via the [System Lifecycle Guide](https://github.com/hotmeshio/sdk-typescript/tree/main/docs/system_lifecycle.md).
320
320
 
321
321
  ## Distributed Orchestration | System Overview
322
- HotMesh is a distributed orchestration engine. Refer to the [Distributed Orchestration Guide](https://github.com/hotmeshio/sdk-typescript/blob/main/docs/distributed_orchestration.md) for a high-level overview of the approach.
322
+ HotMesh is a distributed orchestration engine. Refer to the [Distributed Orchestration Guide](https://github.com/hotmeshio/sdk-typescript/tree/main/docs/distributed_orchestration.md) for a high-level overview of the approach.
323
323
 
324
324
  ## Distributed Orchestration | System Design
325
325
  HotMesh is more than Redis and TypeScript. The theory that underlies the architecture is applicable to any number of data storage and streaming backends: [A Message-Oriented Approach to Decentralized Process Orchestration](https://zenodo.org/records/12168558).
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hotmeshio/hotmesh",
3
- "version": "0.1.6",
3
+ "version": "0.1.8",
4
4
  "description": "Unbreakable Workflows",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",
@@ -41,7 +41,7 @@
41
41
  "test:durable:signal": "NODE_ENV=test jest ./tests/durable/signal/index.test.ts --detectOpenHandles --forceExit --verbose",
42
42
  "test:durable:unknown": "NODE_ENV=test jest ./tests/durable/unknown/index.test.ts --detectOpenHandles --forceExit --verbose",
43
43
  "test:emit": "NODE_ENV=test jest ./tests/functional/emit/index.test.ts --detectOpenHandles --forceExit --verbose",
44
- "test:expired": "NODE_ENV=test jest ./tests/functional/expired/index.test.ts --detectOpenHandles --forceExit --verbose",
44
+ "test:pending": "NODE_ENV=test jest ./tests/functional/pending/index.test.ts --detectOpenHandles --forceExit --verbose",
45
45
  "test:functional": "NODE_ENV=test jest ./tests/functional/*/index.test.ts --detectOpenHandles --forceExit --verbose",
46
46
  "test:hmsh": "NODE_ENV=test jest ./tests/functional/index.test.ts --detectOpenHandles --verbose",
47
47
  "test:hook": "NODE_ENV=test jest ./tests/functional/hook/index.test.ts --detectOpenHandles --forceExit --verbose",
@@ -25,16 +25,16 @@ class Trigger extends activity_1.Activity {
25
25
  telemetry.startJobSpan();
26
26
  telemetry.startActivitySpan(this.leg);
27
27
  this.mapJobData();
28
- await this.setStateNX(options?.expired ? -1 : undefined);
28
+ await this.setStateNX(options?.pending ? -1 : undefined);
29
29
  this.adjacencyList = await this.filterAdjacent();
30
- await this.setStatus(options?.expired ? -1 : this.adjacencyList.length);
30
+ await this.setStatus(options?.pending ? -1 : this.adjacencyList.length);
31
31
  this.bindSearchData(options);
32
32
  this.bindMarkerData(options);
33
33
  const multi = this.store.getMulti();
34
34
  await this.setState(multi);
35
35
  await this.setStats(multi);
36
- if (options?.expired) {
37
- await this.setExpired(options?.expired, multi);
36
+ if (options?.pending) {
37
+ await this.setExpired(options?.pending, multi);
38
38
  }
39
39
  else {
40
40
  await this.registerJobDependency(multi);
@@ -47,8 +47,7 @@ class Trigger extends activity_1.Activity {
47
47
  const jobStatus = Number(this.context.metadata.js);
48
48
  telemetry.setJobAttributes({ 'app.job.jss': jobStatus });
49
49
  const attrs = { 'app.job.jss': jobStatus };
50
- //only transition if not inited in an expired state
51
- //todo: enable resume from expired state
50
+ //todo: enable resume from pending state
52
51
  if (jobStatus !== -1) {
53
52
  const messageIds = await this.transition(this.adjacencyList, jobStatus);
54
53
  if (messageIds.length) {
@@ -19,10 +19,11 @@ class ClientService {
19
19
  this.getHotMeshClient = async (workflowTopic, namespace) => {
20
20
  const targetNS = namespace ?? factory_1.APP_ID;
21
21
  if (ClientService.instances.has(targetNS)) {
22
+ const targetTopic = `${namespace ?? factory_1.APP_ID}.${workflowTopic}`;
22
23
  const hotMeshClient = await ClientService.instances.get(targetNS);
23
24
  await this.verifyWorkflowActive(hotMeshClient, targetNS);
24
- if (!ClientService.topics.includes(workflowTopic)) {
25
- ClientService.topics.push(workflowTopic);
25
+ if (!ClientService.topics.includes(targetTopic)) {
26
+ ClientService.topics.push(targetTopic);
26
27
  await ClientService.createStream(hotMeshClient, workflowTopic, namespace);
27
28
  }
28
29
  return hotMeshClient;
@@ -76,7 +77,7 @@ class ClientService {
76
77
  const jobId = await hotMeshClient.pub(`${options.namespace ?? factory_1.APP_ID}.execute`, payload, context, {
77
78
  search: options?.search?.data,
78
79
  marker: options?.marker,
79
- expired: options?.expired,
80
+ pending: options?.pending,
80
81
  });
81
82
  return new handle_1.WorkflowHandleService(hotMeshClient, workflowTopic, jobId);
82
83
  },
@@ -205,11 +206,12 @@ ClientService.createStream = async (hotMeshClient, workflowTopic, namespace) =>
205
206
  * exists and if not, create it.
206
207
  */
207
208
  ClientService.verifyStream = async (workflowTopic, namespace) => {
209
+ const targetTopic = `${namespace ?? factory_1.APP_ID}.${workflowTopic}`;
208
210
  const targetNS = namespace ?? factory_1.APP_ID;
209
211
  if (ClientService.instances.has(targetNS)) {
210
212
  const hotMeshClient = await ClientService.instances.get(targetNS);
211
- if (!ClientService.topics.includes(workflowTopic)) {
212
- ClientService.topics.push(workflowTopic);
213
+ if (!ClientService.topics.includes(targetTopic)) {
214
+ ClientService.topics.push(targetTopic);
213
215
  await ClientService.createStream(hotMeshClient, workflowTopic, namespace);
214
216
  }
215
217
  return hotMeshClient;
@@ -40,23 +40,23 @@ class ExporterService {
40
40
  //transitions
41
41
  this.inflateTransition(match, value, transitionsObject);
42
42
  }
43
- else if (key.length === 3) {
44
- //state
45
- state[this.inflateKey(key)] = serializer_1.SerializerService.fromString(value);
46
- }
47
43
  else if (key.startsWith('_')) {
48
44
  //data
49
45
  data[key.substring(1)] = value;
50
46
  }
51
47
  else if (key.startsWith('-')) {
52
48
  //timeline
53
- const keyParts = this.keyToObject(key); //key parts have meaning
49
+ const keyParts = this.keyToObject(key);
54
50
  timeline.push({
55
51
  ...keyParts,
56
52
  key,
57
53
  value: this.resolveValue(value, options.values),
58
54
  });
59
55
  }
56
+ else if (key.length === 3) {
57
+ //state
58
+ state[this.inflateKey(key)] = serializer_1.SerializerService.fromString(value);
59
+ }
60
60
  });
61
61
  return this.filterFields({
62
62
  data: (0, utils_1.restoreHierarchy)(data),
@@ -2,11 +2,12 @@ import { HotMeshService as HotMesh } from '../hotmesh';
2
2
  import { Connection, Registry, WorkerConfig, WorkerOptions } from '../../types/durable';
3
3
  export declare class WorkerService {
4
4
  static activityRegistry: Registry;
5
- static connection: Connection;
5
+ static connections: Map<string, import("../../types/durable").ConnectionConfig>;
6
6
  static instances: Map<string, HotMesh | Promise<HotMesh>>;
7
7
  workflowRunner: HotMesh;
8
8
  activityRunner: HotMesh;
9
9
  static getHotMesh: (workflowTopic: string, config?: Partial<WorkerConfig>, options?: WorkerOptions) => Promise<HotMesh>;
10
+ static findConnectionByNamespace: (namespace: string) => Connection;
10
11
  static activateWorkflow(hotMesh: HotMesh): Promise<void>;
11
12
  static registerActivities<ACT>(activities: ACT): Registry;
12
13
  static create(config: WorkerConfig): Promise<WorkerService>;
@@ -58,7 +58,8 @@ class WorkerService {
58
58
  return WorkerService.activityRegistry;
59
59
  }
60
60
  static async create(config) {
61
- WorkerService.connection = config.connection;
61
+ const targetNamespace = config.namespace ?? factory_1.APP_ID;
62
+ WorkerService.connections.set(targetNamespace, config.connection);
62
63
  const workflow = config.workflow;
63
64
  const [workflowFunctionName, workflowFunction] = WorkerService.resolveWorkflowTarget(workflow);
64
65
  const baseTopic = `${config.taskQueue}-${workflowFunctionName}`;
@@ -371,20 +372,37 @@ class WorkerService {
371
372
  }
372
373
  _a = WorkerService;
373
374
  WorkerService.activityRegistry = {}; //user's activities
375
+ WorkerService.connections = new Map();
374
376
  WorkerService.instances = new Map();
375
377
  WorkerService.getHotMesh = async (workflowTopic, config, options) => {
376
- if (WorkerService.instances.has(workflowTopic)) {
377
- return await WorkerService.instances.get(workflowTopic);
378
+ const targetNamespace = config?.namespace ?? factory_1.APP_ID;
379
+ const targetTopic = `${targetNamespace}.${workflowTopic}`;
380
+ if (WorkerService.instances.has(targetTopic)) {
381
+ return await WorkerService.instances.get(targetTopic);
378
382
  }
379
383
  const hotMeshClient = hotmesh_1.HotMeshService.init({
380
384
  logLevel: options?.logLevel ?? enums_1.HMSH_LOGLEVEL,
381
- appId: config.namespace ?? factory_1.APP_ID,
382
- engine: { redis: { ...WorkerService.connection } },
385
+ appId: targetNamespace,
386
+ engine: {
387
+ redis: { ...WorkerService.findConnectionByNamespace(targetNamespace) },
388
+ },
383
389
  });
384
- WorkerService.instances.set(workflowTopic, hotMeshClient);
390
+ WorkerService.instances.set(targetTopic, hotMeshClient);
385
391
  await WorkerService.activateWorkflow(await hotMeshClient);
386
392
  return hotMeshClient;
387
393
  };
394
+ WorkerService.findConnectionByNamespace = (namespace) => {
395
+ let defaultConnection;
396
+ for (const [ns, value] of WorkerService.connections) {
397
+ if (ns === namespace) {
398
+ return value;
399
+ }
400
+ else if (!defaultConnection) {
401
+ defaultConnection = value;
402
+ }
403
+ }
404
+ return defaultConnection;
405
+ };
388
406
  WorkerService.Context = {
389
407
  info: () => {
390
408
  return {
@@ -261,16 +261,16 @@ type WorkflowOptions = {
261
261
  */
262
262
  await?: boolean;
263
263
  /**
264
- * If provided, the job will initialize in an expired state, reserving
264
+ * If provided, the job will initialize in a pending state, reserving
265
265
  * only the job ID (HSETNX) and persisting search and marker (if provided).
266
266
  * If a `resume` signal is sent before the specified number of seconds,
267
- * the job will resume as normal, transition to the adjacent children
267
+ * the job will resume as normal, transitioning to the adjacent children
268
268
  * of the trigger. If the job is not resumed within the number
269
269
  * of seconds specified, the job will be scrubbed. No dependencies
270
- * are added for a job in an expired state; however, dependencies
270
+ * are added for a job in a pending state; however, dependencies
271
271
  * will be added after the job is resumed if relevant.
272
272
  */
273
- expired?: number;
273
+ pending?: number;
274
274
  };
275
275
  /**
276
276
  * Options for setting up a hook.
@@ -7,7 +7,7 @@ export { ActivityConfig, ActivityWorkflowDataType, ChildResponseType, ClientConf
7
7
  export { DurableChildErrorType, DurableProxyErrorType, DurableSleepErrorType, DurableWaitForAllErrorType, DurableWaitForErrorType, } from './error';
8
8
  export { ActivityAction, DependencyExport, DurableJobExport, ExportCycles, ExportItem, ExportOptions, ExportTransitions, JobAction, JobExport, JobActionExport, JobTimeline, } from './exporter';
9
9
  export { HookCondition, HookConditions, HookGate, HookInterface, HookRule, HookRules, HookSignal, } from './hook';
10
- export { ILogger } from './logger';
10
+ export { ILogger, LogLevel, } from './logger';
11
11
  export { ExtensionType, JobCompletionOptions, JobData, JobsData, JobInterruptOptions, JobMetadata, JobOutput, JobState, JobStatus, PartialJobState, } from './job';
12
12
  export { MappingStatements } from './map';
13
13
  export { Pipe, PipeContext, PipeItem, PipeItems, PipeObject, ReduceObject, } from './pipe';
@@ -78,16 +78,16 @@ type ExtensionType = {
78
78
  */
79
79
  marker?: StringStringType;
80
80
  /**
81
- * If provided, the job will initialize in an expired state, reserving
81
+ * If provided, the job will initialize in a pending state, reserving
82
82
  * only the job ID (HSETNX) and persisting search and marker (if provided).
83
83
  * If a `resume` signal is sent before the specified number of seconds,
84
- * the job will resume as normal, transition the the adjacent children
85
- * of the trigger. If the job is not resumed within the
86
- * number of seconds specified, the job will be scrubbed. No dependencies
87
- * are added for a job in an expired state; however, dependencies will be
88
- * added after the job is resumed if relevant.
84
+ * the job will resume as normal, transitioning to the adjacent children
85
+ * of the trigger. If the job is not resumed within the number
86
+ * of seconds specified, the job will be scrubbed. No dependencies
87
+ * are added for a job in a pending state; however, dependencies
88
+ * will be added after the job is resumed if relevant.
89
89
  */
90
- expired?: number;
90
+ pending?: number;
91
91
  };
92
92
  /**
93
93
  * job_status semaphore
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hotmeshio/hotmesh",
3
- "version": "0.1.6",
3
+ "version": "0.1.8",
4
4
  "description": "Unbreakable Workflows",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",
@@ -41,7 +41,7 @@
41
41
  "test:durable:signal": "NODE_ENV=test jest ./tests/durable/signal/index.test.ts --detectOpenHandles --forceExit --verbose",
42
42
  "test:durable:unknown": "NODE_ENV=test jest ./tests/durable/unknown/index.test.ts --detectOpenHandles --forceExit --verbose",
43
43
  "test:emit": "NODE_ENV=test jest ./tests/functional/emit/index.test.ts --detectOpenHandles --forceExit --verbose",
44
- "test:expired": "NODE_ENV=test jest ./tests/functional/expired/index.test.ts --detectOpenHandles --forceExit --verbose",
44
+ "test:pending": "NODE_ENV=test jest ./tests/functional/pending/index.test.ts --detectOpenHandles --forceExit --verbose",
45
45
  "test:functional": "NODE_ENV=test jest ./tests/functional/*/index.test.ts --detectOpenHandles --forceExit --verbose",
46
46
  "test:hmsh": "NODE_ENV=test jest ./tests/functional/index.test.ts --detectOpenHandles --verbose",
47
47
  "test:hook": "NODE_ENV=test jest ./tests/functional/hook/index.test.ts --detectOpenHandles --forceExit --verbose",
package/types/durable.ts CHANGED
@@ -315,16 +315,16 @@ type WorkflowOptions = {
315
315
  await?: boolean;
316
316
 
317
317
  /**
318
- * If provided, the job will initialize in an expired state, reserving
318
+ * If provided, the job will initialize in a pending state, reserving
319
319
  * only the job ID (HSETNX) and persisting search and marker (if provided).
320
320
  * If a `resume` signal is sent before the specified number of seconds,
321
- * the job will resume as normal, transition to the adjacent children
321
+ * the job will resume as normal, transitioning to the adjacent children
322
322
  * of the trigger. If the job is not resumed within the number
323
323
  * of seconds specified, the job will be scrubbed. No dependencies
324
- * are added for a job in an expired state; however, dependencies
324
+ * are added for a job in a pending state; however, dependencies
325
325
  * will be added after the job is resumed if relevant.
326
326
  */
327
- expired?: number;
327
+ pending?: number;
328
328
  };
329
329
 
330
330
  /**
package/types/index.ts CHANGED
@@ -77,7 +77,10 @@ export {
77
77
  HookRules,
78
78
  HookSignal,
79
79
  } from './hook';
80
- export { ILogger } from './logger';
80
+ export {
81
+ ILogger,
82
+ LogLevel,
83
+ } from './logger';
81
84
  export {
82
85
  ExtensionType,
83
86
  JobCompletionOptions,
package/types/job.ts CHANGED
@@ -108,16 +108,16 @@ type ExtensionType = {
108
108
  marker?: StringStringType;
109
109
 
110
110
  /**
111
- * If provided, the job will initialize in an expired state, reserving
111
+ * If provided, the job will initialize in a pending state, reserving
112
112
  * only the job ID (HSETNX) and persisting search and marker (if provided).
113
113
  * If a `resume` signal is sent before the specified number of seconds,
114
- * the job will resume as normal, transition the the adjacent children
115
- * of the trigger. If the job is not resumed within the
116
- * number of seconds specified, the job will be scrubbed. No dependencies
117
- * are added for a job in an expired state; however, dependencies will be
118
- * added after the job is resumed if relevant.
114
+ * the job will resume as normal, transitioning to the adjacent children
115
+ * of the trigger. If the job is not resumed within the number
116
+ * of seconds specified, the job will be scrubbed. No dependencies
117
+ * are added for a job in a pending state; however, dependencies
118
+ * will be added after the job is resumed if relevant.
119
119
  */
120
- expired?: number;
120
+ pending?: number;
121
121
  };
122
122
 
123
123
  /**