@drod915/q9s 0.0.0-stage → 0.1.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.
- package/LICENSE +21 -0
- package/README.md +192 -3
- package/dist/cli.js +3089 -0
- package/dist/index.d.ts +294 -0
- package/dist/index.js +3137 -0
- package/package.json +62 -6
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
type QueueBackendKind = "bullmq" | "river" | "pg-boss";
|
|
2
|
+
type JobState = "waiting" | "active" | "delayed" | "completed" | "failed";
|
|
3
|
+
interface QueueStats {
|
|
4
|
+
name: string;
|
|
5
|
+
backend: QueueBackendKind;
|
|
6
|
+
waiting: number;
|
|
7
|
+
active: number;
|
|
8
|
+
delayed: number;
|
|
9
|
+
completed: number;
|
|
10
|
+
failed: number;
|
|
11
|
+
paused?: boolean;
|
|
12
|
+
throughputHistory?: number[];
|
|
13
|
+
}
|
|
14
|
+
interface JobRecord {
|
|
15
|
+
id: string;
|
|
16
|
+
queue: string;
|
|
17
|
+
name: string;
|
|
18
|
+
state: JobState;
|
|
19
|
+
data: unknown;
|
|
20
|
+
failedReason?: string;
|
|
21
|
+
stacktrace?: string[];
|
|
22
|
+
attemptsMade: number;
|
|
23
|
+
maxAttempts?: number;
|
|
24
|
+
timestamp?: number;
|
|
25
|
+
processedOn?: number;
|
|
26
|
+
finishedOn?: number;
|
|
27
|
+
delay?: number;
|
|
28
|
+
}
|
|
29
|
+
interface ContextEntry {
|
|
30
|
+
name: string;
|
|
31
|
+
url: string;
|
|
32
|
+
backend?: QueueBackendKind;
|
|
33
|
+
readOnly?: boolean;
|
|
34
|
+
prefix?: string;
|
|
35
|
+
schema?: string;
|
|
36
|
+
}
|
|
37
|
+
interface RetryResult {
|
|
38
|
+
queue: string;
|
|
39
|
+
retried: number;
|
|
40
|
+
jobIds: string[];
|
|
41
|
+
}
|
|
42
|
+
interface BackendOptions {
|
|
43
|
+
readOnly: boolean;
|
|
44
|
+
timeoutMs?: number;
|
|
45
|
+
prefix?: string;
|
|
46
|
+
schema?: string;
|
|
47
|
+
}
|
|
48
|
+
interface QueueBackend {
|
|
49
|
+
readonly kind: QueueBackendKind;
|
|
50
|
+
readonly readOnly: boolean;
|
|
51
|
+
listQueues(): Promise<QueueStats[]>;
|
|
52
|
+
listJobs(queue: string, state: JobState, limit?: number): Promise<JobRecord[]>;
|
|
53
|
+
getJob(queue: string, jobId: string): Promise<JobRecord | null>;
|
|
54
|
+
retryJob(queue: string, jobId: string): Promise<RetryResult>;
|
|
55
|
+
retryFailedBulk(queue: string, limit?: number): Promise<RetryResult>;
|
|
56
|
+
close(): Promise<void>;
|
|
57
|
+
}
|
|
58
|
+
interface DashboardSnapshot {
|
|
59
|
+
version: string;
|
|
60
|
+
target: string;
|
|
61
|
+
contextName?: string;
|
|
62
|
+
backend: QueueBackendKind;
|
|
63
|
+
readOnly: boolean;
|
|
64
|
+
capturedAt: string;
|
|
65
|
+
queues: QueueStats[];
|
|
66
|
+
inspectedQueue?: string;
|
|
67
|
+
inspectedState?: JobState;
|
|
68
|
+
inspectedJobs: JobRecord[];
|
|
69
|
+
}
|
|
70
|
+
declare class ReadOnlyError extends Error {
|
|
71
|
+
readonly code = "Q9S_READ_ONLY";
|
|
72
|
+
constructor(action: string);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
type RespValue = string | number | null | RespError | RespValue[];
|
|
76
|
+
declare class RespError extends Error {
|
|
77
|
+
readonly code = "RESP_SERVER_ERROR";
|
|
78
|
+
constructor(message: string);
|
|
79
|
+
}
|
|
80
|
+
declare class RespProtocolError extends Error {
|
|
81
|
+
readonly code = "RESP_PROTOCOL_ERROR";
|
|
82
|
+
constructor(message: string);
|
|
83
|
+
}
|
|
84
|
+
declare class RespTimeoutError extends Error {
|
|
85
|
+
readonly code = "RESP_TIMEOUT";
|
|
86
|
+
constructor(message: string);
|
|
87
|
+
}
|
|
88
|
+
interface ParsedRedisUrl {
|
|
89
|
+
host: string;
|
|
90
|
+
port: number;
|
|
91
|
+
username?: string;
|
|
92
|
+
password?: string;
|
|
93
|
+
db: number;
|
|
94
|
+
tls: boolean;
|
|
95
|
+
servername?: string;
|
|
96
|
+
}
|
|
97
|
+
interface RespConnectOptions {
|
|
98
|
+
timeoutMs?: number;
|
|
99
|
+
rejectUnauthorized?: boolean;
|
|
100
|
+
}
|
|
101
|
+
declare function parseRedisUrl(rawUrl: string): ParsedRedisUrl;
|
|
102
|
+
declare function encodeRespCommand(args: ReadonlyArray<string | number | Buffer>): Buffer;
|
|
103
|
+
interface ParsedFrame {
|
|
104
|
+
value: RespValue | RespError;
|
|
105
|
+
nextOffset: number;
|
|
106
|
+
}
|
|
107
|
+
declare function parseRespFrame(buf: Buffer, offset?: number, depth?: number): ParsedFrame | null;
|
|
108
|
+
declare class RespParser {
|
|
109
|
+
private buffer;
|
|
110
|
+
push(chunk: Buffer): Array<RespValue | RespError>;
|
|
111
|
+
get bufferedBytes(): number;
|
|
112
|
+
}
|
|
113
|
+
declare class RespClient {
|
|
114
|
+
private readonly socket;
|
|
115
|
+
private readonly parser;
|
|
116
|
+
private readonly pending;
|
|
117
|
+
private readonly timeoutMs;
|
|
118
|
+
private closed;
|
|
119
|
+
private constructor();
|
|
120
|
+
static connect(target: string | ParsedRedisUrl, options?: RespConnectOptions): Promise<RespClient>;
|
|
121
|
+
command(...args: Array<string | number | Buffer>): Promise<RespValue>;
|
|
122
|
+
ping(): Promise<string>;
|
|
123
|
+
scan(cursor: string, pattern?: string, count?: number): Promise<{
|
|
124
|
+
cursor: string;
|
|
125
|
+
keys: string[];
|
|
126
|
+
}>;
|
|
127
|
+
scanAll(pattern: string, count?: number): Promise<string[]>;
|
|
128
|
+
llen(key: string): Promise<number>;
|
|
129
|
+
zcard(key: string): Promise<number>;
|
|
130
|
+
lrange(key: string, start: number, stop: number): Promise<string[]>;
|
|
131
|
+
zrange(key: string, start: number, stop: number): Promise<string[]>;
|
|
132
|
+
zrevrange(key: string, start: number, stop: number): Promise<string[]>;
|
|
133
|
+
hget(key: string, field: string): Promise<string | null>;
|
|
134
|
+
hgetall(key: string): Promise<Record<string, string>>;
|
|
135
|
+
close(): Promise<void>;
|
|
136
|
+
private failAllPending;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
interface BullMqBackendOptions extends BackendOptions {
|
|
140
|
+
client?: RespClient;
|
|
141
|
+
rejectUnauthorized?: boolean;
|
|
142
|
+
}
|
|
143
|
+
declare function extractQueueNameFromKey(key: string, prefix: string, suffix: string): string | null;
|
|
144
|
+
declare function parseBullMqJobHash(queue: string, jobId: string, state: JobState, hash: Record<string, string>): JobRecord;
|
|
145
|
+
declare class BullMqBackend implements QueueBackend {
|
|
146
|
+
readonly kind: "bullmq";
|
|
147
|
+
readonly readOnly: boolean;
|
|
148
|
+
private readonly client;
|
|
149
|
+
private readonly ownsClient;
|
|
150
|
+
private readonly prefix;
|
|
151
|
+
private constructor();
|
|
152
|
+
static connect(url: string, options: BullMqBackendOptions): Promise<BullMqBackend>;
|
|
153
|
+
static fromClient(client: RespClient, options: BullMqBackendOptions): BullMqBackend;
|
|
154
|
+
private key;
|
|
155
|
+
discoverQueues(): Promise<string[]>;
|
|
156
|
+
listQueues(): Promise<QueueStats[]>;
|
|
157
|
+
listJobs(queue: string, state: JobState, limit?: number): Promise<JobRecord[]>;
|
|
158
|
+
getJob(queue: string, jobId: string): Promise<JobRecord | null>;
|
|
159
|
+
retryJob(queue: string, jobId: string): Promise<RetryResult>;
|
|
160
|
+
retryFailedBulk(queue: string, limit?: number): Promise<RetryResult>;
|
|
161
|
+
close(): Promise<void>;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
type PostgresQueueKind = "river" | "pg-boss";
|
|
165
|
+
declare const PSQL_FIELD_SEPARATOR = "\u001F";
|
|
166
|
+
interface ParsedPostgresUrl {
|
|
167
|
+
sanitizedUrl: string;
|
|
168
|
+
host: string;
|
|
169
|
+
port: number;
|
|
170
|
+
database: string;
|
|
171
|
+
username?: string;
|
|
172
|
+
password?: string;
|
|
173
|
+
}
|
|
174
|
+
type SqlRunner = (sql: string, readOnly: boolean) => string;
|
|
175
|
+
interface PostgresBackendOptions extends BackendOptions {
|
|
176
|
+
kind?: PostgresQueueKind;
|
|
177
|
+
psqlPath?: string;
|
|
178
|
+
sqlRunner?: SqlRunner;
|
|
179
|
+
}
|
|
180
|
+
declare function parsePostgresUrl(rawUrl: string): ParsedPostgresUrl;
|
|
181
|
+
declare function validateIdentifier(identifier: string, label?: string): string;
|
|
182
|
+
declare function validateQueueName(queue: string): string;
|
|
183
|
+
declare function validateJobId(jobId: string, kind: PostgresQueueKind): string;
|
|
184
|
+
declare function buildDetectPostgresBackendSql(schema?: string): string;
|
|
185
|
+
declare function parseBackendDetection(output: string): {
|
|
186
|
+
kind: PostgresQueueKind;
|
|
187
|
+
schema: string;
|
|
188
|
+
};
|
|
189
|
+
declare function buildRiverQueueStatsSql(schema?: string): string;
|
|
190
|
+
declare function parseRiverQueueStats(output: string): QueueStats[];
|
|
191
|
+
declare function buildRiverJobsSql(schema: string, queue: string, state: JobState, limit?: number): string;
|
|
192
|
+
declare function buildRiverGetJobSql(schema: string, queue: string, jobId: string): string;
|
|
193
|
+
declare function parseRiverJobs(output: string, queue: string): JobRecord[];
|
|
194
|
+
declare function buildRiverRetryJobSql(schema: string, queue: string, jobId: string): string;
|
|
195
|
+
declare function buildRiverRetryFailedBulkSql(schema: string, queue: string, limit?: number): string;
|
|
196
|
+
declare function buildPgBossQueueStatsSql(schema?: string): string;
|
|
197
|
+
declare function parsePgBossQueueStats(output: string): QueueStats[];
|
|
198
|
+
declare function buildPgBossJobsSql(schema: string, queue: string, state: JobState, limit?: number): string;
|
|
199
|
+
declare function buildPgBossGetJobSql(schema: string, queue: string, jobId: string): string;
|
|
200
|
+
declare function parsePgBossJobs(output: string, queue: string): JobRecord[];
|
|
201
|
+
declare function buildPgBossRetryJobSql(schema: string, queue: string, jobId: string): string;
|
|
202
|
+
declare function buildPgBossRetryFailedBulkSql(schema: string, queue: string, limit?: number): string;
|
|
203
|
+
declare function parseReturnedJobIds(output: string): string[];
|
|
204
|
+
declare class PostgresQueueBackend implements QueueBackend {
|
|
205
|
+
readonly kind: PostgresQueueKind;
|
|
206
|
+
readonly readOnly: boolean;
|
|
207
|
+
private readonly schema;
|
|
208
|
+
private readonly runner;
|
|
209
|
+
private constructor();
|
|
210
|
+
static connect(url: string, options: PostgresBackendOptions): PostgresQueueBackend;
|
|
211
|
+
listQueues(): Promise<QueueStats[]>;
|
|
212
|
+
listJobs(queue: string, state: JobState, limit?: number): Promise<JobRecord[]>;
|
|
213
|
+
getJob(queue: string, jobId: string): Promise<JobRecord | null>;
|
|
214
|
+
retryJob(queue: string, jobId: string): Promise<RetryResult>;
|
|
215
|
+
retryFailedBulk(queue: string, limit?: number): Promise<RetryResult>;
|
|
216
|
+
close(): Promise<void>;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
declare function redactUrl(rawUrl: string): string;
|
|
220
|
+
declare function redactContext(ctx: ContextEntry): ContextEntry;
|
|
221
|
+
declare function parseSimpleYamlContexts(content: string): ContextEntry[];
|
|
222
|
+
declare function parseJsonContexts(content: string): ContextEntry[];
|
|
223
|
+
declare function getDefaultConfigPaths(): string[];
|
|
224
|
+
declare function findConfigFile(explicitPath?: string): string | null;
|
|
225
|
+
declare function loadContexts(explicitPath?: string): ContextEntry[];
|
|
226
|
+
declare function resolveContext(name: string, explicitPath?: string): ContextEntry;
|
|
227
|
+
|
|
228
|
+
interface RenderOptions {
|
|
229
|
+
color?: boolean;
|
|
230
|
+
maxStackLines?: number;
|
|
231
|
+
}
|
|
232
|
+
declare function sanitizeTerminalText(raw: string): string;
|
|
233
|
+
declare function renderSparkline(values?: ReadonlyArray<number>): string;
|
|
234
|
+
declare function renderSafetyBadge(readOnly: boolean, color?: boolean): string;
|
|
235
|
+
declare function renderQueueTable(queues: ReadonlyArray<QueueStats>, options?: RenderOptions): string;
|
|
236
|
+
declare function renderJobInspector(jobs: ReadonlyArray<JobRecord>, queueName: string, state: JobState, totalInState?: number, options?: RenderOptions): string;
|
|
237
|
+
declare function renderDashboard(snapshot: DashboardSnapshot, options?: RenderOptions): string;
|
|
238
|
+
declare function renderJson(payload: unknown): string;
|
|
239
|
+
|
|
240
|
+
interface DemoServerHandle {
|
|
241
|
+
host: string;
|
|
242
|
+
port: number;
|
|
243
|
+
url: string;
|
|
244
|
+
close(): Promise<void>;
|
|
245
|
+
}
|
|
246
|
+
interface MockRedisOptions {
|
|
247
|
+
password?: string;
|
|
248
|
+
seedBullMqDemo?: boolean;
|
|
249
|
+
prefix?: string;
|
|
250
|
+
}
|
|
251
|
+
interface RedisStore {
|
|
252
|
+
hashes: Map<string, Map<string, string>>;
|
|
253
|
+
lists: Map<string, string[]>;
|
|
254
|
+
zsets: Map<string, Map<string, number>>;
|
|
255
|
+
strings: Map<string, string>;
|
|
256
|
+
}
|
|
257
|
+
declare function seedBullMqDemoData(store: RedisStore, prefix?: string): void;
|
|
258
|
+
declare function startMockRedisServer(options?: MockRedisOptions): Promise<DemoServerHandle>;
|
|
259
|
+
|
|
260
|
+
declare const Q9S_VERSION = "0.1.0";
|
|
261
|
+
interface ParsedCliArgs {
|
|
262
|
+
url?: string;
|
|
263
|
+
ctx?: string;
|
|
264
|
+
config?: string;
|
|
265
|
+
listContexts: boolean;
|
|
266
|
+
demo: boolean;
|
|
267
|
+
backend?: QueueBackendKind;
|
|
268
|
+
prefix?: string;
|
|
269
|
+
schema?: string;
|
|
270
|
+
inspect?: string;
|
|
271
|
+
queue?: string;
|
|
272
|
+
state: JobState;
|
|
273
|
+
limit?: number;
|
|
274
|
+
readOnlyFlag: boolean;
|
|
275
|
+
allowWrite: boolean;
|
|
276
|
+
retryJobId?: string;
|
|
277
|
+
retryFailedQueue?: string;
|
|
278
|
+
yes: boolean;
|
|
279
|
+
json: boolean;
|
|
280
|
+
noColor: boolean;
|
|
281
|
+
timeoutMs: number;
|
|
282
|
+
help: boolean;
|
|
283
|
+
version: boolean;
|
|
284
|
+
}
|
|
285
|
+
interface CliIo {
|
|
286
|
+
stdout: (line: string) => void;
|
|
287
|
+
stderr: (line: string) => void;
|
|
288
|
+
isTty?: boolean;
|
|
289
|
+
}
|
|
290
|
+
declare function formatHelpText(): string;
|
|
291
|
+
declare function parseCliArgs(rawArgv: ReadonlyArray<string>): ParsedCliArgs;
|
|
292
|
+
declare function runCli(argv: ReadonlyArray<string>, io?: CliIo): Promise<number>;
|
|
293
|
+
|
|
294
|
+
export { type BackendOptions, BullMqBackend, type BullMqBackendOptions, type ContextEntry, type DashboardSnapshot, type DemoServerHandle, type JobRecord, type JobState, type MockRedisOptions, PSQL_FIELD_SEPARATOR, type ParsedFrame, type ParsedPostgresUrl, type ParsedRedisUrl, type PostgresBackendOptions, PostgresQueueBackend, type PostgresQueueKind, Q9S_VERSION, type QueueBackend, type QueueBackendKind, type QueueStats, ReadOnlyError, type RenderOptions, RespClient, type RespConnectOptions, RespError, RespParser, RespProtocolError, RespTimeoutError, type RespValue, type RetryResult, type SqlRunner, buildDetectPostgresBackendSql, buildPgBossGetJobSql, buildPgBossJobsSql, buildPgBossQueueStatsSql, buildPgBossRetryFailedBulkSql, buildPgBossRetryJobSql, buildRiverGetJobSql, buildRiverJobsSql, buildRiverQueueStatsSql, buildRiverRetryFailedBulkSql, buildRiverRetryJobSql, encodeRespCommand, extractQueueNameFromKey, findConfigFile, formatHelpText, getDefaultConfigPaths, loadContexts, parseBackendDetection, parseBullMqJobHash, parseCliArgs, parseJsonContexts, parsePgBossJobs, parsePgBossQueueStats, parsePostgresUrl, parseRedisUrl, parseRespFrame, parseReturnedJobIds, parseRiverJobs, parseRiverQueueStats, parseSimpleYamlContexts, redactContext, redactUrl, renderDashboard, renderJobInspector, renderJson, renderQueueTable, renderSafetyBadge, renderSparkline, resolveContext, runCli, sanitizeTerminalText, seedBullMqDemoData, startMockRedisServer, validateIdentifier, validateJobId, validateQueueName };
|