@payloadcms/drizzle 3.82.0 → 3.83.0-internal.791f423

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 +1 @@
1
- {"version":3,"file":"beginTransaction.d.ts","sourceRoot":"","sources":["../../src/transactions/beginTransaction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAM/C,eAAO,MAAM,gBAAgB,EAAE,gBA2D9B,CAAA"}
1
+ {"version":3,"file":"beginTransaction.d.ts","sourceRoot":"","sources":["../../src/transactions/beginTransaction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAM/C,eAAO,MAAM,gBAAgB,EAAE,gBAgE9B,CAAA"}
@@ -7,6 +7,7 @@ export const beginTransaction = async function beginTransaction(options) {
7
7
  let resolve;
8
8
  let transaction;
9
9
  let transactionReady;
10
+ let transactionFailed;
10
11
  // Await initialization here
11
12
  // Prevent race conditions where the adapter may be
12
13
  // re-initializing, and `this.drizzle` is potentially undefined
@@ -30,12 +31,16 @@ export const beginTransaction = async function beginTransaction(options) {
30
31
  };
31
32
  transactionReady();
32
33
  });
33
- }, options || this.transactionOptions).catch(()=>{
34
- // swallow
34
+ }, options || this.transactionOptions).catch((err)=>{
35
+ // Connection failed before callback ran - reject instead of hanging forever
36
+ transactionFailed(err);
35
37
  });
36
38
  // Need to wait until the transaction is ready
37
39
  // before binding its `resolve` and `reject` methods below
38
- await new Promise((resolve)=>transactionReady = resolve);
40
+ await new Promise((res, rej)=>{
41
+ transactionReady = res;
42
+ transactionFailed = rej;
43
+ });
39
44
  this.sessions[id] = {
40
45
  db: transaction,
41
46
  reject,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/transactions/beginTransaction.ts"],"sourcesContent":["import type { BeginTransaction } from 'payload'\n\nimport { v4 as uuid } from 'uuid'\n\nimport type { DrizzleAdapter, DrizzleTransaction } from '../types.js'\n\nexport const beginTransaction: BeginTransaction = async function beginTransaction(\n this: DrizzleAdapter,\n options: DrizzleAdapter['transactionOptions'],\n) {\n let id\n try {\n id = uuid()\n\n let reject: () => Promise<void>\n let resolve: () => Promise<void>\n let transaction: DrizzleTransaction\n\n let transactionReady: () => void\n\n // Await initialization here\n // Prevent race conditions where the adapter may be\n // re-initializing, and `this.drizzle` is potentially undefined\n await this.initializing\n\n // Drizzle only exposes a transactions API that is sufficient if you\n // can directly pass around the `tx` argument. But our operations are spread\n // over many files and we don't want to pass the `tx` around like that,\n // so instead, we \"lift\" up the `resolve` and `reject` methods\n // and will call them in our respective transaction methods\n const done = this.drizzle\n .transaction(async (tx) => {\n transaction = tx\n await new Promise<void>((res, rej) => {\n resolve = () => {\n res()\n return done\n }\n reject = () => {\n // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors\n rej()\n return done\n }\n transactionReady()\n })\n }, options || this.transactionOptions)\n .catch(() => {\n // swallow\n })\n\n // Need to wait until the transaction is ready\n // before binding its `resolve` and `reject` methods below\n await new Promise<void>((resolve) => (transactionReady = resolve))\n\n this.sessions[id] = {\n db: transaction,\n reject,\n resolve,\n }\n } catch (err) {\n this.payload.logger.error({ err, msg: `Error: cannot begin transaction: ${err.message}` })\n throw new Error(`Error: cannot begin transaction: ${err.message}`)\n }\n\n return id\n}\n"],"names":["v4","uuid","beginTransaction","options","id","reject","resolve","transaction","transactionReady","initializing","done","drizzle","tx","Promise","res","rej","transactionOptions","catch","sessions","db","err","payload","logger","error","msg","message","Error"],"mappings":"AAEA,SAASA,MAAMC,IAAI,QAAQ,OAAM;AAIjC,OAAO,MAAMC,mBAAqC,eAAeA,iBAE/DC,OAA6C;IAE7C,IAAIC;IACJ,IAAI;QACFA,KAAKH;QAEL,IAAII;QACJ,IAAIC;QACJ,IAAIC;QAEJ,IAAIC;QAEJ,4BAA4B;QAC5B,mDAAmD;QACnD,+DAA+D;QAC/D,MAAM,IAAI,CAACC,YAAY;QAEvB,oEAAoE;QACpE,4EAA4E;QAC5E,uEAAuE;QACvE,8DAA8D;QAC9D,2DAA2D;QAC3D,MAAMC,OAAO,IAAI,CAACC,OAAO,CACtBJ,WAAW,CAAC,OAAOK;YAClBL,cAAcK;YACd,MAAM,IAAIC,QAAc,CAACC,KAAKC;gBAC5BT,UAAU;oBACRQ;oBACA,OAAOJ;gBACT;gBACAL,SAAS;oBACP,2EAA2E;oBAC3EU;oBACA,OAAOL;gBACT;gBACAF;YACF;QACF,GAAGL,WAAW,IAAI,CAACa,kBAAkB,EACpCC,KAAK,CAAC;QACL,UAAU;QACZ;QAEF,8CAA8C;QAC9C,0DAA0D;QAC1D,MAAM,IAAIJ,QAAc,CAACP,UAAaE,mBAAmBF;QAEzD,IAAI,CAACY,QAAQ,CAACd,GAAG,GAAG;YAClBe,IAAIZ;YACJF;YACAC;QACF;IACF,EAAE,OAAOc,KAAK;QACZ,IAAI,CAACC,OAAO,CAACC,MAAM,CAACC,KAAK,CAAC;YAAEH;YAAKI,KAAK,CAAC,iCAAiC,EAAEJ,IAAIK,OAAO,EAAE;QAAC;QACxF,MAAM,IAAIC,MAAM,CAAC,iCAAiC,EAAEN,IAAIK,OAAO,EAAE;IACnE;IAEA,OAAOrB;AACT,EAAC"}
1
+ {"version":3,"sources":["../../src/transactions/beginTransaction.ts"],"sourcesContent":["import type { BeginTransaction } from 'payload'\n\nimport { v4 as uuid } from 'uuid'\n\nimport type { DrizzleAdapter, DrizzleTransaction } from '../types.js'\n\nexport const beginTransaction: BeginTransaction = async function beginTransaction(\n this: DrizzleAdapter,\n options: DrizzleAdapter['transactionOptions'],\n) {\n let id\n try {\n id = uuid()\n\n let reject: () => Promise<void>\n let resolve: () => Promise<void>\n let transaction: DrizzleTransaction\n\n let transactionReady: () => void\n let transactionFailed: (err: unknown) => void\n\n // Await initialization here\n // Prevent race conditions where the adapter may be\n // re-initializing, and `this.drizzle` is potentially undefined\n await this.initializing\n\n // Drizzle only exposes a transactions API that is sufficient if you\n // can directly pass around the `tx` argument. But our operations are spread\n // over many files and we don't want to pass the `tx` around like that,\n // so instead, we \"lift\" up the `resolve` and `reject` methods\n // and will call them in our respective transaction methods\n const done = this.drizzle\n .transaction(async (tx) => {\n transaction = tx\n await new Promise<void>((res, rej) => {\n resolve = () => {\n res()\n return done\n }\n reject = () => {\n // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors\n rej()\n return done\n }\n transactionReady()\n })\n }, options || this.transactionOptions)\n .catch((err) => {\n // Connection failed before callback ran - reject instead of hanging forever\n transactionFailed(err)\n })\n\n // Need to wait until the transaction is ready\n // before binding its `resolve` and `reject` methods below\n await new Promise<void>((res, rej) => {\n transactionReady = res\n transactionFailed = rej\n })\n\n this.sessions[id] = {\n db: transaction,\n reject,\n resolve,\n }\n } catch (err) {\n this.payload.logger.error({ err, msg: `Error: cannot begin transaction: ${err.message}` })\n throw new Error(`Error: cannot begin transaction: ${err.message}`)\n }\n\n return id\n}\n"],"names":["v4","uuid","beginTransaction","options","id","reject","resolve","transaction","transactionReady","transactionFailed","initializing","done","drizzle","tx","Promise","res","rej","transactionOptions","catch","err","sessions","db","payload","logger","error","msg","message","Error"],"mappings":"AAEA,SAASA,MAAMC,IAAI,QAAQ,OAAM;AAIjC,OAAO,MAAMC,mBAAqC,eAAeA,iBAE/DC,OAA6C;IAE7C,IAAIC;IACJ,IAAI;QACFA,KAAKH;QAEL,IAAII;QACJ,IAAIC;QACJ,IAAIC;QAEJ,IAAIC;QACJ,IAAIC;QAEJ,4BAA4B;QAC5B,mDAAmD;QACnD,+DAA+D;QAC/D,MAAM,IAAI,CAACC,YAAY;QAEvB,oEAAoE;QACpE,4EAA4E;QAC5E,uEAAuE;QACvE,8DAA8D;QAC9D,2DAA2D;QAC3D,MAAMC,OAAO,IAAI,CAACC,OAAO,CACtBL,WAAW,CAAC,OAAOM;YAClBN,cAAcM;YACd,MAAM,IAAIC,QAAc,CAACC,KAAKC;gBAC5BV,UAAU;oBACRS;oBACA,OAAOJ;gBACT;gBACAN,SAAS;oBACP,2EAA2E;oBAC3EW;oBACA,OAAOL;gBACT;gBACAH;YACF;QACF,GAAGL,WAAW,IAAI,CAACc,kBAAkB,EACpCC,KAAK,CAAC,CAACC;YACN,4EAA4E;YAC5EV,kBAAkBU;QACpB;QAEF,8CAA8C;QAC9C,0DAA0D;QAC1D,MAAM,IAAIL,QAAc,CAACC,KAAKC;YAC5BR,mBAAmBO;YACnBN,oBAAoBO;QACtB;QAEA,IAAI,CAACI,QAAQ,CAAChB,GAAG,GAAG;YAClBiB,IAAId;YACJF;YACAC;QACF;IACF,EAAE,OAAOa,KAAK;QACZ,IAAI,CAACG,OAAO,CAACC,MAAM,CAACC,KAAK,CAAC;YAAEL;YAAKM,KAAK,CAAC,iCAAiC,EAAEN,IAAIO,OAAO,EAAE;QAAC;QACxF,MAAM,IAAIC,MAAM,CAAC,iCAAiC,EAAER,IAAIO,OAAO,EAAE;IACnE;IAEA,OAAOtB;AACT,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"updateJobs.d.ts","sourceRoot":"","sources":["../src/updateJobs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAS,MAAM,SAAS,CAAA;AAYhD,eAAO,MAAM,UAAU,EAAE,UA2FxB,CAAA"}
1
+ {"version":3,"file":"updateJobs.d.ts","sourceRoot":"","sources":["../src/updateJobs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAS,MAAM,SAAS,CAAA;AAYhD,eAAO,MAAM,UAAU,EAAE,UA2IxB,CAAA"}
@@ -4,7 +4,17 @@ import { upsertRow } from './upsertRow/index.js';
4
4
  import { shouldUseOptimizedUpsertRow } from './upsertRow/shouldUseOptimizedUpsertRow.js';
5
5
  import { getPrimaryDb } from './utilities/getPrimaryDb.js';
6
6
  import { getTransaction } from './utilities/getTransaction.js';
7
- export const updateJobs = async function updateMany({ id, data, limit: limitArg, req, returning, sort: sortArg, where: whereArg }) {
7
+ export const updateJobs = async function updateMany({ id, data, debugID, limit: limitArg, req, returning, sort: sortArg, where: whereArg }) {
8
+ const prefix = debugID ? `[${debugID}] drizzle.updateJobs` : null;
9
+ const t0 = prefix ? Date.now() : 0;
10
+ if (prefix) {
11
+ console.log(`${prefix} - enter`, {
12
+ id,
13
+ limit: limitArg,
14
+ returning,
15
+ sort: sortArg
16
+ });
17
+ }
8
18
  if (!data?.log?.length && !(data.log && typeof data.log === 'object' && '$push' in data.log)) {
9
19
  delete data.log;
10
20
  }
@@ -21,8 +31,16 @@ export const updateJobs = async function updateMany({ id, data, limit: limitArg,
21
31
  data,
22
32
  fields: collection.flattenedFields
23
33
  });
34
+ if (prefix) {
35
+ console.log(`${prefix} - useOptimizedUpsertRow: ${useOptimizedUpsertRow}, tableName: ${tableName}`);
36
+ }
24
37
  if (useOptimizedUpsertRow && id) {
25
38
  const db = getPrimaryDb(this, await getTransaction(this, req));
39
+ let ts = Date.now();
40
+ if (prefix) {
41
+ console.log(`${prefix} - getTransaction (optimized path) took ${Date.now() - ts}ms`);
42
+ }
43
+ ts = Date.now();
26
44
  const result = await upsertRow({
27
45
  id,
28
46
  adapter: this,
@@ -35,10 +53,21 @@ export const updateJobs = async function updateMany({ id, data, limit: limitArg,
35
53
  req,
36
54
  tableName
37
55
  });
56
+ if (prefix) {
57
+ console.log(`${prefix} - upsertRow (optimized, single) took ${Date.now() - ts}ms, total ${Date.now() - t0}ms`);
58
+ }
38
59
  return returning === false ? null : [
39
60
  result
40
61
  ];
41
62
  }
63
+ let ts = prefix ? Date.now() : 0;
64
+ if (prefix) {
65
+ console.log(`${prefix} - calling findMany`, {
66
+ limit: id ? 1 : limit,
67
+ sort,
68
+ where: whereToUse
69
+ });
70
+ }
42
71
  const jobs = await findMany({
43
72
  adapter: this,
44
73
  collectionSlug: 'payload-jobs',
@@ -50,17 +79,28 @@ export const updateJobs = async function updateMany({ id, data, limit: limitArg,
50
79
  tableName,
51
80
  where: whereToUse
52
81
  });
82
+ if (prefix) {
83
+ console.log(`${prefix} - findMany took ${Date.now() - ts}ms, found ${jobs.docs.length} docs`);
84
+ }
53
85
  if (!jobs.docs.length) {
86
+ if (prefix) {
87
+ console.log(`${prefix} - no docs found, returning [], total ${Date.now() - t0}ms`);
88
+ }
54
89
  return [];
55
90
  }
91
+ ts = prefix ? Date.now() : 0;
56
92
  const db = await getTransaction(this, req);
93
+ if (prefix) {
94
+ console.log(`${prefix} - getTransaction took ${Date.now() - ts}ms`);
95
+ }
57
96
  const results = [];
58
- // TODO: We need to batch this to reduce the amount of db calls. This can get very slow if we are updating a lot of rows.
59
- for (const job of jobs.docs){
97
+ for(let i = 0; i < jobs.docs.length; i++){
98
+ const job = jobs.docs[i];
60
99
  const updateData = useOptimizedUpsertRow ? data : {
61
100
  ...job,
62
101
  ...data
63
102
  };
103
+ ts = prefix ? Date.now() : 0;
64
104
  const result = await upsertRow({
65
105
  id: job.id,
66
106
  adapter: this,
@@ -73,8 +113,14 @@ export const updateJobs = async function updateMany({ id, data, limit: limitArg,
73
113
  req,
74
114
  tableName
75
115
  });
116
+ if (prefix) {
117
+ console.log(`${prefix} - upsertRow [${i + 1}/${jobs.docs.length}] id=${job.id} took ${Date.now() - ts}ms`);
118
+ }
76
119
  results.push(result);
77
120
  }
121
+ if (prefix) {
122
+ console.log(`${prefix} - all upserts done, total ${Date.now() - t0}ms`);
123
+ }
78
124
  if (returning === false) {
79
125
  return null;
80
126
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/updateJobs.ts"],"sourcesContent":["import type { UpdateJobs, Where } from 'payload'\n\nimport toSnakeCase from 'to-snake-case'\n\nimport type { DrizzleAdapter } from './types.js'\n\nimport { findMany } from './find/findMany.js'\nimport { upsertRow } from './upsertRow/index.js'\nimport { shouldUseOptimizedUpsertRow } from './upsertRow/shouldUseOptimizedUpsertRow.js'\nimport { getPrimaryDb } from './utilities/getPrimaryDb.js'\nimport { getTransaction } from './utilities/getTransaction.js'\n\nexport const updateJobs: UpdateJobs = async function updateMany(\n this: DrizzleAdapter,\n { id, data, limit: limitArg, req, returning, sort: sortArg, where: whereArg },\n) {\n if (\n !(data?.log as object[])?.length &&\n !(data.log && typeof data.log === 'object' && '$push' in data.log)\n ) {\n delete data.log\n }\n\n const whereToUse: Where = id ? { id: { equals: id } } : whereArg\n const limit = id ? 1 : limitArg\n\n const collection = this.payload.collections['payload-jobs'].config\n const tableName = this.tableNameMap.get(toSnakeCase(collection.slug))\n const sort = sortArg !== undefined && sortArg !== null ? sortArg : collection.defaultSort\n\n const useOptimizedUpsertRow = shouldUseOptimizedUpsertRow({\n data,\n fields: collection.flattenedFields,\n })\n\n if (useOptimizedUpsertRow && id) {\n const db = getPrimaryDb(this, await getTransaction(this, req))\n\n const result = await upsertRow({\n id,\n adapter: this,\n collectionSlug: 'payload-jobs',\n data,\n db,\n fields: collection.flattenedFields,\n ignoreResult: returning === false,\n operation: 'update',\n req,\n tableName,\n })\n\n return returning === false ? null : [result]\n }\n\n const jobs = await findMany({\n adapter: this,\n collectionSlug: 'payload-jobs',\n fields: collection.flattenedFields,\n limit: id ? 1 : limit,\n pagination: false,\n req,\n sort,\n tableName,\n where: whereToUse,\n })\n if (!jobs.docs.length) {\n return []\n }\n\n const db = await getTransaction(this, req)\n\n const results = []\n\n // TODO: We need to batch this to reduce the amount of db calls. This can get very slow if we are updating a lot of rows.\n for (const job of jobs.docs) {\n const updateData = useOptimizedUpsertRow\n ? data\n : {\n ...job,\n ...data,\n }\n\n const result = await upsertRow({\n id: job.id,\n adapter: this,\n collectionSlug: 'payload-jobs',\n data: updateData,\n db,\n fields: collection.flattenedFields,\n ignoreResult: returning === false,\n operation: 'update',\n req,\n tableName,\n })\n\n results.push(result)\n }\n\n if (returning === false) {\n return null\n }\n\n return results\n}\n"],"names":["toSnakeCase","findMany","upsertRow","shouldUseOptimizedUpsertRow","getPrimaryDb","getTransaction","updateJobs","updateMany","id","data","limit","limitArg","req","returning","sort","sortArg","where","whereArg","log","length","whereToUse","equals","collection","payload","collections","config","tableName","tableNameMap","get","slug","undefined","defaultSort","useOptimizedUpsertRow","fields","flattenedFields","db","result","adapter","collectionSlug","ignoreResult","operation","jobs","pagination","docs","results","job","updateData","push"],"mappings":"AAEA,OAAOA,iBAAiB,gBAAe;AAIvC,SAASC,QAAQ,QAAQ,qBAAoB;AAC7C,SAASC,SAAS,QAAQ,uBAAsB;AAChD,SAASC,2BAA2B,QAAQ,6CAA4C;AACxF,SAASC,YAAY,QAAQ,8BAA6B;AAC1D,SAASC,cAAc,QAAQ,gCAA+B;AAE9D,OAAO,MAAMC,aAAyB,eAAeC,WAEnD,EAAEC,EAAE,EAAEC,IAAI,EAAEC,OAAOC,QAAQ,EAAEC,GAAG,EAAEC,SAAS,EAAEC,MAAMC,OAAO,EAAEC,OAAOC,QAAQ,EAAE;IAE7E,IACE,CAAER,MAAMS,KAAkBC,UAC1B,CAAEV,CAAAA,KAAKS,GAAG,IAAI,OAAOT,KAAKS,GAAG,KAAK,YAAY,WAAWT,KAAKS,GAAG,AAAD,GAChE;QACA,OAAOT,KAAKS,GAAG;IACjB;IAEA,MAAME,aAAoBZ,KAAK;QAAEA,IAAI;YAAEa,QAAQb;QAAG;IAAE,IAAIS;IACxD,MAAMP,QAAQF,KAAK,IAAIG;IAEvB,MAAMW,aAAa,IAAI,CAACC,OAAO,CAACC,WAAW,CAAC,eAAe,CAACC,MAAM;IAClE,MAAMC,YAAY,IAAI,CAACC,YAAY,CAACC,GAAG,CAAC5B,YAAYsB,WAAWO,IAAI;IACnE,MAAMf,OAAOC,YAAYe,aAAaf,YAAY,OAAOA,UAAUO,WAAWS,WAAW;IAEzF,MAAMC,wBAAwB7B,4BAA4B;QACxDM;QACAwB,QAAQX,WAAWY,eAAe;IACpC;IAEA,IAAIF,yBAAyBxB,IAAI;QAC/B,MAAM2B,KAAK/B,aAAa,IAAI,EAAE,MAAMC,eAAe,IAAI,EAAEO;QAEzD,MAAMwB,SAAS,MAAMlC,UAAU;YAC7BM;YACA6B,SAAS,IAAI;YACbC,gBAAgB;YAChB7B;YACA0B;YACAF,QAAQX,WAAWY,eAAe;YAClCK,cAAc1B,cAAc;YAC5B2B,WAAW;YACX5B;YACAc;QACF;QAEA,OAAOb,cAAc,QAAQ,OAAO;YAACuB;SAAO;IAC9C;IAEA,MAAMK,OAAO,MAAMxC,SAAS;QAC1BoC,SAAS,IAAI;QACbC,gBAAgB;QAChBL,QAAQX,WAAWY,eAAe;QAClCxB,OAAOF,KAAK,IAAIE;QAChBgC,YAAY;QACZ9B;QACAE;QACAY;QACAV,OAAOI;IACT;IACA,IAAI,CAACqB,KAAKE,IAAI,CAACxB,MAAM,EAAE;QACrB,OAAO,EAAE;IACX;IAEA,MAAMgB,KAAK,MAAM9B,eAAe,IAAI,EAAEO;IAEtC,MAAMgC,UAAU,EAAE;IAElB,yHAAyH;IACzH,KAAK,MAAMC,OAAOJ,KAAKE,IAAI,CAAE;QAC3B,MAAMG,aAAad,wBACfvB,OACA;YACE,GAAGoC,GAAG;YACN,GAAGpC,IAAI;QACT;QAEJ,MAAM2B,SAAS,MAAMlC,UAAU;YAC7BM,IAAIqC,IAAIrC,EAAE;YACV6B,SAAS,IAAI;YACbC,gBAAgB;YAChB7B,MAAMqC;YACNX;YACAF,QAAQX,WAAWY,eAAe;YAClCK,cAAc1B,cAAc;YAC5B2B,WAAW;YACX5B;YACAc;QACF;QAEAkB,QAAQG,IAAI,CAACX;IACf;IAEA,IAAIvB,cAAc,OAAO;QACvB,OAAO;IACT;IAEA,OAAO+B;AACT,EAAC"}
1
+ {"version":3,"sources":["../src/updateJobs.ts"],"sourcesContent":["import type { UpdateJobs, Where } from 'payload'\n\nimport toSnakeCase from 'to-snake-case'\n\nimport type { DrizzleAdapter } from './types.js'\n\nimport { findMany } from './find/findMany.js'\nimport { upsertRow } from './upsertRow/index.js'\nimport { shouldUseOptimizedUpsertRow } from './upsertRow/shouldUseOptimizedUpsertRow.js'\nimport { getPrimaryDb } from './utilities/getPrimaryDb.js'\nimport { getTransaction } from './utilities/getTransaction.js'\n\nexport const updateJobs: UpdateJobs = async function updateMany(\n this: DrizzleAdapter,\n { id, data, debugID, limit: limitArg, req, returning, sort: sortArg, where: whereArg },\n) {\n const prefix = debugID ? `[${debugID}] drizzle.updateJobs` : null\n const t0 = prefix ? Date.now() : 0\n\n if (prefix) {\n console.log(`${prefix} - enter`, { id, limit: limitArg, returning, sort: sortArg })\n }\n\n if (\n !(data?.log as object[])?.length &&\n !(data.log && typeof data.log === 'object' && '$push' in data.log)\n ) {\n delete data.log\n }\n\n const whereToUse: Where = id ? { id: { equals: id } } : whereArg\n const limit = id ? 1 : limitArg\n\n const collection = this.payload.collections['payload-jobs'].config\n const tableName = this.tableNameMap.get(toSnakeCase(collection.slug))\n const sort = sortArg !== undefined && sortArg !== null ? sortArg : collection.defaultSort\n\n const useOptimizedUpsertRow = shouldUseOptimizedUpsertRow({\n data,\n fields: collection.flattenedFields,\n })\n\n if (prefix) {\n console.log(\n `${prefix} - useOptimizedUpsertRow: ${useOptimizedUpsertRow}, tableName: ${tableName}`,\n )\n }\n\n if (useOptimizedUpsertRow && id) {\n const db = getPrimaryDb(this, await getTransaction(this, req))\n\n let ts = Date.now()\n if (prefix) {\n console.log(`${prefix} - getTransaction (optimized path) took ${Date.now() - ts}ms`)\n }\n\n ts = Date.now()\n const result = await upsertRow({\n id,\n adapter: this,\n collectionSlug: 'payload-jobs',\n data,\n db,\n fields: collection.flattenedFields,\n ignoreResult: returning === false,\n operation: 'update',\n req,\n tableName,\n })\n if (prefix) {\n console.log(\n `${prefix} - upsertRow (optimized, single) took ${Date.now() - ts}ms, total ${Date.now() - t0}ms`,\n )\n }\n\n return returning === false ? null : [result]\n }\n\n let ts = prefix ? Date.now() : 0\n if (prefix) {\n console.log(`${prefix} - calling findMany`, { limit: id ? 1 : limit, sort, where: whereToUse })\n }\n const jobs = await findMany({\n adapter: this,\n collectionSlug: 'payload-jobs',\n fields: collection.flattenedFields,\n limit: id ? 1 : limit,\n pagination: false,\n req,\n sort,\n tableName,\n where: whereToUse,\n })\n if (prefix) {\n console.log(`${prefix} - findMany took ${Date.now() - ts}ms, found ${jobs.docs.length} docs`)\n }\n if (!jobs.docs.length) {\n if (prefix) {\n console.log(`${prefix} - no docs found, returning [], total ${Date.now() - t0}ms`)\n }\n return []\n }\n\n ts = prefix ? Date.now() : 0\n const db = await getTransaction(this, req)\n if (prefix) {\n console.log(`${prefix} - getTransaction took ${Date.now() - ts}ms`)\n }\n\n const results = []\n\n for (let i = 0; i < jobs.docs.length; i++) {\n const job = jobs.docs[i]\n const updateData = useOptimizedUpsertRow\n ? data\n : {\n ...job,\n ...data,\n }\n\n ts = prefix ? Date.now() : 0\n const result = await upsertRow({\n id: job.id,\n adapter: this,\n collectionSlug: 'payload-jobs',\n data: updateData,\n db,\n fields: collection.flattenedFields,\n ignoreResult: returning === false,\n operation: 'update',\n req,\n tableName,\n })\n if (prefix) {\n console.log(\n `${prefix} - upsertRow [${i + 1}/${jobs.docs.length}] id=${job.id} took ${Date.now() - ts}ms`,\n )\n }\n\n results.push(result)\n }\n\n if (prefix) {\n console.log(`${prefix} - all upserts done, total ${Date.now() - t0}ms`)\n }\n\n if (returning === false) {\n return null\n }\n\n return results\n}\n"],"names":["toSnakeCase","findMany","upsertRow","shouldUseOptimizedUpsertRow","getPrimaryDb","getTransaction","updateJobs","updateMany","id","data","debugID","limit","limitArg","req","returning","sort","sortArg","where","whereArg","prefix","t0","Date","now","console","log","length","whereToUse","equals","collection","payload","collections","config","tableName","tableNameMap","get","slug","undefined","defaultSort","useOptimizedUpsertRow","fields","flattenedFields","db","ts","result","adapter","collectionSlug","ignoreResult","operation","jobs","pagination","docs","results","i","job","updateData","push"],"mappings":"AAEA,OAAOA,iBAAiB,gBAAe;AAIvC,SAASC,QAAQ,QAAQ,qBAAoB;AAC7C,SAASC,SAAS,QAAQ,uBAAsB;AAChD,SAASC,2BAA2B,QAAQ,6CAA4C;AACxF,SAASC,YAAY,QAAQ,8BAA6B;AAC1D,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@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@payloadcms/drizzle",
3
- "version": "3.82.0",
3
+ "version": "3.83.0-internal.791f423",
4
4
  "description": "A library of shared functions used by different payload database adapters",
5
5
  "homepage": "https://payloadcms.com",
6
6
  "repository": {
@@ -60,10 +60,10 @@
60
60
  "@types/pg": "8.10.2",
61
61
  "@types/to-snake-case": "1.0.0",
62
62
  "@payloadcms/eslint-config": "3.28.0",
63
- "payload": "3.82.0"
63
+ "payload": "3.83.0-internal.791f423"
64
64
  },
65
65
  "peerDependencies": {
66
- "payload": "3.82.0"
66
+ "payload": "3.83.0-internal.791f423"
67
67
  },
68
68
  "scripts": {
69
69
  "build": "pnpm build:swc && pnpm build:types",