@mulingai-npm/redis 3.0.0 → 3.0.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.
package/README.md
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { MulingstreamChunkManager, MulingstreamChunkData } from '../managers/mulingstream-chunk-manager';
|
|
2
|
+
export interface ChunkLogOptions {
|
|
3
|
+
chunkNumber?: boolean;
|
|
4
|
+
roomId?: boolean;
|
|
5
|
+
language?: boolean;
|
|
6
|
+
finalTranscription?: boolean;
|
|
7
|
+
sttStatus?: boolean;
|
|
8
|
+
translation?: boolean;
|
|
9
|
+
tts?: boolean;
|
|
10
|
+
retryMs?: number;
|
|
11
|
+
label?: string;
|
|
12
|
+
}
|
|
13
|
+
export declare class MulingstreamChunkLogger extends MulingstreamChunkManager {
|
|
14
|
+
logChunk(roomId: string, chunkNumber: number, opts?: ChunkLogOptions): Promise<void>;
|
|
15
|
+
logChunks(roomId: string, opts?: ChunkLogOptions): Promise<Record<string, unknown>[]>;
|
|
16
|
+
mapChunk(chunk: MulingstreamChunkData, cfg?: ChunkLogOptions): Record<string, unknown>;
|
|
17
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MulingstreamChunkLogger = void 0;
|
|
4
|
+
const mulingstream_chunk_manager_1 = require("../managers/mulingstream-chunk-manager");
|
|
5
|
+
const defaults = {
|
|
6
|
+
chunkNumber: true,
|
|
7
|
+
roomId: true,
|
|
8
|
+
language: true,
|
|
9
|
+
finalTranscription: true,
|
|
10
|
+
sttStatus: true,
|
|
11
|
+
translation: false,
|
|
12
|
+
tts: false,
|
|
13
|
+
retryMs: 100,
|
|
14
|
+
label: ''
|
|
15
|
+
};
|
|
16
|
+
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
17
|
+
class MulingstreamChunkLogger extends mulingstream_chunk_manager_1.MulingstreamChunkManager {
|
|
18
|
+
/* ------------ one chunk ------------------------------------ */
|
|
19
|
+
/* ------------ one chunk ------------------------------------ */
|
|
20
|
+
async logChunk(roomId, chunkNumber, opts = {}) {
|
|
21
|
+
const cfg = { ...defaults, ...opts };
|
|
22
|
+
const prefix = cfg.label ? `[${cfg.label}] ` : '';
|
|
23
|
+
let chunk = await this.getMulingstreamChunkById(roomId, chunkNumber);
|
|
24
|
+
if (!chunk) {
|
|
25
|
+
await sleep(cfg.retryMs);
|
|
26
|
+
chunk = await this.getMulingstreamChunkById(roomId, chunkNumber);
|
|
27
|
+
}
|
|
28
|
+
if (!chunk) {
|
|
29
|
+
console.log(`${prefix}[logger] room ${roomId} chunk ${chunkNumber} not found`);
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
if (cfg.label)
|
|
33
|
+
console.log(prefix.trim()); // single-line label
|
|
34
|
+
console.dir(this.mapChunk(chunk, cfg), { depth: null, colors: true });
|
|
35
|
+
}
|
|
36
|
+
/* ------------ all chunks in room ---------------------------- */
|
|
37
|
+
async logChunks(roomId, opts = {}) {
|
|
38
|
+
const cfg = { ...defaults, ...opts };
|
|
39
|
+
const prefix = cfg.label ? `[${cfg.label}] ` : '';
|
|
40
|
+
let chunks = await this.getRoomById(roomId);
|
|
41
|
+
if (!(chunks === null || chunks === void 0 ? void 0 : chunks.length)) {
|
|
42
|
+
await sleep(cfg.retryMs);
|
|
43
|
+
chunks = await this.getRoomById(roomId);
|
|
44
|
+
}
|
|
45
|
+
if (!(chunks === null || chunks === void 0 ? void 0 : chunks.length)) {
|
|
46
|
+
console.log(`${prefix}[logger] room ${roomId} is empty / not found`);
|
|
47
|
+
return [];
|
|
48
|
+
}
|
|
49
|
+
const view = chunks.map((c) => this.mapChunk(c, cfg));
|
|
50
|
+
if (cfg.label)
|
|
51
|
+
console.log(prefix.trim());
|
|
52
|
+
console.dir(view, { depth: null, colors: true });
|
|
53
|
+
return view;
|
|
54
|
+
}
|
|
55
|
+
/* ------------ filter helper -------------------------------- */
|
|
56
|
+
mapChunk(chunk, cfg = {}) {
|
|
57
|
+
const o = { ...defaults, ...cfg };
|
|
58
|
+
const out = {};
|
|
59
|
+
if (o.roomId)
|
|
60
|
+
out.roomId = chunk.roomId;
|
|
61
|
+
if (o.chunkNumber)
|
|
62
|
+
out.chunkNumber = chunk.chunkNumber;
|
|
63
|
+
if (o.language)
|
|
64
|
+
out.language = chunk.language;
|
|
65
|
+
if (o.finalTranscription)
|
|
66
|
+
out.finalTranscription = chunk.finalTranscription;
|
|
67
|
+
if (o.sttStatus)
|
|
68
|
+
out.sttStatus = chunk.sttStatus;
|
|
69
|
+
if (o.translation)
|
|
70
|
+
out.translation = chunk.translation;
|
|
71
|
+
if (o.tts)
|
|
72
|
+
out.tts = chunk.tts;
|
|
73
|
+
return out;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
exports.MulingstreamChunkLogger = MulingstreamChunkLogger;
|
package/dist/redis-client.d.ts
CHANGED
|
@@ -25,5 +25,4 @@ export declare class RedisClient {
|
|
|
25
25
|
jsonArrAppend<T>(key: string, path: string, ...values: T[]): Promise<number>;
|
|
26
26
|
jsonArrLen(key: string, path: string): Promise<number | null>;
|
|
27
27
|
jsonArrPop(key: string, path: string, index?: number): Promise<any>;
|
|
28
|
-
xadd(key: string, id: string, ...fieldValues: (string | number)[]): Promise<string>;
|
|
29
28
|
}
|
package/dist/redis-client.js
CHANGED
|
@@ -92,10 +92,5 @@ class RedisClient {
|
|
|
92
92
|
}
|
|
93
93
|
return this.client.call('JSON.ARRPOP', key, path);
|
|
94
94
|
}
|
|
95
|
-
async xadd(key, id, ...fieldValues) {
|
|
96
|
-
// IORedis already supports XADD natively
|
|
97
|
-
// key id ('*' for autogenerated) field1 value1 field2 value2 ...
|
|
98
|
-
return this.client.xadd(key, id, ...fieldValues);
|
|
99
|
-
}
|
|
100
95
|
}
|
|
101
96
|
exports.RedisClient = RedisClient;
|