@brandboostinggmbh/observable-workflows 0.3.0 → 0.3.2

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
@@ -1,8 +1,11 @@
1
1
  //#region src/observableWorkflows/createStepContext.d.ts
2
- declare function createStepContext(context: StepContextOptions): Promise<(<RESULT>(step: {
3
- name: string;
4
- metadata?: Record<string, any>;
5
- }, callback: (ctx: StepCtx) => Promise<RESULT>) => Promise<RESULT>)>;
2
+ declare function createStepContext(context: StepContextOptions): Promise<{
3
+ <RESULT>(stepName: string, callback: (ctx: StepCtx) => Promise<RESULT>): Promise<RESULT>;
4
+ <RESULT>(step: {
5
+ name: string;
6
+ metadata?: Record<string, any>;
7
+ }, callback: (ctx: StepCtx) => Promise<RESULT>): Promise<RESULT>;
8
+ }>;
6
9
 
7
10
  //#endregion
8
11
  //#region src/observableWorkflows/helperFunctions.d.ts
@@ -256,7 +259,7 @@ declare function defineWorkflow<I extends {} | null>(workflowType: string, callb
256
259
 
257
260
  //#endregion
258
261
  //#region src/observableWorkflows/createWorkflowContext.d.ts
259
- declare function createWorkflowContext(options: WorkflowContextOptions): Promise<{
262
+ declare function createWorkflowContext(options: WorkflowContextOptions): {
260
263
  call: <I>({
261
264
  workflow,
262
265
  input,
@@ -271,7 +274,7 @@ declare function createWorkflowContext(options: WorkflowContextOptions): Promise
271
274
  parentInstanceId?: string | undefined;
272
275
  }) => Promise<void>;
273
276
  retry: <I>(workflow: WorkflowFunction<I>, retryInstanceId: string) => Promise<void>;
274
- }>;
277
+ };
275
278
 
276
279
  //#endregion
277
280
  //#region src/observableWorkflows/createQueueWorkflowContext.d.ts
package/dist/index.js CHANGED
@@ -192,11 +192,13 @@ async function createStepContext(context) {
192
192
  const instanceId = context.instanceId;
193
193
  await ensureTables(context.D1);
194
194
  const step = async (step$1, callback) => {
195
+ const stepNameParam = typeof step$1 === "string" ? step$1 : step$1.name;
196
+ const stepMetadataParam = typeof step$1 === "string" ? void 0 : step$1.metadata;
195
197
  if (context.parentInstanceId) {
196
198
  const existingStep = await context.D1.prepare(
197
199
  /* sql */
198
200
  `SELECT * FROM StepTable WHERE instanceId = ? AND stepName = ? AND tenantId = ?`
199
- ).bind(context.parentInstanceId, step$1.name, context.tenantId).first();
201
+ ).bind(context.parentInstanceId, stepNameParam, context.tenantId).first();
200
202
  if (existingStep) {
201
203
  const row = existingStep;
202
204
  if (row.status === "completed") {
@@ -217,8 +219,8 @@ async function createStepContext(context) {
217
219
  let waitFor = [];
218
220
  const startTime = Date.now();
219
221
  const stepStatus = "pending";
220
- const stepMetadata = context.serializer.serialize(step$1.metadata || {});
221
- const stepName = step$1.name;
222
+ const stepMetadata = context.serializer.serialize(stepMetadataParam || {});
223
+ const stepName = stepNameParam;
222
224
  const stepResult = null;
223
225
  const stepError = null;
224
226
  await insertStepRecordFull(context, {
@@ -236,7 +238,7 @@ async function createStepContext(context) {
236
238
  logOrder++;
237
239
  const timestamp = Date.now();
238
240
  const logPromise = pushLogToDB(context, {
239
- stepName: step$1.name,
241
+ stepName: stepNameParam,
240
242
  instanceId,
241
243
  message,
242
244
  timestamp,
@@ -312,14 +314,18 @@ const defaultIdFactory = () => crypto.randomUUID();
312
314
 
313
315
  //#endregion
314
316
  //#region src/observableWorkflows/createWorkflowContext.ts
315
- async function createWorkflowContext(options) {
316
- await ensureTables(options.D1);
317
+ function createWorkflowContext(options) {
318
+ let ensuredTables = false;
317
319
  const internalContext = {
318
320
  ...options,
319
321
  serializer: options.serializer ?? defaultSerializer,
320
322
  idFactory: options.idFactory ?? defaultIdFactory
321
323
  };
322
324
  const call = async ({ workflow, input, workflowName, tenantId, parentInstanceId }) => {
325
+ if (!ensuredTables) {
326
+ await ensureTables(options.D1);
327
+ ensuredTables = true;
328
+ }
323
329
  const instanceId = internalContext.idFactory();
324
330
  const startTime = Date.now();
325
331
  await insertWorkflowRecord(internalContext, {
@@ -409,6 +415,10 @@ async function createWorkflowContext(options) {
409
415
  }
410
416
  };
411
417
  const retry = async (workflow, retryInstanceId) => {
418
+ if (!ensuredTables) {
419
+ await ensureTables(options.D1);
420
+ ensuredTables = true;
421
+ }
412
422
  const oldRun = await options.D1.prepare(
413
423
  /* sql */
414
424
  `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.2",
4
4
  "description": "My awesome typescript library",
5
5
  "type": "module",
6
6
  "license": "MIT",