@brandboostinggmbh/observable-workflows 0.17.2 → 0.17.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.
package/dist/index.d.ts CHANGED
@@ -460,6 +460,8 @@ declare const createLogAccessor: (context: {
460
460
  listWorkflows: (limit: number, offset: number, filter?: WorkflowFilter, options?: {
461
461
  /** If false the input will not be populated. This decreases memory load. */
462
462
  populateInput?: boolean;
463
+ /** If true, properties will be populated. This adds one additional query. */
464
+ populateProperties?: boolean;
463
465
  debugLogs?: boolean;
464
466
  }) => Promise<WorkflowRun[]>;
465
467
  getWorkflow: (instanceId: string, populateData?: boolean) => Promise<WorkflowRun | null>;
package/dist/index.js CHANGED
@@ -239,6 +239,7 @@ async function createIndexes(db) {
239
239
  await db.prepare(`CREATE INDEX IF NOT EXISTS idx_workflows_trigger_id ON WorkflowTable (triggerId)`).run();
240
240
  await db.prepare(`CREATE INDEX IF NOT EXISTS idx_workflows_start_time ON WorkflowTable (startTime)`).run();
241
241
  await db.prepare(`CREATE INDEX IF NOT EXISTS idx_workflows_tenant_id ON WorkflowTable (tenantId)`).run();
242
+ await db.prepare(`CREATE INDEX IF NOT EXISTS idx_workflows_tenant_starttime ON WorkflowTable (tenantId, startTime DESC)`).run();
242
243
  await db.prepare(`CREATE INDEX IF NOT EXISTS idx_workflows_instance_id ON WorkflowTable (instanceId)`).run();
243
244
  await db.prepare(`CREATE INDEX IF NOT EXISTS idx_workflows_status ON WorkflowTable (workflowStatus)`).run();
244
245
  await db.prepare(`CREATE INDEX IF NOT EXISTS idx_steps_instance_id ON StepTable (instanceId)`).run();
@@ -776,6 +777,26 @@ const createLogAccessor = (context) => {
776
777
  externalBlobStorage: context.externalBlobStorage,
777
778
  populateInput: options?.populateInput
778
779
  })));
780
+ if (options?.populateProperties && workflows.length > 0) {
781
+ const instanceIds = workflows.map((w) => w.instanceId);
782
+ const placeholders = instanceIds.map(() => "?").join(", ");
783
+ const propertiesResult = await context.D1.prepare(
784
+ /* sql */
785
+ `SELECT * FROM WorkflowProperties WHERE instanceId IN (${placeholders}) AND tenantId = ?`
786
+ ).bind(...instanceIds, context.tenantId).all();
787
+ const propertiesByInstanceId = new Map();
788
+ if (propertiesResult.results) for (const row of propertiesResult.results) {
789
+ const property = {
790
+ key: row.key,
791
+ valueType: row.valueType,
792
+ value: tryDeserializeObj(row.value, internalSerializer)
793
+ };
794
+ const existing = propertiesByInstanceId.get(row.instanceId) || [];
795
+ existing.push(property);
796
+ propertiesByInstanceId.set(row.instanceId, existing);
797
+ }
798
+ for (const workflow of workflows) workflow.properties = propertiesByInstanceId.get(workflow.instanceId) || [];
799
+ }
779
800
  return workflows;
780
801
  }
781
802
  return [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brandboostinggmbh/observable-workflows",
3
- "version": "0.17.2",
3
+ "version": "0.17.4",
4
4
  "description": "My awesome typescript library",
5
5
  "type": "module",
6
6
  "license": "MIT",