-
-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathmain.ts
68 lines (61 loc) · 2.08 KB
/
main.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import type { User } from '@bcms/selfhosted-backend/user/models/main';
import type { ApiKey } from '@bcms/selfhosted-backend/api-key/models/main';
import type { Backup } from '@bcms/selfhosted-backend/backup/models/main';
import type { Entry } from '@bcms/selfhosted-backend/entry/models/main';
import type { Group } from '@bcms/selfhosted-backend/group/models/main';
import type { Language } from '@bcms/selfhosted-backend/language/models/main';
import type { Media } from '@bcms/selfhosted-backend/media/models/main';
import type { Template } from '@bcms/selfhosted-backend/template/models/main';
import type { EntryStatus } from '@bcms/selfhosted-backend/entry-status/models/main';
import type { TemplateOrganizer } from '@bcms/selfhosted-backend/template-organizer/models/main';
import type { Widget } from '@bcms/selfhosted-backend/widget/models/main';
import type { ObjectSchema } from '@bcms/selfhosted-utils/object-utility';
export type BCMSEventType = 'all' | 'update' | 'add' | 'delete';
export interface BCMSEventDataType {
all: unknown;
apiKey: ApiKey;
backup: Backup;
entry: Entry;
entryStatus: EntryStatus;
group: Group;
language: Language;
media: Media;
template: Template;
templateOrganizer: TemplateOrganizer;
user: User;
widgets: Widget;
}
export type BCMSEventScope = keyof BCMSEventDataType;
export interface BCMSEventConfig {
scope: BCMSEventScope;
type: BCMSEventType;
}
export const BCMSEventConfigSchema: ObjectSchema = {
scope: {
__type: 'string',
__required: true,
},
type: {
__type: 'string',
__required: true,
},
};
export interface BCMSEvent {
config: BCMSEventConfig;
handler<Scope extends BCMSEventScope = BCMSEventScope>(
type: BCMSEventType,
scope: Scope,
data: BCMSEventDataType[Scope],
): Promise<void>;
}
export const BCMSEventSchema: ObjectSchema = {
config: {
__type: 'object',
__required: true,
__child: BCMSEventConfigSchema,
},
handler: {
__type: 'function',
__required: true,
},
};