@powfix/core-js 0.13.26 → 0.13.28

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,19 @@
1
1
  import { ModelAttributeColumnOptions, WhereOptions } from "sequelize";
2
- interface UuidColumnOptions<Model = undefined> extends Omit<ModelAttributeColumnOptions, 'type'> {
3
- columnName: Model extends undefined ? string : UuidKeys<Model>;
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
- * Extracts keys from a type `Model` that end with "Uuid".
10
- * It also includes any keys provided in the optional type `CustomKeys`.
11
- * @template Model The type to extract keys from.
12
- * @template CustomKeys An optional type representing additional keys to include. Defaults to `never`.
13
- */
14
- type ExtractUuidKeys<Model, CustomKeys = never> = {
15
- [Property in keyof Model]: Property extends GetIncludeKeyPatterns<Model> ? Property : never;
16
- }[keyof Model] | CustomKeys;
17
- type ExtractAdditionalKeys<Model> = {
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 UuidColumnOptionsForModel<T extends Record<string, any>> extends Omit<ModelAttributeColumnOptions, 'type'> {
11
+ columnName: ConcreteUuidKeys<T>;
12
+ }
28
13
  export declare class SequelizeUtils {
29
14
  static decimal2Number(value: any): number | null | undefined;
30
15
  static getPrimaryUuidColumn: () => Partial<ModelAttributeColumnOptions>;
31
- static getForeignUuidColumn: <Model = never, AdditionalKeys extends Exclude<ExtractAdditionalKeys<Model>, UuidKeys<Model>> = never>({ columnName, allowNull }: {
32
- columnName: Model extends undefined ? string : (UuidKeys<Model> | AdditionalKeys);
33
- allowNull: boolean;
34
- }) => Partial<ModelAttributeColumnOptions>;
35
- static getUuidColumn: ({ columnName, ...overrideOptions }: UuidColumnOptions) => Partial<ModelAttributeColumnOptions>;
16
+ static getUuidColumn<T extends Record<string, any>>(options: UuidColumnOptionsForModel<T>): Partial<ModelAttributeColumnOptions>;
36
17
  static getNullableArrayFilter<T = undefined>(arr: (null | any)[]): WhereOptions<T>;
37
18
  }
38
19
  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
- };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@powfix/core-js",
3
- "version": "0.13.26",
3
+ "version": "0.13.28",
4
4
  "description": "core package",
5
5
  "author": "Kwon Kyung-Min <powfix@gmail.com>",
6
6
  "private": false,