@brandboostinggmbh/observable-workflows 0.3.0 → 0.3.1

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 CHANGED
@@ -256,7 +256,7 @@ declare function defineWorkflow<I extends {} | null>(workflowType: string, callb
256
256
 
257
257
  //#endregion
258
258
  //#region src/observableWorkflows/createWorkflowContext.d.ts
259
- declare function createWorkflowContext(options: WorkflowContextOptions): Promise<{
259
+ declare function createWorkflowContext(options: WorkflowContextOptions): {
260
260
  call: <I>({
261
261
  workflow,
262
262
  input,
@@ -271,7 +271,7 @@ declare function createWorkflowContext(options: WorkflowContextOptions): Promise
271
271
  parentInstanceId?: string | undefined;
272
272
  }) => Promise<void>;
273
273
  retry: <I>(workflow: WorkflowFunction<I>, retryInstanceId: string) => Promise<void>;
274
- }>;
274
+ };
275
275
 
276
276
  //#endregion
277
277
  //#region src/observableWorkflows/createQueueWorkflowContext.d.ts
package/dist/index.js CHANGED
@@ -312,14 +312,18 @@ const defaultIdFactory = () => crypto.randomUUID();
312
312
 
313
313
  //#endregion
314
314
  //#region src/observableWorkflows/createWorkflowContext.ts
315
- async function createWorkflowContext(options) {
316
- await ensureTables(options.D1);
315
+ function createWorkflowContext(options) {
316
+ let ensuredTables = false;
317
317
  const internalContext = {
318
318
  ...options,
319
319
  serializer: options.serializer ?? defaultSerializer,
320
320
  idFactory: options.idFactory ?? defaultIdFactory
321
321
  };
322
322
  const call = async ({ workflow, input, workflowName, tenantId, parentInstanceId }) => {
323
+ if (!ensuredTables) {
324
+ await ensureTables(options.D1);
325
+ ensuredTables = true;
326
+ }
323
327
  const instanceId = internalContext.idFactory();
324
328
  const startTime = Date.now();
325
329
  await insertWorkflowRecord(internalContext, {
@@ -409,6 +413,10 @@ async function createWorkflowContext(options) {
409
413
  }
410
414
  };
411
415
  const retry = async (workflow, retryInstanceId) => {
416
+ if (!ensuredTables) {
417
+ await ensureTables(options.D1);
418
+ ensuredTables = true;
419
+ }
412
420
  const oldRun = await options.D1.prepare(
413
421
  /* sql */
414
422
  `SELECT input, workflowName, tenantId FROM WorkflowTable WHERE instanceId = ? `
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brandboostinggmbh/observable-workflows",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "My awesome typescript library",
5
5
  "type": "module",
6
6
  "license": "MIT",