@rsdk/cli.common 4.3.0-next.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/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
+ ## [4.3.0-next.0](https://github.com/R-Vision/rsdk/compare/v4.2.5-next.0...v4.3.0-next.0) (2024-03-19)
7
+
8
+ ### Features
9
+
10
+ * reworked cli system ([745ebf5](https://github.com/R-Vision/rsdk/commit/745ebf53635de135a4a9083f47ce833efe2d4411))
@@ -0,0 +1,2 @@
1
+ import { Command } from 'commander';
2
+ export declare const getCommanderCommand: (cmd: any) => Command[];
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getCommanderCommand = void 0;
7
+ const commander_1 = require("commander");
8
+ const lodash_1 = __importDefault(require("lodash"));
9
+ const types_1 = require("./types");
10
+ function getRootCommand(globalMetadata) {
11
+ const v = globalMetadata?.get(types_1.MetaKeys.Core);
12
+ if (!v) {
13
+ return;
14
+ }
15
+ return new commander_1.Command(v.name).description(v.description);
16
+ }
17
+ function createCommandHandler(argMap, handler) {
18
+ return (__, cmd) => {
19
+ const opts = cmd.opts();
20
+ const normalizedArgList = [...argMap].map(([index, value]) => ({
21
+ index,
22
+ value,
23
+ }));
24
+ const sortedArgList = lodash_1.default.sortBy(normalizedArgList, ['index']);
25
+ const args = sortedArgList.map(({ value }) => opts[lodash_1.default.camelCase(value.name)]);
26
+ handler(...args);
27
+ };
28
+ }
29
+ function createArgMap(metadata) {
30
+ return metadata.reduce((acc, item) => {
31
+ switch (item.metaKey) {
32
+ case types_1.MetaKeys.Alias:
33
+ case types_1.MetaKeys.DefaultValue:
34
+ case types_1.MetaKeys.Option:
35
+ acc.set(item.value.parameterIndex, {
36
+ ...acc.get(item.value.parameterIndex),
37
+ ...item.value,
38
+ });
39
+ }
40
+ return acc;
41
+ }, new Map());
42
+ }
43
+ const getCommanderCommand = (cmd) => {
44
+ const value = Reflect.getMetadata(types_1.MetaKeys.Core, cmd);
45
+ if (!(value instanceof Map)) {
46
+ throw new TypeError('value not a map');
47
+ }
48
+ const globalMetadata = Reflect.getMetadata(types_1.MetaKeys.Global, cmd);
49
+ const rootCommand = getRootCommand(globalMetadata);
50
+ const map = value;
51
+ // Могут быть методы/поля, на которые ссылается метод через this
52
+ const instance = Reflect.construct(cmd, []);
53
+ const commands = [];
54
+ for (const [propertyKey, metadata] of map) {
55
+ const subCmdMetadata = metadata.filter(({ metaKey }) => metaKey === types_1.MetaKeys.SubCmd);
56
+ if (subCmdMetadata?.length !== 1) {
57
+ throw new Error('Must be one subcmd metadata', {
58
+ cause: {
59
+ subCmdMetadata,
60
+ },
61
+ });
62
+ }
63
+ const subCmdValue = subCmdMetadata[0].value;
64
+ const command = new commander_1.Command(subCmdValue.name).description(subCmdValue.description);
65
+ const argMap = createArgMap(metadata);
66
+ for (const option of argMap.values()) {
67
+ command.option(`--${option.name}${option.strategy === String ? ' <value>' : ''}`, option.description, option.defaultValue);
68
+ }
69
+ command.action(createCommandHandler(argMap,
70
+ // @ts-expect-error потому что не понимает что инстанс это объект у которого есть этот метод
71
+ instance[propertyKey].bind(instance)));
72
+ commands.push(command);
73
+ }
74
+ if (rootCommand) {
75
+ for (const command of commands) {
76
+ rootCommand.addCommand(command);
77
+ }
78
+ return [rootCommand];
79
+ }
80
+ return commands;
81
+ };
82
+ exports.getCommanderCommand = getCommanderCommand;
83
+ //# sourceMappingURL=cmd.core.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cmd.core.js","sourceRoot":"","sources":["../src/cmd.core.ts"],"names":[],"mappings":";;;;;;AAAA,yCAAoC;AACpC,oDAAuB;AAGvB,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AC;QAED,MAAM,WAAW,GAAG,cAAc,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;QAC5C,MAAM,OAAO,GAAG,IAAI,mBAAO,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,WAAW,CACvD,WAAW,CAAC,WAAW,CACxB,CAAC;QAEF,MAAM,MAAM,GAAG,YAAY,CAAC,QAAQ,CAAC,CAAC;QAEtC,KAAK,MAAM,MAAM,IAAI,MAAM,CAAC,MAAM,EAAE,EAAE,CAAC;YACrC,OAAO,CAAC,MAAM,CACZ,KAAK,MAAM,CAAC,IAAI,GAAG,MAAM,CAAC,QAAQ,KAAK,MAAM,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,EAAE,EACjE,MAAM,CAAC,WAAW,EAClB,MAAM,CAAC,YAAY,CACpB,CAAC;QACJ,CAAC;QAED,OAAO,CAAC,MAAM,CACZ,oBAAoB,CAClB,MAAM;QACN,4FAA4F;QAC5F,QAAQ,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CACrC,CACF,CAAC;QACF,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACzB,CAAC;IACD,IAAI,WAAW,EAAE,CAAC;QAChB,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;YAC/B,WAAW,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;QAClC,CAAC;QACD,OAAO,CAAC,WAAW,CAAC,CAAC;IACvB,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC,CAAC;AA5DW,QAAA,mBAAmB,uBA4D9B"}
@@ -0,0 +1,5 @@
1
+ export declare const SubCmd: (name: string, description: string) => MethodDecorator;
2
+ export declare const Cmd: (name: string, description: string) => ClassDecorator;
3
+ export declare const Option: (name: string, description: string, strategy: typeof Boolean | typeof String) => ParameterDecorator;
4
+ export declare const Alias: (alias: string) => ParameterDecorator;
5
+ export declare const Default: (v: any) => ParameterDecorator;
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Default = exports.Alias = exports.Option = exports.Cmd = exports.SubCmd = void 0;
4
+ const types_1 = require("./types");
5
+ const utils_1 = require("./utils");
6
+ const SubCmd = (name, description) => {
7
+ return (target, propertyKey) => {
8
+ (0, utils_1.assertString)(propertyKey);
9
+ (0, utils_1.defineMetadata)(target, propertyKey, types_1.MetaKeys.SubCmd, {
10
+ name,
11
+ description,
12
+ });
13
+ };
14
+ };
15
+ exports.SubCmd = SubCmd;
16
+ const Cmd = (name, description) => {
17
+ return (target) => {
18
+ (0, utils_1.defineCoreMetadata)(target, types_1.MetaKeys.Core, {
19
+ name,
20
+ description,
21
+ });
22
+ };
23
+ };
24
+ exports.Cmd = Cmd;
25
+ const Option = (name, description, strategy) => {
26
+ return (target, propertyKey, parameterIndex) => {
27
+ (0, utils_1.assertString)(propertyKey);
28
+ (0, utils_1.defineMetadata)(target, propertyKey, types_1.MetaKeys.Option, {
29
+ name,
30
+ description,
31
+ strategy,
32
+ parameterIndex,
33
+ });
34
+ };
35
+ };
36
+ exports.Option = Option;
37
+ const Alias = (alias) => {
38
+ return (target, propertyKey, parameterIndex) => {
39
+ (0, utils_1.assertString)(propertyKey);
40
+ (0, utils_1.defineMetadata)(target, propertyKey, types_1.MetaKeys.Alias, {
41
+ alias,
42
+ parameterIndex,
43
+ });
44
+ };
45
+ };
46
+ exports.Alias = Alias;
47
+ const Default = (v) => {
48
+ return (target, propertyKey, parameterIndex) => {
49
+ (0, utils_1.assertString)(propertyKey);
50
+ (0, utils_1.defineMetadata)(target, propertyKey, types_1.MetaKeys.DefaultValue, {
51
+ defaultValue: v,
52
+ parameterIndex,
53
+ });
54
+ };
55
+ };
56
+ exports.Default = Default;
57
+ //# sourceMappingURL=decorators.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decorators.js","sourceRoot":"","sources":["../src/decorators.ts"],"names":[],"mappings":";;;AAAA,mCAAmC;AACnC,mCAA2E;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SACf,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC,CAAC;AARW,QAAA,KAAK,SAQhB;AACK,MAAM,OAAO,GAAG,CAAC,CAAM,EAAsB,EAAE;IACpD,OAAO,CAAC,MAAM,EAAE,WAAW,EAAE,cAAc,EAAE,EAAE;QAC7C,IAAA,oBAAY,EAAC,WAAW,CAAC,CAAC;QAC1B,IAAA,sBAAc,EAAC,MAAM,EAAE,WAAW,EAAE,gBAAQ,CAAC,YAAY,EAAE;YACzD,YAAY,EAAE,CAAC;YACf,cAAc;SACf,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC,CAAC;AARW,QAAA,OAAO,WAQlB"}
@@ -0,0 +1,5 @@
1
+ export declare class EnvProvider {
2
+ static parse(key: string): string | undefined;
3
+ private static parsed;
4
+ private static parseEnv;
5
+ }
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.EnvProvider = void 0;
7
+ const dotenv_1 = __importDefault(require("dotenv"));
8
+ class EnvProvider {
9
+ static parse(key) {
10
+ return process.env[key] ?? EnvProvider.parseEnv()[key];
11
+ }
12
+ static parsed;
13
+ static parseEnv() {
14
+ if (EnvProvider.parsed) {
15
+ return EnvProvider.parsed;
16
+ }
17
+ const parsed = dotenv_1.default.config();
18
+ if (parsed.error) {
19
+ throw new Error('Error read config', {
20
+ cause: parsed.error,
21
+ });
22
+ }
23
+ EnvProvider.parsed = parsed.parsed;
24
+ return EnvProvider.parsed;
25
+ }
26
+ }
27
+ exports.EnvProvider = EnvProvider;
28
+ //# sourceMappingURL=env.provider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"env.provider.js","sourceRoot":"","sources":["../src/env.provider.ts"],"names":[],"mappings":";;;;;;AAAA,oDAA4B;AAE5B,MAAa,WAAW;IACtB,MAAM,CAAC,KAAK,CAAC,GAAW;QACtB,OAAO,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,WAAW,CAAC,QAAQ,EAAE,CAAC,GAAG,CAAC,CAAC;IACzD,CAAC;IAEO,MAAM,CAAC,MAAM,CAA2B;IAExC,MAAM,CAAC,QAAQ;QACrB,IAAI,WAAW,CAAC,MAAM,EAAE,CAAC;YACvB,OAAO,WAAW,CAAC,MAAM,CAAC;QAC5B,CAAC;QACD,MAAM,MAAM,GAAG,gBAAM,CAAC,MAAM,EAAE,CAAC;QAC/B,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC;YACjB,MAAM,IAAI,KAAK,CAAC,mBAAmB,EAAE;gBACnC,KAAK,EAAE,MAAM,CAAC,KAAK;aACpB,CAAC,CAAC;QACL,CAAC;QACD,WAAW,CAAC,MAAM,GAAG,MAAM,CAAC,MAAO,CAAC;QACpC,OAAO,WAAW,CAAC,MAAM,CAAC;IAC5B,CAAC;CACF;AApBD,kCAoBC"}
@@ -0,0 +1,15 @@
1
+ import type { Command } from 'commander';
2
+ import 'reflect-metadata';
3
+ export { getMetadataByPredict } from './rsdk/metadata.aggregator';
4
+ export { RsdkJson } from './types';
5
+ export { RsdkJsonParser } from './rsdk-json.parser';
6
+ export { EnvProvider } from './env.provider';
7
+ export { getCommanderCommand } from './cmd.core';
8
+ export interface RsdkCliCommand {
9
+ getCommands(): Command[];
10
+ }
11
+ export { Default } from './decorators';
12
+ export { Alias } from './decorators';
13
+ export { Option } from './decorators';
14
+ export { SubCmd } from './decorators';
15
+ export { Cmd } from './decorators';
package/dist/index.js ADDED
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Cmd = exports.SubCmd = exports.Option = exports.Alias = exports.Default = exports.getCommanderCommand = exports.EnvProvider = exports.RsdkJsonParser = exports.getMetadataByPredict = void 0;
4
+ require("reflect-metadata");
5
+ var metadata_aggregator_1 = require("./rsdk/metadata.aggregator");
6
+ Object.defineProperty(exports, "getMetadataByPredict", { enumerable: true, get: function () { return metadata_aggregator_1.getMetadataByPredict; } });
7
+ var rsdk_json_parser_1 = require("./rsdk-json.parser");
8
+ Object.defineProperty(exports, "RsdkJsonParser", { enumerable: true, get: function () { return rsdk_json_parser_1.RsdkJsonParser; } });
9
+ var env_provider_1 = require("./env.provider");
10
+ Object.defineProperty(exports, "EnvProvider", { enumerable: true, get: function () { return env_provider_1.EnvProvider; } });
11
+ var cmd_core_1 = require("./cmd.core");
12
+ Object.defineProperty(exports, "getCommanderCommand", { enumerable: true, get: function () { return cmd_core_1.getCommanderCommand; } });
13
+ var decorators_1 = require("./decorators");
14
+ Object.defineProperty(exports, "Default", { enumerable: true, get: function () { return decorators_1.Default; } });
15
+ var decorators_2 = require("./decorators");
16
+ Object.defineProperty(exports, "Alias", { enumerable: true, get: function () { return decorators_2.Alias; } });
17
+ var decorators_3 = require("./decorators");
18
+ Object.defineProperty(exports, "Option", { enumerable: true, get: function () { return decorators_3.Option; } });
19
+ var decorators_4 = require("./decorators");
20
+ Object.defineProperty(exports, "SubCmd", { enumerable: true, get: function () { return decorators_4.SubCmd; } });
21
+ var decorators_5 = require("./decorators");
22
+ Object.defineProperty(exports, "Cmd", { enumerable: true, get: function () { return decorators_5.Cmd; } });
23
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAEA,4BAA0B;AAE1B,kEAAkE;AAAzD,2HAAA,oBAAoB,OAAA;AAI7B,uDAAoD;AAA3C,kHAAA,cAAc,OAAA;AAEvB,+CAA6C;AAApC,2GAAA,WAAW,OAAA;AAEpB,uCAAiD;AAAxC,+GAAA,mBAAmB,OAAA;AAM5B,2CAAuC;AAA9B,qGAAA,OAAO,OAAA;AAChB,2CAAqC;AAA5B,mGAAA,KAAK,OAAA;AACd,2CAAsC;AAA7B,oGAAA,MAAM,OAAA;AACf,2CAAsC;AAA7B,oGAAA,MAAM,OAAA;AACf,2CAAmC;AAA1B,iGAAA,GAAG,OAAA"}
@@ -0,0 +1,6 @@
1
+ import type { RsdkJson, Value } from '../types';
2
+ export declare function getMetadata(rsdkJson: RsdkJson, scope: string): Value[];
3
+ export declare function getMetadataByPredict(rsdkJson: RsdkJson, predict: (meta: {
4
+ scope: string;
5
+ }) => boolean): Value[];
6
+ export declare function getKafkaMetadata(rsdkJson: RsdkJson): Value[];
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getKafkaMetadata = exports.getMetadataByPredict = exports.getMetadata = void 0;
4
+ function getMetadata(rsdkJson, scope) {
5
+ return rsdkJson.rsdkMetadata
6
+ .filter((meta) => meta.scope === scope)
7
+ .map(({ value }) => value);
8
+ }
9
+ exports.getMetadata = getMetadata;
10
+ function getMetadataByPredict(rsdkJson, predict) {
11
+ return rsdkJson.rsdkMetadata.filter(predict).map(({ value }) => value);
12
+ }
13
+ exports.getMetadataByPredict = getMetadataByPredict;
14
+ function getKafkaMetadata(rsdkJson) {
15
+ return getMetadata(rsdkJson, 'kafka-topic');
16
+ }
17
+ exports.getKafkaMetadata = getKafkaMetadata;
18
+ //# sourceMappingURL=metadata.aggregator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"metadata.aggregator.js","sourceRoot":"","sources":["../../src/rsdk/metadata.aggregator.ts"],"names":[],"mappings":";;;AAEA,SAAgB,WAAW,CAAC,QAAkB,EAAE,KAAa;IAC3D,OAAO,QAAQ,CAAC,YAAY;SACzB,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,KAAK,KAAK,CAAC;SACtC,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC;AAC/B,CAAC;AAJD,kCAIC;AACD,SAAgB,oBAAoB,CAClC,QAAkB,EAClB,OAA6C;IAE7C,OAAO,QAAQ,CAAC,YAAY,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC;AACzE,CAAC;AALD,oDAKC;AAED,SAAgB,gBAAgB,CAAC,QAAkB;IACjD,OAAO,WAAW,CAAC,QAAQ,EAAE,aAAa,CAAC,CAAC;AAC9C,CAAC;AAFD,4CAEC"}
@@ -0,0 +1,6 @@
1
+ import type { RsdkJson } from './types';
2
+ export declare class RsdkJsonParser {
3
+ readonly path: string;
4
+ constructor(path?: string);
5
+ parseRsdkJson(): Promise<RsdkJson>;
6
+ }
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RsdkJsonParser = void 0;
4
+ const promises_1 = require("node:fs/promises");
5
+ const node_path_1 = require("node:path");
6
+ class RsdkJsonParser {
7
+ path;
8
+ constructor(path = 'autodoc/rsdk.json') {
9
+ this.path = path;
10
+ }
11
+ async parseRsdkJson() {
12
+ const pathToRsdkJson = (0, node_path_1.resolve)(this.path);
13
+ const rsdkJson = JSON.parse(await (0, promises_1.readFile)(pathToRsdkJson, 'utf8'));
14
+ return rsdkJson;
15
+ }
16
+ }
17
+ exports.RsdkJsonParser = RsdkJsonParser;
18
+ //# sourceMappingURL=rsdk-json.parser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rsdk-json.parser.js","sourceRoot":"","sources":["../src/rsdk-json.parser.ts"],"names":[],"mappings":";;;AAAA,+CAA4C;AAC5C,yCAAoC;AAIpC,MAAa,cAAc;IACJ;IAArB,YAAqB,OAAe,mBAAmB;QAAlC,SAAI,GAAJ,IAAI,CAA8B;IAAG,CAAC;IAE3D,KAAK,CAAC,aAAa;QACjB,MAAM,cAAc,GAAG,IAAA,mBAAO,EAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC1C,MAAM,QAAQ,GAAa,IAAI,CAAC,KAAK,CACnC,MAAM,IAAA,mBAAQ,EAAC,cAAc,EAAE,MAAM,CAAC,CACvC,CAAC;QAEF,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF;AAXD,wCAWC"}
@@ -0,0 +1,97 @@
1
+ export interface RsdkJson {
2
+ metadata: Metadata;
3
+ rsdkMetadata: RsdkMetadaum[];
4
+ }
5
+ export interface Metadata {
6
+ name: string;
7
+ version: string;
8
+ description: string;
9
+ protocols: string[];
10
+ config: Config;
11
+ }
12
+ export interface Config {
13
+ prefix: string;
14
+ sections: Section[];
15
+ sources: any[];
16
+ properties: any[];
17
+ }
18
+ export interface Section {
19
+ tags?: string[];
20
+ constructorName: string;
21
+ properties: Property[];
22
+ name?: string;
23
+ }
24
+ export interface Property {
25
+ expectedInEnv: boolean;
26
+ key: string;
27
+ description: string;
28
+ parser: Parser;
29
+ defaultValue: any;
30
+ }
31
+ export interface Parser {
32
+ type: string;
33
+ description: string;
34
+ }
35
+ export interface RsdkMetadaum {
36
+ scope: string;
37
+ value: Value;
38
+ }
39
+ export interface Value {
40
+ global?: boolean;
41
+ imports?: Import[];
42
+ providers?: Provider2[];
43
+ exports?: string[];
44
+ token?: string;
45
+ partitionKeyField: any;
46
+ topicName?: string;
47
+ group?: string;
48
+ type?: number;
49
+ eventType?: EventType;
50
+ options?: Options3;
51
+ constructorName?: string;
52
+ }
53
+ export interface Import {
54
+ providers: Provider[];
55
+ exports: Export[];
56
+ }
57
+ export interface Provider {
58
+ inject: Inject | undefined[];
59
+ }
60
+ export interface Inject {
61
+ optional: boolean;
62
+ }
63
+ export interface Export {
64
+ inject: Inject2 | undefined[];
65
+ }
66
+ export interface Inject2 {
67
+ optional: boolean;
68
+ }
69
+ export interface Provider2 {
70
+ provide: string;
71
+ useValue: UseValue;
72
+ }
73
+ export interface UseValue {
74
+ context: string;
75
+ }
76
+ export interface EventType {
77
+ $group: string;
78
+ $partitionKeyField: any;
79
+ $type: string;
80
+ }
81
+ export interface Options3 {
82
+ key: string;
83
+ scope: string;
84
+ description: string;
85
+ }
86
+ export declare enum MetaKeys {
87
+ Core = "Core",
88
+ Global = "Global",
89
+ SubCmd = "SubCmd",
90
+ Option = "Option",
91
+ Alias = "Alias",
92
+ DefaultValue = "DefaultValue"
93
+ }
94
+ export type CoreMetadataMap = Map<string, {
95
+ metaKey: MetaKeys;
96
+ value: any;
97
+ }[]>;
package/dist/types.js ADDED
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MetaKeys = void 0;
4
+ var MetaKeys;
5
+ (function (MetaKeys) {
6
+ MetaKeys["Core"] = "Core";
7
+ MetaKeys["Global"] = "Global";
8
+ MetaKeys["SubCmd"] = "SubCmd";
9
+ MetaKeys["Option"] = "Option";
10
+ MetaKeys["Alias"] = "Alias";
11
+ MetaKeys["DefaultValue"] = "DefaultValue";
12
+ })(MetaKeys || (exports.MetaKeys = MetaKeys = {}));
13
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;AAsFA,IAAY,QAOX;AAPD,WAAY,QAAQ;IAClB,yBAAa,CAAA;IACb,6BAAiB,CAAA;IACjB,6BAAiB,CAAA;IACjB,6BAAiB,CAAA;IACjB,2BAAe,CAAA;IACf,yCAA6B,CAAA;AAC/B,CAAC,EAPW,QAAQ,wBAAR,QAAQ,QAOnB"}
@@ -0,0 +1,4 @@
1
+ import { MetaKeys } from './types';
2
+ export declare function assertString(v: string | symbol | undefined): asserts v is string;
3
+ export declare const defineMetadata: (t: object, propertyKey: string, metaKey: MetaKeys, value: unknown) => void;
4
+ export declare const defineCoreMetadata: (target: object, metaKey: MetaKeys, value: any) => void;
package/dist/utils.js ADDED
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.defineCoreMetadata = exports.defineMetadata = exports.assertString = void 0;
4
+ const types_1 = require("./types");
5
+ function assertString(v) {
6
+ if (typeof v !== 'string') {
7
+ throw new TypeError('v must be string');
8
+ }
9
+ }
10
+ exports.assertString = assertString;
11
+ const defineMetadata = (t, propertyKey, metaKey, value) => {
12
+ const target = t.constructor;
13
+ const exist = Reflect.getMetadata(types_1.MetaKeys.Core, target) ??
14
+ new Map();
15
+ const existed = exist.get(propertyKey) ?? [];
16
+ existed.push({
17
+ metaKey,
18
+ value,
19
+ });
20
+ exist.set(propertyKey, existed);
21
+ Reflect.defineMetadata(types_1.MetaKeys.Core, exist, target);
22
+ };
23
+ exports.defineMetadata = defineMetadata;
24
+ const defineCoreMetadata = (target, metaKey, value) => {
25
+ const exist = Reflect.getMetadata(types_1.MetaKeys.Global, target) ?? new Map();
26
+ exist.set(metaKey, value);
27
+ Reflect.defineMetadata(types_1.MetaKeys.Global, exist, target);
28
+ };
29
+ exports.defineCoreMetadata = defineCoreMetadata;
30
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;AACA,mCAAmC;AAEnC,SAAgB,YAAY,CAC1B,CAA8B;IAE9B,IAAI,OAAO,CAAC,KAAK,QAAQ,EAAE,CAAC;QAC1B,MAAM,IAAI,SAAS,CAAC,kBAAkB,CAAC,CAAC;IAC1C,CAAC;AACH,CAAC;AAND,oCAMC;AAEM,MAAM,cAAc,GAAG,CAC5B,CAAS,EACT,WAAmB,EACnB,OAAiB,EACjB,KAAc,EACR,EAAE;IACR,MAAM,MAAM,GAAG,CAAC,CAAC,WAAW,CAAC;IAC7B,MAAM,KAAK,GACT,OAAO,CAAC,WAAW,CAAC,gBAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;QAC1C,IAAI,GAAG,EAMJ,CAAC;IAEN,MAAM,OAAO,GAAG,KAAK,CAAC,GAAG,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC;IAE7C,OAAO,CAAC,IAAI,CAAC;QACX,OAAO;QACP,KAAK;KACN,CAAC,CAAC;IAEH,KAAK,CAAC,GAAG,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;IAEhC,OAAO,CAAC,cAAc,CAAC,gBAAQ,CAAC,IAAI,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;AACvD,CAAC,CAAC;AA3BW,QAAA,cAAc,kBA2BzB;AAEK,MAAM,kBAAkB,GAAG,CAChC,MAAc,EACd,OAAiB,EACjB,KAAU,EACJ,EAAE;IACR,MAAM,KAAK,GACT,OAAO,CAAC,WAAW,CAAC,gBAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,IAAI,GAAG,EAAmB,CAAC;IAE7E,KAAK,CAAC,GAAG,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IAE1B,OAAO,CAAC,cAAc,CAAC,gBAAQ,CAAC,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;AACzD,CAAC,CAAC;AAXW,QAAA,kBAAkB,sBAW7B"}
package/package.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "@rsdk/cli.common",
3
+ "version": "4.3.0-next.0",
4
+ "description": "Shared types and helpers for build work with cli",
5
+ "main": "dist/index.js",
6
+ "bin": {
7
+ "rsdk": "bin.js"
8
+ },
9
+ "publishConfig": {
10
+ "access": "public"
11
+ },
12
+ "keywords": [
13
+ "rsdk",
14
+ "cli"
15
+ ],
16
+ "license": "Apache License 2.0",
17
+ "dependencies": {
18
+ "@rsdk/common": "^4.3.0-next.0",
19
+ "@rsdk/logging": "^4.3.0-next.0",
20
+ "@sinclair/typebox": "^0.32.13",
21
+ "commander": "^12.0.0",
22
+ "dotenv": "^16.3.1",
23
+ "kafkajs": "^2.2.4",
24
+ "listr2": "^6.6.1",
25
+ "lodash": "^4.17.21",
26
+ "yaml": "^2.3.1"
27
+ },
28
+ "peerDependencies": {
29
+ "@rsdk/core": "^4.3.0-next.0",
30
+ "reflect-metadata": "^0.1.12 || ^0.2.0"
31
+ },
32
+ "gitHead": "68619cc6fc60db01568eede7df182d9882e857dd"
33
+ }
@@ -0,0 +1,128 @@
1
+ import { Command } from 'commander';
2
+ import _ from 'lodash';
3
+
4
+ import type { CoreMetadataMap } from './types';
5
+ import { MetaKeys } from './types';
6
+
7
+ type ParameterIndex = number;
8
+ function getRootCommand(globalMetadata: any): Command | undefined {
9
+ const v = globalMetadata?.get(MetaKeys.Core);
10
+
11
+ if (!v) {
12
+ return;
13
+ }
14
+ return new Command(v.name).description(v.description);
15
+ }
16
+
17
+ function createCommandHandler(
18
+ argMap: Map<ParameterIndex, OptionMetadata>,
19
+ handler: (...args: any[]) => any,
20
+ ): (__: any, cmd: Command) => void {
21
+ return (__, cmd: Command) => {
22
+ const opts = cmd.opts();
23
+
24
+ const normalizedArgList: { index: number; value: any }[] = [...argMap].map(
25
+ ([index, value]) => ({
26
+ index,
27
+ value,
28
+ }),
29
+ );
30
+ const sortedArgList: { index: any; value: any }[] = _.sortBy(
31
+ normalizedArgList,
32
+ ['index'],
33
+ );
34
+
35
+ const args: (string | undefined)[] = sortedArgList.map(
36
+ ({ value }) => opts[_.camelCase(value.name)],
37
+ );
38
+
39
+ handler(...args);
40
+ };
41
+ }
42
+
43
+ type OptionMetadata = {
44
+ name: string;
45
+ description: string;
46
+ alias?: string;
47
+ defaultValue?: string | boolean;
48
+ strategy: BooleanConstructor | StringConstructor;
49
+ };
50
+
51
+ function createArgMap(
52
+ metadata: { metaKey: MetaKeys; value: any }[],
53
+ ): Map<ParameterIndex, OptionMetadata> {
54
+ return metadata.reduce((acc, item) => {
55
+ switch (item.metaKey) {
56
+ case MetaKeys.Alias:
57
+ case MetaKeys.DefaultValue:
58
+ case MetaKeys.Option:
59
+ acc.set(item.value.parameterIndex, {
60
+ ...acc.get(item.value.parameterIndex),
61
+ ...item.value,
62
+ });
63
+ }
64
+ return acc;
65
+ }, new Map<ParameterIndex, OptionMetadata>());
66
+ }
67
+
68
+ export const getCommanderCommand = (cmd: any): Command[] => {
69
+ const value = Reflect.getMetadata(MetaKeys.Core, cmd);
70
+ if (!(value instanceof Map)) {
71
+ throw new TypeError('value not a map');
72
+ }
73
+
74
+ const globalMetadata = Reflect.getMetadata(MetaKeys.Global, cmd);
75
+
76
+ const rootCommand = getRootCommand(globalMetadata);
77
+
78
+ const map: CoreMetadataMap = value;
79
+
80
+ // Могут быть методы/поля, на которые ссылается метод через this
81
+ const instance = Reflect.construct(cmd, []);
82
+
83
+ const commands: Command[] = [];
84
+
85
+ for (const [propertyKey, metadata] of map) {
86
+ const subCmdMetadata = metadata.filter(
87
+ ({ metaKey }) => metaKey === MetaKeys.SubCmd,
88
+ );
89
+ if (subCmdMetadata?.length !== 1) {
90
+ throw new Error('Must be one subcmd metadata', {
91
+ cause: {
92
+ subCmdMetadata,
93
+ },
94
+ });
95
+ }
96
+
97
+ const subCmdValue = subCmdMetadata[0].value;
98
+ const command = new Command(subCmdValue.name).description(
99
+ subCmdValue.description,
100
+ );
101
+
102
+ const argMap = createArgMap(metadata);
103
+
104
+ for (const option of argMap.values()) {
105
+ command.option(
106
+ `--${option.name}${option.strategy === String ? ' <value>' : ''}`,
107
+ option.description,
108
+ option.defaultValue,
109
+ );
110
+ }
111
+
112
+ command.action(
113
+ createCommandHandler(
114
+ argMap,
115
+ // @ts-expect-error потому что не понимает что инстанс это объект у которого есть этот метод
116
+ instance[propertyKey].bind(instance),
117
+ ),
118
+ );
119
+ commands.push(command);
120
+ }
121
+ if (rootCommand) {
122
+ for (const command of commands) {
123
+ rootCommand.addCommand(command);
124
+ }
125
+ return [rootCommand];
126
+ }
127
+ return commands;
128
+ };
@@ -0,0 +1,54 @@
1
+ import { MetaKeys } from './types';
2
+ import { assertString, defineCoreMetadata, defineMetadata } from './utils';
3
+
4
+ export const SubCmd = (name: string, description: string): MethodDecorator => {
5
+ return (target, propertyKey) => {
6
+ assertString(propertyKey);
7
+ defineMetadata(target, propertyKey, MetaKeys.SubCmd, {
8
+ name,
9
+ description,
10
+ });
11
+ };
12
+ };
13
+ export const Cmd = (name: string, description: string): ClassDecorator => {
14
+ return (target) => {
15
+ defineCoreMetadata(target, MetaKeys.Core, {
16
+ name,
17
+ description,
18
+ });
19
+ };
20
+ };
21
+
22
+ export const Option = (
23
+ name: string,
24
+ description: string,
25
+ strategy: typeof Boolean | typeof String,
26
+ ): ParameterDecorator => {
27
+ return (target, propertyKey, parameterIndex) => {
28
+ assertString(propertyKey);
29
+ defineMetadata(target, propertyKey, MetaKeys.Option, {
30
+ name,
31
+ description,
32
+ strategy,
33
+ parameterIndex,
34
+ });
35
+ };
36
+ };
37
+ export const Alias = (alias: string): ParameterDecorator => {
38
+ return (target, propertyKey, parameterIndex) => {
39
+ assertString(propertyKey);
40
+ defineMetadata(target, propertyKey, MetaKeys.Alias, {
41
+ alias,
42
+ parameterIndex,
43
+ });
44
+ };
45
+ };
46
+ export const Default = (v: any): ParameterDecorator => {
47
+ return (target, propertyKey, parameterIndex) => {
48
+ assertString(propertyKey);
49
+ defineMetadata(target, propertyKey, MetaKeys.DefaultValue, {
50
+ defaultValue: v,
51
+ parameterIndex,
52
+ });
53
+ };
54
+ };
@@ -0,0 +1,23 @@
1
+ import dotenv from 'dotenv';
2
+
3
+ export class EnvProvider {
4
+ static parse(key: string): string | undefined {
5
+ return process.env[key] ?? EnvProvider.parseEnv()[key];
6
+ }
7
+
8
+ private static parsed: dotenv.DotenvParseOutput;
9
+
10
+ private static parseEnv(): dotenv.DotenvParseOutput {
11
+ if (EnvProvider.parsed) {
12
+ return EnvProvider.parsed;
13
+ }
14
+ const parsed = dotenv.config();
15
+ if (parsed.error) {
16
+ throw new Error('Error read config', {
17
+ cause: parsed.error,
18
+ });
19
+ }
20
+ EnvProvider.parsed = parsed.parsed!;
21
+ return EnvProvider.parsed;
22
+ }
23
+ }
package/src/index.ts ADDED
@@ -0,0 +1,23 @@
1
+ import type { Command } from 'commander';
2
+
3
+ import 'reflect-metadata';
4
+
5
+ export { getMetadataByPredict } from './rsdk/metadata.aggregator';
6
+
7
+ export { RsdkJson } from './types';
8
+
9
+ export { RsdkJsonParser } from './rsdk-json.parser';
10
+
11
+ export { EnvProvider } from './env.provider';
12
+
13
+ export { getCommanderCommand } from './cmd.core';
14
+
15
+ export interface RsdkCliCommand {
16
+ getCommands(): Command[];
17
+ }
18
+
19
+ export { Default } from './decorators';
20
+ export { Alias } from './decorators';
21
+ export { Option } from './decorators';
22
+ export { SubCmd } from './decorators';
23
+ export { Cmd } from './decorators';
@@ -0,0 +1,17 @@
1
+ import type { RsdkJson, Value } from '../types';
2
+
3
+ export function getMetadata(rsdkJson: RsdkJson, scope: string): Value[] {
4
+ return rsdkJson.rsdkMetadata
5
+ .filter((meta) => meta.scope === scope)
6
+ .map(({ value }) => value);
7
+ }
8
+ export function getMetadataByPredict(
9
+ rsdkJson: RsdkJson,
10
+ predict: (meta: { scope: string }) => boolean,
11
+ ): Value[] {
12
+ return rsdkJson.rsdkMetadata.filter(predict).map(({ value }) => value);
13
+ }
14
+
15
+ export function getKafkaMetadata(rsdkJson: RsdkJson): Value[] {
16
+ return getMetadata(rsdkJson, 'kafka-topic');
17
+ }
@@ -0,0 +1,17 @@
1
+ import { readFile } from 'node:fs/promises';
2
+ import { resolve } from 'node:path';
3
+
4
+ import type { RsdkJson } from './types';
5
+
6
+ export class RsdkJsonParser {
7
+ constructor(readonly path: string = 'autodoc/rsdk.json') {}
8
+
9
+ async parseRsdkJson(): Promise<RsdkJson> {
10
+ const pathToRsdkJson = resolve(this.path);
11
+ const rsdkJson: RsdkJson = JSON.parse(
12
+ await readFile(pathToRsdkJson, 'utf8'),
13
+ );
14
+
15
+ return rsdkJson;
16
+ }
17
+ }
package/src/types.ts ADDED
@@ -0,0 +1,102 @@
1
+ export interface RsdkJson {
2
+ metadata: Metadata;
3
+ rsdkMetadata: RsdkMetadaum[];
4
+ }
5
+ export interface Metadata {
6
+ name: string;
7
+ version: string;
8
+ description: string;
9
+ protocols: string[];
10
+ config: Config;
11
+ }
12
+ export interface Config {
13
+ prefix: string;
14
+ sections: Section[];
15
+ sources: any[];
16
+ properties: any[];
17
+ }
18
+ export interface Section {
19
+ tags?: string[];
20
+ constructorName: string;
21
+ properties: Property[];
22
+ name?: string;
23
+ }
24
+ export interface Property {
25
+ expectedInEnv: boolean;
26
+ key: string;
27
+ description: string;
28
+ parser: Parser;
29
+ defaultValue: any;
30
+ }
31
+ export interface Parser {
32
+ type: string;
33
+ description: string;
34
+ }
35
+ export interface RsdkMetadaum {
36
+ scope: string;
37
+ value: Value;
38
+ }
39
+ export interface Value {
40
+ global?: boolean;
41
+ imports?: Import[];
42
+ providers?: Provider2[];
43
+ exports?: string[];
44
+ token?: string;
45
+ partitionKeyField: any;
46
+ topicName?: string;
47
+ group?: string;
48
+ type?: number;
49
+ eventType?: EventType;
50
+ options?: Options3;
51
+ constructorName?: string;
52
+ }
53
+ export interface Import {
54
+ providers: Provider[];
55
+ exports: Export[];
56
+ }
57
+ export interface Provider {
58
+ inject: Inject | undefined[];
59
+ }
60
+ export interface Inject {
61
+ optional: boolean;
62
+ }
63
+ export interface Export {
64
+ inject: Inject2 | undefined[];
65
+ }
66
+ export interface Inject2 {
67
+ optional: boolean;
68
+ }
69
+ export interface Provider2 {
70
+ provide: string;
71
+ useValue: UseValue;
72
+ }
73
+ export interface UseValue {
74
+ context: string;
75
+ }
76
+ export interface EventType {
77
+ $group: string;
78
+ $partitionKeyField: any;
79
+ $type: string;
80
+ }
81
+ export interface Options3 {
82
+ key: string;
83
+ scope: string;
84
+ description: string;
85
+ }
86
+
87
+ export enum MetaKeys {
88
+ Core = 'Core',
89
+ Global = 'Global',
90
+ SubCmd = 'SubCmd',
91
+ Option = 'Option',
92
+ Alias = 'Alias',
93
+ DefaultValue = 'DefaultValue',
94
+ }
95
+
96
+ export type CoreMetadataMap = Map<
97
+ string,
98
+ {
99
+ metaKey: MetaKeys;
100
+ value: any;
101
+ }[]
102
+ >;
package/src/utils.ts ADDED
@@ -0,0 +1,52 @@
1
+ import type { CoreMetadataMap } from './types';
2
+ import { MetaKeys } from './types';
3
+
4
+ export function assertString(
5
+ v: string | symbol | undefined,
6
+ ): asserts v is string {
7
+ if (typeof v !== 'string') {
8
+ throw new TypeError('v must be string');
9
+ }
10
+ }
11
+
12
+ export const defineMetadata = (
13
+ t: object,
14
+ propertyKey: string,
15
+ metaKey: MetaKeys,
16
+ value: unknown,
17
+ ): void => {
18
+ const target = t.constructor;
19
+ const exist: CoreMetadataMap =
20
+ Reflect.getMetadata(MetaKeys.Core, target) ??
21
+ new Map<
22
+ string,
23
+ {
24
+ metaKey: MetaKeys;
25
+ value: unknown;
26
+ }[]
27
+ >();
28
+
29
+ const existed = exist.get(propertyKey) ?? [];
30
+
31
+ existed.push({
32
+ metaKey,
33
+ value,
34
+ });
35
+
36
+ exist.set(propertyKey, existed);
37
+
38
+ Reflect.defineMetadata(MetaKeys.Core, exist, target);
39
+ };
40
+
41
+ export const defineCoreMetadata = (
42
+ target: object,
43
+ metaKey: MetaKeys,
44
+ value: any,
45
+ ): void => {
46
+ const exist: CoreMetadataMap =
47
+ Reflect.getMetadata(MetaKeys.Global, target) ?? new Map<MetaKeys, any[]>();
48
+
49
+ exist.set(metaKey, value);
50
+
51
+ Reflect.defineMetadata(MetaKeys.Global, exist, target);
52
+ };
@@ -0,0 +1,12 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "exclude": [
4
+ "node_modules",
5
+ "dist",
6
+ "test",
7
+ "**/*.spec.ts",
8
+ "**/*.test.ts",
9
+ "**/*.test.e2e.ts",
10
+ "**/*.test.manual-e2e.ts",
11
+ ]
12
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "extends": "@rsdk/tsconfig/base.json",
3
+ "compilerOptions": {
4
+ "declaration": true,
5
+ "outDir": "dist"
6
+ }
7
+ }