@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,7 +1,10 @@
|
|
|
1
|
-
import { DEFAULT_ROUTE_EVENTS, routeEventsProblem } from "../../../boards/board-events.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { DEFAULT_ROUTE_EVENTS, arrivalKinds, routeEventsProblem } from "../../../boards/board-events.js";
|
|
2
|
+
import { deriveIntakeOrder, kindsTakenWhole, reconcileIntakeOrder } from "../../../boards/intake-order.js";
|
|
3
|
+
import { CATCH_ALL_INTAKE_ROUTE, CLOSED_CANCELED_ROUTE, CLOSED_COMPLETED_ROUTE, DEFAULT_INTAKE_ROUTE, DEFAULT_INTAKE_ROUTES, LINKED_PULL_REQUEST_ROUTE, LINKED_PULL_REQUEST_ROUTE_KEY, OUTSIDE_PULL_REQUEST_INTAKE_ROUTE, PULL_REQUEST_CLOSED_ISSUE_ROUTE, PULL_REQUEST_CLOSED_ROUTE, PULL_REQUEST_INTAKE_ROUTE, PULL_REQUEST_MERGED_ROUTE, PULL_REQUEST_REVIEW_REQUESTED_ROUTE, PULL_REQUEST_UPDATED_ROUTE, REOPENED_ROUTE, RETIRED_JOIN_ROUTE } from "../../../boards/work-routes.js";
|
|
4
|
+
import { currentRuleGroup } from "../../../rules/rule-group.js";
|
|
5
|
+
import { 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 } from "./schemas.js";
|
|
4
6
|
import { randomUUID } from "crypto";
|
|
7
|
+
import { isDeepStrictEqual } from "util";
|
|
5
8
|
import { FactoryStorageDomain, UniqueViolationError } from "@mastra/core/storage";
|
|
6
9
|
// src/storage/domains/boards/base.ts
|
|
7
10
|
const EMPTY_MIGRATION_CONTEXT = {
|
|
@@ -10,8 +13,8 @@ const EMPTY_MIGRATION_CONTEXT = {
|
|
|
10
13
|
codePhases: () => void 0,
|
|
11
14
|
warn: () => {}
|
|
12
15
|
};
|
|
13
|
-
/** A
|
|
14
|
-
const
|
|
16
|
+
/** A board's most intake routes. */
|
|
17
|
+
const MAX_INTAKE_ROUTES_PER_BOARD = 100;
|
|
15
18
|
/** The defaults a project whose lock row predates `seeded_defaults` was set up with. */
|
|
16
19
|
const ORIGINAL_DEFAULT_KEYS = ["outside-authors"];
|
|
17
20
|
/** Who the default intake routes are created and last updated by. */
|
|
@@ -24,6 +27,26 @@ var StoredBoardError = class extends Error {
|
|
|
24
27
|
this.code = code;
|
|
25
28
|
}
|
|
26
29
|
};
|
|
30
|
+
function toIntakeDecisionRecord(row) {
|
|
31
|
+
return {
|
|
32
|
+
id: row.id,
|
|
33
|
+
orgId: row.org_id,
|
|
34
|
+
factoryProjectId: row.factory_project_id,
|
|
35
|
+
idempotencyKey: row.idempotency_key,
|
|
36
|
+
outcome: row.outcome,
|
|
37
|
+
evaluator: row.evaluator,
|
|
38
|
+
boardKey: row.board_key,
|
|
39
|
+
routeId: row.route_id,
|
|
40
|
+
reason: row.reason,
|
|
41
|
+
sourceKey: row.source_key,
|
|
42
|
+
title: row.title,
|
|
43
|
+
url: row.url,
|
|
44
|
+
arrival: row.arrival,
|
|
45
|
+
decidedAt: row.decided_at,
|
|
46
|
+
resolvedAt: row.resolved_at,
|
|
47
|
+
resolvedBy: row.resolved_by
|
|
48
|
+
};
|
|
49
|
+
}
|
|
27
50
|
function seededDefaults(lock) {
|
|
28
51
|
return lock.seeded_defaults ?? ORIGINAL_DEFAULT_KEYS;
|
|
29
52
|
}
|
|
@@ -36,6 +59,7 @@ const PHASES = "factory_board_phases";
|
|
|
36
59
|
const VERSIONS = "factory_board_definition_versions";
|
|
37
60
|
const INTAKE_ROUTES = "factory_intake_routes";
|
|
38
61
|
const INTAKE_ROUTE_LOCKS = "factory_intake_route_locks";
|
|
62
|
+
const INTAKE_DECISIONS = "factory_intake_decisions";
|
|
39
63
|
const MAX_WRITE_ATTEMPTS = 3;
|
|
40
64
|
const MIGRATION_ACTOR = "factory";
|
|
41
65
|
function scopeWhere({ orgId, factoryProjectId }) {
|
|
@@ -54,8 +78,11 @@ function toPhaseRecord(row) {
|
|
|
54
78
|
runner: row.runner,
|
|
55
79
|
nextPhases: row.next_phases,
|
|
56
80
|
autoStart: row.auto_start,
|
|
57
|
-
autoStartWhen: row.auto_start_when,
|
|
58
|
-
exitTool: row.exit_tool
|
|
81
|
+
autoStartWhen: currentRuleGroup(row.auto_start_when),
|
|
82
|
+
exitTool: row.exit_tool?.autoApproveWhen ? {
|
|
83
|
+
...row.exit_tool,
|
|
84
|
+
autoApproveWhen: currentRuleGroup(row.exit_tool.autoApproveWhen)
|
|
85
|
+
} : row.exit_tool,
|
|
59
86
|
tools: row.tools ?? null
|
|
60
87
|
};
|
|
61
88
|
}
|
|
@@ -93,10 +120,12 @@ var StoredBoardsStorage = class extends FactoryStorageDomain {
|
|
|
93
120
|
FACTORY_BOARD_PHASES_SCHEMA,
|
|
94
121
|
FACTORY_BOARD_DEFINITION_VERSIONS_SCHEMA,
|
|
95
122
|
FACTORY_INTAKE_ROUTES_SCHEMA,
|
|
96
|
-
FACTORY_INTAKE_ROUTE_LOCKS_SCHEMA
|
|
123
|
+
FACTORY_INTAKE_ROUTE_LOCKS_SCHEMA,
|
|
124
|
+
FACTORY_INTAKE_DECISIONS_SCHEMA
|
|
97
125
|
]);
|
|
98
126
|
}
|
|
99
127
|
async dangerouslyClearAll() {
|
|
128
|
+
await this.ops.deleteMany(INTAKE_DECISIONS, {});
|
|
100
129
|
await this.ops.deleteMany(PHASES, {});
|
|
101
130
|
await this.ops.deleteMany(BOARDS, {});
|
|
102
131
|
await this.ops.deleteMany(VERSIONS, {});
|
|
@@ -338,11 +367,16 @@ var StoredBoardsStorage = class extends FactoryStorageDomain {
|
|
|
338
367
|
});
|
|
339
368
|
return await this.get(scope, key);
|
|
340
369
|
}
|
|
341
|
-
/**
|
|
370
|
+
/**
|
|
371
|
+
* Deletes a board, its phases and its intake routes in one transaction, and takes it out of the
|
|
372
|
+
* intake order. Returns the routes it deleted, for the caller to audit.
|
|
373
|
+
*/
|
|
342
374
|
async delete(scope, key, options) {
|
|
343
|
-
await this.#
|
|
375
|
+
await this.#ensureIntakeRoutes(scope);
|
|
376
|
+
return this.#write(scope, async (ops) => {
|
|
344
377
|
const row = await findBoard(ops, scope, key);
|
|
345
378
|
checkRevision(row, key, options.expectedRevision);
|
|
379
|
+
const routes = await lockIntakeRoutes(ops, scope);
|
|
346
380
|
if (await ops.deleteMany(BOARDS, {
|
|
347
381
|
id: row.id,
|
|
348
382
|
revision: row.revision
|
|
@@ -351,16 +385,234 @@ var StoredBoardsStorage = class extends FactoryStorageDomain {
|
|
|
351
385
|
...scopeWhere(scope),
|
|
352
386
|
board_key: key
|
|
353
387
|
});
|
|
388
|
+
const deleted = routes.filter((route) => route.board_key === key);
|
|
389
|
+
if (deleted.length > 0) {
|
|
390
|
+
await ops.deleteMany(INTAKE_ROUTES, {
|
|
391
|
+
...scopeWhere(scope),
|
|
392
|
+
board_key: key
|
|
393
|
+
});
|
|
394
|
+
await placeIntakeRoutes(ops, routes.filter((route) => route.board_key !== key));
|
|
395
|
+
await forgetDerivedIntakeOrder(ops, scope);
|
|
396
|
+
}
|
|
397
|
+
const lock = await ops.findOne(INTAKE_ROUTE_LOCKS, scopeWhere(scope));
|
|
398
|
+
if (lock.intake_order?.includes(key)) await ops.updateMany(INTAKE_ROUTE_LOCKS, scopeWhere(scope), { intake_order: lock.intake_order.filter((other) => other !== key) });
|
|
354
399
|
return {
|
|
355
|
-
result:
|
|
400
|
+
result: { intakeRoutes: deleted.map(toIntakeRouteRecord) },
|
|
356
401
|
changed: true
|
|
357
402
|
};
|
|
358
403
|
});
|
|
359
404
|
}
|
|
360
|
-
/**
|
|
361
|
-
|
|
405
|
+
/**
|
|
406
|
+
* The project's intake routes in the order they are tried, or one board's list when `boardKey`
|
|
407
|
+
* is set; Factory's `DEFAULT_INTAKE_ROUTES` are added once each.
|
|
408
|
+
*/
|
|
409
|
+
async listIntakeRoutes(scope, options = {}) {
|
|
410
|
+
await this.#ensureIntakeRoutes(scope);
|
|
411
|
+
return (await readIntakeRoutes(this.ops, scope)).filter((row) => options.boardKey === void 0 || row.board_key === options.boardKey).map(toIntakeRouteRecord);
|
|
412
|
+
}
|
|
413
|
+
/**
|
|
414
|
+
* The project's intake order, derived from the route list the first time it is read and kept up
|
|
415
|
+
* to date with its boards (see `reconcileIntakeOrder`), with the migration marker. Its boards are
|
|
416
|
+
* the stored ones plus `options.boards` (the caller's registry, so a code board keeps its place).
|
|
417
|
+
*/
|
|
418
|
+
async readIntakeOrder(scope, options = {}) {
|
|
419
|
+
await this.#ensureIntakeRoutes(scope);
|
|
420
|
+
const current = await this.#intakeOrderState(this.ops, scope, options.boards);
|
|
421
|
+
if (current.lock.intake_order && sameKeys(current.lock.intake_order, current.boardKeys)) return toIntakeOrder(current.lock, current.boardKeys);
|
|
422
|
+
return this.#transact(async (ops) => {
|
|
423
|
+
await lockIntakeRoutes(ops, scope);
|
|
424
|
+
const fresh = await this.#intakeOrderState(ops, scope, options.boards);
|
|
425
|
+
if (!fresh.lock.intake_order || !sameKeys(fresh.lock.intake_order, fresh.boardKeys)) await ops.updateMany(INTAKE_ROUTE_LOCKS, scopeWhere(scope), { intake_order: fresh.boardKeys });
|
|
426
|
+
return toIntakeOrder(fresh.lock, fresh.boardKeys);
|
|
427
|
+
});
|
|
428
|
+
}
|
|
429
|
+
/**
|
|
430
|
+
* Sets the project's intake order, which then no longer follows the route list; `boardKeys` must
|
|
431
|
+
* name every board of the project exactly once: its stored boards, or `options.boards` when given
|
|
432
|
+
* (the caller's registry, code boards too).
|
|
433
|
+
*/
|
|
434
|
+
async setIntakeOrder(scope, boardKeys, options = {}) {
|
|
435
|
+
await this.#ensureIntakeRoutes(scope);
|
|
436
|
+
return this.#transact(async (ops) => {
|
|
437
|
+
await lockIntakeRoutes(ops, scope);
|
|
438
|
+
const keys = new Set(options.boards ?? (await ops.findMany(BOARDS, scopeWhere(scope))).map((board) => board.board_key));
|
|
439
|
+
if (boardKeys.length !== keys.size || new Set(boardKeys).size !== boardKeys.length || boardKeys.some((key) => !keys.has(key))) throw new StoredBoardError("intake_order_set_mismatch", "The intake order must list every board of the project exactly once; reload the boards and try again.");
|
|
440
|
+
await ops.updateMany(INTAKE_ROUTE_LOCKS, scopeWhere(scope), {
|
|
441
|
+
intake_order: boardKeys,
|
|
442
|
+
intake_order_origin: "explicit"
|
|
443
|
+
});
|
|
444
|
+
return toIntakeOrder(await ops.findOne(INTAKE_ROUTE_LOCKS, scopeWhere(scope)), boardKeys);
|
|
445
|
+
});
|
|
446
|
+
}
|
|
447
|
+
/** The project's own evaluator; null for a project created before the setting, which uses `route-list`. */
|
|
448
|
+
async intakeEvaluator(scope) {
|
|
449
|
+
return (await this.ops.findOne(INTAKE_ROUTE_LOCKS, scopeWhere(scope)))?.intake_evaluator ?? null;
|
|
450
|
+
}
|
|
451
|
+
/** Switches the project's evaluator; returns the setting it had (null: none). */
|
|
452
|
+
async setIntakeEvaluator(scope, evaluator) {
|
|
362
453
|
await this.#ensureIntakeRoutes(scope);
|
|
363
|
-
return (
|
|
454
|
+
return this.#transact(async (ops) => {
|
|
455
|
+
await lockIntakeRoutes(ops, scope);
|
|
456
|
+
const lock = await ops.findOne(INTAKE_ROUTE_LOCKS, scopeWhere(scope));
|
|
457
|
+
await ops.updateMany(INTAKE_ROUTE_LOCKS, scopeWhere(scope), { intake_evaluator: evaluator });
|
|
458
|
+
return lock.intake_evaluator ?? null;
|
|
459
|
+
});
|
|
460
|
+
}
|
|
461
|
+
/** Records how intake decided an arrival; a redelivery under the same key replaces the row. */
|
|
462
|
+
async recordIntakeDecision(scope, input, now = /* @__PURE__ */ new Date()) {
|
|
463
|
+
return toIntakeDecisionRecord(await this.ops.upsertOne(INTAKE_DECISIONS, [
|
|
464
|
+
"org_id",
|
|
465
|
+
"factory_project_id",
|
|
466
|
+
"idempotency_key"
|
|
467
|
+
], {
|
|
468
|
+
...scopeWhere(scope),
|
|
469
|
+
idempotency_key: input.idempotencyKey,
|
|
470
|
+
outcome: input.outcome,
|
|
471
|
+
evaluator: input.evaluator,
|
|
472
|
+
board_key: input.boardKey ?? null,
|
|
473
|
+
route_id: input.routeId ?? null,
|
|
474
|
+
reason: input.reason ?? null,
|
|
475
|
+
source_key: input.sourceKey ?? null,
|
|
476
|
+
title: input.title,
|
|
477
|
+
url: input.url ?? null,
|
|
478
|
+
arrival: input.arrival ?? null,
|
|
479
|
+
decided_at: now,
|
|
480
|
+
resolved_at: null,
|
|
481
|
+
resolved_by: null
|
|
482
|
+
}));
|
|
483
|
+
}
|
|
484
|
+
async getIntakeDecision(scope, id) {
|
|
485
|
+
const row = await this.ops.findOne(INTAKE_DECISIONS, {
|
|
486
|
+
...scopeWhere(scope),
|
|
487
|
+
id
|
|
488
|
+
});
|
|
489
|
+
return row ? toIntakeDecisionRecord(row) : null;
|
|
490
|
+
}
|
|
491
|
+
/**
|
|
492
|
+
* Items no board took and nobody has filed since, oldest first, `limit` at a time; pass
|
|
493
|
+
* `nextCursor` back as `cursor` for the next page.
|
|
494
|
+
*/
|
|
495
|
+
async listNotRouted(scope, options = {}) {
|
|
496
|
+
const limit = options.limit ?? 50;
|
|
497
|
+
const after = options.cursor === void 0 ? void 0 : decodeDecisionCursor(options.cursor);
|
|
498
|
+
const rows = await this.ops.findMany(INTAKE_DECISIONS, {
|
|
499
|
+
...scopeWhere(scope),
|
|
500
|
+
outcome: "not_routed",
|
|
501
|
+
resolved_at: null
|
|
502
|
+
}, {
|
|
503
|
+
orderBy: DECISION_ORDER,
|
|
504
|
+
limit: limit + 1,
|
|
505
|
+
...after && { cursor: { values: [after.decidedAt, after.id] } }
|
|
506
|
+
});
|
|
507
|
+
const page = rows.slice(0, limit).map(toIntakeDecisionRecord);
|
|
508
|
+
const last = page.at(-1);
|
|
509
|
+
return {
|
|
510
|
+
notRouted: page,
|
|
511
|
+
nextCursor: rows.length > limit && last ? `${last.decidedAt.toISOString()}_${last.id}` : null
|
|
512
|
+
};
|
|
513
|
+
}
|
|
514
|
+
/** Whether intake turned the source away (Not routed) and nobody has filed it since. */
|
|
515
|
+
async isNotRouted(scope, sourceKey) {
|
|
516
|
+
return await this.ops.findOne(INTAKE_DECISIONS, {
|
|
517
|
+
...scopeWhere(scope),
|
|
518
|
+
outcome: "not_routed",
|
|
519
|
+
source_key: sourceKey,
|
|
520
|
+
resolved_at: null
|
|
521
|
+
}) !== null;
|
|
522
|
+
}
|
|
523
|
+
/** The newest `limit` items no board took and nobody has filed since, newest first. */
|
|
524
|
+
async listRecentNotRouted(scope, limit) {
|
|
525
|
+
return (await this.ops.findMany(INTAKE_DECISIONS, {
|
|
526
|
+
...scopeWhere(scope),
|
|
527
|
+
outcome: "not_routed",
|
|
528
|
+
resolved_at: null
|
|
529
|
+
}, {
|
|
530
|
+
orderBy: NEWEST_DECISION_ORDER,
|
|
531
|
+
limit
|
|
532
|
+
})).map(toIntakeDecisionRecord);
|
|
533
|
+
}
|
|
534
|
+
/**
|
|
535
|
+
* How many items each intake rule placed since `since`, keyed by rule id. Reads placed rows
|
|
536
|
+
* newest first, a page at a time, and stops at the first one older than `since`.
|
|
537
|
+
*/
|
|
538
|
+
async countPlacedByRoute(scope, since, options = {}) {
|
|
539
|
+
const pageSize = options.pageSize ?? 500;
|
|
540
|
+
const counts = {};
|
|
541
|
+
let cursor;
|
|
542
|
+
for (;;) {
|
|
543
|
+
const rows = await this.ops.findMany(INTAKE_DECISIONS, {
|
|
544
|
+
...scopeWhere(scope),
|
|
545
|
+
outcome: "placed"
|
|
546
|
+
}, {
|
|
547
|
+
orderBy: NEWEST_DECISION_ORDER,
|
|
548
|
+
limit: pageSize,
|
|
549
|
+
...cursor && { cursor: { values: [cursor.decided_at, cursor.id] } }
|
|
550
|
+
});
|
|
551
|
+
for (const row of rows) {
|
|
552
|
+
if (row.decided_at < since) return counts;
|
|
553
|
+
if (row.route_id) counts[row.route_id] = (counts[row.route_id] ?? 0) + 1;
|
|
554
|
+
}
|
|
555
|
+
if (rows.length < pageSize) return counts;
|
|
556
|
+
cursor = rows.at(-1);
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
/**
|
|
560
|
+
* How often each card-move rule was skipped since `since`, with its newest skip, keyed by rule id.
|
|
561
|
+
* Reads skipped rows newest first, a page at a time, and stops at the first one older than `since`.
|
|
562
|
+
*/
|
|
563
|
+
async summarizeSkippedByRoute(scope, since, options = {}) {
|
|
564
|
+
const pageSize = options.pageSize ?? 500;
|
|
565
|
+
const summary = {};
|
|
566
|
+
let cursor;
|
|
567
|
+
for (;;) {
|
|
568
|
+
const rows = await this.ops.findMany(INTAKE_DECISIONS, {
|
|
569
|
+
...scopeWhere(scope),
|
|
570
|
+
outcome: "rule_skipped"
|
|
571
|
+
}, {
|
|
572
|
+
orderBy: NEWEST_DECISION_ORDER,
|
|
573
|
+
limit: pageSize,
|
|
574
|
+
...cursor && { cursor: { values: [cursor.decided_at, cursor.id] } }
|
|
575
|
+
});
|
|
576
|
+
for (const row of rows) {
|
|
577
|
+
if (row.decided_at < since) return summary;
|
|
578
|
+
if (!row.route_id) continue;
|
|
579
|
+
const seen = summary[row.route_id];
|
|
580
|
+
if (seen) seen.count += 1;
|
|
581
|
+
else summary[row.route_id] = {
|
|
582
|
+
count: 1,
|
|
583
|
+
latest: toIntakeDecisionRecord(row)
|
|
584
|
+
};
|
|
585
|
+
}
|
|
586
|
+
if (rows.length < pageSize) return summary;
|
|
587
|
+
cursor = rows.at(-1);
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
/** Marks the Not routed rows for a source resolved once a card is filed for it. Returns how many. */
|
|
591
|
+
async resolveNotRouted(scope, sourceKey, by, now = /* @__PURE__ */ new Date()) {
|
|
592
|
+
return this.ops.updateMany(INTAKE_DECISIONS, {
|
|
593
|
+
...scopeWhere(scope),
|
|
594
|
+
outcome: "not_routed",
|
|
595
|
+
source_key: sourceKey,
|
|
596
|
+
resolved_at: null
|
|
597
|
+
}, {
|
|
598
|
+
resolved_at: now,
|
|
599
|
+
resolved_by: by
|
|
600
|
+
});
|
|
601
|
+
}
|
|
602
|
+
async #intakeOrderState(ops, scope, extra = []) {
|
|
603
|
+
const [lock, boards, routes] = await Promise.all([
|
|
604
|
+
ops.findOne(INTAKE_ROUTE_LOCKS, scopeWhere(scope)),
|
|
605
|
+
ops.findMany(BOARDS, scopeWhere(scope)),
|
|
606
|
+
readIntakeRoutes(ops, scope)
|
|
607
|
+
]);
|
|
608
|
+
const sidebar = boards.sort((left, right) => left.position - right.position || left.board_key.localeCompare(right.board_key)).map((board) => board.board_key);
|
|
609
|
+
sidebar.push(...extra.filter((key) => !sidebar.includes(key)));
|
|
610
|
+
const records = routes.map(toIntakeRouteRecord);
|
|
611
|
+
const stored = lock.intake_order ?? deriveIntakeOrder(records, sidebar);
|
|
612
|
+
return {
|
|
613
|
+
lock,
|
|
614
|
+
boardKeys: reconcileIntakeOrder(stored, sidebar, records)
|
|
615
|
+
};
|
|
364
616
|
}
|
|
365
617
|
async getIntakeRoute(scope, id) {
|
|
366
618
|
const row = await this.ops.findOne(INTAKE_ROUTES, {
|
|
@@ -379,7 +631,7 @@ var StoredBoardsStorage = class extends FactoryStorageDomain {
|
|
|
379
631
|
await this.#ensureIntakeRoutes(scope);
|
|
380
632
|
await this.#transact(async (ops) => {
|
|
381
633
|
const rows = await lockIntakeRoutes(ops, scope);
|
|
382
|
-
if (rows.
|
|
634
|
+
if (boardRouteCount(rows, input.target.boardKey) >= 100) throw new StoredBoardError("intake_route_limit", `A board can have at most 100 intake rules; delete one first.`);
|
|
383
635
|
const position = rows.reduce((max, row) => Math.max(max, row.position), -1) + 1;
|
|
384
636
|
await insertIntakeRoute(ops, scope, {
|
|
385
637
|
id,
|
|
@@ -387,7 +639,12 @@ var StoredBoardsStorage = class extends FactoryStorageDomain {
|
|
|
387
639
|
position,
|
|
388
640
|
actor
|
|
389
641
|
});
|
|
390
|
-
|
|
642
|
+
await forgetDerivedIntakeOrder(ops, scope);
|
|
643
|
+
const catchAlls = [...arrivalKinds({
|
|
644
|
+
on: input.on ?? DEFAULT_ROUTE_EVENTS,
|
|
645
|
+
...input.pullRequestOpenedMovesOnly && { pullRequestOpenedMovesOnly: true }
|
|
646
|
+
})].map((kind) => rows.findIndex((row) => catchesEveryNewCard(row, kind)));
|
|
647
|
+
const ahead = catchAlls.length > 0 && !catchAlls.includes(-1) ? Math.max(...catchAlls) : -1;
|
|
391
648
|
if (ahead >= 0) {
|
|
392
649
|
const added = (await readIntakeRoutes(ops, scope)).find((row) => row.id === id);
|
|
393
650
|
await placeIntakeRoutes(ops, rows.toSpliced(ahead, 0, added), actor);
|
|
@@ -398,8 +655,12 @@ var StoredBoardsStorage = class extends FactoryStorageDomain {
|
|
|
398
655
|
/** Changes the fields `patch` names; the route keeps its place in the order. */
|
|
399
656
|
async updateIntakeRoute(scope, id, patch, options) {
|
|
400
657
|
await this.#transact(async (ops) => {
|
|
401
|
-
const
|
|
658
|
+
const rows = await lockIntakeRoutes(ops, scope);
|
|
659
|
+
const row = rows.find((route) => route.id === id);
|
|
660
|
+
if (!row) throw intakeRouteNotFound(id);
|
|
402
661
|
checkIntakeRouteRevision(row, options.expectedRevision);
|
|
662
|
+
const boardKey = patch.target?.boardKey;
|
|
663
|
+
if (boardKey !== void 0 && boardKey !== row.board_key && boardRouteCount(rows, boardKey) >= 100) throw new StoredBoardError("intake_route_limit", `A board can have at most 100 intake rules; delete one first.`);
|
|
403
664
|
checkRouteEvents(patch.on ?? routeEvents(row), patch.when !== void 0 ? patch.when : row.when_condition);
|
|
404
665
|
await updateIntakeRouteRow(ops, row, {
|
|
405
666
|
...patch.on !== void 0 && { on_events: patch.on },
|
|
@@ -409,10 +670,12 @@ var StoredBoardsStorage = class extends FactoryStorageDomain {
|
|
|
409
670
|
...patch.target !== void 0 && {
|
|
410
671
|
board_key: patch.target.boardKey,
|
|
411
672
|
phase_key: patch.target.phaseKey ?? null,
|
|
412
|
-
join_closed_issue: patch.target.joinClosedIssue ?? false
|
|
673
|
+
join_closed_issue: patch.target.joinClosedIssue ?? false,
|
|
674
|
+
move_to_board_key: patch.target.moveToBoardKey ?? null
|
|
413
675
|
},
|
|
414
676
|
updated_by: options.actor
|
|
415
677
|
});
|
|
678
|
+
await forgetDerivedIntakeOrder(ops, scope);
|
|
416
679
|
});
|
|
417
680
|
return await this.getIntakeRoute(scope, id);
|
|
418
681
|
}
|
|
@@ -429,18 +692,27 @@ var StoredBoardsStorage = class extends FactoryStorageDomain {
|
|
|
429
692
|
revision: row.revision
|
|
430
693
|
}) === 0) throw new ConcurrentBoardWrite();
|
|
431
694
|
await placeIntakeRoutes(ops, rows.filter((route) => route.id !== row.id));
|
|
695
|
+
await forgetDerivedIntakeOrder(ops, scope);
|
|
432
696
|
});
|
|
433
697
|
}
|
|
434
|
-
/**
|
|
435
|
-
|
|
698
|
+
/**
|
|
699
|
+
* Puts the project's routes in the order of `ids`, which must name every route exactly once. With
|
|
700
|
+
* `boardKey`, `ids` names every route of that board instead: they trade the places the board's
|
|
701
|
+
* routes hold, and every other board's routes keep theirs. Returns the routes reordered.
|
|
702
|
+
*/
|
|
703
|
+
async reorderIntakeRoutes(scope, ids, actor, options = {}) {
|
|
704
|
+
const { boardKey } = options;
|
|
436
705
|
await this.#ensureIntakeRoutes(scope);
|
|
437
706
|
await this.#transact(async (ops) => {
|
|
438
707
|
const rows = await lockIntakeRoutes(ops, scope);
|
|
439
|
-
const
|
|
440
|
-
|
|
441
|
-
|
|
708
|
+
const scoped = boardKey === void 0 ? rows : rows.filter((row) => row.board_key === boardKey);
|
|
709
|
+
const byId = new Map(scoped.map((row) => [row.id, row]));
|
|
710
|
+
if (ids.length !== scoped.length || new Set(ids).size !== ids.length || ids.some((id) => !byId.has(id))) throw new StoredBoardError("intake_route_set_mismatch", boardKey === void 0 ? "The order must list every intake route of the project exactly once; reload the routes and try again." : `The order must list every intake rule of board "${boardKey}" exactly once; reload the rules and try again.`);
|
|
711
|
+
const queue = ids.map((id) => byId.get(id));
|
|
712
|
+
await placeIntakeRoutes(ops, boardKey === void 0 ? queue : rows.map((row) => row.board_key === boardKey ? queue.shift() : row), actor);
|
|
713
|
+
await forgetDerivedIntakeOrder(ops, scope);
|
|
442
714
|
});
|
|
443
|
-
return this.listIntakeRoutes(scope);
|
|
715
|
+
return this.listIntakeRoutes(scope, { boardKey });
|
|
444
716
|
}
|
|
445
717
|
/**
|
|
446
718
|
* Creates the project's route lock row (see `FACTORY_INTAKE_ROUTE_LOCKS_SCHEMA`) and adds each of
|
|
@@ -462,10 +734,45 @@ var StoredBoardsStorage = class extends FactoryStorageDomain {
|
|
|
462
734
|
const missing = missingDefaults(current);
|
|
463
735
|
if (missing.length === 0) return;
|
|
464
736
|
const rows = await readIntakeRoutes(ops, scope);
|
|
737
|
+
const retired = /* @__PURE__ */ new Set();
|
|
738
|
+
if (missing.some(({ key }) => key === "linked-pull-request")) for (const row of rows) {
|
|
739
|
+
if (!row.join_closed_issue || !row.enabled) continue;
|
|
740
|
+
await updateIntakeRouteRow(ops, row, {
|
|
741
|
+
enabled: false,
|
|
742
|
+
updated_by: DEFAULT_INTAKE_ROUTE_ACTOR
|
|
743
|
+
});
|
|
744
|
+
retired.add(row.id);
|
|
745
|
+
if (isShippedJoinRoute(row)) continue;
|
|
746
|
+
await ops.upsertOne(INTAKE_DECISIONS, [
|
|
747
|
+
"org_id",
|
|
748
|
+
"factory_project_id",
|
|
749
|
+
"idempotency_key"
|
|
750
|
+
], {
|
|
751
|
+
...scopeWhere(scope),
|
|
752
|
+
idempotency_key: `rule-retired:${row.id}`,
|
|
753
|
+
outcome: "rule_retired",
|
|
754
|
+
evaluator: current.intake_evaluator ?? "route-list",
|
|
755
|
+
board_key: row.board_key,
|
|
756
|
+
route_id: row.id,
|
|
757
|
+
reason: "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.",
|
|
758
|
+
source_key: null,
|
|
759
|
+
title: row.name,
|
|
760
|
+
url: null,
|
|
761
|
+
arrival: null,
|
|
762
|
+
decided_at: /* @__PURE__ */ new Date(),
|
|
763
|
+
resolved_at: null,
|
|
764
|
+
resolved_by: null
|
|
765
|
+
});
|
|
766
|
+
}
|
|
465
767
|
let position = rows.reduce((max, row) => Math.max(max, row.position), -1) + 1;
|
|
466
768
|
const first = [];
|
|
467
|
-
|
|
468
|
-
|
|
769
|
+
const perBoard = /* @__PURE__ */ new Map();
|
|
770
|
+
const newProject = seededDefaults(current).length === 0;
|
|
771
|
+
for (const { key, route, first: leads, newProjectsOnly } of missing) {
|
|
772
|
+
if (newProjectsOnly && !newProject) continue;
|
|
773
|
+
const count = perBoard.get(route.target.boardKey) ?? boardRouteCount(key === "linked-pull-request" ? rows.filter((row) => !retired.has(row.id)) : rows, route.target.boardKey);
|
|
774
|
+
if (count >= 100) continue;
|
|
775
|
+
perBoard.set(route.target.boardKey, count + 1);
|
|
469
776
|
const id = randomUUID();
|
|
470
777
|
await insertIntakeRoute(ops, scope, {
|
|
471
778
|
id,
|
|
@@ -630,8 +937,20 @@ async function writeBoard(ops, scope, row, input, actor) {
|
|
|
630
937
|
key: row.board_key
|
|
631
938
|
});
|
|
632
939
|
}
|
|
940
|
+
/**
|
|
941
|
+
* A row's events as stored. One written before routes named events has none: it reads as the legacy
|
|
942
|
+
* `work_item.created`, filing issues and pull requests alike, as it always has (rows are never rewritten).
|
|
943
|
+
*/
|
|
633
944
|
function routeEvents(row) {
|
|
634
|
-
return row.on_events
|
|
945
|
+
return row.on_events ? [...row.on_events] : [...DEFAULT_ROUTE_EVENTS];
|
|
946
|
+
}
|
|
947
|
+
/** A row's events with what they mean on it: `pull_request.opened` only moves a card on a row from before it filed. */
|
|
948
|
+
function routeArrivals(row) {
|
|
949
|
+
const on = routeEvents(row);
|
|
950
|
+
return {
|
|
951
|
+
on,
|
|
952
|
+
pullRequestOpenedMovesOnly: row.opened_files_pull_requests !== true && on.includes("pull_request.opened")
|
|
953
|
+
};
|
|
635
954
|
}
|
|
636
955
|
function checkRouteEvents(on, when) {
|
|
637
956
|
const problem = routeEventsProblem(on, when);
|
|
@@ -645,13 +964,15 @@ function toIntakeRouteRecord(row) {
|
|
|
645
964
|
name: row.name,
|
|
646
965
|
enabled: row.enabled,
|
|
647
966
|
position: row.position,
|
|
648
|
-
when: row.when_condition,
|
|
967
|
+
when: currentRuleGroup(row.when_condition),
|
|
649
968
|
target: {
|
|
650
969
|
boardKey: row.board_key,
|
|
651
970
|
phaseKey: row.phase_key,
|
|
652
|
-
joinClosedIssue: row.join_closed_issue === true
|
|
971
|
+
joinClosedIssue: row.join_closed_issue === true,
|
|
972
|
+
moveToBoardKey: row.move_to_board_key ?? null
|
|
653
973
|
},
|
|
654
974
|
on: routeEvents(row),
|
|
975
|
+
...routeArrivals(row).pullRequestOpenedMovesOnly && { pullRequestOpenedMovesOnly: true },
|
|
655
976
|
revision: row.revision,
|
|
656
977
|
createdBy: row.created_by,
|
|
657
978
|
createdAt: row.created_at,
|
|
@@ -659,20 +980,71 @@ function toIntakeRouteRecord(row) {
|
|
|
659
980
|
updatedAt: row.updated_at
|
|
660
981
|
};
|
|
661
982
|
}
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
983
|
+
const DECISION_ORDER = [["decided_at", "asc"], ["id", "asc"]];
|
|
984
|
+
const NEWEST_DECISION_ORDER = [["decided_at", "desc"], ["id", "desc"]];
|
|
985
|
+
function decodeDecisionCursor(cursor) {
|
|
986
|
+
const sep = cursor.lastIndexOf("_");
|
|
987
|
+
const decidedAt = new Date(cursor.slice(0, sep));
|
|
988
|
+
const id = cursor.slice(sep + 1);
|
|
989
|
+
if (sep <= 0 || Number.isNaN(decidedAt.getTime()) || !id) throw new StoredBoardError("invalid_intake_cursor", "The cursor is not one this list returned.");
|
|
990
|
+
return {
|
|
991
|
+
decidedAt,
|
|
992
|
+
id
|
|
993
|
+
};
|
|
668
994
|
}
|
|
669
|
-
|
|
670
|
-
|
|
995
|
+
/**
|
|
996
|
+
* Stamps a project being created with the `intake-order` evaluator, through `ops`, the creating
|
|
997
|
+
* transaction's, so the project and its setting commit together. A new project has no lock row yet;
|
|
998
|
+
* its first intake read adds the default routes to this one. Its intake order is its own from the
|
|
999
|
+
* start (`explicit`, empty): deriving one from the route list is for projects that had one before,
|
|
1000
|
+
* and would keep Work, whose defaults lead the list, ahead of every board added later. Each board
|
|
1001
|
+
* slots in as it comes, just above the first board that takes every new card.
|
|
1002
|
+
*/
|
|
1003
|
+
async function stampNewProjectIntake(ops, scope) {
|
|
1004
|
+
await ops.insertOne(INTAKE_ROUTE_LOCKS, {
|
|
671
1005
|
...scopeWhere(scope),
|
|
672
|
-
|
|
1006
|
+
locked_at: /* @__PURE__ */ new Date(),
|
|
1007
|
+
seeded_defaults: [],
|
|
1008
|
+
intake_order: [],
|
|
1009
|
+
intake_order_origin: "explicit",
|
|
1010
|
+
intake_evaluator: "intake-order"
|
|
673
1011
|
});
|
|
674
|
-
|
|
675
|
-
|
|
1012
|
+
}
|
|
1013
|
+
function toIntakeOrder(lock, boardKeys) {
|
|
1014
|
+
return {
|
|
1015
|
+
boardKeys,
|
|
1016
|
+
origin: lock.intake_order_origin ?? "derived"
|
|
1017
|
+
};
|
|
1018
|
+
}
|
|
1019
|
+
/**
|
|
1020
|
+
* A rule write changes what a derived order would be: drop it, so the next read derives it afresh.
|
|
1021
|
+
* An order an admin set stays.
|
|
1022
|
+
*/
|
|
1023
|
+
async function forgetDerivedIntakeOrder(ops, scope) {
|
|
1024
|
+
await ops.updateMany(INTAKE_ROUTE_LOCKS, {
|
|
1025
|
+
...scopeWhere(scope),
|
|
1026
|
+
intake_order_origin: null
|
|
1027
|
+
}, { intake_order: null });
|
|
1028
|
+
}
|
|
1029
|
+
function sameKeys(left, right) {
|
|
1030
|
+
return left.length === right.length && left.every((key, index) => key === right[index]);
|
|
1031
|
+
}
|
|
1032
|
+
function boardRouteCount(rows, boardKey) {
|
|
1033
|
+
return rows.filter((row) => row.board_key === boardKey).length;
|
|
1034
|
+
}
|
|
1035
|
+
/** Whether a stored join route is still the one projects were given, which the linked rule replaces. */
|
|
1036
|
+
function isShippedJoinRoute(row) {
|
|
1037
|
+
return row.board_key === RETIRED_JOIN_ROUTE.target.boardKey && row.phase_key === RETIRED_JOIN_ROUTE.target.phaseKey && isDeepStrictEqual(currentRuleGroup(row.when_condition), RETIRED_JOIN_ROUTE.when);
|
|
1038
|
+
}
|
|
1039
|
+
/** Whether `row` files every new issue, or pull request, that reaches it, as the seeded "Everything else" route does. */
|
|
1040
|
+
function catchesEveryNewCard(row, kind) {
|
|
1041
|
+
return row.enabled && !row.join_closed_issue && kindsTakenWhole({
|
|
1042
|
+
when: row.when_condition,
|
|
1043
|
+
...routeArrivals(row)
|
|
1044
|
+
}).includes(kind);
|
|
1045
|
+
}
|
|
1046
|
+
async function readIntakeRoutes(ops, scope) {
|
|
1047
|
+
return (await ops.findMany(INTAKE_ROUTES, scopeWhere(scope))).sort((left, right) => left.position - right.position);
|
|
676
1048
|
}
|
|
677
1049
|
function intakeRouteNotFound(id) {
|
|
678
1050
|
return new StoredBoardError("intake_route_not_found", `Intake route "${id}" does not exist in this project.`);
|
|
@@ -706,6 +1078,8 @@ async function insertIntakeRoute(ops, scope, route) {
|
|
|
706
1078
|
phase_key: route.input.target.phaseKey ?? null,
|
|
707
1079
|
on_events: route.input.on ?? null,
|
|
708
1080
|
join_closed_issue: route.input.target.joinClosedIssue ?? false,
|
|
1081
|
+
opened_files_pull_requests: route.input.pullRequestOpenedMovesOnly ? null : true,
|
|
1082
|
+
move_to_board_key: route.input.target.moveToBoardKey ?? null,
|
|
709
1083
|
revision: 1,
|
|
710
1084
|
created_by: route.actor,
|
|
711
1085
|
created_at: now,
|
|
@@ -744,6 +1118,6 @@ async function placeIntakeRoutes(ops, rows, actor) {
|
|
|
744
1118
|
revision
|
|
745
1119
|
}, { position }) !== 1) throw new ConcurrentBoardWrite();
|
|
746
1120
|
}
|
|
747
|
-
export { CATCH_ALL_INTAKE_ROUTE, CLOSED_CANCELED_ROUTE, CLOSED_COMPLETED_ROUTE,
|
|
1121
|
+
export { CATCH_ALL_INTAKE_ROUTE, CLOSED_CANCELED_ROUTE, CLOSED_COMPLETED_ROUTE, DEFAULT_INTAKE_ROUTE, DEFAULT_INTAKE_ROUTES, DEFAULT_INTAKE_ROUTE_ACTOR, LINKED_PULL_REQUEST_ROUTE, LINKED_PULL_REQUEST_ROUTE_KEY, MAX_INTAKE_ROUTES_PER_BOARD, OUTSIDE_PULL_REQUEST_INTAKE_ROUTE, PULL_REQUEST_CLOSED_ISSUE_ROUTE, PULL_REQUEST_CLOSED_ROUTE, PULL_REQUEST_INTAKE_ROUTE, PULL_REQUEST_MERGED_ROUTE, PULL_REQUEST_REVIEW_REQUESTED_ROUTE, PULL_REQUEST_UPDATED_ROUTE, REOPENED_ROUTE, StoredBoardError, StoredBoardsStorage, readStoredBoard, stampNewProjectIntake };
|
|
748
1122
|
|
|
749
1123
|
//# sourceMappingURL=base.js.map
|