flashq 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.
Files changed (78) hide show
  1. package/README.md +283 -0
  2. package/dist/client/advanced.d.ts +174 -0
  3. package/dist/client/advanced.d.ts.map +1 -0
  4. package/dist/client/advanced.js +248 -0
  5. package/dist/client/advanced.js.map +1 -0
  6. package/dist/client/connection.d.ts +103 -0
  7. package/dist/client/connection.d.ts.map +1 -0
  8. package/dist/client/connection.js +570 -0
  9. package/dist/client/connection.js.map +1 -0
  10. package/dist/client/core.d.ts +119 -0
  11. package/dist/client/core.d.ts.map +1 -0
  12. package/dist/client/core.js +257 -0
  13. package/dist/client/core.js.map +1 -0
  14. package/dist/client/cron.d.ts +59 -0
  15. package/dist/client/cron.d.ts.map +1 -0
  16. package/dist/client/cron.js +82 -0
  17. package/dist/client/cron.js.map +1 -0
  18. package/dist/client/dlq.d.ts +52 -0
  19. package/dist/client/dlq.d.ts.map +1 -0
  20. package/dist/client/dlq.js +73 -0
  21. package/dist/client/dlq.js.map +1 -0
  22. package/dist/client/flows.d.ts +49 -0
  23. package/dist/client/flows.d.ts.map +1 -0
  24. package/dist/client/flows.js +67 -0
  25. package/dist/client/flows.js.map +1 -0
  26. package/dist/client/index.d.ts +644 -0
  27. package/dist/client/index.d.ts.map +1 -0
  28. package/dist/client/index.js +829 -0
  29. package/dist/client/index.js.map +1 -0
  30. package/dist/client/jobs.d.ts +183 -0
  31. package/dist/client/jobs.d.ts.map +1 -0
  32. package/dist/client/jobs.js +272 -0
  33. package/dist/client/jobs.js.map +1 -0
  34. package/dist/client/kv.d.ts +63 -0
  35. package/dist/client/kv.d.ts.map +1 -0
  36. package/dist/client/kv.js +131 -0
  37. package/dist/client/kv.js.map +1 -0
  38. package/dist/client/metrics.d.ts +34 -0
  39. package/dist/client/metrics.d.ts.map +1 -0
  40. package/dist/client/metrics.js +49 -0
  41. package/dist/client/metrics.js.map +1 -0
  42. package/dist/client/pubsub.d.ts +42 -0
  43. package/dist/client/pubsub.d.ts.map +1 -0
  44. package/dist/client/pubsub.js +92 -0
  45. package/dist/client/pubsub.js.map +1 -0
  46. package/dist/client/queue.d.ts +111 -0
  47. package/dist/client/queue.d.ts.map +1 -0
  48. package/dist/client/queue.js +160 -0
  49. package/dist/client/queue.js.map +1 -0
  50. package/dist/client/types.d.ts +23 -0
  51. package/dist/client/types.d.ts.map +1 -0
  52. package/dist/client/types.js +3 -0
  53. package/dist/client/types.js.map +1 -0
  54. package/dist/client.d.ts +17 -0
  55. package/dist/client.d.ts.map +1 -0
  56. package/dist/client.js +23 -0
  57. package/dist/client.js.map +1 -0
  58. package/dist/events.d.ts +184 -0
  59. package/dist/events.d.ts.map +1 -0
  60. package/dist/events.js +340 -0
  61. package/dist/events.js.map +1 -0
  62. package/dist/index.d.ts +30 -0
  63. package/dist/index.d.ts.map +1 -0
  64. package/dist/index.js +43 -0
  65. package/dist/index.js.map +1 -0
  66. package/dist/queue.d.ts +104 -0
  67. package/dist/queue.d.ts.map +1 -0
  68. package/dist/queue.js +139 -0
  69. package/dist/queue.js.map +1 -0
  70. package/dist/types.d.ts +185 -0
  71. package/dist/types.d.ts.map +1 -0
  72. package/dist/types.js +6 -0
  73. package/dist/types.js.map +1 -0
  74. package/dist/worker.d.ts +88 -0
  75. package/dist/worker.d.ts.map +1 -0
  76. package/dist/worker.js +296 -0
  77. package/dist/worker.js.map +1 -0
  78. package/package.json +70 -0
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getDlq = getDlq;
4
+ exports.retryDlq = retryDlq;
5
+ exports.purgeDlq = purgeDlq;
6
+ /**
7
+ * Get jobs from the dead letter queue.
8
+ *
9
+ * @param client - FlashQ client instance
10
+ * @param queue - Queue name
11
+ * @param count - Max jobs to return (default: 100)
12
+ * @returns Array of failed jobs
13
+ *
14
+ * @example
15
+ * ```typescript
16
+ * const failed = await client.getDlq('emails', 50);
17
+ * console.log(`${failed.length} jobs in DLQ`);
18
+ * ```
19
+ */
20
+ async function getDlq(client, queue, count = 100) {
21
+ const response = await client.send({
22
+ cmd: 'DLQ',
23
+ queue,
24
+ count,
25
+ });
26
+ return response.jobs;
27
+ }
28
+ /**
29
+ * Retry jobs from the dead letter queue.
30
+ *
31
+ * @param client - FlashQ client instance
32
+ * @param queue - Queue name
33
+ * @param jobId - Optional specific job ID to retry
34
+ * @returns Number of jobs retried
35
+ *
36
+ * @example
37
+ * ```typescript
38
+ * // Retry all jobs in DLQ
39
+ * const retried = await client.retryDlq('emails');
40
+ *
41
+ * // Retry specific job
42
+ * await client.retryDlq('emails', 123);
43
+ * ```
44
+ */
45
+ async function retryDlq(client, queue, jobId) {
46
+ const response = await client.send({
47
+ cmd: 'RETRYDLQ',
48
+ queue,
49
+ id: jobId,
50
+ });
51
+ return response.ids?.[0] ?? 0;
52
+ }
53
+ /**
54
+ * Purge all jobs from the dead letter queue.
55
+ *
56
+ * @param client - FlashQ client instance
57
+ * @param queue - Queue name
58
+ * @returns Number of jobs purged
59
+ *
60
+ * @example
61
+ * ```typescript
62
+ * const purged = await client.purgeDlq('emails');
63
+ * console.log(`Purged ${purged} failed jobs`);
64
+ * ```
65
+ */
66
+ async function purgeDlq(client, queue) {
67
+ const response = await client.send({
68
+ cmd: 'PURGEDLQ',
69
+ queue,
70
+ });
71
+ return response.count;
72
+ }
73
+ //# sourceMappingURL=dlq.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dlq.js","sourceRoot":"","sources":["../../src/client/dlq.ts"],"names":[],"mappings":";;AAmBA,wBAWC;AAmBD,4BAWC;AAeD,4BASC;AA/ED;;;;;;;;;;;;;GAaG;AACI,KAAK,UAAU,MAAM,CAC1B,MAAqB,EACrB,KAAa,EACb,KAAK,GAAG,GAAG;IAEX,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,IAAI,CAA+B;QAC/D,GAAG,EAAE,KAAK;QACV,KAAK;QACL,KAAK;KACN,CAAC,CAAC;IACH,OAAO,QAAQ,CAAC,IAAI,CAAC;AACvB,CAAC;AAED;;;;;;;;;;;;;;;;GAgBG;AACI,KAAK,UAAU,QAAQ,CAC5B,MAAqB,EACrB,KAAa,EACb,KAAc;IAEd,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,IAAI,CAAiC;QACjE,GAAG,EAAE,UAAU;QACf,KAAK;QACL,EAAE,EAAE,KAAK;KACV,CAAC,CAAC;IACH,OAAO,QAAQ,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;AAChC,CAAC;AAED;;;;;;;;;;;;GAYG;AACI,KAAK,UAAU,QAAQ,CAC5B,MAAqB,EACrB,KAAa;IAEb,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,IAAI,CAAiC;QACjE,GAAG,EAAE,UAAU;QACf,KAAK;KACN,CAAC,CAAC;IACH,OAAO,QAAQ,CAAC,KAAK,CAAC;AACxB,CAAC"}
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Flow operations (parent-child job dependencies)
3
+ */
4
+ import type { IFlashQClient, FlowChild, FlowResult, FlowOptions } from './types';
5
+ /**
6
+ * Push a flow (parent job with children).
7
+ * The parent job waits until all children complete before becoming ready.
8
+ *
9
+ * @param client - FlashQ client instance
10
+ * @param queue - Parent queue name
11
+ * @param parentData - Parent job data
12
+ * @param children - Array of child jobs
13
+ * @param options - Flow options
14
+ * @returns Parent and children IDs
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * const flow = await client.pushFlow(
19
+ * 'reports',
20
+ * { reportType: 'monthly' },
21
+ * [
22
+ * { queue: 'process', data: { section: 'sales' } },
23
+ * { queue: 'process', data: { section: 'marketing' } },
24
+ * { queue: 'process', data: { section: 'operations' } },
25
+ * ]
26
+ * );
27
+ * console.log('Parent:', flow.parent_id);
28
+ * console.log('Children:', flow.children_ids);
29
+ * ```
30
+ */
31
+ export declare function pushFlow<T = unknown>(client: IFlashQClient, queue: string, parentData: T, children: FlowChild[], options?: FlowOptions): Promise<FlowResult>;
32
+ /**
33
+ * Get children job IDs for a parent job in a flow.
34
+ *
35
+ * @param client - FlashQ client instance
36
+ * @param jobId - Parent job ID
37
+ * @returns Array of children job IDs
38
+ *
39
+ * @example
40
+ * ```typescript
41
+ * const childIds = await client.getChildren(parentJobId);
42
+ * for (const id of childIds) {
43
+ * const child = await client.getJob(id);
44
+ * console.log(`Child ${id}: ${child?.state}`);
45
+ * }
46
+ * ```
47
+ */
48
+ export declare function getChildren(client: IFlashQClient, jobId: number): Promise<number[]>;
49
+ //# sourceMappingURL=flows.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"flows.d.ts","sourceRoot":"","sources":["../../src/client/flows.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEjF;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAsB,QAAQ,CAAC,CAAC,GAAG,OAAO,EACxC,MAAM,EAAE,aAAa,EACrB,KAAK,EAAE,MAAM,EACb,UAAU,EAAE,CAAC,EACb,QAAQ,EAAE,SAAS,EAAE,EACrB,OAAO,GAAE,WAAgB,GACxB,OAAO,CAAC,UAAU,CAAC,CAgBrB;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,WAAW,CAC/B,MAAM,EAAE,aAAa,EACrB,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,MAAM,EAAE,CAAC,CAMnB"}
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.pushFlow = pushFlow;
4
+ exports.getChildren = getChildren;
5
+ /**
6
+ * Push a flow (parent job with children).
7
+ * The parent job waits until all children complete before becoming ready.
8
+ *
9
+ * @param client - FlashQ client instance
10
+ * @param queue - Parent queue name
11
+ * @param parentData - Parent job data
12
+ * @param children - Array of child jobs
13
+ * @param options - Flow options
14
+ * @returns Parent and children IDs
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * const flow = await client.pushFlow(
19
+ * 'reports',
20
+ * { reportType: 'monthly' },
21
+ * [
22
+ * { queue: 'process', data: { section: 'sales' } },
23
+ * { queue: 'process', data: { section: 'marketing' } },
24
+ * { queue: 'process', data: { section: 'operations' } },
25
+ * ]
26
+ * );
27
+ * console.log('Parent:', flow.parent_id);
28
+ * console.log('Children:', flow.children_ids);
29
+ * ```
30
+ */
31
+ async function pushFlow(client, queue, parentData, children, options = {}) {
32
+ const response = await client.send({
33
+ cmd: 'FLOW',
34
+ queue,
35
+ data: parentData,
36
+ children,
37
+ priority: options.priority ?? 0,
38
+ });
39
+ return {
40
+ parent_id: response.parent_id,
41
+ children_ids: response.children_ids,
42
+ };
43
+ }
44
+ /**
45
+ * Get children job IDs for a parent job in a flow.
46
+ *
47
+ * @param client - FlashQ client instance
48
+ * @param jobId - Parent job ID
49
+ * @returns Array of children job IDs
50
+ *
51
+ * @example
52
+ * ```typescript
53
+ * const childIds = await client.getChildren(parentJobId);
54
+ * for (const id of childIds) {
55
+ * const child = await client.getJob(id);
56
+ * console.log(`Child ${id}: ${child?.state}`);
57
+ * }
58
+ * ```
59
+ */
60
+ async function getChildren(client, jobId) {
61
+ const response = await client.send({
62
+ cmd: 'GETCHILDREN',
63
+ parent_id: jobId,
64
+ });
65
+ return response.children_ids;
66
+ }
67
+ //# sourceMappingURL=flows.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"flows.js","sourceRoot":"","sources":["../../src/client/flows.ts"],"names":[],"mappings":";;AA+BA,4BAsBC;AAkBD,kCASC;AA3ED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACI,KAAK,UAAU,QAAQ,CAC5B,MAAqB,EACrB,KAAa,EACb,UAAa,EACb,QAAqB,EACrB,UAAuB,EAAE;IAEzB,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,IAAI,CAI/B;QACD,GAAG,EAAE,MAAM;QACX,KAAK;QACL,IAAI,EAAE,UAAU;QAChB,QAAQ;QACR,QAAQ,EAAE,OAAO,CAAC,QAAQ,IAAI,CAAC;KAChC,CAAC,CAAC;IACH,OAAO;QACL,SAAS,EAAE,QAAQ,CAAC,SAAS;QAC7B,YAAY,EAAE,QAAQ,CAAC,YAAY;KACpC,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;;;GAeG;AACI,KAAK,UAAU,WAAW,CAC/B,MAAqB,EACrB,KAAa;IAEb,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,IAAI,CAA0C;QAC1E,GAAG,EAAE,aAAa;QAClB,SAAS,EAAE,KAAK;KACjB,CAAC,CAAC;IACH,OAAO,QAAQ,CAAC,YAAY,CAAC;AAC/B,CAAC"}