|
1 | 1 | import { uniq } from 'lodash';
|
| 2 | +import { AbstractClass } from 'type-fest'; |
2 | 3 | import { DbLabelSymbol } from './db-label.decorator';
|
3 | 4 | import { getParentTypes } from './parent-types';
|
4 | 5 | import { isResourceClass } from './resource.dto';
|
5 |
| -import { AbstractClassType } from './types'; |
6 | 6 |
|
7 |
| -export const getDbPropertyLabels = ( |
8 |
| - type: AbstractClassType<unknown>, |
9 |
| - property: string, |
10 |
| -) => { |
| 7 | +type Class = AbstractClass<any>; |
| 8 | + |
| 9 | +export const getDbPropertyLabels = (type: Class, property: string) => { |
11 | 10 | const labels: string[] | undefined = Reflect.getMetadata(
|
12 | 11 | DbLabelSymbol,
|
13 | 12 | type.prototype,
|
14 | 13 | property,
|
15 | 14 | );
|
16 |
| - const normalized = labels?.flatMap((l) => l.split(':')); |
17 |
| - return uniq([...(normalized ?? []), 'Property']); |
| 15 | + return uniq([...(labels ?? []), 'Property']); |
18 | 16 | };
|
19 | 17 |
|
20 |
| -export const getDbClassLabels = ( |
21 |
| - type: AbstractClassType<unknown>, |
22 |
| -): readonly string[] => { |
| 18 | +export const getDbClassLabels = (type: Class): readonly string[] => { |
23 | 19 | const labels = getParentTypes(type)
|
24 | 20 | .filter(isResourceClass)
|
25 | 21 | .flatMap(getDbClassOwnLabels);
|
26 | 22 | return uniq([...labels, 'BaseNode']);
|
27 | 23 | };
|
28 | 24 |
|
29 |
| -const getDbClassOwnLabels = ( |
30 |
| - type: AbstractClassType<unknown>, |
31 |
| -): readonly string[] => { |
| 25 | +const getDbClassOwnLabels = (type: Class): readonly string[] => { |
32 | 26 | const decorated: string[] | null = Reflect.getOwnMetadata(
|
33 | 27 | DbLabelSymbol,
|
34 | 28 | type,
|
35 | 29 | );
|
36 |
| - return decorated?.flatMap((l) => l.split(':')) ?? [type.name]; |
| 30 | + return decorated ?? [type.name]; |
37 | 31 | };
|
0 commit comments