@typeix/metadata 8.1.3 → 8.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/metadata.js +27 -27
- package/package.json +4 -4
package/dist/metadata.js
CHANGED
|
@@ -12,7 +12,7 @@ exports.TS_PARAMS = "design:paramtypes";
|
|
|
12
12
|
exports.TS_TYPE = "design:type";
|
|
13
13
|
exports.TS_RETURN = "design:returntype";
|
|
14
14
|
function defineMetadata(metadataKey, metadataValue, target, targetKey) {
|
|
15
|
-
if (utils_1.inArray([exports.TS_TYPE, exports.TS_PARAMS, exports.TS_RETURN], metadataKey)) {
|
|
15
|
+
if ((0, utils_1.inArray)([exports.TS_TYPE, exports.TS_PARAMS, exports.TS_RETURN], metadataKey)) {
|
|
16
16
|
throw new Error(`You can't override typescript metadata: ${exports.TS_TYPE}, ${exports.TS_PARAMS}, ${exports.TS_RETURN}`);
|
|
17
17
|
}
|
|
18
18
|
Reflect.defineMetadata(metadataKey, metadataValue, target, targetKey);
|
|
@@ -53,7 +53,7 @@ function getOwnMetadataKeys(target, targetKey) {
|
|
|
53
53
|
}
|
|
54
54
|
exports.getOwnMetadataKeys = getOwnMetadataKeys;
|
|
55
55
|
function deleteMetadata(metadataKey, target, targetKey) {
|
|
56
|
-
if (utils_1.inArray([exports.TS_TYPE, exports.TS_PARAMS, exports.TS_RETURN], metadataKey)) {
|
|
56
|
+
if ((0, utils_1.inArray)([exports.TS_TYPE, exports.TS_PARAMS, exports.TS_RETURN], metadataKey)) {
|
|
57
57
|
throw new Error(`You can't delete typescript metadata: ${exports.TS_TYPE}, ${exports.TS_PARAMS}, ${exports.TS_RETURN}`);
|
|
58
58
|
}
|
|
59
59
|
try {
|
|
@@ -65,32 +65,32 @@ function deleteMetadata(metadataKey, target, targetKey) {
|
|
|
65
65
|
}
|
|
66
66
|
exports.deleteMetadata = deleteMetadata;
|
|
67
67
|
function isDecorator(decorator) {
|
|
68
|
-
return utils_1.isTruthy(decorator[TX_ID]);
|
|
68
|
+
return (0, utils_1.isTruthy)(decorator[TX_ID]);
|
|
69
69
|
}
|
|
70
70
|
exports.isDecorator = isDecorator;
|
|
71
71
|
function getDecoratorId(decorator, index) {
|
|
72
|
-
if (utils_1.isFalsy(decorator[TX_ID])) {
|
|
72
|
+
if ((0, utils_1.isFalsy)(decorator[TX_ID])) {
|
|
73
73
|
throw new TypeError(`Decorator must be created via @typeix decorator functions: ${decorator.toString()}`);
|
|
74
74
|
}
|
|
75
|
-
return decorator[TX_ID] + (utils_1.isNumber(index) ? `:${index}` : "");
|
|
75
|
+
return decorator[TX_ID] + ((0, utils_1.isNumber)(index) ? `:${index}` : "");
|
|
76
76
|
}
|
|
77
77
|
exports.getDecoratorId = getDecoratorId;
|
|
78
78
|
function getDecoratorUUID(decorator) {
|
|
79
|
-
if (utils_1.isFalsy(decorator[TX_UUID])) {
|
|
79
|
+
if ((0, utils_1.isFalsy)(decorator[TX_UUID])) {
|
|
80
80
|
throw new TypeError(`Decorator must be created via @typeix decorator functions: ${decorator.toString()}`);
|
|
81
81
|
}
|
|
82
82
|
return decorator[TX_UUID];
|
|
83
83
|
}
|
|
84
84
|
exports.getDecoratorUUID = getDecoratorUUID;
|
|
85
85
|
function getDecoratorType(decorator) {
|
|
86
|
-
if (utils_1.isFalsy(decorator[TX_TYPE])) {
|
|
86
|
+
if ((0, utils_1.isFalsy)(decorator[TX_TYPE])) {
|
|
87
87
|
throw new TypeError(`Decorator must be created via @typeix decorator functions: ${decorator.toString()}`);
|
|
88
88
|
}
|
|
89
89
|
return decorator[TX_TYPE];
|
|
90
90
|
}
|
|
91
91
|
exports.getDecoratorType = getDecoratorType;
|
|
92
92
|
function getDecoratorName(decorator) {
|
|
93
|
-
if (utils_1.isFalsy(decorator[TX_NAME])) {
|
|
93
|
+
if ((0, utils_1.isFalsy)(decorator[TX_NAME])) {
|
|
94
94
|
throw new TypeError(`Decorator must be created via @typeix decorator functions: ${decorator.toString()}`);
|
|
95
95
|
}
|
|
96
96
|
return decorator[TX_NAME];
|
|
@@ -143,15 +143,15 @@ function mapKeyToMetadata(key) {
|
|
|
143
143
|
}
|
|
144
144
|
return {
|
|
145
145
|
args: metadata,
|
|
146
|
-
propertyKey: utils_1.isDefined(key.propertyKey) ? key.propertyKey : "constructor",
|
|
146
|
+
propertyKey: (0, utils_1.isDefined)(key.propertyKey) ? key.propertyKey : "constructor",
|
|
147
147
|
metadataKey: key.metadataKey
|
|
148
148
|
};
|
|
149
149
|
}
|
|
150
150
|
function mergeKeys(a, b) {
|
|
151
|
-
return a.concat(b.filter((bI) => utils_1.isFalsy(a.find((aI) => aI.metadataKey === bI.metadataKey && aI.propertyKey === bI.propertyKey))));
|
|
151
|
+
return a.concat(b.filter((bI) => (0, utils_1.isFalsy)(a.find((aI) => aI.metadataKey === bI.metadataKey && aI.propertyKey === bI.propertyKey))));
|
|
152
152
|
}
|
|
153
153
|
function getMetadataKeysForTarget(target, targetKey) {
|
|
154
|
-
let _target = utils_1.isObject(target.prototype) && !!targetKey ? target.prototype : target;
|
|
154
|
+
let _target = (0, utils_1.isObject)(target.prototype) && !!targetKey ? target.prototype : target;
|
|
155
155
|
return getMetadataKeys(_target, targetKey)
|
|
156
156
|
.map(key => {
|
|
157
157
|
return {
|
|
@@ -164,17 +164,17 @@ function getMetadataKeysForTarget(target, targetKey) {
|
|
|
164
164
|
exports.getMetadataKeysForTarget = getMetadataKeysForTarget;
|
|
165
165
|
function getMetadataForTarget(target, targetKey) {
|
|
166
166
|
let keys = getMetadataKeysForTarget(target, targetKey), proto = Object.getPrototypeOf(target);
|
|
167
|
-
if (!utils_1.isNull(proto)) {
|
|
167
|
+
if (!(0, utils_1.isNull)(proto)) {
|
|
168
168
|
keys = mergeKeys(keys, getMetadataKeysForTarget(proto, targetKey));
|
|
169
169
|
}
|
|
170
|
-
return utils_1.flatten(keys.map(item => mapKeyToMetadata(item)));
|
|
170
|
+
return (0, utils_1.flatten)(keys.map(item => mapKeyToMetadata(item)));
|
|
171
171
|
}
|
|
172
172
|
exports.getMetadataForTarget = getMetadataForTarget;
|
|
173
173
|
function getAllKeysForTarget(target) {
|
|
174
|
-
let keys = utils_1.isObject(target.prototype) ? [{ target: target, key: undefined }] : [], _target = utils_1.isObject(target.prototype) ? target.prototype : target;
|
|
174
|
+
let keys = (0, utils_1.isObject)(target.prototype) ? [{ target: target, key: undefined }] : [], _target = (0, utils_1.isObject)(target.prototype) ? target.prototype : target;
|
|
175
175
|
return keys.concat(Reflect
|
|
176
176
|
.ownKeys(_target)
|
|
177
|
-
.filter(item => utils_1.isSymbol(item) || utils_1.isString(item))
|
|
177
|
+
.filter(item => (0, utils_1.isSymbol)(item) || (0, utils_1.isString)(item))
|
|
178
178
|
.map(key => {
|
|
179
179
|
return {
|
|
180
180
|
key,
|
|
@@ -186,48 +186,48 @@ exports.getAllKeysForTarget = getAllKeysForTarget;
|
|
|
186
186
|
function getAllMetadataKeysForTarget(target) {
|
|
187
187
|
let keys = getAllKeysForTarget(target), metadata = [], proto = Object.getPrototypeOf(target);
|
|
188
188
|
keys.forEach(item => metadata = metadata.concat(getMetadataKeysForTarget(item.target, item.key)));
|
|
189
|
-
if (!utils_1.isNull(proto)) {
|
|
189
|
+
if (!(0, utils_1.isNull)(proto)) {
|
|
190
190
|
metadata = mergeKeys(metadata, getAllMetadataKeysForTarget(proto));
|
|
191
191
|
}
|
|
192
192
|
return metadata;
|
|
193
193
|
}
|
|
194
194
|
exports.getAllMetadataKeysForTarget = getAllMetadataKeysForTarget;
|
|
195
195
|
function getAllMetadataForTarget(target) {
|
|
196
|
-
return utils_1.flatten(getAllMetadataKeysForTarget(target).map(item => mapKeyToMetadata(item)));
|
|
196
|
+
return (0, utils_1.flatten)(getAllMetadataKeysForTarget(target).map(item => mapKeyToMetadata(item)));
|
|
197
197
|
}
|
|
198
198
|
exports.getAllMetadataForTarget = getAllMetadataForTarget;
|
|
199
199
|
function getType(target, parameterOrDescriptor, propertyKey, type) {
|
|
200
|
-
type = type === "mixed" ? utils_1.isNumber(parameterOrDescriptor) ? "parameter" : "property" : type;
|
|
201
|
-
if (utils_1.inArray(["property", "parameter"], type) && utils_1.isFunction(target) && utils_1.isDefined(propertyKey)) {
|
|
200
|
+
type = type === "mixed" ? (0, utils_1.isNumber)(parameterOrDescriptor) ? "parameter" : "property" : type;
|
|
201
|
+
if ((0, utils_1.inArray)(["property", "parameter"], type) && (0, utils_1.isFunction)(target) && (0, utils_1.isDefined)(propertyKey)) {
|
|
202
202
|
throw new TypeError(`Decorator can´t be declared on static method/property: ${propertyKey}`);
|
|
203
203
|
}
|
|
204
|
-
return type === "method" && utils_1.isFunction(target) ? "static" : type;
|
|
204
|
+
return type === "method" && (0, utils_1.isFunction)(target) ? "static" : type;
|
|
205
205
|
}
|
|
206
206
|
function decorate(decorator, type, args) {
|
|
207
|
-
if (utils_1.isFalsy(decorator.name)) {
|
|
207
|
+
if ((0, utils_1.isFalsy)(decorator.name)) {
|
|
208
208
|
throw new TypeError([
|
|
209
209
|
"Decorator can't be anonymous function",
|
|
210
210
|
`you need to pass function declaration or function expression: ${decorator.toString()}`
|
|
211
211
|
].join());
|
|
212
212
|
}
|
|
213
|
-
if (utils_1.isFalsy(decorator[TX_ID])) {
|
|
214
|
-
decorator[TX_UUID] = utils_1.uuid();
|
|
213
|
+
if ((0, utils_1.isFalsy)(decorator[TX_ID])) {
|
|
214
|
+
decorator[TX_UUID] = (0, utils_1.uuid)();
|
|
215
215
|
decorator[TX_ID] = `${TX_PREFIX}:${type}:${decorator.name}:${decorator[TX_UUID]}`;
|
|
216
216
|
decorator[TX_NAME] = decorator.name;
|
|
217
217
|
decorator[TX_TYPE] = type;
|
|
218
218
|
}
|
|
219
219
|
return (target, propertyKey, parameterOrDescriptor) => {
|
|
220
220
|
let metadata = {
|
|
221
|
-
args: utils_1.isTruthy(args) ? { ...args } : {},
|
|
221
|
+
args: (0, utils_1.isTruthy)(args) ? { ...args } : {},
|
|
222
222
|
decorator: decorator,
|
|
223
223
|
decoratorType: type,
|
|
224
224
|
type: getType(target, parameterOrDescriptor, propertyKey, type),
|
|
225
225
|
metadataKey: ""
|
|
226
226
|
};
|
|
227
|
-
if (utils_1.isNumber(parameterOrDescriptor)) {
|
|
227
|
+
if ((0, utils_1.isNumber)(parameterOrDescriptor)) {
|
|
228
228
|
metadata.paramIndex = parameterOrDescriptor;
|
|
229
229
|
}
|
|
230
|
-
metadata.propertyKey = utils_1.isTruthy(propertyKey) ? propertyKey : "constructor";
|
|
230
|
+
metadata.propertyKey = (0, utils_1.isTruthy)(propertyKey) ? propertyKey : "constructor";
|
|
231
231
|
if (hasMetadata(exports.TS_TYPE, target, propertyKey)) {
|
|
232
232
|
metadata.designType = getMetadata(exports.TS_TYPE, target, propertyKey);
|
|
233
233
|
}
|
|
@@ -240,7 +240,7 @@ function decorate(decorator, type, args) {
|
|
|
240
240
|
metadata.metadataKey = getDecoratorId(decorator, metadata.paramIndex);
|
|
241
241
|
if (hasMetadata(metadata.metadataKey, target, propertyKey) && metadata.type === "method") {
|
|
242
242
|
const currentMetadata = getMetadata(metadata.metadataKey, target, propertyKey);
|
|
243
|
-
if (utils_1.isArray(currentMetadata)) {
|
|
243
|
+
if ((0, utils_1.isArray)(currentMetadata)) {
|
|
244
244
|
currentMetadata.push(metadata);
|
|
245
245
|
defineMetadata(metadata.metadataKey, currentMetadata, target, propertyKey);
|
|
246
246
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@typeix/metadata",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.2.2",
|
|
4
4
|
"description": "@typeix metadata apis::::",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -29,14 +29,14 @@
|
|
|
29
29
|
},
|
|
30
30
|
"homepage": "https://typeix.com",
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@typeix/utils": "^8.
|
|
32
|
+
"@typeix/utils": "^8.2.2",
|
|
33
33
|
"reflect-metadata": "^0.1.13"
|
|
34
34
|
},
|
|
35
35
|
"publishConfig": {
|
|
36
36
|
"access": "public"
|
|
37
37
|
},
|
|
38
38
|
"engines": {
|
|
39
|
-
"node": ">=
|
|
39
|
+
"node": ">=16.10.0"
|
|
40
40
|
},
|
|
41
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "6df8101e353233e545d2db587e32b9f86afc5bfc"
|
|
42
42
|
}
|