@tsed/core 8.11.0 → 8.11.2-rc.1
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/lib/esm/decorators/storeFn.js +0 -1
- package/lib/esm/decorators/storeMerge.js +0 -1
- package/lib/esm/decorators/storeSet.js +0 -1
- package/lib/esm/errors/UnsupportedDecoratorType.js +0 -1
- package/lib/esm/index.js +0 -1
- package/lib/esm/types/AnyDecorator.js +0 -1
- package/lib/esm/types/DecoratorParameters.js +0 -1
- package/lib/esm/types/DecoratorTypes.js +0 -1
- package/lib/esm/types/Env.js +0 -1
- package/lib/esm/types/Metadata.js +0 -1
- package/lib/esm/types/MetadataTypes.js +0 -1
- package/lib/esm/types/Relation.js +0 -1
- package/lib/esm/types/Store.js +0 -1
- package/lib/esm/types/Type.js +0 -1
- package/lib/esm/types/ValueOf.js +0 -1
- package/lib/esm/utils/AnyToPromise.js +0 -1
- package/lib/esm/utils/ancestorOf.js +0 -1
- package/lib/esm/utils/ancestorsOf.js +0 -1
- package/lib/esm/utils/catchError.js +0 -1
- package/lib/esm/utils/classOf.js +0 -1
- package/lib/esm/utils/cleanObject.js +0 -1
- package/lib/esm/utils/constructorOf.js +0 -1
- package/lib/esm/utils/createInstance.js +0 -1
- package/lib/esm/utils/decorateMethodsOf.js +0 -1
- package/lib/esm/utils/decoratorArgs.js +0 -1
- package/lib/esm/utils/decoratorTypeOf.js +0 -1
- package/lib/esm/utils/deepClone.js +0 -1
- package/lib/esm/utils/deepMerge.js +0 -1
- package/lib/esm/utils/descriptorOf.js +0 -1
- package/lib/esm/utils/getClassOrSymbol.js +0 -1
- package/lib/esm/utils/getConstructorArgNames.js +0 -1
- package/lib/esm/utils/getRandomId.js +0 -1
- package/lib/esm/utils/getValue.js +0 -1
- package/lib/esm/utils/hasJsonMethod.js +0 -1
- package/lib/esm/utils/http/getHostInfoFromPort.js +0 -1
- package/lib/esm/utils/inheritedDescriptorOf.js +0 -1
- package/lib/esm/utils/isArray.js +0 -1
- package/lib/esm/utils/isArrowFn.js +0 -1
- package/lib/esm/utils/isBoolean.js +0 -1
- package/lib/esm/utils/isBuffer.js +0 -1
- package/lib/esm/utils/isClass.js +0 -1
- package/lib/esm/utils/isCollection.js +0 -1
- package/lib/esm/utils/isDate.js +0 -1
- package/lib/esm/utils/isEmpty.js +0 -1
- package/lib/esm/utils/isEnumerable.js +0 -1
- package/lib/esm/utils/isFunction.js +0 -1
- package/lib/esm/utils/isInheritedFrom.js +0 -1
- package/lib/esm/utils/isMomentObject.js +0 -1
- package/lib/esm/utils/isMongooseObject.js +0 -1
- package/lib/esm/utils/isNil.js +0 -1
- package/lib/esm/utils/isNumber.js +0 -1
- package/lib/esm/utils/isObject.js +0 -1
- package/lib/esm/utils/isObservable.js +0 -1
- package/lib/esm/utils/isPlainObject.js +0 -1
- package/lib/esm/utils/isPrimitive.js +0 -1
- package/lib/esm/utils/isPromise.js +0 -1
- package/lib/esm/utils/isProtectedKey.js +0 -1
- package/lib/esm/utils/isRegExp.js +0 -1
- package/lib/esm/utils/isSerializable.js +0 -1
- package/lib/esm/utils/isStream.js +0 -1
- package/lib/esm/utils/isString.js +0 -1
- package/lib/esm/utils/isSymbol.js +0 -1
- package/lib/esm/utils/methodsOf.js +0 -1
- package/lib/esm/utils/nameOf.js +0 -1
- package/lib/esm/utils/objectKeys.js +0 -1
- package/lib/esm/utils/primitiveOf.js +0 -1
- package/lib/esm/utils/prototypeOf.js +0 -1
- package/lib/esm/utils/setValue.js +0 -1
- package/lib/esm/utils/toMap.js +0 -1
- package/lib/esm/utils/toStringConstructor.js +0 -1
- package/lib/esm/utils/uniq.js +0 -1
- package/lib/esm/utils/useDecorators.js +0 -1
- package/lib/esm/utils/useMethodDecorators.js +0 -1
- package/package.json +8 -5
- package/.barrelsby.json +0 -5
- package/lib/esm/decorators/storeFn.js.map +0 -1
- package/lib/esm/decorators/storeMerge.js.map +0 -1
- package/lib/esm/decorators/storeSet.js.map +0 -1
- package/lib/esm/errors/UnsupportedDecoratorType.js.map +0 -1
- package/lib/esm/index.js.map +0 -1
- package/lib/esm/types/AnyDecorator.js.map +0 -1
- package/lib/esm/types/DecoratorParameters.js.map +0 -1
- package/lib/esm/types/DecoratorTypes.js.map +0 -1
- package/lib/esm/types/Env.js.map +0 -1
- package/lib/esm/types/Metadata.js.map +0 -1
- package/lib/esm/types/MetadataTypes.js.map +0 -1
- package/lib/esm/types/Relation.js.map +0 -1
- package/lib/esm/types/Store.js.map +0 -1
- package/lib/esm/types/Type.js.map +0 -1
- package/lib/esm/types/ValueOf.js.map +0 -1
- package/lib/esm/utils/AnyToPromise.js.map +0 -1
- package/lib/esm/utils/ancestorOf.js.map +0 -1
- package/lib/esm/utils/ancestorsOf.js.map +0 -1
- package/lib/esm/utils/catchError.js.map +0 -1
- package/lib/esm/utils/classOf.js.map +0 -1
- package/lib/esm/utils/cleanObject.js.map +0 -1
- package/lib/esm/utils/constructorOf.js.map +0 -1
- package/lib/esm/utils/createInstance.js.map +0 -1
- package/lib/esm/utils/decorateMethodsOf.js.map +0 -1
- package/lib/esm/utils/decoratorArgs.js.map +0 -1
- package/lib/esm/utils/decoratorTypeOf.js.map +0 -1
- package/lib/esm/utils/deepClone.js.map +0 -1
- package/lib/esm/utils/deepMerge.js.map +0 -1
- package/lib/esm/utils/descriptorOf.js.map +0 -1
- package/lib/esm/utils/getClassOrSymbol.js.map +0 -1
- package/lib/esm/utils/getConstructorArgNames.js.map +0 -1
- package/lib/esm/utils/getRandomId.js.map +0 -1
- package/lib/esm/utils/getValue.js.map +0 -1
- package/lib/esm/utils/hasJsonMethod.js.map +0 -1
- package/lib/esm/utils/http/getHostInfoFromPort.js.map +0 -1
- package/lib/esm/utils/inheritedDescriptorOf.js.map +0 -1
- package/lib/esm/utils/isArray.js.map +0 -1
- package/lib/esm/utils/isArrowFn.js.map +0 -1
- package/lib/esm/utils/isBoolean.js.map +0 -1
- package/lib/esm/utils/isBuffer.js.map +0 -1
- package/lib/esm/utils/isClass.js.map +0 -1
- package/lib/esm/utils/isCollection.js.map +0 -1
- package/lib/esm/utils/isDate.js.map +0 -1
- package/lib/esm/utils/isEmpty.js.map +0 -1
- package/lib/esm/utils/isEnumerable.js.map +0 -1
- package/lib/esm/utils/isFunction.js.map +0 -1
- package/lib/esm/utils/isInheritedFrom.js.map +0 -1
- package/lib/esm/utils/isMomentObject.js.map +0 -1
- package/lib/esm/utils/isMongooseObject.js.map +0 -1
- package/lib/esm/utils/isNil.js.map +0 -1
- package/lib/esm/utils/isNumber.js.map +0 -1
- package/lib/esm/utils/isObject.js.map +0 -1
- package/lib/esm/utils/isObservable.js.map +0 -1
- package/lib/esm/utils/isPlainObject.js.map +0 -1
- package/lib/esm/utils/isPrimitive.js.map +0 -1
- package/lib/esm/utils/isPromise.js.map +0 -1
- package/lib/esm/utils/isProtectedKey.js.map +0 -1
- package/lib/esm/utils/isRegExp.js.map +0 -1
- package/lib/esm/utils/isSerializable.js.map +0 -1
- package/lib/esm/utils/isStream.js.map +0 -1
- package/lib/esm/utils/isString.js.map +0 -1
- package/lib/esm/utils/isSymbol.js.map +0 -1
- package/lib/esm/utils/methodsOf.js.map +0 -1
- package/lib/esm/utils/nameOf.js.map +0 -1
- package/lib/esm/utils/objectKeys.js.map +0 -1
- package/lib/esm/utils/primitiveOf.js.map +0 -1
- package/lib/esm/utils/prototypeOf.js.map +0 -1
- package/lib/esm/utils/setValue.js.map +0 -1
- package/lib/esm/utils/toMap.js.map +0 -1
- package/lib/esm/utils/toStringConstructor.js.map +0 -1
- package/lib/esm/utils/uniq.js.map +0 -1
- package/lib/esm/utils/useDecorators.js.map +0 -1
- package/lib/esm/utils/useMethodDecorators.js.map +0 -1
- package/src/decorators/storeFn.ts +0 -20
- package/src/decorators/storeMerge.ts +0 -8
- package/src/decorators/storeSet.ts +0 -8
- package/src/errors/UnsupportedDecoratorType.spec.ts +0 -81
- package/src/errors/UnsupportedDecoratorType.ts +0 -25
- package/src/index.ts +0 -75
- package/src/types/AnyDecorator.ts +0 -1
- package/src/types/DecoratorParameters.ts +0 -8
- package/src/types/DecoratorTypes.ts +0 -10
- package/src/types/Env.ts +0 -15
- package/src/types/Metadata.spec.ts +0 -142
- package/src/types/Metadata.ts +0 -523
- package/src/types/MetadataTypes.ts +0 -6
- package/src/types/Relation.ts +0 -1
- package/src/types/Store.spec.ts +0 -164
- package/src/types/Store.ts +0 -175
- package/src/types/Type.ts +0 -20
- package/src/types/ValueOf.ts +0 -1
- package/src/utils/AnyToPromise.spec.ts +0 -159
- package/src/utils/AnyToPromise.ts +0 -181
- package/src/utils/ObjectUtils.spec.ts +0 -322
- package/src/utils/ancestorOf.ts +0 -7
- package/src/utils/ancestorsOf.ts +0 -21
- package/src/utils/catchError.spec.ts +0 -17
- package/src/utils/catchError.ts +0 -15
- package/src/utils/classOf.ts +0 -18
- package/src/utils/cleanObject.spec.ts +0 -22
- package/src/utils/cleanObject.ts +0 -20
- package/src/utils/constructorOf.ts +0 -17
- package/src/utils/createInstance.ts +0 -5
- package/src/utils/decorateMethodsOf.spec.ts +0 -83
- package/src/utils/decorateMethodsOf.ts +0 -31
- package/src/utils/decoratorArgs.spec.ts +0 -15
- package/src/utils/decoratorArgs.ts +0 -6
- package/src/utils/decoratorTypeOf.spec.ts +0 -92
- package/src/utils/decoratorTypeOf.ts +0 -24
- package/src/utils/deepClone.spec.ts +0 -130
- package/src/utils/deepClone.ts +0 -85
- package/src/utils/deepMerge.spec.ts +0 -223
- package/src/utils/deepMerge.ts +0 -85
- package/src/utils/descriptorOf.spec.ts +0 -16
- package/src/utils/descriptorOf.ts +0 -13
- package/src/utils/getClassOrSymbol.ts +0 -6
- package/src/utils/getConstructorArgNames.spec.ts +0 -11
- package/src/utils/getConstructorArgNames.ts +0 -10
- package/src/utils/getRandomId.spec.ts +0 -7
- package/src/utils/getRandomId.ts +0 -3
- package/src/utils/getValue.spec.ts +0 -62
- package/src/utils/getValue.ts +0 -87
- package/src/utils/hasJsonMethod.spec.ts +0 -11
- package/src/utils/hasJsonMethod.ts +0 -3
- package/src/utils/http/getHostInfoFromPort.spec.ts +0 -25
- package/src/utils/http/getHostInfoFromPort.ts +0 -20
- package/src/utils/inheritedDescriptorOf.ts +0 -13
- package/src/utils/isArray.ts +0 -18
- package/src/utils/isArrowFn.ts +0 -5
- package/src/utils/isBoolean.ts +0 -12
- package/src/utils/isBuffer.spec.ts +0 -14
- package/src/utils/isBuffer.ts +0 -19
- package/src/utils/isClass.spec.ts +0 -15
- package/src/utils/isClass.ts +0 -28
- package/src/utils/isCollection.ts +0 -20
- package/src/utils/isDate.ts +0 -8
- package/src/utils/isEmpty.spec.ts +0 -10
- package/src/utils/isEmpty.ts +0 -10
- package/src/utils/isEnumerable.ts +0 -21
- package/src/utils/isFunction.ts +0 -3
- package/src/utils/isInheritedFrom.ts +0 -26
- package/src/utils/isMomentObject.spec.ts +0 -16
- package/src/utils/isMomentObject.ts +0 -3
- package/src/utils/isMongooseObject.spec.ts +0 -22
- package/src/utils/isMongooseObject.ts +0 -9
- package/src/utils/isNil.spec.ts +0 -10
- package/src/utils/isNil.ts +0 -3
- package/src/utils/isNumber.ts +0 -12
- package/src/utils/isObject.ts +0 -3
- package/src/utils/isObservable.ts +0 -3
- package/src/utils/isPlainObject.spec.ts +0 -10
- package/src/utils/isPlainObject.ts +0 -14
- package/src/utils/isPrimitive.spec.ts +0 -17
- package/src/utils/isPrimitive.ts +0 -26
- package/src/utils/isPromise.ts +0 -13
- package/src/utils/isProtectedKey.spec.ts +0 -14
- package/src/utils/isProtectedKey.ts +0 -7
- package/src/utils/isRegExp.ts +0 -3
- package/src/utils/isSerializable.spec.ts +0 -14
- package/src/utils/isSerializable.ts +0 -9
- package/src/utils/isStream.ts +0 -3
- package/src/utils/isString.ts +0 -11
- package/src/utils/isSymbol.spec.ts +0 -11
- package/src/utils/isSymbol.ts +0 -11
- package/src/utils/methodsOf.spec.ts +0 -33
- package/src/utils/methodsOf.ts +0 -26
- package/src/utils/nameOf.ts +0 -27
- package/src/utils/objectKeys.spec.ts +0 -10
- package/src/utils/objectKeys.ts +0 -5
- package/src/utils/primitiveOf.ts +0 -19
- package/src/utils/prototypeOf.ts +0 -10
- package/src/utils/setValue.spec.ts +0 -60
- package/src/utils/setValue.ts +0 -35
- package/src/utils/toMap.spec.ts +0 -211
- package/src/utils/toMap.ts +0 -44
- package/src/utils/toStringConstructor.ts +0 -9
- package/src/utils/toStringConstrutor.spec.ts +0 -18
- package/src/utils/uniq.spec.ts +0 -8
- package/src/utils/uniq.ts +0 -16
- package/src/utils/useDecorators.spec.ts +0 -61
- package/src/utils/useDecorators.ts +0 -21
- package/src/utils/useMethodDecorator.spec.ts +0 -45
- package/src/utils/useMethodDecorators.ts +0 -12
- package/vitest.config.mts +0 -21
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import {decoratorTypeOf} from "./decoratorTypeOf.js";
|
|
2
|
-
|
|
3
|
-
class Test {}
|
|
4
|
-
|
|
5
|
-
describe("decoratorTypeOf()", () => {
|
|
6
|
-
it("should return class", () => {
|
|
7
|
-
expect(decoratorTypeOf([Test])).toBe("class");
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
it("should return property (static)", () => {
|
|
11
|
-
expect(decoratorTypeOf([Test, "props"])).toBe("property.static");
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
it("should return property (instance)", () => {
|
|
15
|
-
expect(decoratorTypeOf([Test.prototype, "props"])).toBe("property");
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
it("should return property (instance with descriptor from babel)", () => {
|
|
19
|
-
expect(
|
|
20
|
-
decoratorTypeOf([
|
|
21
|
-
Test.prototype,
|
|
22
|
-
"props",
|
|
23
|
-
{
|
|
24
|
-
configurable: true,
|
|
25
|
-
enumerable: true,
|
|
26
|
-
writable: true,
|
|
27
|
-
initializer: null
|
|
28
|
-
}
|
|
29
|
-
])
|
|
30
|
-
).toBe("property");
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it("should return method (instance, getter)", () => {
|
|
34
|
-
expect(
|
|
35
|
-
decoratorTypeOf([
|
|
36
|
-
Test.prototype,
|
|
37
|
-
"props",
|
|
38
|
-
{
|
|
39
|
-
get: () => {}
|
|
40
|
-
}
|
|
41
|
-
])
|
|
42
|
-
).toBe("property");
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
it("should return method (instance, setter)", () => {
|
|
46
|
-
expect(
|
|
47
|
-
decoratorTypeOf([
|
|
48
|
-
Test.prototype,
|
|
49
|
-
"props",
|
|
50
|
-
{
|
|
51
|
-
set: () => {}
|
|
52
|
-
}
|
|
53
|
-
])
|
|
54
|
-
).toBe("property");
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it("should return method (static)", () => {
|
|
58
|
-
expect(
|
|
59
|
-
decoratorTypeOf([
|
|
60
|
-
Test,
|
|
61
|
-
"props",
|
|
62
|
-
{
|
|
63
|
-
value: () => {}
|
|
64
|
-
}
|
|
65
|
-
])
|
|
66
|
-
).toBe("method.static");
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
it("should return method (instance)", () => {
|
|
70
|
-
expect(
|
|
71
|
-
decoratorTypeOf([
|
|
72
|
-
Test.prototype,
|
|
73
|
-
"props",
|
|
74
|
-
{
|
|
75
|
-
value: () => {}
|
|
76
|
-
}
|
|
77
|
-
])
|
|
78
|
-
).toBe("method");
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
it("should return params (static)", () => {
|
|
82
|
-
expect(decoratorTypeOf([Test, "props", 0])).toBe("parameter.static");
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
it("should return params (instance)", () => {
|
|
86
|
-
expect(decoratorTypeOf([Test.prototype, "props", 0])).toBe("parameter");
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
it("should return params (constructor)", () => {
|
|
90
|
-
expect(decoratorTypeOf([Test.prototype, undefined, 0])).toBe("parameter.constructor");
|
|
91
|
-
});
|
|
92
|
-
});
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import {DecoratorTypes} from "../types/DecoratorTypes.js";
|
|
2
|
-
import {classOf} from "./classOf.js";
|
|
3
|
-
|
|
4
|
-
export function decoratorTypeOf(args: any[]): DecoratorTypes {
|
|
5
|
-
const [target, propertyKey, descriptor] = args;
|
|
6
|
-
|
|
7
|
-
const staticType = (type: string): any => {
|
|
8
|
-
return target !== classOf(target) ? type : `${type}.static`;
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
if (typeof descriptor === "number") {
|
|
12
|
-
return propertyKey ? staticType("parameter") : "parameter.constructor";
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
if (descriptor && descriptor.value) {
|
|
16
|
-
return staticType("method");
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
if ((propertyKey && descriptor === undefined) || descriptor) {
|
|
20
|
-
return staticType("property");
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return DecoratorTypes.CLASS;
|
|
24
|
-
}
|
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
import {deepClone} from "./deepClone.js";
|
|
2
|
-
|
|
3
|
-
describe("deepClone", () => {
|
|
4
|
-
class Base {
|
|
5
|
-
public test2: string;
|
|
6
|
-
|
|
7
|
-
constructor(test: string) {
|
|
8
|
-
this.test2 = test + "2";
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
get test3(): string {
|
|
12
|
-
return this.test2;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
class Test extends Base {
|
|
17
|
-
constructor(private _test: string) {
|
|
18
|
-
super(_test);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
get test(): string {
|
|
22
|
-
return this._test;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
it("should clone object", () => {
|
|
27
|
-
const externalObject = {
|
|
28
|
-
color: "red"
|
|
29
|
-
};
|
|
30
|
-
const symbol = Symbol("test");
|
|
31
|
-
const original = {
|
|
32
|
-
a: new Date(),
|
|
33
|
-
b: NaN,
|
|
34
|
-
c: new Function(),
|
|
35
|
-
d: undefined,
|
|
36
|
-
e: function name() {},
|
|
37
|
-
f: Number,
|
|
38
|
-
g: false,
|
|
39
|
-
h: Infinity,
|
|
40
|
-
i: externalObject,
|
|
41
|
-
j: new Test("test"),
|
|
42
|
-
k: [new Test("test"), false, 1, Test],
|
|
43
|
-
l: new RegExp(/test/i),
|
|
44
|
-
m: null,
|
|
45
|
-
n: symbol
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
const cloned = deepClone(original);
|
|
49
|
-
|
|
50
|
-
expect(cloned).toEqual(original);
|
|
51
|
-
expect(cloned).not.toBe(original);
|
|
52
|
-
|
|
53
|
-
expect(cloned.j).toBeInstanceOf(Test);
|
|
54
|
-
expect(cloned.j.test).toBe("test");
|
|
55
|
-
expect(cloned.j.test2).toBe("test2");
|
|
56
|
-
|
|
57
|
-
expect(cloned.k).toBeInstanceOf(Array);
|
|
58
|
-
expect(cloned.k.length).toBe(4);
|
|
59
|
-
expect(cloned.k[0]).toBeInstanceOf(Test);
|
|
60
|
-
expect(cloned.k[3]).toBe(Test);
|
|
61
|
-
|
|
62
|
-
expect(cloned.l).toBeInstanceOf(RegExp);
|
|
63
|
-
expect(cloned.l.source).toBe("test");
|
|
64
|
-
expect(cloned.l.flags).toBe("i");
|
|
65
|
-
|
|
66
|
-
expect(cloned.m).toBeNull();
|
|
67
|
-
expect(cloned.n).toBe(symbol);
|
|
68
|
-
|
|
69
|
-
expect(deepClone(new Test("test"))).toBeInstanceOf(Test);
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
it("should clone object with circular obj", () => {
|
|
73
|
-
const original = {
|
|
74
|
-
posts: [
|
|
75
|
-
{
|
|
76
|
-
id: 0,
|
|
77
|
-
user: {}
|
|
78
|
-
}
|
|
79
|
-
],
|
|
80
|
-
user: {
|
|
81
|
-
id: 1,
|
|
82
|
-
posts: [] as any[]
|
|
83
|
-
}
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
original.posts[0].user = original.user;
|
|
87
|
-
original.user.posts.push(original.posts[0]);
|
|
88
|
-
|
|
89
|
-
expect(deepClone(original)).toEqual(original);
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
it("should clone a buffer", () => {
|
|
93
|
-
class FakeStorage {
|
|
94
|
-
testBuffer: Buffer;
|
|
95
|
-
|
|
96
|
-
constructor() {
|
|
97
|
-
this.testBuffer = Buffer.from("Hello");
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
get() {
|
|
101
|
-
return this.testBuffer.toString("utf-8");
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
const result = deepClone({storage: new FakeStorage()});
|
|
106
|
-
expect(result.storage.get()).toEqual("Hello");
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
it("should clone Map, Set, and Array", () => {
|
|
110
|
-
class FakeStorage {
|
|
111
|
-
set = new Set([new Test("test")]);
|
|
112
|
-
map = new Map([["test", Test]]);
|
|
113
|
-
array = [new Test("test"), Test, new Map([["test", new Test("test")]])];
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
const expected = {storage: new FakeStorage()};
|
|
117
|
-
const result = deepClone(expected);
|
|
118
|
-
|
|
119
|
-
expect(result).toEqual(expected);
|
|
120
|
-
expect(result).not.toBe(expected);
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
it("should clone typed arrays", () => {
|
|
124
|
-
const original = new Int8Array([1, 2, 3]);
|
|
125
|
-
const result = deepClone(original);
|
|
126
|
-
|
|
127
|
-
expect(result).toEqual(original);
|
|
128
|
-
expect(result).toBeInstanceOf(Int8Array);
|
|
129
|
-
});
|
|
130
|
-
});
|
package/src/utils/deepClone.ts
DELETED
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import {classOf} from "./classOf.js";
|
|
2
|
-
import {isDate} from "./isDate.js";
|
|
3
|
-
import {isFunction} from "./isFunction.js";
|
|
4
|
-
import {isNil} from "./isNil.js";
|
|
5
|
-
import {isPrimitive} from "./isPrimitive.js";
|
|
6
|
-
import {isRegExp} from "./isRegExp.js";
|
|
7
|
-
import {isSymbol} from "./isSymbol.js";
|
|
8
|
-
|
|
9
|
-
const isBasicType = (source: any) => isNil(source) || isPrimitive(source) || isSymbol(source) || isFunction(source);
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Return a cloned value
|
|
13
|
-
* @param source
|
|
14
|
-
* @param stack
|
|
15
|
-
*/
|
|
16
|
-
export const deepClone = (source: any, stack = new WeakMap()): any => {
|
|
17
|
-
// provides an early exit for simple cases
|
|
18
|
-
if (isBasicType(source)) {
|
|
19
|
-
return source;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const stacked = stack.get(source);
|
|
23
|
-
|
|
24
|
-
if (stacked) {
|
|
25
|
-
// See issue #1619
|
|
26
|
-
return stacked;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
if (ArrayBuffer.isView(source)) {
|
|
30
|
-
return Buffer.isBuffer(source)
|
|
31
|
-
? Buffer.from(source)
|
|
32
|
-
: // adds support for all kind of TypedArray such as Int8Array, Uint8Array, etc
|
|
33
|
-
new (classOf(source))(source.buffer.slice(0), source.byteOffset, source.byteLength);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
if (isDate(source)) {
|
|
37
|
-
return new Date(source);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
if (isRegExp(source)) {
|
|
41
|
-
return new RegExp(source);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
if (Array.isArray(source)) {
|
|
45
|
-
const clone: unknown[] = [];
|
|
46
|
-
stack.set(source, clone);
|
|
47
|
-
source.forEach((item, idx) => (clone[idx] = deepClone(item, stack)));
|
|
48
|
-
return clone;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
if (source instanceof Map) {
|
|
52
|
-
const clone = new Map();
|
|
53
|
-
stack.set(source, clone);
|
|
54
|
-
source.forEach((value, key) => clone.set(deepClone(key, stack), deepClone(value, stack)));
|
|
55
|
-
return clone;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
if (source instanceof Set) {
|
|
59
|
-
const clone = new Set();
|
|
60
|
-
stack.set(source, clone);
|
|
61
|
-
source.forEach((value) => clone.add(deepClone(value, stack)));
|
|
62
|
-
return clone;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
const clone = Object.create(Reflect.getPrototypeOf(source));
|
|
66
|
-
stack.set(source, clone);
|
|
67
|
-
|
|
68
|
-
Reflect.ownKeys(source).forEach((key) => {
|
|
69
|
-
// respects property descriptors and the prototype chain more explicitly, which is important for objects with getter/setter.
|
|
70
|
-
const descriptor = Object.getOwnPropertyDescriptor(source, key);
|
|
71
|
-
|
|
72
|
-
if (descriptor) {
|
|
73
|
-
if (!isFunction(descriptor.value)) {
|
|
74
|
-
Object.defineProperty(clone, key, {
|
|
75
|
-
...descriptor,
|
|
76
|
-
value: deepClone(descriptor.value, stack)
|
|
77
|
-
});
|
|
78
|
-
} else {
|
|
79
|
-
Object.defineProperty(clone, key, descriptor);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
return clone;
|
|
85
|
-
};
|
|
@@ -1,223 +0,0 @@
|
|
|
1
|
-
import {deepMerge} from "./deepMerge.js";
|
|
2
|
-
|
|
3
|
-
describe("deepMerge", () => {
|
|
4
|
-
describe("without reducers", () => {
|
|
5
|
-
describe("when is an object", () => {
|
|
6
|
-
it("should merge data (1)", () => {
|
|
7
|
-
expect(
|
|
8
|
-
deepMerge(
|
|
9
|
-
{
|
|
10
|
-
security: ["o"]
|
|
11
|
-
},
|
|
12
|
-
undefined
|
|
13
|
-
)
|
|
14
|
-
).toEqual({
|
|
15
|
-
security: ["o"]
|
|
16
|
-
});
|
|
17
|
-
});
|
|
18
|
-
it("should merge data (2)", () => {
|
|
19
|
-
const klass = class {
|
|
20
|
-
test = "test";
|
|
21
|
-
};
|
|
22
|
-
const result = deepMerge(
|
|
23
|
-
{
|
|
24
|
-
security: ["o"]
|
|
25
|
-
},
|
|
26
|
-
{
|
|
27
|
-
security: ["o", "o1"],
|
|
28
|
-
withClass: new klass()
|
|
29
|
-
}
|
|
30
|
-
);
|
|
31
|
-
expect(result).toEqual({
|
|
32
|
-
security: ["o", "o1"],
|
|
33
|
-
withClass: {
|
|
34
|
-
test: "test"
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
expect(result.withClass).toBeInstanceOf(klass);
|
|
39
|
-
});
|
|
40
|
-
it("should merge data (3)", () => {
|
|
41
|
-
expect(
|
|
42
|
-
deepMerge(
|
|
43
|
-
{
|
|
44
|
-
security: [{"1": "o"}]
|
|
45
|
-
},
|
|
46
|
-
{
|
|
47
|
-
security: [{"1": "o"}, {"2": "o1"}]
|
|
48
|
-
}
|
|
49
|
-
)
|
|
50
|
-
).toEqual({
|
|
51
|
-
security: [{"1": "o"}, {"1": "o"}, {"2": "o1"}]
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
it("should merge data (4)", () => {
|
|
55
|
-
const alter = vi.fn().mockImplementation((key, value) => {
|
|
56
|
-
return value;
|
|
57
|
-
});
|
|
58
|
-
expect(
|
|
59
|
-
deepMerge(
|
|
60
|
-
{
|
|
61
|
-
prop: {}
|
|
62
|
-
},
|
|
63
|
-
{
|
|
64
|
-
prop: ""
|
|
65
|
-
},
|
|
66
|
-
{
|
|
67
|
-
alter
|
|
68
|
-
}
|
|
69
|
-
)
|
|
70
|
-
).toEqual({
|
|
71
|
-
prop: {}
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
expect(alter).toHaveBeenCalledWith("prop", {});
|
|
75
|
-
});
|
|
76
|
-
it("should alter nested properties", () => {
|
|
77
|
-
const alter = vi.fn().mockImplementation((key, value) => {
|
|
78
|
-
return key === "nested" ? {...value, extra: true} : value;
|
|
79
|
-
});
|
|
80
|
-
expect(
|
|
81
|
-
deepMerge(
|
|
82
|
-
{
|
|
83
|
-
prop: {nested: {a: 1}}
|
|
84
|
-
},
|
|
85
|
-
{
|
|
86
|
-
prop: {nested: {b: 2}}
|
|
87
|
-
},
|
|
88
|
-
{alter}
|
|
89
|
-
)
|
|
90
|
-
).toEqual({
|
|
91
|
-
prop: {nested: {a: 1, b: 2, extra: true}}
|
|
92
|
-
});
|
|
93
|
-
expect(alter).toHaveBeenCalledWith("nested", {a: 1, b: 2});
|
|
94
|
-
});
|
|
95
|
-
it("should merge data and prevent prototype pollution", () => {
|
|
96
|
-
const obj = JSON.parse('{"__proto__": {"a": "vulnerable"}, "security": [{"1": "o"}, {"2": "o1"}]}');
|
|
97
|
-
|
|
98
|
-
expect(
|
|
99
|
-
deepMerge(
|
|
100
|
-
{
|
|
101
|
-
security: [{"1": "o"}]
|
|
102
|
-
},
|
|
103
|
-
obj
|
|
104
|
-
)
|
|
105
|
-
).toEqual({
|
|
106
|
-
security: [{"1": "o"}, {"1": "o"}, {"2": "o1"}]
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
expect(({} as any).a).toBeUndefined();
|
|
110
|
-
});
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
describe("when is an array", () => {
|
|
114
|
-
it("should merge data (1)", () => {
|
|
115
|
-
expect(deepMerge(["1", "2", "4"], ["1", "2", "3"])).toEqual(["1", "2", "4", "3"]);
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
it("should merge data (2)", () => {
|
|
119
|
-
expect(deepMerge([{"1": "1"}, {"2": "2"}, {"4": "4"}], [{"1": "1"}, {"2": "2"}, {"3": "3"}])).toEqual([
|
|
120
|
-
{"1": "1"},
|
|
121
|
-
{"2": "2"},
|
|
122
|
-
{"4": "4"},
|
|
123
|
-
{"1": "1"},
|
|
124
|
-
{"2": "2"},
|
|
125
|
-
{"3": "3"}
|
|
126
|
-
]);
|
|
127
|
-
});
|
|
128
|
-
});
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
describe("with reducers", () => {
|
|
132
|
-
describe("when is an object", () => {
|
|
133
|
-
it("should merge data", () => {
|
|
134
|
-
expect(
|
|
135
|
-
deepMerge(
|
|
136
|
-
{
|
|
137
|
-
security: ["o"]
|
|
138
|
-
},
|
|
139
|
-
{
|
|
140
|
-
security: ["o", "o1"]
|
|
141
|
-
},
|
|
142
|
-
{
|
|
143
|
-
reducers: {
|
|
144
|
-
default: (collection, value) => {
|
|
145
|
-
if (collection.indexOf(value) === -1) {
|
|
146
|
-
collection.push(value);
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
return collection;
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
)
|
|
154
|
-
).toEqual({
|
|
155
|
-
security: ["o", "o1"]
|
|
156
|
-
});
|
|
157
|
-
});
|
|
158
|
-
it("should merge data (2)", () => {
|
|
159
|
-
expect(
|
|
160
|
-
deepMerge(
|
|
161
|
-
{
|
|
162
|
-
parameters: [
|
|
163
|
-
{in: "test", name: "get", description: "test"},
|
|
164
|
-
{
|
|
165
|
-
in: "test",
|
|
166
|
-
name: "post",
|
|
167
|
-
description: "test"
|
|
168
|
-
}
|
|
169
|
-
]
|
|
170
|
-
},
|
|
171
|
-
{
|
|
172
|
-
parameters: [
|
|
173
|
-
{in: "test", name: "get", description: "test2"},
|
|
174
|
-
{
|
|
175
|
-
in: "test",
|
|
176
|
-
name: "util",
|
|
177
|
-
description: "test2"
|
|
178
|
-
}
|
|
179
|
-
]
|
|
180
|
-
},
|
|
181
|
-
{
|
|
182
|
-
reducers: {
|
|
183
|
-
parameters: (collection, value, options) => {
|
|
184
|
-
const index = collection.findIndex((current) => current.in === value.in && current.name === value.name);
|
|
185
|
-
|
|
186
|
-
if (index === -1) {
|
|
187
|
-
return [...collection, value];
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
collection[index] = deepMerge(collection[index], value, options);
|
|
191
|
-
|
|
192
|
-
return collection;
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
)
|
|
197
|
-
).toEqual({
|
|
198
|
-
parameters: [
|
|
199
|
-
{in: "test", name: "get", description: "test2"},
|
|
200
|
-
{in: "test", name: "post", description: "test"},
|
|
201
|
-
{in: "test", name: "util", description: "test2"}
|
|
202
|
-
]
|
|
203
|
-
});
|
|
204
|
-
});
|
|
205
|
-
});
|
|
206
|
-
|
|
207
|
-
describe("when is an array", () => {
|
|
208
|
-
it("should merge data", () => {
|
|
209
|
-
expect(deepMerge(["1", "2", "4"], ["1", "2", "3"])).toEqual(["1", "2", "4", "3"]);
|
|
210
|
-
});
|
|
211
|
-
it("should merge data (2)", () => {
|
|
212
|
-
expect(deepMerge([{"1": "1"}, {"2": "2"}, {"4": "4"}], [{"1": "1"}, {"2": "2"}, {"3": "3"}])).toEqual([
|
|
213
|
-
{"1": "1"},
|
|
214
|
-
{"2": "2"},
|
|
215
|
-
{"4": "4"},
|
|
216
|
-
{"1": "1"},
|
|
217
|
-
{"2": "2"},
|
|
218
|
-
{"3": "3"}
|
|
219
|
-
]);
|
|
220
|
-
});
|
|
221
|
-
});
|
|
222
|
-
});
|
|
223
|
-
});
|
package/src/utils/deepMerge.ts
DELETED
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import {createInstance} from "./createInstance.js";
|
|
2
|
-
import {isFunction} from "./isFunction.js";
|
|
3
|
-
import {isPrimitive} from "./isPrimitive.js";
|
|
4
|
-
import {isSymbol} from "./isSymbol.js";
|
|
5
|
-
import {objectKeys} from "./objectKeys.js";
|
|
6
|
-
|
|
7
|
-
export type DeepMergeReducerCB = (collection: any[], value: any, options?: DeepMergeOptions) => any;
|
|
8
|
-
export type DeepMergeComparatorCB = (item: any, ref: any) => boolean;
|
|
9
|
-
|
|
10
|
-
export interface DeepMergeOptions {
|
|
11
|
-
reducers?: Record<string, DeepMergeReducerCB>;
|
|
12
|
-
parentKey?: string;
|
|
13
|
-
cleanUndefinedProps?: boolean;
|
|
14
|
-
alter?: (key: string, value: any) => any;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export function mergeReducerBuilder(cb: DeepMergeComparatorCB) {
|
|
18
|
-
return (collection: any[], value: any, options: DeepMergeOptions) => {
|
|
19
|
-
const index = collection.findIndex((item) => cb(item, value));
|
|
20
|
-
|
|
21
|
-
if (index === -1) {
|
|
22
|
-
return [...collection, value];
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
collection[index] = deepMerge(collection[index], value, options);
|
|
26
|
-
|
|
27
|
-
return collection;
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const defaultReducer = mergeReducerBuilder((a, b) => a === b);
|
|
32
|
-
|
|
33
|
-
function getReducer({reducers, parentKey}: DeepMergeOptions) {
|
|
34
|
-
if (!reducers) {
|
|
35
|
-
return defaultReducer;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
if (parentKey && reducers[parentKey]) {
|
|
39
|
-
return reducers[parentKey];
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return reducers["default"] || defaultReducer;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function shouldReturnObj(obj: any, source: any) {
|
|
46
|
-
return isPrimitive(obj) || isSymbol(obj) || isFunction(obj) || source === undefined;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
function shouldReturnSource(obj: any, source: any) {
|
|
50
|
-
return obj === undefined || obj === null || (obj === "" && source !== "");
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export function deepMerge<T = any, C = any>(source: T & any, obj: C & any, options: DeepMergeOptions = {}): (T & C) | undefined | null {
|
|
54
|
-
if (shouldReturnSource(obj, source)) {
|
|
55
|
-
return source as any;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
if (shouldReturnObj(obj, source)) {
|
|
59
|
-
return obj;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
if (Array.isArray(source)) {
|
|
63
|
-
const reducer = getReducer(options);
|
|
64
|
-
|
|
65
|
-
return [].concat(obj).reduce((out: any[], value: any) => reducer(out, value, options), [...source]);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
const newObj = createInstance(source);
|
|
69
|
-
|
|
70
|
-
return [...objectKeys(source), ...objectKeys(obj)].reduce((out: any, key: string) => {
|
|
71
|
-
const src = source && source[key];
|
|
72
|
-
const value = deepMerge(src, obj && obj[key], {
|
|
73
|
-
...options,
|
|
74
|
-
parentKey: key
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
if (options.cleanUndefinedProps && value === undefined) {
|
|
78
|
-
return out;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
out[key] = options.alter?.(key, value) ?? value;
|
|
82
|
-
|
|
83
|
-
return out;
|
|
84
|
-
}, newObj);
|
|
85
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import {isMethodDescriptor} from "./descriptorOf.js";
|
|
2
|
-
|
|
3
|
-
describe("isMethodDescriptor()", () => {
|
|
4
|
-
it("should return true", () => {
|
|
5
|
-
class Test {
|
|
6
|
-
test() {}
|
|
7
|
-
}
|
|
8
|
-
expect(isMethodDescriptor(Test, "test")).toBeTruthy();
|
|
9
|
-
});
|
|
10
|
-
it("should return false", () => {
|
|
11
|
-
class Test {
|
|
12
|
-
test: string;
|
|
13
|
-
}
|
|
14
|
-
expect(isMethodDescriptor(Test, "test")).toBeFalsy();
|
|
15
|
-
});
|
|
16
|
-
});
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Return the descriptor for a given class and propertyKey
|
|
3
|
-
* @param target
|
|
4
|
-
* @param {string} propertyKey
|
|
5
|
-
* @returns {PropertyDescriptor}
|
|
6
|
-
*/
|
|
7
|
-
export function descriptorOf(target: any, propertyKey: string | symbol): PropertyDescriptor {
|
|
8
|
-
return Reflect.getOwnPropertyDescriptor((target && target.prototype) || target, propertyKey)!;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export function isMethodDescriptor(target: any, propertyKey: string | symbol) {
|
|
12
|
-
return descriptorOf(target, propertyKey)?.value;
|
|
13
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import {getConstructorArgNames} from "./getConstructorArgNames.js";
|
|
2
|
-
|
|
3
|
-
describe("getConstructorArgNames", () => {
|
|
4
|
-
it("should return the constructor args names", () => {
|
|
5
|
-
class Test {
|
|
6
|
-
constructor(test: string) {}
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
expect(getConstructorArgNames(Test)).toEqual(["test"]);
|
|
10
|
-
});
|
|
11
|
-
});
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import {toStringConstructor} from "./toStringConstructor.js";
|
|
2
|
-
|
|
3
|
-
export function getConstructorArgNames(target: any) {
|
|
4
|
-
return toStringConstructor(target)
|
|
5
|
-
.split("constructor(")[1]
|
|
6
|
-
.split(")")[0]
|
|
7
|
-
.split(", ")
|
|
8
|
-
.filter(Boolean)
|
|
9
|
-
.map((s) => s.trim());
|
|
10
|
-
}
|