refactor: P1-3/4/6 解耦修复 - 拆分 auth/users 文件 + notifications 反向依赖
This commit is contained in:
@@ -13,6 +13,10 @@ import "server-only"
|
||||
* 而本模块 NotificationPayload.type 为 "info" | "warning" | "error" | "success"。
|
||||
* 此处将 payload.type 作为字符串写入 DB(DB 列为 varchar(128),支持任意值),
|
||||
* 不破坏现有 messaging 模块的类型约束。
|
||||
*
|
||||
* 使用动态 import 打破 notifications -> messaging 的静态反向依赖。
|
||||
* 运行时调用链: messaging -> dispatcher -> in-app channel -> messaging.createNotification (存储)
|
||||
* 这是可接受的运行时调用链,但模块级静态依赖必须单向。
|
||||
*/
|
||||
|
||||
import type {
|
||||
@@ -21,11 +25,10 @@ import type {
|
||||
NotificationChannel,
|
||||
} from "../types"
|
||||
import type { NotificationChannelSender, ChannelRecipient } from "./types"
|
||||
import { createNotification } from "@/modules/messaging/data-access"
|
||||
|
||||
const channel: NotificationChannel = "in_app"
|
||||
|
||||
/** 站内消息发送器(调用现有 messaging data-access) */
|
||||
/** 站内消息发送器(通过动态 import 调用 messaging data-access) */
|
||||
class InAppChannelSender implements NotificationChannelSender {
|
||||
readonly channel = channel
|
||||
|
||||
@@ -43,6 +46,8 @@ class InAppChannelSender implements NotificationChannelSender {
|
||||
sentAt: new Date(),
|
||||
}
|
||||
}
|
||||
// Dynamic import to break static reverse dependency on messaging module
|
||||
const { createNotification } = await import("@/modules/messaging/data-access")
|
||||
const id = await createNotification({
|
||||
userId: payload.userId,
|
||||
// DB 列为 varchar(128),支持任意字符串;保留 payload.type 语义
|
||||
|
||||
Reference in New Issue
Block a user