@rothenbergt/backstage-plugin-roadmap-backend 0.7.0 → 1.0.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 CHANGED
@@ -8,9 +8,11 @@ This plugin follows a layered architecture with clear separation of concerns:
8
8
 
9
9
  ### 1. Database Layer
10
10
 
11
- - **RoadmapDatabaseClient**: Handles direct database operations through Knex
11
+ - **RoadmapDatabaseClient**: A thin aggregate over per-table stores (**FeaturesStore**, **CommentsStore**, **VotesStore**)
12
+ - Each store owns its table's queries and maps snake_case rows to the camelCase API types in one place (`database/tables.ts`), so column names never leak past this layer
12
13
  - Uses transactions for all write operations to ensure data consistency
13
14
  - Maps database errors to Backstage's error types for consistent error handling
15
+ - Store tests run against both sqlite and Postgres via `TestDatabases`
14
16
 
15
17
  ### 2. Service Layer
16
18
 
@@ -20,6 +22,8 @@ This plugin follows a layered architecture with clear separation of concerns:
20
22
  - **CommentService**: Comment creation and retrieval
21
23
  - **VoteService**: Vote toggling and counting
22
24
  - **PermissionService**: Authorization and permission checks
25
+ - **RoadmapEventPublisher**: Publishes every mutation to the Backstage events bus and broadcasts signals for live board updates (both optional and fire-and-forget; a missing events or signals service never fails a request)
26
+ - **RoadmapNotificationService**: Sends Backstage notifications for status changes, comments, and new suggestions
23
27
 
24
28
  ### 3. Route Layer
25
29
 
@@ -36,6 +40,26 @@ This plugin follows a layered architecture with clear separation of concerns:
36
40
  - Errors bubble up through layers and are handled centrally
37
41
  - Provides consistent error responses with appropriate HTTP status codes
38
42
 
43
+ ## API Contract
44
+
45
+ All responses use camelCase field names and ISO 8601 UTC timestamps, regardless of datasource or database dialect. A feature looks like:
46
+
47
+ ```json
48
+ {
49
+ "id": "42",
50
+ "title": "Dark mode",
51
+ "description": "Support dark mode",
52
+ "status": "Suggested",
53
+ "author": "user:default/jdoe",
54
+ "votes": 3,
55
+ "boardPosition": 0,
56
+ "createdAt": "2026-07-04T10:15:30.000Z",
57
+ "updatedAt": "2026-07-04T12:00:00.000Z"
58
+ }
59
+ ```
60
+
61
+ Comments follow the same conventions (`featureId`, `createdAt`, `updatedAt`).
62
+
39
63
  ## API Endpoints
40
64
 
41
65
  ### Features
@@ -86,7 +110,7 @@ When `roadmap.source` is `gitlab`, behavior stays limited to what the GitLab int
86
110
 
87
111
  The plugin sets up three main tables:
88
112
 
89
- - **features**: Roadmap items with title, description, status, `board_position` (ordering within a status), etc.
113
+ - **features**: Roadmap items with title, description, status, `board_position` (ordering within a status), etc. Columns are snake_case; the store layer maps them to the camelCase API types.
90
114
  - **comments**: User comments on features
91
115
  - **votes**: User votes on features with unique constraint
92
116
 
@@ -1,9 +1,10 @@
1
1
  'use strict';
2
2
 
3
- var backstagePluginRoadmapCommon = require('@rothenbergt/backstage-plugin-roadmap-common');
4
3
  var errors = require('@backstage/errors');
5
4
  var backendPluginApi = require('@backstage/backend-plugin-api');
6
- var statusDbMapping = require('./statusDbMapping.cjs.js');
5
+ var FeaturesStore = require('./stores/FeaturesStore.cjs.js');
6
+ var CommentsStore = require('./stores/CommentsStore.cjs.js');
7
+ var VotesStore = require('./stores/VotesStore.cjs.js');
7
8
 
8
9
  const migrationsDir = backendPluginApi.resolvePackagePath(
9
10
  "@rothenbergt/backstage-plugin-roadmap-backend",
@@ -22,296 +23,102 @@ class RoadmapDatabaseClient {
22
23
  }
23
24
  return new RoadmapDatabaseClient(client, logger);
24
25
  }
25
- knex;
26
+ features;
27
+ comments;
28
+ votes;
26
29
  logger;
27
30
  constructor(knexInstance, logger) {
28
- this.knex = knexInstance;
31
+ this.features = new FeaturesStore.FeaturesStore(knexInstance);
32
+ this.comments = new CommentsStore.CommentsStore(knexInstance);
33
+ this.votes = new VotesStore.VotesStore(knexInstance);
29
34
  this.logger = logger;
30
35
  }
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
- }
44
- async addComment(comment) {
45
- const trx = await this.knex.transaction();
36
+ /** Logs and normalizes store errors: NotFound passes through, anything else becomes ConflictError. */
37
+ async run(operation, fn) {
46
38
  try {
47
- const feature = await trx("features").where({ id: comment.featureId }).first();
48
- if (!feature) {
49
- await trx.rollback();
50
- throw new errors.NotFoundError(
51
- `Feature with id ${comment.featureId} not found`
52
- );
53
- }
54
- const [newComment] = await trx("comments").insert({
55
- feature_id: comment.featureId,
56
- text: comment.text,
57
- author: comment.author
58
- }).returning("*");
59
- await trx.commit();
60
- return newComment;
39
+ return await fn();
61
40
  } catch (error) {
62
- await trx.rollback();
63
- this.logger.error("Error inserting comment", { error: String(error) });
64
41
  if (error instanceof errors.NotFoundError) {
65
42
  throw error;
66
43
  }
67
- throw new errors.ConflictError("Failed to add comment", error);
68
- }
69
- }
70
- async getCommentsByFeatureId(featureId) {
71
- try {
72
- const feature = await this.knex("features").where({ id: featureId }).first();
73
- if (!feature) {
74
- throw new errors.NotFoundError(`Feature with id ${featureId} not found`);
75
- }
76
- return this.knex("comments").where({ feature_id: featureId }).orderBy("created_at", "desc").select("*");
77
- } catch (error) {
78
- this.logger.error(`Error fetching comments for feature ${featureId}`, {
44
+ this.logger.error(`Error during ${operation}`, {
79
45
  error: String(error)
80
46
  });
81
- if (error instanceof errors.NotFoundError) {
82
- throw error;
83
- }
84
- throw new errors.ConflictError(
85
- `Failed to get comments for feature ${featureId}`,
86
- error
87
- );
47
+ throw new errors.ConflictError(`Failed to ${operation}`, error);
88
48
  }
89
49
  }
50
+ async addComment(comment) {
51
+ return this.run("add comment", () => this.comments.insert(comment));
52
+ }
53
+ async getCommentsByFeatureId(featureId) {
54
+ return this.run(
55
+ `get comments for feature ${featureId}`,
56
+ () => this.comments.getByFeatureId(featureId)
57
+ );
58
+ }
59
+ async deleteCommentById(commentId) {
60
+ return this.run(
61
+ `delete comment ${commentId}`,
62
+ () => this.comments.delete(commentId)
63
+ );
64
+ }
90
65
  async addFeature(feature) {
91
- const trx = await this.knex.transaction();
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;
95
- const [newFeature] = await trx("features").insert({
96
- ...feature,
97
- status: statusDbMapping.statusToDb(backstagePluginRoadmapCommon.FeatureStatus.Suggested),
98
- votes: 0,
99
- board_position: nextPosition
100
- }).returning("*");
101
- await trx.commit();
102
- return this.mapFeature(newFeature);
103
- } catch (error) {
104
- await trx.rollback();
105
- this.logger.error("Error adding feature", { error: String(error) });
106
- throw new errors.ConflictError("Failed to add feature", error);
107
- }
66
+ return this.run("add feature", () => this.features.insert(feature));
108
67
  }
109
68
  async getAllFeatures() {
110
- try {
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));
117
- } catch (error) {
118
- this.logger.error("Error fetching all features", {
119
- error: String(error)
120
- });
121
- throw new errors.ConflictError("Failed to get all features", error);
122
- }
69
+ return this.run("get all features", () => this.features.getAll());
123
70
  }
124
71
  async getFeatureById(id) {
125
- try {
126
- const feature = await this.knex("features").where({ id }).first();
127
- if (!feature) {
128
- throw new errors.NotFoundError(`Feature with id ${id} not found`);
129
- }
130
- return this.mapFeature(feature);
131
- } catch (error) {
132
- this.logger.error(`Error fetching feature ${id}`, {
133
- error: String(error)
134
- });
135
- if (error instanceof errors.NotFoundError) {
136
- throw error;
137
- }
138
- throw new errors.ConflictError(
139
- `Failed to get feature with id ${id}`,
140
- error
141
- );
142
- }
72
+ return this.run(
73
+ `get feature with id ${id}`,
74
+ () => this.features.getById(id)
75
+ );
143
76
  }
144
77
  async updateFeatureStatus(id, status) {
145
- const trx = await this.knex.transaction();
146
- try {
147
- const feature = await trx("features").where({ id }).first();
148
- if (!feature) {
149
- await trx.rollback();
150
- throw new errors.NotFoundError(`Feature with id ${id} not found`);
151
- }
152
- const [updatedFeature] = await trx("features").where({ id }).update({
153
- status: statusDbMapping.statusToDb(status),
154
- updated_at: this.knex.fn.now()
155
- }).returning("*");
156
- await trx.commit();
157
- return this.mapFeature(updatedFeature);
158
- } catch (error) {
159
- await trx.rollback();
160
- this.logger.error("Error updating feature status", {
161
- error: String(error)
162
- });
163
- if (error instanceof errors.NotFoundError) {
164
- throw error;
165
- }
166
- throw new errors.ConflictError(
167
- `Failed to update status for feature ${id}`,
168
- error
169
- );
170
- }
78
+ return this.run(
79
+ `update status for feature ${id}`,
80
+ () => this.features.updateStatus(id, status)
81
+ );
171
82
  }
172
83
  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
- }
84
+ return this.run(
85
+ `update feature ${id}`,
86
+ () => this.features.updateDetails(id, fields)
87
+ );
195
88
  }
196
89
  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
- }
90
+ return this.run(`delete feature ${id}`, () => this.features.delete(id));
201
91
  }
202
92
  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
- }
93
+ return this.run(
94
+ "reorder features",
95
+ () => this.features.reorderInStatus(status, orderedIds)
96
+ );
229
97
  }
230
98
  async toggleVote(featureId, voter) {
231
- const trx = await this.knex.transaction();
232
- try {
233
- const feature = await trx("features").where({ id: featureId }).first();
234
- if (!feature) {
235
- await trx.rollback();
236
- throw new errors.NotFoundError(`Feature with id ${featureId} not found`);
237
- }
238
- const existingVote = await trx("votes").where({ feature_id: featureId, voter }).first();
239
- let voteAdded;
240
- if (existingVote) {
241
- await trx("votes").where({ feature_id: featureId, voter }).delete();
242
- await trx("features").where({ id: featureId }).decrement("votes", 1);
243
- voteAdded = false;
244
- } else {
245
- await trx("votes").insert({ feature_id: featureId, voter });
246
- await trx("features").where({ id: featureId }).increment("votes", 1);
247
- voteAdded = true;
248
- }
249
- const updated = await trx("features").where({ id: featureId }).select("votes").first();
250
- await trx.commit();
251
- return { voteAdded, voteCount: updated?.votes ?? 0 };
252
- } catch (error) {
253
- await trx.rollback();
254
- this.logger.error("Error toggling vote", { error: String(error) });
255
- if (error instanceof errors.NotFoundError) {
256
- throw error;
257
- }
258
- throw new errors.ConflictError(
259
- `Failed to toggle vote for feature ${featureId}`,
260
- error
261
- );
262
- }
99
+ return this.run(
100
+ `toggle vote for feature ${featureId}`,
101
+ () => this.votes.toggle(featureId, voter)
102
+ );
263
103
  }
264
104
  async getVoteCount(featureId) {
265
105
  const counts = await this.getVoteCounts([featureId]);
266
106
  return counts[featureId] || 0;
267
107
  }
268
108
  async getVoteCounts(featureIds) {
269
- try {
270
- if (featureIds.length === 0) {
271
- return {};
272
- }
273
- const results = await this.knex("features").whereIn("id", featureIds).select("id", "votes");
274
- return results.reduce((acc, { id, votes }) => {
275
- acc[id] = votes;
276
- return acc;
277
- }, {});
278
- } catch (error) {
279
- this.logger.error("Error getting vote counts", { error: String(error) });
280
- throw new errors.ConflictError("Failed to get vote counts", error);
281
- }
109
+ return this.run("get vote counts", () => this.votes.getCounts(featureIds));
282
110
  }
283
111
  async hasVoted(featureId, voter) {
284
- try {
285
- const vote = await this.knex("votes").where({ feature_id: featureId, voter }).first();
286
- return !!vote;
287
- } catch (error) {
288
- this.logger.error("Error checking if user has voted", {
289
- error: String(error)
290
- });
291
- throw new errors.ConflictError(
292
- `Failed to check if user ${voter} has voted on feature ${featureId}`,
293
- error
294
- );
295
- }
112
+ return this.run(
113
+ `check if user ${voter} has voted on feature ${featureId}`,
114
+ () => this.votes.hasVoted(featureId, voter)
115
+ );
296
116
  }
297
117
  async hasVotedBatch(featureIds, voter) {
298
- try {
299
- if (featureIds.length === 0) {
300
- return {};
301
- }
302
- const votes = await this.knex("votes").whereIn("feature_id", featureIds).where({ voter }).select("feature_id");
303
- const votedFeatureIds = new Set(votes.map((v) => v.feature_id.toString()));
304
- return featureIds.reduce((acc, featureId) => {
305
- acc[featureId] = votedFeatureIds.has(featureId);
306
- return acc;
307
- }, {});
308
- } catch (error) {
309
- this.logger.error("Error checking batch votes", { error: String(error) });
310
- throw new errors.ConflictError(
311
- `Failed to check votes for user ${voter}`,
312
- error
313
- );
314
- }
118
+ return this.run(
119
+ `check votes for user ${voter}`,
120
+ () => this.votes.hasVotedBatch(featureIds, voter)
121
+ );
315
122
  }
316
123
  }
317
124
 
@@ -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';\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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EA,MAAA,MAAM,QAAQ,MAAM,IAAA,CAAK,IAAA,CAAK,OAAO,EAClC,OAAA,CAAQ,YAAA,EAAc,UAAU,CAAA,CAChC,MAAM,EAAE,KAAA,EAAO,CAAA,CACf,OAAO,YAAY,CAAA;AAEtB,MAAA,MAAM,eAAA,GAAkB,IAAI,GAAA,CAAI,KAAA,CAAM,GAAA,CAAI,OAAK,CAAA,CAAE,UAAA,CAAW,QAAA,EAAU,CAAC,CAAA;AAEvE,MAAA,OAAO,UAAA,CAAW,MAAA,CAAO,CAAC,GAAA,EAAK,SAAA,KAAc;AAC3C,QAAA,GAAA,CAAI,SAAS,CAAA,GAAI,eAAA,CAAgB,GAAA,CAAI,SAAS,CAAA;AAC9C,QAAA,OAAO,GAAA;AAAA,MACT,CAAA,EAAG,EAA6B,CAAA;AAAA,IAClC,SAAS,KAAA,EAAO;AACd,MAAA,IAAA,CAAK,MAAA,CAAO,MAAM,4BAAA,EAA8B,EAAE,OAAO,MAAA,CAAO,KAAK,GAAG,CAAA;AACxE,MAAA,MAAM,IAAIA,oBAAA;AAAA,QACR,kCAAkC,KAAK,CAAA,CAAA;AAAA,QACvC;AAAA,OACF;AAAA,IACF;AAAA,EACF;AACF;;;;"}
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 { FeaturesStore, CommentsStore, VotesStore } from './stores';\n\nconst migrationsDir = resolvePackagePath(\n '@rothenbergt/backstage-plugin-roadmap-backend',\n 'migrations',\n);\n\n/**\n * Knex-backed implementation of the RoadmapDatasource interface.\n *\n * Table access lives in the per-table stores (features/comments/votes);\n * this class aggregates them and wraps unexpected store failures in\n * ConflictError while letting NotFoundError pass through.\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 readonly features: FeaturesStore;\n readonly comments: CommentsStore;\n readonly votes: VotesStore;\n private readonly logger: LoggerService;\n\n constructor(knexInstance: Knex, logger: LoggerService) {\n this.features = new FeaturesStore(knexInstance);\n this.comments = new CommentsStore(knexInstance);\n this.votes = new VotesStore(knexInstance);\n this.logger = logger;\n }\n\n /** Logs and normalizes store errors: NotFound passes through, anything else becomes ConflictError. */\n private async run<T>(operation: string, fn: () => Promise<T>): Promise<T> {\n try {\n return await fn();\n } catch (error) {\n if (error instanceof NotFoundError) {\n throw error;\n }\n this.logger.error(`Error during ${operation}`, {\n error: String(error),\n });\n throw new ConflictError(`Failed to ${operation}`, error as Error);\n }\n }\n\n async addComment(comment: NewComment): Promise<Comment> {\n return this.run('add comment', () => this.comments.insert(comment));\n }\n\n async getCommentsByFeatureId(featureId: string): Promise<Comment[]> {\n return this.run(`get comments for feature ${featureId}`, () =>\n this.comments.getByFeatureId(featureId),\n );\n }\n\n async deleteCommentById(commentId: string): Promise<void> {\n return this.run(`delete comment ${commentId}`, () =>\n this.comments.delete(commentId),\n );\n }\n\n async addFeature(feature: NewFeature & { author: string }): Promise<Feature> {\n return this.run('add feature', () => this.features.insert(feature));\n }\n\n async getAllFeatures(): Promise<Feature[]> {\n return this.run('get all features', () => this.features.getAll());\n }\n\n async getFeatureById(id: string): Promise<Feature> {\n return this.run(`get feature with id ${id}`, () =>\n this.features.getById(id),\n );\n }\n\n async updateFeatureStatus(\n id: string,\n status: FeatureStatus,\n ): Promise<Feature> {\n return this.run(`update status for feature ${id}`, () =>\n this.features.updateStatus(id, status),\n );\n }\n\n async updateFeatureDetails(\n id: string,\n fields: { title?: string; description?: string },\n ): Promise<Feature> {\n return this.run(`update feature ${id}`, () =>\n this.features.updateDetails(id, fields),\n );\n }\n\n async deleteFeature(id: string): Promise<void> {\n return this.run(`delete feature ${id}`, () => this.features.delete(id));\n }\n\n async reorderFeaturesInStatus(\n status: FeatureStatus,\n orderedIds: string[],\n ): Promise<void> {\n return this.run('reorder features', () =>\n this.features.reorderInStatus(status, orderedIds),\n );\n }\n\n async toggleVote(\n featureId: string,\n voter: string,\n ): Promise<{ voteAdded: boolean; voteCount: number }> {\n return this.run(`toggle vote for feature ${featureId}`, () =>\n this.votes.toggle(featureId, voter),\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 return this.run('get vote counts', () => this.votes.getCounts(featureIds));\n }\n\n async hasVoted(featureId: string, voter: string): Promise<boolean> {\n return this.run(\n `check if user ${voter} has voted on feature ${featureId}`,\n () => this.votes.hasVoted(featureId, voter),\n );\n }\n\n async hasVotedBatch(\n featureIds: string[],\n voter: string,\n ): Promise<Record<string, boolean>> {\n return this.run(`check votes for user ${voter}`, () =>\n this.votes.hasVotedBatch(featureIds, voter),\n );\n }\n}\n"],"names":["resolvePackagePath","FeaturesStore","CommentsStore","VotesStore","NotFoundError","ConflictError"],"mappings":";;;;;;;;AAcA,MAAM,aAAA,GAAgBA,mCAAA;AAAA,EACpB,+CAAA;AAAA,EACA;AACF,CAAA;AASO,MAAM,qBAAA,CAAmD;AAAA,EAC9D,aAAa,OAAO,OAAA,EAGe;AACjC,IAAA,MAAM,EAAE,QAAA,EAAU,MAAA,EAAO,GAAI,OAAA;AAC7B,IAAA,MAAA,CAAO,KAAK,sCAAsC,C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A,CAAK,GAAA;AAAA,MACV,CAAA,cAAA,EAAiB,KAAK,CAAA,sBAAA,EAAyB,SAAS,CAAA,CAAA;AAAA,MACxD,MAAM,IAAA,CAAK,KAAA,CAAM,QAAA,CAAS,WAAW,KAAK;AAAA,KAC5C;AAAA,EACF;AAAA,EAEA,MAAM,aAAA,CACJ,UAAA,EACA,KAAA,EACkC;AAClC,IAAA,OAAO,IAAA,CAAK,GAAA;AAAA,MAAI,wBAAwB,KAAK,CAAA,CAAA;AAAA,MAAI,MAC/C,IAAA,CAAK,KAAA,CAAM,aAAA,CAAc,YAAY,KAAK;AAAA,KAC5C;AAAA,EACF;AACF;;;;"}
@@ -0,0 +1,44 @@
1
+ 'use strict';
2
+
3
+ var errors = require('@backstage/errors');
4
+ var tables = require('../tables.cjs.js');
5
+
6
+ class CommentsStore {
7
+ constructor(knex) {
8
+ this.knex = knex;
9
+ }
10
+ knex;
11
+ async insert(comment) {
12
+ return this.knex.transaction(async (trx) => {
13
+ const feature = await trx("features").where({ id: comment.featureId }).first();
14
+ if (!feature) {
15
+ throw new errors.NotFoundError(
16
+ `Feature with id ${comment.featureId} not found`
17
+ );
18
+ }
19
+ const [row] = await trx("comments").insert({
20
+ feature_id: comment.featureId,
21
+ text: comment.text,
22
+ author: comment.author
23
+ }).returning("*");
24
+ return tables.mapCommentRow(row);
25
+ });
26
+ }
27
+ async getByFeatureId(featureId) {
28
+ const feature = await this.knex("features").where({ id: featureId }).first();
29
+ if (!feature) {
30
+ throw new errors.NotFoundError(`Feature with id ${featureId} not found`);
31
+ }
32
+ const rows = await this.knex("comments").where({ feature_id: featureId }).orderBy("created_at", "desc").select("*");
33
+ return rows.map(tables.mapCommentRow);
34
+ }
35
+ async delete(commentId) {
36
+ const n = await this.knex("comments").where({ id: commentId }).delete();
37
+ if (!n) {
38
+ throw new errors.NotFoundError(`Comment with id ${commentId} not found`);
39
+ }
40
+ }
41
+ }
42
+
43
+ exports.CommentsStore = CommentsStore;
44
+ //# sourceMappingURL=CommentsStore.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CommentsStore.cjs.js","sources":["../../../src/database/stores/CommentsStore.ts"],"sourcesContent":["import { Knex } from 'knex';\nimport {\n Comment,\n NewComment,\n} from '@rothenbergt/backstage-plugin-roadmap-common';\nimport { NotFoundError } from '@backstage/errors';\nimport { CommentRow, mapCommentRow } from '../tables';\n\n/**\n * All access to the `comments` table. Returns API types only.\n */\nexport class CommentsStore {\n constructor(private readonly knex: Knex) {}\n\n async insert(comment: NewComment): Promise<Comment> {\n return this.knex.transaction(async trx => {\n const feature = await trx('features')\n .where({ id: comment.featureId })\n .first();\n if (!feature) {\n throw new NotFoundError(\n `Feature with id ${comment.featureId} not found`,\n );\n }\n\n const [row] = await trx<CommentRow>('comments')\n .insert({\n feature_id: comment.featureId,\n text: comment.text,\n author: comment.author,\n })\n .returning('*');\n return mapCommentRow(row);\n });\n }\n\n async getByFeatureId(featureId: string): Promise<Comment[]> {\n const feature = await this.knex('features')\n .where({ id: featureId })\n .first();\n if (!feature) {\n throw new NotFoundError(`Feature with id ${featureId} not found`);\n }\n\n const rows = await this.knex<CommentRow>('comments')\n .where({ feature_id: featureId })\n .orderBy('created_at', 'desc')\n .select('*');\n return rows.map(mapCommentRow);\n }\n\n async delete(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"],"names":["NotFoundError","mapCommentRow"],"mappings":";;;;;AAWO,MAAM,aAAA,CAAc;AAAA,EACzB,YAA6B,IAAA,EAAY;AAAZ,IAAA,IAAA,CAAA,IAAA,GAAA,IAAA;AAAA,EAAa;AAAA,EAAb,IAAA;AAAA,EAE7B,MAAM,OAAO,OAAA,EAAuC;AAClD,IAAA,OAAO,IAAA,CAAK,IAAA,CAAK,WAAA,CAAY,OAAM,GAAA,KAAO;AACxC,MAAA,MAAM,OAAA,GAAU,MAAM,GAAA,CAAI,UAAU,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A,CAAM,EAAE,EAAA,EAAI,SAAA,EAAW,CAAA,CAAE,MAAA,EAAO;AACtE,IAAA,IAAI,CAAC,CAAA,EAAG;AACN,MAAA,MAAM,IAAID,oBAAA,CAAc,CAAA,gBAAA,EAAmB,SAAS,CAAA,UAAA,CAAY,CAAA;AAAA,IAClE;AAAA,EACF;AACF;;;;"}
@@ -0,0 +1,87 @@
1
+ 'use strict';
2
+
3
+ var backstagePluginRoadmapCommon = require('@rothenbergt/backstage-plugin-roadmap-common');
4
+ var errors = require('@backstage/errors');
5
+ var statusDbMapping = require('../statusDbMapping.cjs.js');
6
+ var tables = require('../tables.cjs.js');
7
+
8
+ class FeaturesStore {
9
+ constructor(knex) {
10
+ this.knex = knex;
11
+ }
12
+ knex;
13
+ async insert(feature) {
14
+ return this.knex.transaction(async (trx) => {
15
+ const maxRow = await trx("features").where({ status: statusDbMapping.statusToDb(backstagePluginRoadmapCommon.FeatureStatus.Suggested) }).max("board_position as maxp").first();
16
+ const nextPosition = Number(maxRow?.maxp ?? 0) + 1;
17
+ const [row] = await trx("features").insert({
18
+ ...feature,
19
+ status: statusDbMapping.statusToDb(backstagePluginRoadmapCommon.FeatureStatus.Suggested),
20
+ votes: 0,
21
+ board_position: nextPosition
22
+ }).returning("*");
23
+ return tables.mapFeatureRow(row);
24
+ });
25
+ }
26
+ async getAll() {
27
+ const rows = await this.knex("features").orderBy([
28
+ { column: "status", order: "asc" },
29
+ { column: "board_position", order: "asc" },
30
+ { column: "created_at", order: "desc" }
31
+ ]).select("*");
32
+ return rows.map(tables.mapFeatureRow);
33
+ }
34
+ async getById(id) {
35
+ const row = await this.knex("features").where({ id }).first();
36
+ if (!row) {
37
+ throw new errors.NotFoundError(`Feature with id ${id} not found`);
38
+ }
39
+ return tables.mapFeatureRow(row);
40
+ }
41
+ async updateStatus(id, status) {
42
+ const [row] = await this.knex("features").where({ id }).update({
43
+ status: statusDbMapping.statusToDb(status),
44
+ updated_at: this.knex.fn.now()
45
+ }).returning("*");
46
+ if (!row) {
47
+ throw new errors.NotFoundError(`Feature with id ${id} not found`);
48
+ }
49
+ return tables.mapFeatureRow(row);
50
+ }
51
+ async updateDetails(id, fields) {
52
+ const patch = { updated_at: this.knex.fn.now() };
53
+ if (fields.title !== void 0) patch.title = fields.title;
54
+ if (fields.description !== void 0)
55
+ patch.description = fields.description;
56
+ const [row] = await this.knex("features").where({ id }).update(patch).returning("*");
57
+ if (!row) {
58
+ throw new errors.NotFoundError(`Feature with id ${id} not found`);
59
+ }
60
+ return tables.mapFeatureRow(row);
61
+ }
62
+ async delete(id) {
63
+ const n = await this.knex("features").where({ id }).delete();
64
+ if (!n) {
65
+ throw new errors.NotFoundError(`Feature with id ${id} not found`);
66
+ }
67
+ }
68
+ async reorderInStatus(status, orderedIds) {
69
+ await this.knex.transaction(async (trx) => {
70
+ for (let i = 0; i < orderedIds.length; i += 1) {
71
+ const updated = await trx("features").where({ id: orderedIds[i], status: statusDbMapping.statusToDb(status) }).update({ board_position: i });
72
+ if (!updated) {
73
+ throw new errors.NotFoundError(
74
+ `Feature ${orderedIds[i]} not found or not in status ${status}`
75
+ );
76
+ }
77
+ }
78
+ });
79
+ }
80
+ async exists(id) {
81
+ const row = await this.knex("features").where({ id }).first();
82
+ return Boolean(row);
83
+ }
84
+ }
85
+
86
+ exports.FeaturesStore = FeaturesStore;
87
+ //# sourceMappingURL=FeaturesStore.cjs.js.map