@brandboostinggmbh/observable-workflows 0.20.2-beta.1 → 0.21.0-beta.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 -3
- package/dist/index.js +21 -9
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -686,12 +686,14 @@ type WorkflowFunction<INPUT, OUTPUT, TYPE extends string = string> = {
|
|
|
686
686
|
* Use either the WorkflowContect, or the QueueWorkflowContext to run or enqueue this. */
|
|
687
687
|
_callback: (input: INPUT, ctx: WorkflowContext) => Promise<OUTPUT>;
|
|
688
688
|
};
|
|
689
|
-
type WorkflowEnqueueBatchItem<I, O> = {
|
|
690
|
-
workflow: WorkflowFunction<I, O>;
|
|
689
|
+
type WorkflowEnqueueBatchItem<I, O, TYPE extends string = string> = {
|
|
690
|
+
workflow: WorkflowFunction<I, O, TYPE>;
|
|
691
691
|
tenantId: string;
|
|
692
692
|
input: I;
|
|
693
693
|
initialName: string;
|
|
694
694
|
dependencies?: WorkflowDependency[];
|
|
695
|
+
/** Optional trigger identifier for workflow correlation. If not provided, one will be auto-generated. */
|
|
696
|
+
triggerId?: string | null;
|
|
695
697
|
};
|
|
696
698
|
type WorkflowQueueMessage = {
|
|
697
699
|
type: 'workflow-run';
|
|
@@ -874,7 +876,7 @@ declare const createLogAccessor: (context: {
|
|
|
874
876
|
//#endregion
|
|
875
877
|
//#region src/observableWorkflows/createQueueWorkflowContext.d.ts
|
|
876
878
|
declare function createQueueWorkflowContext(options: QueueWorkflowContextOptions): {
|
|
877
|
-
enqueueWorkflow: <I, O, TYPE extends string>(
|
|
879
|
+
enqueueWorkflow: <I, O, TYPE extends string>(params: WorkflowEnqueueBatchItem<I, O, TYPE>) => Promise<ScheduledWorkflowExecutionStub<O, TYPE>>;
|
|
878
880
|
enqueueWorkflowBatch: <I, O>(workflows: Array<WorkflowEnqueueBatchItem<I, O>>) => Promise<Array<ScheduledWorkflowExecutionStub<O, string>>>;
|
|
879
881
|
enqueueRetryWorkflow: <I, O>(workflow: WorkflowFunction<I, O>, tenantId: string, oldInstanceId: string, reuseSuccessfulSteps?: boolean) => Promise<void>;
|
|
880
882
|
handleWorkflowQueueMessage: ({
|
package/dist/index.js
CHANGED
|
@@ -1419,7 +1419,10 @@ const createLogAccessor = (context) => {
|
|
|
1419
1419
|
offset
|
|
1420
1420
|
]));
|
|
1421
1421
|
const result = await retryD1Operation(() => context.D1.prepare(sql).bind(...bindings, limit, offset).all(), context.retryConfig);
|
|
1422
|
-
if (options?.debugLogs)
|
|
1422
|
+
if (options?.debugLogs) {
|
|
1423
|
+
console.log(`listWorkflows SQL Query executed in ${Date.now() - debugStartTime}ms, rows: ${result.results?.length ?? 0}`);
|
|
1424
|
+
if (result.meta) console.log("listWorkflows D1 meta:", JSON.stringify(result.meta));
|
|
1425
|
+
}
|
|
1423
1426
|
if (result.results) {
|
|
1424
1427
|
const deserializeStart = options?.debugLogs ? Date.now() : 0;
|
|
1425
1428
|
const workflows = await Promise.all(result.results.map((row) => workflowTableRowToWorkflowRun({
|
|
@@ -1515,6 +1518,10 @@ const createLogAccessor = (context) => {
|
|
|
1515
1518
|
}
|
|
1516
1519
|
return [];
|
|
1517
1520
|
};
|
|
1521
|
+
/**
|
|
1522
|
+
* Gets all workflows that have the given parentInstanceId. This is a shallow get - only returns
|
|
1523
|
+
* base workflow data without steps, logs, properties, or dependencies.
|
|
1524
|
+
*/
|
|
1518
1525
|
const getWorkflowByParentId = async (parentInstanceId) => {
|
|
1519
1526
|
const result = await retryD1Operation(() => context.D1.prepare(`SELECT * FROM WorkflowTable WHERE parentInstanceId = ? AND tenantId = ?`).bind(parentInstanceId, context.tenantId).all(), context.retryConfig);
|
|
1520
1527
|
if (result.results) {
|
|
@@ -1527,6 +1534,11 @@ const createLogAccessor = (context) => {
|
|
|
1527
1534
|
}
|
|
1528
1535
|
return null;
|
|
1529
1536
|
};
|
|
1537
|
+
/**
|
|
1538
|
+
* Gets a workflow by its triggerId. This is a shallow get - only returns base workflow data
|
|
1539
|
+
* without steps, logs, properties, retries, or dependencies.
|
|
1540
|
+
* Use getWorkflow(instanceId) if you need the full workflow with all related data.
|
|
1541
|
+
*/
|
|
1530
1542
|
const getWorkflowByTriggerId = async (triggerId) => {
|
|
1531
1543
|
const result = await retryD1Operation(() => context.D1.prepare(`SELECT * FROM WorkflowTable WHERE triggerId = ? AND tenantId = ?`).bind(triggerId, context.tenantId).first(), context.retryConfig);
|
|
1532
1544
|
if (result) {
|
|
@@ -1670,10 +1682,9 @@ const createLogAccessor = (context) => {
|
|
|
1670
1682
|
return step;
|
|
1671
1683
|
};
|
|
1672
1684
|
const getPropertiesKeys = async (instanceId) => {
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
`).bind(context.tenantId, instanceId ?? null, instanceId ?? null).all(), context.retryConfig);
|
|
1685
|
+
let result;
|
|
1686
|
+
if (instanceId) result = await retryD1Operation(() => context.D1.prepare(`SELECT DISTINCT key, valueType FROM WorkflowProperties WHERE instanceId = ?`).bind(instanceId).all(), context.retryConfig);
|
|
1687
|
+
else result = await retryD1Operation(() => context.D1.prepare(`SELECT DISTINCT key, valueType FROM WorkflowProperties WHERE tenantId = ?`).bind(context.tenantId).all(), context.retryConfig);
|
|
1677
1688
|
console.log(`debug getPropertiesKeys: ${JSON.stringify(result)}`);
|
|
1678
1689
|
if (!result.results) return [];
|
|
1679
1690
|
return result.results.map((row) => ({
|
|
@@ -1773,8 +1784,9 @@ function createQueueWorkflowContext(options) {
|
|
|
1773
1784
|
idFactory: options.idFactory ?? defaultIdFactory
|
|
1774
1785
|
};
|
|
1775
1786
|
const idFactory = internalContext.idFactory;
|
|
1776
|
-
const enqueueWorkflow = async (
|
|
1777
|
-
const triggerId =
|
|
1787
|
+
const enqueueWorkflow = async (params) => {
|
|
1788
|
+
const { workflow, tenantId, input, initialName, dependencies, triggerId: providedTriggerId } = params;
|
|
1789
|
+
const triggerId = providedTriggerId ?? idFactory();
|
|
1778
1790
|
const instanceId = idFactory();
|
|
1779
1791
|
const startTime = Date.now();
|
|
1780
1792
|
if (dependencies && dependencies.length > 0) await insertWorkflowRecord(internalContext, {
|
|
@@ -1853,9 +1865,9 @@ function createQueueWorkflowContext(options) {
|
|
|
1853
1865
|
const enqueueWorkflowBatch = async (workflows) => {
|
|
1854
1866
|
const startTime = Date.now();
|
|
1855
1867
|
console.log(`enqueueWorkflowBatch: Starting batch of ${workflows.length} workflows`);
|
|
1856
|
-
const preparedWorkflows = await Promise.all(workflows.map(async ({ workflow, tenantId, input, initialName, dependencies }) => {
|
|
1868
|
+
const preparedWorkflows = await Promise.all(workflows.map(async ({ workflow, tenantId, input, initialName, dependencies, triggerId: providedTriggerId }) => {
|
|
1857
1869
|
const instanceId = idFactory();
|
|
1858
|
-
const triggerId = idFactory();
|
|
1870
|
+
const triggerId = providedTriggerId ?? idFactory();
|
|
1859
1871
|
const hasDependencies = dependencies && dependencies.length > 0;
|
|
1860
1872
|
const prepared = await prepareWorkflowInsertStatements(internalContext, {
|
|
1861
1873
|
instanceId,
|