@alphavishnu2026/chat-cli 1.0.37

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.
@@ -0,0 +1,3 @@
1
+ import { Kafka } from "kafkajs";
2
+ export declare const createConnection: (broker: string) => Kafka;
3
+ //# sourceMappingURL=kafka.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"kafka.d.ts","sourceRoot":"","sources":["../../src/connection/kafka.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEhC,eAAO,MAAM,gBAAgB,GAAI,QAAQ,MAAM,UAK9C,CAAC"}
@@ -0,0 +1,8 @@
1
+ import { Kafka } from "kafkajs";
2
+ export const createConnection = (broker) => {
3
+ return new Kafka({
4
+ brokers: [broker],
5
+ clientId: "chat-cli",
6
+ });
7
+ };
8
+ //# sourceMappingURL=kafka.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"kafka.js","sourceRoot":"","sources":["../../src/connection/kafka.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEhC,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,MAAc,EAAE,EAAE;IACjD,OAAO,IAAI,KAAK,CAAC;QACf,OAAO,EAAE,CAAC,MAAM,CAAC;QACjB,QAAQ,EAAE,UAAU;KACrB,CAAC,CAAC;AACL,CAAC,CAAC"}
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
package/dist/index.js ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env node
2
+ import { Command } from "commander";
3
+ import { startChat } from "./shell.js";
4
+ const program = new Command();
5
+ program
6
+ .command("join")
7
+ .requiredOption("-b, --broker <broker>")
8
+ .requiredOption("-u, --user <username>")
9
+ .requiredOption("-r, --room <room>")
10
+ .action(async (options) => {
11
+ await startChat(options.broker, options.user, options.room);
12
+ });
13
+ program.parse();
14
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE,CAAC;AAE9B,OAAO;KACJ,OAAO,CAAC,MAAM,CAAC;KACf,cAAc,CAAC,uBAAuB,CAAC;KACvC,cAAc,CAAC,uBAAuB,CAAC;KACvC,cAAc,CAAC,mBAAmB,CAAC;KACnC,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE;IACxB,MAAM,SAAS,CACb,OAAO,CAAC,MAAM,EACd,OAAO,CAAC,IAAI,EACZ,OAAO,CAAC,IAAI,CACb,CAAC;AACJ,CAAC,CAAC,CAAC;AAEL,OAAO,CAAC,KAAK,EAAE,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare function startChat(broker: string, username: string, room: string): Promise<void>;
2
+ //# sourceMappingURL=shell.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shell.d.ts","sourceRoot":"","sources":["../src/shell.ts"],"names":[],"mappings":"AAGA,wBAAsB,SAAS,CAC7B,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,iBAoDb"}
package/dist/shell.js ADDED
@@ -0,0 +1,48 @@
1
+ import readline from "readline";
2
+ import { createConnection } from "./connection/kafka.js";
3
+ export async function startChat(broker, username, room) {
4
+ const kafka = createConnection(broker);
5
+ console.log("Connecting to broker...", broker);
6
+ const producer = kafka.producer();
7
+ const consumer = kafka.consumer({
8
+ groupId: `chat-${room}-${username}`,
9
+ });
10
+ await producer.connect();
11
+ await consumer.connect();
12
+ await consumer.subscribe({ topic: room, fromBeginning: true });
13
+ await consumer.run({
14
+ eachMessage: async ({ message }) => {
15
+ const msg = message.value?.toString();
16
+ if (msg) {
17
+ const parsed = JSON.parse(msg);
18
+ if (parsed.user !== username) {
19
+ console.log(`\n${parsed.user}: ${parsed.text}`);
20
+ }
21
+ if (parsed.user === username) {
22
+ console.log(`\nYou: ${parsed.text}`);
23
+ }
24
+ }
25
+ },
26
+ });
27
+ const rl = readline.createInterface({
28
+ input: process.stdin,
29
+ output: process.stdout,
30
+ });
31
+ rl.on("line", async (line) => {
32
+ rl.prompt();
33
+ await producer.send({
34
+ topic: room,
35
+ messages: [
36
+ {
37
+ value: JSON.stringify({
38
+ user: username,
39
+ text: line,
40
+ timestamp: Date.now(),
41
+ }),
42
+ },
43
+ ],
44
+ });
45
+ });
46
+ console.log(`Joined room: ${room}`);
47
+ }
48
+ //# sourceMappingURL=shell.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shell.js","sourceRoot":"","sources":["../src/shell.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,UAAU,CAAC;AAChC,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEzD,MAAM,CAAC,KAAK,UAAU,SAAS,CAC7B,MAAc,EACd,QAAgB,EAChB,IAAY;IAEZ,MAAM,KAAK,GAAG,gBAAgB,CAAC,MAAM,CAAC,CAAC;IACvC,OAAO,CAAC,GAAG,CAAC,yBAAyB,EAAE,MAAM,CAAC,CAAC;IAC/C,MAAM,QAAQ,GAAG,KAAK,CAAC,QAAQ,EAAE,CAAC;IAClC,MAAM,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC;QAC9B,OAAO,EAAE,QAAQ,IAAI,IAAI,QAAQ,EAAE;KACpC,CAAC,CAAC;IAEH,MAAM,QAAQ,CAAC,OAAO,EAAE,CAAC;IACzB,MAAM,QAAQ,CAAC,OAAO,EAAE,CAAC;IACzB,MAAM,QAAQ,CAAC,SAAS,C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AC,GAAG,CAAC,gBAAgB,IAAI,EAAE,CAAC,CAAC;AACtC,CAAC"}
package/package.json ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ "name": "@alphavishnu2026/chat-cli",
3
+ "version": "1.0.37",
4
+ "description": "",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1",
8
+ "dev": "tsc -b && node dist/shell.js"
9
+ },
10
+ "bin": {
11
+ "kchat": "./dist/index.js"
12
+ },
13
+ "keywords": [],
14
+ "author": "",
15
+ "license": "ISC",
16
+ "type": "module",
17
+ "dependencies": {
18
+ "commander": "^14.0.3",
19
+ "kafkajs": "^2.2.4",
20
+ "readline": "^1.3.0"
21
+ },
22
+ "devDependencies": {
23
+ "@types/node": "^25.2.3"
24
+ }
25
+ }
@@ -0,0 +1,9 @@
1
+ import { Kafka } from "kafkajs";
2
+
3
+ export const createConnection = (broker: string) => {
4
+ return new Kafka({
5
+ brokers: [broker],
6
+ clientId: "chat-cli",
7
+ });
8
+ };
9
+
package/src/index.ts ADDED
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env node
2
+ import { Command } from "commander";
3
+ import { startChat } from "./shell.js";
4
+
5
+ const program = new Command();
6
+
7
+ program
8
+ .command("join")
9
+ .requiredOption("-b, --broker <broker>")
10
+ .requiredOption("-u, --user <username>")
11
+ .requiredOption("-r, --room <room>")
12
+ .action(async (options) => {
13
+ await startChat(
14
+ options.broker,
15
+ options.user,
16
+ options.room
17
+ );
18
+ });
19
+
20
+ program.parse();
package/src/shell.ts ADDED
@@ -0,0 +1,59 @@
1
+ import readline from "readline";
2
+ import { createConnection } from "./connection/kafka.js";
3
+
4
+ export async function startChat(
5
+ broker: string,
6
+ username: string,
7
+ room: string,
8
+ ) {
9
+ const kafka = createConnection(broker);
10
+ console.log("Connecting to broker...", broker);
11
+ const producer = kafka.producer();
12
+ const consumer = kafka.consumer({
13
+ groupId: `chat-${room}-${username}`,
14
+ });
15
+
16
+ await producer.connect();
17
+ await consumer.connect();
18
+ await consumer.subscribe({ topic: room, fromBeginning: true });
19
+
20
+ await consumer.run({
21
+ eachMessage: async ({ message }) => {
22
+ const msg = message.value?.toString();
23
+ if (msg) {
24
+ const parsed = JSON.parse(msg);
25
+
26
+ if (parsed.user !== username) {
27
+ console.log(`\n${parsed.user}: ${parsed.text}`);
28
+ }
29
+
30
+ if (parsed.user === username) {
31
+ console.log(`\nYou: ${parsed.text}`);
32
+ }
33
+ }
34
+ },
35
+ });
36
+
37
+ const rl = readline.createInterface({
38
+ input: process.stdin,
39
+ output: process.stdout,
40
+ });
41
+
42
+ rl.on("line", async (line) => {
43
+ rl.prompt();
44
+ await producer.send({
45
+ topic: room,
46
+ messages: [
47
+ {
48
+ value: JSON.stringify({
49
+ user: username,
50
+ text: line,
51
+ timestamp: Date.now(),
52
+ }),
53
+ },
54
+ ],
55
+ });
56
+ });
57
+
58
+ console.log(`Joined room: ${room}`);
59
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ // Visit https://aka.ms/tsconfig to read more about this file
3
+ "compilerOptions": {
4
+ // File Layout
5
+ "rootDir": "./src",
6
+ "outDir": "./dist",
7
+
8
+ // Environment Settings
9
+ // See also https://aka.ms/tsconfig/module
10
+ "module": "nodenext",
11
+ "target": "esnext",
12
+ "types": [],
13
+ // For nodejs:
14
+ // "lib": ["esnext"],
15
+ // "types": ["node"],
16
+ // and npm install -D @types/node
17
+
18
+ // Other Outputs
19
+ "sourceMap": true,
20
+ "declaration": true,
21
+ "declarationMap": true,
22
+
23
+ // Stricter Typechecking Options
24
+ "noUncheckedIndexedAccess": true,
25
+ "exactOptionalPropertyTypes": true,
26
+
27
+ // Style Options
28
+ // "noImplicitReturns": true,
29
+ // "noImplicitOverride": true,
30
+ // "noUnusedLocals": true,
31
+ // "noUnusedParameters": true,
32
+ // "noFallthroughCasesInSwitch": true,
33
+ // "noPropertyAccessFromIndexSignature": true,
34
+
35
+ // Recommended Options
36
+ "strict": true,
37
+ "jsx": "react-jsx",
38
+ "verbatimModuleSyntax": true,
39
+ "isolatedModules": true,
40
+ "noUncheckedSideEffectImports": true,
41
+ "moduleDetection": "force",
42
+ "skipLibCheck": true,
43
+ }
44
+ }
@@ -0,0 +1 @@
1
+ {"root":["./src/index.ts","./src/shell.ts","./src/connection/kafka.ts"],"version":"5.9.3"}