@clipboard-health/background-jobs-adapter 0.1.0 → 0.3.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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@clipboard-health/background-jobs-adapter",
3
3
  "description": "Minimal adapter interface for background jobs operations supporting Mongo and Postgres implementations.",
4
- "version": "0.1.0",
4
+ "version": "0.3.0",
5
5
  "bugs": "https://github.com/ClipboardHealth/core-utils/issues",
6
6
  "dependencies": {
7
7
  "tslib": "2.8.1"
@@ -1,53 +1,60 @@
1
- /**
2
- * Minimal adapter interface for background jobs operations supporting background-jobs-mongo (Mongo)
3
- * and background-jobs-postgres (Postgres) implementations.
4
- */
1
+ export type BackgroundJobsImplementation = "mongo" | "postgres";
2
+ export interface Handler<TData> {
3
+ perform(data: TData, job?: unknown): Promise<string | void>;
4
+ }
5
5
  /**
6
6
  * Base handler interface that supports each implementation.
7
7
  */
8
- export interface BaseHandler<T> {
8
+ export interface BaseHandler<T> extends Handler<T> {
9
9
  name?: string;
10
- perform(data: T, job?: unknown): Promise<unknown>;
11
10
  }
12
11
  /**
13
12
  * Handler class interface that supports each implementation.
14
13
  */
15
14
  export interface BaseHandlerClass<T> {
16
15
  queueName?: string;
17
- new (...arguments_: never[]): BaseHandler<T>;
16
+ new (...arguments_: never[]): Handler<T>;
18
17
  }
19
18
  /**
20
19
  * Union type for handler class or instance.
21
20
  */
22
21
  export type HandlerClassOrInstance<T> = BaseHandlerClass<T> | BaseHandler<T>;
23
- /**
24
- * Common enqueue options that each implementation supports.
25
- */
26
- export interface CommonEnqueueOptions {
22
+ interface WithStartAt {
27
23
  /**
28
24
  * When the job should start being processed.
29
25
  */
30
26
  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 | {
27
+ }
28
+ export interface MongoEnqueueOptions extends WithStartAt {
29
+ session?: unknown;
30
+ unique?: string | {
43
31
  enqueuedKey: string | undefined;
44
32
  runningKey: string | undefined;
45
33
  };
46
34
  }
35
+ export interface PostgresEnqueueOptions extends WithStartAt {
36
+ idempotencyKey?: string;
37
+ transaction?: unknown;
38
+ }
39
+ export declare const ENQUEUE_FIELD_NAMES: {
40
+ readonly mongo: {
41
+ readonly startAt: "startAt";
42
+ readonly transaction: "session";
43
+ readonly idempotencyKey: "unique";
44
+ };
45
+ readonly postgres: {
46
+ readonly startAt: "startAt";
47
+ readonly idempotencyKey: "idempotencyKey";
48
+ readonly transaction: "transaction";
49
+ };
50
+ };
51
+ export type EnqueueOptions = MongoEnqueueOptions | PostgresEnqueueOptions;
47
52
  /**
48
- * Minimal adapter interface for background jobs enqueue operations.
53
+ * Minimal adapter interface for background jobs operations supporting background-jobs-mongo (Mongo)
54
+ * and background-jobs-postgres (Postgres) implementations.
49
55
  */
50
56
  export interface BackgroundJobsAdapter {
57
+ implementation: BackgroundJobsImplementation;
51
58
  /**
52
59
  * Enqueue a job to be processed.
53
60
  *
@@ -56,5 +63,6 @@ export interface BackgroundJobsAdapter {
56
63
  * @param options - Optional configuration for the job
57
64
  * @returns A promise that resolves to the enqueued job or undefined (implementation-specific)
58
65
  */
59
- enqueue<T extends Record<string, unknown>>(handler: string | HandlerClassOrInstance<T>, data: T, options?: CommonEnqueueOptions): Promise<unknown>;
66
+ enqueue<T>(handler: string | HandlerClassOrInstance<T>, data: T, options?: EnqueueOptions): Promise<unknown>;
60
67
  }
68
+ export {};
@@ -1,7 +1,16 @@
1
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ENQUEUE_FIELD_NAMES = void 0;
4
+ exports.ENQUEUE_FIELD_NAMES = {
5
+ mongo: {
6
+ startAt: "startAt",
7
+ transaction: "session",
8
+ idempotencyKey: "unique",
9
+ },
10
+ postgres: {
11
+ startAt: "startAt",
12
+ idempotencyKey: "idempotencyKey",
13
+ transaction: "transaction",
14
+ },
15
+ };
7
16
  //# sourceMappingURL=adapter.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"adapter.js","sourceRoot":"","sources":["../../../../../packages/background-jobs-adapter/src/lib/adapter.ts"],"names":[],"mappings":";AAAA;;;GAGG"}
1
+ {"version":3,"file":"adapter.js","sourceRoot":"","sources":["../../../../../packages/background-jobs-adapter/src/lib/adapter.ts"],"names":[],"mappings":";;;AAsDa,QAAA,mBAAmB,GAAG;IACjC,KAAK,EAAE;QACL,OAAO,EAAE,SAAS;QAClB,WAAW,EAAE,SAAS;QACtB,cAAc,EAAE,QAAQ;KAC2C;IACrE,QAAQ,EAAE;QACR,OAAO,EAAE,SAAS;QAClB,cAAc,EAAE,gBAAgB;QAChC,WAAW,EAAE,aAAa;KAC4C;CAChE,CAAC"}