@cedarjs/jobs 2.6.0 → 2.6.1-next.104

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.
@@ -1,4 +1,3 @@
1
- import type { PrismaClient } from '@prisma/client';
2
1
  import type { BaseJob } from '../../types.js';
3
2
  import type { BaseAdapterOptions, SchedulePayload, FindArgs, SuccessOptions, ErrorOptions, FailureOptions } from '../BaseAdapter/BaseAdapter.js';
4
3
  import { BaseAdapter } from '../BaseAdapter/BaseAdapter.js';
@@ -14,16 +13,51 @@ export interface PrismaJob extends BaseJob {
14
13
  createdAt: Date;
15
14
  updatedAt: Date;
16
15
  }
17
- export interface PrismaAdapterOptions extends BaseAdapterOptions {
16
+ interface PrismaAdapterDelegate {
17
+ findFirst(args: Record<string, unknown>): Promise<any>;
18
+ updateMany(args: Record<string, unknown>): Promise<{
19
+ count: number;
20
+ }>;
21
+ delete(args: Record<string, unknown>): Promise<unknown>;
22
+ update(args: Record<string, unknown>): Promise<unknown>;
23
+ create(args: Record<string, unknown>): Promise<unknown>;
24
+ deleteMany(args?: Record<string, unknown>): Promise<unknown>;
25
+ }
26
+ interface DelegateLike {
27
+ findFirst: (...args: any[]) => any;
28
+ updateMany: (...args: any[]) => any;
29
+ delete: (...args: any[]) => any;
30
+ update: (...args: any[]) => any;
31
+ create: (...args: any[]) => any;
32
+ deleteMany: (...args: any[]) => any;
33
+ }
34
+ type DelegateKey<TDb extends object> = Extract<{
35
+ [K in keyof TDb]-?: TDb[K] extends DelegateLike ? K : never;
36
+ }[keyof TDb], string>;
37
+ export interface PrismaAdapterOptions<TDb extends object = object> extends BaseAdapterOptions {
18
38
  /**
19
- * An instance of PrismaClient which will be used to talk to the database
39
+ * An instance of PrismaClient which will be used to talk to the database.
40
+ *
41
+ * Typed generically so that `model` below is constrained to the model names
42
+ * that actually exist in the user's schema. When the user passes their typed
43
+ * db instance TypeScript infers TDb as the full generated client, giving
44
+ * autocomplete on model names. `PrismaClient` is only the lower bound — in
45
+ * v7 it may be a stub type, but TDb will still be inferred from the value
46
+ * passed at the call site.
20
47
  */
21
- db: PrismaClient;
48
+ db: TDb;
22
49
  /**
23
- * The name of the model in the Prisma schema that represents the job table.
24
- * @default 'BackgroundJob'
50
+ * The camelCase name of the Prisma model accessor that represents the job
51
+ * table, i.e. the key you'd use on `db` to query it.
52
+ *
53
+ * For a Prisma schema model named `BackgroundJob` this would be
54
+ * `'backgroundJob'` (which is also the default). For a custom model named
55
+ * `Job` this would be `'job'`.
56
+ *
57
+ * @default 'BackgroundJob' for now, but will be 'backgroundJob' in the next
58
+ * major release.
25
59
  */
26
- model?: string;
60
+ model?: DelegateKey<TDb> | string;
27
61
  }
28
62
  /**
29
63
  * Implements a job adapter using Prisma ORM.
@@ -49,12 +83,12 @@ export interface PrismaAdapterOptions extends BaseAdapterOptions {
49
83
  * }
50
84
  * ```
51
85
  */
52
- export declare class PrismaAdapter extends BaseAdapter<PrismaAdapterOptions> {
53
- db: PrismaClient;
54
- model: string;
55
- accessor: PrismaClient[keyof PrismaClient];
86
+ export declare class PrismaAdapter<TDb extends object = object> extends BaseAdapter<PrismaAdapterOptions<TDb>> {
87
+ db: TDb;
88
+ model: DelegateKey<TDb> | string;
89
+ accessor: PrismaAdapterDelegate;
56
90
  provider: string;
57
- constructor(options: PrismaAdapterOptions);
91
+ constructor(options: PrismaAdapterOptions<TDb>);
58
92
  /**
59
93
  * Finds the next job to run, locking it so that no other process can pick it
60
94
  * The act of locking a job is dependant on the DB server, so we'll run some
@@ -68,4 +102,5 @@ export declare class PrismaAdapter extends BaseAdapter<PrismaAdapterOptions> {
68
102
  schedule({ name, path, args, runAt, cron, queue, priority, }: SchedulePayload): Promise<void>;
69
103
  clear(): Promise<void>;
70
104
  }
105
+ export {};
71
106
  //# sourceMappingURL=PrismaAdapter.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"PrismaAdapter.d.ts","sourceRoot":"","sources":["../../../src/adapters/PrismaAdapter/PrismaAdap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AM,CACP,CAAA;AA4CD,MAAM,WAAW,oBAAoB,CACnC,GAAG,SAAS,MAAM,GAAG,MAAM,CAC3B,SAAQ,kBAAkB;IAC1B;;;;;;;;;OASG;IAIH,EAAE,EAAE,GAAG,CAAA;IAEP;;;;;;;;;;OAUG;IAGH,KAAK,CAAC,EAAE,WAAW,CAAC,GAAG,CAAC,GAAG,MAAM,CAAA;CAClC;AAUD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,qBAAa,aAAa,CAAC,GAAG,SAAS,MAAM,GAAG,MAAM,CAAE,SAAQ,WAAW,CACzE,oBAAoB,CAAC,GAAG,CAAC,CAC1B;IACC,EAAE,EAAE,GAAG,CAAA;IACP,KAAK,EAAE,WAAW,CAAC,GAAG,CAAC,GAAG,MAAM,CAAA;IAChC,QAAQ,EAAE,qBAAqB,CAAA;IAC/B,QAAQ,EAAE,MAAM,CAAA;gBAEJ,OAAO,EAAE,oBAAoB,CAAC,GAAG,CAAC;IAuB9C;;;;;OAKG;IACY,IAAI,CAAC,EAClB,WAAW,EACX,UAAU,EACV,MAAM,GACP,EAAE,QAAQ,GAAG,OAAO,CAAC,SAAS,GAAG,SAAS,CAAC;IA6F7B,OAAO,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,SAAS,EAAE,EAAE,cAAc,CAAC,SAAS,CAAC;IAoB5D,KAAK,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,YAAY,CAAC,SAAS,CAAC;IAiBpD,OAAO,CAAC,EAAE,GAAG,EAAE,SAAS,EAAE,EAAE,cAAc,CAAC,SAAS,CAAC;IAYrD,QAAQ,CAAC,EACtB,IAAI,EACJ,IAAI,EACJ,IAAI,EACJ,KAAK,EACL,IAAI,EACJ,KAAK,EACL,QAAQ,GACT,EAAE,eAAe;IAYH,KAAK;CAGrB"}
@@ -25,6 +25,27 @@ var import_change_case = require("change-case");
25
25
  var import_consts = require("../../consts.js");
26
26
  var import_BaseAdapter = require("../BaseAdapter/BaseAdapter.js");
27
27
  var import_errors = require("./errors.js");
28
+ function isPrismaAdapterDelegate(value) {
29
+ const candidate = value;
30
+ return candidate !== null && typeof candidate === "object" && typeof candidate.findFirst === "function" && typeof candidate.updateMany === "function" && typeof candidate.delete === "function" && typeof candidate.update === "function" && typeof candidate.create === "function" && typeof candidate.deleteMany === "function";
31
+ }
32
+ function getDelegate(db, model) {
33
+ const delegate = db[model];
34
+ if (!isPrismaAdapterDelegate(delegate)) {
35
+ throw new import_errors.ModelNameError(model);
36
+ }
37
+ return delegate;
38
+ }
39
+ function getActiveProvider(db) {
40
+ const provider = db._activeProvider;
41
+ if (typeof provider !== "string") {
42
+ console.warn(
43
+ "[CedarJS Jobs] Could not determine Prisma active provider from db._activeProvider. Provider-specific behaviour may not work correctly."
44
+ );
45
+ return "";
46
+ }
47
+ return provider;
48
+ }
28
49
  class PrismaAdapter extends import_BaseAdapter.BaseAdapter {
29
50
  db;
30
51
  model;
@@ -34,11 +55,9 @@ class PrismaAdapter extends import_BaseAdapter.BaseAdapter {
34
55
  super(options);
35
56
  this.db = options.db;
36
57
  this.model = options.model || import_consts.DEFAULT_MODEL_NAME;
37
- this.accessor = this.db[(0, import_change_case.camelCase)(this.model)];
38
- this.provider = options.db._activeProvider;
39
- if (!this.accessor) {
40
- throw new import_errors.ModelNameError(this.model);
41
- }
58
+ const camelName = (0, import_change_case.camelCase)(String(this.model));
59
+ this.accessor = getDelegate(this.db, camelName);
60
+ this.provider = getActiveProvider(options.db);
42
61
  }
43
62
  /**
44
63
  * Finds the next job to run, locking it so that no other process can pick it
@@ -1 +1 @@
1
- {"version":3,"file":"consts.d.ts","sourceRoot":"","sources":["../src/consts.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,oBAAoB,KAAK,CAAA;AACtC,yBAAyB;AACzB,eAAO,MAAM,mBAAmB,QAAS,CAAA;AACzC,gBAAgB;AAChB,eAAO,MAAM,mBAAmB,IAAI,CAAA;AAEpC,eAAO,MAAM,8BAA8B,OA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s/jobs",
3
- "version": "2.6.0",
3
+ "version": "2.6.1-next.104+6be0fa58d",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/cedarjs/cedar.git",
@@ -38,13 +38,13 @@
38
38
  "test:watch": "vitest"
39
39
  },
40
40
  "dependencies": {
41
- "@cedarjs/cli-helpers": "2.6.0",
42
- "@cedarjs/project-config": "2.6.0",
41
+ "@cedarjs/cli-helpers": "2.6.1-next.104+6be0fa58d",
42
+ "@cedarjs/project-config": "2.6.1-next.104+6be0fa58d",
43
43
  "cron-parser": "5.5.0",
44
- "type-fest": "5.4.3"
44
+ "type-fest": "5.4.4"
45
45
  },
46
46
  "devDependencies": {
47
- "@cedarjs/framework-tools": "0.0.0",
47
+ "@cedarjs/framework-tools": "2.6.1-next.104",
48
48
  "@prisma/client": "6.19.2",
49
49
  "concurrently": "9.2.1",
50
50
  "publint": "0.3.17",
@@ -55,5 +55,5 @@
55
55
  "publishConfig": {
56
56
  "access": "public"
57
57
  },
58
- "gitHead": "2e238d88be71ec4ec6b9f329bf9c0fc7f2a069fd"
58
+ "gitHead": "6be0fa58d21ad717026065445aab7117e39ee3eb"
59
59
  }