@brandboostinggmbh/observable-workflows 0.4.3 → 0.4.4

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.
Files changed (2) hide show
  1. package/dist/index.js +29 -5
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -23,6 +23,25 @@ function insertStepRecordFull(context, { instanceId, name, status, metadata, sta
23
23
  VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`
24
24
  ).bind(instanceId, name, status, metadata, startTime, endTime, result, error, context.tenantId).run();
25
25
  }
26
+ async function getStepRecord(context, stepName, instanceId) {
27
+ const existingStep = await context.D1.prepare(
28
+ /* sql */
29
+ `SELECT * FROM StepTable WHERE instanceId = ? AND stepName = ? AND tenantId = ?`
30
+ ).bind(instanceId, stepName, context.tenantId).first();
31
+ const row = existingStep;
32
+ if (row) return {
33
+ instanceId: row.instanceId,
34
+ name: row.stepName,
35
+ status: row.stepStatus,
36
+ metadata: tryDeserializeObj(row.stepMetadata, context.serializer),
37
+ startTime: row.startTime,
38
+ endTime: row.endTime,
39
+ result: tryDeserializeObj(row.result, context.serializer),
40
+ error: tryDeserializeObj(row.error, context.serializer),
41
+ tenantId: row.tenantId
42
+ };
43
+ else return null;
44
+ }
26
45
  function pushLogToDB(options, { instanceId, stepName, message, timestamp, type, logOrder, tenantId }) {
27
46
  return options.D1.prepare(
28
47
  /* sql */
@@ -31,6 +50,14 @@ function pushLogToDB(options, { instanceId, stepName, message, timestamp, type,
31
50
  VALUES (?, ?, ?, ?, ?, ?, ?)`
32
51
  ).bind(instanceId, stepName, message, timestamp, type, logOrder, tenantId).run();
33
52
  }
53
+ function trySerializeObj(obj, serializer) {
54
+ try {
55
+ return serializer.serialize(obj);
56
+ } catch (error) {
57
+ console.error("Error serializing object:", error);
58
+ return String(obj);
59
+ }
60
+ }
34
61
  function tryDeserializeObj(obj, serializer) {
35
62
  try {
36
63
  return serializer.deserialize(obj);
@@ -198,10 +225,7 @@ async function createStepContext(context) {
198
225
  const stepMetadataParam = typeof step$1 === "string" ? void 0 : step$1.metadata;
199
226
  if (context.parentInstanceId && reuseSuccessfulSteps) {
200
227
  console.warn("temp: try to reuse successful steps");
201
- const existingStep = await context.D1.prepare(
202
- /* sql */
203
- `SELECT * FROM StepTable WHERE instanceId = ? AND stepName = ? AND tenantId = ?`
204
- ).bind(context.parentInstanceId, stepNameParam, context.tenantId).first();
228
+ const existingStep = await getStepRecord(context, stepNameParam, context.parentInstanceId);
205
229
  if (existingStep) {
206
230
  console.warn("temp: found existing step", existingStep);
207
231
  const row = existingStep;
@@ -211,7 +235,7 @@ async function createStepContext(context) {
211
235
  instanceId,
212
236
  name: row.name,
213
237
  status: row.status,
214
- metadata: row.metadata,
238
+ metadata: trySerializeObj(row.metadata, context.serializer),
215
239
  startTime: row.startTime,
216
240
  endTime: row.endTime,
217
241
  result: row.result,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brandboostinggmbh/observable-workflows",
3
- "version": "0.4.3",
3
+ "version": "0.4.4",
4
4
  "description": "My awesome typescript library",
5
5
  "type": "module",
6
6
  "license": "MIT",