@tsed/core 6.114.16 → 6.115.0
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/jest.config.js +1 -1
- package/lib/cjs/domain/AnyToPromise.js +17 -19
- package/lib/cjs/domain/AnyToPromise.js.map +1 -1
- package/lib/cjs/domain/Hooks.js +1 -3
- package/lib/cjs/domain/Hooks.js.map +1 -1
- package/lib/cjs/domain/Metadata.js +5 -5
- package/lib/cjs/domain/Metadata.js.map +1 -1
- package/lib/cjs/domain/Store.js +1 -3
- package/lib/cjs/domain/Store.js.map +1 -1
- package/lib/cjs/errors/UnsupportedDecoratorType.js +1 -0
- package/lib/cjs/errors/UnsupportedDecoratorType.js.map +1 -1
- package/lib/cjs/utils/objects/descriptorOf.js +1 -2
- package/lib/cjs/utils/objects/descriptorOf.js.map +1 -1
- package/lib/esm/domain/AnyToPromise.js +17 -19
- package/lib/esm/domain/AnyToPromise.js.map +1 -1
- package/lib/esm/domain/Hooks.js +1 -3
- package/lib/esm/domain/Hooks.js.map +1 -1
- package/lib/esm/domain/Metadata.js +5 -5
- package/lib/esm/domain/Metadata.js.map +1 -1
- package/lib/esm/domain/Store.js +1 -3
- package/lib/esm/domain/Store.js.map +1 -1
- package/lib/esm/errors/UnsupportedDecoratorType.js +1 -0
- package/lib/esm/errors/UnsupportedDecoratorType.js.map +1 -1
- package/lib/esm/utils/objects/descriptorOf.js +1 -2
- package/lib/esm/utils/objects/descriptorOf.js.map +1 -1
- package/package.json +1 -1
package/jest.config.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var _AnyToPromise_resolves, _AnyToPromise_rejects, _AnyToPromise_hasNextFunction, _AnyToPromise_promise;
|
|
3
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
3
|
exports.AnyToPromise = exports.AnyToPromiseResponseTypes = exports.AnyToPromiseStatus = void 0;
|
|
5
|
-
const tslib_1 = require("tslib");
|
|
6
4
|
const isObservable_1 = require("../utils/objects/isObservable");
|
|
7
5
|
const isPromise_1 = require("../utils/objects/isPromise");
|
|
8
6
|
const isStream_1 = require("../utils/objects/isStream");
|
|
@@ -29,23 +27,24 @@ var AnyToPromiseResponseTypes;
|
|
|
29
27
|
AnyToPromiseResponseTypes["DATA"] = "DATA";
|
|
30
28
|
})(AnyToPromiseResponseTypes = exports.AnyToPromiseResponseTypes || (exports.AnyToPromiseResponseTypes = {}));
|
|
31
29
|
class AnyToPromise {
|
|
30
|
+
status = AnyToPromiseStatus.PENDING;
|
|
31
|
+
args;
|
|
32
|
+
#resolves;
|
|
33
|
+
#rejects;
|
|
34
|
+
#hasNextFunction = false;
|
|
35
|
+
#promise;
|
|
32
36
|
constructor({ hasNextFunction = false } = {}) {
|
|
33
|
-
this
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
tslib_1.__classPrivateFieldSet(this, _AnyToPromise_hasNextFunction, hasNextFunction, "f");
|
|
39
|
-
tslib_1.__classPrivateFieldSet(this, _AnyToPromise_promise, new Promise((resolve, reject) => {
|
|
40
|
-
tslib_1.__classPrivateFieldSet(this, _AnyToPromise_resolves, resolve, "f");
|
|
41
|
-
tslib_1.__classPrivateFieldSet(this, _AnyToPromise_rejects, reject, "f");
|
|
42
|
-
}), "f");
|
|
37
|
+
this.#hasNextFunction = hasNextFunction;
|
|
38
|
+
this.#promise = new Promise((resolve, reject) => {
|
|
39
|
+
this.#resolves = resolve;
|
|
40
|
+
this.#rejects = reject;
|
|
41
|
+
});
|
|
43
42
|
}
|
|
44
43
|
isDone() {
|
|
45
44
|
return this.status !== AnyToPromiseStatus.PENDING;
|
|
46
45
|
}
|
|
47
46
|
get next() {
|
|
48
|
-
|
|
47
|
+
this.#hasNextFunction = true;
|
|
49
48
|
return (error) => {
|
|
50
49
|
if (this.isDone()) {
|
|
51
50
|
return;
|
|
@@ -66,21 +65,21 @@ class AnyToPromise {
|
|
|
66
65
|
catch (er) {
|
|
67
66
|
this.reject(er);
|
|
68
67
|
}
|
|
69
|
-
return
|
|
68
|
+
return this.#promise;
|
|
70
69
|
}
|
|
71
70
|
reject(er) {
|
|
72
71
|
if (this.isDone()) {
|
|
73
72
|
return;
|
|
74
73
|
}
|
|
75
74
|
this.done(AnyToPromiseStatus.REJECTED);
|
|
76
|
-
|
|
75
|
+
this.#rejects(er);
|
|
77
76
|
}
|
|
78
77
|
resolve(response = {}) {
|
|
79
78
|
if (this.isDone()) {
|
|
80
79
|
return;
|
|
81
80
|
}
|
|
82
81
|
this.done(AnyToPromiseStatus.RESOLVED);
|
|
83
|
-
|
|
82
|
+
this.#resolves({ ...response, state: AnyToPromiseStatus.RESOLVED });
|
|
84
83
|
}
|
|
85
84
|
destroy() { }
|
|
86
85
|
cancel() {
|
|
@@ -88,7 +87,7 @@ class AnyToPromise {
|
|
|
88
87
|
return;
|
|
89
88
|
}
|
|
90
89
|
this.done(AnyToPromiseStatus.CANCELED);
|
|
91
|
-
return
|
|
90
|
+
return this.#resolves({ state: AnyToPromiseStatus.CANCELED });
|
|
92
91
|
}
|
|
93
92
|
done(status) {
|
|
94
93
|
this.destroy();
|
|
@@ -130,7 +129,7 @@ class AnyToPromise {
|
|
|
130
129
|
});
|
|
131
130
|
}
|
|
132
131
|
}
|
|
133
|
-
if (!
|
|
132
|
+
if (!this.#hasNextFunction) {
|
|
134
133
|
// no next function and empty response
|
|
135
134
|
return this.resolve({
|
|
136
135
|
...additionalProps,
|
|
@@ -144,5 +143,4 @@ class AnyToPromise {
|
|
|
144
143
|
}
|
|
145
144
|
}
|
|
146
145
|
exports.AnyToPromise = AnyToPromise;
|
|
147
|
-
_AnyToPromise_resolves = new WeakMap(), _AnyToPromise_rejects = new WeakMap(), _AnyToPromise_hasNextFunction = new WeakMap(), _AnyToPromise_promise = new WeakMap();
|
|
148
146
|
//# sourceMappingURL=AnyToPromise.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AnyToPromise.js","sourceRoot":"","sources":["../../../src/domain/AnyToPromise.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"AnyToPromise.js","sourceRoot":"","sources":["../../../src/domain/AnyToPromise.ts"],"names":[],"mappings":";;;AAAA,gEAA2D;AAC3D,0DAAqD;AACrD,wDAAmD;AAEnD;;GAEG;AACH,SAAS,UAAU,CAAC,GAAQ;IAC1B,OAAO,GAAG,CAAC,IAAI,IAAI,GAAG,CAAC,OAAO,IAAI,GAAG,CAAC,MAAM,IAAI,GAAG,CAAC,UAAU,CAAC;AACjE,CAAC;AAED;;GAEG;AACH,IAAY,kBAKX;AALD,WAAY,kBAAkB;IAC5B,yCAAmB,CAAA;IACnB,2CAAqB,CAAA;IACrB,2CAAqB,CAAA;IACrB,2CAAqB,CAAA;AACvB,CAAC,EALW,kBAAkB,GAAlB,0BAAkB,KAAlB,0BAAkB,QAK7B;AAED,IAAY,yBAIX;AAJD,WAAY,yBAAyB;IACnC,8CAAiB,CAAA;IACjB,8CAAiB,CAAA;IACjB,0CAAa,CAAA;AACf,CAAC,EAJW,yBAAyB,GAAzB,iCAAyB,KAAzB,iCAAyB,QAIpC;AAUD,MAAa,YAAY;IAChB,MAAM,GAAG,kBAAkB,CAAC,OAAO,CAAC;IACpC,IAAI,CAAQ;IAEnB,SAAS,CAAM;IACf,QAAQ,CAAM;IACd,gBAAgB,GAAG,KAAK,CAAC;IAEhB,QAAQ,CAA+B;IAEhD,YAAY,EAAC,eAAe,GAAG,KAAK,KAAiC,EAAE;QACrE,IAAI,CAAC,gBAAgB,GAAG,eAAe,CAAC;QAExC,IAAI,CAAC,QAAQ,GAAG,IAAI,OAAO,CAAC,CAAC,OAAY,EAAE,MAAW,EAAE,EAAE;YACxD,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC;YACzB,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC;QACzB,CAAC,CAAC,CAAC;IACL,CAAC;IAED,MAAM;QACJ,OAAO,IAAI,CAAC,MAAM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,CAAC,EAAC,GAAG,eAAe,EAAE,IAAI,EAAE,yBAAyB,CAAC,MAAM,EAAE,IAAI,EAAE,OAAO,EAAC,CAAC,CAAC;aAClG;YAED,IAAI,IAAA,qBAAS,EAAC,OAAO,CAAC,EAAE;gBACtB,OAAO,OAAO;qBACX,IAAI,CAAC,CAAC,MAAW,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;qBAC3D,KAAK,CAAC,CAAC,KAAU,EAAE,EAAE;oBACpB,IAAI,KAAK,CAAC,QAAQ,IAAI,UAAU,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE;wBAChD,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;qBACpC;oBACD,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;gBAC5B,CAAC,CAAC,CAAC;aACN;SACF;QAED,IAAI,CAAC,IAAI,CAAC,gBAAgB,EAAE;YAC1B,sCAAsC;YACtC,OAAO,IAAI,CAAC,OAAO,CAAC;gBAClB,GAAG,eAAe;gBAClB,IAAI,EAAE,OAAO;gBACb,IAAI,EAAE,yBAAyB,CAAC,IAAI;aACrC,CAAC,CAAC;SACJ;IACH,CAAC;IAES,kBAAkB,CAAC,OAAY;QACvC,OAAO,OAAO,KAAK,kBAAkB,CAAC,QAAQ,CAAC;IACjD,CAAC;CACF;AAhJD,oCAgJC","sourcesContent":["import {isObservable} from \"../utils/objects/isObservable\";\nimport {isPromise} from \"../utils/objects/isPromise\";\nimport {isStream} from \"../utils/objects/isStream\";\n\n/**\n * @ignore\n */\nfunction isResponse(obj: any) {\n return obj.data && obj.headers && obj.status && obj.statusText;\n}\n\n/**\n * @ignore\n */\nexport enum AnyToPromiseStatus {\n PENDING = \"PENDING\",\n CANCELED = \"CANCELED\",\n RESOLVED = \"RESOLVED\",\n REJECTED = \"REJECTED\"\n}\n\nexport enum AnyToPromiseResponseTypes {\n STREAM = \"STREAM\",\n BUFFER = \"BUFFER\",\n DATA = \"DATA\"\n}\n\nexport interface AnyPromiseResult<T = any> {\n state: AnyToPromiseStatus;\n type: AnyToPromiseResponseTypes;\n status?: number;\n headers?: Record<string, any>;\n data: T;\n}\n\nexport class AnyToPromise<T = any> {\n public status = AnyToPromiseStatus.PENDING;\n public args: any[];\n\n #resolves: any;\n #rejects: any;\n #hasNextFunction = false;\n\n readonly #promise: Promise<AnyPromiseResult<T>>;\n\n constructor({hasNextFunction = false}: {hasNextFunction?: boolean} = {}) {\n this.#hasNextFunction = hasNextFunction;\n\n this.#promise = new Promise((resolve: any, reject: any) => {\n this.#resolves = resolve;\n this.#rejects = reject;\n });\n }\n\n isDone(): boolean {\n return this.status !== AnyToPromiseStatus.PENDING;\n }\n\n get next() {\n this.#hasNextFunction = true;\n\n return (error?: any) => {\n if (this.isDone()) {\n return;\n }\n\n return error ? this.reject(error) : this.resolve({type: AnyToPromiseResponseTypes.DATA});\n };\n }\n\n /**\n *\n */\n async call(cb: Function): Promise<AnyPromiseResult<T>> {\n if (this.isDone()) {\n return this as any;\n }\n\n try {\n this.handle(cb());\n } catch (er) {\n this.reject(er);\n }\n\n return this.#promise;\n }\n\n reject(er: any) {\n if (this.isDone()) {\n return;\n }\n\n this.done(AnyToPromiseStatus.REJECTED);\n\n this.#rejects(er);\n }\n\n resolve(response: any = {}) {\n if (this.isDone()) {\n return;\n }\n\n this.done(AnyToPromiseStatus.RESOLVED);\n\n this.#resolves({...response, state: AnyToPromiseStatus.RESOLVED});\n }\n\n destroy() {}\n\n cancel() {\n if (this.isDone()) {\n return;\n }\n\n this.done(AnyToPromiseStatus.CANCELED);\n\n return this.#resolves({state: AnyToPromiseStatus.CANCELED});\n }\n\n done(status: AnyToPromiseStatus) {\n this.destroy();\n this.status = status;\n }\n\n handle(process: any, additionalProps = {}): any {\n if (this.isDone()) {\n return;\n }\n\n if (process) {\n if (this.isCanceledResponse(process)) {\n // ABANDON\n return this.cancel();\n }\n\n if (isObservable(process)) {\n process = process.toPromise();\n }\n\n if (isResponse(process)) {\n return this.handle(process.data, {\n ...additionalProps,\n status: process.status,\n headers: process.headers\n });\n }\n\n if (isStream(process)) {\n return this.resolve({...additionalProps, type: AnyToPromiseResponseTypes.STREAM, data: process});\n }\n if (isStream(process) || Buffer.isBuffer(process)) {\n return this.resolve({...additionalProps, type: AnyToPromiseResponseTypes.BUFFER, data: process});\n }\n\n if (isPromise(process)) {\n return process\n .then((result: any) => this.handle(result, additionalProps))\n .catch((error: any) => {\n if (error.response && isResponse(error.response)) {\n return this.handle(error.response);\n }\n return this.reject(error);\n });\n }\n }\n\n if (!this.#hasNextFunction) {\n // no next function and empty response\n return this.resolve({\n ...additionalProps,\n data: process,\n type: AnyToPromiseResponseTypes.DATA\n });\n }\n }\n\n protected isCanceledResponse(process: any) {\n return process === AnyToPromiseStatus.CANCELED;\n }\n}\n"]}
|
package/lib/cjs/domain/Hooks.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Hooks.js","sourceRoot":"","sources":["../../../src/domain/Hooks.ts"],"names":[],"mappings":";;;AAAA,MAAa,KAAK;
|
|
1
|
+
{"version":3,"file":"Hooks.js","sourceRoot":"","sources":["../../../src/domain/Hooks.ts"],"names":[],"mappings":";;;AAAA,MAAa,KAAK;IACR,SAAS,GAA4B,IAAI,GAAG,EAAE,CAAC;IAEvD;;;;OAIG;IACH,EAAE,CAAC,KAAa,EAAE,EAAY;QAC5B,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE;YAC9B,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;SAC/B;QAED,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,KAAK,CAAE,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAEpC,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;OAIG;IACH,GAAG,CAAC,KAAa,EAAE,EAA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E;gBAC3C,MAAM,EAAE,CAAC,IAAI,CAAC,QAAQ,EAAE,GAAG,IAAI,CAAC,CAAC;aAClC;SACF;IACH,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,UAAU,CAAC,KAAa,EAAE,KAAU,EAAE,OAAiB,EAAE,EAAE,WAAgB,IAAI;QACnF,IAAI,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE;YAC7B,KAAK,MAAM,EAAE,IAAI,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,KAAK,CAAE,EAAE;gBAC3C,KAAK,GAAG,MAAM,EAAE,CAAC,IAAI,CAAC,QAAQ,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC,CAAC;aACjD;SACF;QAED,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AA/FD,sBA+FC","sourcesContent":["export class Hooks {\n private listeners: Map<string, Function[]> = new Map();\n\n /**\n * Listen a hook event\n * @param event\n * @param cb\n */\n on(event: string, cb: Function) {\n if (!this.listeners.has(event)) {\n this.listeners.set(event, []);\n }\n\n this.listeners.get(event)!.push(cb);\n\n return this;\n }\n\n /**\n * Remove a listener attached to an event\n * @param event\n * @param cb\n */\n off(event: string, cb: Function) {\n if (this.listeners.has(event)) {\n this.listeners.set(\n event,\n this.listeners.get(event)!.filter((item) => item === cb)\n );\n }\n\n return this;\n }\n\n /**\n * Trigger an event and call listener.\n * @param event\n * @param args\n * @param callThis\n */\n emit(event: string, args: any[] = [], callThis: any = null): void {\n if (this.listeners.has(event)) {\n for (const cb of this.listeners.get(event)!) {\n cb.call(callThis, ...args);\n }\n }\n }\n\n /**\n * Trigger an event, listener alter given value and return it.\n * @param event\n * @param value\n * @param args\n * @param callThis\n */\n alter(event: string, value: any, args: any[] = [], callThis: any = null): any {\n if (this.listeners.has(event)) {\n for (const cb of this.listeners.get(event)!) {\n value = cb.call(callThis, value, ...args);\n }\n }\n\n return value;\n }\n\n /**\n * Trigger an event and call async listener.\n * @param event\n * @param args\n * @param callThis\n */\n async asyncEmit(event: string, args: any[] = [], callThis: any = null): Promise<void> {\n if (this.listeners.has(event)) {\n for (const cb of this.listeners.get(event)!) {\n await cb.call(callThis, ...args);\n }\n }\n }\n\n /**\n * Trigger an event, async listener alter given value and return it.\n * @param event\n * @param value\n * @param args\n * @param callThis\n */\n async asyncAlter(event: string, value: any, args: string[] = [], callThis: any = null): Promise<any> {\n if (this.listeners.has(event)) {\n for (const cb of this.listeners.get(event)!) {\n value = await cb.call(callThis, value, ...args);\n }\n }\n\n return value;\n }\n}\n"]}
|
|
@@ -387,6 +387,11 @@ class Metadata {
|
|
|
387
387
|
static setParamTypes(target, propertyKey, value) {
|
|
388
388
|
return this.set(DESIGN_PARAM_TYPES, value, target.prototype, propertyKey);
|
|
389
389
|
}
|
|
390
|
+
/**
|
|
391
|
+
* Get all metadata for a metadataKey.
|
|
392
|
+
* @param metadataKey
|
|
393
|
+
*/
|
|
394
|
+
static getTargetsFromPropertyKey = (metadataKey) => PROPERTIES.has(metadataKey) ? PROPERTIES.get(metadataKey) || [] : [];
|
|
390
395
|
/**
|
|
391
396
|
* Define a unique metadata entry on the target.
|
|
392
397
|
* @param key A key used to store and retrieve metadata.
|
|
@@ -500,9 +505,4 @@ class Metadata {
|
|
|
500
505
|
}
|
|
501
506
|
}
|
|
502
507
|
exports.Metadata = Metadata;
|
|
503
|
-
/**
|
|
504
|
-
* Get all metadata for a metadataKey.
|
|
505
|
-
* @param metadataKey
|
|
506
|
-
*/
|
|
507
|
-
Metadata.getTargetsFromPropertyKey = (metadataKey) => PROPERTIES.has(metadataKey) ? PROPERTIES.get(metadataKey) || [] : [];
|
|
508
508
|
//# sourceMappingURL=Metadata.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Metadata.js","sourceRoot":"","sources":["../../../src/domain/Metadata.ts"],"names":[],"mappings":";;;AAAA,4BAA0B;AAC1B,sDAAiD;AAEjD;;;;GAIG;AACH,MAAM,kBAAkB,GAAG,m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";\nimport {classOf} from \"../utils/objects/classOf\";\n\n/**\n * Metadata key\n * @private\n * @type {string}\n */\nconst DESIGN_PARAM_TYPES = \"design:paramtypes\";\n/**\n * Metadata key\n * @private\n * @type {string}\n */\nconst DESIGN_TYPE = \"design:type\";\n/**\n * Metadata key\n * @private\n * @type {string}\n */\nconst DESIGN_RETURN_TYPE = \"design:returntype\";\n\n/**\n * Properties collections\n * @private\n * @type {string}\n */\nconst PROPERTIES: Map<string | symbol, any[]> = new Map<string | symbol, any[]>();\n\n/**\n * @stable\n */\nexport class Metadata {\n /**\n * Gets the metadata value for the provided metadata key on the target object or its prototype chain.\n * @param key A key used to store and retrieve metadata.\n * @param target The target object on which the metadata is defined.\n * @param propertyKey The property key for the target.\n * @returns The metadata value for the metadata key if found; otherwise, `undefined`.\n * @example\n *\n * ```typescript\n * class Example {\n * // property declarations are not part of ES6, though they are valid in TypeScript:\n * // static staticProperty;\n * // property;\n *\n * static staticMethod(p) { }\n * method(p) { }\n * }\n *\n * // constructor\n * result = Metadata.get(\"custom:annotation\", Example);\n *\n * // property (on constructor)\n * result = Metadata.get(\"custom:annotation\", Example, \"staticProperty\");\n *\n * // property (on prototype)\n * result = Metadata.get(\"custom:annotation\", Example.prototype, \"property\");\n *\n * // method (on constructor)\n * result = Metadata.get(\"custom:annotation\", Example, \"staticMethod\");\n *\n * // method (on prototype)\n * result = Metadata.get(\"custom:annotation\", Example.prototype, \"method\");\n * ```\n *\n */\n static get(key: string, target: any, propertyKey?: string | symbol): any {\n return Reflect.getMetadata(key, classOf(target), propertyKey!);\n }\n\n /**\n * Gets the metadata value for the provided metadata key on the target object or its prototype chain.\n * @param key A key used to store and retrieve metadata.\n * @param target The target object on which the metadata is defined.\n * @param propertyKey The property key for the target.\n * @returns The metadata value for the metadata key if found; otherwise, `undefined`.\n * @example\n *\n * ```typescript\n * class Example {\n * // property declarations are not part of ES6, though they are valid in TypeScript:\n * // static staticProperty;\n * // property;\n *\n * static staticMethod(p) { }\n * method(p) { }\n * }\n *\n * // constructor\n * result = Metadata.getOwn(\"custom:annotation\", Example);\n *\n * // property (on constructor)\n * result = Metadata.getOwn(\"custom:annotation\", Example, \"staticProperty\");\n *\n * // property (on prototype)\n * result = Metadata.getOwn(\"custom:annotation\", Example.prototype, \"property\");\n *\n * // method (on constructor)\n * result = Metadata.getOwn(\"custom:annotation\", Example, \"staticMethod\");\n *\n * // method (on prototype)\n * result = Metadata.getOwn(\"custom:annotation\", Example.prototype, \"method\");\n * ```\n *\n */\n static getOwn(key: string, target: any, propertyKey?: string | symbol): any {\n return Reflect.getOwnMetadata(key, classOf(target), propertyKey!);\n }\n\n /**\n * Gets the metadata value for the provided metadata DESIGN_TYPE on the target object or its prototype chain.\n * @param target The target object on which the metadata is defined.\n * @param propertyKey The property key for the target.\n * @returns The metadata value for the metadata key if found; otherwise, `undefined`.\n * @example\n *\n * ```typescript\n * class Example {\n * // property declarations are not part of ES6, though they are valid in TypeScript:\n * // static staticProperty;\n * // property;\n *\n * static staticMethod(p) { }\n * method(p) { }\n * }\n *\n * // on contructor\n * result = Metadata.getType(Example);\n *\n * // property (on constructor)\n * result = Metadata.getType(Example, \"staticProperty\");\n *\n * // method (on constructor)\n * result = Metadata.getType(Example, \"staticMethod\");\n * ```\n *\n */\n static getType(target: any, propertyKey?: string | symbol): any {\n return Reflect.getMetadata(DESIGN_TYPE, target, propertyKey!);\n }\n\n /**\n * Gets the metadata value for the provided metadata DESIGN_TYPE on the target object or its prototype chain.\n * @param target The target object on which the metadata is defined.\n * @param propertyKey The property key for the target.\n * @returns The metadata value for the metadata key if found; otherwise, `undefined`.\n * @example\n *\n * ```typescript\n * class Example {\n * // property declarations are not part of ES6, though they are valid in TypeScript:\n * // static staticProperty;\n * // property;\n *\n * static staticMethod(p) { }\n * method(p) { }\n * }\n *\n * // on contructor\n * result = Metadata.getOwnType(Example);\n *\n * // property (on constructor)\n * result = Metadata.getOwnType(Example, \"staticProperty\");\n *\n * // method (on constructor)\n * result = Metadata.getOwnType(Example, \"staticMethod\");\n * ```\n *\n */\n static getOwnType(target: any, propertyKey?: string | symbol): any {\n return Reflect.getMetadata(DESIGN_TYPE, target, propertyKey!);\n }\n\n /**\n * Gets the metadata value for the provided metadata DESIGN_RETURN_TYPE on the target object or its prototype chain.\n * @param target The target object on which the metadata is defined.\n * @param propertyKey The property key for the target.\n * @returns The metadata value for the metadata key if found; otherwise, `undefined`.\n * @example\n *\n * ```typescript\n * class Example {\n * // property declarations are not part of ES6, though they are valid in TypeScript:\n * // static staticProperty;\n * // property;\n *\n * static staticMethod(p) { }\n * method(p) { }\n * }\n *\n * // on contructor\n * result = Metadata.getReturnType(Example);\n *\n * // property (on constructor)\n * result = Metadata.getReturnType(Example, \"staticProperty\");\n *\n * // method (on constructor)\n * result = Metadata.getReturnType(Example, \"staticMethod\");\n * ```\n *\n */\n static getReturnType(target: any, propertyKey?: string | symbol): any {\n return Reflect.getMetadata(DESIGN_RETURN_TYPE, target, propertyKey!);\n }\n\n /**\n * Gets the metadata value for the provided metadata DESIGN_RETURN_TYPE on the target object or its prototype chain.\n * @param target The target object on which the metadata is defined.\n * @param propertyKey The property key for the target.\n * @returns The metadata value for the metadata key if found; otherwise, `undefined`.\n * @example\n *\n * ```typescript\n * class Example {\n * // property declarations are not part of ES6, though they are valid in TypeScript:\n * // static staticProperty;\n * // property;\n *\n * static staticMethod(p) { }\n * method(p) { }\n * }\n *\n * // on contructor\n * result = Metadata.getOwnReturnType(Example);\n *\n * // property (on constructor)\n * result = Metadata.getOwnReturnType(Example, \"staticProperty\");\n *\n * // method (on constructor)\n * result = Metadata.getOwnReturnType(Example, \"staticMethod\");\n * ```\n *\n */\n static getOwnReturnType(target: any, propertyKey?: string | symbol): any {\n return Reflect.getOwnMetadata(DESIGN_RETURN_TYPE, target, propertyKey!);\n }\n\n /**\n * Gets a value indicating whether the target object or its prototype chain has the provided metadata key defined.\n * @param key A key used to store and retrieve metadata.\n * @param target The target object on which the metadata is defined.\n * @param propertyKey The property key for the target.\n * @returns `true` if the metadata key was defined on the target object or its prototype chain; otherwise, `false`.\n * @example\n *\n * ```typescript\n * class Example {\n * // property declarations are not part of ES6, though they are valid in TypeScript:\n * // static staticProperty;\n * // property;\n *\n * static staticMethod(p) { }\n * method(p) { }\n * }\n *\n * // constructor\n * result = Metadata.has(\"custom:annotation\", Example);\n *\n * // property (on constructor)\n * result = Metadata.has(\"custom:annotation\", Example, \"staticProperty\");\n *\n * // property (on prototype)\n * result = Metadata.has(\"custom:annotation\", Example.prototype, \"property\");\n *\n * // method (on constructor)\n * result = Metadata.has(\"custom:annotation\", Example, \"staticMethod\");\n *\n * // method (on prototype)\n * result = Metadata.has(\"custom:annotation\", Example.prototype, \"method\");\n * ```\n *\n */\n static has(key: string, target: any, propertyKey?: string | symbol): boolean {\n try {\n return Reflect.hasMetadata(key, classOf(target), propertyKey!);\n } catch (er) {}\n\n return false;\n }\n\n /**\n * Gets a value indicating whether the target object or its prototype chain has the provided metadata key defined.\n * @param key A key used to store and retrieve metadata.\n * @param target The target object on which the metadata is defined.\n * @param propertyKey The property key for the target.\n * @returns `true` if the metadata key was defined on the target object or its prototype chain; otherwise, `false`.\n * @example\n *\n * ```typescript\n * class Example {\n * // property declarations are not part of ES6, though they are valid in TypeScript:\n * // static staticProperty;\n * // property;\n *\n * static staticMethod(p) { }\n * method(p) { }\n * }\n *\n * // constructor\n * result = Metadata.has(\"custom:annotation\", Example);\n *\n * // property (on constructor)\n * result = Metadata.hasOwn(\"custom:annotation\", Example, \"staticProperty\");\n *\n * // property (on prototype)\n * result = Metadata.hasOwn(\"custom:annotation\", Example.prototype, \"property\");\n *\n * // method (on constructor)\n * result = Metadata.hasOwn(\"custom:annotation\", Example, \"staticMethod\");\n *\n * // method (on prototype)\n * result = Metadata.hasOwn(\"custom:annotation\", Example.prototype, \"method\");\n * ```\n *\n */\n static hasOwn(key: string, target: any, propertyKey?: string | symbol): boolean {\n return Reflect.hasOwnMetadata(key, classOf(target), propertyKey!);\n }\n\n /**\n * Deletes the metadata entry from the target object with the provided key.\n * @param key A key used to store and retrieve metadata.\n * @param target The target object on which the metadata is defined.\n * @param propertyKey The property key for the target.\n * @returns `true` if the metadata entry was found and deleted; otherwise, false.\n * @example\n *\n * ```typescript\n * class Example {\n * // property declarations are not part of ES6, though they are valid in TypeScript:\n * // static staticProperty;\n * // property;\n *\n * static staticMethod(p) { }\n * method(p) { }\n * }\n *\n * // constructor\n * result = Metadata.delete(\"custom:annotation\", Example);\n *\n * // property (on constructor)\n * result = Metadata.delete(\"custom:annotation\", Example, \"staticProperty\");\n *\n * // property (on prototype)\n * result = Metadata.delete(\"custom:annotation\", Example.prototype, \"property\");\n *\n * // method (on constructor)\n * result = Metadata.delete(\"custom:annotation\", Example, \"staticMethod\");\n *\n * // method (on prototype)\n * result = Metadata.delete(\"custom:annotation\", Example.prototype, \"method\");\n * ```\n *\n */\n static delete(key: string, target: any, propertyKey?: string | symbol): boolean {\n return Reflect.deleteMetadata(key, classOf(target), propertyKey!);\n }\n\n /**\n * Set the metadata value for the provided metadata DESIGN_PARAM_TYPES on the target object or its prototype chain.\n * @param target The target object on which the metadata is defined.\n * @param propertyKey The property key for the target.\n * @param value A value that contains attached metadata.\n * @returns The metadata value for the metadata key if found; otherwise, `undefined`.\n * @example\n *\n * ```typescript\n * class Example {\n * // property declarations are not part of ES6, though they are valid in TypeScript:\n * // static staticProperty;\n * // property;\n *\n * static staticMethod(p) { }\n * method(p) { }\n * }\n *\n * // on contructor\n * result = Metadata.setParamTypes(Example, undefined, [Object]);\n *\n * // property (on constructor)\n * result = Metadata.setParamTypes(Example, \"staticProperty\", [Object]);\n *\n * // property (on prototype)\n * result = Metadata.setParamTypes(Example.prototype, \"property\", [Object]);\n *\n * // method (on constructor)\n * result = Metadata.setParamTypes(Example, \"staticMethod\", [Object]);\n *\n * // method (on prototype)\n * result = Metadata.setParamTypes(Example.prototype, \"method\", [Object]);\n * ```\n *\n */\n static setParamTypes(target: any, propertyKey: string | symbol, value: any): void {\n return this.set(DESIGN_PARAM_TYPES, value, target.prototype, propertyKey);\n }\n\n /**\n * Get all metadata for a metadataKey.\n * @param metadataKey\n */\n static getTargetsFromPropertyKey = (metadataKey: string | symbol): any[] =>\n PROPERTIES.has(metadataKey) ? PROPERTIES.get(metadataKey) || [] : [];\n\n /**\n * Define a unique metadata entry on the target.\n * @param key A key used to store and retrieve metadata.\n * @param value A value that contains attached metadata.\n * @param target The target object on which to define metadata.\n * @param propertyKey The property key for the target.\n * @example\n *\n * ```typescript\n * class Example {\n * // property declarations are not part of ES6, though they are valid in TypeScript:\n * // static staticProperty;\n * // property;\n *\n * static staticMethod(p) { }\n * method(p) { }\n * }\n *\n * // constructor\n * Reflect.defineMetadata(\"custom:annotation\", options, Example);\n *\n * // property (on constructor)\n * Reflect.defineMetadata(\"custom:annotation\", Number, Example, \"staticProperty\");\n *\n * // property (on prototype)\n * Reflect.defineMetadata(\"custom:annotation\", Number, Example.prototype, \"property\");\n *\n * // method (on constructor)\n * Reflect.defineMetadata(\"custom:annotation\", Number, Example, \"staticMethod\");\n *\n * // method (on prototype)\n * Reflect.defineMetadata(\"custom:annotation\", Number, Example.prototype, \"method\");\n *\n * // decorator factory as metadata-producing annotation.\n * function MyAnnotation(options): PropertyDecorator {\n * return (target, key) => Reflect.defineMetadata(\"custom:annotation\", options, target, key);\n * }\n * ```\n *\n */\n static set(key: string, value: any, target: any, propertyKey?: string | symbol): void {\n const targets: any[] = PROPERTIES.has(key) ? PROPERTIES.get(key) || [] : [];\n const classConstructor = classOf(target);\n\n if (targets.indexOf(classConstructor) === -1) {\n targets.push(classConstructor);\n PROPERTIES.set(key, targets);\n }\n\n Reflect.defineMetadata(key, value, classOf(target), propertyKey!);\n }\n\n /**\n * Gets the metadata value for the provided metadata DESIGN_PARAM_TYPES on the target object or its prototype chain.\n * @param targetPrototype\n * @param propertyKey The property key for the target.\n * @returns The metadata value for the metadata key if found; otherwise, `undefined`.\n * @example\n *\n * ```typescript\n * class Example {\n * // property declarations are not part of ES6, though they are valid in TypeScript:\n * // static staticProperty;\n * // property;\n *\n * static staticMethod(p) { }\n * method(p) { }\n * }\n *\n * // on contructor\n * result = Metadata.getParamTypes(Example.prototype);\n *\n * // property (on constructor)\n * result = Metadata.getParamTypes(Example.prototype, \"staticProperty\");\n *\n * // method (on constructor)\n * result = Metadata.getParamTypes(Example.prototype, \"staticMethod\");\n * ```\n *\n */\n static getParamTypes(targetPrototype: any, propertyKey?: string | symbol): any[] {\n return Reflect.getMetadata(DESIGN_PARAM_TYPES, targetPrototype, propertyKey!) || [];\n }\n\n /**\n * Gets the metadata value for the provided metadata DESIGN_PARAM_TYPES on the target object or its prototype chain.\n * @param target The target object on which the metadata is defined.\n * @param propertyKey The property key for the target.\n * @returns The metadata value for the metadata key if found; otherwise, `undefined`.\n * @example\n *\n * ```typescript\n * class Example {\n * // property declarations are not part of ES6, though they are valid in TypeScript:\n * // static staticProperty;\n * // property;\n *\n * static staticMethod(p) { }\n * method(p) { }\n * }\n *\n * // on contructor\n * result = Metadata.getParamTypes(Example);\n *\n * // property (on constructor)\n * result = Metadata.getParamTypes(Example, \"staticProperty\");\n *\n * // method (on constructor)\n * result = Metadata.getParamTypes(Example, \"staticMethod\");\n * ```\n *\n */\n static getOwnParamTypes(target: any, propertyKey?: string | symbol): any[] {\n return Reflect.getOwnMetadata(DESIGN_PARAM_TYPES, target, propertyKey!) || [];\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"Metadata.js","sourceRoot":"","sources":["../../../src/domain/Metadata.ts"],"names":[],"mappings":";;;AAAA,4BAA0B;AAC1B,sDAAiD;AAEjD;;;;GAIG;AACH,MAAM,kBAAkB,GAAG,mBAAmB,CAAC;AAC/C;;;;GAIG;AACH,MAAM,WAAW,GAAG,aAAa,CAAC;AAClC;;;;GAIG;AACH,MAAM,kBAAkB,GAAG,mBAAmB,CAAC;AAE/C;;;;GAIG;AACH,MAAM,UAAU,GAAgC,IAAI,GAAG,EAA0B,CAAC;AAElF;;GAEG;AACH,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AM,CAAC,GAAG,CAAC,GAAW,EAAE,KAAU,EAAE,MAAW,EAAE,WAA6B;QAC5E,MAAM,OAAO,GAAU,UAAU,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC5E,MAAM,gBAAgB,GAAG,IAAA,iBAAO,EAAC,MAAM,CAAC,CAAC;QAEzC,IAAI,OAAO,CAAC,OAAO,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAC,EAAE;YAC5C,OAAO,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;YAC/B,UAAU,CAAC,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;SAC9B;QAED,OAAO,CAAC,cAAc,CAAC,GAAG,EAAE,KAAK,EAAE,IAAA,iBAAO,EAAC,MAAM,CAAC,EAAE,WAAY,CAAC,CAAC;IACpE,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2BG;IACH,MAAM,CAAC,aAAa,CAAC,eAAoB,EAAE,WAA6B;QACtE,OAAO,OAAO,CAAC,WAAW,CAAC,kBAAkB,EAAE,eAAe,EAAE,WAAY,CAAC,IAAI,EAAE,CAAC;IACtF,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2BG;IACH,MAAM,CAAC,gBAAgB,CAAC,MAAW,EAAE,WAA6B;QAChE,OAAO,OAAO,CAAC,cAAc,CAAC,kBAAkB,EAAE,MAAM,EAAE,WAAY,CAAC,IAAI,EAAE,CAAC;IAChF,CAAC;;AAxeH,4BAyeC","sourcesContent":["import \"reflect-metadata\";\nimport {classOf} from \"../utils/objects/classOf\";\n\n/**\n * Metadata key\n * @private\n * @type {string}\n */\nconst DESIGN_PARAM_TYPES = \"design:paramtypes\";\n/**\n * Metadata key\n * @private\n * @type {string}\n */\nconst DESIGN_TYPE = \"design:type\";\n/**\n * Metadata key\n * @private\n * @type {string}\n */\nconst DESIGN_RETURN_TYPE = \"design:returntype\";\n\n/**\n * Properties collections\n * @private\n * @type {string}\n */\nconst PROPERTIES: Map<string | symbol, any[]> = new Map<string | symbol, any[]>();\n\n/**\n * @stable\n */\nexport class Metadata {\n /**\n * Gets the metadata value for the provided metadata key on the target object or its prototype chain.\n * @param key A key used to store and retrieve metadata.\n * @param target The target object on which the metadata is defined.\n * @param propertyKey The property key for the target.\n * @returns The metadata value for the metadata key if found; otherwise, `undefined`.\n * @example\n *\n * ```typescript\n * class Example {\n * // property declarations are not part of ES6, though they are valid in TypeScript:\n * // static staticProperty;\n * // property;\n *\n * static staticMethod(p) { }\n * method(p) { }\n * }\n *\n * // constructor\n * result = Metadata.get(\"custom:annotation\", Example);\n *\n * // property (on constructor)\n * result = Metadata.get(\"custom:annotation\", Example, \"staticProperty\");\n *\n * // property (on prototype)\n * result = Metadata.get(\"custom:annotation\", Example.prototype, \"property\");\n *\n * // method (on constructor)\n * result = Metadata.get(\"custom:annotation\", Example, \"staticMethod\");\n *\n * // method (on prototype)\n * result = Metadata.get(\"custom:annotation\", Example.prototype, \"method\");\n * ```\n *\n */\n static get(key: string, target: any, propertyKey?: string | symbol): any {\n return Reflect.getMetadata(key, classOf(target), propertyKey!);\n }\n\n /**\n * Gets the metadata value for the provided metadata key on the target object or its prototype chain.\n * @param key A key used to store and retrieve metadata.\n * @param target The target object on which the metadata is defined.\n * @param propertyKey The property key for the target.\n * @returns The metadata value for the metadata key if found; otherwise, `undefined`.\n * @example\n *\n * ```typescript\n * class Example {\n * // property declarations are not part of ES6, though they are valid in TypeScript:\n * // static staticProperty;\n * // property;\n *\n * static staticMethod(p) { }\n * method(p) { }\n * }\n *\n * // constructor\n * result = Metadata.getOwn(\"custom:annotation\", Example);\n *\n * // property (on constructor)\n * result = Metadata.getOwn(\"custom:annotation\", Example, \"staticProperty\");\n *\n * // property (on prototype)\n * result = Metadata.getOwn(\"custom:annotation\", Example.prototype, \"property\");\n *\n * // method (on constructor)\n * result = Metadata.getOwn(\"custom:annotation\", Example, \"staticMethod\");\n *\n * // method (on prototype)\n * result = Metadata.getOwn(\"custom:annotation\", Example.prototype, \"method\");\n * ```\n *\n */\n static getOwn(key: string, target: any, propertyKey?: string | symbol): any {\n return Reflect.getOwnMetadata(key, classOf(target), propertyKey!);\n }\n\n /**\n * Gets the metadata value for the provided metadata DESIGN_TYPE on the target object or its prototype chain.\n * @param target The target object on which the metadata is defined.\n * @param propertyKey The property key for the target.\n * @returns The metadata value for the metadata key if found; otherwise, `undefined`.\n * @example\n *\n * ```typescript\n * class Example {\n * // property declarations are not part of ES6, though they are valid in TypeScript:\n * // static staticProperty;\n * // property;\n *\n * static staticMethod(p) { }\n * method(p) { }\n * }\n *\n * // on contructor\n * result = Metadata.getType(Example);\n *\n * // property (on constructor)\n * result = Metadata.getType(Example, \"staticProperty\");\n *\n * // method (on constructor)\n * result = Metadata.getType(Example, \"staticMethod\");\n * ```\n *\n */\n static getType(target: any, propertyKey?: string | symbol): any {\n return Reflect.getMetadata(DESIGN_TYPE, target, propertyKey!);\n }\n\n /**\n * Gets the metadata value for the provided metadata DESIGN_TYPE on the target object or its prototype chain.\n * @param target The target object on which the metadata is defined.\n * @param propertyKey The property key for the target.\n * @returns The metadata value for the metadata key if found; otherwise, `undefined`.\n * @example\n *\n * ```typescript\n * class Example {\n * // property declarations are not part of ES6, though they are valid in TypeScript:\n * // static staticProperty;\n * // property;\n *\n * static staticMethod(p) { }\n * method(p) { }\n * }\n *\n * // on contructor\n * result = Metadata.getOwnType(Example);\n *\n * // property (on constructor)\n * result = Metadata.getOwnType(Example, \"staticProperty\");\n *\n * // method (on constructor)\n * result = Metadata.getOwnType(Example, \"staticMethod\");\n * ```\n *\n */\n static getOwnType(target: any, propertyKey?: string | symbol): any {\n return Reflect.getMetadata(DESIGN_TYPE, target, propertyKey!);\n }\n\n /**\n * Gets the metadata value for the provided metadata DESIGN_RETURN_TYPE on the target object or its prototype chain.\n * @param target The target object on which the metadata is defined.\n * @param propertyKey The property key for the target.\n * @returns The metadata value for the metadata key if found; otherwise, `undefined`.\n * @example\n *\n * ```typescript\n * class Example {\n * // property declarations are not part of ES6, though they are valid in TypeScript:\n * // static staticProperty;\n * // property;\n *\n * static staticMethod(p) { }\n * method(p) { }\n * }\n *\n * // on contructor\n * result = Metadata.getReturnType(Example);\n *\n * // property (on constructor)\n * result = Metadata.getReturnType(Example, \"staticProperty\");\n *\n * // method (on constructor)\n * result = Metadata.getReturnType(Example, \"staticMethod\");\n * ```\n *\n */\n static getReturnType(target: any, propertyKey?: string | symbol): any {\n return Reflect.getMetadata(DESIGN_RETURN_TYPE, target, propertyKey!);\n }\n\n /**\n * Gets the metadata value for the provided metadata DESIGN_RETURN_TYPE on the target object or its prototype chain.\n * @param target The target object on which the metadata is defined.\n * @param propertyKey The property key for the target.\n * @returns The metadata value for the metadata key if found; otherwise, `undefined`.\n * @example\n *\n * ```typescript\n * class Example {\n * // property declarations are not part of ES6, though they are valid in TypeScript:\n * // static staticProperty;\n * // property;\n *\n * static staticMethod(p) { }\n * method(p) { }\n * }\n *\n * // on contructor\n * result = Metadata.getOwnReturnType(Example);\n *\n * // property (on constructor)\n * result = Metadata.getOwnReturnType(Example, \"staticProperty\");\n *\n * // method (on constructor)\n * result = Metadata.getOwnReturnType(Example, \"staticMethod\");\n * ```\n *\n */\n static getOwnReturnType(target: any, propertyKey?: string | symbol): any {\n return Reflect.getOwnMetadata(DESIGN_RETURN_TYPE, target, propertyKey!);\n }\n\n /**\n * Gets a value indicating whether the target object or its prototype chain has the provided metadata key defined.\n * @param key A key used to store and retrieve metadata.\n * @param target The target object on which the metadata is defined.\n * @param propertyKey The property key for the target.\n * @returns `true` if the metadata key was defined on the target object or its prototype chain; otherwise, `false`.\n * @example\n *\n * ```typescript\n * class Example {\n * // property declarations are not part of ES6, though they are valid in TypeScript:\n * // static staticProperty;\n * // property;\n *\n * static staticMethod(p) { }\n * method(p) { }\n * }\n *\n * // constructor\n * result = Metadata.has(\"custom:annotation\", Example);\n *\n * // property (on constructor)\n * result = Metadata.has(\"custom:annotation\", Example, \"staticProperty\");\n *\n * // property (on prototype)\n * result = Metadata.has(\"custom:annotation\", Example.prototype, \"property\");\n *\n * // method (on constructor)\n * result = Metadata.has(\"custom:annotation\", Example, \"staticMethod\");\n *\n * // method (on prototype)\n * result = Metadata.has(\"custom:annotation\", Example.prototype, \"method\");\n * ```\n *\n */\n static has(key: string, target: any, propertyKey?: string | symbol): boolean {\n try {\n return Reflect.hasMetadata(key, classOf(target), propertyKey!);\n } catch (er) {}\n\n return false;\n }\n\n /**\n * Gets a value indicating whether the target object or its prototype chain has the provided metadata key defined.\n * @param key A key used to store and retrieve metadata.\n * @param target The target object on which the metadata is defined.\n * @param propertyKey The property key for the target.\n * @returns `true` if the metadata key was defined on the target object or its prototype chain; otherwise, `false`.\n * @example\n *\n * ```typescript\n * class Example {\n * // property declarations are not part of ES6, though they are valid in TypeScript:\n * // static staticProperty;\n * // property;\n *\n * static staticMethod(p) { }\n * method(p) { }\n * }\n *\n * // constructor\n * result = Metadata.has(\"custom:annotation\", Example);\n *\n * // property (on constructor)\n * result = Metadata.hasOwn(\"custom:annotation\", Example, \"staticProperty\");\n *\n * // property (on prototype)\n * result = Metadata.hasOwn(\"custom:annotation\", Example.prototype, \"property\");\n *\n * // method (on constructor)\n * result = Metadata.hasOwn(\"custom:annotation\", Example, \"staticMethod\");\n *\n * // method (on prototype)\n * result = Metadata.hasOwn(\"custom:annotation\", Example.prototype, \"method\");\n * ```\n *\n */\n static hasOwn(key: string, target: any, propertyKey?: string | symbol): boolean {\n return Reflect.hasOwnMetadata(key, classOf(target), propertyKey!);\n }\n\n /**\n * Deletes the metadata entry from the target object with the provided key.\n * @param key A key used to store and retrieve metadata.\n * @param target The target object on which the metadata is defined.\n * @param propertyKey The property key for the target.\n * @returns `true` if the metadata entry was found and deleted; otherwise, false.\n * @example\n *\n * ```typescript\n * class Example {\n * // property declarations are not part of ES6, though they are valid in TypeScript:\n * // static staticProperty;\n * // property;\n *\n * static staticMethod(p) { }\n * method(p) { }\n * }\n *\n * // constructor\n * result = Metadata.delete(\"custom:annotation\", Example);\n *\n * // property (on constructor)\n * result = Metadata.delete(\"custom:annotation\", Example, \"staticProperty\");\n *\n * // property (on prototype)\n * result = Metadata.delete(\"custom:annotation\", Example.prototype, \"property\");\n *\n * // method (on constructor)\n * result = Metadata.delete(\"custom:annotation\", Example, \"staticMethod\");\n *\n * // method (on prototype)\n * result = Metadata.delete(\"custom:annotation\", Example.prototype, \"method\");\n * ```\n *\n */\n static delete(key: string, target: any, propertyKey?: string | symbol): boolean {\n return Reflect.deleteMetadata(key, classOf(target), propertyKey!);\n }\n\n /**\n * Set the metadata value for the provided metadata DESIGN_PARAM_TYPES on the target object or its prototype chain.\n * @param target The target object on which the metadata is defined.\n * @param propertyKey The property key for the target.\n * @param value A value that contains attached metadata.\n * @returns The metadata value for the metadata key if found; otherwise, `undefined`.\n * @example\n *\n * ```typescript\n * class Example {\n * // property declarations are not part of ES6, though they are valid in TypeScript:\n * // static staticProperty;\n * // property;\n *\n * static staticMethod(p) { }\n * method(p) { }\n * }\n *\n * // on contructor\n * result = Metadata.setParamTypes(Example, undefined, [Object]);\n *\n * // property (on constructor)\n * result = Metadata.setParamTypes(Example, \"staticProperty\", [Object]);\n *\n * // property (on prototype)\n * result = Metadata.setParamTypes(Example.prototype, \"property\", [Object]);\n *\n * // method (on constructor)\n * result = Metadata.setParamTypes(Example, \"staticMethod\", [Object]);\n *\n * // method (on prototype)\n * result = Metadata.setParamTypes(Example.prototype, \"method\", [Object]);\n * ```\n *\n */\n static setParamTypes(target: any, propertyKey: string | symbol, value: any): void {\n return this.set(DESIGN_PARAM_TYPES, value, target.prototype, propertyKey);\n }\n\n /**\n * Get all metadata for a metadataKey.\n * @param metadataKey\n */\n static getTargetsFromPropertyKey = (metadataKey: string | symbol): any[] =>\n PROPERTIES.has(metadataKey) ? PROPERTIES.get(metadataKey) || [] : [];\n\n /**\n * Define a unique metadata entry on the target.\n * @param key A key used to store and retrieve metadata.\n * @param value A value that contains attached metadata.\n * @param target The target object on which to define metadata.\n * @param propertyKey The property key for the target.\n * @example\n *\n * ```typescript\n * class Example {\n * // property declarations are not part of ES6, though they are valid in TypeScript:\n * // static staticProperty;\n * // property;\n *\n * static staticMethod(p) { }\n * method(p) { }\n * }\n *\n * // constructor\n * Reflect.defineMetadata(\"custom:annotation\", options, Example);\n *\n * // property (on constructor)\n * Reflect.defineMetadata(\"custom:annotation\", Number, Example, \"staticProperty\");\n *\n * // property (on prototype)\n * Reflect.defineMetadata(\"custom:annotation\", Number, Example.prototype, \"property\");\n *\n * // method (on constructor)\n * Reflect.defineMetadata(\"custom:annotation\", Number, Example, \"staticMethod\");\n *\n * // method (on prototype)\n * Reflect.defineMetadata(\"custom:annotation\", Number, Example.prototype, \"method\");\n *\n * // decorator factory as metadata-producing annotation.\n * function MyAnnotation(options): PropertyDecorator {\n * return (target, key) => Reflect.defineMetadata(\"custom:annotation\", options, target, key);\n * }\n * ```\n *\n */\n static set(key: string, value: any, target: any, propertyKey?: string | symbol): void {\n const targets: any[] = PROPERTIES.has(key) ? PROPERTIES.get(key) || [] : [];\n const classConstructor = classOf(target);\n\n if (targets.indexOf(classConstructor) === -1) {\n targets.push(classConstructor);\n PROPERTIES.set(key, targets);\n }\n\n Reflect.defineMetadata(key, value, classOf(target), propertyKey!);\n }\n\n /**\n * Gets the metadata value for the provided metadata DESIGN_PARAM_TYPES on the target object or its prototype chain.\n * @param targetPrototype\n * @param propertyKey The property key for the target.\n * @returns The metadata value for the metadata key if found; otherwise, `undefined`.\n * @example\n *\n * ```typescript\n * class Example {\n * // property declarations are not part of ES6, though they are valid in TypeScript:\n * // static staticProperty;\n * // property;\n *\n * static staticMethod(p) { }\n * method(p) { }\n * }\n *\n * // on contructor\n * result = Metadata.getParamTypes(Example.prototype);\n *\n * // property (on constructor)\n * result = Metadata.getParamTypes(Example.prototype, \"staticProperty\");\n *\n * // method (on constructor)\n * result = Metadata.getParamTypes(Example.prototype, \"staticMethod\");\n * ```\n *\n */\n static getParamTypes(targetPrototype: any, propertyKey?: string | symbol): any[] {\n return Reflect.getMetadata(DESIGN_PARAM_TYPES, targetPrototype, propertyKey!) || [];\n }\n\n /**\n * Gets the metadata value for the provided metadata DESIGN_PARAM_TYPES on the target object or its prototype chain.\n * @param target The target object on which the metadata is defined.\n * @param propertyKey The property key for the target.\n * @returns The metadata value for the metadata key if found; otherwise, `undefined`.\n * @example\n *\n * ```typescript\n * class Example {\n * // property declarations are not part of ES6, though they are valid in TypeScript:\n * // static staticProperty;\n * // property;\n *\n * static staticMethod(p) { }\n * method(p) { }\n * }\n *\n * // on contructor\n * result = Metadata.getParamTypes(Example);\n *\n * // property (on constructor)\n * result = Metadata.getParamTypes(Example, \"staticProperty\");\n *\n * // method (on constructor)\n * result = Metadata.getParamTypes(Example, \"staticMethod\");\n * ```\n *\n */\n static getOwnParamTypes(target: any, propertyKey?: string | symbol): any[] {\n return Reflect.getOwnMetadata(DESIGN_PARAM_TYPES, target, propertyKey!) || [];\n }\n}\n"]}
|
package/lib/cjs/domain/Store.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Store.js","sourceRoot":"","sources":["../../../src/domain/Store.ts"],"names":[],"mappings":";;;AAAA,6DAAwD;AACxD,yEAAoE;AACpE,0DAAqD;AACrD,0DAAqD;AACrD,gEAA2D;AAC3D,wDAAmD;AACnD,oDAA+C;AAC/C,yCAAoC;AAGpC;;GAEG;AACU,QAAA,WAAW,GAAG,kBAAkB,CAAC;AAC9C;;GAEG;AACU,QAAA,YAAY,GAAG,mBAAmB,CAAC;AAChD;;GAEG;AACU,QAAA,cAAc,GAAG,qBAAqB,CAAC;AACpD;;GAEG;AACU,QAAA,WAAW,GAAG,kBAAkB,CAAC;AAE9C,MAAM,MAAM,GAAG,IAAI,GAAG,EAAiB,CAAC;AAExC,SAAS,QAAQ,CAAC,GAAW,EAAE,GAAG,IAAW;IAC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\"../domain/DecoratorTypes\";\nimport {decoratorTypeOf} from \"../utils/decorators/decoratorTypeOf\";\nimport {deepClone} from \"../utils/objects/deepClone\";\nimport {deepMerge} from \"../utils/objects/deepMerge\";\nimport {descriptorOf} from \"../utils/objects/descriptorOf\";\nimport {isSymbol} from \"../utils/objects/isSymbol\";\nimport {nameOf} from \"../utils/objects/nameOf\";\nimport {Metadata} from \"./Metadata\";\nimport type {Type} from \"./Type\";\n\n/**\n * @ignore\n */\nexport const CLASS_STORE = \"tsed:class:store\";\n/**\n * @ignore\n */\nexport const METHOD_STORE = \"tsed:method:store\";\n/**\n * @ignore\n */\nexport const PROPERTY_STORE = \"tsed:property:store\";\n/**\n * @ignore\n */\nexport const PARAM_STORE = \"tsed:param:store\";\n\nconst stores = new Map<symbol, Store>();\n\nfunction storeGet(key: string, ...args: any[]): Store {\n if (isSymbol(args[0])) {\n if (!stores.has(args[0])) {\n stores.set(args[0], new Store());\n }\n\n return stores.get(args[0])!;\n } else {\n const registry = Metadata as any;\n\n if (!registry.hasOwn(key, ...args)) {\n registry.set(key, new Store(), ...args);\n }\n\n return registry.getOwn(key, ...args);\n }\n}\n\nfunction defineStore(args: any[]): Store {\n const [target, propertyKey, descriptor] = args;\n\n switch (decoratorTypeOf(args)) {\n case DecoratorTypes.PARAM_CTOR:\n case DecoratorTypes.PARAM_STC:\n case DecoratorTypes.PARAM:\n const store = storeGet(PARAM_STORE, target, propertyKey);\n if (!store.has(\"\" + descriptor)) {\n store.set(\"\" + descriptor, new Store());\n }\n\n return store.get(\"\" + descriptor);\n case DecoratorTypes.PROP:\n case DecoratorTypes.PROP_STC:\n return storeGet(PROPERTY_STORE, target, propertyKey);\n case DecoratorTypes.METHOD:\n case DecoratorTypes.METHOD_STC:\n return storeGet(METHOD_STORE, target, propertyKey);\n case DecoratorTypes.CLASS:\n return storeGet(CLASS_STORE, target);\n }\n}\n\nexport class Store {\n private _entries = new Map<string, any>();\n /**\n * Create or get a Store from args {target + methodName + descriptor}\n * @param args\n * @returns {Store}\n */\n static from(...args: any[]): Store {\n return defineStore(args);\n }\n\n /**\n * Create store on the method.\n * @param target\n * @param {string} propertyKey\n * @returns {Store}\n */\n static fromMethod(target: any, propertyKey: string | symbol): Store {\n return Store.from(target, propertyKey, descriptorOf(target, propertyKey));\n }\n\n static mergeStoreFrom(target: Type<any>, source: Type<any>, ...args: any[]) {\n const store = Store.from(target, ...args);\n\n Store.from(source, ...args)._entries.forEach((value, key) => {\n store.merge(key, value);\n });\n\n return store;\n }\n\n static mergeStoreMethodFrom(target: Type<any>, source: Type<any>, propertyKey: string | symbol) {\n return this.mergeStoreFrom(target, source, propertyKey, descriptorOf(target, propertyKey));\n }\n\n /**\n * The get() method returns a specified element from a Map object.\n * @param key Required. The key of the element to return from the Map object.\n * @param defaultValue\n * @returns {T} Returns the element associated with the specified key or undefined if the key can't be found in the Map object.\n */\n get<T = any>(key: any, defaultValue?: any): T {\n return this._entries.get(nameOf(key)) || defaultValue;\n }\n\n /**\n * The has() method returns a boolean indicating whether an element with the specified key exists or not.\n * @param key\n * @returns {boolean}\n */\n has(key: any): boolean {\n return this._entries.has(nameOf(key));\n }\n\n /**\n * The set() method adds or updates an element with a specified key and value to a Map object.\n * @param key Required. The key of the element to add to the Map object.\n * @param metadata Required. The value of the element to add to the Map object.\n */\n set(key: any, metadata: any): Store {\n this._entries.set(nameOf(key), metadata);\n\n return this;\n }\n\n /**\n * The delete() method removes the specified element from a Map object.\n * @param key Required. The key of the element to remove from the Map object.\n * @returns {boolean} Returns true if an element in the Map object existed and has been removed, or false if the element does not exist.\n */\n delete(key: string): boolean {\n return this._entries.delete(nameOf(key));\n }\n\n /**\n * Merge given value with existing value.\n * @param key\n * @param value\n * @param inverse Change the merge order. Get the existing value and apply over given value\n * @returns {Store}\n */\n merge(key: any, value: any, inverse: boolean = false): Store {\n let _value_ = this.get(key);\n\n if (_value_) {\n value = deepClone(value);\n _value_ = deepClone(_value_);\n value = inverse ? deepMerge(value, _value_) : deepMerge(_value_, value);\n }\n\n this.set(key, value);\n\n return this;\n }\n\n toJson() {\n return [...this._entries.entries()].reduce((obj, [key, value]) => {\n return {\n ...obj,\n [key]: value\n };\n }, {});\n }\n}\n"]}
|
|
@@ -5,6 +5,7 @@ const decoratorTypeOf_1 = require("../utils/decorators/decoratorTypeOf");
|
|
|
5
5
|
const classOf_1 = require("../utils/objects/classOf");
|
|
6
6
|
const nameOf_1 = require("../utils/objects/nameOf");
|
|
7
7
|
class UnsupportedDecoratorType extends Error {
|
|
8
|
+
name;
|
|
8
9
|
constructor(decorator, args) {
|
|
9
10
|
super(UnsupportedDecoratorType.buildMessage(decorator, args));
|
|
10
11
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UnsupportedDecoratorType.js","sourceRoot":"","sources":["../../../src/errors/UnsupportedDecoratorType.ts"],"names":[],"mappings":";;;AAAA,yEAAoE;AACpE,sDAAiD;AACjD,oDAA+C;AAE/C,MAAa,wBAAyB,SAAQ,KAAK;
|
|
1
|
+
{"version":3,"file":"UnsupportedDecoratorType.js","sourceRoot":"","sources":["../../../src/errors/UnsupportedDecoratorType.ts"],"names":[],"mappings":";;;AAAA,yEAAoE;AACpE,sDAAiD;AACjD,oDAA+C;AAE/C,MAAa,wBAAyB,SAAQ,KAAK;IACjD,IAAI,CAA+B;IAEnC,YAAY,SAAc,EAAE,IAAW;QACrC,KAAK,CAAC,wBAAwB,CAAC,YAAY,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC,CAAC;IAChE,CAAC;IAEO,MAAM,CAAC,YAAY,CAAC,SAAc,EAAE,IAAW;QACrD,MAAM,CAAC,MAAM,EAAE,WAAW,EAAE,KAAK,CAAC,GAAG,IAAI,CAAC;QAE1C,MAAM,WAAW,GAAG,IAAA,iCAAe,EAAC,IAAI,CAAC,CAAC;QAC1C,MAAM,YAAY,GAAG,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;QAC/C,MAAM,KAAK,GAAG,YAAY,KAAK,WAAW,CAAC,CAAC,CAAC,IAAI,GAAG,KAAK,GAAG,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;QACrE,MAAM,IAAI,GAAG,YAAY,KAAK,WAAW,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE,CAAC;QAChE,MAAM,MAAM,GAAG,WAAW,CAAC,CAAC,CAAC,GAAG,GAAG,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC;QAEtD,MAAM,IAAI,GAAG,IAAA,eAAM,EAAC,IAAA,iBAAO,EAAC,MAAM,CAAC,CAAC,GAAG,MAAM,GAAG,KAAK,CAAC;QAEtD,OAAO,GAAG,SAAS,CAAC,IAAI,sBAAsB,WAAW,iBAAiB,IAAI,EAAE,CAAC;IACnF,CAAC;CACF;AApBD,4DAoBC","sourcesContent":["import {decoratorTypeOf} from \"../utils/decorators/decoratorTypeOf\";\nimport {classOf} from \"../utils/objects/classOf\";\nimport {nameOf} from \"../utils/objects/nameOf\";\n\nexport class UnsupportedDecoratorType extends Error {\n name: \"UNSUPPORTED_DECORATOR_TYPE\";\n\n constructor(decorator: any, args: any[]) {\n super(UnsupportedDecoratorType.buildMessage(decorator, args));\n }\n\n private static buildMessage(decorator: any, args: any[]): string {\n const [target, propertyKey, index] = args;\n\n const bindingType = decoratorTypeOf(args);\n const shortBinding = bindingType.split(\"/\")[0];\n const param = shortBinding === \"parameter\" ? \".[\" + index + \"]\" : \"\";\n const cstr = shortBinding === \"parameter\" ? \".constructor\" : \"\";\n const method = propertyKey ? \".\" + propertyKey : cstr;\n\n const path = nameOf(classOf(target)) + method + param;\n\n return `${decorator.name} cannot be used as ${bindingType} decorator on ${path}`;\n }\n}\n"]}
|
|
@@ -12,8 +12,7 @@ function descriptorOf(target, propertyKey) {
|
|
|
12
12
|
}
|
|
13
13
|
exports.descriptorOf = descriptorOf;
|
|
14
14
|
function isMethodDescriptor(target, propertyKey) {
|
|
15
|
-
|
|
16
|
-
return (_a = descriptorOf(target, propertyKey)) === null || _a === void 0 ? void 0 : _a.value;
|
|
15
|
+
return descriptorOf(target, propertyKey)?.value;
|
|
17
16
|
}
|
|
18
17
|
exports.isMethodDescriptor = isMethodDescriptor;
|
|
19
18
|
//# sourceMappingURL=descriptorOf.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"descriptorOf.js","sourceRoot":"","sources":["../../../../src/utils/objects/descriptorOf.ts"],"names":[],"mappings":";;;AAAA;;;;;GAKG;AACH,SAAgB,YAAY,CAAC,MAAW,EAAE,WAA4B;IACpE,OAAO,MAAM,CAAC,wBAAwB,CAAC,CAAC,MAAM,IAAI,MAAM,CAAC,SAAS,CAAC,IAAI,MAAM,EAAE,WAAW,CAAE,CAAC;AAC/F,CAAC;AAFD,oCAEC;AAED,SAAgB,kBAAkB,CAAC,MAAW,EAAE,WAA4B
|
|
1
|
+
{"version":3,"file":"descriptorOf.js","sourceRoot":"","sources":["../../../../src/utils/objects/descriptorOf.ts"],"names":[],"mappings":";;;AAAA;;;;;GAKG;AACH,SAAgB,YAAY,CAAC,MAAW,EAAE,WAA4B;IACpE,OAAO,MAAM,CAAC,wBAAwB,CAAC,CAAC,MAAM,IAAI,MAAM,CAAC,SAAS,CAAC,IAAI,MAAM,EAAE,WAAW,CAAE,CAAC;AAC/F,CAAC;AAFD,oCAEC;AAED,SAAgB,kBAAkB,CAAC,MAAW,EAAE,WAA4B;IAC1E,OAAO,YAAY,CAAC,MAAM,EAAE,WAAW,CAAC,EAAE,KAAK,CAAC;AAClD,CAAC;AAFD,gDAEC","sourcesContent":["/**\n * Return the descriptor for a given class and propertyKey\n * @param target\n * @param {string} propertyKey\n * @returns {PropertyDescriptor}\n */\nexport function descriptorOf(target: any, propertyKey: string | symbol): PropertyDescriptor {\n return Object.getOwnPropertyDescriptor((target && target.prototype) || target, propertyKey)!;\n}\n\nexport function isMethodDescriptor(target: any, propertyKey: string | symbol) {\n return descriptorOf(target, propertyKey)?.value;\n}\n"]}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
var _AnyToPromise_resolves, _AnyToPromise_rejects, _AnyToPromise_hasNextFunction, _AnyToPromise_promise;
|
|
2
|
-
import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
|
|
3
1
|
import { isObservable } from "../utils/objects/isObservable.js";
|
|
4
2
|
import { isPromise } from "../utils/objects/isPromise.js";
|
|
5
3
|
import { isStream } from "../utils/objects/isStream.js";
|
|
@@ -26,23 +24,24 @@ export var AnyToPromiseResponseTypes;
|
|
|
26
24
|
AnyToPromiseResponseTypes["DATA"] = "DATA";
|
|
27
25
|
})(AnyToPromiseResponseTypes || (AnyToPromiseResponseTypes = {}));
|
|
28
26
|
export class AnyToPromise {
|
|
27
|
+
status = AnyToPromiseStatus.PENDING;
|
|
28
|
+
args;
|
|
29
|
+
#resolves;
|
|
30
|
+
#rejects;
|
|
31
|
+
#hasNextFunction = false;
|
|
32
|
+
#promise;
|
|
29
33
|
constructor({ hasNextFunction = false } = {}) {
|
|
30
|
-
this
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
__classPrivateFieldSet(this, _AnyToPromise_hasNextFunction, hasNextFunction, "f");
|
|
36
|
-
__classPrivateFieldSet(this, _AnyToPromise_promise, new Promise((resolve, reject) => {
|
|
37
|
-
__classPrivateFieldSet(this, _AnyToPromise_resolves, resolve, "f");
|
|
38
|
-
__classPrivateFieldSet(this, _AnyToPromise_rejects, reject, "f");
|
|
39
|
-
}), "f");
|
|
34
|
+
this.#hasNextFunction = hasNextFunction;
|
|
35
|
+
this.#promise = new Promise((resolve, reject) => {
|
|
36
|
+
this.#resolves = resolve;
|
|
37
|
+
this.#rejects = reject;
|
|
38
|
+
});
|
|
40
39
|
}
|
|
41
40
|
isDone() {
|
|
42
41
|
return this.status !== AnyToPromiseStatus.PENDING;
|
|
43
42
|
}
|
|
44
43
|
get next() {
|
|
45
|
-
|
|
44
|
+
this.#hasNextFunction = true;
|
|
46
45
|
return (error) => {
|
|
47
46
|
if (this.isDone()) {
|
|
48
47
|
return;
|
|
@@ -63,21 +62,21 @@ export class AnyToPromise {
|
|
|
63
62
|
catch (er) {
|
|
64
63
|
this.reject(er);
|
|
65
64
|
}
|
|
66
|
-
return
|
|
65
|
+
return this.#promise;
|
|
67
66
|
}
|
|
68
67
|
reject(er) {
|
|
69
68
|
if (this.isDone()) {
|
|
70
69
|
return;
|
|
71
70
|
}
|
|
72
71
|
this.done(AnyToPromiseStatus.REJECTED);
|
|
73
|
-
|
|
72
|
+
this.#rejects(er);
|
|
74
73
|
}
|
|
75
74
|
resolve(response = {}) {
|
|
76
75
|
if (this.isDone()) {
|
|
77
76
|
return;
|
|
78
77
|
}
|
|
79
78
|
this.done(AnyToPromiseStatus.RESOLVED);
|
|
80
|
-
|
|
79
|
+
this.#resolves({ ...response, state: AnyToPromiseStatus.RESOLVED });
|
|
81
80
|
}
|
|
82
81
|
destroy() { }
|
|
83
82
|
cancel() {
|
|
@@ -85,7 +84,7 @@ export class AnyToPromise {
|
|
|
85
84
|
return;
|
|
86
85
|
}
|
|
87
86
|
this.done(AnyToPromiseStatus.CANCELED);
|
|
88
|
-
return
|
|
87
|
+
return this.#resolves({ state: AnyToPromiseStatus.CANCELED });
|
|
89
88
|
}
|
|
90
89
|
done(status) {
|
|
91
90
|
this.destroy();
|
|
@@ -127,7 +126,7 @@ export class AnyToPromise {
|
|
|
127
126
|
});
|
|
128
127
|
}
|
|
129
128
|
}
|
|
130
|
-
if (!
|
|
129
|
+
if (!this.#hasNextFunction) {
|
|
131
130
|
// no next function and empty response
|
|
132
131
|
return this.resolve({
|
|
133
132
|
...additionalProps,
|
|
@@ -140,5 +139,4 @@ export class AnyToPromise {
|
|
|
140
139
|
return process === AnyToPromiseStatus.CANCELED;
|
|
141
140
|
}
|
|
142
141
|
}
|
|
143
|
-
_AnyToPromise_resolves = new WeakMap(), _AnyToPromise_rejects = new WeakMap(), _AnyToPromise_hasNextFunction = new WeakMap(), _AnyToPromise_promise = new WeakMap();
|
|
144
142
|
//# sourceMappingURL=AnyToPromise.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AnyToPromise.js","sourceRoot":"","sources":["../../../src/domain/AnyToPromise.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"AnyToPromise.js","sourceRoot":"","sources":["../../../src/domain/AnyToPromise.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,+BAA+B,CAAC;AAC3D,OAAO,EAAC,SAAS,EAAC,MAAM,4BAA4B,CAAC;AACrD,OAAO,EAAC,QAAQ,EAAC,MAAM,2BAA2B,CAAC;AAEnD;;GAEG;AACH,SAAS,UAAU,CAAC,GAAQ;IAC1B,OAAO,GAAG,CAAC,IAAI,IAAI,GAAG,CAAC,OAAO,IAAI,GAAG,CAAC,MAAM,IAAI,GAAG,CAAC,UAAU,CAAC;AACjE,CAAC;AAED;;GAEG;AACH,MAAM,CAAN,IAAY,kBAKX;AALD,WAAY,kBAAkB;IAC5B,yCAAmB,CAAA;IACnB,2CAAqB,CAAA;IACrB,2CAAqB,CAAA;IACrB,2CAAqB,CAAA;AACvB,CAAC,EALW,kBAAkB,KAAlB,kBAAkB,QAK7B;AAED,MAAM,CAAN,IAAY,yBAIX;AAJD,WAAY,yBAAyB;IACnC,8CAAiB,CAAA;IACjB,8CAAiB,CAAA;IACjB,0CAAa,CAAA;AACf,CAAC,EAJW,yBAAyB,KAAzB,yBAAyB,QAIpC;AAUD,MAAM,OAAO,YAAY;IAChB,MAAM,GAAG,kBAAkB,CAAC,OAAO,CAAC;IACpC,IAAI,CAAQ;IAEnB,SAAS,CAAM;IACf,QAAQ,CAAM;IACd,gBAAgB,GAAG,KAAK,CAAC;IAEhB,QAAQ,CAA+B;IAEhD,YAAY,EAAC,eAAe,GAAG,KAAK,KAAiC,EAAE;QACrE,IAAI,CAAC,gBAAgB,GAAG,eAAe,CAAC;QAExC,IAAI,CAAC,QA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,EAAE,IAAI,EAAE,yBAAyB,CAAC,MAAM,EAAE,IAAI,EAAE,OAAO,EAAC,CAAC,CAAC;aAClG;YACD,IAAI,QAAQ,CAAC,OAAO,CAAC,IAAI,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE;gBACjD,OAAO,IAAI,CAAC,OAAO,CAAC,EAAC,GAAG,eAAe,EAAE,IAAI,EAAE,yBAAyB,CAAC,MAAM,EAAE,IAAI,EAAE,OAAO,EAAC,CAAC,CAAC;aAClG;YAED,IAAI,SAAS,CAAC,OAAO,CAAC,EAAE;gBACtB,OAAO,OAAO;qBACX,IAAI,CAAC,CAAC,MAAW,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;qBAC3D,KAAK,CAAC,CAAC,KAAU,EAAE,EAAE;oBACpB,IAAI,KAAK,CAAC,QAAQ,IAAI,UAAU,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE;wBAChD,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;qBACpC;oBACD,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;gBAC5B,CAAC,CAAC,CAAC;aACN;SACF;QAED,IAAI,CAAC,IAAI,CAAC,gBAAgB,EAAE;YAC1B,sCAAsC;YACtC,OAAO,IAAI,CAAC,OAAO,CAAC;gBAClB,GAAG,eAAe;gBAClB,IAAI,EAAE,OAAO;gBACb,IAAI,EAAE,yBAAyB,CAAC,IAAI;aACrC,CAAC,CAAC;SACJ;IACH,CAAC;IAES,kBAAkB,CAAC,OAAY;QACvC,OAAO,OAAO,KAAK,kBAAkB,CAAC,QAAQ,CAAC;IACjD,CAAC;CACF","sourcesContent":["import {isObservable} from \"../utils/objects/isObservable\";\nimport {isPromise} from \"../utils/objects/isPromise\";\nimport {isStream} from \"../utils/objects/isStream\";\n\n/**\n * @ignore\n */\nfunction isResponse(obj: any) {\n return obj.data && obj.headers && obj.status && obj.statusText;\n}\n\n/**\n * @ignore\n */\nexport enum AnyToPromiseStatus {\n PENDING = \"PENDING\",\n CANCELED = \"CANCELED\",\n RESOLVED = \"RESOLVED\",\n REJECTED = \"REJECTED\"\n}\n\nexport enum AnyToPromiseResponseTypes {\n STREAM = \"STREAM\",\n BUFFER = \"BUFFER\",\n DATA = \"DATA\"\n}\n\nexport interface AnyPromiseResult<T = any> {\n state: AnyToPromiseStatus;\n type: AnyToPromiseResponseTypes;\n status?: number;\n headers?: Record<string, any>;\n data: T;\n}\n\nexport class AnyToPromise<T = any> {\n public status = AnyToPromiseStatus.PENDING;\n public args: any[];\n\n #resolves: any;\n #rejects: any;\n #hasNextFunction = false;\n\n readonly #promise: Promise<AnyPromiseResult<T>>;\n\n constructor({hasNextFunction = false}: {hasNextFunction?: boolean} = {}) {\n this.#hasNextFunction = hasNextFunction;\n\n this.#promise = new Promise((resolve: any, reject: any) => {\n this.#resolves = resolve;\n this.#rejects = reject;\n });\n }\n\n isDone(): boolean {\n return this.status !== AnyToPromiseStatus.PENDING;\n }\n\n get next() {\n this.#hasNextFunction = true;\n\n return (error?: any) => {\n if (this.isDone()) {\n return;\n }\n\n return error ? this.reject(error) : this.resolve({type: AnyToPromiseResponseTypes.DATA});\n };\n }\n\n /**\n *\n */\n async call(cb: Function): Promise<AnyPromiseResult<T>> {\n if (this.isDone()) {\n return this as any;\n }\n\n try {\n this.handle(cb());\n } catch (er) {\n this.reject(er);\n }\n\n return this.#promise;\n }\n\n reject(er: any) {\n if (this.isDone()) {\n return;\n }\n\n this.done(AnyToPromiseStatus.REJECTED);\n\n this.#rejects(er);\n }\n\n resolve(response: any = {}) {\n if (this.isDone()) {\n return;\n }\n\n this.done(AnyToPromiseStatus.RESOLVED);\n\n this.#resolves({...response, state: AnyToPromiseStatus.RESOLVED});\n }\n\n destroy() {}\n\n cancel() {\n if (this.isDone()) {\n return;\n }\n\n this.done(AnyToPromiseStatus.CANCELED);\n\n return this.#resolves({state: AnyToPromiseStatus.CANCELED});\n }\n\n done(status: AnyToPromiseStatus) {\n this.destroy();\n this.status = status;\n }\n\n handle(process: any, additionalProps = {}): any {\n if (this.isDone()) {\n return;\n }\n\n if (process) {\n if (this.isCanceledResponse(process)) {\n // ABANDON\n return this.cancel();\n }\n\n if (isObservable(process)) {\n process = process.toPromise();\n }\n\n if (isResponse(process)) {\n return this.handle(process.data, {\n ...additionalProps,\n status: process.status,\n headers: process.headers\n });\n }\n\n if (isStream(process)) {\n return this.resolve({...additionalProps, type: AnyToPromiseResponseTypes.STREAM, data: process});\n }\n if (isStream(process) || Buffer.isBuffer(process)) {\n return this.resolve({...additionalProps, type: AnyToPromiseResponseTypes.BUFFER, data: process});\n }\n\n if (isPromise(process)) {\n return process\n .then((result: any) => this.handle(result, additionalProps))\n .catch((error: any) => {\n if (error.response && isResponse(error.response)) {\n return this.handle(error.response);\n }\n return this.reject(error);\n });\n }\n }\n\n if (!this.#hasNextFunction) {\n // no next function and empty response\n return this.resolve({\n ...additionalProps,\n data: process,\n type: AnyToPromiseResponseTypes.DATA\n });\n }\n }\n\n protected isCanceledResponse(process: any) {\n return process === AnyToPromiseStatus.CANCELED;\n }\n}\n"]}
|
package/lib/esm/domain/Hooks.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Hooks.js","sourceRoot":"","sources":["../../../src/domain/Hooks.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,KAAK;
|
|
1
|
+
{"version":3,"file":"Hooks.js","sourceRoot":"","sources":["../../../src/domain/Hooks.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,KAAK;IACR,SAAS,GAA4B,IAAI,GAAG,EAAE,CAAC;IAEvD;;;;OAIG;IACH,EAAE,CAAC,KAAa,EAAE,EAAY;QAC5B,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE;YAC9B,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,KAAK,EAAE,EAAE,CAAC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EAAE,OAAc,EAAE,EAAE,WAAgB,IAAI;QACnE,IAAI,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE;YAC7B,KAAK,MAAM,EAAE,IAAI,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,KAAK,CAAE,EAAE;gBAC3C,MAAM,EAAE,CAAC,IAAI,CAAC,QAAQ,EAAE,GAAG,IAAI,CAAC,CAAC;aAClC;SACF;IACH,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,UAAU,CAAC,KAAa,EAAE,KAAU,EAAE,OAAiB,EAAE,EAAE,WAAgB,IAAI;QACnF,IAAI,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE;YAC7B,KAAK,MAAM,EAAE,IAAI,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,KAAK,CAAE,EAAE;gBAC3C,KAAK,GAAG,MAAM,EAAE,CAAC,IAAI,CAAC,QAAQ,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC,CAAC;aACjD;SACF;QAED,OAAO,KAAK,CAAC;IACf,CAAC;CACF","sourcesContent":["export class Hooks {\n private listeners: Map<string, Function[]> = new Map();\n\n /**\n * Listen a hook event\n * @param event\n * @param cb\n */\n on(event: string, cb: Function) {\n if (!this.listeners.has(event)) {\n this.listeners.set(event, []);\n }\n\n this.listeners.get(event)!.push(cb);\n\n return this;\n }\n\n /**\n * Remove a listener attached to an event\n * @param event\n * @param cb\n */\n off(event: string, cb: Function) {\n if (this.listeners.has(event)) {\n this.listeners.set(\n event,\n this.listeners.get(event)!.filter((item) => item === cb)\n );\n }\n\n return this;\n }\n\n /**\n * Trigger an event and call listener.\n * @param event\n * @param args\n * @param callThis\n */\n emit(event: string, args: any[] = [], callThis: any = null): void {\n if (this.listeners.has(event)) {\n for (const cb of this.listeners.get(event)!) {\n cb.call(callThis, ...args);\n }\n }\n }\n\n /**\n * Trigger an event, listener alter given value and return it.\n * @param event\n * @param value\n * @param args\n * @param callThis\n */\n alter(event: string, value: any, args: any[] = [], callThis: any = null): any {\n if (this.listeners.has(event)) {\n for (const cb of this.listeners.get(event)!) {\n value = cb.call(callThis, value, ...args);\n }\n }\n\n return value;\n }\n\n /**\n * Trigger an event and call async listener.\n * @param event\n * @param args\n * @param callThis\n */\n async asyncEmit(event: string, args: any[] = [], callThis: any = null): Promise<void> {\n if (this.listeners.has(event)) {\n for (const cb of this.listeners.get(event)!) {\n await cb.call(callThis, ...args);\n }\n }\n }\n\n /**\n * Trigger an event, async listener alter given value and return it.\n * @param event\n * @param value\n * @param args\n * @param callThis\n */\n async asyncAlter(event: string, value: any, args: string[] = [], callThis: any = null): Promise<any> {\n if (this.listeners.has(event)) {\n for (const cb of this.listeners.get(event)!) {\n value = await cb.call(callThis, value, ...args);\n }\n }\n\n return value;\n }\n}\n"]}
|
|
@@ -384,6 +384,11 @@ export class Metadata {
|
|
|
384
384
|
static setParamTypes(target, propertyKey, value) {
|
|
385
385
|
return this.set(DESIGN_PARAM_TYPES, value, target.prototype, propertyKey);
|
|
386
386
|
}
|
|
387
|
+
/**
|
|
388
|
+
* Get all metadata for a metadataKey.
|
|
389
|
+
* @param metadataKey
|
|
390
|
+
*/
|
|
391
|
+
static getTargetsFromPropertyKey = (metadataKey) => PROPERTIES.has(metadataKey) ? PROPERTIES.get(metadataKey) || [] : [];
|
|
387
392
|
/**
|
|
388
393
|
* Define a unique metadata entry on the target.
|
|
389
394
|
* @param key A key used to store and retrieve metadata.
|
|
@@ -496,9 +501,4 @@ export class Metadata {
|
|
|
496
501
|
return Reflect.getOwnMetadata(DESIGN_PARAM_TYPES, target, propertyKey) || [];
|
|
497
502
|
}
|
|
498
503
|
}
|
|
499
|
-
/**
|
|
500
|
-
* Get all metadata for a metadataKey.
|
|
501
|
-
* @param metadataKey
|
|
502
|
-
*/
|
|
503
|
-
Metadata.getTargetsFromPropertyKey = (metadataKey) => PROPERTIES.has(metadataKey) ? PROPERTIES.get(metadataKey) || [] : [];
|
|
504
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,GAAG,CAAC,WAA4B,EAAS,EAAE,CACzE,UAAU,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC","sourcesContent":["import \"reflect-metadata\";\nimport {classOf} from \"../utils/objects/classOf\";\n\n/**\n * Metadata key\n * @private\n * @type {string}\n */\nconst DESIGN_PARAM_TYPES = \"design:paramtypes\";\n/**\n * Metadata key\n * @private\n * @type {string}\n */\nconst DESIGN_TYPE = \"design:type\";\n/**\n * Metadata key\n * @private\n * @type {string}\n */\nconst DESIGN_RETURN_TYPE = \"design:returntype\";\n\n/**\n * Properties collections\n * @private\n * @type {string}\n */\nconst PROPERTIES: Map<string | symbol, any[]> = new Map<string | symbol, any[]>();\n\n/**\n * @stable\n */\nexport class Metadata {\n /**\n * Gets the metadata value for the provided metadata key on the target object or its prototype chain.\n * @param key A key used to store and retrieve metadata.\n * @param target The target object on which the metadata is defined.\n * @param propertyKey The property key for the target.\n * @returns The metadata value for the metadata key if found; otherwise, `undefined`.\n * @example\n *\n * ```typescript\n * class Example {\n * // property declarations are not part of ES6, though they are valid in TypeScript:\n * // static staticProperty;\n * // property;\n *\n * static staticMethod(p) { }\n * method(p) { }\n * }\n *\n * // constructor\n * result = Metadata.get(\"custom:annotation\", Example);\n *\n * // property (on constructor)\n * result = Metadata.get(\"custom:annotation\", Example, \"staticProperty\");\n *\n * // property (on prototype)\n * result = Metadata.get(\"custom:annotation\", Example.prototype, \"property\");\n *\n * // method (on constructor)\n * result = Metadata.get(\"custom:annotation\", Example, \"staticMethod\");\n *\n * // method (on prototype)\n * result = Metadata.get(\"custom:annotation\", Example.prototype, \"method\");\n * ```\n *\n */\n static get(key: string, target: any, propertyKey?: string | symbol): any {\n return Reflect.getMetadata(key, classOf(target), propertyKey!);\n }\n\n /**\n * Gets the metadata value for the provided metadata key on the target object or its prototype chain.\n * @param key A key used to store and retrieve metadata.\n * @param target The target object on which the metadata is defined.\n * @param propertyKey The property key for the target.\n * @returns The metadata value for the metadata key if found; otherwise, `undefined`.\n * @example\n *\n * ```typescript\n * class Example {\n * // property declarations are not part of ES6, though they are valid in TypeScript:\n * // static staticProperty;\n * // property;\n *\n * static staticMethod(p) { }\n * method(p) { }\n * }\n *\n * // constructor\n * result = Metadata.getOwn(\"custom:annotation\", Example);\n *\n * // property (on constructor)\n * result = Metadata.getOwn(\"custom:annotation\", Example, \"staticProperty\");\n *\n * // property (on prototype)\n * result = Metadata.getOwn(\"custom:annotation\", Example.prototype, \"property\");\n *\n * // method (on constructor)\n * result = Metadata.getOwn(\"custom:annotation\", Example, \"staticMethod\");\n *\n * // method (on prototype)\n * result = Metadata.getOwn(\"custom:annotation\", Example.prototype, \"method\");\n * ```\n *\n */\n static getOwn(key: string, target: any, propertyKey?: string | symbol): any {\n return Reflect.getOwnMetadata(key, classOf(target), propertyKey!);\n }\n\n /**\n * Gets the metadata value for the provided metadata DESIGN_TYPE on the target object or its prototype chain.\n * @param target The target object on which the metadata is defined.\n * @param propertyKey The property key for the target.\n * @returns The metadata value for the metadata key if found; otherwise, `undefined`.\n * @example\n *\n * ```typescript\n * class Example {\n * // property declarations are not part of ES6, though they are valid in TypeScript:\n * // static staticProperty;\n * // property;\n *\n * static staticMethod(p) { }\n * method(p) { }\n * }\n *\n * // on contructor\n * result = Metadata.getType(Example);\n *\n * // property (on constructor)\n * result = Metadata.getType(Example, \"staticProperty\");\n *\n * // method (on constructor)\n * result = Metadata.getType(Example, \"staticMethod\");\n * ```\n *\n */\n static getType(target: any, propertyKey?: string | symbol): any {\n return Reflect.getMetadata(DESIGN_TYPE, target, propertyKey!);\n }\n\n /**\n * Gets the metadata value for the provided metadata DESIGN_TYPE on the target object or its prototype chain.\n * @param target The target object on which the metadata is defined.\n * @param propertyKey The property key for the target.\n * @returns The metadata value for the metadata key if found; otherwise, `undefined`.\n * @example\n *\n * ```typescript\n * class Example {\n * // property declarations are not part of ES6, though they are valid in TypeScript:\n * // static staticProperty;\n * // property;\n *\n * static staticMethod(p) { }\n * method(p) { }\n * }\n *\n * // on contructor\n * result = Metadata.getOwnType(Example);\n *\n * // property (on constructor)\n * result = Metadata.getOwnType(Example, \"staticProperty\");\n *\n * // method (on constructor)\n * result = Metadata.getOwnType(Example, \"staticMethod\");\n * ```\n *\n */\n static getOwnType(target: any, propertyKey?: string | symbol): any {\n return Reflect.getMetadata(DESIGN_TYPE, target, propertyKey!);\n }\n\n /**\n * Gets the metadata value for the provided metadata DESIGN_RETURN_TYPE on the target object or its prototype chain.\n * @param target The target object on which the metadata is defined.\n * @param propertyKey The property key for the target.\n * @returns The metadata value for the metadata key if found; otherwise, `undefined`.\n * @example\n *\n * ```typescript\n * class Example {\n * // property declarations are not part of ES6, though they are valid in TypeScript:\n * // static staticProperty;\n * // property;\n *\n * static staticMethod(p) { }\n * method(p) { }\n * }\n *\n * // on contructor\n * result = Metadata.getReturnType(Example);\n *\n * // property (on constructor)\n * result = Metadata.getReturnType(Example, \"staticProperty\");\n *\n * // method (on constructor)\n * result = Metadata.getReturnType(Example, \"staticMethod\");\n * ```\n *\n */\n static getReturnType(target: any, propertyKey?: string | symbol): any {\n return Reflect.getMetadata(DESIGN_RETURN_TYPE, target, propertyKey!);\n }\n\n /**\n * Gets the metadata value for the provided metadata DESIGN_RETURN_TYPE on the target object or its prototype chain.\n * @param target The target object on which the metadata is defined.\n * @param propertyKey The property key for the target.\n * @returns The metadata value for the metadata key if found; otherwise, `undefined`.\n * @example\n *\n * ```typescript\n * class Example {\n * // property declarations are not part of ES6, though they are valid in TypeScript:\n * // static staticProperty;\n * // property;\n *\n * static staticMethod(p) { }\n * method(p) { }\n * }\n *\n * // on contructor\n * result = Metadata.getOwnReturnType(Example);\n *\n * // property (on constructor)\n * result = Metadata.getOwnReturnType(Example, \"staticProperty\");\n *\n * // method (on constructor)\n * result = Metadata.getOwnReturnType(Example, \"staticMethod\");\n * ```\n *\n */\n static getOwnReturnType(target: any, propertyKey?: string | symbol): any {\n return Reflect.getOwnMetadata(DESIGN_RETURN_TYPE, target, propertyKey!);\n }\n\n /**\n * Gets a value indicating whether the target object or its prototype chain has the provided metadata key defined.\n * @param key A key used to store and retrieve metadata.\n * @param target The target object on which the metadata is defined.\n * @param propertyKey The property key for the target.\n * @returns `true` if the metadata key was defined on the target object or its prototype chain; otherwise, `false`.\n * @example\n *\n * ```typescript\n * class Example {\n * // property declarations are not part of ES6, though they are valid in TypeScript:\n * // static staticProperty;\n * // property;\n *\n * static staticMethod(p) { }\n * method(p) { }\n * }\n *\n * // constructor\n * result = Metadata.has(\"custom:annotation\", Example);\n *\n * // property (on constructor)\n * result = Metadata.has(\"custom:annotation\", Example, \"staticProperty\");\n *\n * // property (on prototype)\n * result = Metadata.has(\"custom:annotation\", Example.prototype, \"property\");\n *\n * // method (on constructor)\n * result = Metadata.has(\"custom:annotation\", Example, \"staticMethod\");\n *\n * // method (on prototype)\n * result = Metadata.has(\"custom:annotation\", Example.prototype, \"method\");\n * ```\n *\n */\n static has(key: string, target: any, propertyKey?: string | symbol): boolean {\n try {\n return Reflect.hasMetadata(key, classOf(target), propertyKey!);\n } catch (er) {}\n\n return false;\n }\n\n /**\n * Gets a value indicating whether the target object or its prototype chain has the provided metadata key defined.\n * @param key A key used to store and retrieve metadata.\n * @param target The target object on which the metadata is defined.\n * @param propertyKey The property key for the target.\n * @returns `true` if the metadata key was defined on the target object or its prototype chain; otherwise, `false`.\n * @example\n *\n * ```typescript\n * class Example {\n * // property declarations are not part of ES6, though they are valid in TypeScript:\n * // static staticProperty;\n * // property;\n *\n * static staticMethod(p) { }\n * method(p) { }\n * }\n *\n * // constructor\n * result = Metadata.has(\"custom:annotation\", Example);\n *\n * // property (on constructor)\n * result = Metadata.hasOwn(\"custom:annotation\", Example, \"staticProperty\");\n *\n * // property (on prototype)\n * result = Metadata.hasOwn(\"custom:annotation\", Example.prototype, \"property\");\n *\n * // method (on constructor)\n * result = Metadata.hasOwn(\"custom:annotation\", Example, \"staticMethod\");\n *\n * // method (on prototype)\n * result = Metadata.hasOwn(\"custom:annotation\", Example.prototype, \"method\");\n * ```\n *\n */\n static hasOwn(key: string, target: any, propertyKey?: string | symbol): boolean {\n return Reflect.hasOwnMetadata(key, classOf(target), propertyKey!);\n }\n\n /**\n * Deletes the metadata entry from the target object with the provided key.\n * @param key A key used to store and retrieve metadata.\n * @param target The target object on which the metadata is defined.\n * @param propertyKey The property key for the target.\n * @returns `true` if the metadata entry was found and deleted; otherwise, false.\n * @example\n *\n * ```typescript\n * class Example {\n * // property declarations are not part of ES6, though they are valid in TypeScript:\n * // static staticProperty;\n * // property;\n *\n * static staticMethod(p) { }\n * method(p) { }\n * }\n *\n * // constructor\n * result = Metadata.delete(\"custom:annotation\", Example);\n *\n * // property (on constructor)\n * result = Metadata.delete(\"custom:annotation\", Example, \"staticProperty\");\n *\n * // property (on prototype)\n * result = Metadata.delete(\"custom:annotation\", Example.prototype, \"property\");\n *\n * // method (on constructor)\n * result = Metadata.delete(\"custom:annotation\", Example, \"staticMethod\");\n *\n * // method (on prototype)\n * result = Metadata.delete(\"custom:annotation\", Example.prototype, \"method\");\n * ```\n *\n */\n static delete(key: string, target: any, propertyKey?: string | symbol): boolean {\n return Reflect.deleteMetadata(key, classOf(target), propertyKey!);\n }\n\n /**\n * Set the metadata value for the provided metadata DESIGN_PARAM_TYPES on the target object or its prototype chain.\n * @param target The target object on which the metadata is defined.\n * @param propertyKey The property key for the target.\n * @param value A value that contains attached metadata.\n * @returns The metadata value for the metadata key if found; otherwise, `undefined`.\n * @example\n *\n * ```typescript\n * class Example {\n * // property declarations are not part of ES6, though they are valid in TypeScript:\n * // static staticProperty;\n * // property;\n *\n * static staticMethod(p) { }\n * method(p) { }\n * }\n *\n * // on contructor\n * result = Metadata.setParamTypes(Example, undefined, [Object]);\n *\n * // property (on constructor)\n * result = Metadata.setParamTypes(Example, \"staticProperty\", [Object]);\n *\n * // property (on prototype)\n * result = Metadata.setParamTypes(Example.prototype, \"property\", [Object]);\n *\n * // method (on constructor)\n * result = Metadata.setParamTypes(Example, \"staticMethod\", [Object]);\n *\n * // method (on prototype)\n * result = Metadata.setParamTypes(Example.prototype, \"method\", [Object]);\n * ```\n *\n */\n static setParamTypes(target: any, propertyKey: string | symbol, value: any): void {\n return this.set(DESIGN_PARAM_TYPES, value, target.prototype, propertyKey);\n }\n\n /**\n * Get all metadata for a metadataKey.\n * @param metadataKey\n */\n static getTargetsFromPropertyKey = (metadataKey: string | symbol): any[] =>\n PROPERTIES.has(metadataKey) ? PROPERTIES.get(metadataKey) || [] : [];\n\n /**\n * Define a unique metadata entry on the target.\n * @param key A key used to store and retrieve metadata.\n * @param value A value that contains attached metadata.\n * @param target The target object on which to define metadata.\n * @param propertyKey The property key for the target.\n * @example\n *\n * ```typescript\n * class Example {\n * // property declarations are not part of ES6, though they are valid in TypeScript:\n * // static staticProperty;\n * // property;\n *\n * static staticMethod(p) { }\n * method(p) { }\n * }\n *\n * // constructor\n * Reflect.defineMetadata(\"custom:annotation\", options, Example);\n *\n * // property (on constructor)\n * Reflect.defineMetadata(\"custom:annotation\", Number, Example, \"staticProperty\");\n *\n * // property (on prototype)\n * Reflect.defineMetadata(\"custom:annotation\", Number, Example.prototype, \"property\");\n *\n * // method (on constructor)\n * Reflect.defineMetadata(\"custom:annotation\", Number, Example, \"staticMethod\");\n *\n * // method (on prototype)\n * Reflect.defineMetadata(\"custom:annotation\", Number, Example.prototype, \"method\");\n *\n * // decorator factory as metadata-producing annotation.\n * function MyAnnotation(options): PropertyDecorator {\n * return (target, key) => Reflect.defineMetadata(\"custom:annotation\", options, target, key);\n * }\n * ```\n *\n */\n static set(key: string, value: any, target: any, propertyKey?: string | symbol): void {\n const targets: any[] = PROPERTIES.has(key) ? PROPERTIES.get(key) || [] : [];\n const classConstructor = classOf(target);\n\n if (targets.indexOf(classConstructor) === -1) {\n targets.push(classConstructor);\n PROPERTIES.set(key, targets);\n }\n\n Reflect.defineMetadata(key, value, classOf(target), propertyKey!);\n }\n\n /**\n * Gets the metadata value for the provided metadata DESIGN_PARAM_TYPES on the target object or its prototype chain.\n * @param targetPrototype\n * @param propertyKey The property key for the target.\n * @returns The metadata value for the metadata key if found; otherwise, `undefined`.\n * @example\n *\n * ```typescript\n * class Example {\n * // property declarations are not part of ES6, though they are valid in TypeScript:\n * // static staticProperty;\n * // property;\n *\n * static staticMethod(p) { }\n * method(p) { }\n * }\n *\n * // on contructor\n * result = Metadata.getParamTypes(Example.prototype);\n *\n * // property (on constructor)\n * result = Metadata.getParamTypes(Example.prototype, \"staticProperty\");\n *\n * // method (on constructor)\n * result = Metadata.getParamTypes(Example.prototype, \"staticMethod\");\n * ```\n *\n */\n static getParamTypes(targetPrototype: any, propertyKey?: string | symbol): any[] {\n return Reflect.getMetadata(DESIGN_PARAM_TYPES, targetPrototype, propertyKey!) || [];\n }\n\n /**\n * Gets the metadata value for the provided metadata DESIGN_PARAM_TYPES on the target object or its prototype chain.\n * @param target The target object on which the metadata is defined.\n * @param propertyKey The property key for the target.\n * @returns The metadata value for the metadata key if found; otherwise, `undefined`.\n * @example\n *\n * ```typescript\n * class Example {\n * // property declarations are not part of ES6, though they are valid in TypeScript:\n * // static staticProperty;\n * // property;\n *\n * static staticMethod(p) { }\n * method(p) { }\n * }\n *\n * // on contructor\n * result = Metadata.getParamTypes(Example);\n *\n * // property (on constructor)\n * result = Metadata.getParamTypes(Example, \"staticProperty\");\n *\n * // method (on constructor)\n * result = Metadata.getParamTypes(Example, \"staticMethod\");\n * ```\n *\n */\n static getOwnParamTypes(target: any, propertyKey?: string | symbol): any[] {\n return Reflect.getOwnMetadata(DESIGN_PARAM_TYPES, target, propertyKey!) || [];\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"Metadata.js","sourceRoot":"","sources":["../../../src/domain/Metadata.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAC1B,OAAO,EAAC,OAAO,EAAC,MAAM,0BAA0B,CAAC;AAEjD;;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"../utils/objects/classOf\";\n\n/**\n * Metadata key\n * @private\n * @type {string}\n */\nconst DESIGN_PARAM_TYPES = \"design:paramtypes\";\n/**\n * Metadata key\n * @private\n * @type {string}\n */\nconst DESIGN_TYPE = \"design:type\";\n/**\n * Metadata key\n * @private\n * @type {string}\n */\nconst DESIGN_RETURN_TYPE = \"design:returntype\";\n\n/**\n * Properties collections\n * @private\n * @type {string}\n */\nconst PROPERTIES: Map<string | symbol, any[]> = new Map<string | symbol, any[]>();\n\n/**\n * @stable\n */\nexport class Metadata {\n /**\n * Gets the metadata value for the provided metadata key on the target object or its prototype chain.\n * @param key A key used to store and retrieve metadata.\n * @param target The target object on which the metadata is defined.\n * @param propertyKey The property key for the target.\n * @returns The metadata value for the metadata key if found; otherwise, `undefined`.\n * @example\n *\n * ```typescript\n * class Example {\n * // property declarations are not part of ES6, though they are valid in TypeScript:\n * // static staticProperty;\n * // property;\n *\n * static staticMethod(p) { }\n * method(p) { }\n * }\n *\n * // constructor\n * result = Metadata.get(\"custom:annotation\", Example);\n *\n * // property (on constructor)\n * result = Metadata.get(\"custom:annotation\", Example, \"staticProperty\");\n *\n * // property (on prototype)\n * result = Metadata.get(\"custom:annotation\", Example.prototype, \"property\");\n *\n * // method (on constructor)\n * result = Metadata.get(\"custom:annotation\", Example, \"staticMethod\");\n *\n * // method (on prototype)\n * result = Metadata.get(\"custom:annotation\", Example.prototype, \"method\");\n * ```\n *\n */\n static get(key: string, target: any, propertyKey?: string | symbol): any {\n return Reflect.getMetadata(key, classOf(target), propertyKey!);\n }\n\n /**\n * Gets the metadata value for the provided metadata key on the target object or its prototype chain.\n * @param key A key used to store and retrieve metadata.\n * @param target The target object on which the metadata is defined.\n * @param propertyKey The property key for the target.\n * @returns The metadata value for the metadata key if found; otherwise, `undefined`.\n * @example\n *\n * ```typescript\n * class Example {\n * // property declarations are not part of ES6, though they are valid in TypeScript:\n * // static staticProperty;\n * // property;\n *\n * static staticMethod(p) { }\n * method(p) { }\n * }\n *\n * // constructor\n * result = Metadata.getOwn(\"custom:annotation\", Example);\n *\n * // property (on constructor)\n * result = Metadata.getOwn(\"custom:annotation\", Example, \"staticProperty\");\n *\n * // property (on prototype)\n * result = Metadata.getOwn(\"custom:annotation\", Example.prototype, \"property\");\n *\n * // method (on constructor)\n * result = Metadata.getOwn(\"custom:annotation\", Example, \"staticMethod\");\n *\n * // method (on prototype)\n * result = Metadata.getOwn(\"custom:annotation\", Example.prototype, \"method\");\n * ```\n *\n */\n static getOwn(key: string, target: any, propertyKey?: string | symbol): any {\n return Reflect.getOwnMetadata(key, classOf(target), propertyKey!);\n }\n\n /**\n * Gets the metadata value for the provided metadata DESIGN_TYPE on the target object or its prototype chain.\n * @param target The target object on which the metadata is defined.\n * @param propertyKey The property key for the target.\n * @returns The metadata value for the metadata key if found; otherwise, `undefined`.\n * @example\n *\n * ```typescript\n * class Example {\n * // property declarations are not part of ES6, though they are valid in TypeScript:\n * // static staticProperty;\n * // property;\n *\n * static staticMethod(p) { }\n * method(p) { }\n * }\n *\n * // on contructor\n * result = Metadata.getType(Example);\n *\n * // property (on constructor)\n * result = Metadata.getType(Example, \"staticProperty\");\n *\n * // method (on constructor)\n * result = Metadata.getType(Example, \"staticMethod\");\n * ```\n *\n */\n static getType(target: any, propertyKey?: string | symbol): any {\n return Reflect.getMetadata(DESIGN_TYPE, target, propertyKey!);\n }\n\n /**\n * Gets the metadata value for the provided metadata DESIGN_TYPE on the target object or its prototype chain.\n * @param target The target object on which the metadata is defined.\n * @param propertyKey The property key for the target.\n * @returns The metadata value for the metadata key if found; otherwise, `undefined`.\n * @example\n *\n * ```typescript\n * class Example {\n * // property declarations are not part of ES6, though they are valid in TypeScript:\n * // static staticProperty;\n * // property;\n *\n * static staticMethod(p) { }\n * method(p) { }\n * }\n *\n * // on contructor\n * result = Metadata.getOwnType(Example);\n *\n * // property (on constructor)\n * result = Metadata.getOwnType(Example, \"staticProperty\");\n *\n * // method (on constructor)\n * result = Metadata.getOwnType(Example, \"staticMethod\");\n * ```\n *\n */\n static getOwnType(target: any, propertyKey?: string | symbol): any {\n return Reflect.getMetadata(DESIGN_TYPE, target, propertyKey!);\n }\n\n /**\n * Gets the metadata value for the provided metadata DESIGN_RETURN_TYPE on the target object or its prototype chain.\n * @param target The target object on which the metadata is defined.\n * @param propertyKey The property key for the target.\n * @returns The metadata value for the metadata key if found; otherwise, `undefined`.\n * @example\n *\n * ```typescript\n * class Example {\n * // property declarations are not part of ES6, though they are valid in TypeScript:\n * // static staticProperty;\n * // property;\n *\n * static staticMethod(p) { }\n * method(p) { }\n * }\n *\n * // on contructor\n * result = Metadata.getReturnType(Example);\n *\n * // property (on constructor)\n * result = Metadata.getReturnType(Example, \"staticProperty\");\n *\n * // method (on constructor)\n * result = Metadata.getReturnType(Example, \"staticMethod\");\n * ```\n *\n */\n static getReturnType(target: any, propertyKey?: string | symbol): any {\n return Reflect.getMetadata(DESIGN_RETURN_TYPE, target, propertyKey!);\n }\n\n /**\n * Gets the metadata value for the provided metadata DESIGN_RETURN_TYPE on the target object or its prototype chain.\n * @param target The target object on which the metadata is defined.\n * @param propertyKey The property key for the target.\n * @returns The metadata value for the metadata key if found; otherwise, `undefined`.\n * @example\n *\n * ```typescript\n * class Example {\n * // property declarations are not part of ES6, though they are valid in TypeScript:\n * // static staticProperty;\n * // property;\n *\n * static staticMethod(p) { }\n * method(p) { }\n * }\n *\n * // on contructor\n * result = Metadata.getOwnReturnType(Example);\n *\n * // property (on constructor)\n * result = Metadata.getOwnReturnType(Example, \"staticProperty\");\n *\n * // method (on constructor)\n * result = Metadata.getOwnReturnType(Example, \"staticMethod\");\n * ```\n *\n */\n static getOwnReturnType(target: any, propertyKey?: string | symbol): any {\n return Reflect.getOwnMetadata(DESIGN_RETURN_TYPE, target, propertyKey!);\n }\n\n /**\n * Gets a value indicating whether the target object or its prototype chain has the provided metadata key defined.\n * @param key A key used to store and retrieve metadata.\n * @param target The target object on which the metadata is defined.\n * @param propertyKey The property key for the target.\n * @returns `true` if the metadata key was defined on the target object or its prototype chain; otherwise, `false`.\n * @example\n *\n * ```typescript\n * class Example {\n * // property declarations are not part of ES6, though they are valid in TypeScript:\n * // static staticProperty;\n * // property;\n *\n * static staticMethod(p) { }\n * method(p) { }\n * }\n *\n * // constructor\n * result = Metadata.has(\"custom:annotation\", Example);\n *\n * // property (on constructor)\n * result = Metadata.has(\"custom:annotation\", Example, \"staticProperty\");\n *\n * // property (on prototype)\n * result = Metadata.has(\"custom:annotation\", Example.prototype, \"property\");\n *\n * // method (on constructor)\n * result = Metadata.has(\"custom:annotation\", Example, \"staticMethod\");\n *\n * // method (on prototype)\n * result = Metadata.has(\"custom:annotation\", Example.prototype, \"method\");\n * ```\n *\n */\n static has(key: string, target: any, propertyKey?: string | symbol): boolean {\n try {\n return Reflect.hasMetadata(key, classOf(target), propertyKey!);\n } catch (er) {}\n\n return false;\n }\n\n /**\n * Gets a value indicating whether the target object or its prototype chain has the provided metadata key defined.\n * @param key A key used to store and retrieve metadata.\n * @param target The target object on which the metadata is defined.\n * @param propertyKey The property key for the target.\n * @returns `true` if the metadata key was defined on the target object or its prototype chain; otherwise, `false`.\n * @example\n *\n * ```typescript\n * class Example {\n * // property declarations are not part of ES6, though they are valid in TypeScript:\n * // static staticProperty;\n * // property;\n *\n * static staticMethod(p) { }\n * method(p) { }\n * }\n *\n * // constructor\n * result = Metadata.has(\"custom:annotation\", Example);\n *\n * // property (on constructor)\n * result = Metadata.hasOwn(\"custom:annotation\", Example, \"staticProperty\");\n *\n * // property (on prototype)\n * result = Metadata.hasOwn(\"custom:annotation\", Example.prototype, \"property\");\n *\n * // method (on constructor)\n * result = Metadata.hasOwn(\"custom:annotation\", Example, \"staticMethod\");\n *\n * // method (on prototype)\n * result = Metadata.hasOwn(\"custom:annotation\", Example.prototype, \"method\");\n * ```\n *\n */\n static hasOwn(key: string, target: any, propertyKey?: string | symbol): boolean {\n return Reflect.hasOwnMetadata(key, classOf(target), propertyKey!);\n }\n\n /**\n * Deletes the metadata entry from the target object with the provided key.\n * @param key A key used to store and retrieve metadata.\n * @param target The target object on which the metadata is defined.\n * @param propertyKey The property key for the target.\n * @returns `true` if the metadata entry was found and deleted; otherwise, false.\n * @example\n *\n * ```typescript\n * class Example {\n * // property declarations are not part of ES6, though they are valid in TypeScript:\n * // static staticProperty;\n * // property;\n *\n * static staticMethod(p) { }\n * method(p) { }\n * }\n *\n * // constructor\n * result = Metadata.delete(\"custom:annotation\", Example);\n *\n * // property (on constructor)\n * result = Metadata.delete(\"custom:annotation\", Example, \"staticProperty\");\n *\n * // property (on prototype)\n * result = Metadata.delete(\"custom:annotation\", Example.prototype, \"property\");\n *\n * // method (on constructor)\n * result = Metadata.delete(\"custom:annotation\", Example, \"staticMethod\");\n *\n * // method (on prototype)\n * result = Metadata.delete(\"custom:annotation\", Example.prototype, \"method\");\n * ```\n *\n */\n static delete(key: string, target: any, propertyKey?: string | symbol): boolean {\n return Reflect.deleteMetadata(key, classOf(target), propertyKey!);\n }\n\n /**\n * Set the metadata value for the provided metadata DESIGN_PARAM_TYPES on the target object or its prototype chain.\n * @param target The target object on which the metadata is defined.\n * @param propertyKey The property key for the target.\n * @param value A value that contains attached metadata.\n * @returns The metadata value for the metadata key if found; otherwise, `undefined`.\n * @example\n *\n * ```typescript\n * class Example {\n * // property declarations are not part of ES6, though they are valid in TypeScript:\n * // static staticProperty;\n * // property;\n *\n * static staticMethod(p) { }\n * method(p) { }\n * }\n *\n * // on contructor\n * result = Metadata.setParamTypes(Example, undefined, [Object]);\n *\n * // property (on constructor)\n * result = Metadata.setParamTypes(Example, \"staticProperty\", [Object]);\n *\n * // property (on prototype)\n * result = Metadata.setParamTypes(Example.prototype, \"property\", [Object]);\n *\n * // method (on constructor)\n * result = Metadata.setParamTypes(Example, \"staticMethod\", [Object]);\n *\n * // method (on prototype)\n * result = Metadata.setParamTypes(Example.prototype, \"method\", [Object]);\n * ```\n *\n */\n static setParamTypes(target: any, propertyKey: string | symbol, value: any): void {\n return this.set(DESIGN_PARAM_TYPES, value, target.prototype, propertyKey);\n }\n\n /**\n * Get all metadata for a metadataKey.\n * @param metadataKey\n */\n static getTargetsFromPropertyKey = (metadataKey: string | symbol): any[] =>\n PROPERTIES.has(metadataKey) ? PROPERTIES.get(metadataKey) || [] : [];\n\n /**\n * Define a unique metadata entry on the target.\n * @param key A key used to store and retrieve metadata.\n * @param value A value that contains attached metadata.\n * @param target The target object on which to define metadata.\n * @param propertyKey The property key for the target.\n * @example\n *\n * ```typescript\n * class Example {\n * // property declarations are not part of ES6, though they are valid in TypeScript:\n * // static staticProperty;\n * // property;\n *\n * static staticMethod(p) { }\n * method(p) { }\n * }\n *\n * // constructor\n * Reflect.defineMetadata(\"custom:annotation\", options, Example);\n *\n * // property (on constructor)\n * Reflect.defineMetadata(\"custom:annotation\", Number, Example, \"staticProperty\");\n *\n * // property (on prototype)\n * Reflect.defineMetadata(\"custom:annotation\", Number, Example.prototype, \"property\");\n *\n * // method (on constructor)\n * Reflect.defineMetadata(\"custom:annotation\", Number, Example, \"staticMethod\");\n *\n * // method (on prototype)\n * Reflect.defineMetadata(\"custom:annotation\", Number, Example.prototype, \"method\");\n *\n * // decorator factory as metadata-producing annotation.\n * function MyAnnotation(options): PropertyDecorator {\n * return (target, key) => Reflect.defineMetadata(\"custom:annotation\", options, target, key);\n * }\n * ```\n *\n */\n static set(key: string, value: any, target: any, propertyKey?: string | symbol): void {\n const targets: any[] = PROPERTIES.has(key) ? PROPERTIES.get(key) || [] : [];\n const classConstructor = classOf(target);\n\n if (targets.indexOf(classConstructor) === -1) {\n targets.push(classConstructor);\n PROPERTIES.set(key, targets);\n }\n\n Reflect.defineMetadata(key, value, classOf(target), propertyKey!);\n }\n\n /**\n * Gets the metadata value for the provided metadata DESIGN_PARAM_TYPES on the target object or its prototype chain.\n * @param targetPrototype\n * @param propertyKey The property key for the target.\n * @returns The metadata value for the metadata key if found; otherwise, `undefined`.\n * @example\n *\n * ```typescript\n * class Example {\n * // property declarations are not part of ES6, though they are valid in TypeScript:\n * // static staticProperty;\n * // property;\n *\n * static staticMethod(p) { }\n * method(p) { }\n * }\n *\n * // on contructor\n * result = Metadata.getParamTypes(Example.prototype);\n *\n * // property (on constructor)\n * result = Metadata.getParamTypes(Example.prototype, \"staticProperty\");\n *\n * // method (on constructor)\n * result = Metadata.getParamTypes(Example.prototype, \"staticMethod\");\n * ```\n *\n */\n static getParamTypes(targetPrototype: any, propertyKey?: string | symbol): any[] {\n return Reflect.getMetadata(DESIGN_PARAM_TYPES, targetPrototype, propertyKey!) || [];\n }\n\n /**\n * Gets the metadata value for the provided metadata DESIGN_PARAM_TYPES on the target object or its prototype chain.\n * @param target The target object on which the metadata is defined.\n * @param propertyKey The property key for the target.\n * @returns The metadata value for the metadata key if found; otherwise, `undefined`.\n * @example\n *\n * ```typescript\n * class Example {\n * // property declarations are not part of ES6, though they are valid in TypeScript:\n * // static staticProperty;\n * // property;\n *\n * static staticMethod(p) { }\n * method(p) { }\n * }\n *\n * // on contructor\n * result = Metadata.getParamTypes(Example);\n *\n * // property (on constructor)\n * result = Metadata.getParamTypes(Example, \"staticProperty\");\n *\n * // method (on constructor)\n * result = Metadata.getParamTypes(Example, \"staticMethod\");\n * ```\n *\n */\n static getOwnParamTypes(target: any, propertyKey?: string | symbol): any[] {\n return Reflect.getOwnMetadata(DESIGN_PARAM_TYPES, target, propertyKey!) || [];\n }\n}\n"]}
|
package/lib/esm/domain/Store.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Store.js","sourceRoot":"","sources":["../../../src/domain/Store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,cAAc,EAAC,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAC,eAAe,EAAC,MAAM,qCAAqC,CAAC;AACpE,OAAO,EAAC,SAAS,EAAC,MAAM,4BAA4B,CAAC;AACrD,OAAO,EAAC,SAAS,EAAC,MAAM,4BAA4B,CAAC;AACrD,OAAO,EAAC,YAAY,EAAC,MAAM,+BAA+B,CAAC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G,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAE5B,IAAI,OAAO,EAAE;YACX,KAAK,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC;YACzB,OAAO,GAAG,SAAS,CAAC,OAAO,CAAC,CAAC;YAC7B,KAAK,GAAG,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;SACzE;QAED,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QAErB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM;QACJ,OAAO,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;YAC/D,OAAO;gBACL,GAAG,GAAG;gBACN,CAAC,GAAG,CAAC,EAAE,KAAK;aACb,CAAC;QACJ,CAAC,EAAE,EAAE,CAAC,CAAC;IACT,CAAC;CACF","sourcesContent":["import {DecoratorTypes} from \"../domain/DecoratorTypes\";\nimport {decoratorTypeOf} from \"../utils/decorators/decoratorTypeOf\";\nimport {deepClone} from \"../utils/objects/deepClone\";\nimport {deepMerge} from \"../utils/objects/deepMerge\";\nimport {descriptorOf} from \"../utils/objects/descriptorOf\";\nimport {isSymbol} from \"../utils/objects/isSymbol\";\nimport {nameOf} from \"../utils/objects/nameOf\";\nimport {Metadata} from \"./Metadata\";\nimport type {Type} from \"./Type\";\n\n/**\n * @ignore\n */\nexport const CLASS_STORE = \"tsed:class:store\";\n/**\n * @ignore\n */\nexport const METHOD_STORE = \"tsed:method:store\";\n/**\n * @ignore\n */\nexport const PROPERTY_STORE = \"tsed:property:store\";\n/**\n * @ignore\n */\nexport const PARAM_STORE = \"tsed:param:store\";\n\nconst stores = new Map<symbol, Store>();\n\nfunction storeGet(key: string, ...args: any[]): Store {\n if (isSymbol(args[0])) {\n if (!stores.has(args[0])) {\n stores.set(args[0], new Store());\n }\n\n return stores.get(args[0])!;\n } else {\n const registry = Metadata as any;\n\n if (!registry.hasOwn(key, ...args)) {\n registry.set(key, new Store(), ...args);\n }\n\n return registry.getOwn(key, ...args);\n }\n}\n\nfunction defineStore(args: any[]): Store {\n const [target, propertyKey, descriptor] = args;\n\n switch (decoratorTypeOf(args)) {\n case DecoratorTypes.PARAM_CTOR:\n case DecoratorTypes.PARAM_STC:\n case DecoratorTypes.PARAM:\n const store = storeGet(PARAM_STORE, target, propertyKey);\n if (!store.has(\"\" + descriptor)) {\n store.set(\"\" + descriptor, new Store());\n }\n\n return store.get(\"\" + descriptor);\n case DecoratorTypes.PROP:\n case DecoratorTypes.PROP_STC:\n return storeGet(PROPERTY_STORE, target, propertyKey);\n case DecoratorTypes.METHOD:\n case DecoratorTypes.METHOD_STC:\n return storeGet(METHOD_STORE, target, propertyKey);\n case DecoratorTypes.CLASS:\n return storeGet(CLASS_STORE, target);\n }\n}\n\nexport class Store {\n private _entries = new Map<string, any>();\n /**\n * Create or get a Store from args {target + methodName + descriptor}\n * @param args\n * @returns {Store}\n */\n static from(...args: any[]): Store {\n return defineStore(args);\n }\n\n /**\n * Create store on the method.\n * @param target\n * @param {string} propertyKey\n * @returns {Store}\n */\n static fromMethod(target: any, propertyKey: string | symbol): Store {\n return Store.from(target, propertyKey, descriptorOf(target, propertyKey));\n }\n\n static mergeStoreFrom(target: Type<any>, source: Type<any>, ...args: any[]) {\n const store = Store.from(target, ...args);\n\n Store.from(source, ...args)._entries.forEach((value, key) => {\n store.merge(key, value);\n });\n\n return store;\n }\n\n static mergeStoreMethodFrom(target: Type<any>, source: Type<any>, propertyKey: string | symbol) {\n return this.mergeStoreFrom(target, source, propertyKey, descriptorOf(target, propertyKey));\n }\n\n /**\n * The get() method returns a specified element from a Map object.\n * @param key Required. The key of the element to return from the Map object.\n * @param defaultValue\n * @returns {T} Returns the element associated with the specified key or undefined if the key can't be found in the Map object.\n */\n get<T = any>(key: any, defaultValue?: any): T {\n return this._entries.get(nameOf(key)) || defaultValue;\n }\n\n /**\n * The has() method returns a boolean indicating whether an element with the specified key exists or not.\n * @param key\n * @returns {boolean}\n */\n has(key: any): boolean {\n return this._entries.has(nameOf(key));\n }\n\n /**\n * The set() method adds or updates an element with a specified key and value to a Map object.\n * @param key Required. The key of the element to add to the Map object.\n * @param metadata Required. The value of the element to add to the Map object.\n */\n set(key: any, metadata: any): Store {\n this._entries.set(nameOf(key), metadata);\n\n return this;\n }\n\n /**\n * The delete() method removes the specified element from a Map object.\n * @param key Required. The key of the element to remove from the Map object.\n * @returns {boolean} Returns true if an element in the Map object existed and has been removed, or false if the element does not exist.\n */\n delete(key: string): boolean {\n return this._entries.delete(nameOf(key));\n }\n\n /**\n * Merge given value with existing value.\n * @param key\n * @param value\n * @param inverse Change the merge order. Get the existing value and apply over given value\n * @returns {Store}\n */\n merge(key: any, value: any, inverse: boolean = false): Store {\n let _value_ = this.get(key);\n\n if (_value_) {\n value = deepClone(value);\n _value_ = deepClone(_value_);\n value = inverse ? deepMerge(value, _value_) : deepMerge(_value_, value);\n }\n\n this.set(key, value);\n\n return this;\n }\n\n toJson() {\n return [...this._entries.entries()].reduce((obj, [key, value]) => {\n return {\n ...obj,\n [key]: value\n };\n }, {});\n }\n}\n"]}
|
|
@@ -2,6 +2,7 @@ import { decoratorTypeOf } from "../utils/decorators/decoratorTypeOf.js";
|
|
|
2
2
|
import { classOf } from "../utils/objects/classOf.js";
|
|
3
3
|
import { nameOf } from "../utils/objects/nameOf.js";
|
|
4
4
|
export class UnsupportedDecoratorType extends Error {
|
|
5
|
+
name;
|
|
5
6
|
constructor(decorator, args) {
|
|
6
7
|
super(UnsupportedDecoratorType.buildMessage(decorator, args));
|
|
7
8
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UnsupportedDecoratorType.js","sourceRoot":"","sources":["../../../src/errors/UnsupportedDecorat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D,MAAM,IAAI,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,MAAM,GAAG,KAAK,CAAC;QAEtD,OAAO,GAAG,SAAS,CAAC,IAAI,sBAAsB,WAAW,iBAAiB,IAAI,EAAE,CAAC;IACnF,CAAC;CACF","sourcesContent":["import {decoratorTypeOf} from \"../utils/decorators/decoratorTypeOf\";\nimport {classOf} from \"../utils/objects/classOf\";\nimport {nameOf} from \"../utils/objects/nameOf\";\n\nexport class UnsupportedDecoratorType extends Error {\n name: \"UNSUPPORTED_DECORATOR_TYPE\";\n\n constructor(decorator: any, args: any[]) {\n super(UnsupportedDecoratorType.buildMessage(decorator, args));\n }\n\n private static buildMessage(decorator: any, args: any[]): string {\n const [target, propertyKey, index] = args;\n\n const bindingType = decoratorTypeOf(args);\n const shortBinding = bindingType.split(\"/\")[0];\n const param = shortBinding === \"parameter\" ? \".[\" + index + \"]\" : \"\";\n const cstr = shortBinding === \"parameter\" ? \".constructor\" : \"\";\n const method = propertyKey ? \".\" + propertyKey : cstr;\n\n const path = nameOf(classOf(target)) + method + param;\n\n return `${decorator.name} cannot be used as ${bindingType} decorator on ${path}`;\n }\n}\n"]}
|
|
@@ -8,7 +8,6 @@ export function descriptorOf(target, propertyKey) {
|
|
|
8
8
|
return Object.getOwnPropertyDescriptor((target && target.prototype) || target, propertyKey);
|
|
9
9
|
}
|
|
10
10
|
export function isMethodDescriptor(target, propertyKey) {
|
|
11
|
-
|
|
12
|
-
return (_a = descriptorOf(target, propertyKey)) === null || _a === void 0 ? void 0 : _a.value;
|
|
11
|
+
return descriptorOf(target, propertyKey)?.value;
|
|
13
12
|
}
|
|
14
13
|
//# sourceMappingURL=descriptorOf.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"descriptorOf.js","sourceRoot":"","sources":["../../../../src/utils/objects/descriptorOf.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAAC,MAAW,EAAE,WAA4B;IACpE,OAAO,MAAM,CAAC,wBAAwB,CAAC,CAAC,MAAM,IAAI,MAAM,CAAC,SAAS,CAAC,IAAI,MAAM,EAAE,WAAW,CAAE,CAAC;AAC/F,CAAC;AAED,MAAM,UAAU,kBAAkB,CAAC,MAAW,EAAE,WAA4B
|
|
1
|
+
{"version":3,"file":"descriptorOf.js","sourceRoot":"","sources":["../../../../src/utils/objects/descriptorOf.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAAC,MAAW,EAAE,WAA4B;IACpE,OAAO,MAAM,CAAC,wBAAwB,CAAC,CAAC,MAAM,IAAI,MAAM,CAAC,SAAS,CAAC,IAAI,MAAM,EAAE,WAAW,CAAE,CAAC;AAC/F,CAAC;AAED,MAAM,UAAU,kBAAkB,CAAC,MAAW,EAAE,WAA4B;IAC1E,OAAO,YAAY,CAAC,MAAM,EAAE,WAAW,CAAC,EAAE,KAAK,CAAC;AAClD,CAAC","sourcesContent":["/**\n * Return the descriptor for a given class and propertyKey\n * @param target\n * @param {string} propertyKey\n * @returns {PropertyDescriptor}\n */\nexport function descriptorOf(target: any, propertyKey: string | symbol): PropertyDescriptor {\n return Object.getOwnPropertyDescriptor((target && target.prototype) || target, propertyKey)!;\n}\n\nexport function isMethodDescriptor(target: any, propertyKey: string | symbol) {\n return descriptorOf(target, propertyKey)?.value;\n}\n"]}
|