@payloadcms/drizzle 3.28.0-internal.c4e1bed → 3.28.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.
@@ -0,0 +1,3 @@
1
+ import type { UpdateOne } from 'payload';
2
+ export declare const updateOne: UpdateOne;
3
+ //# sourceMappingURL=update.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"update.d.ts","sourceRoot":"","sources":["../src/update.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAYxC,eAAO,MAAM,SAAS,EAAE,SA8DvB,CAAA"}
package/dist/update.js ADDED
@@ -0,0 +1,71 @@
1
+ import toSnakeCase from 'to-snake-case';
2
+ import { buildFindManyArgs } from './find/buildFindManyArgs.js';
3
+ import buildQuery from './queries/buildQuery.js';
4
+ import { selectDistinct } from './queries/selectDistinct.js';
5
+ import { upsertRow } from './upsertRow/index.js';
6
+ import { getTransaction } from './utilities/getTransaction.js';
7
+ export const updateOne = async function updateOne({ id, collection: collectionSlug, data, joins: joinQuery, locale, req, select, where: whereArg }) {
8
+ const db = await getTransaction(this, req);
9
+ const collection = this.payload.collections[collectionSlug].config;
10
+ const tableName = this.tableNameMap.get(toSnakeCase(collection.slug));
11
+ const whereToUse = whereArg || {
12
+ id: {
13
+ equals: id
14
+ }
15
+ };
16
+ let idToUpdate = id;
17
+ const { joins, selectFields, where } = buildQuery({
18
+ adapter: this,
19
+ fields: collection.flattenedFields,
20
+ locale,
21
+ tableName,
22
+ where: whereToUse
23
+ });
24
+ const selectDistinctResult = await selectDistinct({
25
+ adapter: this,
26
+ chainedMethods: [
27
+ {
28
+ args: [
29
+ 1
30
+ ],
31
+ method: 'limit'
32
+ }
33
+ ],
34
+ db,
35
+ joins,
36
+ selectFields,
37
+ tableName,
38
+ where
39
+ });
40
+ if (selectDistinctResult?.[0]?.id) {
41
+ idToUpdate = selectDistinctResult?.[0]?.id;
42
+ // If id wasn't passed but `where` without any joins, retrieve it with findFirst
43
+ } else if (whereArg && !joins.length) {
44
+ const findManyArgs = buildFindManyArgs({
45
+ adapter: this,
46
+ depth: 0,
47
+ fields: collection.flattenedFields,
48
+ joinQuery: false,
49
+ select: {},
50
+ tableName
51
+ });
52
+ findManyArgs.where = where;
53
+ const docToUpdate = await db.query[tableName].findFirst(findManyArgs);
54
+ idToUpdate = docToUpdate?.id;
55
+ }
56
+ const result = await upsertRow({
57
+ id: idToUpdate,
58
+ adapter: this,
59
+ data,
60
+ db,
61
+ fields: collection.flattenedFields,
62
+ joinQuery,
63
+ operation: 'update',
64
+ req,
65
+ select,
66
+ tableName
67
+ });
68
+ return result;
69
+ };
70
+
71
+ //# sourceMappingURL=update.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/update.ts"],"sourcesContent":["import type { UpdateOne } from 'payload'\n\nimport toSnakeCase from 'to-snake-case'\n\nimport type { DrizzleAdapter } from './types.js'\n\nimport { buildFindManyArgs } from './find/buildFindManyArgs.js'\nimport buildQuery from './queries/buildQuery.js'\nimport { selectDistinct } from './queries/selectDistinct.js'\nimport { upsertRow } from './upsertRow/index.js'\nimport { getTransaction } from './utilities/getTransaction.js'\n\nexport const updateOne: UpdateOne = async function updateOne(\n this: DrizzleAdapter,\n { id, collection: collectionSlug, data, joins: joinQuery, locale, req, select, where: whereArg },\n) {\n const db = await getTransaction(this, req)\n const collection = this.payload.collections[collectionSlug].config\n const tableName = this.tableNameMap.get(toSnakeCase(collection.slug))\n const whereToUse = whereArg || { id: { equals: id } }\n let idToUpdate = id\n\n const { joins, selectFields, where } = buildQuery({\n adapter: this,\n fields: collection.flattenedFields,\n locale,\n tableName,\n where: whereToUse,\n })\n\n const selectDistinctResult = await selectDistinct({\n adapter: this,\n chainedMethods: [{ args: [1], method: 'limit' }],\n db,\n joins,\n selectFields,\n tableName,\n where,\n })\n\n if (selectDistinctResult?.[0]?.id) {\n idToUpdate = selectDistinctResult?.[0]?.id\n\n // If id wasn't passed but `where` without any joins, retrieve it with findFirst\n } else if (whereArg && !joins.length) {\n const findManyArgs = buildFindManyArgs({\n adapter: this,\n depth: 0,\n fields: collection.flattenedFields,\n joinQuery: false,\n select: {},\n tableName,\n })\n\n findManyArgs.where = where\n\n const docToUpdate = await db.query[tableName].findFirst(findManyArgs)\n idToUpdate = docToUpdate?.id\n }\n\n const result = await upsertRow({\n id: idToUpdate,\n adapter: this,\n data,\n db,\n fields: collection.flattenedFields,\n joinQuery,\n operation: 'update',\n req,\n select,\n tableName,\n })\n\n return result\n}\n"],"names":["toSnakeCase","buildFindManyArgs","buildQuery","selectDistinct","upsertRow","getTransaction","updateOne","id","collection","collectionSlug","data","joins","joinQuery","locale","req","select","where","whereArg","db","payload","collections","config","tableName","tableNameMap","get","slug","whereToUse","equals","idToUpdate","selectFields","adapter","fields","flattenedFields","selectDistinctResult","chainedMethods","args","method","length","findManyArgs","depth","docToUpdate","query","findFirst","result","operation"],"mappings":"AAEA,OAAOA,iBAAiB,gBAAe;AAIvC,SAASC,iBAAiB,QAAQ,8BAA6B;AAC/D,OAAOC,gBAAgB,0BAAyB;AAChD,SAASC,cAAc,QAAQ,8BAA6B;AAC5D,SAASC,SAAS,QAAQ,uBAAsB;AAChD,SAASC,cAAc,QAAQ,gCAA+B;AAE9D,OAAO,MAAMC,YAAuB,eAAeA,UAEjD,EAAEC,EAAE,EAAEC,YAAYC,cAAc,EAAEC,IAAI,EAAEC,OAAOC,SAAS,EAAEC,MAAM,EAAEC,GAAG,EAAEC,MAAM,EAAEC,OAAOC,QAAQ,EAAE;IAEhG,MAAMC,KAAK,MAAMb,eAAe,IAAI,EAAES;IACtC,MAAMN,aAAa,IAAI,CAACW,OAAO,CAACC,WAAW,CAACX,eAAe,CAACY,MAAM;IAClE,MAAMC,YAAY,IAAI,CAACC,YAAY,CAACC,GAAG,CAACxB,YAAYQ,WAAWiB,IAAI;IACnE,MAAMC,aAAaT,YAAY;QAAEV,IAAI;YAAEoB,QAAQpB;QAAG;IAAE;IACpD,IAAIqB,aAAarB;IAEjB,MAAM,EAAEI,KAAK,EAAEkB,YAAY,EAAEb,KAAK,EAAE,GAAGd,WAAW;QAChD4B,SAAS,IAAI;QACbC,QAAQvB,WAAWwB,eAAe;QAClCnB;QACAS;QACAN,OAAOU;IACT;IAEA,MAAMO,uBAAuB,MAAM9B,eAAe;QAChD2B,SAAS,IAAI;QACbI,gBAAgB;YAAC;gBAAEC,MAAM;oBAAC;iBAAE;gBAAEC,QAAQ;YAAQ;SAAE;QAChDlB;QACAP;QACAkB;QACAP;QACAN;IACF;IAEA,IAAIiB,sBAAsB,CAAC,EAAE,EAAE1B,IAAI;QACjCqB,aAAaK,sBAAsB,CAAC,EAAE,EAAE1B;IAExC,gFAAgF;IAClF,OAAO,IAAIU,YAAY,CAACN,MAAM0B,MAAM,EAAE;QACpC,MAAMC,eAAerC,kBAAkB;YACrC6B,SAAS,IAAI;YACbS,OAAO;YACPR,QAAQvB,WAAWwB,eAAe;YAClCpB,WAAW;YACXG,QAAQ,CAAC;YACTO;QACF;QAEAgB,aAAatB,KAAK,GAAGA;QAErB,MAAMwB,cAAc,MAAMtB,GAAGuB,KAAK,CAACnB,UAAU,CAACoB,SAAS,CAACJ;QACxDV,aAAaY,aAAajC;IAC5B;IAEA,MAAMoC,SAAS,MAAMvC,UAAU;QAC7BG,IAAIqB;QACJE,SAAS,IAAI;QACbpB;QACAQ;QACAa,QAAQvB,WAAWwB,eAAe;QAClCpB;QACAgC,WAAW;QACX9B;QACAC;QACAO;IACF;IAEA,OAAOqB;AACT,EAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@payloadcms/drizzle",
3
- "version": "3.28.0-internal.c4e1bed",
3
+ "version": "3.28.0",
4
4
  "description": "A library of shared functions used by different payload database adapters",
5
5
  "homepage": "https://payloadcms.com",
6
6
  "repository": {
@@ -52,11 +52,11 @@
52
52
  "@libsql/client": "0.14.0",
53
53
  "@types/pg": "8.10.2",
54
54
  "@types/to-snake-case": "1.0.0",
55
- "@payloadcms/eslint-config": "3.9.0",
56
- "payload": "3.28.0-internal.c4e1bed"
55
+ "payload": "3.28.0",
56
+ "@payloadcms/eslint-config": "3.9.0"
57
57
  },
58
58
  "peerDependencies": {
59
- "payload": "3.28.0-internal.c4e1bed"
59
+ "payload": "3.28.0"
60
60
  },
61
61
  "scripts": {
62
62
  "build": "pnpm build:swc && pnpm build:types",