@payloadcms/db-mongodb 3.29.0-canary.8 → 3.29.0-internal.2984e42

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,3 +1,3 @@
1
- import { type UpdateMany } from 'payload';
1
+ import type { UpdateMany } from 'payload';
2
2
  export declare const updateMany: UpdateMany;
3
3
  //# sourceMappingURL=updateMany.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"updateMany.d.ts","sourceRoot":"","sources":["../src/updateMany.ts"],"names":[],"mappings":"AAEA,OAAO,EAA2B,KAAK,UAAU,EAAE,MAAM,SAAS,CAAA;AAYlE,eAAO,MAAM,UAAU,EAAE,UAiGxB,CAAA"}
1
+ {"version":3,"file":"updateMany.d.ts","sourceRoot":"","sources":["../src/updateMany.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAWzC,eAAO,MAAM,UAAU,EAAE,UAuExB,CAAA"}
@@ -1,31 +1,14 @@
1
- import { flattenWhereToOperators } from 'payload';
2
1
  import { buildQuery } from './queries/buildQuery.js';
3
- import { buildSortParam } from './queries/buildSortParam.js';
4
2
  import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js';
5
3
  import { getCollection } from './utilities/getEntity.js';
6
4
  import { getSession } from './utilities/getSession.js';
7
5
  import { handleError } from './utilities/handleError.js';
8
6
  import { transform } from './utilities/transform.js';
9
- export const updateMany = async function updateMany({ collection: collectionSlug, data, limit, locale, options: optionsArgs = {}, req, returning, select, sort: sortArg, where }) {
10
- let hasNearConstraint = false;
11
- if (where) {
12
- const constraints = flattenWhereToOperators(where);
13
- hasNearConstraint = constraints.some((prop)=>Object.keys(prop).some((key)=>key === 'near'));
14
- }
7
+ export const updateMany = async function updateMany({ collection: collectionSlug, data, limit, locale, options: optionsArgs = {}, req, returning, select, where }) {
15
8
  const { collectionConfig, Model } = getCollection({
16
9
  adapter: this,
17
10
  collectionSlug
18
11
  });
19
- let sort;
20
- if (!hasNearConstraint) {
21
- sort = buildSortParam({
22
- config: this.payload.config,
23
- fields: collectionConfig.flattenedFields,
24
- locale,
25
- sort: sortArg || collectionConfig.defaultSort,
26
- timestamps: true
27
- });
28
- }
29
12
  const options = {
30
13
  ...optionsArgs,
31
14
  lean: true,
@@ -57,8 +40,7 @@ export const updateMany = async function updateMany({ collection: collectionSlug
57
40
  limit,
58
41
  projection: {
59
42
  _id: 1
60
- },
61
- sort
43
+ }
62
44
  });
63
45
  if (documentsToUpdate.length === 0) {
64
46
  return null;
@@ -80,10 +62,7 @@ export const updateMany = async function updateMany({ collection: collectionSlug
80
62
  if (returning === false) {
81
63
  return null;
82
64
  }
83
- const result = await Model.find(query, {}, {
84
- ...options,
85
- sort
86
- });
65
+ const result = await Model.find(query, {}, options);
87
66
  transform({
88
67
  adapter: this,
89
68
  data: result,
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/updateMany.ts"],"sourcesContent":["import type { MongooseUpdateQueryOptions } from 'mongoose'\n\nimport { flattenWhereToOperators, type UpdateMany } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { buildSortParam } from './queries/buildSortParam.js'\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getCollection } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\nimport { handleError } from './utilities/handleError.js'\nimport { transform } from './utilities/transform.js'\n\nexport const updateMany: UpdateMany = async function updateMany(\n this: MongooseAdapter,\n {\n collection: collectionSlug,\n data,\n limit,\n locale,\n options: optionsArgs = {},\n req,\n returning,\n select,\n sort: sortArg,\n where,\n },\n) {\n let hasNearConstraint = false\n\n if (where) {\n const constraints = flattenWhereToOperators(where)\n hasNearConstraint = constraints.some((prop) => Object.keys(prop).some((key) => key === 'near'))\n }\n\n const { collectionConfig, Model } = getCollection({ adapter: this, collectionSlug })\n\n let sort: Record<string, unknown> | undefined\n if (!hasNearConstraint) {\n sort = buildSortParam({\n config: this.payload.config,\n fields: collectionConfig.flattenedFields,\n locale,\n sort: sortArg || collectionConfig.defaultSort,\n timestamps: true,\n })\n }\n\n const options: MongooseUpdateQueryOptions = {\n ...optionsArgs,\n lean: true,\n new: true,\n projection: buildProjectionFromSelect({\n adapter: this,\n fields: collectionConfig.flattenedFields,\n select,\n }),\n session: await getSession(this, req),\n }\n\n let query = await buildQuery({\n adapter: this,\n collectionSlug,\n fields: collectionConfig.flattenedFields,\n locale,\n where,\n })\n\n transform({ adapter: this, data, fields: collectionConfig.fields, operation: 'write' })\n\n try {\n if (typeof limit === 'number' && limit > 0) {\n const documentsToUpdate = await Model.find(\n query,\n {},\n { ...options, limit, projection: { _id: 1 }, sort },\n )\n if (documentsToUpdate.length === 0) {\n return null\n }\n\n query = { _id: { $in: documentsToUpdate.map((doc) => doc._id) } }\n }\n\n await Model.updateMany(query, data, options)\n } catch (error) {\n handleError({ collection: collectionSlug, error, req })\n }\n\n if (returning === false) {\n return null\n }\n\n const result = await Model.find(\n query,\n {},\n {\n ...options,\n sort,\n },\n )\n\n transform({\n adapter: this,\n data: result,\n fields: collectionConfig.fields,\n operation: 'read',\n })\n\n return result\n}\n"],"names":["flattenWhereToOperators","buildQuery","buildSortParam","buildProjectionFromSelect","getCollection","getSession","handleError","transform","updateMany","collection","collectionSlug","data","limit","locale","options","optionsArgs","req","returning","select","sort","sortArg","where","hasNearConstraint","constraints","some","prop","Object","keys","key","collectionConfig","Model","adapter","config","payload","fields","flattenedFields","defaultSort","timestamps","lean","new","projection","session","query","operation","documentsToUpdate","find","_id","length","$in","map","doc","error","result"],"mappings":"AAEA,SAASA,uBAAuB,QAAyB,UAAS;AAIlE,SAASC,UAAU,QAAQ,0BAAyB;AACpD,SAASC,cAAc,QAAQ,8BAA6B;AAC5D,SAASC,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,aAAa,QAAQ,2BAA0B;AACxD,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAAS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B,MAAMd,MAAMe,IAAI,CACxCH,OACA,CAAC,GACD;gBAAE,GAAG5B,OAAO;gBAAEF;gBAAO4B,YAAY;oBAAEM,KAAK;gBAAE;gBAAG3B;YAAK;YAEpD,IAAIyB,kBAAkBG,MAAM,KAAK,GAAG;gBAClC,OAAO;YACT;YAEAL,QAAQ;gBAAEI,KAAK;oBAAEE,KAAKJ,kBAAkBK,GAAG,CAAC,CAACC,MAAQA,IAAIJ,GAAG;gBAAE;YAAE;QAClE;QAEA,MAAMhB,MAAMtB,UAAU,CAACkC,OAAO/B,MAAMG;IACtC,EAAE,OAAOqC,OAAO;QACd7C,YAAY;YAAEG,YAAYC;YAAgByC;YAAOnC;QAAI;IACvD;IAEA,IAAIC,cAAc,OAAO;QACvB,OAAO;IACT;IAEA,MAAMmC,SAAS,MAAMtB,MAAMe,IAAI,CAC7BH,OACA,CAAC,GACD;QACE,GAAG5B,OAAO;QACVK;IACF;IAGFZ,UAAU;QACRwB,SAAS,IAAI;QACbpB,MAAMyC;QACNlB,QAAQL,iBAAiBK,MAAM;QAC/BS,WAAW;IACb;IAEA,OAAOS;AACT,EAAC"}
1
+ {"version":3,"sources":["../src/updateMany.ts"],"sourcesContent":["import type { MongooseUpdateQueryOptions } from 'mongoose'\nimport type { UpdateMany } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getCollection } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\nimport { handleError } from './utilities/handleError.js'\nimport { transform } from './utilities/transform.js'\n\nexport const updateMany: UpdateMany = async function updateMany(\n this: MongooseAdapter,\n {\n collection: collectionSlug,\n data,\n limit,\n locale,\n options: optionsArgs = {},\n req,\n returning,\n select,\n where,\n },\n) {\n const { collectionConfig, Model } = getCollection({ adapter: this, collectionSlug })\n\n const options: MongooseUpdateQueryOptions = {\n ...optionsArgs,\n lean: true,\n new: true,\n projection: buildProjectionFromSelect({\n adapter: this,\n fields: collectionConfig.flattenedFields,\n select,\n }),\n session: await getSession(this, req),\n }\n\n let query = await buildQuery({\n adapter: this,\n collectionSlug,\n fields: collectionConfig.flattenedFields,\n locale,\n where,\n })\n\n transform({ adapter: this, data, fields: collectionConfig.fields, operation: 'write' })\n\n try {\n if (typeof limit === 'number' && limit > 0) {\n const documentsToUpdate = await Model.find(\n query,\n {},\n { ...options, limit, projection: { _id: 1 } },\n )\n if (documentsToUpdate.length === 0) {\n return null\n }\n\n query = { _id: { $in: documentsToUpdate.map((doc) => doc._id) } }\n }\n\n await Model.updateMany(query, data, options)\n } catch (error) {\n handleError({ collection: collectionSlug, error, req })\n }\n\n if (returning === false) {\n return null\n }\n\n const result = await Model.find(query, {}, options)\n\n transform({\n adapter: this,\n data: result,\n fields: collectionConfig.fields,\n operation: 'read',\n })\n\n return result\n}\n"],"names":["buildQuery","buildProjectionFromSelect","getCollection","getSession","handleError","transform","updateMany","collection","collectionSlug","data","limit","locale","options","optionsArgs","req","returning","select","where","collectionConfig","Model","adapter","lean","new","projection","fields","flattenedFields","session","query","operation","documentsToUpdate","find","_id","length","$in","map","doc","error","result"],"mappings":"AAKA,SAASA,UAAU,QAAQ,0BAAyB;AACpD,SAASC,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,aAAa,QAAQ,2BAA0B;AACxD,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAASC,WAAW,QAAQ,6BAA4B;AACxD,SAASC,SAAS,QAAQ,2BAA0B;AAEpD,OAAO,MAAMC,aAAyB,eAAeA,WAEnD,EACEC,YAAYC,cAAc,EAC1BC,IAAI,EACJC,KAAK,EACLC,MAAM,EACNC,SAASC,cAAc,CAAC,CAAC,EACzBC,GAAG,EACHC,SAAS,EACTC,MAAM,EACNC,KAAK,EACN;IAED,MAAM,EAAEC,gBAAgB,EAAEC,KAAK,EAAE,GAAGjB,cAAc;QAAEkB,SAAS,IAAI;QAAEZ;IAAe;IAElF,MAAM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.0-internal.2984e42",
4
4
  "description": "The officially supported MongoDB database adapter for Payload",
5
5
  "homepage": "https://payloadcms.com",
6
6
  "repository": {
@@ -48,11 +48,11 @@
48
48
  "@types/uuid": "10.0.0",
49
49
  "mongodb": "6.12.0",
50
50
  "mongodb-memory-server": "^10",
51
- "@payloadcms/eslint-config": "3.28.0",
52
- "payload": "3.29.0-canary.8"
51
+ "payload": "3.29.0-internal.2984e42",
52
+ "@payloadcms/eslint-config": "3.28.0"
53
53
  },
54
54
  "peerDependencies": {
55
- "payload": "3.29.0-canary.8"
55
+ "payload": "3.29.0-internal.2984e42"
56
56
  },
57
57
  "scripts": {
58
58
  "build": "pnpm build:types && pnpm build:swc",