@brandboostinggmbh/observable-workflows 0.18.0 → 0.18.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 +5 -0
- package/dist/index.js +30 -2
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -158,6 +158,11 @@ type ValueTypeMap = {
|
|
|
158
158
|
};
|
|
159
159
|
type PossibleValueTypeNames = keyof ValueTypeMap;
|
|
160
160
|
type PossibleValueTypes = ValueTypeMap[PossibleValueTypeNames];
|
|
161
|
+
/**
|
|
162
|
+
* Serialize a workflow property value for storage
|
|
163
|
+
* We explicitly do not want to use the serializer here, since stringify is much more compatible and human readable.
|
|
164
|
+
*/
|
|
165
|
+
|
|
161
166
|
declare function upsertWorkflowProperty<T extends keyof ValueTypeMap>({
|
|
162
167
|
context,
|
|
163
168
|
instanceId,
|
package/dist/index.js
CHANGED
|
@@ -557,9 +557,37 @@ async function updateWorkflowName(context, instanceId, newWorkflowName) {
|
|
|
557
557
|
SET workflowName = ?
|
|
558
558
|
WHERE instanceId = ?`).bind(newWorkflowName, instanceId).run();
|
|
559
559
|
}
|
|
560
|
-
|
|
560
|
+
/**
|
|
561
|
+
* Serialize a workflow property value for storage
|
|
562
|
+
* We explicitly do not want to use the serializer here, since stringify is much more compatible and human readable.
|
|
563
|
+
*/
|
|
564
|
+
function serializeWorkflowPropertyValue(value) {
|
|
561
565
|
const valueType = typeof value;
|
|
562
566
|
const serializedValue = valueType === "object" ? JSON.stringify(value) : String(value);
|
|
567
|
+
return {
|
|
568
|
+
serializedValue,
|
|
569
|
+
valueType
|
|
570
|
+
};
|
|
571
|
+
}
|
|
572
|
+
/**
|
|
573
|
+
* Deserialize a workflow property value from storage
|
|
574
|
+
*/
|
|
575
|
+
function deserializeWorkflowPropertyValue(serializedValue, valueType) {
|
|
576
|
+
switch (valueType) {
|
|
577
|
+
case "string": return serializedValue;
|
|
578
|
+
case "number": return Number(serializedValue);
|
|
579
|
+
case "boolean": return serializedValue === "true";
|
|
580
|
+
case "object": try {
|
|
581
|
+
return JSON.parse(serializedValue);
|
|
582
|
+
} catch (error) {
|
|
583
|
+
console.error("Error parsing object property value:", error);
|
|
584
|
+
return serializedValue;
|
|
585
|
+
}
|
|
586
|
+
default: return serializedValue;
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
async function upsertWorkflowProperty({ context, instanceId, key, value, tenantId }) {
|
|
590
|
+
const { serializedValue, valueType } = serializeWorkflowPropertyValue(value);
|
|
563
591
|
const res = await context.D1.prepare(`INSERT OR REPLACE INTO WorkflowProperties
|
|
564
592
|
(instanceId, key, value, valueType, tenantId)
|
|
565
593
|
VALUES (?, ?, ?, ?, ?)`).bind(instanceId, key, serializedValue, valueType, tenantId).run();
|
|
@@ -793,7 +821,7 @@ const createLogAccessor = (context) => {
|
|
|
793
821
|
const property = {
|
|
794
822
|
key: row.key,
|
|
795
823
|
valueType: row.valueType,
|
|
796
|
-
value:
|
|
824
|
+
value: deserializeWorkflowPropertyValue(row.value, row.valueType)
|
|
797
825
|
};
|
|
798
826
|
const existing = propertiesByInstanceId.get(row.instanceId) || [];
|
|
799
827
|
existing.push(property);
|