@brandboostinggmbh/observable-workflows 0.4.7 → 0.5.0

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
@@ -151,10 +151,10 @@ type StepContextOptions = {
151
151
  reuseSuccessfulSteps?: boolean;
152
152
  };
153
153
  type ConsoleWrapper = {
154
- log: (message: string) => void;
155
- info: (message: string) => void;
156
- error: (message: string) => void;
157
- warn: (message: string) => void;
154
+ log: (message?: any, ...optionalParams: any[]) => void;
155
+ info: (message?: any, ...optionalParams: any[]) => void;
156
+ error: (message?: any, ...optionalParams: any[]) => void;
157
+ warn: (message?: any, ...optionalParams: any[]) => void;
158
158
  };
159
159
  type StepCtx = {
160
160
  console: ConsoleWrapper;
package/dist/index.js CHANGED
@@ -66,6 +66,24 @@ function tryDeserializeObj(obj, serializer) {
66
66
  return obj;
67
67
  }
68
68
  }
69
+ function safeConsoleArgsToString(message, ...optionalParams) {
70
+ const args = [message, ...optionalParams];
71
+ return args.map((arg) => {
72
+ if (typeof arg === "string") return arg;
73
+ if (arg === null) return "null";
74
+ if (arg === void 0) return "undefined";
75
+ if (typeof arg === "number" || typeof arg === "boolean") return String(arg);
76
+ try {
77
+ return JSON.stringify(arg, (key, value) => {
78
+ if (typeof value === "object" && value !== null) return value;
79
+ return value;
80
+ });
81
+ } catch (error) {
82
+ if (error instanceof TypeError && error.message.includes("circular")) return `[object Object (circular reference)]`;
83
+ return String(arg);
84
+ }
85
+ }).join(" ");
86
+ }
69
87
  /**
70
88
  * We want to save steps to a databse, we are using D1, so SQLite is the database.
71
89
  * Step Table:
@@ -278,17 +296,17 @@ async function createStepContext(context) {
278
296
  waitFor.push(logPromise);
279
297
  };
280
298
  const ctx = { console: {
281
- log: (message) => {
282
- log(message, "info");
299
+ log: (message, ...optionalParams) => {
300
+ log(safeConsoleArgsToString(message, ...optionalParams), "info");
283
301
  },
284
- info: (message) => {
285
- log(message, "info");
302
+ info: (message, ...optionalParams) => {
303
+ log(safeConsoleArgsToString(message, ...optionalParams), "info");
286
304
  },
287
- error: (message) => {
288
- log(message, "error");
305
+ error: (message, ...optionalParams) => {
306
+ log(safeConsoleArgsToString(message, ...optionalParams), "error");
289
307
  },
290
- warn: (message) => {
291
- log(message, "warn");
308
+ warn: (message, ...optionalParams) => {
309
+ log(safeConsoleArgsToString(message, ...optionalParams), "warn");
292
310
  }
293
311
  } };
294
312
  try {
@@ -314,7 +332,6 @@ async function createStepContext(context) {
314
332
  const endTime = Date.now();
315
333
  const stepStatus$1 = "failed";
316
334
  const stepResult$1 = null;
317
- ctx.console.error(`This is a temporary log to debug errors in the error handler: ${error instanceof Error ? `M: ${error.message} N: ${error.name} s: ${error.stack}` : String(error)}`);
318
335
  let stepError$1;
319
336
  try {
320
337
  stepError$1 = context.serializer.serialize(error);
@@ -399,17 +416,17 @@ function createWorkflowContext(options) {
399
416
  await workflow._callback(input, {
400
417
  step: stepContext,
401
418
  console: {
402
- log: (message) => {
403
- log(message, "info");
419
+ log: (message, ...optionalParams) => {
420
+ log(safeConsoleArgsToString(message, ...optionalParams), "info");
404
421
  },
405
- info: (message) => {
406
- log(message, "info");
422
+ info: (message, ...optionalParams) => {
423
+ log(safeConsoleArgsToString(message, ...optionalParams), "info");
407
424
  },
408
- error: (message) => {
409
- log(message, "error");
425
+ error: (message, ...optionalParams) => {
426
+ log(safeConsoleArgsToString(message, ...optionalParams), "error");
410
427
  },
411
- warn: (message) => {
412
- log(message, "warn");
428
+ warn: (message, ...optionalParams) => {
429
+ log(safeConsoleArgsToString(message, ...optionalParams), "warn");
413
430
  }
414
431
  },
415
432
  async setWorkflowName(newName) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brandboostinggmbh/observable-workflows",
3
- "version": "0.4.7",
3
+ "version": "0.5.0",
4
4
  "description": "My awesome typescript library",
5
5
  "type": "module",
6
6
  "license": "MIT",