@powfix/core-js 0.13.27 → 0.13.29
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,38 +1,23 @@
|
|
|
1
1
|
import { ModelAttributeColumnOptions, WhereOptions } from "sequelize";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
}
|
|
5
|
-
type GetIncludeKeyPatterns<Model> = Model extends {
|
|
2
|
+
type Model = Record<string, any> | undefined;
|
|
3
|
+
type GetIncludeKeyPatterns<T extends Model> = T extends {
|
|
6
4
|
_id: string;
|
|
7
5
|
} ? `${string}Uuid` | 'uuid' : `${string}Uuid`;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
[Property in keyof Model]: Property extends GetIncludeKeyPatterns<Model> ? never : Model[Property] extends string | null ? Property : never;
|
|
19
|
-
}[keyof Model];
|
|
20
|
-
/**
|
|
21
|
-
* Extracts all UUID-related keys from a `Model`, including those within related objects.
|
|
22
|
-
* It first ensures all properties of the `Model` are required, then it flattens the UUID keys of related objects
|
|
23
|
-
* using `InjectRelationKeys` and finally extracts the keys ending with "Uuid" using `ExtractKeys`.
|
|
24
|
-
* It also includes any keys provided in the optional `AdditionalKeys` type.
|
|
25
|
-
* @template Model The main model type.
|
|
26
|
-
*/
|
|
27
|
-
export type UuidKeys<Model> = ExtractUuidKeys<Model>;
|
|
6
|
+
type ExtractUuidKeys<T extends Model> = {
|
|
7
|
+
[Property in keyof T]: Property extends GetIncludeKeyPatterns<T> ? Property : never;
|
|
8
|
+
}[keyof T];
|
|
9
|
+
type ConcreteUuidKeys<T extends Record<string, any>> = ExtractUuidKeys<T>;
|
|
10
|
+
interface UuidColumnOptionsBase extends Omit<ModelAttributeColumnOptions, 'type'> {
|
|
11
|
+
columnName: string;
|
|
12
|
+
}
|
|
13
|
+
interface UuidColumnOptionsForModel<T extends Record<string, any>> extends Omit<ModelAttributeColumnOptions, 'type'> {
|
|
14
|
+
columnName: ConcreteUuidKeys<T>;
|
|
15
|
+
}
|
|
28
16
|
export declare class SequelizeUtils {
|
|
29
17
|
static decimal2Number(value: any): number | null | undefined;
|
|
30
18
|
static getPrimaryUuidColumn: () => Partial<ModelAttributeColumnOptions>;
|
|
31
|
-
static
|
|
32
|
-
|
|
33
|
-
allowNull: boolean;
|
|
34
|
-
}) => Partial<ModelAttributeColumnOptions>;
|
|
35
|
-
static getUuidColumn: <Model = undefined>({ columnName, ...overrideOptions }: UuidColumnOptions<Model>) => Partial<ModelAttributeColumnOptions>;
|
|
19
|
+
static getUuidColumn<T extends Record<string, any>>(options: UuidColumnOptionsForModel<T>): Partial<ModelAttributeColumnOptions>;
|
|
20
|
+
static getUuidColumn(options: UuidColumnOptionsBase): Partial<ModelAttributeColumnOptions>;
|
|
36
21
|
static getNullableArrayFilter<T = undefined>(arr: (null | any)[]): WhereOptions<T>;
|
|
37
22
|
}
|
|
38
23
|
export {};
|
|
@@ -26,6 +26,29 @@ class SequelizeUtils {
|
|
|
26
26
|
}
|
|
27
27
|
return parsed;
|
|
28
28
|
}
|
|
29
|
+
static getUuidColumn(options) {
|
|
30
|
+
const { columnName } = options, overrideOptions = __rest(options, ["columnName"]);
|
|
31
|
+
if (overrideOptions.allowNull) {
|
|
32
|
+
return Object.assign({ type: "binary(16)", get() {
|
|
33
|
+
const value = this.getDataValue(columnName);
|
|
34
|
+
if (value === null) {
|
|
35
|
+
return value;
|
|
36
|
+
}
|
|
37
|
+
return UuidUtils_1.UuidUtils.toString(this.getDataValue(columnName));
|
|
38
|
+
},
|
|
39
|
+
set(uuid) {
|
|
40
|
+
this.setDataValue(columnName, uuid === null ? null : UuidUtils_1.UuidUtils.toBuffer(uuid));
|
|
41
|
+
} }, overrideOptions);
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
return Object.assign({ type: "binary(16)", get() {
|
|
45
|
+
return UuidUtils_1.UuidUtils.toString(this.getDataValue(columnName));
|
|
46
|
+
},
|
|
47
|
+
set(uuid) {
|
|
48
|
+
this.setDataValue(columnName, UuidUtils_1.UuidUtils.toBuffer(uuid));
|
|
49
|
+
} }, overrideOptions);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
29
52
|
static getNullableArrayFilter(arr) {
|
|
30
53
|
return {
|
|
31
54
|
[sequelize_1.Op.or]: arr.map(value => {
|
|
@@ -56,56 +79,3 @@ SequelizeUtils.getPrimaryUuidColumn = () => ({
|
|
|
56
79
|
this.setDataValue("uuid", UuidUtils_1.UuidUtils.toBuffer(uuid));
|
|
57
80
|
}
|
|
58
81
|
});
|
|
59
|
-
SequelizeUtils.getForeignUuidColumn = ({ columnName, allowNull }) => {
|
|
60
|
-
if (allowNull) {
|
|
61
|
-
return {
|
|
62
|
-
type: "binary(16)",
|
|
63
|
-
allowNull,
|
|
64
|
-
get() {
|
|
65
|
-
const value = this.getDataValue(columnName);
|
|
66
|
-
if (value === null) {
|
|
67
|
-
return value;
|
|
68
|
-
}
|
|
69
|
-
return UuidUtils_1.UuidUtils.toString(this.getDataValue(columnName));
|
|
70
|
-
},
|
|
71
|
-
set(uuid) {
|
|
72
|
-
this.setDataValue(columnName, uuid === null ? null : UuidUtils_1.UuidUtils.toBuffer(uuid));
|
|
73
|
-
}
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
else {
|
|
77
|
-
return {
|
|
78
|
-
type: "binary(16)",
|
|
79
|
-
allowNull,
|
|
80
|
-
get() {
|
|
81
|
-
return UuidUtils_1.UuidUtils.toString(this.getDataValue(columnName));
|
|
82
|
-
},
|
|
83
|
-
set(uuid) {
|
|
84
|
-
this.setDataValue(columnName, UuidUtils_1.UuidUtils.toBuffer(uuid));
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
SequelizeUtils.getUuidColumn = (_a) => {
|
|
90
|
-
var { columnName } = _a, overrideOptions = __rest(_a, ["columnName"]);
|
|
91
|
-
if (overrideOptions.allowNull) {
|
|
92
|
-
return Object.assign({ type: "binary(16)", get() {
|
|
93
|
-
const value = this.getDataValue(columnName);
|
|
94
|
-
if (value === null) {
|
|
95
|
-
return value;
|
|
96
|
-
}
|
|
97
|
-
return UuidUtils_1.UuidUtils.toString(this.getDataValue(columnName));
|
|
98
|
-
},
|
|
99
|
-
set(uuid) {
|
|
100
|
-
this.setDataValue(columnName, uuid === null ? null : UuidUtils_1.UuidUtils.toBuffer(uuid));
|
|
101
|
-
} }, overrideOptions);
|
|
102
|
-
}
|
|
103
|
-
else {
|
|
104
|
-
return Object.assign({ type: "binary(16)", get() {
|
|
105
|
-
return UuidUtils_1.UuidUtils.toString(this.getDataValue(columnName));
|
|
106
|
-
},
|
|
107
|
-
set(uuid) {
|
|
108
|
-
this.setDataValue(columnName, UuidUtils_1.UuidUtils.toBuffer(uuid));
|
|
109
|
-
} }, overrideOptions);
|
|
110
|
-
}
|
|
111
|
-
};
|