All checks were successful
Build and Publish Docker Image / build-and-push (push) Successful in 50s
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
43 lines
1.2 KiB
TypeScript
43 lines
1.2 KiB
TypeScript
import type { SQLOutputValue } from "node:sqlite";
|
|
import type {
|
|
Notification,
|
|
NotificationData,
|
|
NotificationType,
|
|
} from "../../shared/notification.ts";
|
|
|
|
export interface NotificationRow {
|
|
id: string;
|
|
user_id: string;
|
|
type: string;
|
|
data: string;
|
|
read: number;
|
|
created_at: string;
|
|
source_key: string | null;
|
|
[key: string]: SQLOutputValue;
|
|
}
|
|
|
|
export function isNotificationRow(
|
|
obj: unknown,
|
|
): obj is NotificationRow {
|
|
return !!obj && typeof obj === "object" &&
|
|
"id" in obj && typeof obj.id === "string" &&
|
|
"user_id" in obj && typeof obj.user_id === "string" &&
|
|
"type" in obj && typeof obj.type === "string" &&
|
|
"data" in obj && typeof obj.data === "string" &&
|
|
"read" in obj && typeof obj.read === "number" &&
|
|
"created_at" in obj && typeof obj.created_at === "string" &&
|
|
"source_key" in obj &&
|
|
(typeof obj.source_key === "string" || obj.source_key === null);
|
|
}
|
|
|
|
export function notificationRowToApi(row: NotificationRow): Notification {
|
|
return {
|
|
id: row.id,
|
|
userId: row.user_id,
|
|
type: row.type as NotificationType,
|
|
data: JSON.parse(row.data) as NotificationData,
|
|
read: Boolean(row.read),
|
|
createdAt: new Date(row.created_at),
|
|
};
|
|
}
|