@rsdk/cli 4.2.5-next.0 → 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 +6 -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,35 +0,0 @@
1
- import type { Static } from '@sinclair/typebox';
2
- import type { Admin } from 'kafkajs';
3
- import type { ListrRendererFactory, ListrTaskWrapper } from 'listr2';
4
- import { delay } from 'listr2';
5
-
6
- import type { TopicSchema } from '../../config.schema';
7
-
8
- export async function createTopic(
9
- topic: Static<typeof TopicSchema>,
10
- admin: Admin,
11
- parentTask: ListrTaskWrapper<unknown, ListrRendererFactory>,
12
- ): Promise<void> {
13
- await delay(1000);
14
- const numPartitions = topic.spec?.partitions ?? 2;
15
-
16
- const replicationFactor = topic.spec?.replicationFactor;
17
-
18
- const result = await admin.createTopics({
19
- topics: [
20
- {
21
- topic: topic.name,
22
- ...(replicationFactor && {
23
- replicationFactor: replicationFactor,
24
- }),
25
- numPartitions: numPartitions,
26
- },
27
- ],
28
- });
29
- if (result) {
30
- console.log('create topic %s complete!', topic.name);
31
- parentTask.title = `create topic ${topic.name} complete!`;
32
- return;
33
- }
34
- throw new Error(`create topic ${topic.name} failed!`);
35
- }
@@ -1,25 +0,0 @@
1
- import { InputException } from '@rsdk/core';
2
- import type { Static } from '@sinclair/typebox';
3
- import { readFile } from 'node:fs/promises';
4
- import { resolve } from 'node:path';
5
- import yaml from 'yaml';
6
-
7
- import type { CliKafkaConfigSchema } from '../../config.schema';
8
- import { CliKafkaConfigSchemaChecker } from '../../config.schema';
9
-
10
- export class KafkaExpectedConfigProvider {
11
- static async getConfig(): Promise<Static<typeof CliKafkaConfigSchema>> {
12
- const kafkaYml = await readFile(resolve('kafka.yml'), {
13
- encoding: 'utf8',
14
- });
15
- const config: Static<typeof CliKafkaConfigSchema> = yaml.parse(kafkaYml);
16
-
17
- const isValid = CliKafkaConfigSchemaChecker.Check(config);
18
- if (!isValid) {
19
- throw new InputException('Invalid config', {
20
- cause: [...CliKafkaConfigSchemaChecker.Errors(config)],
21
- });
22
- }
23
- return config;
24
- }
25
- }
@@ -1,16 +0,0 @@
1
- import { InternalException } from '@rsdk/core';
2
- import dotenv from 'dotenv';
3
- import type { KafkaConfig } from 'kafkajs';
4
-
5
- export class KafkaCredsProvider {
6
- static getKafkaCreds(): KafkaConfig {
7
- dotenv.config();
8
- const kafkaHost = process.env.KAFKA_HOST;
9
- if (!kafkaHost) {
10
- throw new InternalException('KAFKA_HOST not found');
11
- }
12
- return {
13
- brokers: [kafkaHost],
14
- };
15
- }
16
- }
@@ -1,66 +0,0 @@
1
- import { Command } from 'commander';
2
- import type { Admin, KafkaConfig } from 'kafkajs';
3
- import { Kafka } from 'kafkajs';
4
- import { Listr } from 'listr2';
5
-
6
- import { KafkaConfigExtractor } from '../extract/kafka-config.extractor';
7
-
8
- import { KafkaTopicConfigurator } from './check-exist';
9
- import type { Context } from './context';
10
- import { createTopic } from './create-topic.task';
11
- import { KafkaExpectedConfigProvider } from './get-config';
12
- import { KafkaCredsProvider } from './kafka.creds-provider';
13
-
14
- async function createAdmin(kafkaCreds: KafkaConfig): Promise<Admin> {
15
- const kafka = new Kafka(kafkaCreds);
16
- const admin = kafka.admin();
17
-
18
- await admin.connect();
19
- return admin;
20
- }
21
-
22
- export const KafkaSyncCommand = new Command('sync')
23
- .description('try sync kafka state from kafka.yml file')
24
- .option('--from-rsdk', 'run command based on rsdk.json, instead of kafka.yml')
25
- .action(async function (_, command: Command) {
26
- const options = command.opts();
27
- const config = options.fromRsdk
28
- ? await KafkaConfigExtractor.extract()
29
- : await KafkaExpectedConfigProvider.getConfig();
30
-
31
- const kafkaCreds = KafkaCredsProvider.getKafkaCreds();
32
- const admin = await createAdmin(kafkaCreds);
33
-
34
- const existedTopic = await admin.listTopics();
35
-
36
- await new Listr<Context>(
37
- config.topics.map((topic) => ({
38
- title: topic.name,
39
- task: async (_ctx, parentTask): Promise<boolean | Listr> => {
40
- const requireCreate = !existedTopic.includes(topic.name);
41
-
42
- return parentTask.newListr(
43
- [
44
- {
45
- title: requireCreate ? 'create' : 'configure',
46
- task: async (): Promise<void | Listr> => {
47
- if (requireCreate) {
48
- await createTopic(topic, admin, parentTask);
49
- return;
50
- }
51
- await KafkaTopicConfigurator.configure(
52
- topic,
53
- admin,
54
- parentTask,
55
- );
56
- },
57
- },
58
- ],
59
- { concurrent: false },
60
- );
61
- },
62
- })),
63
- { concurrent: true },
64
- ).run({ requireCreate: true });
65
- await admin.disconnect();
66
- });
@@ -1,31 +0,0 @@
1
- import { Type } from '@sinclair/typebox';
2
- import { TypeCompiler } from '@sinclair/typebox/compiler';
3
-
4
- import { StringEnum } from './schemas/string-enum';
5
-
6
- const specSchema = Type.Optional(
7
- Type.Partial(
8
- Type.Object({
9
- partitions: Type.Integer({
10
- default: 2,
11
- }),
12
- replicationFactor: Type.Integer({
13
- default: 1,
14
- }),
15
- settings: Type.Object({
16
- 'cleanup.policy': StringEnum(['delete', 'compact']),
17
- }),
18
- }),
19
- ),
20
- );
21
-
22
- export const TopicSchema = Type.Object({
23
- name: Type.String(),
24
- spec: Type.Optional(specSchema),
25
- });
26
-
27
- export const CliKafkaConfigSchema = Type.Object({
28
- topics: Type.Array(TopicSchema),
29
- });
30
- export const CliKafkaConfigSchemaChecker =
31
- TypeCompiler.Compile(CliKafkaConfigSchema);
@@ -1,15 +0,0 @@
1
- import type { TUnsafe } from '@sinclair/typebox';
2
- import { Kind, Type, TypeRegistry } from '@sinclair/typebox';
3
-
4
- TypeRegistry.Set('StringEnum', (schema: any, value: any) => {
5
- return schema.enum.includes(value);
6
- });
7
-
8
- export const StringEnum = <T extends string[]>(
9
- values: [...T],
10
- ): TUnsafe<T[number]> =>
11
- Type.Unsafe<T[number]>({
12
- [Kind]: 'StringEnum',
13
- type: 'string',
14
- enum: values,
15
- });