@tstdl/base 0.92.82 → 0.92.83
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.
- package/orm/decorators.d.ts +1 -1
- package/orm/decorators.js +19 -10
- package/package.json +1 -1
package/orm/decorators.d.ts
CHANGED
|
@@ -18,7 +18,7 @@ export type OrmTableReflectionData = {
|
|
|
18
18
|
export type OrmColumnReflectionData = {
|
|
19
19
|
name?: string;
|
|
20
20
|
primaryKey?: boolean;
|
|
21
|
-
unique?: UniqueReflectionData
|
|
21
|
+
unique?: TypedOmit<UniqueReflectionData, 'columns'>;
|
|
22
22
|
index?: IndexReflectionData;
|
|
23
23
|
uuid?: {
|
|
24
24
|
defaultRandom?: boolean;
|
package/orm/decorators.js
CHANGED
|
@@ -1,8 +1,23 @@
|
|
|
1
1
|
import { createClassDecorator, createDecorator, createPropertyDecorator } from '../reflection/index.js';
|
|
2
2
|
import { Property } from '../schema/index.js';
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
import { objectEntries } from '../utils/object/object.js';
|
|
4
|
+
import { assertNotArrayPass, isArray, isString, isUndefined } from '../utils/type-guards.js';
|
|
5
|
+
export function createTableDecorator(data = {}) {
|
|
6
|
+
return createClassDecorator({
|
|
7
|
+
handler: (_, metadata) => {
|
|
8
|
+
const reflectionData = metadata.data.tryGet('orm') ?? {};
|
|
9
|
+
const dataEntries = objectEntries(data);
|
|
10
|
+
for (const [key, value] of dataEntries) {
|
|
11
|
+
const existingValue = reflectionData[key];
|
|
12
|
+
if (isUndefined(existingValue)) {
|
|
13
|
+
reflectionData[key] = value;
|
|
14
|
+
}
|
|
15
|
+
else if (isArray(existingValue)) {
|
|
16
|
+
reflectionData[key] = [...existingValue, ...value];
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
});
|
|
6
21
|
}
|
|
7
22
|
export function createColumnDecorator(data) {
|
|
8
23
|
return createPropertyDecorator({ data: { orm: data }, mergeData: true });
|
|
@@ -20,13 +35,7 @@ export function References(type) {
|
|
|
20
35
|
return createColumnDecorator({ references: type });
|
|
21
36
|
}
|
|
22
37
|
export function Check(name, builder) {
|
|
23
|
-
return
|
|
24
|
-
handler: (_, metadata) => {
|
|
25
|
-
const checks = metadata.data.tryGet('orm')?.checks ?? [];
|
|
26
|
-
checks.push({ name, builder });
|
|
27
|
-
metadata.data.set('orm', { checks }, true);
|
|
28
|
-
}
|
|
29
|
-
});
|
|
38
|
+
return createTableDecorator({ checks: [{ name, builder }] });
|
|
30
39
|
}
|
|
31
40
|
export function Encrypted() {
|
|
32
41
|
return createColumnDecorator({ encrypted: true });
|