@hexok/queue 0.2.0 → 1.0.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/README.md +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/queue.d.ts +16 -0
- package/dist/queue.d.ts.map +1 -1
- package/dist/queue.js +16 -0
- package/dist/queue.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -6,6 +6,6 @@ Queue port. Install with `npm i @hexok/queue`. A Redis Streams adapter is `@hexo
|
|
|
6
6
|
import { Queue, type QueueHandler } from '@hexok/queue';
|
|
7
7
|
```
|
|
8
8
|
|
|
9
|
-
`publish` resolves a broker id. `subscribe` requires `consumerGroup`. A handler return of `'ack'`, `void`, or `'drop'` acknowledges. `'retry'` leaves the entry pending. A throw uses `onError`, which defaults to `'retry'`. There is no dead-letter stream. A Redis adapter can park a failed publish, a missing payload,
|
|
9
|
+
`publish` resolves a broker id. `subscribe` requires `consumerGroup` and `maxDeliveries`. There is no default. A positive integer runs the handler at most that many times. `'unlimited'` retries without a ceiling. `deliveries` on the message is the 1-based handoff count, including a crash that never acknowledged. It is stored with the entry, not in the process. A handler return of `'ack'`, `void`, or `'drop'` acknowledges, including on the last delivery. `'retry'` leaves the entry pending until the ceiling. A throw uses `onError`, which defaults to `'retry'`. A retry at the ceiling is acknowledged. It is not a handler `'drop'`. There is no dead-letter stream. A Redis adapter can park a failed publish, a missing payload, a decode failure, or a give-up when a quarantine sink is passed. A handler `'drop'` is not parked. Without a durable sink, a give-up discards.
|
|
10
10
|
|
|
11
11
|
Pass `{ sensitive: true }` as the third `publish` argument for a payload that holds a secret, such as a one-time code or a reset link. An adapter then parks and logs that message without its payload.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { dispositionOf, Queue, type QueueDisposition, type QueueHandler, type QueueMessage, type QueuePublishOptions, type QueueStartFrom, type QueueSubscribeOptions, } from './queue.js';
|
|
1
|
+
export { assertMaxDeliveries, deliveryAllowed, dispositionOf, Queue, type QueueDisposition, type QueueHandler, type QueueMaxDeliveries, type QueueMessage, type QueuePublishOptions, type QueueStartFrom, type QueueSubscribeOptions, retryExhausted, } from './queue.js';
|
|
2
2
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,KAAK,EACL,KAAK,gBAAgB,EACrB,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,KAAK,mBAAmB,EACxB,KAAK,cAAc,EACnB,KAAK,qBAAqB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,eAAe,EACf,aAAa,EACb,KAAK,EACL,KAAK,gBAAgB,EACrB,KAAK,YAAY,EACjB,KAAK,kBAAkB,EACvB,KAAK,YAAY,EACjB,KAAK,mBAAmB,EACxB,KAAK,cAAc,EACnB,KAAK,qBAAqB,EAC1B,cAAc,GACf,MAAM,YAAY,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { dispositionOf, Queue, } from './queue.js';
|
|
1
|
+
export { assertMaxDeliveries, deliveryAllowed, dispositionOf, Queue, retryExhausted, } from './queue.js';
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,KAAK,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,eAAe,EACf,aAAa,EACb,KAAK,EAQL,cAAc,GACf,MAAM,YAAY,CAAC"}
|
package/dist/queue.d.ts
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
export type QueueDisposition = 'ack' | 'retry' | 'drop';
|
|
2
|
+
/** A positive integer, or `'unlimited'` to retry without a ceiling. */
|
|
3
|
+
export type QueueMaxDeliveries = number | 'unlimited';
|
|
2
4
|
export interface QueueMessage<T> {
|
|
3
5
|
readonly id: string;
|
|
4
6
|
readonly topic: string;
|
|
5
7
|
readonly payload: T;
|
|
8
|
+
/**
|
|
9
|
+
* 1-based count of handoffs of this entry, including this one.
|
|
10
|
+
* Includes a handoff a crashed consumer never acknowledged.
|
|
11
|
+
* Stored with the entry, not in the process.
|
|
12
|
+
*/
|
|
13
|
+
readonly deliveries: number;
|
|
6
14
|
}
|
|
7
15
|
export type QueueHandler<T> = (message: QueueMessage<T>) => Promise<QueueDisposition | void>;
|
|
8
16
|
export type QueueStartFrom = 'earliest' | 'now' | {
|
|
@@ -12,6 +20,8 @@ export type QueueStartFrom = 'earliest' | 'now' | {
|
|
|
12
20
|
};
|
|
13
21
|
export interface QueueSubscribeOptions<T> {
|
|
14
22
|
readonly consumerGroup: string;
|
|
23
|
+
/** Positive integer, or `'unlimited'`. No default. */
|
|
24
|
+
readonly maxDeliveries: QueueMaxDeliveries;
|
|
15
25
|
readonly startFrom?: QueueStartFrom;
|
|
16
26
|
readonly onError?: QueueDisposition;
|
|
17
27
|
readonly handler: QueueHandler<T>;
|
|
@@ -32,6 +42,12 @@ export declare abstract class Queue extends Queue_base {
|
|
|
32
42
|
readonly consumerGroup: string;
|
|
33
43
|
}): Promise<void>;
|
|
34
44
|
}
|
|
45
|
+
/** Throws `queue: maxDeliveries must be a positive integer or "unlimited"`. */
|
|
46
|
+
export declare function assertMaxDeliveries(value: QueueMaxDeliveries): void;
|
|
47
|
+
/** This handoff may run. `'unlimited'` is always true. */
|
|
48
|
+
export declare function deliveryAllowed(deliveries: number, maxDeliveries: QueueMaxDeliveries): boolean;
|
|
49
|
+
/** A `'retry'` on this handoff is the last one. */
|
|
50
|
+
export declare function retryExhausted(deliveries: number, maxDeliveries: QueueMaxDeliveries): boolean;
|
|
35
51
|
/** Returned value wins. `void` acknowledges. A throw uses `onError`, default `retry`. */
|
|
36
52
|
export declare function dispositionOf(returned: QueueDisposition | void, thrown: boolean, onError?: QueueDisposition): QueueDisposition;
|
|
37
53
|
export {};
|
package/dist/queue.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"queue.d.ts","sourceRoot":"","sources":["../src/queue.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,gBAAgB,GAAG,KAAK,GAAG,OAAO,GAAG,MAAM,CAAC;AAExD,MAAM,WAAW,YAAY,CAAC,CAAC;IAC7B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"queue.d.ts","sourceRoot":"","sources":["../src/queue.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,gBAAgB,GAAG,KAAK,GAAG,OAAO,GAAG,MAAM,CAAC;AAExD,uEAAuE;AACvE,MAAM,MAAM,kBAAkB,GAAG,MAAM,GAAG,WAAW,CAAC;AAEtD,MAAM,WAAW,YAAY,CAAC,CAAC;IAC7B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC;IACpB;;;;OAIG;IACH,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;CAC7B;AAED,MAAM,MAAM,YAAY,CAAC,CAAC,IAAI,CAC5B,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,KACrB,OAAO,CAAC,gBAAgB,GAAG,IAAI,CAAC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;AAED,mDAAmD;AACnD,wBAAgB,cAAc,CAC5B,UAAU,EAAE,MAAM,EAClB,aAAa,EAAE,kBAAkB,GAChC,OAAO,CAET;AAED,yFAAyF;AACzF,wBAAgB,aAAa,CAC3B,QAAQ,EAAE,gBAAgB,GAAG,IAAI,EACjC,MAAM,EAAE,OAAO,EACf,OAAO,GAAE,gBAA0B,GAClC,gBAAgB,CAIlB"}
|
package/dist/queue.js
CHANGED
|
@@ -1,6 +1,22 @@
|
|
|
1
1
|
import { Port } from 'hexok';
|
|
2
2
|
export class Queue extends Port('Queue') {
|
|
3
3
|
}
|
|
4
|
+
/** Throws `queue: maxDeliveries must be a positive integer or "unlimited"`. */
|
|
5
|
+
export function assertMaxDeliveries(value) {
|
|
6
|
+
if (value === 'unlimited')
|
|
7
|
+
return;
|
|
8
|
+
if (Number.isSafeInteger(value) && value >= 1)
|
|
9
|
+
return;
|
|
10
|
+
throw new Error('queue: maxDeliveries must be a positive integer or "unlimited"');
|
|
11
|
+
}
|
|
12
|
+
/** This handoff may run. `'unlimited'` is always true. */
|
|
13
|
+
export function deliveryAllowed(deliveries, maxDeliveries) {
|
|
14
|
+
return maxDeliveries === 'unlimited' || deliveries <= maxDeliveries;
|
|
15
|
+
}
|
|
16
|
+
/** A `'retry'` on this handoff is the last one. */
|
|
17
|
+
export function retryExhausted(deliveries, maxDeliveries) {
|
|
18
|
+
return maxDeliveries !== 'unlimited' && deliveries >= maxDeliveries;
|
|
19
|
+
}
|
|
4
20
|
/** Returned value wins. `void` acknowledges. A throw uses `onError`, default `retry`. */
|
|
5
21
|
export function dispositionOf(returned, thrown, onError = 'retry') {
|
|
6
22
|
if (thrown)
|
package/dist/queue.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"queue.js","sourceRoot":"","sources":["../src/queue.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"queue.js","sourceRoot":"","sources":["../src/queue.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC;AA2C7B,MAAM,OAAgB,KAAM,SAAQ,IAAI,CAAC,OAAO,CAAC;CAchD;AAED,+EAA+E;AAC/E,MAAM,UAAU,mBAAmB,CAAC,KAAyB;IAC3D,IAAI,KAAK,KAAK,WAAW;QAAE,OAAO;IAClC,IAAI,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC;QAAE,OAAO;IACtD,MAAM,IAAI,KAAK,CACb,gEAAgE,CACjE,CAAC;AACJ,CAAC;AAED,0DAA0D;AAC1D,MAAM,UAAU,eAAe,CAC7B,UAAkB,EAClB,aAAiC;IAEjC,OAAO,aAAa,KAAK,WAAW,IAAI,UAAU,IAAI,aAAa,CAAC;AACtE,CAAC;AAED,mDAAmD;AACnD,MAAM,UAAU,cAAc,CAC5B,UAAkB,EAClB,aAAiC;IAEjC,OAAO,aAAa,KAAK,WAAW,IAAI,UAAU,IAAI,aAAa,CAAC;AACtE,CAAC;AAED,yFAAyF;AACzF,MAAM,UAAU,aAAa,CAC3B,QAAiC,EACjC,MAAe,EACf,UAA4B,OAAO;IAEnC,IAAI,MAAM;QAAE,OAAO,OAAO,CAAC;IAC3B,IAAI,QAAQ,KAAK,SAAS;QAAE,OAAO,KAAK,CAAC;IACzC,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hexok/queue",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "Queue port for hexok.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -40,6 +40,6 @@
|
|
|
40
40
|
"clean": "rm -rf dist *.tsbuildinfo"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"hexok": "^2.2.
|
|
43
|
+
"hexok": "^2.2.2"
|
|
44
44
|
}
|
|
45
45
|
}
|