@rsdk/nest-tools 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/.eslintignore +4 -0
- package/.eslintrc.js +4 -0
- package/.prettierignore +1 -0
- package/.prettierrc.json +1 -0
- package/CHANGELOG.md +10 -0
- package/TODO.md +1 -0
- package/dist/constants.d.ts +6 -0
- package/dist/constants.js +10 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +9 -0
- package/dist/nest-definition.d.ts +17 -0
- package/dist/nest-definition.js +53 -0
- package/dist/nest-definition.mediator.d.ts +8 -0
- package/dist/nest-definition.mediator.js +45 -0
- package/package.json +14 -0
- package/src/constants.ts +6 -0
- package/src/index.ts +5 -0
- package/src/nest-definition.mediator.ts +56 -0
- package/src/nest-definition.ts +67 -0
- package/tsconfig.build.json +6 -0
- package/tsconfig.json +19 -0
package/.eslintignore
ADDED
package/.eslintrc.js
ADDED
package/.prettierignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
**/*.spec.ts
|
package/.prettierrc.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"@rsdk/prettier-config"
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# Change Log
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
|
+
|
|
6
|
+
## 1.0.10 (2023-05-22)
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* add "access: public" to new packages ([04d5983](https://github.com/R-Vision/rsdk/commit/04d5983cfa3e97c5d8219e07208a0499a8c6bc83))
|
package/TODO.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
- [ ] Привести api в чувство, потому что на данный момент написано на коленке
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NestDefinitionType = void 0;
|
|
4
|
+
var NestDefinitionType;
|
|
5
|
+
(function (NestDefinitionType) {
|
|
6
|
+
NestDefinitionType[NestDefinitionType["Module"] = 1] = "Module";
|
|
7
|
+
NestDefinitionType[NestDefinitionType["Controllers"] = 2] = "Controllers";
|
|
8
|
+
NestDefinitionType[NestDefinitionType["Providers"] = 4] = "Providers";
|
|
9
|
+
NestDefinitionType[NestDefinitionType["Exports"] = 8] = "Exports";
|
|
10
|
+
})(NestDefinitionType = exports.NestDefinitionType || (exports.NestDefinitionType = {}));
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NestDefinition = exports.NestDefinitionMediator = exports.NestDefinitionType = void 0;
|
|
4
|
+
var constants_1 = require("./constants");
|
|
5
|
+
Object.defineProperty(exports, "NestDefinitionType", { enumerable: true, get: function () { return constants_1.NestDefinitionType; } });
|
|
6
|
+
var nest_definition_mediator_1 = require("./nest-definition.mediator");
|
|
7
|
+
Object.defineProperty(exports, "NestDefinitionMediator", { enumerable: true, get: function () { return nest_definition_mediator_1.NestDefinitionMediator; } });
|
|
8
|
+
var nest_definition_1 = require("./nest-definition");
|
|
9
|
+
Object.defineProperty(exports, "NestDefinition", { enumerable: true, get: function () { return nest_definition_1.NestDefinition; } });
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { DynamicModule, Provider, Type } from '@nestjs/common';
|
|
2
|
+
export type NestModuleDefinition = DynamicModule | Type;
|
|
3
|
+
/**
|
|
4
|
+
* Хелпер для работы с объявлением модуля nest.
|
|
5
|
+
* Получения провайдеров и импортов
|
|
6
|
+
*
|
|
7
|
+
* TODO: Объяснить что это за нафиг?
|
|
8
|
+
*/
|
|
9
|
+
export declare class NestDefinition {
|
|
10
|
+
private definition;
|
|
11
|
+
constructor(definition: NestModuleDefinition);
|
|
12
|
+
getProviders(): Provider[] | undefined;
|
|
13
|
+
getImports(): NestModuleDefinition[] | undefined;
|
|
14
|
+
getControllers(): Type[] | undefined;
|
|
15
|
+
getExports(): Type[] | undefined;
|
|
16
|
+
private reflectMetadata;
|
|
17
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NestDefinition = void 0;
|
|
4
|
+
const constants_1 = require("@nestjs/common/constants");
|
|
5
|
+
const scanner_1 = require("@nestjs/core/scanner");
|
|
6
|
+
/**
|
|
7
|
+
* Хелпер для работы с объявлением модуля nest.
|
|
8
|
+
* Получения провайдеров и импортов
|
|
9
|
+
*
|
|
10
|
+
* TODO: Объяснить что это за нафиг?
|
|
11
|
+
*/
|
|
12
|
+
class NestDefinition {
|
|
13
|
+
definition;
|
|
14
|
+
constructor(definition) {
|
|
15
|
+
this.definition = definition;
|
|
16
|
+
}
|
|
17
|
+
getProviders() {
|
|
18
|
+
return !scanner_1.DependenciesScanner.prototype.isDynamicModule(this.definition)
|
|
19
|
+
? this.reflectMetadata(constants_1.MODULE_METADATA.PROVIDERS, this.definition)
|
|
20
|
+
: [
|
|
21
|
+
...this.reflectMetadata(constants_1.MODULE_METADATA.PROVIDERS, this.definition.module),
|
|
22
|
+
...(this.definition.providers || []),
|
|
23
|
+
];
|
|
24
|
+
}
|
|
25
|
+
getImports() {
|
|
26
|
+
return !scanner_1.DependenciesScanner.prototype.isDynamicModule(this.definition)
|
|
27
|
+
? this.reflectMetadata(constants_1.MODULE_METADATA.IMPORTS, this.definition)
|
|
28
|
+
: [
|
|
29
|
+
...this.reflectMetadata(constants_1.MODULE_METADATA.IMPORTS, this.definition.module),
|
|
30
|
+
...(this.definition.imports || []),
|
|
31
|
+
];
|
|
32
|
+
}
|
|
33
|
+
getControllers() {
|
|
34
|
+
return !scanner_1.DependenciesScanner.prototype.isDynamicModule(this.definition)
|
|
35
|
+
? this.reflectMetadata(constants_1.MODULE_METADATA.CONTROLLERS, this.definition)
|
|
36
|
+
: [
|
|
37
|
+
...this.reflectMetadata(constants_1.MODULE_METADATA.CONTROLLERS, this.definition.module),
|
|
38
|
+
...(this.definition.controllers || []),
|
|
39
|
+
];
|
|
40
|
+
}
|
|
41
|
+
getExports() {
|
|
42
|
+
return !scanner_1.DependenciesScanner.prototype.isDynamicModule(this.definition)
|
|
43
|
+
? this.reflectMetadata(constants_1.MODULE_METADATA.EXPORTS, this.definition)
|
|
44
|
+
: [
|
|
45
|
+
...this.reflectMetadata(constants_1.MODULE_METADATA.EXPORTS, this.definition.module),
|
|
46
|
+
...(this.definition.exports || []),
|
|
47
|
+
];
|
|
48
|
+
}
|
|
49
|
+
reflectMetadata(metadataKey, metatype) {
|
|
50
|
+
return Reflect.getMetadata(metadataKey, metatype) || [];
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
exports.NestDefinition = NestDefinition;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Provider } from '@nestjs/common';
|
|
2
|
+
import { NestDefinitionType } from './constants';
|
|
3
|
+
import type { NestModuleDefinition } from './nest-definition';
|
|
4
|
+
export declare class NestDefinitionMediator {
|
|
5
|
+
private nestModuleDefinition;
|
|
6
|
+
constructor(nestModuleDefinition: NestModuleDefinition);
|
|
7
|
+
iterate(type?: NestDefinitionType): AsyncIterableIterator<NestModuleDefinition | Provider>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NestDefinitionMediator = void 0;
|
|
4
|
+
const constants_1 = require("./constants");
|
|
5
|
+
const nest_definition_1 = require("./nest-definition");
|
|
6
|
+
class NestDefinitionMediator {
|
|
7
|
+
nestModuleDefinition;
|
|
8
|
+
constructor(nestModuleDefinition) {
|
|
9
|
+
this.nestModuleDefinition = nestModuleDefinition;
|
|
10
|
+
}
|
|
11
|
+
async *iterate(type) {
|
|
12
|
+
const iterateAll = typeof type === 'undefined';
|
|
13
|
+
const iterateModule = iterateAll || type & constants_1.NestDefinitionType.Module;
|
|
14
|
+
if (iterateModule) {
|
|
15
|
+
yield this.nestModuleDefinition;
|
|
16
|
+
}
|
|
17
|
+
const nestDefinition = new nest_definition_1.NestDefinition(this.nestModuleDefinition);
|
|
18
|
+
const nestImports = await nestDefinition.getImports();
|
|
19
|
+
const iterateProviders = iterateAll || type & constants_1.NestDefinitionType.Providers;
|
|
20
|
+
if (iterateProviders) {
|
|
21
|
+
const providers = nestDefinition.getProviders();
|
|
22
|
+
for (const provider of providers ?? []) {
|
|
23
|
+
yield provider;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
const iterateExports = iterateAll || type & constants_1.NestDefinitionType.Exports;
|
|
27
|
+
if (iterateExports) {
|
|
28
|
+
const exports = nestDefinition.getExports();
|
|
29
|
+
for (const nestExport of exports ?? []) {
|
|
30
|
+
yield nestExport;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
const iterateControllers = iterateAll || type & constants_1.NestDefinitionType.Controllers;
|
|
34
|
+
if (iterateControllers) {
|
|
35
|
+
const controllers = nestDefinition.getControllers();
|
|
36
|
+
for (const controller of controllers ?? []) {
|
|
37
|
+
yield controller;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
for (const nestImport of nestImports ?? []) {
|
|
41
|
+
yield* new NestDefinitionMediator(nestImport).iterate(type);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
exports.NestDefinitionMediator = NestDefinitionMediator;
|
package/package.json
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@rsdk/nest-tools",
|
|
3
|
+
"version": "1.0.10",
|
|
4
|
+
"license": "Apache License 2.0",
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"access": "public"
|
|
7
|
+
},
|
|
8
|
+
"main": "dist/index.js",
|
|
9
|
+
"peerDependencies": {
|
|
10
|
+
"@nestjs/common": "~9.3.8",
|
|
11
|
+
"@nestjs/core": "~9.3.8"
|
|
12
|
+
},
|
|
13
|
+
"gitHead": "b5bf31eb623ae5d3fbd71aa1598cf199407d7703"
|
|
14
|
+
}
|
package/src/constants.ts
ADDED
package/src/index.ts
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { Provider } from '@nestjs/common';
|
|
2
|
+
|
|
3
|
+
import { NestDefinitionType } from './constants';
|
|
4
|
+
import type { NestModuleDefinition } from './nest-definition';
|
|
5
|
+
import { NestDefinition } from './nest-definition';
|
|
6
|
+
|
|
7
|
+
export class NestDefinitionMediator {
|
|
8
|
+
constructor(private nestModuleDefinition: NestModuleDefinition) {}
|
|
9
|
+
|
|
10
|
+
async *iterate(
|
|
11
|
+
type?: NestDefinitionType,
|
|
12
|
+
): AsyncIterableIterator<NestModuleDefinition | Provider> {
|
|
13
|
+
const iterateAll = typeof type === 'undefined';
|
|
14
|
+
const iterateModule = iterateAll || type & NestDefinitionType.Module;
|
|
15
|
+
if (iterateModule) {
|
|
16
|
+
yield this.nestModuleDefinition;
|
|
17
|
+
}
|
|
18
|
+
const nestDefinition = new NestDefinition(this.nestModuleDefinition);
|
|
19
|
+
|
|
20
|
+
const nestImports = await nestDefinition.getImports();
|
|
21
|
+
|
|
22
|
+
const iterateProviders = iterateAll || type & NestDefinitionType.Providers;
|
|
23
|
+
if (iterateProviders) {
|
|
24
|
+
const providers = nestDefinition.getProviders();
|
|
25
|
+
|
|
26
|
+
for (const provider of providers ?? []) {
|
|
27
|
+
yield provider;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const iterateExports = iterateAll || type & NestDefinitionType.Exports;
|
|
32
|
+
|
|
33
|
+
if (iterateExports) {
|
|
34
|
+
const exports = nestDefinition.getExports();
|
|
35
|
+
|
|
36
|
+
for (const nestExport of exports ?? []) {
|
|
37
|
+
yield nestExport;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const iterateControllers =
|
|
42
|
+
iterateAll || type & NestDefinitionType.Controllers;
|
|
43
|
+
|
|
44
|
+
if (iterateControllers) {
|
|
45
|
+
const controllers = nestDefinition.getControllers();
|
|
46
|
+
|
|
47
|
+
for (const controller of controllers ?? []) {
|
|
48
|
+
yield controller;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
for (const nestImport of nestImports ?? []) {
|
|
53
|
+
yield* new NestDefinitionMediator(nestImport).iterate(type);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { DynamicModule, Provider, Type } from '@nestjs/common';
|
|
2
|
+
import { MODULE_METADATA } from '@nestjs/common/constants';
|
|
3
|
+
import { DependenciesScanner } from '@nestjs/core/scanner';
|
|
4
|
+
|
|
5
|
+
export type NestModuleDefinition = DynamicModule | Type;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Хелпер для работы с объявлением модуля nest.
|
|
9
|
+
* Получения провайдеров и импортов
|
|
10
|
+
*
|
|
11
|
+
* TODO: Объяснить что это за нафиг?
|
|
12
|
+
*/
|
|
13
|
+
export class NestDefinition {
|
|
14
|
+
constructor(private definition: NestModuleDefinition) {}
|
|
15
|
+
|
|
16
|
+
getProviders(): Provider[] | undefined {
|
|
17
|
+
return !DependenciesScanner.prototype.isDynamicModule(this.definition)
|
|
18
|
+
? this.reflectMetadata(MODULE_METADATA.PROVIDERS, this.definition)
|
|
19
|
+
: [
|
|
20
|
+
...this.reflectMetadata(
|
|
21
|
+
MODULE_METADATA.PROVIDERS,
|
|
22
|
+
this.definition.module,
|
|
23
|
+
),
|
|
24
|
+
...(this.definition.providers || []),
|
|
25
|
+
];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
getImports(): NestModuleDefinition[] | undefined {
|
|
29
|
+
return !DependenciesScanner.prototype.isDynamicModule(this.definition)
|
|
30
|
+
? this.reflectMetadata(MODULE_METADATA.IMPORTS, this.definition)
|
|
31
|
+
: [
|
|
32
|
+
...this.reflectMetadata(
|
|
33
|
+
MODULE_METADATA.IMPORTS,
|
|
34
|
+
this.definition.module,
|
|
35
|
+
),
|
|
36
|
+
...(this.definition.imports || []),
|
|
37
|
+
];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
getControllers(): Type[] | undefined {
|
|
41
|
+
return !DependenciesScanner.prototype.isDynamicModule(this.definition)
|
|
42
|
+
? this.reflectMetadata(MODULE_METADATA.CONTROLLERS, this.definition)
|
|
43
|
+
: [
|
|
44
|
+
...this.reflectMetadata(
|
|
45
|
+
MODULE_METADATA.CONTROLLERS,
|
|
46
|
+
this.definition.module,
|
|
47
|
+
),
|
|
48
|
+
...(this.definition.controllers || []),
|
|
49
|
+
];
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
getExports(): Type[] | undefined {
|
|
53
|
+
return !DependenciesScanner.prototype.isDynamicModule(this.definition)
|
|
54
|
+
? this.reflectMetadata(MODULE_METADATA.EXPORTS, this.definition)
|
|
55
|
+
: [
|
|
56
|
+
...this.reflectMetadata(
|
|
57
|
+
MODULE_METADATA.EXPORTS,
|
|
58
|
+
this.definition.module,
|
|
59
|
+
),
|
|
60
|
+
...(this.definition.exports || []),
|
|
61
|
+
];
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
private reflectMetadata<T = any>(metadataKey: string, metatype: Type): T[] {
|
|
65
|
+
return Reflect.getMetadata(metadataKey, metatype) || [];
|
|
66
|
+
}
|
|
67
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "@rsdk/tsconfig/base.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"declaration": true,
|
|
5
|
+
"outDir": "dist",
|
|
6
|
+
"sourceMap": false,
|
|
7
|
+
"esModuleInterop": true,
|
|
8
|
+
"allowSyntheticDefaultImports": true
|
|
9
|
+
},
|
|
10
|
+
"include": [
|
|
11
|
+
"src/**/*"
|
|
12
|
+
],
|
|
13
|
+
"exclude": [
|
|
14
|
+
"node_modules",
|
|
15
|
+
"dist",
|
|
16
|
+
"test",
|
|
17
|
+
"**/*spec.ts"
|
|
18
|
+
]
|
|
19
|
+
}
|