@rothenbergt/backstage-plugin-roadmap-backend 0.7.0 → 1.0.1
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 +26 -2
- package/dist/database/RoadmapDatabaseClient.cjs.js +71 -253
- package/dist/database/RoadmapDatabaseClient.cjs.js.map +1 -1
- package/dist/database/stores/CommentsStore.cjs.js +44 -0
- package/dist/database/stores/CommentsStore.cjs.js.map +1 -0
- package/dist/database/stores/FeaturesStore.cjs.js +103 -0
- package/dist/database/stores/FeaturesStore.cjs.js.map +1 -0
- package/dist/database/stores/VotesStore.cjs.js +59 -0
- package/dist/database/stores/VotesStore.cjs.js.map +1 -0
- package/dist/database/tables.cjs.js +43 -0
- package/dist/database/tables.cjs.js.map +1 -0
- package/dist/gitlab/RoadmapGitlabClient.cjs.js +82 -37
- package/dist/gitlab/RoadmapGitlabClient.cjs.js.map +1 -1
- package/dist/index.d.ts +61 -25
- package/dist/plugin.cjs.js +15 -4
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/routes/commentsRouter.cjs.js +10 -2
- package/dist/routes/commentsRouter.cjs.js.map +1 -1
- package/dist/routes/featuresRouter.cjs.js +25 -17
- package/dist/routes/featuresRouter.cjs.js.map +1 -1
- package/dist/routes/router.cjs.js +0 -6
- package/dist/routes/router.cjs.js.map +1 -1
- package/dist/routes/votesRouter.cjs.js +27 -12
- package/dist/routes/votesRouter.cjs.js.map +1 -1
- package/dist/services/CommentService.cjs.js +4 -4
- package/dist/services/CommentService.cjs.js.map +1 -1
- package/dist/services/FeatureService.cjs.js +5 -5
- package/dist/services/FeatureService.cjs.js.map +1 -1
- package/dist/services/PermissionService.cjs.js +3 -0
- package/dist/services/PermissionService.cjs.js.map +1 -1
- package/dist/services/RoadmapEventPublisher.cjs.js +82 -0
- package/dist/services/RoadmapEventPublisher.cjs.js.map +1 -0
- package/dist/services/featureBoardFilter.cjs.js +1 -1
- package/dist/services/featureBoardFilter.cjs.js.map +1 -1
- package/package.json +7 -4
|
@@ -0,0 +1,103 @@
|
|
|
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
|
+
return this.knex.transaction(async (trx) => {
|
|
43
|
+
const current = await trx("features").where({ id }).first();
|
|
44
|
+
if (!current) {
|
|
45
|
+
throw new errors.NotFoundError(`Feature with id ${id} not found`);
|
|
46
|
+
}
|
|
47
|
+
const dbStatus = statusDbMapping.statusToDb(status);
|
|
48
|
+
const patch = {
|
|
49
|
+
status: dbStatus,
|
|
50
|
+
updated_at: this.knex.fn.now()
|
|
51
|
+
};
|
|
52
|
+
if (current.status !== dbStatus) {
|
|
53
|
+
const maxRow = await trx("features").where({ status: dbStatus }).max("board_position as maxp").first();
|
|
54
|
+
patch.board_position = Number(maxRow?.maxp ?? 0) + 1;
|
|
55
|
+
}
|
|
56
|
+
const [row] = await trx("features").where({ id }).update(patch).returning("*");
|
|
57
|
+
return tables.mapFeatureRow(row);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
async updateDetails(id, fields) {
|
|
61
|
+
const patch = { updated_at: this.knex.fn.now() };
|
|
62
|
+
if (fields.title !== void 0) patch.title = fields.title;
|
|
63
|
+
if (fields.description !== void 0)
|
|
64
|
+
patch.description = fields.description;
|
|
65
|
+
const [row] = await this.knex("features").where({ id }).update(patch).returning("*");
|
|
66
|
+
if (!row) {
|
|
67
|
+
throw new errors.NotFoundError(`Feature with id ${id} not found`);
|
|
68
|
+
}
|
|
69
|
+
return tables.mapFeatureRow(row);
|
|
70
|
+
}
|
|
71
|
+
async delete(id) {
|
|
72
|
+
const n = await this.knex("features").where({ id }).delete();
|
|
73
|
+
if (!n) {
|
|
74
|
+
throw new errors.NotFoundError(`Feature with id ${id} not found`);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
async reorderInStatus(status, orderedIds) {
|
|
78
|
+
await this.knex.transaction(async (trx) => {
|
|
79
|
+
for (let i = 0; i < orderedIds.length; i += 1) {
|
|
80
|
+
const updated = await trx("features").where({ id: orderedIds[i], status: statusDbMapping.statusToDb(status) }).update({ board_position: i });
|
|
81
|
+
if (!updated) {
|
|
82
|
+
throw new errors.NotFoundError(
|
|
83
|
+
`Feature ${orderedIds[i]} not found or not in status ${status}`
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
const omitted = await trx("features").where({ status: statusDbMapping.statusToDb(status) }).whereNotIn("id", orderedIds).orderBy([
|
|
88
|
+
{ column: "board_position", order: "asc" },
|
|
89
|
+
{ column: "created_at", order: "desc" }
|
|
90
|
+
]).select("id");
|
|
91
|
+
for (let i = 0; i < omitted.length; i += 1) {
|
|
92
|
+
await trx("features").where({ id: omitted[i].id }).update({ board_position: orderedIds.length + i });
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
async exists(id) {
|
|
97
|
+
const row = await this.knex("features").where({ id }).first();
|
|
98
|
+
return Boolean(row);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
exports.FeaturesStore = FeaturesStore;
|
|
103
|
+
//# sourceMappingURL=FeaturesStore.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FeaturesStore.cjs.js","sources":["../../../src/database/stores/FeaturesStore.ts"],"sourcesContent":["import { Knex } from 'knex';\nimport {\n Feature,\n NewFeature,\n FeatureStatus,\n} from '@rothenbergt/backstage-plugin-roadmap-common';\nimport { NotFoundError } from '@backstage/errors';\nimport { statusToDb } from '../statusDbMapping';\nimport { FeatureRow, mapFeatureRow } from '../tables';\n\n/**\n * All access to the `features` table. Returns API types only; the raw\n * snake_case rows never leave this store.\n */\nexport class FeaturesStore {\n constructor(private readonly knex: Knex) {}\n\n async insert(feature: NewFeature & { author: string }): Promise<Feature> {\n return this.knex.transaction(async trx => {\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 const [row] = await trx<FeatureRow>('features')\n .insert({\n ...feature,\n status: statusToDb(FeatureStatus.Suggested),\n votes: 0,\n board_position: nextPosition,\n })\n .returning('*');\n return mapFeatureRow(row);\n });\n }\n\n async getAll(): Promise<Feature[]> {\n const rows = await this.knex<FeatureRow>('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(mapFeatureRow);\n }\n\n async getById(id: string): Promise<Feature> {\n const row = await this.knex<FeatureRow>('features').where({ id }).first();\n if (!row) {\n throw new NotFoundError(`Feature with id ${id} not found`);\n }\n return mapFeatureRow(row);\n }\n\n async updateStatus(id: string, status: FeatureStatus): Promise<Feature> {\n return this.knex.transaction(async trx => {\n const current = await trx<FeatureRow>('features').where({ id }).first();\n if (!current) {\n throw new NotFoundError(`Feature with id ${id} not found`);\n }\n const dbStatus = statusToDb(status);\n const patch: Record<string, unknown> = {\n status: dbStatus,\n updated_at: this.knex.fn.now(),\n };\n // Positions only mean something within a column, so a move lands the\n // feature at the end of its destination instead of keeping a position\n // that belonged to the previous column\n if (current.status !== dbStatus) {\n const maxRow = await trx('features')\n .where({ status: dbStatus })\n .max('board_position as maxp')\n .first();\n patch.board_position =\n Number((maxRow as { maxp?: string | number })?.maxp ?? 0) + 1;\n }\n const [row] = await trx<FeatureRow>('features')\n .where({ id })\n .update(patch)\n .returning('*');\n return mapFeatureRow(row);\n });\n }\n\n async updateDetails(\n id: string,\n fields: { title?: string; description?: string },\n ): Promise<Feature> {\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 [row] = await this.knex<FeatureRow>('features')\n .where({ id })\n .update(patch)\n .returning('*');\n if (!row) {\n throw new NotFoundError(`Feature with id ${id} not found`);\n }\n return mapFeatureRow(row);\n }\n\n async delete(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 reorderInStatus(\n status: FeatureStatus,\n orderedIds: string[],\n ): Promise<void> {\n await this.knex.transaction(async trx => {\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({ board_position: i });\n if (!updated) {\n throw new NotFoundError(\n `Feature ${orderedIds[i]} not found or not in status ${status}`,\n );\n }\n }\n\n // The client may only see a filtered view of the column (retention\n // hides older items), so features it omitted are re-positioned after\n // the submitted ones in their existing relative order to avoid\n // position collisions\n const omitted = await trx<FeatureRow>('features')\n .where({ status: statusToDb(status) })\n .whereNotIn('id', orderedIds)\n .orderBy([\n { column: 'board_position', order: 'asc' },\n { column: 'created_at', order: 'desc' },\n ])\n .select('id');\n for (let i = 0; i < omitted.length; i += 1) {\n await trx('features')\n .where({ id: omitted[i].id })\n .update({ board_position: orderedIds.length + i });\n }\n });\n }\n\n async exists(id: string): Promise<boolean> {\n const row = await this.knex('features').where({ id }).first();\n return Boolean(row);\n }\n}\n"],"names":["statusToDb","FeatureStatus","mapFeatureRow","NotFoundError"],"mappings":";;;;;;;AAcO,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,EAA4D;AACvE,IAAA,OAAO,IAAA,CAAK,IAAA,CAAK,WAAA,CAAY,OAAM,GAAA,KAAO;AACxC,MAAA,MAAM,SAAS,MAAM,GAAA,CAAI,UAAU,CAAA,CAChC,MAAM,EAAE,MAAA,EAAQA,0BAAA,CAAWC,0CAAA,CAAc,SAAS,CAAA,EAAG,EACrD,GAAA,CAAI,wBAAwB,EAC5B,KAAA,EAAM;AACT,MAAA,MAAM,YAAA,GACJ,MAAA,CAAQ,MAAA,EAAuC,IAAA,IAAQ,CAAC,CAAA,GAAI,CAAA;AAE9D,MAAA,MAAM,CAAC,GAAG,CAAA,GA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
+
async toggle(featureId, voter) {
|
|
11
|
+
return this.knex.transaction(async (trx) => {
|
|
12
|
+
const feature = await trx("features").where({ id: featureId }).first();
|
|
13
|
+
if (!feature) {
|
|
14
|
+
throw new errors.NotFoundError(`Feature with id ${featureId} not found`);
|
|
15
|
+
}
|
|
16
|
+
const existingVote = await trx("votes").where({ feature_id: featureId, voter }).first();
|
|
17
|
+
let voteAdded;
|
|
18
|
+
if (existingVote) {
|
|
19
|
+
await trx("votes").where({ feature_id: featureId, voter }).delete();
|
|
20
|
+
await trx("features").where({ id: featureId }).decrement("votes", 1);
|
|
21
|
+
voteAdded = false;
|
|
22
|
+
} else {
|
|
23
|
+
await trx("votes").insert({ feature_id: featureId, voter });
|
|
24
|
+
await trx("features").where({ id: featureId }).increment("votes", 1);
|
|
25
|
+
voteAdded = true;
|
|
26
|
+
}
|
|
27
|
+
const updated = await trx("features").where({ id: featureId }).select("votes").first();
|
|
28
|
+
return { voteAdded, voteCount: Number(updated?.votes ?? 0) };
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
async getCounts(featureIds) {
|
|
32
|
+
if (featureIds.length === 0) {
|
|
33
|
+
return {};
|
|
34
|
+
}
|
|
35
|
+
const results = await this.knex("features").whereIn("id", featureIds).select("id", "votes");
|
|
36
|
+
return results.reduce((acc, { id, votes }) => {
|
|
37
|
+
acc[String(id)] = Number(votes ?? 0);
|
|
38
|
+
return acc;
|
|
39
|
+
}, {});
|
|
40
|
+
}
|
|
41
|
+
async hasVoted(featureId, voter) {
|
|
42
|
+
const vote = await this.knex("votes").where({ feature_id: featureId, voter }).first();
|
|
43
|
+
return Boolean(vote);
|
|
44
|
+
}
|
|
45
|
+
async hasVotedBatch(featureIds, voter) {
|
|
46
|
+
if (featureIds.length === 0) {
|
|
47
|
+
return {};
|
|
48
|
+
}
|
|
49
|
+
const votes = await this.knex("votes").whereIn("feature_id", featureIds).where({ voter }).select("feature_id");
|
|
50
|
+
const votedFeatureIds = new Set(votes.map((v) => String(v.feature_id)));
|
|
51
|
+
return featureIds.reduce((acc, featureId) => {
|
|
52
|
+
acc[featureId] = votedFeatureIds.has(featureId);
|
|
53
|
+
return acc;
|
|
54
|
+
}, {});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
exports.VotesStore = VotesStore;
|
|
59
|
+
//# sourceMappingURL=VotesStore.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"VotesStore.cjs.js","sources":["../../../src/database/stores/VotesStore.ts"],"sourcesContent":["import { Knex } from 'knex';\nimport { NotFoundError } from '@backstage/errors';\n\n/**\n * All access to the `votes` table plus the denormalized `features.votes`\n * counter, which is kept in sync inside the same transaction.\n */\nexport class VotesStore {\n constructor(private readonly knex: Knex) {}\n\n async toggle(\n featureId: string,\n voter: string,\n ): Promise<{ voteAdded: boolean; voteCount: number }> {\n return this.knex.transaction(async trx => {\n const feature = await trx('features').where({ id: featureId }).first();\n if (!feature) {\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 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 await trx('votes').insert({ feature_id: featureId, voter });\n await trx('features').where({ id: featureId }).increment('votes', 1);\n voteAdded = true;\n }\n\n const updated = await trx('features')\n .where({ id: featureId })\n .select('votes')\n .first();\n return { voteAdded, voteCount: Number(updated?.votes ?? 0) };\n });\n }\n\n async getCounts(featureIds: string[]): Promise<Record<string, number>> {\n if (featureIds.length === 0) {\n return {};\n }\n const results = await this.knex('features')\n .whereIn('id', featureIds)\n .select('id', 'votes');\n return results.reduce((acc, { id, votes }) => {\n acc[String(id)] = Number(votes ?? 0);\n return acc;\n }, {} as Record<string, number>);\n }\n\n async hasVoted(featureId: string, voter: string): Promise<boolean> {\n const vote = await this.knex('votes')\n .where({ feature_id: featureId, voter })\n .first();\n return Boolean(vote);\n }\n\n async hasVotedBatch(\n featureIds: string[],\n voter: string,\n ): Promise<Record<string, boolean>> {\n if (featureIds.length === 0) {\n return {};\n }\n const votes = await this.knex('votes')\n .whereIn('feature_id', featureIds)\n .where({ voter })\n .select('feature_id');\n const votedFeatureIds = new Set(votes.map(v => String(v.feature_id)));\n return featureIds.reduce((acc, featureId) => {\n acc[featureId] = votedFeatureIds.has(featureId);\n return acc;\n }, {} as Record<string, boolean>);\n }\n}\n"],"names":["NotFoundError"],"mappings":";;;;AAOO,MAAM,UAAA,CAAW;AAAA,EACtB,YAA6B,IAAA,EAAY;AAAZ,IAAA,IAAA,CAAA,IAAA,GAAA,IAAA;AAAA,EAAa;AAAA,EAAb,IAAA;AAAA,EAE7B,MAAM,MAAA,CACJ,SAAA,EACA,KAAA,EACoD;AACpD,IAAA,OAAO,IAAA,CAAK,IAAA,CAAK,WAAA,CAAY,OAAM,GAAA,KAAO;AACxC,MAAA,MAAM,OAAA,GAAU,MAAM,GAAA,CAAI,UAAU,CAAA,CAAE,KAAA,CAAM,EAAE,EAAA,EAAI,SAAA,EAAW,CAAA,CAAE,KAAA,EAAM;AACrE,MAAA,IAAI,CAAC,OAAA,EAAS;AACZ,QAAA,MAAM,IAAIA,oBAAA,CAAc,CAAA,gBAAA,EAAmB,SAAS,CAAA,UAAA,CAAY,CAAA;AAAA,MAClE;AAEA,MAAA,MAAM,YAAA,GAAe,MAAM,GAAA,CAAI,OAAO,CAAA,CACnC,KAAA,CAAM,EAAE,UAAA,EAAY,SAAA,EAAW,KAAA,EAAO,CAAA,CACtC,KAAA,EAAM;AAET,MAAA,IAAI,SAAA;AACJ,MAAA,IAAI,YAAA,EAAc;AAChB,QAAA,MAAM,GAAA,CAAI,OAAO,CAAA,CAAE,KAAA,CAAM,EAAE,YAAY,SAAA,EAAW,KAAA,EAAO,CAAA,CAAE,MAAA,EAAO;AAClE,QAAA,MAAM,GAAA,CAAI,UAAU,CAAA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,EAEA,MAAM,QAAA,CAAS,SAAA,EAAmB,KAAA,EAAiC;AACjE,IAAA,MAAM,IAAA,GAAO,MAAM,IAAA,CAAK,IAAA,CAAK,OAAO,CAAA,CACjC,KAAA,CAAM,EAAE,UAAA,EAAY,SAAA,EAAW,KAAA,EAAO,EACtC,KAAA,EAAM;AACT,IAAA,OAAO,QAAQ,IAAI,CAAA;AAAA,EACrB;AAAA,EAEA,MAAM,aAAA,CACJ,UAAA,EACA,KAAA,EACkC;AAClC,IAAA,IAAI,UAAA,CAAW,WAAW,CAAA,EAAG;AAC3B,MAAA,OAAO,EAAC;AAAA,IACV;AACA,IAAA,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;AACtB,IAAA,MAAM,eAAA,GAAkB,IAAI,GAAA,CAAI,KAAA,CAAM,GAAA,CAAI,OAAK,MAAA,CAAO,CAAA,CAAE,UAAU,CAAC,CAAC,CAAA;AACpE,IAAA,OAAO,UAAA,CAAW,MAAA,CAAO,CAAC,GAAA,EAAK,SAAA,KAAc;AAC3C,MAAA,GAAA,CAAI,SAAS,CAAA,GAAI,eAAA,CAAgB,GAAA,CAAI,SAAS,CAAA;AAC9C,MAAA,OAAO,GAAA;AAAA,IACT,CAAA,EAAG,EAA6B,CAAA;AAAA,EAClC;AACF;;;;"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var statusDbMapping = require('./statusDbMapping.cjs.js');
|
|
4
|
+
|
|
5
|
+
function toIsoUtc(value) {
|
|
6
|
+
if (value instanceof Date) {
|
|
7
|
+
return value.toISOString();
|
|
8
|
+
}
|
|
9
|
+
const trimmed = value.trim();
|
|
10
|
+
if (/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(trimmed)) {
|
|
11
|
+
return (/* @__PURE__ */ new Date(`${trimmed.replace(" ", "T")}Z`)).toISOString();
|
|
12
|
+
}
|
|
13
|
+
const parsed = new Date(trimmed);
|
|
14
|
+
return Number.isNaN(parsed.getTime()) ? trimmed : parsed.toISOString();
|
|
15
|
+
}
|
|
16
|
+
function mapFeatureRow(row) {
|
|
17
|
+
return {
|
|
18
|
+
id: String(row.id),
|
|
19
|
+
title: row.title,
|
|
20
|
+
description: row.description,
|
|
21
|
+
status: statusDbMapping.statusFromDb(row.status),
|
|
22
|
+
votes: Number(row.votes ?? 0),
|
|
23
|
+
author: row.author,
|
|
24
|
+
createdAt: toIsoUtc(row.created_at),
|
|
25
|
+
updatedAt: toIsoUtc(row.updated_at),
|
|
26
|
+
boardPosition: row.board_position !== void 0 && row.board_position !== null ? Number(row.board_position) : 0
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
function mapCommentRow(row) {
|
|
30
|
+
return {
|
|
31
|
+
id: String(row.id),
|
|
32
|
+
featureId: String(row.feature_id),
|
|
33
|
+
text: row.text,
|
|
34
|
+
author: row.author,
|
|
35
|
+
createdAt: toIsoUtc(row.created_at),
|
|
36
|
+
updatedAt: toIsoUtc(row.updated_at)
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
exports.mapCommentRow = mapCommentRow;
|
|
41
|
+
exports.mapFeatureRow = mapFeatureRow;
|
|
42
|
+
exports.toIsoUtc = toIsoUtc;
|
|
43
|
+
//# sourceMappingURL=tables.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tables.cjs.js","sources":["../../src/database/tables.ts"],"sourcesContent":["import { Feature, Comment } from '@rothenbergt/backstage-plugin-roadmap-common';\nimport { statusFromDb } from './statusDbMapping';\n\n/**\n * Raw row shapes as they come back from Knex (snake_case, driver-typed).\n * All reads must go through the mappers below so snake_case never leaks\n * into code typed against the camelCase API types.\n */\nexport type FeatureRow = {\n id: number | string;\n title: string;\n description: string;\n status: string;\n votes: number | string | null;\n author: string;\n created_at: string | Date;\n updated_at: string | Date;\n board_position: number | string | null;\n};\n\nexport type CommentRow = {\n id: number | string;\n feature_id: number | string;\n text: string;\n author: string;\n created_at: string | Date;\n updated_at: string | Date;\n};\n\nexport type VoteRow = {\n id: number | string;\n feature_id: number | string;\n voter: string;\n created_at: string | Date;\n updated_at: string | Date;\n};\n\n/**\n * Normalizes driver-specific timestamps to ISO 8601 UTC, the API contract.\n * Postgres returns Date objects; sqlite returns `YYYY-MM-DD HH:MM:SS` strings\n * that are UTC but carry no timezone marker.\n */\nexport function toIsoUtc(value: string | Date): string {\n if (value instanceof Date) {\n return value.toISOString();\n }\n const trimmed = value.trim();\n // SQL datetime without timezone: interpret as UTC.\n if (/^\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}/.test(trimmed)) {\n return new Date(`${trimmed.replace(' ', 'T')}Z`).toISOString();\n }\n const parsed = new Date(trimmed);\n return Number.isNaN(parsed.getTime()) ? trimmed : parsed.toISOString();\n}\n\nexport function mapFeatureRow(row: FeatureRow): Feature {\n return {\n id: String(row.id),\n title: row.title,\n description: row.description,\n status: statusFromDb(row.status),\n votes: Number(row.votes ?? 0),\n author: row.author,\n createdAt: toIsoUtc(row.created_at),\n updatedAt: toIsoUtc(row.updated_at),\n boardPosition:\n row.board_position !== undefined && row.board_position !== null\n ? Number(row.board_position)\n : 0,\n };\n}\n\nexport function mapCommentRow(row: CommentRow): Comment {\n return {\n id: String(row.id),\n featureId: String(row.feature_id),\n text: row.text,\n author: row.author,\n createdAt: toIsoUtc(row.created_at),\n updatedAt: toIsoUtc(row.updated_at),\n };\n}\n"],"names":["statusFromDb"],"mappings":";;;;AA0CO,SAAS,SAAS,KAAA,EAA8B;AACrD,EAAA,IAAI,iBAAiB,IAAA,EAAM;AACzB,IAAA,OAAO,MAAM,WAAA,EAAY;AAAA,EAC3B;AACA,EAAA,MAAM,OAAA,GAAU,MAAM,IAAA,EAAK;AAE3B,EAAA,IA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AAA;AAAA,IACZ,SAAA,EAAW,QAAA,CAAS,GAAA,CAAI,UAAU,CAAA;AAAA,IAClC,SAAA,EAAW,QAAA,CAAS,GAAA,CAAI,UAAU;AAAA,GACpC;AACF;;;;;;"}
|
|
@@ -11,6 +11,7 @@ const STATUS_LABELS = Object.values(backstagePluginRoadmapCommon.FeatureStatus).
|
|
|
11
11
|
);
|
|
12
12
|
const PAGINATION = "per_page=100";
|
|
13
13
|
const AUTHOR_TAG_RE = /^<!-- author:(\S+) -->\n/;
|
|
14
|
+
const ISSUE_AUTHOR_TAG_RE = /^<!-- backstage-author:(\S+) -->\n/;
|
|
14
15
|
const VOTE_TAG_RE = /^<!-- vote:(\S+) -->$/;
|
|
15
16
|
function formatStatusAsGitLabLabel(status) {
|
|
16
17
|
return `${ROADMAP_SCOPE_LABEL}${status}`;
|
|
@@ -26,19 +27,25 @@ function replaceStatusLabels(labels, newStatus) {
|
|
|
26
27
|
cleaned.push(formatStatusAsGitLabLabel(newStatus));
|
|
27
28
|
return cleaned;
|
|
28
29
|
}
|
|
29
|
-
function
|
|
30
|
-
|
|
30
|
+
function toIsoUtc(isoDate) {
|
|
31
|
+
const parsed = new Date(isoDate);
|
|
32
|
+
return Number.isNaN(parsed.getTime()) ? isoDate : parsed.toISOString();
|
|
31
33
|
}
|
|
32
34
|
function mapGitLabIssueToFeature(issue, voteCount) {
|
|
35
|
+
const rawDescription = issue.description ?? "";
|
|
36
|
+
const authorMatch = rawDescription.match(ISSUE_AUTHOR_TAG_RE);
|
|
33
37
|
return {
|
|
34
38
|
id: String(issue.id),
|
|
35
39
|
title: issue.title,
|
|
36
|
-
description:
|
|
40
|
+
description: authorMatch ? rawDescription.replace(ISSUE_AUTHOR_TAG_RE, "") : rawDescription,
|
|
37
41
|
status: extractStatusFromLabels(issue.labels ?? []),
|
|
38
42
|
votes: voteCount ?? issue.upvotes ?? 0,
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
43
|
+
// Issues created by this plugin carry the real Backstage author in a
|
|
44
|
+
// hidden tag because the GitLab issue author is just the API token owner.
|
|
45
|
+
// External issues fall back to the GitLab username.
|
|
46
|
+
author: authorMatch ? authorMatch[1] : issue.author?.username ?? "",
|
|
47
|
+
createdAt: toIsoUtc(issue.created_at),
|
|
48
|
+
updatedAt: toIsoUtc(issue.updated_at)
|
|
42
49
|
};
|
|
43
50
|
}
|
|
44
51
|
function mapGitLabNoteToComment(note, featureId) {
|
|
@@ -49,8 +56,8 @@ function mapGitLabNoteToComment(note, featureId) {
|
|
|
49
56
|
author: authorMatch ? authorMatch[1] : note.author?.username ?? "",
|
|
50
57
|
featureId,
|
|
51
58
|
text: authorMatch ? body.replace(AUTHOR_TAG_RE, "") : body,
|
|
52
|
-
|
|
53
|
-
|
|
59
|
+
createdAt: toIsoUtc(note.created_at),
|
|
60
|
+
updatedAt: toIsoUtc(note.updated_at)
|
|
54
61
|
};
|
|
55
62
|
}
|
|
56
63
|
function isHiddenVoteMarker(body) {
|
|
@@ -66,12 +73,16 @@ function parseUsernameFromEntityRef(userEntityRef) {
|
|
|
66
73
|
const entity = catalogModel.parseEntityRef(userEntityRef);
|
|
67
74
|
return entity.name;
|
|
68
75
|
}
|
|
69
|
-
function buildAuthorTaggedBody(
|
|
70
|
-
return `<!-- author:${
|
|
76
|
+
function buildAuthorTaggedBody(authorRef, text) {
|
|
77
|
+
return `<!-- author:${authorRef} -->
|
|
71
78
|
${text}`;
|
|
72
79
|
}
|
|
73
|
-
function buildVoteMarker(
|
|
74
|
-
return `<!-- vote:${
|
|
80
|
+
function buildVoteMarker(voterRef) {
|
|
81
|
+
return `<!-- vote:${voterRef} -->`;
|
|
82
|
+
}
|
|
83
|
+
function buildIssueAuthorTaggedDescription(authorRef, description) {
|
|
84
|
+
return `<!-- backstage-author:${authorRef} -->
|
|
85
|
+
${description}`;
|
|
75
86
|
}
|
|
76
87
|
function convertIssuesToFeatures(issues, voteCounts) {
|
|
77
88
|
return issues.map(
|
|
@@ -85,13 +96,15 @@ function filterUserComments(notes) {
|
|
|
85
96
|
return notes.filter(isUserComment);
|
|
86
97
|
}
|
|
87
98
|
function buildCommentBody(comment) {
|
|
88
|
-
|
|
89
|
-
return author ? buildAuthorTaggedBody(author, comment.text) : comment.text;
|
|
99
|
+
return comment.author ? buildAuthorTaggedBody(comment.author, comment.text) : comment.text;
|
|
90
100
|
}
|
|
91
101
|
function buildNewRoadmapIssuePayload(feature) {
|
|
92
102
|
return JSON.stringify({
|
|
93
103
|
title: feature.title,
|
|
94
|
-
description:
|
|
104
|
+
description: buildIssueAuthorTaggedDescription(
|
|
105
|
+
feature.author,
|
|
106
|
+
feature.description
|
|
107
|
+
),
|
|
95
108
|
labels: `${ROADMAP_LABEL},${formatStatusAsGitLabLabel(
|
|
96
109
|
backstagePluginRoadmapCommon.FeatureStatus.Suggested
|
|
97
110
|
)}`
|
|
@@ -114,6 +127,25 @@ function voteMapToJson(map) {
|
|
|
114
127
|
function jsonToVoteMap(json) {
|
|
115
128
|
return new Map(Object.entries(json));
|
|
116
129
|
}
|
|
130
|
+
function voterMarkerKeys(voterRef) {
|
|
131
|
+
const username = parseUsernameFromEntityRef(voterRef);
|
|
132
|
+
return username === voterRef ? [voterRef] : [voterRef, username];
|
|
133
|
+
}
|
|
134
|
+
function normalizeVoters(markers) {
|
|
135
|
+
const refKeyByName = /* @__PURE__ */ new Map();
|
|
136
|
+
for (const key of markers.keys()) {
|
|
137
|
+
if (key.includes("/")) {
|
|
138
|
+
const name = key.split("/").pop();
|
|
139
|
+
refKeyByName.set(name, refKeyByName.has(name) ? "" : key);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
const logical = /* @__PURE__ */ new Map();
|
|
143
|
+
for (const [key, ids] of markers) {
|
|
144
|
+
const target = key.includes("/") ? key : refKeyByName.get(key) || key;
|
|
145
|
+
logical.set(target, [...logical.get(target) ?? [], ...ids]);
|
|
146
|
+
}
|
|
147
|
+
return logical;
|
|
148
|
+
}
|
|
117
149
|
class RoadmapGitlabClient {
|
|
118
150
|
baseUrl;
|
|
119
151
|
token;
|
|
@@ -252,11 +284,11 @@ class RoadmapGitlabClient {
|
|
|
252
284
|
)})`
|
|
253
285
|
);
|
|
254
286
|
if (res.status === 401)
|
|
255
|
-
throw new errors.
|
|
256
|
-
"GitLab API authentication failed
|
|
287
|
+
throw new errors.ServiceUnavailableError(
|
|
288
|
+
"GitLab API authentication failed because the configured token is missing or invalid"
|
|
257
289
|
);
|
|
258
290
|
if (res.status === 404) throw new errors.NotFoundError(text);
|
|
259
|
-
throw new errors.
|
|
291
|
+
throw new errors.ServiceUnavailableError(`GitLab API error: ${res.status}`);
|
|
260
292
|
}
|
|
261
293
|
if (res.status === 204 || res.headers.get("content-length") === "0") {
|
|
262
294
|
return { data: void 0, res };
|
|
@@ -308,7 +340,7 @@ class RoadmapGitlabClient {
|
|
|
308
340
|
}
|
|
309
341
|
async createRoadmapIssue(feature) {
|
|
310
342
|
if (this.isGroupMode && !this.defaultProjectId) {
|
|
311
|
-
throw new errors.
|
|
343
|
+
throw new errors.ServiceUnavailableError(
|
|
312
344
|
"Creating features in group mode requires defaultProjectId to be configured"
|
|
313
345
|
);
|
|
314
346
|
}
|
|
@@ -347,9 +379,13 @@ class RoadmapGitlabClient {
|
|
|
347
379
|
for (const note of notes) {
|
|
348
380
|
if (note.system) continue;
|
|
349
381
|
const match = (note.body ?? "").trim().match(VOTE_TAG_RE);
|
|
350
|
-
if (match)
|
|
382
|
+
if (match) {
|
|
383
|
+
const ids = votesByUser.get(match[1]) ?? [];
|
|
384
|
+
ids.push(note.id);
|
|
385
|
+
votesByUser.set(match[1], ids);
|
|
386
|
+
}
|
|
351
387
|
}
|
|
352
|
-
return votesByUser;
|
|
388
|
+
return normalizeVoters(votesByUser);
|
|
353
389
|
}
|
|
354
390
|
async deleteNote(featureId, noteId) {
|
|
355
391
|
const pid = await this.resolveProjectId(featureId);
|
|
@@ -372,13 +408,17 @@ class RoadmapGitlabClient {
|
|
|
372
408
|
await this.ensureIssueProjectCached(featureId);
|
|
373
409
|
await this.fetchIssueById(featureId);
|
|
374
410
|
}
|
|
375
|
-
async removeVote(featureId,
|
|
376
|
-
|
|
377
|
-
|
|
411
|
+
async removeVote(featureId, noteIds, votesByUser, voterKeys) {
|
|
412
|
+
for (const noteId of noteIds) {
|
|
413
|
+
await this.deleteNote(featureId, noteId);
|
|
414
|
+
}
|
|
415
|
+
for (const key of voterKeys) {
|
|
416
|
+
votesByUser.delete(key);
|
|
417
|
+
}
|
|
378
418
|
}
|
|
379
|
-
async addVote(featureId, votesByUser,
|
|
380
|
-
await this.createNote(featureId, buildVoteMarker(
|
|
381
|
-
votesByUser.set(
|
|
419
|
+
async addVote(featureId, votesByUser, voterRef) {
|
|
420
|
+
const note = await this.createNote(featureId, buildVoteMarker(voterRef));
|
|
421
|
+
votesByUser.set(voterRef, [note.id]);
|
|
382
422
|
}
|
|
383
423
|
async getOrFetchVotes(featureId) {
|
|
384
424
|
const cached = await this.getCachedVotes(featureId);
|
|
@@ -438,21 +478,27 @@ class RoadmapGitlabClient {
|
|
|
438
478
|
status
|
|
439
479
|
);
|
|
440
480
|
const updatedIssue = await this.updateIssueLabels(id, updatedLabels);
|
|
441
|
-
|
|
481
|
+
const voteCount = await this.getVoteCount(id);
|
|
482
|
+
return mapGitLabIssueToFeature(updatedIssue, voteCount);
|
|
442
483
|
}
|
|
443
484
|
async toggleVote(featureId, voter) {
|
|
444
485
|
await this.ensureIssueProjectCached(featureId);
|
|
445
486
|
await this.invalidateCachedVotes(featureId);
|
|
446
|
-
const
|
|
487
|
+
const voterKeys = voterMarkerKeys(voter);
|
|
447
488
|
const votesByUser = await this.collectVoteMarkersByUser(featureId);
|
|
448
|
-
const
|
|
449
|
-
|
|
450
|
-
|
|
489
|
+
const existingNoteIds = voterKeys.flatMap(
|
|
490
|
+
(key) => votesByUser.get(key) ?? []
|
|
491
|
+
);
|
|
492
|
+
if (existingNoteIds.length > 0) {
|
|
493
|
+
await this.removeVote(featureId, existingNoteIds, votesByUser, voterKeys);
|
|
451
494
|
} else {
|
|
452
|
-
await this.addVote(featureId, votesByUser,
|
|
495
|
+
await this.addVote(featureId, votesByUser, voter);
|
|
453
496
|
}
|
|
454
|
-
await this.
|
|
455
|
-
return {
|
|
497
|
+
await this.invalidateCachedVotes(featureId);
|
|
498
|
+
return {
|
|
499
|
+
voteAdded: existingNoteIds.length === 0,
|
|
500
|
+
voteCount: votesByUser.size
|
|
501
|
+
};
|
|
456
502
|
}
|
|
457
503
|
async getVoteCount(featureId) {
|
|
458
504
|
await this.ensureIssueProjectCached(featureId);
|
|
@@ -468,9 +514,8 @@ class RoadmapGitlabClient {
|
|
|
468
514
|
}
|
|
469
515
|
async hasVoted(featureId, voter) {
|
|
470
516
|
await this.ensureIssueProjectCached(featureId);
|
|
471
|
-
const username = parseUsernameFromEntityRef(voter);
|
|
472
517
|
const votes = await this.getOrFetchVotes(featureId);
|
|
473
|
-
return votes.has(
|
|
518
|
+
return voterMarkerKeys(voter).some((key) => votes.has(key));
|
|
474
519
|
}
|
|
475
520
|
async hasVotedBatch(featureIds, voter) {
|
|
476
521
|
const results = {};
|