From b345e53dd30d644a573a00614a3a630e473a2dc6 Mon Sep 17 00:00:00 2001 From: Frank Ye Date: Fri, 30 May 2025 14:05:19 -0400 Subject: [PATCH] rename to metadata Signed-off-by: Frank Ye --- .changeset/wise-mails-agree.md | 2 +- ..._addAttributes.js => 20250521_addMetadata.js} | 8 ++++---- plugins/notifications-backend/report.sql.md | 4 ++-- .../database/DatabaseNotificationsStore.test.ts | 8 ++++---- .../src/database/DatabaseNotificationsStore.ts | 12 ++++++------ .../src/service/router.test.ts | 16 ++++++++-------- plugins/notifications-common/package.json | 1 + plugins/notifications-common/report.api.md | 15 +++++++-------- plugins/notifications-common/src/types.ts | 16 +++++++--------- yarn.lock | 1 + 10 files changed, 41 insertions(+), 42 deletions(-) rename plugins/notifications-backend/migrations/{20250521_addAttributes.js => 20250521_addMetadata.js} (85%) diff --git a/.changeset/wise-mails-agree.md b/.changeset/wise-mails-agree.md index d6e96a3f20..301c941339 100644 --- a/.changeset/wise-mails-agree.md +++ b/.changeset/wise-mails-agree.md @@ -3,4 +3,4 @@ '@backstage/plugin-notifications-common': minor --- -Add an optional generic object `attributes` field to `NotificationPayload`. Attributes can be used to store additional unstructured data for the notification, and are stored in the database. +Add an optional generic object `metadata` field to `NotificationPayload`. Metadata can be used to store additional unstructured data for the notification, and are stored in the database. diff --git a/plugins/notifications-backend/migrations/20250521_addAttributes.js b/plugins/notifications-backend/migrations/20250521_addMetadata.js similarity index 85% rename from plugins/notifications-backend/migrations/20250521_addAttributes.js rename to plugins/notifications-backend/migrations/20250521_addMetadata.js index e7519d2e29..c298ed49e1 100644 --- a/plugins/notifications-backend/migrations/20250521_addAttributes.js +++ b/plugins/notifications-backend/migrations/20250521_addMetadata.js @@ -16,18 +16,18 @@ exports.up = async function up(knex) { await knex.schema.alterTable('notification', table => { - table.text('attributes').nullable(); + table.text('metadata').nullable(); }); await knex.schema.alterTable('broadcast', table => { - table.text('attributes').nullable(); + table.text('metadata').nullable(); }); }; exports.down = async function down(knex) { await knex.schema.alterTable('notification', table => { - table.dropColumn('attributes'); + table.dropColumn('metadata'); }); await knex.schema.alterTable('broadcast', table => { - table.dropColumn('attributes'); + table.dropColumn('metadata'); }); }; diff --git a/plugins/notifications-backend/report.sql.md b/plugins/notifications-backend/report.sql.md index bb9612b357..ab491dc791 100644 --- a/plugins/notifications-backend/report.sql.md +++ b/plugins/notifications-backend/report.sql.md @@ -6,12 +6,12 @@ | Column | Type | Nullable | Max Length | Default | | ------------- | -------------------------- | -------- | ---------- | ------------------- | -| `attributes` | `text` | true | - | - | | `created` | `timestamp with time zone` | false | - | `CURRENT_TIMESTAMP` | | `description` | `text` | true | - | - | | `icon` | `character varying` | true | 255 | - | | `id` | `uuid` | false | - | - | | `link` | `text` | true | - | - | +| `metadata` | `text` | true | - | - | | `origin` | `character varying` | false | 255 | - | | `scope` | `character varying` | true | 255 | - | | `severity` | `character varying` | false | 8 | - | @@ -41,12 +41,12 @@ | Column | Type | Nullable | Max Length | Default | | ------------- | -------------------------- | -------- | ---------- | ------------------- | -| `attributes` | `text` | true | - | - | | `created` | `timestamp with time zone` | false | - | `CURRENT_TIMESTAMP` | | `description` | `text` | true | - | - | | `icon` | `character varying` | true | 255 | - | | `id` | `uuid` | false | - | - | | `link` | `text` | true | - | - | +| `metadata` | `text` | true | - | - | | `origin` | `character varying` | false | 255 | - | | `read` | `timestamp with time zone` | true | - | - | | `saved` | `timestamp with time zone` | true | - | - | diff --git a/plugins/notifications-backend/src/database/DatabaseNotificationsStore.test.ts b/plugins/notifications-backend/src/database/DatabaseNotificationsStore.test.ts index 03c4428289..9d8898f0e8 100644 --- a/plugins/notifications-backend/src/database/DatabaseNotificationsStore.test.ts +++ b/plugins/notifications-backend/src/database/DatabaseNotificationsStore.test.ts @@ -69,8 +69,8 @@ const testNotification1: Notification = { link: '/catalog', severity: 'critical', icon: 'docs', - attributes: { - attribute1: 'attributeValue', + metadata: { + attribute1: 'value1', }, }, }; @@ -212,8 +212,8 @@ describe.each(databases.eachSupportedId())( expect(notification?.payload?.link).toBe('/catalog'); expect(notification?.payload?.severity).toBe('critical'); expect(notification?.payload?.icon).toBe('docs'); - expect(notification?.payload?.attributes).toEqual({ - attribute1: 'attributeValue', + expect(notification?.payload?.metadata).toEqual({ + attribute1: 'value1', }); }); }); diff --git a/plugins/notifications-backend/src/database/DatabaseNotificationsStore.ts b/plugins/notifications-backend/src/database/DatabaseNotificationsStore.ts index 5f68aa0e39..6a2f3f80b8 100644 --- a/plugins/notifications-backend/src/database/DatabaseNotificationsStore.ts +++ b/plugins/notifications-backend/src/database/DatabaseNotificationsStore.ts @@ -53,7 +53,7 @@ const NOTIFICATION_COLUMNS = [ 'user', 'read', 'saved', - 'attributes', + 'metadata', ]; type NotificationRowType = { @@ -165,7 +165,7 @@ export class DatabaseNotificationsStore implements NotificationsStore { severity: row.severity, scope: row.scope, icon: row.icon, - attributes: row.attributes ? JSON.parse(row.attributes) : undefined, + metadata: row.metadata ? JSON.parse(row.metadata) : undefined, }, })); }; @@ -229,8 +229,8 @@ export class DatabaseNotificationsStore implements NotificationsStore { icon: notification.payload?.icon, saved: notification.saved, read: notification.read, - attributes: notification.payload?.attributes - ? JSON.stringify(notification.payload.attributes) + metadata: notification.payload?.metadata + ? JSON.stringify(notification.payload.metadata) : undefined, }; }; @@ -247,8 +247,8 @@ export class DatabaseNotificationsStore implements NotificationsStore { severity: normalizeSeverity(notification.payload?.severity), icon: notification.payload.icon, scope: notification.payload?.scope, - attributes: notification.payload?.attributes - ? JSON.stringify(notification.payload.attributes) + metadata: notification.payload?.metadata + ? JSON.stringify(notification.payload.metadata) : undefined, }; }; diff --git a/plugins/notifications-backend/src/service/router.test.ts b/plugins/notifications-backend/src/service/router.test.ts index b745754ba6..b19a78c3d9 100644 --- a/plugins/notifications-backend/src/service/router.test.ts +++ b/plugins/notifications-backend/src/service/router.test.ts @@ -529,8 +529,8 @@ describe.each(databases.eachSupportedId())('createRouter (%s)', databaseId => { title: 'Test broadcast notification', created: new Date(), severity: 'high', - attributes: { - attr1: 'attrValue', + metadata: { + attr1: 'value1', }, }); await client('notification').insert({ @@ -540,8 +540,8 @@ describe.each(databases.eachSupportedId())('createRouter (%s)', databaseId => { title: 'Test notification', created: new Date(), severity: 'normal', - attributes: { - attr1: 'attrValue', + metadata: { + attr1: 'value1', }, }); @@ -561,8 +561,8 @@ describe.each(databases.eachSupportedId())('createRouter (%s)', databaseId => { severity: 'normal', title: 'Test notification', topic: null, - attributes: { - attr1: 'attrValue', + metadata: { + attr1: 'value1', }, }, read: null, @@ -582,8 +582,8 @@ describe.each(databases.eachSupportedId())('createRouter (%s)', databaseId => { severity: 'high', title: 'Test broadcast notification', topic: null, - attributes: { - attr1: 'attrValue', + metadata: { + attr1: 'value1', }, }, read: null, diff --git a/plugins/notifications-common/package.json b/plugins/notifications-common/package.json index 66473d0237..9e1c544ba1 100644 --- a/plugins/notifications-common/package.json +++ b/plugins/notifications-common/package.json @@ -40,6 +40,7 @@ }, "dependencies": { "@backstage/config": "workspace:^", + "@backstage/types": "workspace:^", "@material-ui/icons": "^4.9.1" }, "devDependencies": { diff --git a/plugins/notifications-common/report.api.md b/plugins/notifications-common/report.api.md index f619ab677d..337c41b7b5 100644 --- a/plugins/notifications-common/report.api.md +++ b/plugins/notifications-common/report.api.md @@ -4,6 +4,7 @@ ```ts import { Config } from '@backstage/config'; +import { JsonValue } from '@backstage/types'; // @public (undocumented) export type ChannelSetting = { @@ -31,9 +32,7 @@ export type NewNotificationSignal = { }; // @public (undocumented) -type Notification_2< - T extends Record = Record, -> = { +type Notification_2 = { id: string; user: string | null; created: Date; @@ -41,14 +40,12 @@ type Notification_2< read?: Date; updated?: Date; origin: string; - payload: NotificationPayload; + payload: NotificationPayload; }; export { Notification_2 as Notification }; // @public (undocumented) -export type NotificationPayload< - T extends Record = Record, -> = { +export type NotificationPayload = { title: string; description?: string; link?: string; @@ -56,7 +53,9 @@ export type NotificationPayload< topic?: string; scope?: string; icon?: string; - attributes?: T; + metadata?: { + [KMetadataKey in string]?: JsonValue; + }; }; // @public (undocumented) diff --git a/plugins/notifications-common/src/types.ts b/plugins/notifications-common/src/types.ts index 2583d44dc1..4e49de79de 100644 --- a/plugins/notifications-common/src/types.ts +++ b/plugins/notifications-common/src/types.ts @@ -14,13 +14,13 @@ * limitations under the License. */ +import { JsonValue } from '@backstage/types'; + /** @public */ export type NotificationSeverity = 'critical' | 'high' | 'normal' | 'low'; /** @public */ -export type NotificationPayload< - T extends Record = Record, -> = { +export type NotificationPayload = { /** * Notification title */ @@ -53,15 +53,13 @@ export type NotificationPayload< */ icon?: string; /** - * Optional additional customizable attributes. + * Optional additional customizable metadata. */ - attributes?: T; + metadata?: { [KMetadataKey in string]?: JsonValue }; }; /** @public */ -export type Notification< - T extends Record = Record, -> = { +export type Notification = { /** * Unique identifier for the notification */ @@ -95,7 +93,7 @@ export type Notification< /** * Actual notification payload */ - payload: NotificationPayload; + payload: NotificationPayload; }; /** @public */ diff --git a/yarn.lock b/yarn.lock index a3334417ab..c3cdc943dd 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5751,6 +5751,7 @@ __metadata: dependencies: "@backstage/cli": "workspace:^" "@backstage/config": "workspace:^" + "@backstage/types": "workspace:^" "@material-ui/icons": "npm:^4.9.1" languageName: unknown linkType: soft