@powfix/core-js 0.13.36 → 0.13.38
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/dist/src/utils/global/flat.d.ts +14 -0
- package/dist/src/utils/global/flat.js +117 -0
- package/dist/src/utils/global/index.d.ts +1 -0
- package/dist/src/utils/global/index.js +1 -0
- package/dist/src/utils/nodejs/SequelizeUtils.d.ts +23 -0
- package/dist/src/utils/nodejs/{sequelize-utils/SequelizeUtils.js → SequelizeUtils.js} +12 -6
- package/dist/src/utils/nodejs/index.d.ts +1 -1
- package/dist/src/utils/nodejs/index.js +1 -3
- package/package.json +2 -3
- package/dist/src/utils/nodejs/sequelize-utils/SequelizeUtils.d.ts +0 -9
- package/dist/src/utils/nodejs/sequelize-utils/index.d.ts +0 -1
- package/dist/src/utils/nodejs/sequelize-utils/index.js +0 -5
- package/dist/src/utils/nodejs/sequelize-utils/types.d.ts +0 -16
- package/dist/src/utils/nodejs/sequelize-utils/types.js +0 -2
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface FlattenOptions {
|
|
2
|
+
delimiter?: string;
|
|
3
|
+
maxDepth?: number;
|
|
4
|
+
safe?: boolean;
|
|
5
|
+
transformKey?: (key: string) => string;
|
|
6
|
+
}
|
|
7
|
+
export interface UnflattenOptions {
|
|
8
|
+
delimiter?: string;
|
|
9
|
+
object?: boolean;
|
|
10
|
+
overwrite?: boolean;
|
|
11
|
+
transformKey?: (key: string) => string;
|
|
12
|
+
}
|
|
13
|
+
export declare function flatten<T extends object>(target: T, opts?: FlattenOptions): Record<string, any>;
|
|
14
|
+
export declare function unflatten<T extends object>(target: T, opts?: UnflattenOptions): any;
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// flat.ts
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.flatten = flatten;
|
|
5
|
+
exports.unflatten = unflatten;
|
|
6
|
+
function isBuffer(obj) {
|
|
7
|
+
return !!(obj &&
|
|
8
|
+
obj.constructor &&
|
|
9
|
+
typeof obj.constructor.isBuffer === 'function' &&
|
|
10
|
+
obj.constructor.isBuffer(obj));
|
|
11
|
+
}
|
|
12
|
+
function keyIdentity(key) {
|
|
13
|
+
return key;
|
|
14
|
+
}
|
|
15
|
+
function flatten(target, opts = {}) {
|
|
16
|
+
const delimiter = opts.delimiter || '.';
|
|
17
|
+
const maxDepth = opts.maxDepth;
|
|
18
|
+
const transformKey = opts.transformKey || keyIdentity;
|
|
19
|
+
const output = {};
|
|
20
|
+
function step(object, prev, currentDepth = 1) {
|
|
21
|
+
Object.keys(object).forEach((key) => {
|
|
22
|
+
const value = object[key];
|
|
23
|
+
const isarray = opts.safe && Array.isArray(value);
|
|
24
|
+
const type = Object.prototype.toString.call(value);
|
|
25
|
+
const isbuffer = isBuffer(value);
|
|
26
|
+
const isobject = type === '[object Object]' || type === '[object Array]';
|
|
27
|
+
const newKey = prev
|
|
28
|
+
? `${prev}${delimiter}${transformKey(key)}`
|
|
29
|
+
: transformKey(key);
|
|
30
|
+
if (!isarray &&
|
|
31
|
+
!isbuffer &&
|
|
32
|
+
isobject &&
|
|
33
|
+
Object.keys(value).length &&
|
|
34
|
+
(!maxDepth || currentDepth < maxDepth)) {
|
|
35
|
+
return step(value, newKey, currentDepth + 1);
|
|
36
|
+
}
|
|
37
|
+
output[newKey] = value;
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
step(target);
|
|
41
|
+
return output;
|
|
42
|
+
}
|
|
43
|
+
function unflatten(target, opts = {}) {
|
|
44
|
+
const delimiter = opts.delimiter || '.';
|
|
45
|
+
const overwrite = opts.overwrite || false;
|
|
46
|
+
const transformKey = opts.transformKey || keyIdentity;
|
|
47
|
+
const result = {};
|
|
48
|
+
if (isBuffer(target) ||
|
|
49
|
+
Object.prototype.toString.call(target) !== '[object Object]') {
|
|
50
|
+
return target;
|
|
51
|
+
}
|
|
52
|
+
function getkey(key) {
|
|
53
|
+
const parsedKey = Number(key);
|
|
54
|
+
return isNaN(parsedKey) || key.indexOf('.') !== -1 || opts.object
|
|
55
|
+
? key
|
|
56
|
+
: parsedKey;
|
|
57
|
+
}
|
|
58
|
+
function addKeys(keyPrefix, recipient, target) {
|
|
59
|
+
return Object.keys(target).reduce((res, key) => {
|
|
60
|
+
res[`${keyPrefix}${delimiter}${key}`] = target[key];
|
|
61
|
+
return res;
|
|
62
|
+
}, recipient);
|
|
63
|
+
}
|
|
64
|
+
function isEmpty(val) {
|
|
65
|
+
const type = Object.prototype.toString.call(val);
|
|
66
|
+
const isArray = type === '[object Array]';
|
|
67
|
+
const isObject = type === '[object Object]';
|
|
68
|
+
if (!val) {
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
else if (isArray) {
|
|
72
|
+
return !val.length;
|
|
73
|
+
}
|
|
74
|
+
else if (isObject) {
|
|
75
|
+
return !Object.keys(val).length;
|
|
76
|
+
}
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
const target2 = Object.keys(target).reduce((res, key) => {
|
|
80
|
+
const value = target[key];
|
|
81
|
+
const type = Object.prototype.toString.call(value);
|
|
82
|
+
const isObject = type === '[object Object]' || type === '[object Array]';
|
|
83
|
+
if (!isObject || isEmpty(value)) {
|
|
84
|
+
res[key] = value;
|
|
85
|
+
return res;
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
return addKeys(key, res, flatten(value, opts));
|
|
89
|
+
}
|
|
90
|
+
}, {});
|
|
91
|
+
Object.keys(target2).forEach((key) => {
|
|
92
|
+
const split = key.split(delimiter).map(transformKey);
|
|
93
|
+
let key1 = getkey(split.shift());
|
|
94
|
+
let key2 = getkey(split[0]);
|
|
95
|
+
let recipient = result;
|
|
96
|
+
while (key2 !== undefined) {
|
|
97
|
+
if (key1 === '__proto__')
|
|
98
|
+
return;
|
|
99
|
+
const type = Object.prototype.toString.call(recipient[key1]);
|
|
100
|
+
const isobject = type === '[object Object]' || type === '[object Array]';
|
|
101
|
+
if (!overwrite && !isobject && typeof recipient[key1] !== 'undefined') {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
if ((overwrite && !isobject) || (!overwrite && recipient[key1] == null)) {
|
|
105
|
+
recipient[key1] =
|
|
106
|
+
typeof key2 === 'number' && !opts.object ? [] : {};
|
|
107
|
+
}
|
|
108
|
+
recipient = recipient[key1];
|
|
109
|
+
if (split.length > 0) {
|
|
110
|
+
key1 = getkey(split.shift());
|
|
111
|
+
key2 = getkey(split[0]);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
recipient[key1] = unflatten(target2[key], opts);
|
|
115
|
+
});
|
|
116
|
+
return result;
|
|
117
|
+
}
|
|
@@ -22,5 +22,6 @@ __exportStar(require("./fallbackIfEqual"), exports);
|
|
|
22
22
|
__exportStar(require("./fallbackIfNull"), exports);
|
|
23
23
|
__exportStar(require("./fallbackIfUndefined"), exports);
|
|
24
24
|
__exportStar(require("./firstNonNullish"), exports);
|
|
25
|
+
__exportStar(require("./flat"), exports);
|
|
25
26
|
__exportStar(require("./processFirstNonNullish"), exports);
|
|
26
27
|
__exportStar(require("./pureEnum"), exports);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ModelAttributeColumnOptions, WhereOptions } from "sequelize";
|
|
2
|
+
type Model = Record<string, any> | undefined;
|
|
3
|
+
type GetIncludeKeyPatterns<T extends Model> = T extends {
|
|
4
|
+
_id: string;
|
|
5
|
+
} ? `${string}Uuid` | 'uuid' : `${string}Uuid`;
|
|
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
|
+
}
|
|
16
|
+
export declare class SequelizeUtils {
|
|
17
|
+
static decimal2Number(value: any): number | null | undefined;
|
|
18
|
+
static getPrimaryUuidColumn: () => Partial<ModelAttributeColumnOptions>;
|
|
19
|
+
static getUuidColumn<T extends Record<string, any>>(options: UuidColumnOptionsForModel<T>): Partial<ModelAttributeColumnOptions>;
|
|
20
|
+
static getUuidColumn(options: UuidColumnOptionsBase): Partial<ModelAttributeColumnOptions>;
|
|
21
|
+
static getNullableArrayFilter<T = undefined>(arr: (null | any)[]): WhereOptions<T>;
|
|
22
|
+
}
|
|
23
|
+
export {};
|
|
@@ -13,8 +13,8 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
13
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
14
|
exports.SequelizeUtils = void 0;
|
|
15
15
|
const sequelize_1 = require("sequelize");
|
|
16
|
-
const UuidUtils_1 = require("
|
|
17
|
-
const constants_1 = require("
|
|
16
|
+
const UuidUtils_1 = require("../UuidUtils");
|
|
17
|
+
const constants_1 = require("../../constants");
|
|
18
18
|
class SequelizeUtils {
|
|
19
19
|
static decimal2Number(value) {
|
|
20
20
|
if (value === null || value === undefined) {
|
|
@@ -26,7 +26,7 @@ class SequelizeUtils {
|
|
|
26
26
|
}
|
|
27
27
|
return parsed;
|
|
28
28
|
}
|
|
29
|
-
static
|
|
29
|
+
static getUuidColumn(options) {
|
|
30
30
|
const { columnName } = options, overrideOptions = __rest(options, ["columnName"]);
|
|
31
31
|
if (overrideOptions.allowNull) {
|
|
32
32
|
return Object.assign({ type: "binary(16)", get() {
|
|
@@ -66,10 +66,16 @@ class SequelizeUtils {
|
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
68
|
exports.SequelizeUtils = SequelizeUtils;
|
|
69
|
-
SequelizeUtils.
|
|
70
|
-
|
|
69
|
+
SequelizeUtils.getPrimaryUuidColumn = () => ({
|
|
70
|
+
type: "binary(16)",
|
|
71
71
|
allowNull: false,
|
|
72
72
|
primaryKey: true,
|
|
73
73
|
unique: true,
|
|
74
74
|
defaultValue: () => UuidUtils_1.UuidUtils.toBuffer(UuidUtils_1.UuidUtils.v4()),
|
|
75
|
-
|
|
75
|
+
get() {
|
|
76
|
+
return UuidUtils_1.UuidUtils.toString(this.getDataValue("uuid"));
|
|
77
|
+
},
|
|
78
|
+
set(uuid) {
|
|
79
|
+
this.setDataValue("uuid", UuidUtils_1.UuidUtils.toBuffer(uuid));
|
|
80
|
+
}
|
|
81
|
+
});
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export * from './HookUtils';
|
|
2
|
-
export
|
|
2
|
+
export * from './SequelizeUtils';
|
|
@@ -14,7 +14,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.SequelizeUtils = void 0;
|
|
18
17
|
__exportStar(require("./HookUtils"), exports);
|
|
19
|
-
|
|
20
|
-
Object.defineProperty(exports, "SequelizeUtils", { enumerable: true, get: function () { return sequelize_utils_1.SequelizeUtils; } });
|
|
18
|
+
__exportStar(require("./SequelizeUtils"), exports);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@powfix/core-js",
|
|
3
|
-
"version": "0.13.
|
|
3
|
+
"version": "0.13.38",
|
|
4
4
|
"description": "core package",
|
|
5
5
|
"author": "Kwon Kyung-Min <powfix@gmail.com>",
|
|
6
6
|
"private": false,
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"@types/base-64": "1.0.2",
|
|
36
36
|
"@types/node": "20.9.5",
|
|
37
37
|
"@types/uuid": "9.0.7",
|
|
38
|
-
"axios": "^1.
|
|
38
|
+
"axios": "^1.9.0",
|
|
39
39
|
"moment": "^2.30.1",
|
|
40
40
|
"sequelize": "6.37.7",
|
|
41
41
|
"sequelize-typescript": "^2.1.6",
|
|
@@ -43,7 +43,6 @@
|
|
|
43
43
|
"typescript": "5.8.3"
|
|
44
44
|
},
|
|
45
45
|
"peerDependencies": {
|
|
46
|
-
"axios": ">=1.7.0",
|
|
47
46
|
"moment": ">=2.0.0"
|
|
48
47
|
}
|
|
49
48
|
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { ModelAttributeColumnOptions, WhereOptions } from "sequelize";
|
|
2
|
-
import { Model, NonKnownUuidStringKeys, UuidColumnOptionsBase, UuidColumnOptionsForModel } from "./types";
|
|
3
|
-
export declare class SequelizeUtils {
|
|
4
|
-
static decimal2Number(value: any): number | null | undefined;
|
|
5
|
-
static buildPrimaryUuidColumn: () => Partial<ModelAttributeColumnOptions>;
|
|
6
|
-
static buildUuidColumn<T extends Model, AdditionalKeys extends NonKnownUuidStringKeys<T> = never>(options: UuidColumnOptionsForModel<T, AdditionalKeys>): Partial<ModelAttributeColumnOptions>;
|
|
7
|
-
static buildUuidColumn(options: UuidColumnOptionsBase): Partial<ModelAttributeColumnOptions>;
|
|
8
|
-
static getNullableArrayFilter<T = undefined>(arr: (null | any)[]): WhereOptions<T>;
|
|
9
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { SequelizeUtils } from './SequelizeUtils';
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SequelizeUtils = void 0;
|
|
4
|
-
var SequelizeUtils_1 = require("./SequelizeUtils");
|
|
5
|
-
Object.defineProperty(exports, "SequelizeUtils", { enumerable: true, get: function () { return SequelizeUtils_1.SequelizeUtils; } });
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { ModelAttributeColumnOptions } from "sequelize";
|
|
2
|
-
export type Model = Record<string, any> | undefined;
|
|
3
|
-
export type ExtractUuidKeys<T extends Model> = {
|
|
4
|
-
[Property in keyof T]: Property extends `${string}Uuid` | 'uuid' ? Property : never;
|
|
5
|
-
}[keyof T];
|
|
6
|
-
export type ExtractStringKeys<T extends Model> = {
|
|
7
|
-
[Property in keyof T]: string extends T[Property] ? Property : never;
|
|
8
|
-
}[keyof T];
|
|
9
|
-
export type ConcreteUuidKeys<T extends Model> = ExtractUuidKeys<T>;
|
|
10
|
-
export type NonKnownUuidStringKeys<T extends Model> = Exclude<ExtractStringKeys<T>, ConcreteUuidKeys<T>> & string;
|
|
11
|
-
export interface UuidColumnOptionsBase extends Omit<ModelAttributeColumnOptions, 'type'> {
|
|
12
|
-
columnName: string;
|
|
13
|
-
}
|
|
14
|
-
export interface UuidColumnOptionsForModel<T extends Model, AdditionalKeys extends string> extends Omit<ModelAttributeColumnOptions, 'type'> {
|
|
15
|
-
columnName: ConcreteUuidKeys<T> | AdditionalKeys;
|
|
16
|
-
}
|