@hotmeshio/hotmesh 0.0.52 → 0.0.54

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 (134) hide show
  1. package/README.md +22 -18
  2. package/build/index.d.ts +1 -2
  3. package/build/index.js +1 -3
  4. package/build/modules/enums.d.ts +8 -3
  5. package/build/modules/enums.js +16 -8
  6. package/build/modules/errors.d.ts +58 -20
  7. package/build/modules/errors.js +90 -33
  8. package/build/package.json +7 -2
  9. package/build/services/activities/activity.d.ts +8 -0
  10. package/build/services/activities/activity.js +63 -14
  11. package/build/services/activities/await.js +6 -6
  12. package/build/services/activities/cycle.d.ts +2 -2
  13. package/build/services/activities/cycle.js +5 -5
  14. package/build/services/activities/hook.js +9 -5
  15. package/build/services/activities/interrupt.d.ts +3 -3
  16. package/build/services/activities/interrupt.js +15 -6
  17. package/build/services/activities/signal.d.ts +2 -2
  18. package/build/services/activities/signal.js +4 -4
  19. package/build/services/activities/trigger.d.ts +5 -2
  20. package/build/services/activities/trigger.js +34 -4
  21. package/build/services/activities/worker.js +6 -6
  22. package/build/services/compiler/deployer.js +33 -5
  23. package/build/services/compiler/validator.d.ts +2 -0
  24. package/build/services/compiler/validator.js +5 -1
  25. package/build/services/durable/client.d.ts +7 -1
  26. package/build/services/durable/client.js +57 -38
  27. package/build/services/durable/exporter.d.ts +27 -81
  28. package/build/services/durable/exporter.js +153 -325
  29. package/build/services/durable/handle.d.ts +13 -8
  30. package/build/services/durable/handle.js +61 -48
  31. package/build/services/durable/index.d.ts +0 -2
  32. package/build/services/durable/index.js +0 -2
  33. package/build/services/durable/schemas/factory.d.ts +33 -0
  34. package/build/services/durable/schemas/factory.js +2356 -0
  35. package/build/services/durable/search.js +8 -8
  36. package/build/services/durable/worker.js +117 -25
  37. package/build/services/durable/workflow.d.ts +67 -52
  38. package/build/services/durable/workflow.js +322 -306
  39. package/build/services/engine/index.d.ts +2 -2
  40. package/build/services/engine/index.js +5 -2
  41. package/build/services/exporter/index.d.ts +2 -4
  42. package/build/services/exporter/index.js +4 -5
  43. package/build/services/hotmesh/index.d.ts +2 -2
  44. package/build/services/hotmesh/index.js +2 -2
  45. package/build/services/mapper/index.d.ts +6 -2
  46. package/build/services/mapper/index.js +6 -2
  47. package/build/services/pipe/functions/array.d.ts +2 -10
  48. package/build/services/pipe/functions/array.js +30 -28
  49. package/build/services/pipe/functions/conditional.d.ts +1 -0
  50. package/build/services/pipe/functions/conditional.js +3 -0
  51. package/build/services/pipe/functions/date.d.ts +1 -0
  52. package/build/services/pipe/functions/date.js +4 -0
  53. package/build/services/pipe/functions/index.d.ts +2 -0
  54. package/build/services/pipe/functions/index.js +2 -0
  55. package/build/services/pipe/functions/logical.d.ts +5 -0
  56. package/build/services/pipe/functions/logical.js +12 -0
  57. package/build/services/pipe/functions/object.d.ts +3 -0
  58. package/build/services/pipe/functions/object.js +25 -7
  59. package/build/services/pipe/index.d.ts +20 -3
  60. package/build/services/pipe/index.js +82 -16
  61. package/build/services/router/index.js +14 -3
  62. package/build/services/serializer/index.d.ts +3 -2
  63. package/build/services/serializer/index.js +11 -4
  64. package/build/services/store/clients/ioredis.js +6 -6
  65. package/build/services/store/clients/redis.js +7 -7
  66. package/build/services/store/index.d.ts +2 -0
  67. package/build/services/store/index.js +4 -1
  68. package/build/services/stream/clients/ioredis.js +8 -8
  69. package/build/services/stream/clients/redis.js +1 -1
  70. package/build/types/activity.d.ts +60 -5
  71. package/build/types/durable.d.ts +183 -36
  72. package/build/types/error.d.ts +48 -0
  73. package/build/types/error.js +2 -0
  74. package/build/types/exporter.d.ts +35 -7
  75. package/build/types/index.d.ts +4 -3
  76. package/build/types/job.d.ts +93 -6
  77. package/build/types/pipe.d.ts +81 -3
  78. package/build/types/stream.d.ts +61 -1
  79. package/build/types/stream.js +4 -0
  80. package/index.ts +1 -2
  81. package/modules/enums.ts +16 -8
  82. package/modules/errors.ts +139 -34
  83. package/package.json +7 -2
  84. package/services/activities/activity.ts +63 -14
  85. package/services/activities/await.ts +6 -6
  86. package/services/activities/cycle.ts +7 -6
  87. package/services/activities/hook.ts +12 -5
  88. package/services/activities/interrupt.ts +19 -9
  89. package/services/activities/signal.ts +6 -5
  90. package/services/activities/trigger.ts +43 -6
  91. package/services/activities/worker.ts +7 -7
  92. package/services/compiler/deployer.ts +33 -6
  93. package/services/compiler/validator.ts +7 -3
  94. package/services/durable/client.ts +49 -22
  95. package/services/durable/exporter.ts +162 -349
  96. package/services/durable/handle.ts +66 -53
  97. package/services/durable/index.ts +0 -2
  98. package/services/durable/schemas/factory.ts +2358 -0
  99. package/services/durable/search.ts +8 -8
  100. package/services/durable/worker.ts +128 -29
  101. package/services/durable/workflow.ts +371 -322
  102. package/services/engine/index.ts +8 -3
  103. package/services/exporter/index.ts +10 -12
  104. package/services/hotmesh/index.ts +4 -3
  105. package/services/mapper/index.ts +6 -2
  106. package/services/pipe/functions/array.ts +24 -37
  107. package/services/pipe/functions/conditional.ts +4 -0
  108. package/services/pipe/functions/date.ts +6 -0
  109. package/services/pipe/functions/index.ts +7 -5
  110. package/services/pipe/functions/logical.ts +11 -0
  111. package/services/pipe/functions/object.ts +26 -7
  112. package/services/pipe/index.ts +99 -21
  113. package/services/quorum/index.ts +1 -3
  114. package/services/router/index.ts +14 -3
  115. package/services/serializer/index.ts +12 -5
  116. package/services/store/clients/ioredis.ts +6 -6
  117. package/services/store/clients/redis.ts +7 -7
  118. package/services/store/index.ts +4 -1
  119. package/services/stream/clients/ioredis.ts +8 -8
  120. package/services/stream/clients/redis.ts +1 -1
  121. package/types/activity.ts +87 -15
  122. package/types/durable.ts +263 -75
  123. package/types/error.ts +52 -0
  124. package/types/exporter.ts +43 -9
  125. package/types/index.ts +14 -8
  126. package/types/job.ts +157 -36
  127. package/types/pipe.ts +84 -3
  128. package/types/stream.ts +82 -23
  129. package/build/services/durable/factory.d.ts +0 -17
  130. package/build/services/durable/factory.js +0 -817
  131. package/build/services/durable/meshos.d.ts +0 -127
  132. package/build/services/durable/meshos.js +0 -380
  133. package/services/durable/factory.ts +0 -818
  134. package/services/durable/meshos.ts +0 -441
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.WorkflowHandleService = void 0;
4
- const enums_1 = require("../../modules/enums");
5
4
  const exporter_1 = require("./exporter");
6
5
  class WorkflowHandleService {
7
6
  constructor(hotMesh, workflowTopic, workflowId) {
@@ -10,14 +9,14 @@ class WorkflowHandleService {
10
9
  this.hotMesh = hotMesh;
11
10
  this.exporter = new exporter_1.ExporterService(this.hotMesh.appId, this.hotMesh.engine.store, this.hotMesh.engine.logger);
12
11
  }
13
- async export() {
14
- return this.exporter.export(this.workflowId);
12
+ async export(options) {
13
+ return this.exporter.export(this.workflowId, options);
15
14
  }
16
15
  /**
17
16
  * Sends a signal to the workflow. This is a way to send
18
17
  * a message to a workflow that is paused due to having
19
- * executed a `waitForSignal` workflow extension. Awakens
20
- * the workflow if no other signals are pending.
18
+ * executed `Durable.workflow.waitFor`. The workflow
19
+ * will awaken if no other signals are pending.
21
20
  */
22
21
  async signal(signalId, data) {
23
22
  await this.hotMesh.hook(`${this.hotMesh.appId}.wfs.signal`, { id: signalId, data });
@@ -63,68 +62,82 @@ class WorkflowHandleService {
63
62
  return await this.hotMesh.interrupt(`${this.hotMesh.appId}.execute`, this.workflowId, options);
64
63
  }
65
64
  /**
66
- * Awaits for the workflow to complete and returns the result. If
67
- * the workflow thows and error, this method will likewise throw
68
- * an error.
65
+ * Waits for the workflow to complete and returns the result. If
66
+ * the workflow response includes an error, this method will rethrow
67
+ * the error, including the stack trace if available.
68
+ * Wrap calls in a try/catch as necessary to avoid unhandled exceptions.
69
69
  */
70
- async result(loadState) {
71
- if (loadState) {
72
- const state = await this.hotMesh.getState(`${this.hotMesh.appId}.execute`, this.workflowId);
73
- if (!state.data && state.metadata.err) {
74
- throw new Error(JSON.parse(state.metadata.err));
75
- }
76
- if (state?.data?.done) {
77
- //child flows are never 'done'; they use a hook
78
- //that only closes upon parent flow completion.
79
- return state.data.response;
80
- }
81
- }
82
- let status = await this.hotMesh.getStatus(this.workflowId);
70
+ async result(config) {
83
71
  const topic = `${this.hotMesh.appId}.executed.${this.workflowId}`;
84
- return new Promise((resolve, reject) => {
85
- let isResolved = false;
86
- //common fulfill/unsubscribe
72
+ let isResolved = false;
73
+ return new Promise(async (resolve, reject) => {
74
+ /**
75
+ * rejects/resolves the promise based on the `throwOnError`
76
+ * default behavior is to throw if error
77
+ */
78
+ const safeReject = (err) => {
79
+ if (config?.throwOnError === false) {
80
+ return resolve(err);
81
+ }
82
+ reject(err);
83
+ };
84
+ /**
85
+ * Common completion function that unsubscribes from the topic/returns
86
+ */
87
87
  const complete = async (response, err) => {
88
88
  if (isResolved)
89
89
  return;
90
90
  isResolved = true;
91
- this.hotMesh.unsub(topic);
92
91
  if (err) {
93
- return reject(JSON.parse(err));
92
+ return safeReject(err);
94
93
  }
95
94
  else if (!response) {
96
95
  const state = await this.hotMesh.getState(`${this.hotMesh.appId}.execute`, this.workflowId);
97
- if (state.metadata.err) {
98
- const error = JSON.parse(state.metadata.err);
99
- if (error.code === enums_1.HMSH_CODE_INTERRUPT || !state.data) {
100
- return reject({ ...error, job_id: this.workflowId });
101
- }
96
+ if (state.data?.done && !state.data?.$error) {
97
+ return resolve(state.data.response);
98
+ }
99
+ else if (state.data?.$error) {
100
+ return safeReject(state.data.$error);
101
+ }
102
+ else if (state.metadata.err) {
103
+ return safeReject(JSON.parse(state.metadata.err));
102
104
  }
103
105
  response = state.data?.response;
104
106
  }
105
107
  resolve(response);
106
108
  };
107
- //check for done
108
- if (status <= 0) {
109
- return complete();
109
+ //more expensive; fetches the entire job, not just the `status`
110
+ if (config?.state) {
111
+ const state = await this.hotMesh.getState(`${this.hotMesh.appId}.execute`, this.workflowId);
112
+ if (state?.data?.done && !state.data?.$error) {
113
+ return complete(state.data.response);
114
+ }
115
+ else if (state.data?.$error) {
116
+ return complete(null, state.data.$error);
117
+ }
118
+ else if (state.metadata.err) {
119
+ return complete(null, JSON.parse(state.metadata.err));
120
+ }
110
121
  }
111
- //subscribe to topic
112
- this.hotMesh.sub(topic, async (topic, state) => {
113
- if (state.metadata.err) {
122
+ //subscribe to 'done' topic
123
+ this.hotMesh.sub(topic, async (_topic, state) => {
124
+ this.hotMesh.unsub(topic);
125
+ if (state.data.done && !state.data?.$error) {
126
+ await complete(state.data?.response);
127
+ }
128
+ else if (state.data?.$error) {
129
+ return complete(null, state.data.$error);
130
+ }
131
+ else if (state.metadata.err) {
114
132
  const error = JSON.parse(state.metadata.err);
115
- if (error.code === enums_1.HMSH_CODE_INTERRUPT || !state.data) {
116
- return await complete(null, state.metadata.err);
117
- }
133
+ return await complete(null, error);
118
134
  }
119
- await complete(state.data?.response);
120
135
  });
121
- //resolve for race condition
122
- setTimeout(async () => {
123
- status = await this.hotMesh.getStatus(this.workflowId);
124
- if (status <= 0) {
125
- await complete();
126
- }
127
- }, 0);
136
+ //check state in case completed during wiring
137
+ const status = await this.hotMesh.getStatus(this.workflowId);
138
+ if (status <= 0) {
139
+ await complete();
140
+ }
128
141
  });
129
142
  }
130
143
  }
@@ -1,6 +1,5 @@
1
1
  import { ClientService } from './client';
2
2
  import { ConnectionService } from './connection';
3
- import { MeshOSService } from './meshos';
4
3
  import { Search } from './search';
5
4
  import { WorkerService } from './worker';
6
5
  import { WorkflowService } from './workflow';
@@ -9,7 +8,6 @@ export declare const Durable: {
9
8
  Client: typeof ClientService;
10
9
  Connection: typeof ConnectionService;
11
10
  Search: typeof Search;
12
- MeshOS: typeof MeshOSService;
13
11
  Worker: typeof WorkerService;
14
12
  workflow: typeof WorkflowService;
15
13
  /**
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Durable = void 0;
4
4
  const client_1 = require("./client");
5
5
  const connection_1 = require("./connection");
6
- const meshos_1 = require("./meshos");
7
6
  const search_1 = require("./search");
8
7
  const worker_1 = require("./worker");
9
8
  const workflow_1 = require("./workflow");
@@ -12,7 +11,6 @@ exports.Durable = {
12
11
  Client: client_1.ClientService,
13
12
  Connection: connection_1.ConnectionService,
14
13
  Search: search_1.Search,
15
- MeshOS: meshos_1.MeshOSService,
16
14
  Worker: worker_1.WorkerService,
17
15
  workflow: workflow_1.WorkflowService,
18
16
  /**
@@ -0,0 +1,33 @@
1
+ /**
2
+ *********** HOTMESH 'DURABLE' MODULE APPLICATION GRAPH **********
3
+ *
4
+ * This HotMesh application spec uses 50 activities and 25 transitions
5
+ * to model and emulate the Temporal Application & Query servers using
6
+ * Redis as the backend.
7
+ *
8
+ * It's particularly useful for organizations with high-speed, high-volume
9
+ * use cases as it uses in-memory Redis Streams for transactional,
10
+ * workflow processing, while adhering to Temporal's developer-friendly syntax.
11
+ *
12
+ * This YAML file can also serve as a useful starting point for building
13
+ * Integration/BPM/Workflow servers in general (MuleSoft, etc) without the need
14
+ * for a physical application server.
15
+ *
16
+ * Possible use cases include:
17
+ * * Orchestration servers
18
+ * * Integration servers
19
+ * * BPMN engines
20
+ * * Reentrant process servers
21
+ * * Service Meshes
22
+ * * Master Data Management systems
23
+ */
24
+ declare const APP_VERSION = "1";
25
+ declare const APP_ID = "durable";
26
+ /**
27
+ * returns a new durable workflow schema
28
+ * @param {string} app - app name (e.g., 'durable')
29
+ * @param {string} version - number as string (e.g., '1')
30
+ * @returns {string} HotMesh App YAML
31
+ */
32
+ declare const getWorkflowYAML: (app: string, version: string) => string;
33
+ export { getWorkflowYAML, APP_VERSION, APP_ID, };