mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-23 05:25:53 +08:00
refactor(server): use events system (#5149)
This commit is contained in:
@@ -1,23 +1,18 @@
|
||||
import type { Snapshot, User, Workspace } from '@prisma/client';
|
||||
import type { Snapshot, Workspace } from '@prisma/client';
|
||||
|
||||
import { ChangePayload, Flatten, Payload } from './types';
|
||||
import { Flatten, Payload } from './types';
|
||||
|
||||
interface EventDefinitions {
|
||||
user: {
|
||||
created: Payload<User>;
|
||||
updated: Payload<ChangePayload<User>>;
|
||||
deleted: Payload<User['id']>;
|
||||
};
|
||||
|
||||
workspace: {
|
||||
created: Payload<Workspace>;
|
||||
updated: Payload<ChangePayload<Workspace>>;
|
||||
deleted: Payload<Workspace['id']>;
|
||||
};
|
||||
|
||||
snapshot: {
|
||||
created: Payload<Snapshot>;
|
||||
updated: Payload<ChangePayload<Snapshot>>;
|
||||
updated: Payload<
|
||||
Pick<Snapshot, 'id' | 'workspaceId'> & {
|
||||
previous: Pick<Snapshot, 'blob' | 'state' | 'updatedAt'>;
|
||||
}
|
||||
>;
|
||||
deleted: Payload<Pick<Snapshot, 'id' | 'workspaceId'>>;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import {
|
||||
OnEvent as RawOnEvent,
|
||||
} from '@nestjs/event-emitter';
|
||||
|
||||
import { Event, EventPayload } from './events';
|
||||
import type { Event, EventPayload } from './events';
|
||||
|
||||
@Injectable()
|
||||
export class EventEmitter {
|
||||
@@ -42,3 +42,4 @@ export const OnEvent = (
|
||||
exports: [EventEmitter],
|
||||
})
|
||||
export class EventModule {}
|
||||
export { EventPayload };
|
||||
|
||||
@@ -3,11 +3,6 @@ export type Payload<T> = {
|
||||
data: T;
|
||||
};
|
||||
|
||||
export type ChangePayload<T> = {
|
||||
from: Partial<T>;
|
||||
to: Partial<T>;
|
||||
};
|
||||
|
||||
export type Join<A extends string, B extends string> = A extends ''
|
||||
? B
|
||||
: `${A}.${B}`;
|
||||
@@ -33,6 +28,6 @@ export type Leaves<T, P extends string = ''> = T extends Payload<any>
|
||||
export type Flatten<T> = Leaves<T> extends infer R
|
||||
? {
|
||||
// @ts-expect-error yo, ts can't make it
|
||||
[K in R]: PathType<T, K> extends Payload<infer U> ? { data: U } : never;
|
||||
[K in R]: PathType<T, K> extends Payload<infer U> ? U : never;
|
||||
}
|
||||
: never;
|
||||
|
||||
Reference in New Issue
Block a user