@clipboard-health/background-jobs-adapter 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/README.md ADDED
@@ -0,0 +1,21 @@
1
+ # @clipboard-health/background-jobs-adapter <!-- omit from toc -->
2
+
3
+ Minimal adapter interface for background jobs operations supporting Mongo and Postgres implementations.
4
+
5
+ ## Table of contents <!-- omit from toc -->
6
+
7
+ - [Install](#install)
8
+ - [Usage](#usage)
9
+ - [Local development commands](#local-development-commands)
10
+
11
+ ## Install
12
+
13
+ ```bash
14
+ npm install @clipboard-health/background-jobs-adapter
15
+ ```
16
+
17
+ ## Usage
18
+
19
+ ## Local development commands
20
+
21
+ See [`package.json`](./package.json) `scripts` for a list of commands.
package/package.json ADDED
@@ -0,0 +1,23 @@
1
+ {
2
+ "name": "@clipboard-health/background-jobs-adapter",
3
+ "description": "Minimal adapter interface for background jobs operations supporting Mongo and Postgres implementations.",
4
+ "version": "0.1.0",
5
+ "bugs": "https://github.com/ClipboardHealth/core-utils/issues",
6
+ "dependencies": {
7
+ "tslib": "2.8.1"
8
+ },
9
+ "keywords": [],
10
+ "license": "MIT",
11
+ "main": "./src/index.js",
12
+ "publishConfig": {
13
+ "access": "public"
14
+ },
15
+ "repository": {
16
+ "directory": "packages/background-jobs-adapter",
17
+ "type": "git",
18
+ "url": "git+https://github.com/ClipboardHealth/core-utils.git"
19
+ },
20
+ "type": "commonjs",
21
+ "typings": "./src/index.d.ts",
22
+ "types": "./src/index.d.ts"
23
+ }
package/src/index.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from "./lib/adapter";
package/src/index.js ADDED
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./lib/adapter"), exports);
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/background-jobs-adapter/src/index.ts"],"names":[],"mappings":";;;AAAA,wDAA8B"}
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Minimal adapter interface for background jobs operations supporting background-jobs-mongo (Mongo)
3
+ * and background-jobs-postgres (Postgres) implementations.
4
+ */
5
+ /**
6
+ * Base handler interface that supports each implementation.
7
+ */
8
+ export interface BaseHandler<T> {
9
+ name?: string;
10
+ perform(data: T, job?: unknown): Promise<unknown>;
11
+ }
12
+ /**
13
+ * Handler class interface that supports each implementation.
14
+ */
15
+ export interface BaseHandlerClass<T> {
16
+ queueName?: string;
17
+ new (...arguments_: never[]): BaseHandler<T>;
18
+ }
19
+ /**
20
+ * Union type for handler class or instance.
21
+ */
22
+ export type HandlerClassOrInstance<T> = BaseHandlerClass<T> | BaseHandler<T>;
23
+ /**
24
+ * Common enqueue options that each implementation supports.
25
+ */
26
+ export interface CommonEnqueueOptions {
27
+ /**
28
+ * When the job should start being processed.
29
+ */
30
+ startAt?: Date;
31
+ /**
32
+ * Database transaction/session to use for atomic job creation.
33
+ * - Mongo: called `session`; ClientSession
34
+ * - Postgres: DatabaseClient (Prisma transaction, pg client, etc.)
35
+ */
36
+ transaction?: unknown;
37
+ /**
38
+ * Unique key for job deduplication
39
+ * - Mongo: called `unique`; string or JobUniqueOptions
40
+ * - Postgres: idempotencyKey
41
+ */
42
+ idempotencyKey?: string | {
43
+ enqueuedKey: string | undefined;
44
+ runningKey: string | undefined;
45
+ };
46
+ }
47
+ /**
48
+ * Minimal adapter interface for background jobs enqueue operations.
49
+ */
50
+ export interface BackgroundJobsAdapter {
51
+ /**
52
+ * Enqueue a job to be processed.
53
+ *
54
+ * @param handler - The handler class or instance that will process the job
55
+ * @param data - The data to be processed by the handler
56
+ * @param options - Optional configuration for the job
57
+ * @returns A promise that resolves to the enqueued job or undefined (implementation-specific)
58
+ */
59
+ enqueue<T extends Record<string, unknown>>(handler: string | HandlerClassOrInstance<T>, data: T, options?: CommonEnqueueOptions): Promise<unknown>;
60
+ }
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ /**
3
+ * Minimal adapter interface for background jobs operations supporting background-jobs-mongo (Mongo)
4
+ * and background-jobs-postgres (Postgres) implementations.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ //# sourceMappingURL=adapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adapter.js","sourceRoot":"","sources":["../../../../../packages/background-jobs-adapter/src/lib/adapter.ts"],"names":[],"mappings":";AAAA;;;GAGG"}