@mastra/factory 0.27.0-alpha.1 → 0.27.0-alpha.2
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 +91 -9
- package/dist/boards/card-facts.d.ts +1 -1
- package/dist/boards/card-facts.d.ts.map +1 -1
- package/dist/boards/card-facts.js +3 -1
- package/dist/boards/card-facts.js.map +1 -1
- package/dist/boards/index.d.ts +2 -2
- package/dist/boards/index.d.ts.map +1 -1
- package/dist/boards/index.js +2 -2
- package/dist/boards/index.js.map +1 -1
- package/dist/boards/intake-routing.d.ts +37 -0
- package/dist/boards/intake-routing.d.ts.map +1 -0
- package/dist/boards/intake-routing.js +70 -0
- package/dist/boards/intake-routing.js.map +1 -0
- package/dist/boards/pull-request-review.d.ts +21 -0
- package/dist/boards/pull-request-review.d.ts.map +1 -0
- package/dist/boards/pull-request-review.js +80 -0
- package/dist/boards/pull-request-review.js.map +1 -0
- package/dist/boards/review.d.ts +0 -2
- package/dist/boards/review.d.ts.map +1 -1
- package/dist/boards/review.js +2 -76
- package/dist/boards/review.js.map +1 -1
- package/dist/boards/semantics.d.ts +20 -0
- package/dist/boards/semantics.d.ts.map +1 -1
- package/dist/boards/semantics.js +21 -1
- package/dist/boards/semantics.js.map +1 -1
- package/dist/boards/work-transition-policy.d.ts.map +1 -1
- package/dist/boards/work-transition-policy.js +22 -0
- package/dist/boards/work-transition-policy.js.map +1 -1
- package/dist/boards/work.d.ts +2 -2
- package/dist/boards/work.d.ts.map +1 -1
- package/dist/boards/work.js +12 -0
- package/dist/boards/work.js.map +1 -1
- package/dist/factory.d.ts +4 -2
- package/dist/factory.d.ts.map +1 -1
- package/dist/factory.js +18 -27
- package/dist/factory.js.map +1 -1
- package/dist/integrations/github/default-rules.d.ts +14 -14
- package/dist/integrations/github/default-rules.d.ts.map +1 -1
- package/dist/integrations/github/default-rules.js +36 -21
- package/dist/integrations/github/default-rules.js.map +1 -1
- package/dist/integrations/github/rules.d.ts.map +1 -1
- package/dist/integrations/github/rules.js +2 -0
- package/dist/integrations/github/rules.js.map +1 -1
- package/dist/integrations/gitlab/default-rules.d.ts +7 -7
- package/dist/integrations/gitlab/default-rules.d.ts.map +1 -1
- package/dist/integrations/gitlab/default-rules.js +28 -14
- package/dist/integrations/gitlab/default-rules.js.map +1 -1
- package/dist/integrations/gitlab/rules.js.map +1 -1
- package/dist/packages/_internals/workspace/dist/index.js.map +1 -1
- package/dist/routes/boards.js +1 -1
- package/dist/routes/config.d.ts +4 -4
- package/dist/routes/config.d.ts.map +1 -1
- package/dist/routes/config.js +6 -5
- package/dist/routes/config.js.map +1 -1
- package/dist/routes/contracts.d.ts +195 -0
- package/dist/routes/contracts.d.ts.map +1 -1
- package/dist/routes/contracts.js +105 -1
- package/dist/routes/contracts.js.map +1 -1
- package/dist/routes/intake-routes.d.ts +28 -0
- package/dist/routes/intake-routes.d.ts.map +1 -0
- package/dist/routes/intake-routes.js +199 -0
- package/dist/routes/intake-routes.js.map +1 -0
- package/dist/routes/intake.d.ts.map +1 -1
- package/dist/routes/intake.js +9 -0
- package/dist/routes/intake.js.map +1 -1
- package/dist/routes/surface.d.ts.map +1 -1
- package/dist/routes/surface.js +14 -3
- package/dist/routes/surface.js.map +1 -1
- package/dist/routes/work-items.d.ts +3 -0
- package/dist/routes/work-items.d.ts.map +1 -1
- package/dist/routes/work-items.js +1 -0
- package/dist/routes/work-items.js.map +1 -1
- package/dist/rules/dispatcher.d.ts +4 -1
- package/dist/rules/dispatcher.d.ts.map +1 -1
- package/dist/rules/dispatcher.js +96 -17
- package/dist/rules/dispatcher.js.map +1 -1
- package/dist/rules/processor.d.ts.map +1 -1
- package/dist/rules/processor.js +5 -2
- package/dist/rules/processor.js.map +1 -1
- package/dist/rules/rule-group.d.ts +1 -1
- package/dist/rules/rule-group.d.ts.map +1 -1
- package/dist/rules/rule-group.js +1 -0
- package/dist/rules/rule-group.js.map +1 -1
- package/dist/rules/tools.d.ts.map +1 -1
- package/dist/rules/tools.js +11 -5
- package/dist/rules/tools.js.map +1 -1
- package/dist/rules/transition-service.d.ts.map +1 -1
- package/dist/rules/transition-service.js +2 -7
- package/dist/rules/transition-service.js.map +1 -1
- package/dist/rules/types.d.ts +3 -1
- package/dist/rules/types.d.ts.map +1 -1
- package/dist/rules/types.js +7 -3
- package/dist/rules/types.js.map +1 -1
- package/dist/session/self-review-gate.d.ts +13 -0
- package/dist/session/self-review-gate.d.ts.map +1 -0
- package/dist/session/self-review-gate.js +37 -0
- package/dist/session/self-review-gate.js.map +1 -0
- package/dist/storage/domains/audit/actions.d.ts +1 -0
- package/dist/storage/domains/audit/actions.d.ts.map +1 -1
- package/dist/storage/domains/audit/actions.js +7 -1
- package/dist/storage/domains/audit/actions.js.map +1 -1
- package/dist/storage/domains/boards/base.d.ts +72 -1
- package/dist/storage/domains/boards/base.d.ts.map +1 -1
- package/dist/storage/domains/boards/base.js +292 -8
- package/dist/storage/domains/boards/base.js.map +1 -1
- package/dist/storage/domains/boards/schemas.d.ts +8 -0
- package/dist/storage/domains/boards/schemas.d.ts.map +1 -1
- package/dist/storage/domains/boards/schemas.js +64 -1
- package/dist/storage/domains/boards/schemas.js.map +1 -1
- package/dist/storage/domains/work-items/base.d.ts.map +1 -1
- package/dist/storage/domains/work-items/base.js +2 -1
- package/dist/storage/domains/work-items/base.js.map +1 -1
- package/dist/tools/permissions.d.ts.map +1 -1
- package/dist/tools/permissions.js +2 -1
- package/dist/tools/permissions.js.map +1 -1
- package/dist/tools/sandbox-tools.d.ts +5 -0
- package/dist/tools/sandbox-tools.d.ts.map +1 -1
- package/dist/tools/sandbox-tools.js +68 -30
- package/dist/tools/sandbox-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 +2 -1
- package/dist/tools/work-item-tools.js.map +1 -1
- package/dist/work-items/create-work-item.d.ts +5 -2
- package/dist/work-items/create-work-item.d.ts.map +1 -1
- package/dist/work-items/create-work-item.js +54 -3
- package/dist/work-items/create-work-item.js.map +1 -1
- package/factory-skills/configure-factory-rules/SKILL.md +1 -1
- package/package.json +9 -9
|
@@ -68,7 +68,62 @@ export interface StoredBoardSnapshot {
|
|
|
68
68
|
version: string | null;
|
|
69
69
|
boards: StoredBoardRecord[];
|
|
70
70
|
}
|
|
71
|
-
export
|
|
71
|
+
export interface IntakeRouteTarget {
|
|
72
|
+
boardKey: string;
|
|
73
|
+
/** Unset lands the card in the board's first phase. */
|
|
74
|
+
phaseKey?: string | null;
|
|
75
|
+
}
|
|
76
|
+
/** An intake route as it is written. */
|
|
77
|
+
export interface StoredIntakeRouteInput {
|
|
78
|
+
name: string;
|
|
79
|
+
enabled?: boolean;
|
|
80
|
+
/** Null matches every card. */
|
|
81
|
+
when?: RuleGroup | null;
|
|
82
|
+
target: IntakeRouteTarget;
|
|
83
|
+
}
|
|
84
|
+
export interface StoredIntakeRouteRecord {
|
|
85
|
+
id: string;
|
|
86
|
+
orgId: string;
|
|
87
|
+
factoryProjectId: string;
|
|
88
|
+
name: string;
|
|
89
|
+
enabled: boolean;
|
|
90
|
+
position: number;
|
|
91
|
+
when: RuleGroup | null;
|
|
92
|
+
target: {
|
|
93
|
+
boardKey: string;
|
|
94
|
+
phaseKey: string | null;
|
|
95
|
+
};
|
|
96
|
+
revision: number;
|
|
97
|
+
createdBy: string;
|
|
98
|
+
createdAt: Date;
|
|
99
|
+
updatedBy: string;
|
|
100
|
+
updatedAt: Date;
|
|
101
|
+
}
|
|
102
|
+
export type StoredBoardErrorCode = 'board_exists' | 'board_not_found' | 'revision_mismatch' | 'intake_route_not_found' | 'intake_route_set_mismatch' | 'intake_route_limit';
|
|
103
|
+
/** A project's most intake routes; a reorder names every one of them. */
|
|
104
|
+
export declare const MAX_INTAKE_ROUTES = 100;
|
|
105
|
+
/**
|
|
106
|
+
* The route every project starts with: a GitHub or GitLab card whose author is outside the
|
|
107
|
+
* write-access circle lands in Work › Intake, where nothing starts until a person moves it.
|
|
108
|
+
* It is a stored route like any other, so admins can see, edit, disable or delete it.
|
|
109
|
+
*/
|
|
110
|
+
export declare const DEFAULT_INTAKE_ROUTE: StoredIntakeRouteInput;
|
|
111
|
+
/**
|
|
112
|
+
* Pull requests are reviewed in Work › PR review. It comes after `DEFAULT_INTAKE_ROUTE`, so a
|
|
113
|
+
* pull request from outside the write-access circle still waits in Intake for a person.
|
|
114
|
+
*/
|
|
115
|
+
export declare const PULL_REQUEST_INTAKE_ROUTE: StoredIntakeRouteInput;
|
|
116
|
+
/**
|
|
117
|
+
* The routes Factory adds to a project, in order, each under a key that never changes. A project
|
|
118
|
+
* gets each one once: a new project gets them all, a project set up earlier gets a route added
|
|
119
|
+
* since at the end of its list, and a route an admin deleted stays deleted.
|
|
120
|
+
*/
|
|
121
|
+
export declare const DEFAULT_INTAKE_ROUTES: readonly {
|
|
122
|
+
key: string;
|
|
123
|
+
route: StoredIntakeRouteInput;
|
|
124
|
+
}[];
|
|
125
|
+
/** Who the default intake routes are created and last updated by. */
|
|
126
|
+
export declare const DEFAULT_INTAKE_ROUTE_ACTOR = "factory";
|
|
72
127
|
export declare class StoredBoardError extends Error {
|
|
73
128
|
readonly code: StoredBoardErrorCode;
|
|
74
129
|
name: string;
|
|
@@ -106,5 +161,21 @@ export declare class StoredBoardsStorage extends FactoryStorageDomain {
|
|
|
106
161
|
delete(scope: StoredBoardScope, key: string, options: {
|
|
107
162
|
expectedRevision: number;
|
|
108
163
|
}): Promise<void>;
|
|
164
|
+
/** The project's intake routes in the order they are tried; Factory's `DEFAULT_INTAKE_ROUTES` are added once each. */
|
|
165
|
+
listIntakeRoutes(scope: StoredBoardScope): Promise<StoredIntakeRouteRecord[]>;
|
|
166
|
+
getIntakeRoute(scope: StoredBoardScope, id: string): Promise<StoredIntakeRouteRecord | null>;
|
|
167
|
+
/** Adds a route after the project's last one. */
|
|
168
|
+
createIntakeRoute(scope: StoredBoardScope, input: StoredIntakeRouteInput, actor: string): Promise<StoredIntakeRouteRecord>;
|
|
169
|
+
/** Changes the fields `patch` names; the route keeps its place in the order. */
|
|
170
|
+
updateIntakeRoute(scope: StoredBoardScope, id: string, patch: Partial<StoredIntakeRouteInput>, options: {
|
|
171
|
+
expectedRevision: number;
|
|
172
|
+
actor: string;
|
|
173
|
+
}): Promise<StoredIntakeRouteRecord>;
|
|
174
|
+
/** Deletes a route; the routes after it move up one place. */
|
|
175
|
+
deleteIntakeRoute(scope: StoredBoardScope, id: string, options: {
|
|
176
|
+
expectedRevision: number;
|
|
177
|
+
}): Promise<void>;
|
|
178
|
+
/** Puts the project's routes in the order of `ids`, which must name every route exactly once. */
|
|
179
|
+
reorderIntakeRoutes(scope: StoredBoardScope, ids: string[], actor: string): Promise<StoredIntakeRouteRecord[]>;
|
|
109
180
|
}
|
|
110
181
|
//# sourceMappingURL=base.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../../../src/storage/domains/boards/base.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAwB,MAAM,sBAAsB,CAAC;AAGlF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;
|
|
1
|
+
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../../../src/storage/domains/boards/base.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAwB,MAAM,sBAAsB,CAAC;AAGlF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAS9D,sCAAsC;AACtC,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,MAAM,CAAC;IACd,gBAAgB,EAAE,MAAM,CAAC;CAC1B;AAED,MAAM,MAAM,eAAe,GAAG,SAAS,GAAG,SAAS,GAAG,UAAU,CAAC;AAEjE,8EAA8E;AAC9E,MAAM,WAAW,iBAAiB;IAChC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAA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;QAAE,gBAAgB,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,GACnD,OAAO,CAAC,uBAAuB,CAAC,CAgBlC;IAED,8DAA8D;IACxD,iBAAiB,CAAC,KAAK,EAAE,gBAAgB,EAAE,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE;QAAE,gBAAgB,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAejH;IAED,iGAAiG;IAC3F,mBAAmB,CAAC,KAAK,EAAE,gBAAgB,EAAE,GAAG,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,uBAAuB,EAAE,CAAC,CAkBnH;CAwEF"}
|
|
@@ -1,7 +1,68 @@
|
|
|
1
|
-
import { FACTORY_BOARDS_SCHEMA, FACTORY_BOARD_DEFINITION_VERSIONS_SCHEMA, FACTORY_BOARD_PHASES_SCHEMA } from "./schemas.js";
|
|
1
|
+
import { FACTORY_BOARDS_SCHEMA, FACTORY_BOARD_DEFINITION_VERSIONS_SCHEMA, FACTORY_BOARD_PHASES_SCHEMA, FACTORY_INTAKE_ROUTES_SCHEMA, FACTORY_INTAKE_ROUTE_LOCKS_SCHEMA } from "./schemas.js";
|
|
2
2
|
import { randomUUID } from "crypto";
|
|
3
3
|
import { FactoryStorageDomain, UniqueViolationError } from "@mastra/core/storage";
|
|
4
4
|
// src/storage/domains/boards/base.ts
|
|
5
|
+
/** A project's most intake routes; a reorder names every one of them. */
|
|
6
|
+
const MAX_INTAKE_ROUTES = 100;
|
|
7
|
+
/**
|
|
8
|
+
* The route every project starts with: a GitHub or GitLab card whose author is outside the
|
|
9
|
+
* write-access circle lands in Work › Intake, where nothing starts until a person moves it.
|
|
10
|
+
* It is a stored route like any other, so admins can see, edit, disable or delete it.
|
|
11
|
+
*/
|
|
12
|
+
const DEFAULT_INTAKE_ROUTE = {
|
|
13
|
+
name: "Outside authors wait in Intake",
|
|
14
|
+
when: {
|
|
15
|
+
operator: "AND",
|
|
16
|
+
conditions: [{
|
|
17
|
+
field: "source.integration",
|
|
18
|
+
operator: "in",
|
|
19
|
+
value: ["github", "gitlab"]
|
|
20
|
+
}, {
|
|
21
|
+
field: "author.trusted",
|
|
22
|
+
operator: "equals",
|
|
23
|
+
value: false
|
|
24
|
+
}]
|
|
25
|
+
},
|
|
26
|
+
target: {
|
|
27
|
+
boardKey: "work",
|
|
28
|
+
phaseKey: "intake"
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Pull requests are reviewed in Work › PR review. It comes after `DEFAULT_INTAKE_ROUTE`, so a
|
|
33
|
+
* pull request from outside the write-access circle still waits in Intake for a person.
|
|
34
|
+
*/
|
|
35
|
+
const PULL_REQUEST_INTAKE_ROUTE = {
|
|
36
|
+
name: "Pull requests go to PR review",
|
|
37
|
+
when: {
|
|
38
|
+
operator: "AND",
|
|
39
|
+
conditions: [{
|
|
40
|
+
field: "source.kind",
|
|
41
|
+
operator: "equals",
|
|
42
|
+
value: "pull_request"
|
|
43
|
+
}]
|
|
44
|
+
},
|
|
45
|
+
target: {
|
|
46
|
+
boardKey: "work",
|
|
47
|
+
phaseKey: "pr-review"
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* The routes Factory adds to a project, in order, each under a key that never changes. A project
|
|
52
|
+
* gets each one once: a new project gets them all, a project set up earlier gets a route added
|
|
53
|
+
* since at the end of its list, and a route an admin deleted stays deleted.
|
|
54
|
+
*/
|
|
55
|
+
const DEFAULT_INTAKE_ROUTES = [{
|
|
56
|
+
key: "outside-authors",
|
|
57
|
+
route: DEFAULT_INTAKE_ROUTE
|
|
58
|
+
}, {
|
|
59
|
+
key: "pull-requests",
|
|
60
|
+
route: PULL_REQUEST_INTAKE_ROUTE
|
|
61
|
+
}];
|
|
62
|
+
/** The defaults a project whose lock row predates `seeded_defaults` was set up with. */
|
|
63
|
+
const ORIGINAL_DEFAULT_KEYS = ["outside-authors"];
|
|
64
|
+
/** Who the default intake routes are created and last updated by. */
|
|
65
|
+
const DEFAULT_INTAKE_ROUTE_ACTOR = "factory";
|
|
5
66
|
var StoredBoardError = class extends Error {
|
|
6
67
|
code;
|
|
7
68
|
name = "StoredBoardError";
|
|
@@ -10,9 +71,18 @@ var StoredBoardError = class extends Error {
|
|
|
10
71
|
this.code = code;
|
|
11
72
|
}
|
|
12
73
|
};
|
|
74
|
+
function seededDefaults(lock) {
|
|
75
|
+
return lock.seeded_defaults ?? ORIGINAL_DEFAULT_KEYS;
|
|
76
|
+
}
|
|
77
|
+
function missingDefaults(lock) {
|
|
78
|
+
const seeded = new Set(seededDefaults(lock));
|
|
79
|
+
return DEFAULT_INTAKE_ROUTES.filter(({ key }) => !seeded.has(key));
|
|
80
|
+
}
|
|
13
81
|
const BOARDS = "factory_boards";
|
|
14
82
|
const PHASES = "factory_board_phases";
|
|
15
83
|
const VERSIONS = "factory_board_definition_versions";
|
|
84
|
+
const INTAKE_ROUTES = "factory_intake_routes";
|
|
85
|
+
const INTAKE_ROUTE_LOCKS = "factory_intake_route_locks";
|
|
16
86
|
const MAX_WRITE_ATTEMPTS = 3;
|
|
17
87
|
function scopeWhere({ orgId, factoryProjectId }) {
|
|
18
88
|
return {
|
|
@@ -66,13 +136,17 @@ var StoredBoardsStorage = class extends FactoryStorageDomain {
|
|
|
66
136
|
await this.ensureCollections([
|
|
67
137
|
FACTORY_BOARDS_SCHEMA,
|
|
68
138
|
FACTORY_BOARD_PHASES_SCHEMA,
|
|
69
|
-
FACTORY_BOARD_DEFINITION_VERSIONS_SCHEMA
|
|
139
|
+
FACTORY_BOARD_DEFINITION_VERSIONS_SCHEMA,
|
|
140
|
+
FACTORY_INTAKE_ROUTES_SCHEMA,
|
|
141
|
+
FACTORY_INTAKE_ROUTE_LOCKS_SCHEMA
|
|
70
142
|
]);
|
|
71
143
|
}
|
|
72
144
|
async dangerouslyClearAll() {
|
|
73
145
|
await this.ops.deleteMany(PHASES, {});
|
|
74
146
|
await this.ops.deleteMany(BOARDS, {});
|
|
75
147
|
await this.ops.deleteMany(VERSIONS, {});
|
|
148
|
+
await this.ops.deleteMany(INTAKE_ROUTES, {});
|
|
149
|
+
await this.ops.deleteMany(INTAKE_ROUTE_LOCKS, {});
|
|
76
150
|
}
|
|
77
151
|
/** The project's current definition version; null before its first board write. */
|
|
78
152
|
async readVersion(scope) {
|
|
@@ -160,18 +234,129 @@ var StoredBoardsStorage = class extends FactoryStorageDomain {
|
|
|
160
234
|
};
|
|
161
235
|
});
|
|
162
236
|
}
|
|
237
|
+
/** The project's intake routes in the order they are tried; Factory's `DEFAULT_INTAKE_ROUTES` are added once each. */
|
|
238
|
+
async listIntakeRoutes(scope) {
|
|
239
|
+
await this.#ensureIntakeRoutes(scope);
|
|
240
|
+
return (await readIntakeRoutes(this.ops, scope)).map(toIntakeRouteRecord);
|
|
241
|
+
}
|
|
242
|
+
async getIntakeRoute(scope, id) {
|
|
243
|
+
const row = await this.ops.findOne(INTAKE_ROUTES, {
|
|
244
|
+
...scopeWhere(scope),
|
|
245
|
+
id
|
|
246
|
+
});
|
|
247
|
+
return row ? toIntakeRouteRecord(row) : null;
|
|
248
|
+
}
|
|
249
|
+
/** Adds a route after the project's last one. */
|
|
250
|
+
async createIntakeRoute(scope, input, actor) {
|
|
251
|
+
const id = randomUUID();
|
|
252
|
+
await this.#ensureIntakeRoutes(scope);
|
|
253
|
+
await this.#transact(async (ops) => {
|
|
254
|
+
const rows = await lockIntakeRoutes(ops, scope);
|
|
255
|
+
if (rows.length >= 100) throw new StoredBoardError("intake_route_limit", `A project can have at most 100 intake routes; delete one first.`);
|
|
256
|
+
await insertIntakeRoute(ops, scope, {
|
|
257
|
+
id,
|
|
258
|
+
input,
|
|
259
|
+
position: rows.reduce((max, row) => Math.max(max, row.position), -1) + 1,
|
|
260
|
+
actor
|
|
261
|
+
});
|
|
262
|
+
});
|
|
263
|
+
return await this.getIntakeRoute(scope, id);
|
|
264
|
+
}
|
|
265
|
+
/** Changes the fields `patch` names; the route keeps its place in the order. */
|
|
266
|
+
async updateIntakeRoute(scope, id, patch, options) {
|
|
267
|
+
await this.#transact(async (ops) => {
|
|
268
|
+
const row = await findIntakeRoute(ops, scope, id);
|
|
269
|
+
checkIntakeRouteRevision(row, options.expectedRevision);
|
|
270
|
+
await updateIntakeRouteRow(ops, row, {
|
|
271
|
+
...patch.name !== void 0 && { name: patch.name },
|
|
272
|
+
...patch.enabled !== void 0 && { enabled: patch.enabled },
|
|
273
|
+
...patch.when !== void 0 && { when_condition: patch.when },
|
|
274
|
+
...patch.target !== void 0 && {
|
|
275
|
+
board_key: patch.target.boardKey,
|
|
276
|
+
phase_key: patch.target.phaseKey ?? null
|
|
277
|
+
},
|
|
278
|
+
updated_by: options.actor
|
|
279
|
+
});
|
|
280
|
+
});
|
|
281
|
+
return await this.getIntakeRoute(scope, id);
|
|
282
|
+
}
|
|
283
|
+
/** Deletes a route; the routes after it move up one place. */
|
|
284
|
+
async deleteIntakeRoute(scope, id, options) {
|
|
285
|
+
await this.#ensureIntakeRoutes(scope);
|
|
286
|
+
await this.#transact(async (ops) => {
|
|
287
|
+
const rows = await lockIntakeRoutes(ops, scope);
|
|
288
|
+
const row = rows.find((route) => route.id === id);
|
|
289
|
+
if (!row) throw intakeRouteNotFound(id);
|
|
290
|
+
checkIntakeRouteRevision(row, options.expectedRevision);
|
|
291
|
+
if (await ops.deleteMany(INTAKE_ROUTES, {
|
|
292
|
+
id: row.id,
|
|
293
|
+
revision: row.revision
|
|
294
|
+
}) === 0) throw new ConcurrentBoardWrite();
|
|
295
|
+
await placeIntakeRoutes(ops, rows.filter((route) => route.id !== row.id));
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
/** Puts the project's routes in the order of `ids`, which must name every route exactly once. */
|
|
299
|
+
async reorderIntakeRoutes(scope, ids, actor) {
|
|
300
|
+
await this.#ensureIntakeRoutes(scope);
|
|
301
|
+
await this.#transact(async (ops) => {
|
|
302
|
+
const rows = await lockIntakeRoutes(ops, scope);
|
|
303
|
+
const byId = new Map(rows.map((row) => [row.id, row]));
|
|
304
|
+
if (ids.length !== rows.length || new Set(ids).size !== ids.length || ids.some((id) => !byId.has(id))) throw new StoredBoardError("intake_route_set_mismatch", "The order must list every intake route of the project exactly once; reload the routes and try again.");
|
|
305
|
+
await placeIntakeRoutes(ops, ids.map((id) => byId.get(id)), actor);
|
|
306
|
+
});
|
|
307
|
+
return this.listIntakeRoutes(scope);
|
|
308
|
+
}
|
|
309
|
+
/**
|
|
310
|
+
* Creates the project's route lock row (see `FACTORY_INTAKE_ROUTE_LOCKS_SCHEMA`) and adds each of
|
|
311
|
+
* `DEFAULT_INTAKE_ROUTES` the row doesn't list as added yet, after the project's routes. The row
|
|
312
|
+
* records every default it added, so a project whose admin deleted one doesn't get it back. Runs
|
|
313
|
+
* before, never inside, a write's transaction: the lock taken there must always be an update.
|
|
314
|
+
*/
|
|
315
|
+
async #ensureIntakeRoutes(scope) {
|
|
316
|
+
const lock = await this.ops.findOne(INTAKE_ROUTE_LOCKS, scopeWhere(scope));
|
|
317
|
+
if (lock && missingDefaults(lock).length === 0) return;
|
|
318
|
+
await this.#transact(async (ops) => {
|
|
319
|
+
if (await ops.findOne(INTAKE_ROUTE_LOCKS, scopeWhere(scope))) await lockIntakeRoutes(ops, scope);
|
|
320
|
+
else await ops.insertOne(INTAKE_ROUTE_LOCKS, {
|
|
321
|
+
...scopeWhere(scope),
|
|
322
|
+
locked_at: /* @__PURE__ */ new Date(),
|
|
323
|
+
seeded_defaults: []
|
|
324
|
+
});
|
|
325
|
+
const current = await ops.findOne(INTAKE_ROUTE_LOCKS, scopeWhere(scope));
|
|
326
|
+
const missing = missingDefaults(current);
|
|
327
|
+
if (missing.length === 0) return;
|
|
328
|
+
let position = (await readIntakeRoutes(ops, scope)).reduce((max, row) => Math.max(max, row.position), -1) + 1;
|
|
329
|
+
for (const { route } of missing) {
|
|
330
|
+
if (position >= 100) break;
|
|
331
|
+
await insertIntakeRoute(ops, scope, {
|
|
332
|
+
id: randomUUID(),
|
|
333
|
+
input: route,
|
|
334
|
+
position: position++,
|
|
335
|
+
actor: DEFAULT_INTAKE_ROUTE_ACTOR
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
await ops.updateMany(INTAKE_ROUTE_LOCKS, scopeWhere(scope), { seeded_defaults: [...seededDefaults(current), ...missing.map(({ key }) => key)] });
|
|
339
|
+
});
|
|
340
|
+
}
|
|
163
341
|
/**
|
|
164
342
|
* Runs `fn` in a transaction and replaces the project's version when it changed anything.
|
|
165
343
|
* Lost races (a compare-and-set miss, or a concurrent write that inserted the same board or the
|
|
166
344
|
* project's first version row) retry from fresh reads.
|
|
167
345
|
*/
|
|
168
346
|
async #write(scope, fn) {
|
|
347
|
+
return this.#transact(async (ops) => {
|
|
348
|
+
const { result, changed } = await fn(ops);
|
|
349
|
+
if (changed) await bumpVersion(ops, scope);
|
|
350
|
+
return result;
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
/**
|
|
354
|
+
* Runs `fn` in a transaction, retrying lost races from fresh reads. Intake route writes use it
|
|
355
|
+
* directly: routes are read uncached, so they leave the board definition version alone.
|
|
356
|
+
*/
|
|
357
|
+
async #transact(fn) {
|
|
169
358
|
for (let attempt = 1;; attempt++) try {
|
|
170
|
-
return await this.storage.withTransaction(
|
|
171
|
-
const { result, changed } = await fn(ops);
|
|
172
|
-
if (changed) await bumpVersion(ops, scope);
|
|
173
|
-
return result;
|
|
174
|
-
});
|
|
359
|
+
return await this.storage.withTransaction(fn);
|
|
175
360
|
} catch (error) {
|
|
176
361
|
if (!(error instanceof ConcurrentBoardWrite || error instanceof UniqueViolationError) || attempt >= MAX_WRITE_ATTEMPTS) throw error;
|
|
177
362
|
}
|
|
@@ -287,6 +472,105 @@ async function writeBoard(ops, scope, row, input, actor) {
|
|
|
287
472
|
key: row.board_key
|
|
288
473
|
});
|
|
289
474
|
}
|
|
290
|
-
|
|
475
|
+
function toIntakeRouteRecord(row) {
|
|
476
|
+
return {
|
|
477
|
+
id: row.id,
|
|
478
|
+
orgId: row.org_id,
|
|
479
|
+
factoryProjectId: row.factory_project_id,
|
|
480
|
+
name: row.name,
|
|
481
|
+
enabled: row.enabled,
|
|
482
|
+
position: row.position,
|
|
483
|
+
when: row.when_condition,
|
|
484
|
+
target: {
|
|
485
|
+
boardKey: row.board_key,
|
|
486
|
+
phaseKey: row.phase_key
|
|
487
|
+
},
|
|
488
|
+
revision: row.revision,
|
|
489
|
+
createdBy: row.created_by,
|
|
490
|
+
createdAt: row.created_at,
|
|
491
|
+
updatedBy: row.updated_by,
|
|
492
|
+
updatedAt: row.updated_at
|
|
493
|
+
};
|
|
494
|
+
}
|
|
495
|
+
async function readIntakeRoutes(ops, scope) {
|
|
496
|
+
return (await ops.findMany(INTAKE_ROUTES, scopeWhere(scope))).sort((left, right) => left.position - right.position);
|
|
497
|
+
}
|
|
498
|
+
async function findIntakeRoute(ops, scope, id) {
|
|
499
|
+
const row = await ops.findOne(INTAKE_ROUTES, {
|
|
500
|
+
...scopeWhere(scope),
|
|
501
|
+
id
|
|
502
|
+
});
|
|
503
|
+
if (!row) throw intakeRouteNotFound(id);
|
|
504
|
+
return row;
|
|
505
|
+
}
|
|
506
|
+
function intakeRouteNotFound(id) {
|
|
507
|
+
return new StoredBoardError("intake_route_not_found", `Intake route "${id}" does not exist in this project.`);
|
|
508
|
+
}
|
|
509
|
+
function checkIntakeRouteRevision(row, expectedRevision) {
|
|
510
|
+
if (row.revision !== expectedRevision) throw new StoredBoardError("revision_mismatch", `Intake route "${row.name}" is at revision ${row.revision}, not ${expectedRevision}; reload it and try again.`);
|
|
511
|
+
}
|
|
512
|
+
/** Sets columns on a route row and raises its revision, unless another writer changed it first. */
|
|
513
|
+
async function updateIntakeRouteRow(ops, row, set) {
|
|
514
|
+
const revision = row.revision + 1;
|
|
515
|
+
if (await ops.updateMany(INTAKE_ROUTES, {
|
|
516
|
+
id: row.id,
|
|
517
|
+
revision: row.revision
|
|
518
|
+
}, {
|
|
519
|
+
...set,
|
|
520
|
+
revision,
|
|
521
|
+
updated_at: /* @__PURE__ */ new Date()
|
|
522
|
+
}) !== 1) throw new ConcurrentBoardWrite();
|
|
523
|
+
return revision;
|
|
524
|
+
}
|
|
525
|
+
async function insertIntakeRoute(ops, scope, route) {
|
|
526
|
+
const now = /* @__PURE__ */ new Date();
|
|
527
|
+
await ops.insertOne(INTAKE_ROUTES, {
|
|
528
|
+
id: route.id,
|
|
529
|
+
...scopeWhere(scope),
|
|
530
|
+
name: route.input.name,
|
|
531
|
+
enabled: route.input.enabled ?? true,
|
|
532
|
+
position: route.position,
|
|
533
|
+
when_condition: route.input.when ?? null,
|
|
534
|
+
board_key: route.input.target.boardKey,
|
|
535
|
+
phase_key: route.input.target.phaseKey ?? null,
|
|
536
|
+
revision: 1,
|
|
537
|
+
created_by: route.actor,
|
|
538
|
+
created_at: now,
|
|
539
|
+
updated_by: route.actor,
|
|
540
|
+
updated_at: now
|
|
541
|
+
});
|
|
542
|
+
}
|
|
543
|
+
/**
|
|
544
|
+
* Takes the project's route lock and reads the routes. Writes that add, delete or move routes
|
|
545
|
+
* call this first, so they run one after another and each reads what the one before committed.
|
|
546
|
+
*/
|
|
547
|
+
async function lockIntakeRoutes(ops, scope) {
|
|
548
|
+
if (await ops.updateMany(INTAKE_ROUTE_LOCKS, scopeWhere(scope), { locked_at: /* @__PURE__ */ new Date() }) !== 1) throw new ConcurrentBoardWrite();
|
|
549
|
+
return readIntakeRoutes(ops, scope);
|
|
550
|
+
}
|
|
551
|
+
/** Moves routes, read under the project's route lock, to the positions of their order in `rows`. */
|
|
552
|
+
async function placeIntakeRoutes(ops, rows, actor) {
|
|
553
|
+
const moving = rows.flatMap((row, position) => row.position === position ? [] : [{
|
|
554
|
+
row,
|
|
555
|
+
position
|
|
556
|
+
}]);
|
|
557
|
+
const parked = [];
|
|
558
|
+
for (const [index, { row, position }] of moving.entries()) {
|
|
559
|
+
const revision = await updateIntakeRouteRow(ops, row, {
|
|
560
|
+
position: -(index + 1),
|
|
561
|
+
...actor !== void 0 && { updated_by: actor }
|
|
562
|
+
});
|
|
563
|
+
parked.push({
|
|
564
|
+
id: row.id,
|
|
565
|
+
revision,
|
|
566
|
+
position
|
|
567
|
+
});
|
|
568
|
+
}
|
|
569
|
+
for (const { id, revision, position } of parked) if (await ops.updateMany(INTAKE_ROUTES, {
|
|
570
|
+
id,
|
|
571
|
+
revision
|
|
572
|
+
}, { position }) !== 1) throw new ConcurrentBoardWrite();
|
|
573
|
+
}
|
|
574
|
+
export { DEFAULT_INTAKE_ROUTE, DEFAULT_INTAKE_ROUTES, DEFAULT_INTAKE_ROUTE_ACTOR, MAX_INTAKE_ROUTES, PULL_REQUEST_INTAKE_ROUTE, StoredBoardError, StoredBoardsStorage };
|
|
291
575
|
|
|
292
576
|
//# sourceMappingURL=base.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.js","names":[],"sources":["../../../../src/storage/domains/boards/base.ts"],"sourcesContent":["import { randomUUID } from 'node:crypto';\n\nimport { FactoryStorageDomain, UniqueViolationError } from '@mastra/core/storage';\nimport type { FactoryStorageOps } from '@mastra/core/storage';\n\nimport type { RuleGroup } from '../../../rules/rule-group.js';\nimport {\n FACTORY_BOARD_DEFINITION_VERSIONS_SCHEMA,\n FACTORY_BOARD_PHASES_SCHEMA,\n FACTORY_BOARDS_SCHEMA,\n} from './schemas.js';\n\n/** The project a board belongs to. */\nexport interface StoredBoardScope {\n orgId: string;\n factoryProjectId: string;\n}\n\nexport type StoredPhaseKind = 'resting' | 'working' | 'terminal';\n\n/** Who runs a working phase. Factory runs every phase with its code agent. */\nexport interface StoredPhaseRunner {\n skill?: string;\n context?: string;\n instructions?: string;\n}\n\nexport interface StoredPhaseExitTool {\n id: string;\n autoApprove?: boolean;\n autoApproveWhen?: RuleGroup;\n}\n\n/** A phase as it is written. `key` is the stage id cards sit in. */\nexport interface StoredPhaseInput {\n key: string;\n name: string;\n description?: string | null;\n kind: StoredPhaseKind;\n runner?: StoredPhaseRunner | null;\n /** Unset or `null` on a resting or working phase means every other phase; `[]` means none. */\n nextPhases?: string[] | null;\n autoStart?: boolean;\n autoStartWhen?: RuleGroup | null;\n exitTool?: StoredPhaseExitTool | null;\n}\n\n/** A board as it is written. Phase order is significant: the first phase is where cards start. */\nexport interface StoredBoardInput {\n key: string;\n name: string;\n description?: string | null;\n phases: StoredPhaseInput[];\n}\n\nexport interface StoredPhaseRecord {\n key: string;\n position: number;\n name: string;\n description: string | null;\n kind: StoredPhaseKind;\n runner: StoredPhaseRunner | null;\n nextPhases: string[] | null;\n autoStart: boolean;\n autoStartWhen: RuleGroup | null;\n exitTool: StoredPhaseExitTool | null;\n}\n\nexport interface StoredBoardRecord {\n id: string;\n orgId: string;\n factoryProjectId: string;\n key: string;\n name: string;\n description: string | null;\n position: number;\n revision: number;\n createdBy: string;\n createdAt: Date;\n updatedBy: string;\n updatedAt: Date;\n phases: StoredPhaseRecord[];\n}\n\nexport interface StoredBoardSnapshot {\n version: string | null;\n boards: StoredBoardRecord[];\n}\n\nexport type StoredBoardErrorCode = 'board_exists' | 'board_not_found' | 'revision_mismatch';\n\nexport class StoredBoardError extends Error {\n override name = 'StoredBoardError';\n constructor(\n readonly code: StoredBoardErrorCode,\n message: string,\n ) {\n super(message);\n }\n}\n\ninterface BoardRow extends Record<string, unknown> {\n id: string;\n org_id: string;\n factory_project_id: string;\n board_key: string;\n name: string;\n description: string | null;\n position: number;\n revision: number;\n created_by: string;\n created_at: Date;\n updated_by: string;\n updated_at: Date;\n}\n\ninterface PhaseRow extends Record<string, unknown> {\n id: string;\n org_id: string;\n factory_project_id: string;\n board_key: string;\n phase_key: string;\n position: number;\n name: string;\n description: string | null;\n kind: StoredPhaseKind;\n runner: StoredPhaseRunner | null;\n next_phases: string[] | null;\n auto_start: boolean;\n auto_start_when: RuleGroup | null;\n exit_tool: StoredPhaseExitTool | null;\n}\n\nconst BOARDS = 'factory_boards';\nconst PHASES = 'factory_board_phases';\nconst VERSIONS = 'factory_board_definition_versions';\nconst MAX_WRITE_ATTEMPTS = 3;\n\nfunction scopeWhere({ orgId, factoryProjectId }: StoredBoardScope) {\n return { org_id: orgId, factory_project_id: factoryProjectId };\n}\n\nfunction toPhaseRecord(row: PhaseRow): StoredPhaseRecord {\n return {\n key: row.phase_key,\n position: row.position,\n name: row.name,\n description: row.description,\n kind: row.kind,\n runner: row.runner,\n nextPhases: row.next_phases,\n autoStart: row.auto_start,\n autoStartWhen: row.auto_start_when,\n exitTool: row.exit_tool,\n };\n}\n\nfunction toRecord(row: BoardRow, phases: PhaseRow[]): StoredBoardRecord {\n return {\n id: row.id,\n orgId: row.org_id,\n factoryProjectId: row.factory_project_id,\n key: row.board_key,\n name: row.name,\n description: row.description,\n position: row.position,\n revision: row.revision,\n createdBy: row.created_by,\n createdAt: row.created_at,\n updatedBy: row.updated_by,\n updatedAt: row.updated_at,\n phases: phases.sort((left, right) => left.position - right.position).map(toPhaseRecord),\n };\n}\n\n/** A compare-and-set inside a write lost to a concurrent writer; the write is retried from fresh reads. */\nclass ConcurrentBoardWrite extends Error {}\n\n/**\n * Each project's boards and their ordered phases. Every write runs in one transaction that also\n * replaces the project's row in `factory_board_definition_versions`, so caches on other\n * replicas can detect it.\n */\nexport class StoredBoardsStorage extends FactoryStorageDomain {\n constructor() {\n super('boards');\n }\n\n async init(): Promise<void> {\n await this.ensureCollections([\n FACTORY_BOARDS_SCHEMA,\n FACTORY_BOARD_PHASES_SCHEMA,\n FACTORY_BOARD_DEFINITION_VERSIONS_SCHEMA,\n ]);\n }\n\n async dangerouslyClearAll(): Promise<void> {\n await this.ops.deleteMany(PHASES, {});\n await this.ops.deleteMany(BOARDS, {});\n await this.ops.deleteMany(VERSIONS, {});\n }\n\n /** The project's current definition version; null before its first board write. */\n async readVersion(scope: StoredBoardScope): Promise<string | null> {\n return readVersion(this.ops, scope);\n }\n\n /** The project's boards in order. */\n async list(scope: StoredBoardScope): Promise<StoredBoardRecord[]> {\n return readBoards(this.ops, scope);\n }\n\n /**\n * The version and the boards, read in that order: a write landing between the two reads leaves a\n * version older than the rows, so a cache keyed on it rereads on its next check instead of\n * keeping the stale rows.\n */\n async snapshot(scope: StoredBoardScope): Promise<StoredBoardSnapshot> {\n const version = await readVersion(this.ops, scope);\n return { version, boards: await this.list(scope) };\n }\n\n async get(scope: StoredBoardScope, key: string): Promise<StoredBoardRecord | null> {\n const row = await this.ops.findOne<BoardRow>(BOARDS, { ...scopeWhere(scope), board_key: key });\n if (!row) return null;\n const phases = await this.ops.findMany<PhaseRow>(PHASES, { ...scopeWhere(scope), board_key: key });\n return toRecord(row, phases);\n }\n\n /** Creates a board through the API. */\n async create(scope: StoredBoardScope, input: StoredBoardInput, actor: string): Promise<StoredBoardRecord> {\n await ensureVersionRow(this.ops, scope);\n try {\n return await this.#write(scope, async ops => {\n const rows = await ops.findMany<BoardRow>(BOARDS, scopeWhere(scope));\n if (rows.some(row => row.board_key === input.key)) {\n throw new StoredBoardError('board_exists', `Board \"${input.key}\" already exists in this project.`);\n }\n await insertBoard(ops, scope, input, { position: nextPosition(rows), actor });\n return { result: undefined, changed: true };\n }).then(async () => (await this.get(scope, input.key))!);\n } catch (error) {\n // Only the board key's index means the board exists; a lost race on another table is not that.\n if (error instanceof UniqueViolationError && error.collection === BOARDS) {\n throw new StoredBoardError('board_exists', `Board \"${input.key}\" already exists in this project.`);\n }\n throw error;\n }\n }\n\n /** Replaces a board's name, description and phases. The board key never changes. */\n async replace(\n scope: StoredBoardScope,\n key: string,\n input: Omit<StoredBoardInput, 'key'>,\n options: { expectedRevision: number; actor: string },\n ): Promise<StoredBoardRecord> {\n await this.#write(scope, async ops => {\n const row = await findBoard(ops, scope, key);\n checkRevision(row, key, options.expectedRevision);\n await writeBoard(ops, scope, row, { key, ...input }, options.actor);\n return { result: undefined, changed: true };\n });\n return (await this.get(scope, key))!;\n }\n\n /** Deletes a board and its phases. */\n async delete(scope: StoredBoardScope, key: string, options: { expectedRevision: number }): Promise<void> {\n await this.#write(scope, async ops => {\n const row = await findBoard(ops, scope, key);\n checkRevision(row, key, options.expectedRevision);\n if ((await ops.deleteMany(BOARDS, { id: row.id, revision: row.revision })) === 0)\n throw new ConcurrentBoardWrite();\n await ops.deleteMany(PHASES, { ...scopeWhere(scope), board_key: key });\n return { result: undefined, changed: true };\n });\n }\n\n /**\n * Runs `fn` in a transaction and replaces the project's version when it changed anything.\n * Lost races (a compare-and-set miss, or a concurrent write that inserted the same board or the\n * project's first version row) retry from fresh reads.\n */\n async #write<T>(\n scope: StoredBoardScope,\n fn: (ops: FactoryStorageOps) => Promise<{ result: T; changed: boolean }>,\n ): Promise<T> {\n for (let attempt = 1; ; attempt++) {\n try {\n // Read committed is enough: every row change is a compare-and-set on `revision` and every\n // insert meets the unique index. Serializable isolation would also fail writes to\n // unrelated projects that replicas run side by side.\n return await this.storage.withTransaction(async ops => {\n const { result, changed } = await fn(ops);\n if (changed) await bumpVersion(ops, scope);\n return result;\n });\n } catch (error) {\n const retryable = error instanceof ConcurrentBoardWrite || error instanceof UniqueViolationError;\n if (!retryable || attempt >= MAX_WRITE_ATTEMPTS) throw error;\n }\n }\n }\n}\n\nasync function readVersion(ops: FactoryStorageOps, scope: StoredBoardScope): Promise<string | null> {\n const row = await ops.findOne<{ version: string }>(VERSIONS, scopeWhere(scope));\n return row?.version ?? null;\n}\n\nasync function readBoards(ops: FactoryStorageOps, scope: StoredBoardScope): Promise<StoredBoardRecord[]> {\n const [rows, phases] = await Promise.all([\n ops.findMany<BoardRow>(BOARDS, scopeWhere(scope)),\n ops.findMany<PhaseRow>(PHASES, scopeWhere(scope)),\n ]);\n const byBoard = new Map<string, PhaseRow[]>();\n for (const phase of phases) {\n const list = byBoard.get(phase.board_key) ?? [];\n list.push(phase);\n byBoard.set(phase.board_key, list);\n }\n return rows\n .sort((left, right) => left.position - right.position || left.board_key.localeCompare(right.board_key))\n .map(row => toRecord(row, byBoard.get(row.board_key) ?? []));\n}\n\n/**\n * Inserts the project's version row if it has none. This runs outside the write transaction: on\n * Postgres, two transactions racing to insert it would leave the loser's transaction aborted, so\n * the version bump inside a write must always be an update.\n */\nasync function ensureVersionRow(ops: FactoryStorageOps, scope: StoredBoardScope): Promise<void> {\n if (await ops.findOne(VERSIONS, scopeWhere(scope))) return;\n try {\n await ops.insertOne(VERSIONS, { ...scopeWhere(scope), version: randomUUID(), updated_at: new Date() });\n } catch (error) {\n if (!(error instanceof UniqueViolationError)) throw error;\n }\n}\n\nasync function bumpVersion(ops: FactoryStorageOps, scope: StoredBoardScope): Promise<void> {\n await ops.upsertOne(VERSIONS, ['org_id', 'factory_project_id'], {\n ...scopeWhere(scope),\n version: randomUUID(),\n updated_at: new Date(),\n });\n}\n\nasync function findBoard(ops: FactoryStorageOps, scope: StoredBoardScope, key: string): Promise<BoardRow> {\n const row = await ops.findOne<BoardRow>(BOARDS, { ...scopeWhere(scope), board_key: key });\n if (!row) {\n throw new StoredBoardError('board_not_found', `Board \"${key}\" does not exist in this project.`);\n }\n return row;\n}\n\nfunction checkRevision(row: BoardRow, key: string, expectedRevision: number): void {\n if (row.revision !== expectedRevision) {\n throw new StoredBoardError(\n 'revision_mismatch',\n `Board \"${key}\" is at revision ${row.revision}, not ${expectedRevision}; reload it and try again.`,\n );\n }\n}\n\nfunction nextPosition(rows: BoardRow[]): number {\n return rows.reduce((max, row) => Math.max(max, row.position), -1) + 1;\n}\n\n/** Sets columns on a board row and raises its revision, unless another writer changed it first. */\nasync function updateRow(ops: FactoryStorageOps, row: BoardRow, set: Partial<BoardRow>): Promise<void> {\n const updated = await ops.updateMany(\n BOARDS,\n { id: row.id, revision: row.revision },\n { ...set, revision: row.revision + 1, updated_at: new Date() },\n );\n if (updated !== 1) throw new ConcurrentBoardWrite();\n}\n\nasync function insertPhases(ops: FactoryStorageOps, scope: StoredBoardScope, input: StoredBoardInput): Promise<void> {\n for (const [position, phase] of input.phases.entries()) {\n await ops.insertOne<PhaseRow>(PHASES, {\n ...scopeWhere(scope),\n board_key: input.key,\n phase_key: phase.key,\n position,\n name: phase.name,\n description: phase.description ?? null,\n kind: phase.kind,\n runner: phase.runner ?? null,\n next_phases: phase.nextPhases ?? null,\n auto_start: phase.autoStart ?? false,\n auto_start_when: phase.autoStartWhen ?? null,\n exit_tool: phase.exitTool ?? null,\n });\n }\n}\n\nasync function insertBoard(\n ops: FactoryStorageOps,\n scope: StoredBoardScope,\n input: StoredBoardInput,\n options: { position: number; actor: string },\n): Promise<void> {\n const now = new Date();\n await ops.insertOne<BoardRow>(BOARDS, {\n ...scopeWhere(scope),\n board_key: input.key,\n name: input.name,\n description: input.description ?? null,\n position: options.position,\n revision: 1,\n created_by: options.actor,\n created_at: now,\n updated_by: options.actor,\n updated_at: now,\n });\n await insertPhases(ops, scope, input);\n}\n\n/** Replaces a board's definition and phases in place, keeping its key, position and history. */\nasync function writeBoard(\n ops: FactoryStorageOps,\n scope: StoredBoardScope,\n row: BoardRow,\n input: StoredBoardInput,\n actor: string,\n): Promise<void> {\n await updateRow(ops, row, { name: input.name, description: input.description ?? null, updated_by: actor });\n await ops.deleteMany(PHASES, { ...scopeWhere(scope), board_key: row.board_key });\n await insertPhases(ops, scope, { ...input, key: row.board_key });\n}\n"],"mappings":";;;;AA2FA,IAAa,mBAAb,cAAsC,MAAM;CAG/B;CAFX,OAAgB;CAChB,YACE,MACA,SACA;EACA,MAAM,OAAO;EAHJ,KAAA,OAAA;CAIX;AACF;AAkCA,MAAM,SAAS;AACf,MAAM,SAAS;AACf,MAAM,WAAW;AACjB,MAAM,qBAAqB;AAE3B,SAAS,WAAW,EAAE,OAAO,oBAAsC;CACjE,OAAO;EAAE,QAAQ;EAAO,oBAAoB;CAAiB;AAC/D;AAEA,SAAS,cAAc,KAAkC;CACvD,OAAO;EACL,KAAK,IAAI;EACT,UAAU,IAAI;EACd,MAAM,IAAI;EACV,aAAa,IAAI;EACjB,MAAM,IAAI;EACV,QAAQ,IAAI;EACZ,YAAY,IAAI;EAChB,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AAU,IAAI,WAAW;EAAG,4BAAY,IAAI,KAAK;CAAE,CAC/D,MACgB,GAAG,MAAM,IAAI,qBAAqB;AACpD;AAEA,eAAe,aAAa,KAAwB,OAAyB,OAAwC;CACnH,KAAK,MAAM,CAAC,UAAU,UAAU,MAAM,OAAO,QAAQ,GACnD,MAAM,IAAI,UAAoB,QAAQ;EACpC,GAAG,WAAW,KAAK;EACnB,WAAW,MAAM;EACjB,WAAW,MAAM;EACjB;EACA,MAAM,MAAM;EACZ,aAAa,MAAM,eAAe;EAClC,MAAM,MAAM;EACZ,QAAQ,MAAM,UAAU;EACxB,aAAa,MAAM,cAAc;EACjC,YAAY,MAAM,aAAa;EAC/B,iBAAiB,MAAM,iBAAiB;EACxC,WAAW,MAAM,YAAY;CAC/B,CAAC;AAEL;AAEA,eAAe,YACb,KACA,OACA,OACA,SACe;CACf,MAAM,sBAAM,IAAI,KAAK;CACrB,MAAM,IAAI,UAAoB,QAAQ;EACpC,GAAG,WAAW,KAAK;EACnB,WAAW,MAAM;EACjB,MAAM,MAAM;EACZ,aAAa,MAAM,eAAe;EAClC,UAAU,QAAQ;EAClB,UAAU;EACV,YAAY,QAAQ;EACpB,YAAY;EACZ,YAAY,QAAQ;EACpB,YAAY;CACd,CAAC;CACD,MAAM,aAAa,KAAK,OAAO,KAAK;AACtC;;AAGA,eAAe,WACb,KACA,OACA,KACA,OACA,OACe;CACf,MAAM,UAAU,KAAK,KAAK;EAAE,MAAM,MAAM;EAAM,aAAa,MAAM,eAAe;EAAM,YAAY;CAAM,CAAC;CACzG,MAAM,IAAI,WAAW,QAAQ;EAAE,GAAG,WAAW,KAAK;EAAG,WAAW,IAAI;CAAU,CAAC;CAC/E,MAAM,aAAa,KAAK,OAAO;EAAE,GAAG;EAAO,KAAK,IAAI;CAAU,CAAC;AACjE"}
|
|
1
|
+
{"version":3,"file":"base.js","names":[],"sources":["../../../../src/storage/domains/boards/base.ts"],"sourcesContent":["import { randomUUID } from 'node:crypto';\n\nimport { FactoryStorageDomain, UniqueViolationError } from '@mastra/core/storage';\nimport type { FactoryStorageOps } from '@mastra/core/storage';\n\nimport type { RuleGroup } from '../../../rules/rule-group.js';\nimport {\n FACTORY_BOARD_DEFINITION_VERSIONS_SCHEMA,\n FACTORY_BOARD_PHASES_SCHEMA,\n FACTORY_BOARDS_SCHEMA,\n FACTORY_INTAKE_ROUTE_LOCKS_SCHEMA,\n FACTORY_INTAKE_ROUTES_SCHEMA,\n} from './schemas.js';\n\n/** The project a board belongs to. */\nexport interface StoredBoardScope {\n orgId: string;\n factoryProjectId: string;\n}\n\nexport type StoredPhaseKind = 'resting' | 'working' | 'terminal';\n\n/** Who runs a working phase. Factory runs every phase with its code agent. */\nexport interface StoredPhaseRunner {\n skill?: string;\n context?: string;\n instructions?: string;\n}\n\nexport interface StoredPhaseExitTool {\n id: string;\n autoApprove?: boolean;\n autoApproveWhen?: RuleGroup;\n}\n\n/** A phase as it is written. `key` is the stage id cards sit in. */\nexport interface StoredPhaseInput {\n key: string;\n name: string;\n description?: string | null;\n kind: StoredPhaseKind;\n runner?: StoredPhaseRunner | null;\n /** Unset or `null` on a resting or working phase means every other phase; `[]` means none. */\n nextPhases?: string[] | null;\n autoStart?: boolean;\n autoStartWhen?: RuleGroup | null;\n exitTool?: StoredPhaseExitTool | null;\n}\n\n/** A board as it is written. Phase order is significant: the first phase is where cards start. */\nexport interface StoredBoardInput {\n key: string;\n name: string;\n description?: string | null;\n phases: StoredPhaseInput[];\n}\n\nexport interface StoredPhaseRecord {\n key: string;\n position: number;\n name: string;\n description: string | null;\n kind: StoredPhaseKind;\n runner: StoredPhaseRunner | null;\n nextPhases: string[] | null;\n autoStart: boolean;\n autoStartWhen: RuleGroup | null;\n exitTool: StoredPhaseExitTool | null;\n}\n\nexport interface StoredBoardRecord {\n id: string;\n orgId: string;\n factoryProjectId: string;\n key: string;\n name: string;\n description: string | null;\n position: number;\n revision: number;\n createdBy: string;\n createdAt: Date;\n updatedBy: string;\n updatedAt: Date;\n phases: StoredPhaseRecord[];\n}\n\nexport interface StoredBoardSnapshot {\n version: string | null;\n boards: StoredBoardRecord[];\n}\n\nexport interface IntakeRouteTarget {\n boardKey: string;\n /** Unset lands the card in the board's first phase. */\n phaseKey?: string | null;\n}\n\n/** An intake route as it is written. */\nexport interface StoredIntakeRouteInput {\n name: string;\n enabled?: boolean;\n /** Null matches every card. */\n when?: RuleGroup | null;\n target: IntakeRouteTarget;\n}\n\nexport interface StoredIntakeRouteRecord {\n id: string;\n orgId: string;\n factoryProjectId: string;\n name: string;\n enabled: boolean;\n position: number;\n when: RuleGroup | null;\n target: { boardKey: string; phaseKey: string | null };\n revision: number;\n createdBy: string;\n createdAt: Date;\n updatedBy: string;\n updatedAt: Date;\n}\n\nexport type StoredBoardErrorCode =\n | 'board_exists'\n | 'board_not_found'\n | 'revision_mismatch'\n | 'intake_route_not_found'\n | 'intake_route_set_mismatch'\n | 'intake_route_limit';\n\n/** A project's most intake routes; a reorder names every one of them. */\nexport const MAX_INTAKE_ROUTES = 100;\n\n/**\n * The route every project starts with: a GitHub or GitLab card whose author is outside the\n * write-access circle lands in Work › Intake, where nothing starts until a person moves it.\n * It is a stored route like any other, so admins can see, edit, disable or delete it.\n */\nexport const DEFAULT_INTAKE_ROUTE: StoredIntakeRouteInput = {\n name: 'Outside authors wait in Intake',\n when: {\n operator: 'AND',\n conditions: [\n { field: 'source.integration', operator: 'in', value: ['github', 'gitlab'] },\n { field: 'author.trusted', operator: 'equals', value: false },\n ],\n },\n target: { boardKey: 'work', phaseKey: 'intake' },\n};\n\n/**\n * Pull requests are reviewed in Work › PR review. It comes after `DEFAULT_INTAKE_ROUTE`, so a\n * pull request from outside the write-access circle still waits in Intake for a person.\n */\nexport const PULL_REQUEST_INTAKE_ROUTE: StoredIntakeRouteInput = {\n name: 'Pull requests go to PR review',\n when: { operator: 'AND', conditions: [{ field: 'source.kind', operator: 'equals', value: 'pull_request' }] },\n target: { boardKey: 'work', phaseKey: 'pr-review' },\n};\n\n/**\n * The routes Factory adds to a project, in order, each under a key that never changes. A project\n * gets each one once: a new project gets them all, a project set up earlier gets a route added\n * since at the end of its list, and a route an admin deleted stays deleted.\n */\nexport const DEFAULT_INTAKE_ROUTES: readonly { key: string; route: StoredIntakeRouteInput }[] = [\n { key: 'outside-authors', route: DEFAULT_INTAKE_ROUTE },\n { key: 'pull-requests', route: PULL_REQUEST_INTAKE_ROUTE },\n];\n\n/** The defaults a project whose lock row predates `seeded_defaults` was set up with. */\nconst ORIGINAL_DEFAULT_KEYS = ['outside-authors'];\n\n/** Who the default intake routes are created and last updated by. */\nexport const DEFAULT_INTAKE_ROUTE_ACTOR = 'factory';\n\nexport class StoredBoardError extends Error {\n override name = 'StoredBoardError';\n constructor(\n readonly code: StoredBoardErrorCode,\n message: string,\n ) {\n super(message);\n }\n}\n\ninterface BoardRow extends Record<string, unknown> {\n id: string;\n org_id: string;\n factory_project_id: string;\n board_key: string;\n name: string;\n description: string | null;\n position: number;\n revision: number;\n created_by: string;\n created_at: Date;\n updated_by: string;\n updated_at: Date;\n}\n\ninterface PhaseRow extends Record<string, unknown> {\n id: string;\n org_id: string;\n factory_project_id: string;\n board_key: string;\n phase_key: string;\n position: number;\n name: string;\n description: string | null;\n kind: StoredPhaseKind;\n runner: StoredPhaseRunner | null;\n next_phases: string[] | null;\n auto_start: boolean;\n auto_start_when: RuleGroup | null;\n exit_tool: StoredPhaseExitTool | null;\n}\n\ninterface IntakeRouteRow extends Record<string, unknown> {\n id: string;\n org_id: string;\n factory_project_id: string;\n name: string;\n enabled: boolean;\n position: number;\n when_condition: RuleGroup | null;\n board_key: string;\n phase_key: string | null;\n revision: number;\n created_by: string;\n created_at: Date;\n updated_by: string;\n updated_at: Date;\n}\n\ninterface IntakeRouteLockRow extends Record<string, unknown> {\n /** Keys of the `DEFAULT_INTAKE_ROUTES` added to the project; null on rows written before the list. */\n seeded_defaults: string[] | null;\n}\n\nfunction seededDefaults(lock: IntakeRouteLockRow): string[] {\n return lock.seeded_defaults ?? ORIGINAL_DEFAULT_KEYS;\n}\n\nfunction missingDefaults(lock: IntakeRouteLockRow): (typeof DEFAULT_INTAKE_ROUTES)[number][] {\n const seeded = new Set(seededDefaults(lock));\n return DEFAULT_INTAKE_ROUTES.filter(({ key }) => !seeded.has(key));\n}\n\nconst BOARDS = 'factory_boards';\nconst PHASES = 'factory_board_phases';\nconst VERSIONS = 'factory_board_definition_versions';\nconst INTAKE_ROUTES = 'factory_intake_routes';\nconst INTAKE_ROUTE_LOCKS = 'factory_intake_route_locks';\nconst MAX_WRITE_ATTEMPTS = 3;\n\nfunction scopeWhere({ orgId, factoryProjectId }: StoredBoardScope) {\n return { org_id: orgId, factory_project_id: factoryProjectId };\n}\n\nfunction toPhaseRecord(row: PhaseRow): StoredPhaseRecord {\n return {\n key: row.phase_key,\n position: row.position,\n name: row.name,\n description: row.description,\n kind: row.kind,\n runner: row.runner,\n nextPhases: row.next_phases,\n autoStart: row.auto_start,\n autoStartWhen: row.auto_start_when,\n exitTool: row.exit_tool,\n };\n}\n\nfunction toRecord(row: BoardRow, phases: PhaseRow[]): StoredBoardRecord {\n return {\n id: row.id,\n orgId: row.org_id,\n factoryProjectId: row.factory_project_id,\n key: row.board_key,\n name: row.name,\n description: row.description,\n position: row.position,\n revision: row.revision,\n createdBy: row.created_by,\n createdAt: row.created_at,\n updatedBy: row.updated_by,\n updatedAt: row.updated_at,\n phases: phases.sort((left, right) => left.position - right.position).map(toPhaseRecord),\n };\n}\n\n/** A compare-and-set inside a write lost to a concurrent writer; the write is retried from fresh reads. */\nclass ConcurrentBoardWrite extends Error {}\n\n/**\n * Each project's boards and their ordered phases. Every write runs in one transaction that also\n * replaces the project's row in `factory_board_definition_versions`, so caches on other\n * replicas can detect it.\n */\nexport class StoredBoardsStorage extends FactoryStorageDomain {\n constructor() {\n super('boards');\n }\n\n async init(): Promise<void> {\n await this.ensureCollections([\n FACTORY_BOARDS_SCHEMA,\n FACTORY_BOARD_PHASES_SCHEMA,\n FACTORY_BOARD_DEFINITION_VERSIONS_SCHEMA,\n FACTORY_INTAKE_ROUTES_SCHEMA,\n FACTORY_INTAKE_ROUTE_LOCKS_SCHEMA,\n ]);\n }\n\n async dangerouslyClearAll(): Promise<void> {\n await this.ops.deleteMany(PHASES, {});\n await this.ops.deleteMany(BOARDS, {});\n await this.ops.deleteMany(VERSIONS, {});\n await this.ops.deleteMany(INTAKE_ROUTES, {});\n await this.ops.deleteMany(INTAKE_ROUTE_LOCKS, {});\n }\n\n /** The project's current definition version; null before its first board write. */\n async readVersion(scope: StoredBoardScope): Promise<string | null> {\n return readVersion(this.ops, scope);\n }\n\n /** The project's boards in order. */\n async list(scope: StoredBoardScope): Promise<StoredBoardRecord[]> {\n return readBoards(this.ops, scope);\n }\n\n /**\n * The version and the boards, read in that order: a write landing between the two reads leaves a\n * version older than the rows, so a cache keyed on it rereads on its next check instead of\n * keeping the stale rows.\n */\n async snapshot(scope: StoredBoardScope): Promise<StoredBoardSnapshot> {\n const version = await readVersion(this.ops, scope);\n return { version, boards: await this.list(scope) };\n }\n\n async get(scope: StoredBoardScope, key: string): Promise<StoredBoardRecord | null> {\n const row = await this.ops.findOne<BoardRow>(BOARDS, { ...scopeWhere(scope), board_key: key });\n if (!row) return null;\n const phases = await this.ops.findMany<PhaseRow>(PHASES, { ...scopeWhere(scope), board_key: key });\n return toRecord(row, phases);\n }\n\n /** Creates a board through the API. */\n async create(scope: StoredBoardScope, input: StoredBoardInput, actor: string): Promise<StoredBoardRecord> {\n await ensureVersionRow(this.ops, scope);\n try {\n return await this.#write(scope, async ops => {\n const rows = await ops.findMany<BoardRow>(BOARDS, scopeWhere(scope));\n if (rows.some(row => row.board_key === input.key)) {\n throw new StoredBoardError('board_exists', `Board \"${input.key}\" already exists in this project.`);\n }\n await insertBoard(ops, scope, input, { position: nextPosition(rows), actor });\n return { result: undefined, changed: true };\n }).then(async () => (await this.get(scope, input.key))!);\n } catch (error) {\n // Only the board key's index means the board exists; a lost race on another table is not that.\n if (error instanceof UniqueViolationError && error.collection === BOARDS) {\n throw new StoredBoardError('board_exists', `Board \"${input.key}\" already exists in this project.`);\n }\n throw error;\n }\n }\n\n /** Replaces a board's name, description and phases. The board key never changes. */\n async replace(\n scope: StoredBoardScope,\n key: string,\n input: Omit<StoredBoardInput, 'key'>,\n options: { expectedRevision: number; actor: string },\n ): Promise<StoredBoardRecord> {\n await this.#write(scope, async ops => {\n const row = await findBoard(ops, scope, key);\n checkRevision(row, key, options.expectedRevision);\n await writeBoard(ops, scope, row, { key, ...input }, options.actor);\n return { result: undefined, changed: true };\n });\n return (await this.get(scope, key))!;\n }\n\n /** Deletes a board and its phases. */\n async delete(scope: StoredBoardScope, key: string, options: { expectedRevision: number }): Promise<void> {\n await this.#write(scope, async ops => {\n const row = await findBoard(ops, scope, key);\n checkRevision(row, key, options.expectedRevision);\n if ((await ops.deleteMany(BOARDS, { id: row.id, revision: row.revision })) === 0)\n throw new ConcurrentBoardWrite();\n await ops.deleteMany(PHASES, { ...scopeWhere(scope), board_key: key });\n return { result: undefined, changed: true };\n });\n }\n\n /** The project's intake routes in the order they are tried; Factory's `DEFAULT_INTAKE_ROUTES` are added once each. */\n async listIntakeRoutes(scope: StoredBoardScope): Promise<StoredIntakeRouteRecord[]> {\n await this.#ensureIntakeRoutes(scope);\n return (await readIntakeRoutes(this.ops, scope)).map(toIntakeRouteRecord);\n }\n\n async getIntakeRoute(scope: StoredBoardScope, id: string): Promise<StoredIntakeRouteRecord | null> {\n const row = await this.ops.findOne<IntakeRouteRow>(INTAKE_ROUTES, { ...scopeWhere(scope), id });\n return row ? toIntakeRouteRecord(row) : null;\n }\n\n /** Adds a route after the project's last one. */\n async createIntakeRoute(\n scope: StoredBoardScope,\n input: StoredIntakeRouteInput,\n actor: string,\n ): Promise<StoredIntakeRouteRecord> {\n const id = randomUUID();\n await this.#ensureIntakeRoutes(scope);\n await this.#transact(async ops => {\n const rows = await lockIntakeRoutes(ops, scope);\n if (rows.length >= MAX_INTAKE_ROUTES) {\n throw new StoredBoardError(\n 'intake_route_limit',\n `A project can have at most ${MAX_INTAKE_ROUTES} intake routes; delete one first.`,\n );\n }\n await insertIntakeRoute(ops, scope, {\n id,\n input,\n position: rows.reduce((max, row) => Math.max(max, row.position), -1) + 1,\n actor,\n });\n });\n return (await this.getIntakeRoute(scope, id))!;\n }\n\n /** Changes the fields `patch` names; the route keeps its place in the order. */\n async updateIntakeRoute(\n scope: StoredBoardScope,\n id: string,\n patch: Partial<StoredIntakeRouteInput>,\n options: { expectedRevision: number; actor: string },\n ): Promise<StoredIntakeRouteRecord> {\n await this.#transact(async ops => {\n const row = await findIntakeRoute(ops, scope, id);\n checkIntakeRouteRevision(row, options.expectedRevision);\n await updateIntakeRouteRow(ops, row, {\n ...(patch.name !== undefined && { name: patch.name }),\n ...(patch.enabled !== undefined && { enabled: patch.enabled }),\n ...(patch.when !== undefined && { when_condition: patch.when }),\n ...(patch.target !== undefined && {\n board_key: patch.target.boardKey,\n phase_key: patch.target.phaseKey ?? null,\n }),\n updated_by: options.actor,\n });\n });\n return (await this.getIntakeRoute(scope, id))!;\n }\n\n /** Deletes a route; the routes after it move up one place. */\n async deleteIntakeRoute(scope: StoredBoardScope, id: string, options: { expectedRevision: number }): Promise<void> {\n await this.#ensureIntakeRoutes(scope);\n await this.#transact(async ops => {\n const rows = await lockIntakeRoutes(ops, scope);\n const row = rows.find(route => route.id === id);\n if (!row) throw intakeRouteNotFound(id);\n checkIntakeRouteRevision(row, options.expectedRevision);\n if ((await ops.deleteMany(INTAKE_ROUTES, { id: row.id, revision: row.revision })) === 0) {\n throw new ConcurrentBoardWrite();\n }\n await placeIntakeRoutes(\n ops,\n rows.filter(route => route.id !== row.id),\n );\n });\n }\n\n /** Puts the project's routes in the order of `ids`, which must name every route exactly once. */\n async reorderIntakeRoutes(scope: StoredBoardScope, ids: string[], actor: string): Promise<StoredIntakeRouteRecord[]> {\n await this.#ensureIntakeRoutes(scope);\n await this.#transact(async ops => {\n const rows = await lockIntakeRoutes(ops, scope);\n const byId = new Map(rows.map(row => [row.id, row]));\n if (ids.length !== rows.length || new Set(ids).size !== ids.length || ids.some(id => !byId.has(id))) {\n throw new StoredBoardError(\n 'intake_route_set_mismatch',\n 'The order must list every intake route of the project exactly once; reload the routes and try again.',\n );\n }\n await placeIntakeRoutes(\n ops,\n ids.map(id => byId.get(id)!),\n actor,\n );\n });\n return this.listIntakeRoutes(scope);\n }\n\n /**\n * Creates the project's route lock row (see `FACTORY_INTAKE_ROUTE_LOCKS_SCHEMA`) and adds each of\n * `DEFAULT_INTAKE_ROUTES` the row doesn't list as added yet, after the project's routes. The row\n * records every default it added, so a project whose admin deleted one doesn't get it back. Runs\n * before, never inside, a write's transaction: the lock taken there must always be an update.\n */\n async #ensureIntakeRoutes(scope: StoredBoardScope): Promise<void> {\n const lock = await this.ops.findOne<IntakeRouteLockRow>(INTAKE_ROUTE_LOCKS, scopeWhere(scope));\n if (lock && missingDefaults(lock).length === 0) return;\n await this.#transact(async ops => {\n if (await ops.findOne(INTAKE_ROUTE_LOCKS, scopeWhere(scope))) await lockIntakeRoutes(ops, scope);\n // A racing first read inserted the lock row first: this one fails on the unique index and\n // retries, taking the lock above.\n else\n await ops.insertOne(INTAKE_ROUTE_LOCKS, { ...scopeWhere(scope), locked_at: new Date(), seeded_defaults: [] });\n // Read under the lock: a racing seeder that committed first already added what it listed.\n const current = (await ops.findOne<IntakeRouteLockRow>(INTAKE_ROUTE_LOCKS, scopeWhere(scope)))!;\n const missing = missingDefaults(current);\n if (missing.length === 0) return;\n const rows = await readIntakeRoutes(ops, scope);\n let position = rows.reduce((max, row) => Math.max(max, row.position), -1) + 1;\n for (const { route } of missing) {\n // A project at the limit keeps its own routes; the default counts as added all the same.\n if (position >= MAX_INTAKE_ROUTES) break;\n await insertIntakeRoute(ops, scope, {\n id: randomUUID(),\n input: route,\n position: position++,\n actor: DEFAULT_INTAKE_ROUTE_ACTOR,\n });\n }\n await ops.updateMany(INTAKE_ROUTE_LOCKS, scopeWhere(scope), {\n seeded_defaults: [...seededDefaults(current), ...missing.map(({ key }) => key)],\n });\n });\n }\n\n /**\n * Runs `fn` in a transaction and replaces the project's version when it changed anything.\n * Lost races (a compare-and-set miss, or a concurrent write that inserted the same board or the\n * project's first version row) retry from fresh reads.\n */\n async #write<T>(\n scope: StoredBoardScope,\n fn: (ops: FactoryStorageOps) => Promise<{ result: T; changed: boolean }>,\n ): Promise<T> {\n return this.#transact(async ops => {\n const { result, changed } = await fn(ops);\n if (changed) await bumpVersion(ops, scope);\n return result;\n });\n }\n\n /**\n * Runs `fn` in a transaction, retrying lost races from fresh reads. Intake route writes use it\n * directly: routes are read uncached, so they leave the board definition version alone.\n */\n async #transact<T>(fn: (ops: FactoryStorageOps) => Promise<T>): Promise<T> {\n for (let attempt = 1; ; attempt++) {\n try {\n // Read committed is enough: every row change is a compare-and-set on `revision` and every\n // insert meets the unique index. Serializable isolation would also fail writes to\n // unrelated projects that replicas run side by side.\n return await this.storage.withTransaction(fn);\n } catch (error) {\n const retryable = error instanceof ConcurrentBoardWrite || error instanceof UniqueViolationError;\n if (!retryable || attempt >= MAX_WRITE_ATTEMPTS) throw error;\n }\n }\n }\n}\n\nasync function readVersion(ops: FactoryStorageOps, scope: StoredBoardScope): Promise<string | null> {\n const row = await ops.findOne<{ version: string }>(VERSIONS, scopeWhere(scope));\n return row?.version ?? null;\n}\n\nasync function readBoards(ops: FactoryStorageOps, scope: StoredBoardScope): Promise<StoredBoardRecord[]> {\n const [rows, phases] = await Promise.all([\n ops.findMany<BoardRow>(BOARDS, scopeWhere(scope)),\n ops.findMany<PhaseRow>(PHASES, scopeWhere(scope)),\n ]);\n const byBoard = new Map<string, PhaseRow[]>();\n for (const phase of phases) {\n const list = byBoard.get(phase.board_key) ?? [];\n list.push(phase);\n byBoard.set(phase.board_key, list);\n }\n return rows\n .sort((left, right) => left.position - right.position || left.board_key.localeCompare(right.board_key))\n .map(row => toRecord(row, byBoard.get(row.board_key) ?? []));\n}\n\n/**\n * Inserts the project's version row if it has none. This runs outside the write transaction: on\n * Postgres, two transactions racing to insert it would leave the loser's transaction aborted, so\n * the version bump inside a write must always be an update.\n */\nasync function ensureVersionRow(ops: FactoryStorageOps, scope: StoredBoardScope): Promise<void> {\n if (await ops.findOne(VERSIONS, scopeWhere(scope))) return;\n try {\n await ops.insertOne(VERSIONS, { ...scopeWhere(scope), version: randomUUID(), updated_at: new Date() });\n } catch (error) {\n if (!(error instanceof UniqueViolationError)) throw error;\n }\n}\n\nasync function bumpVersion(ops: FactoryStorageOps, scope: StoredBoardScope): Promise<void> {\n await ops.upsertOne(VERSIONS, ['org_id', 'factory_project_id'], {\n ...scopeWhere(scope),\n version: randomUUID(),\n updated_at: new Date(),\n });\n}\n\nasync function findBoard(ops: FactoryStorageOps, scope: StoredBoardScope, key: string): Promise<BoardRow> {\n const row = await ops.findOne<BoardRow>(BOARDS, { ...scopeWhere(scope), board_key: key });\n if (!row) {\n throw new StoredBoardError('board_not_found', `Board \"${key}\" does not exist in this project.`);\n }\n return row;\n}\n\nfunction checkRevision(row: BoardRow, key: string, expectedRevision: number): void {\n if (row.revision !== expectedRevision) {\n throw new StoredBoardError(\n 'revision_mismatch',\n `Board \"${key}\" is at revision ${row.revision}, not ${expectedRevision}; reload it and try again.`,\n );\n }\n}\n\nfunction nextPosition(rows: BoardRow[]): number {\n return rows.reduce((max, row) => Math.max(max, row.position), -1) + 1;\n}\n\n/** Sets columns on a board row and raises its revision, unless another writer changed it first. */\nasync function updateRow(ops: FactoryStorageOps, row: BoardRow, set: Partial<BoardRow>): Promise<void> {\n const updated = await ops.updateMany(\n BOARDS,\n { id: row.id, revision: row.revision },\n { ...set, revision: row.revision + 1, updated_at: new Date() },\n );\n if (updated !== 1) throw new ConcurrentBoardWrite();\n}\n\nasync function insertPhases(ops: FactoryStorageOps, scope: StoredBoardScope, input: StoredBoardInput): Promise<void> {\n for (const [position, phase] of input.phases.entries()) {\n await ops.insertOne<PhaseRow>(PHASES, {\n ...scopeWhere(scope),\n board_key: input.key,\n phase_key: phase.key,\n position,\n name: phase.name,\n description: phase.description ?? null,\n kind: phase.kind,\n runner: phase.runner ?? null,\n next_phases: phase.nextPhases ?? null,\n auto_start: phase.autoStart ?? false,\n auto_start_when: phase.autoStartWhen ?? null,\n exit_tool: phase.exitTool ?? null,\n });\n }\n}\n\nasync function insertBoard(\n ops: FactoryStorageOps,\n scope: StoredBoardScope,\n input: StoredBoardInput,\n options: { position: number; actor: string },\n): Promise<void> {\n const now = new Date();\n await ops.insertOne<BoardRow>(BOARDS, {\n ...scopeWhere(scope),\n board_key: input.key,\n name: input.name,\n description: input.description ?? null,\n position: options.position,\n revision: 1,\n created_by: options.actor,\n created_at: now,\n updated_by: options.actor,\n updated_at: now,\n });\n await insertPhases(ops, scope, input);\n}\n\n/** Replaces a board's definition and phases in place, keeping its key, position and history. */\nasync function writeBoard(\n ops: FactoryStorageOps,\n scope: StoredBoardScope,\n row: BoardRow,\n input: StoredBoardInput,\n actor: string,\n): Promise<void> {\n await updateRow(ops, row, { name: input.name, description: input.description ?? null, updated_by: actor });\n await ops.deleteMany(PHASES, { ...scopeWhere(scope), board_key: row.board_key });\n await insertPhases(ops, scope, { ...input, key: row.board_key });\n}\n\nfunction toIntakeRouteRecord(row: IntakeRouteRow): StoredIntakeRouteRecord {\n return {\n id: row.id,\n orgId: row.org_id,\n factoryProjectId: row.factory_project_id,\n name: row.name,\n enabled: row.enabled,\n position: row.position,\n when: row.when_condition,\n target: { boardKey: row.board_key, phaseKey: row.phase_key },\n revision: row.revision,\n createdBy: row.created_by,\n createdAt: row.created_at,\n updatedBy: row.updated_by,\n updatedAt: row.updated_at,\n };\n}\n\nasync function readIntakeRoutes(ops: FactoryStorageOps, scope: StoredBoardScope): Promise<IntakeRouteRow[]> {\n const rows = await ops.findMany<IntakeRouteRow>(INTAKE_ROUTES, scopeWhere(scope));\n return rows.sort((left, right) => left.position - right.position);\n}\n\nasync function findIntakeRoute(ops: FactoryStorageOps, scope: StoredBoardScope, id: string): Promise<IntakeRouteRow> {\n const row = await ops.findOne<IntakeRouteRow>(INTAKE_ROUTES, { ...scopeWhere(scope), id });\n if (!row) throw intakeRouteNotFound(id);\n return row;\n}\n\nfunction intakeRouteNotFound(id: string): StoredBoardError {\n return new StoredBoardError('intake_route_not_found', `Intake route \"${id}\" does not exist in this project.`);\n}\n\nfunction checkIntakeRouteRevision(row: IntakeRouteRow, expectedRevision: number): void {\n if (row.revision !== expectedRevision) {\n throw new StoredBoardError(\n 'revision_mismatch',\n `Intake route \"${row.name}\" is at revision ${row.revision}, not ${expectedRevision}; reload it and try again.`,\n );\n }\n}\n\n/** Sets columns on a route row and raises its revision, unless another writer changed it first. */\nasync function updateIntakeRouteRow(\n ops: FactoryStorageOps,\n row: IntakeRouteRow,\n set: Partial<IntakeRouteRow>,\n): Promise<number> {\n const revision = row.revision + 1;\n const updated = await ops.updateMany(\n INTAKE_ROUTES,\n { id: row.id, revision: row.revision },\n { ...set, revision, updated_at: new Date() },\n );\n if (updated !== 1) throw new ConcurrentBoardWrite();\n return revision;\n}\n\nasync function insertIntakeRoute(\n ops: FactoryStorageOps,\n scope: StoredBoardScope,\n route: { id: string; input: StoredIntakeRouteInput; position: number; actor: string },\n): Promise<void> {\n const now = new Date();\n await ops.insertOne<IntakeRouteRow>(INTAKE_ROUTES, {\n id: route.id,\n ...scopeWhere(scope),\n name: route.input.name,\n enabled: route.input.enabled ?? true,\n position: route.position,\n when_condition: route.input.when ?? null,\n board_key: route.input.target.boardKey,\n phase_key: route.input.target.phaseKey ?? null,\n revision: 1,\n created_by: route.actor,\n created_at: now,\n updated_by: route.actor,\n updated_at: now,\n });\n}\n\n/**\n * Takes the project's route lock and reads the routes. Writes that add, delete or move routes\n * call this first, so they run one after another and each reads what the one before committed.\n */\nasync function lockIntakeRoutes(ops: FactoryStorageOps, scope: StoredBoardScope): Promise<IntakeRouteRow[]> {\n if ((await ops.updateMany(INTAKE_ROUTE_LOCKS, scopeWhere(scope), { locked_at: new Date() })) !== 1) {\n throw new ConcurrentBoardWrite();\n }\n return readIntakeRoutes(ops, scope);\n}\n\n/** Moves routes, read under the project's route lock, to the positions of their order in `rows`. */\nasync function placeIntakeRoutes(ops: FactoryStorageOps, rows: IntakeRouteRow[], actor?: string): Promise<void> {\n const moving = rows.flatMap((row, position) => (row.position === position ? [] : [{ row, position }]));\n const parked = [];\n for (const [index, { row, position }] of moving.entries()) {\n const revision = await updateIntakeRouteRow(ops, row, {\n position: -(index + 1),\n ...(actor !== undefined && { updated_by: actor }),\n });\n parked.push({ id: row.id, revision, position });\n }\n for (const { id, revision, position } of parked) {\n if ((await ops.updateMany(INTAKE_ROUTES, { id, revision }, { position })) !== 1) throw new ConcurrentBoardWrite();\n }\n}\n"],"mappings":";;;;;AAmIA,MAAa,oBAAoB;;;;;;AAOjC,MAAa,uBAA+C;CAC1D,MAAM;CACN,MAAM;EACJ,UAAU;EACV,YAAY,CACV;GAAE,OAAO;GAAsB,UAAU;GAAM,OAAO,CAAC,UAAU,QAAQ;EAAE,GAC3E;GAAE,OAAO;GAAkB,UAAU;GAAU,OAAO;EAAM,CAC9D;CACF;CACA,QAAQ;EAAE,UAAU;EAAQ,UAAU;CAAS;AACjD;;;;;AAMA,MAAa,4BAAoD;CAC/D,MAAM;CACN,MAAM;EAAE,UAAU;EAAO,YAAY,CAAC;GAAE,OAAO;GAAe,UAAU;GAAU,OAAO;EAAe,CAAC;CAAE;CAC3G,QAAQ;EAAE,UAAU;EAAQ,UAAU;CAAY;AACpD;;;;;;AAOA,MAAa,wBAAmF,CAC9F;CAAE,KAAK;CAAmB,OAAO;AAAqB,GACtD;CAAE,KAAK;CAAiB,OAAO;AAA0B,CAC3D;;AAGA,MAAM,wBAAwB,CAAC,iBAAiB;;AAGhD,MAAa,6BAA6B;AAE1C,IAAa,mBAAb,cAAsC,MAAM;CAG/B;CAFX,OAAgB;CAChB,YACE,MACA,SACA;EACA,MAAM,OAAO;EAHJ,KAAA,OAAA;CAIX;AACF;AAwDA,SA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I,IAAI;GAAI;GAAU;EAAS,CAAC;CAChD;CACA,KAAK,MAAM,EAAE,IAAI,UAAU,cAAc,QACvC,IAAK,MAAM,IAAI,WAAW,eAAe;EAAE;EAAI;CAAS,GAAG,EAAE,SAAS,CAAC,MAAO,GAAG,MAAM,IAAI,qBAAqB;AAEpH"}
|
|
@@ -3,6 +3,14 @@ import type { CollectionSchema } from '@mastra/core/storage';
|
|
|
3
3
|
export declare const FACTORY_BOARDS_SCHEMA: CollectionSchema;
|
|
4
4
|
/** A board's ordered phases. `phase_key` is the stage id cards sit in. */
|
|
5
5
|
export declare const FACTORY_BOARD_PHASES_SCHEMA: CollectionSchema;
|
|
6
|
+
/** A project's ordered intake routes: where new cards matching `when_condition` land. */
|
|
7
|
+
export declare const FACTORY_INTAKE_ROUTES_SCHEMA: CollectionSchema;
|
|
8
|
+
/**
|
|
9
|
+
* One row per project that every write adding, deleting or moving intake routes upserts first,
|
|
10
|
+
* inside its transaction. The upsert holds the row until commit, so those writes on one project
|
|
11
|
+
* run one after another and positions stay 0..n-1 with no gaps.
|
|
12
|
+
*/
|
|
13
|
+
export declare const FACTORY_INTAKE_ROUTE_LOCKS_SCHEMA: CollectionSchema;
|
|
6
14
|
/**
|
|
7
15
|
* One row per project whose `version` is replaced inside every board write, so other replicas
|
|
8
16
|
* can tell their cached boards are stale with one indexed read.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../../../../src/storage/domains/boards/schemas.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAE7D,sFAAsF;AACtF,eAAO,MAAM,qBAAqB,EAAE,gBAmBnC,CAAC;AAEF,0EAA0E;AAC1E,eAAO,MAAM,2BAA2B,EAAE,gBA0BzC,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,wCAAwC,EAAE,gBAUtD,CAAC"}
|
|
1
|
+
{"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../../../../src/storage/domains/boards/schemas.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAE7D,sFAAsF;AACtF,eAAO,MAAM,qBAAqB,EAAE,gBAmBnC,CAAC;AAEF,0EAA0E;AAC1E,eAAO,MAAM,2BAA2B,EAAE,gBA0BzC,CAAC;AAEF,yFAAyF;AACzF,eAAO,MAAM,4BAA4B,EAAE,gBAyB1C,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,iCAAiC,EAAE,gBAY/C,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,wCAAwC,EAAE,gBAUtD,CAAC"}
|