@payloadcms/db-mongodb 3.25.0-canary.46647b4 → 3.25.0-canary.4880129

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.
Files changed (66) hide show
  1. package/dist/create.js +15 -15
  2. package/dist/create.js.map +1 -1
  3. package/dist/createGlobal.d.ts.map +1 -1
  4. package/dist/createGlobal.js +15 -14
  5. package/dist/createGlobal.js.map +1 -1
  6. package/dist/createGlobalVersion.d.ts.map +1 -1
  7. package/dist/createGlobalVersion.js +26 -23
  8. package/dist/createGlobalVersion.js.map +1 -1
  9. package/dist/createVersion.d.ts.map +1 -1
  10. package/dist/createVersion.js +26 -31
  11. package/dist/createVersion.js.map +1 -1
  12. package/dist/deleteOne.d.ts.map +1 -1
  13. package/dist/deleteOne.js +8 -6
  14. package/dist/deleteOne.js.map +1 -1
  15. package/dist/find.d.ts.map +1 -1
  16. package/dist/find.js +8 -9
  17. package/dist/find.js.map +1 -1
  18. package/dist/findGlobal.d.ts.map +1 -1
  19. package/dist/findGlobal.js +10 -9
  20. package/dist/findGlobal.js.map +1 -1
  21. package/dist/findGlobalVersions.d.ts.map +1 -1
  22. package/dist/findGlobalVersions.js +10 -10
  23. package/dist/findGlobalVersions.js.map +1 -1
  24. package/dist/findOne.d.ts.map +1 -1
  25. package/dist/findOne.js +8 -6
  26. package/dist/findOne.js.map +1 -1
  27. package/dist/findVersions.js +8 -9
  28. package/dist/findVersions.js.map +1 -1
  29. package/dist/models/buildSchema.js +2 -0
  30. package/dist/models/buildSchema.js.map +1 -1
  31. package/dist/predefinedMigrations/migrateRelationshipsV2_V3.d.ts.map +1 -1
  32. package/dist/predefinedMigrations/migrateRelationshipsV2_V3.js +12 -7
  33. package/dist/predefinedMigrations/migrateRelationshipsV2_V3.js.map +1 -1
  34. package/dist/queries/buildSearchParams.d.ts.map +1 -1
  35. package/dist/queries/buildSearchParams.js +16 -0
  36. package/dist/queries/buildSearchParams.js.map +1 -1
  37. package/dist/queryDrafts.js +13 -13
  38. package/dist/queryDrafts.js.map +1 -1
  39. package/dist/updateGlobal.d.ts.map +1 -1
  40. package/dist/updateGlobal.js +15 -15
  41. package/dist/updateGlobal.js.map +1 -1
  42. package/dist/updateGlobalVersion.d.ts.map +1 -1
  43. package/dist/updateGlobalVersion.js +13 -13
  44. package/dist/updateGlobalVersion.js.map +1 -1
  45. package/dist/updateOne.d.ts.map +1 -1
  46. package/dist/updateOne.js +12 -9
  47. package/dist/updateOne.js.map +1 -1
  48. package/dist/updateVersion.d.ts.map +1 -1
  49. package/dist/updateVersion.js +13 -13
  50. package/dist/updateVersion.js.map +1 -1
  51. package/dist/utilities/transform.d.ts +27 -0
  52. package/dist/utilities/transform.d.ts.map +1 -0
  53. package/dist/utilities/transform.js +224 -0
  54. package/dist/utilities/transform.js.map +1 -0
  55. package/dist/utilities/{sanitizeRelationshipIDs.spec.js → transform.spec.js} +11 -5
  56. package/dist/utilities/transform.spec.js.map +1 -0
  57. package/package.json +3 -3
  58. package/dist/utilities/sanitizeInternalFields.d.ts +0 -2
  59. package/dist/utilities/sanitizeInternalFields.d.ts.map +0 -1
  60. package/dist/utilities/sanitizeInternalFields.js +0 -20
  61. package/dist/utilities/sanitizeInternalFields.js.map +0 -1
  62. package/dist/utilities/sanitizeRelationshipIDs.d.ts +0 -10
  63. package/dist/utilities/sanitizeRelationshipIDs.d.ts.map +0 -1
  64. package/dist/utilities/sanitizeRelationshipIDs.js +0 -130
  65. package/dist/utilities/sanitizeRelationshipIDs.js.map +0 -1
  66. package/dist/utilities/sanitizeRelationshipIDs.spec.js.map +0 -1
@@ -4,7 +4,7 @@ import { buildSortParam } from './queries/buildSortParam.js';
4
4
  import { buildJoinAggregation } from './utilities/buildJoinAggregation.js';
5
5
  import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js';
6
6
  import { getSession } from './utilities/getSession.js';
7
- import { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js';
7
+ import { transform } from './utilities/transform.js';
8
8
  export const queryDrafts = async function queryDrafts({ collection, joins, limit, locale, page, pagination, req, select, sort: sortArg, where }) {
9
9
  const VersionModel = this.versions[collection];
10
10
  const collectionConfig = this.payload.collections[collection].config;
@@ -97,18 +97,18 @@ export const queryDrafts = async function queryDrafts({ collection, joins, limit
97
97
  } else {
98
98
  result = await VersionModel.paginate(versionQuery, paginationOptions);
99
99
  }
100
- const docs = JSON.parse(JSON.stringify(result.docs));
101
- return {
102
- ...result,
103
- docs: docs.map((doc)=>{
104
- doc = {
105
- _id: doc.parent,
106
- id: doc.parent,
107
- ...doc.version
108
- };
109
- return sanitizeInternalFields(doc);
110
- })
111
- };
100
+ transform({
101
+ adapter: this,
102
+ data: result.docs,
103
+ fields: buildVersionCollectionFields(this.payload.config, collectionConfig),
104
+ operation: 'read'
105
+ });
106
+ for(let i = 0; i < result.docs.length; i++){
107
+ const id = result.docs[i].parent;
108
+ result.docs[i] = result.docs[i].version;
109
+ result.docs[i].id = id;
110
+ }
111
+ return result;
112
112
  };
113
113
 
114
114
  //# sourceMappingURL=queryDrafts.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/queryDrafts.ts"],"sourcesContent":["import type { PaginateOptions, QueryOptions } from 'mongoose'\nimport type { QueryDrafts } from 'payload'\n\nimport { buildVersionCollectionFields, combineQueries, flattenWhereToOperators } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { buildSortParam } from './queries/buildSortParam.js'\nimport { buildJoinAggregation } from './utilities/buildJoinAggregation.js'\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getSession } from './utilities/getSession.js'\nimport { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js'\n\nexport const queryDrafts: QueryDrafts = async function queryDrafts(\n this: MongooseAdapter,\n { collection, joins, limit, locale, page, pagination, req, select, sort: sortArg, where },\n) {\n const VersionModel = this.versions[collection]\n const collectionConfig = this.payload.collections[collection].config\n const options: QueryOptions = {\n session: await getSession(this, req),\n }\n\n let hasNearConstraint\n let sort\n\n if (where) {\n const constraints = flattenWhereToOperators(where)\n hasNearConstraint = constraints.some((prop) => Object.keys(prop).some((key) => key === 'near'))\n }\n\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 combinedWhere = combineQueries({ latest: { equals: true } }, where)\n\n const fields = buildVersionCollectionFields(this.payload.config, collectionConfig, true)\n const versionQuery = await buildQuery({\n adapter: this,\n fields,\n locale,\n where: combinedWhere,\n })\n\n const projection = buildProjectionFromSelect({\n adapter: this,\n fields,\n select,\n })\n // useEstimatedCount is faster, but not accurate, as it ignores any filters. It is thus set to true if there are no filters.\n const useEstimatedCount =\n hasNearConstraint || !versionQuery || Object.keys(versionQuery).length === 0\n const paginationOptions: PaginateOptions = {\n lean: true,\n leanWithId: true,\n options,\n page,\n pagination,\n projection,\n sort,\n useEstimatedCount,\n }\n\n if (this.collation) {\n const defaultLocale = 'en'\n paginationOptions.collation = {\n locale: locale && locale !== 'all' && locale !== '*' ? locale : defaultLocale,\n ...this.collation,\n }\n }\n\n if (\n !useEstimatedCount &&\n Object.keys(versionQuery).length === 0 &&\n this.disableIndexHints !== true\n ) {\n // Improve the performance of the countDocuments query which is used if useEstimatedCount is set to false by adding\n // a hint. By default, if no hint is provided, MongoDB does not use an indexed field to count the returned documents,\n // which makes queries very slow. This only happens when no query (filter) is provided. If one is provided, it uses\n // the correct indexed field\n paginationOptions.useCustomCountFn = () => {\n return Promise.resolve(\n VersionModel.countDocuments(versionQuery, {\n hint: { _id: 1 },\n }),\n )\n }\n }\n\n if (limit > 0) {\n paginationOptions.limit = limit\n // limit must also be set here, it's ignored when pagination is false\n paginationOptions.options.limit = limit\n }\n\n let result\n\n const aggregate = await buildJoinAggregation({\n adapter: this,\n collection,\n collectionConfig,\n joins,\n locale,\n projection,\n query: versionQuery,\n versions: true,\n })\n\n // build join aggregation\n if (aggregate) {\n result = await VersionModel.aggregatePaginate(\n VersionModel.aggregate(aggregate),\n paginationOptions,\n )\n } else {\n result = await VersionModel.paginate(versionQuery, paginationOptions)\n }\n\n const docs = JSON.parse(JSON.stringify(result.docs))\n\n return {\n ...result,\n docs: docs.map((doc) => {\n doc = {\n _id: doc.parent,\n id: doc.parent,\n ...doc.version,\n }\n\n return sanitizeInternalFields(doc)\n }),\n }\n}\n"],"names":["buildVersionCollectionFields","combineQueries","flattenWhereToOperators","buildQuery","buildSortParam","buildJoinAggregation","buildProjectionFromSelect","getSession","sanitizeInternalFields","queryDrafts","collection","joins","limit","locale","page","pagination","req","select","sort","sortArg","where","VersionModel","versions","collectionConfig","payload","collections","config","options","session","hasNearConstraint","constraints","some","prop","Object","keys","key","fields","flattenedFields","defaultSort","timestamps","combinedWhere","latest","equals","versionQuery","adapter","projection","useEstimatedCount","length","paginationOptions","lean","leanWithId","collation","defaultLocale","disableIndexHints","useCustomCountFn","Promise","resolve","countDocuments","hint","_id","result","aggregate","query","aggregatePaginate","paginate","docs","JSON","parse","stringify","map","doc","parent","id","version"],"mappings":"AAGA,SAASA,4BAA4B,EAAEC,cAAc,EAAEC,uBAAuB,QAAQ,UAAS;AAI/F,SAASC,UAAU,QAAQ,0BAAyB;AACpD,SAASC,cAAc,QAAQ,8BAA6B;AAC5D,SAASC,oBAAoB,QAAQ,sCAAqC;AAC1E,SAASC,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAASC,sBAAsB,QAAQ,wCAAuC;AAE9E,OAAO,MAAMC,cAA2B,eAAeA,YAErD,EAAEC,UAAU,EAAEC,KAAK,EAAEC,KAAK,EAAEC,MAAM,EAAEC,IAAI,EAAEC,UAAU,EAAEC,GAAG,EAAEC,MAAM,EAAEC,MAAMC,OAAO,EAAEC,KAAK,EAAE;IAEzF,MAAMC,eAAe,IAAI,CAACC,QAAQ,CAACZ,WAAW;IAC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CAACL,qBACDb,OAAOC,IAAI,CAACS,cAAcI,MAAM,KAAK,KACrC,IAAI,CAACM,iBAAiB,KAAK,MAC3B;QACA,mHAAmH;QACnH,qHAAqH;QACrH,mHAAmH;QACnH,4BAA4B;QAC5BL,kBAAkBM,gBAAgB,GAAG;YACnC,OAAOC,QAAQC,OAAO,CACpBnC,aAAaoC,cAAc,CAACd,cAAc;gBACxCe,MAAM;oBAAEC,KAAK;gBAAE;YACjB;QAEJ;IACF;IAEA,IAAI/C,QAAQ,GAAG;QACboC,kBAAkBpC,KAAK,GAAGA;QAC1B,qEAAqE;QACrEoC,kBAAkBrB,OAAO,CAACf,KAAK,GAAGA;IACpC;IAEA,IAAIgD;IAEJ,MAAMC,YAAY,MAAMxD,qBAAqB;QAC3CuC,SAAS,IAAI;QACblC;QACAa;QACAZ;QACAE;QACAgC;QACAiB,OAAOnB;QACPrB,UAAU;IACZ;IAEA,yBAAyB;IACzB,IAAIuC,WAAW;QACbD,SAAS,MAAMvC,aAAa0C,iBAAiB,CAC3C1C,aAAawC,SAAS,CAACA,YACvBb;IAEJ,OAAO;QACLY,SAAS,MAAMvC,aAAa2C,QAAQ,CAACrB,cAAcK;IACrD;IAEA,MAAMiB,OAAOC,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACR,OAAOK,IAAI;IAElD,OAAO;QACL,GAAGL,MAAM;QACTK,MAAMA,KAAKI,GAAG,CAAC,CAACC;YACdA,MAAM;gBACJX,KAAKW,IAAIC,MAAM;gBACfC,IAAIF,IAAIC,MAAM;gBACd,GAAGD,IAAIG,OAAO;YAChB;YAEA,OAAOjE,uBAAuB8D;QAChC;IACF;AACF,EAAC"}
1
+ {"version":3,"sources":["../src/queryDrafts.ts"],"sourcesContent":["import type { PaginateOptions, QueryOptions } from 'mongoose'\nimport type { QueryDrafts } from 'payload'\n\nimport { buildVersionCollectionFields, combineQueries, flattenWhereToOperators } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { buildSortParam } from './queries/buildSortParam.js'\nimport { buildJoinAggregation } from './utilities/buildJoinAggregation.js'\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getSession } from './utilities/getSession.js'\nimport { transform } from './utilities/transform.js'\n\nexport const queryDrafts: QueryDrafts = async function queryDrafts(\n this: MongooseAdapter,\n { collection, joins, limit, locale, page, pagination, req, select, sort: sortArg, where },\n) {\n const VersionModel = this.versions[collection]\n const collectionConfig = this.payload.collections[collection].config\n const options: QueryOptions = {\n session: await getSession(this, req),\n }\n\n let hasNearConstraint\n let sort\n\n if (where) {\n const constraints = flattenWhereToOperators(where)\n hasNearConstraint = constraints.some((prop) => Object.keys(prop).some((key) => key === 'near'))\n }\n\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 combinedWhere = combineQueries({ latest: { equals: true } }, where)\n\n const fields = buildVersionCollectionFields(this.payload.config, collectionConfig, true)\n const versionQuery = await buildQuery({\n adapter: this,\n fields,\n locale,\n where: combinedWhere,\n })\n\n const projection = buildProjectionFromSelect({\n adapter: this,\n fields,\n select,\n })\n // useEstimatedCount is faster, but not accurate, as it ignores any filters. It is thus set to true if there are no filters.\n const useEstimatedCount =\n hasNearConstraint || !versionQuery || Object.keys(versionQuery).length === 0\n const paginationOptions: PaginateOptions = {\n lean: true,\n leanWithId: true,\n options,\n page,\n pagination,\n projection,\n sort,\n useEstimatedCount,\n }\n\n if (this.collation) {\n const defaultLocale = 'en'\n paginationOptions.collation = {\n locale: locale && locale !== 'all' && locale !== '*' ? locale : defaultLocale,\n ...this.collation,\n }\n }\n\n if (\n !useEstimatedCount &&\n Object.keys(versionQuery).length === 0 &&\n this.disableIndexHints !== true\n ) {\n // Improve the performance of the countDocuments query which is used if useEstimatedCount is set to false by adding\n // a hint. By default, if no hint is provided, MongoDB does not use an indexed field to count the returned documents,\n // which makes queries very slow. This only happens when no query (filter) is provided. If one is provided, it uses\n // the correct indexed field\n paginationOptions.useCustomCountFn = () => {\n return Promise.resolve(\n VersionModel.countDocuments(versionQuery, {\n hint: { _id: 1 },\n }),\n )\n }\n }\n\n if (limit > 0) {\n paginationOptions.limit = limit\n // limit must also be set here, it's ignored when pagination is false\n paginationOptions.options.limit = limit\n }\n\n let result\n\n const aggregate = await buildJoinAggregation({\n adapter: this,\n collection,\n collectionConfig,\n joins,\n locale,\n projection,\n query: versionQuery,\n versions: true,\n })\n\n // build join aggregation\n if (aggregate) {\n result = await VersionModel.aggregatePaginate(\n VersionModel.aggregate(aggregate),\n paginationOptions,\n )\n } else {\n result = await VersionModel.paginate(versionQuery, paginationOptions)\n }\n\n transform({\n adapter: this,\n data: result.docs,\n fields: buildVersionCollectionFields(this.payload.config, collectionConfig),\n operation: 'read',\n })\n\n for (let i = 0; i < result.docs.length; i++) {\n const id = result.docs[i].parent\n result.docs[i] = result.docs[i].version\n result.docs[i].id = id\n }\n\n return result\n}\n"],"names":["buildVersionCollectionFields","combineQueries","flattenWhereToOperators","buildQuery","buildSortParam","buildJoinAggregation","buildProjectionFromSelect","getSession","transform","queryDrafts","collection","joins","limit","locale","page","pagination","req","select","sort","sortArg","where","VersionModel","versions","collectionConfig","payload","collections","config","options","session","hasNearConstraint","constraints","some","prop","Object","keys","key","fields","flattenedFields","defaultSort","timestamps","combinedWhere","latest","equals","versionQuery","adapter","projection","useEstimatedCount","length","paginationOptions","lean","leanWithId","collation","defaultLocale","disableIndexHints","useCustomCountFn","Promise","resolve","countDocuments","hint","_id","result","aggregate","query","aggregatePaginate","paginate","data","docs","operation","i","id","parent","version"],"mappings":"AAGA,SAASA,4BAA4B,EAAEC,cAAc,EAAEC,uBAAuB,QAAQ,UAAS;AAI/F,SAASC,UAAU,QAAQ,0BAAyB;AACpD,SAASC,cAAc,QAAQ,8BAA6B;AAC5D,SAASC,oBAAoB,QAAQ,sCAAqC;AAC1E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AAK,IAAIC,IAAI,GAAGA,IAAIR,OAAOM,IAAI,CAACnB,MAAM,EAAEqB,IAAK;QAC3C,MAAMC,KAAKT,OAAOM,IAAI,CAACE,EAAE,CAACE,MAAM;QAChCV,OAAOM,IAAI,CAACE,EAAE,GAAGR,OAAOM,IAAI,CAACE,EAAE,CAACG,OAAO;QACvCX,OAAOM,IAAI,CAACE,EAAE,CAACC,EAAE,GAAGA;IACtB;IAEA,OAAOT;AACT,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"updateGlobal.d.ts","sourceRoot":"","sources":["../src/updateGlobal.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAS3C,eAAO,MAAM,YAAY,EAAE,YAwC1B,CAAA"}
1
+ {"version":3,"file":"updateGlobal.d.ts","sourceRoot":"","sources":["../src/updateGlobal.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAQ3C,eAAO,MAAM,YAAY,EAAE,YA0B1B,CAAA"}
@@ -1,7 +1,6 @@
1
1
  import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js';
2
2
  import { getSession } from './utilities/getSession.js';
3
- import { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js';
4
- import { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.js';
3
+ import { transform } from './utilities/transform.js';
5
4
  export const updateGlobal = async function updateGlobal({ slug, data, options: optionsArgs = {}, req, select }) {
6
5
  const Model = this.globals;
7
6
  const fields = this.payload.config.globals.find((global)=>global.slug === slug).fields;
@@ -16,22 +15,23 @@ export const updateGlobal = async function updateGlobal({ slug, data, options: o
16
15
  }),
17
16
  session: await getSession(this, req)
18
17
  };
19
- let result;
20
- const sanitizedData = sanitizeRelationshipIDs({
21
- config: this.payload.config,
18
+ transform({
19
+ adapter: this,
22
20
  data,
23
- fields
21
+ fields,
22
+ globalSlug: slug,
23
+ operation: 'write'
24
24
  });
25
- result = await Model.findOneAndUpdate({
25
+ const result = await Model.findOneAndUpdate({
26
26
  globalType: slug
27
- }, sanitizedData, options);
28
- if (!result) {
29
- return null;
30
- }
31
- result = JSON.parse(JSON.stringify(result));
32
- // custom id type reset
33
- result.id = result._id;
34
- result = sanitizeInternalFields(result);
27
+ }, data, options);
28
+ transform({
29
+ adapter: this,
30
+ data: result,
31
+ fields,
32
+ globalSlug: slug,
33
+ operation: 'read'
34
+ });
35
35
  return result;
36
36
  };
37
37
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/updateGlobal.ts"],"sourcesContent":["import type { QueryOptions } from 'mongoose'\nimport type { UpdateGlobal } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getSession } from './utilities/getSession.js'\nimport { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js'\nimport { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.js'\n\nexport const updateGlobal: UpdateGlobal = async function updateGlobal(\n this: MongooseAdapter,\n { slug, data, options: optionsArgs = {}, req, select },\n) {\n const Model = this.globals\n const fields = this.payload.config.globals.find((global) => global.slug === slug).fields\n\n const options: QueryOptions = {\n ...optionsArgs,\n lean: true,\n new: true,\n projection: buildProjectionFromSelect({\n adapter: this,\n fields: this.payload.config.globals.find((global) => global.slug === slug).flattenedFields,\n select,\n }),\n session: await getSession(this, req),\n }\n\n let result\n\n const sanitizedData = sanitizeRelationshipIDs({\n config: this.payload.config,\n data,\n fields,\n })\n\n result = await Model.findOneAndUpdate({ globalType: slug }, sanitizedData, options)\n\n if (!result) {\n return null\n }\n\n result = JSON.parse(JSON.stringify(result))\n\n // custom id type reset\n result.id = result._id\n result = sanitizeInternalFields(result)\n\n return result\n}\n"],"names":["buildProjectionFromSelect","getSession","sanitizeInternalFields","sanitizeRelationshipIDs","updateGlobal","slug","data","options","optionsArgs","req","select","Model","globals","fields","payload","config","find","global","lean","new","projection","adapter","flattenedFields","session","result","sanitizedData","findOneAndUpdate","globalType","JSON","parse","stringify","id","_id"],"mappings":"AAKA,SAASA,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAASC,sBAAsB,QAAQ,wCAAuC;AAC9E,SAASC,uBAAuB,QAAQ,yCAAwC;AAEhF,OAAO,MAAMC,eAA6B,eAAeA,aAEvD,EAAEC,IAAI,EAAEC,IAAI,EAAEC,SAASC,cAAc,CAAC,CAAC,EAAEC,GAAG,EAAEC,MAAM,EAAE;IAEtD,MAAMC,QAAQ,IAAI,CAACC,OAAO;IAC1B,MAAMC,SAAS,IAAI,CAACC,OAAO,CAACC,MAAM,CAACH,OAAO,CAACI,IAAI,CAAC,CAACC,SAAWA,OAAOZ,IAAI,KAAKA,MAAMQ,MAAM;IAExF,MAAMN,UAAwB;QAC5B,GAAGC,WAAW;QACdU,MAAM;QACNC,KAAK;QACLC,YAAYpB,0BAA0B;YACpCqB,SAAS,IAAI;YACbR,QAAQ,IAAI,CAACC,OAAO,CAACC,MAAM,CAACH,OAAO,CAACI,IAAI,CAAC,CAACC,SAAWA,OAAOZ,IAAI,KAAKA,MAAMiB,eAAe;YAC1FZ;QACF;QACAa,SAAS,MAAMtB,WAAW,IAAI,EAAEQ;IAClC;IAEA,IAAIe;IAEJ,MAAMC,gBAAgBtB,wBAAwB;QAC5CY,QAAQ,IAAI,CAACD,OAAO,CAACC,MAAM;QAC3BT;QACAO;IACF;IAEAW,SAAS,MAAMb,MAAMe,gBAAgB,CAAC;QAAEC,YAAYtB;IAAK,GAAGoB,eAAelB;IAE3E,IAAI,CAACiB,QAAQ;QACX,OAAO;IACT;IAEAA,SAASI,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACN;IAEnC,uBAAuB;IACvBA,OAAOO,EAAE,GAAGP,OAAOQ,GAAG;IACtBR,SAAStB,uBAAuBsB;IAEhC,OAAOA;AACT,EAAC"}
1
+ {"version":3,"sources":["../src/updateGlobal.ts"],"sourcesContent":["import type { QueryOptions } from 'mongoose'\nimport type { UpdateGlobal } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getSession } from './utilities/getSession.js'\nimport { transform } from './utilities/transform.js'\n\nexport const updateGlobal: UpdateGlobal = async function updateGlobal(\n this: MongooseAdapter,\n { slug, data, options: optionsArgs = {}, req, select },\n) {\n const Model = this.globals\n const fields = this.payload.config.globals.find((global) => global.slug === slug).fields\n\n const options: QueryOptions = {\n ...optionsArgs,\n lean: true,\n new: true,\n projection: buildProjectionFromSelect({\n adapter: this,\n fields: this.payload.config.globals.find((global) => global.slug === slug).flattenedFields,\n select,\n }),\n session: await getSession(this, req),\n }\n\n transform({ adapter: this, data, fields, globalSlug: slug, operation: 'write' })\n\n const result: any = await Model.findOneAndUpdate({ globalType: slug }, data, options)\n\n transform({ adapter: this, data: result, fields, globalSlug: slug, operation: 'read' })\n\n return result\n}\n"],"names":["buildProjectionFromSelect","getSession","transform","updateGlobal","slug","data","options","optionsArgs","req","select","Model","globals","fields","payload","config","find","global","lean","new","projection","adapter","flattenedFields","session","globalSlug","operation","result","findOneAndUpdate","globalType"],"mappings":"AAKA,SAASA,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAASC,SAAS,QAAQ,2BAA0B;AAEpD,OAAO,MAAMC,eAA6B,eAAeA,aAEvD,EAAEC,IAAI,EAAEC,IAAI,EAAEC,SAASC,cAAc,CAAC,CAAC,EAAEC,GAAG,EAAEC,MAAM,EAAE;IAEtD,MAAMC,QAAQ,IAAI,CAACC,OAAO;IAC1B,MAAMC,SAAS,IAAI,CAACC,OAAO,CAACC,MAAM,CAACH,OAAO,CAACI,IAAI,CAAC,CAACC,SAAWA,OAAOZ,IAAI,KAAKA,MAAMQ,MAAM;IAExF,MAAMN,UAAwB;QAC5B,GAAGC,WAAW;QACdU,MAAM;QACNC,KAAK;QACLC,YAAYnB,0BAA0B;YACpCoB,SAAS,IAAI;YACbR,QAAQ,IAAI,CAACC,OAAO,CAACC,MAAM,CAACH,OAAO,CAACI,IAAI,CAAC,CAACC,SAAWA,OAAOZ,IAAI,KAAKA,MAAMiB,eAAe;YAC1FZ;QACF;QACAa,SAAS,MAAMrB,WAAW,IAAI,EAAEO;IAClC;IAEAN,UAAU;QAAEkB,SAAS,IAAI;QAAEf;QAAMO;QAAQW,YAAYnB;QAAMoB,WAAW;IAAQ;IAE9E,MAAMC,SAAc,MAAMf,MAAMgB,gBAAgB,CAAC;QAAEC,YAAYvB;IAAK,GAAGC,MAAMC;IAE7EJ,UAAU;QAAEkB,SAAS,IAAI;QAAEf,MAAMoB;QAAQb;QAAQW,YAAYnB;QAAMoB,WAAW;IAAO;IAErF,OAAOC;AACT,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"updateGlobalVersion.d.ts","sourceRoot":"","sources":["../src/updateGlobalVersion.ts"],"names":[],"mappings":"AAEA,OAAO,EAA4B,KAAK,UAAU,EAAE,KAAK,uBAAuB,EAAE,MAAM,SAAS,CAAA;AAEjG,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAOjD,wBAAsB,mBAAmB,CAAC,CAAC,SAAS,UAAU,EAC5D,IAAI,EAAE,eAAe,EACrB,EACE,EAAE,EACF,MAAM,EAAE,UAAU,EAClB,MAAM,EACN,OAAO,EAAE,WAAgB,EACzB,GAAG,EACH,MAAM,EACN,WAAW,EACX,KAAK,GACN,EAAE,uBAAuB,CAAC,CAAC,CAAC,gBAiD9B"}
1
+ {"version":3,"file":"updateGlobalVersion.d.ts","sourceRoot":"","sources":["../src/updateGlobalVersion.ts"],"names":[],"mappings":"AAEA,OAAO,EAA4B,KAAK,UAAU,EAAE,KAAK,uBAAuB,EAAE,MAAM,SAAS,CAAA;AAEjG,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAOjD,wBAAsB,mBAAmB,CAAC,CAAC,SAAS,UAAU,EAC5D,IAAI,EAAE,eAAe,EACrB,EACE,EAAE,EACF,MAAM,EAAE,UAAU,EAClB,MAAM,EACN,OAAO,EAAE,WAAgB,EACzB,GAAG,EACH,MAAM,EACN,WAAW,EACX,KAAK,GACN,EAAE,uBAAuB,CAAC,CAAC,CAAC,gBAsC9B"}
@@ -2,7 +2,7 @@ import { buildVersionGlobalFields } from 'payload';
2
2
  import { buildQuery } from './queries/buildQuery.js';
3
3
  import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js';
4
4
  import { getSession } from './utilities/getSession.js';
5
- import { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.js';
5
+ import { transform } from './utilities/transform.js';
6
6
  export async function updateGlobalVersion({ id, global: globalSlug, locale, options: optionsArgs = {}, req, select, versionData, where }) {
7
7
  const VersionModel = this.versions[globalSlug];
8
8
  const whereToUse = where || {
@@ -30,23 +30,23 @@ export async function updateGlobalVersion({ id, global: globalSlug, locale, opti
30
30
  locale,
31
31
  where: whereToUse
32
32
  });
33
- const sanitizedData = sanitizeRelationshipIDs({
34
- config: this.payload.config,
33
+ transform({
34
+ adapter: this,
35
35
  data: versionData,
36
- fields
36
+ fields,
37
+ operation: 'write'
37
38
  });
38
- const doc = await VersionModel.findOneAndUpdate(query, sanitizedData, options);
39
+ const doc = await VersionModel.findOneAndUpdate(query, versionData, options);
39
40
  if (!doc) {
40
41
  return null;
41
42
  }
42
- const result = JSON.parse(JSON.stringify(doc));
43
- const verificationToken = doc._verificationToken;
44
- // custom id type reset
45
- result.id = result._id;
46
- if (verificationToken) {
47
- result._verificationToken = verificationToken;
48
- }
49
- return result;
43
+ transform({
44
+ adapter: this,
45
+ data: doc,
46
+ fields,
47
+ operation: 'read'
48
+ });
49
+ return doc;
50
50
  }
51
51
 
52
52
  //# sourceMappingURL=updateGlobalVersion.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/updateGlobalVersion.ts"],"sourcesContent":["import type { QueryOptions } from 'mongoose'\n\nimport { buildVersionGlobalFields, type TypeWithID, type UpdateGlobalVersionArgs } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getSession } from './utilities/getSession.js'\nimport { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.js'\n\nexport async function updateGlobalVersion<T extends TypeWithID>(\n this: MongooseAdapter,\n {\n id,\n global: globalSlug,\n locale,\n options: optionsArgs = {},\n req,\n select,\n versionData,\n where,\n }: UpdateGlobalVersionArgs<T>,\n) {\n const VersionModel = this.versions[globalSlug]\n const whereToUse = where || { id: { equals: id } }\n\n const currentGlobal = this.payload.config.globals.find((global) => global.slug === globalSlug)\n const fields = buildVersionGlobalFields(this.payload.config, currentGlobal)\n const flattenedFields = buildVersionGlobalFields(this.payload.config, currentGlobal, true)\n const options: QueryOptions = {\n ...optionsArgs,\n lean: true,\n new: true,\n projection: buildProjectionFromSelect({\n adapter: this,\n fields: flattenedFields,\n select,\n }),\n session: await getSession(this, req),\n }\n\n const query = await buildQuery({\n adapter: this,\n fields: flattenedFields,\n locale,\n where: whereToUse,\n })\n\n const sanitizedData = sanitizeRelationshipIDs({\n config: this.payload.config,\n data: versionData,\n fields,\n })\n\n const doc = await VersionModel.findOneAndUpdate(query, sanitizedData, options)\n\n if (!doc) {\n return null\n }\n\n const result = JSON.parse(JSON.stringify(doc))\n\n const verificationToken = doc._verificationToken\n\n // custom id type reset\n result.id = result._id\n if (verificationToken) {\n result._verificationToken = verificationToken\n }\n return result\n}\n"],"names":["buildVersionGlobalFields","buildQuery","buildProjectionFromSelect","getSession","sanitizeRelationshipIDs","updateGlobalVersion","id","global","globalSlug","locale","options","optionsArgs","req","select","versionData","where","VersionModel","versions","whereToUse","equals","currentGlobal","payload","config","globals","find","slug","fields","flattenedFields","lean","new","projection","adapter","session","query","sanitizedData","data","doc","findOneAndUpdate","result","JS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AAK;QACR,OAAO;IACT;IAEA,MAAME,SAASC,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACL;IAEzC,MAAMM,oBAAoBN,IAAIO,kBAAkB;IAEhD,uBAAuB;IACvBL,OAAOhC,EAAE,GAAGgC,OAAOM,GAAG;IACtB,IAAIF,mBAAmB;QACrBJ,OAAOK,kBAAkB,GAAGD;IAC9B;IACA,OAAOJ;AACT"}
1
+ {"version":3,"sources":["../src/updateGlobalVersion.ts"],"sourcesContent":["import type { QueryOptions } from 'mongoose'\n\nimport { buildVersionGlobalFields, type TypeWithID, type UpdateGlobalVersionArgs } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getSession } from './utilities/getSession.js'\nimport { transform } from './utilities/transform.js'\n\nexport async function updateGlobalVersion<T extends TypeWithID>(\n this: MongooseAdapter,\n {\n id,\n global: globalSlug,\n locale,\n options: optionsArgs = {},\n req,\n select,\n versionData,\n where,\n }: UpdateGlobalVersionArgs<T>,\n) {\n const VersionModel = this.versions[globalSlug]\n const whereToUse = where || { id: { equals: id } }\n\n const currentGlobal = this.payload.config.globals.find((global) => global.slug === globalSlug)\n const fields = buildVersionGlobalFields(this.payload.config, currentGlobal)\n const flattenedFields = buildVersionGlobalFields(this.payload.config, currentGlobal, true)\n const options: QueryOptions = {\n ...optionsArgs,\n lean: true,\n new: true,\n projection: buildProjectionFromSelect({\n adapter: this,\n fields: flattenedFields,\n select,\n }),\n session: await getSession(this, req),\n }\n\n const query = await buildQuery({\n adapter: this,\n fields: flattenedFields,\n locale,\n where: whereToUse,\n })\n\n transform({ adapter: this, data: versionData, fields, operation: 'write' })\n\n const doc = await VersionModel.findOneAndUpdate(query, versionData, options)\n\n if (!doc) {\n return null\n }\n\n transform({ adapter: this, data: doc, fields, operation: 'read' })\n\n return doc\n}\n"],"names":["buildVersionGlobalFields","buildQuery","buildProjectionFromSelect","getSession","transform","updateGlobalVersion","id","global","globalSlug","locale","options","optionsArgs","req","select","versionData","where","VersionModel","versions","whereToUse","equals","currentGlobal","payload","config","globals","find","slug","fields","flattenedFields","lean","new","projection","adapter","session","query","data","operation","doc","findOneAndUpdate"],"mappings":"AAEA,SAASA,wBAAwB,QAAuD,UAAS;AAIjG,SAASC,UAAU,QAAQ,0BAAyB;AACpD,SAASC,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAASC,SAAS,QAAQ,2BAA0B;AAEpD,OAAO,eAAeC,oBAEpB,EACEC,EAAE,EACFC,QAAQC,UAAU,EAClBC,MAAM,EACNC,SAASC,cAAc,CAAC,CAAC,EACzBC,GAAG,EACHC,MAAM,EACNC,WAAW,EACXC,KAAK,EACsB;IAE7B,MAAMC,eAAe,IAAI,CAACC,QAAQ,CAACT,WAAW;IAC9C,MAAMU,aAAaH,SAAS;QAAET,IAAI;YAAEa,QAAQb;QAAG;IAAE;IAEjD,MAAMc,gBAAgB,IAAI,CAACC,OAAO,CAACC,MAAM,CAACC,OAAO,CAACC,IAAI,CAAC,CAACjB,SAAWA,OAAOkB,IAAI,KAAKjB;IACnF,MAAMkB,SAAS1B,yBAAyB,IAAI,CAACqB,OAAO,CAACC,MAAM,EAAEF;IAC7D,MAAMO,kBAAkB3B,yBAAyB,IAAI,CAACqB,OAAO,CAACC,MAAM,EAAEF,eAAe;IACrF,MAAMV,UAAwB;QAC5B,GAAGC,WAAW;QACdiB,MAAM;QACNC,KAAK;QACLC,YAAY5B,0BAA0B;YACpC6B,SAAS,IAAI;YACbL,QAAQC;YACRd;QACF;QACAmB,SAAS,MAAM7B,WAAW,IAAI,EAAES;IAClC;IAEA,MAAMqB,QAAQ,MAAMhC,WAAW;QAC7B8B,SAAS,IAAI;QACbL,QAAQC;QACRlB;QACAM,OAAOG;IACT;IAEAd,UAAU;QAAE2B,SAAS,IAAI;QAAEG,MAAMpB;QAAaY;QAAQS,WAAW;IAAQ;IAEzE,MAAMC,MAAM,MAAMpB,aAAaqB,gBAAgB,CAACJ,OAAOnB,aAAaJ;IAEpE,IAAI,CAAC0B,KAAK;QACR,OAAO;IACT;IAEAhC,UAAU;QAAE2B,SAAS,IAAI;QAAEG,MAAME;QAAKV;QAAQS,WAAW;IAAO;IAEhE,OAAOC;AACT"}
@@ -1 +1 @@
1
- {"version":3,"file":"updateOne.d.ts","sourceRoot":"","sources":["../src/updateOne.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAWxC,eAAO,MAAM,SAAS,EAAE,SAkDvB,CAAA"}
1
+ {"version":3,"file":"updateOne.d.ts","sourceRoot":"","sources":["../src/updateOne.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAUxC,eAAO,MAAM,SAAS,EAAE,SA4CvB,CAAA"}
package/dist/updateOne.js CHANGED
@@ -2,8 +2,7 @@ import { buildQuery } from './queries/buildQuery.js';
2
2
  import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js';
3
3
  import { getSession } from './utilities/getSession.js';
4
4
  import { handleError } from './utilities/handleError.js';
5
- import { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js';
6
- import { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.js';
5
+ import { transform } from './utilities/transform.js';
7
6
  export const updateOne = async function updateOne({ id, collection, data, locale, options: optionsArgs = {}, req, select, where: whereArg }) {
8
7
  const where = id ? {
9
8
  id: {
@@ -31,13 +30,14 @@ export const updateOne = async function updateOne({ id, collection, data, locale
31
30
  where
32
31
  });
33
32
  let result;
34
- const sanitizedData = sanitizeRelationshipIDs({
35
- config: this.payload.config,
33
+ transform({
34
+ adapter: this,
36
35
  data,
37
- fields
36
+ fields,
37
+ operation: 'write'
38
38
  });
39
39
  try {
40
- result = await Model.findOneAndUpdate(query, sanitizedData, options);
40
+ result = await Model.findOneAndUpdate(query, data, options);
41
41
  } catch (error) {
42
42
  handleError({
43
43
  collection,
@@ -48,9 +48,12 @@ export const updateOne = async function updateOne({ id, collection, data, locale
48
48
  if (!result) {
49
49
  return null;
50
50
  }
51
- result = JSON.parse(JSON.stringify(result));
52
- result.id = result._id;
53
- result = sanitizeInternalFields(result);
51
+ transform({
52
+ adapter: this,
53
+ data: result,
54
+ fields,
55
+ operation: 'read'
56
+ });
54
57
  return result;
55
58
  };
56
59
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/updateOne.ts"],"sourcesContent":["import type { QueryOptions } from 'mongoose'\nimport type { UpdateOne } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getSession } from './utilities/getSession.js'\nimport { handleError } from './utilities/handleError.js'\nimport { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js'\nimport { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.js'\n\nexport const updateOne: UpdateOne = async function updateOne(\n this: MongooseAdapter,\n { id, collection, data, locale, options: optionsArgs = {}, req, select, where: whereArg },\n) {\n const where = id ? { id: { equals: id } } : whereArg\n const Model = this.collections[collection]\n const fields = this.payload.collections[collection].config.fields\n const options: QueryOptions = {\n ...optionsArgs,\n lean: true,\n new: true,\n projection: buildProjectionFromSelect({\n adapter: this,\n fields: this.payload.collections[collection].config.flattenedFields,\n select,\n }),\n session: await getSession(this, req),\n }\n\n const query = await buildQuery({\n adapter: this,\n collectionSlug: collection,\n fields: this.payload.collections[collection].config.flattenedFields,\n locale,\n where,\n })\n\n let result\n\n const sanitizedData = sanitizeRelationshipIDs({\n config: this.payload.config,\n data,\n fields,\n })\n\n try {\n result = await Model.findOneAndUpdate(query, sanitizedData, options)\n } catch (error) {\n handleError({ collection, error, req })\n }\n\n if (!result) {\n return null\n }\n\n result = JSON.parse(JSON.stringify(result))\n result.id = result._id\n result = sanitizeInternalFields(result)\n\n return result\n}\n"],"names":["buildQuery","buildProjectionFromSelect","getSession","handleError","sanitizeInternalFields","sanitizeRelationshipIDs","updateOne","id","collection","data","locale","options","optionsArgs","req","select","where","whereArg","equals","Model","collections","fields","payload","config","lean","new","projection","adapter","flattenedFields","session","query","collectionSlug","result","sanitizedData","findOneAndUpdate","error","JSON","parse","stringify","_id"],"mappings":"AAKA,SAASA,UAAU,QAAQ,0BAAyB;AACpD,SAASC,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAASC,WAAW,QAAQ,6BAA4B;AACxD,SAASC,sBAAsB,QAAQ,wCAAuC;AAC9E,SAASC,uBAAuB,QAAQ,yCAAwC;AAEhF,OAAO,MAAMC,YAAuB,eAAeA,UAEjD,EAAEC,EAAE,EAAEC,UAAU,EAAEC,IAAI,EAAEC,MAAM,EAAEC,SAASC,cAAc,CAAC,CAAC,EAAEC,GAAG,EAAEC,MAAM,EAAEC,OAAOC,QAAQ,EAAE;IAEzF,MAAMD,QAAQR,KAAK;QAAEA,IAAI;YAAEU,QAAQV;QAAG;IAAE,IAAIS;IAC5C,MAAME,QAAQ,IAAI,CAACC,WAAW,CAACX,WAAW;IAC1C,MAAMY,SAAS,IAAI,CAACC,OAAO,CAACF,WAAW,CAACX,WAAW,CAACc,MAAM,CAACF,MAAM;IACjE,MAAMT,UAAwB;QAC5B,GAAGC,WAAW;QACdW,MAAM;QACNC,KAAK;QACLC,YAAYxB,0BAA0B;YACpCyB,SAAS,IAAI;YACbN,QAAQ,IAAI,CAACC,OAAO,CAACF,WAAW,CAACX,WAAW,CAACc,MAAM,CAACK,eAAe;YACnEb;QACF;QACAc,SAAS,MAAM1B,WAAW,IAAI,EAAEW;IAClC;IAEA,MAAMgB,QAAQ,MAAM7B,WAAW;QAC7B0B,SAAS,IAAI;QACbI,gBAAgBtB;QAChBY,QAAQ,IAAI,CAACC,OAAO,CAACF,WAAW,CAACX,WAAW,CAACc,MAAM,CAACK,eAAe;QACnEjB;QACAK;IACF;IAEA,IAAIgB;IAEJ,MAAMC,gBAAgB3B,wBAAwB;QAC5CiB,QAAQ,IAAI,CAACD,OAAO,CAACC,MAAM;QAC3Bb;QACAW;IACF;IAEA,IAAI;QACFW,SAAS,MAAMb,MAAMe,gBAAgB,CAACJ,OAAOG,eAAerB;IAC9D,EAAE,OAAOuB,OAAO;QACd/B,YAAY;YAAEK;YAAY0B;YAAOrB;QAAI;IACvC;IAEA,IAAI,CAACkB,QAAQ;QACX,OAAO;IACT;IAEAA,SAASI,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACN;IACnCA,OAAOxB,EAAE,GAAGwB,OAAOO,GAAG;IACtBP,SAAS3B,uBAAuB2B;IAEhC,OAAOA;AACT,EAAC"}
1
+ {"version":3,"sources":["../src/updateOne.ts"],"sourcesContent":["import type { QueryOptions } from 'mongoose'\nimport type { UpdateOne } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getSession } from './utilities/getSession.js'\nimport { handleError } from './utilities/handleError.js'\nimport { transform } from './utilities/transform.js'\n\nexport const updateOne: UpdateOne = async function updateOne(\n this: MongooseAdapter,\n { id, collection, data, locale, options: optionsArgs = {}, req, select, where: whereArg },\n) {\n const where = id ? { id: { equals: id } } : whereArg\n const Model = this.collections[collection]\n const fields = this.payload.collections[collection].config.fields\n const options: QueryOptions = {\n ...optionsArgs,\n lean: true,\n new: true,\n projection: buildProjectionFromSelect({\n adapter: this,\n fields: this.payload.collections[collection].config.flattenedFields,\n select,\n }),\n session: await getSession(this, req),\n }\n\n const query = await buildQuery({\n adapter: this,\n collectionSlug: collection,\n fields: this.payload.collections[collection].config.flattenedFields,\n locale,\n where,\n })\n\n let result\n\n transform({ adapter: this, data, fields, operation: 'write' })\n\n try {\n result = await Model.findOneAndUpdate(query, data, options)\n } catch (error) {\n handleError({ collection, error, req })\n }\n\n if (!result) {\n return null\n }\n\n transform({ adapter: this, data: result, fields, operation: 'read' })\n\n return result\n}\n"],"names":["buildQuery","buildProjectionFromSelect","getSession","handleError","transform","updateOne","id","collection","data","locale","options","optionsArgs","req","select","where","whereArg","equals","Model","collections","fields","payload","config","lean","new","projection","adapter","flattenedFields","session","query","collectionSlug","result","operation","findOneAndUpdate","error"],"mappings":"AAKA,SAASA,UAAU,QAAQ,0BAAyB;AACpD,SAASC,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAASC,WAAW,QAAQ,6BAA4B;AACxD,SAASC,SAAS,QAAQ,2BAA0B;AAEpD,OAAO,MAAMC,YAAuB,eAAeA,UAEjD,EAAEC,EAAE,EAAEC,UAAU,EAAEC,IAAI,EAAEC,MAAM,EAAEC,SAASC,cAAc,CAAC,CAAC,EAAEC,GAAG,EAAEC,MAAM,EAAEC,OAAOC,QAAQ,EAAE;IAEzF,MAAMD,QAAQR,KAAK;QAAEA,IAAI;YAAEU,QAAQV;QAAG;IAAE,IAAIS;IAC5C,MAAME,QAAQ,IAAI,CAACC,WAAW,CAACX,WAAW;IAC1C,MAAMY,SAAS,IAAI,CAACC,OAAO,CAACF,WAAW,CAACX,WAAW,CAACc,MAAM,CAACF,MAAM;IACjE,MAAMT,UAAwB;QAC5B,GAAGC,WAAW;QACdW,MAAM;QACNC,KAAK;QACLC,YAAYvB,0BAA0B;YACpCwB,SAAS,IAAI;YACbN,QAAQ,IAAI,CAACC,OAAO,CAACF,WAAW,CAACX,WAAW,CAACc,MAAM,CAACK,eAAe;YACnEb;QACF;QACAc,SAAS,MAAMzB,WAAW,IAAI,EAAEU;IAClC;IAEA,MAAMgB,QAAQ,MAAM5B,WAAW;QAC7ByB,SAAS,IAAI;QACbI,gBAAgBtB;QAChBY,QAAQ,IAAI,CAACC,OAAO,CAACF,WAAW,CAACX,WAAW,CAACc,MAAM,CAACK,eAAe;QACnEjB;QACAK;IACF;IAEA,IAAIgB;IAEJ1B,UAAU;QAAEqB,SAAS,IAAI;QAAEjB;QAAMW;QAAQY,WAAW;IAAQ;IAE5D,IAAI;QACFD,SAAS,MAAMb,MAAMe,gBAAgB,CAACJ,OAAOpB,MAAME;IACrD,EAAE,OAAOuB,OAAO;QACd9B,YAAY;YAAEI;YAAY0B;YAAOrB;QAAI;IACvC;IAEA,IAAI,CAACkB,QAAQ;QACX,OAAO;IACT;IAEA1B,UAAU;QAAEqB,SAAS,IAAI;QAAEjB,MAAMsB;QAAQX;QAAQY,WAAW;IAAO;IAEnE,OAAOD;AACT,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"updateVersion.d.ts","sourceRoot":"","sources":["../src/updateVersion.ts"],"names":[],"mappings":"AAEA,OAAO,EAAgC,KAAK,aAAa,EAAE,MAAM,SAAS,CAAA;AAS1E,eAAO,MAAM,aAAa,EAAE,aA0D3B,CAAA"}
1
+ {"version":3,"file":"updateVersion.d.ts","sourceRoot":"","sources":["../src/updateVersion.ts"],"names":[],"mappings":"AAEA,OAAO,EAAgC,KAAK,aAAa,EAAE,MAAM,SAAS,CAAA;AAS1E,eAAO,MAAM,aAAa,EAAE,aA+C3B,CAAA"}
@@ -2,7 +2,7 @@ import { buildVersionCollectionFields } from 'payload';
2
2
  import { buildQuery } from './queries/buildQuery.js';
3
3
  import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js';
4
4
  import { getSession } from './utilities/getSession.js';
5
- import { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.js';
5
+ import { transform } from './utilities/transform.js';
6
6
  export const updateVersion = async function updateVersion({ id, collection, locale, options: optionsArgs = {}, req, select, versionData, where }) {
7
7
  const VersionModel = this.versions[collection];
8
8
  const whereToUse = where || {
@@ -29,23 +29,23 @@ export const updateVersion = async function updateVersion({ id, collection, loca
29
29
  locale,
30
30
  where: whereToUse
31
31
  });
32
- const sanitizedData = sanitizeRelationshipIDs({
33
- config: this.payload.config,
32
+ transform({
33
+ adapter: this,
34
34
  data: versionData,
35
- fields
35
+ fields,
36
+ operation: 'write'
36
37
  });
37
- const doc = await VersionModel.findOneAndUpdate(query, sanitizedData, options);
38
+ const doc = await VersionModel.findOneAndUpdate(query, versionData, options);
38
39
  if (!doc) {
39
40
  return null;
40
41
  }
41
- const result = JSON.parse(JSON.stringify(doc));
42
- const verificationToken = doc._verificationToken;
43
- // custom id type reset
44
- result.id = result._id;
45
- if (verificationToken) {
46
- result._verificationToken = verificationToken;
47
- }
48
- return result;
42
+ transform({
43
+ adapter: this,
44
+ data: doc,
45
+ fields,
46
+ operation: 'write'
47
+ });
48
+ return doc;
49
49
  };
50
50
 
51
51
  //# sourceMappingURL=updateVersion.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/updateVersion.ts"],"sourcesContent":["import type { QueryOptions } from 'mongoose'\n\nimport { buildVersionCollectionFields, type UpdateVersion } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getSession } from './utilities/getSession.js'\nimport { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.js'\n\nexport const updateVersion: UpdateVersion = async function updateVersion(\n this: MongooseAdapter,\n { id, collection, locale, options: optionsArgs = {}, req, select, versionData, where },\n) {\n const VersionModel = this.versions[collection]\n const whereToUse = where || { id: { equals: id } }\n const fields = buildVersionCollectionFields(\n this.payload.config,\n this.payload.collections[collection].config,\n )\n\n const flattenedFields = buildVersionCollectionFields(\n this.payload.config,\n this.payload.collections[collection].config,\n true,\n )\n\n const options: QueryOptions = {\n ...optionsArgs,\n lean: true,\n new: true,\n projection: buildProjectionFromSelect({\n adapter: this,\n fields: flattenedFields,\n select,\n }),\n session: await getSession(this, req),\n }\n\n const query = await buildQuery({\n adapter: this,\n fields: flattenedFields,\n locale,\n where: whereToUse,\n })\n\n const sanitizedData = sanitizeRelationshipIDs({\n config: this.payload.config,\n data: versionData,\n fields,\n })\n\n const doc = await VersionModel.findOneAndUpdate(query, sanitizedData, options)\n\n if (!doc) {\n return null\n }\n\n const result = JSON.parse(JSON.stringify(doc))\n\n const verificationToken = doc._verificationToken\n\n // custom id type reset\n result.id = result._id\n if (verificationToken) {\n result._verificationToken = verificationToken\n }\n return result\n}\n"],"names":["buildVersionCollectionFields","buildQuery","buildProjectionFromSelect","getSession","sanitizeRelationshipIDs","updateVersion","id","collection","locale","options","optionsArgs","req","select","versionData","where","VersionModel","versions","whereToUse","equals","fields","payload","config","collections","flattenedFields","lean","new","projection","adapter","session","query","sanitizedData","data","doc","findOneAndUpdate","result","JSON","parse","stringify","verificationToken","_verificationToken","_id"],"mappings":"AAEA,SAASA,4BAA4B,QAA4B,UAAS;AAI1E,SAASC,UAAU,QAAQ,0BAAyB;AACpD,SAASC,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAASC,uBAAuB,QAAQ,yCAAwC;AAEhF,OAAO,MAAMC,gBAA+B,eAAeA,cAEzD,EAAEC,EAAE,EAAEC,UAAU,EAAEC,MAAM,EAAEC,SAASC,cAAc,CAAC,CAAC,EAAEC,GAAG,EAAEC,MAAM,EAAEC,WAAW,EAAEC,KAAK,EAAE;IAEtF,MAAMC,eAAe,IAAI,CAACC,QAAQ,CAACT,WAAW;IAC9C,MAAMU,aAAaH,SAAS;QAAER,IAAI;YAAEY,QAAQZ;QAAG;IAAE;IACjD,MAAMa,SAASnB,6BACb,IAAI,CAACoB,OAAO,CAACC,MAAM,EACnB,IAAI,CAACD,OAAO,CAACE,WAAW,CAACf,WAAW,CAACc,MAAM;IAG7C,MAAME,kBAAkBvB,6BACtB,IAAI,CAACoB,OAAO,CAACC,MAAM,EACnB,IAAI,CAACD,OAAO,CAACE,WAAW,CAACf,WAAW,CAACc,MAAM,EAC3C;IAGF,MAAMZ,UAAwB;QAC5B,GAAGC,WAAW;QACdc,MAAM;QACNC,KAAK;QACLC,YAAYxB,0BAA0B;YACpCyB,SAAS,IAAI;YACbR,QAAQI;YACRX;QACF;QACAgB,SAAS,MAAMzB,WAAW,IAAI,EAAEQ;IAClC;IAEA,MAAMkB,QAAQ,MAAM5B,WAAW;QAC7B0B,SAAS,IAAI;QACbR,QAAQI;QACRf;QACAM,OAAOG;IACT;IAEA,MAAMa,gBAAgB1B,wBAAwB;QAC5CiB,QAAQ,IAAI,CAACD,OAAO,CAACC,MAAM;QAC3BU,MAAMlB;QACNM;IACF;IAEA,MAAMa,MAAM,MAAMjB,aAAakB,gBAAgB,CAACJ,OAAOC,eAAerB;IAEtE,IAAI,CAACuB,KAAK;QACR,OAAO;IACT;IAEA,MAAME,SAASC,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACL;IAEzC,MAAMM,oBAAoBN,IAAIO,kBAAkB;IAEhD,uBAAuB;IACvBL,OAAO5B,EAAE,GAAG4B,OAAOM,GAAG;IACtB,IAAIF,mBAAmB;QACrBJ,OAAOK,kBAAkB,GAAGD;IAC9B;IACA,OAAOJ;AACT,EAAC"}
1
+ {"version":3,"sources":["../src/updateVersion.ts"],"sourcesContent":["import type { QueryOptions } from 'mongoose'\n\nimport { buildVersionCollectionFields, type UpdateVersion } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getSession } from './utilities/getSession.js'\nimport { transform } from './utilities/transform.js'\n\nexport const updateVersion: UpdateVersion = async function updateVersion(\n this: MongooseAdapter,\n { id, collection, locale, options: optionsArgs = {}, req, select, versionData, where },\n) {\n const VersionModel = this.versions[collection]\n const whereToUse = where || { id: { equals: id } }\n const fields = buildVersionCollectionFields(\n this.payload.config,\n this.payload.collections[collection].config,\n )\n\n const flattenedFields = buildVersionCollectionFields(\n this.payload.config,\n this.payload.collections[collection].config,\n true,\n )\n\n const options: QueryOptions = {\n ...optionsArgs,\n lean: true,\n new: true,\n projection: buildProjectionFromSelect({\n adapter: this,\n fields: flattenedFields,\n select,\n }),\n session: await getSession(this, req),\n }\n\n const query = await buildQuery({\n adapter: this,\n fields: flattenedFields,\n locale,\n where: whereToUse,\n })\n\n transform({ adapter: this, data: versionData, fields, operation: 'write' })\n\n const doc = await VersionModel.findOneAndUpdate(query, versionData, options)\n\n if (!doc) {\n return null\n }\n\n transform({ adapter: this, data: doc, fields, operation: 'write' })\n\n return doc\n}\n"],"names":["buildVersionCollectionFields","buildQuery","buildProjectionFromSelect","getSession","transform","updateVersion","id","collection","locale","options","optionsArgs","req","select","versionData","where","VersionModel","versions","whereToUse","equals","fields","payload","config","collections","flattenedFields","lean","new","projection","adapter","session","query","data","operation","doc","findOneAndUpdate"],"mappings":"AAEA,SAASA,4BAA4B,QAA4B,UAAS;AAI1E,SAASC,UAAU,QAAQ,0BAAyB;AACpD,SAASC,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAASC,SAAS,QAAQ,2BAA0B;AAEpD,OAAO,MAAMC,gBAA+B,eAAeA,cAEzD,EAAEC,EAAE,EAAEC,UAAU,EAAEC,MAAM,EAAEC,SAASC,cAAc,CAAC,CAAC,EAAEC,GAAG,EAAEC,MAAM,EAAEC,WAAW,EAAEC,KAAK,EAAE;IAEtF,MAAMC,eAAe,IAAI,CAACC,QAAQ,CAACT,WAAW;IAC9C,MAAMU,aAAaH,SAAS;QAAER,IAAI;YAAEY,QAAQZ;QAAG;IAAE;IACjD,MAAMa,SAASnB,6BACb,IAAI,CAACoB,OAAO,CAACC,MAAM,EACnB,IAAI,CAACD,OAAO,CAACE,WAAW,CAACf,WAAW,CAACc,MAAM;IAG7C,MAAME,kBAAkBvB,6BACtB,IAAI,CAACoB,OAAO,CAACC,MAAM,EACnB,IAAI,CAACD,OAAO,CAACE,WAAW,CAACf,WAAW,CAACc,MAAM,EAC3C;IAGF,MAAMZ,UAAwB;QAC5B,GAAGC,WAAW;QACdc,MAAM;QACNC,KAAK;QACLC,YAAYxB,0BAA0B;YACpCyB,SAAS,IAAI;YACbR,QAAQI;YACRX;QACF;QACAgB,SAAS,MAAMzB,WAAW,IAAI,EAAEQ;IAClC;IAEA,MAAMkB,QAAQ,MAAM5B,WAAW;QAC7B0B,SAAS,IAAI;QACbR,QAAQI;QACRf;QACAM,OAAOG;IACT;IAEAb,UAAU;QAAEuB,SAAS,IAAI;QAAEG,MAAMjB;QAAaM;QAAQY,WAAW;IAAQ;IAEzE,MAAMC,MAAM,MAAMjB,aAAakB,gBAAgB,CAACJ,OAAOhB,aAAaJ;IAEpE,IAAI,CAACuB,KAAK;QACR,OAAO;IACT;IAEA5B,UAAU;QAAEuB,SAAS,IAAI;QAAEG,MAAME;QAAKb;QAAQY,WAAW;IAAQ;IAEjE,OAAOC;AACT,EAAC"}
@@ -0,0 +1,27 @@
1
+ import type { Field } from 'payload';
2
+ import type { MongooseAdapter } from '../index.js';
3
+ type Args = {
4
+ /** instance of the adapter */
5
+ adapter: MongooseAdapter;
6
+ /** data to transform, can be an array of documents or a single document */
7
+ data: Record<string, unknown> | Record<string, unknown>[];
8
+ /** fields accossiated with the data */
9
+ fields: Field[];
10
+ /** slug of the global, pass only when the operation is `write` */
11
+ globalSlug?: string;
12
+ /**
13
+ * Type of the operation
14
+ * read - sanitizes ObjectIDs, Date to strings.
15
+ * write - sanitizes string relationships to ObjectIDs.
16
+ */
17
+ operation: 'read' | 'write';
18
+ parentIsLocalized?: boolean;
19
+ /**
20
+ * Throw errors on invalid relationships
21
+ * @default true
22
+ */
23
+ validateRelationships?: boolean;
24
+ };
25
+ export declare const transform: ({ adapter, data, fields, globalSlug, operation, parentIsLocalized, validateRelationships, }: Args) => void;
26
+ export {};
27
+ //# sourceMappingURL=transform.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transform.d.ts","sourceRoot":"","sources":["../../src/utilities/transform.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,KAAK,EAMN,MAAM,SAAS,CAAA;AAMhB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAgMlD,KAAK,IAAI,GAAG;IACV,8BAA8B;IAC9B,OAAO,EAAE,eAAe,CAAA;IACxB,2EAA2E;IAC3E,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAA;IACzD,uCAAuC;IACvC,MAAM,EAAE,KAAK,EAAE,CAAA;IACf,kEAAkE;IAClE,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB;;;;OAIG;IACH,SAAS,EAAE,MAAM,GAAG,OAAO,CAAA;IAC3B,iBAAiB,CAAC,EAAE,OAAO,CAAA;IAC3B;;;OAGG;IACH,qBAAqB,CAAC,EAAE,OAAO,CAAA;CAChC,CAAA;AAED,eAAO,MAAM,SAAS,gGAQnB,IAAI,SA4GN,CAAA"}
@@ -0,0 +1,224 @@
1
+ import { Types } from 'mongoose';
2
+ import { traverseFields } from 'payload';
3
+ import { fieldAffectsData, fieldShouldBeLocalized } from 'payload/shared';
4
+ function isValidRelationObject(value) {
5
+ return typeof value === 'object' && value !== null && 'relationTo' in value && 'value' in value;
6
+ }
7
+ const convertRelationshipValue = ({ operation, relatedCollection, validateRelationships, value })=>{
8
+ const customIDField = relatedCollection.fields.find((field)=>fieldAffectsData(field) && field.name === 'id');
9
+ if (operation === 'read') {
10
+ if (value instanceof Types.ObjectId) {
11
+ return value.toHexString();
12
+ }
13
+ return value;
14
+ }
15
+ if (customIDField) {
16
+ return value;
17
+ }
18
+ if (typeof value === 'string') {
19
+ try {
20
+ return new Types.ObjectId(value);
21
+ } catch (e) {
22
+ if (validateRelationships) {
23
+ throw e;
24
+ }
25
+ return value;
26
+ }
27
+ }
28
+ return value;
29
+ };
30
+ const sanitizeRelationship = ({ config, field, locale, operation, ref, validateRelationships, value })=>{
31
+ if (field.type === 'join') {
32
+ if (operation === 'read' && value && typeof value === 'object' && 'docs' in value && Array.isArray(value.docs)) {
33
+ for(let i = 0; i < value.docs.length; i++){
34
+ const item = value.docs[i];
35
+ if (item instanceof Types.ObjectId) {
36
+ value.docs[i] = item.toHexString();
37
+ } else if (Array.isArray(field.collection) && item) {
38
+ // Fields here for polymorphic joins cannot be determinted, JSON.parse needed
39
+ value.docs[i] = JSON.parse(JSON.stringify(value.docs[i]));
40
+ }
41
+ }
42
+ }
43
+ return value;
44
+ }
45
+ let relatedCollection;
46
+ let result = value;
47
+ const hasManyRelations = typeof field.relationTo !== 'string';
48
+ if (!hasManyRelations) {
49
+ relatedCollection = config.collections?.find(({ slug })=>slug === field.relationTo);
50
+ }
51
+ if (Array.isArray(value)) {
52
+ result = value.map((val)=>{
53
+ // Handle has many - polymorphic
54
+ if (isValidRelationObject(val)) {
55
+ const relatedCollectionForSingleValue = config.collections?.find(({ slug })=>slug === val.relationTo);
56
+ if (relatedCollectionForSingleValue) {
57
+ return {
58
+ relationTo: val.relationTo,
59
+ value: convertRelationshipValue({
60
+ operation,
61
+ relatedCollection: relatedCollectionForSingleValue,
62
+ validateRelationships,
63
+ value: val.value
64
+ })
65
+ };
66
+ }
67
+ }
68
+ if (relatedCollection) {
69
+ return convertRelationshipValue({
70
+ operation,
71
+ relatedCollection,
72
+ validateRelationships,
73
+ value: val
74
+ });
75
+ }
76
+ return val;
77
+ });
78
+ } else if (isValidRelationObject(value)) {
79
+ relatedCollection = config.collections?.find(({ slug })=>slug === value.relationTo);
80
+ if (relatedCollection) {
81
+ result = {
82
+ relationTo: value.relationTo,
83
+ value: convertRelationshipValue({
84
+ operation,
85
+ relatedCollection,
86
+ validateRelationships,
87
+ value: value.value
88
+ })
89
+ };
90
+ }
91
+ } else if (relatedCollection) {
92
+ result = convertRelationshipValue({
93
+ operation,
94
+ relatedCollection,
95
+ validateRelationships,
96
+ value
97
+ });
98
+ }
99
+ if (locale) {
100
+ ref[locale] = result;
101
+ } else {
102
+ ref[field.name] = result;
103
+ }
104
+ };
105
+ const sanitizeDate = ({ field, locale, ref, value })=>{
106
+ if (!value) {
107
+ return;
108
+ }
109
+ if (value instanceof Date) {
110
+ value = value.toISOString();
111
+ }
112
+ if (locale) {
113
+ ref[locale] = value;
114
+ } else {
115
+ ref[field.name] = value;
116
+ }
117
+ };
118
+ export const transform = ({ adapter, data, fields, globalSlug, operation, parentIsLocalized, validateRelationships = true })=>{
119
+ if (Array.isArray(data)) {
120
+ for(let i = 0; i < data.length; i++){
121
+ transform({
122
+ adapter,
123
+ data: data[i],
124
+ fields,
125
+ globalSlug,
126
+ operation,
127
+ validateRelationships
128
+ });
129
+ }
130
+ return;
131
+ }
132
+ const { payload: { config } } = adapter;
133
+ if (operation === 'read') {
134
+ delete data['__v'];
135
+ data.id = data._id;
136
+ delete data['_id'];
137
+ if (data.id instanceof Types.ObjectId) {
138
+ data.id = data.id.toHexString();
139
+ }
140
+ }
141
+ if (operation === 'write' && globalSlug) {
142
+ data.globalType = globalSlug;
143
+ }
144
+ const sanitize = ({ field, ref })=>{
145
+ if (!ref || typeof ref !== 'object') {
146
+ return;
147
+ }
148
+ if (field.type === 'date' && operation === 'read' && ref[field.name]) {
149
+ if (config.localization && fieldShouldBeLocalized({
150
+ field,
151
+ parentIsLocalized
152
+ })) {
153
+ const fieldRef = ref[field.name];
154
+ if (!fieldRef || typeof fieldRef !== 'object') {
155
+ return;
156
+ }
157
+ for (const locale of config.localization.localeCodes){
158
+ sanitizeDate({
159
+ field,
160
+ ref: fieldRef,
161
+ value: fieldRef[locale]
162
+ });
163
+ }
164
+ } else {
165
+ sanitizeDate({
166
+ field,
167
+ ref: ref,
168
+ value: ref[field.name]
169
+ });
170
+ }
171
+ }
172
+ if (field.type === 'relationship' || field.type === 'upload' || operation === 'read' && field.type === 'join') {
173
+ if (!ref[field.name]) {
174
+ return;
175
+ }
176
+ // handle localized relationships
177
+ if (config.localization && fieldShouldBeLocalized({
178
+ field,
179
+ parentIsLocalized
180
+ })) {
181
+ const locales = config.localization.locales;
182
+ const fieldRef = ref[field.name];
183
+ if (typeof fieldRef !== 'object') {
184
+ return;
185
+ }
186
+ for (const { code } of locales){
187
+ const value = ref[field.name][code];
188
+ if (value) {
189
+ sanitizeRelationship({
190
+ config,
191
+ field,
192
+ locale: code,
193
+ operation,
194
+ ref: fieldRef,
195
+ validateRelationships,
196
+ value
197
+ });
198
+ }
199
+ }
200
+ } else {
201
+ // handle non-localized relationships
202
+ sanitizeRelationship({
203
+ config,
204
+ field,
205
+ locale: undefined,
206
+ operation,
207
+ ref: ref,
208
+ validateRelationships,
209
+ value: ref[field.name]
210
+ });
211
+ }
212
+ }
213
+ };
214
+ traverseFields({
215
+ callback: sanitize,
216
+ config,
217
+ fields,
218
+ fillEmpty: false,
219
+ parentIsLocalized,
220
+ ref: data
221
+ });
222
+ };
223
+
224
+ //# sourceMappingURL=transform.js.map