@rsdk/metadata 1.0.10
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/constants.d.ts +1 -0
- package/dist/constants.js +4 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +6 -0
- package/dist/metadata.d.ts +47 -0
- package/dist/metadata.js +68 -0
- package/package.json +19 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const RSDK_METADATA_KEY: unique symbol;
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RsdkMetadata = void 0;
|
|
4
|
+
require("reflect-metadata");
|
|
5
|
+
var metadata_1 = require("./metadata");
|
|
6
|
+
Object.defineProperty(exports, "RsdkMetadata", { enumerable: true, get: function () { return metadata_1.RsdkMetadata; } });
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Абстракция для изоляции значений метаданных...
|
|
3
|
+
* От метаданных rsdk...
|
|
4
|
+
*/
|
|
5
|
+
export type Resource<T> = {
|
|
6
|
+
/**
|
|
7
|
+
* Произвольная строка идентификатор исключительно для упрощения работы с метаданными в рамках модулей.
|
|
8
|
+
* Чтобы получать только значения по-определенному скоупу.
|
|
9
|
+
* Никаких дополнительных проверок не происходит, используется обычный массив
|
|
10
|
+
*/
|
|
11
|
+
scope: string;
|
|
12
|
+
value: T;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* RSDK metadata for object
|
|
16
|
+
*/
|
|
17
|
+
export declare class RsdkMetadata<T = unknown> {
|
|
18
|
+
readonly target: any;
|
|
19
|
+
readonly scope?: string | undefined;
|
|
20
|
+
/**
|
|
21
|
+
* @param target Target object (could be anything)
|
|
22
|
+
* @param scope Just tag for organizing metadata into groups
|
|
23
|
+
*/
|
|
24
|
+
constructor(target: any, scope?: string | undefined);
|
|
25
|
+
/**
|
|
26
|
+
* Sets metadata for object itself
|
|
27
|
+
* @param value Metadata value (could be anything)
|
|
28
|
+
*/
|
|
29
|
+
add(value: T): void;
|
|
30
|
+
/**
|
|
31
|
+
* Sets metadata for property
|
|
32
|
+
* @param {string|symbol} propKey Property name
|
|
33
|
+
* @param value Metadata value (could be anything)
|
|
34
|
+
*/
|
|
35
|
+
addForProperty(propKey: string | symbol, value: T): void;
|
|
36
|
+
/**
|
|
37
|
+
* Gets metadata for object itself
|
|
38
|
+
* @returns {Resource<T>} Array of resources
|
|
39
|
+
*/
|
|
40
|
+
get(): Resource<T>[] | null;
|
|
41
|
+
/**
|
|
42
|
+
* Gets metadata for property
|
|
43
|
+
* @param propKey Property name
|
|
44
|
+
* @returns {Resource<T>} Array of resources
|
|
45
|
+
*/
|
|
46
|
+
getForProperty(propKey: string | symbol): Resource<T>[] | null;
|
|
47
|
+
}
|
package/dist/metadata.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RsdkMetadata = void 0;
|
|
4
|
+
const constants_1 = require("./constants");
|
|
5
|
+
/**
|
|
6
|
+
* RSDK metadata for object
|
|
7
|
+
*/
|
|
8
|
+
class RsdkMetadata {
|
|
9
|
+
target;
|
|
10
|
+
scope;
|
|
11
|
+
/**
|
|
12
|
+
* @param target Target object (could be anything)
|
|
13
|
+
* @param scope Just tag for organizing metadata into groups
|
|
14
|
+
*/
|
|
15
|
+
constructor(target, scope) {
|
|
16
|
+
this.target = target;
|
|
17
|
+
this.scope = scope;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Sets metadata for object itself
|
|
21
|
+
* @param value Metadata value (could be anything)
|
|
22
|
+
*/
|
|
23
|
+
add(value) {
|
|
24
|
+
const metadata = Reflect.getMetadata(constants_1.RSDK_METADATA_KEY, this.target) ?? [];
|
|
25
|
+
metadata.push({ scope: this.scope, value: value });
|
|
26
|
+
Reflect.defineMetadata(constants_1.RSDK_METADATA_KEY, metadata, this.target);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Sets metadata for property
|
|
30
|
+
* @param {string|symbol} propKey Property name
|
|
31
|
+
* @param value Metadata value (could be anything)
|
|
32
|
+
*/
|
|
33
|
+
addForProperty(propKey, value) {
|
|
34
|
+
const metadata = Reflect.getMetadata(constants_1.RSDK_METADATA_KEY, this.target, propKey) ?? [];
|
|
35
|
+
metadata.push({ scope: this.scope, value });
|
|
36
|
+
Reflect.defineMetadata(constants_1.RSDK_METADATA_KEY, metadata, this.target, propKey);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Gets metadata for object itself
|
|
40
|
+
* @returns {Resource<T>} Array of resources
|
|
41
|
+
*/
|
|
42
|
+
get() {
|
|
43
|
+
const resources = Reflect.getMetadata(constants_1.RSDK_METADATA_KEY, this.target);
|
|
44
|
+
if (!resources) {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
if (!this.scope) {
|
|
48
|
+
return resources;
|
|
49
|
+
}
|
|
50
|
+
return resources.filter((resource) => resource.scope === this.scope);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Gets metadata for property
|
|
54
|
+
* @param propKey Property name
|
|
55
|
+
* @returns {Resource<T>} Array of resources
|
|
56
|
+
*/
|
|
57
|
+
getForProperty(propKey) {
|
|
58
|
+
const resources = Reflect.getMetadata(constants_1.RSDK_METADATA_KEY, this.target, propKey);
|
|
59
|
+
if (!resources) {
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
if (!this.scope) {
|
|
63
|
+
return resources;
|
|
64
|
+
}
|
|
65
|
+
return resources.filter((resource) => resource.scope === this.scope);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
exports.RsdkMetadata = RsdkMetadata;
|
package/package.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@rsdk/metadata",
|
|
3
|
+
"version": "1.0.10",
|
|
4
|
+
"license": "Apache License 2.0",
|
|
5
|
+
"description": "Rsdk stack metadata management",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"publishConfig": {
|
|
8
|
+
"access": "public"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"dist"
|
|
12
|
+
],
|
|
13
|
+
"peerDependencies": {
|
|
14
|
+
"@nestjs/common": "~9.3.8",
|
|
15
|
+
"@nestjs/core": "~9.3.8",
|
|
16
|
+
"reflect-metadata": "^0.1.13"
|
|
17
|
+
},
|
|
18
|
+
"gitHead": "b5bf31eb623ae5d3fbd71aa1598cf199407d7703"
|
|
19
|
+
}
|