@rsdk/cli.common 5.7.0-next.6 → 6.0.0-next.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.
Files changed (69) hide show
  1. package/dist/common/metadata.registry.d.ts +19 -0
  2. package/dist/common/metadata.registry.js +57 -0
  3. package/dist/common/metadata.registry.js.map +1 -0
  4. package/dist/common/types.d.ts +32 -0
  5. package/dist/common/types.js +22 -0
  6. package/dist/common/types.js.map +1 -0
  7. package/dist/decorators/command.decorator.d.ts +14 -0
  8. package/dist/decorators/command.decorator.js +27 -0
  9. package/dist/decorators/command.decorator.js.map +1 -0
  10. package/dist/decorators/index.d.ts +5 -0
  11. package/dist/decorators/index.js +22 -0
  12. package/dist/decorators/index.js.map +1 -0
  13. package/dist/decorators/option-with-value.decorator.d.ts +13 -0
  14. package/dist/decorators/option-with-value.decorator.js +26 -0
  15. package/dist/decorators/option-with-value.decorator.js.map +1 -0
  16. package/dist/decorators/option.decorator.d.ts +10 -0
  17. package/dist/decorators/option.decorator.js +23 -0
  18. package/dist/decorators/option.decorator.js.map +1 -0
  19. package/dist/decorators/sub-command.decorator.d.ts +9 -0
  20. package/dist/decorators/sub-command.decorator.js +19 -0
  21. package/dist/decorators/sub-command.decorator.js.map +1 -0
  22. package/dist/decorators/variation.decorator.d.ts +10 -0
  23. package/dist/decorators/variation.decorator.js +20 -0
  24. package/dist/decorators/variation.decorator.js.map +1 -0
  25. package/dist/index.d.ts +4 -13
  26. package/dist/index.js +20 -17
  27. package/dist/index.js.map +1 -1
  28. package/dist/runnable.interface.d.ts +11 -0
  29. package/dist/runnable.interface.js +3 -0
  30. package/dist/runnable.interface.js.map +1 -0
  31. package/package.json +6 -6
  32. package/src/common/metadata.registry.ts +91 -0
  33. package/src/common/types.ts +57 -0
  34. package/src/decorators/command.decorator.ts +36 -0
  35. package/src/decorators/index.ts +5 -0
  36. package/src/decorators/option-with-value.decorator.ts +30 -0
  37. package/src/decorators/option.decorator.ts +24 -0
  38. package/src/decorators/sub-command.decorator.ts +22 -0
  39. package/src/decorators/variation.decorator.ts +23 -0
  40. package/src/index.ts +9 -16
  41. package/src/runnable.interface.ts +11 -0
  42. package/dist/cmd.core.d.ts +0 -2
  43. package/dist/cmd.core.js +0 -157
  44. package/dist/cmd.core.js.map +0 -1
  45. package/dist/decorators.d.ts +0 -5
  46. package/dist/decorators.js +0 -58
  47. package/dist/decorators.js.map +0 -1
  48. package/dist/env.provider.d.ts +0 -6
  49. package/dist/env.provider.js +0 -29
  50. package/dist/env.provider.js.map +0 -1
  51. package/dist/rsdk/metadata.aggregator.d.ts +0 -6
  52. package/dist/rsdk/metadata.aggregator.js +0 -17
  53. package/dist/rsdk/metadata.aggregator.js.map +0 -1
  54. package/dist/rsdk-json.parser.d.ts +0 -6
  55. package/dist/rsdk-json.parser.js +0 -21
  56. package/dist/rsdk-json.parser.js.map +0 -1
  57. package/dist/types.d.ts +0 -97
  58. package/dist/types.js +0 -13
  59. package/dist/types.js.map +0 -1
  60. package/dist/utils.d.ts +0 -4
  61. package/dist/utils.js +0 -30
  62. package/dist/utils.js.map +0 -1
  63. package/src/cmd.core.ts +0 -221
  64. package/src/decorators.ts +0 -56
  65. package/src/env.provider.ts +0 -30
  66. package/src/rsdk/metadata.aggregator.ts +0 -17
  67. package/src/rsdk-json.parser.ts +0 -17
  68. package/src/types.ts +0 -102
  69. package/src/utils.ts +0 -52
package/dist/types.d.ts DELETED
@@ -1,97 +0,0 @@
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 DELETED
@@ -1,13 +0,0 @@
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
package/dist/types.js.map DELETED
@@ -1 +0,0 @@
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"}
package/dist/utils.d.ts DELETED
@@ -1,4 +0,0 @@
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 DELETED
@@ -1,30 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.defineCoreMetadata = exports.defineMetadata = void 0;
4
- exports.assertString = assertString;
5
- const types_1 = require("./types");
6
- function assertString(v) {
7
- if (typeof v !== 'string') {
8
- throw new TypeError('v must be string');
9
- }
10
- }
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
package/dist/utils.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;AAGA,oCAMC;AARD,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;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/src/cmd.core.ts DELETED
@@ -1,221 +0,0 @@
1
- import { LoggerFactory } from '@rsdk/logging';
2
- import type { OptionValues } from 'commander';
3
- import { Command } from 'commander';
4
- import _ from 'lodash';
5
-
6
- import { Env } from './env.provider';
7
- import type { CoreMetadataMap } from './types';
8
- import { MetaKeys } from './types';
9
-
10
- const cliLogger = LoggerFactory.create('@rsdk/cli.common');
11
-
12
- type ParameterIndex = number;
13
- function getRootCommand(globalMetadata: any): Command | undefined {
14
- const v = globalMetadata?.get(MetaKeys.Core);
15
-
16
- if (!v) {
17
- return;
18
- }
19
- return new Command(v.name).description(v.description);
20
- }
21
-
22
- function createEnvKey(optionMetadata: OptionMetadata): string {
23
- return _.snakeCase(
24
- `${optionMetadata.name}${optionMetadata.strategy === Boolean ? '_enabled' : ''}`,
25
- ).toUpperCase();
26
- }
27
-
28
- /**
29
- * Приоритет значений env -> flagValue -> defaultValue
30
- * Сделано намеренно так как в кейсе использования локально проблем с ENV вряд ли будет.
31
- * А вот в кубе например удобнее редактировать ConfigMap и добавить туда ключ, чем редактировать Deployment
32
- * @param {OptionMetadata} optionMetadata
33
- * @param {OptionValues} opts
34
- * @returns {any}
35
- */
36
- function extractValue(optionMetadata: OptionMetadata, opts: OptionValues): any {
37
- // Создаем ключ для переменной окружения на основе метаданных опции
38
- const envKey = createEnvKey(optionMetadata);
39
-
40
- // Проверяем, существует ли значение для данного ключа в переменных окружения
41
- const envHasValue = Env.has(envKey);
42
-
43
- // Преобразуем имя опции в camelCase для использования в объекте opts
44
- const optsKey = _.camelCase(optionMetadata.name);
45
-
46
- // Получаем значение флага из объекта opts
47
- const flagValue = opts[optsKey];
48
-
49
- // Проверяем, был ли предоставлен флаг в объекте opts
50
- const flagProvided = Object.hasOwn(opts, optsKey);
51
-
52
- // Если значение переменной окружения существует
53
- if (envHasValue) {
54
- // Получаем значение переменной окружения
55
- const envValue = Env.get(envKey);
56
-
57
- // Если флаг был предоставлен, выводим предупреждение о переопределении значения флага значением переменной окружения
58
- if (flagProvided) {
59
- cliLogger.warn('Env value override flag value', {
60
- optionMetadata,
61
- envKey,
62
- envValue,
63
- flagValue,
64
- });
65
- }
66
-
67
- // Возвращаем значение переменной окружения
68
- return envValue;
69
- }
70
-
71
- // Если значение переменной окружения не предоставлено, выводим отладочное сообщение
72
- cliLogger.trace('Env value not provided', { key: optsKey, envKey });
73
-
74
- // Если флаг был предоставлен, выводим отладочное сообщение и возвращаем значение флага
75
- if (flagProvided) {
76
- cliLogger.trace('Use flag value', {
77
- key: optsKey,
78
- flagValue,
79
- opts,
80
- envHasValue,
81
- envKey,
82
- });
83
- return flagValue;
84
- }
85
-
86
- // Если ни значение переменной окружения, ни флаг не предоставлены, выводим отладочное сообщение и возвращаем значение по умолчанию
87
- cliLogger.trace('Use default value', {
88
- key: optsKey,
89
- flagValue,
90
- opts,
91
- envHasValue,
92
- envKey,
93
- defaultValue: optionMetadata.defaultValue,
94
- });
95
-
96
- return optionMetadata.defaultValue;
97
- }
98
-
99
- function createCommandHandler(
100
- argMap: Map<ParameterIndex, OptionMetadata>,
101
- handler: (...args: any[]) => any,
102
- ): (__: any, cmd: Command) => void {
103
- return (__, cmd: Command) => {
104
- const opts = cmd.opts();
105
-
106
- const normalizedArgList: {
107
- index: number;
108
- optionMetadata: OptionMetadata;
109
- }[] = [...argMap].map(([index, optionMetadata]) => ({
110
- index,
111
- optionMetadata,
112
- }));
113
- const sortedArgList: { index: any; optionMetadata: OptionMetadata }[] =
114
- _.sortBy(normalizedArgList, ['index']);
115
-
116
- const args: (string | undefined)[] = sortedArgList.map(
117
- ({ optionMetadata }) => {
118
- cliLogger.trace('handle arg', {
119
- optionMetadata,
120
- });
121
- const result = extractValue(optionMetadata, opts);
122
-
123
- if (optionMetadata.parser) {
124
- return optionMetadata.parser(result);
125
- }
126
- return result;
127
- },
128
- );
129
-
130
- handler(...args);
131
- };
132
- }
133
-
134
- type OptionMetadata = {
135
- name: string;
136
- description: string;
137
- alias?: string;
138
- defaultValue?: string | boolean;
139
- parser?: (v: any) => any;
140
- strategy: BooleanConstructor | StringConstructor;
141
- };
142
-
143
- function createArgMap(
144
- metadata: { metaKey: MetaKeys; value: any }[],
145
- ): Map<ParameterIndex, OptionMetadata> {
146
- return metadata.reduce((acc, item) => {
147
- switch (item.metaKey) {
148
- case MetaKeys.Alias:
149
- case MetaKeys.DefaultValue:
150
- case MetaKeys.Option:
151
- acc.set(item.value.parameterIndex, {
152
- ...acc.get(item.value.parameterIndex),
153
- ...item.value,
154
- });
155
- }
156
- return acc;
157
- }, new Map<ParameterIndex, OptionMetadata>());
158
- }
159
-
160
- export const getCommanderCommand = (cmd: any): Command[] => {
161
- const value = Reflect.getMetadata(MetaKeys.Core, cmd);
162
- if (!(value instanceof Map)) {
163
- throw new TypeError('value not a map');
164
- }
165
-
166
- const globalMetadata = Reflect.getMetadata(MetaKeys.Global, cmd);
167
-
168
- const rootCommand = getRootCommand(globalMetadata);
169
-
170
- const map: CoreMetadataMap = value;
171
-
172
- // Могут быть методы/поля, на которые ссылается метод через this
173
- const instance = Reflect.construct(cmd, []);
174
-
175
- const commands: Command[] = [];
176
-
177
- for (const [propertyKey, metadata] of map) {
178
- const subCmdMetadata = metadata.filter(
179
- ({ metaKey }) => metaKey === MetaKeys.SubCmd,
180
- );
181
- if (subCmdMetadata?.length !== 1) {
182
- throw new Error('Must be one subcmd metadata', {
183
- cause: {
184
- subCmdMetadata,
185
- },
186
- });
187
- }
188
-
189
- const subCmdValue = subCmdMetadata[0].value;
190
- const command = new Command(subCmdValue.name).description(
191
- subCmdValue.description,
192
- );
193
-
194
- const argMap = createArgMap(metadata);
195
-
196
- for (const option of argMap.values()) {
197
- command.option(
198
- `--${option.name}${option.strategy === String ? ' <value>' : ''}`,
199
- `${option.description} [eq ${createEnvKey(option)} in env]`,
200
- option.defaultValue,
201
- );
202
- }
203
-
204
- command.action(
205
- createCommandHandler(
206
- argMap,
207
-
208
- // @ts-expect-error потому что не понимает что инстанс это объект у которого есть этот метод
209
- instance[propertyKey].bind(instance),
210
- ),
211
- );
212
- commands.push(command);
213
- }
214
- if (rootCommand) {
215
- for (const command of commands) {
216
- rootCommand.addCommand(command);
217
- }
218
- return [rootCommand];
219
- }
220
- return commands;
221
- };
package/src/decorators.ts DELETED
@@ -1,56 +0,0 @@
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
- parser?: (v: any) => any,
27
- ): ParameterDecorator => {
28
- return (target, propertyKey, parameterIndex) => {
29
- assertString(propertyKey);
30
- defineMetadata(target, propertyKey, MetaKeys.Option, {
31
- name,
32
- description,
33
- strategy,
34
- parameterIndex,
35
- parser,
36
- });
37
- };
38
- };
39
- export const Alias = (alias: string): ParameterDecorator => {
40
- return (target, propertyKey, parameterIndex) => {
41
- assertString(propertyKey);
42
- defineMetadata(target, propertyKey, MetaKeys.Alias, {
43
- alias,
44
- parameterIndex,
45
- });
46
- };
47
- };
48
- export const Default = (v: any): ParameterDecorator => {
49
- return (target, propertyKey, parameterIndex) => {
50
- assertString(propertyKey);
51
- defineMetadata(target, propertyKey, MetaKeys.DefaultValue, {
52
- defaultValue: v,
53
- parameterIndex,
54
- });
55
- };
56
- };
@@ -1,30 +0,0 @@
1
- import _ from 'lodash';
2
-
3
- export class Env {
4
- static has(key: string): boolean {
5
- const nk = Env.normalizeKey(key);
6
-
7
- return nk in process.env;
8
- }
9
-
10
- static get(key: string): string | undefined;
11
- static get<V = string>(key: string, parser: (v: string | undefined) => V): V;
12
- static get<V = string>(
13
- key: string,
14
- parser?: (v: string | undefined) => V,
15
- ): V | undefined | string {
16
- const nk = this.normalizeKey(key);
17
- if (!Env.has(nk)) {
18
- return undefined;
19
- }
20
- const v = process.env[nk];
21
- if (parser) {
22
- return parser(v);
23
- }
24
- return v;
25
- }
26
-
27
- private static normalizeKey(key: string): string {
28
- return _.snakeCase(key).toUpperCase();
29
- }
30
- }
@@ -1,17 +0,0 @@
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
- }
@@ -1,17 +0,0 @@
1
- import { readFile } from 'node:fs/promises';
2
- import path 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 = path.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 DELETED
@@ -1,102 +0,0 @@
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 DELETED
@@ -1,52 +0,0 @@
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
- };