@qkitt/queue 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 +15 -0
- package/README.md +723 -0
- package/dist/config/config-freeze.util.d.ts +7 -0
- package/dist/config/from-config.d.ts +33 -0
- package/dist/config/index.d.ts +4 -0
- package/dist/config/parse.util.d.ts +12 -0
- package/dist/config/store-resolve.util.d.ts +11 -0
- package/dist/config/types.d.ts +205 -0
- package/dist/config/validate.d.ts +36 -0
- package/dist/events/index.d.ts +48 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +1552 -0
- package/dist/persist/index.d.ts +3 -0
- package/dist/persist/json-codec.util.d.ts +13 -0
- package/dist/persist/memory.d.ts +14 -0
- package/dist/persist/web-storage-access.util.d.ts +10 -0
- package/dist/persist/web-storage.d.ts +59 -0
- package/dist/queue/core/forward.util.d.ts +21 -0
- package/dist/queue/core/layers.util.d.ts +13 -0
- package/dist/queue/core/queue.d.ts +66 -0
- package/dist/queue/index.d.ts +7 -0
- package/dist/queue/persist/create-id.util.d.ts +10 -0
- package/dist/queue/persist/hydrate-gate.util.d.ts +9 -0
- package/dist/queue/persist/persist.support.d.ts +19 -0
- package/dist/queue/persist/persist.types.d.ts +23 -0
- package/dist/queue/persist/row-ids.util.d.ts +14 -0
- package/dist/queue/persist/with-row-persist.d.ts +72 -0
- package/dist/queue/persist/with-snapshot-persist.d.ts +45 -0
- package/dist/queue/persist/write-chain.util.d.ts +12 -0
- package/dist/queue/worker/with-worker.d.ts +56 -0
- package/dist/router/index.d.ts +3 -0
- package/dist/router/match.util.d.ts +24 -0
- package/dist/router/router.d.ts +107 -0
- package/dist/worker/index.d.ts +4 -0
- package/dist/worker/pipeline.d.ts +22 -0
- package/dist/worker/retry.d.ts +31 -0
- package/dist/worker/types.d.ts +5 -0
- package/package.json +64 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { StepFn, WorkerFn } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Compose steps into a pipeline (pipe / chain):
|
|
4
|
+
* output of step n is the input of step n+1.
|
|
5
|
+
*
|
|
6
|
+
* Common name: **pipeline** (also pipe, chain).
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* const worker = pipeline(
|
|
10
|
+
* async (id: string) => fetchUser(id),
|
|
11
|
+
* async (user) => enrich(user),
|
|
12
|
+
* async (enriched) => save(enriched),
|
|
13
|
+
* )
|
|
14
|
+
* withWorker(queue, worker)
|
|
15
|
+
*/
|
|
16
|
+
export declare function pipeline<A, B>(s1: StepFn<A, B>): WorkerFn<A, B>;
|
|
17
|
+
export declare function pipeline<A, B, C>(s1: StepFn<A, B>, s2: StepFn<B, C>): WorkerFn<A, C>;
|
|
18
|
+
export declare function pipeline<A, B, C, D>(s1: StepFn<A, B>, s2: StepFn<B, C>, s3: StepFn<C, D>): WorkerFn<A, D>;
|
|
19
|
+
export declare function pipeline<A, B, C, D, E>(s1: StepFn<A, B>, s2: StepFn<B, C>, s3: StepFn<C, D>, s4: StepFn<D, E>): WorkerFn<A, E>;
|
|
20
|
+
export declare function pipeline<A, B, C, D, E, F>(s1: StepFn<A, B>, s2: StepFn<B, C>, s3: StepFn<C, D>, s4: StepFn<D, E>, s5: StepFn<E, F>): WorkerFn<A, F>;
|
|
21
|
+
export declare function pipeline<A, B, C, D, E, F, G>(s1: StepFn<A, B>, s2: StepFn<B, C>, s3: StepFn<C, D>, s4: StepFn<D, E>, s5: StepFn<E, F>, s6: StepFn<F, G>): WorkerFn<A, G>;
|
|
22
|
+
//# sourceMappingURL=pipeline.d.ts.map
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { WorkerFn } from './types';
|
|
2
|
+
export type RetryOptions = {
|
|
3
|
+
/**
|
|
4
|
+
* How many times to retry after the first failure.
|
|
5
|
+
* Total attempts = `retries + 1`.
|
|
6
|
+
*/
|
|
7
|
+
retries: number;
|
|
8
|
+
/**
|
|
9
|
+
* Delay in ms before each retry. Number or function of
|
|
10
|
+
* (failedAttempt, error) where failedAttempt is 1-based.
|
|
11
|
+
*/
|
|
12
|
+
delay?: number | ((failedAttempt: number, error: unknown) => number);
|
|
13
|
+
/** Return false to stop retrying early. Defaults to always retry. */
|
|
14
|
+
shouldRetry?: (error: unknown, failedAttempt: number) => boolean;
|
|
15
|
+
};
|
|
16
|
+
/** Thrown when all retry attempts are exhausted (or `shouldRetry` returns false). */
|
|
17
|
+
export declare class RetryExhaustedError extends Error {
|
|
18
|
+
readonly name = "RetryExhaustedError";
|
|
19
|
+
readonly attempts: number;
|
|
20
|
+
readonly cause: unknown;
|
|
21
|
+
constructor(attempts: number, cause: unknown);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Wrap a worker so failed jobs are retried a fixed number of times.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* const worker = withRetry(async (job) => callApi(job), { retries: 3, delay: 100 })
|
|
28
|
+
* withWorker(queue, worker)
|
|
29
|
+
*/
|
|
30
|
+
export declare const withRetry: <T, R>(worker: WorkerFn<T, R>, options: RetryOptions | number) => WorkerFn<T, R>;
|
|
31
|
+
//# sourceMappingURL=retry.d.ts.map
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** Sync or async unit of work over a single job/item. */
|
|
2
|
+
export type WorkerFn<T, R = unknown> = (item: T) => R | Promise<R>;
|
|
3
|
+
/** Alias used by pipelines — same shape as {@link WorkerFn}. */
|
|
4
|
+
export type StepFn<TIn, TOut = unknown> = WorkerFn<TIn, TOut>;
|
|
5
|
+
//# sourceMappingURL=types.d.ts.map
|
package/package.json
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@qkitt/queue",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "A small, typed FIFO queue toolkit for TypeScript",
|
|
6
|
+
"license": "ISC",
|
|
7
|
+
"author": "eugene-p",
|
|
8
|
+
"keywords": [
|
|
9
|
+
"queue",
|
|
10
|
+
"fifo",
|
|
11
|
+
"worker",
|
|
12
|
+
"retry",
|
|
13
|
+
"pipeline",
|
|
14
|
+
"router",
|
|
15
|
+
"topic",
|
|
16
|
+
"persist",
|
|
17
|
+
"typescript",
|
|
18
|
+
"esm"
|
|
19
|
+
],
|
|
20
|
+
"homepage": "https://github.com/eugene-p/qkitt-queue#readme",
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "git+https://github.com/eugene-p/qkitt-queue.git"
|
|
24
|
+
},
|
|
25
|
+
"bugs": {
|
|
26
|
+
"url": "https://github.com/eugene-p/qkitt-queue/issues"
|
|
27
|
+
},
|
|
28
|
+
"engines": {
|
|
29
|
+
"node": ">=18"
|
|
30
|
+
},
|
|
31
|
+
"sideEffects": false,
|
|
32
|
+
"main": "./dist/index.js",
|
|
33
|
+
"types": "./dist/index.d.ts",
|
|
34
|
+
"exports": {
|
|
35
|
+
".": {
|
|
36
|
+
"types": "./dist/index.d.ts",
|
|
37
|
+
"import": "./dist/index.js",
|
|
38
|
+
"default": "./dist/index.js"
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
"files": [
|
|
42
|
+
"dist/**/*.js",
|
|
43
|
+
"dist/**/*.d.ts",
|
|
44
|
+
"README.md",
|
|
45
|
+
"LICENSE"
|
|
46
|
+
],
|
|
47
|
+
"publishConfig": {
|
|
48
|
+
"access": "public"
|
|
49
|
+
},
|
|
50
|
+
"scripts": {
|
|
51
|
+
"test": "vitest run",
|
|
52
|
+
"typecheck": "tsc --noEmit",
|
|
53
|
+
"build": "tsup && tsc -p tsconfig.build.json",
|
|
54
|
+
"pack:check": "npm pack --dry-run",
|
|
55
|
+
"release:check": "npm run typecheck && npm test && npm run build && npm run pack:check",
|
|
56
|
+
"prepublishOnly": "npm run release:check"
|
|
57
|
+
},
|
|
58
|
+
"devDependencies": {
|
|
59
|
+
"@vitest/coverage-v8": "^4.1.10",
|
|
60
|
+
"tsup": "^8.5.1",
|
|
61
|
+
"typescript": "^7.0.2",
|
|
62
|
+
"vitest": "^4.1.10"
|
|
63
|
+
}
|
|
64
|
+
}
|