@payloadcms/drizzle 3.42.0-internal.f9d0258 → 3.43.0-canary.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"deleteVersions.d.ts","sourceRoot":"","sources":["../src/deleteVersions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAA6B,MAAM,SAAS,CAAA;AAWxE,eAAO,MAAM,cAAc,EAAE,cAyC5B,CAAA"}
1
+ {"version":3,"file":"deleteVersions.d.ts","sourceRoot":"","sources":["../src/deleteVersions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAA6C,MAAM,SAAS,CAAA;AAWxF,eAAO,MAAM,cAAc,EAAE,cAoD5B,CAAA"}
@@ -1,13 +1,23 @@
1
1
  import { inArray } from 'drizzle-orm';
2
- import { buildVersionCollectionFields } from 'payload';
2
+ import { APIError, buildVersionCollectionFields, buildVersionGlobalFields } from 'payload';
3
3
  import toSnakeCase from 'to-snake-case';
4
4
  import { findMany } from './find/findMany.js';
5
5
  import { getTransaction } from './utilities/getTransaction.js';
6
- export const deleteVersions = async function deleteVersion({ collection, locale, req, where: where }) {
6
+ export const deleteVersions = async function deleteVersion({ collection: collectionSlug, globalSlug, locale, req, where: where }) {
7
7
  const db = await getTransaction(this, req);
8
- const collectionConfig = this.payload.collections[collection].config;
9
- const tableName = this.tableNameMap.get(`_${toSnakeCase(collectionConfig.slug)}${this.versionsSuffix}`);
10
- const fields = buildVersionCollectionFields(this.payload.config, collectionConfig, true);
8
+ let tableName;
9
+ let fields;
10
+ if (globalSlug) {
11
+ const globalConfig = this.payload.globals.config.find(({ slug })=>slug === globalSlug);
12
+ tableName = this.tableNameMap.get(`_${toSnakeCase(globalSlug)}${this.versionsSuffix}`);
13
+ fields = buildVersionGlobalFields(this.payload.config, globalConfig, true);
14
+ } else if (collectionSlug) {
15
+ const collectionConfig = this.payload.collections[collectionSlug].config;
16
+ tableName = this.tableNameMap.get(`_${toSnakeCase(collectionConfig.slug)}${this.versionsSuffix}`);
17
+ fields = buildVersionCollectionFields(this.payload.config, collectionConfig, true);
18
+ } else {
19
+ throw new APIError('Either collection or globalSlug must be passed.');
20
+ }
11
21
  const { docs } = await findMany({
12
22
  adapter: this,
13
23
  fields,
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/deleteVersions.ts"],"sourcesContent":["import type { DeleteVersions, SanitizedCollectionConfig } from 'payload'\n\nimport { inArray } from 'drizzle-orm'\nimport { buildVersionCollectionFields } from 'payload'\nimport toSnakeCase from 'to-snake-case'\n\nimport type { DrizzleAdapter } from './types.js'\n\nimport { findMany } from './find/findMany.js'\nimport { getTransaction } from './utilities/getTransaction.js'\n\nexport const deleteVersions: DeleteVersions = async function deleteVersion(\n this: DrizzleAdapter,\n { collection, locale, req, where: where },\n) {\n const db = await getTransaction(this, req)\n const collectionConfig: SanitizedCollectionConfig = this.payload.collections[collection].config\n\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 { docs } = await findMany({\n adapter: this,\n fields,\n joins: false,\n limit: 0,\n locale,\n page: 1,\n pagination: false,\n req,\n tableName,\n where,\n })\n\n const ids = []\n\n docs.forEach((doc) => {\n ids.push(doc.id)\n })\n\n if (ids.length > 0) {\n await this.deleteWhere({\n db,\n tableName,\n where: inArray(this.tables[tableName].id, ids),\n })\n }\n\n return docs\n}\n"],"names":["inArray","buildVersionCollectionFields","toSnakeCase","findMany","getTransaction","deleteVersions","deleteVersion","collection","locale","req","where","db","collectionConfig","payload","collections","config","tableName","tableNameMap","get","slug","versionsSuffix","fields","docs","adapter","joins","limit","page","pagination","ids","forEach","doc","push","id","length","deleteWhere","tables"],"mappings":"AAEA,SAASA,OAAO,QAAQ,cAAa;AACrC,SAASC,4BAA4B,QAAQ,UAAS;AACtD,OAAOC,iBAAiB,gBAAe;AAIvC,SAASC,QAAQ,QAAQ,qBAAoB;AAC7C,SAASC,cAAc,QAAQ,gCAA+B;AAE9D,OAAO,MAAMC,iBAAiC,eAAeC,cAE3D,EAAEC,UAAU,EAAEC,MAAM,EAAEC,GAAG,EAAEC,OAAOA,KAAK,EAAE;IAEzC,MAAMC,KAAK,MAAMP,eAAe,IAAI,EAAEK;IACtC,MAAMG,mBAA8C,IAAI,CAACC,OAAO,CAACC,WAAW,CAACP,WAAW,CAACQ,MAAM;IAE/F,MAAMC,YAAY,IAAI,CAACC,YAAY,CAACC,GAAG,CACrC,CAAC,CAAC,EAAEhB,YAAYU,iBAAiBO,IAAI,IAAI,IAAI,CAACC,cAAc,EAAE;IAGhE,MAAMC,SAASpB,6BAA6B,IAAI,CAACY,OAAO,CAACE,MAAM,EAAEH,kBAAkB;IAEnF,MAAM,EAAEU,IAAI,EAAE,GAAG,MAAMnB,SAAS;QAC9BoB,SAAS,IAAI;QACbF;QACAG,OAAO;QACPC,OAAO;QACPjB;QACAkB,MAAM;QACNC,YAAY;QACZlB;QACAO;QACAN;IACF;IAEA,MAAMkB,MAAM,EAAE;IAEdN,KAAKO,OAAO,CAAC,CAACC;QACZF,IAAIG,IAAI,CAACD,IAAIE,EAAE;IACjB;IAEA,IAAIJ,IAAIK,MAAM,GAAG,GAAG;QAClB,MAAM,IAAI,CAACC,WAAW,CAAC;YACrBvB;YACAK;YACAN,OAAOV,QAAQ,IAAI,CAACmC,MAAM,CAACnB,UAAU,CAACgB,EAAE,EAAEJ;QAC5C;IACF;IAEA,OAAON;AACT,EAAC"}
1
+ {"version":3,"sources":["../src/deleteVersions.ts"],"sourcesContent":["import type { DeleteVersions, FlattenedField, SanitizedCollectionConfig } from 'payload'\n\nimport { inArray } from 'drizzle-orm'\nimport { APIError, buildVersionCollectionFields, buildVersionGlobalFields } from 'payload'\nimport toSnakeCase from 'to-snake-case'\n\nimport type { DrizzleAdapter } from './types.js'\n\nimport { findMany } from './find/findMany.js'\nimport { getTransaction } from './utilities/getTransaction.js'\n\nexport const deleteVersions: DeleteVersions = async function deleteVersion(\n this: DrizzleAdapter,\n { collection: collectionSlug, globalSlug, locale, req, where: where },\n) {\n const db = await getTransaction(this, req)\n\n let tableName: string\n let fields: FlattenedField[]\n\n if (globalSlug) {\n const globalConfig = this.payload.globals.config.find(({ slug }) => slug === globalSlug)\n tableName = this.tableNameMap.get(`_${toSnakeCase(globalSlug)}${this.versionsSuffix}`)\n fields = buildVersionGlobalFields(this.payload.config, globalConfig, true)\n } else if (collectionSlug) {\n const collectionConfig: SanitizedCollectionConfig =\n this.payload.collections[collectionSlug].config\n tableName = this.tableNameMap.get(\n `_${toSnakeCase(collectionConfig.slug)}${this.versionsSuffix}`,\n )\n fields = buildVersionCollectionFields(this.payload.config, collectionConfig, true)\n } else {\n throw new APIError('Either collection or globalSlug must be passed.')\n }\n\n const { docs } = await findMany({\n adapter: this,\n fields,\n joins: false,\n limit: 0,\n locale,\n page: 1,\n pagination: false,\n req,\n tableName,\n where,\n })\n\n const ids = []\n\n docs.forEach((doc) => {\n ids.push(doc.id)\n })\n\n if (ids.length > 0) {\n await this.deleteWhere({\n db,\n tableName,\n where: inArray(this.tables[tableName].id, ids),\n })\n }\n\n return docs\n}\n"],"names":["inArray","APIError","buildVersionCollectionFields","buildVersionGlobalFields","toSnakeCase","findMany","getTransaction","deleteVersions","deleteVersion","collection","collectionSlug","globalSlug","locale","req","where","db","tableName","fields","globalConfig","payload","globals","config","find","slug","tableNameMap","get","versionsSuffix","collectionConfig","collections","docs","adapter","joins","limit","page","pagination","ids","forEach","doc","push","id","length","deleteWhere","tables"],"mappings":"AAEA,SAASA,OAAO,QAAQ,cAAa;AACrC,SAASC,QAAQ,EAAEC,4BAA4B,EAAEC,wBAAwB,QAAQ,UAAS;AAC1F,OAAOC,iBAAiB,gBAAe;AAIvC,SAASC,QAAQ,QAAQ,qBAAoB;AAC7C,SAASC,cAAc,QAAQ,gCAA+B;AAE9D,OAAO,M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0C,MAAM,CAAC1B,UAAU,CAACuB,EAAE,EAAEJ;QAC5C;IACF;IAEA,OAAON;AACT,EAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@payloadcms/drizzle",
3
- "version": "3.42.0-internal.f9d0258",
3
+ "version": "3.43.0-canary.0",
4
4
  "description": "A library of shared functions used by different payload database adapters",
5
5
  "homepage": "https://payloadcms.com",
6
6
  "repository": {
@@ -54,11 +54,11 @@
54
54
  "@libsql/client": "0.14.0",
55
55
  "@types/pg": "8.10.2",
56
56
  "@types/to-snake-case": "1.0.0",
57
- "payload": "3.42.0-internal.f9d0258",
58
- "@payloadcms/eslint-config": "3.28.0"
57
+ "@payloadcms/eslint-config": "3.28.0",
58
+ "payload": "3.43.0-canary.0"
59
59
  },
60
60
  "peerDependencies": {
61
- "payload": "3.42.0-internal.f9d0258"
61
+ "payload": "3.43.0-canary.0"
62
62
  },
63
63
  "scripts": {
64
64
  "build": "pnpm build:swc && pnpm build:types",