|
1 | | -import { DOMAIN_SPACE } from '@hcengineering/core' |
| 1 | +import { DOMAIN_DOC_INDEX_STATE, DOMAIN_SPACE, DOMAIN_TX } from '@hcengineering/core' |
2 | 2 |
|
3 | 3 | type DataType = 'bigint' | 'bool' | 'text' | 'text[]' |
4 | 4 |
|
5 | 5 | type Schema = Record<string, [DataType, boolean]> |
6 | 6 |
|
7 | | -export const defaultSchema: Schema = { |
| 7 | +const baseSchema: Schema = { |
8 | 8 | _id: ['text', true], |
9 | 9 | _class: ['text', true], |
10 | 10 | space: ['text', true], |
11 | 11 | modifiedBy: ['text', true], |
12 | 12 | createdBy: ['text', false], |
13 | 13 | modifiedOn: ['bigint', true], |
14 | 14 | createdOn: ['bigint', false], |
| 15 | + '%hash%': ['text', false] |
| 16 | +} |
| 17 | + |
| 18 | +const defaultSchema: Schema = { |
| 19 | + ...baseSchema, |
15 | 20 | attachedTo: ['text', false] |
16 | 21 | } |
17 | 22 |
|
18 | | -export const spaceSchema: Schema = { |
19 | | - _id: ['text', true], |
20 | | - _class: ['text', true], |
21 | | - space: ['text', true], |
22 | | - modifiedBy: ['text', true], |
23 | | - createdBy: ['text', false], |
24 | | - modifiedOn: ['bigint', true], |
25 | | - createdOn: ['bigint', false], |
| 23 | +const spaceSchema: Schema = { |
| 24 | + ...baseSchema, |
26 | 25 | private: ['bool', true], |
27 | 26 | members: ['text[]', true] |
28 | 27 | } |
29 | 28 |
|
| 29 | +const txSchema: Schema = { |
| 30 | + ...baseSchema, |
| 31 | + objectSpace: ['text', true], |
| 32 | + objectId: ['text', false] |
| 33 | +} |
| 34 | + |
| 35 | +const notificationSchema: Schema = { |
| 36 | + ...baseSchema, |
| 37 | + isViewed: ['bool', true], |
| 38 | + archived: ['bool', true], |
| 39 | + user: ['text', true] |
| 40 | +} |
| 41 | + |
| 42 | +const dncSchema: Schema = { |
| 43 | + ...baseSchema, |
| 44 | + objectId: ['text', true], |
| 45 | + objectClass: ['text', true], |
| 46 | + user: ['text', true] |
| 47 | +} |
| 48 | + |
| 49 | +const userNotificationSchema: Schema = { |
| 50 | + ...baseSchema, |
| 51 | + user: ['text', true] |
| 52 | +} |
| 53 | + |
| 54 | +const docIndexStateSchema: Schema = { |
| 55 | + ...baseSchema, |
| 56 | + needIndex: ['bool', true] |
| 57 | +} |
| 58 | + |
| 59 | +export function translateDomain (domain: string): string { |
| 60 | + return domain.replaceAll('-', '_') |
| 61 | +} |
| 62 | + |
30 | 63 | export const domainSchemas: Record<string, Schema> = { |
31 | | - [DOMAIN_SPACE]: spaceSchema |
| 64 | + [DOMAIN_SPACE]: spaceSchema, |
| 65 | + [DOMAIN_TX]: txSchema, |
| 66 | + [translateDomain(DOMAIN_DOC_INDEX_STATE)]: docIndexStateSchema, |
| 67 | + notification: notificationSchema, |
| 68 | + [translateDomain('notification-dnc')]: dncSchema, |
| 69 | + [translateDomain('notification-user')]: userNotificationSchema |
32 | 70 | } |
33 | 71 |
|
34 | 72 | export function getSchema (domain: string): Schema { |
35 | | - return domainSchemas[domain] ?? defaultSchema |
| 73 | + return domainSchemas[translateDomain(domain)] ?? defaultSchema |
| 74 | +} |
| 75 | + |
| 76 | +export function getDocFieldsByDomains (domain: string): string[] { |
| 77 | + const schema = domainSchemas[translateDomain(domain)] ?? defaultSchema |
| 78 | + return Object.keys(schema) |
36 | 79 | } |
0 commit comments