@brandboostinggmbh/observable-workflows 0.3.5 → 0.3.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/dist/index.d.ts +14 -22
- package/dist/index.js +4 -8
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -127,14 +127,12 @@ declare function upsertWorkflowProperty<T extends keyof ValueTypeMap>({
|
|
|
127
127
|
context,
|
|
128
128
|
instanceId,
|
|
129
129
|
key,
|
|
130
|
-
valueType,
|
|
131
130
|
value,
|
|
132
131
|
tenantId
|
|
133
132
|
}: {
|
|
134
133
|
context: InternalWorkflowContextOptions;
|
|
135
134
|
instanceId: string;
|
|
136
135
|
key: string;
|
|
137
|
-
valueType: T;
|
|
138
136
|
value: ValueTypeMap[T];
|
|
139
137
|
tenantId: string;
|
|
140
138
|
}): Promise<boolean>;
|
|
@@ -216,16 +214,25 @@ type WorkflowContextOptions = {
|
|
|
216
214
|
serializer?: Serializer;
|
|
217
215
|
};
|
|
218
216
|
type InternalWorkflowContextOptions = WorkflowContextOptions & Required<Pick<WorkflowContextOptions, 'serializer' | 'idFactory'>>;
|
|
217
|
+
type WorkflowContextInstance = {
|
|
218
|
+
call: <I>(args: {
|
|
219
|
+
workflow: WorkflowFunction<I>;
|
|
220
|
+
input: I;
|
|
221
|
+
workflowName: string;
|
|
222
|
+
tenantId: string;
|
|
223
|
+
parentInstanceId?: string | undefined;
|
|
224
|
+
}) => Promise<void>;
|
|
225
|
+
retry: <I>(workflow: WorkflowFunction<I>, retryInstanceId: string) => Promise<void>;
|
|
226
|
+
};
|
|
219
227
|
type QueueWorkflowContextOptions = {
|
|
220
228
|
QUEUE: Queue<WorkflowQueueMessage>;
|
|
221
|
-
|
|
222
|
-
idFactory?: () => string;
|
|
229
|
+
workflowContext: WorkflowContextInstance;
|
|
223
230
|
};
|
|
224
231
|
type WorkflowContext = {
|
|
225
232
|
step: StepContext;
|
|
226
233
|
console: ConsoleWrapper;
|
|
227
234
|
setWorkflowName: (newName: string) => Promise<void>;
|
|
228
|
-
setWorkflowProperty: <T extends keyof ValueTypeMap>(key: string,
|
|
235
|
+
setWorkflowProperty: <T extends keyof ValueTypeMap>(key: string, value: ValueTypeMap[T]) => Promise<void>;
|
|
229
236
|
tenantId: string;
|
|
230
237
|
};
|
|
231
238
|
type WorkflowFunction<INPUT, TYPE extends string = string> = {
|
|
@@ -260,22 +267,7 @@ declare function defineWorkflow<I extends {} | null>(workflowType: string, callb
|
|
|
260
267
|
|
|
261
268
|
//#endregion
|
|
262
269
|
//#region src/observableWorkflows/createWorkflowContext.d.ts
|
|
263
|
-
declare function createWorkflowContext(options: WorkflowContextOptions):
|
|
264
|
-
call: <I>({
|
|
265
|
-
workflow,
|
|
266
|
-
input,
|
|
267
|
-
workflowName,
|
|
268
|
-
tenantId,
|
|
269
|
-
parentInstanceId
|
|
270
|
-
}: {
|
|
271
|
-
workflow: WorkflowFunction<I>;
|
|
272
|
-
input: I;
|
|
273
|
-
workflowName: string;
|
|
274
|
-
tenantId: string;
|
|
275
|
-
parentInstanceId?: string | undefined;
|
|
276
|
-
}) => Promise<void>;
|
|
277
|
-
retry: <I>(workflow: WorkflowFunction<I>, retryInstanceId: string) => Promise<void>;
|
|
278
|
-
};
|
|
270
|
+
declare function createWorkflowContext(options: WorkflowContextOptions): WorkflowContextInstance;
|
|
279
271
|
|
|
280
272
|
//#endregion
|
|
281
273
|
//#region src/observableWorkflows/createQueueWorkflowContext.d.ts
|
|
@@ -314,4 +306,4 @@ declare const defaultSerializer: {
|
|
|
314
306
|
declare const defaultIdFactory: () => string;
|
|
315
307
|
|
|
316
308
|
//#endregion
|
|
317
|
-
export { ConsoleWrapper, InternalWorkflowContextOptions, Log, PossibleValueTypeNames, PossibleValueTypes, QueueWorkflowContextOptions, Serializer, Step, StepContextOptions, StepCtx, StepWorkflowStatus, ValueTypeMap, WorkflowContext, WorkflowContextOptions, WorkflowFunction, WorkflowProperty, WorkflowPropertyDefinition, WorkflowQueueMessage, WorkflowRun, createLogAccessor, createQueueWorkflowContext, createStepContext, createWorkflowContext, defaultIdFactory, defaultSerializer, defineWorkflow, ensureTables, finalizeWorkflowRecord, insertStepRecordFull, insertWorkflowRecord, pushLogToDB, tryDeserializeObj, updateWorkflowName, upsertWorkflowProperty, workflowTableRowToWorkflowRun };
|
|
309
|
+
export { ConsoleWrapper, InternalWorkflowContextOptions, Log, PossibleValueTypeNames, PossibleValueTypes, QueueWorkflowContextOptions, Serializer, Step, StepContextOptions, StepCtx, StepWorkflowStatus, ValueTypeMap, WorkflowContext, WorkflowContextInstance, WorkflowContextOptions, WorkflowFunction, WorkflowProperty, WorkflowPropertyDefinition, WorkflowQueueMessage, WorkflowRun, createLogAccessor, createQueueWorkflowContext, createStepContext, createWorkflowContext, defaultIdFactory, defaultSerializer, defineWorkflow, ensureTables, finalizeWorkflowRecord, insertStepRecordFull, insertWorkflowRecord, pushLogToDB, tryDeserializeObj, updateWorkflowName, upsertWorkflowProperty, workflowTableRowToWorkflowRun };
|
package/dist/index.js
CHANGED
|
@@ -159,7 +159,8 @@ async function updateWorkflowName(context, instanceId, newWorkflowName) {
|
|
|
159
159
|
WHERE instanceId = ?`
|
|
160
160
|
).bind(newWorkflowName, instanceId).run();
|
|
161
161
|
}
|
|
162
|
-
async function upsertWorkflowProperty({ context, instanceId, key,
|
|
162
|
+
async function upsertWorkflowProperty({ context, instanceId, key, value, tenantId }) {
|
|
163
|
+
const valueType = typeof value;
|
|
163
164
|
const serializedValue = valueType === "object" ? JSON.stringify(value) : String(value);
|
|
164
165
|
const res = await context.D1.prepare(
|
|
165
166
|
/* sql */
|
|
@@ -383,12 +384,11 @@ function createWorkflowContext(options) {
|
|
|
383
384
|
async setWorkflowName(newName) {
|
|
384
385
|
await updateWorkflowName({ D1: options.D1 }, instanceId, newName);
|
|
385
386
|
},
|
|
386
|
-
async setWorkflowProperty(key,
|
|
387
|
+
async setWorkflowProperty(key, value) {
|
|
387
388
|
await upsertWorkflowProperty({
|
|
388
389
|
context: internalContext,
|
|
389
390
|
instanceId,
|
|
390
391
|
key,
|
|
391
|
-
valueType,
|
|
392
392
|
value,
|
|
393
393
|
tenantId
|
|
394
394
|
});
|
|
@@ -467,11 +467,7 @@ function createQueueWorkflowContext(options) {
|
|
|
467
467
|
const handleWorkflowQueueMessage = async (message, env, workflowResolver) => {
|
|
468
468
|
const workflowFunction = workflowResolver(message.workflowType);
|
|
469
469
|
if (!workflowFunction) throw new Error(`Workflow ${message.workflowType} not found`);
|
|
470
|
-
const wfc =
|
|
471
|
-
D1: env.LOG_DB,
|
|
472
|
-
serializer: options.serializer,
|
|
473
|
-
idFactory: options.idFactory
|
|
474
|
-
});
|
|
470
|
+
const wfc = options.workflowContext;
|
|
475
471
|
if (message.type === "workflow-run") {
|
|
476
472
|
console.log("running workflow", message.input);
|
|
477
473
|
await wfc.call({
|