@mastra/factory 0.29.0-alpha.4 → 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 +119 -60
- 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 +31 -9
- package/dist/factory.js.map +1 -1
- package/dist/integrations/base.d.ts +9 -0
- package/dist/integrations/base.d.ts.map +1 -1
- package/dist/integrations/dependabot/rules.js +1 -1
- package/dist/integrations/dependabot/rules.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 +19 -5
- package/dist/integrations/github/integration.d.ts.map +1 -1
- package/dist/integrations/github/integration.js +21 -6
- 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.map +1 -1
- package/dist/integrations/github/routes.js +14 -2
- 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 +218 -30
- 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/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 -1
- package/dist/integrations/gitlab/integration.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 +108 -12
- package/dist/integrations/gitlab/rules.js.map +1 -1
- package/dist/integrations/incidentio/rules.d.ts.map +1 -1
- package/dist/integrations/incidentio/rules.js +14 -4
- package/dist/integrations/incidentio/rules.js.map +1 -1
- package/dist/integrations/jira/rules.d.ts.map +1 -1
- package/dist/integrations/jira/rules.js +12 -2
- package/dist/integrations/jira/rules.js.map +1 -1
- package/dist/integrations/linear/rules.d.ts.map +1 -1
- package/dist/integrations/linear/rules.js +13 -2
- 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 +22 -3
- package/dist/integrations/platform/github/integration.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.js +1 -1
- package/dist/integrations/vanta/rules.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 -0
- package/dist/routes/contracts.d.ts.map +1 -1
- package/dist/routes/contracts.js +586 -13
- package/dist/routes/contracts.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/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 -5
- package/dist/routes/source-control-sessions.d.ts.map +1 -1
- package/dist/routes/source-control-sessions.js +8 -87
- package/dist/routes/source-control-sessions.js.map +1 -1
- package/dist/routes/surface.d.ts +13 -1
- package/dist/routes/surface.d.ts.map +1 -1
- package/dist/routes/surface.js +24 -26
- 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 +361 -122
- 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/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 +26 -34
- 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 -10
- 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 +95 -1
- package/dist/storage/domains/boards/schemas.js.map +1 -1
- package/dist/storage/domains/projects/base.d.ts.map +1 -1
- package/dist/storage/domains/projects/base.js +19 -10
- package/dist/storage/domains/projects/base.js.map +1 -1
- package/dist/storage/domains/source-control/base.d.ts.map +1 -1
- package/dist/storage/domains/source-control/base.js +5 -2
- package/dist/storage/domains/source-control/base.js.map +1 -1
- package/dist/storage/domains/work-items/base.d.ts +48 -17
- package/dist/storage/domains/work-items/base.d.ts.map +1 -1
- package/dist/storage/domains/work-items/base.js +128 -75
- 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/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/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 +8 -8
|
@@ -4,8 +4,57 @@ import type { RuleGroup } from '../rules/rule-group.js';
|
|
|
4
4
|
* webhooks onto these. Status events change where a card belongs: only these can move a card, so
|
|
5
5
|
* only these may be named in a route's `on`.
|
|
6
6
|
*/
|
|
7
|
-
export declare const STATUS_EVENTS: readonly ['work_item.
|
|
7
|
+
export declare const STATUS_EVENTS: readonly ['work_item.opened', 'work_item.reopened', 'work_item.updated', 'work_item.closed', 'pull_request.opened', 'pull_request.reopened', 'pull_request.updated', 'pull_request.synchronized', 'pull_request.review_requested', 'pull_request.merged', 'pull_request.closed'];
|
|
8
8
|
export type StatusEvent = (typeof STATUS_EVENTS)[number];
|
|
9
|
+
/**
|
|
10
|
+
* The event routes placed new cards on before issues and pull requests had events of their own: an
|
|
11
|
+
* issue or a pull request with no card opened. It never fires and never moves a card. A stored
|
|
12
|
+
* route naming it, or naming no event, keeps filing both for good, and the API keeps accepting and
|
|
13
|
+
* returning it, so editing such a route never narrows it.
|
|
14
|
+
*/
|
|
15
|
+
export declare const LEGACY_ARRIVAL_EVENT = "work_item.created";
|
|
16
|
+
/** What a route's `on` may name: the status events, and the legacy arrival event. */
|
|
17
|
+
export declare const ROUTE_EVENTS: readonly ["work_item.opened", "work_item.reopened", "work_item.updated", "work_item.closed", "pull_request.opened", "pull_request.reopened", "pull_request.updated", "pull_request.synchronized", "pull_request.review_requested", "pull_request.merged", "pull_request.closed", "work_item.created"];
|
|
18
|
+
export type RouteEvent = (typeof ROUTE_EVENTS)[number];
|
|
19
|
+
/** What an arrival is: an issue (any provider's work item) or a pull request with no card. */
|
|
20
|
+
export type ArrivalKind = 'issue' | 'pull_request';
|
|
21
|
+
/** The kind of an arrival, read from its `source.kind` fact. */
|
|
22
|
+
export declare function arrivalKind(facts: Record<string, unknown>): ArrivalKind;
|
|
23
|
+
/** What a route's arrival events mean: a route stored by 0.28 moved cards on `pull_request.opened` and filed none. */
|
|
24
|
+
export interface RouteArrivals {
|
|
25
|
+
on: readonly string[];
|
|
26
|
+
/** True on a route stored before `pull_request.opened` filed pull requests: there it only moves a card. */
|
|
27
|
+
pullRequestOpenedMovesOnly?: boolean;
|
|
28
|
+
}
|
|
29
|
+
/** The arrivals a route files: issues on `work_item.opened`, pull requests on `pull_request.opened`, both on `work_item.created`. */
|
|
30
|
+
export declare function arrivalKinds({ on, pullRequestOpenedMovesOnly }: RouteArrivals): Set<ArrivalKind>;
|
|
31
|
+
/** Labels or assignees an update added and removed. */
|
|
32
|
+
export interface ItemChange {
|
|
33
|
+
added: string[];
|
|
34
|
+
removed: string[];
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Folds several changes, oldest first, into the net change: a label added then removed (or removed
|
|
38
|
+
* then added back) cancels out, so the result never carries just the newest delta.
|
|
39
|
+
*/
|
|
40
|
+
export declare function combineChanges(changes: readonly ItemChange[]): ItemChange;
|
|
41
|
+
/** The change between two lists (compared case-insensitively, keeping the newer spelling). */
|
|
42
|
+
export declare function listChange(before: readonly string[], after: readonly string[]): ItemChange;
|
|
43
|
+
/** The events that report labels or assignees changing on the card's work item or pull request. */
|
|
44
|
+
export declare const UPDATE_EVENTS: readonly ['work_item.updated', 'pull_request.updated'];
|
|
45
|
+
export type UpdateEvent = (typeof UPDATE_EVENTS)[number];
|
|
46
|
+
export declare function isUpdateEvent(type: string): type is UpdateEvent;
|
|
47
|
+
/**
|
|
48
|
+
* The update event for a change of labels and assignees, or undefined when nothing changed: an
|
|
49
|
+
* item that reports "changed" without a label or assignee difference produces no event, and
|
|
50
|
+
* neither does a change to only the labels Factory manages.
|
|
51
|
+
*/
|
|
52
|
+
export declare function updateEventFacts(type: UpdateEvent, { assignees, ...rest }: {
|
|
53
|
+
labels?: ItemChange;
|
|
54
|
+
assignees?: ItemChange;
|
|
55
|
+
}): BoardEventFacts | undefined;
|
|
56
|
+
/** One update event standing for several, oldest first, or undefined when they cancel out. */
|
|
57
|
+
export declare function combineUpdates(events: readonly BoardEventFacts[]): BoardEventFacts | undefined;
|
|
9
58
|
/**
|
|
10
59
|
* What happened to a card's pull request (GitHub) or merge request (GitLab): opened by the card's
|
|
11
60
|
* session, pushed to, re-review requested, merged, or closed unmerged. A provider's default rule
|
|
@@ -17,7 +66,8 @@ export declare function isPullRequestEvent(type: StatusEvent): type is PullReque
|
|
|
17
66
|
/**
|
|
18
67
|
* Whether the event may move a card that is, or isn't, finished: a reopen moves only a finished
|
|
19
68
|
* card, a close or a merge only an unfinished one. A push or a review request re-reviews a pull
|
|
20
|
-
* request whatever its card's phase
|
|
69
|
+
* request whatever its card's phase, and an update or a pull request reopening moves the card
|
|
70
|
+
* wherever a route sends it.
|
|
21
71
|
*/
|
|
22
72
|
export declare function eventMovesCard(type: StatusEvent, finished: boolean): boolean;
|
|
23
73
|
/** Activity on a card: it never moves the card, it only tells the card's session. */
|
|
@@ -26,28 +76,58 @@ export type ActivityEvent = (typeof ACTIVITY_EVENTS)[number];
|
|
|
26
76
|
/** Why a work item closed: `canceled` covers "not planned" and duplicates. */
|
|
27
77
|
export declare const CLOSE_REASONS: readonly ['completed', 'canceled'];
|
|
28
78
|
export type CloseReason = (typeof CLOSE_REASONS)[number];
|
|
29
|
-
/** A status event as routes see it. */
|
|
79
|
+
/** A status event as routes see it. Update events carry what changed. */
|
|
30
80
|
export interface BoardEventFacts {
|
|
31
81
|
type: StatusEvent;
|
|
32
82
|
reason?: CloseReason;
|
|
83
|
+
labels?: ItemChange;
|
|
84
|
+
assignees?: ItemChange;
|
|
85
|
+
/**
|
|
86
|
+
* On a pull request's update: which pull request changed (its source's external id), so changes
|
|
87
|
+
* to two pull requests on one card never net out against each other.
|
|
88
|
+
*/
|
|
89
|
+
pullRequest?: string;
|
|
90
|
+
/** On a pull request event: whether that pull request's author has write access (or is Factory). */
|
|
91
|
+
pullRequestTrusted?: boolean;
|
|
92
|
+
/**
|
|
93
|
+
* On the `pull_request.opened` a pull request linking to the card of the issue it closes brings:
|
|
94
|
+
* that card as it was before the pull request joined it (see `closedIssueRuleFacts`).
|
|
95
|
+
*/
|
|
96
|
+
closedIssue?: {
|
|
97
|
+
phase: string | null;
|
|
98
|
+
hasPullRequest: boolean;
|
|
99
|
+
};
|
|
33
100
|
}
|
|
101
|
+
/** The facts a route's `when` reads from an event. */
|
|
102
|
+
export declare function eventRuleFacts(event: BoardEventFacts): Record<string, unknown>;
|
|
34
103
|
/** The close reason for a provider's own closed-state fact. */
|
|
35
104
|
export declare function closeReason(canceled: boolean): CloseReason;
|
|
36
|
-
/** What a route without `on` handles: placing new cards, as routes always have. */
|
|
37
|
-
export declare const DEFAULT_ROUTE_EVENTS: readonly
|
|
105
|
+
/** What a route without `on` handles: placing new cards, issues and pull requests alike, as routes always have. */
|
|
106
|
+
export declare const DEFAULT_ROUTE_EVENTS: readonly RouteEvent[];
|
|
107
|
+
/** What an update changed: only update events carry these. */
|
|
108
|
+
export declare const CHANGE_RULE_FIELDS: readonly ['event.labels.added', 'event.labels.removed', 'event.assignees.added', 'event.assignees.removed'];
|
|
38
109
|
/** Facts a route's `when` can test about the event, besides the card's own facts. */
|
|
39
|
-
export declare const EVENT_RULE_FIELDS: readonly [
|
|
110
|
+
export declare const EVENT_RULE_FIELDS: readonly ["event.type", "event.reason", "event.labels.added", "event.labels.removed", "event.assignees.added", "event.assignees.removed"];
|
|
111
|
+
/** Facts about the card an event would move; a new item has no card yet. */
|
|
112
|
+
export declare const CARD_MOVE_RULE_FIELDS: readonly ['card.phase'];
|
|
40
113
|
/**
|
|
41
114
|
* Facts a route can test about the issue an arriving pull request closes (see
|
|
42
115
|
* `closedIssueRuleFacts`). Only arrivals have them, so phase conditions can't name them.
|
|
43
116
|
*/
|
|
44
117
|
export declare const CLOSED_ISSUE_RULE_FIELDS: readonly ['pullRequest.closesIssue', 'closedIssue.phase', 'closedIssue.hasPullRequest'];
|
|
45
118
|
/** Every field an intake route's `when` may name. */
|
|
46
|
-
export declare const INTAKE_ROUTE_RULE_FIELDS: readonly ["item.labels", "item.title", "item.author", "item.key", "item.state", "item.assignees", "
|
|
119
|
+
export declare const INTAKE_ROUTE_RULE_FIELDS: readonly ["item.labels", "item.title", "item.author", "item.key", "item.state", "item.assignees", "item.trusted", "pullRequest.trusted", "source.kind", "source.integration", "source.provider", "source.repository", "item.pullRequest", "item.hasPullRequest", "item.hasIssue", "card.phase", "event.type", "event.reason", "event.labels.added", "event.labels.removed", "event.assignees.added", "event.assignees.removed", "pullRequest.closesIssue", "closedIssue.phase", "closedIssue.hasPullRequest"];
|
|
120
|
+
/**
|
|
121
|
+
* Fields a stored route may still name and that keep evaluating, but the filter picker no longer
|
|
122
|
+
* offers; the picker shows them as "Legacy filter" with a remove button.
|
|
123
|
+
*/
|
|
124
|
+
export declare const LEGACY_RULE_FIELDS: readonly ["item.key", "item.title", "item.state", "source.integration", "item.pullRequest", "event.type", "pullRequest.closesIssue", "closedIssue.phase", "closedIssue.hasPullRequest"];
|
|
125
|
+
/** The one filter set the picker offers: every route field that isn't legacy. */
|
|
126
|
+
export declare const PICKER_RULE_FIELDS: ("card.phase" | "closedIssue.hasPullRequest" | "closedIssue.phase" | "event.assignees.added" | "event.assignees.removed" | "event.labels.added" | "event.labels.removed" | "event.reason" | "event.type" | "item.assignees" | "item.author" | "item.hasIssue" | "item.hasPullRequest" | "item.key" | "item.labels" | "item.pullRequest" | "item.state" | "item.title" | "item.trusted" | "pullRequest.closesIssue" | "pullRequest.trusted" | "source.integration" | "source.kind" | "source.provider" | "source.repository")[];
|
|
47
127
|
/**
|
|
48
128
|
* Why a route's `on` and `when` can't be saved together, or null. `on` must name at least one
|
|
49
|
-
*
|
|
50
|
-
*
|
|
129
|
+
* route event, each once; `event.*` conditions need an event besides `work_item.opened` and
|
|
130
|
+
* `work_item.created`, which place new cards and carry no event facts, and `event.reason` needs `work_item.closed`, the
|
|
51
131
|
* only event with a reason.
|
|
52
132
|
*/
|
|
53
133
|
export declare function routeEventsProblem(on: readonly string[], when: RuleGroup | null): string | null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"board-events.d.ts","sourceRoot":"","sources":["../../src/boards/board-events.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"board-events.d.ts","sourceRoot":"","sources":["../../src/boards/board-events.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAIxD;;;;GAIG;AACH,eAAO,MAAM,aAAa,YACxB,kBAAkB,EAClB,oBAAoB,EACpB,mBAAmB,EACnB,kBAAkB,EAClB,qBAAqB,EACrB,uBAAuB,EACvB,sBAAsB,EACtB,2BAA2B,EAC3B,+BAA+B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js";
|
|
2
3
|
// src/boards/board-events.ts
|
|
3
4
|
/**
|
|
4
5
|
* What happened to a card's source, named the same for every provider. Integrations map their
|
|
@@ -6,22 +7,138 @@ import { CARD_RULE_FIELDS } from "../rules/rule-group.js";
|
|
|
6
7
|
* only these may be named in a route's `on`.
|
|
7
8
|
*/
|
|
8
9
|
const STATUS_EVENTS = [
|
|
9
|
-
"work_item.
|
|
10
|
-
"work_item.closed",
|
|
10
|
+
"work_item.opened",
|
|
11
11
|
"work_item.reopened",
|
|
12
|
+
"work_item.updated",
|
|
13
|
+
"work_item.closed",
|
|
12
14
|
"pull_request.opened",
|
|
15
|
+
"pull_request.reopened",
|
|
16
|
+
"pull_request.updated",
|
|
13
17
|
"pull_request.synchronized",
|
|
14
18
|
"pull_request.review_requested",
|
|
15
19
|
"pull_request.merged",
|
|
16
20
|
"pull_request.closed"
|
|
17
21
|
];
|
|
22
|
+
/**
|
|
23
|
+
* The event routes placed new cards on before issues and pull requests had events of their own: an
|
|
24
|
+
* issue or a pull request with no card opened. It never fires and never moves a card. A stored
|
|
25
|
+
* route naming it, or naming no event, keeps filing both for good, and the API keeps accepting and
|
|
26
|
+
* returning it, so editing such a route never narrows it.
|
|
27
|
+
*/
|
|
28
|
+
const LEGACY_ARRIVAL_EVENT = "work_item.created";
|
|
29
|
+
/** What a route's `on` may name: the status events, and the legacy arrival event. */
|
|
30
|
+
const ROUTE_EVENTS = [...STATUS_EVENTS, LEGACY_ARRIVAL_EVENT];
|
|
31
|
+
/** The kind of an arrival, read from its `source.kind` fact. */
|
|
32
|
+
function arrivalKind(facts) {
|
|
33
|
+
return facts["source.kind"] === "pull_request" ? "pull_request" : "issue";
|
|
34
|
+
}
|
|
35
|
+
/** The arrivals a route files: issues on `work_item.opened`, pull requests on `pull_request.opened`, both on `work_item.created`. */
|
|
36
|
+
function arrivalKinds({ on, pullRequestOpenedMovesOnly }) {
|
|
37
|
+
const kinds = /* @__PURE__ */ new Set();
|
|
38
|
+
if (on.includes("work_item.opened") || on.includes("work_item.created")) kinds.add("issue");
|
|
39
|
+
if (on.includes("pull_request.opened") && !pullRequestOpenedMovesOnly || on.includes("work_item.created")) kinds.add("pull_request");
|
|
40
|
+
return kinds;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Folds several changes, oldest first, into the net change: a label added then removed (or removed
|
|
44
|
+
* then added back) cancels out, so the result never carries just the newest delta.
|
|
45
|
+
*/
|
|
46
|
+
function combineChanges(changes) {
|
|
47
|
+
const net = /* @__PURE__ */ new Map();
|
|
48
|
+
const fold = (name, side) => {
|
|
49
|
+
const key = name.toLowerCase();
|
|
50
|
+
const seen = net.get(key);
|
|
51
|
+
if (seen && seen.side !== side) net.delete(key);
|
|
52
|
+
else net.set(key, {
|
|
53
|
+
name,
|
|
54
|
+
side
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
for (const change of changes) {
|
|
58
|
+
for (const name of change.removed) fold(name, "removed");
|
|
59
|
+
for (const name of change.added) fold(name, "added");
|
|
60
|
+
}
|
|
61
|
+
const pick = (side) => [...net.values()].filter((entry) => entry.side === side).map((entry) => entry.name);
|
|
62
|
+
return {
|
|
63
|
+
added: pick("added"),
|
|
64
|
+
removed: pick("removed")
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
/** The change between two lists (compared case-insensitively, keeping the newer spelling). */
|
|
68
|
+
function listChange(before, after) {
|
|
69
|
+
const key = (value) => value.toLowerCase();
|
|
70
|
+
const had = new Set(before.map(key));
|
|
71
|
+
const has = new Set(after.map(key));
|
|
72
|
+
return {
|
|
73
|
+
added: after.filter((value) => !had.has(key(value))),
|
|
74
|
+
removed: before.filter((value) => !has.has(key(value)))
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
function changed(change) {
|
|
78
|
+
return Boolean(change && (change.added.length > 0 || change.removed.length > 0));
|
|
79
|
+
}
|
|
80
|
+
/** The events that report labels or assignees changing on the card's work item or pull request. */
|
|
81
|
+
const UPDATE_EVENTS = ["work_item.updated", "pull_request.updated"];
|
|
82
|
+
function isUpdateEvent(type) {
|
|
83
|
+
return UPDATE_EVENTS.includes(type);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Labels Factory sets and clears itself to track triage and acceptance. Like a rule's own move,
|
|
87
|
+
* changing them is bookkeeping, so they never count as a change, whoever made it.
|
|
88
|
+
*/
|
|
89
|
+
const FACTORY_MANAGED_LABELS = /* @__PURE__ */ new Set([NEEDS_APPROVAL_LABEL, AUTO_TRIAGED_LABEL]);
|
|
90
|
+
function withoutManagedLabels(change) {
|
|
91
|
+
if (!change) return void 0;
|
|
92
|
+
const kept = (names) => names.filter((name) => !FACTORY_MANAGED_LABELS.has(name.toLowerCase()));
|
|
93
|
+
return {
|
|
94
|
+
added: kept(change.added),
|
|
95
|
+
removed: kept(change.removed)
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* The update event for a change of labels and assignees, or undefined when nothing changed: an
|
|
100
|
+
* item that reports "changed" without a label or assignee difference produces no event, and
|
|
101
|
+
* neither does a change to only the labels Factory manages.
|
|
102
|
+
*/
|
|
103
|
+
function updateEventFacts(type, { assignees, ...rest }) {
|
|
104
|
+
const change = {
|
|
105
|
+
labels: withoutManagedLabels(rest.labels),
|
|
106
|
+
assignees
|
|
107
|
+
};
|
|
108
|
+
if (!changed(change.labels) && !changed(change.assignees)) return void 0;
|
|
109
|
+
return {
|
|
110
|
+
type,
|
|
111
|
+
...changed(change.labels) ? { labels: change.labels } : {},
|
|
112
|
+
...changed(change.assignees) ? { assignees: change.assignees } : {}
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
/** One update event standing for several, oldest first, or undefined when they cancel out. */
|
|
116
|
+
function combineUpdates(events) {
|
|
117
|
+
const [first] = events;
|
|
118
|
+
if (!first || !isUpdateEvent(first.type)) return void 0;
|
|
119
|
+
const combined = updateEventFacts(first.type, {
|
|
120
|
+
labels: combineChanges(events.flatMap((event) => event.labels ? [event.labels] : [])),
|
|
121
|
+
assignees: combineChanges(events.flatMap((event) => event.assignees ? [event.assignees] : []))
|
|
122
|
+
});
|
|
123
|
+
if (!combined) return void 0;
|
|
124
|
+
const identified = first.pullRequest !== void 0 ? {
|
|
125
|
+
...combined,
|
|
126
|
+
pullRequest: first.pullRequest
|
|
127
|
+
} : combined;
|
|
128
|
+
if (events.some((event) => event.pullRequestTrusted === void 0)) return identified;
|
|
129
|
+
return {
|
|
130
|
+
...identified,
|
|
131
|
+
pullRequestTrusted: events.every((event) => event.pullRequestTrusted === true)
|
|
132
|
+
};
|
|
133
|
+
}
|
|
18
134
|
function isPullRequestEvent(type) {
|
|
19
135
|
return type.startsWith("pull_request.");
|
|
20
136
|
}
|
|
21
137
|
/**
|
|
22
138
|
* Whether the event may move a card that is, or isn't, finished: a reopen moves only a finished
|
|
23
139
|
* card, a close or a merge only an unfinished one. A push or a review request re-reviews a pull
|
|
24
|
-
* request whatever its card's phase
|
|
140
|
+
* request whatever its card's phase, and an update or a pull request reopening moves the card
|
|
141
|
+
* wherever a route sends it.
|
|
25
142
|
*/
|
|
26
143
|
function eventMovesCard(type, finished) {
|
|
27
144
|
switch (type) {
|
|
@@ -36,14 +153,38 @@ function eventMovesCard(type, finished) {
|
|
|
36
153
|
const ACTIVITY_EVENTS = ["work_item.commented", "work_item.edited"];
|
|
37
154
|
/** Why a work item closed: `canceled` covers "not planned" and duplicates. */
|
|
38
155
|
const CLOSE_REASONS = ["completed", "canceled"];
|
|
156
|
+
/** The facts a route's `when` reads from an event. */
|
|
157
|
+
function eventRuleFacts(event) {
|
|
158
|
+
return {
|
|
159
|
+
"event.type": event.type,
|
|
160
|
+
"event.reason": event.reason,
|
|
161
|
+
"event.labels.added": event.labels?.added,
|
|
162
|
+
"event.labels.removed": event.labels?.removed,
|
|
163
|
+
"event.assignees.added": event.assignees?.added,
|
|
164
|
+
"event.assignees.removed": event.assignees?.removed
|
|
165
|
+
};
|
|
166
|
+
}
|
|
39
167
|
/** The close reason for a provider's own closed-state fact. */
|
|
40
168
|
function closeReason(canceled) {
|
|
41
169
|
return canceled ? "canceled" : "completed";
|
|
42
170
|
}
|
|
43
|
-
/** What a route without `on` handles: placing new cards, as routes always have. */
|
|
44
|
-
const DEFAULT_ROUTE_EVENTS = [
|
|
171
|
+
/** What a route without `on` handles: placing new cards, issues and pull requests alike, as routes always have. */
|
|
172
|
+
const DEFAULT_ROUTE_EVENTS = [LEGACY_ARRIVAL_EVENT];
|
|
173
|
+
/** What an update changed: only update events carry these. */
|
|
174
|
+
const CHANGE_RULE_FIELDS = [
|
|
175
|
+
"event.labels.added",
|
|
176
|
+
"event.labels.removed",
|
|
177
|
+
"event.assignees.added",
|
|
178
|
+
"event.assignees.removed"
|
|
179
|
+
];
|
|
45
180
|
/** Facts a route's `when` can test about the event, besides the card's own facts. */
|
|
46
|
-
const EVENT_RULE_FIELDS = [
|
|
181
|
+
const EVENT_RULE_FIELDS = [
|
|
182
|
+
"event.type",
|
|
183
|
+
"event.reason",
|
|
184
|
+
...CHANGE_RULE_FIELDS
|
|
185
|
+
];
|
|
186
|
+
/** Facts about the card an event would move; a new item has no card yet. */
|
|
187
|
+
const CARD_MOVE_RULE_FIELDS = ["card.phase"];
|
|
47
188
|
/**
|
|
48
189
|
* Facts a route can test about the issue an arriving pull request closes (see
|
|
49
190
|
* `closedIssueRuleFacts`). Only arrivals have them, so phase conditions can't name them.
|
|
@@ -56,19 +197,39 @@ const CLOSED_ISSUE_RULE_FIELDS = [
|
|
|
56
197
|
/** Every field an intake route's `when` may name. */
|
|
57
198
|
const INTAKE_ROUTE_RULE_FIELDS = [
|
|
58
199
|
...CARD_RULE_FIELDS,
|
|
200
|
+
...CARD_MOVE_RULE_FIELDS,
|
|
59
201
|
...EVENT_RULE_FIELDS,
|
|
60
202
|
...CLOSED_ISSUE_RULE_FIELDS
|
|
61
203
|
];
|
|
62
|
-
|
|
63
|
-
|
|
204
|
+
/**
|
|
205
|
+
* Fields a stored route may still name and that keep evaluating, but the filter picker no longer
|
|
206
|
+
* offers; the picker shows them as "Legacy filter" with a remove button.
|
|
207
|
+
*/
|
|
208
|
+
const LEGACY_RULE_FIELDS = [
|
|
209
|
+
"item.key",
|
|
210
|
+
"item.title",
|
|
211
|
+
"item.state",
|
|
212
|
+
"source.integration",
|
|
213
|
+
"item.pullRequest",
|
|
214
|
+
"event.type",
|
|
215
|
+
...CLOSED_ISSUE_RULE_FIELDS
|
|
216
|
+
];
|
|
217
|
+
/** The one filter set the picker offers: every route field that isn't legacy. */
|
|
218
|
+
const PICKER_RULE_FIELDS = INTAKE_ROUTE_RULE_FIELDS.filter((field) => !LEGACY_RULE_FIELDS.includes(field));
|
|
219
|
+
function isRouteEvent(value) {
|
|
220
|
+
return ROUTE_EVENTS.includes(value);
|
|
221
|
+
}
|
|
222
|
+
/** Events that only file new cards, so carry no event facts: `pull_request.opened` also moves cards. */
|
|
223
|
+
function onlyFilesNewCards(event) {
|
|
224
|
+
return event === "work_item.opened" || event === "work_item.created";
|
|
64
225
|
}
|
|
65
226
|
function namesField(group, fields) {
|
|
66
227
|
return group.conditions.some((condition) => "conditions" in condition ? namesField(condition, fields) : fields.includes(condition.field));
|
|
67
228
|
}
|
|
68
229
|
/**
|
|
69
230
|
* Why a route's `on` and `when` can't be saved together, or null. `on` must name at least one
|
|
70
|
-
*
|
|
71
|
-
*
|
|
231
|
+
* route event, each once; `event.*` conditions need an event besides `work_item.opened` and
|
|
232
|
+
* `work_item.created`, which place new cards and carry no event facts, and `event.reason` needs `work_item.closed`, the
|
|
72
233
|
* only event with a reason.
|
|
73
234
|
*/
|
|
74
235
|
function routeEventsProblem(on, when) {
|
|
@@ -76,12 +237,14 @@ function routeEventsProblem(on, when) {
|
|
|
76
237
|
if (new Set(on).size !== on.length) return "`on` may name each event only once.";
|
|
77
238
|
for (const event of on) {
|
|
78
239
|
if (ACTIVITY_EVENTS.includes(event)) return `"${event}" is activity, not a status change: it notifies the card's session and can't move a card, so a route can't name it.`;
|
|
79
|
-
if (!
|
|
240
|
+
if (!isRouteEvent(event)) return `"${event}" is not a board event; use one of ${ROUTE_EVENTS.join(", ")}.`;
|
|
80
241
|
}
|
|
81
|
-
if (when && on.every(
|
|
242
|
+
if (when && on.every(onlyFilesNewCards) && namesField(when, EVENT_RULE_FIELDS)) return "`event.*` filters only apply to routes that handle an event besides work_item.opened and work_item.created.";
|
|
243
|
+
if (when && on.every(onlyFilesNewCards) && namesField(when, CARD_MOVE_RULE_FIELDS)) return "`card.phase` only applies to routes that move an existing card: a new item has no card yet.";
|
|
244
|
+
if (when && !on.some(isUpdateEvent) && namesField(when, CHANGE_RULE_FIELDS)) return "What changed (`event.labels.*`, `event.assignees.*`) only applies to routes that handle work_item.updated or pull_request.updated.";
|
|
82
245
|
if (when && !on.includes("work_item.closed") && namesField(when, ["event.reason"])) return "`event.reason` only applies to routes that handle work_item.closed: no other event carries a reason.";
|
|
83
246
|
return null;
|
|
84
247
|
}
|
|
85
|
-
export { ACTIVITY_EVENTS, CLOSED_ISSUE_RULE_FIELDS, CLOSE_REASONS, DEFAULT_ROUTE_EVENTS, EVENT_RULE_FIELDS, INTAKE_ROUTE_RULE_FIELDS, STATUS_EVENTS, closeReason, eventMovesCard, isPullRequestEvent, routeEventsProblem };
|
|
248
|
+
export { ACTIVITY_EVENTS, CARD_MOVE_RULE_FIELDS, CHANGE_RULE_FIELDS, CLOSED_ISSUE_RULE_FIELDS, CLOSE_REASONS, DEFAULT_ROUTE_EVENTS, EVENT_RULE_FIELDS, INTAKE_ROUTE_RULE_FIELDS, LEGACY_ARRIVAL_EVENT, LEGACY_RULE_FIELDS, PICKER_RULE_FIELDS, ROUTE_EVENTS, STATUS_EVENTS, UPDATE_EVENTS, arrivalKind, arrivalKinds, closeReason, combineChanges, combineUpdates, eventMovesCard, eventRuleFacts, isPullRequestEvent, isUpdateEvent, listChange, routeEventsProblem, updateEventFacts };
|
|
86
249
|
|
|
87
250
|
//# sourceMappingURL=board-events.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"board-events.js","names":[],"sources":["../../src/boards/board-events.ts"],"sourcesContent":["import type { RuleGroup } from '../rules/rule-group.js';\nimport { CARD_RULE_FIELDS } from '../rules/rule-group.js';\n\n/**\n * What happened to a card's source, named the same for every provider. Integrations map their\n * webhooks onto these. Status events change where a card belongs: only these can move a card, so\n * only these may be named in a route's `on`.\n */\nexport const STATUS_EVENTS = [\n 'work_item.created',\n 'work_item.closed',\n 'work_item.reopened',\n 'pull_request.opened',\n 'pull_request.synchronized',\n 'pull_request.review_requested',\n 'pull_request.merged',\n 'pull_request.closed',\n] as const;\nexport type StatusEvent = (typeof STATUS_EVENTS)[number];\n\n/**\n * What happened to a card's pull request (GitHub) or merge request (GitLab): opened by the card's\n * session, pushed to, re-review requested, merged, or closed unmerged. A provider's default rule\n * decides whether the event moves the card at all; a route on the card's board naming the event\n * decides where it goes.\n */\nexport type PullRequestEvent = Extract<StatusEvent, `pull_request.${string}`>;\n\nexport function isPullRequestEvent(type: StatusEvent): type is PullRequestEvent {\n return type.startsWith('pull_request.');\n}\n\n/**\n * Whether the event may move a card that is, or isn't, finished: a reopen moves only a finished\n * card, a close or a merge only an unfinished one. A push or a review request re-reviews a pull\n * request whatever its card's phase.\n */\nexport function eventMovesCard(type: StatusEvent, finished: boolean): boolean {\n switch (type) {\n case 'work_item.reopened':\n return finished;\n case 'work_item.closed':\n case 'pull_request.merged':\n case 'pull_request.closed':\n return !finished;\n default:\n return true;\n }\n}\n\n/** Activity on a card: it never moves the card, it only tells the card's session. */\nexport const ACTIVITY_EVENTS = ['work_item.commented', 'work_item.edited'] as const;\nexport type ActivityEvent = (typeof ACTIVITY_EVENTS)[number];\n\n/** Why a work item closed: `canceled` covers \"not planned\" and duplicates. */\nexport const CLOSE_REASONS = ['completed', 'canceled'] as const;\nexport type CloseReason = (typeof CLOSE_REASONS)[number];\n\n/** A status event as routes see it. */\nexport interface BoardEventFacts {\n type: StatusEvent;\n reason?: CloseReason;\n}\n\n/** The close reason for a provider's own closed-state fact. */\nexport function closeReason(canceled: boolean): CloseReason {\n return canceled ? 'canceled' : 'completed';\n}\n\n/** What a route without `on` handles: placing new cards, as routes always have. */\nexport const DEFAULT_ROUTE_EVENTS: readonly StatusEvent[] = ['work_item.created'];\n\n/** Facts a route's `when` can test about the event, besides the card's own facts. */\nexport const EVENT_RULE_FIELDS = ['event.type', 'event.reason'] as const;\n\n/**\n * Facts a route can test about the issue an arriving pull request closes (see\n * `closedIssueRuleFacts`). Only arrivals have them, so phase conditions can't name them.\n */\nexport const CLOSED_ISSUE_RULE_FIELDS = [\n 'pullRequest.closesIssue',\n 'closedIssue.phase',\n 'closedIssue.hasPullRequest',\n] as const;\n\n/** Every field an intake route's `when` may name. */\nexport const INTAKE_ROUTE_RULE_FIELDS = [\n ...CARD_RULE_FIELDS,\n ...EVENT_RULE_FIELDS,\n ...CLOSED_ISSUE_RULE_FIELDS,\n] as const;\n\nfunction isStatusEvent(value: string): value is StatusEvent {\n return (STATUS_EVENTS as readonly string[]).includes(value);\n}\n\nfunction namesField(group: RuleGroup, fields: readonly string[]): boolean {\n return group.conditions.some(condition =>\n 'conditions' in condition ? namesField(condition, fields) : fields.includes(condition.field),\n );\n}\n\n/**\n * Why a route's `on` and `when` can't be saved together, or null. `on` must name at least one\n * status event, each once; `event.*` conditions need an event besides `work_item.created`, which\n * places new cards and carries no event facts, and `event.reason` needs `work_item.closed`, the\n * only event with a reason.\n */\nexport function routeEventsProblem(on: readonly string[], when: RuleGroup | null): string | null {\n if (on.length === 0) return '`on` must name at least one event.';\n if (new Set(on).size !== on.length) return '`on` may name each event only once.';\n for (const event of on) {\n if ((ACTIVITY_EVENTS as readonly string[]).includes(event)) {\n return `\"${event}\" is activity, not a status change: it notifies the card's session and can't move a card, so a route can't name it.`;\n }\n if (!isStatusEvent(event)) return `\"${event}\" is not a board event; use one of ${STATUS_EVENTS.join(', ')}.`;\n }\n if (when && on.every(event => event === 'work_item.created') && namesField(when, EVENT_RULE_FIELDS)) {\n return '`event.type` and `event.reason` only apply to routes that handle an event besides work_item.created.';\n }\n if (when && !on.includes('work_item.closed') && namesField(when, ['event.reason'])) {\n return '`event.reason` only applies to routes that handle work_item.closed: no other event carries a reason.';\n }\n return null;\n}\n"],"mappings":";;;;;;;AAQA,MAAa,gBAAgB;CAC3B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AAWA,SAAgB,mBAAmB,MAA6C;CAC9E,OAAO,KAAK,WAAW,eAAe;AACxC;;;;;;AAOA,SAAgB,eAAe,MAAmB,UAA4B;CAC5E,QAAQ,MAAR;EACE,KAAK,sBACH,OAAO;EACT,KAAK;EACL,KAAK;EACL,KAAK,uBACH,OAAO,CAAC;EACV,SACE,OAAO;CACX;AACF;;AAGA,MAAa,kBAAkB,CAAC,uBAAuB,kBAAkB;;AAIzE,MAAa,gBAAgB,CAAC,aAAa,UAAU;;AAUrD,SAAgB,YAAY,UAAgC;CAC1D,OAAO,WAAW,aAAa;AACjC;;AAGA,MAAa,uBAA+C,CAAC,mBAAmB;;AAGhF,MAAa,oBAAoB,CAAC,cAAc,cAAc;;;;;AAM9D,MAAa,2BAA2B;CACtC;CACA;CACA;AACF;;AAGA,MAAa,2BAA2B;CACtC,GAAG;CACH,GAAG;CACH,GAAG;AACL;AAEA,SAAS,cAAc,OAAqC;CAC1D,OAAQ,cAAoC,SAAS,KAAK;AAC5D;AAEA,SAAS,WAAW,OAAkB,QAAoC;CACxE,OAAO,MAAM,WAAW,MAAK,cAC3B,gBAAgB,YAAY,WAAW,WAAW,MAAM,IAAI,OAAO,SAAS,UAAU,KAAK,CAC7F;AACF;;;;;;;AAQA,SAAgB,mBAAmB,IAAuB,MAAuC;CAC/F,IAAI,GAAG,WAAW,GAAG,OAAO;CAC5B,IAAI,IAAI,IAAI,EAAE,CAAC,CAAC,SAAS,GAAG,QAAQ,OAAO;CAC3C,KAAK,MAAM,SAAS,IAAI;EACtB,IAAK,gBAAsC,SAAS,KAAK,GACvD,OAAO,IAAI,MAAM;EAEnB,IAAI,CAAC,cAAc,KAAK,GAAG,OAAO,IAAI,MAAM,qCAAqC,cAAc,KAAK,IAAI,EAAE;CAC5G;CACA,IAAI,QAAQ,GAAG,OAAM,UAAS,UAAU,mBAAmB,KAAK,WAAW,MAAM,iBAAiB,GAChG,OAAO;CAET,IAAI,QAAQ,CAAC,GAAG,SAAS,kBAAkB,KAAK,WAAW,MAAM,CAAC,cAAc,CAAC,GAC/E,OAAO;CAET,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"board-events.js","names":[],"sources":["../../src/boards/board-events.ts"],"sourcesContent":["import type { RuleGroup } from '../rules/rule-group.js';\nimport { CARD_RULE_FIELDS } from '../rules/rule-group.js';\nimport { AUTO_TRIAGED_LABEL, NEEDS_APPROVAL_LABEL } from '../rules/types.js';\n\n/**\n * What happened to a card's source, named the same for every provider. Integrations map their\n * webhooks onto these. Status events change where a card belongs: only these can move a card, so\n * only these may be named in a route's `on`.\n */\nexport const STATUS_EVENTS = [\n 'work_item.opened',\n 'work_item.reopened',\n 'work_item.updated',\n 'work_item.closed',\n 'pull_request.opened',\n 'pull_request.reopened',\n 'pull_request.updated',\n 'pull_request.synchronized',\n 'pull_request.review_requested',\n 'pull_request.merged',\n 'pull_request.closed',\n] as const;\nexport type StatusEvent = (typeof STATUS_EVENTS)[number];\n\n/**\n * The event routes placed new cards on before issues and pull requests had events of their own: an\n * issue or a pull request with no card opened. It never fires and never moves a card. A stored\n * route naming it, or naming no event, keeps filing both for good, and the API keeps accepting and\n * returning it, so editing such a route never narrows it.\n */\nexport const LEGACY_ARRIVAL_EVENT = 'work_item.created';\n\n/** What a route's `on` may name: the status events, and the legacy arrival event. */\nexport const ROUTE_EVENTS = [...STATUS_EVENTS, LEGACY_ARRIVAL_EVENT] as const;\nexport type RouteEvent = (typeof ROUTE_EVENTS)[number];\n\n/** What an arrival is: an issue (any provider's work item) or a pull request with no card. */\nexport type ArrivalKind = 'issue' | 'pull_request';\n\n/** The kind of an arrival, read from its `source.kind` fact. */\nexport function arrivalKind(facts: Record<string, unknown>): ArrivalKind {\n return facts['source.kind'] === 'pull_request' ? 'pull_request' : 'issue';\n}\n\n/** What a route's arrival events mean: a route stored by 0.28 moved cards on `pull_request.opened` and filed none. */\nexport interface RouteArrivals {\n on: readonly string[];\n /** True on a route stored before `pull_request.opened` filed pull requests: there it only moves a card. */\n pullRequestOpenedMovesOnly?: boolean;\n}\n\n/** The arrivals a route files: issues on `work_item.opened`, pull requests on `pull_request.opened`, both on `work_item.created`. */\nexport function arrivalKinds({ on, pullRequestOpenedMovesOnly }: RouteArrivals): Set<ArrivalKind> {\n const kinds = new Set<ArrivalKind>();\n if (on.includes('work_item.opened') || on.includes(LEGACY_ARRIVAL_EVENT)) kinds.add('issue');\n if ((on.includes('pull_request.opened') && !pullRequestOpenedMovesOnly) || on.includes(LEGACY_ARRIVAL_EVENT)) {\n kinds.add('pull_request');\n }\n return kinds;\n}\n\n/** Labels or assignees an update added and removed. */\nexport interface ItemChange {\n added: string[];\n removed: string[];\n}\n\n/**\n * Folds several changes, oldest first, into the net change: a label added then removed (or removed\n * then added back) cancels out, so the result never carries just the newest delta.\n */\nexport function combineChanges(changes: readonly ItemChange[]): ItemChange {\n // Keyed case-insensitively like `listChange`, keeping the newest spelling.\n const net = new Map<string, { name: string; side: 'added' | 'removed' }>();\n const fold = (name: string, side: 'added' | 'removed') => {\n const key = name.toLowerCase();\n const seen = net.get(key);\n if (seen && seen.side !== side) net.delete(key);\n else net.set(key, { name, side });\n };\n for (const change of changes) {\n for (const name of change.removed) fold(name, 'removed');\n for (const name of change.added) fold(name, 'added');\n }\n const pick = (side: 'added' | 'removed') =>\n [...net.values()].filter(entry => entry.side === side).map(entry => entry.name);\n return { added: pick('added'), removed: pick('removed') };\n}\n\n/** The change between two lists (compared case-insensitively, keeping the newer spelling). */\nexport function listChange(before: readonly string[], after: readonly string[]): ItemChange {\n const key = (value: string) => value.toLowerCase();\n const had = new Set(before.map(key));\n const has = new Set(after.map(key));\n return {\n added: after.filter(value => !had.has(key(value))),\n removed: before.filter(value => !has.has(key(value))),\n };\n}\n\nfunction changed(change: ItemChange | undefined): boolean {\n return Boolean(change && (change.added.length > 0 || change.removed.length > 0));\n}\n\n/** The events that report labels or assignees changing on the card's work item or pull request. */\nexport const UPDATE_EVENTS = ['work_item.updated', 'pull_request.updated'] as const;\nexport type UpdateEvent = (typeof UPDATE_EVENTS)[number];\n\nexport function isUpdateEvent(type: string): type is UpdateEvent {\n return (UPDATE_EVENTS as readonly string[]).includes(type);\n}\n\n/**\n * Labels Factory sets and clears itself to track triage and acceptance. Like a rule's own move,\n * changing them is bookkeeping, so they never count as a change, whoever made it.\n */\nconst FACTORY_MANAGED_LABELS = new Set([NEEDS_APPROVAL_LABEL, AUTO_TRIAGED_LABEL]);\n\nfunction withoutManagedLabels(change: ItemChange | undefined): ItemChange | undefined {\n if (!change) return undefined;\n const kept = (names: readonly string[]) => names.filter(name => !FACTORY_MANAGED_LABELS.has(name.toLowerCase()));\n return { added: kept(change.added), removed: kept(change.removed) };\n}\n\n/**\n * The update event for a change of labels and assignees, or undefined when nothing changed: an\n * item that reports \"changed\" without a label or assignee difference produces no event, and\n * neither does a change to only the labels Factory manages.\n */\nexport function updateEventFacts(\n type: UpdateEvent,\n { assignees, ...rest }: { labels?: ItemChange; assignees?: ItemChange },\n): BoardEventFacts | undefined {\n const change = { labels: withoutManagedLabels(rest.labels), assignees };\n if (!changed(change.labels) && !changed(change.assignees)) return undefined;\n return {\n type,\n ...(changed(change.labels) ? { labels: change.labels } : {}),\n ...(changed(change.assignees) ? { assignees: change.assignees } : {}),\n };\n}\n\n/** One update event standing for several, oldest first, or undefined when they cancel out. */\nexport function combineUpdates(events: readonly BoardEventFacts[]): BoardEventFacts | undefined {\n const [first] = events;\n if (!first || !isUpdateEvent(first.type)) return undefined;\n const combined = updateEventFacts(first.type, {\n labels: combineChanges(events.flatMap(event => (event.labels ? [event.labels] : []))),\n assignees: combineChanges(events.flatMap(event => (event.assignees ? [event.assignees] : []))),\n });\n if (!combined) return undefined;\n const identified = first.pullRequest !== undefined ? { ...combined, pullRequest: first.pullRequest } : combined;\n // The folded change stands for every pull request in it, so it is trusted only when each one is.\n if (events.some(event => event.pullRequestTrusted === undefined)) return identified;\n return { ...identified, pullRequestTrusted: events.every(event => event.pullRequestTrusted === true) };\n}\n\n/**\n * What happened to a card's pull request (GitHub) or merge request (GitLab): opened by the card's\n * session, pushed to, re-review requested, merged, or closed unmerged. A provider's default rule\n * decides whether the event moves the card at all; a route on the card's board naming the event\n * decides where it goes.\n */\nexport type PullRequestEvent = Extract<StatusEvent, `pull_request.${string}`>;\n\nexport function isPullRequestEvent(type: StatusEvent): type is PullRequestEvent {\n return type.startsWith('pull_request.');\n}\n\n/**\n * Whether the event may move a card that is, or isn't, finished: a reopen moves only a finished\n * card, a close or a merge only an unfinished one. A push or a review request re-reviews a pull\n * request whatever its card's phase, and an update or a pull request reopening moves the card\n * wherever a route sends it.\n */\nexport function eventMovesCard(type: StatusEvent, finished: boolean): boolean {\n switch (type) {\n case 'work_item.reopened':\n return finished;\n case 'work_item.closed':\n case 'pull_request.merged':\n case 'pull_request.closed':\n return !finished;\n default:\n return true;\n }\n}\n\n/** Activity on a card: it never moves the card, it only tells the card's session. */\nexport const ACTIVITY_EVENTS = ['work_item.commented', 'work_item.edited'] as const;\nexport type ActivityEvent = (typeof ACTIVITY_EVENTS)[number];\n\n/** Why a work item closed: `canceled` covers \"not planned\" and duplicates. */\nexport const CLOSE_REASONS = ['completed', 'canceled'] as const;\nexport type CloseReason = (typeof CLOSE_REASONS)[number];\n\n/** A status event as routes see it. Update events carry what changed. */\nexport interface BoardEventFacts {\n type: StatusEvent;\n reason?: CloseReason;\n labels?: ItemChange;\n assignees?: ItemChange;\n /**\n * On a pull request's update: which pull request changed (its source's external id), so changes\n * to two pull requests on one card never net out against each other.\n */\n pullRequest?: string;\n /** On a pull request event: whether that pull request's author has write access (or is Factory). */\n pullRequestTrusted?: boolean;\n /**\n * On the `pull_request.opened` a pull request linking to the card of the issue it closes brings:\n * that card as it was before the pull request joined it (see `closedIssueRuleFacts`).\n */\n closedIssue?: { phase: string | null; hasPullRequest: boolean };\n}\n\n/** The facts a route's `when` reads from an event. */\nexport function eventRuleFacts(event: BoardEventFacts): Record<string, unknown> {\n return {\n 'event.type': event.type,\n 'event.reason': event.reason,\n 'event.labels.added': event.labels?.added,\n 'event.labels.removed': event.labels?.removed,\n 'event.assignees.added': event.assignees?.added,\n 'event.assignees.removed': event.assignees?.removed,\n };\n}\n\n/** The close reason for a provider's own closed-state fact. */\nexport function closeReason(canceled: boolean): CloseReason {\n return canceled ? 'canceled' : 'completed';\n}\n\n/** What a route without `on` handles: placing new cards, issues and pull requests alike, as routes always have. */\nexport const DEFAULT_ROUTE_EVENTS: readonly RouteEvent[] = [LEGACY_ARRIVAL_EVENT];\n\n/** What an update changed: only update events carry these. */\nexport const CHANGE_RULE_FIELDS = [\n 'event.labels.added',\n 'event.labels.removed',\n 'event.assignees.added',\n 'event.assignees.removed',\n] as const;\n\n/** Facts a route's `when` can test about the event, besides the card's own facts. */\nexport const EVENT_RULE_FIELDS = ['event.type', 'event.reason', ...CHANGE_RULE_FIELDS] as const;\n\n/** Facts about the card an event would move; a new item has no card yet. */\nexport const CARD_MOVE_RULE_FIELDS = ['card.phase'] as const;\n\n/**\n * Facts a route can test about the issue an arriving pull request closes (see\n * `closedIssueRuleFacts`). Only arrivals have them, so phase conditions can't name them.\n */\nexport const CLOSED_ISSUE_RULE_FIELDS = [\n 'pullRequest.closesIssue',\n 'closedIssue.phase',\n 'closedIssue.hasPullRequest',\n] as const;\n\n/** Every field an intake route's `when` may name. */\nexport const INTAKE_ROUTE_RULE_FIELDS = [\n ...CARD_RULE_FIELDS,\n ...CARD_MOVE_RULE_FIELDS,\n ...EVENT_RULE_FIELDS,\n ...CLOSED_ISSUE_RULE_FIELDS,\n] as const;\n\n/**\n * Fields a stored route may still name and that keep evaluating, but the filter picker no longer\n * offers; the picker shows them as \"Legacy filter\" with a remove button.\n */\nexport const LEGACY_RULE_FIELDS = [\n 'item.key',\n 'item.title',\n 'item.state',\n 'source.integration',\n 'item.pullRequest',\n 'event.type',\n ...CLOSED_ISSUE_RULE_FIELDS,\n] as const;\n\n/** The one filter set the picker offers: every route field that isn't legacy. */\nexport const PICKER_RULE_FIELDS = INTAKE_ROUTE_RULE_FIELDS.filter(\n field => !(LEGACY_RULE_FIELDS as readonly string[]).includes(field),\n);\n\nfunction isStatusEvent(value: string): value is StatusEvent {\n return (STATUS_EVENTS as readonly string[]).includes(value);\n}\n\nfunction isRouteEvent(value: string): value is RouteEvent {\n return (ROUTE_EVENTS as readonly string[]).includes(value);\n}\n\n/** Events that only file new cards, so carry no event facts: `pull_request.opened` also moves cards. */\nfunction onlyFilesNewCards(event: string): boolean {\n return event === 'work_item.opened' || event === LEGACY_ARRIVAL_EVENT;\n}\n\nfunction namesField(group: RuleGroup, fields: readonly string[]): boolean {\n return group.conditions.some(condition =>\n 'conditions' in condition ? namesField(condition, fields) : fields.includes(condition.field),\n );\n}\n\n/**\n * Why a route's `on` and `when` can't be saved together, or null. `on` must name at least one\n * route event, each once; `event.*` conditions need an event besides `work_item.opened` and\n * `work_item.created`, which place new cards and carry no event facts, and `event.reason` needs `work_item.closed`, the\n * only event with a reason.\n */\nexport function routeEventsProblem(on: readonly string[], when: RuleGroup | null): string | null {\n if (on.length === 0) return '`on` must name at least one event.';\n if (new Set(on).size !== on.length) return '`on` may name each event only once.';\n for (const event of on) {\n if ((ACTIVITY_EVENTS as readonly string[]).includes(event)) {\n return `\"${event}\" is activity, not a status change: it notifies the card's session and can't move a card, so a route can't name it.`;\n }\n if (!isRouteEvent(event)) return `\"${event}\" is not a board event; use one of ${ROUTE_EVENTS.join(', ')}.`;\n }\n if (when && on.every(onlyFilesNewCards) && namesField(when, EVENT_RULE_FIELDS)) {\n return '`event.*` filters only apply to routes that handle an event besides work_item.opened and work_item.created.';\n }\n if (when && on.every(onlyFilesNewCards) && namesField(when, CARD_MOVE_RULE_FIELDS)) {\n return '`card.phase` only applies to routes that move an existing card: a new item has no card yet.';\n }\n if (when && !on.some(isUpdateEvent) && namesField(when, CHANGE_RULE_FIELDS)) {\n return 'What changed (`event.labels.*`, `event.assignees.*`) only applies to routes that handle work_item.updated or pull_request.updated.';\n }\n if (when && !on.includes('work_item.closed') && namesField(when, ['event.reason'])) {\n return '`event.reason` only applies to routes that handle work_item.closed: no other event carries a reason.';\n }\n return null;\n}\n"],"mappings":";;;;;;;;AASA,MAAa,gBAAgB;CAC3B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;;;;;;;AASA,MAAa,uBAAuB;;AAGpC,MAAa,eAAe,CAAC,GAAG,eAAe,oBAAoB;;AAOnE,SAAgB,YAAY,OAA6C;CACvE,OAAO,MAAM,mBAAmB,iBAAiB,iBAAiB;AACpE;;AAUA,SAAgB,aAAa,EAAE,IAAI,8BAA+D;CAChG,MAAM,wBAAQ,IAAI,IAAiB;CACnC,IAAI,GAAG,SAAS,kBAAkB,KAAK,GAAG,SAAA,mBAA6B,GAAG,MAAM,IAAI,OAAO;CAC3F,IAAK,GAAG,SAAS,qBAAqB,KAAK,CAAC,8BAA+B,GAAG,SAAA,mBAA6B,GACzG,MAAM,IAAI,cAAc;CAE1B,OAAO;AACT;;;;;AAYA,SAAgB,eAAe,SAA4C;CAEzE,MAAM,sBAAM,IAAI,IAAyD;CACzE,MAAM,QAAQ,MAAc,SAA8B;EACxD,MAAM,MAAM,KAAK,YAAY;EAC7B,MAAM,OAAO,IAAI,IAAI,GAAG;EACxB,IAAI,QAAQ,KAAK,SAAS,MAAM,IAAI,OAAO,GAAG;OACzC,IAAI,IAAI,KAAK;GAAE;GAAM;EAAK,CAAC;CAClC;CACA,KAAK,MAAM,UAAU,SAAS;EAC5B,KAAK,MAAM,QAAQ,OAAO,SAAS,KAAK,MAAM,SAAS;EACvD,KAAK,MAAM,QAAQ,OAAO,OAAO,K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@ var BoardWrites = class {
|
|
|
187
187
|
message: `Board "${key}" still has cards; move or delete them first.`,
|
|
188
188
|
cards
|
|
189
189
|
});
|
|
190
|
-
await stored(() => this.deps.storage.delete(scope, key, { expectedRevision }));
|
|
190
|
+
const { intakeRoutes } = await stored(() => this.deps.storage.delete(scope, key, { expectedRevision }));
|
|
191
191
|
this.deps.boards.invalidate(scope);
|
|
192
192
|
await this.#audit(scope, writer, "deleted", row);
|
|
193
|
+
for (const route of intakeRoutes) await writer.audit({
|
|
194
|
+
action: "factory.intake_route.deleted",
|
|
195
|
+
factoryProjectId: scope.factoryProjectId,
|
|
196
|
+
targets: [{
|
|
197
|
+
type: "intake_route",
|
|
198
|
+
id: route.id,
|
|
199
|
+
name: route.name
|
|
200
|
+
}],
|
|
201
|
+
metadata: {
|
|
202
|
+
boardKey: key,
|
|
203
|
+
cause: "board_deleted"
|
|
204
|
+
}
|
|
205
|
+
});
|
|
193
206
|
}
|
|
194
207
|
/** Rewrites a board Factory stores to Factory's current definition of it, at the next revision. */
|
|
195
208
|
async reset(scope, key, { expectedRevision, writer }) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"board-writes.js","names":[],"sources":["../../src/boards/board-writes.ts"],"sourcesContent":["/**\n * Writes to a project's stored boards, shared by the boards API and `MastraFactory#upsertBoard()`.\n *\n * Every write is checked against the rules `defineBoard()` enforces, the skills its runners name,\n * the code behaviour of a code board's copy, and the cards sitting on the board. It then\n * invalidates the project's board cache and records an audit event.\n */\n\nimport type { z } from 'zod';\n\nimport { findBoardSkillProblems } from '../skills/app-skills.js';\nimport type { EmitAuditInput } from '../storage/domains/audit/domain.js';\nimport { StoredBoardError } from '../storage/domains/boards/base.js';\nimport type {\n BoardWriteStep,\n StoredBoardInput,\n StoredBoardRecord,\n StoredBoardScope,\n StoredBoardsStorage,\n StoredPhaseInput,\n} from '../storage/domains/boards/base.js';\nimport type { WorkItemsStorage } from '../storage/domains/work-items/base.js';\nimport { LEGACY_REVIEW_BOARD, ReviewBoardInUseError } from '../storage/domains/work-items/legacy-review.js';\nimport { codeBoardOf } from './define-board.js';\nimport { isUntouchedReviewSeed } from './project-boards.js';\nimport type { ProjectBoardCache } from './project-boards.js';\nimport { boardRegistryOf } from './registry.js';\nimport { boardForWorkItem } from './semantics.js';\nimport {\n codeBehaviourConflicts,\n compileStoredBoard,\n sameBoardDefinition,\n storedBoardInputSchema,\n} from './stored-board.js';\nimport { workBoard } from './work.js';\n\nexport interface BoardWritesDeps {\n storage: StoredBoardsStorage;\n /** The per-project boards: the code boards and their seeds, skills, and the cache to invalidate. */\n boards: Pick<ProjectBoardCache, 'describe' | 'invalidate' | 'codeRegistry' | 'codeSkills' | 'seedFor'>;\n /** Read to refuse edits that would strand cards; the retired Review board's cards leave `review` through it. */\n workItems: Pick<WorkItemsStorage, 'listShared' | 'releaseReviewCards'>;\n}\n\n/** Who writes: stored as the board's author, and the audit event's actor. */\nexport interface BoardWriter {\n id: string;\n audit(input: EmitAuditInput): Promise<void>;\n}\n\n/** A refused board write. `status` and `body` are what the boards API answers with. */\nexport class BoardWriteError extends Error {\n override name = 'BoardWriteError';\n constructor(\n readonly status: 404 | 409 | 422,\n readonly body: { error: string; message?: string } & Record<string, unknown>,\n ) {\n super(body.message ?? body.error);\n }\n\n get code(): string {\n return this.body.error;\n }\n}\n\nexport function issueMessage(issues: readonly z.core.$ZodIssue[]): string {\n return issues\n .map(issue => (issue.path.length > 0 ? `${issue.path.join('.')}: ${issue.message}` : issue.message))\n .join('; ');\n}\n\nconst UNKNOWN_SKILL = 'but no such skill exists';\nconst UPSERT_ATTEMPTS = 3;\n\n/** Storage refusals (a stale revision, a missing or existing board) as board write errors. */\nasync function stored<T>(write: () => Promise<T>): Promise<T> {\n try {\n return await write();\n } catch (error) {\n if (error instanceof StoredBoardError) {\n throw new BoardWriteError(error.code === 'board_not_found' ? 404 : 409, {\n error: error.code,\n message: error.message,\n });\n }\n if (error instanceof ReviewBoardInUseError) {\n throw new BoardWriteError(409, { error: 'board_in_use', message: error.message, cards: error.cards });\n }\n throw error;\n }\n}\n\nexport class BoardWrites {\n constructor(private readonly deps: BoardWritesDeps) {}\n\n /**\n * Code boards can't be created over, and Work can't be deleted while its code handlers run by its\n * key.\n */\n refuseCodeBoard(key: string, action: 'create' | 'edit' | 'delete'): void {\n const { boards } = this.deps;\n const code = boards.codeRegistry.get(key);\n if (!code) return;\n const stored = boards.seedFor(key) !== undefined;\n if (action === 'edit' && stored) return;\n if (action === 'delete' && stored && codeBoardOf(code) !== workBoard) return;\n throw new BoardWriteError(409, {\n error: 'code_board',\n message:\n action === 'delete' && stored\n ? `Board \"${key}\" is defined in code and can't be deleted; reset it to its default instead.`\n : `Board \"${key}\" is defined in code and can't be ${action === 'create' ? 'created over' : 'changed'} here.`,\n });\n }\n\n async existing(scope: StoredBoardScope, key: string): Promise<StoredBoardRecord> {\n const row = await this.deps.storage.get(scope, key);\n if (!row) throw new BoardWriteError(404, { error: 'board_not_found', message: `Board \"${key}\" does not exist.` });\n return row;\n }\n\n /**\n * Validates a definition the way `defineBoard()` does, plus the skills its runners name. A code\n * board's copy is also checked against the code behaviour of its board and phase keys.\n */\n validate(input: unknown): StoredBoardInput {\n const { boards } = this.deps;\n const parsed = storedBoardInputSchema.safeParse(input);\n if (!parsed.success) {\n throw new BoardWriteError(422, { error: 'invalid_board', message: issueMessage(parsed.error.issues) });\n }\n const code = boards.seedFor(parsed.data.key) && boards.codeRegistry.get(parsed.data.key);\n if (code) {\n const conflicts = codeBehaviourConflicts(parsed.data, code);\n if (conflicts.length > 0) {\n throw new BoardWriteError(422, { error: 'code_behaviour', message: conflicts.join(' '), conflicts });\n }\n }\n const board = code ? compileStoredBoard(parsed.data, code) : compileStoredBoard(parsed.data);\n const problems = findBoardSkillProblems(boardRegistryOf([board]), boards.codeSkills);\n const unknown = problems.filter(problem => problem.includes(UNKNOWN_SKILL));\n if (unknown.length > 0) throw new BoardWriteError(422, { error: 'unknown_skill', message: unknown.join(' ') });\n return parsed.data;\n }\n\n /** Creates a board under a key no code board uses. */\n async create(scope: StoredBoardScope, input: unknown, writer: BoardWriter): Promise<StoredBoardRecord> {\n const key = (input as { key?: unknown } | null)?.key;\n if (typeof key === 'string') this.refuseCodeBoard(key, 'create');\n const board = this.validate(input);\n // Factory stores its boards only into a project that has none, so they go in first.\n await this.deps.boards.describe(scope);\n const row = await stored(() =>\n this.deps.storage.create(\n scope,\n board,\n writer.id,\n this.#takeReviewKey(scope, board.key, null),\n // The row an earlier release seeded for the retired Review board is nobody's board.\n board.key === LEGACY_REVIEW_BOARD ? isUntouchedReviewSeed : undefined,\n ),\n );\n this.deps.boards.invalidate(scope);\n await this.#audit(scope, writer, 'created', board);\n return row;\n }\n\n /**\n * Stores a validated board in a project, after its first load stored Factory's boards: creates\n * it when the project has none under its key, and otherwise replaces the project's board, edited\n * or not, at its current revision, with the same checks as an edit. A write that loses a race\n * with another one rereads and tries again.\n */\n async upsert(\n scope: StoredBoardScope,\n board: StoredBoardInput,\n writer: BoardWriter,\n ): Promise<'inserted' | 'updated' | 'unchanged'> {\n const { storage, boards } = this.deps;\n await boards.describe(scope);\n for (let attempt = 1; ; attempt++) {\n const row = await storage.get(scope, board.key);\n try {\n if (!row) {\n const inserted = await stored(() =>\n storage.insertIfMissing(scope, board, writer.id, this.#takeReviewKey(scope, board.key, null)),\n );\n if (!inserted) {\n throw new BoardWriteError(409, {\n error: 'revision_mismatch',\n message: `Board \"${board.key}\" was stored by another write; try again.`,\n });\n }\n boards.invalidate(scope);\n await this.#audit(scope, writer, 'created', board);\n return 'inserted';\n }\n const { key, ...definition } = board;\n const { written } = await this.replace(scope, key, definition, { expectedRevision: row.revision, writer });\n return written ? 'updated' : 'unchanged';\n } catch (error) {\n const lost =\n error instanceof BoardWriteError && (error.code === 'revision_mismatch' || error.code === 'board_not_found');\n if (!lost || attempt >= UPSERT_ATTEMPTS) throw error;\n }\n }\n }\n\n /**\n * Replaces a board's definition at `expectedRevision`. Saving it unchanged writes nothing;\n * `written` says whether anything was stored.\n */\n async replace(\n scope: StoredBoardScope,\n key: string,\n definition: Omit<StoredBoardInput, 'key'>,\n { expectedRevision, writer }: { expectedRevision: number; writer: BoardWriter },\n ): Promise<{ row: StoredBoardRecord; written: boolean }> {\n const { storage, boards } = this.deps;\n this.refuseCodeBoard(key, 'edit');\n const seed = boards.seedFor(key);\n // The project's first load stores Factory's boards.\n if (seed) await boards.describe(scope);\n const row = await this.existing(scope, key);\n const input = this.validate({ key, ...definition });\n if (row.revision === expectedRevision && sameBoardDefinition(row, input)) {\n return { row, written: false };\n }\n const takeKey = this.#takeReviewKey(scope, key, row);\n // No card is on a seed nobody made into a board: the ones stored there are the retired board's.\n if (!takeKey) await this.#checkPhasesFree(scope, row, input.phases);\n const { key: _key, ...replacement } = input;\n const replaced = await stored(() =>\n storage.replace(scope, key, replacement, {\n expectedRevision,\n actor: writer.id,\n before: takeKey,\n }),\n );\n boards.invalidate(scope);\n await this.#audit(scope, writer, 'updated', input);\n return { row: replaced, written: true };\n }\n\n /** Deletes a stored board that no card sits on. */\n async remove(\n scope: StoredBoardScope,\n key: string,\n { expectedRevision, writer }: { expectedRevision: number; writer: BoardWriter },\n ): Promise<void> {\n this.refuseCodeBoard(key, 'delete');\n // The project's first load stores Factory's boards.\n if (this.deps.boards.seedFor(key)) await this.deps.boards.describe(scope);\n const row = await this.existing(scope, key);\n const { cards } = await this.#occupancy(scope, key);\n if (cards > 0) {\n throw new BoardWriteError(409, {\n error: 'board_in_use',\n message: `Board \"${key}\" still has cards; move or delete them first.`,\n cards,\n });\n }\n await stored(() => this.deps.storage.delete(scope, key, { expectedRevision }));\n this.deps.boards.invalidate(scope);\n await this.#audit(scope, writer, 'deleted', row);\n }\n\n /** Rewrites a board Factory stores to Factory's current definition of it, at the next revision. */\n async reset(\n scope: StoredBoardScope,\n key: string,\n { expectedRevision, writer }: { expectedRevision: number; writer: BoardWriter },\n ): Promise<StoredBoardRecord> {\n const { storage, boards } = this.deps;\n const seed = boards.seedFor(key);\n if (!seed) {\n this.refuseCodeBoard(key, 'edit');\n await this.existing(scope, key);\n throw new BoardWriteError(409, {\n error: 'not_code_board',\n message: `Board \"${key}\" was created in this project and has no default to reset to.`,\n });\n }\n await boards.describe(scope);\n const row = await this.existing(scope, key);\n // A board the app upserts for every project resets to the app's. Factory's Work resets to the\n // Work the project was stored with: today's for a project Factory created with it, Work with\n // Triage for every other.\n const definition = boards.seedFor(key, row) ?? seed;\n await this.#checkPhasesFree(scope, row, definition.phases);\n const reset = await stored(() => storage.resetTo(scope, key, definition, { expectedRevision, actor: writer.id }));\n boards.invalidate(scope);\n await this.#audit(scope, writer, 'reset', row);\n return reset;\n }\n\n /**\n * What a write does first, in its transaction, when it gives the project a board of its own\n * under `review` (none is stored, or only the seed an earlier release left): the cards the\n * retired Review board left stored there get their Work placement, so the new board starts\n * empty. Refused while one of them is still open.\n */\n #takeReviewKey(scope: StoredBoardScope, key: string, row: StoredBoardRecord | null): BoardWriteStep | undefined {\n if (key !== LEGACY_REVIEW_BOARD || (row && !isUntouchedReviewSeed(row))) return undefined;\n return ops => this.deps.workItems.releaseReviewCards(ops, scope, { open: 'refuse' });\n }\n\n /** The cards on a board, and how many sit in each phase. */\n async #occupancy(scope: StoredBoardScope, key: string): Promise<{ cards: number; phases: Map<string, number> }> {\n const phases = new Map<string, number>();\n let cards = 0;\n for (const item of await this.deps.workItems.listShared(scope)) {\n if (boardForWorkItem(item) !== key) continue;\n cards++;\n for (const stage of new Set(item.stages)) phases.set(stage, (phases.get(stage) ?? 0) + 1);\n }\n return { cards, phases };\n }\n\n /** Refuses a change that removes, or changes the kind of, a phase cards sit in. */\n async #checkPhasesFree(\n scope: StoredBoardScope,\n row: StoredBoardRecord,\n next: readonly StoredPhaseInput[],\n ): Promise<void> {\n const kinds = new Map(next.map(phase => [phase.key, phase.kind]));\n const changed = row.phases.filter(phase => kinds.get(phase.key) !== phase.kind).map(phase => phase.key);\n if (changed.length === 0) return;\n const occupancy = (await this.#occupancy(scope, row.key)).phases;\n const inUse = Object.fromEntries(changed.flatMap(key => (occupancy.get(key) ? [[key, occupancy.get(key)!]] : [])));\n if (Object.keys(inUse).length === 0) return;\n throw new BoardWriteError(409, {\n error: 'phase_in_use',\n message: `Cards sit in ${Object.entries(inUse)\n .map(([key, count]) => `\"${key}\" (${count})`)\n .join(', ')}; move them before removing those phases or changing their kind.`,\n phases: inUse,\n });\n }\n\n async #audit(\n scope: StoredBoardScope,\n writer: BoardWriter,\n action: 'created' | 'updated' | 'deleted' | 'reset',\n board: { key: string; name: string },\n ): Promise<void> {\n await writer.audit({\n action: `factory.board.${action}`,\n factoryProjectId: scope.factoryProjectId,\n targets: [{ type: 'board', id: board.key, name: board.name }],\n });\n }\n}\n"],"mappings":";;;;;;;;;;;AAmDA,IAAa,kBAAb,cAAqC,MAAM;CAG9B;CACA;CAHX,OAAgB;CAChB,YACE,QACA,MACA;EACA,MAAM,KAAK,WAAW,KAAK,KAAK;EAHvB,KAAA,SAAA;EACA,KAAA,OAAA;CAGX;CAEA,IAAI,OAAe;EACjB,OAAO,KAAK,KAAK;CACnB;AACF;AAEA,SAAgB,aAAa,QAA6C;CACxE,OAAO,OACJ,KAAI,UAAU,MAAM,KAAK,SAAS,IAAI,GAAG,MAAM,KAAK,KAAK,GAAG,EAAE,IAAI,MAAM,YAAY,MAAM,OAAQ,CAAC,CACnG,KAAK,IAAI;AACd;AAEA,MAAM,gBAAgB;AACtB,MAAM,kBAAkB;;AAGxB,eAAe,OAAU,OAAqC;CAC5D,IAAI;EACF,OAAO,MAAM,MAAM;CACrB,SAAS,OAAO;EACd,IAAI,iBAAiB,kBACnB,MAAM,IAAI,gBAAgB,MAAM,SAAS,oBAAoB,MAAM,KAAK;GACtE,OAAO,MAAM;GACb,SAAS,MAAM;EACjB,CAAC;EAEH,IAAI,iBAAiB,uBACnB,MAAM,IAAI,gBAAgB,KAAK;GAAE,OAAO;GAAgB,SAAS,MAAM;GAAS,OAAO,MAAM;EAAM,CAAC;E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AQ;EACV,CAAC;CACH;CAEA,MAAM,OACJ,OACA,QACA,QACA,OACe;EACf,MAAM,OAAO,MAAM;GACjB,QAAQ,iBAAiB;GACzB,kBAAkB,MAAM;GACxB,SAAS,CAAC;IAAE,MAAM;IAAS,IAAI,MAAM;IAAK,MAAM,MAAM;GAAK,CAAC;EAC9D,CAAC;CACH;AACF"}
|
|
1
|
+
{"version":3,"file":"board-writes.js","names":[],"sources":["../../src/boards/board-writes.ts"],"sourcesContent":["/**\n * Writes to a project's stored boards, shared by the boards API and `MastraFactory#upsertBoard()`.\n *\n * Every write is checked against the rules `defineBoard()` enforces, the skills its runners name,\n * the code behaviour of a code board's copy, and the cards sitting on the board. It then\n * invalidates the project's board cache and records an audit event.\n */\n\nimport type { z } from 'zod';\nimport { findBoardSkillProblems } from '../skills/app-skills.js';\n\nimport type { EmitAuditInput } from '../storage/domains/audit/domain.js';\nimport { StoredBoardError } from '../storage/domains/boards/base.js';\nimport type {\n BoardWriteStep,\n StoredBoardInput,\n StoredBoardRecord,\n StoredBoardScope,\n StoredBoardsStorage,\n StoredPhaseInput,\n} from '../storage/domains/boards/base.js';\nimport type { WorkItemsStorage } from '../storage/domains/work-items/base.js';\nimport { LEGACY_REVIEW_BOARD, ReviewBoardInUseError } from '../storage/domains/work-items/legacy-review.js';\nimport { codeBoardOf } from './define-board.js';\nimport { isUntouchedReviewSeed } from './project-boards.js';\nimport type { ProjectBoardCache } from './project-boards.js';\nimport { boardRegistryOf } from './registry.js';\nimport { boardForWorkItem } from './semantics.js';\nimport {\n codeBehaviourConflicts,\n compileStoredBoard,\n sameBoardDefinition,\n storedBoardInputSchema,\n} from './stored-board.js';\nimport { workBoard } from './work.js';\n\nexport interface BoardWritesDeps {\n storage: StoredBoardsStorage;\n /** The per-project boards: the code boards and their seeds, skills, and the cache to invalidate. */\n boards: Pick<ProjectBoardCache, 'describe' | 'invalidate' | 'codeRegistry' | 'codeSkills' | 'seedFor'>;\n /** Read to refuse edits that would strand cards; the retired Review board's cards leave `review` through it. */\n workItems: Pick<WorkItemsStorage, 'listShared' | 'releaseReviewCards'>;\n}\n\n/** Who writes: stored as the board's author, and the audit event's actor. */\nexport interface BoardWriter {\n id: string;\n audit(input: EmitAuditInput): Promise<void>;\n}\n\n/** A refused board write. `status` and `body` are what the boards API answers with. */\nexport class BoardWriteError extends Error {\n override name = 'BoardWriteError';\n constructor(\n readonly status: 404 | 409 | 422,\n readonly body: { error: string; message?: string } & Record<string, unknown>,\n ) {\n super(body.message ?? body.error);\n }\n\n get code(): string {\n return this.body.error;\n }\n}\n\nexport function issueMessage(issues: readonly z.core.$ZodIssue[]): string {\n return issues\n .map(issue => (issue.path.length > 0 ? `${issue.path.join('.')}: ${issue.message}` : issue.message))\n .join('; ');\n}\n\nconst UNKNOWN_SKILL = 'but no such skill exists';\nconst UPSERT_ATTEMPTS = 3;\n\n/** Storage refusals (a stale revision, a missing or existing board) as board write errors. */\nasync function stored<T>(write: () => Promise<T>): Promise<T> {\n try {\n return await write();\n } catch (error) {\n if (error instanceof StoredBoardError) {\n throw new BoardWriteError(error.code === 'board_not_found' ? 404 : 409, {\n error: error.code,\n message: error.message,\n });\n }\n if (error instanceof ReviewBoardInUseError) {\n throw new BoardWriteError(409, { error: 'board_in_use', message: error.message, cards: error.cards });\n }\n throw error;\n }\n}\n\nexport class BoardWrites {\n constructor(private readonly deps: BoardWritesDeps) {}\n\n /**\n * Code boards can't be created over, and Work can't be deleted while its code handlers run by its\n * key.\n */\n refuseCodeBoard(key: string, action: 'create' | 'edit' | 'delete'): void {\n const { boards } = this.deps;\n const code = boards.codeRegistry.get(key);\n if (!code) return;\n const stored = boards.seedFor(key) !== undefined;\n if (action === 'edit' && stored) return;\n if (action === 'delete' && stored && codeBoardOf(code) !== workBoard) return;\n throw new BoardWriteError(409, {\n error: 'code_board',\n message:\n action === 'delete' && stored\n ? `Board \"${key}\" is defined in code and can't be deleted; reset it to its default instead.`\n : `Board \"${key}\" is defined in code and can't be ${action === 'create' ? 'created over' : 'changed'} here.`,\n });\n }\n\n async existing(scope: StoredBoardScope, key: string): Promise<StoredBoardRecord> {\n const row = await this.deps.storage.get(scope, key);\n if (!row) throw new BoardWriteError(404, { error: 'board_not_found', message: `Board \"${key}\" does not exist.` });\n return row;\n }\n\n /**\n * Validates a definition the way `defineBoard()` does, plus the skills its runners name. A code\n * board's copy is also checked against the code behaviour of its board and phase keys.\n */\n validate(input: unknown): StoredBoardInput {\n const { boards } = this.deps;\n const parsed = storedBoardInputSchema.safeParse(input);\n if (!parsed.success) {\n throw new BoardWriteError(422, { error: 'invalid_board', message: issueMessage(parsed.error.issues) });\n }\n const code = boards.seedFor(parsed.data.key) && boards.codeRegistry.get(parsed.data.key);\n if (code) {\n const conflicts = codeBehaviourConflicts(parsed.data, code);\n if (conflicts.length > 0) {\n throw new BoardWriteError(422, { error: 'code_behaviour', message: conflicts.join(' '), conflicts });\n }\n }\n const board = code ? compileStoredBoard(parsed.data, code) : compileStoredBoard(parsed.data);\n const problems = findBoardSkillProblems(boardRegistryOf([board]), boards.codeSkills);\n const unknown = problems.filter(problem => problem.includes(UNKNOWN_SKILL));\n if (unknown.length > 0) throw new BoardWriteError(422, { error: 'unknown_skill', message: unknown.join(' ') });\n return parsed.data;\n }\n\n /** Creates a board under a key no code board uses. */\n async create(scope: StoredBoardScope, input: unknown, writer: BoardWriter): Promise<StoredBoardRecord> {\n const key = (input as { key?: unknown } | null)?.key;\n if (typeof key === 'string') this.refuseCodeBoard(key, 'create');\n const board = this.validate(input);\n // Factory stores its boards only into a project that has none, so they go in first.\n await this.deps.boards.describe(scope);\n const row = await stored(() =>\n this.deps.storage.create(\n scope,\n board,\n writer.id,\n this.#takeReviewKey(scope, board.key, null),\n // The row an earlier release seeded for the retired Review board is nobody's board.\n board.key === LEGACY_REVIEW_BOARD ? isUntouchedReviewSeed : undefined,\n ),\n );\n this.deps.boards.invalidate(scope);\n await this.#audit(scope, writer, 'created', board);\n return row;\n }\n\n /**\n * Stores a validated board in a project, after its first load stored Factory's boards: creates\n * it when the project has none under its key, and otherwise replaces the project's board, edited\n * or not, at its current revision, with the same checks as an edit. A write that loses a race\n * with another one rereads and tries again.\n */\n async upsert(\n scope: StoredBoardScope,\n board: StoredBoardInput,\n writer: BoardWriter,\n ): Promise<'inserted' | 'updated' | 'unchanged'> {\n const { storage, boards } = this.deps;\n await boards.describe(scope);\n for (let attempt = 1; ; attempt++) {\n const row = await storage.get(scope, board.key);\n try {\n if (!row) {\n const inserted = await stored(() =>\n storage.insertIfMissing(scope, board, writer.id, this.#takeReviewKey(scope, board.key, null)),\n );\n if (!inserted) {\n throw new BoardWriteError(409, {\n error: 'revision_mismatch',\n message: `Board \"${board.key}\" was stored by another write; try again.`,\n });\n }\n boards.invalidate(scope);\n await this.#audit(scope, writer, 'created', board);\n return 'inserted';\n }\n const { key, ...definition } = board;\n const { written } = await this.replace(scope, key, definition, { expectedRevision: row.revision, writer });\n return written ? 'updated' : 'unchanged';\n } catch (error) {\n const lost =\n error instanceof BoardWriteError && (error.code === 'revision_mismatch' || error.code === 'board_not_found');\n if (!lost || attempt >= UPSERT_ATTEMPTS) throw error;\n }\n }\n }\n\n /**\n * Replaces a board's definition at `expectedRevision`. Saving it unchanged writes nothing;\n * `written` says whether anything was stored.\n */\n async replace(\n scope: StoredBoardScope,\n key: string,\n definition: Omit<StoredBoardInput, 'key'>,\n { expectedRevision, writer }: { expectedRevision: number; writer: BoardWriter },\n ): Promise<{ row: StoredBoardRecord; written: boolean }> {\n const { storage, boards } = this.deps;\n this.refuseCodeBoard(key, 'edit');\n const seed = boards.seedFor(key);\n // The project's first load stores Factory's boards.\n if (seed) await boards.describe(scope);\n const row = await this.existing(scope, key);\n const input = this.validate({ key, ...definition });\n if (row.revision === expectedRevision && sameBoardDefinition(row, input)) {\n return { row, written: false };\n }\n const takeKey = this.#takeReviewKey(scope, key, row);\n // No card is on a seed nobody made into a board: the ones stored there are the retired board's.\n if (!takeKey) await this.#checkPhasesFree(scope, row, input.phases);\n const { key: _key, ...replacement } = input;\n const replaced = await stored(() =>\n storage.replace(scope, key, replacement, {\n expectedRevision,\n actor: writer.id,\n before: takeKey,\n }),\n );\n boards.invalidate(scope);\n await this.#audit(scope, writer, 'updated', input);\n return { row: replaced, written: true };\n }\n\n /** Deletes a stored board that no card sits on. */\n async remove(\n scope: StoredBoardScope,\n key: string,\n { expectedRevision, writer }: { expectedRevision: number; writer: BoardWriter },\n ): Promise<void> {\n this.refuseCodeBoard(key, 'delete');\n // The project's first load stores Factory's boards.\n if (this.deps.boards.seedFor(key)) await this.deps.boards.describe(scope);\n const row = await this.existing(scope, key);\n const { cards } = await this.#occupancy(scope, key);\n if (cards > 0) {\n throw new BoardWriteError(409, {\n error: 'board_in_use',\n message: `Board \"${key}\" still has cards; move or delete them first.`,\n cards,\n });\n }\n const { intakeRoutes } = await stored(() => this.deps.storage.delete(scope, key, { expectedRevision }));\n this.deps.boards.invalidate(scope);\n await this.#audit(scope, writer, 'deleted', row);\n for (const route of intakeRoutes) {\n await writer.audit({\n action: 'factory.intake_route.deleted',\n factoryProjectId: scope.factoryProjectId,\n targets: [{ type: 'intake_route', id: route.id, name: route.name }],\n metadata: { boardKey: key, cause: 'board_deleted' },\n });\n }\n }\n\n /** Rewrites a board Factory stores to Factory's current definition of it, at the next revision. */\n async reset(\n scope: StoredBoardScope,\n key: string,\n { expectedRevision, writer }: { expectedRevision: number; writer: BoardWriter },\n ): Promise<StoredBoardRecord> {\n const { storage, boards } = this.deps;\n const seed = boards.seedFor(key);\n if (!seed) {\n this.refuseCodeBoard(key, 'edit');\n await this.existing(scope, key);\n throw new BoardWriteError(409, {\n error: 'not_code_board',\n message: `Board \"${key}\" was created in this project and has no default to reset to.`,\n });\n }\n await boards.describe(scope);\n const row = await this.existing(scope, key);\n // A board the app upserts for every project resets to the app's. Factory's Work resets to the\n // Work the project was stored with: today's for a project Factory created with it, Work with\n // Triage for every other.\n const definition = boards.seedFor(key, row) ?? seed;\n await this.#checkPhasesFree(scope, row, definition.phases);\n const reset = await stored(() => storage.resetTo(scope, key, definition, { expectedRevision, actor: writer.id }));\n boards.invalidate(scope);\n await this.#audit(scope, writer, 'reset', row);\n return reset;\n }\n\n /**\n * What a write does first, in its transaction, when it gives the project a board of its own\n * under `review` (none is stored, or only the seed an earlier release left): the cards the\n * retired Review board left stored there get their Work placement, so the new board starts\n * empty. Refused while one of them is still open.\n */\n #takeReviewKey(scope: StoredBoardScope, key: string, row: StoredBoardRecord | null): BoardWriteStep | undefined {\n if (key !== LEGACY_REVIEW_BOARD || (row && !isUntouchedReviewSeed(row))) return undefined;\n return ops => this.deps.workItems.releaseReviewCards(ops, scope, { open: 'refuse' });\n }\n\n /** The cards on a board, and how many sit in each phase. */\n async #occupancy(scope: StoredBoardScope, key: string): Promise<{ cards: number; phases: Map<string, number> }> {\n const phases = new Map<string, number>();\n let cards = 0;\n for (const item of await this.deps.workItems.listShared(scope)) {\n if (boardForWorkItem(item) !== key) continue;\n cards++;\n for (const stage of new Set(item.stages)) phases.set(stage, (phases.get(stage) ?? 0) + 1);\n }\n return { cards, phases };\n }\n\n /** Refuses a change that removes, or changes the kind of, a phase cards sit in. */\n async #checkPhasesFree(\n scope: StoredBoardScope,\n row: StoredBoardRecord,\n next: readonly StoredPhaseInput[],\n ): Promise<void> {\n const kinds = new Map(next.map(phase => [phase.key, phase.kind]));\n const changed = row.phases.filter(phase => kinds.get(phase.key) !== phase.kind).map(phase => phase.key);\n if (changed.length === 0) return;\n const occupancy = (await this.#occupancy(scope, row.key)).phases;\n const inUse = Object.fromEntries(changed.flatMap(key => (occupancy.get(key) ? [[key, occupancy.get(key)!]] : [])));\n if (Object.keys(inUse).length === 0) return;\n throw new BoardWriteError(409, {\n error: 'phase_in_use',\n message: `Cards sit in ${Object.entries(inUse)\n .map(([key, count]) => `\"${key}\" (${count})`)\n .join(', ')}; move them before removing those phases or changing their kind.`,\n phases: inUse,\n });\n }\n\n async #audit(\n scope: StoredBoardScope,\n writer: BoardWriter,\n action: 'created' | 'updated' | 'deleted' | 'reset',\n board: { key: string; name: string },\n ): Promise<void> {\n await writer.audit({\n action: `factory.board.${action}`,\n factoryProjectId: scope.factoryProjectId,\n targets: [{ type: 'board', id: board.key, name: board.name }],\n });\n }\n}\n"],"mappings":";;;;;;;;;;;AAmDA,IAAa,kBAAb,cAAqC,MAAM;CAG9B;CACA;CAHX,OAAgB;CAChB,YACE,QACA,MACA;EACA,MAAM,KAAK,WAAW,KAAK,KAAK;EAHvB,KAAA,SAAA;EACA,KAAA,OAAA;CAGX;CAEA,IAAI,OAAe;EACjB,OAAO,KAAK,KAAK;CACnB;AACF;AAEA,SAAgB,aAAa,QAA6C;CACxE,OAAO,OACJ,KAAI,UAAU,MAAM,KAAK,SAAS,IAAI,GAAG,MAAM,KAAK,KAAK,GAAG,EAAE,IAAI,MAAM,YAAY,MAAM,OAAQ,CAAC,CACnG,KAAK,IAAI;AACd;AAEA,MAAM,gBAAgB;AACtB,MAAM,kBAAkB;;AAGxB,eAAe,OAAU,OAAqC;CAC5D,IAAI;EACF,OAAO,MAAM,MAAM;CACrB,SAAS,OAAO;EACd,IAAI,iBAAiB,kBACnB,MAAM,IAAI,gBAAgB,MAAM,SAAS,oBAAoB,MAAM,KAAK;GACtE,OAAO,MAAM;GACb,SAAS,MAAM;EACjB,CAAC;EAEH,IAAI,iBAAiB,uBACnB,MAAM,IAAI,gBAAgB,KAAK;GAAE,OAAO;GAAgB,SAAS,MAAM;GAAS,OAAO,MAAM;EAAM,CAAC;EAEtG,MAAM;CACR;AACF;AAEA,IAAa,cAAb,MAAyB;CACM;CAA7B,YAAY,MAAwC;EAAvB,KAAA,OAAA;CAAwB;;;;;CAMrD,gBAAgB,KAAa,QAA4C;EACvE,MAAM,EAAE,WAAW,KAAK;EACxB,MAAM,OAAO,OAAO,aAAa,IAAI,GAAG;EACxC,IAAI,CAAC,MAAM;EACX,MAAM,SAAS,OAAO,QAAQ,GAAG,MAAM,KAAA;EACvC,IAAI,WAAW,UAAU,QAAQ;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