@payloadcms/drizzle 3.39.0-canary.2 → 3.39.0-canary.4
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/count.js +1 -1
- package/dist/count.js.map +1 -1
- package/dist/countGlobalVersions.js +1 -1
- package/dist/countGlobalVersions.js.map +1 -1
- package/dist/countVersions.js +1 -1
- package/dist/countVersions.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/find/findMany.js +1 -1
- package/dist/find/findMany.js.map +1 -1
- package/dist/find/traverseFields.js +1 -1
- package/dist/find/traverseFields.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/postgres/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.d.ts.map +1 -1
- package/dist/postgres/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.js.map +1 -1
- package/dist/queries/buildOrderBy.d.ts.map +1 -1
- package/dist/queries/buildOrderBy.js +11 -2
- package/dist/queries/buildOrderBy.js.map +1 -1
- package/dist/queries/buildQuery.d.ts +2 -2
- package/dist/queries/buildQuery.d.ts.map +1 -1
- package/dist/queries/buildQuery.js +1 -2
- package/dist/queries/buildQuery.js.map +1 -1
- package/dist/queries/getTableColumnFromPath.js +1 -1
- package/dist/queries/getTableColumnFromPath.js.map +1 -1
- package/dist/queries/operatorMap.d.ts +2 -2
- package/dist/queries/operatorMap.d.ts.map +1 -1
- package/dist/queries/operatorMap.js.map +1 -1
- package/dist/queries/selectDistinct.d.ts.map +1 -1
- package/dist/queries/selectDistinct.js.map +1 -1
- package/dist/transactions/commitTransaction.js +1 -1
- package/dist/transactions/commitTransaction.js.map +1 -1
- package/dist/transform/write/relationships.js +1 -1
- package/dist/transform/write/relationships.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 +4 -4
- package/dist/updateGlobalVersion.js.map +1 -1
- package/dist/updateMany.js +1 -1
- package/dist/updateMany.js.map +1 -1
- package/dist/updateOne.js +1 -1
- 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 +4 -4
- package/dist/updateVersion.js.map +1 -1
- package/dist/upsertRow/insertArrays.js +1 -1
- package/dist/upsertRow/insertArrays.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
|
@@ -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"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { buildVersionGlobalFields } from 'payload';
|
|
2
2
|
import toSnakeCase from 'to-snake-case';
|
|
3
|
-
import buildQuery from './queries/buildQuery.js';
|
|
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,SAASC,UAAU,QAAQ,0BAAyB;AACpD,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/updateMany.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import toSnakeCase from 'to-snake-case';
|
|
2
|
-
import buildQuery from './queries/buildQuery.js';
|
|
2
|
+
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';
|
package/dist/updateMany.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/updateMany.ts"],"sourcesContent":["import type { LibSQLDatabase } from 'drizzle-orm/libsql'\nimport type { UpdateMany } 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 updateMany: UpdateMany = async function updateMany(\n this: DrizzleAdapter,\n {\n collection: collectionSlug,\n data,\n joins: joinQuery,\n limit,\n locale,\n req,\n returning,\n select,\n sort: sortArg,\n where: whereToUse,\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\n const sort = sortArg !== undefined && sortArg !== null ? sortArg : collection.defaultSort\n\n const { joins, orderBy, selectFields, where } = buildQuery({\n adapter: this,\n fields: collection.flattenedFields,\n locale,\n sort,\n tableName,\n where: whereToUse,\n })\n\n let idsToUpdate: (number | string)[] = []\n\n const selectDistinctResult = await selectDistinct({\n adapter: this,\n db,\n joins,\n query: ({ query }) =>\n orderBy ? query.orderBy(() => orderBy.map(({ column, order }) => order(column))) : query,\n selectFields,\n tableName,\n where,\n })\n\n if (selectDistinctResult?.[0]?.id) {\n idsToUpdate = selectDistinctResult?.map((doc) => doc.id)\n } else if (whereToUse && !joins.length) {\n // If id wasn't passed but `where` without any joins, retrieve it with findFirst\n\n const _db = db as LibSQLDatabase\n\n const table = this.tables[tableName]\n\n let query = _db.select({ id: table.id }).from(table).where(where).$dynamic()\n\n if (typeof limit === 'number' && limit > 0) {\n query = query.limit(limit)\n }\n\n if (orderBy) {\n query = query.orderBy(() => orderBy.map(({ column, order }) => order(column)))\n }\n\n const docsToUpdate = await query\n\n idsToUpdate = docsToUpdate?.map((doc) => doc.id)\n }\n\n if (!idsToUpdate.length) {\n return []\n }\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 idToUpdate of idsToUpdate) {\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 results.push(result)\n }\n\n if (returning === false) {\n return null\n }\n\n return results\n}\n"],"names":["toSnakeCase","buildQuery","selectDistinct","upsertRow","getTransaction","updateMany","collection","collectionSlug","data","joins","joinQuery","limit","locale","req","returning","select","sort","sortArg","where","whereToUse","db","payload","collections","config","tableName","tableNameMap","get","slug","undefined","defaultSort","orderBy","selectFields","adapter","fields","flattenedFields","idsToUpdate","selectDistinctResult","query","map","column","order","id","doc","length","_db","table","tables","from","$dynamic","docsToUpdate","results","idToUpdate","result","ignoreResult","operation","push"],"mappings":"AAGA,OAAOA,iBAAiB,gBAAe;AAIvC,
|
|
1
|
+
{"version":3,"sources":["../src/updateMany.ts"],"sourcesContent":["import type { LibSQLDatabase } from 'drizzle-orm/libsql'\nimport type { UpdateMany } 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 updateMany: UpdateMany = async function updateMany(\n this: DrizzleAdapter,\n {\n collection: collectionSlug,\n data,\n joins: joinQuery,\n limit,\n locale,\n req,\n returning,\n select,\n sort: sortArg,\n where: whereToUse,\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\n const sort = sortArg !== undefined && sortArg !== null ? sortArg : collection.defaultSort\n\n const { joins, orderBy, selectFields, where } = buildQuery({\n adapter: this,\n fields: collection.flattenedFields,\n locale,\n sort,\n tableName,\n where: whereToUse,\n })\n\n let idsToUpdate: (number | string)[] = []\n\n const selectDistinctResult = await selectDistinct({\n adapter: this,\n db,\n joins,\n query: ({ query }) =>\n orderBy ? query.orderBy(() => orderBy.map(({ column, order }) => order(column))) : query,\n selectFields,\n tableName,\n where,\n })\n\n if (selectDistinctResult?.[0]?.id) {\n idsToUpdate = selectDistinctResult?.map((doc) => doc.id)\n } else if (whereToUse && !joins.length) {\n // If id wasn't passed but `where` without any joins, retrieve it with findFirst\n\n const _db = db as LibSQLDatabase\n\n const table = this.tables[tableName]\n\n let query = _db.select({ id: table.id }).from(table).where(where).$dynamic()\n\n if (typeof limit === 'number' && limit > 0) {\n query = query.limit(limit)\n }\n\n if (orderBy) {\n query = query.orderBy(() => orderBy.map(({ column, order }) => order(column)))\n }\n\n const docsToUpdate = await query\n\n idsToUpdate = docsToUpdate?.map((doc) => doc.id)\n }\n\n if (!idsToUpdate.length) {\n return []\n }\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 idToUpdate of idsToUpdate) {\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 results.push(result)\n }\n\n if (returning === false) {\n return null\n }\n\n return results\n}\n"],"names":["toSnakeCase","buildQuery","selectDistinct","upsertRow","getTransaction","updateMany","collection","collectionSlug","data","joins","joinQuery","limit","locale","req","returning","select","sort","sortArg","where","whereToUse","db","payload","collections","config","tableName","tableNameMap","get","slug","undefined","defaultSort","orderBy","selectFields","adapter","fields","flattenedFields","idsToUpdate","selectDistinctResult","query","map","column","order","id","doc","length","_db","table","tables","from","$dynamic","docsToUpdate","results","idToUpdate","result","ignoreResult","operation","push"],"mappings":"AAGA,OAAOA,iBAAiB,gBAAe;AAIvC,SAASC,UAAU,QAAQ,0BAAyB;AACpD,SAASC,cAAc,QAAQ,8BAA6B;AAC5D,SAASC,SAAS,QAAQ,uBAAsB;AAChD,SAASC,cAAc,QAAQ,gCAA+B;AAE9D,OAAO,MAAMC,aAAyB,eAAeA,WAEnD,EACEC,YAAYC,cAAc,EAC1BC,IAAI,EACJC,OAAOC,SAAS,EAChBC,KAAK,EACLC,MAAM,EACNC,GAAG,EACHC,SAAS,EACTC,MAAM,EACNC,MAAMC,OAAO,EACbC,OAAOC,UAAU,EAClB;IAED,MAAMC,KAAK,MAAMhB,eAAe,IAAI,EAAES;IACtC,MAAMP,aAAa,IAAI,CAACe,OAAO,CAACC,WAAW,CAACf,eAAe,CAACgB,MAAM;IAClE,MAAMC,YAAY,IAAI,CAACC,YAAY,CAACC,GAAG,CAAC1B,YAAYM,WAAWqB,IAAI;IAEnE,MAAMX,OAAOC,YAAYW,aAAaX,YAAY,OAAOA,UAAUX,WAAWuB,WAAW;IAEzF,MAAM,EAAEpB,KAAK,EAAEqB,OAAO,EAAEC,YAAY,EAAEb,KAAK,EAAE,GAAGjB,WAAW;QACzD+B,SAAS,IAAI;QACbC,QAAQ3B,WAAW4B,eAAe;QAClCtB;QACAI;QACAQ;QACAN,OAAOC;IACT;IAEA,IA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C,cAAc;YAC5BJ;YACA4C,WAAW;YACXzC;YACAE;YACAS;QACF;QACA0B,QAAQK,IAAI,CAACH;IACf;IAEA,IAAItC,cAAc,OAAO;QACvB,OAAO;IACT;IAEA,OAAOoC;AACT,EAAC"}
|
package/dist/updateOne.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import toSnakeCase from 'to-snake-case';
|
|
2
|
-
import buildQuery from './queries/buildQuery.js';
|
|
2
|
+
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';
|
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 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 let idToUpdate = id\n\n if (!idToUpdate) {\n const { joins, selectFields, where } = buildQuery({\n adapter: this,\n fields: collection.flattenedFields,\n locale,\n tableName,\n where: whereArg,\n })\n\n // selectDistinct will only return if there are joins\n const selectDistinctResult = await selectDistinct({\n adapter: this,\n db,\n joins,\n query: ({ query }) => query.limit(1),\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\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","idToUpdate","selectFields","adapter","fields","flattenedFields","selectDistinctResult","query","limit","length","table","tables","docsToUpdate","from","result","ignoreResult","operation"],"mappings":"AAGA,OAAOA,iBAAiB,gBAAe;AAIvC,
|
|
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 let idToUpdate = id\n\n if (!idToUpdate) {\n const { joins, selectFields, where } = buildQuery({\n adapter: this,\n fields: collection.flattenedFields,\n locale,\n tableName,\n where: whereArg,\n })\n\n // selectDistinct will only return if there are joins\n const selectDistinctResult = await selectDistinct({\n adapter: this,\n db,\n joins,\n query: ({ query }) => query.limit(1),\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\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","idToUpdate","selectFields","adapter","fields","flattenedFields","selectDistinctResult","query","limit","length","table","tables","docsToUpdate","from","result","ignoreResult","operation"],"mappings":"AAGA,OAAOA,iBAAiB,gBAAe;AAIvC,SAASC,UAAU,QAAQ,0BAAyB;AACpD,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,IAAIC,aAAapB;IAEjB,IAAI,CAACoB,YAAY;QACf,MAAM,EAAEhB,KAAK,EAAEiB,YAAY,EAAEX,KAAK,EAAE,GAAGf,WAAW;YAChD2B,SAAS,IAAI;YACbC,QAAQtB,WAAWuB,eAAe;YAClClB;YACAU;YACAN,OAAOC;QACT;QAEA,qDAAqD;QACrD,MAAMc,uBAAuB,MAAM7B,eAAe;YAChD0B,SAAS,IAAI;YACbV;YACAR;YACAsB,OAAO,CAAC,EAAEA,KAAK,EAAE,GAAKA,MAAMC,KAAK,CAAC;YAClCN;YACAL;YACAN;QACF;QAEA,IAAIe,sBAAsB,CAAC,EAAE,EAAEzB,IAAI;YACjCoB,aAAaK,sBAAsB,CAAC,EAAE,EAAEzB;QACxC,gFAAgF;QAClF,OAAO,IAAIW,YAAY,CAACP,MAAMwB,MAAM,EAAE;YACpC,MAAMC,QAAQ,IAAI,CAACC,MAAM,CAACd,UAAU;YAEpC,MAAMe,eAAe,MAAM,AAACnB,GACzBH,MAAM,CAAC;gBACNT,IAAI6B,MAAM7B,EAAE;YACd,GACCgC,IAAI,CAACH,OACLnB,KAAK,CAACA,OACNiB,KAAK,CAAC;YACTP,aAAaW,cAAc,CAAC,EAAE,EAAE/B;QAClC;IACF;IAEA,MAAMiC,SAAS,MAAMpC,UAAU;QAC7BG,IAAIoB;QACJE,SAAS,IAAI;QACbnB;QACAS;QACAW,QAAQtB,WAAWuB,eAAe;QAClCU,cAAc1B,cAAc;QAC5BH;QACA8B,WAAW;QACX5B;QACAE;QACAO;IACF;IAEA,IAAIR,cAAc,OAAO;QACvB,OAAO;IACT;IAEA,OAAOyB;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
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { buildVersionCollectionFields } from 'payload';
|
|
2
2
|
import toSnakeCase from 'to-snake-case';
|
|
3
|
-
import buildQuery from './queries/buildQuery.js';
|
|
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,SAASC,UAAU,QAAQ,0BAAyB;AACpD,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"}
|
|
@@ -14,7 +14,7 @@ export const insertArrays = async ({ adapter, arrays, db, parentRows, uuidMap =
|
|
|
14
14
|
const parentID = parentRows[parentRowIndex].id;
|
|
15
15
|
// Add any sub arrays that need to be created
|
|
16
16
|
// We will call this recursively below
|
|
17
|
-
arrayRows.forEach((arrayRow
|
|
17
|
+
arrayRows.forEach((arrayRow)=>{
|
|
18
18
|
if (Object.keys(arrayRow.arrays).length > 0) {
|
|
19
19
|
rowsByTable[tableName].arrays.push(arrayRow.arrays);
|
|
20
20
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/upsertRow/insertArrays.ts"],"sourcesContent":["import type { ArrayRowToInsert } from '../transform/write/types.js'\nimport type { DrizzleAdapter, DrizzleTransaction } from '../types.js'\n\ntype Args = {\n adapter: DrizzleAdapter\n arrays: {\n [tableName: string]: ArrayRowToInsert[]\n }[]\n db: DrizzleAdapter['drizzle'] | DrizzleTransaction\n parentRows: Record<string, unknown>[]\n uuidMap?: Record<string, number | string>\n}\n\ntype RowsByTable = {\n [tableName: string]: {\n arrays: {\n [tableName: string]: ArrayRowToInsert[]\n }[]\n locales: Record<string, unknown>[]\n rows: Record<string, unknown>[]\n }\n}\n\nexport const insertArrays = async ({\n adapter,\n arrays,\n db,\n parentRows,\n uuidMap = {},\n}: Args): Promise<void> => {\n // Maintain a map of flattened rows by table\n const rowsByTable: RowsByTable = {}\n\n arrays.forEach((arraysByTable, parentRowIndex) => {\n Object.entries(arraysByTable).forEach(([tableName, arrayRows]) => {\n // If the table doesn't exist in map, initialize it\n if (!rowsByTable[tableName]) {\n rowsByTable[tableName] = {\n arrays: [],\n locales: [],\n rows: [],\n }\n }\n\n const parentID = parentRows[parentRowIndex].id\n\n // Add any sub arrays that need to be created\n // We will call this recursively below\n arrayRows.forEach((arrayRow
|
|
1
|
+
{"version":3,"sources":["../../src/upsertRow/insertArrays.ts"],"sourcesContent":["import type { ArrayRowToInsert } from '../transform/write/types.js'\nimport type { DrizzleAdapter, DrizzleTransaction } from '../types.js'\n\ntype Args = {\n adapter: DrizzleAdapter\n arrays: {\n [tableName: string]: ArrayRowToInsert[]\n }[]\n db: DrizzleAdapter['drizzle'] | DrizzleTransaction\n parentRows: Record<string, unknown>[]\n uuidMap?: Record<string, number | string>\n}\n\ntype RowsByTable = {\n [tableName: string]: {\n arrays: {\n [tableName: string]: ArrayRowToInsert[]\n }[]\n locales: Record<string, unknown>[]\n rows: Record<string, unknown>[]\n }\n}\n\nexport const insertArrays = async ({\n adapter,\n arrays,\n db,\n parentRows,\n uuidMap = {},\n}: Args): Promise<void> => {\n // Maintain a map of flattened rows by table\n const rowsByTable: RowsByTable = {}\n\n arrays.forEach((arraysByTable, parentRowIndex) => {\n Object.entries(arraysByTable).forEach(([tableName, arrayRows]) => {\n // If the table doesn't exist in map, initialize it\n if (!rowsByTable[tableName]) {\n rowsByTable[tableName] = {\n arrays: [],\n locales: [],\n rows: [],\n }\n }\n\n const parentID = parentRows[parentRowIndex].id\n\n // Add any sub arrays that need to be created\n // We will call this recursively below\n arrayRows.forEach((arrayRow) => {\n if (Object.keys(arrayRow.arrays).length > 0) {\n rowsByTable[tableName].arrays.push(arrayRow.arrays)\n }\n\n // Set up parent IDs for both row and locale row\n arrayRow.row._parentID = parentID\n rowsByTable[tableName].rows.push(arrayRow.row)\n\n Object.entries(arrayRow.locales).forEach(([arrayRowLocale, arrayRowLocaleData]) => {\n arrayRowLocaleData._parentID = arrayRow.row.id\n arrayRowLocaleData._locale = arrayRowLocale\n rowsByTable[tableName].locales.push(arrayRowLocaleData)\n if (!arrayRow.row.id) {\n arrayRowLocaleData._getParentID = (rows: { _uuid: string; id: number }[]) => {\n const { id } = rows.find((each) => each._uuid === arrayRow.row._uuid)\n return id\n }\n }\n })\n })\n })\n })\n\n // Insert all corresponding arrays\n // (one insert per array table)\n for (const [tableName, row] of Object.entries(rowsByTable)) {\n // the nested arrays need the ID for the parentID foreign key\n let insertedRows: Args['parentRows']\n if (row.rows.length > 0) {\n insertedRows = await adapter.insert({\n db,\n tableName,\n values: row.rows,\n })\n\n insertedRows.forEach((row) => {\n if (\n typeof row._uuid === 'string' &&\n (typeof row.id === 'string' || typeof row.id === 'number')\n ) {\n uuidMap[row._uuid] = row.id\n }\n })\n }\n\n // Insert locale rows\n if (adapter.tables[`${tableName}${adapter.localesSuffix}`] && row.locales.length > 0) {\n if (!row.locales[0]._parentID) {\n row.locales = row.locales.map((localeRow) => {\n if (typeof localeRow._getParentID === 'function') {\n localeRow._parentID = localeRow._getParentID(insertedRows)\n delete localeRow._getParentID\n }\n return localeRow\n })\n }\n await adapter.insert({\n db,\n tableName: `${tableName}${adapter.localesSuffix}`,\n values: row.locales,\n })\n }\n\n // If there are sub arrays, call this function recursively\n if (row.arrays.length > 0) {\n await insertArrays({\n adapter,\n arrays: row.arrays,\n db,\n parentRows: insertedRows,\n })\n }\n }\n}\n"],"names":["insertArrays","adapter","arrays","db","parentRows","uuidMap","rowsByTable","forEach","arraysByTable","parentRowIndex","Object","entries","tableName","arrayRows","locales","rows","parentID","id","arrayRow","keys","length","push","row","_parentID","arrayRowLocale","arrayRowLocaleData","_locale","_getParentID","find","each","_uuid","insertedRows","insert","values","tables","localesSuffix","map","localeRow"],"mappings":"AAuBA,OAAO,MAAMA,eAAe,OAAO,EACjCC,OAAO,EACPC,MAAM,EACNC,EAAE,EACFC,UAAU,EACVC,UAAU,CAAC,CAAC,EACP;IACL,4CAA4C;IAC5C,MAAMC,cAA2B,CAAC;IAElCJ,OAAOK,OAAO,CAAC,CAACC,eAAeC;QAC7BC,OAAOC,OAAO,CAACH,eAAeD,OAAO,CAAC,CAAC,CAACK,WAAWC,UAAU;YAC3D,mDAAmD;YACnD,IAAI,CAACP,WAAW,CAACM,UAAU,EAAE;gBAC3BN,WAAW,CAACM,UAAU,GAAG;oBACvBV,QAAQ,EAAE;oBACVY,SAAS,EAAE;oBACXC,MAAM,EAAE;gBACV;YACF;YAEA,MAAMC,WAAWZ,UAAU,CAACK,eAAe,CAACQ,EAAE;YAE9C,6CAA6C;YAC7C,sCAAsC;YACtCJ,UAAUN,OAAO,CAAC,CAACW;gBACjB,IAAIR,OAAOS,IAAI,CAACD,SAAShB,MAAM,EAAEkB,MAAM,GAAG,GAAG;oBAC3Cd,WAAW,CAACM,UAAU,CAACV,MAAM,CAACmB,IAAI,CAACH,SAAShB,MAAM;gBACpD;gBAEA,gDAAgD;gBAChDgB,SAASI,GAAG,CAACC,SAAS,GAAGP;gBACzBV,WAAW,CAACM,UAAU,CAACG,IAAI,CAACM,IAAI,CAACH,SAASI,GAAG;gBAE7CZ,OAAOC,OAAO,CAACO,SAASJ,OAAO,EAAEP,OAAO,CAAC,CAAC,CAACiB,gBAAgBC,mBAAmB;oBAC5EA,mBAAmBF,SAAS,GAAGL,SAASI,GAAG,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ACI;wBAC7C,OAAOM,UAAUV,YAAY;oBAC/B;oBACA,OAAOU;gBACT;YACF;YACA,MAAMpC,QAAQ+B,MAAM,CAAC;gBACnB7B;gBACAS,WAAW,GAAGA,YAAYX,QAAQkC,aAAa,EAAE;gBACjDF,QAAQX,IAAIR,OAAO;YACrB;QACF;QAEA,0DAA0D;QAC1D,IAAIQ,IAAIpB,MAAM,CAACkB,MAAM,GAAG,GAAG;YACzB,MAAMpB,aAAa;gBACjBC;gBACAC,QAAQoB,IAAIpB,MAAM;gBAClBC;gBACAC,YAAY2B;YACd;QACF;IACF;AACF,EAAC"}
|
|
@@ -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,"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G,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.39.0-canary.
|
|
3
|
+
"version": "3.39.0-canary.4",
|
|
4
4
|
"description": "A library of shared functions used by different payload database adapters",
|
|
5
5
|
"homepage": "https://payloadcms.com",
|
|
6
6
|
"repository": {
|
|
@@ -54,10 +54,10 @@
|
|
|
54
54
|
"@types/pg": "8.10.2",
|
|
55
55
|
"@types/to-snake-case": "1.0.0",
|
|
56
56
|
"@payloadcms/eslint-config": "3.28.0",
|
|
57
|
-
"payload": "3.39.0-canary.
|
|
57
|
+
"payload": "3.39.0-canary.4"
|
|
58
58
|
},
|
|
59
59
|
"peerDependencies": {
|
|
60
|
-
"payload": "3.39.0-canary.
|
|
60
|
+
"payload": "3.39.0-canary.4"
|
|
61
61
|
},
|
|
62
62
|
"scripts": {
|
|
63
63
|
"build": "pnpm build:swc && pnpm build:types",
|