@rsdk/cli 4.2.4 → 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.
Files changed (71) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/bin.js +10 -0
  3. package/dist/exception.d.ts +4 -0
  4. package/dist/exception.js +23 -0
  5. package/dist/exception.js.map +1 -0
  6. package/dist/index.d.ts +1 -0
  7. package/dist/index.js +61 -0
  8. package/dist/index.js.map +1 -0
  9. package/dist/package.loader.d.ts +6 -0
  10. package/dist/package.loader.js +28 -0
  11. package/dist/package.loader.js.map +1 -0
  12. package/package.json +11 -6
  13. package/src/exception.ts +25 -0
  14. package/src/index.ts +71 -0
  15. package/src/package.loader.ts +36 -0
  16. package/dist/bin.d.ts +0 -2
  17. package/dist/bin.js +0 -21
  18. package/dist/bin.js.map +0 -1
  19. package/dist/kafka/commands/extract/extract.command.d.ts +0 -2
  20. package/dist/kafka/commands/extract/extract.command.js +0 -17
  21. package/dist/kafka/commands/extract/extract.command.js.map +0 -1
  22. package/dist/kafka/commands/extract/kafka-config.extractor.d.ts +0 -6
  23. package/dist/kafka/commands/extract/kafka-config.extractor.js +0 -40
  24. package/dist/kafka/commands/extract/kafka-config.extractor.js.map +0 -1
  25. package/dist/kafka/commands/extract/types.d.ts +0 -85
  26. package/dist/kafka/commands/extract/types.js +0 -3
  27. package/dist/kafka/commands/extract/types.js.map +0 -1
  28. package/dist/kafka/commands/schema/print-schema.d.ts +0 -5
  29. package/dist/kafka/commands/schema/print-schema.js +0 -11
  30. package/dist/kafka/commands/schema/print-schema.js.map +0 -1
  31. package/dist/kafka/commands/schema/schema.command.d.ts +0 -2
  32. package/dist/kafka/commands/schema/schema.command.js +0 -12
  33. package/dist/kafka/commands/schema/schema.command.js.map +0 -1
  34. package/dist/kafka/commands/sync/check-exist.d.ts +0 -7
  35. package/dist/kafka/commands/sync/check-exist.js +0 -57
  36. package/dist/kafka/commands/sync/check-exist.js.map +0 -1
  37. package/dist/kafka/commands/sync/context.d.ts +0 -3
  38. package/dist/kafka/commands/sync/context.js +0 -3
  39. package/dist/kafka/commands/sync/context.js.map +0 -1
  40. package/dist/kafka/commands/sync/create-topic.task.d.ts +0 -5
  41. package/dist/kafka/commands/sync/create-topic.task.js +0 -28
  42. package/dist/kafka/commands/sync/create-topic.task.js.map +0 -1
  43. package/dist/kafka/commands/sync/get-config.d.ts +0 -5
  44. package/dist/kafka/commands/sync/get-config.js +0 -28
  45. package/dist/kafka/commands/sync/get-config.js.map +0 -1
  46. package/dist/kafka/commands/sync/kafka.creds-provider.d.ts +0 -4
  47. package/dist/kafka/commands/sync/kafka.creds-provider.js +0 -22
  48. package/dist/kafka/commands/sync/kafka.creds-provider.js.map +0 -1
  49. package/dist/kafka/commands/sync/sync.command.d.ts +0 -2
  50. package/dist/kafka/commands/sync/sync.command.js +0 -49
  51. package/dist/kafka/commands/sync/sync.command.js.map +0 -1
  52. package/dist/kafka/config.schema.d.ts +0 -34
  53. package/dist/kafka/config.schema.js +0 -26
  54. package/dist/kafka/config.schema.js.map +0 -1
  55. package/dist/kafka/schemas/string-enum.d.ts +0 -2
  56. package/dist/kafka/schemas/string-enum.js +0 -14
  57. package/dist/kafka/schemas/string-enum.js.map +0 -1
  58. package/src/bin.ts +0 -26
  59. package/src/kafka/commands/extract/extract.command.ts +0 -16
  60. package/src/kafka/commands/extract/kafka-config.extractor.ts +0 -47
  61. package/src/kafka/commands/extract/types.ts +0 -101
  62. package/src/kafka/commands/schema/print-schema.ts +0 -15
  63. package/src/kafka/commands/schema/schema.command.ts +0 -10
  64. package/src/kafka/commands/sync/check-exist.ts +0 -68
  65. package/src/kafka/commands/sync/context.ts +0 -3
  66. package/src/kafka/commands/sync/create-topic.task.ts +0 -35
  67. package/src/kafka/commands/sync/get-config.ts +0 -25
  68. package/src/kafka/commands/sync/kafka.creds-provider.ts +0 -16
  69. package/src/kafka/commands/sync/sync.command.ts +0 -66
  70. package/src/kafka/config.schema.ts +0 -31
  71. package/src/kafka/schemas/string-enum.ts +0 -15
@@ -1,57 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.KafkaTopicConfigurator = void 0;
4
- const core_1 = require("@rsdk/core");
5
- const kafkajs_1 = require("kafkajs");
6
- const listr2_1 = require("listr2");
7
- class KafkaTopicConfigurator {
8
- static async configure(topic, admin, parentTask) {
9
- const metadata = await admin.fetchTopicMetadata({
10
- topics: [topic.name],
11
- });
12
- const partitions = metadata.topics[0].partitions.length;
13
- if (topic.spec?.partitions && partitions !== topic.spec.partitions) {
14
- throw new Error(`partitoins for ${topic.name} settled to ${partitions}, but expected ${topic.spec.partitions}`);
15
- }
16
- const topicConfig = await admin.describeConfigs({
17
- resources: [
18
- {
19
- type: kafkajs_1.ConfigResourceTypes.TOPIC,
20
- configNames: ['cleanup.policy'],
21
- name: topic.name,
22
- },
23
- ],
24
- includeSynonyms: true,
25
- });
26
- const cleanupPolicy = topicConfig.resources.find(({ resourceName }) => resourceName === topic.name);
27
- if (!cleanupPolicy) {
28
- throw new core_1.InternalException('cleanupPolicy not found');
29
- }
30
- const currentValue = cleanupPolicy?.configEntries[0].configValue;
31
- const configValue = topic?.spec?.settings?.['cleanup.policy'];
32
- if (configValue && currentValue !== configValue) {
33
- parentTask.output = `Alter cleanup.policy from ${currentValue} to ${configValue}`;
34
- await (0, listr2_1.delay)(3e3);
35
- await admin.alterConfigs({
36
- validateOnly: false,
37
- resources: [
38
- {
39
- type: kafkajs_1.ConfigResourceTypes.TOPIC,
40
- configEntries: [
41
- {
42
- value: configValue,
43
- name: 'cleanup.policy',
44
- },
45
- ],
46
- name: topic.name,
47
- },
48
- ],
49
- });
50
- parentTask.output = `Alter cleanup.policy from ${currentValue} to ${configValue} completed!`;
51
- await (0, listr2_1.delay)(3e3);
52
- }
53
- parentTask.title = `topic ${topic.name} exists and respond config`;
54
- }
55
- }
56
- exports.KafkaTopicConfigurator = KafkaTopicConfigurator;
57
- //# sourceMappingURL=check-exist.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"check-exist.js","sourceRoot":"","sources":["../../../../src/kafka/commands/sync/check-exist.ts"],"names":[],"mappings":";;;AAAA,qCAA+C;AAG/C,qCAA8C;AAE9C,mCAA+B;AAI/B,MAAa,sBAAsB;IACjC,MAAM,CAAC,KAAK,CAAC,SAAS,CACpB,KAAiC,EACjC,KAAY,EACZ,UAA2D;QAE3D,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,kBAAkB,CAAC;YAC9C,MAAM,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC;SACrB,CAAC,CAAC;QACH,MAAM,UAAU,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,MAAM,CAAC;QACxD,IAAI,KAAK,CAAC,IAAI,EAAE,UAAU,IAAI,UAAU,KAAK,KAAK,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC;YACnE,MAAM,IAAI,KAAK,CACb,kBAAkB,KAAK,CAAC,IAAI,eAAe,UAAU,kBAAkB,KAAK,CAAC,IAAI,CAAC,UAAU,EAAE,CAC/F,CAAC;QACJ,CAAC;QACD,MAAM,WAAW,GAAG,MAAM,KAAK,CAAC,eAAe,CAAC;YAC9C,SAAS,EAAE;gBACT;oBACE,IAAI,EAAE,6BAAmB,CAAC,KAAK;oBAC/B,WAAW,EAAE,CAAC,gBAAgB,CAAC;oBAC/B,IAAI,EAAE,KAAK,CAAC,IAAI;iBACjB;aACF;YACD,eAAe,EAAE,IAAI;SACtB,CAAC,CAAC;QAEH,MAAM,aAAa,GAAG,WAAW,CAAC,SAAS,CAAC,IAAI,CAC9C,CAAC,EAAE,YAAY,EAAE,EAAE,EAAE,CAAC,YAAY,KAAK,KAAK,CAAC,IAAI,CAClD,CAAC;QACF,IAAI,CAAC,aAAa,EAAE,CAAC;YACnB,MAAM,IAAI,wBAAiB,CAAC,yBAAyB,CAAC,CAAC;QACzD,CAAC;QACD,MAAM,YAAY,GAAG,aAAa,EAAE,aAAa,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC;QACjE,MAAM,WAAW,GAAG,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,gBAAgB,CAAC,CAAC;QAE9D,IAAI,WAAW,IAAI,YAAY,KAAK,WAAW,EAAE,CAAC;YAChD,UAAU,CAAC,MAAM,GAAG,6BAA6B,YAAY,OAAO,WAAW,EAAE,CAAC;YAClF,MAAM,IAAA,cAAK,EAAC,GAAG,CAAC,CAAC;YACjB,MAAM,KAAK,CAAC,YAAY,CAAC;gBACvB,YAAY,EAAE,KAAK;gBACnB,SAAS,EAAE;oBACT;wBACE,IAAI,EAAE,6BAAmB,CAAC,KAAK;wBAC/B,aAAa,EAAE;4BACb;gCACE,KAAK,EAAE,WAAW;gCAClB,IAAI,EAAE,gBAAgB;6BACvB;yBACF;wBACD,IAAI,EAAE,KAAK,CAAC,IAAI;qBACjB;iBACF;aACF,CAAC,CAAC;YACH,UAAU,CAAC,MAAM,GAAG,6BAA6B,YAAY,OAAO,WAAW,aAAa,CAAC;YAC7F,MAAM,IAAA,cAAK,EAAC,GAAG,CAAC,CAAC;QACnB,CAAC;QACD,UAAU,CAAC,KAAK,GAAG,SAAS,KAAK,CAAC,IAAI,4BAA4B,CAAC;IACrE,CAAC;CACF;AA1DD,wDA0DC"}
@@ -1,3 +0,0 @@
1
- export type Context = {
2
- requireCreate: boolean;
3
- };
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=context.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"context.js","sourceRoot":"","sources":["../../../../src/kafka/commands/sync/context.ts"],"names":[],"mappings":""}
@@ -1,5 +0,0 @@
1
- import type { Static } from '@sinclair/typebox';
2
- import type { Admin } from 'kafkajs';
3
- import type { ListrRendererFactory, ListrTaskWrapper } from 'listr2';
4
- import type { TopicSchema } from '../../config.schema';
5
- export declare function createTopic(topic: Static<typeof TopicSchema>, admin: Admin, parentTask: ListrTaskWrapper<unknown, ListrRendererFactory>): Promise<void>;
@@ -1,28 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createTopic = void 0;
4
- const listr2_1 = require("listr2");
5
- async function createTopic(topic, admin, parentTask) {
6
- await (0, listr2_1.delay)(1000);
7
- const numPartitions = topic.spec?.partitions ?? 2;
8
- const replicationFactor = topic.spec?.replicationFactor;
9
- const result = await admin.createTopics({
10
- topics: [
11
- {
12
- topic: topic.name,
13
- ...(replicationFactor && {
14
- replicationFactor: replicationFactor,
15
- }),
16
- numPartitions: numPartitions,
17
- },
18
- ],
19
- });
20
- if (result) {
21
- console.log('create topic %s complete!', topic.name);
22
- parentTask.title = `create topic ${topic.name} complete!`;
23
- return;
24
- }
25
- throw new Error(`create topic ${topic.name} failed!`);
26
- }
27
- exports.createTopic = createTopic;
28
- //# sourceMappingURL=create-topic.task.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"create-topic.task.js","sourceRoot":"","sources":["../../../../src/kafka/commands/sync/create-topic.task.ts"],"names":[],"mappings":";;;AAGA,mCAA+B;AAIxB,KAAK,UAAU,WAAW,CAC/B,KAAiC,EACjC,KAAY,EACZ,UAA2D;IAE3D,MAAM,IAAA,cAAK,EAAC,IAAI,CAAC,CAAC;IAClB,MAAM,aAAa,GAAG,KAAK,CAAC,IAAI,EAAE,UAAU,IAAI,CAAC,CAAC;IAElD,MAAM,iBAAiB,GAAG,KAAK,CAAC,IAAI,EAAE,iBAAiB,CAAC;IAExD,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,YAAY,CAAC;QACtC,MAAM,EAAE;YACN;gBACE,KAAK,EAAE,KAAK,CAAC,IAAI;gBACjB,GAAG,CAAC,iBAAiB,IAAI;oBACvB,iBAAiB,EAAE,iBAAiB;iBACrC,CAAC;gBACF,aAAa,EAAE,aAAa;aAC7B;SACF;KACF,CAAC,CAAC;IACH,IAAI,MAAM,EAAE,CAAC;QACX,OAAO,CAAC,GAAG,CAAC,2BAA2B,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;QACrD,UAAU,CAAC,KAAK,GAAG,gBAAgB,KAAK,CAAC,IAAI,YAAY,CAAC;QAC1D,OAAO;IACT,CAAC;IACD,MAAM,IAAI,KAAK,CAAC,gBAAgB,KAAK,CAAC,IAAI,UAAU,CAAC,CAAC;AACxD,CAAC;AA3BD,kCA2BC"}
@@ -1,5 +0,0 @@
1
- import type { Static } from '@sinclair/typebox';
2
- import type { CliKafkaConfigSchema } from '../../config.schema';
3
- export declare class KafkaExpectedConfigProvider {
4
- static getConfig(): Promise<Static<typeof CliKafkaConfigSchema>>;
5
- }
@@ -1,28 +0,0 @@
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.KafkaExpectedConfigProvider = void 0;
7
- const core_1 = require("@rsdk/core");
8
- const promises_1 = require("node:fs/promises");
9
- const node_path_1 = require("node:path");
10
- const yaml_1 = __importDefault(require("yaml"));
11
- const config_schema_1 = require("../../config.schema");
12
- class KafkaExpectedConfigProvider {
13
- static async getConfig() {
14
- const kafkaYml = await (0, promises_1.readFile)((0, node_path_1.resolve)('kafka.yml'), {
15
- encoding: 'utf8',
16
- });
17
- const config = yaml_1.default.parse(kafkaYml);
18
- const isValid = config_schema_1.CliKafkaConfigSchemaChecker.Check(config);
19
- if (!isValid) {
20
- throw new core_1.InputException('Invalid config', {
21
- cause: [...config_schema_1.CliKafkaConfigSchemaChecker.Errors(config)],
22
- });
23
- }
24
- return config;
25
- }
26
- }
27
- exports.KafkaExpectedConfigProvider = KafkaExpectedConfigProvider;
28
- //# sourceMappingURL=get-config.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"get-config.js","sourceRoot":"","sources":["../../../../src/kafka/commands/sync/get-config.ts"],"names":[],"mappings":";;;;;;AAAA,qCAA4C;AAE5C,+CAA4C;AAC5C,yCAAoC;AACpC,gDAAwB;AAGxB,uDAAkE;AAElE,MAAa,2BAA2B;IACtC,MAAM,CAAC,KAAK,CAAC,SAAS;QACpB,MAAM,QAAQ,GAAG,MAAM,IAAA,mBAAQ,EAAC,IAAA,mBAAO,EAAC,WAAW,CAAC,EAAE;YACpD,QAAQ,EAAE,MAAM;SACjB,CAAC,CAAC;QACH,MAAM,MAAM,GAAwC,cAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;QAEzE,MAAM,OAAO,GAAG,2CAA2B,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QAC1D,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,MAAM,IAAI,qBAAc,CAAC,gBAAgB,EAAE;gBACzC,KAAK,EAAE,CAAC,GAAG,2CAA2B,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;aACvD,CAAC,CAAC;QACL,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;CACF;AAfD,kEAeC"}
@@ -1,4 +0,0 @@
1
- import type { KafkaConfig } from 'kafkajs';
2
- export declare class KafkaCredsProvider {
3
- static getKafkaCreds(): KafkaConfig;
4
- }
@@ -1,22 +0,0 @@
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.KafkaCredsProvider = void 0;
7
- const core_1 = require("@rsdk/core");
8
- const dotenv_1 = __importDefault(require("dotenv"));
9
- class KafkaCredsProvider {
10
- static getKafkaCreds() {
11
- dotenv_1.default.config();
12
- const kafkaHost = process.env.KAFKA_HOST;
13
- if (!kafkaHost) {
14
- throw new core_1.InternalException('KAFKA_HOST not found');
15
- }
16
- return {
17
- brokers: [kafkaHost],
18
- };
19
- }
20
- }
21
- exports.KafkaCredsProvider = KafkaCredsProvider;
22
- //# sourceMappingURL=kafka.creds-provider.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"kafka.creds-provider.js","sourceRoot":"","sources":["../../../../src/kafka/commands/sync/kafka.creds-provider.ts"],"names":[],"mappings":";;;;;;AAAA,qCAA+C;AAC/C,oDAA4B;AAG5B,MAAa,kBAAkB;IAC7B,MAAM,CAAC,aAAa;QAClB,gBAAM,CAAC,MAAM,EAAE,CAAC;QAChB,MAAM,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC;QACzC,IAAI,CAAC,SAAS,EAAE,CAAC;YACf,MAAM,IAAI,wBAAiB,CAAC,sBAAsB,CAAC,CAAC;QACtD,CAAC;QACD,OAAO;YACL,OAAO,EAAE,CAAC,SAAS,CAAC;SACrB,CAAC;IACJ,CAAC;CACF;AAXD,gDAWC"}
@@ -1,2 +0,0 @@
1
- import { Command } from 'commander';
2
- export declare const KafkaSyncCommand: Command;
@@ -1,49 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.KafkaSyncCommand = void 0;
4
- const commander_1 = require("commander");
5
- const kafkajs_1 = require("kafkajs");
6
- const listr2_1 = require("listr2");
7
- const kafka_config_extractor_1 = require("../extract/kafka-config.extractor");
8
- const check_exist_1 = require("./check-exist");
9
- const create_topic_task_1 = require("./create-topic.task");
10
- const get_config_1 = require("./get-config");
11
- const kafka_creds_provider_1 = require("./kafka.creds-provider");
12
- async function createAdmin(kafkaCreds) {
13
- const kafka = new kafkajs_1.Kafka(kafkaCreds);
14
- const admin = kafka.admin();
15
- await admin.connect();
16
- return admin;
17
- }
18
- exports.KafkaSyncCommand = new commander_1.Command('sync')
19
- .description('try sync kafka state from kafka.yml file')
20
- .option('--from-rsdk', 'run command based on rsdk.json, instead of kafka.yml')
21
- .action(async function (_, command) {
22
- const options = command.opts();
23
- const config = options.fromRsdk
24
- ? await kafka_config_extractor_1.KafkaConfigExtractor.extract()
25
- : await get_config_1.KafkaExpectedConfigProvider.getConfig();
26
- const kafkaCreds = kafka_creds_provider_1.KafkaCredsProvider.getKafkaCreds();
27
- const admin = await createAdmin(kafkaCreds);
28
- const existedTopic = await admin.listTopics();
29
- await new listr2_1.Listr(config.topics.map((topic) => ({
30
- title: topic.name,
31
- task: async (_ctx, parentTask) => {
32
- const requireCreate = !existedTopic.includes(topic.name);
33
- return parentTask.newListr([
34
- {
35
- title: requireCreate ? 'create' : 'configure',
36
- task: async () => {
37
- if (requireCreate) {
38
- await (0, create_topic_task_1.createTopic)(topic, admin, parentTask);
39
- return;
40
- }
41
- await check_exist_1.KafkaTopicConfigurator.configure(topic, admin, parentTask);
42
- },
43
- },
44
- ], { concurrent: false });
45
- },
46
- })), { concurrent: true }).run({ requireCreate: true });
47
- await admin.disconnect();
48
- });
49
- //# sourceMappingURL=sync.command.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"sync.command.js","sourceRoot":"","sources":["../../../../src/kafka/commands/sync/sync.command.ts"],"names":[],"mappings":";;;AAAA,yCAAoC;AAEpC,qCAAgC;AAChC,mCAA+B;AAE/B,8EAAyE;AAEzE,+CAAuD;AAEvD,2DAAkD;AAClD,6CAA2D;AAC3D,iEAA4D;AAE5D,KAAK,UAAU,WAAW,CAAC,UAAuB;IAChD,MAAM,KAAK,GAAG,IAAI,eAAK,CAAC,UAAU,CAAC,CAAC;IACpC,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,EAAE,CAAC;IAE5B,MAAM,KAAK,CAAC,OAAO,EAAE,CAAC;IACtB,OAAO,KAAK,CAAC;AACf,CAAC;AAEY,QAAA,gBAAgB,GAAG,IAAI,mBAAO,CAAC,MAAM,CAAC;KAChD,WAAW,CAAC,0CAA0C,CAAC;KACvD,MAAM,CAAC,aAAa,EAAE,sDAAsD,CAAC;KAC7E,MAAM,CAAC,KAAK,WAAW,CAAC,EAAE,OAAgB;IACzC,MAAM,OAAO,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;IAC/B,MAAM,MAAM,GAAG,OAAO,CAAC,QAAQ;QAC7B,CAAC,CAAC,MAAM,6CAAoB,CAAC,OAAO,EAAE;QACtC,CAAC,CAAC,MAAM,wCAA2B,CAAC,SAAS,EAAE,CAAC;IAElD,MAAM,UAAU,GAAG,yCAAkB,CAAC,aAAa,EAAE,CAAC;IACtD,MAAM,KAAK,GAAG,MAAM,WAAW,CAAC,UAAU,CAAC,CAAC;IAE5C,MAAM,YAAY,GAAG,MAAM,KAAK,CAAC,UAAU,EAAE,CAAC;IAE9C,MAAM,IAAI,cAAK,CACb,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QAC5B,KAAK,EAAE,KAAK,CAAC,IAAI;QACjB,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,UAAU,EAA4B,EAAE;YACzD,MAAM,aAAa,GAAG,CAAC,YAAY,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YAEzD,OAAO,UAAU,CAAC,QAAQ,CACxB;gBACE;oBACE,KAAK,EAAE,aAAa,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,WAAW;oBAC7C,IAAI,EAAE,KAAK,IAA2B,EAAE;wBACtC,IAAI,aAAa,EAAE,CAAC;4BAClB,MAAM,IAAA,+BAAW,EAAC,KAAK,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC;4BAC5C,OAAO;wBACT,CAAC;wBACD,MAAM,oCAAsB,CAAC,SAAS,CACpC,KAAK,EACL,KAAK,EACL,UAAU,CACX,CAAC;oBACJ,CAAC;iBACF;aACF,EACD,EAAE,UAAU,EAAE,KAAK,EAAE,CACtB,CAAC;QACJ,CAAC;KACF,CAAC,CAAC,EACH,EAAE,UAAU,EAAE,IAAI,EAAE,CACrB,CAAC,GAAG,CAAC,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC;IAC/B,MAAM,KAAK,CAAC,UAAU,EAAE,CAAC;AAC3B,CAAC,CAAC,CAAC"}
@@ -1,34 +0,0 @@
1
- export declare const TopicSchema: import("@sinclair/typebox").TObject<{
2
- name: import("@sinclair/typebox").TString;
3
- spec: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TObject<{
4
- partitions: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TInteger>;
5
- replicationFactor: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TInteger>;
6
- settings: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TObject<{
7
- 'cleanup.policy': import("@sinclair/typebox").TUnsafe<"delete" | "compact">;
8
- }>>;
9
- }>>>;
10
- }>;
11
- export declare const CliKafkaConfigSchema: import("@sinclair/typebox").TObject<{
12
- topics: import("@sinclair/typebox").TArray<import("@sinclair/typebox").TObject<{
13
- name: import("@sinclair/typebox").TString;
14
- spec: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TObject<{
15
- partitions: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TInteger>;
16
- replicationFactor: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TInteger>;
17
- settings: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TObject<{
18
- 'cleanup.policy': import("@sinclair/typebox").TUnsafe<"delete" | "compact">;
19
- }>>;
20
- }>>>;
21
- }>>;
22
- }>;
23
- export declare const CliKafkaConfigSchemaChecker: import("@sinclair/typebox/compiler").TypeCheck<import("@sinclair/typebox").TObject<{
24
- topics: import("@sinclair/typebox").TArray<import("@sinclair/typebox").TObject<{
25
- name: import("@sinclair/typebox").TString;
26
- spec: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TObject<{
27
- partitions: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TInteger>;
28
- replicationFactor: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TInteger>;
29
- settings: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TObject<{
30
- 'cleanup.policy': import("@sinclair/typebox").TUnsafe<"delete" | "compact">;
31
- }>>;
32
- }>>>;
33
- }>>;
34
- }>>;
@@ -1,26 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CliKafkaConfigSchemaChecker = exports.CliKafkaConfigSchema = exports.TopicSchema = void 0;
4
- const typebox_1 = require("@sinclair/typebox");
5
- const compiler_1 = require("@sinclair/typebox/compiler");
6
- const string_enum_1 = require("./schemas/string-enum");
7
- const specSchema = typebox_1.Type.Optional(typebox_1.Type.Partial(typebox_1.Type.Object({
8
- partitions: typebox_1.Type.Integer({
9
- default: 2,
10
- }),
11
- replicationFactor: typebox_1.Type.Integer({
12
- default: 1,
13
- }),
14
- settings: typebox_1.Type.Object({
15
- 'cleanup.policy': (0, string_enum_1.StringEnum)(['delete', 'compact']),
16
- }),
17
- })));
18
- exports.TopicSchema = typebox_1.Type.Object({
19
- name: typebox_1.Type.String(),
20
- spec: typebox_1.Type.Optional(specSchema),
21
- });
22
- exports.CliKafkaConfigSchema = typebox_1.Type.Object({
23
- topics: typebox_1.Type.Array(exports.TopicSchema),
24
- });
25
- exports.CliKafkaConfigSchemaChecker = compiler_1.TypeCompiler.Compile(exports.CliKafkaConfigSchema);
26
- //# sourceMappingURL=config.schema.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"config.schema.js","sourceRoot":"","sources":["../../src/kafka/config.schema.ts"],"names":[],"mappings":";;;AAAA,+CAAyC;AACzC,yDAA0D;AAE1D,uDAAmD;AAEnD,MAAM,UAAU,GAAG,cAAI,CAAC,QAAQ,CAC9B,cAAI,CAAC,OAAO,CACV,cAAI,CAAC,MAAM,CAAC;IACV,UAAU,EAAE,cAAI,CAAC,OAAO,CAAC;QACvB,OAAO,EAAE,CAAC;KACX,CAAC;IACF,iBAAiB,EAAE,cAAI,CAAC,OAAO,CAAC;QAC9B,OAAO,EAAE,CAAC;KACX,CAAC;IACF,QAAQ,EAAE,cAAI,CAAC,MAAM,CAAC;QACpB,gBAAgB,EAAE,IAAA,wBAAU,EAAC,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;KACpD,CAAC;CACH,CAAC,CACH,CACF,CAAC;AAEW,QAAA,WAAW,GAAG,cAAI,CAAC,MAAM,CAAC;IACrC,IAAI,EAAE,cAAI,CAAC,MAAM,EAAE;IACnB,IAAI,EAAE,cAAI,CAAC,QAAQ,CAAC,UAAU,CAAC;CAChC,CAAC,CAAC;AAEU,QAAA,oBAAoB,GAAG,cAAI,CAAC,MAAM,CAAC;IAC9C,MAAM,EAAE,cAAI,CAAC,KAAK,CAAC,mBAAW,CAAC;CAChC,CAAC,CAAC;AACU,QAAA,2BAA2B,GACtC,uBAAY,CAAC,OAAO,CAAC,4BAAoB,CAAC,CAAC"}
@@ -1,2 +0,0 @@
1
- import type { TUnsafe } from '@sinclair/typebox';
2
- export declare const StringEnum: <T extends string[]>(values: [...T]) => TUnsafe<T[number]>;
@@ -1,14 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.StringEnum = void 0;
4
- const typebox_1 = require("@sinclair/typebox");
5
- typebox_1.TypeRegistry.Set('StringEnum', (schema, value) => {
6
- return schema.enum.includes(value);
7
- });
8
- const StringEnum = (values) => typebox_1.Type.Unsafe({
9
- [typebox_1.Kind]: 'StringEnum',
10
- type: 'string',
11
- enum: values,
12
- });
13
- exports.StringEnum = StringEnum;
14
- //# sourceMappingURL=string-enum.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"string-enum.js","sourceRoot":"","sources":["../../../src/kafka/schemas/string-enum.ts"],"names":[],"mappings":";;;AACA,+CAA6D;AAE7D,sBAAY,CAAC,GAAG,CAAC,YAAY,EAAE,CAAC,MAAW,EAAE,KAAU,EAAE,EAAE;IACzD,OAAO,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AACrC,CAAC,CAAC,CAAC;AAEI,MAAM,UAAU,GAAG,CACxB,MAAc,EACM,EAAE,CACtB,cAAI,CAAC,MAAM,CAAY;IACrB,CAAC,cAAI,CAAC,EAAE,YAAY;IACpB,IAAI,EAAE,QAAQ;IACd,IAAI,EAAE,MAAM;CACb,CAAC,CAAC;AAPQ,QAAA,UAAU,cAOlB"}
package/src/bin.ts DELETED
@@ -1,26 +0,0 @@
1
- #!/usr/bin/env node
2
- import { Command, program } from 'commander';
3
-
4
- import { KafkaExtractCommand } from './kafka/commands/extract/extract.command';
5
- import { SchemaCommand } from './kafka/commands/schema/schema.command';
6
- import { KafkaSyncCommand } from './kafka/commands/sync/sync.command';
7
-
8
- // TODO: сделать более понятным, переиспользуемым, консистентным и контролируем
9
- process.env.RSDK_CLI_MODE = 'true';
10
-
11
- const kafkaCommand = new Command('kafka');
12
-
13
- program.addCommand(
14
- kafkaCommand
15
- .addCommand(KafkaSyncCommand)
16
- .addCommand(KafkaExtractCommand)
17
- .addCommand(SchemaCommand),
18
- );
19
-
20
- const execute = (): void => {
21
- program.parse();
22
- };
23
-
24
- if (require.main === module) {
25
- execute();
26
- }
@@ -1,16 +0,0 @@
1
- import { Command } from 'commander';
2
-
3
- import { printDefaultOutFile, printSchema } from '../schema/print-schema';
4
-
5
- import { KafkaConfigExtractor } from './kafka-config.extractor';
6
-
7
- export const KafkaExtractCommand = new Command('extract')
8
- .description('extract kafka.yml from rsdk.json')
9
- .option('--with-schema', 'print and include $schema to yaml for autocomplete')
10
- .action(async (_, cmd: Command) => {
11
- const options = cmd.opts();
12
- if (options.withSchema) {
13
- await printSchema({ outFile: printDefaultOutFile, pretty: true });
14
- }
15
- await KafkaConfigExtractor.extractCommand(printDefaultOutFile);
16
- });
@@ -1,47 +0,0 @@
1
- import { InputException } from '@rsdk/core';
2
- import type { Static } from '@sinclair/typebox';
3
- import { readFile, writeFile } from 'node:fs/promises';
4
- import { resolve } from 'node:path';
5
- import yaml from 'yaml';
6
-
7
- import type { CliKafkaConfigSchema } from '../../config.schema';
8
-
9
- import type { Root } from './types';
10
-
11
- export class KafkaConfigExtractor {
12
- static async extractCommand(includeSchema?: string): Promise<void> {
13
- const resultKafkaConfig = await this.extract();
14
-
15
- await writeFile(
16
- resolve('kafka.yml'),
17
- yaml.stringify({
18
- ...(includeSchema && { $schema: includeSchema }),
19
- ...resultKafkaConfig,
20
- }),
21
- );
22
- }
23
-
24
- static async extract(): Promise<Static<typeof CliKafkaConfigSchema>> {
25
- const pathToRsdkJson = resolve('autodoc/rsdk.json');
26
- const rsdkJson: Root = JSON.parse(await readFile(pathToRsdkJson, 'utf8'));
27
-
28
- const kafkaMetadata = rsdkJson.rsdkMetadata
29
- .filter(({ scope }) => scope === 'kafka-topic')
30
- .map(({ value }) => value);
31
-
32
- const topics: Static<typeof CliKafkaConfigSchema>['topics'] =
33
- kafkaMetadata.map((meta) => {
34
- const topicName = meta.topicName;
35
- if (!topicName) {
36
- throw new InputException('topicName must be provided', {
37
- details: meta,
38
- });
39
- }
40
- return {
41
- name: topicName,
42
- };
43
- });
44
-
45
- return { topics };
46
- }
47
- }
@@ -1,101 +0,0 @@
1
- export interface Root {
2
- metadata: Metadata;
3
- rsdkMetadata: RsdkMetadaum[];
4
- }
5
-
6
- export interface Metadata {
7
- name: string;
8
- version: string;
9
- description: string;
10
- protocols: string[];
11
- config: Config;
12
- }
13
-
14
- export interface Config {
15
- prefix: string;
16
- sections: Section[];
17
- sources: any[];
18
- properties: any[];
19
- }
20
-
21
- export interface Section {
22
- tags?: string[];
23
- constructorName: string;
24
- properties: Property[];
25
- name?: string;
26
- }
27
-
28
- export interface Property {
29
- expectedInEnv: boolean;
30
- key: string;
31
- description: string;
32
- parser: Parser;
33
- defaultValue: any;
34
- }
35
-
36
- export interface Parser {
37
- type: string;
38
- description: string;
39
- }
40
-
41
- export interface RsdkMetadaum {
42
- scope: string;
43
- value: Value;
44
- }
45
-
46
- export interface Value {
47
- global?: boolean;
48
- imports?: Import[];
49
- providers?: Provider2[];
50
- exports?: string[];
51
- token?: string;
52
- partitionKeyField: any;
53
- topicName?: string;
54
- group?: string;
55
- type?: number;
56
- eventType?: EventType;
57
- options?: Options3;
58
- constructorName?: string;
59
- }
60
-
61
- export interface Import {
62
- providers: Provider[];
63
- exports: Export[];
64
- }
65
-
66
- export interface Provider {
67
- inject: Inject | undefined[];
68
- }
69
-
70
- export interface Inject {
71
- optional: boolean;
72
- }
73
-
74
- export interface Export {
75
- inject: Inject2 | undefined[];
76
- }
77
-
78
- export interface Inject2 {
79
- optional: boolean;
80
- }
81
-
82
- export interface Provider2 {
83
- provide: string;
84
- useValue: UseValue;
85
- }
86
-
87
- export interface UseValue {
88
- context: string;
89
- }
90
-
91
- export interface EventType {
92
- $group: string;
93
- $partitionKeyField: any;
94
- $type: string;
95
- }
96
-
97
- export interface Options3 {
98
- key: string;
99
- scope: string;
100
- description: string;
101
- }
@@ -1,15 +0,0 @@
1
- import { writeFile } from 'node:fs/promises';
2
-
3
- import { CliKafkaConfigSchema } from '../../config.schema';
4
-
5
- export const printDefaultOutFile = './kafka.schema.json';
6
-
7
- export async function printSchema(options?: {
8
- outFile?: string;
9
- pretty?: boolean;
10
- }): Promise<void> {
11
- await writeFile(
12
- options?.outFile ?? printDefaultOutFile,
13
- JSON.stringify(CliKafkaConfigSchema, null, options?.pretty ? 2 : 0),
14
- );
15
- }
@@ -1,10 +0,0 @@
1
- import { Command } from 'commander';
2
-
3
- import { printSchema } from './print-schema';
4
-
5
- export const SchemaCommand = new Command('schema')
6
- .description('print json schema for kafka.yml')
7
- .option('-o, --out-file', 'output file name', 'kafka.schema.json')
8
- .action(async (_, cmd: Command) => {
9
- await printSchema(cmd.opts().outFile);
10
- });
@@ -1,68 +0,0 @@
1
- import { InternalException } from '@rsdk/core';
2
- import type { Static } from '@sinclair/typebox';
3
- import type { Admin } from 'kafkajs';
4
- import { ConfigResourceTypes } from 'kafkajs';
5
- import type { Listr, ListrRendererFactory, ListrTaskWrapper } from 'listr2';
6
- import { delay } from 'listr2';
7
-
8
- import type { TopicSchema } from '../../config.schema';
9
-
10
- export class KafkaTopicConfigurator {
11
- static async configure(
12
- topic: Static<typeof TopicSchema>,
13
- admin: Admin,
14
- parentTask: ListrTaskWrapper<unknown, ListrRendererFactory>,
15
- ): Promise<Listr | void> {
16
- const metadata = await admin.fetchTopicMetadata({
17
- topics: [topic.name],
18
- });
19
- const partitions = metadata.topics[0].partitions.length;
20
- if (topic.spec?.partitions && partitions !== topic.spec.partitions) {
21
- throw new Error(
22
- `partitoins for ${topic.name} settled to ${partitions}, but expected ${topic.spec.partitions}`,
23
- );
24
- }
25
- const topicConfig = await admin.describeConfigs({
26
- resources: [
27
- {
28
- type: ConfigResourceTypes.TOPIC,
29
- configNames: ['cleanup.policy'],
30
- name: topic.name,
31
- },
32
- ],
33
- includeSynonyms: true,
34
- });
35
-
36
- const cleanupPolicy = topicConfig.resources.find(
37
- ({ resourceName }) => resourceName === topic.name,
38
- );
39
- if (!cleanupPolicy) {
40
- throw new InternalException('cleanupPolicy not found');
41
- }
42
- const currentValue = cleanupPolicy?.configEntries[0].configValue;
43
- const configValue = topic?.spec?.settings?.['cleanup.policy'];
44
-
45
- if (configValue && currentValue !== configValue) {
46
- parentTask.output = `Alter cleanup.policy from ${currentValue} to ${configValue}`;
47
- await delay(3e3);
48
- await admin.alterConfigs({
49
- validateOnly: false,
50
- resources: [
51
- {
52
- type: ConfigResourceTypes.TOPIC,
53
- configEntries: [
54
- {
55
- value: configValue,
56
- name: 'cleanup.policy',
57
- },
58
- ],
59
- name: topic.name,
60
- },
61
- ],
62
- });
63
- parentTask.output = `Alter cleanup.policy from ${currentValue} to ${configValue} completed!`;
64
- await delay(3e3);
65
- }
66
- parentTask.title = `topic ${topic.name} exists and respond config`;
67
- }
68
- }
@@ -1,3 +0,0 @@
1
- export type Context = {
2
- requireCreate: boolean;
3
- };