@shipfox/api-definitions 2.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 +2 -0
- package/.turbo/turbo-type$colon$emit.log +1 -0
- package/.turbo/turbo-type.log +1 -0
- package/CHANGELOG.md +215 -0
- package/LICENSE +21 -0
- package/dist/config.d.ts +10 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +35 -0
- package/dist/config.js.map +1 -0
- package/dist/core/entities/index.d.ts +5 -0
- package/dist/core/entities/index.d.ts.map +1 -0
- package/dist/core/entities/index.js +6 -0
- package/dist/core/entities/index.js.map +1 -0
- package/dist/core/entities/integration-context.d.ts +11 -0
- package/dist/core/entities/integration-context.d.ts.map +1 -0
- package/dist/core/entities/integration-context.js +3 -0
- package/dist/core/entities/integration-context.js.map +1 -0
- package/dist/core/entities/sync-state.d.ts +19 -0
- package/dist/core/entities/sync-state.d.ts.map +1 -0
- package/dist/core/entities/sync-state.js +20 -0
- package/dist/core/entities/sync-state.js.map +1 -0
- package/dist/core/entities/workflow-definition.d.ts +35 -0
- package/dist/core/entities/workflow-definition.d.ts.map +1 -0
- package/dist/core/entities/workflow-definition.js +3 -0
- package/dist/core/entities/workflow-definition.js.map +1 -0
- package/dist/core/entities/workflow-model.d.ts +138 -0
- package/dist/core/entities/workflow-model.d.ts.map +1 -0
- package/dist/core/entities/workflow-model.js +3 -0
- package/dist/core/entities/workflow-model.js.map +1 -0
- package/dist/core/errors.d.ts +10 -0
- package/dist/core/errors.d.ts.map +1 -0
- package/dist/core/errors.js +14 -0
- package/dist/core/errors.js.map +1 -0
- package/dist/core/has-agent-step-integrations.d.ts +3 -0
- package/dist/core/has-agent-step-integrations.d.ts.map +1 -0
- package/dist/core/has-agent-step-integrations.js +5 -0
- package/dist/core/has-agent-step-integrations.js.map +1 -0
- package/dist/core/index.d.ts +9 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +9 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/parse-definition.d.ts +9 -0
- package/dist/core/parse-definition.d.ts.map +1 -0
- package/dist/core/parse-definition.js +17 -0
- package/dist/core/parse-definition.js.map +1 -0
- package/dist/core/sync-definitions.d.ts +44 -0
- package/dist/core/sync-definitions.d.ts.map +1 -0
- package/dist/core/sync-definitions.js +140 -0
- package/dist/core/sync-definitions.js.map +1 -0
- package/dist/core/validate-definition.d.ts +20 -0
- package/dist/core/validate-definition.d.ts.map +1 -0
- package/dist/core/validate-definition.js +61 -0
- package/dist/core/validate-definition.js.map +1 -0
- package/dist/core/workflow-model/constants.d.ts +2 -0
- package/dist/core/workflow-model/constants.d.ts.map +1 -0
- package/dist/core/workflow-model/constants.js +3 -0
- package/dist/core/workflow-model/constants.js.map +1 -0
- package/dist/core/workflow-model/cron-trigger.d.ts +16 -0
- package/dist/core/workflow-model/cron-trigger.d.ts.map +1 -0
- package/dist/core/workflow-model/cron-trigger.js +85 -0
- package/dist/core/workflow-model/cron-trigger.js.map +1 -0
- package/dist/core/workflow-model/index.d.ts +4 -0
- package/dist/core/workflow-model/index.d.ts.map +1 -0
- package/dist/core/workflow-model/index.js +5 -0
- package/dist/core/workflow-model/index.js.map +1 -0
- package/dist/core/workflow-model/invalid-workflow-model-error.d.ts +15 -0
- package/dist/core/workflow-model/invalid-workflow-model-error.d.ts.map +1 -0
- package/dist/core/workflow-model/invalid-workflow-model-error.js +9 -0
- package/dist/core/workflow-model/invalid-workflow-model-error.js.map +1 -0
- package/dist/core/workflow-model/map-job-ids.d.ts +4 -0
- package/dist/core/workflow-model/map-job-ids.d.ts.map +1 -0
- package/dist/core/workflow-model/map-job-ids.js +33 -0
- package/dist/core/workflow-model/map-job-ids.js.map +1 -0
- package/dist/core/workflow-model/normalize-agent-integrations.d.ts +12 -0
- package/dist/core/workflow-model/normalize-agent-integrations.d.ts.map +1 -0
- package/dist/core/workflow-model/normalize-agent-integrations.js +157 -0
- package/dist/core/workflow-model/normalize-agent-integrations.js.map +1 -0
- package/dist/core/workflow-model/normalize-dependencies.d.ts +6 -0
- package/dist/core/workflow-model/normalize-dependencies.d.ts.map +1 -0
- package/dist/core/workflow-model/normalize-dependencies.js +119 -0
- package/dist/core/workflow-model/normalize-dependencies.js.map +1 -0
- package/dist/core/workflow-model/normalize-env.d.ts +17 -0
- package/dist/core/workflow-model/normalize-env.d.ts.map +1 -0
- package/dist/core/workflow-model/normalize-env.js +40 -0
- package/dist/core/workflow-model/normalize-env.js.map +1 -0
- package/dist/core/workflow-model/normalize-if-condition.d.ts +14 -0
- package/dist/core/workflow-model/normalize-if-condition.d.ts.map +1 -0
- package/dist/core/workflow-model/normalize-if-condition.js +75 -0
- package/dist/core/workflow-model/normalize-if-condition.js.map +1 -0
- package/dist/core/workflow-model/normalize-job-checkout.d.ts +5 -0
- package/dist/core/workflow-model/normalize-job-checkout.d.ts.map +1 -0
- package/dist/core/workflow-model/normalize-job-checkout.js +16 -0
- package/dist/core/workflow-model/normalize-job-checkout.js.map +1 -0
- package/dist/core/workflow-model/normalize-job-listening.d.ts +10 -0
- package/dist/core/workflow-model/normalize-job-listening.d.ts.map +1 -0
- package/dist/core/workflow-model/normalize-job-listening.js +125 -0
- package/dist/core/workflow-model/normalize-job-listening.js.map +1 -0
- package/dist/core/workflow-model/normalize-job-success.d.ts +11 -0
- package/dist/core/workflow-model/normalize-job-success.d.ts.map +1 -0
- package/dist/core/workflow-model/normalize-job-success.js +23 -0
- package/dist/core/workflow-model/normalize-job-success.js.map +1 -0
- package/dist/core/workflow-model/normalize-jobs.d.ts +12 -0
- package/dist/core/workflow-model/normalize-jobs.d.ts.map +1 -0
- package/dist/core/workflow-model/normalize-jobs.js +935 -0
- package/dist/core/workflow-model/normalize-jobs.js.map +1 -0
- package/dist/core/workflow-model/normalize-needs.d.ts +2 -0
- package/dist/core/workflow-model/normalize-needs.d.ts.map +1 -0
- package/dist/core/workflow-model/normalize-needs.js +16 -0
- package/dist/core/workflow-model/normalize-needs.js.map +1 -0
- package/dist/core/workflow-model/normalize-step-gate.d.ts +15 -0
- package/dist/core/workflow-model/normalize-step-gate.d.ts.map +1 -0
- package/dist/core/workflow-model/normalize-step-gate.js +89 -0
- package/dist/core/workflow-model/normalize-step-gate.js.map +1 -0
- package/dist/core/workflow-model/normalize-step-outputs.d.ts +10 -0
- package/dist/core/workflow-model/normalize-step-outputs.d.ts.map +1 -0
- package/dist/core/workflow-model/normalize-step-outputs.js +32 -0
- package/dist/core/workflow-model/normalize-step-outputs.js.map +1 -0
- package/dist/core/workflow-model/normalize-triggers.d.ts +11 -0
- package/dist/core/workflow-model/normalize-triggers.d.ts.map +1 -0
- package/dist/core/workflow-model/normalize-triggers.js +128 -0
- package/dist/core/workflow-model/normalize-triggers.js.map +1 -0
- package/dist/core/workflow-model/normalize-workflow-document.d.ts +11 -0
- package/dist/core/workflow-model/normalize-workflow-document.d.ts.map +1 -0
- package/dist/core/workflow-model/normalize-workflow-document.js +43 -0
- package/dist/core/workflow-model/normalize-workflow-document.js.map +1 -0
- package/dist/core/workflow-model/parse-duration-ms.d.ts +11 -0
- package/dist/core/workflow-model/parse-duration-ms.d.ts.map +1 -0
- package/dist/core/workflow-model/parse-duration-ms.js +47 -0
- package/dist/core/workflow-model/parse-duration-ms.js.map +1 -0
- package/dist/core/workflow-model/parse-interpolation-field.d.ts +14 -0
- package/dist/core/workflow-model/parse-interpolation-field.d.ts.map +1 -0
- package/dist/core/workflow-model/parse-interpolation-field.js +377 -0
- package/dist/core/workflow-model/parse-interpolation-field.js.map +1 -0
- package/dist/core/workflow-model/stable-id.d.ts +2 -0
- package/dist/core/workflow-model/stable-id.d.ts.map +1 -0
- package/dist/core/workflow-model/stable-id.js +8 -0
- package/dist/core/workflow-model/stable-id.js.map +1 -0
- package/dist/core/workflow-model/validate-job-references.d.ts +10 -0
- package/dist/core/workflow-model/validate-job-references.d.ts.map +1 -0
- package/dist/core/workflow-model/validate-job-references.js +42 -0
- package/dist/core/workflow-model/validate-job-references.js.map +1 -0
- package/dist/core/workflow-model/validate-predicate-expression.d.ts +14 -0
- package/dist/core/workflow-model/validate-predicate-expression.d.ts.map +1 -0
- package/dist/core/workflow-model/validate-predicate-expression.js +273 -0
- package/dist/core/workflow-model/validate-predicate-expression.js.map +1 -0
- package/dist/core/workflow-model/validation-issue.d.ts +8 -0
- package/dist/core/workflow-model/validation-issue.d.ts.map +1 -0
- package/dist/core/workflow-model/validation-issue.js +17 -0
- package/dist/core/workflow-model/validation-issue.js.map +1 -0
- package/dist/core/workflow-model/workflow-field-label.d.ts +3 -0
- package/dist/core/workflow-model/workflow-field-label.d.ts.map +1 -0
- package/dist/core/workflow-model/workflow-field-label.js +47 -0
- package/dist/core/workflow-model/workflow-field-label.js.map +1 -0
- package/dist/core/workflow-yaml/index.d.ts +3 -0
- package/dist/core/workflow-yaml/index.d.ts.map +1 -0
- package/dist/core/workflow-yaml/index.js +4 -0
- package/dist/core/workflow-yaml/index.js.map +1 -0
- package/dist/core/workflow-yaml/invalid-workflow-yaml-error.d.ts +16 -0
- package/dist/core/workflow-yaml/invalid-workflow-yaml-error.d.ts.map +1 -0
- package/dist/core/workflow-yaml/invalid-workflow-yaml-error.js +12 -0
- package/dist/core/workflow-yaml/invalid-workflow-yaml-error.js.map +1 -0
- package/dist/core/workflow-yaml/parse-workflow-yaml.d.ts +9 -0
- package/dist/core/workflow-yaml/parse-workflow-yaml.d.ts.map +1 -0
- package/dist/core/workflow-yaml/parse-workflow-yaml.js +52 -0
- package/dist/core/workflow-yaml/parse-workflow-yaml.js.map +1 -0
- package/dist/core/workflow-yaml/source-locations.d.ts +3 -0
- package/dist/core/workflow-yaml/source-locations.d.ts.map +1 -0
- package/dist/core/workflow-yaml/source-locations.js +48 -0
- package/dist/core/workflow-yaml/source-locations.js.map +1 -0
- package/dist/db/db.d.ts +1277 -0
- package/dist/db/db.d.ts.map +1 -0
- package/dist/db/db.js +22 -0
- package/dist/db/db.js.map +1 -0
- package/dist/db/definition-triggers.d.ts +4 -0
- package/dist/db/definition-triggers.d.ts.map +1 -0
- package/dist/db/definition-triggers.js +17 -0
- package/dist/db/definition-triggers.js.map +1 -0
- package/dist/db/definitions.d.ts +63 -0
- package/dist/db/definitions.d.ts.map +1 -0
- package/dist/db/definitions.js +208 -0
- package/dist/db/definitions.js.map +1 -0
- package/dist/db/index.d.ts +8 -0
- package/dist/db/index.d.ts.map +1 -0
- package/dist/db/index.js +10 -0
- package/dist/db/index.js.map +1 -0
- package/dist/db/schema/common.d.ts +2 -0
- package/dist/db/schema/common.d.ts.map +1 -0
- package/dist/db/schema/common.js +4 -0
- package/dist/db/schema/common.js.map +1 -0
- package/dist/db/schema/definitions.d.ts +237 -0
- package/dist/db/schema/definitions.d.ts.map +1 -0
- package/dist/db/schema/definitions.js +63 -0
- package/dist/db/schema/definitions.js.map +1 -0
- package/dist/db/schema/outbox.d.ts +195 -0
- package/dist/db/schema/outbox.d.ts.map +1 -0
- package/dist/db/schema/outbox.js +5 -0
- package/dist/db/schema/outbox.js.map +1 -0
- package/dist/db/schema/sync-states.d.ts +218 -0
- package/dist/db/schema/sync-states.d.ts.map +1 -0
- package/dist/db/schema/sync-states.js +68 -0
- package/dist/db/schema/sync-states.js.map +1 -0
- package/dist/db/sync-states.d.ts +21 -0
- package/dist/db/sync-states.d.ts.map +1 -0
- package/dist/db/sync-states.js +47 -0
- package/dist/db/sync-states.js.map +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +63 -0
- package/dist/index.js.map +1 -0
- package/dist/presentation/dto/definition.d.ts +6 -0
- package/dist/presentation/dto/definition.d.ts.map +1 -0
- package/dist/presentation/dto/definition.js +35 -0
- package/dist/presentation/dto/definition.js.map +1 -0
- package/dist/presentation/dto/index.d.ts +2 -0
- package/dist/presentation/dto/index.d.ts.map +1 -0
- package/dist/presentation/dto/index.js +3 -0
- package/dist/presentation/dto/index.js.map +1 -0
- package/dist/presentation/index.d.ts +2 -0
- package/dist/presentation/index.d.ts.map +1 -0
- package/dist/presentation/index.js +3 -0
- package/dist/presentation/index.js.map +1 -0
- package/dist/presentation/routes/create-definition.d.ts +9 -0
- package/dist/presentation/routes/create-definition.d.ts.map +1 -0
- package/dist/presentation/routes/create-definition.js +76 -0
- package/dist/presentation/routes/create-definition.js.map +1 -0
- package/dist/presentation/routes/get-definition.d.ts +2 -0
- package/dist/presentation/routes/get-definition.d.ts.map +1 -0
- package/dist/presentation/routes/get-definition.js +43 -0
- package/dist/presentation/routes/get-definition.js.map +1 -0
- package/dist/presentation/routes/index.d.ts +7 -0
- package/dist/presentation/routes/index.d.ts.map +1 -0
- package/dist/presentation/routes/index.js +22 -0
- package/dist/presentation/routes/index.js.map +1 -0
- package/dist/presentation/routes/list-definitions.d.ts +2 -0
- package/dist/presentation/routes/list-definitions.d.ts.map +1 -0
- package/dist/presentation/routes/list-definitions.js +56 -0
- package/dist/presentation/routes/list-definitions.js.map +1 -0
- package/dist/presentation/routes/validate-definition.d.ts +2 -0
- package/dist/presentation/routes/validate-definition.d.ts.map +1 -0
- package/dist/presentation/routes/validate-definition.js +43 -0
- package/dist/presentation/routes/validate-definition.js.map +1 -0
- package/dist/presentation/subscribers/index.d.ts +3 -0
- package/dist/presentation/subscribers/index.d.ts.map +1 -0
- package/dist/presentation/subscribers/index.js +4 -0
- package/dist/presentation/subscribers/index.js.map +1 -0
- package/dist/presentation/subscribers/on-project-source-bound.d.ts +3 -0
- package/dist/presentation/subscribers/on-project-source-bound.d.ts.map +1 -0
- package/dist/presentation/subscribers/on-project-source-bound.js +11 -0
- package/dist/presentation/subscribers/on-project-source-bound.js.map +1 -0
- package/dist/presentation/subscribers/on-project-source-commit-observed.d.ts +3 -0
- package/dist/presentation/subscribers/on-project-source-commit-observed.d.ts.map +1 -0
- package/dist/presentation/subscribers/on-project-source-commit-observed.js +13 -0
- package/dist/presentation/subscribers/on-project-source-commit-observed.js.map +1 -0
- package/dist/presentation/subscribers/start-definition-sync.d.ts +10 -0
- package/dist/presentation/subscribers/start-definition-sync.d.ts.map +1 -0
- package/dist/presentation/subscribers/start-definition-sync.js +26 -0
- package/dist/presentation/subscribers/start-definition-sync.js.map +1 -0
- package/dist/temporal/activities/index.d.ts +3 -0
- package/dist/temporal/activities/index.d.ts.map +1 -0
- package/dist/temporal/activities/index.js +3 -0
- package/dist/temporal/activities/index.js.map +1 -0
- package/dist/temporal/activities/sync-activities.d.ts +47 -0
- package/dist/temporal/activities/sync-activities.d.ts.map +1 -0
- package/dist/temporal/activities/sync-activities.js +128 -0
- package/dist/temporal/activities/sync-activities.js.map +1 -0
- package/dist/temporal/constants.d.ts +3 -0
- package/dist/temporal/constants.d.ts.map +1 -0
- package/dist/temporal/constants.js +4 -0
- package/dist/temporal/constants.js.map +1 -0
- package/dist/temporal/index.d.ts +3 -0
- package/dist/temporal/index.d.ts.map +1 -0
- package/dist/temporal/index.js +4 -0
- package/dist/temporal/index.js.map +1 -0
- package/dist/temporal/workflows/definition-sync.d.ts +20 -0
- package/dist/temporal/workflows/definition-sync.d.ts.map +1 -0
- package/dist/temporal/workflows/definition-sync.js +95 -0
- package/dist/temporal/workflows/definition-sync.js.map +1 -0
- package/dist/temporal/workflows/index.d.ts +2 -0
- package/dist/temporal/workflows/index.d.ts.map +1 -0
- package/dist/temporal/workflows/index.js +3 -0
- package/dist/temporal/workflows/index.js.map +1 -0
- package/dist/tsconfig.test.tsbuildinfo +1 -0
- package/drizzle/0000_initial.sql +64 -0
- package/drizzle/0001_definition_list_pagination.sql +1 -0
- package/drizzle/meta/0000_snapshot.json +527 -0
- package/drizzle/meta/_journal.json +20 -0
- package/drizzle.config.ts +11 -0
- package/package.json +89 -0
- package/src/config.test.ts +23 -0
- package/src/config.ts +50 -0
- package/src/core/entities/index.ts +4 -0
- package/src/core/entities/integration-context.ts +21 -0
- package/src/core/entities/sync-state.ts +40 -0
- package/src/core/entities/workflow-definition.ts +38 -0
- package/src/core/entities/workflow-model.ts +162 -0
- package/src/core/errors.ts +21 -0
- package/src/core/has-agent-step-integrations.ts +7 -0
- package/src/core/index.ts +23 -0
- package/src/core/parse-definition.test.ts +200 -0
- package/src/core/parse-definition.ts +28 -0
- package/src/core/sync-definitions.test.ts +390 -0
- package/src/core/sync-definitions.ts +216 -0
- package/src/core/validate-definition.test.ts +152 -0
- package/src/core/validate-definition.ts +72 -0
- package/src/core/workflow-model/README.md +129 -0
- package/src/core/workflow-model/constants.ts +1 -0
- package/src/core/workflow-model/cron-trigger.test.ts +29 -0
- package/src/core/workflow-model/cron-trigger.ts +83 -0
- package/src/core/workflow-model/index.ts +9 -0
- package/src/core/workflow-model/invalid-workflow-model-error.ts +71 -0
- package/src/core/workflow-model/map-job-ids.ts +33 -0
- package/src/core/workflow-model/normalize-agent-integrations.ts +208 -0
- package/src/core/workflow-model/normalize-dependencies.ts +139 -0
- package/src/core/workflow-model/normalize-env.ts +48 -0
- package/src/core/workflow-model/normalize-if-condition.ts +126 -0
- package/src/core/workflow-model/normalize-job-checkout.ts +19 -0
- package/src/core/workflow-model/normalize-job-listening.ts +121 -0
- package/src/core/workflow-model/normalize-job-success.ts +28 -0
- package/src/core/workflow-model/normalize-jobs.ts +1010 -0
- package/src/core/workflow-model/normalize-needs.ts +12 -0
- package/src/core/workflow-model/normalize-step-gate.ts +90 -0
- package/src/core/workflow-model/normalize-step-outputs.ts +36 -0
- package/src/core/workflow-model/normalize-triggers.ts +130 -0
- package/src/core/workflow-model/normalize-workflow-document.test.ts +4463 -0
- package/src/core/workflow-model/normalize-workflow-document.ts +63 -0
- package/src/core/workflow-model/parse-duration-ms.ts +58 -0
- package/src/core/workflow-model/parse-interpolation-field.ts +566 -0
- package/src/core/workflow-model/stable-id.ts +12 -0
- package/src/core/workflow-model/validate-job-references.ts +54 -0
- package/src/core/workflow-model/validate-predicate-expression.test.ts +161 -0
- package/src/core/workflow-model/validate-predicate-expression.ts +406 -0
- package/src/core/workflow-model/validation-issue.ts +27 -0
- package/src/core/workflow-model/workflow-field-label.ts +50 -0
- package/src/core/workflow-yaml/README.md +77 -0
- package/src/core/workflow-yaml/index.ts +11 -0
- package/src/core/workflow-yaml/invalid-workflow-yaml-error.ts +23 -0
- package/src/core/workflow-yaml/parse-workflow-yaml.test.ts +71 -0
- package/src/core/workflow-yaml/parse-workflow-yaml.ts +74 -0
- package/src/core/workflow-yaml/source-locations.ts +62 -0
- package/src/db/db.ts +18 -0
- package/src/db/definition-triggers.test.ts +95 -0
- package/src/db/definition-triggers.ts +17 -0
- package/src/db/definitions.test.ts +1309 -0
- package/src/db/definitions.ts +357 -0
- package/src/db/index.ts +31 -0
- package/src/db/schema/common.ts +3 -0
- package/src/db/schema/definitions.test.ts +36 -0
- package/src/db/schema/definitions.ts +76 -0
- package/src/db/schema/outbox.ts +4 -0
- package/src/db/schema/sync-states.ts +79 -0
- package/src/db/sync-states.test.ts +90 -0
- package/src/db/sync-states.ts +86 -0
- package/src/index.ts +104 -0
- package/src/presentation/dto/definition.test.ts +59 -0
- package/src/presentation/dto/definition.ts +41 -0
- package/src/presentation/dto/index.ts +1 -0
- package/src/presentation/index.ts +1 -0
- package/src/presentation/routes/create-definition.test.ts +356 -0
- package/src/presentation/routes/create-definition.ts +101 -0
- package/src/presentation/routes/get-definition.test.ts +79 -0
- package/src/presentation/routes/get-definition.ts +37 -0
- package/src/presentation/routes/index.test.ts +41 -0
- package/src/presentation/routes/index.ts +28 -0
- package/src/presentation/routes/list-definitions.test.ts +195 -0
- package/src/presentation/routes/list-definitions.ts +49 -0
- package/src/presentation/routes/validate-definition.test.ts +63 -0
- package/src/presentation/routes/validate-definition.ts +46 -0
- package/src/presentation/subscribers/index.ts +2 -0
- package/src/presentation/subscribers/on-project-source-bound.test.ts +65 -0
- package/src/presentation/subscribers/on-project-source-bound.ts +11 -0
- package/src/presentation/subscribers/on-project-source-commit-observed.test.ts +56 -0
- package/src/presentation/subscribers/on-project-source-commit-observed.ts +15 -0
- package/src/presentation/subscribers/start-definition-sync.ts +38 -0
- package/src/temporal/activities/index.ts +10 -0
- package/src/temporal/activities/sync-activities.test.ts +337 -0
- package/src/temporal/activities/sync-activities.ts +206 -0
- package/src/temporal/constants.ts +2 -0
- package/src/temporal/index.ts +2 -0
- package/src/temporal/workflows/definition-sync.test.ts +59 -0
- package/src/temporal/workflows/definition-sync.ts +116 -0
- package/src/temporal/workflows/index.ts +1 -0
- package/test/env.ts +7 -0
- package/test/factories/definition.ts +66 -0
- package/test/fixtures/invalid-cycle.yml +13 -0
- package/test/fixtures/invalid-missing-name.yml +4 -0
- package/test/fixtures/invalid-yaml-syntax.yml +6 -0
- package/test/fixtures/valid-dag.yml +25 -0
- package/test/fixtures/valid-listening-job.yml +21 -0
- package/test/fixtures/valid-simple.yml +18 -0
- package/test/fixtures/workflow-yaml/invalid/invalid-yaml-syntax.yaml +6 -0
- package/test/fixtures/workflow-yaml/invalid/missing-step-run.yaml +5 -0
- package/test/fixtures/workflow-yaml/valid/simple-build.document.json +26 -0
- package/test/fixtures/workflow-yaml/valid/simple-build.yaml +14 -0
- package/test/globalSetup.ts +25 -0
- package/test/index.ts +1 -0
- package/test/setup.ts +17 -0
- package/tsconfig.build.json +9 -0
- package/tsconfig.build.tsbuildinfo +1 -0
- package/tsconfig.json +3 -0
- package/tsconfig.test.json +8 -0
- package/vitest.config.ts +11 -0
|
@@ -0,0 +1,357 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DEFINITION_DELETED,
|
|
3
|
+
DEFINITION_RESOLVED,
|
|
4
|
+
type DefinitionsEventMap,
|
|
5
|
+
} from '@shipfox/api-definitions-dto';
|
|
6
|
+
import {writeOutboxEvent} from '@shipfox/node-outbox';
|
|
7
|
+
import type {WorkflowDocument} from '@shipfox/workflow-document';
|
|
8
|
+
import {and, asc, eq, gt, isNull, notInArray, or, type SQL, sql} from 'drizzle-orm';
|
|
9
|
+
import type {
|
|
10
|
+
WorkflowDefinition,
|
|
11
|
+
WorkflowDefinitionPayload,
|
|
12
|
+
WorkflowSourceSnapshot,
|
|
13
|
+
} from '#core/entities/workflow-definition.js';
|
|
14
|
+
import type {WorkflowModel} from '#core/entities/workflow-model.js';
|
|
15
|
+
import {db} from './db.js';
|
|
16
|
+
import {definitionTriggersFor} from './definition-triggers.js';
|
|
17
|
+
import {toDefinition, workflowDefinitions} from './schema/definitions.js';
|
|
18
|
+
import {definitionsOutbox} from './schema/outbox.js';
|
|
19
|
+
|
|
20
|
+
type Tx = Parameters<Parameters<ReturnType<typeof db>['transaction']>[0]>[0];
|
|
21
|
+
|
|
22
|
+
export interface UpsertDefinitionParams {
|
|
23
|
+
projectId: string;
|
|
24
|
+
workspaceId: string;
|
|
25
|
+
configPath?: string | null | undefined;
|
|
26
|
+
source?: 'manual' | 'vcs' | undefined;
|
|
27
|
+
name: string;
|
|
28
|
+
document: WorkflowDocument;
|
|
29
|
+
model: WorkflowModel;
|
|
30
|
+
sourceSnapshot?: WorkflowSourceSnapshot | null | undefined;
|
|
31
|
+
contentHash?: string | null | undefined;
|
|
32
|
+
sha?: string | undefined;
|
|
33
|
+
ref?: string | undefined;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function buildUpsertQuery(tx: Tx, params: UpsertDefinitionParams) {
|
|
37
|
+
const source = params.source ?? 'manual';
|
|
38
|
+
if (source === 'vcs' && !params.configPath) {
|
|
39
|
+
throw new Error('configPath is required for VCS definitions');
|
|
40
|
+
}
|
|
41
|
+
// Keep source aligned with the conflict arbiter (chosen by ref/sha presence):
|
|
42
|
+
// vcs rows are versioned by ref/sha, manual rows have neither.
|
|
43
|
+
const hasRefOrSha = params.ref != null || params.sha != null;
|
|
44
|
+
if ((source === 'vcs') !== hasRefOrSha) {
|
|
45
|
+
throw new Error(
|
|
46
|
+
'Definition source/ref/sha mismatch: vcs requires a ref or sha, manual requires neither',
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const definition: WorkflowDefinitionPayload = {
|
|
51
|
+
document: params.document,
|
|
52
|
+
model: params.model,
|
|
53
|
+
sourceSnapshot: params.sourceSnapshot ?? null,
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const set = {
|
|
57
|
+
name: params.name,
|
|
58
|
+
source,
|
|
59
|
+
definition,
|
|
60
|
+
contentHash: params.contentHash ?? null,
|
|
61
|
+
fetchedAt: sql`now()`,
|
|
62
|
+
updatedAt: sql`now()`,
|
|
63
|
+
deletedAt: null,
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
const values = {
|
|
67
|
+
projectId: params.projectId,
|
|
68
|
+
configPath: params.configPath ?? null,
|
|
69
|
+
source,
|
|
70
|
+
sha: params.sha ?? null,
|
|
71
|
+
ref: params.ref ?? null,
|
|
72
|
+
name: params.name,
|
|
73
|
+
definition,
|
|
74
|
+
contentHash: params.contentHash ?? null,
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
if (params.sha) {
|
|
78
|
+
return tx
|
|
79
|
+
.insert(workflowDefinitions)
|
|
80
|
+
.values(values)
|
|
81
|
+
.onConflictDoUpdate({
|
|
82
|
+
target: [
|
|
83
|
+
workflowDefinitions.projectId,
|
|
84
|
+
workflowDefinitions.sha,
|
|
85
|
+
workflowDefinitions.configPath,
|
|
86
|
+
],
|
|
87
|
+
targetWhere: sql`"sha" IS NOT NULL`,
|
|
88
|
+
set,
|
|
89
|
+
})
|
|
90
|
+
.returning();
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (params.ref) {
|
|
94
|
+
return tx
|
|
95
|
+
.insert(workflowDefinitions)
|
|
96
|
+
.values(values)
|
|
97
|
+
.onConflictDoUpdate({
|
|
98
|
+
target: [
|
|
99
|
+
workflowDefinitions.projectId,
|
|
100
|
+
workflowDefinitions.ref,
|
|
101
|
+
workflowDefinitions.configPath,
|
|
102
|
+
],
|
|
103
|
+
targetWhere: sql`"ref" IS NOT NULL`,
|
|
104
|
+
set,
|
|
105
|
+
})
|
|
106
|
+
.returning();
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return tx
|
|
110
|
+
.insert(workflowDefinitions)
|
|
111
|
+
.values(values)
|
|
112
|
+
.onConflictDoUpdate({
|
|
113
|
+
target: [workflowDefinitions.projectId, workflowDefinitions.configPath],
|
|
114
|
+
targetWhere: sql`"config_path" IS NOT NULL AND "ref" IS NULL AND "sha" IS NULL`,
|
|
115
|
+
set,
|
|
116
|
+
})
|
|
117
|
+
.returning();
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export async function upsertDefinition(
|
|
121
|
+
params: UpsertDefinitionParams,
|
|
122
|
+
): Promise<WorkflowDefinition> {
|
|
123
|
+
return await db().transaction(async (tx) => {
|
|
124
|
+
const rows = await buildUpsertQuery(tx, params);
|
|
125
|
+
const row = rows[0];
|
|
126
|
+
if (!row) throw new Error('Upsert returned no rows');
|
|
127
|
+
|
|
128
|
+
await writeOutboxEvent<DefinitionsEventMap>(tx, definitionsOutbox, {
|
|
129
|
+
type: DEFINITION_RESOLVED,
|
|
130
|
+
payload: {
|
|
131
|
+
definitionId: row.id,
|
|
132
|
+
projectId: row.projectId,
|
|
133
|
+
workspaceId: params.workspaceId,
|
|
134
|
+
configPath: row.configPath,
|
|
135
|
+
triggers: definitionTriggersFor(row.definition.model),
|
|
136
|
+
},
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
return toDefinition(row);
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export async function getDefinitionById(id: string): Promise<WorkflowDefinition | undefined> {
|
|
144
|
+
const rows = await db()
|
|
145
|
+
.select()
|
|
146
|
+
.from(workflowDefinitions)
|
|
147
|
+
.where(and(eq(workflowDefinitions.id, id), isNull(workflowDefinitions.deletedAt)))
|
|
148
|
+
.limit(1);
|
|
149
|
+
const row = rows[0];
|
|
150
|
+
|
|
151
|
+
if (!row) return undefined;
|
|
152
|
+
return toDefinition(row);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export interface DefinitionCursor {
|
|
156
|
+
value: string;
|
|
157
|
+
id: string;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export interface ListDefinitionsParams {
|
|
161
|
+
projectId: string;
|
|
162
|
+
limit: number;
|
|
163
|
+
cursor?: DefinitionCursor | undefined;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export interface ListDefinitionsResult {
|
|
167
|
+
definitions: WorkflowDefinition[];
|
|
168
|
+
nextCursor: DefinitionCursor | null;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function cursorWhere(cursor: DefinitionCursor | undefined): SQL | undefined {
|
|
172
|
+
if (!cursor) return undefined;
|
|
173
|
+
return or(
|
|
174
|
+
gt(workflowDefinitions.name, cursor.value),
|
|
175
|
+
and(eq(workflowDefinitions.name, cursor.value), gt(workflowDefinitions.id, cursor.id)),
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
export async function listDefinitions(
|
|
180
|
+
params: ListDefinitionsParams,
|
|
181
|
+
): Promise<ListDefinitionsResult> {
|
|
182
|
+
const conditions = [
|
|
183
|
+
eq(workflowDefinitions.projectId, params.projectId),
|
|
184
|
+
isNull(workflowDefinitions.deletedAt),
|
|
185
|
+
];
|
|
186
|
+
const cursorCondition = cursorWhere(params.cursor);
|
|
187
|
+
if (cursorCondition) conditions.push(cursorCondition);
|
|
188
|
+
|
|
189
|
+
const rows = await db()
|
|
190
|
+
.select()
|
|
191
|
+
.from(workflowDefinitions)
|
|
192
|
+
.where(and(...conditions))
|
|
193
|
+
.orderBy(asc(workflowDefinitions.name), asc(workflowDefinitions.id))
|
|
194
|
+
.limit(params.limit + 1);
|
|
195
|
+
|
|
196
|
+
const hasMore = rows.length > params.limit;
|
|
197
|
+
const pageRows = hasMore ? rows.slice(0, params.limit) : rows;
|
|
198
|
+
const last = pageRows.at(-1);
|
|
199
|
+
|
|
200
|
+
return {
|
|
201
|
+
definitions: pageRows.map(toDefinition),
|
|
202
|
+
nextCursor: hasMore && last ? {value: last.name, id: last.id} : null,
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
export async function listDefinitionsByProject(projectId: string): Promise<WorkflowDefinition[]> {
|
|
207
|
+
const result = await listDefinitions({projectId, limit: 100});
|
|
208
|
+
return result.definitions;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
export interface SoftDeleteVcsDefinitionsParams {
|
|
212
|
+
projectId: string;
|
|
213
|
+
workspaceId: string;
|
|
214
|
+
ref: string;
|
|
215
|
+
keepConfigPaths: string[];
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
async function softDeleteVcsDefinitionsNotInTx(
|
|
219
|
+
tx: Tx,
|
|
220
|
+
params: SoftDeleteVcsDefinitionsParams,
|
|
221
|
+
): Promise<number> {
|
|
222
|
+
const now = sql`now()`;
|
|
223
|
+
const baseWhere = and(
|
|
224
|
+
eq(workflowDefinitions.projectId, params.projectId),
|
|
225
|
+
eq(workflowDefinitions.source, 'vcs'),
|
|
226
|
+
eq(workflowDefinitions.ref, params.ref),
|
|
227
|
+
isNull(workflowDefinitions.deletedAt),
|
|
228
|
+
);
|
|
229
|
+
const where =
|
|
230
|
+
params.keepConfigPaths.length > 0
|
|
231
|
+
? and(baseWhere, notInArray(workflowDefinitions.configPath, params.keepConfigPaths))
|
|
232
|
+
: baseWhere;
|
|
233
|
+
|
|
234
|
+
const rows = await tx
|
|
235
|
+
.update(workflowDefinitions)
|
|
236
|
+
.set({deletedAt: now, updatedAt: now})
|
|
237
|
+
.where(where)
|
|
238
|
+
.returning({id: workflowDefinitions.id});
|
|
239
|
+
|
|
240
|
+
for (const row of rows) {
|
|
241
|
+
await writeOutboxEvent<DefinitionsEventMap>(tx, definitionsOutbox, {
|
|
242
|
+
type: DEFINITION_DELETED,
|
|
243
|
+
payload: {
|
|
244
|
+
definitionId: row.id,
|
|
245
|
+
projectId: params.projectId,
|
|
246
|
+
workspaceId: params.workspaceId,
|
|
247
|
+
},
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
return rows.length;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
export async function softDeleteVcsDefinitionsNotIn(
|
|
255
|
+
params: SoftDeleteVcsDefinitionsParams,
|
|
256
|
+
): Promise<number> {
|
|
257
|
+
return await db().transaction((tx) => softDeleteVcsDefinitionsNotInTx(tx, params));
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
export interface ApplyVcsDefinitionsBatchParams {
|
|
261
|
+
projectId: string;
|
|
262
|
+
workspaceId: string;
|
|
263
|
+
ref: string;
|
|
264
|
+
upserts: Array<{
|
|
265
|
+
configPath: string;
|
|
266
|
+
name: string;
|
|
267
|
+
document: WorkflowDocument;
|
|
268
|
+
model: WorkflowModel;
|
|
269
|
+
sourceSnapshot?: WorkflowSourceSnapshot | null | undefined;
|
|
270
|
+
contentHash: string;
|
|
271
|
+
}>;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
export interface ApplyVcsDefinitionsBatchResult {
|
|
275
|
+
appliedCount: number;
|
|
276
|
+
deletedCount: number;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
export async function applyVcsDefinitionsBatch(
|
|
280
|
+
params: ApplyVcsDefinitionsBatchParams,
|
|
281
|
+
): Promise<ApplyVcsDefinitionsBatchResult> {
|
|
282
|
+
return await db().transaction(async (tx) => {
|
|
283
|
+
let appliedCount = 0;
|
|
284
|
+
for (const item of params.upserts) {
|
|
285
|
+
const existing = await tx
|
|
286
|
+
.select({
|
|
287
|
+
contentHash: workflowDefinitions.contentHash,
|
|
288
|
+
deletedAt: workflowDefinitions.deletedAt,
|
|
289
|
+
})
|
|
290
|
+
.from(workflowDefinitions)
|
|
291
|
+
.where(
|
|
292
|
+
and(
|
|
293
|
+
eq(workflowDefinitions.projectId, params.projectId),
|
|
294
|
+
eq(workflowDefinitions.ref, params.ref),
|
|
295
|
+
eq(workflowDefinitions.configPath, item.configPath),
|
|
296
|
+
),
|
|
297
|
+
)
|
|
298
|
+
.limit(1);
|
|
299
|
+
|
|
300
|
+
const previous = existing[0];
|
|
301
|
+
const unchanged =
|
|
302
|
+
previous !== undefined &&
|
|
303
|
+
previous.deletedAt === null &&
|
|
304
|
+
previous.contentHash === item.contentHash;
|
|
305
|
+
|
|
306
|
+
const rows = await buildUpsertQuery(tx, {
|
|
307
|
+
projectId: params.projectId,
|
|
308
|
+
workspaceId: params.workspaceId,
|
|
309
|
+
configPath: item.configPath,
|
|
310
|
+
source: 'vcs',
|
|
311
|
+
ref: params.ref,
|
|
312
|
+
name: item.name,
|
|
313
|
+
document: item.document,
|
|
314
|
+
model: item.model,
|
|
315
|
+
sourceSnapshot: item.sourceSnapshot ?? null,
|
|
316
|
+
contentHash: item.contentHash,
|
|
317
|
+
});
|
|
318
|
+
const row = rows[0];
|
|
319
|
+
if (!row) throw new Error('Upsert returned no rows');
|
|
320
|
+
|
|
321
|
+
if (!unchanged) {
|
|
322
|
+
await writeOutboxEvent<DefinitionsEventMap>(tx, definitionsOutbox, {
|
|
323
|
+
type: DEFINITION_RESOLVED,
|
|
324
|
+
payload: {
|
|
325
|
+
definitionId: row.id,
|
|
326
|
+
projectId: row.projectId,
|
|
327
|
+
workspaceId: params.workspaceId,
|
|
328
|
+
configPath: row.configPath,
|
|
329
|
+
triggers: definitionTriggersFor(row.definition.model),
|
|
330
|
+
},
|
|
331
|
+
});
|
|
332
|
+
appliedCount += 1;
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
const keepConfigPaths = params.upserts.map((upsert) => upsert.configPath);
|
|
337
|
+
const deletedCount = await softDeleteVcsDefinitionsNotInTx(tx, {
|
|
338
|
+
projectId: params.projectId,
|
|
339
|
+
workspaceId: params.workspaceId,
|
|
340
|
+
ref: params.ref,
|
|
341
|
+
keepConfigPaths,
|
|
342
|
+
});
|
|
343
|
+
|
|
344
|
+
return {appliedCount, deletedCount};
|
|
345
|
+
});
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
export async function invalidateCache(params: {projectId: string; ref: string}): Promise<void> {
|
|
349
|
+
await db()
|
|
350
|
+
.delete(workflowDefinitions)
|
|
351
|
+
.where(
|
|
352
|
+
and(
|
|
353
|
+
eq(workflowDefinitions.projectId, params.projectId),
|
|
354
|
+
eq(workflowDefinitions.ref, params.ref),
|
|
355
|
+
),
|
|
356
|
+
);
|
|
357
|
+
}
|
package/src/db/index.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import {dirname, resolve} from 'node:path';
|
|
2
|
+
import {fileURLToPath} from 'node:url';
|
|
3
|
+
|
|
4
|
+
export {closeDb, db, schema} from './db.js';
|
|
5
|
+
export type {
|
|
6
|
+
ApplyVcsDefinitionsBatchParams,
|
|
7
|
+
ApplyVcsDefinitionsBatchResult,
|
|
8
|
+
ListDefinitionsParams,
|
|
9
|
+
ListDefinitionsResult,
|
|
10
|
+
SoftDeleteVcsDefinitionsParams,
|
|
11
|
+
UpsertDefinitionParams,
|
|
12
|
+
} from './definitions.js';
|
|
13
|
+
export {
|
|
14
|
+
applyVcsDefinitionsBatch,
|
|
15
|
+
getDefinitionById,
|
|
16
|
+
invalidateCache,
|
|
17
|
+
listDefinitions,
|
|
18
|
+
listDefinitionsByProject,
|
|
19
|
+
softDeleteVcsDefinitionsNotIn,
|
|
20
|
+
upsertDefinition,
|
|
21
|
+
} from './definitions.js';
|
|
22
|
+
export {definitionsOutbox} from './schema/outbox.js';
|
|
23
|
+
export {definitionSyncStates} from './schema/sync-states.js';
|
|
24
|
+
export {
|
|
25
|
+
type DefinitionSyncStateKey,
|
|
26
|
+
getLatestDefinitionSyncState,
|
|
27
|
+
type MarkDefinitionSyncParams,
|
|
28
|
+
markDefinitionSyncState,
|
|
29
|
+
} from './sync-states.js';
|
|
30
|
+
|
|
31
|
+
export const migrationsPath = resolve(dirname(fileURLToPath(import.meta.url)), '../../drizzle');
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import {normalizeWorkflowDocument} from '#core/workflow-model/index.js';
|
|
2
|
+
import type {DefinitionDb} from './definitions.js';
|
|
3
|
+
import {toDefinition} from './definitions.js';
|
|
4
|
+
|
|
5
|
+
describe('toDefinition', () => {
|
|
6
|
+
it('maps legacy definition payloads without source snapshots to null', () => {
|
|
7
|
+
const document = {
|
|
8
|
+
name: 'Manual workflow',
|
|
9
|
+
runner: 'ubuntu-latest',
|
|
10
|
+
jobs: {
|
|
11
|
+
build: {
|
|
12
|
+
steps: [{run: 'pnpm build'}],
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
};
|
|
16
|
+
const row: DefinitionDb = {
|
|
17
|
+
id: '019e98ab-6656-7ca1-b9ad-1ca4442c479d',
|
|
18
|
+
projectId: '019e98ab-b90f-7265-b13c-8b441c991381',
|
|
19
|
+
configPath: '.shipfox/workflows/manual.yml',
|
|
20
|
+
source: 'manual',
|
|
21
|
+
sha: null,
|
|
22
|
+
ref: null,
|
|
23
|
+
name: 'Manual workflow',
|
|
24
|
+
definition: {document, model: normalizeWorkflowDocument(document)},
|
|
25
|
+
contentHash: null,
|
|
26
|
+
fetchedAt: new Date('2026-06-09T10:00:00.000Z'),
|
|
27
|
+
createdAt: new Date('2026-06-09T10:00:01.000Z'),
|
|
28
|
+
updatedAt: new Date('2026-06-09T10:00:02.000Z'),
|
|
29
|
+
deletedAt: null,
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const result = toDefinition(row);
|
|
33
|
+
|
|
34
|
+
expect(result.sourceSnapshot).toBeNull();
|
|
35
|
+
});
|
|
36
|
+
});
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import {uuidv7PrimaryKey} from '@shipfox/node-drizzle';
|
|
2
|
+
import {sql} from 'drizzle-orm';
|
|
3
|
+
import {check, index, jsonb, pgEnum, text, timestamp, uniqueIndex, uuid} from 'drizzle-orm/pg-core';
|
|
4
|
+
import type {
|
|
5
|
+
WorkflowDefinition,
|
|
6
|
+
WorkflowDefinitionPayload,
|
|
7
|
+
} from '#core/entities/workflow-definition.js';
|
|
8
|
+
import {pgTable} from './common.js';
|
|
9
|
+
|
|
10
|
+
export const definitionSourceEnum = pgEnum('definitions_source', ['manual', 'vcs']);
|
|
11
|
+
|
|
12
|
+
export const workflowDefinitions = pgTable(
|
|
13
|
+
'workflow_definitions',
|
|
14
|
+
{
|
|
15
|
+
id: uuidv7PrimaryKey(),
|
|
16
|
+
projectId: uuid('project_id').notNull(),
|
|
17
|
+
configPath: text('config_path'),
|
|
18
|
+
source: definitionSourceEnum('source').notNull().default('manual'),
|
|
19
|
+
sha: text('sha'),
|
|
20
|
+
ref: text('ref'),
|
|
21
|
+
name: text('name').notNull(),
|
|
22
|
+
definition: jsonb('definition').notNull().$type<WorkflowDefinitionPayload>(),
|
|
23
|
+
contentHash: text('content_hash'),
|
|
24
|
+
fetchedAt: timestamp('fetched_at', {withTimezone: true}).notNull().defaultNow(),
|
|
25
|
+
createdAt: timestamp('created_at', {withTimezone: true}).notNull().defaultNow(),
|
|
26
|
+
updatedAt: timestamp('updated_at', {withTimezone: true}).notNull().defaultNow(),
|
|
27
|
+
deletedAt: timestamp('deleted_at', {withTimezone: true}),
|
|
28
|
+
},
|
|
29
|
+
(table) => [
|
|
30
|
+
// Manual definitions only (no ref, no sha); VCS uniqueness is sha_lookup/ref_lookup.
|
|
31
|
+
// A source-agnostic predicate here collides VCS upserts on a non-arbiter index. ENG-659.
|
|
32
|
+
uniqueIndex('definitions_wd_manual_unique')
|
|
33
|
+
.on(table.projectId, table.configPath)
|
|
34
|
+
.where(sql`"config_path" IS NOT NULL AND "ref" IS NULL AND "sha" IS NULL`),
|
|
35
|
+
uniqueIndex('definitions_wd_sha_lookup')
|
|
36
|
+
.on(table.projectId, table.sha, table.configPath)
|
|
37
|
+
.where(sql`"sha" IS NOT NULL`),
|
|
38
|
+
uniqueIndex('definitions_wd_ref_lookup')
|
|
39
|
+
.on(table.projectId, table.ref, table.configPath)
|
|
40
|
+
.where(sql`"ref" IS NOT NULL`),
|
|
41
|
+
index('definitions_wd_project_name_id_idx')
|
|
42
|
+
.on(table.projectId, table.name, table.id)
|
|
43
|
+
.where(sql`"deleted_at" IS NULL`),
|
|
44
|
+
// Binds source to its git coordinates so the partial indexes above stay
|
|
45
|
+
// unambiguous: vcs rows carry a ref or sha; manual rows carry neither.
|
|
46
|
+
check(
|
|
47
|
+
'definitions_wd_source_ref_sha_consistent',
|
|
48
|
+
sql`("source" = 'vcs') = ("ref" IS NOT NULL OR "sha" IS NOT NULL)`,
|
|
49
|
+
),
|
|
50
|
+
],
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
export type DefinitionDb = typeof workflowDefinitions.$inferSelect;
|
|
54
|
+
export type DefinitionCreateDb = typeof workflowDefinitions.$inferInsert;
|
|
55
|
+
export type DefinitionUpdateDb = Partial<DefinitionCreateDb>;
|
|
56
|
+
|
|
57
|
+
export function toDefinition(row: DefinitionDb): WorkflowDefinition {
|
|
58
|
+
return {
|
|
59
|
+
id: row.id,
|
|
60
|
+
projectId: row.projectId,
|
|
61
|
+
configPath: row.configPath,
|
|
62
|
+
source: row.source,
|
|
63
|
+
sha: row.sha,
|
|
64
|
+
ref: row.ref,
|
|
65
|
+
name: row.name,
|
|
66
|
+
definition: row.definition.document,
|
|
67
|
+
document: row.definition.document,
|
|
68
|
+
model: row.definition.model,
|
|
69
|
+
sourceSnapshot: row.definition.sourceSnapshot ?? null,
|
|
70
|
+
contentHash: row.contentHash,
|
|
71
|
+
fetchedAt: row.fetchedAt,
|
|
72
|
+
createdAt: row.createdAt,
|
|
73
|
+
updatedAt: row.updatedAt,
|
|
74
|
+
deletedAt: row.deletedAt,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import {uuidv7PrimaryKey} from '@shipfox/node-drizzle';
|
|
2
|
+
import {sql} from 'drizzle-orm';
|
|
3
|
+
import {index, pgEnum, text, timestamp, uniqueIndex, uuid} from 'drizzle-orm/pg-core';
|
|
4
|
+
import type {
|
|
5
|
+
DefinitionSyncErrorCode,
|
|
6
|
+
DefinitionSyncState,
|
|
7
|
+
DefinitionSyncStatus,
|
|
8
|
+
} from '#core/entities/sync-state.js';
|
|
9
|
+
import {pgTable} from './common.js';
|
|
10
|
+
|
|
11
|
+
export const definitionSyncStatusEnum = pgEnum('definitions_sync_status', [
|
|
12
|
+
'pending',
|
|
13
|
+
'syncing',
|
|
14
|
+
'succeeded',
|
|
15
|
+
'failed',
|
|
16
|
+
]);
|
|
17
|
+
|
|
18
|
+
export const definitionSyncErrorCodeEnum = pgEnum('definitions_sync_error_code', [
|
|
19
|
+
'no-workflow-files',
|
|
20
|
+
'invalid-definition',
|
|
21
|
+
'provider-repository-not-found',
|
|
22
|
+
'provider-file-not-found',
|
|
23
|
+
'provider-access-denied',
|
|
24
|
+
'provider-rate-limited',
|
|
25
|
+
'provider-timeout',
|
|
26
|
+
'provider-unavailable',
|
|
27
|
+
'provider-malformed-response',
|
|
28
|
+
'content-too-large',
|
|
29
|
+
'too-many-files',
|
|
30
|
+
'connection-unavailable',
|
|
31
|
+
'unknown',
|
|
32
|
+
]);
|
|
33
|
+
|
|
34
|
+
export const definitionSyncStates = pgTable(
|
|
35
|
+
'sync_states',
|
|
36
|
+
{
|
|
37
|
+
id: uuidv7PrimaryKey(),
|
|
38
|
+
projectId: uuid('project_id').notNull(),
|
|
39
|
+
sourceConnectionId: uuid('source_connection_id').notNull(),
|
|
40
|
+
sourceExternalRepositoryId: text('source_external_repository_id').notNull(),
|
|
41
|
+
ref: text('ref').notNull(),
|
|
42
|
+
status: definitionSyncStatusEnum('status').notNull().default('pending'),
|
|
43
|
+
lastErrorCode: definitionSyncErrorCodeEnum('last_error_code'),
|
|
44
|
+
lastErrorMessage: text('last_error_message'),
|
|
45
|
+
startedAt: timestamp('started_at', {withTimezone: true}),
|
|
46
|
+
finishedAt: timestamp('finished_at', {withTimezone: true}),
|
|
47
|
+
createdAt: timestamp('created_at', {withTimezone: true}).notNull().defaultNow(),
|
|
48
|
+
updatedAt: timestamp('updated_at', {withTimezone: true}).notNull().defaultNow(),
|
|
49
|
+
},
|
|
50
|
+
(table) => [
|
|
51
|
+
uniqueIndex('definitions_sync_states_source_unique').on(
|
|
52
|
+
table.projectId,
|
|
53
|
+
table.sourceConnectionId,
|
|
54
|
+
table.sourceExternalRepositoryId,
|
|
55
|
+
table.ref,
|
|
56
|
+
),
|
|
57
|
+
index('definitions_sync_states_failed_idx').on(table.updatedAt).where(sql`"status" = 'failed'`),
|
|
58
|
+
],
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
export type DefinitionSyncStateDb = typeof definitionSyncStates.$inferSelect;
|
|
62
|
+
export type DefinitionSyncStateCreateDb = typeof definitionSyncStates.$inferInsert;
|
|
63
|
+
|
|
64
|
+
export function toDefinitionSyncState(row: DefinitionSyncStateDb): DefinitionSyncState {
|
|
65
|
+
return {
|
|
66
|
+
id: row.id,
|
|
67
|
+
projectId: row.projectId,
|
|
68
|
+
sourceConnectionId: row.sourceConnectionId,
|
|
69
|
+
sourceExternalRepositoryId: row.sourceExternalRepositoryId,
|
|
70
|
+
ref: row.ref,
|
|
71
|
+
status: row.status as DefinitionSyncStatus,
|
|
72
|
+
lastErrorCode: row.lastErrorCode as DefinitionSyncErrorCode | null,
|
|
73
|
+
lastErrorMessage: row.lastErrorMessage,
|
|
74
|
+
startedAt: row.startedAt,
|
|
75
|
+
finishedAt: row.finishedAt,
|
|
76
|
+
createdAt: row.createdAt,
|
|
77
|
+
updatedAt: row.updatedAt,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import {eq} from 'drizzle-orm';
|
|
2
|
+
import {db} from './db.js';
|
|
3
|
+
import {definitionSyncStates} from './schema/sync-states.js';
|
|
4
|
+
import {markDefinitionSyncState} from './sync-states.js';
|
|
5
|
+
|
|
6
|
+
describe('definition sync state queries', () => {
|
|
7
|
+
let projectId: string;
|
|
8
|
+
let sourceConnectionId: string;
|
|
9
|
+
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
projectId = crypto.randomUUID();
|
|
12
|
+
sourceConnectionId = crypto.randomUUID();
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it('creates a sync-state row', async () => {
|
|
16
|
+
const state = await markDefinitionSyncState({
|
|
17
|
+
projectId,
|
|
18
|
+
sourceConnectionId,
|
|
19
|
+
sourceExternalRepositoryId: 'gitea-owner/platform',
|
|
20
|
+
ref: 'main',
|
|
21
|
+
status: 'syncing',
|
|
22
|
+
startedAt: new Date(),
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
expect(state.projectId).toBe(projectId);
|
|
26
|
+
expect(state.status).toBe('syncing');
|
|
27
|
+
expect(state.lastErrorCode).toBeNull();
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('updates the same logical sync-state row', async () => {
|
|
31
|
+
const first = await markDefinitionSyncState({
|
|
32
|
+
projectId,
|
|
33
|
+
sourceConnectionId,
|
|
34
|
+
sourceExternalRepositoryId: 'gitea-owner/platform',
|
|
35
|
+
ref: 'main',
|
|
36
|
+
status: 'syncing',
|
|
37
|
+
startedAt: new Date(),
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
const second = await markDefinitionSyncState({
|
|
41
|
+
projectId,
|
|
42
|
+
sourceConnectionId,
|
|
43
|
+
sourceExternalRepositoryId: 'gitea-owner/platform',
|
|
44
|
+
ref: 'main',
|
|
45
|
+
status: 'failed',
|
|
46
|
+
lastErrorCode: 'invalid-definition',
|
|
47
|
+
lastErrorMessage: 'Invalid YAML',
|
|
48
|
+
finishedAt: new Date(),
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
const rows = await db()
|
|
52
|
+
.select()
|
|
53
|
+
.from(definitionSyncStates)
|
|
54
|
+
.where(eq(definitionSyncStates.projectId, projectId));
|
|
55
|
+
expect(rows).toHaveLength(1);
|
|
56
|
+
expect(second.id).toBe(first.id);
|
|
57
|
+
expect(second.status).toBe('failed');
|
|
58
|
+
expect(second.lastErrorCode).toBe('invalid-definition');
|
|
59
|
+
expect(second.startedAt?.getTime()).toBe(first.startedAt?.getTime());
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('clears stale finish data when a sync starts again', async () => {
|
|
63
|
+
await markDefinitionSyncState({
|
|
64
|
+
projectId,
|
|
65
|
+
sourceConnectionId,
|
|
66
|
+
sourceExternalRepositoryId: 'gitea-owner/platform',
|
|
67
|
+
ref: 'main',
|
|
68
|
+
status: 'failed',
|
|
69
|
+
lastErrorCode: 'invalid-definition',
|
|
70
|
+
lastErrorMessage: 'Invalid YAML',
|
|
71
|
+
startedAt: new Date(),
|
|
72
|
+
finishedAt: new Date(),
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
const state = await markDefinitionSyncState({
|
|
76
|
+
projectId,
|
|
77
|
+
sourceConnectionId,
|
|
78
|
+
sourceExternalRepositoryId: 'gitea-owner/platform',
|
|
79
|
+
ref: 'main',
|
|
80
|
+
status: 'syncing',
|
|
81
|
+
startedAt: new Date(),
|
|
82
|
+
finishedAt: null,
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
expect(state.status).toBe('syncing');
|
|
86
|
+
expect(state.lastErrorCode).toBeNull();
|
|
87
|
+
expect(state.lastErrorMessage).toBeNull();
|
|
88
|
+
expect(state.finishedAt).toBeNull();
|
|
89
|
+
});
|
|
90
|
+
});
|