@cenk1cenk2/oclif-common 6.3.30 → 6.4.0
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/commands/base.command.d.ts +43 -0
- package/dist/commands/base.command.js +156 -0
- package/dist/commands/index.js +1 -0
- package/dist/constants/file.constants.d.ts +6 -0
- package/dist/constants/file.constants.js +8 -0
- package/dist/constants/help-groups.constants.d.ts +6 -0
- package/dist/constants/help-groups.constants.js +8 -0
- package/dist/hooks/index.js +2 -0
- package/dist/hooks/not-found.hook.d.ts +6 -0
- package/dist/hooks/not-found.hook.js +18 -0
- package/dist/hooks/update-notifier.hook.d.ts +6 -0
- package/dist/hooks/update-notifier.hook.js +11 -0
- package/dist/index.d.ts +51 -450
- package/dist/index.js +42 -1361
- package/dist/interfaces/class.interface.d.ts +4 -0
- package/dist/interfaces/hooks.interface.d.ts +16 -0
- package/dist/interfaces/index.js +1 -0
- package/dist/interfaces/oclif.interface.d.ts +9 -0
- package/dist/interfaces/oclif.interface.js +3 -0
- package/dist/interfaces/type-helper.interface.d.ts +7 -0
- package/dist/lib/cli.interface.d.ts +8 -0
- package/dist/lib/cli.module.d.ts +11 -0
- package/dist/lib/cli.module.js +57 -0
- package/dist/lib/config/config.constants.js +12 -0
- package/dist/lib/config/config.interface.d.ts +21 -0
- package/dist/lib/config/config.module.d.ts +4 -0
- package/dist/lib/config/config.module.js +15 -0
- package/dist/lib/config/config.service.d.ts +32 -0
- package/dist/lib/config/config.service.js +152 -0
- package/dist/lib/config/index.js +2 -0
- package/dist/lib/fs/filesystem.interface.d.ts +2 -0
- package/dist/lib/fs/filesystem.module.d.ts +4 -0
- package/dist/lib/fs/filesystem.module.js +13 -0
- package/dist/lib/fs/filesystem.service.d.ts +31 -0
- package/dist/lib/fs/filesystem.service.js +141 -0
- package/dist/lib/fs/index.js +2 -0
- package/dist/lib/index.js +32 -0
- package/dist/lib/locker/index.js +2 -0
- package/dist/lib/locker/locker.interface.d.ts +28 -0
- package/dist/lib/locker/locker.module.d.ts +9 -0
- package/dist/lib/locker/locker.module.js +33 -0
- package/dist/lib/locker/locker.service.d.ts +41 -0
- package/dist/lib/locker/locker.service.js +170 -0
- package/dist/lib/logger/index.js +6 -0
- package/dist/lib/logger/logger.constants.d.ts +21 -0
- package/dist/lib/logger/logger.constants.js +24 -0
- package/dist/lib/logger/logger.interface.d.ts +13 -0
- package/dist/lib/logger/logger.module.d.ts +4 -0
- package/dist/lib/logger/logger.module.js +17 -0
- package/dist/lib/logger/logger.service.d.ts +31 -0
- package/dist/lib/logger/logger.service.js +70 -0
- package/dist/lib/logger/pipe/pipe-process-to-listr.d.ts +7 -0
- package/dist/lib/logger/pipe/pipe-process-to-listr.js +9 -0
- package/dist/lib/logger/pipe/pipe-process-to-logger.d.ts +12 -0
- package/dist/lib/logger/pipe/pipe-process-to-logger.interface.d.ts +19 -0
- package/dist/lib/logger/pipe/pipe-process-to-logger.js +54 -0
- package/dist/lib/logger/winston.service.d.ts +15 -0
- package/dist/lib/logger/winston.service.js +91 -0
- package/dist/lib/logo/index.js +3 -0
- package/dist/lib/logo/logo.constants.d.ts +6 -0
- package/dist/lib/logo/logo.constants.js +5 -0
- package/dist/lib/logo/logo.interface.d.ts +6 -0
- package/dist/lib/logo/logo.module.d.ts +4 -0
- package/dist/lib/logo/logo.module.js +13 -0
- package/dist/lib/logo/logo.service.d.ts +17 -0
- package/dist/lib/logo/logo.service.js +42 -0
- package/dist/lib/parser/fts/env-parser.service.d.ts +16 -0
- package/dist/lib/parser/fts/env-parser.service.js +42 -0
- package/dist/lib/parser/fts/index.js +3 -0
- package/dist/lib/parser/fts/json-parser.service.d.ts +15 -0
- package/dist/lib/parser/fts/json-parser.service.js +32 -0
- package/dist/lib/parser/fts/yaml-parser.service.d.ts +15 -0
- package/dist/lib/parser/fts/yaml-parser.service.js +33 -0
- package/dist/lib/parser/index.js +6 -0
- package/dist/lib/parser/parser.interface.d.ts +8 -0
- package/dist/lib/parser/parser.module.d.ts +4 -0
- package/dist/lib/parser/parser.module.js +16 -0
- package/dist/lib/parser/parser.service.d.ts +29 -0
- package/dist/lib/parser/parser.service.js +76 -0
- package/dist/lib/setup.d.ts +4 -0
- package/dist/lib/setup.js +16 -0
- package/dist/lib/validator/index.js +3 -0
- package/dist/lib/validator/validator.constants.d.ts +6 -0
- package/dist/lib/validator/validator.constants.js +5 -0
- package/dist/lib/validator/validator.interface.d.ts +10 -0
- package/dist/lib/validator/validator.module.d.ts +4 -0
- package/dist/lib/validator/validator.module.js +13 -0
- package/dist/lib/validator/validator.service.d.ts +19 -0
- package/dist/lib/validator/validator.service.js +76 -0
- package/dist/utils/defaults.d.ts +12 -0
- package/dist/utils/defaults.js +16 -0
- package/dist/utils/environment.d.ts +8 -0
- package/dist/utils/environment.js +16 -0
- package/dist/utils/guards.d.ts +9 -0
- package/dist/utils/guards.js +13 -0
- package/dist/utils/index.d.ts +7 -0
- package/dist/utils/index.js +8 -0
- package/dist/utils/merge.constants.d.ts +7 -0
- package/dist/utils/merge.constants.js +9 -0
- package/dist/utils/merge.d.ts +9 -0
- package/dist/utils/merge.js +15 -0
- package/package.json +26 -22
- package/dist/chunk-DzC9Nte8.js +0 -31
- package/dist/source-map-support-CuBekda-.js +0 -2435
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { LogoService } from "./logo.service.js";
|
|
2
|
+
import { Module } from "@nestjs/common";
|
|
3
|
+
import _decorate from "@oxc-project/runtime/helpers/decorate";
|
|
4
|
+
|
|
5
|
+
//#region src/lib/logo/logo.module.ts
|
|
6
|
+
let LogoModule = class LogoModule$1 {};
|
|
7
|
+
LogoModule = _decorate([Module({
|
|
8
|
+
providers: [LogoService],
|
|
9
|
+
exports: [LogoService]
|
|
10
|
+
})], LogoModule);
|
|
11
|
+
|
|
12
|
+
//#endregion
|
|
13
|
+
export { LogoModule };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ConfigService } from "../config/config.service.js";
|
|
2
|
+
import { OnModuleInit } from "@nestjs/common";
|
|
3
|
+
import { ModuleRef } from "@nestjs/core";
|
|
4
|
+
|
|
5
|
+
//#region src/lib/logo/logo.service.d.ts
|
|
6
|
+
declare class LogoService implements OnModuleInit {
|
|
7
|
+
readonly cs: ConfigService;
|
|
8
|
+
private readonly moduleRef;
|
|
9
|
+
private generator;
|
|
10
|
+
constructor(cs: ConfigService, moduleRef: ModuleRef);
|
|
11
|
+
onModuleInit(): Promise<void>;
|
|
12
|
+
generate(): void;
|
|
13
|
+
shouldBeSilent(): boolean;
|
|
14
|
+
write(...data: string[]): void;
|
|
15
|
+
}
|
|
16
|
+
//#endregion
|
|
17
|
+
export { LogoService };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { ConfigService } from "../config/config.service.js";
|
|
2
|
+
import "../config/index.js";
|
|
3
|
+
import { TOKEN_LOGO_GENERATOR } from "./logo.constants.js";
|
|
4
|
+
import { Injectable } from "@nestjs/common";
|
|
5
|
+
import { EOL } from "os";
|
|
6
|
+
import _decorateMetadata from "@oxc-project/runtime/helpers/decorateMetadata";
|
|
7
|
+
import _decorate from "@oxc-project/runtime/helpers/decorate";
|
|
8
|
+
import { ModuleRef } from "@nestjs/core";
|
|
9
|
+
|
|
10
|
+
//#region src/lib/logo/logo.service.ts
|
|
11
|
+
var _ref, _ref2;
|
|
12
|
+
let LogoService = class LogoService$1 {
|
|
13
|
+
constructor(cs, moduleRef) {
|
|
14
|
+
this.cs = cs;
|
|
15
|
+
this.moduleRef = moduleRef;
|
|
16
|
+
}
|
|
17
|
+
async onModuleInit() {
|
|
18
|
+
try {
|
|
19
|
+
this.generator = this.moduleRef.get(TOKEN_LOGO_GENERATOR, { strict: false });
|
|
20
|
+
} catch {
|
|
21
|
+
this.generator = function() {
|
|
22
|
+
if (this.shouldBeSilent()) return;
|
|
23
|
+
const logo = this.cs.oclif.name + " v" + this.cs.oclif.version;
|
|
24
|
+
this.write(logo);
|
|
25
|
+
this.write("-".repeat(logo.length));
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
generate() {
|
|
30
|
+
return this.generator.call(this);
|
|
31
|
+
}
|
|
32
|
+
shouldBeSilent() {
|
|
33
|
+
return this.cs.isJson || this.cs.isSilent;
|
|
34
|
+
}
|
|
35
|
+
write(...data) {
|
|
36
|
+
process.stdout.write(data.join(" ") + EOL);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
LogoService = _decorate([Injectable(), _decorateMetadata("design:paramtypes", [typeof (_ref = typeof ConfigService !== "undefined" && ConfigService) === "function" ? _ref : Object, typeof (_ref2 = typeof ModuleRef !== "undefined" && ModuleRef) === "function" ? _ref2 : Object])], LogoService);
|
|
40
|
+
|
|
41
|
+
//#endregion
|
|
42
|
+
export { LogoService };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { GenericParser } from "../parser.interface.js";
|
|
2
|
+
import { LoggerService } from "../../logger/logger.service.js";
|
|
3
|
+
import { OnModuleInit } from "@nestjs/common";
|
|
4
|
+
|
|
5
|
+
//#region src/lib/parser/fts/env-parser.service.d.ts
|
|
6
|
+
declare class EnvironmentVariableParser implements GenericParser, OnModuleInit {
|
|
7
|
+
private readonly logger;
|
|
8
|
+
readonly extensions: string[];
|
|
9
|
+
private readonly LINE;
|
|
10
|
+
constructor(logger: LoggerService);
|
|
11
|
+
onModuleInit(): Promise<void>;
|
|
12
|
+
parse<T = unknown>(data: string | Buffer): T;
|
|
13
|
+
stringify<T = any>(data: T): string;
|
|
14
|
+
}
|
|
15
|
+
//#endregion
|
|
16
|
+
export { EnvironmentVariableParser };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { LoggerService } from "../../logger/logger.service.js";
|
|
2
|
+
import "../../logger/index.js";
|
|
3
|
+
import { Injectable } from "@nestjs/common";
|
|
4
|
+
import { EOL } from "os";
|
|
5
|
+
import _decorateMetadata from "@oxc-project/runtime/helpers/decorateMetadata";
|
|
6
|
+
import _decorate from "@oxc-project/runtime/helpers/decorate";
|
|
7
|
+
|
|
8
|
+
//#region src/lib/parser/fts/env-parser.service.ts
|
|
9
|
+
var _ref;
|
|
10
|
+
let EnvironmentVariableParser = class EnvironmentVariableParser$1 {
|
|
11
|
+
constructor(logger) {
|
|
12
|
+
this.logger = logger;
|
|
13
|
+
this.extensions = ["env"];
|
|
14
|
+
this.LINE = /(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/gm;
|
|
15
|
+
}
|
|
16
|
+
async onModuleInit() {
|
|
17
|
+
this.logger.setup(this.constructor.name);
|
|
18
|
+
}
|
|
19
|
+
parse(data) {
|
|
20
|
+
try {
|
|
21
|
+
return data.toString().split(EOL).reduce((o, line) => {
|
|
22
|
+
const match = this.LINE.exec(line);
|
|
23
|
+
const key = match[1];
|
|
24
|
+
const value = match[2] ?? "";
|
|
25
|
+
return {
|
|
26
|
+
...o,
|
|
27
|
+
[key]: value
|
|
28
|
+
};
|
|
29
|
+
}, {});
|
|
30
|
+
} catch (e) {
|
|
31
|
+
this.logger.trace("Error during parsing environment file: %s", e.message);
|
|
32
|
+
throw e;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
stringify(data) {
|
|
36
|
+
return Object.entries(data).map(([k, v]) => `${k}=${v}`).join(EOL) + EOL;
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
EnvironmentVariableParser = _decorate([Injectable(), _decorateMetadata("design:paramtypes", [typeof (_ref = typeof LoggerService !== "undefined" && LoggerService) === "function" ? _ref : Object])], EnvironmentVariableParser);
|
|
40
|
+
|
|
41
|
+
//#endregion
|
|
42
|
+
export { EnvironmentVariableParser };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { GenericParser } from "../parser.interface.js";
|
|
2
|
+
import { LoggerService } from "../../logger/logger.service.js";
|
|
3
|
+
import { OnModuleInit } from "@nestjs/common";
|
|
4
|
+
|
|
5
|
+
//#region src/lib/parser/fts/json-parser.service.d.ts
|
|
6
|
+
declare class JsonParser implements GenericParser, OnModuleInit {
|
|
7
|
+
private readonly logger;
|
|
8
|
+
readonly extensions: string[];
|
|
9
|
+
constructor(logger: LoggerService);
|
|
10
|
+
onModuleInit(): Promise<void>;
|
|
11
|
+
parse<T = unknown>(data: string | Buffer): T;
|
|
12
|
+
stringify<T = any>(data: T): string;
|
|
13
|
+
}
|
|
14
|
+
//#endregion
|
|
15
|
+
export { JsonParser };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { LoggerService } from "../../logger/logger.service.js";
|
|
2
|
+
import "../../logger/index.js";
|
|
3
|
+
import { Injectable } from "@nestjs/common";
|
|
4
|
+
import _decorateMetadata from "@oxc-project/runtime/helpers/decorateMetadata";
|
|
5
|
+
import _decorate from "@oxc-project/runtime/helpers/decorate";
|
|
6
|
+
|
|
7
|
+
//#region src/lib/parser/fts/json-parser.service.ts
|
|
8
|
+
var _ref;
|
|
9
|
+
let JsonParser = class JsonParser$1 {
|
|
10
|
+
constructor(logger) {
|
|
11
|
+
this.logger = logger;
|
|
12
|
+
this.extensions = ["json"];
|
|
13
|
+
}
|
|
14
|
+
async onModuleInit() {
|
|
15
|
+
this.logger.setup(this.constructor.name);
|
|
16
|
+
}
|
|
17
|
+
parse(data) {
|
|
18
|
+
try {
|
|
19
|
+
return JSON.parse(data.toString());
|
|
20
|
+
} catch (e) {
|
|
21
|
+
this.logger.trace("Error during parsing JSON file: %s", e.message);
|
|
22
|
+
throw e;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
stringify(data) {
|
|
26
|
+
return JSON.stringify(data, null, 2);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
JsonParser = _decorate([Injectable(), _decorateMetadata("design:paramtypes", [typeof (_ref = typeof LoggerService !== "undefined" && LoggerService) === "function" ? _ref : Object])], JsonParser);
|
|
30
|
+
|
|
31
|
+
//#endregion
|
|
32
|
+
export { JsonParser };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { GenericParser } from "../parser.interface.js";
|
|
2
|
+
import { LoggerService } from "../../logger/logger.service.js";
|
|
3
|
+
import { OnModuleInit } from "@nestjs/common";
|
|
4
|
+
|
|
5
|
+
//#region src/lib/parser/fts/yaml-parser.service.d.ts
|
|
6
|
+
declare class YamlParser implements GenericParser, OnModuleInit {
|
|
7
|
+
private readonly logger;
|
|
8
|
+
readonly extensions: string[];
|
|
9
|
+
constructor(logger: LoggerService);
|
|
10
|
+
onModuleInit(): Promise<void>;
|
|
11
|
+
parse<T = unknown>(data: string | Buffer): T;
|
|
12
|
+
stringify<T = any>(data: T): string;
|
|
13
|
+
}
|
|
14
|
+
//#endregion
|
|
15
|
+
export { YamlParser };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { LoggerService } from "../../logger/logger.service.js";
|
|
2
|
+
import "../../logger/index.js";
|
|
3
|
+
import { Injectable } from "@nestjs/common";
|
|
4
|
+
import _decorateMetadata from "@oxc-project/runtime/helpers/decorateMetadata";
|
|
5
|
+
import _decorate from "@oxc-project/runtime/helpers/decorate";
|
|
6
|
+
import { parse, stringify } from "yaml";
|
|
7
|
+
|
|
8
|
+
//#region src/lib/parser/fts/yaml-parser.service.ts
|
|
9
|
+
var _ref;
|
|
10
|
+
let YamlParser = class YamlParser$1 {
|
|
11
|
+
constructor(logger) {
|
|
12
|
+
this.logger = logger;
|
|
13
|
+
this.extensions = ["yaml", "yml"];
|
|
14
|
+
}
|
|
15
|
+
async onModuleInit() {
|
|
16
|
+
this.logger.setup(this.constructor.name);
|
|
17
|
+
}
|
|
18
|
+
parse(data) {
|
|
19
|
+
try {
|
|
20
|
+
return parse(data.toString());
|
|
21
|
+
} catch (e) {
|
|
22
|
+
this.logger.trace("Error during parsing YAML file: %s", e.message);
|
|
23
|
+
throw e;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
stringify(data) {
|
|
27
|
+
return stringify(data, { prettyErrors: true });
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
YamlParser = _decorate([Injectable(), _decorateMetadata("design:paramtypes", [typeof (_ref = typeof LoggerService !== "undefined" && LoggerService) === "function" ? _ref : Object])], YamlParser);
|
|
31
|
+
|
|
32
|
+
//#endregion
|
|
33
|
+
export { YamlParser };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ParserService } from "./parser.service.js";
|
|
2
|
+
import { ParserModule } from "./parser.module.js";
|
|
3
|
+
import { EnvironmentVariableParser } from "./fts/env-parser.service.js";
|
|
4
|
+
import { JsonParser } from "./fts/json-parser.service.js";
|
|
5
|
+
import { YamlParser } from "./fts/yaml-parser.service.js";
|
|
6
|
+
import "./fts/index.js";
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { FilesystemModule } from "../fs/filesystem.module.js";
|
|
2
|
+
import "../fs/index.js";
|
|
3
|
+
import { ParserService } from "./parser.service.js";
|
|
4
|
+
import { Global, Module } from "@nestjs/common";
|
|
5
|
+
import _decorate from "@oxc-project/runtime/helpers/decorate";
|
|
6
|
+
|
|
7
|
+
//#region src/lib/parser/parser.module.ts
|
|
8
|
+
let ParserModule = class ParserModule$1 {};
|
|
9
|
+
ParserModule = _decorate([Global(), Module({
|
|
10
|
+
imports: [FilesystemModule],
|
|
11
|
+
providers: [ParserService],
|
|
12
|
+
exports: [ParserService]
|
|
13
|
+
})], ParserModule);
|
|
14
|
+
|
|
15
|
+
//#endregion
|
|
16
|
+
export { ParserModule };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { ClassType } from "../../interfaces/class.interface.js";
|
|
2
|
+
import { GenericParser } from "./parser.interface.js";
|
|
3
|
+
import { LoggerService } from "../logger/logger.service.js";
|
|
4
|
+
import { FileSystemService } from "../fs/filesystem.service.js";
|
|
5
|
+
import { LockableData } from "../locker/locker.interface.js";
|
|
6
|
+
import { OnModuleInit } from "@nestjs/common";
|
|
7
|
+
import { ModuleRef } from "@nestjs/core";
|
|
8
|
+
|
|
9
|
+
//#region src/lib/parser/parser.service.d.ts
|
|
10
|
+
declare class ParserService implements OnModuleInit {
|
|
11
|
+
private moduleRef;
|
|
12
|
+
private fs;
|
|
13
|
+
private readonly logger;
|
|
14
|
+
private readonly instances;
|
|
15
|
+
constructor(moduleRef: ModuleRef, fs: FileSystemService, logger: LoggerService);
|
|
16
|
+
onModuleInit(): Promise<void>;
|
|
17
|
+
byFt(file: string): GenericParser;
|
|
18
|
+
fetch<T extends GenericParser>(Parser: ClassType<T>): T;
|
|
19
|
+
inject<T extends GenericParser>(Parser: ClassType<T>): Promise<T>;
|
|
20
|
+
register(...parsers: ClassType<GenericParser>[]): Promise<void>;
|
|
21
|
+
read<T = unknown>(file: string): Promise<T>;
|
|
22
|
+
write<T = LockableData>(file: string, data: T): Promise<void>;
|
|
23
|
+
parse<T = unknown>(file: string, data: string | Buffer): T;
|
|
24
|
+
parseWith<T = unknown>(Parser: ClassType<GenericParser>, data: string | Buffer): T;
|
|
25
|
+
stringify<T = any>(file: string, data: T): string;
|
|
26
|
+
stringifyWith<T = any>(Parser: ClassType<GenericParser>, data: T): string;
|
|
27
|
+
}
|
|
28
|
+
//#endregion
|
|
29
|
+
export { ParserService };
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { LoggerService } from "../logger/logger.service.js";
|
|
2
|
+
import "../logger/index.js";
|
|
3
|
+
import { FileSystemService } from "../fs/filesystem.service.js";
|
|
4
|
+
import "../fs/index.js";
|
|
5
|
+
import { Injectable } from "@nestjs/common";
|
|
6
|
+
import _decorateMetadata from "@oxc-project/runtime/helpers/decorateMetadata";
|
|
7
|
+
import _decorate from "@oxc-project/runtime/helpers/decorate";
|
|
8
|
+
import { ModuleRef } from "@nestjs/core";
|
|
9
|
+
|
|
10
|
+
//#region src/lib/parser/parser.service.ts
|
|
11
|
+
var _ref, _ref2, _ref3;
|
|
12
|
+
let ParserService = class ParserService$1 {
|
|
13
|
+
constructor(moduleRef, fs, logger) {
|
|
14
|
+
this.moduleRef = moduleRef;
|
|
15
|
+
this.fs = fs;
|
|
16
|
+
this.logger = logger;
|
|
17
|
+
this.instances = [];
|
|
18
|
+
}
|
|
19
|
+
async onModuleInit() {
|
|
20
|
+
this.logger.setup(this.constructor.name);
|
|
21
|
+
}
|
|
22
|
+
byFt(file) {
|
|
23
|
+
const ext = (file.includes(".") ? this.fs.extname(file) : file).replace(/^\./, "");
|
|
24
|
+
const Parser = this.instances.find((parser) => parser.extensions.includes(ext));
|
|
25
|
+
if (!Parser) throw new Error(`Parser for the extension is not configured: ${ext}`);
|
|
26
|
+
return Parser;
|
|
27
|
+
}
|
|
28
|
+
fetch(Parser) {
|
|
29
|
+
const parser = this.instances.find((instance) => instance instanceof Parser);
|
|
30
|
+
if (!parser) throw new Error(`Specified parser has not been initiated: ${Parser.name}`);
|
|
31
|
+
return parser;
|
|
32
|
+
}
|
|
33
|
+
async inject(Parser) {
|
|
34
|
+
const parser = await this.moduleRef.create(Parser);
|
|
35
|
+
this.instances.push(parser);
|
|
36
|
+
return parser;
|
|
37
|
+
}
|
|
38
|
+
async register(...parsers) {
|
|
39
|
+
await Promise.all(parsers.map(async (parser) => this.inject(parser)));
|
|
40
|
+
this.logger.trace("Registered parsers: %o", parsers.map((p) => p.name));
|
|
41
|
+
}
|
|
42
|
+
async read(file) {
|
|
43
|
+
return this.parse(file, await this.fs.read(file));
|
|
44
|
+
}
|
|
45
|
+
async write(file, data) {
|
|
46
|
+
return this.fs.write(file, this.stringify(file, data));
|
|
47
|
+
}
|
|
48
|
+
parse(file, data) {
|
|
49
|
+
const parser = this.byFt(file);
|
|
50
|
+
this.logger.trace("Parsing file: %s -> %s", file, parser.constructor.name);
|
|
51
|
+
return parser.parse(data);
|
|
52
|
+
}
|
|
53
|
+
parseWith(Parser, data) {
|
|
54
|
+
const parser = this.fetch(Parser);
|
|
55
|
+
this.logger.trace("Parsing data with: %s", parser.constructor.name);
|
|
56
|
+
return parser.parse(data);
|
|
57
|
+
}
|
|
58
|
+
stringify(file, data) {
|
|
59
|
+
const parser = this.byFt(file);
|
|
60
|
+
this.logger.trace("Stringifying file: %s -> %s", file, parser.constructor.name);
|
|
61
|
+
return parser.stringify(data);
|
|
62
|
+
}
|
|
63
|
+
stringifyWith(Parser, data) {
|
|
64
|
+
const parser = this.fetch(Parser);
|
|
65
|
+
this.logger.trace("Stringifying data: %s", parser.constructor.name);
|
|
66
|
+
return parser.stringify(data);
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
ParserService = _decorate([Injectable(), _decorateMetadata("design:paramtypes", [
|
|
70
|
+
typeof (_ref = typeof ModuleRef !== "undefined" && ModuleRef) === "function" ? _ref : Object,
|
|
71
|
+
typeof (_ref2 = typeof FileSystemService !== "undefined" && FileSystemService) === "function" ? _ref2 : Object,
|
|
72
|
+
typeof (_ref3 = typeof LoggerService !== "undefined" && LoggerService) === "function" ? _ref3 : Object
|
|
73
|
+
])], ParserService);
|
|
74
|
+
|
|
75
|
+
//#endregion
|
|
76
|
+
export { ParserService };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
//#region src/lib/setup.ts
|
|
2
|
+
async function setup() {
|
|
3
|
+
const inspect = process.argv.indexOf("--inspect");
|
|
4
|
+
if (inspect !== -1) {
|
|
5
|
+
await import("inspector").then((mod) => mod.open());
|
|
6
|
+
process.argv.splice(inspect, 1);
|
|
7
|
+
}
|
|
8
|
+
const sourceMaps = process.argv.indexOf("--source-map");
|
|
9
|
+
if (sourceMaps !== -1) {
|
|
10
|
+
await import("source-map-support").then((mod) => mod.install());
|
|
11
|
+
process.argv.splice(sourceMaps, 1);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
//#endregion
|
|
16
|
+
export { setup };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ClassTransformOptions } from "class-transformer";
|
|
2
|
+
import { ValidatorOptions } from "class-validator";
|
|
3
|
+
|
|
4
|
+
//#region src/lib/validator/validator.interface.d.ts
|
|
5
|
+
interface ValidatorServiceOptions {
|
|
6
|
+
validator?: ValidatorOptions;
|
|
7
|
+
transformer?: ClassTransformOptions;
|
|
8
|
+
}
|
|
9
|
+
//#endregion
|
|
10
|
+
export { ValidatorServiceOptions };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ValidatorService } from "./validator.service.js";
|
|
2
|
+
import { Global, Module } from "@nestjs/common";
|
|
3
|
+
import _decorate from "@oxc-project/runtime/helpers/decorate";
|
|
4
|
+
|
|
5
|
+
//#region src/lib/validator/validator.module.ts
|
|
6
|
+
let ValidatorModule = class ValidatorModule$1 {};
|
|
7
|
+
ValidatorModule = _decorate([Global(), Module({
|
|
8
|
+
providers: [ValidatorService],
|
|
9
|
+
exports: [ValidatorService]
|
|
10
|
+
})], ValidatorModule);
|
|
11
|
+
|
|
12
|
+
//#endregion
|
|
13
|
+
export { ValidatorModule };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ClassType } from "../../interfaces/class.interface.js";
|
|
2
|
+
import { LoggerService } from "../logger/logger.service.js";
|
|
3
|
+
import { ValidatorServiceOptions } from "./validator.interface.js";
|
|
4
|
+
import { OnModuleInit } from "@nestjs/common";
|
|
5
|
+
import { ModuleRef } from "@nestjs/core";
|
|
6
|
+
|
|
7
|
+
//#region src/lib/validator/validator.service.d.ts
|
|
8
|
+
declare class ValidatorService implements OnModuleInit {
|
|
9
|
+
private readonly logger;
|
|
10
|
+
private readonly moduleRef;
|
|
11
|
+
private options;
|
|
12
|
+
constructor(logger: LoggerService, moduleRef: ModuleRef);
|
|
13
|
+
onModuleInit(): Promise<void>;
|
|
14
|
+
validate<T extends Record<PropertyKey, any>>(classType: ClassType<T>, object: T, options?: ValidatorServiceOptions): Promise<T>;
|
|
15
|
+
validateSync<T extends Record<PropertyKey, any>>(classType: ClassType<T>, object: T, options?: ValidatorServiceOptions): T;
|
|
16
|
+
private logValidationError;
|
|
17
|
+
}
|
|
18
|
+
//#endregion
|
|
19
|
+
export { ValidatorService };
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { LoggerService } from "../logger/logger.service.js";
|
|
2
|
+
import "../logger/index.js";
|
|
3
|
+
import { TOKEN_VALIDATOR_SERVICE_OPTIONS } from "./validator.constants.js";
|
|
4
|
+
import { Injectable } from "@nestjs/common";
|
|
5
|
+
import _decorateMetadata from "@oxc-project/runtime/helpers/decorateMetadata";
|
|
6
|
+
import _decorate from "@oxc-project/runtime/helpers/decorate";
|
|
7
|
+
import { ModuleRef } from "@nestjs/core";
|
|
8
|
+
import { plainToClass } from "class-transformer";
|
|
9
|
+
import { validate, validateSync } from "class-validator";
|
|
10
|
+
|
|
11
|
+
//#region src/lib/validator/validator.service.ts
|
|
12
|
+
var _ref, _ref2;
|
|
13
|
+
let ValidatorService = class ValidatorService$1 {
|
|
14
|
+
constructor(logger, moduleRef) {
|
|
15
|
+
this.logger = logger;
|
|
16
|
+
this.moduleRef = moduleRef;
|
|
17
|
+
}
|
|
18
|
+
async onModuleInit() {
|
|
19
|
+
this.logger.setup(this.constructor.name);
|
|
20
|
+
try {
|
|
21
|
+
this.options = this.moduleRef.get(TOKEN_VALIDATOR_SERVICE_OPTIONS, { strict: false });
|
|
22
|
+
} catch {
|
|
23
|
+
this.options = {
|
|
24
|
+
validator: {
|
|
25
|
+
skipMissingProperties: true,
|
|
26
|
+
whitelist: false,
|
|
27
|
+
always: true,
|
|
28
|
+
enableDebugMessages: true
|
|
29
|
+
},
|
|
30
|
+
transformer: { enableImplicitConversion: true }
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
async validate(classType, object, options) {
|
|
35
|
+
const classObject = plainToClass(classType, object, {
|
|
36
|
+
...this.options.transformer,
|
|
37
|
+
...options?.transformer ?? {}
|
|
38
|
+
});
|
|
39
|
+
const errors = await validate(classObject, {
|
|
40
|
+
...this.options.validator,
|
|
41
|
+
...options?.validator ?? {}
|
|
42
|
+
});
|
|
43
|
+
if (errors.length) {
|
|
44
|
+
errors.forEach((error) => {
|
|
45
|
+
this.logValidationError(error);
|
|
46
|
+
});
|
|
47
|
+
throw new Error("Validation failed.");
|
|
48
|
+
}
|
|
49
|
+
return classObject;
|
|
50
|
+
}
|
|
51
|
+
validateSync(classType, object, options) {
|
|
52
|
+
const classObject = plainToClass(classType, object, {
|
|
53
|
+
...this.options.transformer,
|
|
54
|
+
...options?.transformer ?? {}
|
|
55
|
+
});
|
|
56
|
+
const errors = validateSync(classObject, {
|
|
57
|
+
...this.options.validator,
|
|
58
|
+
...options?.validator ?? {}
|
|
59
|
+
});
|
|
60
|
+
if (errors.length) {
|
|
61
|
+
errors.forEach((error) => {
|
|
62
|
+
this.logValidationError(error);
|
|
63
|
+
});
|
|
64
|
+
throw new Error("Validation failed.");
|
|
65
|
+
}
|
|
66
|
+
return classObject;
|
|
67
|
+
}
|
|
68
|
+
logValidationError(err) {
|
|
69
|
+
this.logger.error("Field \"%s\" failed validation with value \"%s\": %o", err.property, err.value, err.constraints);
|
|
70
|
+
if (err.children) err.children.forEach((children) => this.logValidationError(children));
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
ValidatorService = _decorate([Injectable(), _decorateMetadata("design:paramtypes", [typeof (_ref = typeof LoggerService !== "undefined" && LoggerService) === "function" ? _ref : Object, typeof (_ref2 = typeof ModuleRef !== "undefined" && ModuleRef) === "function" ? _ref2 : Object])], ValidatorService);
|
|
74
|
+
|
|
75
|
+
//#endregion
|
|
76
|
+
export { ValidatorService };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ListrContext } from "listr2";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/defaults.d.ts
|
|
4
|
+
type SetCtxDefaultsOptions<T extends ListrContext = ListrContext> = Partial<T>;
|
|
5
|
+
interface SetCtxAssignOptions<K = Record<PropertyKey, any>> {
|
|
6
|
+
from: K;
|
|
7
|
+
keys: (keyof K)[];
|
|
8
|
+
}
|
|
9
|
+
declare function setCtxDefaults<T extends ListrContext = ListrContext>(ctx: T, ...defaults: SetCtxDefaultsOptions<T>[]): void;
|
|
10
|
+
declare function setCtxAssign<T extends ListrContext = ListrContext, K = Record<PropertyKey, any>>(ctx: T, ...assigns: SetCtxAssignOptions<K>[]): void;
|
|
11
|
+
//#endregion
|
|
12
|
+
export { SetCtxAssignOptions, SetCtxDefaultsOptions, setCtxAssign, setCtxDefaults };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
//#region src/utils/defaults.ts
|
|
2
|
+
function setCtxDefaults(ctx, ...defaults) {
|
|
3
|
+
defaults?.forEach((i) => {
|
|
4
|
+
if (typeof i === "object" && !Array.isArray(i)) Object.assign(ctx, i);
|
|
5
|
+
});
|
|
6
|
+
}
|
|
7
|
+
function setCtxAssign(ctx, ...assigns) {
|
|
8
|
+
assigns.forEach((assign) => {
|
|
9
|
+
assign?.keys.forEach((i) => {
|
|
10
|
+
if (assign.from[i]) ctx[i] = assign.from[i];
|
|
11
|
+
});
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
//#endregion
|
|
16
|
+
export { setCtxAssign, setCtxDefaults };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { LogLevels } from "../lib/logger/logger.constants.js";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/environment.d.ts
|
|
4
|
+
declare function isVerbose(logLevel: LogLevels): boolean;
|
|
5
|
+
declare function isDebug(logLevel: LogLevels): boolean;
|
|
6
|
+
declare function isSilent(logLevel: LogLevels): boolean;
|
|
7
|
+
//#endregion
|
|
8
|
+
export { isDebug, isSilent, isVerbose };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { LogLevels } from "../lib/logger/logger.constants.js";
|
|
2
|
+
import "../lib/logger/index.js";
|
|
3
|
+
|
|
4
|
+
//#region src/utils/environment.ts
|
|
5
|
+
function isVerbose(logLevel) {
|
|
6
|
+
return logLevel === LogLevels.VERBOSE;
|
|
7
|
+
}
|
|
8
|
+
function isDebug(logLevel) {
|
|
9
|
+
return [LogLevels.DEBUG, LogLevels.TRACE].includes(logLevel);
|
|
10
|
+
}
|
|
11
|
+
function isSilent(logLevel) {
|
|
12
|
+
return logLevel === LogLevels.SILENT;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
//#endregion
|
|
16
|
+
export { isDebug, isSilent, isVerbose };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { RegisterHook, ShouldRunAfterHook, ShouldRunBeforeHook } from "../interfaces/hooks.interface.js";
|
|
2
|
+
import { Command } from "@oclif/core";
|
|
3
|
+
|
|
4
|
+
//#region src/utils/guards.d.ts
|
|
5
|
+
declare function isHookedWithShouldRunBefore<T extends Command = Command>(command: T): command is T & ShouldRunBeforeHook;
|
|
6
|
+
declare function isHookedWithShouldRunAfter<T extends Command = Command>(command: T): command is T & ShouldRunAfterHook<any>;
|
|
7
|
+
declare function isHookedWithRegister<T extends Command = Command>(command: T): command is T & RegisterHook;
|
|
8
|
+
//#endregion
|
|
9
|
+
export { isHookedWithRegister, isHookedWithShouldRunAfter, isHookedWithShouldRunBefore };
|