@tsed/core 8.11.1 → 8.12.0-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,322 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ancestorsOf,
|
|
3
|
-
classOf,
|
|
4
|
-
constructorOf,
|
|
5
|
-
getClass,
|
|
6
|
-
getClassOrSymbol,
|
|
7
|
-
getConstructor,
|
|
8
|
-
isArrayOrArrayClass,
|
|
9
|
-
isClass,
|
|
10
|
-
isCollection,
|
|
11
|
-
isEmpty,
|
|
12
|
-
isInheritedFrom,
|
|
13
|
-
isPrimitiveOrPrimitiveClass,
|
|
14
|
-
isPromise,
|
|
15
|
-
methodsOf,
|
|
16
|
-
nameOf,
|
|
17
|
-
nameOfClass,
|
|
18
|
-
primitiveOf
|
|
19
|
-
} from "../index.js";
|
|
20
|
-
|
|
21
|
-
class Base {
|
|
22
|
-
test1() {}
|
|
23
|
-
|
|
24
|
-
test3() {}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
class Test extends Base {
|
|
28
|
-
test1() {}
|
|
29
|
-
|
|
30
|
-
test2() {}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const sym = Symbol("test2");
|
|
34
|
-
|
|
35
|
-
describe("ObjectUtils", () => {
|
|
36
|
-
describe("getConstructor()", () => {
|
|
37
|
-
it("should return the constructor when class is given", () => {
|
|
38
|
-
expect(getConstructor(Test)).toBe(Test);
|
|
39
|
-
});
|
|
40
|
-
it("should return the constructor when instance is given", () => {
|
|
41
|
-
expect(getConstructor(new Test())).toBe(Test);
|
|
42
|
-
});
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
describe("getClass()", () => {
|
|
46
|
-
it("should return the class when class is given", () => {
|
|
47
|
-
expect(getClass(Test)).toBe(Test);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it("should return the class when instance is given", () => {
|
|
51
|
-
expect(getClass(new Test())).toBe(Test);
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it("should return the class when prototype is given", () => {
|
|
55
|
-
expect(getClass(Test.prototype)).toBe(Test);
|
|
56
|
-
});
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
describe("getClassOrSymbol()", () => {
|
|
60
|
-
it("should return the class when class is given", () => {
|
|
61
|
-
expect(getClassOrSymbol(Test)).toBe(Test);
|
|
62
|
-
});
|
|
63
|
-
it("should return the class when class is symbol", () => {
|
|
64
|
-
expect(getClassOrSymbol(sym)).toBe(sym);
|
|
65
|
-
});
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
describe("isPrimitiveOrPrimitiveClass()", () => {
|
|
69
|
-
it("should return true when a primitive is given", () => {
|
|
70
|
-
expect(isPrimitiveOrPrimitiveClass("test")).toBe(true);
|
|
71
|
-
});
|
|
72
|
-
it("should return true when a PrimitiveClass is given", () => {
|
|
73
|
-
expect(isPrimitiveOrPrimitiveClass(String())).toBe(true);
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
it("should return false when a class is given", () => {
|
|
77
|
-
expect(isPrimitiveOrPrimitiveClass(Test)).toBe(false);
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
describe("isArrayOrArrayClass()", () => {
|
|
82
|
-
it("should return true when Array is given", () => {
|
|
83
|
-
expect(isArrayOrArrayClass(Array)).toBe(true);
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
it("should return true when [] is given", () => {
|
|
87
|
-
expect(isArrayOrArrayClass([])).toBe(true);
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
it("should return false when {} is given", () => {
|
|
91
|
-
expect(isArrayOrArrayClass({})).toBe(false);
|
|
92
|
-
});
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
describe("isCollection()", () => {
|
|
96
|
-
it("should return true when Array is given", () => {
|
|
97
|
-
expect(isCollection(Array)).toBe(true);
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
it("should return true when [] is given", () => {
|
|
101
|
-
expect(isCollection([])).toBe(true);
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
it("should return true when Map is given", () => {
|
|
105
|
-
expect(isCollection(Map)).toBe(true);
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
it("should return true when Set is given", () => {
|
|
109
|
-
expect(isCollection(Set)).toBe(true);
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
it("should return true when WeakMap is given", () => {
|
|
113
|
-
expect(isCollection(WeakMap)).toBe(true);
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
it("should return true when WeakSet is given", () => {
|
|
117
|
-
expect(isCollection(WeakSet)).toBe(true);
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
it("should return false when {} is given", () => {
|
|
121
|
-
expect(isCollection({})).toBe(false);
|
|
122
|
-
});
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
describe("isEmpty()", () => {
|
|
126
|
-
it("should return true when empty string is given", () => {
|
|
127
|
-
expect(isEmpty("")).toBe(true);
|
|
128
|
-
});
|
|
129
|
-
it("should return true when null is given", () => {
|
|
130
|
-
expect(isEmpty(null)).toBe(true);
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
it("should return true when undefined is given", () => {
|
|
134
|
-
expect(isEmpty(undefined)).toBe(true);
|
|
135
|
-
});
|
|
136
|
-
it("should return false when {} is given", () => {
|
|
137
|
-
expect(isEmpty({})).toBe(false);
|
|
138
|
-
});
|
|
139
|
-
it("should return false when [] is given", () => {
|
|
140
|
-
expect(isEmpty([])).toBe(false);
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
it("should return false when false is given", () => {
|
|
144
|
-
expect(isEmpty(false)).toBe(false);
|
|
145
|
-
});
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
describe("isClass()", () => {
|
|
149
|
-
it("should return true when is a class", () => {
|
|
150
|
-
expect(isClass(class {})).toBe(true);
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
it("should return true when is a function", () => {
|
|
154
|
-
expect(isClass(function t() {})).toBe(true);
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
it("should return false (arrow function)", () => {
|
|
158
|
-
expect(isClass(() => {})).toBe(false);
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
it("should return false (date)", () => {
|
|
162
|
-
expect(isClass(new Date())).toBe(false);
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
it("should return false (number)", () => {
|
|
166
|
-
expect(isClass(1)).toBe(false);
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
it("should return false (obj)", () => {
|
|
170
|
-
expect(isClass(Object)).toBe(false);
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
it("should return false (promise)", () => {
|
|
174
|
-
expect(isClass(Promise.resolve())).toBe(false);
|
|
175
|
-
});
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
describe("isPromise()", () => {
|
|
179
|
-
it("should return true", () => {
|
|
180
|
-
expect(isPromise(Promise)).toBe(true);
|
|
181
|
-
});
|
|
182
|
-
|
|
183
|
-
it("should return true when its promise resolved", () => {
|
|
184
|
-
expect(isPromise(Promise.resolve())).toBe(true);
|
|
185
|
-
});
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
describe("nameOf", () => {
|
|
189
|
-
it("should return 'Test' when class is given", () => {
|
|
190
|
-
expect(nameOf(Test)).toBe("Test");
|
|
191
|
-
});
|
|
192
|
-
it("should return 'test2' when symbol is given", () => {
|
|
193
|
-
expect(nameOf(sym)).toBe("test2");
|
|
194
|
-
});
|
|
195
|
-
it("should return 'test' when string is given", () => {
|
|
196
|
-
expect(nameOf("test")).toBe("test");
|
|
197
|
-
});
|
|
198
|
-
it("should return '1' when string is given", () => {
|
|
199
|
-
expect(nameOf(1)).toBe("1");
|
|
200
|
-
});
|
|
201
|
-
it("should return 'true' when boolean is given", () => {
|
|
202
|
-
expect(nameOf(true)).toBe("true");
|
|
203
|
-
});
|
|
204
|
-
it("should return 'null' when null is given", () => {
|
|
205
|
-
expect(nameOf(null)).toBe("null");
|
|
206
|
-
});
|
|
207
|
-
it("should return 'undefined' when undefined is given", () => {
|
|
208
|
-
expect(nameOf(undefined)).toBe("undefined");
|
|
209
|
-
});
|
|
210
|
-
});
|
|
211
|
-
|
|
212
|
-
describe("nameOfClass", () => {
|
|
213
|
-
it("should return name when class is given", () => {
|
|
214
|
-
expect(nameOfClass(Test)).toBe("Test");
|
|
215
|
-
});
|
|
216
|
-
it("should return name when instance is given", () => {
|
|
217
|
-
expect(nameOfClass(new Test())).toBe("Test");
|
|
218
|
-
});
|
|
219
|
-
});
|
|
220
|
-
|
|
221
|
-
describe("primitiveOf", () => {
|
|
222
|
-
it("should return string", () => {
|
|
223
|
-
expect(primitiveOf(String)).toBe("string");
|
|
224
|
-
});
|
|
225
|
-
|
|
226
|
-
it("should return number", () => {
|
|
227
|
-
expect(primitiveOf(Number)).toBe("number");
|
|
228
|
-
});
|
|
229
|
-
|
|
230
|
-
it("should return boolean", () => {
|
|
231
|
-
expect(primitiveOf(Boolean)).toBe("boolean");
|
|
232
|
-
});
|
|
233
|
-
|
|
234
|
-
it("should return any", () => {
|
|
235
|
-
expect(primitiveOf(Object)).toBe("any");
|
|
236
|
-
});
|
|
237
|
-
});
|
|
238
|
-
|
|
239
|
-
describe("constructorOf()", () => {
|
|
240
|
-
it("should return the constructor when class is given", () => {
|
|
241
|
-
expect(constructorOf(Test)).toBe(Test);
|
|
242
|
-
});
|
|
243
|
-
it("should return the constructor when instance is given", () => {
|
|
244
|
-
expect(constructorOf(new Test())).toBe(Test);
|
|
245
|
-
});
|
|
246
|
-
});
|
|
247
|
-
|
|
248
|
-
describe("classOf()", () => {
|
|
249
|
-
it("should return the class when class is given", () => {
|
|
250
|
-
expect(classOf(Test)).toBe(Test);
|
|
251
|
-
});
|
|
252
|
-
|
|
253
|
-
it("should return the class when instance is given", () => {
|
|
254
|
-
expect(classOf(new Test())).toBe(Test);
|
|
255
|
-
});
|
|
256
|
-
|
|
257
|
-
it("should return the class when prototype is given", () => {
|
|
258
|
-
expect(classOf(Test.prototype)).toBe(Test);
|
|
259
|
-
});
|
|
260
|
-
});
|
|
261
|
-
describe("ancestorsOf()", () => {
|
|
262
|
-
it("should returns ancestors", () => {
|
|
263
|
-
class Base {}
|
|
264
|
-
|
|
265
|
-
class Test extends Base {}
|
|
266
|
-
|
|
267
|
-
expect(ancestorsOf(Test)).toEqual([Base, Test]);
|
|
268
|
-
expect(ancestorsOf(Test).reverse()).toEqual([Test, Base]);
|
|
269
|
-
});
|
|
270
|
-
});
|
|
271
|
-
|
|
272
|
-
describe("methodsOf", () => {
|
|
273
|
-
it("should return all methods", () => {
|
|
274
|
-
const methods = methodsOf(Test);
|
|
275
|
-
expect(methods).toEqual([
|
|
276
|
-
{propertyKey: "test1", target: Test},
|
|
277
|
-
{propertyKey: "test3", target: Base},
|
|
278
|
-
{propertyKey: "test2", target: Test}
|
|
279
|
-
]);
|
|
280
|
-
});
|
|
281
|
-
});
|
|
282
|
-
describe("isInheritedFrom", () => {
|
|
283
|
-
it("should return true when class inherit from another", () => {
|
|
284
|
-
class Test1 {}
|
|
285
|
-
|
|
286
|
-
class Test2 extends Test1 {}
|
|
287
|
-
|
|
288
|
-
expect(isInheritedFrom(Test2, Test1)).toBe(true);
|
|
289
|
-
});
|
|
290
|
-
it("should return false when deep is down", () => {
|
|
291
|
-
class Test1 {}
|
|
292
|
-
|
|
293
|
-
class Test2 extends Test1 {}
|
|
294
|
-
|
|
295
|
-
class Test3 extends Test2 {}
|
|
296
|
-
|
|
297
|
-
expect(isInheritedFrom(Test3, Test1, 1)).toBe(false);
|
|
298
|
-
});
|
|
299
|
-
|
|
300
|
-
it("should return true when deep is not down", () => {
|
|
301
|
-
class Test1 {}
|
|
302
|
-
|
|
303
|
-
class Test2 extends Test1 {}
|
|
304
|
-
|
|
305
|
-
class Test3 extends Test2 {}
|
|
306
|
-
|
|
307
|
-
expect(isInheritedFrom(Test3, Test1, 3)).toBe(true);
|
|
308
|
-
});
|
|
309
|
-
|
|
310
|
-
it("should return false when class isn't inherit from another", () => {
|
|
311
|
-
class Test1 {}
|
|
312
|
-
|
|
313
|
-
class Test3 {}
|
|
314
|
-
|
|
315
|
-
expect(isInheritedFrom(Test3, Test1)).toBe(false);
|
|
316
|
-
});
|
|
317
|
-
|
|
318
|
-
it("should return false when undefined is given", () => {
|
|
319
|
-
expect(isInheritedFrom(undefined, undefined)).toBe(false);
|
|
320
|
-
});
|
|
321
|
-
});
|
|
322
|
-
});
|
package/src/utils/ancestorOf.ts
DELETED
package/src/utils/ancestorsOf.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import {getInheritedClass} from "./ancestorOf.js";
|
|
2
|
-
import {classOf} from "./classOf.js";
|
|
3
|
-
import {nameOf} from "./nameOf.js";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
*
|
|
7
|
-
* @param target
|
|
8
|
-
* @returns {Array}
|
|
9
|
-
*/
|
|
10
|
-
export function ancestorsOf(target: any) {
|
|
11
|
-
const classes = [];
|
|
12
|
-
|
|
13
|
-
let currentTarget = classOf(target);
|
|
14
|
-
|
|
15
|
-
while (currentTarget && nameOf(currentTarget) !== "") {
|
|
16
|
-
classes.unshift(currentTarget);
|
|
17
|
-
currentTarget = getInheritedClass(currentTarget);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
return classes;
|
|
21
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import {catchAsyncError, catchError} from "./catchError.js";
|
|
2
|
-
|
|
3
|
-
describe("catchError", () => {
|
|
4
|
-
it("should catch error", () => {
|
|
5
|
-
expect(
|
|
6
|
-
catchError(() => {
|
|
7
|
-
throw new Error("message");
|
|
8
|
-
})?.message
|
|
9
|
-
).toEqual("message");
|
|
10
|
-
});
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
describe("catchAsyncError", () => {
|
|
14
|
-
it("should catch error", async () => {
|
|
15
|
-
expect((await catchAsyncError(() => Promise.reject(new Error("message"))))?.message).toEqual("message");
|
|
16
|
-
});
|
|
17
|
-
});
|
package/src/utils/catchError.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export function catchError<T extends Error>(cb: Function): T | undefined {
|
|
2
|
-
try {
|
|
3
|
-
cb();
|
|
4
|
-
} catch (er) {
|
|
5
|
-
return er;
|
|
6
|
-
}
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export async function catchAsyncError<T extends Error>(cb: Function): Promise<T | undefined> {
|
|
10
|
-
try {
|
|
11
|
-
await cb();
|
|
12
|
-
} catch (er) {
|
|
13
|
-
return er;
|
|
14
|
-
}
|
|
15
|
-
}
|
package/src/utils/classOf.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Get the provide constructor if target is an instance.
|
|
3
|
-
* @param target
|
|
4
|
-
* @returns {*}
|
|
5
|
-
*/
|
|
6
|
-
export function getClass(target: any): any {
|
|
7
|
-
return target.prototype ? target : target.constructor;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Get the provide constructor if target is an instance.
|
|
12
|
-
* @param target
|
|
13
|
-
* @returns {*}
|
|
14
|
-
* @alias getClass
|
|
15
|
-
*/
|
|
16
|
-
export function classOf(target: any) {
|
|
17
|
-
return getClass(target);
|
|
18
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import {cleanObject} from "./cleanObject.js";
|
|
2
|
-
|
|
3
|
-
describe("cleanObject", () => {
|
|
4
|
-
it("should clean undefined value from object", () => {
|
|
5
|
-
expect(
|
|
6
|
-
cleanObject(
|
|
7
|
-
{
|
|
8
|
-
test: undefined,
|
|
9
|
-
test2: false,
|
|
10
|
-
test3: null,
|
|
11
|
-
test4: "",
|
|
12
|
-
ignored: "key"
|
|
13
|
-
},
|
|
14
|
-
["ignored"]
|
|
15
|
-
)
|
|
16
|
-
).toEqual({
|
|
17
|
-
test2: false,
|
|
18
|
-
test3: null,
|
|
19
|
-
test4: ""
|
|
20
|
-
});
|
|
21
|
-
});
|
|
22
|
-
});
|
package/src/utils/cleanObject.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import {isProtectedKey} from "./isProtectedKey.js";
|
|
2
|
-
/**
|
|
3
|
-
* Remove undefined value
|
|
4
|
-
* @param obj
|
|
5
|
-
* @param ignore
|
|
6
|
-
*/
|
|
7
|
-
export function cleanObject(obj: Record<string, unknown>, ignore: string[] = []): any {
|
|
8
|
-
return Object.entries(obj).reduce(
|
|
9
|
-
(obj, [key, value]) => {
|
|
10
|
-
if (isProtectedKey(key) || ignore.includes(key) || value === undefined) {
|
|
11
|
-
return obj;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
obj[key] = value;
|
|
15
|
-
|
|
16
|
-
return obj;
|
|
17
|
-
},
|
|
18
|
-
{} as Record<string, unknown>
|
|
19
|
-
);
|
|
20
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type {Type} from "../types/Type.js";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Get the class constructor
|
|
5
|
-
* @param target
|
|
6
|
-
*/
|
|
7
|
-
export function getConstructor(target: any): Type<any> {
|
|
8
|
-
return typeof target === "function" ? target : target.constructor;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Get the class constructor
|
|
13
|
-
* @param target
|
|
14
|
-
*/
|
|
15
|
-
export function constructorOf(target: any): Type<any> {
|
|
16
|
-
return getConstructor(target);
|
|
17
|
-
}
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import {StoreMerge} from "../decorators/storeMerge.js";
|
|
2
|
-
import {StoreSet} from "../decorators/storeSet.js";
|
|
3
|
-
import {Store} from "../types/Store.js";
|
|
4
|
-
import {decorateMethodsOf} from "./decorateMethodsOf.js";
|
|
5
|
-
import {descriptorOf} from "./descriptorOf.js";
|
|
6
|
-
|
|
7
|
-
describe("decorateMethodsOf", () => {
|
|
8
|
-
it("should decorate all methods", () => {
|
|
9
|
-
function decorate() {
|
|
10
|
-
return (target: any) => {
|
|
11
|
-
decorateMethodsOf(target, (klass: any, property: any, descriptor: any) => {
|
|
12
|
-
Store.from(klass, property, descriptor).set("test", property);
|
|
13
|
-
|
|
14
|
-
return descriptor;
|
|
15
|
-
});
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
class TestParent {
|
|
20
|
-
test2(a: any) {
|
|
21
|
-
return "test" + a;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// WHEN
|
|
26
|
-
@decorate()
|
|
27
|
-
class Test extends TestParent {
|
|
28
|
-
test() {}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// THEN
|
|
32
|
-
const result = Store.from(Test, "test", descriptorOf(Test, "test")).get("test");
|
|
33
|
-
expect(result).toBe("test");
|
|
34
|
-
|
|
35
|
-
const result2 = Store.from(Test, "test2", descriptorOf(Test, "test2")).get("test");
|
|
36
|
-
expect(result2).toBe("test2");
|
|
37
|
-
|
|
38
|
-
expect(new Test().test2("1")).toBe("test1");
|
|
39
|
-
});
|
|
40
|
-
it("should decorate all methods and copy store metadata to the new property", () => {
|
|
41
|
-
function decorate() {
|
|
42
|
-
return (target: any) => {
|
|
43
|
-
decorateMethodsOf(target, (klass: any, property: any, descriptor: any) => {
|
|
44
|
-
Store.from(klass, property, descriptor).set("test", property);
|
|
45
|
-
});
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
class TestParent {
|
|
50
|
-
@StoreSet("options", {parent: "test", override: "parent"})
|
|
51
|
-
test(a: any) {}
|
|
52
|
-
|
|
53
|
-
@StoreSet("options", {parent: "test2"})
|
|
54
|
-
test2(a: any) {}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// WHEN
|
|
58
|
-
@decorate()
|
|
59
|
-
class Test extends TestParent {
|
|
60
|
-
@StoreMerge("options", {children: "test", override: "child"})
|
|
61
|
-
test() {}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
// THEN
|
|
65
|
-
const storeObj2 = Store.fromMethod(Test, "test2").toJson();
|
|
66
|
-
expect(storeObj2).toEqual({
|
|
67
|
-
options: {
|
|
68
|
-
parent: "test2"
|
|
69
|
-
},
|
|
70
|
-
test: "test2"
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
const storeObj = Store.fromMethod(Test, "test").toJson();
|
|
74
|
-
// store aren't merged
|
|
75
|
-
expect(storeObj).toEqual({
|
|
76
|
-
options: {
|
|
77
|
-
children: "test",
|
|
78
|
-
override: "child"
|
|
79
|
-
},
|
|
80
|
-
test: "test"
|
|
81
|
-
});
|
|
82
|
-
});
|
|
83
|
-
});
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import {Store} from "../types/Store.js";
|
|
2
|
-
import {classOf} from "./classOf.js";
|
|
3
|
-
import {descriptorOf} from "./descriptorOf.js";
|
|
4
|
-
import {methodsOf} from "./methodsOf.js";
|
|
5
|
-
import {prototypeOf} from "./prototypeOf.js";
|
|
6
|
-
|
|
7
|
-
export function decorateMethodsOf(klass: any, decorator: any) {
|
|
8
|
-
methodsOf(klass).forEach(({target, propertyKey}) => {
|
|
9
|
-
const proto = prototypeOf(klass);
|
|
10
|
-
|
|
11
|
-
if (target !== classOf(klass)) {
|
|
12
|
-
Object.defineProperty(proto, propertyKey, {
|
|
13
|
-
writable: true,
|
|
14
|
-
configurable: true,
|
|
15
|
-
value(...args: any[]) {
|
|
16
|
-
return prototypeOf(target)[propertyKey].apply(this, args);
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
Store.mergeStoreMethodFrom(klass, target, propertyKey);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
let descriptor = descriptorOf(klass, propertyKey);
|
|
24
|
-
|
|
25
|
-
const newDescriptor = decorator(proto, propertyKey, descriptor) || descriptor;
|
|
26
|
-
|
|
27
|
-
if (newDescriptor) {
|
|
28
|
-
Object.defineProperty(proto, propertyKey, newDescriptor);
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import {decoratorArgs} from "./decoratorArgs.js";
|
|
2
|
-
import {descriptorOf} from "./descriptorOf.js";
|
|
3
|
-
import {prototypeOf} from "./prototypeOf.js";
|
|
4
|
-
|
|
5
|
-
describe("decoratorArgs", () => {
|
|
6
|
-
it("should return decorator arguments", () => {
|
|
7
|
-
class Test {
|
|
8
|
-
test() {}
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
const args = decoratorArgs(prototypeOf(Test), "test");
|
|
12
|
-
|
|
13
|
-
expect(args).toEqual([prototypeOf(Test), "test", descriptorOf(Test, "test")]);
|
|
14
|
-
});
|
|
15
|
-
});
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import {DecoratorParameters} from "../types/DecoratorParameters.js";
|
|
2
|
-
import {descriptorOf} from "./descriptorOf.js";
|
|
3
|
-
|
|
4
|
-
export function decoratorArgs(target: any, propertyKey: string): DecoratorParameters {
|
|
5
|
-
return [target, propertyKey, descriptorOf(target, propertyKey)!];
|
|
6
|
-
}
|