@qwickapps/qwickbrain-proxy 1.0.1 → 1.0.3

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 (67) hide show
  1. package/.claude/engineering/bugs/BUG-qwickbrain-proxy-cache-and-design.md +840 -0
  2. package/.github/workflows/publish.yml +13 -0
  3. package/CHANGELOG.md +54 -0
  4. package/dist/db/schema.d.ts +63 -6
  5. package/dist/db/schema.d.ts.map +1 -1
  6. package/dist/db/schema.js +17 -2
  7. package/dist/db/schema.js.map +1 -1
  8. package/dist/lib/__tests__/cache-manager.test.js +146 -83
  9. package/dist/lib/__tests__/cache-manager.test.js.map +1 -1
  10. package/dist/lib/__tests__/proxy-server.test.js +16 -44
  11. package/dist/lib/__tests__/proxy-server.test.js.map +1 -1
  12. package/dist/lib/__tests__/sse-invalidation-listener.test.d.ts +2 -0
  13. package/dist/lib/__tests__/sse-invalidation-listener.test.d.ts.map +1 -0
  14. package/dist/lib/__tests__/sse-invalidation-listener.test.js +245 -0
  15. package/dist/lib/__tests__/sse-invalidation-listener.test.js.map +1 -0
  16. package/dist/lib/__tests__/write-queue-manager.test.d.ts +2 -0
  17. package/dist/lib/__tests__/write-queue-manager.test.d.ts.map +1 -0
  18. package/dist/lib/__tests__/write-queue-manager.test.js +291 -0
  19. package/dist/lib/__tests__/write-queue-manager.test.js.map +1 -0
  20. package/dist/lib/cache-manager.d.ts +35 -6
  21. package/dist/lib/cache-manager.d.ts.map +1 -1
  22. package/dist/lib/cache-manager.js +154 -41
  23. package/dist/lib/cache-manager.js.map +1 -1
  24. package/dist/lib/connection-manager.d.ts.map +1 -1
  25. package/dist/lib/connection-manager.js +4 -1
  26. package/dist/lib/connection-manager.js.map +1 -1
  27. package/dist/lib/proxy-server.d.ts +6 -0
  28. package/dist/lib/proxy-server.d.ts.map +1 -1
  29. package/dist/lib/proxy-server.js +182 -87
  30. package/dist/lib/proxy-server.js.map +1 -1
  31. package/dist/lib/qwickbrain-client.d.ts +4 -0
  32. package/dist/lib/qwickbrain-client.d.ts.map +1 -1
  33. package/dist/lib/qwickbrain-client.js +133 -0
  34. package/dist/lib/qwickbrain-client.js.map +1 -1
  35. package/dist/lib/sse-invalidation-listener.d.ts +27 -0
  36. package/dist/lib/sse-invalidation-listener.d.ts.map +1 -0
  37. package/dist/lib/sse-invalidation-listener.js +145 -0
  38. package/dist/lib/sse-invalidation-listener.js.map +1 -0
  39. package/dist/lib/tools.d.ts +21 -0
  40. package/dist/lib/tools.d.ts.map +1 -0
  41. package/dist/lib/tools.js +488 -0
  42. package/dist/lib/tools.js.map +1 -0
  43. package/dist/lib/write-queue-manager.d.ts +88 -0
  44. package/dist/lib/write-queue-manager.d.ts.map +1 -0
  45. package/dist/lib/write-queue-manager.js +191 -0
  46. package/dist/lib/write-queue-manager.js.map +1 -0
  47. package/dist/types/config.d.ts +7 -42
  48. package/dist/types/config.d.ts.map +1 -1
  49. package/dist/types/config.js +1 -6
  50. package/dist/types/config.js.map +1 -1
  51. package/drizzle/0002_lru_cache_migration.sql +94 -0
  52. package/drizzle/meta/_journal.json +7 -0
  53. package/package.json +6 -2
  54. package/scripts/rebuild-sqlite.sh +26 -0
  55. package/src/db/schema.ts +17 -2
  56. package/src/lib/__tests__/cache-manager.test.ts +180 -90
  57. package/src/lib/__tests__/proxy-server.test.ts +16 -51
  58. package/src/lib/__tests__/sse-invalidation-listener.test.ts +326 -0
  59. package/src/lib/__tests__/write-queue-manager.test.ts +383 -0
  60. package/src/lib/cache-manager.ts +198 -46
  61. package/src/lib/connection-manager.ts +4 -1
  62. package/src/lib/proxy-server.ts +222 -90
  63. package/src/lib/qwickbrain-client.ts +145 -1
  64. package/src/lib/sse-invalidation-listener.ts +171 -0
  65. package/src/lib/tools.ts +500 -0
  66. package/src/lib/write-queue-manager.ts +271 -0
  67. package/src/types/config.ts +1 -6
@@ -0,0 +1,488 @@
1
+ /**
2
+ * Static tool definitions for QwickBrain MCP Proxy
3
+ *
4
+ * These tools are always exposed regardless of connection state.
5
+ * Non-cacheable tools return offline errors when QwickBrain is unavailable.
6
+ */
7
+ export const QWICKBRAIN_TOOLS = [
8
+ // Code Analysis Tools
9
+ {
10
+ name: 'analyze_repository',
11
+ description: 'Analyze a repository and extract architecture-level information. Returns modules, files, languages, and import relationships. Use this for initial exploration of a codebase.',
12
+ inputSchema: {
13
+ type: 'object',
14
+ properties: {
15
+ path: {
16
+ type: 'string',
17
+ description: 'Absolute path to the repository root',
18
+ },
19
+ language: {
20
+ type: 'string',
21
+ description: 'Optional: filter by language (python, javascript, typescript, java, go)',
22
+ },
23
+ },
24
+ required: ['path'],
25
+ },
26
+ },
27
+ {
28
+ name: 'analyze_file',
29
+ description: 'Analyze a single source file and extract its structure. Returns functions, classes, methods, interfaces, and type aliases. Use this to understand the contents of a specific file.',
30
+ inputSchema: {
31
+ type: 'object',
32
+ properties: {
33
+ path: {
34
+ type: 'string',
35
+ description: 'Absolute path to the source file',
36
+ },
37
+ },
38
+ required: ['path'],
39
+ },
40
+ },
41
+ {
42
+ name: 'find_functions',
43
+ description: 'Find all functions in a file or repository matching a pattern. Returns function names, signatures, and locations.',
44
+ inputSchema: {
45
+ type: 'object',
46
+ properties: {
47
+ path: {
48
+ type: 'string',
49
+ description: 'Path to a file or repository',
50
+ },
51
+ pattern: {
52
+ type: 'string',
53
+ description: 'Optional: pattern to match function names (case-insensitive substring)',
54
+ },
55
+ },
56
+ required: ['path'],
57
+ },
58
+ },
59
+ {
60
+ name: 'find_classes',
61
+ description: 'Find all classes in a file or repository matching a pattern. Returns class names, bases, and locations.',
62
+ inputSchema: {
63
+ type: 'object',
64
+ properties: {
65
+ path: {
66
+ type: 'string',
67
+ description: 'Path to a file or repository',
68
+ },
69
+ pattern: {
70
+ type: 'string',
71
+ description: 'Optional: pattern to match class names (case-insensitive substring)',
72
+ },
73
+ },
74
+ required: ['path'],
75
+ },
76
+ },
77
+ {
78
+ name: 'get_imports',
79
+ description: 'Get all imports from a file or repository. Shows what modules and packages are imported and from where.',
80
+ inputSchema: {
81
+ type: 'object',
82
+ properties: {
83
+ path: {
84
+ type: 'string',
85
+ description: 'Path to a file or repository',
86
+ },
87
+ },
88
+ required: ['path'],
89
+ },
90
+ },
91
+ {
92
+ name: 'search_codebase',
93
+ description: 'Semantic search across the indexed codebase. Uses natural language to find relevant functions, classes, and methods. Requires the codebase to be indexed first. Returns ranked results with similarity scores.',
94
+ inputSchema: {
95
+ type: 'object',
96
+ properties: {
97
+ query: {
98
+ type: 'string',
99
+ description: 'Natural language search query. Examples: "function to parse JSON", "class that handles authentication", "async method for file upload"',
100
+ },
101
+ limit: {
102
+ type: 'integer',
103
+ description: 'Maximum results to return (default: 10, max: 20)',
104
+ default: 10,
105
+ },
106
+ min_score: {
107
+ type: 'number',
108
+ description: 'Minimum similarity score threshold (default: 0.5)',
109
+ default: 0.5,
110
+ },
111
+ },
112
+ required: ['query'],
113
+ },
114
+ },
115
+ {
116
+ name: 'explain_function',
117
+ description: 'Get detailed explanation of a function or method. Analyzes implementation and provides insights.',
118
+ inputSchema: {
119
+ type: 'object',
120
+ properties: {
121
+ path: {
122
+ type: 'string',
123
+ description: 'Path to the file containing the function',
124
+ },
125
+ function_name: {
126
+ type: 'string',
127
+ description: 'Name of the function to explain',
128
+ },
129
+ },
130
+ required: ['path', 'function_name'],
131
+ },
132
+ },
133
+ // Repository Management Tools
134
+ {
135
+ name: 'add_repository',
136
+ description: 'Add a repository to the index for semantic search.',
137
+ inputSchema: {
138
+ type: 'object',
139
+ properties: {
140
+ path: {
141
+ type: 'string',
142
+ description: 'Absolute path to the repository root',
143
+ },
144
+ },
145
+ required: ['path'],
146
+ },
147
+ },
148
+ {
149
+ name: 'list_repositories',
150
+ description: 'List all indexed repositories.',
151
+ inputSchema: {
152
+ type: 'object',
153
+ properties: {},
154
+ },
155
+ },
156
+ {
157
+ name: 'remove_repository',
158
+ description: 'Remove a repository from the index.',
159
+ inputSchema: {
160
+ type: 'object',
161
+ properties: {
162
+ path: {
163
+ type: 'string',
164
+ description: 'Path to the repository to remove',
165
+ },
166
+ },
167
+ required: ['path'],
168
+ },
169
+ },
170
+ {
171
+ name: 'update_repository',
172
+ description: 'Update the index for a repository (re-index).',
173
+ inputSchema: {
174
+ type: 'object',
175
+ properties: {
176
+ path: {
177
+ type: 'string',
178
+ description: 'Path to the repository to update',
179
+ },
180
+ },
181
+ required: ['path'],
182
+ },
183
+ },
184
+ // Document Management Tools (Cacheable)
185
+ {
186
+ name: 'create_document',
187
+ description: 'Create a new document.',
188
+ inputSchema: {
189
+ type: 'object',
190
+ properties: {
191
+ name: {
192
+ type: 'string',
193
+ description: 'Document name',
194
+ },
195
+ doc_type: {
196
+ type: 'string',
197
+ description: 'Document type',
198
+ enum: ['adr', 'spike', 'frd', 'design', 'review', 'memory', 'workflow', 'rule'],
199
+ },
200
+ content: {
201
+ type: 'string',
202
+ description: 'Document content (markdown)',
203
+ },
204
+ project: {
205
+ type: 'string',
206
+ description: 'Optional: Project scope',
207
+ },
208
+ metadata: {
209
+ type: 'object',
210
+ description: 'Optional: Additional metadata',
211
+ },
212
+ },
213
+ required: ['name', 'doc_type', 'content'],
214
+ },
215
+ },
216
+ {
217
+ name: 'get_document',
218
+ description: 'Get a document by name, type, and optional project. Returns the full document content and metadata. CACHEABLE - works offline with cached data.',
219
+ inputSchema: {
220
+ type: 'object',
221
+ properties: {
222
+ name: {
223
+ type: 'string',
224
+ description: 'Document name',
225
+ },
226
+ doc_type: {
227
+ type: 'string',
228
+ description: 'Document type',
229
+ enum: ['adr', 'spike', 'frd', 'design', 'review', 'memory', 'workflow', 'rule'],
230
+ },
231
+ project: {
232
+ type: 'string',
233
+ description: 'Optional: Project scope (omit for global documents)',
234
+ },
235
+ },
236
+ required: ['name', 'doc_type'],
237
+ },
238
+ },
239
+ {
240
+ name: 'list_documents',
241
+ description: 'List documents with optional filters. Can filter by type and/or project.',
242
+ inputSchema: {
243
+ type: 'object',
244
+ properties: {
245
+ doc_type: {
246
+ type: 'string',
247
+ description: 'Optional: Filter by document type',
248
+ },
249
+ project: {
250
+ type: 'string',
251
+ description: 'Optional: Filter by project',
252
+ },
253
+ },
254
+ },
255
+ },
256
+ {
257
+ name: 'update_document',
258
+ description: 'Update an existing document.',
259
+ inputSchema: {
260
+ type: 'object',
261
+ properties: {
262
+ name: {
263
+ type: 'string',
264
+ description: 'Document name',
265
+ },
266
+ doc_type: {
267
+ type: 'string',
268
+ description: 'Document type',
269
+ },
270
+ content: {
271
+ type: 'string',
272
+ description: 'New document content',
273
+ },
274
+ project: {
275
+ type: 'string',
276
+ description: 'Optional: Project scope',
277
+ },
278
+ metadata: {
279
+ type: 'object',
280
+ description: 'Optional: Updated metadata',
281
+ },
282
+ },
283
+ required: ['name', 'doc_type', 'content'],
284
+ },
285
+ },
286
+ {
287
+ name: 'delete_document',
288
+ description: 'Delete a document.',
289
+ inputSchema: {
290
+ type: 'object',
291
+ properties: {
292
+ name: {
293
+ type: 'string',
294
+ description: 'Document name',
295
+ },
296
+ doc_type: {
297
+ type: 'string',
298
+ description: 'Document type',
299
+ },
300
+ project: {
301
+ type: 'string',
302
+ description: 'Optional: Project scope',
303
+ },
304
+ },
305
+ required: ['name', 'doc_type'],
306
+ },
307
+ },
308
+ {
309
+ name: 'search_documents',
310
+ description: 'Search documents by content or metadata.',
311
+ inputSchema: {
312
+ type: 'object',
313
+ properties: {
314
+ query: {
315
+ type: 'string',
316
+ description: 'Search query',
317
+ },
318
+ doc_type: {
319
+ type: 'string',
320
+ description: 'Optional: Filter by document type',
321
+ },
322
+ project: {
323
+ type: 'string',
324
+ description: 'Optional: Filter by project',
325
+ },
326
+ },
327
+ required: ['query'],
328
+ },
329
+ },
330
+ // Workflow Tools (Cacheable)
331
+ {
332
+ name: 'get_workflow',
333
+ description: 'Get a workflow definition by name. CACHEABLE - works offline with cached data.',
334
+ inputSchema: {
335
+ type: 'object',
336
+ properties: {
337
+ name: {
338
+ type: 'string',
339
+ description: 'Workflow name',
340
+ },
341
+ },
342
+ required: ['name'],
343
+ },
344
+ },
345
+ {
346
+ name: 'list_workflows',
347
+ description: 'List all available workflows.',
348
+ inputSchema: {
349
+ type: 'object',
350
+ properties: {},
351
+ },
352
+ },
353
+ {
354
+ name: 'create_workflow',
355
+ description: 'Create a new workflow definition.',
356
+ inputSchema: {
357
+ type: 'object',
358
+ properties: {
359
+ name: {
360
+ type: 'string',
361
+ description: 'Workflow name',
362
+ },
363
+ content: {
364
+ type: 'string',
365
+ description: 'Workflow content (markdown)',
366
+ },
367
+ metadata: {
368
+ type: 'object',
369
+ description: 'Optional: Workflow metadata',
370
+ },
371
+ },
372
+ required: ['name', 'content'],
373
+ },
374
+ },
375
+ {
376
+ name: 'update_workflow',
377
+ description: 'Update an existing workflow.',
378
+ inputSchema: {
379
+ type: 'object',
380
+ properties: {
381
+ name: {
382
+ type: 'string',
383
+ description: 'Workflow name',
384
+ },
385
+ content: {
386
+ type: 'string',
387
+ description: 'Updated workflow content',
388
+ },
389
+ metadata: {
390
+ type: 'object',
391
+ description: 'Optional: Updated metadata',
392
+ },
393
+ },
394
+ required: ['name', 'content'],
395
+ },
396
+ },
397
+ // Memory Tools (Cacheable)
398
+ {
399
+ name: 'get_memory',
400
+ description: 'Get a memory/context document by name. CACHEABLE - works offline with cached data.',
401
+ inputSchema: {
402
+ type: 'object',
403
+ properties: {
404
+ name: {
405
+ type: 'string',
406
+ description: 'Memory name',
407
+ },
408
+ project: {
409
+ type: 'string',
410
+ description: 'Optional: Project scope',
411
+ },
412
+ },
413
+ required: ['name'],
414
+ },
415
+ },
416
+ {
417
+ name: 'set_memory',
418
+ description: 'Set or update a memory/context document.',
419
+ inputSchema: {
420
+ type: 'object',
421
+ properties: {
422
+ name: {
423
+ type: 'string',
424
+ description: 'Memory name',
425
+ },
426
+ content: {
427
+ type: 'string',
428
+ description: 'Memory content',
429
+ },
430
+ project: {
431
+ type: 'string',
432
+ description: 'Optional: Project scope',
433
+ },
434
+ metadata: {
435
+ type: 'object',
436
+ description: 'Optional: Memory metadata',
437
+ },
438
+ },
439
+ required: ['name', 'content'],
440
+ },
441
+ },
442
+ {
443
+ name: 'list_memories',
444
+ description: 'List all memories with optional project filter.',
445
+ inputSchema: {
446
+ type: 'object',
447
+ properties: {
448
+ project: {
449
+ type: 'string',
450
+ description: 'Optional: Filter by project',
451
+ },
452
+ },
453
+ },
454
+ },
455
+ {
456
+ name: 'search_memories',
457
+ description: 'Search memories by content.',
458
+ inputSchema: {
459
+ type: 'object',
460
+ properties: {
461
+ query: {
462
+ type: 'string',
463
+ description: 'Search query',
464
+ },
465
+ project: {
466
+ type: 'string',
467
+ description: 'Optional: Filter by project',
468
+ },
469
+ },
470
+ required: ['query'],
471
+ },
472
+ },
473
+ ];
474
+ /**
475
+ * Tools that are cacheable and work offline
476
+ */
477
+ export const CACHEABLE_TOOLS = new Set([
478
+ 'get_workflow',
479
+ 'get_document',
480
+ 'get_memory',
481
+ ]);
482
+ /**
483
+ * Tools that require active connection
484
+ */
485
+ export function requiresConnection(toolName) {
486
+ return !CACHEABLE_TOOLS.has(toolName);
487
+ }
488
+ //# sourceMappingURL=tools.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tools.js","sourceRoot":"","sources":["../../src/lib/tools.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAQH,MAAM,CAAC,MAAM,gBAAgB,GAAqB;IAChD,sBAAsB;IACtB;QACE,IAAI,EAAE,oBAAoB;QAC1B,WAAW,EAAE,+KAA+K;QAC5L,WAAW,EAAE;YACX,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE;gBACV,IAAI,EAAE;oBACJ,IAAI,EAAE,QAAQ;oBACd,WAAW,EAAE,sCAAsC;iBACpD;gBACD,QAAQ,EAAE;oBACR,IAAI,EAAE,QAAQ;oBACd,WAAW,EAAE,yEAAyE;iBACvF;aACF;YACD,QAAQ,EAAE,CAAC,MAAM,CAAC;SACnB;KACF;IACD;QACE,IAAI,EAAE,cAAc;QACpB,WAAW,EAAE,oLAAoL;QACjM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;oBACd,WAAW,EAAE,aAAa;iBAC3B;gBACD,OAAO,EAAE;oBACP,IAAI,EAAE,QAAQ;oBACd,WAAW,EAAE,gBAAgB;iBAC9B;gBACD,OAAO,EAAE;oBACP,IAAI,EAAE,QAAQ;oBACd,WAAW,EAAE,yBAAyB;iBACvC;gBACD,QAAQ,EAAE;oBACR,IAAI,EAAE,QAAQ;oBACd,WAAW,EAAE,2BAA2B;iBACzC;aACF;YACD,QAAQ,EAAE,CAAC,MAAM,EAAE,SAAS,CAAC;SAC9B;KACF;IACD;QACE,IAAI,EAAE,eAAe;QACrB,WAAW,EAAE,iDAAiD;QAC9D,WAAW,EAAE;YACX,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE;gBACV,OAAO,EAAE;oBACP,IAAI,EAAE,QAAQ;oBACd,WAAW,EAAE,6BAA6B;iBAC3C;aACF;SACF;KACF;IACD;QACE,IAAI,EAAE,iBAAiB;QACvB,WAAW,EAAE,6BAA6B;QAC1C,WAAW,EAAE;YACX,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE;gBACV,KAAK,EAAE;oBACL,IAAI,EAAE,QAAQ;oBACd,WAAW,EAAE,cAAc;iBAC5B;gBACD,OAAO,EAAE;oBACP,IAAI,EAAE,QAAQ;oBACd,WAAW,EAAE,6BAA6B;iBAC3C;aACF;YACD,QAAQ,EAAE,CAAC,OAAO,CAAC;SACpB;KACF;CACF,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,IAAI,GAAG,CAAC;IACrC,cAAc;IACd,cAAc;IACd,YAAY;CACb,CAAC,CAAC;AAEH;;GAEG;AACH,MAAM,UAAU,kBAAkB,CAAC,QAAgB;IACjD,OAAO,CAAC,eAAe,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;AACxC,CAAC"}
@@ -0,0 +1,88 @@
1
+ import type { DB } from '../db/client.js';
2
+ import type { QwickBrainClient } from './qwickbrain-client.js';
3
+ interface QueuedOperation {
4
+ id: number;
5
+ operation: string;
6
+ payload: string;
7
+ createdAt: Date;
8
+ status: string;
9
+ error: string | null;
10
+ attempts: number;
11
+ lastAttemptAt: Date | null;
12
+ }
13
+ interface CreateDocumentPayload {
14
+ docType: string;
15
+ name: string;
16
+ content: string;
17
+ project?: string;
18
+ metadata?: Record<string, unknown>;
19
+ }
20
+ interface SetMemoryPayload {
21
+ name: string;
22
+ content: string;
23
+ project?: string;
24
+ metadata?: Record<string, unknown>;
25
+ }
26
+ interface DeleteDocumentPayload {
27
+ docType: string;
28
+ name: string;
29
+ project?: string;
30
+ }
31
+ interface DeleteMemoryPayload {
32
+ name: string;
33
+ project?: string;
34
+ }
35
+ type OperationPayload = CreateDocumentPayload | SetMemoryPayload | DeleteDocumentPayload | DeleteMemoryPayload;
36
+ export declare class WriteQueueManager {
37
+ private db;
38
+ private qwickbrainClient;
39
+ private maxAttempts;
40
+ private isSyncing;
41
+ constructor(db: DB, qwickbrainClient: QwickBrainClient);
42
+ /**
43
+ * Queue a write operation for later sync
44
+ */
45
+ queueOperation(operation: string, payload: OperationPayload): Promise<void>;
46
+ /**
47
+ * Get count of pending operations
48
+ */
49
+ getPendingCount(): Promise<number>;
50
+ /**
51
+ * Sync all pending operations
52
+ * Returns number of operations synced successfully
53
+ */
54
+ syncPendingOperations(): Promise<{
55
+ synced: number;
56
+ failed: number;
57
+ }>;
58
+ /**
59
+ * Execute a single queued operation
60
+ */
61
+ private executeOperation;
62
+ /**
63
+ * Clean up completed operations
64
+ */
65
+ private cleanupCompleted;
66
+ /**
67
+ * Get failed operations for inspection
68
+ */
69
+ getFailedOperations(): Promise<QueuedOperation[]>;
70
+ /**
71
+ * Retry a specific failed operation
72
+ */
73
+ retryOperation(id: number): Promise<void>;
74
+ /**
75
+ * Clear all failed operations
76
+ */
77
+ clearFailed(): Promise<number>;
78
+ /**
79
+ * Get queue statistics
80
+ */
81
+ getQueueStats(): Promise<{
82
+ pending: number;
83
+ failed: number;
84
+ total: number;
85
+ }>;
86
+ }
87
+ export {};
88
+ //# sourceMappingURL=write-queue-manager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"write-queue-manager.d.ts","sourceRoot":"","sources":["../../src/lib/write-queue-manager.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,iBAAiB,CAAC;AAE1C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAE/D,UAAU,eAAe;IACvB,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,IAAI,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,aAAa,EAAE,IAAI,GAAG,IAAI,CAAC;CAC5B;AAED,UAAU,qBAAqB;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAED,UAAU,gBAAgB;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAED,UAAU,qBAAqB;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,UAAU,mBAAmB;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,KAAK,gBAAgB,GACjB,qBAAqB,GACrB,gBAAgB,GAChB,qBAAqB,GACrB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