framework-do-dede 1.0.20 → 1.0.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,3 +1,8 @@
|
|
|
1
1
|
export declare function Restrict(): (target: any, propertyKey: string) => void;
|
|
2
2
|
export declare function VirtualProperty(propertyName: string): (target: any, methodName: string, descriptor: PropertyDescriptor) => void;
|
|
3
|
-
|
|
3
|
+
type DbColumnConfig = {
|
|
4
|
+
mapping?: string | Record<string, string>;
|
|
5
|
+
serialize?: (value: any) => any | Promise<any>;
|
|
6
|
+
};
|
|
7
|
+
export declare function DbColumn(config: string | Record<string, string> | DbColumnConfig): (target: Object, propertyKey: string) => void;
|
|
8
|
+
export {};
|
|
@@ -15,15 +15,27 @@ export function VirtualProperty(propertyName) {
|
|
|
15
15
|
ctor._exposedProperties.set(propertyName, methodName);
|
|
16
16
|
};
|
|
17
17
|
}
|
|
18
|
-
export function DbColumn(
|
|
18
|
+
export function DbColumn(config) {
|
|
19
19
|
return function (target, propertyKey) {
|
|
20
20
|
const ctor = target.constructor;
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
let actualMapping;
|
|
22
|
+
let serialize;
|
|
23
|
+
if (typeof config === 'string') {
|
|
24
|
+
actualMapping = config;
|
|
25
|
+
}
|
|
26
|
+
else if (typeof config === 'object') {
|
|
27
|
+
if ('serialize' in config || 'mapping' in config) {
|
|
28
|
+
actualMapping = config.mapping ?? propertyKey;
|
|
29
|
+
// @ts-ignore
|
|
30
|
+
serialize = config.serialize;
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
// @ts-ignore
|
|
34
|
+
actualMapping = config;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
throw new Error('Configuração inválida para @DbColumn');
|
|
23
39
|
}
|
|
24
|
-
ctor._dbColumns.add({
|
|
25
|
-
property: propertyKey,
|
|
26
|
-
mapping: mapping
|
|
27
|
-
});
|
|
28
40
|
};
|
|
29
41
|
}
|