@hotmeshio/hotmesh 0.0.51 → 0.0.53
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 +13 -9
- package/build/index.d.ts +1 -2
- package/build/index.js +1 -3
- package/build/modules/enums.d.ts +8 -3
- package/build/modules/enums.js +16 -8
- package/build/modules/errors.d.ts +98 -18
- package/build/modules/errors.js +90 -33
- package/build/package.json +7 -2
- package/build/services/activities/activity.d.ts +8 -0
- package/build/services/activities/activity.js +65 -16
- package/build/services/activities/await.js +6 -6
- package/build/services/activities/cycle.d.ts +2 -2
- package/build/services/activities/cycle.js +5 -5
- package/build/services/activities/hook.js +4 -4
- package/build/services/activities/interrupt.d.ts +3 -3
- package/build/services/activities/interrupt.js +15 -6
- package/build/services/activities/signal.d.ts +2 -2
- package/build/services/activities/signal.js +4 -4
- package/build/services/activities/trigger.js +12 -3
- package/build/services/activities/worker.js +6 -6
- package/build/services/compiler/deployer.js +33 -5
- package/build/services/compiler/validator.d.ts +2 -0
- package/build/services/compiler/validator.js +5 -1
- package/build/services/durable/client.d.ts +7 -1
- package/build/services/durable/client.js +56 -30
- package/build/services/durable/exporter.d.ts +7 -72
- package/build/services/durable/exporter.js +105 -295
- package/build/services/durable/handle.d.ts +11 -6
- package/build/services/durable/handle.js +59 -46
- package/build/services/durable/index.d.ts +0 -2
- package/build/services/durable/index.js +0 -2
- package/build/services/durable/schemas/factory.d.ts +33 -0
- package/build/services/durable/schemas/factory.js +2356 -0
- package/build/services/durable/search.js +8 -8
- package/build/services/durable/worker.js +117 -25
- package/build/services/durable/workflow.d.ts +46 -43
- package/build/services/durable/workflow.js +273 -277
- package/build/services/engine/index.js +3 -0
- package/build/services/exporter/index.d.ts +2 -4
- package/build/services/exporter/index.js +4 -5
- package/build/services/mapper/index.d.ts +6 -2
- package/build/services/mapper/index.js +6 -2
- package/build/services/pipe/functions/array.d.ts +2 -10
- package/build/services/pipe/functions/array.js +30 -28
- package/build/services/pipe/functions/conditional.d.ts +1 -0
- package/build/services/pipe/functions/conditional.js +3 -0
- package/build/services/pipe/functions/date.d.ts +1 -0
- package/build/services/pipe/functions/date.js +4 -0
- package/build/services/pipe/functions/index.d.ts +2 -0
- package/build/services/pipe/functions/index.js +2 -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/object.d.ts +3 -0
- package/build/services/pipe/functions/object.js +25 -7
- package/build/services/pipe/index.d.ts +20 -3
- package/build/services/pipe/index.js +82 -16
- package/build/services/router/index.js +14 -3
- package/build/services/serializer/index.d.ts +3 -2
- package/build/services/serializer/index.js +11 -4
- package/build/services/store/clients/ioredis.js +6 -6
- package/build/services/store/clients/redis.js +7 -7
- package/build/services/store/index.d.ts +2 -0
- package/build/services/store/index.js +4 -1
- package/build/services/stream/clients/ioredis.js +8 -8
- package/build/services/stream/clients/redis.js +1 -1
- package/build/types/activity.d.ts +60 -5
- package/build/types/durable.d.ts +168 -33
- package/build/types/exporter.d.ts +26 -4
- package/build/types/index.d.ts +2 -2
- package/build/types/job.d.ts +69 -5
- package/build/types/pipe.d.ts +81 -3
- package/build/types/stream.d.ts +61 -1
- package/build/types/stream.js +4 -0
- package/index.ts +1 -2
- package/modules/enums.ts +16 -8
- package/modules/errors.ts +174 -32
- package/package.json +7 -2
- package/services/activities/activity.ts +67 -18
- package/services/activities/await.ts +6 -6
- package/services/activities/cycle.ts +7 -6
- package/services/activities/hook.ts +4 -4
- package/services/activities/interrupt.ts +19 -9
- package/services/activities/signal.ts +6 -5
- package/services/activities/trigger.ts +16 -4
- package/services/activities/worker.ts +7 -7
- package/services/compiler/deployer.ts +33 -6
- package/services/compiler/validator.ts +7 -3
- package/services/durable/client.ts +47 -14
- package/services/durable/exporter.ts +110 -318
- package/services/durable/handle.ts +63 -50
- package/services/durable/index.ts +0 -2
- package/services/durable/schemas/factory.ts +2358 -0
- package/services/durable/search.ts +8 -8
- package/services/durable/worker.ts +128 -29
- package/services/durable/workflow.ts +304 -288
- package/services/engine/index.ts +4 -0
- package/services/exporter/index.ts +10 -12
- package/services/mapper/index.ts +6 -2
- package/services/pipe/functions/array.ts +24 -37
- package/services/pipe/functions/conditional.ts +4 -0
- package/services/pipe/functions/date.ts +6 -0
- package/services/pipe/functions/index.ts +7 -5
- package/services/pipe/functions/logical.ts +11 -0
- package/services/pipe/functions/object.ts +26 -7
- package/services/pipe/index.ts +99 -21
- package/services/quorum/index.ts +1 -3
- package/services/router/index.ts +14 -3
- package/services/serializer/index.ts +12 -5
- package/services/store/clients/ioredis.ts +6 -6
- package/services/store/clients/redis.ts +7 -7
- package/services/store/index.ts +4 -1
- package/services/stream/clients/ioredis.ts +8 -8
- package/services/stream/clients/redis.ts +1 -1
- package/types/activity.ts +87 -15
- package/types/durable.ts +246 -73
- package/types/exporter.ts +31 -5
- package/types/index.ts +6 -7
- package/types/job.ts +130 -36
- package/types/pipe.ts +84 -3
- package/types/stream.ts +82 -23
- package/build/services/durable/factory.d.ts +0 -17
- package/build/services/durable/factory.js +0 -817
- package/build/services/durable/meshos.d.ts +0 -127
- package/build/services/durable/meshos.js +0 -380
- package/services/durable/factory.ts +0 -818
- package/services/durable/meshos.ts +0 -441
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { HMSH_CODE_INTERRUPT } from '../../modules/enums';
|
|
2
1
|
import { ExporterService } from './exporter';
|
|
3
2
|
import { HotMeshService as HotMesh } from '../hotmesh';
|
|
4
3
|
import { DurableJobExport } from '../../types/exporter';
|
|
@@ -29,8 +28,8 @@ export class WorkflowHandleService {
|
|
|
29
28
|
/**
|
|
30
29
|
* Sends a signal to the workflow. This is a way to send
|
|
31
30
|
* a message to a workflow that is paused due to having
|
|
32
|
-
* executed
|
|
33
|
-
*
|
|
31
|
+
* executed `Durable.workflow.waitFor`. The workflow
|
|
32
|
+
* will awaken if no other signals are pending.
|
|
34
33
|
*/
|
|
35
34
|
async signal(signalId: string, data: Record<any, any>): Promise<void> {
|
|
36
35
|
await this.hotMesh.hook(`${this.hotMesh.appId}.wfs.signal`, { id: signalId, data });
|
|
@@ -81,67 +80,81 @@ export class WorkflowHandleService {
|
|
|
81
80
|
}
|
|
82
81
|
|
|
83
82
|
/**
|
|
84
|
-
*
|
|
85
|
-
* the workflow
|
|
86
|
-
*
|
|
83
|
+
* Waits for the workflow to complete and returns the result. If
|
|
84
|
+
* the workflow response includes an error, this method will rethrow
|
|
85
|
+
* the error, including the stack trace if available.
|
|
86
|
+
* Wrap calls in a try/catch as necessary to avoid unhandled exceptions.
|
|
87
87
|
*/
|
|
88
|
-
async result(
|
|
89
|
-
if (loadState) {
|
|
90
|
-
const state = await this.hotMesh.getState(`${this.hotMesh.appId}.execute`, this.workflowId);
|
|
91
|
-
if (!state.data && state.metadata.err) {
|
|
92
|
-
throw new Error(JSON.parse(state.metadata.err));
|
|
93
|
-
}
|
|
94
|
-
if (state?.data?.done) {
|
|
95
|
-
//child flows are never 'done'; they use a hook
|
|
96
|
-
//that only closes upon parent flow completion.
|
|
97
|
-
return state.data.response;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
let status = await this.hotMesh.getStatus(this.workflowId);
|
|
88
|
+
async result<T>(config?: {state?: boolean, throwOnError?: boolean}): Promise<T | StreamError> {
|
|
101
89
|
const topic = `${this.hotMesh.appId}.executed.${this.workflowId}`;
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
90
|
+
let isResolved = false;
|
|
91
|
+
|
|
92
|
+
return new Promise(async (resolve, reject) => {
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* rejects/resolves the promise based on the `throwOnError`
|
|
96
|
+
* default behavior is to throw if error
|
|
97
|
+
*/
|
|
98
|
+
const safeReject = (err: StreamError) => {
|
|
99
|
+
if (config?.throwOnError === false) {
|
|
100
|
+
return resolve(err);
|
|
101
|
+
}
|
|
102
|
+
reject(err);
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Common completion function that unsubscribes from the topic/returns
|
|
107
|
+
*/
|
|
108
|
+
const complete = async (response?: T, err?: StreamError) => {
|
|
107
109
|
if (isResolved) return;
|
|
108
110
|
isResolved = true;
|
|
109
|
-
|
|
111
|
+
|
|
110
112
|
if (err) {
|
|
111
|
-
return
|
|
113
|
+
return safeReject(err as StreamError);
|
|
112
114
|
} else if (!response) {
|
|
113
115
|
const state = await this.hotMesh.getState(`${this.hotMesh.appId}.execute`, this.workflowId);
|
|
114
|
-
if (state.
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
116
|
+
if (state.data?.done && !state.data?.$error) {
|
|
117
|
+
return resolve(state.data.response as T);
|
|
118
|
+
} else if (state.data?.$error) {
|
|
119
|
+
return safeReject(state.data.$error as StreamError)
|
|
120
|
+
} else if (state.metadata.err) {
|
|
121
|
+
return safeReject(JSON.parse(state.metadata.err) as StreamError);
|
|
119
122
|
}
|
|
120
|
-
response = state.data?.response;
|
|
123
|
+
response = state.data?.response as T;
|
|
121
124
|
}
|
|
122
|
-
resolve(response);
|
|
125
|
+
resolve(response as T);
|
|
123
126
|
};
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
+
|
|
128
|
+
//more expensive; fetches the entire job, not just the `status`
|
|
129
|
+
if (config?.state) {
|
|
130
|
+
const state = await this.hotMesh.getState(`${this.hotMesh.appId}.execute`, this.workflowId);
|
|
131
|
+
if (state?.data?.done && !state.data?.$error) {
|
|
132
|
+
return complete(state.data.response as T);
|
|
133
|
+
} else if (state.data?.$error) {
|
|
134
|
+
return complete(null, state.data.$error as StreamError);
|
|
135
|
+
} else if (state.metadata.err) {
|
|
136
|
+
return complete(null, JSON.parse(state.metadata.err) as StreamError);
|
|
137
|
+
}
|
|
127
138
|
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
139
|
+
|
|
140
|
+
//subscribe to 'done' topic
|
|
141
|
+
this.hotMesh.sub(topic, async (_topic: string, state: JobOutput) => {
|
|
142
|
+
this.hotMesh.unsub(topic);
|
|
143
|
+
if (state.data.done && !state.data?.$error) {
|
|
144
|
+
await complete(state.data?.response as T);
|
|
145
|
+
} else if (state.data?.$error) {
|
|
146
|
+
return complete(null, state.data.$error as StreamError)
|
|
147
|
+
} else if (state.metadata.err) {
|
|
131
148
|
const error = JSON.parse(state.metadata.err) as StreamError;
|
|
132
|
-
|
|
133
|
-
return await complete(null, state.metadata.err);
|
|
134
|
-
}
|
|
149
|
+
return await complete(null, error);
|
|
135
150
|
}
|
|
136
|
-
await complete(state.data?.response);
|
|
137
151
|
});
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
}, 0);
|
|
152
|
+
|
|
153
|
+
//check state in case completed during wiring
|
|
154
|
+
const status = await this.hotMesh.getStatus(this.workflowId);
|
|
155
|
+
if (status <= 0) {
|
|
156
|
+
await complete();
|
|
157
|
+
}
|
|
145
158
|
});
|
|
146
159
|
}
|
|
147
160
|
}
|
|
@@ -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';
|
|
@@ -11,7 +10,6 @@ export const Durable = {
|
|
|
11
10
|
Client: ClientService,
|
|
12
11
|
Connection: ConnectionService,
|
|
13
12
|
Search,
|
|
14
|
-
MeshOS: MeshOSService,
|
|
15
13
|
Worker: WorkerService,
|
|
16
14
|
workflow: WorkflowService,
|
|
17
15
|
|