@rsdk/metadata 2.4.2-next.0 → 2.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/exception.d.ts +15 -0
- package/dist/exception.js +26 -0
- package/dist/resource-aggregator.d.ts +32 -0
- package/dist/resource-aggregator.js +69 -0
- package/dist/resource-extractor.d.ts +5 -0
- package/dist/resource-extractor.js +2 -0
- package/dist/utils/nest-assert.d.ts +6 -0
- package/dist/utils/nest-assert.js +16 -0
- package/package.json +5 -5
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ResourceExtractor } from './resource-extractor';
|
|
2
|
+
declare abstract class RsdkMetadataProviderException extends Error {
|
|
3
|
+
name: string;
|
|
4
|
+
}
|
|
5
|
+
export declare class ExtractFailed extends RsdkMetadataProviderException {
|
|
6
|
+
readonly exception: unknown;
|
|
7
|
+
readonly extractor: ResourceExtractor;
|
|
8
|
+
readonly metadataSource: unknown;
|
|
9
|
+
constructor(exception: unknown, extractor: ResourceExtractor, metadataSource: unknown);
|
|
10
|
+
}
|
|
11
|
+
export declare class IncorrectNestDefinitionType extends RsdkMetadataProviderException {
|
|
12
|
+
readonly nestDefinition: unknown;
|
|
13
|
+
constructor(nestDefinition: unknown);
|
|
14
|
+
}
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.IncorrectNestDefinitionType = exports.ExtractFailed = void 0;
|
|
4
|
+
class RsdkMetadataProviderException extends Error {
|
|
5
|
+
name = this.constructor.name;
|
|
6
|
+
}
|
|
7
|
+
class ExtractFailed extends RsdkMetadataProviderException {
|
|
8
|
+
exception;
|
|
9
|
+
extractor;
|
|
10
|
+
metadataSource;
|
|
11
|
+
constructor(exception, extractor, metadataSource) {
|
|
12
|
+
super();
|
|
13
|
+
this.exception = exception;
|
|
14
|
+
this.extractor = extractor;
|
|
15
|
+
this.metadataSource = metadataSource;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.ExtractFailed = ExtractFailed;
|
|
19
|
+
class IncorrectNestDefinitionType extends RsdkMetadataProviderException {
|
|
20
|
+
nestDefinition;
|
|
21
|
+
constructor(nestDefinition) {
|
|
22
|
+
super(`Expect object, but received: ${nestDefinition}`);
|
|
23
|
+
this.nestDefinition = nestDefinition;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.IncorrectNestDefinitionType = IncorrectNestDefinitionType;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { Resource } from './metadata';
|
|
2
|
+
/**
|
|
3
|
+
* Хелпер для работы с массивами ресурсов, включающий функционал дедупликации по сигнатуре
|
|
4
|
+
*/
|
|
5
|
+
export declare class ResourceAggregator {
|
|
6
|
+
readonly resources: Resource<unknown>[];
|
|
7
|
+
private readonly map;
|
|
8
|
+
private readonly keys;
|
|
9
|
+
/**
|
|
10
|
+
* Проверка есть ли уже такой ресурс в агрегаторе
|
|
11
|
+
* @param resource
|
|
12
|
+
*/
|
|
13
|
+
isDuplicate(resource: Resource<unknown>): boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Добавить новый ресурс
|
|
16
|
+
* Если ресурс с такой же сигнатурой уже будет найден, он будет пропущен
|
|
17
|
+
* @param resources
|
|
18
|
+
*/
|
|
19
|
+
add(...resources: Resource<unknown>[]): void;
|
|
20
|
+
/**
|
|
21
|
+
* Внутренний метод добавления, не делает никаких проверок на существование с такой же сигнатурой
|
|
22
|
+
* @param resource
|
|
23
|
+
* @private
|
|
24
|
+
*/
|
|
25
|
+
private handle;
|
|
26
|
+
/**
|
|
27
|
+
* Добавляет сигнатуру в "существующие" в списке
|
|
28
|
+
* @param resource
|
|
29
|
+
* @private
|
|
30
|
+
*/
|
|
31
|
+
private handleSignature;
|
|
32
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ResourceAggregator = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Хелпер для работы с массивами ресурсов, включающий функционал дедупликации по сигнатуре
|
|
6
|
+
*/
|
|
7
|
+
class ResourceAggregator {
|
|
8
|
+
resources = [];
|
|
9
|
+
map = new Map();
|
|
10
|
+
keys = new Set();
|
|
11
|
+
/**
|
|
12
|
+
* Проверка есть ли уже такой ресурс в агрегаторе
|
|
13
|
+
* @param resource
|
|
14
|
+
*/
|
|
15
|
+
isDuplicate(resource) {
|
|
16
|
+
const hasKey = Object.hasOwn(resource, 'key');
|
|
17
|
+
if (!hasKey) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
const hasScope = Object.hasOwn(resource, 'scope');
|
|
21
|
+
if (hasScope) {
|
|
22
|
+
const keys = this.map.get(resource.scope);
|
|
23
|
+
return Boolean(keys?.some((key) => key === resource.key));
|
|
24
|
+
}
|
|
25
|
+
return this.keys.has(resource.key);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Добавить новый ресурс
|
|
29
|
+
* Если ресурс с такой же сигнатурой уже будет найден, он будет пропущен
|
|
30
|
+
* @param resources
|
|
31
|
+
*/
|
|
32
|
+
add(...resources) {
|
|
33
|
+
for (const resource of resources) {
|
|
34
|
+
const isDuplicate = this.isDuplicate(resource);
|
|
35
|
+
if (isDuplicate) {
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
this.handle(resource);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Внутренний метод добавления, не делает никаких проверок на существование с такой же сигнатурой
|
|
43
|
+
* @param resource
|
|
44
|
+
* @private
|
|
45
|
+
*/
|
|
46
|
+
handle(resource) {
|
|
47
|
+
this.handleSignature(resource);
|
|
48
|
+
this.resources.push(resource);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Добавляет сигнатуру в "существующие" в списке
|
|
52
|
+
* @param resource
|
|
53
|
+
* @private
|
|
54
|
+
*/
|
|
55
|
+
handleSignature(resource) {
|
|
56
|
+
const hasKey = Object.hasOwn(resource, 'key');
|
|
57
|
+
if (!hasKey) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
const hasScope = Object.hasOwn(resource, 'scope');
|
|
61
|
+
if (hasScope) {
|
|
62
|
+
const keys = this.map.get(resource.scope) ?? [];
|
|
63
|
+
this.map.set(resource.scope, [...keys, resource.key]);
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
this.keys.add(resource.key);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
exports.ResourceAggregator = ResourceAggregator;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { ClassProvider, DynamicModule, ExistingProvider, FactoryProvider, InjectionToken, ValueProvider } from '@nestjs/common';
|
|
2
|
+
import type { Resource } from './metadata';
|
|
3
|
+
export interface ResourceExtractor {
|
|
4
|
+
extract(value: DynamicModule | ClassProvider<any> | ValueProvider<any> | FactoryProvider<any> | ExistingProvider<any> | InjectionToken): Resource<unknown>[];
|
|
5
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Abstract, ClassProvider, DynamicModule, ExistingProvider, FactoryProvider, Type, ValueProvider } from '@nestjs/common';
|
|
2
|
+
export declare class NestAssert {
|
|
3
|
+
static isNestDefinition(nestDefinition: DynamicModule | Type<any> | ClassProvider<any> | ValueProvider<any> | FactoryProvider<any> | ExistingProvider<any> | string | symbol | Abstract<any>): nestDefinition is DynamicModule | Type<any> | ClassProvider<any> | ValueProvider<any> | FactoryProvider<any> | ExistingProvider<any> | Abstract<any> | Function;
|
|
4
|
+
static isObjectOrCtor(v: unknown): v is object | Function;
|
|
5
|
+
static isObject(v: unknown): v is object;
|
|
6
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NestAssert = void 0;
|
|
4
|
+
class NestAssert {
|
|
5
|
+
static isNestDefinition(nestDefinition) {
|
|
6
|
+
return ['object', 'function'].includes(typeof nestDefinition);
|
|
7
|
+
}
|
|
8
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
9
|
+
static isObjectOrCtor(v) {
|
|
10
|
+
return ['object', 'function'].includes(typeof v);
|
|
11
|
+
}
|
|
12
|
+
static isObject(v) {
|
|
13
|
+
return typeof v === 'object';
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.NestAssert = NestAssert;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rsdk/metadata",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.5.1",
|
|
4
4
|
"license": "Apache License 2.0",
|
|
5
5
|
"description": "Rsdk stack metadata management",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -13,10 +13,10 @@
|
|
|
13
13
|
"peerDependencies": {
|
|
14
14
|
"@nestjs/common": "^9.0.0",
|
|
15
15
|
"@nestjs/core": "^9.0.0",
|
|
16
|
-
"@rsdk/common": "^2.4.2
|
|
17
|
-
"@rsdk/logging": "^2.
|
|
18
|
-
"@rsdk/nest-tools": "^2.4.2
|
|
16
|
+
"@rsdk/common": "^2.4.2",
|
|
17
|
+
"@rsdk/logging": "^2.5.1",
|
|
18
|
+
"@rsdk/nest-tools": "^2.4.2",
|
|
19
19
|
"reflect-metadata": "^0.1.13"
|
|
20
20
|
},
|
|
21
|
-
"gitHead": "
|
|
21
|
+
"gitHead": "8762f61fce4c854db863ef204d245d1f69d51655"
|
|
22
22
|
}
|