@tsed/core 8.11.1 → 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,14 +0,0 @@
|
|
|
1
|
-
import {isProtectedKey} from "./isProtectedKey.js";
|
|
2
|
-
|
|
3
|
-
describe("isProtectedKey", () => {
|
|
4
|
-
it("should return true", () => {
|
|
5
|
-
expect(isProtectedKey("__proto__")).toBe(true);
|
|
6
|
-
expect(isProtectedKey("prototype")).toBe(true);
|
|
7
|
-
expect(isProtectedKey("constructor")).toBe(true);
|
|
8
|
-
});
|
|
9
|
-
it("should return false", () => {
|
|
10
|
-
expect(isProtectedKey("test")).toBe(false);
|
|
11
|
-
expect(isProtectedKey("pro")).toBe(false);
|
|
12
|
-
expect(isProtectedKey("const")).toBe(false);
|
|
13
|
-
});
|
|
14
|
-
});
|
package/src/utils/isRegExp.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import {isSerializable} from "./isSerializable.js";
|
|
2
|
-
|
|
3
|
-
describe("isSerializable()", () => {
|
|
4
|
-
it("should return the expected value", () => {
|
|
5
|
-
expect(isSerializable(true)).toBe(false);
|
|
6
|
-
expect(isSerializable(null)).toBe(false);
|
|
7
|
-
expect(isSerializable(undefined)).toBe(false);
|
|
8
|
-
expect(isSerializable("")).toBe(false);
|
|
9
|
-
expect(isSerializable("test")).toBe(false);
|
|
10
|
-
expect(isSerializable(0)).toBe(false);
|
|
11
|
-
expect(isSerializable(1)).toBe(false);
|
|
12
|
-
expect(isSerializable({})).toBe(true);
|
|
13
|
-
});
|
|
14
|
-
});
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import {isBoolean} from "./isBoolean.js";
|
|
2
|
-
import {isNil} from "./isNil.js";
|
|
3
|
-
import {isNumber} from "./isNumber.js";
|
|
4
|
-
import {isStream} from "./isStream.js";
|
|
5
|
-
import {isString} from "./isString.js";
|
|
6
|
-
|
|
7
|
-
export function isSerializable(data: any) {
|
|
8
|
-
return !(Buffer.isBuffer(data) || isStream(data) || isBoolean(data) || isNumber(data) || isString(data) || isNil(data));
|
|
9
|
-
}
|
package/src/utils/isStream.ts
DELETED
package/src/utils/isString.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @param target
|
|
3
|
-
* @returns {boolean}
|
|
4
|
-
*/
|
|
5
|
-
export function isString(target: any): target is string {
|
|
6
|
-
return typeof target === "string";
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export function isStringOrStringClass(target: any): target is string {
|
|
10
|
-
return typeof target === "string" || target instanceof String || target === String;
|
|
11
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import {isSymbol, isSymbolOrSymbolClass} from "./isSymbol.js";
|
|
2
|
-
|
|
3
|
-
describe("isSymbol()", () => {
|
|
4
|
-
it("should validate value", () => {
|
|
5
|
-
expect(isSymbol(Symbol.for("test"))).toBe(true);
|
|
6
|
-
expect(isSymbol("test")).toBe(false);
|
|
7
|
-
expect(isSymbolOrSymbolClass(Symbol.for("test"))).toBe(true);
|
|
8
|
-
expect(isSymbolOrSymbolClass(Symbol)).toBe(true);
|
|
9
|
-
expect(isSymbolOrSymbolClass("test")).toBe(false);
|
|
10
|
-
});
|
|
11
|
-
});
|
package/src/utils/isSymbol.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
* @param target
|
|
4
|
-
*/
|
|
5
|
-
export function isSymbol(target: any): target is symbol {
|
|
6
|
-
return typeof target === "symbol";
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export function isSymbolOrSymbolClass(target: any): target is symbol {
|
|
10
|
-
return typeof target === "symbol" || target instanceof Symbol || target === Symbol;
|
|
11
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import {methodsOf} from "./methodsOf.js";
|
|
2
|
-
|
|
3
|
-
describe("methodsOf()", () => {
|
|
4
|
-
it("should return methods", () => {
|
|
5
|
-
class TestClass {
|
|
6
|
-
method() {}
|
|
7
|
-
|
|
8
|
-
property: string;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
const methods = methodsOf(TestClass);
|
|
12
|
-
expect(methods).toHaveLength(1);
|
|
13
|
-
expect(methods[0]).toMatchObject({
|
|
14
|
-
propertyKey: "method"
|
|
15
|
-
});
|
|
16
|
-
});
|
|
17
|
-
it("should not return getters", () => {
|
|
18
|
-
class TestClass {
|
|
19
|
-
method() {}
|
|
20
|
-
|
|
21
|
-
get property() {
|
|
22
|
-
return "";
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const methods = methodsOf(TestClass);
|
|
27
|
-
|
|
28
|
-
expect(methods).toHaveLength(1);
|
|
29
|
-
expect(methods[0]).toMatchObject({
|
|
30
|
-
propertyKey: "method"
|
|
31
|
-
});
|
|
32
|
-
});
|
|
33
|
-
});
|
package/src/utils/methodsOf.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import {Type} from "../types/Type.js";
|
|
2
|
-
import {ancestorsOf} from "./ancestorsOf.js";
|
|
3
|
-
import {classOf} from "./classOf.js";
|
|
4
|
-
import {isSymbol} from "./isSymbol.js";
|
|
5
|
-
import {prototypeOf} from "./prototypeOf.js";
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Return all methods for a given class.
|
|
9
|
-
* @param target
|
|
10
|
-
*/
|
|
11
|
-
export function methodsOf(target: any): {target: Type; propertyKey: string}[] {
|
|
12
|
-
const methods = new Map();
|
|
13
|
-
target = classOf(target);
|
|
14
|
-
|
|
15
|
-
ancestorsOf(target).forEach((target) => {
|
|
16
|
-
const keys = Reflect.ownKeys(prototypeOf(target));
|
|
17
|
-
|
|
18
|
-
keys.forEach((propertyKey: string) => {
|
|
19
|
-
if (isSymbol(propertyKey) || propertyKey === "constructor" || Object.getOwnPropertyDescriptor(prototypeOf(target), propertyKey)?.get)
|
|
20
|
-
return;
|
|
21
|
-
methods.set(propertyKey, {target, propertyKey});
|
|
22
|
-
});
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
return Array.from(methods.values());
|
|
26
|
-
}
|
package/src/utils/nameOf.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Get the provide name.
|
|
3
|
-
* @param targetClass
|
|
4
|
-
*/
|
|
5
|
-
export function nameOfClass(targetClass: any): string {
|
|
6
|
-
return typeof targetClass === "function" ? targetClass.name : targetClass.constructor.name;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Get symbol name.
|
|
11
|
-
* @param sym
|
|
12
|
-
*/
|
|
13
|
-
export const nameOfSymbol = (sym: symbol): string => sym.toString().replace("Symbol(", "").replace(")", "");
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Get object name
|
|
17
|
-
*/
|
|
18
|
-
export function nameOf(obj: any): string {
|
|
19
|
-
switch (typeof obj) {
|
|
20
|
-
default:
|
|
21
|
-
return "" + obj;
|
|
22
|
-
case "symbol":
|
|
23
|
-
return nameOfSymbol(obj);
|
|
24
|
-
case "function":
|
|
25
|
-
return nameOfClass(obj);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import {objectKeys} from "./objectKeys.js";
|
|
2
|
-
|
|
3
|
-
describe("objectKeys", () => {
|
|
4
|
-
it("should return only authorized keys", () => {
|
|
5
|
-
const obj = JSON.parse('{"__proto__": {"a": "vulnerable"}, "test": "test"}');
|
|
6
|
-
|
|
7
|
-
expect(objectKeys(obj)).toEqual(["test"]);
|
|
8
|
-
expect(({} as any).a).toBeUndefined();
|
|
9
|
-
});
|
|
10
|
-
});
|
package/src/utils/objectKeys.ts
DELETED
package/src/utils/primitiveOf.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import {isBooleanOrBooleanClass} from "./isBoolean.js";
|
|
2
|
-
import {isNumberOrNumberClass} from "./isNumber.js";
|
|
3
|
-
import {isStringOrStringClass} from "./isString.js";
|
|
4
|
-
|
|
5
|
-
export function primitiveOf(target: any): "string" | "number" | "boolean" | "any" {
|
|
6
|
-
if (isStringOrStringClass(target)) {
|
|
7
|
-
return "string";
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
if (isNumberOrNumberClass(target)) {
|
|
11
|
-
return "number";
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
if (isBooleanOrBooleanClass(target)) {
|
|
15
|
-
return "boolean";
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
return "any";
|
|
19
|
-
}
|
package/src/utils/prototypeOf.ts
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import {setValue} from "./setValue.js";
|
|
2
|
-
|
|
3
|
-
describe("setValue()", () => {
|
|
4
|
-
describe("when map", () => {
|
|
5
|
-
it("should set value", () => {
|
|
6
|
-
let map: Map<any, any> = new Map();
|
|
7
|
-
|
|
8
|
-
setValue(map, "test", "value");
|
|
9
|
-
|
|
10
|
-
expect(map.get("test")).toBe("value");
|
|
11
|
-
});
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
describe("when map with dep", () => {
|
|
15
|
-
it("should set value", () => {
|
|
16
|
-
let map: Map<any, any> = new Map();
|
|
17
|
-
map.set("test", {t1: "value"});
|
|
18
|
-
setValue(map, "test.t1", "value2");
|
|
19
|
-
|
|
20
|
-
expect(map.get("test").t1).toBe("value2");
|
|
21
|
-
});
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
describe("when map with dep (without defined value)", () => {
|
|
25
|
-
it("should set value", () => {
|
|
26
|
-
let map: Map<any, any> = new Map();
|
|
27
|
-
setValue(map, "test.t1", "value2");
|
|
28
|
-
|
|
29
|
-
expect(map.get("test").t1).toBe("value2");
|
|
30
|
-
});
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
describe("when object with dep (without defined value)", () => {
|
|
34
|
-
it("should set value", () => {
|
|
35
|
-
const map: any = {test: {t1: "value"}};
|
|
36
|
-
setValue(map, "test.t1", "value2");
|
|
37
|
-
|
|
38
|
-
expect(map.test.t1).toBe("value2");
|
|
39
|
-
});
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
describe("when object with dep (with object defined value)", () => {
|
|
43
|
-
it("should set value", () => {
|
|
44
|
-
const obj = {};
|
|
45
|
-
setValue(obj, "__proto__", "vulnerable");
|
|
46
|
-
expect(obj).toEqual({});
|
|
47
|
-
expect(({} as any).a).toBeUndefined();
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
describe("when a function is given a value", () => {
|
|
52
|
-
it("should set value", () => {
|
|
53
|
-
let map: any = {};
|
|
54
|
-
|
|
55
|
-
setValue(map, "test.deep", () => {});
|
|
56
|
-
|
|
57
|
-
expect(map.test.deep).toBeInstanceOf(Function);
|
|
58
|
-
});
|
|
59
|
-
});
|
|
60
|
-
});
|
package/src/utils/setValue.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import {isProtectedKey} from "./isProtectedKey.js";
|
|
2
|
-
|
|
3
|
-
export function setValue(scope: any, expression: string, value: any, separator = ".") {
|
|
4
|
-
const keys: string[] = expression.split(separator);
|
|
5
|
-
|
|
6
|
-
const setValue = (key: string, add: boolean) => {
|
|
7
|
-
if (isProtectedKey(key)) {
|
|
8
|
-
return false;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
if (add) {
|
|
12
|
-
if (typeof scope.set === "function") {
|
|
13
|
-
scope.set(key, value);
|
|
14
|
-
} else {
|
|
15
|
-
scope[key] = value;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
return false;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
if (typeof scope.set === "function") {
|
|
22
|
-
if (!scope.has(key)) {
|
|
23
|
-
scope.set(key, {});
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
scope = scope.get(key);
|
|
27
|
-
} else {
|
|
28
|
-
scope = scope[key] = scope[key] || {};
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
return true;
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
while (setValue(keys.shift()!, !keys.length)) {}
|
|
35
|
-
}
|
package/src/utils/toMap.spec.ts
DELETED
|
@@ -1,211 +0,0 @@
|
|
|
1
|
-
import {toMap} from "./toMap.js";
|
|
2
|
-
|
|
3
|
-
describe("toMap", () => {
|
|
4
|
-
describe("from Object", () => {
|
|
5
|
-
it("should create map", () => {
|
|
6
|
-
const result = toMap({
|
|
7
|
-
test: {top: "test"},
|
|
8
|
-
test1: {top: "test1"}
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
expect(result).toBeInstanceOf(Map);
|
|
12
|
-
expect(result.size).toBe(2);
|
|
13
|
-
expect([...result.keys()]).toEqual(["test", "test1"]);
|
|
14
|
-
expect([...result.values()]).toEqual([{top: "test"}, {top: "test1"}]);
|
|
15
|
-
});
|
|
16
|
-
it("should create map by id", () => {
|
|
17
|
-
const result = toMap(
|
|
18
|
-
{
|
|
19
|
-
test: {id: "1", top: "test"},
|
|
20
|
-
test1: {id: "2", top: "test1"},
|
|
21
|
-
test3: {id: "1", top: "test"}
|
|
22
|
-
},
|
|
23
|
-
"id"
|
|
24
|
-
);
|
|
25
|
-
|
|
26
|
-
expect(result).toBeInstanceOf(Map);
|
|
27
|
-
expect(result.size).toBe(2);
|
|
28
|
-
expect([...result.keys()]).toEqual(["1", "2"]);
|
|
29
|
-
expect([...result.values()]).toEqual([
|
|
30
|
-
{
|
|
31
|
-
id: "1",
|
|
32
|
-
top: "test"
|
|
33
|
-
},
|
|
34
|
-
{
|
|
35
|
-
id: "2",
|
|
36
|
-
top: "test1"
|
|
37
|
-
}
|
|
38
|
-
]);
|
|
39
|
-
});
|
|
40
|
-
it("should create map by fn id", () => {
|
|
41
|
-
const result = toMap(
|
|
42
|
-
{
|
|
43
|
-
test: {id: "1", top: "test"},
|
|
44
|
-
test1: {id: "2", top: "test1"},
|
|
45
|
-
test3: {id: "1", top: "test"}
|
|
46
|
-
},
|
|
47
|
-
(item) => item.id
|
|
48
|
-
);
|
|
49
|
-
|
|
50
|
-
expect(result).toBeInstanceOf(Map);
|
|
51
|
-
expect(result.size).toBe(2);
|
|
52
|
-
expect([...result.keys()]).toEqual(["1", "2"]);
|
|
53
|
-
expect([...result.values()]).toEqual([
|
|
54
|
-
{
|
|
55
|
-
id: "1",
|
|
56
|
-
top: "test"
|
|
57
|
-
},
|
|
58
|
-
{
|
|
59
|
-
id: "2",
|
|
60
|
-
top: "test1"
|
|
61
|
-
}
|
|
62
|
-
]);
|
|
63
|
-
});
|
|
64
|
-
});
|
|
65
|
-
describe("from Array", () => {
|
|
66
|
-
it("should create map", () => {
|
|
67
|
-
const result = toMap([
|
|
68
|
-
{
|
|
69
|
-
id: "1",
|
|
70
|
-
top: "test"
|
|
71
|
-
},
|
|
72
|
-
{
|
|
73
|
-
id: "2",
|
|
74
|
-
top: "test1"
|
|
75
|
-
},
|
|
76
|
-
{
|
|
77
|
-
id: "1",
|
|
78
|
-
top: "test"
|
|
79
|
-
}
|
|
80
|
-
]);
|
|
81
|
-
|
|
82
|
-
expect(result).toBeInstanceOf(Map);
|
|
83
|
-
expect(result.size).toBe(2);
|
|
84
|
-
expect([...result.keys()]).toEqual(["1", "2"]);
|
|
85
|
-
expect([...result.values()]).toEqual([
|
|
86
|
-
{
|
|
87
|
-
id: "1",
|
|
88
|
-
top: "test"
|
|
89
|
-
},
|
|
90
|
-
{
|
|
91
|
-
id: "2",
|
|
92
|
-
top: "test1"
|
|
93
|
-
}
|
|
94
|
-
]);
|
|
95
|
-
});
|
|
96
|
-
it("should create map by id", () => {
|
|
97
|
-
const result = toMap(
|
|
98
|
-
[
|
|
99
|
-
{
|
|
100
|
-
id: "1",
|
|
101
|
-
top: "test"
|
|
102
|
-
},
|
|
103
|
-
{
|
|
104
|
-
id: "2",
|
|
105
|
-
top: "test1"
|
|
106
|
-
},
|
|
107
|
-
{
|
|
108
|
-
id: "1",
|
|
109
|
-
top: "test"
|
|
110
|
-
}
|
|
111
|
-
],
|
|
112
|
-
"id"
|
|
113
|
-
);
|
|
114
|
-
|
|
115
|
-
expect(result).toBeInstanceOf(Map);
|
|
116
|
-
expect(result.size).toBe(2);
|
|
117
|
-
expect([...result.keys()]).toEqual(["1", "2"]);
|
|
118
|
-
expect([...result.values()]).toEqual([
|
|
119
|
-
{
|
|
120
|
-
id: "1",
|
|
121
|
-
top: "test"
|
|
122
|
-
},
|
|
123
|
-
{
|
|
124
|
-
id: "2",
|
|
125
|
-
top: "test1"
|
|
126
|
-
}
|
|
127
|
-
]);
|
|
128
|
-
});
|
|
129
|
-
it("should create map by fn id", () => {
|
|
130
|
-
const result = toMap(
|
|
131
|
-
[
|
|
132
|
-
{
|
|
133
|
-
id: "1",
|
|
134
|
-
top: "test"
|
|
135
|
-
},
|
|
136
|
-
{
|
|
137
|
-
id: "2",
|
|
138
|
-
top: "test1"
|
|
139
|
-
},
|
|
140
|
-
{
|
|
141
|
-
id: "1",
|
|
142
|
-
top: "test"
|
|
143
|
-
}
|
|
144
|
-
],
|
|
145
|
-
(item) => item.id
|
|
146
|
-
);
|
|
147
|
-
|
|
148
|
-
expect(result).toBeInstanceOf(Map);
|
|
149
|
-
expect(result.size).toBe(2);
|
|
150
|
-
expect([...result.keys()]).toEqual(["1", "2"]);
|
|
151
|
-
expect([...result.values()]).toEqual([
|
|
152
|
-
{
|
|
153
|
-
id: "1",
|
|
154
|
-
top: "test"
|
|
155
|
-
},
|
|
156
|
-
{
|
|
157
|
-
id: "2",
|
|
158
|
-
top: "test1"
|
|
159
|
-
}
|
|
160
|
-
]);
|
|
161
|
-
});
|
|
162
|
-
it("should create map by fn id + merge", () => {
|
|
163
|
-
class Data {
|
|
164
|
-
id: string;
|
|
165
|
-
count: string;
|
|
166
|
-
|
|
167
|
-
constructor(opts: any) {
|
|
168
|
-
this.id = opts.id;
|
|
169
|
-
this.count = opts.count;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
merge(d: Data) {
|
|
173
|
-
this.count += d.count;
|
|
174
|
-
return this;
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
const result = toMap(
|
|
179
|
-
[
|
|
180
|
-
new Data({
|
|
181
|
-
id: "1",
|
|
182
|
-
count: 5
|
|
183
|
-
}),
|
|
184
|
-
new Data({
|
|
185
|
-
id: "2",
|
|
186
|
-
count: 5
|
|
187
|
-
}),
|
|
188
|
-
new Data({
|
|
189
|
-
id: "1",
|
|
190
|
-
count: 10
|
|
191
|
-
})
|
|
192
|
-
],
|
|
193
|
-
(item) => item.id
|
|
194
|
-
);
|
|
195
|
-
|
|
196
|
-
expect(result).toBeInstanceOf(Map);
|
|
197
|
-
expect(result.size).toBe(2);
|
|
198
|
-
expect([...result.keys()]).toEqual(["1", "2"]);
|
|
199
|
-
expect([...result.values()]).toEqual([
|
|
200
|
-
{
|
|
201
|
-
count: 15,
|
|
202
|
-
id: "1"
|
|
203
|
-
},
|
|
204
|
-
{
|
|
205
|
-
count: 5,
|
|
206
|
-
id: "2"
|
|
207
|
-
}
|
|
208
|
-
]);
|
|
209
|
-
});
|
|
210
|
-
});
|
|
211
|
-
});
|
package/src/utils/toMap.ts
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import {isArray} from "./isArray.js";
|
|
2
|
-
import {isString} from "./isString.js";
|
|
3
|
-
|
|
4
|
-
export type ToMapIdentityCB<V> = (item: V, index: string | number) => string | string[];
|
|
5
|
-
export type ToMapIdentity<V> = string | ToMapIdentityCB<V>;
|
|
6
|
-
|
|
7
|
-
function createIdentityFn<V>(keyOrFn?: ToMapIdentity<V>): ToMapIdentityCB<V> {
|
|
8
|
-
if (!keyOrFn) {
|
|
9
|
-
return (v, k) => String(k);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
if (isString(keyOrFn)) {
|
|
13
|
-
return (item: any) => {
|
|
14
|
-
return item[keyOrFn as string];
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
return keyOrFn;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export function toMap<K extends keyof any = any, V = any>(input: Record<K, V> | V[], keyOrFn?: ToMapIdentity<V>): Map<K, V> {
|
|
22
|
-
if (isArray<V>(input)) {
|
|
23
|
-
const identity = createIdentityFn<V>(keyOrFn || "id");
|
|
24
|
-
return input.reduce((map, value, index) => {
|
|
25
|
-
const ids = ([] as string[]).concat(identity(value, index));
|
|
26
|
-
|
|
27
|
-
ids.forEach((id) => {
|
|
28
|
-
const item = map.get(id);
|
|
29
|
-
|
|
30
|
-
value = item?.merge?.(value) || value;
|
|
31
|
-
|
|
32
|
-
map.set(id, value);
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
return map;
|
|
36
|
-
}, new Map());
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const identity = createIdentityFn<V>(keyOrFn);
|
|
40
|
-
|
|
41
|
-
return Object.entries(input).reduce((map, [key, value]) => {
|
|
42
|
-
return map.set(identity(value as V, key), value);
|
|
43
|
-
}, new Map());
|
|
44
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import {constructorOf} from "./constructorOf.js";
|
|
2
|
-
|
|
3
|
-
export function toStringConstructor(target: any): string {
|
|
4
|
-
const ctr = constructorOf(target);
|
|
5
|
-
const strings = ctr.toString().split("\n");
|
|
6
|
-
const ctrString = strings.find((s) => s.indexOf("constructor(") > -1) || "constructor()";
|
|
7
|
-
|
|
8
|
-
return `${ctrString.replace("{", "").trim()}`;
|
|
9
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import {toStringConstructor} from "./toStringConstructor.js";
|
|
2
|
-
|
|
3
|
-
describe("toStringConstructor", () => {
|
|
4
|
-
it("should return the constructor signature (empty)", () => {
|
|
5
|
-
class Test {}
|
|
6
|
-
|
|
7
|
-
expect(toStringConstructor(Test)).toBe("constructor()");
|
|
8
|
-
});
|
|
9
|
-
it("should return the constructor signature", () => {
|
|
10
|
-
class Test {
|
|
11
|
-
constructor(test: string) {
|
|
12
|
-
console.log("test");
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
expect(toStringConstructor(Test)).toBe("constructor(test)");
|
|
17
|
-
});
|
|
18
|
-
});
|
package/src/utils/uniq.spec.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import {uniq, uniqBy} from "./uniq.js";
|
|
2
|
-
|
|
3
|
-
describe("uniq", () => {
|
|
4
|
-
it("should return uniq item", () => {
|
|
5
|
-
expect(uniq(["test", "test1", "test"])).toEqual(["test", "test1"]);
|
|
6
|
-
expect(uniqBy([{id: "test"}, {id: "test1"}, {id: "test"}], "id")).toEqual([{id: "test"}, {id: "test1"}]);
|
|
7
|
-
});
|
|
8
|
-
});
|
package/src/utils/uniq.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @param list
|
|
3
|
-
*/
|
|
4
|
-
export function uniq<T = any>(list: T[]): T[] {
|
|
5
|
-
return Array.from(new Set(list).values());
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export function uniqBy<T = any>(list: T[], key = "id"): T[] {
|
|
9
|
-
const map = new Map();
|
|
10
|
-
|
|
11
|
-
list.forEach((item: any) => {
|
|
12
|
-
map.set(item[key], item);
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
return Array.from(map.values());
|
|
16
|
-
}
|