@rothenbergt/backstage-plugin-roadmap-backend 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -2
- package/dist/boardConfig.cjs.js +86 -0
- package/dist/boardConfig.cjs.js.map +1 -0
- package/dist/database/RoadmapDatabaseClient.cjs.js +87 -7
- package/dist/database/RoadmapDatabaseClient.cjs.js.map +1 -1
- package/dist/database/statusDbMapping.cjs.js +19 -0
- package/dist/database/statusDbMapping.cjs.js.map +1 -0
- package/dist/gitlab/RoadmapGitlabClient.cjs.js +68 -29
- package/dist/gitlab/RoadmapGitlabClient.cjs.js.map +1 -1
- package/dist/index.d.ts +6 -1
- package/dist/plugin.cjs.js +8 -2
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/routes/commentsRouter.cjs.js +21 -2
- package/dist/routes/commentsRouter.cjs.js.map +1 -1
- package/dist/routes/featuresRouter.cjs.js +105 -8
- package/dist/routes/featuresRouter.cjs.js.map +1 -1
- package/dist/routes/router.cjs.js.map +1 -1
- package/dist/services/CommentService.cjs.js +13 -1
- package/dist/services/CommentService.cjs.js.map +1 -1
- package/dist/services/FeatureService.cjs.js +84 -9
- package/dist/services/FeatureService.cjs.js.map +1 -1
- package/dist/services/featureBoardFilter.cjs.js +36 -0
- package/dist/services/featureBoardFilter.cjs.js.map +1 -0
- package/migrations/20260420000000_board_position.js +17 -0
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -40,15 +40,21 @@ This plugin follows a layered architecture with clear separation of concerns:
|
|
|
40
40
|
|
|
41
41
|
### Features
|
|
42
42
|
|
|
43
|
-
- `GET /features`:
|
|
43
|
+
- `GET /features/board-config`: Resolved board columns (labels, visibility, retention settings) and UI capability flags for the active datasource.
|
|
44
|
+
- `GET /features`: Roadmap features for the board. With the **database** datasource, the list is filtered server-side using merged board config: hidden columns (`visible: false`) are omitted, and per-status **retention** hides stale items from this response. GitLab mode returns the existing issue list (no retention filtering added server-side).
|
|
45
|
+
- `GET /features?includeBeyondRetention=true`: **Database only.** Same column-visibility rules as the default list, but items past their retention window are included. Ignored when `roadmap.source` is `gitlab`.
|
|
44
46
|
- `POST /features`: Create a new feature suggestion
|
|
45
47
|
- `GET /features/:id`: Get a specific feature
|
|
46
48
|
- `PUT /features/:id/status`: Update feature status (admin only)
|
|
49
|
+
- `PUT /features/:id`: Update title and/or description (**database** only; admins always; non-admins only when they are the author and the feature is **Suggested**). Returns **403** for GitLab.
|
|
50
|
+
- `DELETE /features/:id`: Delete a feature (**database** only; admin, or author on **Suggested**). Returns **403** for GitLab.
|
|
51
|
+
- `PUT /features/reorder`: Reorder features within a status column (**database**, admin). Returns **403** for GitLab.
|
|
47
52
|
|
|
48
53
|
### Comments
|
|
49
54
|
|
|
50
55
|
- `GET /comments?featureId=123`: Get comments for a feature
|
|
51
56
|
- `POST /comments`: Add a comment to a feature
|
|
57
|
+
- `DELETE /comments/:commentId`: Delete a comment (**database**, admin). Returns **403** for GitLab.
|
|
52
58
|
|
|
53
59
|
### Votes
|
|
54
60
|
|
|
@@ -63,11 +69,24 @@ This plugin follows a layered architecture with clear separation of concerns:
|
|
|
63
69
|
|
|
64
70
|
## Development
|
|
65
71
|
|
|
72
|
+
### Board configuration (`app-config.yaml`)
|
|
73
|
+
|
|
74
|
+
Optional `roadmap.columns` merges with built-in defaults. Each entry may set:
|
|
75
|
+
|
|
76
|
+
- `status`: One of the `FeatureStatus` values (`Suggested`, `Planned`, `InProgress`, `Completed`, `Declined`).
|
|
77
|
+
- `title`: Column label shown in the UI.
|
|
78
|
+
- `visible`: When `false`, features in that status are omitted from list endpoints (default board keeps **In Progress** hidden).
|
|
79
|
+
- `retentionDays` / `retentionAnchor` (`created` | `updated`): **Database** list filtering only; default list excludes older items; `includeBeyondRetention=true` opts in to the full set (still respecting hidden columns).
|
|
80
|
+
|
|
81
|
+
### GitLab datasource freeze
|
|
82
|
+
|
|
83
|
+
When `roadmap.source` is `gitlab`, behavior stays limited to what the GitLab integration already supported: read/list, create feature and comment, voting, and admin status changes via labels. New capabilities (title/description edit, deletes, creator self-service edit/delete, reorder, retention and `includeBeyondRetention`) are **not** implemented for GitLab; related routes return **403 Not allowed** and the frontend hides those actions based on `GET /features/board-config` capabilities.
|
|
84
|
+
|
|
66
85
|
### Database Schema
|
|
67
86
|
|
|
68
87
|
The plugin sets up three main tables:
|
|
69
88
|
|
|
70
|
-
- **features**: Roadmap items with title, description, status, etc.
|
|
89
|
+
- **features**: Roadmap items with title, description, status, `board_position` (ordering within a status), etc.
|
|
71
90
|
- **comments**: User comments on features
|
|
72
91
|
- **votes**: User votes on features with unique constraint
|
|
73
92
|
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var backstagePluginRoadmapCommon = require('@rothenbergt/backstage-plugin-roadmap-common');
|
|
4
|
+
|
|
5
|
+
const ALL_STATUSES = Object.values(backstagePluginRoadmapCommon.FeatureStatus);
|
|
6
|
+
function defaultTitle(status) {
|
|
7
|
+
return status;
|
|
8
|
+
}
|
|
9
|
+
function buildDefaultColumns() {
|
|
10
|
+
return ALL_STATUSES.map((status) => ({
|
|
11
|
+
status,
|
|
12
|
+
title: defaultTitle(status),
|
|
13
|
+
visible: status === backstagePluginRoadmapCommon.FeatureStatus.InProgress ? false : true,
|
|
14
|
+
retentionAnchor: "updated"
|
|
15
|
+
}));
|
|
16
|
+
}
|
|
17
|
+
function parseAnchor(v) {
|
|
18
|
+
if (v === "created" || v === "updated") return v;
|
|
19
|
+
return "updated";
|
|
20
|
+
}
|
|
21
|
+
function getMergedBoardColumns(config) {
|
|
22
|
+
const defaults = buildDefaultColumns();
|
|
23
|
+
const roadmap = config.getOptionalConfig("roadmap");
|
|
24
|
+
const entries = roadmap?.getOptionalConfigArray("columns");
|
|
25
|
+
if (!entries?.length) {
|
|
26
|
+
return defaults;
|
|
27
|
+
}
|
|
28
|
+
const byStatus = new Map(
|
|
29
|
+
defaults.map((c) => [c.status, { ...c }])
|
|
30
|
+
);
|
|
31
|
+
for (const entry of entries) {
|
|
32
|
+
const statusStr = entry.getOptionalString("status");
|
|
33
|
+
if (!statusStr || !ALL_STATUSES.includes(statusStr)) {
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
const status = statusStr;
|
|
37
|
+
const existing = byStatus.get(status);
|
|
38
|
+
const title = entry.getOptionalString("title") ?? existing.title;
|
|
39
|
+
const visible = entry.getOptionalBoolean("visible") ?? existing.visible;
|
|
40
|
+
const retentionDays = entry.getOptionalNumber("retentionDays");
|
|
41
|
+
const retentionAnchor = parseAnchor(
|
|
42
|
+
entry.getOptionalString("retentionAnchor")
|
|
43
|
+
);
|
|
44
|
+
byStatus.set(status, {
|
|
45
|
+
status,
|
|
46
|
+
title,
|
|
47
|
+
visible,
|
|
48
|
+
retentionDays: retentionDays !== void 0 && retentionDays > 0 ? retentionDays : void 0,
|
|
49
|
+
retentionAnchor
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
return ALL_STATUSES.map((s) => byStatus.get(s));
|
|
53
|
+
}
|
|
54
|
+
function getRoadmapUiCapabilities(datasource) {
|
|
55
|
+
if (datasource === "gitlab") {
|
|
56
|
+
return {
|
|
57
|
+
retentionFiltering: false,
|
|
58
|
+
includeBeyondRetentionQuery: false,
|
|
59
|
+
adminEditTitleDescription: false,
|
|
60
|
+
adminDeleteFeature: false,
|
|
61
|
+
adminDeleteComment: false,
|
|
62
|
+
creatorEditDeleteSuggested: false,
|
|
63
|
+
adminReorder: false
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
return {
|
|
67
|
+
retentionFiltering: true,
|
|
68
|
+
includeBeyondRetentionQuery: true,
|
|
69
|
+
adminEditTitleDescription: true,
|
|
70
|
+
adminDeleteFeature: true,
|
|
71
|
+
adminDeleteComment: true,
|
|
72
|
+
creatorEditDeleteSuggested: true,
|
|
73
|
+
adminReorder: true
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
function getBoardConfigResponse(config, datasource) {
|
|
77
|
+
return {
|
|
78
|
+
columns: getMergedBoardColumns(config),
|
|
79
|
+
capabilities: getRoadmapUiCapabilities(datasource)
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
exports.getBoardConfigResponse = getBoardConfigResponse;
|
|
84
|
+
exports.getMergedBoardColumns = getMergedBoardColumns;
|
|
85
|
+
exports.getRoadmapUiCapabilities = getRoadmapUiCapabilities;
|
|
86
|
+
//# sourceMappingURL=boardConfig.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"boardConfig.cjs.js","sources":["../src/boardConfig.ts"],"sourcesContent":["import { Config } from '@backstage/config';\nimport {\n FeatureStatus,\n RoadmapBoardColumnResolved,\n RoadmapRetentionAnchor,\n RoadmapBoardConfigResponse,\n RoadmapUiCapabilities,\n} from '@rothenbergt/backstage-plugin-roadmap-common';\nimport { DatasourceType } from './types';\n\nconst ALL_STATUSES = Object.values(FeatureStatus);\n\nfunction defaultTitle(status: FeatureStatus): string {\n return status;\n}\n\nfunction buildDefaultColumns(): RoadmapBoardColumnResolved[] {\n return ALL_STATUSES.map(status => ({\n status,\n title: defaultTitle(status),\n visible: status === FeatureStatus.InProgress ? false : true,\n retentionAnchor: 'updated' as RoadmapRetentionAnchor,\n }));\n}\n\nfunction parseAnchor(v: string | undefined): RoadmapRetentionAnchor {\n if (v === 'created' || v === 'updated') return v;\n return 'updated';\n}\n\n/**\n * Reads optional `roadmap.columns` from config and merges with defaults.\n * Default: In Progress column exists but `visible: false`.\n */\nexport function getMergedBoardColumns(\n config: Config,\n): RoadmapBoardColumnResolved[] {\n const defaults = buildDefaultColumns();\n const roadmap = config.getOptionalConfig('roadmap');\n const entries = roadmap?.getOptionalConfigArray('columns');\n if (!entries?.length) {\n return defaults;\n }\n\n const byStatus = new Map<FeatureStatus, RoadmapBoardColumnResolved>(\n defaults.map(c => [c.status, { ...c }]),\n );\n\n for (const entry of entries) {\n const statusStr = entry.getOptionalString('status');\n if (!statusStr || !ALL_STATUSES.includes(statusStr as FeatureStatus)) {\n continue;\n }\n const status = statusStr as FeatureStatus;\n const existing = byStatus.get(status)!;\n const title = entry.getOptionalString('title') ?? existing.title;\n const visible = entry.getOptionalBoolean('visible') ?? existing.visible;\n const retentionDays = entry.getOptionalNumber('retentionDays');\n const retentionAnchor = parseAnchor(\n entry.getOptionalString('retentionAnchor'),\n );\n byStatus.set(status, {\n status,\n title,\n visible,\n retentionDays:\n retentionDays !== undefined && retentionDays > 0\n ? retentionDays\n : undefined,\n retentionAnchor,\n });\n }\n\n return ALL_STATUSES.map(s => byStatus.get(s)!);\n}\n\nexport function getRoadmapUiCapabilities(\n datasource: DatasourceType,\n): RoadmapUiCapabilities {\n if (datasource === 'gitlab') {\n return {\n retentionFiltering: false,\n includeBeyondRetentionQuery: false,\n adminEditTitleDescription: false,\n adminDeleteFeature: false,\n adminDeleteComment: false,\n creatorEditDeleteSuggested: false,\n adminReorder: false,\n };\n }\n return {\n retentionFiltering: true,\n includeBeyondRetentionQuery: true,\n adminEditTitleDescription: true,\n adminDeleteFeature: true,\n adminDeleteComment: true,\n creatorEditDeleteSuggested: true,\n adminReorder: true,\n };\n}\n\nexport function getBoardConfigResponse(\n config: Config,\n datasource: DatasourceType,\n): RoadmapBoardConfigResponse {\n return {\n columns: getMergedBoardColumns(config),\n capabilities: getRoadmapUiCapabilities(datasource),\n };\n}\n"],"names":["FeatureStatus"],"mappings":";;;;AAUA,MAAM,YAAA,GAAe,MAAO,CAAA,MAAA,CAAOA,0CAAa,CAAA;AAEhD,SAAS,aAAa,MAA+B,EAAA;AACnD,EAAO,OAAA,MAAA;AACT;AAEA,SAAS,mBAAoD,GAAA;AAC3D,EAAO,OAAA,YAAA,CAAa,IAAI,CAAW,MAAA,MAAA;AAAA,IACjC,MAAA;AAAA,IACA,KAAA,EAAO,aAAa,MAAM,CAAA;AAAA,IAC1B,OAAS,EAAA,MAAA,KAAWA,0C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enbergt/backstage-plugin-roadmap-common');
|
|
4
4
|
var errors = require('@backstage/errors');
|
|
5
5
|
var backendPluginApi = require('@backstage/backend-plugin-api');
|
|
6
|
+
var statusDbMapping = require('./statusDbMapping.cjs.js');
|
|
6
7
|
|
|
7
8
|
const migrationsDir = backendPluginApi.resolvePackagePath(
|
|
8
9
|
"@rothenbergt/backstage-plugin-roadmap-backend",
|
|
@@ -27,6 +28,19 @@ class RoadmapDatabaseClient {
|
|
|
27
28
|
this.knex = knexInstance;
|
|
28
29
|
this.logger = logger;
|
|
29
30
|
}
|
|
31
|
+
mapFeature(row) {
|
|
32
|
+
return {
|
|
33
|
+
id: String(row.id),
|
|
34
|
+
title: String(row.title),
|
|
35
|
+
description: String(row.description),
|
|
36
|
+
status: statusDbMapping.statusFromDb(String(row.status)),
|
|
37
|
+
votes: Number(row.votes ?? 0),
|
|
38
|
+
author: String(row.author),
|
|
39
|
+
created_at: String(row.created_at),
|
|
40
|
+
updated_at: String(row.updated_at),
|
|
41
|
+
board_position: row.board_position !== void 0 && row.board_position !== null ? Number(row.board_position) : 0
|
|
42
|
+
};
|
|
43
|
+
}
|
|
30
44
|
async addComment(comment) {
|
|
31
45
|
const trx = await this.knex.transaction();
|
|
32
46
|
try {
|
|
@@ -76,13 +90,16 @@ class RoadmapDatabaseClient {
|
|
|
76
90
|
async addFeature(feature) {
|
|
77
91
|
const trx = await this.knex.transaction();
|
|
78
92
|
try {
|
|
93
|
+
const maxRow = await trx("features").where({ status: statusDbMapping.statusToDb(backstagePluginRoadmapCommon.FeatureStatus.Suggested) }).max("board_position as maxp").first();
|
|
94
|
+
const nextPosition = Number(maxRow?.maxp ?? 0) + 1;
|
|
79
95
|
const [newFeature] = await trx("features").insert({
|
|
80
96
|
...feature,
|
|
81
|
-
status: backstagePluginRoadmapCommon.FeatureStatus.Suggested,
|
|
82
|
-
votes: 0
|
|
97
|
+
status: statusDbMapping.statusToDb(backstagePluginRoadmapCommon.FeatureStatus.Suggested),
|
|
98
|
+
votes: 0,
|
|
99
|
+
board_position: nextPosition
|
|
83
100
|
}).returning("*");
|
|
84
101
|
await trx.commit();
|
|
85
|
-
return newFeature;
|
|
102
|
+
return this.mapFeature(newFeature);
|
|
86
103
|
} catch (error) {
|
|
87
104
|
await trx.rollback();
|
|
88
105
|
this.logger.error("Error adding feature", { error: String(error) });
|
|
@@ -91,7 +108,12 @@ class RoadmapDatabaseClient {
|
|
|
91
108
|
}
|
|
92
109
|
async getAllFeatures() {
|
|
93
110
|
try {
|
|
94
|
-
|
|
111
|
+
const rows = await this.knex("features").orderBy([
|
|
112
|
+
{ column: "status", order: "asc" },
|
|
113
|
+
{ column: "board_position", order: "asc" },
|
|
114
|
+
{ column: "created_at", order: "desc" }
|
|
115
|
+
]).select("*");
|
|
116
|
+
return rows.map((r) => this.mapFeature(r));
|
|
95
117
|
} catch (error) {
|
|
96
118
|
this.logger.error("Error fetching all features", {
|
|
97
119
|
error: String(error)
|
|
@@ -105,7 +127,7 @@ class RoadmapDatabaseClient {
|
|
|
105
127
|
if (!feature) {
|
|
106
128
|
throw new errors.NotFoundError(`Feature with id ${id} not found`);
|
|
107
129
|
}
|
|
108
|
-
return feature;
|
|
130
|
+
return this.mapFeature(feature);
|
|
109
131
|
} catch (error) {
|
|
110
132
|
this.logger.error(`Error fetching feature ${id}`, {
|
|
111
133
|
error: String(error)
|
|
@@ -128,11 +150,11 @@ class RoadmapDatabaseClient {
|
|
|
128
150
|
throw new errors.NotFoundError(`Feature with id ${id} not found`);
|
|
129
151
|
}
|
|
130
152
|
const [updatedFeature] = await trx("features").where({ id }).update({
|
|
131
|
-
status,
|
|
153
|
+
status: statusDbMapping.statusToDb(status),
|
|
132
154
|
updated_at: this.knex.fn.now()
|
|
133
155
|
}).returning("*");
|
|
134
156
|
await trx.commit();
|
|
135
|
-
return updatedFeature;
|
|
157
|
+
return this.mapFeature(updatedFeature);
|
|
136
158
|
} catch (error) {
|
|
137
159
|
await trx.rollback();
|
|
138
160
|
this.logger.error("Error updating feature status", {
|
|
@@ -147,6 +169,64 @@ class RoadmapDatabaseClient {
|
|
|
147
169
|
);
|
|
148
170
|
}
|
|
149
171
|
}
|
|
172
|
+
async updateFeatureDetails(id, fields) {
|
|
173
|
+
const trx = await this.knex.transaction();
|
|
174
|
+
try {
|
|
175
|
+
const feature = await trx("features").where({ id }).first();
|
|
176
|
+
if (!feature) {
|
|
177
|
+
await trx.rollback();
|
|
178
|
+
throw new errors.NotFoundError(`Feature with id ${id} not found`);
|
|
179
|
+
}
|
|
180
|
+
const patch = { updated_at: this.knex.fn.now() };
|
|
181
|
+
if (fields.title !== void 0) patch.title = fields.title;
|
|
182
|
+
if (fields.description !== void 0)
|
|
183
|
+
patch.description = fields.description;
|
|
184
|
+
const [updated] = await trx("features").where({ id }).update(patch).returning("*");
|
|
185
|
+
await trx.commit();
|
|
186
|
+
return this.mapFeature(updated);
|
|
187
|
+
} catch (error) {
|
|
188
|
+
await trx.rollback();
|
|
189
|
+
if (error instanceof errors.NotFoundError) throw error;
|
|
190
|
+
this.logger.error("Error updating feature details", {
|
|
191
|
+
error: String(error)
|
|
192
|
+
});
|
|
193
|
+
throw new errors.ConflictError(`Failed to update feature ${id}`, error);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
async deleteFeature(id) {
|
|
197
|
+
const n = await this.knex("features").where({ id }).delete();
|
|
198
|
+
if (!n) {
|
|
199
|
+
throw new errors.NotFoundError(`Feature with id ${id} not found`);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
async reorderFeaturesInStatus(status, orderedIds) {
|
|
203
|
+
const trx = await this.knex.transaction();
|
|
204
|
+
try {
|
|
205
|
+
for (let i = 0; i < orderedIds.length; i += 1) {
|
|
206
|
+
const updated = await trx("features").where({ id: orderedIds[i], status: statusDbMapping.statusToDb(status) }).update({
|
|
207
|
+
board_position: i
|
|
208
|
+
});
|
|
209
|
+
if (!updated) {
|
|
210
|
+
await trx.rollback();
|
|
211
|
+
throw new errors.NotFoundError(
|
|
212
|
+
`Feature ${orderedIds[i]} not found or not in status ${status}`
|
|
213
|
+
);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
await trx.commit();
|
|
217
|
+
} catch (error) {
|
|
218
|
+
await trx.rollback();
|
|
219
|
+
if (error instanceof errors.NotFoundError) throw error;
|
|
220
|
+
this.logger.error("Error reordering features", { error: String(error) });
|
|
221
|
+
throw new errors.ConflictError("Failed to reorder features", error);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
async deleteCommentById(commentId) {
|
|
225
|
+
const n = await this.knex("comments").where({ id: commentId }).delete();
|
|
226
|
+
if (!n) {
|
|
227
|
+
throw new errors.NotFoundError(`Comment with id ${commentId} not found`);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
150
230
|
async toggleVote(featureId, voter) {
|
|
151
231
|
const trx = await this.knex.transaction();
|
|
152
232
|
try {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RoadmapDatabaseClient.cjs.js","sources":["../../src/database/RoadmapDatabaseClient.ts"],"sourcesContent":["import { Knex } from 'knex';\nimport {\n Feature,\n NewFeature,\n FeatureStatus,\n Comment,\n NewComment,\n} from '@rothenbergt/backstage-plugin-roadmap-common';\nimport { RoadmapDatasource } from '../types';\nimport { LoggerService, DatabaseService } from '@backstage/backend-plugin-api';\nimport { NotFoundError, ConflictError } from '@backstage/errors';\nimport { resolvePackagePath } from '@backstage/backend-plugin-api';\n\nconst migrationsDir = resolvePackagePath(\n '@rothenbergt/backstage-plugin-roadmap-backend',\n 'migrations',\n);\n\n/**\n * Implementation of the RoadmapDatasource interface using Knex\n */\nexport class RoadmapDatabaseClient implements RoadmapDatasource {\n static async create(options: {\n database: DatabaseService;\n logger: LoggerService;\n }): Promise<RoadmapDatabaseClient> {\n const { database, logger } = options;\n logger.info('Creating database for roadmap plugin');\n\n const client = await database.getClient();\n\n if (!database.migrations?.skip) {\n logger.info('Running migrations for roadmap plugin');\n await client.migrate.latest({\n directory: migrationsDir,\n });\n }\n\n return new RoadmapDatabaseClient(client, logger);\n }\n\n private readonly knex: Knex;\n private readonly logger: LoggerService;\n\n constructor(knexInstance: Knex, logger: LoggerService) {\n this.knex = knexInstance;\n this.logger = logger;\n }\n\n async addComment(comment: NewComment): Promise<Comment> {\n const trx = await this.knex.transaction();\n try {\n // First check if the feature exists\n const feature = await trx('features')\n .where({ id: comment.featureId })\n .first();\n\n if (!feature) {\n await trx.rollback();\n throw new NotFoundError(\n `Feature with id ${comment.featureId} not found`,\n );\n }\n\n // Insert comment and return the complete inserted object\n const [newComment] = await trx('comments')\n .insert({\n feature_id: comment.featureId,\n text: comment.text,\n author: comment.author,\n })\n .returning('*');\n\n await trx.commit();\n return newComment;\n } catch (error) {\n await trx.rollback();\n this.logger.error('Error inserting comment', { error: String(error) });\n\n // Rethrow NotFoundError as is\n if (error instanceof NotFoundError) {\n throw error;\n }\n\n throw new ConflictError('Failed to add comment', error as Error);\n }\n }\n\n async getCommentsByFeatureId(featureId: string): Promise<Comment[]> {\n try {\n // First check if the feature exists\n const feature = await this.knex('features')\n .where({ id: featureId })\n .first();\n\n if (!feature) {\n throw new NotFoundError(`Feature with id ${featureId} not found`);\n }\n\n // Get comments ordered by creation date (newest first)\n return this.knex('comments')\n .where({ feature_id: featureId })\n .orderBy('created_at', 'desc')\n .select('*');\n } catch (error) {\n this.logger.error(`Error fetching comments for feature ${featureId}`, {\n error: String(error),\n });\n\n // Rethrow NotFoundError as is\n if (error instanceof NotFoundError) {\n throw error;\n }\n\n throw new ConflictError(\n `Failed to get comments for feature ${featureId}`,\n error as Error,\n );\n }\n }\n\n async addFeature(feature: NewFeature & { author: string }): Promise<Feature> {\n const trx = await this.knex.transaction();\n try {\n // Insert feature and return the complete inserted object\n const [newFeature] = await trx('features')\n .insert({\n ...feature,\n status: FeatureStatus.Suggested,\n votes: 0,\n })\n .returning('*');\n\n await trx.commit();\n return newFeature;\n } catch (error) {\n await trx.rollback();\n this.logger.error('Error adding feature', { error: String(error) });\n throw new ConflictError('Failed to add feature', error as Error);\n }\n }\n\n async getAllFeatures(): Promise<Feature[]> {\n try {\n return this.knex('features').orderBy('created_at', 'desc').select('*');\n } catch (error) {\n this.logger.error('Error fetching all features', {\n error: String(error),\n });\n throw new ConflictError('Failed to get all features', error as Error);\n }\n }\n\n async getFeatureById(id: string): Promise<Feature> {\n try {\n const feature = await this.knex('features').where({ id }).first();\n\n if (!feature) {\n throw new NotFoundError(`Feature with id ${id} not found`);\n }\n\n return feature;\n } catch (error) {\n this.logger.error(`Error fetching feature ${id}`, {\n error: String(error),\n });\n\n // Rethrow NotFoundError as is\n if (error instanceof NotFoundError) {\n throw error;\n }\n\n throw new ConflictError(\n `Failed to get feature with id ${id}`,\n error as Error,\n );\n }\n }\n\n async updateFeatureStatus(\n id: string,\n status: FeatureStatus,\n ): Promise<Feature> {\n const trx = await this.knex.transaction();\n try {\n // First check if the feature exists\n const feature = await trx('features').where({ id }).first();\n\n if (!feature) {\n await trx.rollback();\n throw new NotFoundError(`Feature with id ${id} not found`);\n }\n\n // Update the status and return the updated object\n const [updatedFeature] = await trx('features')\n .where({ id })\n .update({\n status,\n updated_at: this.knex.fn.now(),\n })\n .returning('*');\n\n await trx.commit();\n return updatedFeature;\n } catch (error) {\n await trx.rollback();\n this.logger.error('Error updating feature status', {\n error: String(error),\n });\n\n // Rethrow NotFoundError as is\n if (error instanceof NotFoundError) {\n throw error;\n }\n\n throw new ConflictError(\n `Failed to update status for feature ${id}`,\n error as Error,\n );\n }\n }\n\n async toggleVote(\n featureId: string,\n voter: string,\n ): Promise<{ voteAdded: boolean; voteCount: number }> {\n const trx = await this.knex.transaction();\n try {\n // First check if the feature exists\n const feature = await trx('features').where({ id: featureId }).first();\n\n if (!feature) {\n await trx.rollback();\n throw new NotFoundError(`Feature with id ${featureId} not found`);\n }\n\n const existingVote = await trx('votes')\n .where({ feature_id: featureId, voter })\n .first();\n\n let voteAdded: boolean;\n if (existingVote) {\n // Remove the vote\n await trx('votes').where({ feature_id: featureId, voter }).delete();\n await trx('features').where({ id: featureId }).decrement('votes', 1);\n voteAdded = false;\n } else {\n // Add the vote\n await trx('votes').insert({ feature_id: featureId, voter });\n await trx('features').where({ id: featureId }).increment('votes', 1);\n voteAdded = true;\n }\n\n // Read the updated count within the same transaction\n const updated = await trx('features')\n .where({ id: featureId })\n .select('votes')\n .first();\n await trx.commit();\n return { voteAdded, voteCount: updated?.votes ?? 0 };\n } catch (error) {\n await trx.rollback();\n this.logger.error('Error toggling vote', { error: String(error) });\n\n // Rethrow NotFoundError as is\n if (error instanceof NotFoundError) {\n throw error;\n }\n\n throw new ConflictError(\n `Failed to toggle vote for feature ${featureId}`,\n error as Error,\n );\n }\n }\n\n async getVoteCount(featureId: string): Promise<number> {\n const counts = await this.getVoteCounts([featureId]);\n return counts[featureId] || 0;\n }\n\n async getVoteCounts(featureIds: string[]): Promise<Record<string, number>> {\n try {\n if (featureIds.length === 0) {\n return {};\n }\n\n const results = await this.knex('features')\n .whereIn('id', featureIds)\n .select('id', 'votes');\n\n return results.reduce((acc, { id, votes }) => {\n acc[id] = votes;\n return acc;\n }, {} as Record<string, number>);\n } catch (error) {\n this.logger.error('Error getting vote counts', { error: String(error) });\n throw new ConflictError('Failed to get vote counts', error as Error);\n }\n }\n\n async hasVoted(featureId: string, voter: string): Promise<boolean> {\n try {\n const vote = await this.knex('votes')\n .where({ feature_id: featureId, voter })\n .first();\n return !!vote;\n } catch (error) {\n this.logger.error('Error checking if user has voted', {\n error: String(error),\n });\n throw new ConflictError(\n `Failed to check if user ${voter} has voted on feature ${featureId}`,\n error as Error,\n );\n }\n }\n\n async hasVotedBatch(\n featureIds: string[],\n voter: string,\n ): Promise<Record<string, boolean>> {\n try {\n if (featureIds.length === 0) {\n return {};\n }\n\n const votes = await this.knex('votes')\n .whereIn('feature_id', featureIds)\n .where({ voter })\n .select('feature_id');\n\n const votedFeatureIds = new Set(votes.map(v => v.feature_id.toString()));\n\n return featureIds.reduce((acc, featureId) => {\n acc[featureId] = votedFeatureIds.has(featureId);\n return acc;\n }, {} as Record<string, boolean>);\n } catch (error) {\n this.logger.error('Error checking batch votes', { error: String(error) });\n throw new ConflictError(\n `Failed to check votes for user ${voter}`,\n error as Error,\n );\n }\n }\n}\n"],"names":["resolvePackagePath","NotFoundError","ConflictError","FeatureStatus"],"mappings":";;;;;;AAaA,MAAM,aAAgB,GAAAA,mCAAA;AAAA,EACpB,+CAAA;AAAA,EACA;AACF,CAAA;AAKO,MAAM,qBAAmD,CAAA;AAAA,EAC9D,aAAa,OAAO,OAGe,EAAA;AACjC,IAAM,MAAA,EAAE,QAAU,EAAA,MAAA,EAAW,GAAA,OAAA;AAC7B,IAAA,MAAA,CAAO,KAAK,sCAAsC,CAAA;AAElD,IAAM,MAAA,MAAA,GAAS,MAAM,QAAA,CAAS,SAAU,EAAA;AAExC,IAAI,IAAA,CAAC,QAAS,CAAA,UAAA,EAAY,IAAM,EAAA;AAC9B,MAAA,MAAA,CAAO,KAAK,uCAAuC,CAAA;AACnD,MAAM,MAAA,MAAA,CAAO,QAAQ,MAAO,CAAA;AAAA,QAC1B,SAAW,EAAA;AAAA,OACZ,CAAA;AAAA;AAGH,IAAO,OAAA,IAAI,qBAAsB,CAAA,MAAA,EAAQ,MAAM,CAAA;AAAA;AACjD,EAEiB,IAAA;AAAA,EACA,MAAA;AAAA,EAEjB,WAAA,CAAY,cAAoB,MAAuB,EAAA;AACrD,IAAA,IAAA,CAAK,IAAO,GAAA,YAAA;AACZ,IAAA,IAAA,CAAK,MAAS,GAAA,MAAA;AAAA;AAChB,EAEA,MAAM,WAAW,OAAuC,EAAA;AACtD,IAAA,MAAM,GAAM,GAAA,MAAM,IAAK,CAAA,IAAA,CAAK,WAAY,EAAA;AACxC,IAAI,IAAA;AAEF,MAAA,MAAM,OAAU,GAAA,MAAM,GAAI,CAAA,UAAU,CACjC,CAAA,KAAA,CAAM,EAAE,EAAA,EAAI,OAAQ,CAAA,SAAA,EAAW,CAAA,CAC/B,KA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AAA,CAAO,MAAM,kCAAoC,EAAA;AAAA,QACpD,KAAA,EAAO,OAAO,KAAK;AAAA,OACpB,CAAA;AACD,MAAA,MAAM,IAAIA,oBAAA;AAAA,QACR,CAAA,wBAAA,EAA2B,KAAK,CAAA,sBAAA,EAAyB,SAAS,CAAA,CAAA;AAAA,QAClE;AAAA,OACF;AAAA;AACF;AACF,EAEA,MAAM,aACJ,CAAA,UAAA,EACA,KACkC,EAAA;AAClC,IAAI,IAAA;AACF,MAAI,IAAA,UAAA,CAAW,WAAW,CAAG,EAAA;AAC3B,QAAA,OAAO,EAAC;AAAA;AAGV,MAAA,MAAM,QAAQ,MAAM,IAAA,CAAK,IAAK,CAAA,OAAO,EAClC,OAAQ,CAAA,YAAA,EAAc,UAAU,CAAA,CAChC,MAAM,EAAE,KAAA,EAAO,CAAA,CACf,OAAO,YAAY,CAAA;AAEtB,MAAM,MAAA,eAAA,GAAkB,IAAI,GAAA,CAAI,KAAM,CAAA,GAAA,CAAI,OAAK,CAAE,CAAA,UAAA,CAAW,QAAS,EAAC,CAAC,CAAA;AAEvE,MAAA,OAAO,UAAW,CAAA,MAAA,CAAO,CAAC,GAAA,EAAK,SAAc,KAAA;AAC3C,QAAA,GAAA,CAAI,SAAS,CAAA,GAAI,eAAgB,CAAA,GAAA,CAAI,SAAS,CAAA;AAC9C,QAAO,OAAA,GAAA;AAAA,OACT,EAAG,EAA6B,CAAA;AAAA,aACzB,KAAO,EAAA;AACd,MAAK,IAAA,CAAA,MAAA,CAAO,MAAM,4BAA8B,EAAA,EAAE,OAAO,MAAO,CAAA,KAAK,GAAG,CAAA;AACxE,MAAA,MAAM,IAAIA,oBAAA;AAAA,QACR,kCAAkC,KAAK,CAAA,CAAA;AAAA,QACvC;AAAA,OACF;AAAA;AACF;AAEJ;;;;"}
|
|
1
|
+
{"version":3,"file":"RoadmapDatabaseClient.cjs.js","sources":["../../src/database/RoadmapDatabaseClient.ts"],"sourcesContent":["import { Knex } from 'knex';\nimport {\n Feature,\n NewFeature,\n FeatureStatus,\n Comment,\n NewComment,\n} from '@rothenbergt/backstage-plugin-roadmap-common';\nimport { RoadmapDatasource } from '../types';\nimport { LoggerService, DatabaseService } from '@backstage/backend-plugin-api';\nimport { NotFoundError, ConflictError } from '@backstage/errors';\nimport { resolvePackagePath } from '@backstage/backend-plugin-api';\nimport { statusFromDb, statusToDb } from './statusDbMapping';\n\nconst migrationsDir = resolvePackagePath(\n '@rothenbergt/backstage-plugin-roadmap-backend',\n 'migrations',\n);\n\n/**\n * Implementation of the RoadmapDatasource interface using Knex\n */\nexport class RoadmapDatabaseClient implements RoadmapDatasource {\n static async create(options: {\n database: DatabaseService;\n logger: LoggerService;\n }): Promise<RoadmapDatabaseClient> {\n const { database, logger } = options;\n logger.info('Creating database for roadmap plugin');\n\n const client = await database.getClient();\n\n if (!database.migrations?.skip) {\n logger.info('Running migrations for roadmap plugin');\n await client.migrate.latest({\n directory: migrationsDir,\n });\n }\n\n return new RoadmapDatabaseClient(client, logger);\n }\n\n private readonly knex: Knex;\n private readonly logger: LoggerService;\n\n constructor(knexInstance: Knex, logger: LoggerService) {\n this.knex = knexInstance;\n this.logger = logger;\n }\n\n private mapFeature(row: Record<string, unknown>): Feature {\n return {\n id: String(row.id),\n title: String(row.title),\n description: String(row.description),\n status: statusFromDb(String(row.status)),\n votes: Number(row.votes ?? 0),\n author: String(row.author),\n created_at: String(row.created_at),\n updated_at: String(row.updated_at),\n board_position:\n row.board_position !== undefined && row.board_position !== null\n ? Number(row.board_position)\n : 0,\n };\n }\n\n async addComment(comment: NewComment): Promise<Comment> {\n const trx = await this.knex.transaction();\n try {\n // First check if the feature exists\n const feature = await trx('features')\n .where({ id: comment.featureId })\n .first();\n\n if (!feature) {\n await trx.rollback();\n throw new NotFoundError(\n `Feature with id ${comment.featureId} not found`,\n );\n }\n\n // Insert comment and return the complete inserted object\n const [newComment] = await trx('comments')\n .insert({\n feature_id: comment.featureId,\n text: comment.text,\n author: comment.author,\n })\n .returning('*');\n\n await trx.commit();\n return newComment;\n } catch (error) {\n await trx.rollback();\n this.logger.error('Error inserting comment', { error: String(error) });\n\n // Rethrow NotFoundError as is\n if (error instanceof NotFoundError) {\n throw error;\n }\n\n throw new ConflictError('Failed to add comment', error as Error);\n }\n }\n\n async getCommentsByFeatureId(featureId: string): Promise<Comment[]> {\n try {\n // First check if the feature exists\n const feature = await this.knex('features')\n .where({ id: featureId })\n .first();\n\n if (!feature) {\n throw new NotFoundError(`Feature with id ${featureId} not found`);\n }\n\n // Get comments ordered by creation date (newest first)\n return this.knex('comments')\n .where({ feature_id: featureId })\n .orderBy('created_at', 'desc')\n .select('*');\n } catch (error) {\n this.logger.error(`Error fetching comments for feature ${featureId}`, {\n error: String(error),\n });\n\n // Rethrow NotFoundError as is\n if (error instanceof NotFoundError) {\n throw error;\n }\n\n throw new ConflictError(\n `Failed to get comments for feature ${featureId}`,\n error as Error,\n );\n }\n }\n\n async addFeature(feature: NewFeature & { author: string }): Promise<Feature> {\n const trx = await this.knex.transaction();\n try {\n const maxRow = await trx('features')\n .where({ status: statusToDb(FeatureStatus.Suggested) })\n .max('board_position as maxp')\n .first();\n const nextPosition =\n Number((maxRow as { maxp?: string | number })?.maxp ?? 0) + 1;\n\n // Insert feature and return the complete inserted object\n const [newFeature] = await trx('features')\n .insert({\n ...feature,\n status: statusToDb(FeatureStatus.Suggested),\n votes: 0,\n board_position: nextPosition,\n })\n .returning('*');\n\n await trx.commit();\n return this.mapFeature(newFeature);\n } catch (error) {\n await trx.rollback();\n this.logger.error('Error adding feature', { error: String(error) });\n throw new ConflictError('Failed to add feature', error as Error);\n }\n }\n\n async getAllFeatures(): Promise<Feature[]> {\n try {\n const rows = await this.knex('features')\n .orderBy([\n { column: 'status', order: 'asc' },\n { column: 'board_position', order: 'asc' },\n { column: 'created_at', order: 'desc' },\n ])\n .select('*');\n return rows.map(r => this.mapFeature(r));\n } catch (error) {\n this.logger.error('Error fetching all features', {\n error: String(error),\n });\n throw new ConflictError('Failed to get all features', error as Error);\n }\n }\n\n async getFeatureById(id: string): Promise<Feature> {\n try {\n const feature = await this.knex('features').where({ id }).first();\n\n if (!feature) {\n throw new NotFoundError(`Feature with id ${id} not found`);\n }\n\n return this.mapFeature(feature);\n } catch (error) {\n this.logger.error(`Error fetching feature ${id}`, {\n error: String(error),\n });\n\n // Rethrow NotFoundError as is\n if (error instanceof NotFoundError) {\n throw error;\n }\n\n throw new ConflictError(\n `Failed to get feature with id ${id}`,\n error as Error,\n );\n }\n }\n\n async updateFeatureStatus(\n id: string,\n status: FeatureStatus,\n ): Promise<Feature> {\n const trx = await this.knex.transaction();\n try {\n // First check if the feature exists\n const feature = await trx('features').where({ id }).first();\n\n if (!feature) {\n await trx.rollback();\n throw new NotFoundError(`Feature with id ${id} not found`);\n }\n\n // Update the status and return the updated object\n const [updatedFeature] = await trx('features')\n .where({ id })\n .update({\n status: statusToDb(status),\n updated_at: this.knex.fn.now(),\n })\n .returning('*');\n\n await trx.commit();\n return this.mapFeature(updatedFeature);\n } catch (error) {\n await trx.rollback();\n this.logger.error('Error updating feature status', {\n error: String(error),\n });\n\n // Rethrow NotFoundError as is\n if (error instanceof NotFoundError) {\n throw error;\n }\n\n throw new ConflictError(\n `Failed to update status for feature ${id}`,\n error as Error,\n );\n }\n }\n\n async updateFeatureDetails(\n id: string,\n fields: { title?: string; description?: string },\n ): Promise<Feature> {\n const trx = await this.knex.transaction();\n try {\n const feature = await trx('features').where({ id }).first();\n if (!feature) {\n await trx.rollback();\n throw new NotFoundError(`Feature with id ${id} not found`);\n }\n const patch: Record<string, unknown> = { updated_at: this.knex.fn.now() };\n if (fields.title !== undefined) patch.title = fields.title;\n if (fields.description !== undefined)\n patch.description = fields.description;\n const [updated] = await trx('features')\n .where({ id })\n .update(patch)\n .returning('*');\n await trx.commit();\n return this.mapFeature(updated);\n } catch (error) {\n await trx.rollback();\n if (error instanceof NotFoundError) throw error;\n this.logger.error('Error updating feature details', {\n error: String(error),\n });\n throw new ConflictError(`Failed to update feature ${id}`, error as Error);\n }\n }\n\n async deleteFeature(id: string): Promise<void> {\n const n = await this.knex('features').where({ id }).delete();\n if (!n) {\n throw new NotFoundError(`Feature with id ${id} not found`);\n }\n }\n\n async reorderFeaturesInStatus(\n status: FeatureStatus,\n orderedIds: string[],\n ): Promise<void> {\n const trx = await this.knex.transaction();\n try {\n for (let i = 0; i < orderedIds.length; i += 1) {\n const updated = await trx('features')\n .where({ id: orderedIds[i], status: statusToDb(status) })\n .update({\n board_position: i,\n });\n if (!updated) {\n await trx.rollback();\n throw new NotFoundError(\n `Feature ${orderedIds[i]} not found or not in status ${status}`,\n );\n }\n }\n await trx.commit();\n } catch (error) {\n await trx.rollback();\n if (error instanceof NotFoundError) throw error;\n this.logger.error('Error reordering features', { error: String(error) });\n throw new ConflictError('Failed to reorder features', error as Error);\n }\n }\n\n async deleteCommentById(commentId: string): Promise<void> {\n const n = await this.knex('comments').where({ id: commentId }).delete();\n if (!n) {\n throw new NotFoundError(`Comment with id ${commentId} not found`);\n }\n }\n\n async toggleVote(\n featureId: string,\n voter: string,\n ): Promise<{ voteAdded: boolean; voteCount: number }> {\n const trx = await this.knex.transaction();\n try {\n // First check if the feature exists\n const feature = await trx('features').where({ id: featureId }).first();\n\n if (!feature) {\n await trx.rollback();\n throw new NotFoundError(`Feature with id ${featureId} not found`);\n }\n\n const existingVote = await trx('votes')\n .where({ feature_id: featureId, voter })\n .first();\n\n let voteAdded: boolean;\n if (existingVote) {\n // Remove the vote\n await trx('votes').where({ feature_id: featureId, voter }).delete();\n await trx('features').where({ id: featureId }).decrement('votes', 1);\n voteAdded = false;\n } else {\n // Add the vote\n await trx('votes').insert({ feature_id: featureId, voter });\n await trx('features').where({ id: featureId }).increment('votes', 1);\n voteAdded = true;\n }\n\n // Read the updated count within the same transaction\n const updated = await trx('features')\n .where({ id: featureId })\n .select('votes')\n .first();\n await trx.commit();\n return { voteAdded, voteCount: updated?.votes ?? 0 };\n } catch (error) {\n await trx.rollback();\n this.logger.error('Error toggling vote', { error: String(error) });\n\n // Rethrow NotFoundError as is\n if (error instanceof NotFoundError) {\n throw error;\n }\n\n throw new ConflictError(\n `Failed to toggle vote for feature ${featureId}`,\n error as Error,\n );\n }\n }\n\n async getVoteCount(featureId: string): Promise<number> {\n const counts = await this.getVoteCounts([featureId]);\n return counts[featureId] || 0;\n }\n\n async getVoteCounts(featureIds: string[]): Promise<Record<string, number>> {\n try {\n if (featureIds.length === 0) {\n return {};\n }\n\n const results = await this.knex('features')\n .whereIn('id', featureIds)\n .select('id', 'votes');\n\n return results.reduce((acc, { id, votes }) => {\n acc[id] = votes;\n return acc;\n }, {} as Record<string, number>);\n } catch (error) {\n this.logger.error('Error getting vote counts', { error: String(error) });\n throw new ConflictError('Failed to get vote counts', error as Error);\n }\n }\n\n async hasVoted(featureId: string, voter: string): Promise<boolean> {\n try {\n const vote = await this.knex('votes')\n .where({ feature_id: featureId, voter })\n .first();\n return !!vote;\n } catch (error) {\n this.logger.error('Error checking if user has voted', {\n error: String(error),\n });\n throw new ConflictError(\n `Failed to check if user ${voter} has voted on feature ${featureId}`,\n error as Error,\n );\n }\n }\n\n async hasVotedBatch(\n featureIds: string[],\n voter: string,\n ): Promise<Record<string, boolean>> {\n try {\n if (featureIds.length === 0) {\n return {};\n }\n\n const votes = await this.knex('votes')\n .whereIn('feature_id', featureIds)\n .where({ voter })\n .select('feature_id');\n\n const votedFeatureIds = new Set(votes.map(v => v.feature_id.toString()));\n\n return featureIds.reduce((acc, featureId) => {\n acc[featureId] = votedFeatureIds.has(featureId);\n return acc;\n }, {} as Record<string, boolean>);\n } catch (error) {\n this.logger.error('Error checking batch votes', { error: String(error) });\n throw new ConflictError(\n `Failed to check votes for user ${voter}`,\n error as Error,\n );\n }\n }\n}\n"],"names":["resolvePackagePath","statusFromDb","NotFoundError","ConflictError","statusToDb","FeatureStatus"],"mappings":";;;;;;;AAcA,MAAM,aAAgB,GAAAA,mCAAA;AAAA,EACpB,+CAAA;AAAA,EACA;AACF,CA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,aACzB,KAAO,EAAA;AACd,MAAK,IAAA,CAAA,MAAA,CAAO,MAAM,4BAA8B,EAAA,EAAE,OAAO,MAAO,CAAA,KAAK,GAAG,CAAA;AACxE,MAAA,MAAM,IAAIA,oBAAA;AAAA,QACR,kCAAkC,KAAK,CAAA,CAAA;AAAA,QACvC;AAAA,OACF;AAAA;AACF;AAEJ;;;;"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var backstagePluginRoadmapCommon = require('@rothenbergt/backstage-plugin-roadmap-common');
|
|
4
|
+
|
|
5
|
+
const DB_STATUS_IN_PROGRESS = "InProgress";
|
|
6
|
+
function statusToDb(status) {
|
|
7
|
+
return status === backstagePluginRoadmapCommon.FeatureStatus.InProgress ? DB_STATUS_IN_PROGRESS : status;
|
|
8
|
+
}
|
|
9
|
+
function statusFromDb(dbStatus) {
|
|
10
|
+
if (dbStatus === DB_STATUS_IN_PROGRESS) {
|
|
11
|
+
return backstagePluginRoadmapCommon.FeatureStatus.InProgress;
|
|
12
|
+
}
|
|
13
|
+
return dbStatus;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
exports.DB_STATUS_IN_PROGRESS = DB_STATUS_IN_PROGRESS;
|
|
17
|
+
exports.statusFromDb = statusFromDb;
|
|
18
|
+
exports.statusToDb = statusToDb;
|
|
19
|
+
//# sourceMappingURL=statusDbMapping.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"statusDbMapping.cjs.js","sources":["../../src/database/statusDbMapping.ts"],"sourcesContent":["import { FeatureStatus } from '@rothenbergt/backstage-plugin-roadmap-common';\n\n/**\n * API uses `FeatureStatus.InProgress` (`In Progress`); SQLite CHECK uses `InProgress`.\n * See migrations/20250330000000_init.js.\n */\nexport const DB_STATUS_IN_PROGRESS = 'InProgress';\n\n/** Value written to the `features.status` column. */\nexport function statusToDb(status: FeatureStatus): string {\n return status === FeatureStatus.InProgress ? DB_STATUS_IN_PROGRESS : status;\n}\n\n/** Value returned to callers as `FeatureStatus`. */\nexport function statusFromDb(dbStatus: string): FeatureStatus {\n if (dbStatus === DB_STATUS_IN_PROGRESS) {\n return FeatureStatus.InProgress;\n }\n return dbStatus as FeatureStatus;\n}\n"],"names":["FeatureStatus"],"mappings":";;;;AAMO,MAAM,qBAAwB,GAAA;AAG9B,SAAS,WAAW,MAA+B,EAAA;AACxD,EAAO,OAAA,MAAA,KAAWA,0CAAc,CAAA,UAAA,GAAa,qBAAwB,GAAA,MAAA;AACvE;AAGO,SAAS,aAAa,QAAiC,EAAA;AAC5D,EAAA,IAAI,aAAa,qBAAuB,EAAA;AACtC,IAAA,OAAOA,0CAAc,CAAA,UAAA;AAAA;AAEvB,EAAO,OAAA,QAAA;AACT;;;;;;"}
|
|
@@ -31,7 +31,7 @@ function formatIsoDateForStorage(isoDate) {
|
|
|
31
31
|
}
|
|
32
32
|
function mapGitLabIssueToFeature(issue, voteCount) {
|
|
33
33
|
return {
|
|
34
|
-
id: String(issue.
|
|
34
|
+
id: String(issue.id),
|
|
35
35
|
title: issue.title,
|
|
36
36
|
description: issue.description ?? "",
|
|
37
37
|
status: extractStatusFromLabels(issue.labels ?? []),
|
|
@@ -75,7 +75,7 @@ function buildVoteMarker(username) {
|
|
|
75
75
|
}
|
|
76
76
|
function convertIssuesToFeatures(issues, voteCounts) {
|
|
77
77
|
return issues.map(
|
|
78
|
-
(issue) => mapGitLabIssueToFeature(issue, voteCounts?.[String(issue.
|
|
78
|
+
(issue) => mapGitLabIssueToFeature(issue, voteCounts?.[String(issue.id)])
|
|
79
79
|
);
|
|
80
80
|
}
|
|
81
81
|
function convertNotesToComments(notes, featureId) {
|
|
@@ -99,8 +99,11 @@ function buildNewRoadmapIssuePayload(feature) {
|
|
|
99
99
|
}
|
|
100
100
|
const VOTE_CACHE_TTL_MS = 3e4;
|
|
101
101
|
const PROJECT_MAP_CACHE_TTL_MS = 3e5;
|
|
102
|
-
function issueProjectCacheKey(
|
|
103
|
-
return `roadmap:issue-project:${
|
|
102
|
+
function issueProjectCacheKey(issueId) {
|
|
103
|
+
return `roadmap:issue-project:${issueId}`;
|
|
104
|
+
}
|
|
105
|
+
function issueIidCacheKey(issueId) {
|
|
106
|
+
return `roadmap:issue-iid:${issueId}`;
|
|
104
107
|
}
|
|
105
108
|
function voteCacheKey(featureId) {
|
|
106
109
|
return `roadmap:votes:${featureId}`;
|
|
@@ -168,34 +171,62 @@ class RoadmapGitlabClient {
|
|
|
168
171
|
return `${this.baseUrl}/groups/${this.groupId}${path}`;
|
|
169
172
|
}
|
|
170
173
|
/**
|
|
171
|
-
* Resolves the encoded project ID for a given issue
|
|
174
|
+
* Resolves the encoded project ID for a given issue id.
|
|
172
175
|
* In project mode, returns the configured projectId.
|
|
173
176
|
* In group mode, looks up the cached mapping from group issue responses.
|
|
174
177
|
*/
|
|
175
|
-
async resolveProjectId(
|
|
178
|
+
async resolveProjectId(issueId) {
|
|
176
179
|
if (!this.isGroupMode) return this.projectId;
|
|
177
|
-
const pid = await this.cache.get(issueProjectCacheKey(
|
|
180
|
+
const pid = await this.cache.get(issueProjectCacheKey(issueId));
|
|
178
181
|
if (!pid) {
|
|
179
182
|
throw new errors.NotFoundError(
|
|
180
|
-
`No cached project mapping for issue ${
|
|
183
|
+
`No cached project mapping for issue ${issueId}. Fetch all features first.`
|
|
181
184
|
);
|
|
182
185
|
}
|
|
183
186
|
return pid;
|
|
184
187
|
}
|
|
185
|
-
|
|
186
|
-
|
|
188
|
+
/**
|
|
189
|
+
* Resolves the project-scoped iid for a given global issue id.
|
|
190
|
+
* Looks up the cached id→iid mapping.
|
|
191
|
+
*/
|
|
192
|
+
async resolveIid(issueId) {
|
|
193
|
+
const iid = await this.cache.get(issueIidCacheKey(issueId));
|
|
194
|
+
if (!iid) {
|
|
195
|
+
throw new errors.NotFoundError(
|
|
196
|
+
`No cached iid mapping for issue ${issueId}. Fetch all features first.`
|
|
197
|
+
);
|
|
198
|
+
}
|
|
199
|
+
return iid;
|
|
200
|
+
}
|
|
201
|
+
async hasIssueProjectCached(issueId) {
|
|
202
|
+
const iid = await this.cache.get(issueIidCacheKey(issueId));
|
|
203
|
+
if (!iid) return false;
|
|
204
|
+
if (!this.isGroupMode) return true;
|
|
205
|
+
const pid = await this.cache.get(issueProjectCacheKey(issueId));
|
|
187
206
|
return !!pid;
|
|
188
207
|
}
|
|
189
|
-
/** Caches the project_id for issues returned from group-level queries. */
|
|
190
|
-
async
|
|
208
|
+
/** Caches the project_id and iid for issues returned from group-level queries. */
|
|
209
|
+
async cacheIssueMetadata(issues) {
|
|
191
210
|
await Promise.all(
|
|
192
|
-
issues.
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
211
|
+
issues.flatMap((issue) => {
|
|
212
|
+
const ops = [
|
|
213
|
+
this.cache.set(
|
|
214
|
+
issueIidCacheKey(String(issue.id)),
|
|
215
|
+
String(issue.iid),
|
|
216
|
+
{ ttl: PROJECT_MAP_CACHE_TTL_MS }
|
|
217
|
+
)
|
|
218
|
+
];
|
|
219
|
+
if (this.isGroupMode && issue.project_id) {
|
|
220
|
+
ops.push(
|
|
221
|
+
this.cache.set(
|
|
222
|
+
issueProjectCacheKey(String(issue.id)),
|
|
223
|
+
String(issue.project_id),
|
|
224
|
+
{ ttl: PROJECT_MAP_CACHE_TTL_MS }
|
|
225
|
+
)
|
|
226
|
+
);
|
|
227
|
+
}
|
|
228
|
+
return ops;
|
|
229
|
+
})
|
|
199
230
|
);
|
|
200
231
|
}
|
|
201
232
|
authHeaders() {
|
|
@@ -205,13 +236,13 @@ class RoadmapGitlabClient {
|
|
|
205
236
|
};
|
|
206
237
|
}
|
|
207
238
|
async ensureIssueProjectCached(featureId) {
|
|
208
|
-
if (
|
|
239
|
+
if (!await this.hasIssueProjectCached(featureId)) {
|
|
209
240
|
await this.fetchAllRoadmapIssues();
|
|
210
241
|
}
|
|
211
242
|
}
|
|
212
243
|
async callGitLabApi(url, init) {
|
|
213
244
|
const method = init?.method ?? "GET";
|
|
214
|
-
this.logger.
|
|
245
|
+
this.logger.debug(`GitLab API request: ${method} ${sanitizeLog(url)}`);
|
|
215
246
|
const res = await fetch(url, { ...init, headers: this.authHeaders() });
|
|
216
247
|
if (!res.ok) {
|
|
217
248
|
const text = await res.text();
|
|
@@ -254,21 +285,25 @@ class RoadmapGitlabClient {
|
|
|
254
285
|
const issues = await this.fetchAllPages(
|
|
255
286
|
this.roadmapIssuesUrl("desc")
|
|
256
287
|
);
|
|
257
|
-
|
|
288
|
+
await this.cacheIssueMetadata(issues);
|
|
258
289
|
return issues;
|
|
259
290
|
}
|
|
260
291
|
async fetchIssueById(id) {
|
|
261
292
|
const pid = await this.resolveProjectId(id);
|
|
293
|
+
const iid = await this.resolveIid(id);
|
|
262
294
|
const { data } = await this.callGitLabApi(
|
|
263
|
-
this.projectApiUrl(`/issues/${
|
|
295
|
+
this.projectApiUrl(`/issues/${iid}`, pid)
|
|
264
296
|
);
|
|
265
297
|
if (this.isGroupMode && data.project_id) {
|
|
266
298
|
await this.cache.set(
|
|
267
|
-
issueProjectCacheKey(String(data.
|
|
299
|
+
issueProjectCacheKey(String(data.id)),
|
|
268
300
|
String(data.project_id),
|
|
269
301
|
{ ttl: PROJECT_MAP_CACHE_TTL_MS }
|
|
270
302
|
);
|
|
271
303
|
}
|
|
304
|
+
await this.cache.set(issueIidCacheKey(String(data.id)), String(data.iid), {
|
|
305
|
+
ttl: PROJECT_MAP_CACHE_TTL_MS
|
|
306
|
+
});
|
|
272
307
|
return data;
|
|
273
308
|
}
|
|
274
309
|
async createRoadmapIssue(feature) {
|
|
@@ -289,17 +324,19 @@ class RoadmapGitlabClient {
|
|
|
289
324
|
}
|
|
290
325
|
async updateIssueLabels(id, labels) {
|
|
291
326
|
const pid = await this.resolveProjectId(id);
|
|
327
|
+
const iid = await this.resolveIid(id);
|
|
292
328
|
const { data } = await this.callGitLabApi(
|
|
293
|
-
this.projectApiUrl(`/issues/${
|
|
329
|
+
this.projectApiUrl(`/issues/${iid}`, pid),
|
|
294
330
|
{ method: "PUT", body: JSON.stringify({ labels: labels.join(",") }) }
|
|
295
331
|
);
|
|
296
332
|
return data;
|
|
297
333
|
}
|
|
298
334
|
async fetchIssueNotes(featureId, sort = "desc") {
|
|
299
335
|
const pid = await this.resolveProjectId(featureId);
|
|
336
|
+
const iid = await this.resolveIid(featureId);
|
|
300
337
|
return this.fetchAllPages(
|
|
301
338
|
this.projectApiUrl(
|
|
302
|
-
`/issues/${
|
|
339
|
+
`/issues/${iid}/notes?sort=${sort}&order_by=created_at&${PAGINATION}`,
|
|
303
340
|
pid
|
|
304
341
|
)
|
|
305
342
|
);
|
|
@@ -316,15 +353,17 @@ class RoadmapGitlabClient {
|
|
|
316
353
|
}
|
|
317
354
|
async deleteNote(featureId, noteId) {
|
|
318
355
|
const pid = await this.resolveProjectId(featureId);
|
|
356
|
+
const iid = await this.resolveIid(featureId);
|
|
319
357
|
await this.callGitLabApi(
|
|
320
|
-
this.projectApiUrl(`/issues/${
|
|
358
|
+
this.projectApiUrl(`/issues/${iid}/notes/${noteId}`, pid),
|
|
321
359
|
{ method: "DELETE" }
|
|
322
360
|
);
|
|
323
361
|
}
|
|
324
362
|
async createNote(featureId, body) {
|
|
325
363
|
const pid = await this.resolveProjectId(featureId);
|
|
364
|
+
const iid = await this.resolveIid(featureId);
|
|
326
365
|
const { data } = await this.callGitLabApi(
|
|
327
|
-
this.projectApiUrl(`/issues/${
|
|
366
|
+
this.projectApiUrl(`/issues/${iid}/notes`, pid),
|
|
328
367
|
{ method: "POST", body: JSON.stringify({ body }) }
|
|
329
368
|
);
|
|
330
369
|
return data;
|
|
@@ -352,7 +391,7 @@ class RoadmapGitlabClient {
|
|
|
352
391
|
const counts = {};
|
|
353
392
|
await Promise.all(
|
|
354
393
|
issues.map(async (issue) => {
|
|
355
|
-
const id = String(issue.
|
|
394
|
+
const id = String(issue.id);
|
|
356
395
|
const votes = await this.getOrFetchVotes(id);
|
|
357
396
|
counts[id] = votes.size;
|
|
358
397
|
})
|