@mastra/factory 0.29.0-alpha.3 → 0.29.0-alpha.5
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/README.md +123 -64
- package/dist/boards/board-events.d.ts +89 -9
- package/dist/boards/board-events.d.ts.map +1 -1
- package/dist/boards/board-events.js +176 -13
- package/dist/boards/board-events.js.map +1 -1
- package/dist/boards/board-writes.d.ts.map +1 -1
- package/dist/boards/board-writes.js +14 -1
- package/dist/boards/board-writes.js.map +1 -1
- package/dist/boards/busy-card.d.ts +11 -0
- package/dist/boards/busy-card.d.ts.map +1 -0
- package/dist/boards/busy-card.js +15 -0
- package/dist/boards/busy-card.js.map +1 -0
- package/dist/boards/card-facts.d.ts.map +1 -1
- package/dist/boards/card-facts.js +18 -4
- package/dist/boards/card-facts.js.map +1 -1
- package/dist/boards/index.d.ts +2 -1
- package/dist/boards/index.d.ts.map +1 -1
- package/dist/boards/index.js +3 -2
- package/dist/boards/intake-dry-run.d.ts +109 -0
- package/dist/boards/intake-dry-run.d.ts.map +1 -0
- package/dist/boards/intake-dry-run.js +158 -0
- package/dist/boards/intake-dry-run.js.map +1 -0
- package/dist/boards/intake-lookup.d.ts +32 -0
- package/dist/boards/intake-lookup.d.ts.map +1 -0
- package/dist/boards/intake-lookup.js +12 -0
- package/dist/boards/intake-lookup.js.map +1 -0
- package/dist/boards/intake-order.d.ts +32 -0
- package/dist/boards/intake-order.d.ts.map +1 -0
- package/dist/boards/intake-order.js +60 -0
- package/dist/boards/intake-order.js.map +1 -0
- package/dist/boards/intake-routing.d.ts +246 -35
- package/dist/boards/intake-routing.d.ts.map +1 -1
- package/dist/boards/intake-routing.js +437 -52
- package/dist/boards/intake-routing.js.map +1 -1
- package/dist/boards/reroute.d.ts +7 -3
- package/dist/boards/reroute.d.ts.map +1 -1
- package/dist/boards/reroute.js +21 -4
- package/dist/boards/reroute.js.map +1 -1
- package/dist/boards/semantics.d.ts +8 -28
- package/dist/boards/semantics.d.ts.map +1 -1
- package/dist/boards/semantics.js +7 -39
- package/dist/boards/semantics.js.map +1 -1
- package/dist/boards/work-routes.d.ts +31 -11
- package/dist/boards/work-routes.d.ts.map +1 -1
- package/dist/boards/work-routes.js +104 -20
- package/dist/boards/work-routes.js.map +1 -1
- package/dist/factory.d.ts +27 -1
- package/dist/factory.d.ts.map +1 -1
- package/dist/factory.js +32 -18
- package/dist/factory.js.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -2
- package/dist/integrations/base.d.ts +9 -0
- package/dist/integrations/base.d.ts.map +1 -1
- package/dist/integrations/dependabot/rules.d.ts.map +1 -1
- package/dist/integrations/dependabot/rules.js +2 -6
- package/dist/integrations/dependabot/rules.js.map +1 -1
- package/dist/integrations/github/commits.d.ts +0 -21
- package/dist/integrations/github/commits.d.ts.map +1 -1
- package/dist/integrations/github/commits.js +1 -24
- package/dist/integrations/github/commits.js.map +1 -1
- package/dist/integrations/github/default-rules.d.ts +22 -1
- package/dist/integrations/github/default-rules.d.ts.map +1 -1
- package/dist/integrations/github/default-rules.js +23 -5
- package/dist/integrations/github/default-rules.js.map +1 -1
- package/dist/integrations/github/intake-lookup.d.ts +16 -0
- package/dist/integrations/github/intake-lookup.d.ts.map +1 -0
- package/dist/integrations/github/intake-lookup.js +76 -0
- package/dist/integrations/github/intake-lookup.js.map +1 -0
- package/dist/integrations/github/integration.d.ts +20 -6
- package/dist/integrations/github/integration.d.ts.map +1 -1
- package/dist/integrations/github/integration.js +23 -12
- package/dist/integrations/github/integration.js.map +1 -1
- package/dist/integrations/github/review-status-reporter.js +1 -1
- package/dist/integrations/github/routes.d.ts +1 -11
- package/dist/integrations/github/routes.d.ts.map +1 -1
- package/dist/integrations/github/routes.js +20 -517
- package/dist/integrations/github/routes.js.map +1 -1
- package/dist/integrations/github/rules.d.ts +12 -1
- package/dist/integrations/github/rules.d.ts.map +1 -1
- package/dist/integrations/github/rules.js +275 -38
- package/dist/integrations/github/rules.js.map +1 -1
- package/dist/integrations/github/sandbox.d.ts.map +1 -1
- package/dist/integrations/github/sandbox.js +30 -4
- package/dist/integrations/github/sandbox.js.map +1 -1
- package/dist/integrations/gitlab/default-rules.d.ts.map +1 -1
- package/dist/integrations/gitlab/default-rules.js +19 -3
- package/dist/integrations/gitlab/default-rules.js.map +1 -1
- package/dist/integrations/gitlab/discovery.d.ts +1 -1
- package/dist/integrations/gitlab/discovery.js +1 -1
- package/dist/integrations/gitlab/discovery.js.map +1 -1
- package/dist/integrations/gitlab/intake-lookup.d.ts +17 -0
- package/dist/integrations/gitlab/intake-lookup.d.ts.map +1 -0
- package/dist/integrations/gitlab/intake-lookup.js +85 -0
- package/dist/integrations/gitlab/intake-lookup.js.map +1 -0
- package/dist/integrations/gitlab/integration.d.ts +5 -0
- package/dist/integrations/gitlab/integration.d.ts.map +1 -1
- package/dist/integrations/gitlab/integration.js +21 -2
- package/dist/integrations/gitlab/integration.js.map +1 -1
- package/dist/integrations/gitlab/routes.d.ts +0 -2
- package/dist/integrations/gitlab/routes.d.ts.map +1 -1
- package/dist/integrations/gitlab/routes.js +49 -165
- package/dist/integrations/gitlab/routes.js.map +1 -1
- package/dist/integrations/gitlab/rules.d.ts +20 -0
- package/dist/integrations/gitlab/rules.d.ts.map +1 -1
- package/dist/integrations/gitlab/rules.js +128 -19
- package/dist/integrations/gitlab/rules.js.map +1 -1
- package/dist/integrations/incidentio/routes.d.ts +5 -5
- package/dist/integrations/incidentio/routes.d.ts.map +1 -1
- package/dist/integrations/incidentio/routes.js +3 -59
- package/dist/integrations/incidentio/routes.js.map +1 -1
- package/dist/integrations/incidentio/rules.d.ts.map +1 -1
- package/dist/integrations/incidentio/rules.js +15 -9
- package/dist/integrations/incidentio/rules.js.map +1 -1
- package/dist/integrations/jira/issue-reconciler.d.ts +1 -1
- package/dist/integrations/jira/issue-reconciler.d.ts.map +1 -1
- package/dist/integrations/jira/issue-reconciler.js.map +1 -1
- package/dist/integrations/jira/routes.d.ts +2 -2
- package/dist/integrations/jira/routes.d.ts.map +1 -1
- package/dist/integrations/jira/routes.js +0 -68
- package/dist/integrations/jira/routes.js.map +1 -1
- package/dist/integrations/jira/rules.d.ts.map +1 -1
- package/dist/integrations/jira/rules.js +13 -7
- package/dist/integrations/jira/rules.js.map +1 -1
- package/dist/integrations/linear/routes.d.ts +2 -2
- package/dist/integrations/linear/routes.d.ts.map +1 -1
- package/dist/integrations/linear/routes.js +0 -83
- package/dist/integrations/linear/routes.js.map +1 -1
- package/dist/integrations/linear/rules.d.ts.map +1 -1
- package/dist/integrations/linear/rules.js +14 -7
- package/dist/integrations/linear/rules.js.map +1 -1
- package/dist/integrations/platform/github/event-worker.js +9 -1
- package/dist/integrations/platform/github/event-worker.js.map +1 -1
- package/dist/integrations/platform/github/integration.d.ts +6 -6
- package/dist/integrations/platform/github/integration.d.ts.map +1 -1
- package/dist/integrations/platform/github/integration.js +23 -6
- package/dist/integrations/platform/github/integration.js.map +1 -1
- package/dist/integrations/platform/jira/routes.d.ts +2 -2
- package/dist/integrations/platform/jira/routes.d.ts.map +1 -1
- package/dist/integrations/platform/jira/routes.js +0 -69
- package/dist/integrations/platform/jira/routes.js.map +1 -1
- package/dist/integrations/pull-request-head.d.ts +1 -1
- package/dist/integrations/pull-request-head.d.ts.map +1 -1
- package/dist/integrations/pull-request-head.js +5 -0
- package/dist/integrations/pull-request-head.js.map +1 -1
- package/dist/integrations/vanta/rules.d.ts.map +1 -1
- package/dist/integrations/vanta/rules.js +2 -6
- package/dist/integrations/vanta/rules.js.map +1 -1
- package/dist/packages/_internals/workspace/dist/index.js.map +1 -1
- package/dist/routes/automation-runs.d.ts +0 -2
- package/dist/routes/automation-runs.d.ts.map +1 -1
- package/dist/routes/automation-runs.js +2 -6
- package/dist/routes/automation-runs.js.map +1 -1
- package/dist/routes/board-snapshot.d.ts +8 -1
- package/dist/routes/board-snapshot.d.ts.map +1 -1
- package/dist/routes/board-snapshot.js +33 -7
- package/dist/routes/board-snapshot.js.map +1 -1
- package/dist/routes/boards.js.map +1 -1
- package/dist/routes/config.d.ts +6 -0
- package/dist/routes/config.d.ts.map +1 -1
- package/dist/routes/config.js +5 -2
- package/dist/routes/config.js.map +1 -1
- package/dist/routes/contracts.d.ts +1258 -5
- package/dist/routes/contracts.d.ts.map +1 -1
- package/dist/routes/contracts.js +588 -17
- package/dist/routes/contracts.js.map +1 -1
- package/dist/routes/fs.d.ts +10 -0
- package/dist/routes/fs.d.ts.map +1 -1
- package/dist/routes/fs.js +184 -11
- package/dist/routes/fs.js.map +1 -1
- package/dist/routes/intake-check.d.ts +92 -0
- package/dist/routes/intake-check.d.ts.map +1 -0
- package/dist/routes/intake-check.js +322 -0
- package/dist/routes/intake-check.js.map +1 -0
- package/dist/routes/intake-routes.d.ts +10 -2
- package/dist/routes/intake-routes.d.ts.map +1 -1
- package/dist/routes/intake-routes.js +292 -11
- package/dist/routes/intake-routes.js.map +1 -1
- package/dist/routes/mastra-gateway.d.ts.map +1 -1
- package/dist/routes/mastra-gateway.js +3 -2
- package/dist/routes/mastra-gateway.js.map +1 -1
- package/dist/routes/project-sessions.d.ts +49 -0
- package/dist/routes/project-sessions.d.ts.map +1 -0
- package/dist/routes/project-sessions.js +93 -0
- package/dist/routes/project-sessions.js.map +1 -0
- package/dist/routes/projects.d.ts.map +1 -1
- package/dist/routes/projects.js +4 -17
- package/dist/routes/projects.js.map +1 -1
- package/dist/routes/run-queue.d.ts +6 -6
- package/dist/routes/run-queue.d.ts.map +1 -1
- package/dist/routes/run-queue.js +28 -8
- package/dist/routes/run-queue.js.map +1 -1
- package/dist/routes/session-rows.d.ts +30 -0
- package/dist/routes/session-rows.d.ts.map +1 -0
- package/dist/routes/session-rows.js +98 -0
- package/dist/routes/session-rows.js.map +1 -0
- package/dist/routes/source-control-sessions.d.ts +4 -8
- package/dist/routes/source-control-sessions.d.ts.map +1 -1
- package/dist/routes/source-control-sessions.js +8 -106
- package/dist/routes/source-control-sessions.js.map +1 -1
- package/dist/routes/surface.d.ts +13 -3
- package/dist/routes/surface.d.ts.map +1 -1
- package/dist/routes/surface.js +25 -38
- package/dist/routes/surface.js.map +1 -1
- package/dist/routes/work-item-starters.d.ts +1 -0
- package/dist/routes/work-item-starters.d.ts.map +1 -1
- package/dist/routes/work-item-starters.js +14 -2
- package/dist/routes/work-item-starters.js.map +1 -1
- package/dist/routes/work-items.d.ts +13 -0
- package/dist/routes/work-items.d.ts.map +1 -1
- package/dist/routes/work-items.js +87 -34
- package/dist/routes/work-items.js.map +1 -1
- package/dist/rules/dispatch-errors.js +1 -1
- package/dist/rules/dispatch-errors.js.map +1 -1
- package/dist/rules/dispatcher.d.ts +39 -7
- package/dist/rules/dispatcher.d.ts.map +1 -1
- package/dist/rules/dispatcher.js +362 -127
- package/dist/rules/dispatcher.js.map +1 -1
- package/dist/rules/event-rules.d.ts +69 -1
- package/dist/rules/event-rules.d.ts.map +1 -1
- package/dist/rules/event-rules.js +151 -5
- package/dist/rules/event-rules.js.map +1 -1
- package/dist/rules/processor.d.ts.map +1 -1
- package/dist/rules/processor.js +1 -6
- package/dist/rules/processor.js.map +1 -1
- package/dist/rules/review-source-tool.js +1 -1
- package/dist/rules/rule-group.d.ts +18 -1
- package/dist/rules/rule-group.d.ts.map +1 -1
- package/dist/rules/rule-group.js +52 -8
- package/dist/rules/rule-group.js.map +1 -1
- package/dist/rules/run-bearing.d.ts +8 -0
- package/dist/rules/run-bearing.d.ts.map +1 -0
- package/dist/rules/run-bearing.js +11 -0
- package/dist/rules/run-bearing.js.map +1 -0
- package/dist/rules/start-coordinator.d.ts +2 -3
- package/dist/rules/start-coordinator.d.ts.map +1 -1
- package/dist/rules/start-coordinator.js +27 -35
- package/dist/rules/start-coordinator.js.map +1 -1
- package/dist/rules/tools.js +2 -1
- package/dist/rules/tools.js.map +1 -1
- package/dist/rules/transition-service.d.ts +16 -0
- package/dist/rules/transition-service.d.ts.map +1 -1
- package/dist/rules/transition-service.js +34 -12
- package/dist/rules/transition-service.js.map +1 -1
- package/dist/rules/types.d.ts +18 -5
- package/dist/rules/types.d.ts.map +1 -1
- package/dist/rules/types.js +2 -1
- package/dist/rules/types.js.map +1 -1
- package/dist/rules/update-fold.d.ts +32 -0
- package/dist/rules/update-fold.d.ts.map +1 -0
- package/dist/rules/update-fold.js +60 -0
- package/dist/rules/update-fold.js.map +1 -0
- package/dist/rules/validation.d.ts.map +1 -1
- package/dist/rules/validation.js +54 -6
- package/dist/rules/validation.js.map +1 -1
- package/dist/session/resource-migration.d.ts.map +1 -1
- package/dist/session/resource-migration.js +2 -3
- package/dist/session/resource-migration.js.map +1 -1
- package/dist/session/run-audit.d.ts +9 -0
- package/dist/session/run-audit.d.ts.map +1 -1
- package/dist/session/run-audit.js +9 -1
- package/dist/session/run-audit.js.map +1 -1
- package/dist/session/self-review-gate.d.ts +26 -2
- package/dist/session/self-review-gate.d.ts.map +1 -1
- package/dist/session/self-review-gate.js +60 -10
- package/dist/session/self-review-gate.js.map +1 -1
- package/dist/session/session-row-query.d.ts +25 -0
- package/dist/session/session-row-query.d.ts.map +1 -0
- package/dist/session/session-row-query.js +47 -0
- package/dist/session/session-row-query.js.map +1 -0
- package/dist/session/session-row-status.d.ts +16 -0
- package/dist/session/session-row-status.d.ts.map +1 -0
- package/dist/session/session-row-status.js +14 -0
- package/dist/session/session-row-status.js.map +1 -0
- package/dist/session/session-row-view.d.ts +14 -0
- package/dist/session/session-row-view.d.ts.map +1 -0
- package/dist/session/session-row-view.js +125 -0
- package/dist/session/session-row-view.js.map +1 -0
- package/dist/session/session-rows.d.ts +46 -0
- package/dist/session/session-rows.d.ts.map +1 -0
- package/dist/session/session-rows.js +232 -0
- package/dist/session/session-rows.js.map +1 -0
- package/dist/session/session-threads.d.ts.map +1 -1
- package/dist/session/session-threads.js +1 -0
- package/dist/session/session-threads.js.map +1 -1
- package/dist/session/source-control-tools.d.ts +14 -7
- package/dist/session/source-control-tools.d.ts.map +1 -1
- package/dist/session/source-control-tools.js +10 -2
- package/dist/session/source-control-tools.js.map +1 -1
- package/dist/session/work-item-repository.d.ts +44 -0
- package/dist/session/work-item-repository.d.ts.map +1 -1
- package/dist/session/work-item-repository.js +80 -1
- package/dist/session/work-item-repository.js.map +1 -1
- package/dist/session/work-item-state-processor.d.ts.map +1 -1
- package/dist/session/work-item-state-processor.js +44 -8
- package/dist/session/work-item-state-processor.js.map +1 -1
- package/dist/storage/domains/audit/actions.d.ts +2 -1
- package/dist/storage/domains/audit/actions.d.ts.map +1 -1
- package/dist/storage/domains/audit/actions.js +3 -1
- package/dist/storage/domains/audit/actions.js.map +1 -1
- package/dist/storage/domains/boards/base.d.ts +162 -14
- package/dist/storage/domains/boards/base.d.ts.map +1 -1
- package/dist/storage/domains/boards/base.js +415 -41
- package/dist/storage/domains/boards/base.js.map +1 -1
- package/dist/storage/domains/boards/schemas.d.ts +6 -0
- package/dist/storage/domains/boards/schemas.d.ts.map +1 -1
- package/dist/storage/domains/boards/schemas.js +93 -3
- package/dist/storage/domains/boards/schemas.js.map +1 -1
- package/dist/storage/domains/intake/base.d.ts +11 -10
- package/dist/storage/domains/intake/base.d.ts.map +1 -1
- package/dist/storage/domains/intake/base.js +30 -65
- package/dist/storage/domains/intake/base.js.map +1 -1
- package/dist/storage/domains/integrations/base.d.ts +0 -2
- package/dist/storage/domains/integrations/base.d.ts.map +1 -1
- package/dist/storage/domains/integrations/base.js +0 -6
- package/dist/storage/domains/integrations/base.js.map +1 -1
- package/dist/storage/domains/projects/base.d.ts.map +1 -1
- package/dist/storage/domains/projects/base.js +19 -22
- package/dist/storage/domains/projects/base.js.map +1 -1
- package/dist/storage/domains/source-control/base.d.ts +0 -10
- package/dist/storage/domains/source-control/base.d.ts.map +1 -1
- package/dist/storage/domains/source-control/base.js +6 -21
- package/dist/storage/domains/source-control/base.js.map +1 -1
- package/dist/storage/domains/source-control/inmemory.d.ts +1 -1
- package/dist/storage/domains/source-control/inmemory.d.ts.map +1 -1
- package/dist/storage/domains/source-control/inmemory.js +1 -6
- package/dist/storage/domains/source-control/inmemory.js.map +1 -1
- package/dist/storage/domains/work-items/base.d.ts +49 -53
- package/dist/storage/domains/work-items/base.d.ts.map +1 -1
- package/dist/storage/domains/work-items/base.js +152 -156
- package/dist/storage/domains/work-items/base.js.map +1 -1
- package/dist/storage/domains/work-items/cards.d.ts +3 -2
- package/dist/storage/domains/work-items/cards.d.ts.map +1 -1
- package/dist/storage/domains/work-items/cards.js +4 -2
- package/dist/storage/domains/work-items/cards.js.map +1 -1
- package/dist/storage/domains/work-items/work-item-schema.d.ts +12 -3
- package/dist/storage/domains/work-items/work-item-schema.d.ts.map +1 -1
- package/dist/storage/domains/work-items/work-item-schema.js +12 -3
- package/dist/storage/domains/work-items/work-item-schema.js.map +1 -1
- package/dist/storage/legacy-collections.d.ts +9 -0
- package/dist/storage/legacy-collections.d.ts.map +1 -0
- package/dist/storage/legacy-collections.js +17 -0
- package/dist/storage/legacy-collections.js.map +1 -0
- package/dist/storage/probed-list.d.ts +11 -0
- package/dist/storage/probed-list.d.ts.map +1 -0
- package/dist/storage/probed-list.js +52 -0
- package/dist/storage/probed-list.js.map +1 -0
- package/dist/tools/audit-events-tool.d.ts +2 -2
- package/dist/tools/read-tools.d.ts +0 -3
- package/dist/tools/read-tools.d.ts.map +1 -1
- package/dist/tools/read-tools.js +4 -42
- package/dist/tools/read-tools.js.map +1 -1
- package/dist/tools/session-tools.d.ts.map +1 -1
- package/dist/tools/session-tools.js +5 -9
- package/dist/tools/session-tools.js.map +1 -1
- package/dist/tools/work-item-tools.d.ts +3 -0
- package/dist/tools/work-item-tools.d.ts.map +1 -1
- package/dist/tools/work-item-tools.js +8 -4
- package/dist/tools/work-item-tools.js.map +1 -1
- package/dist/work-item-branch.d.ts +4 -0
- package/dist/work-item-branch.d.ts.map +1 -1
- package/dist/work-item-branch.js +7 -1
- package/dist/work-item-branch.js.map +1 -1
- package/dist/work-items/card-context-sessions.d.ts +50 -0
- package/dist/work-items/card-context-sessions.d.ts.map +1 -0
- package/dist/work-items/card-context-sessions.js +84 -0
- package/dist/work-items/card-context-sessions.js.map +1 -0
- package/dist/work-items/change-requests.d.ts +87 -0
- package/dist/work-items/change-requests.d.ts.map +1 -0
- package/dist/work-items/change-requests.js +134 -0
- package/dist/work-items/change-requests.js.map +1 -0
- package/dist/work-items/create-work-item.d.ts +7 -2
- package/dist/work-items/create-work-item.d.ts.map +1 -1
- package/dist/work-items/create-work-item.js +44 -13
- package/dist/work-items/create-work-item.js.map +1 -1
- package/dist/work-items/list-related-cards.d.ts.map +1 -1
- package/dist/work-items/list-related-cards.js +1 -1
- package/dist/work-items/list-related-cards.js.map +1 -1
- package/dist/work-items/providers/github.d.ts.map +1 -1
- package/dist/work-items/providers/github.js +1 -0
- package/dist/work-items/providers/github.js.map +1 -1
- package/dist/workspace.d.ts.map +1 -1
- package/dist/workspace.js +1 -3
- package/dist/workspace.js.map +1 -1
- package/factory-skills/configure-factory-rules/SKILL.md +2 -2
- package/factory-skills/factory-build/SKILL.md +1 -1
- package/factory-skills/factory-plan/SKILL.md +5 -3
- package/factory-skills/factory-self-review/SKILL.md +2 -0
- package/factory-skills/factory-triage/SKILL.md +1 -1
- package/package.json +10 -10
- package/dist/session/filesystem-capture.d.ts +0 -50
- package/dist/session/filesystem-capture.d.ts.map +0 -1
- package/dist/session/filesystem-capture.js +0 -229
- package/dist/session/filesystem-capture.js.map +0 -1
- package/dist/storage/domains/filesystem/base.d.ts +0 -30
- package/dist/storage/domains/filesystem/base.d.ts.map +0 -1
- package/dist/storage/domains/filesystem/base.js +0 -78
- package/dist/storage/domains/filesystem/base.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.js","names":[],"sources":["../../../../src/storage/domains/boards/base.ts"],"sourcesContent":["import { randomUUID } from 'node:crypto';\n\nimport { FactoryStorageDomain, UniqueViolationError } from '@mastra/core/storage';\nimport type { FactoryStorageOps } from '@mastra/core/storage';\n\nimport { DEFAULT_ROUTE_EVENTS, routeEventsProblem } from '../../../boards/board-events.js';\nimport type { StatusEvent } from '../../../boards/board-events.js';\nimport type { FactoryPhaseTool } from '../../../boards/define-board.js';\nimport { DEFAULT_INTAKE_ROUTES } from '../../../boards/work-routes.js';\nimport type { RuleGroup } from '../../../rules/rule-group.js';\nimport type { RetiredAutomationSettings } from '../projects/base.js';\nimport {\n FACTORY_BOARD_DEFINITION_VERSIONS_SCHEMA,\n FACTORY_BOARD_PHASES_SCHEMA,\n FACTORY_BOARDS_SCHEMA,\n FACTORY_INTAKE_ROUTE_LOCKS_SCHEMA,\n FACTORY_INTAKE_ROUTES_SCHEMA,\n} from './schemas.js';\n\n/** The project a board belongs to. */\nexport interface StoredBoardScope {\n orgId: string;\n factoryProjectId: string;\n}\n\nexport type StoredPhaseKind = 'resting' | 'working' | 'terminal';\n\n/** Who runs a working phase. Factory runs every phase with its code agent. */\nexport interface StoredPhaseRunner {\n skill?: string;\n context?: string;\n instructions?: string;\n /** The objective the phase's runs pursue as a goal. */\n goal?: { objective: string; maxRuns?: number };\n}\n\nexport interface StoredPhaseExitTool {\n id: string;\n autoApprove?: boolean;\n autoApproveWhen?: RuleGroup;\n}\n\n/** A phase as it is written. `key` is the stage id cards sit in. */\nexport interface StoredPhaseInput {\n key: string;\n name: string;\n description?: string | null;\n kind: StoredPhaseKind;\n runner?: StoredPhaseRunner | null;\n /** Unset or `null` on a resting or working phase means every other phase; `[]` means none. */\n nextPhases?: string[] | null;\n autoStart?: boolean;\n autoStartWhen?: RuleGroup | null;\n exitTool?: StoredPhaseExitTool | null;\n /** Factory tools the phase grants the session working the card there. */\n tools?: FactoryPhaseTool[] | null;\n}\n\n/** A board as it is written. Phase order is significant: the first phase is where cards start. */\nexport interface StoredBoardInput {\n key: string;\n name: string;\n description?: string | null;\n phases: StoredPhaseInput[];\n}\n\nexport interface StoredPhaseRecord {\n key: string;\n position: number;\n name: string;\n description: string | null;\n kind: StoredPhaseKind;\n runner: StoredPhaseRunner | null;\n nextPhases: string[] | null;\n autoStart: boolean;\n autoStartWhen: RuleGroup | null;\n exitTool: StoredPhaseExitTool | null;\n tools: FactoryPhaseTool[] | null;\n}\n\nexport interface StoredBoardRecord {\n id: string;\n orgId: string;\n factoryProjectId: string;\n key: string;\n name: string;\n description: string | null;\n position: number;\n revision: number;\n createdBy: string;\n createdAt: Date;\n updatedBy: string;\n updatedAt: Date;\n phases: StoredPhaseRecord[];\n}\n\n/** What a board migration may know about the project besides the board it rewrites. */\nexport interface BoardMigrationContext {\n /** The project switches the boards replaced, as the project last stored them; null when unknown. */\n readonly retiredSettings: RetiredAutomationSettings | null;\n /** The phases of each board that cards sit in, by board key; null when the cards can't be read. */\n readonly occupiedPhases: ReadonlyMap<string, ReadonlySet<string>> | null;\n /**\n * The phases the code board under this key declares; undefined for a board only the project\n * stores. A row that drops one runs without its code rules (`mergeCodeBehaviour`).\n */\n codePhases(boardKey: string): ReadonlySet<string> | undefined;\n /** Tells the operator about a board a migration left as it is. */\n warn(message: string): void;\n}\n\n/** A one-time rewrite of a stored board, keyed so each project gets it once. */\nexport interface StoredBoardMigration {\n key: string;\n /** The board it rewrites; `null` rewrites every board the project stores. */\n boardKey: string | null;\n /** The board to write instead, with what changed; undefined leaves it as it is. */\n migrate(\n board: StoredBoardRecord,\n context: BoardMigrationContext,\n ): { board: Omit<StoredBoardInput, 'key'>; filled: string[] } | undefined;\n}\n\nconst EMPTY_MIGRATION_CONTEXT: BoardMigrationContext = {\n retiredSettings: null,\n occupiedPhases: new Map(),\n codePhases: () => undefined,\n warn: () => {},\n};\n\nexport interface AppliedBoardMigration {\n key: string;\n boardKey: string;\n filled: string[];\n}\n\nexport interface StoredBoardSnapshot {\n version: string | null;\n boards: StoredBoardRecord[];\n}\n\nexport interface IntakeRouteTarget {\n boardKey: string;\n /**\n * Unset lands the card in the board's first phase. On a route that joins a closed issue's\n * card, the phase that card moves to when its board allows it; unset leaves it where it is.\n */\n phaseKey?: string | null;\n /**\n * Files a pull request on the card of the issue it closes, which must be on `boardKey`, as one\n * more source instead of a card of its own. The route doesn't match any other arrival.\n */\n joinClosedIssue?: boolean;\n}\n\n/** An intake route as it is written. */\nexport interface StoredIntakeRouteInput {\n name: string;\n enabled?: boolean;\n /** Null matches every card. */\n when?: RuleGroup | null;\n target: IntakeRouteTarget;\n /** The status events the route handles; unset handles new cards (`work_item.created`). */\n on?: StatusEvent[];\n}\n\nexport interface StoredIntakeRouteRecord {\n id: string;\n orgId: string;\n factoryProjectId: string;\n name: string;\n enabled: boolean;\n position: number;\n when: RuleGroup | null;\n target: { boardKey: string; phaseKey: string | null; joinClosedIssue: boolean };\n on: StatusEvent[];\n revision: number;\n createdBy: string;\n createdAt: Date;\n updatedBy: string;\n updatedAt: Date;\n}\n\nexport type StoredBoardErrorCode =\n | 'board_exists'\n | 'board_not_found'\n | 'revision_mismatch'\n | 'intake_route_not_found'\n | 'intake_route_set_mismatch'\n | 'intake_route_limit'\n | 'invalid_intake_route';\n\n/** A project's most intake routes; a reorder names every one of them. */\nexport const MAX_INTAKE_ROUTES = 100;\n\n// Work's routes are its seed data, kept with the board they target.\nexport {\n DEFAULT_INTAKE_ROUTE,\n PULL_REQUEST_INTAKE_ROUTE,\n CLOSED_COMPLETED_ROUTE,\n CLOSED_CANCELED_ROUTE,\n REOPENED_ROUTE,\n PULL_REQUEST_MERGED_ROUTE,\n PULL_REQUEST_CLOSED_ROUTE,\n PULL_REQUEST_CLOSED_ISSUE_ROUTE,\n PULL_REQUEST_UPDATED_ROUTE,\n PULL_REQUEST_REVIEW_REQUESTED_ROUTE,\n CLOSES_ISSUE_INTAKE_ROUTE,\n CATCH_ALL_INTAKE_ROUTE,\n DEFAULT_INTAKE_ROUTES,\n} from '../../../boards/work-routes.js';\n\n/** The defaults a project whose lock row predates `seeded_defaults` was set up with. */\nconst ORIGINAL_DEFAULT_KEYS = ['outside-authors'];\n\n/** Who the default intake routes are created and last updated by. */\nexport const DEFAULT_INTAKE_ROUTE_ACTOR = 'factory';\n\nexport class StoredBoardError extends Error {\n override name = 'StoredBoardError';\n constructor(\n readonly code: StoredBoardErrorCode,\n message: string,\n ) {\n super(message);\n }\n}\n\ninterface BoardRow extends Record<string, unknown> {\n id: string;\n org_id: string;\n factory_project_id: string;\n board_key: string;\n name: string;\n description: string | null;\n position: number;\n revision: number;\n created_by: string;\n created_at: Date;\n updated_by: string;\n updated_at: Date;\n}\n\ninterface VersionRow extends Record<string, unknown> {\n version: string;\n /** Keys of the boards Factory stored in the project; null on rows written before the list. */\n seeded_boards: string[] | null;\n /** Keys of the board migrations applied to the project; null before the first one. */\n applied_migrations: string[] | null;\n}\n\ninterface PhaseRow extends Record<string, unknown> {\n id: string;\n org_id: string;\n factory_project_id: string;\n board_key: string;\n phase_key: string;\n position: number;\n name: string;\n description: string | null;\n kind: StoredPhaseKind;\n runner: StoredPhaseRunner | null;\n next_phases: string[] | null;\n auto_start: boolean;\n auto_start_when: RuleGroup | null;\n exit_tool: StoredPhaseExitTool | null;\n tools: FactoryPhaseTool[] | null;\n}\n\ninterface IntakeRouteRow extends Record<string, unknown> {\n id: string;\n org_id: string;\n factory_project_id: string;\n name: string;\n enabled: boolean;\n position: number;\n when_condition: RuleGroup | null;\n board_key: string;\n phase_key: string | null;\n /** Null on rows written before routes named events: they place new cards. */\n on_events: StatusEvent[] | null;\n join_closed_issue: boolean | null;\n revision: number;\n created_by: string;\n created_at: Date;\n updated_by: string;\n updated_at: Date;\n}\n\ninterface IntakeRouteLockRow extends Record<string, unknown> {\n /** Keys of the `DEFAULT_INTAKE_ROUTES` added to the project; null on rows written before the list. */\n seeded_defaults: string[] | null;\n}\n\nfunction seededDefaults(lock: IntakeRouteLockRow): string[] {\n return lock.seeded_defaults ?? ORIGINAL_DEFAULT_KEYS;\n}\n\nfunction missingDefaults(lock: IntakeRouteLockRow): (typeof DEFAULT_INTAKE_ROUTES)[number][] {\n const seeded = new Set(seededDefaults(lock));\n return DEFAULT_INTAKE_ROUTES.filter(({ key }) => !seeded.has(key));\n}\n\nconst BOARDS = 'factory_boards';\nconst PHASES = 'factory_board_phases';\nconst VERSIONS = 'factory_board_definition_versions';\nconst INTAKE_ROUTES = 'factory_intake_routes';\nconst INTAKE_ROUTE_LOCKS = 'factory_intake_route_locks';\nconst MAX_WRITE_ATTEMPTS = 3;\nconst MIGRATION_ACTOR = 'factory';\n\nfunction scopeWhere({ orgId, factoryProjectId }: StoredBoardScope) {\n return { org_id: orgId, factory_project_id: factoryProjectId };\n}\n\nfunction toPhaseRecord(row: PhaseRow): StoredPhaseRecord {\n return {\n key: row.phase_key,\n position: row.position,\n name: row.name,\n description: row.description,\n kind: row.kind,\n runner: row.runner,\n nextPhases: row.next_phases,\n autoStart: row.auto_start,\n autoStartWhen: row.auto_start_when,\n exitTool: row.exit_tool,\n tools: row.tools ?? null,\n };\n}\n\nfunction toRecord(row: BoardRow, phases: PhaseRow[]): StoredBoardRecord {\n return {\n id: row.id,\n orgId: row.org_id,\n factoryProjectId: row.factory_project_id,\n key: row.board_key,\n name: row.name,\n description: row.description,\n position: row.position,\n revision: row.revision,\n createdBy: row.created_by,\n createdAt: row.created_at,\n updatedBy: row.updated_by,\n updatedAt: row.updated_at,\n phases: phases.sort((left, right) => left.position - right.position).map(toPhaseRecord),\n };\n}\n\n/** Runs inside a board write's transaction, before the board is written. */\nexport type BoardWriteStep = (ops: FactoryStorageOps) => Promise<void>;\n\n/** A compare-and-set inside a write lost to a concurrent writer; the write is retried from fresh reads. */\nclass ConcurrentBoardWrite extends Error {}\n\n/**\n * Each project's boards and their ordered phases. Every write runs in one transaction that also\n * replaces the project's row in `factory_board_definition_versions`, so caches on other\n * replicas can detect it.\n */\nexport class StoredBoardsStorage extends FactoryStorageDomain {\n constructor() {\n super('boards');\n }\n\n async init(): Promise<void> {\n await this.ensureCollections([\n FACTORY_BOARDS_SCHEMA,\n FACTORY_BOARD_PHASES_SCHEMA,\n FACTORY_BOARD_DEFINITION_VERSIONS_SCHEMA,\n FACTORY_INTAKE_ROUTES_SCHEMA,\n FACTORY_INTAKE_ROUTE_LOCKS_SCHEMA,\n ]);\n }\n\n async dangerouslyClearAll(): Promise<void> {\n await this.ops.deleteMany(PHASES, {});\n await this.ops.deleteMany(BOARDS, {});\n await this.ops.deleteMany(VERSIONS, {});\n await this.ops.deleteMany(INTAKE_ROUTES, {});\n await this.ops.deleteMany(INTAKE_ROUTE_LOCKS, {});\n }\n\n /** The project's current definition version; null before its first board write. */\n async readVersion(scope: StoredBoardScope): Promise<string | null> {\n return readVersion(this.ops, scope);\n }\n\n /** The project's boards in order. */\n async list(scope: StoredBoardScope): Promise<StoredBoardRecord[]> {\n return readBoards(this.ops, scope);\n }\n\n /**\n * The version and the boards, read in that order: a write landing between the two reads leaves a\n * version older than the rows, so a cache keyed on it rereads on its next check instead of\n * keeping the stale rows.\n */\n async snapshot(scope: StoredBoardScope): Promise<StoredBoardSnapshot> {\n const version = await readVersion(this.ops, scope);\n return { version, boards: await this.list(scope) };\n }\n\n get(scope: StoredBoardScope, key: string): Promise<StoredBoardRecord | null> {\n return readStoredBoard(this.ops, scope, key);\n }\n\n /**\n * Creates a board through the API. `before` runs in the same transaction, once the key is known\n * to be free. A row under the key that `over` accepts does not hold it: the board is written\n * over that row.\n */\n async create(\n scope: StoredBoardScope,\n input: StoredBoardInput,\n actor: string,\n before?: BoardWriteStep,\n over?: (row: StoredBoardRecord) => boolean,\n ): Promise<StoredBoardRecord> {\n await ensureVersionRow(this.ops, scope);\n try {\n return await this.#write(scope, async ops => {\n const rows = await ops.findMany<BoardRow>(BOARDS, scopeWhere(scope));\n const taken = rows.find(row => row.board_key === input.key);\n const stored = taken && over ? await readStoredBoard(ops, scope, input.key) : null;\n if (taken && !(stored && over?.(stored))) {\n throw new StoredBoardError('board_exists', `Board \"${input.key}\" already exists in this project.`);\n }\n await before?.(ops);\n if (taken) await writeBoard(ops, scope, taken, input, actor);\n else await insertBoard(ops, scope, input, { position: nextPosition(rows), actor });\n return { result: undefined, changed: true };\n }).then(async () => (await this.get(scope, input.key))!);\n } catch (error) {\n // Only the board key's index means the board exists; a lost race on another table is not that.\n if (error instanceof UniqueViolationError && error.collection === BOARDS) {\n throw new StoredBoardError('board_exists', `Board \"${input.key}\" already exists in this project.`);\n }\n throw error;\n }\n }\n\n /** Replaces a board's name, description and phases. The board key never changes. */\n async replace(\n scope: StoredBoardScope,\n key: string,\n input: Omit<StoredBoardInput, 'key'>,\n options: { expectedRevision: number; actor: string; before?: BoardWriteStep },\n ): Promise<StoredBoardRecord> {\n await this.#write(scope, async ops => {\n const row = await findBoard(ops, scope, key);\n checkRevision(row, key, options.expectedRevision);\n await options.before?.(ops);\n await writeBoard(ops, scope, row, { key, ...input }, options.actor);\n return { result: undefined, changed: true };\n });\n return (await this.get(scope, key))!;\n }\n\n /**\n * Stores Factory's boards (Work, app and seed boards) in the project, each key once: a key the\n * project has had before is skipped even if its board was deleted since, and a stored board is\n * never rewritten. A project stored before the list was kept counts the boards it has as stored.\n * Reads one row when every key was stored before. Returns the keys it inserted.\n *\n * A key in `onlyIntoEmpty` is inserted only into a project that has no boards at all: one that\n * already has any board, such as one an app stored under that key, is left as it is. The key\n * is still recorded as stored, so it never goes in later, even after the project's boards are\n * deleted: that project chose its boards, and Work is never added beside or after them. The\n * `intoEmpty` boards (an app's, for every project) go first into a project with no boards, so\n * Factory's own under the same key, or in `onlyIntoEmpty`, then stay out. `actor` is recorded\n * as the inserted boards' creator. `before` runs in the same\n * transaction ahead of each board it inserts.\n */\n async seedBoards(\n scope: StoredBoardScope,\n boards: readonly StoredBoardInput[],\n options: {\n actor?: string;\n onlyIntoEmpty?: readonly string[];\n intoEmpty?: readonly StoredBoardInput[];\n before?: (ops: FactoryStorageOps, key: string) => Promise<void>;\n } = {},\n ): Promise<string[]> {\n const marker = await this.ops.findOne<VersionRow>(VERSIONS, scopeWhere(scope));\n if (marker?.seeded_boards && boards.every(board => marker.seeded_boards!.includes(board.key))) return [];\n return this.#insertOnce(scope, boards, {\n actor: options.actor ?? DEFAULT_INTAKE_ROUTE_ACTOR,\n skipSeeded: true,\n onlyIntoEmpty: options.onlyIntoEmpty ?? [],\n intoEmpty: options.intoEmpty ?? [],\n before: options.before,\n });\n }\n\n /** The keys of the boards Factory stored in the project; null before it kept the list. */\n async seededBoardKeys(scope: StoredBoardScope): Promise<string[] | null> {\n return (await this.ops.findOne<VersionRow>(VERSIONS, scopeWhere(scope)))?.seeded_boards ?? null;\n }\n\n /**\n * Rewrites the board stored under `seed.key` to `seed` at its next revision when `when` says the\n * row is nobody's: one an earlier release seeded for a board Factory no longer has, under a key\n * the app now defines. `before` runs in the same transaction. Returns whether it rewrote the row.\n */\n async adoptSeed(\n scope: StoredBoardScope,\n seed: StoredBoardInput,\n options: { when: (row: StoredBoardRecord) => boolean; before?: BoardWriteStep },\n ): Promise<boolean> {\n return this.#write(scope, async ops => {\n const stored = await readStoredBoard(ops, scope, seed.key);\n if (!stored || !options.when(stored)) return { result: false, changed: false };\n await options.before?.(ops);\n await writeBoard(ops, scope, await findBoard(ops, scope, seed.key), seed, DEFAULT_INTAKE_ROUTE_ACTOR);\n return { result: true, changed: true };\n });\n }\n\n /**\n * Inserts a board into the project unless one is stored under its key, and records the key as\n * stored, so seeding never adds it again. Unlike seeding, it inserts a key the project deleted.\n * Returns whether it inserted the board. `before` runs in the same transaction when it does.\n */\n async insertIfMissing(\n scope: StoredBoardScope,\n board: StoredBoardInput,\n actor: string,\n before?: BoardWriteStep,\n ): Promise<boolean> {\n return (await this.#insertOnce(scope, [board], { actor, skipSeeded: false, before })).length > 0;\n }\n\n async #insertOnce(\n scope: StoredBoardScope,\n boards: readonly StoredBoardInput[],\n options: {\n actor: string;\n skipSeeded: boolean;\n onlyIntoEmpty?: readonly string[];\n intoEmpty?: readonly StoredBoardInput[];\n before?: (ops: FactoryStorageOps, key: string) => Promise<void>;\n },\n ): Promise<string[]> {\n await ensureVersionRow(this.ops, scope);\n return this.#transact(async ops => {\n const marker = (await ops.findOne<VersionRow>(VERSIONS, scopeWhere(scope)))!;\n const rows = await ops.findMany<BoardRow>(BOARDS, scopeWhere(scope));\n const present = new Set(rows.map(row => row.board_key));\n const seeded = new Set(marker.seeded_boards ?? present);\n // The `intoEmpty` boards go into a project with no boards, first; `onlyIntoEmpty` keys then\n // go in only when nothing is stored yet, so a project holding them gets no default beside them.\n const candidates = [...(rows.length === 0 ? (options.intoEmpty ?? []) : []), ...boards];\n let position = nextPosition(rows);\n const inserted: string[] = [];\n for (const board of candidates) {\n if (present.has(board.key) || (options.skipSeeded && seeded.has(board.key))) continue;\n if (present.size > 0 && options.onlyIntoEmpty?.includes(board.key)) continue;\n await options.before?.(ops, board.key);\n await insertBoard(ops, scope, board, { position: position++, actor: options.actor });\n present.add(board.key);\n inserted.push(board.key);\n }\n const next = [...new Set([...seeded, ...candidates.map(board => board.key)])];\n const unchanged = marker.seeded_boards !== null && next.length === marker.seeded_boards.length;\n if (inserted.length === 0 && unchanged) return inserted;\n // Compare-and-set on the version, and every marker write takes a new one: two replicas\n // recording different keys can't both match the version they read, so neither key is lost.\n const updated = await ops.updateMany(\n VERSIONS,\n { ...scopeWhere(scope), version: marker.version },\n {\n seeded_boards: next,\n version: randomUUID(),\n updated_at: new Date(),\n },\n );\n if (updated !== 1) throw new ConcurrentBoardWrite();\n return inserted;\n });\n }\n\n /**\n * Runs each migration the project hasn't had yet, once: the keys applied are recorded on the\n * project's version row in the same transaction as the board writes, and the compare-and-set on\n * its version makes a concurrent first load retry from fresh reads, where it finds them applied.\n * A migration whose board the project doesn't have is recorded without running, and the version\n * only changes when a board was rewritten. Reads one row\n * when every key was applied before. Returns what each migration that rewrote a board filled.\n */\n async applyBoardMigrations(\n scope: StoredBoardScope,\n migrations: readonly StoredBoardMigration[],\n /**\n * Read through the transaction's `ops`, again on every retry, and only when a migration is still\n * pending, so what it reports is as fresh as the boards the migrations rewrite.\n */\n context: (ops: FactoryStorageOps) => Promise<BoardMigrationContext> = async () => EMPTY_MIGRATION_CONTEXT,\n ): Promise<AppliedBoardMigration[]> {\n if (migrations.length === 0) return [];\n const marker = await this.ops.findOne<VersionRow>(VERSIONS, scopeWhere(scope));\n if (marker?.applied_migrations && migrations.every(({ key }) => marker.applied_migrations!.includes(key))) {\n return [];\n }\n await ensureVersionRow(this.ops, scope);\n return this.#transact(async ops => {\n const current = (await ops.findOne<VersionRow>(VERSIONS, scopeWhere(scope)))!;\n const applied = current.applied_migrations ?? [];\n const pending = migrations.filter(({ key }) => !applied.includes(key));\n if (pending.length === 0) return [];\n const project = await context(ops);\n const changed: AppliedBoardMigration[] = [];\n for (const migration of pending) {\n const rows =\n migration.boardKey === null\n ? await ops.findMany<BoardRow>(BOARDS, scopeWhere(scope))\n : await ops.findMany<BoardRow>(BOARDS, { ...scopeWhere(scope), board_key: migration.boardKey });\n for (const row of rows) {\n const phases = await ops.findMany<PhaseRow>(PHASES, { ...scopeWhere(scope), board_key: row.board_key });\n const result = migration.migrate(toRecord(row, phases), project);\n if (!result) continue;\n await writeBoard(ops, scope, row, { ...result.board, key: row.board_key }, MIGRATION_ACTOR);\n changed.push({ key: migration.key, boardKey: row.board_key, filled: result.filled });\n }\n }\n const updated = await ops.updateMany(\n VERSIONS,\n { ...scopeWhere(scope), version: current.version },\n {\n applied_migrations: [...applied, ...pending.map(({ key }) => key)],\n // Only a rewritten board is news to the other replicas' caches.\n version: changed.length > 0 ? randomUUID() : current.version,\n updated_at: new Date(),\n },\n );\n if (updated !== 1) throw new ConcurrentBoardWrite();\n return changed;\n });\n }\n\n /** Rewrites a board to `definition` (Factory's current one for its key), raising its revision. */\n async resetTo(\n scope: StoredBoardScope,\n key: string,\n definition: StoredBoardInput,\n options: { expectedRevision: number; actor: string },\n ): Promise<StoredBoardRecord> {\n await this.#write(scope, async ops => {\n const row = await findBoard(ops, scope, key);\n checkRevision(row, key, options.expectedRevision);\n await writeBoard(ops, scope, row, { ...definition, key }, options.actor);\n return { result: undefined, changed: true };\n });\n return (await this.get(scope, key))!;\n }\n\n /** Deletes a board and its phases. */\n async delete(scope: StoredBoardScope, key: string, options: { expectedRevision: number }): Promise<void> {\n await this.#write(scope, async ops => {\n const row = await findBoard(ops, scope, key);\n checkRevision(row, key, options.expectedRevision);\n if ((await ops.deleteMany(BOARDS, { id: row.id, revision: row.revision })) === 0)\n throw new ConcurrentBoardWrite();\n await ops.deleteMany(PHASES, { ...scopeWhere(scope), board_key: key });\n return { result: undefined, changed: true };\n });\n }\n\n /** The project's intake routes in the order they are tried; Factory's `DEFAULT_INTAKE_ROUTES` are added once each. */\n async listIntakeRoutes(scope: StoredBoardScope): Promise<StoredIntakeRouteRecord[]> {\n await this.#ensureIntakeRoutes(scope);\n return (await readIntakeRoutes(this.ops, scope)).map(toIntakeRouteRecord);\n }\n\n async getIntakeRoute(scope: StoredBoardScope, id: string): Promise<StoredIntakeRouteRecord | null> {\n const row = await this.ops.findOne<IntakeRouteRow>(INTAKE_ROUTES, { ...scopeWhere(scope), id });\n return row ? toIntakeRouteRecord(row) : null;\n }\n\n /**\n * Adds a route after the project's last one. A route that places new cards goes just ahead of the\n * first route that takes every new card instead, since after it it would never place one.\n */\n async createIntakeRoute(\n scope: StoredBoardScope,\n input: StoredIntakeRouteInput,\n actor: string,\n ): Promise<StoredIntakeRouteRecord> {\n const id = randomUUID();\n checkRouteEvents(input.on ?? DEFAULT_ROUTE_EVENTS, input.when ?? null);\n await this.#ensureIntakeRoutes(scope);\n await this.#transact(async ops => {\n const rows = await lockIntakeRoutes(ops, scope);\n if (rows.length >= MAX_INTAKE_ROUTES) {\n throw new StoredBoardError(\n 'intake_route_limit',\n `A project can have at most ${MAX_INTAKE_ROUTES} intake routes; delete one first.`,\n );\n }\n const position = rows.reduce((max, row) => Math.max(max, row.position), -1) + 1;\n await insertIntakeRoute(ops, scope, { id, input, position, actor });\n const ahead = (input.on ?? DEFAULT_ROUTE_EVENTS).includes('work_item.created')\n ? rows.findIndex(catchesEveryNewCard)\n : -1;\n if (ahead >= 0) {\n const added = (await readIntakeRoutes(ops, scope)).find(row => row.id === id)!;\n await placeIntakeRoutes(ops, rows.toSpliced(ahead, 0, added), actor);\n }\n });\n return (await this.getIntakeRoute(scope, id))!;\n }\n\n /** Changes the fields `patch` names; the route keeps its place in the order. */\n async updateIntakeRoute(\n scope: StoredBoardScope,\n id: string,\n patch: Partial<StoredIntakeRouteInput>,\n options: { expectedRevision: number; actor: string },\n ): Promise<StoredIntakeRouteRecord> {\n await this.#transact(async ops => {\n const row = await findIntakeRoute(ops, scope, id);\n checkIntakeRouteRevision(row, options.expectedRevision);\n checkRouteEvents(patch.on ?? routeEvents(row), patch.when !== undefined ? patch.when : row.when_condition);\n await updateIntakeRouteRow(ops, row, {\n ...(patch.on !== undefined && { on_events: patch.on }),\n ...(patch.name !== undefined && { name: patch.name }),\n ...(patch.enabled !== undefined && { enabled: patch.enabled }),\n ...(patch.when !== undefined && { when_condition: patch.when }),\n ...(patch.target !== undefined && {\n board_key: patch.target.boardKey,\n phase_key: patch.target.phaseKey ?? null,\n join_closed_issue: patch.target.joinClosedIssue ?? false,\n }),\n updated_by: options.actor,\n });\n });\n return (await this.getIntakeRoute(scope, id))!;\n }\n\n /** Deletes a route; the routes after it move up one place. */\n async deleteIntakeRoute(scope: StoredBoardScope, id: string, options: { expectedRevision: number }): Promise<void> {\n await this.#ensureIntakeRoutes(scope);\n await this.#transact(async ops => {\n const rows = await lockIntakeRoutes(ops, scope);\n const row = rows.find(route => route.id === id);\n if (!row) throw intakeRouteNotFound(id);\n checkIntakeRouteRevision(row, options.expectedRevision);\n if ((await ops.deleteMany(INTAKE_ROUTES, { id: row.id, revision: row.revision })) === 0) {\n throw new ConcurrentBoardWrite();\n }\n await placeIntakeRoutes(\n ops,\n rows.filter(route => route.id !== row.id),\n );\n });\n }\n\n /** Puts the project's routes in the order of `ids`, which must name every route exactly once. */\n async reorderIntakeRoutes(scope: StoredBoardScope, ids: string[], actor: string): Promise<StoredIntakeRouteRecord[]> {\n await this.#ensureIntakeRoutes(scope);\n await this.#transact(async ops => {\n const rows = await lockIntakeRoutes(ops, scope);\n const byId = new Map(rows.map(row => [row.id, row]));\n if (ids.length !== rows.length || new Set(ids).size !== ids.length || ids.some(id => !byId.has(id))) {\n throw new StoredBoardError(\n 'intake_route_set_mismatch',\n 'The order must list every intake route of the project exactly once; reload the routes and try again.',\n );\n }\n await placeIntakeRoutes(\n ops,\n ids.map(id => byId.get(id)!),\n actor,\n );\n });\n return this.listIntakeRoutes(scope);\n }\n\n /**\n * Creates the project's route lock row (see `FACTORY_INTAKE_ROUTE_LOCKS_SCHEMA`) and adds each of\n * `DEFAULT_INTAKE_ROUTES` the row doesn't list as added yet, after the project's routes. The row\n * records every default it added, so a project whose admin deleted one doesn't get it back. Runs\n * before, never inside, a write's transaction: the lock taken there must always be an update.\n */\n async #ensureIntakeRoutes(scope: StoredBoardScope): Promise<void> {\n const lock = await this.ops.findOne<IntakeRouteLockRow>(INTAKE_ROUTE_LOCKS, scopeWhere(scope));\n if (lock && missingDefaults(lock).length === 0) return;\n await this.#transact(async ops => {\n if (await ops.findOne(INTAKE_ROUTE_LOCKS, scopeWhere(scope))) await lockIntakeRoutes(ops, scope);\n // A racing first read inserted the lock row first: this one fails on the unique index and\n // retries, taking the lock above.\n else\n await ops.insertOne(INTAKE_ROUTE_LOCKS, { ...scopeWhere(scope), locked_at: new Date(), seeded_defaults: [] });\n // Read under the lock: a racing seeder that committed first already added what it listed.\n const current = (await ops.findOne<IntakeRouteLockRow>(INTAKE_ROUTE_LOCKS, scopeWhere(scope)))!;\n const missing = missingDefaults(current);\n if (missing.length === 0) return;\n const rows = await readIntakeRoutes(ops, scope);\n let position = rows.reduce((max, row) => Math.max(max, row.position), -1) + 1;\n const first: string[] = [];\n for (const { route, first: leads } of missing) {\n // A project at the limit keeps its own routes; the default counts as added all the same.\n if (position >= MAX_INTAKE_ROUTES) break;\n const id = randomUUID();\n await insertIntakeRoute(ops, scope, {\n id,\n input: route,\n position: position++,\n actor: DEFAULT_INTAKE_ROUTE_ACTOR,\n });\n if (leads) first.push(id);\n }\n // A project that had routes before gets a leading default ahead of them.\n if (first.length > 0 && rows.length > 0) {\n const placed = await readIntakeRoutes(ops, scope);\n const leading = new Set(first);\n await placeIntakeRoutes(ops, [\n ...first.map(id => placed.find(row => row.id === id)!),\n ...placed.filter(row => !leading.has(row.id)),\n ]);\n }\n await ops.updateMany(INTAKE_ROUTE_LOCKS, scopeWhere(scope), {\n seeded_defaults: [...seededDefaults(current), ...missing.map(({ key }) => key)],\n });\n });\n }\n\n /**\n * Runs `fn` in a transaction and replaces the project's version when it changed anything.\n * Lost races (a compare-and-set miss, or a concurrent write that inserted the same board or the\n * project's first version row) retry from fresh reads.\n */\n async #write<T>(\n scope: StoredBoardScope,\n fn: (ops: FactoryStorageOps) => Promise<{ result: T; changed: boolean }>,\n ): Promise<T> {\n return this.#transact(async ops => {\n const { result, changed } = await fn(ops);\n if (changed) await bumpVersion(ops, scope);\n return result;\n });\n }\n\n /**\n * Runs `fn` in a transaction, retrying lost races from fresh reads. Intake route writes use it\n * directly: routes are read uncached, so they leave the board definition version alone.\n */\n async #transact<T>(fn: (ops: FactoryStorageOps) => Promise<T>): Promise<T> {\n for (let attempt = 1; ; attempt++) {\n try {\n // Read committed is enough: every row change is a compare-and-set on `revision` and every\n // insert meets the unique index. Serializable isolation would also fail writes to\n // unrelated projects that replicas run side by side.\n return await this.storage.withTransaction(fn);\n } catch (error) {\n const retryable = error instanceof ConcurrentBoardWrite || error instanceof UniqueViolationError;\n if (!retryable || attempt >= MAX_WRITE_ATTEMPTS) throw error;\n }\n }\n }\n}\n\nasync function readVersion(ops: FactoryStorageOps, scope: StoredBoardScope): Promise<string | null> {\n const row = await ops.findOne<{ version: string }>(VERSIONS, scopeWhere(scope));\n return row?.version ?? null;\n}\n\n/** The project's board under `key`, read through `ops` so a caller inside a transaction reads within it. */\nexport async function readStoredBoard(\n ops: FactoryStorageOps,\n scope: StoredBoardScope,\n key: string,\n): Promise<StoredBoardRecord | null> {\n const row = await ops.findOne<BoardRow>(BOARDS, { ...scopeWhere(scope), board_key: key });\n if (!row) return null;\n const phases = await ops.findMany<PhaseRow>(PHASES, { ...scopeWhere(scope), board_key: key });\n return toRecord(row, phases);\n}\n\nasync function readBoards(ops: FactoryStorageOps, scope: StoredBoardScope): Promise<StoredBoardRecord[]> {\n const [rows, phases] = await Promise.all([\n ops.findMany<BoardRow>(BOARDS, scopeWhere(scope)),\n ops.findMany<PhaseRow>(PHASES, scopeWhere(scope)),\n ]);\n const byBoard = new Map<string, PhaseRow[]>();\n for (const phase of phases) {\n const list = byBoard.get(phase.board_key) ?? [];\n list.push(phase);\n byBoard.set(phase.board_key, list);\n }\n return rows\n .sort((left, right) => left.position - right.position || left.board_key.localeCompare(right.board_key))\n .map(row => toRecord(row, byBoard.get(row.board_key) ?? []));\n}\n\n/**\n * Inserts the project's version row if it has none. This runs outside the write transaction: on\n * Postgres, two transactions racing to insert it would leave the loser's transaction aborted, so\n * the version bump inside a write must always be an update.\n */\nasync function ensureVersionRow(ops: FactoryStorageOps, scope: StoredBoardScope): Promise<void> {\n if (await ops.findOne(VERSIONS, scopeWhere(scope))) return;\n try {\n await ops.insertOne(VERSIONS, { ...scopeWhere(scope), version: randomUUID(), updated_at: new Date() });\n } catch (error) {\n if (!(error instanceof UniqueViolationError)) throw error;\n }\n}\n\nasync function bumpVersion(ops: FactoryStorageOps, scope: StoredBoardScope): Promise<void> {\n await ops.upsertOne(VERSIONS, ['org_id', 'factory_project_id'], {\n ...scopeWhere(scope),\n version: randomUUID(),\n updated_at: new Date(),\n });\n}\n\nasync function findBoard(ops: FactoryStorageOps, scope: StoredBoardScope, key: string): Promise<BoardRow> {\n const row = await ops.findOne<BoardRow>(BOARDS, { ...scopeWhere(scope), board_key: key });\n if (!row) {\n throw new StoredBoardError('board_not_found', `Board \"${key}\" does not exist in this project.`);\n }\n return row;\n}\n\nfunction checkRevision(row: BoardRow, key: string, expectedRevision: number): void {\n if (row.revision !== expectedRevision) {\n throw new StoredBoardError(\n 'revision_mismatch',\n `Board \"${key}\" is at revision ${row.revision}, not ${expectedRevision}; reload it and try again.`,\n );\n }\n}\n\nfunction nextPosition(rows: BoardRow[]): number {\n return rows.reduce((max, row) => Math.max(max, row.position), -1) + 1;\n}\n\n/** Sets columns on a board row and raises its revision, unless another writer changed it first. */\nasync function updateRow(ops: FactoryStorageOps, row: BoardRow, set: Partial<BoardRow>): Promise<void> {\n const updated = await ops.updateMany(\n BOARDS,\n { id: row.id, revision: row.revision },\n { ...set, revision: row.revision + 1, updated_at: new Date() },\n );\n if (updated !== 1) throw new ConcurrentBoardWrite();\n}\n\nasync function insertPhases(ops: FactoryStorageOps, scope: StoredBoardScope, input: StoredBoardInput): Promise<void> {\n for (const [position, phase] of input.phases.entries()) {\n await ops.insertOne<PhaseRow>(PHASES, {\n ...scopeWhere(scope),\n board_key: input.key,\n phase_key: phase.key,\n position,\n name: phase.name,\n description: phase.description ?? null,\n kind: phase.kind,\n runner: phase.runner ?? null,\n next_phases: phase.nextPhases ?? null,\n auto_start: phase.autoStart ?? false,\n auto_start_when: phase.autoStartWhen ?? null,\n exit_tool: phase.exitTool ?? null,\n tools: phase.tools?.length ? phase.tools : null,\n });\n }\n}\n\nasync function insertBoard(\n ops: FactoryStorageOps,\n scope: StoredBoardScope,\n input: StoredBoardInput,\n options: { position: number; actor: string },\n): Promise<void> {\n const now = new Date();\n await ops.insertOne<BoardRow>(BOARDS, {\n ...scopeWhere(scope),\n board_key: input.key,\n name: input.name,\n description: input.description ?? null,\n position: options.position,\n revision: 1,\n created_by: options.actor,\n created_at: now,\n updated_by: options.actor,\n updated_at: now,\n });\n await insertPhases(ops, scope, input);\n}\n\n/** Replaces a board's definition and phases in place, keeping its key, position and history. */\nasync function writeBoard(\n ops: FactoryStorageOps,\n scope: StoredBoardScope,\n row: BoardRow,\n input: StoredBoardInput,\n actor: string,\n): Promise<void> {\n await updateRow(ops, row, { name: input.name, description: input.description ?? null, updated_by: actor });\n await ops.deleteMany(PHASES, { ...scopeWhere(scope), board_key: row.board_key });\n await insertPhases(ops, scope, { ...input, key: row.board_key });\n}\n\nfunction routeEvents(row: IntakeRouteRow): StatusEvent[] {\n return row.on_events ?? [...DEFAULT_ROUTE_EVENTS];\n}\n\nfunction checkRouteEvents(on: readonly string[], when: RuleGroup | null): void {\n const problem = routeEventsProblem(on, when);\n if (problem) throw new StoredBoardError('invalid_intake_route', problem);\n}\n\nfunction toIntakeRouteRecord(row: IntakeRouteRow): StoredIntakeRouteRecord {\n return {\n id: row.id,\n orgId: row.org_id,\n factoryProjectId: row.factory_project_id,\n name: row.name,\n enabled: row.enabled,\n position: row.position,\n when: row.when_condition,\n target: { boardKey: row.board_key, phaseKey: row.phase_key, joinClosedIssue: row.join_closed_issue === true },\n on: routeEvents(row),\n revision: row.revision,\n createdBy: row.created_by,\n createdAt: row.created_at,\n updatedBy: row.updated_by,\n updatedAt: row.updated_at,\n };\n}\n\n/** Whether `row` places every new card that reaches it, as the seeded \"Everything else\" route does. */\nfunction catchesEveryNewCard(row: IntakeRouteRow): boolean {\n return (\n row.enabled &&\n row.when_condition === null &&\n (row.on_events ?? DEFAULT_ROUTE_EVENTS).includes('work_item.created') &&\n !row.join_closed_issue\n );\n}\n\nasync function readIntakeRoutes(ops: FactoryStorageOps, scope: StoredBoardScope): Promise<IntakeRouteRow[]> {\n const rows = await ops.findMany<IntakeRouteRow>(INTAKE_ROUTES, scopeWhere(scope));\n return rows.sort((left, right) => left.position - right.position);\n}\n\nasync function findIntakeRoute(ops: FactoryStorageOps, scope: StoredBoardScope, id: string): Promise<IntakeRouteRow> {\n const row = await ops.findOne<IntakeRouteRow>(INTAKE_ROUTES, { ...scopeWhere(scope), id });\n if (!row) throw intakeRouteNotFound(id);\n return row;\n}\n\nfunction intakeRouteNotFound(id: string): StoredBoardError {\n return new StoredBoardError('intake_route_not_found', `Intake route \"${id}\" does not exist in this project.`);\n}\n\nfunction checkIntakeRouteRevision(row: IntakeRouteRow, expectedRevision: number): void {\n if (row.revision !== expectedRevision) {\n throw new StoredBoardError(\n 'revision_mismatch',\n `Intake route \"${row.name}\" is at revision ${row.revision}, not ${expectedRevision}; reload it and try again.`,\n );\n }\n}\n\n/** Sets columns on a route row and raises its revision, unless another writer changed it first. */\nasync function updateIntakeRouteRow(\n ops: FactoryStorageOps,\n row: IntakeRouteRow,\n set: Partial<IntakeRouteRow>,\n): Promise<number> {\n const revision = row.revision + 1;\n const updated = await ops.updateMany(\n INTAKE_ROUTES,\n { id: row.id, revision: row.revision },\n { ...set, revision, updated_at: new Date() },\n );\n if (updated !== 1) throw new ConcurrentBoardWrite();\n return revision;\n}\n\nasync function insertIntakeRoute(\n ops: FactoryStorageOps,\n scope: StoredBoardScope,\n route: { id: string; input: StoredIntakeRouteInput; position: number; actor: string },\n): Promise<void> {\n const now = new Date();\n await ops.insertOne<IntakeRouteRow>(INTAKE_ROUTES, {\n id: route.id,\n ...scopeWhere(scope),\n name: route.input.name,\n enabled: route.input.enabled ?? true,\n position: route.position,\n when_condition: route.input.when ?? null,\n board_key: route.input.target.boardKey,\n phase_key: route.input.target.phaseKey ?? null,\n on_events: route.input.on ?? null,\n join_closed_issue: route.input.target.joinClosedIssue ?? false,\n revision: 1,\n created_by: route.actor,\n created_at: now,\n updated_by: route.actor,\n updated_at: now,\n });\n}\n\n/**\n * Takes the project's route lock and reads the routes. Writes that add, delete or move routes\n * call this first, so they run one after another and each reads what the one before committed.\n */\nasync function lockIntakeRoutes(ops: FactoryStorageOps, scope: StoredBoardScope): Promise<IntakeRouteRow[]> {\n if ((await ops.updateMany(INTAKE_ROUTE_LOCKS, scopeWhere(scope), { locked_at: new Date() })) !== 1) {\n throw new ConcurrentBoardWrite();\n }\n return readIntakeRoutes(ops, scope);\n}\n\n/** Moves routes, read under the project's route lock, to the positions of their order in `rows`. */\nasync function placeIntakeRoutes(ops: FactoryStorageOps, rows: IntakeRouteRow[], actor?: string): Promise<void> {\n const moving = rows.flatMap((row, position) => (row.position === position ? [] : [{ row, position }]));\n const parked = [];\n for (const [index, { row, position }] of moving.entries()) {\n const revision = await updateIntakeRouteRow(ops, row, {\n position: -(index + 1),\n ...(actor !== undefined && { updated_by: actor }),\n });\n parked.push({ id: row.id, revision, position });\n }\n for (const { id, revision, position } of parked) {\n if ((await ops.updateMany(INTAKE_ROUTES, { id, revision }, { position })) !== 1) throw new ConcurrentBoardWrite();\n }\n}\n"],"mappings":";;;;;;AA2HA,MAAM,0BAAiD;CACrD,iBAAiB;CACjB,gCAAgB,IAAI,IAAI;CACxB,kBAAkB,KAAA;CAClB,YAAY,CAAC;AACf;;AAiEA,MAAa,oBAAoB;;AAoBjC,MAAM,wBAAwB,CAAC,iBAAiB;;AAGhD,MAAa,6BAA6B;AAE1C,IAAa,mBAAb,cAAsC,MAAM;CAG/B;CAFX,OAAgB;CAChB,YACE,MACA,SACA;EACA,MAAM,OAAO;EAHJ,KAAA,OAAA;CAIX;AACF;AAoEA,SAAS,eAAe,MAAoC;CAC1D,OAAO,KAAK,mBAAmB;AACjC;AAEA,SAAS,gBAAgB,MAAoE;CAC3F,MAAM,SAAS,IAAI,IAAI,eAAe,IAAI,CAAC;CAC3C,OAAO,sBAAsB,QAAQ,EAAE,UAAU,CAAC,OAAO,IAAI,GAAG,CAAC;AACnE;AAEA,MAAM,SAAS;AACf,MAAM,SAAS;AACf,MAAM,WAAW;AACjB,MAAM,gBAAgB;AACtB,MAAM,qBAAqB;AAC3B,MAAM,qBAAqB;AAC3B,MAAM,kBAAkB;AAExB,SAAS,WAAW,EAAE,OAAO,oBAAsC;CACjE,OAAO;EAAE,QAAQ;EAAO,oBAAoB;CAAiB;AAC/D;AAEA,SAAS,cAAc,KAAkC;CACvD,OAAO;EACL,KAAK,IAAI;EACT,UAAU,IAAI;EACd,MAAM,IAAI;EACV,aAAa,IAAI;EACjB,MAAM,IAAI;EACV,QAAQ,IAAI;EACZ,YAAY,IAAI;EAChB,WAAW,IAAI;EACf,eAAe,IAAI;EACnB,UAAU,IAAI;EACd,OAAO,IAAI,SAAS;CACtB;AACF;AAEA,SAAS,SAAS,KAAe,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W,oBAAoB,WAAW,KAAK,GAAG,EAAE,2BAAW,IAAI,KAAK,EAAE,CAAC,MAAO,GAC/F,MAAM,IAAI,qBAAqB;CAEjC,OAAO,iBAAiB,KAAK,KAAK;AACpC;;AAGA,eAAe,kBAAkB,KAAwB,MAAwB,OAA+B;CAC9G,MAAM,SAAS,KAAK,SAAS,KAAK,aAAc,IAAI,aAAa,WAAW,CAAC,IAAI,CAAC;EAAE;EAAK;CAAS,CAAC,CAAE;CACrG,MAAM,SAAS,CAAC;CAChB,KAAK,MAAM,CAAC,OAAO,EAAE,KAAK,eAAe,OAAO,QAAQ,GAAG;EACzD,MAAM,WAAW,MAAM,qBAAqB,KAAK,KAAK;GACpD,UAAU,EAAE,QAAQ;GACpB,GAAI,UAAU,KAAA,KAAa,EAAE,YAAY,MAAM;EACjD,CAAC;EACD,OAAO,KAAK;GAAE,IAAI,IAAI;GAAI;GAAU;EAAS,CAAC;CAChD;CACA,KAAK,MAAM,EAAE,IAAI,UAAU,cAAc,QACvC,IAAK,MAAM,IAAI,WAAW,eAAe;EAAE;EAAI;CAAS,GAAG,EAAE,SAAS,CAAC,MAAO,GAAG,MAAM,IAAI,qBAAqB;AAEpH"}
|
|
1
|
+
{"version":3,"file":"base.js","names":[],"sources":["../../../../src/storage/domains/boards/base.ts"],"sourcesContent":["import { randomUUID } from 'node:crypto';\nimport { isDeepStrictEqual } from 'node:util';\n\nimport { FactoryStorageDomain, UniqueViolationError } from '@mastra/core/storage';\nimport type { FactoryStorageOps } from '@mastra/core/storage';\n\nimport { arrivalKinds, DEFAULT_ROUTE_EVENTS, routeEventsProblem } from '../../../boards/board-events.js';\nimport type { ArrivalKind, RouteArrivals, RouteEvent } from '../../../boards/board-events.js';\nimport type { FactoryPhaseTool } from '../../../boards/define-board.js';\nimport { deriveIntakeOrder, kindsTakenWhole, reconcileIntakeOrder } from '../../../boards/intake-order.js';\nimport {\n DEFAULT_INTAKE_ROUTES,\n LINKED_PULL_REQUEST_ROUTE_KEY,\n RETIRED_JOIN_ROUTE,\n} from '../../../boards/work-routes.js';\nimport { currentRuleGroup } from '../../../rules/rule-group.js';\nimport type { RuleGroup } from '../../../rules/rule-group.js';\nimport type { RetiredAutomationSettings } from '../projects/base.js';\nimport {\n FACTORY_BOARD_DEFINITION_VERSIONS_SCHEMA,\n FACTORY_BOARD_PHASES_SCHEMA,\n FACTORY_BOARDS_SCHEMA,\n FACTORY_INTAKE_DECISIONS_SCHEMA,\n FACTORY_INTAKE_ROUTE_LOCKS_SCHEMA,\n FACTORY_INTAKE_ROUTES_SCHEMA,\n} from './schemas.js';\n\n/** The project a board belongs to. */\nexport interface StoredBoardScope {\n orgId: string;\n factoryProjectId: string;\n}\n\nexport type StoredPhaseKind = 'resting' | 'working' | 'terminal';\n\n/** Who runs a working phase. Factory runs every phase with its code agent. */\nexport interface StoredPhaseRunner {\n skill?: string;\n context?: string;\n instructions?: string;\n /** The objective the phase's runs pursue as a goal. */\n goal?: { objective: string; maxRuns?: number };\n}\n\nexport interface StoredPhaseExitTool {\n id: string;\n autoApprove?: boolean;\n autoApproveWhen?: RuleGroup;\n}\n\n/** A phase as it is written. `key` is the stage id cards sit in. */\nexport interface StoredPhaseInput {\n key: string;\n name: string;\n description?: string | null;\n kind: StoredPhaseKind;\n runner?: StoredPhaseRunner | null;\n /** Unset or `null` on a resting or working phase means every other phase; `[]` means none. */\n nextPhases?: string[] | null;\n autoStart?: boolean;\n autoStartWhen?: RuleGroup | null;\n exitTool?: StoredPhaseExitTool | null;\n /** Factory tools the phase grants the session working the card there. */\n tools?: FactoryPhaseTool[] | null;\n}\n\n/** A board as it is written. Phase order is significant: the first phase is where cards start. */\nexport interface StoredBoardInput {\n key: string;\n name: string;\n description?: string | null;\n phases: StoredPhaseInput[];\n}\n\nexport interface StoredPhaseRecord {\n key: string;\n position: number;\n name: string;\n description: string | null;\n kind: StoredPhaseKind;\n runner: StoredPhaseRunner | null;\n nextPhases: string[] | null;\n autoStart: boolean;\n autoStartWhen: RuleGroup | null;\n exitTool: StoredPhaseExitTool | null;\n tools: FactoryPhaseTool[] | null;\n}\n\nexport interface StoredBoardRecord {\n id: string;\n orgId: string;\n factoryProjectId: string;\n key: string;\n name: string;\n description: string | null;\n position: number;\n revision: number;\n createdBy: string;\n createdAt: Date;\n updatedBy: string;\n updatedAt: Date;\n phases: StoredPhaseRecord[];\n}\n\n/** What a board migration may know about the project besides the board it rewrites. */\nexport interface BoardMigrationContext {\n /** The project switches the boards replaced, as the project last stored them; null when unknown. */\n readonly retiredSettings: RetiredAutomationSettings | null;\n /** The phases of each board that cards sit in, by board key; null when the cards can't be read. */\n readonly occupiedPhases: ReadonlyMap<string, ReadonlySet<string>> | null;\n /**\n * The phases the code board under this key declares; undefined for a board only the project\n * stores. A row that drops one runs without its code rules (`mergeCodeBehaviour`).\n */\n codePhases(boardKey: string): ReadonlySet<string> | undefined;\n /** Tells the operator about a board a migration left as it is. */\n warn(message: string): void;\n}\n\n/** A one-time rewrite of a stored board, keyed so each project gets it once. */\nexport interface StoredBoardMigration {\n key: string;\n /** The board it rewrites; `null` rewrites every board the project stores. */\n boardKey: string | null;\n /** The board to write instead, with what changed; undefined leaves it as it is. */\n migrate(\n board: StoredBoardRecord,\n context: BoardMigrationContext,\n ): { board: Omit<StoredBoardInput, 'key'>; filled: string[] } | undefined;\n}\n\nconst EMPTY_MIGRATION_CONTEXT: BoardMigrationContext = {\n retiredSettings: null,\n occupiedPhases: new Map(),\n codePhases: () => undefined,\n warn: () => {},\n};\n\nexport interface AppliedBoardMigration {\n key: string;\n boardKey: string;\n filled: string[];\n}\n\nexport interface StoredBoardSnapshot {\n version: string | null;\n boards: StoredBoardRecord[];\n}\n\nexport interface IntakeRouteTarget {\n boardKey: string;\n /**\n * Unset lands the card in the board's first phase. On a route that joins a closed issue's\n * card, the phase that card moves to when its board allows it; unset leaves it where it is.\n */\n phaseKey?: string | null;\n /**\n * Files a pull request on the card of the issue it closes, which must be on `boardKey`, as one\n * more source instead of a card of its own. The route doesn't match any other arrival.\n */\n joinClosedIssue?: boolean;\n /**\n * On a route moving existing cards (one naming events besides `work_item.opened`), the board the\n * card moves to, at `phaseKey`. `boardKey` stays the board whose cards the route moves. Unset\n * keeps the card on `boardKey`.\n */\n moveToBoardKey?: string | null;\n}\n\n/** An intake route as it is written. */\nexport interface StoredIntakeRouteInput {\n name: string;\n enabled?: boolean;\n /** Null matches every card. */\n when?: RuleGroup | null;\n target: IntakeRouteTarget;\n /** The events the route handles; unset files new issues and pull requests (`work_item.created`). */\n on?: RouteEvent[];\n /** Writes the route as 0.28 did, moving cards on `pull_request.opened` and filing none: how a deleted one is restored. */\n pullRequestOpenedMovesOnly?: true;\n}\n\nexport interface StoredIntakeRouteRecord {\n id: string;\n orgId: string;\n factoryProjectId: string;\n name: string;\n enabled: boolean;\n position: number;\n when: RuleGroup | null;\n target: { boardKey: string; phaseKey: string | null; joinClosedIssue: boolean; moveToBoardKey: string | null };\n on: RouteEvent[];\n /**\n * Set on a route stored before `pull_request.opened` filed pull requests with no card (0.28): it\n * names that event and only moves cards on it, as it always has. Writing `on` again clears it.\n */\n pullRequestOpenedMovesOnly?: true;\n revision: number;\n createdBy: string;\n createdAt: Date;\n updatedBy: string;\n updatedAt: Date;\n}\n\nexport type StoredBoardErrorCode =\n | 'board_exists'\n | 'board_not_found'\n | 'revision_mismatch'\n | 'intake_route_not_found'\n | 'intake_route_set_mismatch'\n | 'intake_route_limit'\n | 'invalid_intake_route'\n | 'intake_order_set_mismatch'\n | 'intake_decision_not_found'\n | 'invalid_intake_cursor';\n\n/** A board's most intake routes. */\nexport const MAX_INTAKE_ROUTES_PER_BOARD = 100;\n\n/**\n * How an arrival was decided; `rule_skipped` warns that a card-move rule matched but its target\n * couldn't take the card, and `rule_retired` that Factory switched off a join route an admin had\n * changed, whose work no rule does now.\n */\nexport type IntakeDecisionOutcome = 'placed' | 'not_routed' | 'rule_skipped' | 'rule_retired';\n\n/**\n * Which evaluator decides where an arrival goes: `route-list` is the old one, which projects created\n * before `intake-order` shipped keep until an admin switches them.\n */\nexport type IntakeEvaluator = 'route-list' | 'intake-order';\n\n/**\n * `derived` while the order still follows the route list: every rule write re-derives it. `explicit`\n * once an admin sets it.\n */\nexport type IntakeOrderOrigin = 'derived' | 'explicit';\n\nexport interface StoredIntakeOrder {\n /** Board keys in the order intake checks them. */\n boardKeys: string[];\n origin: IntakeOrderOrigin;\n}\n\nexport interface IntakeDecisionInput {\n idempotencyKey: string;\n outcome: IntakeDecisionOutcome;\n evaluator: IntakeEvaluator;\n boardKey?: string | null;\n routeId?: string | null;\n reason?: string | null;\n sourceKey?: string | null;\n title: string;\n url?: string | null;\n /** The arrival as it was decided on; kept so Route again can file it. */\n arrival?: Record<string, unknown> | null;\n}\n\nexport interface StoredIntakeDecisionRecord {\n id: string;\n orgId: string;\n factoryProjectId: string;\n idempotencyKey: string;\n outcome: IntakeDecisionOutcome;\n evaluator: IntakeEvaluator;\n boardKey: string | null;\n routeId: string | null;\n reason: string | null;\n sourceKey: string | null;\n title: string;\n url: string | null;\n arrival: Record<string, unknown> | null;\n decidedAt: Date;\n resolvedAt: Date | null;\n resolvedBy: string | null;\n}\n\n// Work's routes are its seed data, kept with the board they target.\nexport {\n DEFAULT_INTAKE_ROUTE,\n OUTSIDE_PULL_REQUEST_INTAKE_ROUTE,\n PULL_REQUEST_INTAKE_ROUTE,\n CLOSED_COMPLETED_ROUTE,\n CLOSED_CANCELED_ROUTE,\n REOPENED_ROUTE,\n PULL_REQUEST_MERGED_ROUTE,\n PULL_REQUEST_CLOSED_ROUTE,\n PULL_REQUEST_CLOSED_ISSUE_ROUTE,\n PULL_REQUEST_UPDATED_ROUTE,\n PULL_REQUEST_REVIEW_REQUESTED_ROUTE,\n LINKED_PULL_REQUEST_ROUTE,\n LINKED_PULL_REQUEST_ROUTE_KEY,\n CATCH_ALL_INTAKE_ROUTE,\n DEFAULT_INTAKE_ROUTES,\n} from '../../../boards/work-routes.js';\n\n/** The defaults a project whose lock row predates `seeded_defaults` was set up with. */\nconst ORIGINAL_DEFAULT_KEYS = ['outside-authors'];\n\n/** Who the default intake routes are created and last updated by. */\nexport const DEFAULT_INTAKE_ROUTE_ACTOR = 'factory';\n\nexport class StoredBoardError extends Error {\n override name = 'StoredBoardError';\n constructor(\n readonly code: StoredBoardErrorCode,\n message: string,\n ) {\n super(message);\n }\n}\n\ninterface BoardRow extends Record<string, unknown> {\n id: string;\n org_id: string;\n factory_project_id: string;\n board_key: string;\n name: string;\n description: string | null;\n position: number;\n revision: number;\n created_by: string;\n created_at: Date;\n updated_by: string;\n updated_at: Date;\n}\n\ninterface VersionRow extends Record<string, unknown> {\n version: string;\n /** Keys of the boards Factory stored in the project; null on rows written before the list. */\n seeded_boards: string[] | null;\n /** Keys of the board migrations applied to the project; null before the first one. */\n applied_migrations: string[] | null;\n}\n\ninterface PhaseRow extends Record<string, unknown> {\n id: string;\n org_id: string;\n factory_project_id: string;\n board_key: string;\n phase_key: string;\n position: number;\n name: string;\n description: string | null;\n kind: StoredPhaseKind;\n runner: StoredPhaseRunner | null;\n next_phases: string[] | null;\n auto_start: boolean;\n auto_start_when: RuleGroup | null;\n exit_tool: StoredPhaseExitTool | null;\n tools: FactoryPhaseTool[] | null;\n}\n\ninterface IntakeRouteRow extends Record<string, unknown> {\n id: string;\n org_id: string;\n factory_project_id: string;\n name: string;\n enabled: boolean;\n position: number;\n when_condition: RuleGroup | null;\n board_key: string;\n phase_key: string | null;\n /** Null on rows written before routes named events: they place new cards. */\n on_events: RouteEvent[] | null;\n join_closed_issue: boolean | null;\n /** Null on rows written before `pull_request.opened` filed pull requests: there it only moves a card. */\n opened_files_pull_requests?: boolean | null;\n move_to_board_key: string | null;\n revision: number;\n created_by: string;\n created_at: Date;\n updated_by: string;\n updated_at: Date;\n}\n\ninterface IntakeRouteLockRow extends Record<string, unknown> {\n /** Keys of the `DEFAULT_INTAKE_ROUTES` added to the project; null on rows written before the list. */\n seeded_defaults: string[] | null;\n intake_order: string[] | null;\n /** Null while derived. */\n intake_order_origin: 'explicit' | null;\n /** Null on projects created before the setting: they use `route-list`. */\n intake_evaluator?: IntakeEvaluator | null;\n}\n\ninterface IntakeDecisionRow extends Record<string, unknown> {\n id: string;\n org_id: string;\n factory_project_id: string;\n idempotency_key: string;\n outcome: IntakeDecisionOutcome;\n evaluator: IntakeEvaluator;\n board_key: string | null;\n route_id: string | null;\n reason: string | null;\n source_key: string | null;\n title: string;\n url: string | null;\n arrival: Record<string, unknown> | null;\n decided_at: Date;\n resolved_at: Date | null;\n resolved_by: string | null;\n}\n\nfunction toIntakeDecisionRecord(row: IntakeDecisionRow): StoredIntakeDecisionRecord {\n return {\n id: row.id,\n orgId: row.org_id,\n factoryProjectId: row.factory_project_id,\n idempotencyKey: row.idempotency_key,\n outcome: row.outcome,\n evaluator: row.evaluator,\n boardKey: row.board_key,\n routeId: row.route_id,\n reason: row.reason,\n sourceKey: row.source_key,\n title: row.title,\n url: row.url,\n arrival: row.arrival,\n decidedAt: row.decided_at,\n resolvedAt: row.resolved_at,\n resolvedBy: row.resolved_by,\n };\n}\n\nfunction seededDefaults(lock: IntakeRouteLockRow): string[] {\n return lock.seeded_defaults ?? ORIGINAL_DEFAULT_KEYS;\n}\n\nfunction missingDefaults(lock: IntakeRouteLockRow): (typeof DEFAULT_INTAKE_ROUTES)[number][] {\n const seeded = new Set(seededDefaults(lock));\n return DEFAULT_INTAKE_ROUTES.filter(({ key }) => !seeded.has(key));\n}\n\nconst BOARDS = 'factory_boards';\nconst PHASES = 'factory_board_phases';\nconst VERSIONS = 'factory_board_definition_versions';\nconst INTAKE_ROUTES = 'factory_intake_routes';\nconst INTAKE_ROUTE_LOCKS = 'factory_intake_route_locks';\nconst INTAKE_DECISIONS = 'factory_intake_decisions';\nconst MAX_WRITE_ATTEMPTS = 3;\nconst MIGRATION_ACTOR = 'factory';\n\nfunction scopeWhere({ orgId, factoryProjectId }: StoredBoardScope) {\n return { org_id: orgId, factory_project_id: factoryProjectId };\n}\n\nfunction toPhaseRecord(row: PhaseRow): StoredPhaseRecord {\n return {\n key: row.phase_key,\n position: row.position,\n name: row.name,\n description: row.description,\n kind: row.kind,\n runner: row.runner,\n nextPhases: row.next_phases,\n autoStart: row.auto_start,\n autoStartWhen: currentRuleGroup(row.auto_start_when),\n exitTool: row.exit_tool?.autoApproveWhen\n ? { ...row.exit_tool, autoApproveWhen: currentRuleGroup(row.exit_tool.autoApproveWhen) }\n : row.exit_tool,\n tools: row.tools ?? null,\n };\n}\n\nfunction toRecord(row: BoardRow, phases: PhaseRow[]): StoredBoardRecord {\n return {\n id: row.id,\n orgId: row.org_id,\n factoryProjectId: row.factory_project_id,\n key: row.board_key,\n name: row.name,\n description: row.description,\n position: row.position,\n revision: row.revision,\n createdBy: row.created_by,\n createdAt: row.created_at,\n updatedBy: row.updated_by,\n updatedAt: row.updated_at,\n phases: phases.sort((left, right) => left.position - right.position).map(toPhaseRecord),\n };\n}\n\n/** Runs inside a board write's transaction, before the board is written. */\nexport type BoardWriteStep = (ops: FactoryStorageOps) => Promise<void>;\n\n/** A compare-and-set inside a write lost to a concurrent writer; the write is retried from fresh reads. */\nclass ConcurrentBoardWrite extends Error {}\n\n/**\n * Each project's boards and their ordered phases. Every write runs in one transaction that also\n * replaces the project's row in `factory_board_definition_versions`, so caches on other\n * replicas can detect it.\n */\nexport class StoredBoardsStorage extends FactoryStorageDomain {\n constructor() {\n super('boards');\n }\n\n async init(): Promise<void> {\n await this.ensureCollections([\n FACTORY_BOARDS_SCHEMA,\n FACTORY_BOARD_PHASES_SCHEMA,\n FACTORY_BOARD_DEFINITION_VERSIONS_SCHEMA,\n FACTORY_INTAKE_ROUTES_SCHEMA,\n FACTORY_INTAKE_ROUTE_LOCKS_SCHEMA,\n FACTORY_INTAKE_DECISIONS_SCHEMA,\n ]);\n }\n\n async dangerouslyClearAll(): Promise<void> {\n await this.ops.deleteMany(INTAKE_DECISIONS, {});\n await this.ops.deleteMany(PHASES, {});\n await this.ops.deleteMany(BOARDS, {});\n await this.ops.deleteMany(VERSIONS, {});\n await this.ops.deleteMany(INTAKE_ROUTES, {});\n await this.ops.deleteMany(INTAKE_ROUTE_LOCKS, {});\n }\n\n /** The project's current definition version; null before its first board write. */\n async readVersion(scope: StoredBoardScope): Promise<string | null> {\n return readVersion(this.ops, scope);\n }\n\n /** The project's boards in order. */\n async list(scope: StoredBoardScope): Promise<StoredBoardRecord[]> {\n return readBoards(this.ops, scope);\n }\n\n /**\n * The version and the boards, read in that order: a write landing between the two reads leaves a\n * version older than the rows, so a cache keyed on it rereads on its next check instead of\n * keeping the stale rows.\n */\n async snapshot(scope: StoredBoardScope): Promise<StoredBoardSnapshot> {\n const version = await readVersion(this.ops, scope);\n return { version, boards: await this.list(scope) };\n }\n\n get(scope: StoredBoardScope, key: string): Promise<StoredBoardRecord | null> {\n return readStoredBoard(this.ops, scope, key);\n }\n\n /**\n * Creates a board through the API. `before` runs in the same transaction, once the key is known\n * to be free. A row under the key that `over` accepts does not hold it: the board is written\n * over that row.\n */\n async create(\n scope: StoredBoardScope,\n input: StoredBoardInput,\n actor: string,\n before?: BoardWriteStep,\n over?: (row: StoredBoardRecord) => boolean,\n ): Promise<StoredBoardRecord> {\n await ensureVersionRow(this.ops, scope);\n try {\n return await this.#write(scope, async ops => {\n const rows = await ops.findMany<BoardRow>(BOARDS, scopeWhere(scope));\n const taken = rows.find(row => row.board_key === input.key);\n const stored = taken && over ? await readStoredBoard(ops, scope, input.key) : null;\n if (taken && !(stored && over?.(stored))) {\n throw new StoredBoardError('board_exists', `Board \"${input.key}\" already exists in this project.`);\n }\n await before?.(ops);\n if (taken) await writeBoard(ops, scope, taken, input, actor);\n else await insertBoard(ops, scope, input, { position: nextPosition(rows), actor });\n return { result: undefined, changed: true };\n }).then(async () => (await this.get(scope, input.key))!);\n } catch (error) {\n // Only the board key's index means the board exists; a lost race on another table is not that.\n if (error instanceof UniqueViolationError && error.collection === BOARDS) {\n throw new StoredBoardError('board_exists', `Board \"${input.key}\" already exists in this project.`);\n }\n throw error;\n }\n }\n\n /** Replaces a board's name, description and phases. The board key never changes. */\n async replace(\n scope: StoredBoardScope,\n key: string,\n input: Omit<StoredBoardInput, 'key'>,\n options: { expectedRevision: number; actor: string; before?: BoardWriteStep },\n ): Promise<StoredBoardRecord> {\n await this.#write(scope, async ops => {\n const row = await findBoard(ops, scope, key);\n checkRevision(row, key, options.expectedRevision);\n await options.before?.(ops);\n await writeBoard(ops, scope, row, { key, ...input }, options.actor);\n return { result: undefined, changed: true };\n });\n return (await this.get(scope, key))!;\n }\n\n /**\n * Stores Factory's boards (Work, app and seed boards) in the project, each key once: a key the\n * project has had before is skipped even if its board was deleted since, and a stored board is\n * never rewritten. A project stored before the list was kept counts the boards it has as stored.\n * Reads one row when every key was stored before. Returns the keys it inserted.\n *\n * A key in `onlyIntoEmpty` is inserted only into a project that has no boards at all: one that\n * already has any board, such as one an app stored under that key, is left as it is. The key\n * is still recorded as stored, so it never goes in later, even after the project's boards are\n * deleted: that project chose its boards, and Work is never added beside or after them. The\n * `intoEmpty` boards (an app's, for every project) go first into a project with no boards, so\n * Factory's own under the same key, or in `onlyIntoEmpty`, then stay out. `actor` is recorded\n * as the inserted boards' creator. `before` runs in the same\n * transaction ahead of each board it inserts.\n */\n async seedBoards(\n scope: StoredBoardScope,\n boards: readonly StoredBoardInput[],\n options: {\n actor?: string;\n onlyIntoEmpty?: readonly string[];\n intoEmpty?: readonly StoredBoardInput[];\n before?: (ops: FactoryStorageOps, key: string) => Promise<void>;\n } = {},\n ): Promise<string[]> {\n const marker = await this.ops.findOne<VersionRow>(VERSIONS, scopeWhere(scope));\n if (marker?.seeded_boards && boards.every(board => marker.seeded_boards!.includes(board.key))) return [];\n return this.#insertOnce(scope, boards, {\n actor: options.actor ?? DEFAULT_INTAKE_ROUTE_ACTOR,\n skipSeeded: true,\n onlyIntoEmpty: options.onlyIntoEmpty ?? [],\n intoEmpty: options.intoEmpty ?? [],\n before: options.before,\n });\n }\n\n /** The keys of the boards Factory stored in the project; null before it kept the list. */\n async seededBoardKeys(scope: StoredBoardScope): Promise<string[] | null> {\n return (await this.ops.findOne<VersionRow>(VERSIONS, scopeWhere(scope)))?.seeded_boards ?? null;\n }\n\n /**\n * Rewrites the board stored under `seed.key` to `seed` at its next revision when `when` says the\n * row is nobody's: one an earlier release seeded for a board Factory no longer has, under a key\n * the app now defines. `before` runs in the same transaction. Returns whether it rewrote the row.\n */\n async adoptSeed(\n scope: StoredBoardScope,\n seed: StoredBoardInput,\n options: { when: (row: StoredBoardRecord) => boolean; before?: BoardWriteStep },\n ): Promise<boolean> {\n return this.#write(scope, async ops => {\n const stored = await readStoredBoard(ops, scope, seed.key);\n if (!stored || !options.when(stored)) return { result: false, changed: false };\n await options.before?.(ops);\n await writeBoard(ops, scope, await findBoard(ops, scope, seed.key), seed, DEFAULT_INTAKE_ROUTE_ACTOR);\n return { result: true, changed: true };\n });\n }\n\n /**\n * Inserts a board into the project unless one is stored under its key, and records the key as\n * stored, so seeding never adds it again. Unlike seeding, it inserts a key the project deleted.\n * Returns whether it inserted the board. `before` runs in the same transaction when it does.\n */\n async insertIfMissing(\n scope: StoredBoardScope,\n board: StoredBoardInput,\n actor: string,\n before?: BoardWriteStep,\n ): Promise<boolean> {\n return (await this.#insertOnce(scope, [board], { actor, skipSeeded: false, before })).length > 0;\n }\n\n async #insertOnce(\n scope: StoredBoardScope,\n boards: readonly StoredBoardInput[],\n options: {\n actor: string;\n skipSeeded: boolean;\n onlyIntoEmpty?: readonly string[];\n intoEmpty?: readonly StoredBoardInput[];\n before?: (ops: FactoryStorageOps, key: string) => Promise<void>;\n },\n ): Promise<string[]> {\n await ensureVersionRow(this.ops, scope);\n return this.#transact(async ops => {\n const marker = (await ops.findOne<VersionRow>(VERSIONS, scopeWhere(scope)))!;\n const rows = await ops.findMany<BoardRow>(BOARDS, scopeWhere(scope));\n const present = new Set(rows.map(row => row.board_key));\n const seeded = new Set(marker.seeded_boards ?? present);\n // The `intoEmpty` boards go into a project with no boards, first; `onlyIntoEmpty` keys then\n // go in only when nothing is stored yet, so a project holding them gets no default beside them.\n const candidates = [...(rows.length === 0 ? (options.intoEmpty ?? []) : []), ...boards];\n let position = nextPosition(rows);\n const inserted: string[] = [];\n for (const board of candidates) {\n if (present.has(board.key) || (options.skipSeeded && seeded.has(board.key))) continue;\n if (present.size > 0 && options.onlyIntoEmpty?.includes(board.key)) continue;\n await options.before?.(ops, board.key);\n await insertBoard(ops, scope, board, { position: position++, actor: options.actor });\n present.add(board.key);\n inserted.push(board.key);\n }\n const next = [...new Set([...seeded, ...candidates.map(board => board.key)])];\n const unchanged = marker.seeded_boards !== null && next.length === marker.seeded_boards.length;\n if (inserted.length === 0 && unchanged) return inserted;\n // Compare-and-set on the version, and every marker write takes a new one: two replicas\n // recording different keys can't both match the version they read, so neither key is lost.\n const updated = await ops.updateMany(\n VERSIONS,\n { ...scopeWhere(scope), version: marker.version },\n {\n seeded_boards: next,\n version: randomUUID(),\n updated_at: new Date(),\n },\n );\n if (updated !== 1) throw new ConcurrentBoardWrite();\n return inserted;\n });\n }\n\n /**\n * Runs each migration the project hasn't had yet, once: the keys applied are recorded on the\n * project's version row in the same transaction as the board writes, and the compare-and-set on\n * its version makes a concurrent first load retry from fresh reads, where it finds them applied.\n * A migration whose board the project doesn't have is recorded without running, and the version\n * only changes when a board was rewritten. Reads one row\n * when every key was applied before. Returns what each migration that rewrote a board filled.\n */\n async applyBoardMigrations(\n scope: StoredBoardScope,\n migrations: readonly StoredBoardMigration[],\n /**\n * Read through the transaction's `ops`, again on every retry, and only when a migration is still\n * pending, so what it reports is as fresh as the boards the migrations rewrite.\n */\n context: (ops: FactoryStorageOps) => Promise<BoardMigrationContext> = async () => EMPTY_MIGRATION_CONTEXT,\n ): Promise<AppliedBoardMigration[]> {\n if (migrations.length === 0) return [];\n const marker = await this.ops.findOne<VersionRow>(VERSIONS, scopeWhere(scope));\n if (marker?.applied_migrations && migrations.every(({ key }) => marker.applied_migrations!.includes(key))) {\n return [];\n }\n await ensureVersionRow(this.ops, scope);\n return this.#transact(async ops => {\n const current = (await ops.findOne<VersionRow>(VERSIONS, scopeWhere(scope)))!;\n const applied = current.applied_migrations ?? [];\n const pending = migrations.filter(({ key }) => !applied.includes(key));\n if (pending.length === 0) return [];\n const project = await context(ops);\n const changed: AppliedBoardMigration[] = [];\n for (const migration of pending) {\n const rows =\n migration.boardKey === null\n ? await ops.findMany<BoardRow>(BOARDS, scopeWhere(scope))\n : await ops.findMany<BoardRow>(BOARDS, { ...scopeWhere(scope), board_key: migration.boardKey });\n for (const row of rows) {\n const phases = await ops.findMany<PhaseRow>(PHASES, { ...scopeWhere(scope), board_key: row.board_key });\n const result = migration.migrate(toRecord(row, phases), project);\n if (!result) continue;\n await writeBoard(ops, scope, row, { ...result.board, key: row.board_key }, MIGRATION_ACTOR);\n changed.push({ key: migration.key, boardKey: row.board_key, filled: result.filled });\n }\n }\n const updated = await ops.updateMany(\n VERSIONS,\n { ...scopeWhere(scope), version: current.version },\n {\n applied_migrations: [...applied, ...pending.map(({ key }) => key)],\n // Only a rewritten board is news to the other replicas' caches.\n version: changed.length > 0 ? randomUUID() : current.version,\n updated_at: new Date(),\n },\n );\n if (updated !== 1) throw new ConcurrentBoardWrite();\n return changed;\n });\n }\n\n /** Rewrites a board to `definition` (Factory's current one for its key), raising its revision. */\n async resetTo(\n scope: StoredBoardScope,\n key: string,\n definition: StoredBoardInput,\n options: { expectedRevision: number; actor: string },\n ): Promise<StoredBoardRecord> {\n await this.#write(scope, async ops => {\n const row = await findBoard(ops, scope, key);\n checkRevision(row, key, options.expectedRevision);\n await writeBoard(ops, scope, row, { ...definition, key }, options.actor);\n return { result: undefined, changed: true };\n });\n return (await this.get(scope, key))!;\n }\n\n /**\n * Deletes a board, its phases and its intake routes in one transaction, and takes it out of the\n * intake order. Returns the routes it deleted, for the caller to audit.\n */\n async delete(\n scope: StoredBoardScope,\n key: string,\n options: { expectedRevision: number },\n ): Promise<{ intakeRoutes: StoredIntakeRouteRecord[] }> {\n await this.#ensureIntakeRoutes(scope);\n return this.#write(scope, async ops => {\n const row = await findBoard(ops, scope, key);\n checkRevision(row, key, options.expectedRevision);\n const routes = await lockIntakeRoutes(ops, scope);\n if ((await ops.deleteMany(BOARDS, { id: row.id, revision: row.revision })) === 0)\n throw new ConcurrentBoardWrite();\n await ops.deleteMany(PHASES, { ...scopeWhere(scope), board_key: key });\n const deleted = routes.filter(route => route.board_key === key);\n if (deleted.length > 0) {\n await ops.deleteMany(INTAKE_ROUTES, { ...scopeWhere(scope), board_key: key });\n await placeIntakeRoutes(\n ops,\n routes.filter(route => route.board_key !== key),\n );\n await forgetDerivedIntakeOrder(ops, scope);\n }\n const lock = (await ops.findOne<IntakeRouteLockRow>(INTAKE_ROUTE_LOCKS, scopeWhere(scope)))!;\n if (lock.intake_order?.includes(key)) {\n await ops.updateMany(INTAKE_ROUTE_LOCKS, scopeWhere(scope), {\n intake_order: lock.intake_order.filter(other => other !== key),\n });\n }\n return { result: { intakeRoutes: deleted.map(toIntakeRouteRecord) }, changed: true };\n });\n }\n\n /**\n * The project's intake routes in the order they are tried, or one board's list when `boardKey`\n * is set; Factory's `DEFAULT_INTAKE_ROUTES` are added once each.\n */\n async listIntakeRoutes(\n scope: StoredBoardScope,\n options: { boardKey?: string } = {},\n ): Promise<StoredIntakeRouteRecord[]> {\n await this.#ensureIntakeRoutes(scope);\n const rows = await readIntakeRoutes(this.ops, scope);\n return rows\n .filter(row => options.boardKey === undefined || row.board_key === options.boardKey)\n .map(toIntakeRouteRecord);\n }\n\n /**\n * The project's intake order, derived from the route list the first time it is read and kept up\n * to date with its boards (see `reconcileIntakeOrder`), with the migration marker. Its boards are\n * the stored ones plus `options.boards` (the caller's registry, so a code board keeps its place).\n */\n async readIntakeOrder(\n scope: StoredBoardScope,\n options: { boards?: readonly string[] } = {},\n ): Promise<StoredIntakeOrder> {\n await this.#ensureIntakeRoutes(scope);\n const current = await this.#intakeOrderState(this.ops, scope, options.boards);\n if (current.lock.intake_order && sameKeys(current.lock.intake_order, current.boardKeys)) {\n return toIntakeOrder(current.lock, current.boardKeys);\n }\n return this.#transact(async ops => {\n await lockIntakeRoutes(ops, scope);\n const fresh = await this.#intakeOrderState(ops, scope, options.boards);\n if (!fresh.lock.intake_order || !sameKeys(fresh.lock.intake_order, fresh.boardKeys)) {\n await ops.updateMany(INTAKE_ROUTE_LOCKS, scopeWhere(scope), { intake_order: fresh.boardKeys });\n }\n return toIntakeOrder(fresh.lock, fresh.boardKeys);\n });\n }\n\n /**\n * Sets the project's intake order, which then no longer follows the route list; `boardKeys` must\n * name every board of the project exactly once: its stored boards, or `options.boards` when given\n * (the caller's registry, code boards too).\n */\n async setIntakeOrder(\n scope: StoredBoardScope,\n boardKeys: string[],\n options: { boards?: readonly string[] } = {},\n ): Promise<StoredIntakeOrder> {\n await this.#ensureIntakeRoutes(scope);\n return this.#transact(async ops => {\n await lockIntakeRoutes(ops, scope);\n const keys = new Set(\n options.boards ?? (await ops.findMany<BoardRow>(BOARDS, scopeWhere(scope))).map(board => board.board_key),\n );\n if (\n boardKeys.length !== keys.size ||\n new Set(boardKeys).size !== boardKeys.length ||\n boardKeys.some(key => !keys.has(key))\n ) {\n throw new StoredBoardError(\n 'intake_order_set_mismatch',\n 'The intake order must list every board of the project exactly once; reload the boards and try again.',\n );\n }\n await ops.updateMany(INTAKE_ROUTE_LOCKS, scopeWhere(scope), {\n intake_order: boardKeys,\n intake_order_origin: 'explicit',\n });\n const lock = (await ops.findOne<IntakeRouteLockRow>(INTAKE_ROUTE_LOCKS, scopeWhere(scope)))!;\n return toIntakeOrder(lock, boardKeys);\n });\n }\n\n /** The project's own evaluator; null for a project created before the setting, which uses `route-list`. */\n async intakeEvaluator(scope: StoredBoardScope): Promise<IntakeEvaluator | null> {\n const lock = await this.ops.findOne<IntakeRouteLockRow>(INTAKE_ROUTE_LOCKS, scopeWhere(scope));\n return lock?.intake_evaluator ?? null;\n }\n\n /** Switches the project's evaluator; returns the setting it had (null: none). */\n async setIntakeEvaluator(scope: StoredBoardScope, evaluator: IntakeEvaluator): Promise<IntakeEvaluator | null> {\n await this.#ensureIntakeRoutes(scope);\n return this.#transact(async ops => {\n await lockIntakeRoutes(ops, scope);\n const lock = (await ops.findOne<IntakeRouteLockRow>(INTAKE_ROUTE_LOCKS, scopeWhere(scope)))!;\n await ops.updateMany(INTAKE_ROUTE_LOCKS, scopeWhere(scope), { intake_evaluator: evaluator });\n return lock.intake_evaluator ?? null;\n });\n }\n\n /** Records how intake decided an arrival; a redelivery under the same key replaces the row. */\n async recordIntakeDecision(\n scope: StoredBoardScope,\n input: IntakeDecisionInput,\n now = new Date(),\n ): Promise<StoredIntakeDecisionRecord> {\n const row = await this.ops.upsertOne<IntakeDecisionRow>(\n INTAKE_DECISIONS,\n ['org_id', 'factory_project_id', 'idempotency_key'],\n {\n ...scopeWhere(scope),\n idempotency_key: input.idempotencyKey,\n outcome: input.outcome,\n evaluator: input.evaluator,\n board_key: input.boardKey ?? null,\n route_id: input.routeId ?? null,\n reason: input.reason ?? null,\n source_key: input.sourceKey ?? null,\n title: input.title,\n url: input.url ?? null,\n arrival: input.arrival ?? null,\n decided_at: now,\n resolved_at: null,\n resolved_by: null,\n },\n );\n return toIntakeDecisionRecord(row);\n }\n\n async getIntakeDecision(scope: StoredBoardScope, id: string): Promise<StoredIntakeDecisionRecord | null> {\n const row = await this.ops.findOne<IntakeDecisionRow>(INTAKE_DECISIONS, { ...scopeWhere(scope), id });\n return row ? toIntakeDecisionRecord(row) : null;\n }\n\n /**\n * Items no board took and nobody has filed since, oldest first, `limit` at a time; pass\n * `nextCursor` back as `cursor` for the next page.\n */\n async listNotRouted(\n scope: StoredBoardScope,\n options: { limit?: number; cursor?: string } = {},\n ): Promise<{ notRouted: StoredIntakeDecisionRecord[]; nextCursor: string | null }> {\n const limit = options.limit ?? 50;\n const after = options.cursor === undefined ? undefined : decodeDecisionCursor(options.cursor);\n const rows = await this.ops.findMany<IntakeDecisionRow>(\n INTAKE_DECISIONS,\n { ...scopeWhere(scope), outcome: 'not_routed', resolved_at: null },\n {\n orderBy: DECISION_ORDER,\n limit: limit + 1,\n ...(after && { cursor: { values: [after.decidedAt, after.id] } }),\n },\n );\n const page = rows.slice(0, limit).map(toIntakeDecisionRecord);\n const last = page.at(-1);\n return {\n notRouted: page,\n nextCursor: rows.length > limit && last ? `${last.decidedAt.toISOString()}_${last.id}` : null,\n };\n }\n\n /** Whether intake turned the source away (Not routed) and nobody has filed it since. */\n async isNotRouted(scope: StoredBoardScope, sourceKey: string): Promise<boolean> {\n const row = await this.ops.findOne<IntakeDecisionRow>(INTAKE_DECISIONS, {\n ...scopeWhere(scope),\n outcome: 'not_routed',\n source_key: sourceKey,\n resolved_at: null,\n });\n return row !== null;\n }\n\n /** The newest `limit` items no board took and nobody has filed since, newest first. */\n async listRecentNotRouted(scope: StoredBoardScope, limit: number): Promise<StoredIntakeDecisionRecord[]> {\n const rows = await this.ops.findMany<IntakeDecisionRow>(\n INTAKE_DECISIONS,\n { ...scopeWhere(scope), outcome: 'not_routed', resolved_at: null },\n { orderBy: NEWEST_DECISION_ORDER, limit },\n );\n return rows.map(toIntakeDecisionRecord);\n }\n\n /**\n * How many items each intake rule placed since `since`, keyed by rule id. Reads placed rows\n * newest first, a page at a time, and stops at the first one older than `since`.\n */\n async countPlacedByRoute(\n scope: StoredBoardScope,\n since: Date,\n options: { pageSize?: number } = {},\n ): Promise<Record<string, number>> {\n const pageSize = options.pageSize ?? 500;\n const counts: Record<string, number> = {};\n let cursor: IntakeDecisionRow | undefined;\n for (;;) {\n const rows = await this.ops.findMany<IntakeDecisionRow>(\n INTAKE_DECISIONS,\n { ...scopeWhere(scope), outcome: 'placed' },\n {\n orderBy: NEWEST_DECISION_ORDER,\n limit: pageSize,\n ...(cursor && { cursor: { values: [cursor.decided_at, cursor.id] } }),\n },\n );\n for (const row of rows) {\n if (row.decided_at < since) return counts;\n if (row.route_id) counts[row.route_id] = (counts[row.route_id] ?? 0) + 1;\n }\n if (rows.length < pageSize) return counts;\n cursor = rows.at(-1);\n }\n }\n\n /**\n * How often each card-move rule was skipped since `since`, with its newest skip, keyed by rule id.\n * Reads skipped rows newest first, a page at a time, and stops at the first one older than `since`.\n */\n async summarizeSkippedByRoute(\n scope: StoredBoardScope,\n since: Date,\n options: { pageSize?: number } = {},\n ): Promise<Record<string, { count: number; latest: StoredIntakeDecisionRecord }>> {\n const pageSize = options.pageSize ?? 500;\n const summary: Record<string, { count: number; latest: StoredIntakeDecisionRecord }> = {};\n let cursor: IntakeDecisionRow | undefined;\n for (;;) {\n const rows = await this.ops.findMany<IntakeDecisionRow>(\n INTAKE_DECISIONS,\n { ...scopeWhere(scope), outcome: 'rule_skipped' },\n {\n orderBy: NEWEST_DECISION_ORDER,\n limit: pageSize,\n ...(cursor && { cursor: { values: [cursor.decided_at, cursor.id] } }),\n },\n );\n for (const row of rows) {\n if (row.decided_at < since) return summary;\n if (!row.route_id) continue;\n const seen = summary[row.route_id];\n if (seen) seen.count += 1;\n else summary[row.route_id] = { count: 1, latest: toIntakeDecisionRecord(row) };\n }\n if (rows.length < pageSize) return summary;\n cursor = rows.at(-1);\n }\n }\n\n /** Marks the Not routed rows for a source resolved once a card is filed for it. Returns how many. */\n async resolveNotRouted(scope: StoredBoardScope, sourceKey: string, by: string, now = new Date()): Promise<number> {\n return this.ops.updateMany(\n INTAKE_DECISIONS,\n { ...scopeWhere(scope), outcome: 'not_routed', source_key: sourceKey, resolved_at: null },\n { resolved_at: now, resolved_by: by },\n );\n }\n\n async #intakeOrderState(\n ops: FactoryStorageOps,\n scope: StoredBoardScope,\n extra: readonly string[] = [],\n ): Promise<{ lock: IntakeRouteLockRow; boardKeys: string[] }> {\n const [lock, boards, routes] = await Promise.all([\n ops.findOne<IntakeRouteLockRow>(INTAKE_ROUTE_LOCKS, scopeWhere(scope)),\n ops.findMany<BoardRow>(BOARDS, scopeWhere(scope)),\n readIntakeRoutes(ops, scope),\n ]);\n const sidebar = boards\n .sort((left, right) => left.position - right.position || left.board_key.localeCompare(right.board_key))\n .map(board => board.board_key);\n sidebar.push(...extra.filter(key => !sidebar.includes(key)));\n const records = routes.map(toIntakeRouteRecord);\n const stored = lock!.intake_order ?? deriveIntakeOrder(records, sidebar);\n return { lock: lock!, boardKeys: reconcileIntakeOrder(stored, sidebar, records) };\n }\n\n async getIntakeRoute(scope: StoredBoardScope, id: string): Promise<StoredIntakeRouteRecord | null> {\n const row = await this.ops.findOne<IntakeRouteRow>(INTAKE_ROUTES, { ...scopeWhere(scope), id });\n return row ? toIntakeRouteRecord(row) : null;\n }\n\n /**\n * Adds a route after the project's last one. A route that places new cards goes just ahead of the\n * first route that takes every new card instead, since after it it would never place one.\n */\n async createIntakeRoute(\n scope: StoredBoardScope,\n input: StoredIntakeRouteInput,\n actor: string,\n ): Promise<StoredIntakeRouteRecord> {\n const id = randomUUID();\n checkRouteEvents(input.on ?? DEFAULT_ROUTE_EVENTS, input.when ?? null);\n await this.#ensureIntakeRoutes(scope);\n await this.#transact(async ops => {\n const rows = await lockIntakeRoutes(ops, scope);\n if (boardRouteCount(rows, input.target.boardKey) >= MAX_INTAKE_ROUTES_PER_BOARD) {\n throw new StoredBoardError(\n 'intake_route_limit',\n `A board can have at most ${MAX_INTAKE_ROUTES_PER_BOARD} intake rules; delete one first.`,\n );\n }\n const position = rows.reduce((max, row) => Math.max(max, row.position), -1) + 1;\n await insertIntakeRoute(ops, scope, { id, input, position, actor });\n await forgetDerivedIntakeOrder(ops, scope);\n // Ahead of the catch-all taking each kind it files, the later one when they differ, so a route\n // filing issues and pull requests stays behind a catch-all for pull requests, as it always\n // has. A kind no route catches reaches it at the end, so it stays there.\n const catchAlls = [\n ...arrivalKinds({\n on: input.on ?? DEFAULT_ROUTE_EVENTS,\n ...(input.pullRequestOpenedMovesOnly && { pullRequestOpenedMovesOnly: true }),\n }),\n ].map(kind => rows.findIndex(row => catchesEveryNewCard(row, kind)));\n const ahead = catchAlls.length > 0 && !catchAlls.includes(-1) ? Math.max(...catchAlls) : -1;\n if (ahead >= 0) {\n const added = (await readIntakeRoutes(ops, scope)).find(row => row.id === id)!;\n await placeIntakeRoutes(ops, rows.toSpliced(ahead, 0, added), actor);\n }\n });\n return (await this.getIntakeRoute(scope, id))!;\n }\n\n /** Changes the fields `patch` names; the route keeps its place in the order. */\n async updateIntakeRoute(\n scope: StoredBoardScope,\n id: string,\n patch: Partial<StoredIntakeRouteInput>,\n options: { expectedRevision: number; actor: string },\n ): Promise<StoredIntakeRouteRecord> {\n await this.#transact(async ops => {\n // Lock first, as every route write does, so it can't deadlock against a reorder.\n const rows = await lockIntakeRoutes(ops, scope);\n const row = rows.find(route => route.id === id);\n if (!row) throw intakeRouteNotFound(id);\n checkIntakeRouteRevision(row, options.expectedRevision);\n const boardKey = patch.target?.boardKey;\n if (\n boardKey !== undefined &&\n boardKey !== row.board_key &&\n boardRouteCount(rows, boardKey) >= MAX_INTAKE_ROUTES_PER_BOARD\n ) {\n throw new StoredBoardError(\n 'intake_route_limit',\n `A board can have at most ${MAX_INTAKE_ROUTES_PER_BOARD} intake rules; delete one first.`,\n );\n }\n checkRouteEvents(patch.on ?? routeEvents(row), patch.when !== undefined ? patch.when : row.when_condition);\n await updateIntakeRouteRow(ops, row, {\n ...(patch.on !== undefined && { on_events: patch.on }),\n ...(patch.name !== undefined && { name: patch.name }),\n ...(patch.enabled !== undefined && { enabled: patch.enabled }),\n ...(patch.when !== undefined && { when_condition: patch.when }),\n ...(patch.target !== undefined && {\n board_key: patch.target.boardKey,\n phase_key: patch.target.phaseKey ?? null,\n join_closed_issue: patch.target.joinClosedIssue ?? false,\n move_to_board_key: patch.target.moveToBoardKey ?? null,\n }),\n updated_by: options.actor,\n });\n await forgetDerivedIntakeOrder(ops, scope);\n });\n return (await this.getIntakeRoute(scope, id))!;\n }\n\n /** Deletes a route; the routes after it move up one place. */\n async deleteIntakeRoute(scope: StoredBoardScope, id: string, options: { expectedRevision: number }): Promise<void> {\n await this.#ensureIntakeRoutes(scope);\n await this.#transact(async ops => {\n const rows = await lockIntakeRoutes(ops, scope);\n const row = rows.find(route => route.id === id);\n if (!row) throw intakeRouteNotFound(id);\n checkIntakeRouteRevision(row, options.expectedRevision);\n if ((await ops.deleteMany(INTAKE_ROUTES, { id: row.id, revision: row.revision })) === 0) {\n throw new ConcurrentBoardWrite();\n }\n await placeIntakeRoutes(\n ops,\n rows.filter(route => route.id !== row.id),\n );\n await forgetDerivedIntakeOrder(ops, scope);\n });\n }\n\n /**\n * Puts the project's routes in the order of `ids`, which must name every route exactly once. With\n * `boardKey`, `ids` names every route of that board instead: they trade the places the board's\n * routes hold, and every other board's routes keep theirs. Returns the routes reordered.\n */\n async reorderIntakeRoutes(\n scope: StoredBoardScope,\n ids: string[],\n actor: string,\n options: { boardKey?: string } = {},\n ): Promise<StoredIntakeRouteRecord[]> {\n const { boardKey } = options;\n await this.#ensureIntakeRoutes(scope);\n await this.#transact(async ops => {\n const rows = await lockIntakeRoutes(ops, scope);\n const scoped = boardKey === undefined ? rows : rows.filter(row => row.board_key === boardKey);\n const byId = new Map(scoped.map(row => [row.id, row]));\n if (ids.length !== scoped.length || new Set(ids).size !== ids.length || ids.some(id => !byId.has(id))) {\n throw new StoredBoardError(\n 'intake_route_set_mismatch',\n boardKey === undefined\n ? 'The order must list every intake route of the project exactly once; reload the routes and try again.'\n : `The order must list every intake rule of board \"${boardKey}\" exactly once; reload the rules and try again.`,\n );\n }\n const queue = ids.map(id => byId.get(id)!);\n const order =\n boardKey === undefined ? queue : rows.map(row => (row.board_key === boardKey ? queue.shift()! : row));\n await placeIntakeRoutes(ops, order, actor);\n await forgetDerivedIntakeOrder(ops, scope);\n });\n return this.listIntakeRoutes(scope, { boardKey });\n }\n\n /**\n * Creates the project's route lock row (see `FACTORY_INTAKE_ROUTE_LOCKS_SCHEMA`) and adds each of\n * `DEFAULT_INTAKE_ROUTES` the row doesn't list as added yet, after the project's routes. The row\n * records every default it added, so a project whose admin deleted one doesn't get it back. Runs\n * before, never inside, a write's transaction: the lock taken there must always be an update.\n */\n async #ensureIntakeRoutes(scope: StoredBoardScope): Promise<void> {\n const lock = await this.ops.findOne<IntakeRouteLockRow>(INTAKE_ROUTE_LOCKS, scopeWhere(scope));\n if (lock && missingDefaults(lock).length === 0) return;\n await this.#transact(async ops => {\n if (await ops.findOne(INTAKE_ROUTE_LOCKS, scopeWhere(scope))) await lockIntakeRoutes(ops, scope);\n // A racing first read inserted the lock row first: this one fails on the unique index and\n // retries, taking the lock above.\n else\n await ops.insertOne(INTAKE_ROUTE_LOCKS, { ...scopeWhere(scope), locked_at: new Date(), seeded_defaults: [] });\n // Read under the lock: a racing seeder that committed first already added what it listed.\n const current = (await ops.findOne<IntakeRouteLockRow>(INTAKE_ROUTE_LOCKS, scopeWhere(scope)))!;\n const missing = missingDefaults(current);\n if (missing.length === 0) return;\n const rows = await readIntakeRoutes(ops, scope);\n const retired = new Set<string>();\n // Pull requests link to the card of the issue they close on their own now: a route that\n // joined them is switched off, and kept so its history stays readable.\n // One an admin had changed is named in the decision log: the linked rule doesn't do all it did.\n if (missing.some(({ key }) => key === LINKED_PULL_REQUEST_ROUTE_KEY)) {\n for (const row of rows) {\n if (!row.join_closed_issue || !row.enabled) continue;\n await updateIntakeRouteRow(ops, row, { enabled: false, updated_by: DEFAULT_INTAKE_ROUTE_ACTOR });\n retired.add(row.id);\n if (isShippedJoinRoute(row)) continue;\n await ops.upsertOne(INTAKE_DECISIONS, ['org_id', 'factory_project_id', 'idempotency_key'], {\n ...scopeWhere(scope),\n idempotency_key: `rule-retired:${row.id}`,\n outcome: 'rule_retired',\n evaluator: current.intake_evaluator ?? 'route-list',\n board_key: row.board_key,\n route_id: row.id,\n reason:\n 'Switched off: pull requests now link to the card of the issue they close on their own, and only the rule `Trusted pull requests take a waiting issue to Review` moves a waiting card. Add a card-move rule on pull_request.opened to move cards the way this route did.',\n source_key: null,\n title: row.name,\n url: null,\n arrival: null,\n decided_at: new Date(),\n resolved_at: null,\n resolved_by: null,\n });\n }\n }\n let position = rows.reduce((max, row) => Math.max(max, row.position), -1) + 1;\n const first: string[] = [];\n const perBoard = new Map<string, number>();\n // Only a project no default was added to yet is new.\n const newProject = seededDefaults(current).length === 0;\n for (const { key, route, first: leads, newProjectsOnly } of missing) {\n if (newProjectsOnly && !newProject) continue;\n // A board at the limit keeps its own routes; the default counts as added all the same. The\n // linked rule takes the slot of a join route it switched off.\n const count =\n perBoard.get(route.target.boardKey) ??\n boardRouteCount(\n key === LINKED_PULL_REQUEST_ROUTE_KEY ? rows.filter(row => !retired.has(row.id)) : rows,\n route.target.boardKey,\n );\n if (count >= MAX_INTAKE_ROUTES_PER_BOARD) continue;\n perBoard.set(route.target.boardKey, count + 1);\n const id = randomUUID();\n await insertIntakeRoute(ops, scope, {\n id,\n input: route,\n position: position++,\n actor: DEFAULT_INTAKE_ROUTE_ACTOR,\n });\n if (leads) first.push(id);\n }\n // A project that had routes before gets a leading default ahead of them.\n if (first.length > 0 && rows.length > 0) {\n const placed = await readIntakeRoutes(ops, scope);\n const leading = new Set(first);\n await placeIntakeRoutes(ops, [\n ...first.map(id => placed.find(row => row.id === id)!),\n ...placed.filter(row => !leading.has(row.id)),\n ]);\n }\n await ops.updateMany(INTAKE_ROUTE_LOCKS, scopeWhere(scope), {\n seeded_defaults: [...seededDefaults(current), ...missing.map(({ key }) => key)],\n });\n });\n }\n\n /**\n * Runs `fn` in a transaction and replaces the project's version when it changed anything.\n * Lost races (a compare-and-set miss, or a concurrent write that inserted the same board or the\n * project's first version row) retry from fresh reads.\n */\n async #write<T>(\n scope: StoredBoardScope,\n fn: (ops: FactoryStorageOps) => Promise<{ result: T; changed: boolean }>,\n ): Promise<T> {\n return this.#transact(async ops => {\n const { result, changed } = await fn(ops);\n if (changed) await bumpVersion(ops, scope);\n return result;\n });\n }\n\n /**\n * Runs `fn` in a transaction, retrying lost races from fresh reads. Intake route writes use it\n * directly: routes are read uncached, so they leave the board definition version alone.\n */\n async #transact<T>(fn: (ops: FactoryStorageOps) => Promise<T>): Promise<T> {\n for (let attempt = 1; ; attempt++) {\n try {\n // Read committed is enough: every row change is a compare-and-set on `revision` and every\n // insert meets the unique index. Serializable isolation would also fail writes to\n // unrelated projects that replicas run side by side.\n return await this.storage.withTransaction(fn);\n } catch (error) {\n const retryable = error instanceof ConcurrentBoardWrite || error instanceof UniqueViolationError;\n if (!retryable || attempt >= MAX_WRITE_ATTEMPTS) throw error;\n }\n }\n }\n}\n\nasync function readVersion(ops: FactoryStorageOps, scope: StoredBoardScope): Promise<string | null> {\n const row = await ops.findOne<{ version: string }>(VERSIONS, scopeWhere(scope));\n return row?.version ?? null;\n}\n\n/** The project's board under `key`, read through `ops` so a caller inside a transaction reads within it. */\nexport async function readStoredBoard(\n ops: FactoryStorageOps,\n scope: StoredBoardScope,\n key: string,\n): Promise<StoredBoardRecord | null> {\n const row = await ops.findOne<BoardRow>(BOARDS, { ...scopeWhere(scope), board_key: key });\n if (!row) return null;\n const phases = await ops.findMany<PhaseRow>(PHASES, { ...scopeWhere(scope), board_key: key });\n return toRecord(row, phases);\n}\n\nasync function readBoards(ops: FactoryStorageOps, scope: StoredBoardScope): Promise<StoredBoardRecord[]> {\n const [rows, phases] = await Promise.all([\n ops.findMany<BoardRow>(BOARDS, scopeWhere(scope)),\n ops.findMany<PhaseRow>(PHASES, scopeWhere(scope)),\n ]);\n const byBoard = new Map<string, PhaseRow[]>();\n for (const phase of phases) {\n const list = byBoard.get(phase.board_key) ?? [];\n list.push(phase);\n byBoard.set(phase.board_key, list);\n }\n return rows\n .sort((left, right) => left.position - right.position || left.board_key.localeCompare(right.board_key))\n .map(row => toRecord(row, byBoard.get(row.board_key) ?? []));\n}\n\n/**\n * Inserts the project's version row if it has none. This runs outside the write transaction: on\n * Postgres, two transactions racing to insert it would leave the loser's transaction aborted, so\n * the version bump inside a write must always be an update.\n */\nasync function ensureVersionRow(ops: FactoryStorageOps, scope: StoredBoardScope): Promise<void> {\n if (await ops.findOne(VERSIONS, scopeWhere(scope))) return;\n try {\n await ops.insertOne(VERSIONS, { ...scopeWhere(scope), version: randomUUID(), updated_at: new Date() });\n } catch (error) {\n if (!(error instanceof UniqueViolationError)) throw error;\n }\n}\n\nasync function bumpVersion(ops: FactoryStorageOps, scope: StoredBoardScope): Promise<void> {\n await ops.upsertOne(VERSIONS, ['org_id', 'factory_project_id'], {\n ...scopeWhere(scope),\n version: randomUUID(),\n updated_at: new Date(),\n });\n}\n\nasync function findBoard(ops: FactoryStorageOps, scope: StoredBoardScope, key: string): Promise<BoardRow> {\n const row = await ops.findOne<BoardRow>(BOARDS, { ...scopeWhere(scope), board_key: key });\n if (!row) {\n throw new StoredBoardError('board_not_found', `Board \"${key}\" does not exist in this project.`);\n }\n return row;\n}\n\nfunction checkRevision(row: BoardRow, key: string, expectedRevision: number): void {\n if (row.revision !== expectedRevision) {\n throw new StoredBoardError(\n 'revision_mismatch',\n `Board \"${key}\" is at revision ${row.revision}, not ${expectedRevision}; reload it and try again.`,\n );\n }\n}\n\nfunction nextPosition(rows: BoardRow[]): number {\n return rows.reduce((max, row) => Math.max(max, row.position), -1) + 1;\n}\n\n/** Sets columns on a board row and raises its revision, unless another writer changed it first. */\nasync function updateRow(ops: FactoryStorageOps, row: BoardRow, set: Partial<BoardRow>): Promise<void> {\n const updated = await ops.updateMany(\n BOARDS,\n { id: row.id, revision: row.revision },\n { ...set, revision: row.revision + 1, updated_at: new Date() },\n );\n if (updated !== 1) throw new ConcurrentBoardWrite();\n}\n\nasync function insertPhases(ops: FactoryStorageOps, scope: StoredBoardScope, input: StoredBoardInput): Promise<void> {\n for (const [position, phase] of input.phases.entries()) {\n await ops.insertOne<PhaseRow>(PHASES, {\n ...scopeWhere(scope),\n board_key: input.key,\n phase_key: phase.key,\n position,\n name: phase.name,\n description: phase.description ?? null,\n kind: phase.kind,\n runner: phase.runner ?? null,\n next_phases: phase.nextPhases ?? null,\n auto_start: phase.autoStart ?? false,\n auto_start_when: phase.autoStartWhen ?? null,\n exit_tool: phase.exitTool ?? null,\n tools: phase.tools?.length ? phase.tools : null,\n });\n }\n}\n\nasync function insertBoard(\n ops: FactoryStorageOps,\n scope: StoredBoardScope,\n input: StoredBoardInput,\n options: { position: number; actor: string },\n): Promise<void> {\n const now = new Date();\n await ops.insertOne<BoardRow>(BOARDS, {\n ...scopeWhere(scope),\n board_key: input.key,\n name: input.name,\n description: input.description ?? null,\n position: options.position,\n revision: 1,\n created_by: options.actor,\n created_at: now,\n updated_by: options.actor,\n updated_at: now,\n });\n await insertPhases(ops, scope, input);\n}\n\n/** Replaces a board's definition and phases in place, keeping its key, position and history. */\nasync function writeBoard(\n ops: FactoryStorageOps,\n scope: StoredBoardScope,\n row: BoardRow,\n input: StoredBoardInput,\n actor: string,\n): Promise<void> {\n await updateRow(ops, row, { name: input.name, description: input.description ?? null, updated_by: actor });\n await ops.deleteMany(PHASES, { ...scopeWhere(scope), board_key: row.board_key });\n await insertPhases(ops, scope, { ...input, key: row.board_key });\n}\n\n/**\n * A row's events as stored. One written before routes named events has none: it reads as the legacy\n * `work_item.created`, filing issues and pull requests alike, as it always has (rows are never rewritten).\n */\nfunction routeEvents(row: IntakeRouteRow): RouteEvent[] {\n return row.on_events ? [...row.on_events] : [...DEFAULT_ROUTE_EVENTS];\n}\n\n/** A row's events with what they mean on it: `pull_request.opened` only moves a card on a row from before it filed. */\nfunction routeArrivals(row: IntakeRouteRow): RouteArrivals {\n const on = routeEvents(row);\n return {\n on,\n pullRequestOpenedMovesOnly: row.opened_files_pull_requests !== true && on.includes('pull_request.opened'),\n };\n}\n\nfunction checkRouteEvents(on: readonly string[], when: RuleGroup | null): void {\n const problem = routeEventsProblem(on, when);\n if (problem) throw new StoredBoardError('invalid_intake_route', problem);\n}\n\nfunction toIntakeRouteRecord(row: IntakeRouteRow): StoredIntakeRouteRecord {\n return {\n id: row.id,\n orgId: row.org_id,\n factoryProjectId: row.factory_project_id,\n name: row.name,\n enabled: row.enabled,\n position: row.position,\n when: currentRuleGroup(row.when_condition),\n target: {\n boardKey: row.board_key,\n phaseKey: row.phase_key,\n joinClosedIssue: row.join_closed_issue === true,\n moveToBoardKey: row.move_to_board_key ?? null,\n },\n on: routeEvents(row),\n ...(routeArrivals(row).pullRequestOpenedMovesOnly && { pullRequestOpenedMovesOnly: true as const }),\n revision: row.revision,\n createdBy: row.created_by,\n createdAt: row.created_at,\n updatedBy: row.updated_by,\n updatedAt: row.updated_at,\n };\n}\n\nconst DECISION_ORDER: [string, 'asc'][] = [\n ['decided_at', 'asc'],\n ['id', 'asc'],\n];\nconst NEWEST_DECISION_ORDER: [string, 'desc'][] = [\n ['decided_at', 'desc'],\n ['id', 'desc'],\n];\n\nfunction decodeDecisionCursor(cursor: string): { decidedAt: Date; id: string } {\n const sep = cursor.lastIndexOf('_');\n const decidedAt = new Date(cursor.slice(0, sep));\n const id = cursor.slice(sep + 1);\n if (sep <= 0 || Number.isNaN(decidedAt.getTime()) || !id) {\n throw new StoredBoardError('invalid_intake_cursor', 'The cursor is not one this list returned.');\n }\n return { decidedAt, id };\n}\n\n/**\n * Stamps a project being created with the `intake-order` evaluator, through `ops`, the creating\n * transaction's, so the project and its setting commit together. A new project has no lock row yet;\n * its first intake read adds the default routes to this one. Its intake order is its own from the\n * start (`explicit`, empty): deriving one from the route list is for projects that had one before,\n * and would keep Work, whose defaults lead the list, ahead of every board added later. Each board\n * slots in as it comes, just above the first board that takes every new card.\n */\nexport async function stampNewProjectIntake(ops: FactoryStorageOps, scope: StoredBoardScope): Promise<void> {\n await ops.insertOne(INTAKE_ROUTE_LOCKS, {\n ...scopeWhere(scope),\n locked_at: new Date(),\n seeded_defaults: [],\n intake_order: [],\n intake_order_origin: 'explicit',\n intake_evaluator: 'intake-order',\n });\n}\n\nfunction toIntakeOrder(lock: IntakeRouteLockRow, boardKeys: string[]): StoredIntakeOrder {\n return { boardKeys, origin: lock.intake_order_origin ?? 'derived' };\n}\n\n/**\n * A rule write changes what a derived order would be: drop it, so the next read derives it afresh.\n * An order an admin set stays.\n */\nasync function forgetDerivedIntakeOrder(ops: FactoryStorageOps, scope: StoredBoardScope): Promise<void> {\n await ops.updateMany(INTAKE_ROUTE_LOCKS, { ...scopeWhere(scope), intake_order_origin: null }, { intake_order: null });\n}\n\nfunction sameKeys(left: readonly string[], right: readonly string[]): boolean {\n return left.length === right.length && left.every((key, index) => key === right[index]);\n}\n\nfunction boardRouteCount(rows: readonly IntakeRouteRow[], boardKey: string): number {\n return rows.filter(row => row.board_key === boardKey).length;\n}\n\n/** Whether a stored join route is still the one projects were given, which the linked rule replaces. */\nfunction isShippedJoinRoute(row: IntakeRouteRow): boolean {\n return (\n row.board_key === RETIRED_JOIN_ROUTE.target.boardKey &&\n row.phase_key === RETIRED_JOIN_ROUTE.target.phaseKey &&\n isDeepStrictEqual(currentRuleGroup(row.when_condition), RETIRED_JOIN_ROUTE.when)\n );\n}\n\n/** Whether `row` files every new issue, or pull request, that reaches it, as the seeded \"Everything else\" route does. */\nfunction catchesEveryNewCard(row: IntakeRouteRow, kind: ArrivalKind): boolean {\n return (\n row.enabled &&\n !row.join_closed_issue &&\n kindsTakenWhole({ when: row.when_condition, ...routeArrivals(row) }).includes(kind)\n );\n}\n\nasync function readIntakeRoutes(ops: FactoryStorageOps, scope: StoredBoardScope): Promise<IntakeRouteRow[]> {\n const rows = await ops.findMany<IntakeRouteRow>(INTAKE_ROUTES, scopeWhere(scope));\n return rows.sort((left, right) => left.position - right.position);\n}\n\nfunction intakeRouteNotFound(id: string): StoredBoardError {\n return new StoredBoardError('intake_route_not_found', `Intake route \"${id}\" does not exist in this project.`);\n}\n\nfunction checkIntakeRouteRevision(row: IntakeRouteRow, expectedRevision: number): void {\n if (row.revision !== expectedRevision) {\n throw new StoredBoardError(\n 'revision_mismatch',\n `Intake route \"${row.name}\" is at revision ${row.revision}, not ${expectedRevision}; reload it and try again.`,\n );\n }\n}\n\n/** Sets columns on a route row and raises its revision, unless another writer changed it first. */\nasync function updateIntakeRouteRow(\n ops: FactoryStorageOps,\n row: IntakeRouteRow,\n set: Partial<IntakeRouteRow>,\n): Promise<number> {\n const revision = row.revision + 1;\n const updated = await ops.updateMany(\n INTAKE_ROUTES,\n { id: row.id, revision: row.revision },\n { ...set, revision, updated_at: new Date() },\n );\n if (updated !== 1) throw new ConcurrentBoardWrite();\n return revision;\n}\n\nasync function insertIntakeRoute(\n ops: FactoryStorageOps,\n scope: StoredBoardScope,\n route: { id: string; input: StoredIntakeRouteInput; position: number; actor: string },\n): Promise<void> {\n const now = new Date();\n await ops.insertOne<IntakeRouteRow>(INTAKE_ROUTES, {\n id: route.id,\n ...scopeWhere(scope),\n name: route.input.name,\n enabled: route.input.enabled ?? true,\n position: route.position,\n when_condition: route.input.when ?? null,\n board_key: route.input.target.boardKey,\n phase_key: route.input.target.phaseKey ?? null,\n on_events: route.input.on ?? null,\n join_closed_issue: route.input.target.joinClosedIssue ?? false,\n opened_files_pull_requests: route.input.pullRequestOpenedMovesOnly ? null : true,\n move_to_board_key: route.input.target.moveToBoardKey ?? null,\n revision: 1,\n created_by: route.actor,\n created_at: now,\n updated_by: route.actor,\n updated_at: now,\n });\n}\n\n/**\n * Takes the project's route lock and reads the routes. Writes that add, delete or move routes\n * call this first, so they run one after another and each reads what the one before committed.\n */\nasync function lockIntakeRoutes(ops: FactoryStorageOps, scope: StoredBoardScope): Promise<IntakeRouteRow[]> {\n if ((await ops.updateMany(INTAKE_ROUTE_LOCKS, scopeWhere(scope), { locked_at: new Date() })) !== 1) {\n throw new ConcurrentBoardWrite();\n }\n return readIntakeRoutes(ops, scope);\n}\n\n/** Moves routes, read under the project's route lock, to the positions of their order in `rows`. */\nasync function placeIntakeRoutes(ops: FactoryStorageOps, rows: IntakeRouteRow[], actor?: string): Promise<void> {\n const moving = rows.flatMap((row, position) => (row.position === position ? [] : [{ row, position }]));\n const parked = [];\n for (const [index, { row, position }] of moving.entries()) {\n const revision = await updateIntakeRouteRow(ops, row, {\n position: -(index + 1),\n ...(actor !== undefined && { updated_by: actor }),\n });\n parked.push({ id: row.id, revision, position });\n }\n for (const { id, revision, position } of parked) {\n if ((await ops.updateMany(INTAKE_ROUTES, { id, revision }, { position })) !== 1) throw new ConcurrentBoardWrite();\n }\n}\n"],"mappings":";;;;;;;;;AAmIA,MAAM,0BAAiD;CACrD,iBAAiB;CACjB,gCAAgB,IAAI,IAAI;CACxB,kBAAkB,KAAA;CAClB,YAAY,CAAC;AACf;;AAiFA,MAAa,8BAA8B;;AAgF3C,MAAM,wBAAwB,CAAC,iBAAiB;;AAGhD,MAAa,6BAA6B;AAE1C,IAAa,mBAAb,cAAsC,MAAM;CAG/B;CAFX,OAAgB;CAChB,YACE,MACA,SACA;EACA,MAAM,OAAO;EAHJ,KAAA,OAAA;CAIX;AACF;AA+FA,SAAS,uBAAuB,KAAoD;CAClF,OAAO;EACL,IAAI,IAAI;EACR,OAAO,IAAI;EACX,kBAAkB,IAAI;EACtB,gBAAgB,IAAI;EACpB,SAAS,IAAI;EACb,WAAW,IAAI;EACf,UAAU,IAAI;EACd,SAAS,IAAI;EACb,QAAQ,IAAI;EACZ,WAAW,IAAI;EACf,OAAO,IAAI;EACX,KAAK,IAAI;EACT,SAAS,IAAI;EACb,WAAW,IAAI;EACf,YAAY,IAAI;EAChB,YAAY,IAAI;CAClB;AACF;AAEA,SAAS,eAAe,MAAoC;CAC1D,OAAO,KAAK,mBAAmB;AACjC;AAEA,SAAS,gBAAgB,MAAoE;CAC3F,MAAM,SAAS,IAAI,IAAI,eAAe,IAAI,CAAC;CAC3C,OAAO,sBAAsB,QAAQ,EAAE,UAAU,CAAC,OAAO,IAAI,GAAG,CAAC;AACnE;AAEA,MAAM,SAAS;AACf,MAAM,SAAS;AACf,MAAM,WAAW;AACjB,MAAM,gBAAgB;AACtB,MAAM,qBAAqB;AAC3B,MAAM,mBAAmB;AACzB,MAAM,qBAAqB;AAC3B,MAAM,kBAAkB;AAExB,SAAS,WAAW,EAAE,OAAO,oBAAsC;CACjE,OAAO;EAAE,QAAQ;EAAO,oBAAoB;CAAiB;AAC/D;AAEA,SAAS,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,IAAI,WAAW,oBAAoB,WAAW,KAAK,GAAG,EAAE,2BAAW,IAAI,KAAK,EAAE,CAAC,MAAO,GAC/F,MAAM,IAAI,qBAAqB;CAEjC,OAAO,iBAAiB,KAAK,KAAK;AACpC;;AAGA,eAAe,kBAAkB,KAAwB,MAAwB,OAA+B;CAC9G,MAAM,SAAS,KAAK,SAAS,KAAK,aAAc,IAAI,aAAa,WAAW,CAAC,IAAI,CAAC;EAAE;EAAK;CAAS,CAAC,CAAE;CACrG,MAAM,SAAS,CAAC;CAChB,KAAK,MAAM,CAAC,OAAO,EAAE,KAAK,eAAe,OAAO,QAAQ,GAAG;EACzD,MAAM,WAAW,MAAM,qBAAqB,KAAK,KAAK;GACpD,UAAU,EAAE,QAAQ;GACpB,GAAI,UAAU,KAAA,KAAa,EAAE,YAAY,MAAM;EACjD,CAAC;EACD,OAAO,KAAK;GAAE,IAAI,IAAI;GAAI;GAAU;EAAS,CAAC;CAChD;CACA,KAAK,MAAM,EAAE,IAAI,UAAU,cAAc,QACvC,IAAK,MAAM,IAAI,WAAW,eAAe;EAAE;EAAI;CAAS,GAAG,EAAE,SAAS,CAAC,MAAO,GAAG,MAAM,IAAI,qBAAqB;AAEpH"}
|
|
@@ -11,6 +11,12 @@ export declare const FACTORY_INTAKE_ROUTES_SCHEMA: CollectionSchema;
|
|
|
11
11
|
* run one after another and positions stay 0..n-1 with no gaps.
|
|
12
12
|
*/
|
|
13
13
|
export declare const FACTORY_INTAKE_ROUTE_LOCKS_SCHEMA: CollectionSchema;
|
|
14
|
+
/**
|
|
15
|
+
* One row per arrival intake decided on, keyed by the arrival's decision, so a redelivery updates
|
|
16
|
+
* it instead of adding another. A `not_routed` row is an item no board took; it holds the arrival
|
|
17
|
+
* so Route again can file it, and is resolved once a card is filed for its source.
|
|
18
|
+
*/
|
|
19
|
+
export declare const FACTORY_INTAKE_DECISIONS_SCHEMA: CollectionSchema;
|
|
14
20
|
/**
|
|
15
21
|
* One row per project whose `version` is replaced inside every board write, so other replicas
|
|
16
22
|
* can tell their cached boards are stale with one indexed read.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../../../../src/storage/domains/boards/schemas.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAE7D,sFAAsF;AACtF,eAAO,MAAM,qBAAqB,EAAE,gBAmBnC,CAAC;AAEF,0EAA0E;AAC1E,eAAO,MAAM,2BAA2B,EAAE,gBA4BzC,CAAC;AAEF,yFAAyF;AACzF,eAAO,MAAM,4BAA4B,EAAE,
|
|
1
|
+
{"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../../../../src/storage/domains/boards/schemas.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAE7D,sFAAsF;AACtF,eAAO,MAAM,qBAAqB,EAAE,gBAmBnC,CAAC;AAEF,0EAA0E;AAC1E,eAAO,MAAM,2BAA2B,EAAE,gBA4BzC,CAAC;AAEF,yFAAyF;AACzF,eAAO,MAAM,4BAA4B,EAAE,gBAmC1C,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,iCAAiC,EAAE,gBAqB/C,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,+BAA+B,EAAE,gBA4B7C,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,wCAAwC,EAAE,gBAgBtD,CAAC"}
|
|
@@ -113,14 +113,18 @@ const FACTORY_INTAKE_ROUTES_SCHEMA = {
|
|
|
113
113
|
type: "json",
|
|
114
114
|
nullable: true
|
|
115
115
|
},
|
|
116
|
-
|
|
116
|
+
join_closed_issue: {
|
|
117
117
|
type: "boolean",
|
|
118
118
|
nullable: true
|
|
119
119
|
},
|
|
120
|
-
|
|
120
|
+
opened_files_pull_requests: {
|
|
121
121
|
type: "boolean",
|
|
122
122
|
nullable: true
|
|
123
123
|
},
|
|
124
|
+
move_to_board_key: {
|
|
125
|
+
type: "text",
|
|
126
|
+
nullable: true
|
|
127
|
+
},
|
|
124
128
|
revision: { type: "integer" },
|
|
125
129
|
created_by: { type: "text" },
|
|
126
130
|
created_at: { type: "timestamp" },
|
|
@@ -155,6 +159,18 @@ const FACTORY_INTAKE_ROUTE_LOCKS_SCHEMA = {
|
|
|
155
159
|
seeded_defaults: {
|
|
156
160
|
type: "json",
|
|
157
161
|
nullable: true
|
|
162
|
+
},
|
|
163
|
+
intake_order: {
|
|
164
|
+
type: "json",
|
|
165
|
+
nullable: true
|
|
166
|
+
},
|
|
167
|
+
intake_order_origin: {
|
|
168
|
+
type: "text",
|
|
169
|
+
nullable: true
|
|
170
|
+
},
|
|
171
|
+
intake_evaluator: {
|
|
172
|
+
type: "text",
|
|
173
|
+
nullable: true
|
|
158
174
|
}
|
|
159
175
|
},
|
|
160
176
|
uniqueIndexes: [{
|
|
@@ -163,6 +179,80 @@ const FACTORY_INTAKE_ROUTE_LOCKS_SCHEMA = {
|
|
|
163
179
|
}]
|
|
164
180
|
};
|
|
165
181
|
/**
|
|
182
|
+
* One row per arrival intake decided on, keyed by the arrival's decision, so a redelivery updates
|
|
183
|
+
* it instead of adding another. A `not_routed` row is an item no board took; it holds the arrival
|
|
184
|
+
* so Route again can file it, and is resolved once a card is filed for its source.
|
|
185
|
+
*/
|
|
186
|
+
const FACTORY_INTAKE_DECISIONS_SCHEMA = {
|
|
187
|
+
name: "factory_intake_decisions",
|
|
188
|
+
columns: {
|
|
189
|
+
id: { type: "uuid-pk" },
|
|
190
|
+
org_id: { type: "text" },
|
|
191
|
+
factory_project_id: { type: "text" },
|
|
192
|
+
idempotency_key: { type: "text" },
|
|
193
|
+
outcome: { type: "text" },
|
|
194
|
+
evaluator: { type: "text" },
|
|
195
|
+
board_key: {
|
|
196
|
+
type: "text",
|
|
197
|
+
nullable: true
|
|
198
|
+
},
|
|
199
|
+
route_id: {
|
|
200
|
+
type: "text",
|
|
201
|
+
nullable: true
|
|
202
|
+
},
|
|
203
|
+
reason: {
|
|
204
|
+
type: "text",
|
|
205
|
+
nullable: true
|
|
206
|
+
},
|
|
207
|
+
source_key: {
|
|
208
|
+
type: "text",
|
|
209
|
+
nullable: true
|
|
210
|
+
},
|
|
211
|
+
title: { type: "text" },
|
|
212
|
+
url: {
|
|
213
|
+
type: "text",
|
|
214
|
+
nullable: true
|
|
215
|
+
},
|
|
216
|
+
arrival: {
|
|
217
|
+
type: "json",
|
|
218
|
+
nullable: true
|
|
219
|
+
},
|
|
220
|
+
decided_at: { type: "timestamp" },
|
|
221
|
+
resolved_at: {
|
|
222
|
+
type: "timestamp",
|
|
223
|
+
nullable: true
|
|
224
|
+
},
|
|
225
|
+
resolved_by: {
|
|
226
|
+
type: "text",
|
|
227
|
+
nullable: true
|
|
228
|
+
}
|
|
229
|
+
},
|
|
230
|
+
uniqueIndexes: [{
|
|
231
|
+
name: "factory_intake_decisions_key",
|
|
232
|
+
columns: [
|
|
233
|
+
"org_id",
|
|
234
|
+
"factory_project_id",
|
|
235
|
+
"idempotency_key"
|
|
236
|
+
]
|
|
237
|
+
}],
|
|
238
|
+
indexes: [{
|
|
239
|
+
name: "factory_intake_decisions_project",
|
|
240
|
+
columns: [
|
|
241
|
+
"org_id",
|
|
242
|
+
"factory_project_id",
|
|
243
|
+
"outcome",
|
|
244
|
+
"decided_at"
|
|
245
|
+
]
|
|
246
|
+
}, {
|
|
247
|
+
name: "factory_intake_decisions_source",
|
|
248
|
+
columns: [
|
|
249
|
+
"org_id",
|
|
250
|
+
"factory_project_id",
|
|
251
|
+
"source_key"
|
|
252
|
+
]
|
|
253
|
+
}]
|
|
254
|
+
};
|
|
255
|
+
/**
|
|
166
256
|
* One row per project whose `version` is replaced inside every board write, so other replicas
|
|
167
257
|
* can tell their cached boards are stale with one indexed read.
|
|
168
258
|
*/
|
|
@@ -188,6 +278,6 @@ const FACTORY_BOARD_DEFINITION_VERSIONS_SCHEMA = {
|
|
|
188
278
|
columns: ["org_id", "factory_project_id"]
|
|
189
279
|
}]
|
|
190
280
|
};
|
|
191
|
-
export { FACTORY_BOARDS_SCHEMA, FACTORY_BOARD_DEFINITION_VERSIONS_SCHEMA, FACTORY_BOARD_PHASES_SCHEMA, FACTORY_INTAKE_ROUTES_SCHEMA, FACTORY_INTAKE_ROUTE_LOCKS_SCHEMA };
|
|
281
|
+
export { FACTORY_BOARDS_SCHEMA, FACTORY_BOARD_DEFINITION_VERSIONS_SCHEMA, FACTORY_BOARD_PHASES_SCHEMA, FACTORY_INTAKE_DECISIONS_SCHEMA, FACTORY_INTAKE_ROUTES_SCHEMA, FACTORY_INTAKE_ROUTE_LOCKS_SCHEMA };
|
|
192
282
|
|
|
193
283
|
//# sourceMappingURL=schemas.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schemas.js","names":[],"sources":["../../../../src/storage/domains/boards/schemas.ts"],"sourcesContent":["import type { CollectionSchema } from '@mastra/core/storage';\n\n/** A project's boards. `board_key` is the id cards reference (`work_items.board`). */\nexport const FACTORY_BOARDS_SCHEMA: CollectionSchema = {\n name: 'factory_boards',\n columns: {\n id: { type: 'uuid-pk' },\n org_id: { type: 'text' },\n factory_project_id: { type: 'text' },\n board_key: { type: 'text' },\n name: { type: 'text' },\n description: { type: 'text', nullable: true },\n position: { type: 'integer' },\n // Rises on every write to the board or its phases; the compare-and-set token for edits.\n revision: { type: 'integer' },\n created_by: { type: 'text' },\n created_at: { type: 'timestamp' },\n updated_by: { type: 'text' },\n updated_at: { type: 'timestamp' },\n },\n uniqueIndexes: [{ name: 'factory_boards_project_key', columns: ['org_id', 'factory_project_id', 'board_key'] }],\n indexes: [{ name: 'factory_boards_project', columns: ['org_id', 'factory_project_id'] }],\n};\n\n/** A board's ordered phases. `phase_key` is the stage id cards sit in. */\nexport const FACTORY_BOARD_PHASES_SCHEMA: CollectionSchema = {\n name: 'factory_board_phases',\n columns: {\n id: { type: 'uuid-pk' },\n org_id: { type: 'text' },\n factory_project_id: { type: 'text' },\n board_key: { type: 'text' },\n phase_key: { type: 'text' },\n position: { type: 'integer' },\n name: { type: 'text' },\n description: { type: 'text', nullable: true },\n kind: { type: 'text' },\n // { skill?, context?, instructions? }; room for other runner types later.\n runner: { type: 'json', nullable: true },\n next_phases: { type: 'json', nullable: true },\n auto_start: { type: 'boolean', default: false },\n auto_start_when: { type: 'json', nullable: true },\n exit_tool: { type: 'json', nullable: true },\n // Factory tools the phase grants the session working the card there, e.g. [\"factory_record_review_verdict\"].\n tools: { type: 'json', nullable: true },\n },\n uniqueIndexes: [\n {\n name: 'factory_board_phases_project_board_phase',\n columns: ['org_id', 'factory_project_id', 'board_key', 'phase_key'],\n },\n ],\n indexes: [{ name: 'factory_board_phases_project', columns: ['org_id', 'factory_project_id'] }],\n};\n\n/** A project's ordered intake routes: where new cards matching `when_condition` land. */\nexport const FACTORY_INTAKE_ROUTES_SCHEMA: CollectionSchema = {\n name: 'factory_intake_routes',\n columns: {\n id: { type: 'uuid-pk' },\n org_id: { type: 'text' },\n factory_project_id: { type: 'text' },\n name: { type: 'text' },\n enabled: { type: 'boolean', default: true },\n position: { type: 'integer' },\n // A card RuleGroup; null matches every card. Not named `when`, which is an SQL keyword.\n when_condition: { type: 'json', nullable: true },\n board_key: { type: 'text' },\n // Null lands the card in the board's first phase.\n phase_key: { type: 'text', nullable: true },\n // The status events the route handles (`StatusEvent`s). Null on rows written before routes named\n // events: those place new cards, as `['work_item.created']`.\n on_events: { type: 'json', nullable: true },\n // No longer read or written: a route moves a card into any phase. Kept so existing tables match.\n allow_working_phase: { type: 'boolean', nullable: true },\n // True files a pull request on the card of the issue it closes instead of a new card. Null on rows written before it.\n join_closed_issue: { type: 'boolean', nullable: true },\n // Rises on every write to the route, including a move; the compare-and-set token for edits.\n revision: { type: 'integer' },\n created_by: { type: 'text' },\n created_at: { type: 'timestamp' },\n updated_by: { type: 'text' },\n updated_at: { type: 'timestamp' },\n },\n uniqueIndexes: [\n { name: 'factory_intake_routes_project_position', columns: ['org_id', 'factory_project_id', 'position'] },\n ],\n indexes: [{ name: 'factory_intake_routes_project', columns: ['org_id', 'factory_project_id'] }],\n};\n\n/**\n * One row per project that every write adding, deleting or moving intake routes upserts first,\n * inside its transaction. The upsert holds the row until commit, so those writes on one project\n * run one after another and positions stay 0..n-1 with no gaps.\n */\nexport const FACTORY_INTAKE_ROUTE_LOCKS_SCHEMA: CollectionSchema = {\n name: 'factory_intake_route_locks',\n columns: {\n id: { type: 'uuid-pk' },\n org_id: { type: 'text' },\n factory_project_id: { type: 'text' },\n locked_at: { type: 'timestamp' },\n // Keys of the default routes Factory added to the project (`DEFAULT_INTAKE_ROUTES`), so each is\n // added once. Null on rows written before the list: those projects got `outside-authors`.\n seeded_defaults: { type: 'json', nullable: true },\n },\n uniqueIndexes: [{ name: 'factory_intake_route_locks_project', columns: ['org_id', 'factory_project_id'] }],\n};\n\n/**\n * One row per project whose `version` is replaced inside every board write, so other replicas\n * can tell their cached boards are stale with one indexed read.\n */\nexport const FACTORY_BOARD_DEFINITION_VERSIONS_SCHEMA: CollectionSchema = {\n name: 'factory_board_definition_versions',\n columns: {\n id: { type: 'uuid-pk' },\n org_id: { type: 'text' },\n factory_project_id: { type: 'text' },\n version: { type: 'text' },\n updated_at: { type: 'timestamp' },\n // Keys of the boards Factory stored in the project (Work, app and seed boards); each is stored\n // once, so one the project deleted stays deleted. Null on projects stored before the list.\n seeded_boards: { type: 'json', nullable: true },\n // Keys of the board migrations applied to the project, so each runs once: a field a user\n // later sets back to an old default is never rewritten again. Null before the first one.\n applied_migrations: { type: 'json', nullable: true },\n },\n uniqueIndexes: [{ name: 'factory_board_definition_versions_project', columns: ['org_id', 'factory_project_id'] }],\n};\n"],"mappings":";;AAGA,MAAa,wBAA0C;CACrD,MAAM;CACN,SAAS;EACP,IAAI,EAAE,MAAM,UAAU;EACtB,QAAQ,EAAE,MAAM,OAAO;EACvB,oBAAoB,EAAE,MAAM,OAAO;EACnC,WAAW,EAAE,MAAM,OAAO;EAC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EACnC,SAAS,EAAE,MAAM,OAAO;EACxB,YAAY,EAAE,MAAM,YAAY;EAGhC,eAAe;GAAE,MAAM;GAAQ,UAAU;EAAK;EAG9C,oBAAoB;GAAE,MAAM;GAAQ,UAAU;EAAK;CACrD;CACA,eAAe,CAAC;EAAE,MAAM;EAA6C,SAAS,CAAC,UAAU,oBAAoB;CAAE,CAAC;AAClH"}
|
|
1
|
+
{"version":3,"file":"schemas.js","names":[],"sources":["../../../../src/storage/domains/boards/schemas.ts"],"sourcesContent":["import type { CollectionSchema } from '@mastra/core/storage';\n\n/** A project's boards. `board_key` is the id cards reference (`work_items.board`). */\nexport const FACTORY_BOARDS_SCHEMA: CollectionSchema = {\n name: 'factory_boards',\n columns: {\n id: { type: 'uuid-pk' },\n org_id: { type: 'text' },\n factory_project_id: { type: 'text' },\n board_key: { type: 'text' },\n name: { type: 'text' },\n description: { type: 'text', nullable: true },\n position: { type: 'integer' },\n // Rises on every write to the board or its phases; the compare-and-set token for edits.\n revision: { type: 'integer' },\n created_by: { type: 'text' },\n created_at: { type: 'timestamp' },\n updated_by: { type: 'text' },\n updated_at: { type: 'timestamp' },\n },\n uniqueIndexes: [{ name: 'factory_boards_project_key', columns: ['org_id', 'factory_project_id', 'board_key'] }],\n indexes: [{ name: 'factory_boards_project', columns: ['org_id', 'factory_project_id'] }],\n};\n\n/** A board's ordered phases. `phase_key` is the stage id cards sit in. */\nexport const FACTORY_BOARD_PHASES_SCHEMA: CollectionSchema = {\n name: 'factory_board_phases',\n columns: {\n id: { type: 'uuid-pk' },\n org_id: { type: 'text' },\n factory_project_id: { type: 'text' },\n board_key: { type: 'text' },\n phase_key: { type: 'text' },\n position: { type: 'integer' },\n name: { type: 'text' },\n description: { type: 'text', nullable: true },\n kind: { type: 'text' },\n // { skill?, context?, instructions? }; room for other runner types later.\n runner: { type: 'json', nullable: true },\n next_phases: { type: 'json', nullable: true },\n auto_start: { type: 'boolean', default: false },\n auto_start_when: { type: 'json', nullable: true },\n exit_tool: { type: 'json', nullable: true },\n // Factory tools the phase grants the session working the card there, e.g. [\"factory_record_review_verdict\"].\n tools: { type: 'json', nullable: true },\n },\n uniqueIndexes: [\n {\n name: 'factory_board_phases_project_board_phase',\n columns: ['org_id', 'factory_project_id', 'board_key', 'phase_key'],\n },\n ],\n indexes: [{ name: 'factory_board_phases_project', columns: ['org_id', 'factory_project_id'] }],\n};\n\n/** A project's ordered intake routes: where new cards matching `when_condition` land. */\nexport const FACTORY_INTAKE_ROUTES_SCHEMA: CollectionSchema = {\n name: 'factory_intake_routes',\n columns: {\n id: { type: 'uuid-pk' },\n org_id: { type: 'text' },\n factory_project_id: { type: 'text' },\n name: { type: 'text' },\n enabled: { type: 'boolean', default: true },\n position: { type: 'integer' },\n // A card RuleGroup; null matches every card. Not named `when`, which is an SQL keyword.\n when_condition: { type: 'json', nullable: true },\n board_key: { type: 'text' },\n // Null lands the card in the board's first phase.\n phase_key: { type: 'text', nullable: true },\n // The status events the route handles (`StatusEvent`s). Null on rows written before routes named\n // events: those place new cards, as `['work_item.opened']`.\n on_events: { type: 'json', nullable: true },\n // True files a pull request on the card of the issue it closes instead of a new card. Null on rows written before it.\n join_closed_issue: { type: 'boolean', nullable: true },\n // True on rows written since `pull_request.opened` files pull requests with no card. Null on rows\n // written before (0.28): there `pull_request.opened` only moves a card. Never backfilled.\n opened_files_pull_requests: { type: 'boolean', nullable: true },\n // A card-move route on `board_key` that sends the card to this other board (at `phase_key`). Null keeps it on `board_key`.\n move_to_board_key: { type: 'text', nullable: true },\n // Rises on every write to the route, including a move; the compare-and-set token for edits.\n revision: { type: 'integer' },\n created_by: { type: 'text' },\n created_at: { type: 'timestamp' },\n updated_by: { type: 'text' },\n updated_at: { type: 'timestamp' },\n },\n uniqueIndexes: [\n { name: 'factory_intake_routes_project_position', columns: ['org_id', 'factory_project_id', 'position'] },\n ],\n indexes: [{ name: 'factory_intake_routes_project', columns: ['org_id', 'factory_project_id'] }],\n};\n\n/**\n * One row per project that every write adding, deleting or moving intake routes upserts first,\n * inside its transaction. The upsert holds the row until commit, so those writes on one project\n * run one after another and positions stay 0..n-1 with no gaps.\n */\nexport const FACTORY_INTAKE_ROUTE_LOCKS_SCHEMA: CollectionSchema = {\n name: 'factory_intake_route_locks',\n columns: {\n id: { type: 'uuid-pk' },\n org_id: { type: 'text' },\n factory_project_id: { type: 'text' },\n locked_at: { type: 'timestamp' },\n // Keys of the default routes Factory added to the project (`DEFAULT_INTAKE_ROUTES`), so each is\n // added once. Null on rows written before the list: those projects got `outside-authors`.\n seeded_defaults: { type: 'json', nullable: true },\n // Board keys in the order intake checks them, separate from the sidebar's `position`. Null\n // until first derived from the route list (`deriveIntakeOrder`).\n intake_order: { type: 'json', nullable: true },\n // 'explicit' once an admin set the order; null while it is derived from the route list, which\n // re-derives it on every rule write.\n intake_order_origin: { type: 'text', nullable: true },\n // Which evaluator places the project's new items: 'intake-order' for projects created since it\n // shipped (stamped with the project), or set by an admin. Null on older projects: 'route-list'.\n intake_evaluator: { type: 'text', nullable: true },\n },\n uniqueIndexes: [{ name: 'factory_intake_route_locks_project', columns: ['org_id', 'factory_project_id'] }],\n};\n\n/**\n * One row per arrival intake decided on, keyed by the arrival's decision, so a redelivery updates\n * it instead of adding another. A `not_routed` row is an item no board took; it holds the arrival\n * so Route again can file it, and is resolved once a card is filed for its source.\n */\nexport const FACTORY_INTAKE_DECISIONS_SCHEMA: CollectionSchema = {\n name: 'factory_intake_decisions',\n columns: {\n id: { type: 'uuid-pk' },\n org_id: { type: 'text' },\n factory_project_id: { type: 'text' },\n idempotency_key: { type: 'text' },\n outcome: { type: 'text' },\n evaluator: { type: 'text' },\n board_key: { type: 'text', nullable: true },\n route_id: { type: 'text', nullable: true },\n reason: { type: 'text', nullable: true },\n source_key: { type: 'text', nullable: true },\n title: { type: 'text' },\n url: { type: 'text', nullable: true },\n // The `upsertLinkedWorkItem` decision as it arrived; Route again files it.\n arrival: { type: 'json', nullable: true },\n decided_at: { type: 'timestamp' },\n resolved_at: { type: 'timestamp', nullable: true },\n resolved_by: { type: 'text', nullable: true },\n },\n uniqueIndexes: [\n { name: 'factory_intake_decisions_key', columns: ['org_id', 'factory_project_id', 'idempotency_key'] },\n ],\n indexes: [\n { name: 'factory_intake_decisions_project', columns: ['org_id', 'factory_project_id', 'outcome', 'decided_at'] },\n { name: 'factory_intake_decisions_source', columns: ['org_id', 'factory_project_id', 'source_key'] },\n ],\n};\n\n/**\n * One row per project whose `version` is replaced inside every board write, so other replicas\n * can tell their cached boards are stale with one indexed read.\n */\nexport const FACTORY_BOARD_DEFINITION_VERSIONS_SCHEMA: CollectionSchema = {\n name: 'factory_board_definition_versions',\n columns: {\n id: { type: 'uuid-pk' },\n org_id: { type: 'text' },\n factory_project_id: { type: 'text' },\n version: { type: 'text' },\n updated_at: { type: 'timestamp' },\n // Keys of the boards Factory stored in the project (Work, app and seed boards); each is stored\n // once, so one the project deleted stays deleted. Null on projects stored before the list.\n seeded_boards: { type: 'json', nullable: true },\n // Keys of the board migrations applied to the project, so each runs once: a field a user\n // later sets back to an old default is never rewritten again. Null before the first one.\n applied_migrations: { type: 'json', nullable: true },\n },\n uniqueIndexes: [{ name: 'factory_board_definition_versions_project', columns: ['org_id', 'factory_project_id'] }],\n};\n"],"mappings":";;AAGA,MAAa,wBAA0C;CACrD,MAAM;CACN,SAAS;EACP,IAAI,EAAE,MAAM,UAAU;EACtB,QAAQ,EAAE,MAAM,OAAO;EACvB,oBAAoB,EAAE,MAAM,OAAO;EACnC,WAAW,EAAE,MAAM,OAAO;EAC1B,MAAM,EAAE,MAAM,OAAO;EACrB,aAAa;GAAE,MAAM;GAAQ,UAAU;EAAK;EAC5C,UAAU,EAAE,MAAM,UAAU;EAE5B,UAAU,EAAE,MAAM,UAAU;EAC5B,YAAY,EAAE,MAAM,OAAO;EAC3B,YAAY,EAAE,MAAM,YAAY;EAChC,YAAY,EAAE,MAAM,OAAO;EAC3B,YAAY,EAAE,MAAM,YAAY;CAClC;CACA,eAAe,CAAC;EAAE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