@payloadcms/drizzle 3.26.0 → 3.27.0-canary.7edf702
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/dist/create.js +3 -3
- package/dist/create.js.map +1 -1
- package/dist/createGlobal.js +2 -2
- package/dist/createGlobal.js.map +1 -1
- package/dist/createGlobalVersion.d.ts +1 -1
- package/dist/createGlobalVersion.d.ts.map +1 -1
- package/dist/createGlobalVersion.js +3 -3
- package/dist/createGlobalVersion.js.map +1 -1
- package/dist/createVersion.d.ts +1 -1
- package/dist/createVersion.d.ts.map +1 -1
- package/dist/createVersion.js +1 -1
- package/dist/createVersion.js.map +1 -1
- package/dist/deleteOne.js +1 -1
- package/dist/deleteOne.js.map +1 -1
- package/dist/updateGlobal.d.ts +1 -1
- package/dist/updateGlobal.d.ts.map +1 -1
- package/dist/updateGlobal.js +3 -3
- package/dist/updateGlobal.js.map +1 -1
- package/dist/updateGlobalVersion.d.ts +1 -1
- package/dist/updateGlobalVersion.d.ts.map +1 -1
- package/dist/updateGlobalVersion.js +3 -3
- package/dist/updateGlobalVersion.js.map +1 -1
- package/dist/updateOne.js +3 -3
- package/dist/updateOne.js.map +1 -1
- package/dist/updateVersion.d.ts +1 -1
- package/dist/updateVersion.d.ts.map +1 -1
- package/dist/updateVersion.js +3 -3
- package/dist/updateVersion.js.map +1 -1
- package/dist/upsertRow/types.d.ts +1 -1
- package/dist/upsertRow/types.d.ts.map +1 -1
- package/dist/upsertRow/types.js.map +1 -1
- package/package.json +3 -3
- package/dist/update.d.ts +0 -3
- package/dist/update.d.ts.map +0 -1
- package/dist/update.js +0 -71
- package/dist/update.js.map +0 -1
package/dist/create.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import toSnakeCase from 'to-snake-case';
|
|
2
2
|
import { upsertRow } from './upsertRow/index.js';
|
|
3
3
|
import { getTransaction } from './utilities/getTransaction.js';
|
|
4
|
-
export const create = async function create({ collection: collectionSlug, data, req,
|
|
4
|
+
export const create = async function create({ collection: collectionSlug, data, req, returning, select }) {
|
|
5
5
|
const db = await getTransaction(this, req);
|
|
6
6
|
const collection = this.payload.collections[collectionSlug].config;
|
|
7
7
|
const tableName = this.tableNameMap.get(toSnakeCase(collection.slug));
|
|
@@ -10,11 +10,11 @@ export const create = async function create({ collection: collectionSlug, data,
|
|
|
10
10
|
data,
|
|
11
11
|
db,
|
|
12
12
|
fields: collection.flattenedFields,
|
|
13
|
+
ignoreResult: returning === false,
|
|
13
14
|
operation: 'create',
|
|
14
15
|
req,
|
|
15
16
|
select,
|
|
16
|
-
tableName
|
|
17
|
-
ignoreResult: returning === false
|
|
17
|
+
tableName
|
|
18
18
|
});
|
|
19
19
|
if (returning === false) {
|
|
20
20
|
return null;
|
package/dist/create.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/create.ts"],"sourcesContent":["import type { Create } from 'payload'\n\nimport toSnakeCase from 'to-snake-case'\n\nimport type { DrizzleAdapter } from './types.js'\n\nimport { upsertRow } from './upsertRow/index.js'\nimport { getTransaction } from './utilities/getTransaction.js'\n\nexport const create: Create = async function create(\n this: DrizzleAdapter,\n { collection: collectionSlug, data, req,
|
|
1
|
+
{"version":3,"sources":["../src/create.ts"],"sourcesContent":["import type { Create } from 'payload'\n\nimport toSnakeCase from 'to-snake-case'\n\nimport type { DrizzleAdapter } from './types.js'\n\nimport { upsertRow } from './upsertRow/index.js'\nimport { getTransaction } from './utilities/getTransaction.js'\n\nexport const create: Create = async function create(\n this: DrizzleAdapter,\n { collection: collectionSlug, data, req, returning, select },\n) {\n const db = await getTransaction(this, req)\n const collection = this.payload.collections[collectionSlug].config\n\n const tableName = this.tableNameMap.get(toSnakeCase(collection.slug))\n\n const result = await upsertRow({\n adapter: this,\n data,\n db,\n fields: collection.flattenedFields,\n ignoreResult: returning === false,\n operation: 'create',\n req,\n select,\n tableName,\n })\n\n if (returning === false) {\n return null\n }\n\n return result\n}\n"],"names":["toSnakeCase","upsertRow","getTransaction","create","collection","collectionSlug","data","req","returning","select","db","payload","collections","config","tableName","tableNameMap","get","slug","result","adapter","fields","flattenedFields","ignoreResult","operation"],"mappings":"AAEA,OAAOA,iBAAiB,gBAAe;AAIvC,SAASC,SAAS,QAAQ,uBAAsB;AAChD,SAASC,cAAc,QAAQ,gCAA+B;AAE9D,OAAO,MAAMC,SAAiB,eAAeA,OAE3C,EAAEC,YAAYC,cAAc,EAAEC,IAAI,EAAEC,GAAG,EAAEC,SAAS,EAAEC,MAAM,EAAE;IAE5D,MAAMC,KAAK,MAAMR,eAAe,IAAI,EAAEK;IACtC,MAAMH,aAAa,IAAI,CAACO,OAAO,CAACC,WAAW,CAACP,eAAe,CAACQ,MAAM;IAElE,MAAMC,YAAY,IAAI,CAACC,YAAY,CAACC,GAAG,CAAChB,YAAYI,WAAWa,IAAI;IAEnE,MAAMC,SAAS,MAAMjB,UAAU;QAC7BkB,SAAS,IAAI;QACbb;QACAI;QACAU,QAAQhB,WAAWiB,eAAe;QAClCC,cAAcd,cAAc;QAC5Be,WAAW;QACXhB;QACAE;QACAK;IACF;IAEA,IAAIN,cAAc,OAAO;QACvB,OAAO;IACT;IAEA,OAAOU;AACT,EAAC"}
|
package/dist/createGlobal.js
CHANGED
|
@@ -11,10 +11,10 @@ export async function createGlobal({ slug, data, req, returning }) {
|
|
|
11
11
|
data,
|
|
12
12
|
db,
|
|
13
13
|
fields: globalConfig.flattenedFields,
|
|
14
|
+
ignoreResult: returning === false,
|
|
14
15
|
operation: 'create',
|
|
15
16
|
req,
|
|
16
|
-
tableName
|
|
17
|
-
ignoreResult: returning === false
|
|
17
|
+
tableName
|
|
18
18
|
});
|
|
19
19
|
if (returning === false) {
|
|
20
20
|
return null;
|
package/dist/createGlobal.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/createGlobal.ts"],"sourcesContent":["import type { CreateGlobalArgs } from 'payload'\n\nimport toSnakeCase from 'to-snake-case'\n\nimport type { DrizzleAdapter } from './types.js'\n\nimport { upsertRow } from './upsertRow/index.js'\nimport { getTransaction } from './utilities/getTransaction.js'\n\nexport async function createGlobal<T extends Record<string, unknown>>(\n this: DrizzleAdapter,\n { slug, data, req, returning }: CreateGlobalArgs,\n): Promise<T> {\n const db = await getTransaction(this, req)\n const globalConfig = this.payload.globals.config.find((config) => config.slug === slug)\n\n const tableName = this.tableNameMap.get(toSnakeCase(globalConfig.slug))\n\n data.createdAt = new Date().toISOString()\n\n const result = await upsertRow<{ globalType: string } & T>({\n adapter: this,\n data,\n db,\n fields: globalConfig.flattenedFields,\n operation: 'create',\n req,\n tableName,\n
|
|
1
|
+
{"version":3,"sources":["../src/createGlobal.ts"],"sourcesContent":["import type { CreateGlobalArgs } from 'payload'\n\nimport toSnakeCase from 'to-snake-case'\n\nimport type { DrizzleAdapter } from './types.js'\n\nimport { upsertRow } from './upsertRow/index.js'\nimport { getTransaction } from './utilities/getTransaction.js'\n\nexport async function createGlobal<T extends Record<string, unknown>>(\n this: DrizzleAdapter,\n { slug, data, req, returning }: CreateGlobalArgs,\n): Promise<T> {\n const db = await getTransaction(this, req)\n const globalConfig = this.payload.globals.config.find((config) => config.slug === slug)\n\n const tableName = this.tableNameMap.get(toSnakeCase(globalConfig.slug))\n\n data.createdAt = new Date().toISOString()\n\n const result = await upsertRow<{ globalType: string } & T>({\n adapter: this,\n data,\n db,\n fields: globalConfig.flattenedFields,\n ignoreResult: returning === false,\n operation: 'create',\n req,\n tableName,\n })\n\n if (returning === false) {\n return null\n }\n\n result.globalType = slug\n\n return result\n}\n"],"names":["toSnakeCase","upsertRow","getTransaction","createGlobal","slug","data","req","returning","db","globalConfig","payload","globals","config","find","tableName","tableNameMap","get","createdAt","Date","toISOString","result","adapter","fields","flattenedFields","ignoreResult","operation","globalType"],"mappings":"AAEA,OAAOA,iBAAiB,gBAAe;AAIvC,SAASC,SAAS,QAAQ,uBAAsB;AAChD,SAASC,cAAc,QAAQ,gCAA+B;AAE9D,OAAO,eAAeC,aAEpB,EAAEC,IAAI,EAAEC,IAAI,EAAEC,GAAG,EAAEC,SAAS,EAAoB;IAEhD,MAAMC,KAAK,MAAMN,eAAe,IAAI,EAAEI;IACtC,MAAMG,eAAe,IAAI,CAACC,OAAO,CAACC,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC,CAACD,SAAWA,OAAOR,IAAI,KAAKA;IAElF,MAAMU,YAAY,IAAI,CAACC,YAAY,CAACC,GAAG,CAAChB,YAAYS,aAAaL,IAAI;IAErEC,KAAKY,SAAS,GAAG,IAAIC,OAAOC,WAAW;IAEvC,MAAMC,SAAS,MAAMnB,UAAsC;QACzDoB,SAAS,IAAI;QACbhB;QACAG;QACAc,QAAQb,aAAac,eAAe;QACpCC,cAAcjB,cAAc;QAC5BkB,WAAW;QACXnB;QACAQ;IACF;IAEA,IAAIP,cAAc,OAAO;QACvB,OAAO;IACT;IAEAa,OAAOM,UAAU,GAAGtB;IAEpB,OAAOgB;AACT"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { CreateGlobalVersionArgs, TypeWithID, TypeWithVersion } from 'payload';
|
|
2
2
|
import type { DrizzleAdapter } from './types.js';
|
|
3
|
-
export declare function createGlobalVersion<T extends TypeWithID>(this: DrizzleAdapter, { autosave, createdAt, globalSlug, publishedLocale, req, select, snapshot, updatedAt, versionData,
|
|
3
|
+
export declare function createGlobalVersion<T extends TypeWithID>(this: DrizzleAdapter, { autosave, createdAt, globalSlug, publishedLocale, req, returning, select, snapshot, updatedAt, versionData, }: CreateGlobalVersionArgs): Promise<TypeWithVersion<T>>;
|
|
4
4
|
//# sourceMappingURL=createGlobalVersion.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createGlobalVersion.d.ts","sourceRoot":"","sources":["../src/createGlobalVersion.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAMnF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAKhD,wBAAsB,mBAAmB,CAAC,CAAC,SAAS,UAAU,EAC5D,IAAI,EAAE,cAAc,EACpB,EACE,QAAQ,EACR,SAAS,EACT,UAAU,EACV,eAAe,EACf,GAAG,EACH,MAAM,EACN,QAAQ,EACR,SAAS,EACT,WAAW,
|
|
1
|
+
{"version":3,"file":"createGlobalVersion.d.ts","sourceRoot":"","sources":["../src/createGlobalVersion.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAMnF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAKhD,wBAAsB,mBAAmB,CAAC,CAAC,SAAS,UAAU,EAC5D,IAAI,EAAE,cAAc,EACpB,EACE,QAAQ,EACR,SAAS,EACT,UAAU,EACV,eAAe,EACf,GAAG,EACH,SAAS,EACT,MAAM,EACN,QAAQ,EACR,SAAS,EACT,WAAW,GACZ,EAAE,uBAAuB,+BA4C3B"}
|
|
@@ -3,7 +3,7 @@ import { buildVersionGlobalFields } from 'payload';
|
|
|
3
3
|
import toSnakeCase from 'to-snake-case';
|
|
4
4
|
import { upsertRow } from './upsertRow/index.js';
|
|
5
5
|
import { getTransaction } from './utilities/getTransaction.js';
|
|
6
|
-
export async function createGlobalVersion({ autosave, createdAt, globalSlug, publishedLocale, req, select, snapshot, updatedAt, versionData
|
|
6
|
+
export async function createGlobalVersion({ autosave, createdAt, globalSlug, publishedLocale, req, returning, select, snapshot, updatedAt, versionData }) {
|
|
7
7
|
const db = await getTransaction(this, req);
|
|
8
8
|
const global = this.payload.globals.config.find(({ slug })=>slug === globalSlug);
|
|
9
9
|
const tableName = this.tableNameMap.get(`_${toSnakeCase(global.slug)}${this.versionsSuffix}`);
|
|
@@ -20,11 +20,11 @@ export async function createGlobalVersion({ autosave, createdAt, globalSlug, pub
|
|
|
20
20
|
},
|
|
21
21
|
db,
|
|
22
22
|
fields: buildVersionGlobalFields(this.payload.config, global, true),
|
|
23
|
+
ignoreResult: returning === false ? 'idOnly' : false,
|
|
23
24
|
operation: 'create',
|
|
24
25
|
req,
|
|
25
26
|
select,
|
|
26
|
-
tableName
|
|
27
|
-
ignoreResult: returning === false ? 'idOnly' : false
|
|
27
|
+
tableName
|
|
28
28
|
});
|
|
29
29
|
const table = this.tables[tableName];
|
|
30
30
|
if (global.versions.drafts) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/createGlobalVersion.ts"],"sourcesContent":["import type { CreateGlobalVersionArgs, TypeWithID, TypeWithVersion } from 'payload'\n\nimport { sql } from 'drizzle-orm'\nimport { buildVersionGlobalFields } from 'payload'\nimport toSnakeCase from 'to-snake-case'\n\nimport type { DrizzleAdapter } from './types.js'\n\nimport { upsertRow } from './upsertRow/index.js'\nimport { getTransaction } from './utilities/getTransaction.js'\n\nexport async function createGlobalVersion<T extends TypeWithID>(\n this: DrizzleAdapter,\n {\n autosave,\n createdAt,\n globalSlug,\n publishedLocale,\n req,\n select,\n snapshot,\n updatedAt,\n versionData,\n
|
|
1
|
+
{"version":3,"sources":["../src/createGlobalVersion.ts"],"sourcesContent":["import type { CreateGlobalVersionArgs, TypeWithID, TypeWithVersion } from 'payload'\n\nimport { sql } from 'drizzle-orm'\nimport { buildVersionGlobalFields } from 'payload'\nimport toSnakeCase from 'to-snake-case'\n\nimport type { DrizzleAdapter } from './types.js'\n\nimport { upsertRow } from './upsertRow/index.js'\nimport { getTransaction } from './utilities/getTransaction.js'\n\nexport async function createGlobalVersion<T extends TypeWithID>(\n this: DrizzleAdapter,\n {\n autosave,\n createdAt,\n globalSlug,\n publishedLocale,\n req,\n returning,\n select,\n snapshot,\n updatedAt,\n versionData,\n }: CreateGlobalVersionArgs,\n) {\n const db = await getTransaction(this, req)\n const global = this.payload.globals.config.find(({ slug }) => slug === globalSlug)\n\n const tableName = this.tableNameMap.get(`_${toSnakeCase(global.slug)}${this.versionsSuffix}`)\n\n const result = await upsertRow<TypeWithVersion<T>>({\n adapter: this,\n data: {\n autosave,\n createdAt,\n latest: true,\n publishedLocale,\n snapshot,\n updatedAt,\n version: versionData,\n },\n db,\n fields: buildVersionGlobalFields(this.payload.config, global, true),\n ignoreResult: returning === false ? 'idOnly' : false,\n operation: 'create',\n req,\n select,\n tableName,\n })\n\n const table = this.tables[tableName]\n if (global.versions.drafts) {\n await this.execute({\n db,\n sql: sql`\n UPDATE ${table}\n SET latest = false\n WHERE ${table.id} != ${result.id};\n `,\n })\n }\n\n if (returning === false) {\n return null\n }\n\n return result\n}\n"],"names":["sql","buildVersionGlobalFields","toSnakeCase","upsertRow","getTransaction","createGlobalVersion","autosave","createdAt","globalSlug","publishedLocale","req","returning","select","snapshot","updatedAt","versionData","db","global","payload","globals","config","find","slug","tableName","tableNameMap","get","versionsSuffix","result","adapter","data","latest","version","fields","ignoreResult","operation","table","tables","versions","drafts","execute","id"],"mappings":"AAEA,SAASA,GAAG,QAAQ,cAAa;AACjC,SAASC,wBAAwB,QAAQ,UAAS;AAClD,OAAOC,iBAAiB,gBAAe;AAIvC,SAASC,SAAS,QAAQ,uBAAsB;AAChD,SAASC,cAAc,QAAQ,gCAA+B;AAE9D,OAAO,eAAeC,oBAEpB,EACEC,QAAQ,EACRC,SAAS,EACTC,UAAU,EACVC,eAAe,EACfC,GAAG,EACHC,SAAS,EACTC,MAAM,EACNC,QAAQ,EACRC,SAAS,EACTC,WAAW,EACa;IAE1B,MAAMC,KAAK,MAAMZ,eAAe,IAAI,EAAEM;IACtC,MAAMO,SAAS,IAAI,CAACC,OAAO,CAACC,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC,CAAC,EAAEC,IAAI,EAAE,GAAKA,SAASd;IAEvE,MAAMe,YAAY,IAAI,CAACC,YAAY,CAACC,GAAG,CAAC,CAAC,CAAC,EAAEvB,YAAYe,OAAOK,IAAI,IAAI,IAAI,CAACI,cAAc,EAAE;IAE5F,MAAMC,SAAS,MAAMxB,UAA8B;QACjDyB,SAAS,IAAI;QACbC,MAAM;YACJvB;YACAC;YACAuB,QAAQ;YACRrB;YACAI;YACAC;YACAiB,SAAShB;QACX;QACAC;QACAgB,QAAQ/B,yBAAyB,IAAI,CAACiB,OAAO,CAACE,MAAM,EAAEH,QAAQ;QAC9DgB,cAActB,cAAc,QAAQ,WAAW;QAC/CuB,WAAW;QACXxB;QACAE;QACAW;IACF;IAEA,MAAMY,QAAQ,IAAI,CAACC,MAAM,CAACb,UAAU;IACpC,IAAIN,OAAOoB,QAAQ,CAACC,MAAM,EAAE;QAC1B,MAAM,IAAI,CAACC,OAAO,CAAC;YACjBvB;YACAhB,KAAKA,GAAG,CAAC;iBACE,EAAEmC,MAAM;;gBAET,EAAEA,MAAMK,EAAE,CAAC,IAAI,EAAEb,OAAOa,EAAE,CAAC;QACnC,CAAC;QACL;IACF;IAEA,IAAI7B,cAAc,OAAO;QACvB,OAAO;IACT;IAEA,OAAOgB;AACT"}
|
package/dist/createVersion.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { CreateVersionArgs, TypeWithID, TypeWithVersion } from 'payload';
|
|
2
2
|
import type { DrizzleAdapter } from './types.js';
|
|
3
|
-
export declare function createVersion<T extends TypeWithID>(this: DrizzleAdapter, { autosave, collectionSlug, createdAt, parent, publishedLocale, req, select, snapshot, updatedAt, versionData,
|
|
3
|
+
export declare function createVersion<T extends TypeWithID>(this: DrizzleAdapter, { autosave, collectionSlug, createdAt, parent, publishedLocale, req, returning, select, snapshot, updatedAt, versionData, }: CreateVersionArgs<T>): Promise<TypeWithVersion<T>>;
|
|
4
4
|
//# sourceMappingURL=createVersion.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createVersion.d.ts","sourceRoot":"","sources":["../src/createVersion.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAM7E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAKhD,wBAAsB,aAAa,CAAC,CAAC,SAAS,UAAU,EACtD,IAAI,EAAE,cAAc,EACpB,EACE,QAAQ,EACR,cAAc,EACd,SAAS,EACT,MAAM,EACN,eAAe,EACf,GAAG,EACH,MAAM,EACN,QAAQ,EACR,SAAS,EACT,WAAW,
|
|
1
|
+
{"version":3,"file":"createVersion.d.ts","sourceRoot":"","sources":["../src/createVersion.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAM7E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAKhD,wBAAsB,aAAa,CAAC,CAAC,SAAS,UAAU,EACtD,IAAI,EAAE,cAAc,EACpB,EACE,QAAQ,EACR,cAAc,EACd,SAAS,EACT,MAAM,EACN,eAAe,EACf,GAAG,EACH,SAAS,EACT,MAAM,EACN,QAAQ,EACR,SAAS,EACT,WAAW,GACZ,EAAE,iBAAiB,CAAC,CAAC,CAAC,+BAuDxB"}
|
package/dist/createVersion.js
CHANGED
|
@@ -3,7 +3,7 @@ import { buildVersionCollectionFields } from 'payload';
|
|
|
3
3
|
import toSnakeCase from 'to-snake-case';
|
|
4
4
|
import { upsertRow } from './upsertRow/index.js';
|
|
5
5
|
import { getTransaction } from './utilities/getTransaction.js';
|
|
6
|
-
export async function createVersion({ autosave, collectionSlug, createdAt, parent, publishedLocale, req, select, snapshot, updatedAt, versionData
|
|
6
|
+
export async function createVersion({ autosave, collectionSlug, createdAt, parent, publishedLocale, req, returning, select, snapshot, updatedAt, versionData }) {
|
|
7
7
|
const db = await getTransaction(this, req);
|
|
8
8
|
const collection = this.payload.collections[collectionSlug].config;
|
|
9
9
|
const defaultTableName = toSnakeCase(collection.slug);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/createVersion.ts"],"sourcesContent":["import type { CreateVersionArgs, TypeWithID, TypeWithVersion } from 'payload'\n\nimport { sql } from 'drizzle-orm'\nimport { buildVersionCollectionFields } from 'payload'\nimport toSnakeCase from 'to-snake-case'\n\nimport type { DrizzleAdapter } from './types.js'\n\nimport { upsertRow } from './upsertRow/index.js'\nimport { getTransaction } from './utilities/getTransaction.js'\n\nexport async function createVersion<T extends TypeWithID>(\n this: DrizzleAdapter,\n {\n autosave,\n collectionSlug,\n createdAt,\n parent,\n publishedLocale,\n req,\n select,\n snapshot,\n updatedAt,\n versionData,\n
|
|
1
|
+
{"version":3,"sources":["../src/createVersion.ts"],"sourcesContent":["import type { CreateVersionArgs, TypeWithID, TypeWithVersion } from 'payload'\n\nimport { sql } from 'drizzle-orm'\nimport { buildVersionCollectionFields } from 'payload'\nimport toSnakeCase from 'to-snake-case'\n\nimport type { DrizzleAdapter } from './types.js'\n\nimport { upsertRow } from './upsertRow/index.js'\nimport { getTransaction } from './utilities/getTransaction.js'\n\nexport async function createVersion<T extends TypeWithID>(\n this: DrizzleAdapter,\n {\n autosave,\n collectionSlug,\n createdAt,\n parent,\n publishedLocale,\n req,\n returning,\n select,\n snapshot,\n updatedAt,\n versionData,\n }: CreateVersionArgs<T>,\n) {\n const db = await getTransaction(this, req)\n const collection = this.payload.collections[collectionSlug].config\n const defaultTableName = toSnakeCase(collection.slug)\n\n const tableName = this.tableNameMap.get(`_${defaultTableName}${this.versionsSuffix}`)\n\n const version = { ...versionData }\n if (version.id) {\n delete version.id\n }\n\n const data: Record<string, unknown> = {\n autosave,\n createdAt,\n latest: true,\n parent,\n publishedLocale,\n snapshot,\n updatedAt,\n version,\n }\n\n const result = await upsertRow<TypeWithVersion<T>>({\n adapter: this,\n data,\n db,\n fields: buildVersionCollectionFields(this.payload.config, collection, true),\n operation: 'create',\n req,\n select,\n tableName,\n })\n\n const table = this.tables[tableName]\n\n if (collection.versions.drafts) {\n await this.execute({\n db,\n sql: sql`\n UPDATE ${table}\n SET latest = false\n WHERE ${table.id} != ${result.id}\n AND ${table.parent} = ${parent}\n AND ${table.updatedAt} < ${result.updatedAt}\n `,\n })\n }\n\n if (returning === false) {\n return null\n }\n\n return result\n}\n"],"names":["sql","buildVersionCollectionFields","toSnakeCase","upsertRow","getTransaction","createVersion","autosave","collectionSlug","createdAt","parent","publishedLocale","req","returning","select","snapshot","updatedAt","versionData","db","collection","payload","collections","config","defaultTableName","slug","tableName","tableNameMap","get","versionsSuffix","version","id","data","latest","result","adapter","fields","operation","table","tables","versions","drafts","execute"],"mappings":"AAEA,SAASA,GAAG,QAAQ,cAAa;AACjC,SAASC,4BAA4B,QAAQ,UAAS;AACtD,OAAOC,iBAAiB,gBAAe;AAIvC,SAASC,SAAS,QAAQ,uBAAsB;AAChD,SAASC,cAAc,QAAQ,gCAA+B;AAE9D,OAAO,eAAeC,cAEpB,EACEC,QAAQ,EACRC,cAAc,EACdC,SAAS,EACTC,MAAM,EACNC,eAAe,EACfC,GAAG,EACHC,SAAS,EACTC,MAAM,EACNC,QAAQ,EACRC,SAAS,EACTC,WAAW,EACU;IAEvB,MAAMC,KAAK,MAAMb,eAAe,IAAI,EAAEO;IACtC,MAAMO,aAAa,IAAI,CAACC,OAAO,CAACC,WAAW,CAACb,eAAe,CAACc,MAAM;IAClE,MAAMC,mBAAmBpB,YAAYgB,WAAWK,IAAI;IAEpD,MAAMC,YAAY,IAAI,CAACC,YAAY,CAACC,GAAG,CAAC,CAAC,CAAC,EAAEJ,mBAAmB,IAAI,CAACK,cAAc,EAAE;IAEpF,MAAMC,UAAU;QAAE,GAAGZ,WAAW;IAAC;IACjC,IAAIY,QAAQC,EAAE,EAAE;QACd,OAAOD,QAAQC,EAAE;IACnB;IAEA,MAAMC,OAAgC;QACpCxB;QACAE;QACAuB,QAAQ;QACRtB;QACAC;QACAI;QACAC;QACAa;IACF;IAEA,MAAMI,SAAS,MAAM7B,UAA8B;QACjD8B,SAAS,IAAI;QACbH;QACAb;QACAiB,QAAQjC,6BAA6B,IAAI,CAACkB,OAAO,CAACE,MAAM,EAAEH,YAAY;QACtEiB,WAAW;QACXxB;QACAE;QACAW;IACF;IAEA,MAAMY,QAAQ,IAAI,CAACC,MAAM,CAACb,UAAU;IAEpC,IAAIN,WAAWoB,QAAQ,CAACC,MAAM,EAAE;QAC9B,MAAM,IAAI,CAACC,OAAO,CAAC;YACjBvB;YACAjB,KAAKA,GAAG,CAAC;eACA,EAAEoC,MAAM;;cAET,EAAEA,MAAMP,EAAE,CAAC,IAAI,EAAEG,OAAOH,EAAE,CAAC;cAC3B,EAAEO,MAAM3B,MAAM,CAAC,GAAG,EAAEA,OAAO;cAC3B,EAAE2B,MAAMrB,SAAS,CAAC,GAAG,EAAEiB,OAAOjB,SAAS,CAAC;MAChD,CAAC;QACH;IACF;IAEA,IAAIH,cAAc,OAAO;QACvB,OAAO;IACT;IAEA,OAAOoB;AACT"}
|
package/dist/deleteOne.js
CHANGED
|
@@ -5,7 +5,7 @@ import buildQuery from './queries/buildQuery.js';
|
|
|
5
5
|
import { selectDistinct } from './queries/selectDistinct.js';
|
|
6
6
|
import { transform } from './transform/read/index.js';
|
|
7
7
|
import { getTransaction } from './utilities/getTransaction.js';
|
|
8
|
-
export const deleteOne = async function deleteOne({ collection: collectionSlug, req, select, where: whereArg
|
|
8
|
+
export const deleteOne = async function deleteOne({ collection: collectionSlug, req, returning, select, where: whereArg }) {
|
|
9
9
|
const db = await getTransaction(this, req);
|
|
10
10
|
const collection = this.payload.collections[collectionSlug].config;
|
|
11
11
|
const tableName = this.tableNameMap.get(toSnakeCase(collection.slug));
|
package/dist/deleteOne.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/deleteOne.ts"],"sourcesContent":["import type { DeleteOne } from 'payload'\n\nimport { eq } from 'drizzle-orm'\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 { transform } from './transform/read/index.js'\nimport { getTransaction } from './utilities/getTransaction.js'\n\nexport const deleteOne: DeleteOne = async function deleteOne(\n this: DrizzleAdapter,\n { collection: collectionSlug, req, select, where: whereArg
|
|
1
|
+
{"version":3,"sources":["../src/deleteOne.ts"],"sourcesContent":["import type { DeleteOne } from 'payload'\n\nimport { eq } from 'drizzle-orm'\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 { transform } from './transform/read/index.js'\nimport { getTransaction } from './utilities/getTransaction.js'\n\nexport const deleteOne: DeleteOne = async function deleteOne(\n this: DrizzleAdapter,\n { collection: collectionSlug, req, returning, select, where: whereArg },\n) {\n const db = await getTransaction(this, req)\n const collection = this.payload.collections[collectionSlug].config\n\n const tableName = this.tableNameMap.get(toSnakeCase(collection.slug))\n\n let docToDelete: Record<string, unknown>\n\n const { joins, selectFields, where } = buildQuery({\n adapter: this,\n fields: collection.flattenedFields,\n locale: req?.locale,\n tableName,\n where: whereArg,\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 docToDelete = await db.query[tableName].findFirst({\n where: eq(this.tables[tableName].id, selectDistinctResult[0].id),\n })\n } else {\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 docToDelete = await db.query[tableName].findFirst(findManyArgs)\n }\n\n const result =\n returning === false\n ? null\n : transform({\n adapter: this,\n config: this.payload.config,\n data: docToDelete,\n fields: collection.flattenedFields,\n joinQuery: false,\n })\n\n await this.deleteWhere({\n db,\n tableName,\n where: eq(this.tables[tableName].id, docToDelete.id),\n })\n\n return result\n}\n"],"names":["eq","toSnakeCase","buildFindManyArgs","buildQuery","selectDistinct","transform","getTransaction","deleteOne","collection","collectionSlug","req","returning","select","where","whereArg","db","payload","collections","config","tableName","tableNameMap","get","slug","docToDelete","joins","selectFields","adapter","fields","flattenedFields","locale","selectDistinctResult","chainedMethods","args","method","id","query","findFirst","tables","findManyArgs","depth","joinQuery","result","data","deleteWhere"],"mappings":"AAEA,SAASA,EAAE,QAAQ,cAAa;AAChC,OAAOC,iBAAiB,gBAAe;AAIvC,SAASC,iBAAiB,QAAQ,8BAA6B;AAC/D,OAAOC,gBAAgB,0BAAyB;AAChD,SAASC,cAAc,QAAQ,8BAA6B;AAC5D,SAASC,SAAS,QAAQ,4BAA2B;AACrD,SAASC,cAAc,QAAQ,gCAA+B;AAE9D,OAAO,MAAMC,YAAuB,eAAeA,UAEjD,EAAEC,YAAYC,cAAc,EAAEC,GAAG,EAAEC,SAAS,EAAEC,MAAM,EAAEC,OAAOC,QAAQ,EAAE;IAEvE,MAAMC,KAAK,MAAMT,eAAe,IAAI,EAAEI;IACtC,MAAMF,aAAa,IAAI,CAACQ,OAAO,CAACC,WAAW,CAACR,eAAe,CAACS,MAAM;IAElE,MAAMC,YAAY,IAAI,CAACC,YAAY,CAACC,GAAG,CAACpB,YAAYO,WAAWc,IAAI;IAEnE,IAAIC;IAEJ,MAAM,EAAEC,KAAK,EAAEC,YAAY,EAAEZ,KAAK,EAAE,GAAGV,WAAW;QAChDuB,SAAS,IAAI;QACbC,QAAQnB,WAAWoB,eAAe;QAClCC,QAAQnB,KAAKmB;QACbV;QACAN,OAAOC;IACT;IAEA,MAAMgB,uBAAuB,MAAM1B,eAAe;QAChDsB,SAAS,IAAI;QACbK,gBAAgB;YAAC;gBAAEC,MAAM;oBAAC;iBAAE;gBAAEC,QAAQ;YAAQ;SAAE;QAChDlB;QACAS;QACAC;QACAN;QACAN;IACF;IAEA,IAAIiB,sBAAsB,CAAC,EAAE,EAAEI,IAAI;QACjCX,cAAc,MAAMR,GAAGoB,KAAK,CAAChB,UAAU,CAACiB,SAAS,CAAC;YAChDvB,OAAOb,GAAG,IAAI,CAACqC,MAAM,CAAClB,UAAU,CAACe,EAAE,EAAEJ,oBAAoB,CAAC,EAAE,CAACI,EAAE;QACjE;IACF,OAAO;QACL,MAAMI,eAAepC,kBAAkB;YACrCwB,SAAS,IAAI;YACba,OAAO;YACPZ,QAAQnB,WAAWoB,eAAe;YAClCY,WAAW;YACX5B;YACAO;QACF;QAEAmB,aAAazB,KAAK,GAAGA;QAErBU,cAAc,MAAMR,GAAGoB,KAAK,CAAChB,UAAU,CAACiB,SAAS,CAACE;IACpD;IAEA,MAAMG,SACJ9B,cAAc,QACV,OACAN,UAAU;QACRqB,SAAS,IAAI;QACbR,QAAQ,IAAI,CAACF,OAAO,CAACE,MAAM;QAC3BwB,MAAMnB;QACNI,QAAQnB,WAAWoB,eAAe;QAClCY,WAAW;IACb;IAEN,MAAM,IAAI,CAACG,WAAW,CAAC;QACrB5B;QACAI;QACAN,OAAOb,GAAG,IAAI,CAACqC,MAAM,CAAClB,UAAU,CAACe,EAAE,EAAEX,YAAYW,EAAE;IACrD;IAEA,OAAOO;AACT,EAAC"}
|
package/dist/updateGlobal.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { UpdateGlobalArgs } from 'payload';
|
|
2
2
|
import type { DrizzleAdapter } from './types.js';
|
|
3
|
-
export declare function updateGlobal<T extends Record<string, unknown>>(this: DrizzleAdapter, { slug, data, req,
|
|
3
|
+
export declare function updateGlobal<T extends Record<string, unknown>>(this: DrizzleAdapter, { slug, data, req, returning, select }: UpdateGlobalArgs): Promise<T>;
|
|
4
4
|
//# sourceMappingURL=updateGlobal.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"updateGlobal.d.ts","sourceRoot":"","sources":["../src/updateGlobal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAI/C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAKhD,wBAAsB,YAAY,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAClE,IAAI,EAAE,cAAc,EACpB,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,
|
|
1
|
+
{"version":3,"file":"updateGlobal.d.ts","sourceRoot":"","sources":["../src/updateGlobal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAI/C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAKhD,wBAAsB,YAAY,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAClE,IAAI,EAAE,cAAc,EACpB,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,EAAE,EAAE,gBAAgB,GACvD,OAAO,CAAC,CAAC,CAAC,CA0BZ"}
|
package/dist/updateGlobal.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import toSnakeCase from 'to-snake-case';
|
|
2
2
|
import { upsertRow } from './upsertRow/index.js';
|
|
3
3
|
import { getTransaction } from './utilities/getTransaction.js';
|
|
4
|
-
export async function updateGlobal({ slug, data, req,
|
|
4
|
+
export async function updateGlobal({ slug, data, req, returning, select }) {
|
|
5
5
|
const db = await getTransaction(this, req);
|
|
6
6
|
const globalConfig = this.payload.globals.config.find((config)=>config.slug === slug);
|
|
7
7
|
const tableName = this.tableNameMap.get(toSnakeCase(globalConfig.slug));
|
|
@@ -17,10 +17,10 @@ export async function updateGlobal({ slug, data, req, select, returning }) {
|
|
|
17
17
|
data,
|
|
18
18
|
db,
|
|
19
19
|
fields: globalConfig.flattenedFields,
|
|
20
|
+
ignoreResult: returning === false,
|
|
20
21
|
req,
|
|
21
22
|
select,
|
|
22
|
-
tableName
|
|
23
|
-
ignoreResult: returning === false
|
|
23
|
+
tableName
|
|
24
24
|
});
|
|
25
25
|
if (returning === false) {
|
|
26
26
|
return null;
|
package/dist/updateGlobal.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/updateGlobal.ts"],"sourcesContent":["import type { UpdateGlobalArgs } from 'payload'\n\nimport toSnakeCase from 'to-snake-case'\n\nimport type { DrizzleAdapter } from './types.js'\n\nimport { upsertRow } from './upsertRow/index.js'\nimport { getTransaction } from './utilities/getTransaction.js'\n\nexport async function updateGlobal<T extends Record<string, unknown>>(\n this: DrizzleAdapter,\n { slug, data, req,
|
|
1
|
+
{"version":3,"sources":["../src/updateGlobal.ts"],"sourcesContent":["import type { UpdateGlobalArgs } from 'payload'\n\nimport toSnakeCase from 'to-snake-case'\n\nimport type { DrizzleAdapter } from './types.js'\n\nimport { upsertRow } from './upsertRow/index.js'\nimport { getTransaction } from './utilities/getTransaction.js'\n\nexport async function updateGlobal<T extends Record<string, unknown>>(\n this: DrizzleAdapter,\n { slug, data, req, returning, select }: UpdateGlobalArgs,\n): Promise<T> {\n const db = await getTransaction(this, req)\n const globalConfig = this.payload.globals.config.find((config) => config.slug === slug)\n const tableName = this.tableNameMap.get(toSnakeCase(globalConfig.slug))\n\n const existingGlobal = await db.query[tableName].findFirst({})\n\n const result = await upsertRow<{ globalType: string } & T>({\n ...(existingGlobal ? { id: existingGlobal.id, operation: 'update' } : { operation: 'create' }),\n adapter: this,\n data,\n db,\n fields: globalConfig.flattenedFields,\n ignoreResult: returning === false,\n req,\n select,\n tableName,\n })\n\n if (returning === false) {\n return null\n }\n\n result.globalType = slug\n\n return result\n}\n"],"names":["toSnakeCase","upsertRow","getTransaction","updateGlobal","slug","data","req","returning","select","db","globalConfig","payload","globals","config","find","tableName","tableNameMap","get","existingGlobal","query","findFirst","result","id","operation","adapter","fields","flattenedFields","ignoreResult","globalType"],"mappings":"AAEA,OAAOA,iBAAiB,gBAAe;AAIvC,SAASC,SAAS,QAAQ,uBAAsB;AAChD,SAASC,cAAc,QAAQ,gCAA+B;AAE9D,OAAO,eAAeC,aAEpB,EAAEC,IAAI,EAAEC,IAAI,EAAEC,GAAG,EAAEC,SAAS,EAAEC,MAAM,EAAoB;IAExD,MAAMC,KAAK,MAAMP,eAAe,IAAI,EAAEI;IACtC,MAAMI,eAAe,IAAI,CAACC,OAAO,CAACC,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC,CAACD,SAAWA,OAAOT,IAAI,KAAKA;IAClF,MAAMW,YAAY,IAAI,CAACC,YAAY,CAACC,GAAG,CAACjB,YAAYU,aAAaN,IAAI;IAErE,MAAMc,iBAAiB,MAAMT,GAAGU,KAAK,CAACJ,UAAU,CAACK,SAAS,CAAC,CAAC;IAE5D,MAAMC,SAAS,MAAMpB,UAAsC;QACzD,GAAIiB,iBAAiB;YAAEI,IAAIJ,eAAeI,EAAE;YAAEC,WAAW;QAAS,IAAI;YAAEA,WAAW;QAAS,CAAC;QAC7FC,SAAS,IAAI;QACbnB;QACAI;QACAgB,QAAQf,aAAagB,eAAe;QACpCC,cAAcpB,cAAc;QAC5BD;QACAE;QACAO;IACF;IAEA,IAAIR,cAAc,OAAO;QACvB,OAAO;IACT;IAEAc,OAAOO,UAAU,GAAGxB;IAEpB,OAAOiB;AACT"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { TypeWithID, TypeWithVersion, UpdateGlobalVersionArgs } from 'payload';
|
|
2
2
|
import type { DrizzleAdapter } from './types.js';
|
|
3
|
-
export declare function updateGlobalVersion<T extends TypeWithID>(this: DrizzleAdapter, { id, global, locale, req, select, versionData, where: whereArg,
|
|
3
|
+
export declare function updateGlobalVersion<T extends TypeWithID>(this: DrizzleAdapter, { id, global, locale, req, returning, select, versionData, where: whereArg, }: UpdateGlobalVersionArgs<T>): Promise<TypeWithVersion<T>>;
|
|
4
4
|
//# sourceMappingURL=updateGlobalVersion.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"updateGlobalVersion.d.ts","sourceRoot":"","sources":["../src/updateGlobalVersion.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,UAAU,EACV,eAAe,EACf,uBAAuB,EACxB,MAAM,SAAS,CAAA;AAKhB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAMhD,wBAAsB,mBAAmB,CAAC,CAAC,SAAS,UAAU,EAC5D,IAAI,EAAE,cAAc,EACpB,EACE,EAAE,EACF,MAAM,EACN,MAAM,EACN,GAAG,EACH,MAAM,EACN,WAAW,EACX,KAAK,EAAE,QAAQ,
|
|
1
|
+
{"version":3,"file":"updateGlobalVersion.d.ts","sourceRoot":"","sources":["../src/updateGlobalVersion.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,UAAU,EACV,eAAe,EACf,uBAAuB,EACxB,MAAM,SAAS,CAAA;AAKhB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAMhD,wBAAsB,mBAAmB,CAAC,CAAC,SAAS,UAAU,EAC5D,IAAI,EAAE,cAAc,EACpB,EACE,EAAE,EACF,MAAM,EACN,MAAM,EACN,GAAG,EACH,SAAS,EACT,MAAM,EACN,WAAW,EACX,KAAK,EAAE,QAAQ,GAChB,EAAE,uBAAuB,CAAC,CAAC,CAAC,+BAyC9B"}
|
|
@@ -3,7 +3,7 @@ import toSnakeCase from 'to-snake-case';
|
|
|
3
3
|
import buildQuery from './queries/buildQuery.js';
|
|
4
4
|
import { upsertRow } from './upsertRow/index.js';
|
|
5
5
|
import { getTransaction } from './utilities/getTransaction.js';
|
|
6
|
-
export async function updateGlobalVersion({ id, global, locale, req, select, versionData, where: whereArg
|
|
6
|
+
export async function updateGlobalVersion({ id, global, locale, req, returning, select, versionData, where: whereArg }) {
|
|
7
7
|
const db = await getTransaction(this, req);
|
|
8
8
|
const globalConfig = this.payload.globals.config.find(({ slug })=>slug === global);
|
|
9
9
|
const whereToUse = whereArg || {
|
|
@@ -26,12 +26,12 @@ export async function updateGlobalVersion({ id, global, locale, req, select, ver
|
|
|
26
26
|
data: versionData,
|
|
27
27
|
db,
|
|
28
28
|
fields,
|
|
29
|
+
ignoreResult: returning === false,
|
|
29
30
|
operation: 'update',
|
|
30
31
|
req,
|
|
31
32
|
select,
|
|
32
33
|
tableName,
|
|
33
|
-
where
|
|
34
|
-
ignoreResult: returning === false
|
|
34
|
+
where
|
|
35
35
|
});
|
|
36
36
|
if (returning === false) {
|
|
37
37
|
return null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/updateGlobalVersion.ts"],"sourcesContent":["import type {\n SanitizedGlobalConfig,\n TypeWithID,\n TypeWithVersion,\n UpdateGlobalVersionArgs,\n} from 'payload'\n\nimport { buildVersionGlobalFields } from 'payload'\nimport toSnakeCase from 'to-snake-case'\n\nimport type { DrizzleAdapter } from './types.js'\n\nimport buildQuery from './queries/buildQuery.js'\nimport { upsertRow } from './upsertRow/index.js'\nimport { getTransaction } from './utilities/getTransaction.js'\n\nexport async function updateGlobalVersion<T extends TypeWithID>(\n this: DrizzleAdapter,\n {\n id,\n global,\n locale,\n req,\n select,\n versionData,\n where: whereArg,\n
|
|
1
|
+
{"version":3,"sources":["../src/updateGlobalVersion.ts"],"sourcesContent":["import type {\n SanitizedGlobalConfig,\n TypeWithID,\n TypeWithVersion,\n UpdateGlobalVersionArgs,\n} from 'payload'\n\nimport { buildVersionGlobalFields } from 'payload'\nimport toSnakeCase from 'to-snake-case'\n\nimport type { DrizzleAdapter } from './types.js'\n\nimport buildQuery from './queries/buildQuery.js'\nimport { upsertRow } from './upsertRow/index.js'\nimport { getTransaction } from './utilities/getTransaction.js'\n\nexport async function updateGlobalVersion<T extends TypeWithID>(\n this: DrizzleAdapter,\n {\n id,\n global,\n locale,\n req,\n returning,\n select,\n versionData,\n where: whereArg,\n }: UpdateGlobalVersionArgs<T>,\n) {\n const db = await getTransaction(this, req)\n const globalConfig: SanitizedGlobalConfig = this.payload.globals.config.find(\n ({ slug }) => slug === global,\n )\n const whereToUse = whereArg || { id: { equals: id } }\n\n const tableName = this.tableNameMap.get(\n `_${toSnakeCase(globalConfig.slug)}${this.versionsSuffix}`,\n )\n\n const fields = buildVersionGlobalFields(this.payload.config, globalConfig, true)\n\n const { where } = buildQuery({\n adapter: this,\n fields,\n locale,\n tableName,\n where: whereToUse,\n })\n\n const result = await upsertRow<TypeWithVersion<T>>({\n id,\n adapter: this,\n data: versionData,\n db,\n fields,\n ignoreResult: returning === false,\n operation: 'update',\n req,\n select,\n tableName,\n where,\n })\n\n if (returning === false) {\n return null\n }\n\n return result\n}\n"],"names":["buildVersionGlobalFields","toSnakeCase","buildQuery","upsertRow","getTransaction","updateGlobalVersion","id","global","locale","req","returning","select","versionData","where","whereArg","db","globalConfig","payload","globals","config","find","slug","whereToUse","equals","tableName","tableNameMap","get","versionsSuffix","fields","adapter","result","data","ignoreResult","operation"],"mappings":"AAOA,SAASA,wBAAwB,QAAQ,UAAS;AAClD,OAAOC,iBAAiB,gBAAe;AAIvC,OAAOC,gBAAgB,0BAAyB;AAChD,SAASC,SAAS,QAAQ,uBAAsB;AAChD,SAASC,cAAc,QAAQ,gCAA+B;AAE9D,OAAO,eAAeC,oBAEpB,EACEC,EAAE,EACFC,MAAM,EACNC,MAAM,EACNC,GAAG,EACHC,SAAS,EACTC,MAAM,EACNC,WAAW,EACXC,OAAOC,QAAQ,EACY;IAE7B,MAAMC,KAAK,MAAMX,eAAe,IAAI,EAAEK;IACtC,MAAMO,eAAsC,IAAI,CAACC,OAAO,CAACC,OAAO,CAACC,MAAM,CAACC,IAAI,CAC1E,CAAC,EAAEC,IAAI,EAAE,GAAKA,SAASd;IAEzB,MAAMe,aAAaR,YAAY;QAAER,IAAI;YAAEiB,QAAQjB;QAAG;IAAE;IAEpD,MAAMkB,YAAY,IAAI,CAACC,YAAY,CAACC,GAAG,CACrC,CAAC,CAAC,EAAEzB,YAAYe,aAAaK,IAAI,IAAI,IAAI,CAACM,cAAc,EAAE;IAG5D,MAAMC,SAAS5B,yBAAyB,IAAI,CAACiB,OAAO,CAACE,MAAM,EAAEH,cAAc;IAE3E,MAAM,EAAEH,KAAK,EAAE,GAAGX,WAAW;QAC3B2B,SAAS,IAAI;QACbD;QACApB;QACAgB;QACAX,OAAOS;IACT;IAEA,MAAMQ,SAAS,MAAM3B,UAA8B;QACjDG;QACAuB,SAAS,IAAI;QACbE,MAAMnB;QACNG;QACAa;QACAI,cAActB,cAAc;QAC5BuB,WAAW;QACXxB;QACAE;QACAa;QACAX;IACF;IAEA,IAAIH,cAAc,OAAO;QACvB,OAAO;IACT;IAEA,OAAOoB;AACT"}
|
package/dist/updateOne.js
CHANGED
|
@@ -3,7 +3,7 @@ import buildQuery from './queries/buildQuery.js';
|
|
|
3
3
|
import { selectDistinct } from './queries/selectDistinct.js';
|
|
4
4
|
import { upsertRow } from './upsertRow/index.js';
|
|
5
5
|
import { getTransaction } from './utilities/getTransaction.js';
|
|
6
|
-
export const updateOne = async function updateOne({ id, collection: collectionSlug, data, joins: joinQuery, locale, req, select, where: whereArg
|
|
6
|
+
export const updateOne = async function updateOne({ id, collection: collectionSlug, data, joins: joinQuery, locale, req, returning, select, where: whereArg }) {
|
|
7
7
|
const db = await getTransaction(this, req);
|
|
8
8
|
const collection = this.payload.collections[collectionSlug].config;
|
|
9
9
|
const tableName = this.tableNameMap.get(toSnakeCase(collection.slug));
|
|
@@ -53,12 +53,12 @@ export const updateOne = async function updateOne({ id, collection: collectionSl
|
|
|
53
53
|
data,
|
|
54
54
|
db,
|
|
55
55
|
fields: collection.flattenedFields,
|
|
56
|
+
ignoreResult: returning === false,
|
|
56
57
|
joinQuery,
|
|
57
58
|
operation: 'update',
|
|
58
59
|
req,
|
|
59
60
|
select,
|
|
60
|
-
tableName
|
|
61
|
-
ignoreResult: returning === false
|
|
61
|
+
tableName
|
|
62
62
|
});
|
|
63
63
|
if (returning === false) {
|
|
64
64
|
return null;
|
package/dist/updateOne.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/updateOne.ts"],"sourcesContent":["import type { LibSQLDatabase } from 'drizzle-orm/libsql'\nimport type { UpdateOne } from 'payload'\n\nimport toSnakeCase from 'to-snake-case'\n\nimport type { DrizzleAdapter } from './types.js'\n\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 {\n id,\n collection: collectionSlug,\n data,\n joins: joinQuery,\n locale,\n req,\n select,\n where: whereArg,\n
|
|
1
|
+
{"version":3,"sources":["../src/updateOne.ts"],"sourcesContent":["import type { LibSQLDatabase } from 'drizzle-orm/libsql'\nimport type { UpdateOne } from 'payload'\n\nimport toSnakeCase from 'to-snake-case'\n\nimport type { DrizzleAdapter } from './types.js'\n\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 {\n id,\n collection: collectionSlug,\n data,\n joins: joinQuery,\n locale,\n req,\n returning,\n select,\n where: whereArg,\n },\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 // selectDistinct will only return if there are joins\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 // If id wasn't passed but `where` without any joins, retrieve it with findFirst\n } else if (whereArg && !joins.length) {\n const table = this.tables[tableName]\n\n const docsToUpdate = await (db as LibSQLDatabase)\n .select({\n id: table.id,\n })\n .from(table)\n .where(where)\n .limit(1)\n idToUpdate = docsToUpdate?.[0]?.id\n }\n\n const result = await upsertRow({\n id: idToUpdate,\n adapter: this,\n data,\n db,\n fields: collection.flattenedFields,\n ignoreResult: returning === false,\n joinQuery,\n operation: 'update',\n req,\n select,\n tableName,\n })\n\n if (returning === false) {\n return null\n }\n\n return result\n}\n"],"names":["toSnakeCase","buildQuery","selectDistinct","upsertRow","getTransaction","updateOne","id","collection","collectionSlug","data","joins","joinQuery","locale","req","returning","select","where","whereArg","db","payload","collections","config","tableName","tableNameMap","get","slug","whereToUse","equals","idToUpdate","selectFields","adapter","fields","flattenedFields","selectDistinctResult","chainedMethods","args","method","length","table","tables","docsToUpdate","from","limit","result","ignoreResult","operation"],"mappings":"AAGA,OAAOA,iBAAiB,gBAAe;AAIvC,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,EACEC,EAAE,EACFC,YAAYC,cAAc,EAC1BC,IAAI,EACJC,OAAOC,SAAS,EAChBC,MAAM,EACNC,GAAG,EACHC,SAAS,EACTC,MAAM,EACNC,OAAOC,QAAQ,EAChB;IAED,MAAMC,KAAK,MAAMd,eAAe,IAAI,EAAES;IACtC,MAAMN,aAAa,IAAI,CAACY,OAAO,CAACC,WAAW,CAACZ,eAAe,CAACa,MAAM;IAClE,MAAMC,YAAY,IAAI,CAACC,YAAY,CAACC,GAAG,CAACxB,YAAYO,WAAWkB,IAAI;IACnE,MAAMC,aAAaT,YAAY;QAAEX,IAAI;YAAEqB,QAAQrB;QAAG;IAAE;IACpD,IAAIsB,aAAatB;IAEjB,MAAM,EAAEI,KAAK,EAAEmB,YAAY,EAAEb,KAAK,EAAE,GAAGf,WAAW;QAChD6B,SAAS,IAAI;QACbC,QAAQxB,WAAWyB,eAAe;QAClCpB;QACAU;QACAN,OAAOU;IACT;IAEA,qDAAqD;IACrD,MAAMO,uBAAuB,MAAM/B,eAAe;QAChD4B,SAAS,IAAI;QACbI,gBAAgB;YAAC;gBAAEC,MAAM;oBAAC;iBAAE;gBAAEC,QAAQ;YAAQ;SAAE;QAChDlB;QACAR;QACAmB;QACAP;QACAN;IACF;IAEA,IAAIiB,sBAAsB,CAAC,EAAE,EAAE3B,IAAI;QACjCsB,aAAaK,sBAAsB,CAAC,EAAE,EAAE3B;IACxC,gFAAgF;IAClF,OAAO,IAAIW,YAAY,CAACP,MAAM2B,MAAM,EAAE;QACpC,MAAMC,QAAQ,IAAI,CAACC,MAAM,CAACjB,UAAU;QAEpC,MAAMkB,eAAe,MAAM,AAACtB,GACzBH,MAAM,CAAC;YACNT,IAAIgC,MAAMhC,EAAE;QACd,GACCmC,IAAI,CAACH,OACLtB,KAAK,CAACA,OACN0B,KAAK,CAAC;QACTd,aAAaY,cAAc,CAAC,EAAE,EAAElC;IAClC;IAEA,MAAMqC,SAAS,MAAMxC,UAAU;QAC7BG,IAAIsB;QACJE,SAAS,IAAI;QACbrB;QACAS;QACAa,QAAQxB,WAAWyB,eAAe;QAClCY,cAAc9B,cAAc;QAC5BH;QACAkC,WAAW;QACXhC;QACAE;QACAO;IACF;IAEA,IAAIR,cAAc,OAAO;QACvB,OAAO;IACT;IAEA,OAAO6B;AACT,EAAC"}
|
package/dist/updateVersion.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { TypeWithID, TypeWithVersion, UpdateVersionArgs } from 'payload';
|
|
2
2
|
import type { DrizzleAdapter } from './types.js';
|
|
3
|
-
export declare function updateVersion<T extends TypeWithID>(this: DrizzleAdapter, { id, collection, locale, req, select, versionData, where: whereArg,
|
|
3
|
+
export declare function updateVersion<T extends TypeWithID>(this: DrizzleAdapter, { id, collection, locale, req, returning, select, versionData, where: whereArg, }: UpdateVersionArgs<T>): Promise<TypeWithVersion<T>>;
|
|
4
4
|
//# sourceMappingURL=updateVersion.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"updateVersion.d.ts","sourceRoot":"","sources":["../src/updateVersion.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,UAAU,EACV,eAAe,EACf,iBAAiB,EAClB,MAAM,SAAS,CAAA;AAKhB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAMhD,wBAAsB,aAAa,CAAC,CAAC,SAAS,UAAU,EACtD,IAAI,EAAE,cAAc,EACpB,EACE,EAAE,EACF,UAAU,EACV,MAAM,EACN,GAAG,EACH,MAAM,EACN,WAAW,EACX,KAAK,EAAE,QAAQ,
|
|
1
|
+
{"version":3,"file":"updateVersion.d.ts","sourceRoot":"","sources":["../src/updateVersion.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,UAAU,EACV,eAAe,EACf,iBAAiB,EAClB,MAAM,SAAS,CAAA;AAKhB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAMhD,wBAAsB,aAAa,CAAC,CAAC,SAAS,UAAU,EACtD,IAAI,EAAE,cAAc,EACpB,EACE,EAAE,EACF,UAAU,EACV,MAAM,EACN,GAAG,EACH,SAAS,EACT,MAAM,EACN,WAAW,EACX,KAAK,EAAE,QAAQ,GAChB,EAAE,iBAAiB,CAAC,CAAC,CAAC,+BAuCxB"}
|
package/dist/updateVersion.js
CHANGED
|
@@ -3,7 +3,7 @@ import toSnakeCase from 'to-snake-case';
|
|
|
3
3
|
import buildQuery from './queries/buildQuery.js';
|
|
4
4
|
import { upsertRow } from './upsertRow/index.js';
|
|
5
5
|
import { getTransaction } from './utilities/getTransaction.js';
|
|
6
|
-
export async function updateVersion({ id, collection, locale, req, select, versionData, where: whereArg
|
|
6
|
+
export async function updateVersion({ id, collection, locale, req, returning, select, versionData, where: whereArg }) {
|
|
7
7
|
const db = await getTransaction(this, req);
|
|
8
8
|
const collectionConfig = this.payload.collections[collection].config;
|
|
9
9
|
const whereToUse = whereArg || {
|
|
@@ -26,13 +26,13 @@ export async function updateVersion({ id, collection, locale, req, select, versi
|
|
|
26
26
|
data: versionData,
|
|
27
27
|
db,
|
|
28
28
|
fields,
|
|
29
|
+
ignoreResult: returning === false,
|
|
29
30
|
joinQuery: false,
|
|
30
31
|
operation: 'update',
|
|
31
32
|
req,
|
|
32
33
|
select,
|
|
33
34
|
tableName,
|
|
34
|
-
where
|
|
35
|
-
ignoreResult: returning === false
|
|
35
|
+
where
|
|
36
36
|
});
|
|
37
37
|
if (returning === false) {
|
|
38
38
|
return null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/updateVersion.ts"],"sourcesContent":["import type {\n SanitizedCollectionConfig,\n TypeWithID,\n TypeWithVersion,\n UpdateVersionArgs,\n} from 'payload'\n\nimport { buildVersionCollectionFields } from 'payload'\nimport toSnakeCase from 'to-snake-case'\n\nimport type { DrizzleAdapter } from './types.js'\n\nimport buildQuery from './queries/buildQuery.js'\nimport { upsertRow } from './upsertRow/index.js'\nimport { getTransaction } from './utilities/getTransaction.js'\n\nexport async function updateVersion<T extends TypeWithID>(\n this: DrizzleAdapter,\n {\n id,\n collection,\n locale,\n req,\n select,\n versionData,\n where: whereArg,\n
|
|
1
|
+
{"version":3,"sources":["../src/updateVersion.ts"],"sourcesContent":["import type {\n SanitizedCollectionConfig,\n TypeWithID,\n TypeWithVersion,\n UpdateVersionArgs,\n} from 'payload'\n\nimport { buildVersionCollectionFields } from 'payload'\nimport toSnakeCase from 'to-snake-case'\n\nimport type { DrizzleAdapter } from './types.js'\n\nimport buildQuery from './queries/buildQuery.js'\nimport { upsertRow } from './upsertRow/index.js'\nimport { getTransaction } from './utilities/getTransaction.js'\n\nexport async function updateVersion<T extends TypeWithID>(\n this: DrizzleAdapter,\n {\n id,\n collection,\n locale,\n req,\n returning,\n select,\n versionData,\n where: whereArg,\n }: UpdateVersionArgs<T>,\n) {\n const db = await getTransaction(this, req)\n const collectionConfig: SanitizedCollectionConfig = this.payload.collections[collection].config\n const whereToUse = whereArg || { id: { equals: id } }\n const tableName = this.tableNameMap.get(\n `_${toSnakeCase(collectionConfig.slug)}${this.versionsSuffix}`,\n )\n\n const fields = buildVersionCollectionFields(this.payload.config, collectionConfig, true)\n\n const { where } = buildQuery({\n adapter: this,\n fields,\n locale,\n tableName,\n where: whereToUse,\n })\n\n const result = await upsertRow<TypeWithVersion<T>>({\n id,\n adapter: this,\n data: versionData,\n db,\n fields,\n ignoreResult: returning === false,\n joinQuery: false,\n operation: 'update',\n req,\n select,\n tableName,\n where,\n })\n\n if (returning === false) {\n return null\n }\n\n return result\n}\n"],"names":["buildVersionCollectionFields","toSnakeCase","buildQuery","upsertRow","getTransaction","updateVersion","id","collection","locale","req","returning","select","versionData","where","whereArg","db","collectionConfig","payload","collections","config","whereToUse","equals","tableName","tableNameMap","get","slug","versionsSuffix","fields","adapter","result","data","ignoreResult","joinQuery","operation"],"mappings":"AAOA,SAASA,4BAA4B,QAAQ,UAAS;AACtD,OAAOC,iBAAiB,gBAAe;AAIvC,OAAOC,gBAAgB,0BAAyB;AAChD,SAASC,SAAS,QAAQ,uBAAsB;AAChD,SAASC,cAAc,QAAQ,gCAA+B;AAE9D,OAAO,eAAeC,cAEpB,EACEC,EAAE,EACFC,UAAU,EACVC,MAAM,EACNC,GAAG,EACHC,SAAS,EACTC,MAAM,EACNC,WAAW,EACXC,OAAOC,QAAQ,EACM;IAEvB,MAAMC,KAAK,MAAMX,eAAe,IAAI,EAAEK;IACtC,MAAMO,mBAA8C,IAAI,CAACC,OAAO,CAACC,WAAW,CAACX,WAAW,CAACY,MAAM;IAC/F,MAAMC,aAAaN,YAAY;QAAER,IAAI;YAAEe,QAAQf;QAAG;IAAE;IACpD,MAAMgB,YAAY,IAAI,CAACC,YAAY,CAACC,GAAG,CACrC,CAAC,CAAC,EAAEvB,YAAYe,iBAAiBS,IAAI,IAAI,IAAI,CAACC,cAAc,EAAE;IAGhE,MAAMC,SAAS3B,6BAA6B,IAAI,CAACiB,OAAO,CAACE,MAAM,EAAEH,kBAAkB;IAEnF,MAAM,EAAEH,KAAK,EAAE,GAAGX,WAAW;QAC3B0B,SAAS,IAAI;QACbD;QACAnB;QACAc;QACAT,OAAOO;IACT;IAEA,MAAMS,SAAS,MAAM1B,UAA8B;QACjDG;QACAsB,SAAS,IAAI;QACbE,MAAMlB;QACNG;QACAY;QACAI,cAAcrB,cAAc;QAC5BsB,WAAW;QACXC,WAAW;QACXxB;QACAE;QACAW;QACAT;IACF;IAEA,IAAIH,cAAc,OAAO;QACvB,OAAO;IACT;IAEA,OAAOmB;AACT"}
|
|
@@ -10,7 +10,7 @@ type BaseArgs = {
|
|
|
10
10
|
* When true, skips reading the data back from the database and returns the input data
|
|
11
11
|
* @default false
|
|
12
12
|
*/
|
|
13
|
-
ignoreResult?:
|
|
13
|
+
ignoreResult?: 'idOnly' | boolean;
|
|
14
14
|
joinQuery?: JoinQuery;
|
|
15
15
|
path?: string;
|
|
16
16
|
req?: Partial<PayloadRequest>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/upsertRow/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,aAAa,CAAA;AACtC,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAEpF,OAAO,KAAK,EAAE,cAAc,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAEpF,KAAK,QAAQ,GAAG;IACd,OAAO,EAAE,cAAc,CAAA;IACvB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC7B,EAAE,EAAE,cAAc,CAAC,SAAS,CAAC,GAAG,kBAAkB,CAAA;IAClD,MAAM,EAAE,cAAc,EAAE,CAAA;IACxB;;;OAGG;IACH,YAAY,CAAC,EAAE,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/upsertRow/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,aAAa,CAAA;AACtC,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAEpF,OAAO,KAAK,EAAE,cAAc,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAEpF,KAAK,QAAQ,GAAG;IACd,OAAO,EAAE,cAAc,CAAA;IACvB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC7B,EAAE,EAAE,cAAc,CAAC,SAAS,CAAC,GAAG,kBAAkB,CAAA;IAClD,MAAM,EAAE,cAAc,EAAE,CAAA;IACxB;;;OAGG;IACH,YAAY,CAAC,EAAE,QAAQ,GAAG,OAAO,CAAA;IACjC,SAAS,CAAC,EAAE,SAAS,CAAA;IACrB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,GAAG,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC,CAAA;IAC7B,SAAS,EAAE,MAAM,CAAA;CAClB,CAAA;AAED,KAAK,UAAU,GAAG;IAChB,EAAE,CAAC,EAAE,KAAK,CAAA;IACV,SAAS,CAAC,EAAE,KAAK,CAAA;IACjB,SAAS,EAAE,QAAQ,CAAA;IACnB,MAAM,CAAC,EAAE,UAAU,CAAA;IACnB,YAAY,CAAC,EAAE,KAAK,CAAA;IACpB,KAAK,CAAC,EAAE,KAAK,CAAA;CACd,GAAG,QAAQ,CAAA;AAEZ,KAAK,UAAU,GAAG;IAChB,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IACpB,SAAS,CAAC,EAAE,SAAS,CAAA;IACrB,SAAS,EAAE,QAAQ,CAAA;IACnB,MAAM,CAAC,EAAE,UAAU,CAAA;IACnB,YAAY,CAAC,EAAE,aAAa,CAAA;IAC5B,KAAK,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC,CAAA;CACrB,GAAG,QAAQ,CAAA;AAEZ,MAAM,MAAM,IAAI,GAAG,UAAU,GAAG,UAAU,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/upsertRow/types.ts"],"sourcesContent":["import type { SQL } from 'drizzle-orm'\nimport type { FlattenedField, JoinQuery, PayloadRequest, SelectType } from 'payload'\n\nimport type { DrizzleAdapter, DrizzleTransaction, GenericColumn } from '../types.js'\n\ntype BaseArgs = {\n adapter: DrizzleAdapter\n data: Record<string, unknown>\n db: DrizzleAdapter['drizzle'] | DrizzleTransaction\n fields: FlattenedField[]\n /**\n * When true, skips reading the data back from the database and returns the input data\n * @default false\n */\n ignoreResult?:
|
|
1
|
+
{"version":3,"sources":["../../src/upsertRow/types.ts"],"sourcesContent":["import type { SQL } from 'drizzle-orm'\nimport type { FlattenedField, JoinQuery, PayloadRequest, SelectType } from 'payload'\n\nimport type { DrizzleAdapter, DrizzleTransaction, GenericColumn } from '../types.js'\n\ntype BaseArgs = {\n adapter: DrizzleAdapter\n data: Record<string, unknown>\n db: DrizzleAdapter['drizzle'] | DrizzleTransaction\n fields: FlattenedField[]\n /**\n * When true, skips reading the data back from the database and returns the input data\n * @default false\n */\n ignoreResult?: 'idOnly' | boolean\n joinQuery?: JoinQuery\n path?: string\n req?: Partial<PayloadRequest>\n tableName: string\n}\n\ntype CreateArgs = {\n id?: never\n joinQuery?: never\n operation: 'create'\n select?: SelectType\n upsertTarget?: never\n where?: never\n} & BaseArgs\n\ntype UpdateArgs = {\n id?: number | string\n joinQuery?: JoinQuery\n operation: 'update'\n select?: SelectType\n upsertTarget?: GenericColumn\n where?: SQL<unknown>\n} & BaseArgs\n\nexport type Args = CreateArgs | UpdateArgs\n"],"names":[],"mappings":"AAuCA,WAA0C"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payloadcms/drizzle",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.27.0-canary.7edf702",
|
|
4
4
|
"description": "A library of shared functions used by different payload database adapters",
|
|
5
5
|
"homepage": "https://payloadcms.com",
|
|
6
6
|
"repository": {
|
|
@@ -53,10 +53,10 @@
|
|
|
53
53
|
"@types/pg": "8.10.2",
|
|
54
54
|
"@types/to-snake-case": "1.0.0",
|
|
55
55
|
"@payloadcms/eslint-config": "3.9.0",
|
|
56
|
-
"payload": "3.
|
|
56
|
+
"payload": "3.27.0-canary.7edf702"
|
|
57
57
|
},
|
|
58
58
|
"peerDependencies": {
|
|
59
|
-
"payload": "3.
|
|
59
|
+
"payload": "3.27.0-canary.7edf702"
|
|
60
60
|
},
|
|
61
61
|
"scripts": {
|
|
62
62
|
"build": "pnpm build:swc && pnpm build:types",
|
package/dist/update.d.ts
DELETED
package/dist/update.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
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
|
package/dist/update.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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"}
|