@rsdk/metadata 4.0.4 → 4.0.5
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/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import 'reflect-metadata';
|
|
2
|
-
export {
|
|
2
|
+
export { PLATFORM_RAW_GLOBAL_METADATA_SCOPE, PlatformRawGlobalMetadata, RSDK_METADATA_KEY, } from './constants';
|
|
3
3
|
export { NestAssert } from './utils/nest-assert';
|
|
4
4
|
export { ResourceExtractor } from './resource-extractor';
|
|
5
5
|
export { RsdkMetadataProvider } from './rsdk-metadata-provider';
|
|
@@ -3,6 +3,3 @@ import type { Resource } from './metadata';
|
|
|
3
3
|
export interface ResourceExtractor {
|
|
4
4
|
extract(value: DynamicModule | ClassProvider<any> | ValueProvider<any> | FactoryProvider<any> | ExistingProvider<any> | InjectionToken): Resource<unknown>[];
|
|
5
5
|
}
|
|
6
|
-
export interface ModuleExtractor {
|
|
7
|
-
extract(value: DynamicModule | ClassProvider<any> | ValueProvider<any> | FactoryProvider<any> | ExistingProvider<any> | InjectionToken): DynamicModule[];
|
|
8
|
-
}
|
|
@@ -2,22 +2,16 @@ import type { ClassProvider, DynamicModule, ExistingProvider, FactoryProvider, I
|
|
|
2
2
|
import type { NestModuleDefinition } from '@rsdk/common.nestjs';
|
|
3
3
|
import type { Promisable } from 'type-fest';
|
|
4
4
|
import type { Resource } from './metadata';
|
|
5
|
-
import {
|
|
6
|
-
import type { ModuleExtractor, ResourceExtractor } from './resource-extractor';
|
|
7
|
-
type Extractors = {
|
|
8
|
-
resource?: ResourceExtractor[];
|
|
9
|
-
moduleExtractor?: ModuleExtractor[];
|
|
10
|
-
};
|
|
5
|
+
import type { ResourceExtractor } from './resource-extractor';
|
|
11
6
|
/**
|
|
12
7
|
* Провайдер агрегирующий в себе ресурсы из метаданных
|
|
13
8
|
* По задумке должен выступать лишь в роли фасада/агрегатора который знает о структуре ресурсов и её значении
|
|
14
9
|
* Также он знает о том где могут быть записаны rsdk метаданные
|
|
15
10
|
*/
|
|
16
11
|
export declare class RsdkMetadataProvider {
|
|
17
|
-
private
|
|
18
|
-
|
|
19
|
-
protected constructor(
|
|
20
|
-
static create(modules: Promisable<NestModuleDefinition>[], extractors?: Extractors): Promise<RsdkMetadataProvider>;
|
|
12
|
+
private readonly resources;
|
|
13
|
+
static create(modules: Promisable<NestModuleDefinition>[], extractors?: ResourceExtractor[]): Promise<RsdkMetadataProvider>;
|
|
14
|
+
protected constructor(resources: Resource<any>[]);
|
|
21
15
|
static getMetadataSource(nestDefinition: DynamicModule | Type | ClassProvider | ValueProvider | FactoryProvider | ExistingProvider | Function): IterableIterator<InjectionToken | DynamicModule | Type | ClassProvider | ValueProvider | FactoryProvider | ExistingProvider>;
|
|
22
16
|
/**
|
|
23
17
|
* Есть ли уже этот ресурс в массиве
|
|
@@ -26,8 +20,7 @@ export declare class RsdkMetadataProvider {
|
|
|
26
20
|
* @param definitionResource
|
|
27
21
|
*/
|
|
28
22
|
static isDuplicate(resources: Resource<any>[], definitionResource: Resource<unknown>): boolean;
|
|
29
|
-
private static extractResources;
|
|
30
23
|
get<T>(scope?: string): Resource<T>[];
|
|
31
24
|
add(...moduleDef: Promisable<NestModuleDefinition>[]): Promise<void>;
|
|
25
|
+
private static extractResources;
|
|
32
26
|
}
|
|
33
|
-
export {};
|
|
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.RsdkMetadataProvider = void 0;
|
|
4
4
|
const nest_tools_1 = require("@rsdk/nest-tools");
|
|
5
5
|
const nest_assert_1 = require("./utils/nest-assert");
|
|
6
|
-
const constants_1 = require("./constants");
|
|
7
6
|
const exception_1 = require("./exception");
|
|
8
7
|
const metadata_1 = require("./metadata");
|
|
9
8
|
const resource_aggregator_1 = require("./resource-aggregator");
|
|
@@ -13,16 +12,14 @@ const resource_aggregator_1 = require("./resource-aggregator");
|
|
|
13
12
|
* Также он знает о том где могут быть записаны rsdk метаданные
|
|
14
13
|
*/
|
|
15
14
|
class RsdkMetadataProvider {
|
|
16
|
-
|
|
17
|
-
extractors;
|
|
18
|
-
constructor(resourceAggregator, extractors) {
|
|
19
|
-
this.resourceAggregator = resourceAggregator;
|
|
20
|
-
this.extractors = extractors;
|
|
21
|
-
}
|
|
15
|
+
resources;
|
|
22
16
|
static async create(modules, extractors) {
|
|
23
|
-
const
|
|
24
|
-
await this.extractResources(modules,
|
|
25
|
-
return new RsdkMetadataProvider(
|
|
17
|
+
const resources = [];
|
|
18
|
+
await this.extractResources(modules, resources, extractors);
|
|
19
|
+
return new RsdkMetadataProvider(resources);
|
|
20
|
+
}
|
|
21
|
+
constructor(resources) {
|
|
22
|
+
this.resources = resources;
|
|
26
23
|
}
|
|
27
24
|
static *getMetadataSource(nestDefinition) {
|
|
28
25
|
// TODO: throw exception
|
|
@@ -50,7 +47,17 @@ class RsdkMetadataProvider {
|
|
|
50
47
|
static isDuplicate(resources, definitionResource) {
|
|
51
48
|
return resources.some((resource) => metadata_1.RsdkMetadata.isEqual(resource, definitionResource));
|
|
52
49
|
}
|
|
53
|
-
|
|
50
|
+
get(scope) {
|
|
51
|
+
if (scope === undefined) {
|
|
52
|
+
return this.resources;
|
|
53
|
+
}
|
|
54
|
+
return this.resources.filter((resource) => resource.scope === scope);
|
|
55
|
+
}
|
|
56
|
+
async add(...moduleDef) {
|
|
57
|
+
await RsdkMetadataProvider.extractResources(moduleDef, this.resources);
|
|
58
|
+
}
|
|
59
|
+
static async extractResources(rootModule, resources, extractors) {
|
|
60
|
+
const resourceAggregator = new resource_aggregator_1.ResourceAggregator();
|
|
54
61
|
for await (const rootModuleElement of rootModule) {
|
|
55
62
|
const nestDefinitionIterator = new nest_tools_1.NestDefinitionIterator(rootModuleElement);
|
|
56
63
|
for await (const nestDefinition of nestDefinitionIterator.iterate()) {
|
|
@@ -62,7 +69,7 @@ class RsdkMetadataProvider {
|
|
|
62
69
|
continue;
|
|
63
70
|
}
|
|
64
71
|
const definitionResources = metadata_1.RsdkMetadata.get(metadataSource);
|
|
65
|
-
const extractedResources = extractors?.
|
|
72
|
+
const extractedResources = extractors?.reduce((acc, extractor) => {
|
|
66
73
|
try {
|
|
67
74
|
const resources = extractor.extract(metadataSource);
|
|
68
75
|
acc.push(...resources);
|
|
@@ -79,23 +86,11 @@ class RsdkMetadataProvider {
|
|
|
79
86
|
if (!foundedResources?.length) {
|
|
80
87
|
continue;
|
|
81
88
|
}
|
|
82
|
-
const extractedModules = foundedResources
|
|
83
|
-
.filter(({ scope }) => scope === constants_1.PLATFORM_RAW_GLOBAL_METADATA_SCOPE)
|
|
84
|
-
.map(({ value }) => value);
|
|
85
|
-
await RsdkMetadataProvider.extractResources(extractedModules, resourceAggregator, extractors);
|
|
86
89
|
resourceAggregator.add(...foundedResources);
|
|
87
90
|
}
|
|
88
91
|
}
|
|
89
92
|
}
|
|
90
|
-
|
|
91
|
-
get(scope) {
|
|
92
|
-
if (scope === undefined) {
|
|
93
|
-
return this.resourceAggregator.resources;
|
|
94
|
-
}
|
|
95
|
-
return this.resourceAggregator.resources.filter((resource) => resource.scope === scope);
|
|
96
|
-
}
|
|
97
|
-
async add(...moduleDef) {
|
|
98
|
-
await RsdkMetadataProvider.extractResources(moduleDef, this.resourceAggregator, this.extractors);
|
|
93
|
+
resources.push(...resourceAggregator.resources);
|
|
99
94
|
}
|
|
100
95
|
}
|
|
101
96
|
exports.RsdkMetadataProvider = RsdkMetadataProvider;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rsdk/metadata",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.5",
|
|
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": "^10.0.0",
|
|
15
15
|
"@nestjs/core": "^10.0.0",
|
|
16
|
-
"@rsdk/common": "^4.0.
|
|
17
|
-
"@rsdk/logging": "^4.0.
|
|
18
|
-
"@rsdk/nest-tools": "^4.0.
|
|
16
|
+
"@rsdk/common": "^4.0.5",
|
|
17
|
+
"@rsdk/logging": "^4.0.5",
|
|
18
|
+
"@rsdk/nest-tools": "^4.0.5",
|
|
19
19
|
"reflect-metadata": "^0.1.13"
|
|
20
20
|
},
|
|
21
|
-
"gitHead": "
|
|
21
|
+
"gitHead": "374611198a781fec1328b9b2f1ff977eb1bdaa16"
|
|
22
22
|
}
|