mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-17 10:06:17 +08:00
feat(server): cluster level event system (#9884)
This commit is contained in:
@@ -5,11 +5,10 @@ import { pick } from 'lodash-es';
|
||||
import {
|
||||
CryptoHelper,
|
||||
EmailAlreadyUsed,
|
||||
EventEmitter,
|
||||
EventBus,
|
||||
WrongSignInCredentials,
|
||||
WrongSignInMethod,
|
||||
} from '../base';
|
||||
import type { Payload } from '../base/event/def';
|
||||
import { Quota_FreePlanV1_1 } from '../core/quota/schema';
|
||||
import { BaseModel } from './base';
|
||||
import type { Workspace } from './workspace';
|
||||
@@ -40,21 +39,15 @@ const defaultUserCreatingData = {
|
||||
},
|
||||
};
|
||||
|
||||
declare module '../base/event/def' {
|
||||
interface UserEvents {
|
||||
created: Payload<User>;
|
||||
updated: Payload<User>;
|
||||
deleted: Payload<
|
||||
User & {
|
||||
// TODO(@forehalo): unlink foreign key constraint on [WorkspaceUserPermission] to delegate
|
||||
// dealing of owned workspaces of deleted users to workspace model
|
||||
ownedWorkspaces: Workspace['id'][];
|
||||
}
|
||||
>;
|
||||
}
|
||||
|
||||
interface EventDefinitions {
|
||||
user: UserEvents;
|
||||
declare global {
|
||||
interface Events {
|
||||
'user.created': User;
|
||||
'user.updated': User;
|
||||
'user.deleted': User & {
|
||||
// TODO(@forehalo): unlink foreign key constraint on [WorkspaceUserPermission] to delegate
|
||||
// dealing of owned workspaces of deleted users to workspace model
|
||||
ownedWorkspaces: Workspace['id'][];
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,7 +58,7 @@ export type { User };
|
||||
export class UserModel extends BaseModel {
|
||||
constructor(
|
||||
private readonly crypto: CryptoHelper,
|
||||
private readonly event: EventEmitter
|
||||
private readonly event: EventBus
|
||||
) {
|
||||
super();
|
||||
}
|
||||
|
||||
@@ -7,10 +7,57 @@ import {
|
||||
} from '@prisma/client';
|
||||
import { groupBy } from 'lodash-es';
|
||||
|
||||
import { EventEmitter } from '../base';
|
||||
import { EventBus } from '../base';
|
||||
import { BaseModel } from './base';
|
||||
import { Permission } from './common';
|
||||
|
||||
declare global {
|
||||
interface Events {
|
||||
'workspace.members.reviewRequested': { inviteId: string };
|
||||
'workspace.members.requestDeclined': {
|
||||
userId: string;
|
||||
workspaceId: string;
|
||||
};
|
||||
'workspace.members.requestApproved': { inviteId: string };
|
||||
'workspace.members.roleChanged': {
|
||||
userId: string;
|
||||
workspaceId: string;
|
||||
permission: number;
|
||||
};
|
||||
'workspace.members.ownershipTransferred': {
|
||||
from: string;
|
||||
to: string;
|
||||
workspaceId: string;
|
||||
};
|
||||
'workspace.members.updated': {
|
||||
workspaceId: string;
|
||||
count: number;
|
||||
};
|
||||
'workspace.members.leave': {
|
||||
user: {
|
||||
id: string;
|
||||
email: string;
|
||||
};
|
||||
workspaceId: string;
|
||||
};
|
||||
'workspace.members.removed': {
|
||||
workspaceId: string;
|
||||
userId: string;
|
||||
};
|
||||
'workspace.deleted': {
|
||||
id: string;
|
||||
};
|
||||
'workspace.blob.delete': {
|
||||
workspaceId: string;
|
||||
key: string;
|
||||
};
|
||||
'workspace.blob.sync': {
|
||||
workspaceId: string;
|
||||
key: string;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export { WorkspaceMemberStatus };
|
||||
export type { Workspace };
|
||||
export type UpdateWorkspaceInput = Pick<
|
||||
@@ -28,7 +75,7 @@ export interface FindWorkspaceMembersOptions {
|
||||
|
||||
@Injectable()
|
||||
export class WorkspaceModel extends BaseModel {
|
||||
constructor(private readonly event: EventEmitter) {
|
||||
constructor(private readonly event: EventBus) {
|
||||
super();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user