@shipfox/api-definitions 12.3.0 → 14.0.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/.turbo/turbo-build.log +11 -11
- package/CHANGELOG.md +45 -0
- package/dist/core/entities/index.d.ts +1 -1
- package/dist/core/entities/index.d.ts.map +1 -1
- package/dist/core/entities/index.js +1 -1
- package/dist/core/entities/index.js.map +1 -1
- package/dist/core/entities/integration-context.d.ts +4 -0
- package/dist/core/entities/integration-context.d.ts.map +1 -1
- package/dist/core/entities/integration-context.js.map +1 -1
- package/dist/core/entities/sync-state.d.ts +10 -4
- package/dist/core/entities/sync-state.d.ts.map +1 -1
- package/dist/core/entities/sync-state.js +26 -7
- package/dist/core/entities/sync-state.js.map +1 -1
- package/dist/core/entities/validation-diagnostic.d.ts +8 -0
- package/dist/core/entities/validation-diagnostic.d.ts.map +1 -0
- package/dist/core/entities/validation-diagnostic.js +3 -0
- package/dist/core/entities/validation-diagnostic.js.map +1 -0
- package/dist/core/entities/workflow-definition.d.ts +2 -0
- package/dist/core/entities/workflow-definition.d.ts.map +1 -1
- package/dist/core/entities/workflow-definition.js.map +1 -1
- package/dist/core/errors.d.ts +10 -0
- package/dist/core/errors.d.ts.map +1 -1
- package/dist/core/errors.js +9 -0
- package/dist/core/errors.js.map +1 -1
- package/dist/core/index.d.ts +2 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +2 -1
- package/dist/core/index.js.map +1 -1
- package/dist/core/integrations.d.ts +3 -1
- package/dist/core/integrations.d.ts.map +1 -1
- package/dist/core/integrations.js +10 -2
- package/dist/core/integrations.js.map +1 -1
- package/dist/core/parse-definition.d.ts +4 -4
- package/dist/core/parse-definition.d.ts.map +1 -1
- package/dist/core/parse-definition.js +5 -5
- package/dist/core/parse-definition.js.map +1 -1
- package/dist/core/resolve-definition-at-ref.d.ts +66 -0
- package/dist/core/resolve-definition-at-ref.d.ts.map +1 -0
- package/dist/core/resolve-definition-at-ref.js +374 -0
- package/dist/core/resolve-definition-at-ref.js.map +1 -0
- package/dist/core/sync-definitions.d.ts +2 -2
- package/dist/core/sync-definitions.d.ts.map +1 -1
- package/dist/core/sync-definitions.js +5 -5
- package/dist/core/sync-definitions.js.map +1 -1
- package/dist/core/validate-definition.d.ts +3 -3
- package/dist/core/validate-definition.d.ts.map +1 -1
- package/dist/core/validate-definition.js +17 -12
- package/dist/core/validate-definition.js.map +1 -1
- package/dist/core/workflow-model/cron-trigger.d.ts +1 -1
- package/dist/core/workflow-model/cron-trigger.d.ts.map +1 -1
- package/dist/core/workflow-model/cron-trigger.js +9 -5
- package/dist/core/workflow-model/cron-trigger.js.map +1 -1
- package/dist/core/workflow-model/index.d.ts +1 -1
- package/dist/core/workflow-model/index.d.ts.map +1 -1
- package/dist/core/workflow-model/index.js.map +1 -1
- package/dist/core/workflow-model/invalid-workflow-model-error.d.ts +4 -2
- package/dist/core/workflow-model/invalid-workflow-model-error.d.ts.map +1 -1
- package/dist/core/workflow-model/invalid-workflow-model-error.js.map +1 -1
- package/dist/core/workflow-model/normalize-job-listening.d.ts.map +1 -1
- package/dist/core/workflow-model/normalize-job-listening.js +51 -30
- package/dist/core/workflow-model/normalize-job-listening.js.map +1 -1
- package/dist/core/workflow-model/normalize-triggers.d.ts +1 -1
- package/dist/core/workflow-model/normalize-triggers.d.ts.map +1 -1
- package/dist/core/workflow-model/normalize-triggers.js +48 -18
- package/dist/core/workflow-model/normalize-triggers.js.map +1 -1
- package/dist/core/workflow-model/normalize-workflow-document.d.ts +1 -1
- package/dist/core/workflow-model/normalize-workflow-document.d.ts.map +1 -1
- package/dist/core/workflow-model/normalize-workflow-document.js +3 -3
- package/dist/core/workflow-model/normalize-workflow-document.js.map +1 -1
- package/dist/core/workflow-model/parse-interpolation-field.d.ts.map +1 -1
- package/dist/core/workflow-model/parse-interpolation-field.js +1 -15
- package/dist/core/workflow-model/parse-interpolation-field.js.map +1 -1
- package/dist/core/workflow-model/validate-predicate-expression.d.ts +3 -1
- package/dist/core/workflow-model/validate-predicate-expression.d.ts.map +1 -1
- package/dist/core/workflow-model/validate-predicate-expression.js +3 -0
- package/dist/core/workflow-model/validate-predicate-expression.js.map +1 -1
- package/dist/core/workflow-model/validation-issue.d.ts +2 -1
- package/dist/core/workflow-model/validation-issue.d.ts.map +1 -1
- package/dist/core/workflow-model/validation-issue.js +12 -15
- package/dist/core/workflow-model/validation-issue.js.map +1 -1
- package/dist/db/db.d.ts +196 -4
- package/dist/db/db.d.ts.map +1 -1
- package/dist/db/db.js +3 -1
- package/dist/db/db.js.map +1 -1
- package/dist/db/definition-triggers.js +3 -1
- package/dist/db/definition-triggers.js.map +1 -1
- package/dist/db/definitions.d.ts +17 -0
- package/dist/db/definitions.d.ts.map +1 -1
- package/dist/db/definitions.js +190 -23
- package/dist/db/definitions.js.map +1 -1
- package/dist/db/index.d.ts +2 -1
- package/dist/db/index.d.ts.map +1 -1
- package/dist/db/index.js +2 -1
- package/dist/db/index.js.map +1 -1
- package/dist/db/schema/definitions.d.ts +17 -0
- package/dist/db/schema/definitions.d.ts.map +1 -1
- package/dist/db/schema/definitions.js +8 -0
- package/dist/db/schema/definitions.js.map +1 -1
- package/dist/db/schema/sync-states.d.ts +7 -3
- package/dist/db/schema/sync-states.d.ts.map +1 -1
- package/dist/db/schema/sync-states.js +5 -1
- package/dist/db/schema/sync-states.js.map +1 -1
- package/dist/db/schema/workflows.d.ts +78 -0
- package/dist/db/schema/workflows.d.ts.map +1 -0
- package/dist/db/schema/workflows.js +17 -0
- package/dist/db/schema/workflows.js.map +1 -0
- package/dist/db/sync-states.d.ts +2 -2
- package/dist/db/sync-states.d.ts.map +1 -1
- package/dist/db/sync-states.js +4 -4
- package/dist/db/sync-states.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -1
- package/dist/index.js.map +1 -1
- package/dist/metrics/index.d.ts +2 -0
- package/dist/metrics/index.d.ts.map +1 -0
- package/dist/metrics/index.js +3 -0
- package/dist/metrics/index.js.map +1 -0
- package/dist/metrics/instance.d.ts +4 -0
- package/dist/metrics/instance.d.ts.map +1 -0
- package/dist/metrics/instance.js +19 -0
- package/dist/metrics/instance.js.map +1 -0
- package/dist/presentation/dto/definition.d.ts.map +1 -1
- package/dist/presentation/dto/definition.js +11 -4
- package/dist/presentation/dto/definition.js.map +1 -1
- package/dist/presentation/inter-module.d.ts +9 -1
- package/dist/presentation/inter-module.d.ts.map +1 -1
- package/dist/presentation/inter-module.js +66 -2
- package/dist/presentation/inter-module.js.map +1 -1
- package/dist/presentation/routes/create-definition.d.ts.map +1 -1
- package/dist/presentation/routes/create-definition.js +16 -3
- package/dist/presentation/routes/create-definition.js.map +1 -1
- package/dist/presentation/routes/get-definition.d.ts.map +1 -1
- package/dist/presentation/routes/get-definition.js +18 -4
- package/dist/presentation/routes/get-definition.js.map +1 -1
- package/dist/presentation/routes/project-access.d.ts +1 -0
- package/dist/presentation/routes/project-access.d.ts.map +1 -1
- package/dist/presentation/routes/validate-definition.js +3 -3
- package/dist/presentation/routes/validate-definition.js.map +1 -1
- package/dist/temporal/activities/sync-activities.d.ts +3 -3
- package/dist/temporal/activities/sync-activities.d.ts.map +1 -1
- package/dist/temporal/activities/sync-activities.js +7 -4
- package/dist/temporal/activities/sync-activities.js.map +1 -1
- package/dist/temporal/workflows/definition-sync.js +1 -1
- package/dist/temporal/workflows/definition-sync.js.map +1 -1
- package/dist/temporal/workflows/index.bundle.js +50 -22
- package/dist/tsconfig.test.tsbuildinfo +1 -1
- package/drizzle/0003_nebulous_nemesis.sql +11 -0
- package/drizzle/0004_workflow_ref_lookup.sql +1 -0
- package/drizzle/meta/0003_snapshot.json +627 -0
- package/drizzle/meta/0004_snapshot.json +649 -0
- package/drizzle/meta/_journal.json +14 -0
- package/drizzle.config.ts +1 -0
- package/package.json +7 -7
- package/src/core/entities/index.ts +1 -1
- package/src/core/entities/integration-context.ts +4 -0
- package/src/core/entities/sync-state.test.ts +49 -0
- package/src/core/entities/sync-state.ts +35 -12
- package/src/core/entities/validation-diagnostic.ts +8 -0
- package/src/core/entities/workflow-definition.ts +2 -0
- package/src/core/errors.ts +26 -0
- package/src/core/index.ts +12 -0
- package/src/core/integrations.test.ts +38 -0
- package/src/core/integrations.ts +10 -1
- package/src/core/parse-definition-diagnostics.test.ts +47 -0
- package/src/core/parse-definition.test.ts +29 -5
- package/src/core/parse-definition.ts +7 -7
- package/src/core/resolve-definition-at-ref.test.ts +792 -0
- package/src/core/resolve-definition-at-ref.ts +551 -0
- package/src/core/sync-definitions.test.ts +61 -2
- package/src/core/sync-definitions.ts +7 -7
- package/src/core/validate-definition.test.ts +31 -22
- package/src/core/validate-definition.ts +21 -13
- package/src/core/workflow-model/cron-trigger.ts +6 -2
- package/src/core/workflow-model/index.ts +1 -0
- package/src/core/workflow-model/invalid-workflow-model-error.ts +5 -1
- package/src/core/workflow-model/normalize-job-listening.ts +55 -23
- package/src/core/workflow-model/normalize-triggers.ts +44 -15
- package/src/core/workflow-model/normalize-workflow-document.test.ts +494 -36
- package/src/core/workflow-model/normalize-workflow-document.ts +8 -4
- package/src/core/workflow-model/parse-interpolation-field.ts +1 -23
- package/src/core/workflow-model/validate-predicate-expression.ts +6 -0
- package/src/core/workflow-model/validation-issue.ts +8 -13
- package/src/db/db.ts +7 -1
- package/src/db/definition-triggers.test.ts +44 -0
- package/src/db/definition-triggers.ts +1 -1
- package/src/db/definitions.test.ts +300 -1
- package/src/db/definitions.ts +282 -28
- package/src/db/index.ts +2 -0
- package/src/db/schema/definitions.test.ts +1 -0
- package/src/db/schema/definitions.ts +11 -0
- package/src/db/schema/sync-states.ts +12 -3
- package/src/db/schema/workflows.ts +23 -0
- package/src/db/sync-states.test.ts +87 -18
- package/src/db/sync-states.ts +6 -6
- package/src/db/workflow-lineage-migration.test.ts +158 -0
- package/src/index.ts +3 -1
- package/src/metrics/index.ts +1 -0
- package/src/metrics/instance.test.ts +50 -0
- package/src/metrics/instance.ts +23 -0
- package/src/presentation/dto/definition.test.ts +89 -1
- package/src/presentation/dto/definition.ts +8 -5
- package/src/presentation/inter-module.test.ts +177 -0
- package/src/presentation/inter-module.ts +77 -4
- package/src/presentation/routes/create-definition.test.ts +38 -0
- package/src/presentation/routes/create-definition.ts +20 -3
- package/src/presentation/routes/get-definition.test.ts +125 -11
- package/src/presentation/routes/get-definition.ts +21 -4
- package/src/presentation/routes/list-definitions.test.ts +1 -1
- package/src/presentation/routes/validate-definition.test.ts +1 -1
- package/src/presentation/routes/validate-definition.ts +3 -3
- package/src/presentation/subscribers/on-integration-connection-available.test.ts +3 -0
- package/src/temporal/activities/sync-activities.test.ts +46 -2
- package/src/temporal/activities/sync-activities.ts +9 -7
- package/src/temporal/workflows/definition-sync.ts +1 -1
- package/test/factories/definition.ts +1 -0
- package/test/globalSetup.ts +2 -0
- package/tsconfig.build.tsbuildinfo +1 -1
- package/dist/core/entities/validation-warning.d.ts +0 -6
- package/dist/core/entities/validation-warning.d.ts.map +0 -1
- package/dist/core/entities/validation-warning.js +0 -3
- package/dist/core/entities/validation-warning.js.map +0 -1
- package/src/core/entities/validation-warning.ts +0 -5
- package/src/core/parse-definition-warnings.test.ts +0 -33
package/dist/db/db.d.ts
CHANGED
|
@@ -21,6 +21,23 @@ export declare const schema: {
|
|
|
21
21
|
identity: undefined;
|
|
22
22
|
generated: undefined;
|
|
23
23
|
}, {}, {}>;
|
|
24
|
+
workflowId: import("drizzle-orm/pg-core").PgColumn<{
|
|
25
|
+
name: "workflow_id";
|
|
26
|
+
tableName: "workflow_definitions";
|
|
27
|
+
dataType: "string";
|
|
28
|
+
columnType: "PgUUID";
|
|
29
|
+
data: string;
|
|
30
|
+
driverParam: string;
|
|
31
|
+
notNull: false;
|
|
32
|
+
hasDefault: false;
|
|
33
|
+
isPrimaryKey: false;
|
|
34
|
+
isAutoincrement: false;
|
|
35
|
+
hasRuntimeDefault: false;
|
|
36
|
+
enumValues: undefined;
|
|
37
|
+
baseColumn: never;
|
|
38
|
+
identity: undefined;
|
|
39
|
+
generated: undefined;
|
|
40
|
+
}, {}, {}>;
|
|
24
41
|
projectId: import("drizzle-orm/pg-core").PgColumn<{
|
|
25
42
|
name: "project_id";
|
|
26
43
|
tableName: "workflow_definitions";
|
|
@@ -569,7 +586,9 @@ export declare const schema: {
|
|
|
569
586
|
tableName: "sync_states";
|
|
570
587
|
dataType: "json";
|
|
571
588
|
columnType: "PgJsonb";
|
|
572
|
-
data: import("../core/
|
|
589
|
+
data: (Omit<import("../core/index.js").DefinitionSyncDiagnostic, "severity"> & {
|
|
590
|
+
severity?: import("../core/index.js").DefinitionSyncDiagnostic['severity'];
|
|
591
|
+
})[];
|
|
573
592
|
driverParam: unknown;
|
|
574
593
|
notNull: true;
|
|
575
594
|
hasDefault: true;
|
|
@@ -581,7 +600,9 @@ export declare const schema: {
|
|
|
581
600
|
identity: undefined;
|
|
582
601
|
generated: undefined;
|
|
583
602
|
}, {}, {
|
|
584
|
-
$type: import("../core/
|
|
603
|
+
$type: (Omit<import("../core/index.js").DefinitionSyncDiagnostic, "severity"> & {
|
|
604
|
+
severity?: import("../core/index.js").DefinitionSyncDiagnostic['severity'];
|
|
605
|
+
})[];
|
|
585
606
|
}>;
|
|
586
607
|
startedAt: import("drizzle-orm/pg-core").PgColumn<{
|
|
587
608
|
name: "started_at";
|
|
@@ -654,6 +675,81 @@ export declare const schema: {
|
|
|
654
675
|
};
|
|
655
676
|
dialect: 'pg';
|
|
656
677
|
}>;
|
|
678
|
+
workflowWorkflows: import("drizzle-orm/pg-core").PgTableWithColumns<{
|
|
679
|
+
name: "workflows";
|
|
680
|
+
schema: undefined;
|
|
681
|
+
columns: {
|
|
682
|
+
id: import("drizzle-orm/pg-core").PgColumn<{
|
|
683
|
+
name: "id";
|
|
684
|
+
tableName: "workflows";
|
|
685
|
+
dataType: "string";
|
|
686
|
+
columnType: "PgUUID";
|
|
687
|
+
data: string;
|
|
688
|
+
driverParam: string;
|
|
689
|
+
notNull: true;
|
|
690
|
+
hasDefault: true;
|
|
691
|
+
isPrimaryKey: true;
|
|
692
|
+
isAutoincrement: false;
|
|
693
|
+
hasRuntimeDefault: false;
|
|
694
|
+
enumValues: undefined;
|
|
695
|
+
baseColumn: never;
|
|
696
|
+
identity: undefined;
|
|
697
|
+
generated: undefined;
|
|
698
|
+
}, {}, {}>;
|
|
699
|
+
projectId: import("drizzle-orm/pg-core").PgColumn<{
|
|
700
|
+
name: "project_id";
|
|
701
|
+
tableName: "workflows";
|
|
702
|
+
dataType: "string";
|
|
703
|
+
columnType: "PgUUID";
|
|
704
|
+
data: string;
|
|
705
|
+
driverParam: string;
|
|
706
|
+
notNull: true;
|
|
707
|
+
hasDefault: false;
|
|
708
|
+
isPrimaryKey: false;
|
|
709
|
+
isAutoincrement: false;
|
|
710
|
+
hasRuntimeDefault: false;
|
|
711
|
+
enumValues: undefined;
|
|
712
|
+
baseColumn: never;
|
|
713
|
+
identity: undefined;
|
|
714
|
+
generated: undefined;
|
|
715
|
+
}, {}, {}>;
|
|
716
|
+
configPath: import("drizzle-orm/pg-core").PgColumn<{
|
|
717
|
+
name: "config_path";
|
|
718
|
+
tableName: "workflows";
|
|
719
|
+
dataType: "string";
|
|
720
|
+
columnType: "PgText";
|
|
721
|
+
data: string;
|
|
722
|
+
driverParam: string;
|
|
723
|
+
notNull: false;
|
|
724
|
+
hasDefault: false;
|
|
725
|
+
isPrimaryKey: false;
|
|
726
|
+
isAutoincrement: false;
|
|
727
|
+
hasRuntimeDefault: false;
|
|
728
|
+
enumValues: [string, ...string[]];
|
|
729
|
+
baseColumn: never;
|
|
730
|
+
identity: undefined;
|
|
731
|
+
generated: undefined;
|
|
732
|
+
}, {}, {}>;
|
|
733
|
+
createdAt: import("drizzle-orm/pg-core").PgColumn<{
|
|
734
|
+
name: "created_at";
|
|
735
|
+
tableName: "workflows";
|
|
736
|
+
dataType: "date";
|
|
737
|
+
columnType: "PgTimestamp";
|
|
738
|
+
data: Date;
|
|
739
|
+
driverParam: string;
|
|
740
|
+
notNull: true;
|
|
741
|
+
hasDefault: true;
|
|
742
|
+
isPrimaryKey: false;
|
|
743
|
+
isAutoincrement: false;
|
|
744
|
+
hasRuntimeDefault: false;
|
|
745
|
+
enumValues: undefined;
|
|
746
|
+
baseColumn: never;
|
|
747
|
+
identity: undefined;
|
|
748
|
+
generated: undefined;
|
|
749
|
+
}, {}, {}>;
|
|
750
|
+
};
|
|
751
|
+
dialect: 'pg';
|
|
752
|
+
}>;
|
|
657
753
|
};
|
|
658
754
|
export declare function db(): NodePgDatabase<{
|
|
659
755
|
workflowDefinitions: import("drizzle-orm/pg-core").PgTableWithColumns<{
|
|
@@ -677,6 +773,23 @@ export declare function db(): NodePgDatabase<{
|
|
|
677
773
|
identity: undefined;
|
|
678
774
|
generated: undefined;
|
|
679
775
|
}, {}, {}>;
|
|
776
|
+
workflowId: import("drizzle-orm/pg-core").PgColumn<{
|
|
777
|
+
name: "workflow_id";
|
|
778
|
+
tableName: "workflow_definitions";
|
|
779
|
+
dataType: "string";
|
|
780
|
+
columnType: "PgUUID";
|
|
781
|
+
data: string;
|
|
782
|
+
driverParam: string;
|
|
783
|
+
notNull: false;
|
|
784
|
+
hasDefault: false;
|
|
785
|
+
isPrimaryKey: false;
|
|
786
|
+
isAutoincrement: false;
|
|
787
|
+
hasRuntimeDefault: false;
|
|
788
|
+
enumValues: undefined;
|
|
789
|
+
baseColumn: never;
|
|
790
|
+
identity: undefined;
|
|
791
|
+
generated: undefined;
|
|
792
|
+
}, {}, {}>;
|
|
680
793
|
projectId: import("drizzle-orm/pg-core").PgColumn<{
|
|
681
794
|
name: "project_id";
|
|
682
795
|
tableName: "workflow_definitions";
|
|
@@ -1225,7 +1338,9 @@ export declare function db(): NodePgDatabase<{
|
|
|
1225
1338
|
tableName: "sync_states";
|
|
1226
1339
|
dataType: "json";
|
|
1227
1340
|
columnType: "PgJsonb";
|
|
1228
|
-
data: import("../core/
|
|
1341
|
+
data: (Omit<import("../core/index.js").DefinitionSyncDiagnostic, "severity"> & {
|
|
1342
|
+
severity?: import("../core/index.js").DefinitionSyncDiagnostic['severity'];
|
|
1343
|
+
})[];
|
|
1229
1344
|
driverParam: unknown;
|
|
1230
1345
|
notNull: true;
|
|
1231
1346
|
hasDefault: true;
|
|
@@ -1237,7 +1352,9 @@ export declare function db(): NodePgDatabase<{
|
|
|
1237
1352
|
identity: undefined;
|
|
1238
1353
|
generated: undefined;
|
|
1239
1354
|
}, {}, {
|
|
1240
|
-
$type: import("../core/
|
|
1355
|
+
$type: (Omit<import("../core/index.js").DefinitionSyncDiagnostic, "severity"> & {
|
|
1356
|
+
severity?: import("../core/index.js").DefinitionSyncDiagnostic['severity'];
|
|
1357
|
+
})[];
|
|
1241
1358
|
}>;
|
|
1242
1359
|
startedAt: import("drizzle-orm/pg-core").PgColumn<{
|
|
1243
1360
|
name: "started_at";
|
|
@@ -1310,6 +1427,81 @@ export declare function db(): NodePgDatabase<{
|
|
|
1310
1427
|
};
|
|
1311
1428
|
dialect: 'pg';
|
|
1312
1429
|
}>;
|
|
1430
|
+
workflowWorkflows: import("drizzle-orm/pg-core").PgTableWithColumns<{
|
|
1431
|
+
name: "workflows";
|
|
1432
|
+
schema: undefined;
|
|
1433
|
+
columns: {
|
|
1434
|
+
id: import("drizzle-orm/pg-core").PgColumn<{
|
|
1435
|
+
name: "id";
|
|
1436
|
+
tableName: "workflows";
|
|
1437
|
+
dataType: "string";
|
|
1438
|
+
columnType: "PgUUID";
|
|
1439
|
+
data: string;
|
|
1440
|
+
driverParam: string;
|
|
1441
|
+
notNull: true;
|
|
1442
|
+
hasDefault: true;
|
|
1443
|
+
isPrimaryKey: true;
|
|
1444
|
+
isAutoincrement: false;
|
|
1445
|
+
hasRuntimeDefault: false;
|
|
1446
|
+
enumValues: undefined;
|
|
1447
|
+
baseColumn: never;
|
|
1448
|
+
identity: undefined;
|
|
1449
|
+
generated: undefined;
|
|
1450
|
+
}, {}, {}>;
|
|
1451
|
+
projectId: import("drizzle-orm/pg-core").PgColumn<{
|
|
1452
|
+
name: "project_id";
|
|
1453
|
+
tableName: "workflows";
|
|
1454
|
+
dataType: "string";
|
|
1455
|
+
columnType: "PgUUID";
|
|
1456
|
+
data: string;
|
|
1457
|
+
driverParam: string;
|
|
1458
|
+
notNull: true;
|
|
1459
|
+
hasDefault: false;
|
|
1460
|
+
isPrimaryKey: false;
|
|
1461
|
+
isAutoincrement: false;
|
|
1462
|
+
hasRuntimeDefault: false;
|
|
1463
|
+
enumValues: undefined;
|
|
1464
|
+
baseColumn: never;
|
|
1465
|
+
identity: undefined;
|
|
1466
|
+
generated: undefined;
|
|
1467
|
+
}, {}, {}>;
|
|
1468
|
+
configPath: import("drizzle-orm/pg-core").PgColumn<{
|
|
1469
|
+
name: "config_path";
|
|
1470
|
+
tableName: "workflows";
|
|
1471
|
+
dataType: "string";
|
|
1472
|
+
columnType: "PgText";
|
|
1473
|
+
data: string;
|
|
1474
|
+
driverParam: string;
|
|
1475
|
+
notNull: false;
|
|
1476
|
+
hasDefault: false;
|
|
1477
|
+
isPrimaryKey: false;
|
|
1478
|
+
isAutoincrement: false;
|
|
1479
|
+
hasRuntimeDefault: false;
|
|
1480
|
+
enumValues: [string, ...string[]];
|
|
1481
|
+
baseColumn: never;
|
|
1482
|
+
identity: undefined;
|
|
1483
|
+
generated: undefined;
|
|
1484
|
+
}, {}, {}>;
|
|
1485
|
+
createdAt: import("drizzle-orm/pg-core").PgColumn<{
|
|
1486
|
+
name: "created_at";
|
|
1487
|
+
tableName: "workflows";
|
|
1488
|
+
dataType: "date";
|
|
1489
|
+
columnType: "PgTimestamp";
|
|
1490
|
+
data: Date;
|
|
1491
|
+
driverParam: string;
|
|
1492
|
+
notNull: true;
|
|
1493
|
+
hasDefault: true;
|
|
1494
|
+
isPrimaryKey: false;
|
|
1495
|
+
isAutoincrement: false;
|
|
1496
|
+
hasRuntimeDefault: false;
|
|
1497
|
+
enumValues: undefined;
|
|
1498
|
+
baseColumn: never;
|
|
1499
|
+
identity: undefined;
|
|
1500
|
+
generated: undefined;
|
|
1501
|
+
}, {}, {}>;
|
|
1502
|
+
};
|
|
1503
|
+
dialect: 'pg';
|
|
1504
|
+
}>;
|
|
1313
1505
|
}>;
|
|
1314
1506
|
export declare function closeDb(): void;
|
|
1315
1507
|
//# sourceMappingURL=db.d.ts.map
|
package/dist/db/db.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"db.d.ts","sourceRoot":"","sources":["../../src/db/db.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,KAAK,cAAc,EAAC,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"db.d.ts","sourceRoot":"","sources":["../../src/db/db.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,KAAK,cAAc,EAAC,MAAM,uBAAuB,CAAC;AAOnE,eAAO,MAAM,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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ox/node-postgres';
|
|
|
3
3
|
import { workflowDefinitions } from './schema/definitions.js';
|
|
4
4
|
import { definitionsOutbox } from './schema/outbox.js';
|
|
5
5
|
import { definitionSyncStates } from './schema/sync-states.js';
|
|
6
|
+
import { workflowWorkflows } from './schema/workflows.js';
|
|
6
7
|
export const schema = {
|
|
7
8
|
workflowDefinitions,
|
|
8
9
|
definitionsOutbox,
|
|
9
|
-
definitionSyncStates
|
|
10
|
+
definitionSyncStates,
|
|
11
|
+
workflowWorkflows
|
|
10
12
|
};
|
|
11
13
|
let _db;
|
|
12
14
|
export function db() {
|
package/dist/db/db.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/db/db.ts"],"sourcesContent":["import {drizzle, type NodePgDatabase} from '@shipfox/node-drizzle';\nimport {pgClient} from '@shipfox/node-postgres';\nimport {workflowDefinitions} from './schema/definitions.js';\nimport {definitionsOutbox} from './schema/outbox.js';\nimport {definitionSyncStates} from './schema/sync-states.js';\n\nexport const schema = {workflowDefinitions
|
|
1
|
+
{"version":3,"sources":["../../src/db/db.ts"],"sourcesContent":["import {drizzle, type NodePgDatabase} from '@shipfox/node-drizzle';\nimport {pgClient} from '@shipfox/node-postgres';\nimport {workflowDefinitions} from './schema/definitions.js';\nimport {definitionsOutbox} from './schema/outbox.js';\nimport {definitionSyncStates} from './schema/sync-states.js';\nimport {workflowWorkflows} from './schema/workflows.js';\n\nexport const schema = {\n workflowDefinitions,\n definitionsOutbox,\n definitionSyncStates,\n workflowWorkflows,\n};\n\nlet _db: NodePgDatabase<typeof schema> | undefined;\n\nexport function db() {\n if (!_db) _db = drizzle(pgClient(), {schema});\n return _db;\n}\n\nexport function closeDb(): void {\n _db = undefined;\n}\n"],"names":["drizzle","pgClient","workflowDefinitions","definitionsOutbox","definitionSyncStates","workflowWorkflows","schema","_db","db","closeDb","undefined"],"mappings":"AAAA,SAAQA,OAAO,QAA4B,wBAAwB;AACnE,SAAQC,QAAQ,QAAO,yBAAyB;AAChD,SAAQC,mBAAmB,QAAO,0BAA0B;AAC5D,SAAQC,iBAAiB,QAAO,qBAAqB;AACrD,SAAQC,oBAAoB,QAAO,0BAA0B;AAC7D,SAAQC,iBAAiB,QAAO,wBAAwB;AAExD,OAAO,MAAMC,SAAS;IACpBJ;IACAC;IACAC;IACAC;AACF,EAAE;AAEF,IAAIE;AAEJ,OAAO,SAASC;IACd,IAAI,CAACD,KAAKA,MAAMP,QAAQC,YAAY;QAACK;IAAM;IAC3C,OAAOC;AACT;AAEA,OAAO,SAASE;IACdF,MAAMG;AACR"}
|
|
@@ -2,7 +2,9 @@ export function definitionTriggersFor(model) {
|
|
|
2
2
|
return Object.fromEntries(model.triggers.map((trigger)=>{
|
|
3
3
|
const dto = {
|
|
4
4
|
source: trigger.source,
|
|
5
|
-
event:
|
|
5
|
+
...trigger.event === undefined ? {} : {
|
|
6
|
+
event: trigger.event
|
|
7
|
+
}
|
|
6
8
|
};
|
|
7
9
|
if (trigger.inputs !== undefined) dto.with = trigger.inputs;
|
|
8
10
|
if (trigger.filter !== undefined) dto.filter = trigger.filter;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/db/definition-triggers.ts"],"sourcesContent":["import type {TriggerDto} from '@shipfox/api-definitions-dto';\nimport type {WorkflowModel} from '#core/entities/workflow-model.js';\n\nexport function definitionTriggersFor(model: WorkflowModel): Record<string, TriggerDto> {\n return Object.fromEntries(\n model.triggers.map((trigger) => {\n const dto: TriggerDto = {\n source: trigger.source,\n event: trigger.event,\n };\n if (trigger.inputs !== undefined) dto.with = trigger.inputs;\n if (trigger.filter !== undefined) dto.filter = trigger.filter;\n if (trigger.config !== undefined) dto.config = trigger.config;\n return [trigger.key, dto];\n }),\n );\n}\n"],"names":["definitionTriggersFor","model","Object","fromEntries","triggers","map","trigger","dto","source","event","
|
|
1
|
+
{"version":3,"sources":["../../src/db/definition-triggers.ts"],"sourcesContent":["import type {TriggerDto} from '@shipfox/api-definitions-dto';\nimport type {WorkflowModel} from '#core/entities/workflow-model.js';\n\nexport function definitionTriggersFor(model: WorkflowModel): Record<string, TriggerDto> {\n return Object.fromEntries(\n model.triggers.map((trigger) => {\n const dto: TriggerDto = {\n source: trigger.source,\n ...(trigger.event === undefined ? {} : {event: trigger.event}),\n };\n if (trigger.inputs !== undefined) dto.with = trigger.inputs;\n if (trigger.filter !== undefined) dto.filter = trigger.filter;\n if (trigger.config !== undefined) dto.config = trigger.config;\n return [trigger.key, dto];\n }),\n );\n}\n"],"names":["definitionTriggersFor","model","Object","fromEntries","triggers","map","trigger","dto","source","event","undefined","inputs","with","filter","config","key"],"mappings":"AAGA,OAAO,SAASA,sBAAsBC,KAAoB;IACxD,OAAOC,OAAOC,WAAW,CACvBF,MAAMG,QAAQ,CAACC,GAAG,CAAC,CAACC;QAClB,MAAMC,MAAkB;YACtBC,QAAQF,QAAQE,MAAM;YACtB,GAAIF,QAAQG,KAAK,KAAKC,YAAY,CAAC,IAAI;gBAACD,OAAOH,QAAQG,KAAK;YAAA,CAAC;QAC/D;QACA,IAAIH,QAAQK,MAAM,KAAKD,WAAWH,IAAIK,IAAI,GAAGN,QAAQK,MAAM;QAC3D,IAAIL,QAAQO,MAAM,KAAKH,WAAWH,IAAIM,MAAM,GAAGP,QAAQO,MAAM;QAC7D,IAAIP,QAAQQ,MAAM,KAAKJ,WAAWH,IAAIO,MAAM,GAAGR,QAAQQ,MAAM;QAC7D,OAAO;YAACR,QAAQS,GAAG;YAAER;SAAI;IAC3B;AAEJ"}
|
package/dist/db/definitions.d.ts
CHANGED
|
@@ -15,7 +15,24 @@ export interface UpsertDefinitionParams {
|
|
|
15
15
|
ref?: string | undefined;
|
|
16
16
|
}
|
|
17
17
|
export declare function upsertDefinition(params: UpsertDefinitionParams): Promise<WorkflowDefinition>;
|
|
18
|
+
/**
|
|
19
|
+
* Finds or creates the workflow lineage for (projectId, configPath) outside a
|
|
20
|
+
* sync. A dev definition uses the lineage for run numbering without ever
|
|
21
|
+
* persisting a definition row or publishing a resolution event.
|
|
22
|
+
*/
|
|
23
|
+
export declare function findOrCreateWorkflowLineage(params: {
|
|
24
|
+
projectId: string;
|
|
25
|
+
configPath: string;
|
|
26
|
+
}): Promise<string>;
|
|
18
27
|
export declare function getDefinitionById(id: string): Promise<WorkflowDefinition | undefined>;
|
|
28
|
+
export declare function getWorkflowLineageById(id: string): Promise<{
|
|
29
|
+
id: string;
|
|
30
|
+
projectId: string;
|
|
31
|
+
} | undefined>;
|
|
32
|
+
export declare function getDefinitionByWorkflowId(params: {
|
|
33
|
+
workflowId: string;
|
|
34
|
+
ref: string;
|
|
35
|
+
}): Promise<WorkflowDefinition | undefined>;
|
|
19
36
|
export interface DefinitionCursor {
|
|
20
37
|
value: string;
|
|
21
38
|
id: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"definitions.d.ts","sourceRoot":"","sources":["../../src/db/definitions.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAC,gBAAgB,EAAC,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"definitions.d.ts","sourceRoot":"","sources":["../../src/db/definitions.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAC,gBAAgB,EAAC,MAAM,4BAA4B,CAAC;AAcjE,OAAO,KAAK,EACV,kBAAkB,EAElB,sBAAsB,EACvB,MAAM,uCAAuC,CAAC;AAC/C,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,kCAAkC,CAAC;AASpE,MAAM,WAAW,sBAAsB;IACrC,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IACvC,MAAM,CAAC,EAAE,QAAQ,GAAG,KAAK,GAAG,SAAS,CAAC;IACtC,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,gBAAgB,CAAC;IAC3B,KAAK,EAAE,aAAa,CAAC;IACrB,cAAc,CAA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/api-definitions-dto';
|
|
2
2
|
import { writeOutboxEvent } from '@shipfox/node-outbox';
|
|
3
|
-
import { and, asc, eq, gt, isNull, notInArray, or, sql } from 'drizzle-orm';
|
|
3
|
+
import { and, asc, eq, gt, inArray, isNotNull, isNull, notInArray, or, sql } from 'drizzle-orm';
|
|
4
4
|
import { db } from './db.js';
|
|
5
5
|
import { definitionTriggersFor } from './definition-triggers.js';
|
|
6
6
|
import { toDefinition, workflowDefinitions } from './schema/definitions.js';
|
|
7
7
|
import { definitionsOutbox } from './schema/outbox.js';
|
|
8
|
+
import { workflowWorkflows } from './schema/workflows.js';
|
|
9
|
+
/**
|
|
10
|
+
* Finds or creates the workflow lineage for (projectId, configPath) and returns
|
|
11
|
+
* its id. Pathless manual definitions share a project-scoped lineage because
|
|
12
|
+
* their request has no more specific stable key.
|
|
13
|
+
*/ async function findOrCreateWorkflow(tx, params) {
|
|
14
|
+
if (params.configPath === null) {
|
|
15
|
+
// Serialize the first pathless definition for a project so concurrent saves
|
|
16
|
+
// cannot create multiple project-scoped lineages.
|
|
17
|
+
await tx.execute(sql`SELECT pg_advisory_xact_lock(hashtextextended(${params.projectId}, 0))`);
|
|
18
|
+
const existing = await tx.select({
|
|
19
|
+
workflowId: workflowDefinitions.workflowId
|
|
20
|
+
}).from(workflowDefinitions).where(and(eq(workflowDefinitions.projectId, params.projectId), isNull(workflowDefinitions.configPath), eq(workflowDefinitions.source, 'manual'), isNotNull(workflowDefinitions.workflowId))).orderBy(asc(workflowDefinitions.createdAt), asc(workflowDefinitions.id)).limit(1);
|
|
21
|
+
const existingRow = existing[0];
|
|
22
|
+
if (existingRow?.workflowId) return existingRow.workflowId;
|
|
23
|
+
const inserted = await tx.insert(workflowWorkflows).values({
|
|
24
|
+
projectId: params.projectId,
|
|
25
|
+
configPath: null
|
|
26
|
+
}).onConflictDoNothing().returning({
|
|
27
|
+
id: workflowWorkflows.id
|
|
28
|
+
});
|
|
29
|
+
const insertedRow = inserted[0];
|
|
30
|
+
if (insertedRow) return insertedRow.id;
|
|
31
|
+
const existingLineage = await tx.select({
|
|
32
|
+
id: workflowWorkflows.id
|
|
33
|
+
}).from(workflowWorkflows).where(and(eq(workflowWorkflows.projectId, params.projectId), isNull(workflowWorkflows.configPath))).limit(1);
|
|
34
|
+
const existingLineageRow = existingLineage[0];
|
|
35
|
+
if (!existingLineageRow) {
|
|
36
|
+
throw new Error(`Pathless workflow lineage missing for project ${params.projectId}`);
|
|
37
|
+
}
|
|
38
|
+
return existingLineageRow.id;
|
|
39
|
+
}
|
|
40
|
+
const inserted = await tx.insert(workflowWorkflows).values({
|
|
41
|
+
projectId: params.projectId,
|
|
42
|
+
configPath: params.configPath
|
|
43
|
+
}).onConflictDoNothing().returning({
|
|
44
|
+
id: workflowWorkflows.id
|
|
45
|
+
});
|
|
46
|
+
const insertedRow = inserted[0];
|
|
47
|
+
if (insertedRow) return insertedRow.id;
|
|
48
|
+
const existing = await tx.select({
|
|
49
|
+
id: workflowWorkflows.id
|
|
50
|
+
}).from(workflowWorkflows).where(and(eq(workflowWorkflows.projectId, params.projectId), eq(workflowWorkflows.configPath, params.configPath))).limit(1);
|
|
51
|
+
const existingRow = existing[0];
|
|
52
|
+
if (!existingRow) {
|
|
53
|
+
throw new Error(`Workflow lineage upsert returned no row for project ${params.projectId} and config path ${params.configPath}`);
|
|
54
|
+
}
|
|
55
|
+
return existingRow.id;
|
|
56
|
+
}
|
|
57
|
+
async function findOrCreateWorkflows(tx, params) {
|
|
58
|
+
const configPaths = [
|
|
59
|
+
...new Set(params.configPaths)
|
|
60
|
+
].sort((left, right)=>left < right ? -1 : left > right ? 1 : 0);
|
|
61
|
+
if (configPaths.length === 0) return new Map();
|
|
62
|
+
await tx.insert(workflowWorkflows).values(configPaths.map((configPath)=>({
|
|
63
|
+
projectId: params.projectId,
|
|
64
|
+
configPath
|
|
65
|
+
}))).onConflictDoNothing();
|
|
66
|
+
const rows = await tx.select({
|
|
67
|
+
id: workflowWorkflows.id,
|
|
68
|
+
configPath: workflowWorkflows.configPath
|
|
69
|
+
}).from(workflowWorkflows).where(and(eq(workflowWorkflows.projectId, params.projectId), inArray(workflowWorkflows.configPath, configPaths)));
|
|
70
|
+
const workflowIds = new Map();
|
|
71
|
+
for (const row of rows){
|
|
72
|
+
if (row.configPath !== null) workflowIds.set(row.configPath, row.id);
|
|
73
|
+
}
|
|
74
|
+
for (const configPath of configPaths){
|
|
75
|
+
if (!workflowIds.has(configPath)) {
|
|
76
|
+
throw new Error(`Workflow lineage upsert returned no row for project ${params.projectId} and config path ${configPath}`);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return workflowIds;
|
|
80
|
+
}
|
|
81
|
+
async function ensureWorkflowId(tx, row) {
|
|
82
|
+
if (row.workflowId !== null) return row.workflowId;
|
|
83
|
+
const workflowId = await findOrCreateWorkflow(tx, {
|
|
84
|
+
projectId: row.projectId,
|
|
85
|
+
configPath: row.configPath
|
|
86
|
+
});
|
|
87
|
+
const updated = await tx.update(workflowDefinitions).set({
|
|
88
|
+
workflowId
|
|
89
|
+
}).where(and(eq(workflowDefinitions.id, row.id), isNull(workflowDefinitions.workflowId))).returning({
|
|
90
|
+
workflowId: workflowDefinitions.workflowId
|
|
91
|
+
});
|
|
92
|
+
const updatedRow = updated[0];
|
|
93
|
+
if (updatedRow?.workflowId) return updatedRow.workflowId;
|
|
94
|
+
const current = await tx.select({
|
|
95
|
+
workflowId: workflowDefinitions.workflowId
|
|
96
|
+
}).from(workflowDefinitions).where(eq(workflowDefinitions.id, row.id)).limit(1);
|
|
97
|
+
const currentRow = current[0];
|
|
98
|
+
if (!currentRow?.workflowId) {
|
|
99
|
+
throw new Error(`Definition ${row.id} still has no workflow lineage after reconciliation`);
|
|
100
|
+
}
|
|
101
|
+
return currentRow.workflowId;
|
|
102
|
+
}
|
|
8
103
|
function buildUpsertQuery(tx, params) {
|
|
9
104
|
const source = params.source ?? 'manual';
|
|
10
105
|
if (source === 'vcs' && !params.configPath) {
|
|
@@ -22,6 +117,7 @@ function buildUpsertQuery(tx, params) {
|
|
|
22
117
|
sourceSnapshot: params.sourceSnapshot ?? null
|
|
23
118
|
};
|
|
24
119
|
const set = {
|
|
120
|
+
workflowId: params.workflowId,
|
|
25
121
|
name: params.name,
|
|
26
122
|
source,
|
|
27
123
|
definition,
|
|
@@ -32,6 +128,7 @@ function buildUpsertQuery(tx, params) {
|
|
|
32
128
|
};
|
|
33
129
|
const values = {
|
|
34
130
|
projectId: params.projectId,
|
|
131
|
+
workflowId: params.workflowId,
|
|
35
132
|
configPath: params.configPath ?? null,
|
|
36
133
|
source,
|
|
37
134
|
sha: params.sha ?? null,
|
|
@@ -73,7 +170,14 @@ function buildUpsertQuery(tx, params) {
|
|
|
73
170
|
}
|
|
74
171
|
export async function upsertDefinition(params) {
|
|
75
172
|
return await db().transaction(async (tx)=>{
|
|
76
|
-
const
|
|
173
|
+
const workflowId = await findOrCreateWorkflow(tx, {
|
|
174
|
+
projectId: params.projectId,
|
|
175
|
+
configPath: params.configPath ?? null
|
|
176
|
+
});
|
|
177
|
+
const rows = await buildUpsertQuery(tx, {
|
|
178
|
+
...params,
|
|
179
|
+
workflowId
|
|
180
|
+
});
|
|
77
181
|
const row = rows[0];
|
|
78
182
|
if (!row) throw new Error('Upsert returned no rows');
|
|
79
183
|
await writeOutboxEvent(tx, definitionsOutbox, {
|
|
@@ -89,34 +193,76 @@ export async function upsertDefinition(params) {
|
|
|
89
193
|
return toDefinition(row);
|
|
90
194
|
});
|
|
91
195
|
}
|
|
196
|
+
/**
|
|
197
|
+
* Finds or creates the workflow lineage for (projectId, configPath) outside a
|
|
198
|
+
* sync. A dev definition uses the lineage for run numbering without ever
|
|
199
|
+
* persisting a definition row or publishing a resolution event.
|
|
200
|
+
*/ export async function findOrCreateWorkflowLineage(params) {
|
|
201
|
+
return await db().transaction(async (tx)=>{
|
|
202
|
+
return await findOrCreateWorkflow(tx, params);
|
|
203
|
+
});
|
|
204
|
+
}
|
|
92
205
|
export async function getDefinitionById(id) {
|
|
93
|
-
|
|
206
|
+
return await db().transaction(async (tx)=>{
|
|
207
|
+
const rows = await tx.select().from(workflowDefinitions).where(and(eq(workflowDefinitions.id, id), isNull(workflowDefinitions.deletedAt))).limit(1);
|
|
208
|
+
const row = rows[0];
|
|
209
|
+
if (row) {
|
|
210
|
+
const workflowId = await ensureWorkflowId(tx, row);
|
|
211
|
+
return toDefinition({
|
|
212
|
+
...row,
|
|
213
|
+
workflowId
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
return undefined;
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
export async function getWorkflowLineageById(id) {
|
|
220
|
+
const rows = await db().select({
|
|
221
|
+
id: workflowWorkflows.id,
|
|
222
|
+
projectId: workflowWorkflows.projectId
|
|
223
|
+
}).from(workflowWorkflows).where(eq(workflowWorkflows.id, id)).limit(1);
|
|
224
|
+
return rows[0];
|
|
225
|
+
}
|
|
226
|
+
export async function getDefinitionByWorkflowId(params) {
|
|
227
|
+
const rows = await db().select().from(workflowDefinitions).where(and(eq(workflowDefinitions.workflowId, params.workflowId), eq(workflowDefinitions.ref, params.ref), isNull(workflowDefinitions.deletedAt))).limit(1);
|
|
94
228
|
const row = rows[0];
|
|
95
|
-
|
|
96
|
-
|
|
229
|
+
return row ? toDefinition({
|
|
230
|
+
...row,
|
|
231
|
+
workflowId: params.workflowId
|
|
232
|
+
}) : undefined;
|
|
97
233
|
}
|
|
98
234
|
function cursorWhere(cursor) {
|
|
99
235
|
if (!cursor) return undefined;
|
|
100
236
|
return or(gt(workflowDefinitions.name, cursor.value), and(eq(workflowDefinitions.name, cursor.value), gt(workflowDefinitions.id, cursor.id)));
|
|
101
237
|
}
|
|
102
238
|
export async function listDefinitions(params) {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
definitions
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
239
|
+
return await db().transaction(async (tx)=>{
|
|
240
|
+
const conditions = [
|
|
241
|
+
eq(workflowDefinitions.projectId, params.projectId),
|
|
242
|
+
isNull(workflowDefinitions.deletedAt)
|
|
243
|
+
];
|
|
244
|
+
const cursorCondition = cursorWhere(params.cursor);
|
|
245
|
+
if (cursorCondition) conditions.push(cursorCondition);
|
|
246
|
+
const rows = await tx.select().from(workflowDefinitions).where(and(...conditions)).orderBy(asc(workflowDefinitions.name), asc(workflowDefinitions.id)).limit(params.limit + 1);
|
|
247
|
+
const hasMore = rows.length > params.limit;
|
|
248
|
+
const pageRows = hasMore ? rows.slice(0, params.limit) : rows;
|
|
249
|
+
const last = pageRows.at(-1);
|
|
250
|
+
const definitions = [];
|
|
251
|
+
for (const row of pageRows){
|
|
252
|
+
const workflowId = await ensureWorkflowId(tx, row);
|
|
253
|
+
definitions.push(toDefinition({
|
|
254
|
+
...row,
|
|
255
|
+
workflowId
|
|
256
|
+
}));
|
|
257
|
+
}
|
|
258
|
+
return {
|
|
259
|
+
definitions,
|
|
260
|
+
nextCursor: hasMore && last ? {
|
|
261
|
+
value: last.name,
|
|
262
|
+
id: last.id
|
|
263
|
+
} : null
|
|
264
|
+
};
|
|
265
|
+
});
|
|
120
266
|
}
|
|
121
267
|
export async function listDefinitionsByProject(projectId) {
|
|
122
268
|
const result = await listDefinitions({
|
|
@@ -153,16 +299,37 @@ export async function softDeleteVcsDefinitionsNotIn(params) {
|
|
|
153
299
|
export async function applyVcsDefinitionsBatch(params) {
|
|
154
300
|
return await db().transaction(async (tx)=>{
|
|
155
301
|
let appliedCount = 0;
|
|
302
|
+
const prepared = [];
|
|
156
303
|
for (const item of params.upserts){
|
|
157
304
|
const existing = await tx.select({
|
|
158
305
|
contentHash: workflowDefinitions.contentHash,
|
|
159
|
-
deletedAt: workflowDefinitions.deletedAt
|
|
306
|
+
deletedAt: workflowDefinitions.deletedAt,
|
|
307
|
+
workflowId: workflowDefinitions.workflowId
|
|
160
308
|
}).from(workflowDefinitions).where(and(eq(workflowDefinitions.projectId, params.projectId), eq(workflowDefinitions.ref, params.ref), eq(workflowDefinitions.configPath, item.configPath))).limit(1);
|
|
161
309
|
const previous = existing[0];
|
|
162
310
|
const unchanged = previous !== undefined && previous.deletedAt === null && previous.contentHash === item.contentHash;
|
|
311
|
+
prepared.push({
|
|
312
|
+
item,
|
|
313
|
+
unchanged,
|
|
314
|
+
workflowId: previous?.workflowId
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
const workflowIds = await findOrCreateWorkflows(tx, {
|
|
318
|
+
projectId: params.projectId,
|
|
319
|
+
configPaths: prepared.filter(({ unchanged })=>!unchanged).map(({ item })=>item.configPath)
|
|
320
|
+
});
|
|
321
|
+
for (const { item, unchanged, workflowId: previousWorkflowId } of prepared){
|
|
322
|
+
const workflowId = unchanged ? previousWorkflowId ?? await findOrCreateWorkflow(tx, {
|
|
323
|
+
projectId: params.projectId,
|
|
324
|
+
configPath: item.configPath
|
|
325
|
+
}) : workflowIds.get(item.configPath);
|
|
326
|
+
if (!workflowId) {
|
|
327
|
+
throw new Error(`Workflow lineage missing for project ${params.projectId} and config path ${item.configPath}`);
|
|
328
|
+
}
|
|
163
329
|
const rows = await buildUpsertQuery(tx, {
|
|
164
330
|
projectId: params.projectId,
|
|
165
331
|
workspaceId: params.workspaceId,
|
|
332
|
+
workflowId,
|
|
166
333
|
configPath: item.configPath,
|
|
167
334
|
source: 'vcs',
|
|
168
335
|
ref: params.ref,
|