rename to metadata

Signed-off-by: Frank Ye <franky@spotify.com>
This commit is contained in:
Frank Ye
2025-05-30 14:05:19 -04:00
parent 9152ba8f36
commit b345e53dd3
10 changed files with 41 additions and 42 deletions
+1 -1
View File
@@ -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.
@@ -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');
});
};
+2 -2
View File
@@ -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 | - | - |
@@ -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',
});
});
});
@@ -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,
};
};
@@ -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,
@@ -40,6 +40,7 @@
},
"dependencies": {
"@backstage/config": "workspace:^",
"@backstage/types": "workspace:^",
"@material-ui/icons": "^4.9.1"
},
"devDependencies": {
+7 -8
View File
@@ -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<string, unknown> = Record<string, unknown>,
> = {
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<T>;
payload: NotificationPayload;
};
export { Notification_2 as Notification };
// @public (undocumented)
export type NotificationPayload<
T extends Record<string, unknown> = Record<string, unknown>,
> = {
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)
+7 -9
View File
@@ -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<string, unknown> = Record<string, unknown>,
> = {
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<string, unknown> = Record<string, unknown>,
> = {
export type Notification = {
/**
* Unique identifier for the notification
*/
@@ -95,7 +93,7 @@ export type Notification<
/**
* Actual notification payload
*/
payload: NotificationPayload<T>;
payload: NotificationPayload;
};
/** @public */
+1
View File
@@ -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