@payloadcms/db-mongodb 3.0.0-canary.a0b06af → 3.0.0-canary.a14e066

Sign up to get free protection for your applications and to get access to all the features.
Files changed (121) hide show
  1. package/dist/connect.d.ts.map +1 -1
  2. package/dist/connect.js +13 -4
  3. package/dist/connect.js.map +1 -1
  4. package/dist/create.d.ts.map +1 -1
  5. package/dist/create.js +7 -1
  6. package/dist/create.js.map +1 -1
  7. package/dist/createGlobal.d.ts.map +1 -1
  8. package/dist/createGlobal.js +10 -5
  9. package/dist/createGlobal.js.map +1 -1
  10. package/dist/createGlobalVersion.d.ts +1 -1
  11. package/dist/createGlobalVersion.d.ts.map +1 -1
  12. package/dist/createGlobalVersion.js +13 -4
  13. package/dist/createGlobalVersion.js.map +1 -1
  14. package/dist/createMigration.d.ts.map +1 -1
  15. package/dist/createMigration.js +3 -3
  16. package/dist/createMigration.js.map +1 -1
  17. package/dist/createVersion.d.ts +1 -1
  18. package/dist/createVersion.d.ts.map +1 -1
  19. package/dist/createVersion.js +31 -9
  20. package/dist/createVersion.js.map +1 -1
  21. package/dist/deleteOne.js +1 -1
  22. package/dist/deleteOne.js.map +1 -1
  23. package/dist/find.d.ts.map +1 -1
  24. package/dist/find.js +27 -4
  25. package/dist/find.js.map +1 -1
  26. package/dist/findGlobal.js +1 -1
  27. package/dist/findGlobal.js.map +1 -1
  28. package/dist/findGlobalVersions.d.ts.map +1 -1
  29. package/dist/findGlobalVersions.js +10 -4
  30. package/dist/findGlobalVersions.js.map +1 -1
  31. package/dist/findOne.d.ts.map +1 -1
  32. package/dist/findOne.js +19 -3
  33. package/dist/findOne.js.map +1 -1
  34. package/dist/findVersions.d.ts.map +1 -1
  35. package/dist/findVersions.js +8 -2
  36. package/dist/findVersions.js.map +1 -1
  37. package/dist/index.d.ts +52 -10
  38. package/dist/index.d.ts.map +1 -1
  39. package/dist/index.js +12 -6
  40. package/dist/index.js.map +1 -1
  41. package/dist/init.d.ts.map +1 -1
  42. package/dist/init.js +10 -7
  43. package/dist/init.js.map +1 -1
  44. package/dist/models/buildCollectionSchema.d.ts +1 -2
  45. package/dist/models/buildCollectionSchema.d.ts.map +1 -1
  46. package/dist/models/buildCollectionSchema.js +16 -4
  47. package/dist/models/buildCollectionSchema.js.map +1 -1
  48. package/dist/models/buildGlobalModel.js +2 -2
  49. package/dist/models/buildGlobalModel.js.map +1 -1
  50. package/dist/models/buildSchema.d.ts +1 -2
  51. package/dist/models/buildSchema.d.ts.map +1 -1
  52. package/dist/models/buildSchema.js +100 -22
  53. package/dist/models/buildSchema.js.map +1 -1
  54. package/dist/queries/buildAndOrConditions.d.ts.map +1 -1
  55. package/dist/queries/buildAndOrConditions.js +0 -2
  56. package/dist/queries/buildAndOrConditions.js.map +1 -1
  57. package/dist/queries/buildQuery.d.ts +2 -2
  58. package/dist/queries/buildQuery.d.ts.map +1 -1
  59. package/dist/queries/buildQuery.js +1 -2
  60. package/dist/queries/buildQuery.js.map +1 -1
  61. package/dist/queries/buildSearchParams.d.ts.map +1 -1
  62. package/dist/queries/buildSearchParams.js +19 -11
  63. package/dist/queries/buildSearchParams.js.map +1 -1
  64. package/dist/queries/getLocalizedSortProperty.spec.js +43 -43
  65. package/dist/queries/getLocalizedSortProperty.spec.js.map +1 -1
  66. package/dist/queries/parseParams.d.ts.map +1 -1
  67. package/dist/queries/parseParams.js +5 -6
  68. package/dist/queries/parseParams.js.map +1 -1
  69. package/dist/queries/sanitizeQueryValue.d.ts.map +1 -1
  70. package/dist/queries/sanitizeQueryValue.js +142 -26
  71. package/dist/queries/sanitizeQueryValue.js.map +1 -1
  72. package/dist/queryDrafts.d.ts.map +1 -1
  73. package/dist/queryDrafts.js +9 -5
  74. package/dist/queryDrafts.js.map +1 -1
  75. package/dist/transactions/beginTransaction.d.ts.map +1 -1
  76. package/dist/transactions/beginTransaction.js +2 -0
  77. package/dist/transactions/beginTransaction.js.map +1 -1
  78. package/dist/transactions/commitTransaction.d.ts.map +1 -1
  79. package/dist/transactions/commitTransaction.js +3 -1
  80. package/dist/transactions/commitTransaction.js.map +1 -1
  81. package/dist/types.d.ts +7 -4
  82. package/dist/types.d.ts.map +1 -1
  83. package/dist/types.js.map +1 -1
  84. package/dist/updateGlobal.d.ts.map +1 -1
  85. package/dist/updateGlobal.js +8 -2
  86. package/dist/updateGlobal.js.map +1 -1
  87. package/dist/updateGlobalVersion.d.ts +2 -2
  88. package/dist/updateGlobalVersion.d.ts.map +1 -1
  89. package/dist/updateGlobalVersion.js +10 -3
  90. package/dist/updateGlobalVersion.js.map +1 -1
  91. package/dist/updateOne.d.ts.map +1 -1
  92. package/dist/updateOne.js +10 -3
  93. package/dist/updateOne.js.map +1 -1
  94. package/dist/updateVersion.d.ts +1 -1
  95. package/dist/updateVersion.d.ts.map +1 -1
  96. package/dist/updateVersion.js +8 -1
  97. package/dist/updateVersion.js.map +1 -1
  98. package/dist/upsert.d.ts +3 -0
  99. package/dist/upsert.d.ts.map +1 -0
  100. package/dist/upsert.js +14 -0
  101. package/dist/upsert.js.map +1 -0
  102. package/dist/utilities/buildJoinAggregation.d.ts +15 -0
  103. package/dist/utilities/buildJoinAggregation.d.ts.map +1 -0
  104. package/dist/utilities/buildJoinAggregation.js +148 -0
  105. package/dist/utilities/buildJoinAggregation.js.map +1 -0
  106. package/dist/utilities/getDBName.d.ts.map +1 -1
  107. package/dist/utilities/getDBName.js +3 -1
  108. package/dist/utilities/getDBName.js.map +1 -1
  109. package/dist/utilities/sanitizeInternalFields.d.ts +1 -2
  110. package/dist/utilities/sanitizeInternalFields.d.ts.map +1 -1
  111. package/dist/utilities/sanitizeInternalFields.js +1 -2
  112. package/dist/utilities/sanitizeInternalFields.js.map +1 -1
  113. package/dist/utilities/sanitizeRelationshipIDs.d.ts +9 -0
  114. package/dist/utilities/sanitizeRelationshipIDs.d.ts.map +1 -0
  115. package/dist/utilities/sanitizeRelationshipIDs.js +115 -0
  116. package/dist/utilities/sanitizeRelationshipIDs.js.map +1 -0
  117. package/dist/withSession.d.ts +1 -1
  118. package/dist/withSession.d.ts.map +1 -1
  119. package/dist/withSession.js +5 -3
  120. package/dist/withSession.js.map +1 -1
  121. package/package.json +9 -7
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/queryDrafts.ts"],"sourcesContent":["import type { PaginateOptions } from 'mongoose'\nimport type { PayloadRequest, QueryDrafts } from 'payload'\n\nimport { combineQueries, flattenWhereToOperators } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildSortParam } from './queries/buildSortParam.js'\nimport sanitizeInternalFields from './utilities/sanitizeInternalFields.js'\nimport { withSession } from './withSession.js'\n\nexport const queryDrafts: QueryDrafts = async function queryDrafts(\n this: MongooseAdapter,\n { collection, limit, locale, page, pagination, req = {} as PayloadRequest, sort: sortArg, where },\n) {\n const VersionModel = this.versions[collection]\n const collectionConfig = this.payload.collections[collection].config\n const options = await withSession(this, req)\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.fields,\n locale,\n sort: sortArg || collectionConfig.defaultSort,\n timestamps: true,\n })\n }\n\n const combinedWhere = combineQueries({ latest: { equals: true } }, where)\n\n const versionQuery = await VersionModel.buildQuery({\n locale,\n payload: this.payload,\n where: combinedWhere,\n })\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 forceCountFn: hasNearConstraint,\n lean: true,\n leanWithId: true,\n options,\n page,\n pagination,\n sort,\n useEstimatedCount,\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 const result = await VersionModel.paginate(versionQuery, paginationOptions)\n const docs = JSON.parse(JSON.stringify(result.docs))\n\n return {\n ...result,\n docs: docs.map((doc) => {\n // eslint-disable-next-line no-param-reassign\n doc = {\n _id: doc.parent,\n id: doc.parent,\n ...doc.version,\n createdAt: doc.createdAt,\n updatedAt: doc.updatedAt,\n }\n\n return sanitizeInternalFields(doc)\n }),\n }\n}\n"],"names":["combineQueries","flattenWhereToOperators","buildSortParam","sanitizeInternalFields","withSession","queryDrafts","collection","limit","locale","page","pagination","req","sort","sortArg","where","VersionModel","versions","collectionConfig","payload","collections","config","options","hasNearConstraint","constraints","some","prop","Object","keys","key","fields","defaultSort","timestamps","combinedWhere","latest","equals","versionQuery","buildQuery","useEstimatedCount","length","paginationOptions","forceCountFn","lean","leanWithId","disableIndexHints","useCustomCountFn","Promise","resolve","countDocuments","hint","_id","result","paginate","docs","JSON","parse","stringify","map","doc","parent","id","version","createdAt","updatedAt"],"mappings":"AAGA,SAASA,cAAc,EAAEC,uBAAuB,QAAQ,UAAS;AAIjE,SAASC,cAAc,QAAQ,8BAA6B;AAC5D,OAAOC,4BAA4B,wCAAuC;AAC1E,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,cAA2B,eAAeA,YAErD,EAAEC,UAAU,EAAEC,KAAK,EAAEC,MAAM,EAAEC,IAAI,EAAEC,UAAU,EAAEC,MAAM,CAAC,CAAmB,EAAEC,MAAMC,OAAO,EAAEC,KAAK,EAAE;IAEjG,MAAMC,eAAe,IAAI,CAACC,QAAQ,CAACV,WAAW;IAC9C,MAAMW,mBAAmB,IAAI,CAACC,OAAO,CA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,qEAAqE;QACrEgC,kBAAkBlB,OAAO,CAACd,KAAK,GAAGA;IACpC;IAEA,MAAM2C,SAAS,MAAMnC,aAAaoC,QAAQ,CAAChB,cAAcI;IACzD,MAAMa,OAAOC,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACL,OAAOE,IAAI;IAElD,OAAO;QACL,GAAGF,MAAM;QACTE,MAAMA,KAAKI,GAAG,CAAC,CAACC;YACd,6CAA6C;YAC7CA,MAAM;gBACJR,KAAKQ,IAAIC,MAAM;gBACfC,IAAIF,IAAIC,MAAM;gBACd,GAAGD,IAAIG,OAAO;gBACdC,WAAWJ,IAAII,SAAS;gBACxBC,WAAWL,IAAIK,SAAS;YAC1B;YAEA,OAAO3D,uBAAuBsD;QAChC;IACF;AACF,EAAC"}
1
+ {"version":3,"sources":["../src/queryDrafts.ts"],"sourcesContent":["import type { PaginateOptions } from 'mongoose'\nimport type { PayloadRequest, QueryDrafts } from 'payload'\n\nimport { combineQueries, flattenWhereToOperators } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildSortParam } from './queries/buildSortParam.js'\nimport { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js'\nimport { withSession } from './withSession.js'\n\nexport const queryDrafts: QueryDrafts = async function queryDrafts(\n this: MongooseAdapter,\n { collection, limit, locale, page, pagination, req = {} as PayloadRequest, sort: sortArg, where },\n) {\n const VersionModel = this.versions[collection]\n const collectionConfig = this.payload.collections[collection].config\n const options = await withSession(this, req)\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.fields,\n locale,\n sort: sortArg || collectionConfig.defaultSort,\n timestamps: true,\n })\n }\n\n const combinedWhere = combineQueries({ latest: { equals: true } }, where)\n\n const versionQuery = await VersionModel.buildQuery({\n locale,\n payload: this.payload,\n where: combinedWhere,\n })\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 forceCountFn: hasNearConstraint,\n lean: true,\n leanWithId: true,\n options,\n page,\n pagination,\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 const result = await VersionModel.paginate(versionQuery, paginationOptions)\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":["combineQueries","flattenWhereToOperators","buildSortParam","sanitizeInternalFields","withSession","queryDrafts","collection","limit","locale","page","pagination","req","sort","sortArg","where","VersionModel","versions","collectionConfig","payload","collections","config","options","hasNearConstraint","constraints","some","prop","Object","keys","key","fields","defaultSort","timestamps","combinedWhere","latest","equals","versionQuery","buildQuery","useEstimatedCount","length","paginationOptions","forceCountFn","lean","leanWithId","collation","defaultLocale","disableIndexHints","useCustomCountFn","Promise","resolve","countDocuments","hint","_id","result","paginate","docs","J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AqC;QACzCC,cAAclB;QACdmB,MAAM;QACNC,YAAY;QACZrB;QACAZ;QACAC;QACAE;QACAyB;IACF;IAEA,IAAI,IAAI,CAACM,SAAS,EAAE;QAClB,MAAMC,gBAAgB;QACtBL,kBAAkBI,SAAS,GAAG;YAC5BnC,QAAQA,UAAUA,WAAW,SAASA,WAAW,MAAMA,SAASoC;YAChE,GAAG,IAAI,CAACD,SAAS;QACnB;IACF;IAEA,IACE,CAACN,qBACDX,OAAOC,IAAI,CAACQ,cAAcG,MAAM,KAAK,KACrC,IAAI,CAACO,iBAAiB,KAAK,MAC3B;QACA,mHAAmH;QACnH,qHAAqH;QACrH,mHAAmH;QACnH,4BAA4B;QAC5BN,kBAAkBO,gBAAgB,GAAG;YACnC,OAAOC,QAAQC,OAAO,CACpBjC,aAAakC,cAAc,CAACd,cAAc;gBACxCe,MAAM;oBAAEC,KAAK;gBAAE;YACjB;QAEJ;IACF;IAEA,IAAI5C,QAAQ,GAAG;QACbgC,kBAAkBhC,KAAK,GAAGA;QAC1B,qEAAqE;QACrEgC,kBAAkBlB,OAAO,CAACd,KAAK,GAAGA;IACpC;IAEA,MAAM6C,SAAS,MAAMrC,aAAasC,QAAQ,CAAClB,cAAcI;IACzD,MAAMe,OAAOC,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACL,OAAOE,IAAI;IAElD,OAAO;QACL,GAAGF,MAAM;QACTE,MAAMA,KAAKI,GAAG,CAAC,CAACC;YACdA,MAAM;gBACJR,KAAKQ,IAAIC,MAAM;gBACfC,IAAIF,IAAIC,MAAM;gBACd,GAAGD,IAAIG,OAAO;YAChB;YAEA,OAAO3D,uBAAuBwD;QAChC;IACF;AACF,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"beginTransaction.d.ts","sourceRoot":"","sources":["../../src/transactions/beginTransaction.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAO/C,eAAO,MAAM,gBAAgB,EAAE,gBAqB9B,CAAA"}
1
+ {"version":3,"file":"beginTransaction.d.ts","sourceRoot":"","sources":["../../src/transactions/beginTransaction.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAS/C,eAAO,MAAM,gBAAgB,EAAE,gBAqB9B,CAAA"}
@@ -1,5 +1,7 @@
1
1
  import { APIError } from 'payload';
2
2
  import { v4 as uuid } from 'uuid';
3
+ // Needs await to fulfill the interface
4
+ // eslint-disable-next-line @typescript-eslint/require-await
3
5
  export const beginTransaction = async function beginTransaction(options) {
4
6
  if (!this.connection) {
5
7
  throw new APIError('beginTransaction called while no connection to the database exists');
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/transactions/beginTransaction.ts"],"sourcesContent":["import type { TransactionOptions } from 'mongodb'\nimport type { BeginTransaction } from 'payload'\n\nimport { APIError } from 'payload'\nimport { v4 as uuid } from 'uuid'\n\nimport type { MongooseAdapter } from '../index.js'\n\nexport const beginTransaction: BeginTransaction = async function beginTransaction(\n this: MongooseAdapter,\n options: TransactionOptions,\n) {\n if (!this.connection) {\n throw new APIError('beginTransaction called while no connection to the database exists')\n }\n\n const client = this.connection.getClient()\n const id = uuid()\n\n if (!this.sessions[id]) {\n this.sessions[id] = client.startSession()\n }\n if (this.sessions[id].inTransaction()) {\n this.payload.logger.warn('beginTransaction called while transaction already exists')\n } else {\n this.sessions[id].startTransaction(options || (this.transactionOptions as TransactionOptions))\n }\n\n return id\n}\n"],"names":["APIError","v4","uuid","beginTransaction","options","connection","client","getClient","id","sessions","startSession","inTransaction","payload","logger","warn","startTransaction","transactionOptions"],"mappings":"AAGA,SAASA,QAAQ,QAAQ,UAAS;AAClC,SAASC,MAAMC,IAAI,QAAQ,OAAM;AAIjC,OAAO,MAAMC,mBAAqC,eAAeA,iBAE/DC,OAA2B;IAE3B,IAAI,CAAC,IAAI,CAACC,UAAU,EAAE;QACpB,MAAM,IAAIL,SAAS;IACrB;IAEA,MAAMM,SAAS,IAAI,CAACD,UAAU,CAACE,SAAS;IACxC,MAAMC,KAAKN;IAEX,IAAI,CAAC,IAAI,CAACO,QAAQ,CAACD,GAAG,EAAE;QACtB,IAAI,CAACC,QAAQ,CAACD,GAAG,GAAGF,OAAOI,YAAY;IACzC;IACA,IAAI,IAAI,CAACD,QAAQ,CAACD,GAAG,CAACG,aAAa,IAAI;QACrC,IAAI,CAACC,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC;IAC3B,OAAO;QACL,IAAI,CAACL,QAAQ,CAACD,GAAG,CAACO,gBAAgB,CAACX,WAAY,IAAI,CAACY,kBAAkB;IACxE;IAEA,OAAOR;AACT,EAAC"}
1
+ {"version":3,"sources":["../../src/transactions/beginTransaction.ts"],"sourcesContent":["import type { TransactionOptions } from 'mongodb'\nimport type { BeginTransaction } from 'payload'\n\nimport { APIError } from 'payload'\nimport { v4 as uuid } from 'uuid'\n\nimport type { MongooseAdapter } from '../index.js'\n\n// Needs await to fulfill the interface\n// eslint-disable-next-line @typescript-eslint/require-await\nexport const beginTransaction: BeginTransaction = async function beginTransaction(\n this: MongooseAdapter,\n options: TransactionOptions,\n) {\n if (!this.connection) {\n throw new APIError('beginTransaction called while no connection to the database exists')\n }\n\n const client = this.connection.getClient()\n const id = uuid()\n\n if (!this.sessions[id]) {\n this.sessions[id] = client.startSession()\n }\n if (this.sessions[id].inTransaction()) {\n this.payload.logger.warn('beginTransaction called while transaction already exists')\n } else {\n this.sessions[id].startTransaction(options || (this.transactionOptions as TransactionOptions))\n }\n\n return id\n}\n"],"names":["APIError","v4","uuid","beginTransaction","options","connection","client","getClient","id","sessions","startSession","inTransaction","payload","logger","warn","startTransaction","transactionOptions"],"mappings":"AAGA,SAASA,QAAQ,QAAQ,UAAS;AAClC,SAASC,MAAMC,IAAI,QAAQ,OAAM;AAIjC,uCAAuC;AACvC,4DAA4D;AAC5D,OAAO,MAAMC,mBAAqC,eAAeA,iBAE/DC,OAA2B;IAE3B,IAAI,CAAC,IAAI,CAACC,UAAU,EAAE;QACpB,MAAM,IAAIL,SAAS;IACrB;IAEA,MAAMM,SAAS,IAAI,CAACD,UAAU,CAACE,SAAS;IACxC,MAAMC,KAAKN;IAEX,IAAI,CAAC,IAAI,CAACO,QAAQ,CAACD,GAAG,EAAE;QACtB,IAAI,CAACC,QAAQ,CAACD,GAAG,GAAGF,OAAOI,YAAY;IACzC;IACA,IAAI,IAAI,CAACD,QAAQ,CAACD,GAAG,CAACG,aAAa,IAAI;QACrC,IAAI,CAACC,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC;IAC3B,OAAO;QACL,IAAI,CAACL,QAAQ,CAACD,GAAG,CAACO,gBAAgB,CAACX,WAAY,IAAI,CAACY,kBAAkB;IACxE;IAEA,OAAOR;AACT,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"commitTransaction.d.ts","sourceRoot":"","sources":["../../src/transactions/commitTransaction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAEhD,eAAO,MAAM,iBAAiB,EAAE,iBAc/B,CAAA"}
1
+ {"version":3,"file":"commitTransaction.d.ts","sourceRoot":"","sources":["../../src/transactions/commitTransaction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAEhD,eAAO,MAAM,iBAAiB,EAAE,iBAgB/B,CAAA"}
@@ -1,5 +1,7 @@
1
1
  export const commitTransaction = async function commitTransaction(id) {
2
- if (id instanceof Promise) return;
2
+ if (id instanceof Promise) {
3
+ return;
4
+ }
3
5
  if (!this.sessions[id]?.inTransaction()) {
4
6
  return;
5
7
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/transactions/commitTransaction.ts"],"sourcesContent":["import type { CommitTransaction } from 'payload'\n\nexport const commitTransaction: CommitTransaction = async function commitTransaction(id) {\n if (id instanceof Promise) return\n\n if (!this.sessions[id]?.inTransaction()) {\n return\n }\n\n await this.sessions[id].commitTransaction()\n try {\n await this.sessions[id].endSession()\n } catch (error) {\n // ending sessions is only best effort and won't impact anything if it fails since the transaction was committed\n }\n delete this.sessions[id]\n}\n"],"names":["commitTransaction","id","Promise","sessions","inTransaction","endSession","error"],"mappings":"AAEA,OAAO,MAAMA,oBAAuC,eAAeA,kBAAkBC,EAAE;IACrF,IAAIA,cAAcC,SAAS;IAE3B,IAAI,CAAC,IAAI,CAACC,QAAQ,CAACF,GAAG,EAAEG,iBAAiB;QACvC;IACF;IAEA,MAAM,IAAI,CAACD,QAAQ,CAACF,GAAG,CAACD,iBAAiB;IACzC,IAAI;QACF,MAAM,IAAI,CAACG,QAAQ,CAACF,GAAG,CAACI,UAAU;IACpC,EAAE,OAAOC,OAAO;IACd,gHAAgH;IAClH;IACA,OAAO,IAAI,CAACH,QAAQ,CAACF,GAAG;AAC1B,EAAC"}
1
+ {"version":3,"sources":["../../src/transactions/commitTransaction.ts"],"sourcesContent":["import type { CommitTransaction } from 'payload'\n\nexport const commitTransaction: CommitTransaction = async function commitTransaction(id) {\n if (id instanceof Promise) {\n return\n }\n\n if (!this.sessions[id]?.inTransaction()) {\n return\n }\n\n await this.sessions[id].commitTransaction()\n try {\n await this.sessions[id].endSession()\n } catch (error) {\n // ending sessions is only best effort and won't impact anything if it fails since the transaction was committed\n }\n delete this.sessions[id]\n}\n"],"names":["commitTransaction","id","Promise","sessions","inTransaction","endSession","error"],"mappings":"AAEA,OAAO,MAAMA,oBAAuC,eAAeA,kBAAkBC,EAAE;IACrF,IAAIA,cAAcC,SAAS;QACzB;IACF;IAEA,IAAI,CAAC,IAAI,CAACC,QAAQ,CAACF,GAAG,EAAEG,iBAAiB;QACvC;IACF;IAEA,MAAM,IAAI,CAACD,QAAQ,CAACF,GAAG,CAACD,iBAAiB;IACzC,IAAI;QACF,MAAM,IAAI,CAACG,QAAQ,CAACF,GAAG,CAACI,UAAU;IACpC,EAAE,OAAOC,OAAO;IACd,gHAAgH;IAClH;IACA,OAAO,IAAI,CAACH,QAAQ,CAACF,GAAG;AAC1B,EAAC"}
package/dist/types.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import type { IndexDefinition, IndexOptions, Model, PaginateModel, SchemaOptions } from 'mongoose';
2
- import type { ArrayField, BlockField, CheckboxField, CodeField, CollapsibleField, DateField, EmailField, Field, GroupField, JSONField, NumberField, Payload, PointField, RadioField, RelationshipField, RichTextField, RowField, SanitizedConfig, SelectField, TabsField, TextField, TextareaField, UploadField } from 'payload';
1
+ import type { AggregatePaginateModel, IndexDefinition, IndexOptions, Model, PaginateModel, SchemaOptions } from 'mongoose';
2
+ import type { ArrayField, BlocksField, CheckboxField, CodeField, CollapsibleField, DateField, EmailField, Field, GroupField, JoinField, JSONField, NumberField, Payload, PayloadRequest, PointField, RadioField, RelationshipField, RichTextField, RowField, SanitizedConfig, SelectField, TabsField, TextareaField, TextField, UploadField } from 'payload';
3
3
  import type { BuildQueryArgs } from './queries/buildQuery.js';
4
- export interface CollectionModel extends Model<any>, PaginateModel<any> {
4
+ export interface CollectionModel extends Model<any>, PaginateModel<any>, AggregatePaginateModel<any> {
5
5
  /** buildQuery is used to transform payload's where operator into what can be used by mongoose (e.g. id => _id) */
6
6
  buildQuery: (args: BuildQueryArgs) => Promise<Record<string, unknown>>;
7
7
  }
@@ -40,13 +40,14 @@ export type FieldGeneratorFunction<TSchema, TField extends Field> = (args: Field
40
40
  */
41
41
  export type FieldToSchemaMap<TSchema> = {
42
42
  array: FieldGeneratorFunction<TSchema, ArrayField>;
43
- blocks: FieldGeneratorFunction<TSchema, BlockField>;
43
+ blocks: FieldGeneratorFunction<TSchema, BlocksField>;
44
44
  checkbox: FieldGeneratorFunction<TSchema, CheckboxField>;
45
45
  code: FieldGeneratorFunction<TSchema, CodeField>;
46
46
  collapsible: FieldGeneratorFunction<TSchema, CollapsibleField>;
47
47
  date: FieldGeneratorFunction<TSchema, DateField>;
48
48
  email: FieldGeneratorFunction<TSchema, EmailField>;
49
49
  group: FieldGeneratorFunction<TSchema, GroupField>;
50
+ join: FieldGeneratorFunction<TSchema, JoinField>;
50
51
  json: FieldGeneratorFunction<TSchema, JSONField>;
51
52
  number: FieldGeneratorFunction<TSchema, NumberField>;
52
53
  point: FieldGeneratorFunction<TSchema, PointField>;
@@ -62,8 +63,10 @@ export type FieldToSchemaMap<TSchema> = {
62
63
  };
63
64
  export type MigrateUpArgs = {
64
65
  payload: Payload;
66
+ req: PayloadRequest;
65
67
  };
66
68
  export type MigrateDownArgs = {
67
69
  payload: Payload;
70
+ req: PayloadRequest;
68
71
  };
69
72
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,KAAK,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAClG,OAAO,KAAK,EACV,UAAU,EACV,UAAU,EACV,aAAa,EACb,SAAS,EACT,gBAAgB,EAChB,SAAS,EACT,UAAU,EACV,KAAK,EACL,UAAU,EACV,SAAS,EACT,WAAW,EACX,OAAO,EACP,UAAU,EACV,UAAU,EACV,iBAAiB,EACjB,aAAa,EACb,QAAQ,EACR,eAAe,EACf,WAAW,EACX,SAAS,EACT,SAAS,EACT,aAAa,EACb,WAAW,EACZ,MAAM,SAAS,CAAA;AAEhB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AAE7D,MAAM,WAAW,eAAgB,SAAQ,KAAK,CAAC,GAAG,CAAC,EAAE,aAAa,CAAC,GAAG,CAAC;IACrE,kHAAkH;IAClH,UAAU,EAAE,CAAC,IAAI,EAAE,cAAc,KAAK,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAA;CACvE;AAED,MAAM,WAAW,mBAAoB,SAAQ,eAAe;IAC1D,uBAAuB,EAAE,IAAI,CAAA;IAC7B,kBAAkB,EAAE,MAAM,CAAA;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esContent":["import type { IndexDefinition, IndexOptions, Model, PaginateModel, SchemaOptions } from 'mongoose'\nimport type {\n ArrayField,\n BlockField,\n CheckboxField,\n CodeField,\n CollapsibleField,\n DateField,\n EmailField,\n Field,\n GroupField,\n JSONField,\n NumberField,\n Payload,\n PointField,\n RadioField,\n RelationshipField,\n RichTextField,\n RowField,\n SanitizedConfig,\n SelectField,\n TabsField,\n TextField,\n TextareaField,\n UploadField,\n} from 'payload'\n\nimport type { BuildQueryArgs } from './queries/buildQuery.js'\n\nexport interface CollectionModel extends Model<any>, PaginateModel<any> {\n /** buildQuery is used to transform payload's where operator into what can be used by mongoose (e.g. id => _id) */\n buildQuery: (args: BuildQueryArgs) => Promise<Record<string, unknown>> // TODO: Delete this\n}\n\nexport interface AuthCollectionModel extends CollectionModel {\n resetPasswordExpiration: Date\n resetPasswordToken: string\n}\n\nexport type TypeOfIndex = {\n fields: IndexDefinition\n options?: IndexOptions\n}\n\nexport interface GlobalModel extends Model<Document> {\n buildQuery: (query: unknown, locale?: string) => Promise<Record<string, unknown>>\n}\n\nexport type BuildSchema<TSchema> = (args: {\n config: SanitizedConfig\n fields: Field[]\n options: BuildSchemaOptions\n}) => TSchema\n\nexport type BuildSchemaOptions = {\n allowIDField?: boolean\n disableUnique?: boolean\n draftsEnabled?: boolean\n indexSortableFields?: boolean\n options?: SchemaOptions\n}\n\nexport type FieldGenerator<TSchema, TField> = {\n config: SanitizedConfig\n field: TField\n options: BuildSchemaOptions\n schema: TSchema\n}\n\n/**\n * Field config types that need representation in the database\n */\ntype FieldType =\n | 'array'\n | 'blocks'\n | 'checkbox'\n | 'code'\n | 'collapsible'\n | 'date'\n | 'email'\n | 'group'\n | 'json'\n | 'number'\n | 'point'\n | 'radio'\n | 'relationship'\n | 'richText'\n | 'row'\n | 'select'\n | 'tabs'\n | 'text'\n | 'textarea'\n | 'upload'\n\nexport type FieldGeneratorFunction<TSchema, TField extends Field> = (\n args: FieldGenerator<TSchema, TField>,\n) => void\n\n/**\n * Object mapping types to a schema based on TSchema\n */\nexport type FieldToSchemaMap<TSchema> = {\n array: FieldGeneratorFunction<TSchema, ArrayField>\n blocks: FieldGeneratorFunction<TSchema, BlockField>\n checkbox: FieldGeneratorFunction<TSchema, CheckboxField>\n code: FieldGeneratorFunction<TSchema, CodeField>\n collapsible: FieldGeneratorFunction<TSchema, CollapsibleField>\n date: FieldGeneratorFunction<TSchema, DateField>\n email: FieldGeneratorFunction<TSchema, EmailField>\n group: FieldGeneratorFunction<TSchema, GroupField>\n json: FieldGeneratorFunction<TSchema, JSONField>\n number: FieldGeneratorFunction<TSchema, NumberField>\n point: FieldGeneratorFunction<TSchema, PointField>\n radio: FieldGeneratorFunction<TSchema, RadioField>\n relationship: FieldGeneratorFunction<TSchema, RelationshipField>\n richText: FieldGeneratorFunction<TSchema, RichTextField>\n row: FieldGeneratorFunction<TSchema, RowField>\n select: FieldGeneratorFunction<TSchema, SelectField>\n tabs: FieldGeneratorFunction<TSchema, TabsField>\n text: FieldGeneratorFunction<TSchema, TextField>\n textarea: FieldGeneratorFunction<TSchema, TextareaField>\n upload: FieldGeneratorFunction<TSchema, UploadField>\n}\n\nexport type MigrateUpArgs = { payload: Payload }\nexport type MigrateDownArgs = { payload: Payload }\n"],"names":[],"mappings":"AA6HA,WAAkD"}
1
+ {"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type {\n AggregatePaginateModel,\n IndexDefinition,\n IndexOptions,\n Model,\n PaginateModel,\n SchemaOptions,\n} from 'mongoose'\nimport type {\n ArrayField,\n BlocksField,\n CheckboxField,\n CodeField,\n CollapsibleField,\n DateField,\n EmailField,\n Field,\n GroupField,\n JoinField,\n JSONField,\n NumberField,\n Payload,\n PayloadRequest,\n PointField,\n RadioField,\n RelationshipField,\n RichTextField,\n RowField,\n SanitizedConfig,\n SelectField,\n TabsField,\n TextareaField,\n TextField,\n UploadField,\n} from 'payload'\n\nimport type { BuildQueryArgs } from './queries/buildQuery.js'\n\nexport interface CollectionModel\n extends Model<any>,\n PaginateModel<any>,\n AggregatePaginateModel<any> {\n /** buildQuery is used to transform payload's where operator into what can be used by mongoose (e.g. id => _id) */\n buildQuery: (args: BuildQueryArgs) => Promise<Record<string, unknown>> // TODO: Delete this\n}\n\nexport interface AuthCollectionModel extends CollectionModel {\n resetPasswordExpiration: Date\n resetPasswordToken: string\n}\n\nexport type TypeOfIndex = {\n fields: IndexDefinition\n options?: IndexOptions\n}\n\nexport interface GlobalModel extends Model<Document> {\n buildQuery: (query: unknown, locale?: string) => Promise<Record<string, unknown>>\n}\n\nexport type BuildSchema<TSchema> = (args: {\n config: SanitizedConfig\n fields: Field[]\n options: BuildSchemaOptions\n}) => TSchema\n\nexport type BuildSchemaOptions = {\n allowIDField?: boolean\n disableUnique?: boolean\n draftsEnabled?: boolean\n indexSortableFields?: boolean\n options?: SchemaOptions\n}\n\nexport type FieldGenerator<TSchema, TField> = {\n config: SanitizedConfig\n field: TField\n options: BuildSchemaOptions\n schema: TSchema\n}\n\nexport type FieldGeneratorFunction<TSchema, TField extends Field> = (\n args: FieldGenerator<TSchema, TField>,\n) => void\n\n/**\n * Object mapping types to a schema based on TSchema\n */\nexport type FieldToSchemaMap<TSchema> = {\n array: FieldGeneratorFunction<TSchema, ArrayField>\n blocks: FieldGeneratorFunction<TSchema, BlocksField>\n checkbox: FieldGeneratorFunction<TSchema, CheckboxField>\n code: FieldGeneratorFunction<TSchema, CodeField>\n collapsible: FieldGeneratorFunction<TSchema, CollapsibleField>\n date: FieldGeneratorFunction<TSchema, DateField>\n email: FieldGeneratorFunction<TSchema, EmailField>\n group: FieldGeneratorFunction<TSchema, GroupField>\n join: FieldGeneratorFunction<TSchema, JoinField>\n json: FieldGeneratorFunction<TSchema, JSONField>\n number: FieldGeneratorFunction<TSchema, NumberField>\n point: FieldGeneratorFunction<TSchema, PointField>\n radio: FieldGeneratorFunction<TSchema, RadioField>\n relationship: FieldGeneratorFunction<TSchema, RelationshipField>\n richText: FieldGeneratorFunction<TSchema, RichTextField>\n row: FieldGeneratorFunction<TSchema, RowField>\n select: FieldGeneratorFunction<TSchema, SelectField>\n tabs: FieldGeneratorFunction<TSchema, TabsField>\n text: FieldGeneratorFunction<TSchema, TextField>\n textarea: FieldGeneratorFunction<TSchema, TextareaField>\n upload: FieldGeneratorFunction<TSchema, UploadField>\n}\n\nexport type MigrateUpArgs = { payload: Payload; req: PayloadRequest }\nexport type MigrateDownArgs = { payload: Payload; req: PayloadRequest }\n"],"names":[],"mappings":"AAiHA,WAAuE"}
@@ -1 +1 @@
1
- {"version":3,"file":"updateGlobal.d.ts","sourceRoot":"","sources":["../src/updateGlobal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAkB,YAAY,EAAE,MAAM,SAAS,CAAA;AAO3D,eAAO,MAAM,YAAY,EAAE,YAqB1B,CAAA"}
1
+ {"version":3,"file":"updateGlobal.d.ts","sourceRoot":"","sources":["../src/updateGlobal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAkB,YAAY,EAAE,MAAM,SAAS,CAAA;AAQ3D,eAAO,MAAM,YAAY,EAAE,YA4B1B,CAAA"}
@@ -1,4 +1,5 @@
1
- import sanitizeInternalFields from './utilities/sanitizeInternalFields.js';
1
+ import { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js';
2
+ import { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.js';
2
3
  import { withSession } from './withSession.js';
3
4
  export const updateGlobal = async function updateGlobal({ slug, data, req = {} }) {
4
5
  const Model = this.globals;
@@ -8,9 +9,14 @@ export const updateGlobal = async function updateGlobal({ slug, data, req = {} }
8
9
  new: true
9
10
  };
10
11
  let result;
12
+ const sanitizedData = sanitizeRelationshipIDs({
13
+ config: this.payload.config,
14
+ data,
15
+ fields: this.payload.config.globals.find((global)=>global.slug === slug).fields
16
+ });
11
17
  result = await Model.findOneAndUpdate({
12
18
  globalType: slug
13
- }, data, options);
19
+ }, sanitizedData, options);
14
20
  result = JSON.parse(JSON.stringify(result));
15
21
  // custom id type reset
16
22
  result.id = result._id;
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/updateGlobal.ts"],"sourcesContent":["import type { PayloadRequest, UpdateGlobal } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport sanitizeInternalFields from './utilities/sanitizeInternalFields.js'\nimport { withSession } from './withSession.js'\n\nexport const updateGlobal: UpdateGlobal = async function updateGlobal(\n this: MongooseAdapter,\n { slug, data, req = {} as PayloadRequest },\n) {\n const Model = this.globals\n const options = {\n ...(await withSession(this, req)),\n lean: true,\n new: true,\n }\n\n let result\n result = await Model.findOneAndUpdate({ globalType: slug }, data, options)\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":["sanitizeInternalFields","withSession","updateGlobal","slug","data","req","Model","globals","options","lean","new","result","findOneAndUpdate","globalType","JSON","parse","stringify","id","_id"],"mappings":"AAIA,OAAOA,4BAA4B,wCAAuC;AAC1E,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,eAA6B,eAAeA,aAEvD,EAAEC,IAAI,EAAEC,IAAI,EAAEC,MAAM,CAAC,CAAmB,EAAE;IAE1C,MAAMC,QAAQ,IAAI,CAACC,OAAO;IAC1B,MAAMC,UAAU;QACd,GAAI,MAAMP,YAAY,IAAI,EAAEI,IAAI;QAChCI,MAAM;QACNC,KAAK;IACP;IAEA,IAAIC;IACJA,SAAS,MAAML,MAAMM,gBAAgB,CAAC;QAAEC,YAAYV;IAAK,GAAGC,MAAMI;IAElEG,SAASG,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACL;IAEnC,uBAAuB;IACvBA,OAAOM,EAAE,GAAGN,OAAOO,GAAG;IACtBP,SAASX,uBAAuBW;IAEhC,OAAOA;AACT,EAAC"}
1
+ {"version":3,"sources":["../src/updateGlobal.ts"],"sourcesContent":["import type { PayloadRequest, UpdateGlobal } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js'\nimport { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.js'\nimport { withSession } from './withSession.js'\n\nexport const updateGlobal: UpdateGlobal = async function updateGlobal(\n this: MongooseAdapter,\n { slug, data, req = {} as PayloadRequest },\n) {\n const Model = this.globals\n const options = {\n ...(await withSession(this, req)),\n lean: true,\n new: true,\n }\n\n let result\n\n const sanitizedData = sanitizeRelationshipIDs({\n config: this.payload.config,\n data,\n fields: this.payload.config.globals.find((global) => global.slug === slug).fields,\n })\n\n result = await Model.findOneAndUpdate({ globalType: slug }, sanitizedData, options)\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":["sanitizeInternalFields","sanitizeRelationshipIDs","withSession","updateGlobal","slug","data","req","Model","globals","options","lean","new","result","sanitizedData","config","payload","fields","find","global","findOneAndUpdate","globalType","JSON","parse","stringify","id","_id"],"mappings":"AAIA,SAASA,sBAAsB,QAAQ,wCAAuC;AAC9E,SAASC,uBAAuB,QAAQ,yCAAwC;AAChF,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,eAA6B,eAAeA,aAEvD,EAAEC,IAAI,EAAEC,IAAI,EAAEC,MAAM,CAAC,CAAmB,EAAE;IAE1C,MAAMC,QAAQ,IAAI,CAACC,OAAO;IAC1B,MAAMC,UAAU;QACd,GAAI,MAAMP,YAAY,IAAI,EAAEI,IAAI;QAChCI,MAAM;QACNC,KAAK;IACP;IAEA,IAAIC;IAEJ,MAAMC,gBAAgBZ,wBAAwB;QAC5Ca,QAAQ,IAAI,CAACC,OAAO,CAACD,MAAM;QAC3BT;QACAW,QAAQ,IAAI,CAACD,OAAO,CAACD,MAAM,CAACN,OAAO,CAACS,IAAI,CAAC,CAACC,SAAWA,OAAOd,IAAI,KAAKA,MAAMY,MAAM;IACnF;IAEAJ,SAAS,MAAML,MAAMY,gBAAgB,CAAC;QAAEC,YAAYhB;IAAK,GAAGS,eAAeJ;IAE3EG,SAASS,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACX;IAEnC,uBAAuB;IACvBA,OAAOY,EAAE,GAAGZ,OAAOa,GAAG;IACtBb,SAASZ,uBAAuBY;IAEhC,OAAOA;AACT,EAAC"}
@@ -1,4 +1,4 @@
1
- import type { TypeWithID, UpdateGlobalVersionArgs } from 'payload';
1
+ import { type TypeWithID, type UpdateGlobalVersionArgs } from 'payload';
2
2
  import type { MongooseAdapter } from './index.js';
3
- export declare function updateGlobalVersion<T extends TypeWithID>(this: MongooseAdapter, { id, global, locale, req, versionData, where, }: UpdateGlobalVersionArgs<T>): Promise<any>;
3
+ export declare function updateGlobalVersion<T extends TypeWithID>(this: MongooseAdapter, { id, global: globalSlug, locale, req, versionData, where, }: UpdateGlobalVersionArgs<T>): Promise<any>;
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,EAAkB,UAAU,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAA;AAElF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAIjD,wBAAsB,mBAAmB,CAAC,CAAC,SAAS,UAAU,EAC5D,IAAI,EAAE,eAAe,EACrB,EACE,EAAE,EACF,MAAM,EACN,MAAM,EACN,GAA0B,EAC1B,WAAW,EACX,KAAK,GACN,EAAE,uBAAuB,CAAC,CAAC,CAAC,gBA4B9B"}
1
+ {"version":3,"file":"updateGlobalVersion.d.ts","sourceRoot":"","sources":["../src/updateGlobalVersion.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,UAAU,EACf,KAAK,uBAAuB,EAC7B,MAAM,SAAS,CAAA;AAEhB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAKjD,wBAAsB,mBAAmB,CAAC,CAAC,SAAS,UAAU,EAC5D,IAAI,EAAE,eAAe,EACrB,EACE,EAAE,EACF,MAAM,EAAE,UAAU,EAClB,MAAM,EACN,GAA0B,EAC1B,WAAW,EACX,KAAK,GACN,EAAE,uBAAuB,CAAC,CAAC,CAAC,gBAqC9B"}
@@ -1,6 +1,8 @@
1
+ import { buildVersionGlobalFields } from 'payload';
2
+ import { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.js';
1
3
  import { withSession } from './withSession.js';
2
- export async function updateGlobalVersion({ id, global, locale, req = {}, versionData, where }) {
3
- const VersionModel = this.versions[global];
4
+ export async function updateGlobalVersion({ id, global: globalSlug, locale, req = {}, versionData, where }) {
5
+ const VersionModel = this.versions[globalSlug];
4
6
  const whereToUse = where || {
5
7
  id: {
6
8
  equals: id
@@ -16,7 +18,12 @@ export async function updateGlobalVersion({ id, global, locale, req = {}, versio
16
18
  payload: this.payload,
17
19
  where: whereToUse
18
20
  });
19
- const doc = await VersionModel.findOneAndUpdate(query, versionData, options);
21
+ const sanitizedData = sanitizeRelationshipIDs({
22
+ config: this.payload.config,
23
+ data: versionData,
24
+ fields: buildVersionGlobalFields(this.payload.config, this.payload.config.globals.find((global)=>global.slug === globalSlug))
25
+ });
26
+ const doc = await VersionModel.findOneAndUpdate(query, sanitizedData, options);
20
27
  const result = JSON.parse(JSON.stringify(doc));
21
28
  const verificationToken = doc._verificationToken;
22
29
  // custom id type reset
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/updateGlobalVersion.ts"],"sourcesContent":["import type { PayloadRequest, TypeWithID, UpdateGlobalVersionArgs } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { withSession } from './withSession.js'\n\nexport async function updateGlobalVersion<T extends TypeWithID>(\n this: MongooseAdapter,\n {\n id,\n global,\n locale,\n req = {} as PayloadRequest,\n versionData,\n where,\n }: UpdateGlobalVersionArgs<T>,\n) {\n const VersionModel = this.versions[global]\n const whereToUse = where || { id: { equals: id } }\n const options = {\n ...(await withSession(this, req)),\n lean: true,\n new: true,\n }\n\n const query = await VersionModel.buildQuery({\n locale,\n payload: this.payload,\n where: whereToUse,\n })\n\n const doc = await VersionModel.findOneAndUpdate(query, versionData, options)\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":["withSession","updateGlobalVersion","id","global","locale","req","versionData","where","VersionModel","versions","whereToUse","equals","options","lean","new","query","buildQuery","payload","doc","findOneAndUpdate","result","JSON","parse","stringify","verificationToken","_verificationToken","_id"],"mappings":"AAIA,SAASA,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,eAAeC,oBAEpB,EACEC,EAAE,EACFC,MAAM,EACNC,MAAM,EACNC,MAAM,CAAC,CAAmB,EAC1BC,WAAW,EACXC,KAAK,EACsB;IAE7B,MAAMC,eAAe,IAAI,CAACC,QAAQ,CAACN,OAAO;IAC1C,MAAMO,aAAaH,SAAS;QAAEL,IAAI;YAAES,QAAQT;QAAG;IAAE;IACjD,MAAMU,UAAU;QACd,GAAI,MAAMZ,YAAY,IAAI,EAAEK,IAAI;QAChCQ,MAAM;QACNC,KAAK;IACP;IAEA,MAAMC,QAAQ,MAAMP,aAAaQ,UAAU,CAAC;QAC1CZ;QACAa,SAAS,IAAI,CAACA,OAAO;QACrBV,OAAOG;IACT;IAEA,MAAMQ,MAAM,MAAMV,aAAaW,gBAAgB,CAACJ,OAAOT,aAAaM;IAEpE,MAAMQ,SAASC,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACL;IAEzC,MAAMM,oBAAoBN,IAAIO,kBAAkB;IAEhD,uBAAuB;IACvBL,OAAOlB,EAAE,GAAGkB,OAAOM,GAAG;IACtB,IAAIF,mBAAmB;QACrBJ,OAAOK,kBAAkB,GAAGD;IAC9B;IACA,OAAOJ;AACT"}
1
+ {"version":3,"sources":["../src/updateGlobalVersion.ts"],"sourcesContent":["import {\n buildVersionGlobalFields,\n type PayloadRequest,\n type TypeWithID,\n type UpdateGlobalVersionArgs,\n} from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.js'\nimport { withSession } from './withSession.js'\n\nexport async function updateGlobalVersion<T extends TypeWithID>(\n this: MongooseAdapter,\n {\n id,\n global: globalSlug,\n locale,\n req = {} as PayloadRequest,\n versionData,\n where,\n }: UpdateGlobalVersionArgs<T>,\n) {\n const VersionModel = this.versions[globalSlug]\n const whereToUse = where || { id: { equals: id } }\n const options = {\n ...(await withSession(this, req)),\n lean: true,\n new: true,\n }\n\n const query = await VersionModel.buildQuery({\n locale,\n payload: this.payload,\n where: whereToUse,\n })\n\n const sanitizedData = sanitizeRelationshipIDs({\n config: this.payload.config,\n data: versionData,\n fields: buildVersionGlobalFields(\n this.payload.config,\n this.payload.config.globals.find((global) => global.slug === globalSlug),\n ),\n })\n\n const doc = await VersionModel.findOneAndUpdate(query, sanitizedData, options)\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","sanitizeRelationshipIDs","withSession","updateGlobalVersion","id","global","globalSlug","locale","req","versionData","where","VersionModel","versions","whereToUse","equals","options","lean","new","query","buildQuery","payload","sanitizedData","config","data","fields","globals","find","slug","doc","findOneAndUpdate","result","JSON","parse","stringify","verificationToken","_verificationToken","_id"],"mappings":"AAAA,SACEA,wBAAwB,QAInB,UAAS;AAIhB,SAASC,uBAAuB,QAAQ,yCAAwC;AAChF,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,eAAeC,oBAEpB,EACEC,EAAE,EACFC,QAAQC,UAAU,EAClBC,MAAM,EACNC,MAAM,CAAC,CAAmB,EAC1BC,WAAW,EACXC,KAAK,EACsB;IAE7B,MAAMC,eAAe,IAAI,CAACC,QAAQ,CAACN,WAAW;IAC9C,MAAMO,aAAaH,SAAS;QAAEN,IAAI;YAAEU,QAAQV;QAAG;IAAE;IACjD,MAAMW,UAAU;QACd,GAAI,MAAMb,YAAY,IAAI,EAAEM,IAAI;QAChCQ,MAAM;QACNC,KAAK;IACP;IAEA,MAAMC,QAAQ,MAAMP,aAAaQ,UAAU,CAAC;QAC1CZ;QACAa,SAAS,IAAI,CAACA,OAAO;QACrBV,OAAOG;IACT;IAEA,MAAMQ,gBAAgBpB,wBAAwB;QAC5CqB,QAAQ,IAAI,CAACF,OAAO,CAACE,MAAM;QAC3BC,MAAMd;QACNe,QAAQxB,yBACN,IAAI,CAACoB,OAAO,CAACE,MAAM,EACnB,IAAI,CAACF,OAAO,CAACE,MAAM,CAACG,OAAO,CAACC,IAAI,CAAC,CAACrB,SAAWA,OAAOsB,IAAI,KAAKrB;IAEjE;IAEA,MAAMsB,MAAM,MAAMjB,aAAakB,gBAAgB,CAACX,OAAOG,eAAeN;IAEtE,MAAMe,SAASC,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACL;IAEzC,MAAMM,oBAAoBN,IAAIO,kBAAkB;IAEhD,uBAAuB;IACvBL,OAAO1B,EAAE,GAAG0B,OAAOM,GAAG;IACtB,IAAIF,mBAAmB;QACrBJ,OAAOK,kBAAkB,GAAGD;IAC9B;IACA,OAAOJ;AACT"}
@@ -1 +1 @@
1
- {"version":3,"file":"updateOne.d.ts","sourceRoot":"","sources":["../src/updateOne.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAkB,SAAS,EAAE,MAAM,SAAS,CAAA;AAQxD,eAAO,MAAM,SAAS,EAAE,SA+BvB,CAAA"}
1
+ {"version":3,"file":"updateOne.d.ts","sourceRoot":"","sources":["../src/updateOne.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAkB,SAAS,EAAE,MAAM,SAAS,CAAA;AASxD,eAAO,MAAM,SAAS,EAAE,SA8CvB,CAAA"}
package/dist/updateOne.js CHANGED
@@ -1,7 +1,8 @@
1
1
  import { handleError } from './utilities/handleError.js';
2
- import sanitizeInternalFields from './utilities/sanitizeInternalFields.js';
2
+ import { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js';
3
+ import { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.js';
3
4
  import { withSession } from './withSession.js';
4
- export const updateOne = async function updateOne({ id, collection, data, locale, req = {}, where: whereArg }) {
5
+ export const updateOne = async function updateOne({ id, collection, data, locale, options: optionsArgs = {}, req = {}, where: whereArg }) {
5
6
  const where = id ? {
6
7
  id: {
7
8
  equals: id
@@ -9,6 +10,7 @@ export const updateOne = async function updateOne({ id, collection, data, locale
9
10
  } : whereArg;
10
11
  const Model = this.collections[collection];
11
12
  const options = {
13
+ ...optionsArgs,
12
14
  ...await withSession(this, req),
13
15
  lean: true,
14
16
  new: true
@@ -19,8 +21,13 @@ export const updateOne = async function updateOne({ id, collection, data, locale
19
21
  where
20
22
  });
21
23
  let result;
24
+ const sanitizedData = sanitizeRelationshipIDs({
25
+ config: this.payload.config,
26
+ data,
27
+ fields: this.payload.collections[collection].config.fields
28
+ });
22
29
  try {
23
- result = await Model.findOneAndUpdate(query, data, options);
30
+ result = await Model.findOneAndUpdate(query, sanitizedData, options);
24
31
  } catch (error) {
25
32
  handleError({
26
33
  collection,
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/updateOne.ts"],"sourcesContent":["import type { PayloadRequest, UpdateOne } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { handleError } from './utilities/handleError.js'\nimport sanitizeInternalFields from './utilities/sanitizeInternalFields.js'\nimport { withSession } from './withSession.js'\n\nexport const updateOne: UpdateOne = async function updateOne(\n this: MongooseAdapter,\n { id, collection, data, locale, req = {} as PayloadRequest, where: whereArg },\n) {\n const where = id ? { id: { equals: id } } : whereArg\n const Model = this.collections[collection]\n const options = {\n ...(await withSession(this, req)),\n lean: true,\n new: true,\n }\n\n const query = await Model.buildQuery({\n locale,\n payload: this.payload,\n where,\n })\n\n let result\n\n try {\n result = await Model.findOneAndUpdate(query, data, options)\n } catch (error) {\n handleError({ collection, error, req })\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":["handleError","sanitizeInternalFields","withSession","updateOne","id","collection","data","locale","req","where","whereArg","equals","Model","collections","options","lean","new","query","buildQuery","payload","result","findOneAndUpdate","error","JSON","parse","stringify","_id"],"mappings":"AAIA,SAASA,WAAW,QAAQ,6BAA4B;AACxD,OAAOC,4BAA4B,wCAAuC;AAC1E,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,YAAuB,eAAeA,UAEjD,EAAEC,EAAE,EAAEC,UAAU,EAAEC,IAAI,EAAEC,MAAM,EAAEC,MAAM,CAAC,CAAmB,EAAEC,OAAOC,QAAQ,EAAE;IAE7E,MAAMD,QAAQL,KAAK;QAAEA,IAAI;YAAEO,QAAQP;QAAG;IAAE,IAAIM;IAC5C,MAAME,QAAQ,IAAI,CAACC,WAAW,CAACR,WAAW;IAC1C,MAAMS,UAAU;QACd,GAAI,MAAMZ,YAAY,IAAI,EAAEM,IAAI;QAChCO,MAAM;QACNC,KAAK;IACP;IAEA,MAAMC,QAAQ,MAAML,MAAMM,UAAU,CAAC;QACnCX;QACAY,SAAS,IAAI,CAACA,OAAO;QACrBV;IACF;IAEA,IAAIW;IAEJ,IAAI;QACFA,SAAS,MAAMR,MAAMS,gBAAgB,CAACJ,OAAOX,MAAMQ;IACrD,EAAE,OAAOQ,OAAO;QACdtB,YAAY;YAAEK;YAAYiB;YAAOd;QAAI;IACvC;IAEAY,SAASG,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACL;IACnCA,OAAOhB,EAAE,GAAGgB,OAAOM,GAAG;IACtBN,SAASnB,uBAAuBmB;IAEhC,OAAOA;AACT,EAAC"}
1
+ {"version":3,"sources":["../src/updateOne.ts"],"sourcesContent":["import type { QueryOptions } from 'mongoose'\nimport type { PayloadRequest, UpdateOne } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { handleError } from './utilities/handleError.js'\nimport { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js'\nimport { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.js'\nimport { withSession } from './withSession.js'\n\nexport const updateOne: UpdateOne = async function updateOne(\n this: MongooseAdapter,\n {\n id,\n collection,\n data,\n locale,\n options: optionsArgs = {},\n req = {} as PayloadRequest,\n where: whereArg,\n },\n) {\n const where = id ? { id: { equals: id } } : whereArg\n const Model = this.collections[collection]\n const options: QueryOptions = {\n ...optionsArgs,\n ...(await withSession(this, req)),\n lean: true,\n new: true,\n }\n\n const query = await Model.buildQuery({\n locale,\n payload: this.payload,\n where,\n })\n\n let result\n\n const sanitizedData = sanitizeRelationshipIDs({\n config: this.payload.config,\n data,\n fields: this.payload.collections[collection].config.fields,\n })\n\n try {\n result = await Model.findOneAndUpdate(query, sanitizedData, options)\n } catch (error) {\n handleError({ collection, error, req })\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":["handleError","sanitizeInternalFields","sanitizeRelationshipIDs","withSession","updateOne","id","collection","data","locale","options","optionsArgs","req","where","whereArg","equals","Model","collections","lean","new","query","buildQuery","payload","result","sanitizedData","config","fields","findOneAndUpdate","error","JSON","parse","stringify","_id"],"mappings":"AAKA,SAASA,WAAW,QAAQ,6BAA4B;AACxD,SAASC,sBAAsB,QAAQ,wCAAuC;AAC9E,SAASC,uBAAuB,QAAQ,yCAAwC;AAChF,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,YAAuB,eAAeA,UAEjD,EACEC,EAAE,EACFC,UAAU,EACVC,IAAI,EACJC,MAAM,EACNC,SAASC,cAAc,CAAC,CAAC,EACzBC,MAAM,CAAC,CAAmB,EAC1BC,OAAOC,QAAQ,EAChB;IAED,MAAMD,QAAQP,KAAK;QAAEA,IAAI;YAAES,QAAQT;QAAG;IAAE,IAAIQ;IAC5C,MAAME,QAAQ,IAAI,CAACC,WAAW,CAACV,WAAW;IAC1C,MAAMG,UAAwB;QAC5B,GAAGC,WAAW;QACd,GAAI,MAAMP,YAAY,IAAI,EAAEQ,IAAI;QAChCM,MAAM;QACNC,KAAK;IACP;IAEA,MAAMC,QAAQ,MAAMJ,MAAMK,UAAU,CAAC;QACnCZ;QACAa,SAAS,IAAI,CAACA,OAAO;QACrBT;IACF;IAEA,IAAIU;IAEJ,MAAMC,gBAAgBrB,wBAAwB;QAC5CsB,QAAQ,IAAI,CAACH,OAAO,CAACG,MAAM;QAC3BjB;QACAkB,QAAQ,IAAI,CAACJ,OAAO,CAACL,WAAW,CAACV,WAAW,CAACkB,MAAM,CAACC,MAAM;IAC5D;IAEA,IAAI;QACFH,SAAS,MAAMP,MAAMW,gBAAgB,CAACP,OAAOI,eAAed;IAC9D,EAAE,OAAOkB,OAAO;QACd3B,YAAY;YAAEM;YAAYqB;YAAOhB;QAAI;IACvC;IAEAW,SAASM,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACR;IACnCA,OAAOjB,EAAE,GAAGiB,OAAOS,GAAG;IACtBT,SAASrB,uBAAuBqB;IAEhC,OAAOA;AACT,EAAC"}
@@ -1,3 +1,3 @@
1
- import type { UpdateVersion } from 'payload';
1
+ import { type UpdateVersion } from 'payload';
2
2
  export declare const updateVersion: UpdateVersion;
3
3
  //# sourceMappingURL=updateVersion.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"updateVersion.d.ts","sourceRoot":"","sources":["../src/updateVersion.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAkB,aAAa,EAAE,MAAM,SAAS,CAAA;AAM5D,eAAO,MAAM,aAAa,EAAE,aA8B3B,CAAA"}
1
+ {"version":3,"file":"updateVersion.d.ts","sourceRoot":"","sources":["../src/updateVersion.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqD,KAAK,aAAa,EAAE,MAAM,SAAS,CAAA;AAO/F,eAAO,MAAM,aAAa,EAAE,aAuC3B,CAAA"}
@@ -1,3 +1,5 @@
1
+ import { buildVersionCollectionFields } from 'payload';
2
+ import { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.js';
1
3
  import { withSession } from './withSession.js';
2
4
  export const updateVersion = async function updateVersion({ id, collection, locale, req = {}, versionData, where }) {
3
5
  const VersionModel = this.versions[collection];
@@ -16,7 +18,12 @@ export const updateVersion = async function updateVersion({ id, collection, loca
16
18
  payload: this.payload,
17
19
  where: whereToUse
18
20
  });
19
- const doc = await VersionModel.findOneAndUpdate(query, versionData, options);
21
+ const sanitizedData = sanitizeRelationshipIDs({
22
+ config: this.payload.config,
23
+ data: versionData,
24
+ fields: buildVersionCollectionFields(this.payload.config, this.payload.collections[collection].config)
25
+ });
26
+ const doc = await VersionModel.findOneAndUpdate(query, sanitizedData, options);
20
27
  const result = JSON.parse(JSON.stringify(doc));
21
28
  const verificationToken = doc._verificationToken;
22
29
  // custom id type reset
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/updateVersion.ts"],"sourcesContent":["import type { PayloadRequest, UpdateVersion } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { withSession } from './withSession.js'\n\nexport const updateVersion: UpdateVersion = async function updateVersion(\n this: MongooseAdapter,\n { id, collection, locale, req = {} as PayloadRequest, versionData, where },\n) {\n const VersionModel = this.versions[collection]\n const whereToUse = where || { id: { equals: id } }\n const options = {\n ...(await withSession(this, req)),\n lean: true,\n new: true,\n }\n\n const query = await VersionModel.buildQuery({\n locale,\n payload: this.payload,\n where: whereToUse,\n })\n\n const doc = await VersionModel.findOneAndUpdate(query, versionData, options)\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":["withSession","updateVersion","id","collection","locale","req","versionData","where","VersionModel","versions","whereToUse","equals","options","lean","new","query","buildQuery","payload","doc","findOneAndUpdate","result","JSON","parse","stringify","verificationToken","_verificationToken","_id"],"mappings":"AAIA,SAASA,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,gBAA+B,eAAeA,cAEzD,EAAEC,EAAE,EAAEC,UAAU,EAAEC,MAAM,EAAEC,MAAM,CAAC,CAAmB,EAAEC,WAAW,EAAEC,KAAK,EAAE;IAE1E,MAAMC,eAAe,IAAI,CAACC,QAAQ,CAACN,WAAW;IAC9C,MAAMO,aAAaH,SAAS;QAAEL,IAAI;YAAES,QAAQT;QAAG;IAAE;IACjD,MAAMU,UAAU;QACd,GAAI,MAAMZ,YAAY,IAAI,EAAEK,IAAI;QAChCQ,MAAM;QACNC,KAAK;IACP;IAEA,MAAMC,QAAQ,MAAMP,aAAaQ,UAAU,CAAC;QAC1CZ;QACAa,SAAS,IAAI,CAACA,OAAO;QACrBV,OAAOG;IACT;IAEA,MAAMQ,MAAM,MAAMV,aAAaW,gBAAgB,CAACJ,OAAOT,aAAaM;IAEpE,MAAMQ,SAASC,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACL;IAEzC,MAAMM,oBAAoBN,IAAIO,kBAAkB;IAEhD,uBAAuB;IACvBL,OAAOlB,EAAE,GAAGkB,OAAOM,GAAG;IACtB,IAAIF,mBAAmB;QACrBJ,OAAOK,kBAAkB,GAAGD;IAC9B;IACA,OAAOJ;AACT,EAAC"}
1
+ {"version":3,"sources":["../src/updateVersion.ts"],"sourcesContent":["import { buildVersionCollectionFields, type PayloadRequest, type UpdateVersion } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.js'\nimport { withSession } from './withSession.js'\n\nexport const updateVersion: UpdateVersion = async function updateVersion(\n this: MongooseAdapter,\n { id, collection, locale, req = {} as PayloadRequest, versionData, where },\n) {\n const VersionModel = this.versions[collection]\n const whereToUse = where || { id: { equals: id } }\n const options = {\n ...(await withSession(this, req)),\n lean: true,\n new: true,\n }\n\n const query = await VersionModel.buildQuery({\n locale,\n payload: this.payload,\n where: whereToUse,\n })\n\n const sanitizedData = sanitizeRelationshipIDs({\n config: this.payload.config,\n data: versionData,\n fields: buildVersionCollectionFields(\n this.payload.config,\n this.payload.collections[collection].config,\n ),\n })\n\n const doc = await VersionModel.findOneAndUpdate(query, sanitizedData, options)\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","sanitizeRelationshipIDs","withSession","updateVersion","id","collection","locale","req","versionData","where","VersionModel","versions","whereToUse","equals","options","lean","new","query","buildQuery","payload","sanitizedData","config","data","fields","collections","doc","findOneAndUpdate","result","JSON","parse","stringify","verificationToken","_verificationToken","_id"],"mappings":"AAAA,SAASA,4BAA4B,QAAiD,UAAS;AAI/F,SAASC,uBAAuB,QAAQ,yCAAwC;AAChF,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,gBAA+B,eAAeA,cAEzD,EAAEC,EAAE,EAAEC,UAAU,EAAEC,MAAM,EAAEC,MAAM,CAAC,CAAmB,EAAEC,WAAW,EAAEC,KAAK,EAAE;IAE1E,MAAMC,eAAe,IAAI,CAACC,QAAQ,CAACN,WAAW;IAC9C,MAAMO,aAAaH,SAAS;QAAEL,IAAI;YAAES,QAAQT;QAAG;IAAE;IACjD,MAAMU,UAAU;QACd,GAAI,MAAMZ,YAAY,IAAI,EAAEK,IAAI;QAChCQ,MAAM;QACNC,KAAK;IACP;IAEA,MAAMC,QAAQ,MAAMP,aAAaQ,UAAU,CAAC;QAC1CZ;QACAa,SAAS,IAAI,CAACA,OAAO;QACrBV,OAAOG;IACT;IAEA,MAAMQ,gBAAgBnB,wBAAwB;QAC5CoB,QAAQ,IAAI,CAACF,OAAO,CAACE,MAAM;QAC3BC,MAAMd;QACNe,QAAQvB,6BACN,IAAI,CAACmB,OAAO,CAACE,MAAM,EACnB,IAAI,CAACF,OAAO,CAACK,WAAW,CAACnB,WAAW,CAACgB,MAAM;IAE/C;IAEA,MAAMI,MAAM,MAAMf,aAAagB,gBAAgB,CAACT,OAAOG,eAAeN;IAEtE,MAAMa,SAASC,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACL;IAEzC,MAAMM,oBAAoBN,IAAIO,kBAAkB;IAEhD,uBAAuB;IACvBL,OAAOvB,EAAE,GAAGuB,OAAOM,GAAG;IACtB,IAAIF,mBAAmB;QACrBJ,OAAOK,kBAAkB,GAAGD;IAC9B;IACA,OAAOJ;AACT,EAAC"}
@@ -0,0 +1,3 @@
1
+ import type { Upsert } from 'payload';
2
+ export declare const upsert: Upsert;
3
+ //# sourceMappingURL=upsert.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"upsert.d.ts","sourceRoot":"","sources":["../src/upsert.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAkB,MAAM,EAAE,MAAM,SAAS,CAAA;AAIrD,eAAO,MAAM,MAAM,EAAE,MAKpB,CAAA"}
package/dist/upsert.js ADDED
@@ -0,0 +1,14 @@
1
+ export const upsert = async function upsert({ collection, data, locale, req = {}, where }) {
2
+ return this.updateOne({
3
+ collection,
4
+ data,
5
+ locale,
6
+ options: {
7
+ upsert: true
8
+ },
9
+ req,
10
+ where
11
+ });
12
+ };
13
+
14
+ //# sourceMappingURL=upsert.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/upsert.ts"],"sourcesContent":["import type { PayloadRequest, Upsert } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nexport const upsert: Upsert = async function upsert(\n this: MongooseAdapter,\n { collection, data, locale, req = {} as PayloadRequest, where },\n) {\n return this.updateOne({ collection, data, locale, options: { upsert: true }, req, where })\n}\n"],"names":["upsert","collection","data","locale","req","where","updateOne","options"],"mappings":"AAIA,OAAO,MAAMA,SAAiB,eAAeA,OAE3C,EAAEC,UAAU,EAAEC,IAAI,EAAEC,MAAM,EAAEC,MAAM,CAAC,CAAmB,EAAEC,KAAK,EAAE;IAE/D,OAAO,IAAI,CAACC,SAAS,CAAC;QAAEL;QAAYC;QAAMC;QAAQI,SAAS;YAAEP,QAAQ;QAAK;QAAGI;QAAKC;IAAM;AAC1F,EAAC"}
@@ -0,0 +1,15 @@
1
+ import type { PipelineStage } from 'mongoose';
2
+ import type { CollectionSlug, JoinQuery, SanitizedCollectionConfig, Where } from 'payload';
3
+ import type { MongooseAdapter } from '../index.js';
4
+ type BuildJoinAggregationArgs = {
5
+ adapter: MongooseAdapter;
6
+ collection: CollectionSlug;
7
+ collectionConfig: SanitizedCollectionConfig;
8
+ joins: JoinQuery;
9
+ limit?: number;
10
+ locale: string;
11
+ query?: Where;
12
+ };
13
+ export declare const buildJoinAggregation: ({ adapter, collection, collectionConfig, joins, limit, locale, query, }: BuildJoinAggregationArgs) => Promise<PipelineStage[] | undefined>;
14
+ export {};
15
+ //# sourceMappingURL=buildJoinAggregation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"buildJoinAggregation.d.ts","sourceRoot":"","sources":["../../src/utilities/buildJoinAggregation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAC7C,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,yBAAyB,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAE1F,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAIlD,KAAK,wBAAwB,GAAG;IAC9B,OAAO,EAAE,eAAe,CAAA;IACxB,UAAU,EAAE,cAAc,CAAA;IAC1B,gBAAgB,EAAE,yBAAyB,CAAA;IAC3C,KAAK,EAAE,SAAS,CAAA;IAEhB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,MAAM,CAAA;IAEd,KAAK,CAAC,EAAE,KAAK,CAAA;CACd,CAAA;AAED,eAAO,MAAM,oBAAoB,4EAQ9B,wBAAwB,KAAG,OAAO,CAAC,aAAa,EAAE,GAAG,SAAS,CAmJhE,CAAA"}
@@ -0,0 +1,148 @@
1
+ import { buildSortParam } from '../queries/buildSortParam.js';
2
+ export const buildJoinAggregation = async ({ adapter, collection, collectionConfig, joins, limit, locale, query })=>{
3
+ if (Object.keys(collectionConfig.joins).length === 0 || joins === false) {
4
+ return;
5
+ }
6
+ const joinConfig = adapter.payload.collections[collection].config.joins;
7
+ const aggregate = [
8
+ {
9
+ $sort: {
10
+ createdAt: -1
11
+ }
12
+ }
13
+ ];
14
+ if (query) {
15
+ aggregate.push({
16
+ $match: query
17
+ });
18
+ }
19
+ if (limit) {
20
+ aggregate.push({
21
+ $limit: limit
22
+ });
23
+ }
24
+ for (const slug of Object.keys(joinConfig)){
25
+ for (const join of joinConfig[slug]){
26
+ const joinModel = adapter.collections[join.field.collection];
27
+ const { limit: limitJoin = 10, sort: sortJoin, where: whereJoin } = joins?.[join.schemaPath] || {};
28
+ const sort = buildSortParam({
29
+ config: adapter.payload.config,
30
+ fields: adapter.payload.collections[slug].config.fields,
31
+ locale,
32
+ sort: sortJoin || collectionConfig.defaultSort,
33
+ timestamps: true
34
+ });
35
+ const sortProperty = Object.keys(sort)[0];
36
+ const sortDirection = sort[sortProperty] === 'asc' ? 1 : -1;
37
+ const $match = await joinModel.buildQuery({
38
+ locale,
39
+ payload: adapter.payload,
40
+ where: whereJoin
41
+ });
42
+ const pipeline = [
43
+ {
44
+ $match
45
+ },
46
+ {
47
+ $sort: {
48
+ [sortProperty]: sortDirection
49
+ }
50
+ }
51
+ ];
52
+ if (limitJoin > 0) {
53
+ pipeline.push({
54
+ $limit: limitJoin + 1
55
+ });
56
+ }
57
+ if (adapter.payload.config.localization && locale === 'all') {
58
+ adapter.payload.config.localization.localeCodes.forEach((code)=>{
59
+ const as = `${join.schemaPath}${code}`;
60
+ aggregate.push({
61
+ $lookup: {
62
+ as: `${as}.docs`,
63
+ foreignField: `${join.field.on}${code}`,
64
+ from: slug,
65
+ localField: '_id',
66
+ pipeline
67
+ }
68
+ }, {
69
+ $addFields: {
70
+ [`${as}.docs`]: {
71
+ $map: {
72
+ as: 'doc',
73
+ in: '$$doc._id',
74
+ input: `$${as}.docs`
75
+ }
76
+ },
77
+ [`${as}.hasNextPage`]: limitJoin ? {
78
+ $gt: [
79
+ {
80
+ $size: `$${as}.docs`
81
+ },
82
+ limitJoin
83
+ ]
84
+ } : false
85
+ }
86
+ });
87
+ if (limitJoin > 0) {
88
+ aggregate.push({
89
+ $addFields: {
90
+ [`${as}.docs`]: {
91
+ $slice: [
92
+ `$${as}.docs`,
93
+ limitJoin
94
+ ]
95
+ }
96
+ }
97
+ });
98
+ }
99
+ });
100
+ } else {
101
+ const localeSuffix = join.field.localized && adapter.payload.config.localization && locale ? `.${locale}` : '';
102
+ const as = `${join.schemaPath}${localeSuffix}`;
103
+ aggregate.push({
104
+ $lookup: {
105
+ as: `${as}.docs`,
106
+ foreignField: `${join.field.on}${localeSuffix}`,
107
+ from: slug,
108
+ localField: '_id',
109
+ pipeline
110
+ }
111
+ }, {
112
+ $addFields: {
113
+ [`${as}.docs`]: {
114
+ $map: {
115
+ as: 'doc',
116
+ in: '$$doc._id',
117
+ input: `$${as}.docs`
118
+ }
119
+ },
120
+ [`${as}.hasNextPage`]: {
121
+ $gt: [
122
+ {
123
+ $size: `$${as}.docs`
124
+ },
125
+ limitJoin || Number.MAX_VALUE
126
+ ]
127
+ }
128
+ }
129
+ });
130
+ if (limitJoin > 0) {
131
+ aggregate.push({
132
+ $addFields: {
133
+ [`${as}.docs`]: {
134
+ $slice: [
135
+ `$${as}.docs`,
136
+ limitJoin
137
+ ]
138
+ }
139
+ }
140
+ });
141
+ }
142
+ }
143
+ }
144
+ }
145
+ return aggregate;
146
+ };
147
+
148
+ //# sourceMappingURL=buildJoinAggregation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utilities/buildJoinAggregation.ts"],"sourcesContent":["import type { PipelineStage } from 'mongoose'\nimport type { CollectionSlug, JoinQuery, SanitizedCollectionConfig, Where } from 'payload'\n\nimport type { MongooseAdapter } from '../index.js'\n\nimport { buildSortParam } from '../queries/buildSortParam.js'\n\ntype BuildJoinAggregationArgs = {\n adapter: MongooseAdapter\n collection: CollectionSlug\n collectionConfig: SanitizedCollectionConfig\n joins: JoinQuery\n // the number of docs to get at the top collection level\n limit?: number\n locale: string\n // the where clause for the top collection\n query?: Where\n}\n\nexport const buildJoinAggregation = async ({\n adapter,\n collection,\n collectionConfig,\n joins,\n limit,\n locale,\n query,\n}: BuildJoinAggregationArgs): Promise<PipelineStage[] | undefined> => {\n if (Object.keys(collectionConfig.joins).length === 0 || joins === false) {\n return\n }\n\n const joinConfig = adapter.payload.collections[collection].config.joins\n const aggregate: PipelineStage[] = [\n {\n $sort: { createdAt: -1 },\n },\n ]\n\n if (query) {\n aggregate.push({\n $match: query,\n })\n }\n\n if (limit) {\n aggregate.push({\n $limit: limit,\n })\n }\n\n for (const slug of Object.keys(joinConfig)) {\n for (const join of joinConfig[slug]) {\n const joinModel = adapter.collections[join.field.collection]\n\n const {\n limit: limitJoin = 10,\n sort: sortJoin,\n where: whereJoin,\n } = joins?.[join.schemaPath] || {}\n\n const sort = buildSortParam({\n config: adapter.payload.config,\n fields: adapter.payload.collections[slug].config.fields,\n locale,\n sort: sortJoin || collectionConfig.defaultSort,\n timestamps: true,\n })\n const sortProperty = Object.keys(sort)[0]\n const sortDirection = sort[sortProperty] === 'asc' ? 1 : -1\n\n const $match = await joinModel.buildQuery({\n locale,\n payload: adapter.payload,\n where: whereJoin,\n })\n\n const pipeline: Exclude<PipelineStage, PipelineStage.Merge | PipelineStage.Out>[] = [\n { $match },\n {\n $sort: { [sortProperty]: sortDirection },\n },\n ]\n\n if (limitJoin > 0) {\n pipeline.push({\n $limit: limitJoin + 1,\n })\n }\n\n if (adapter.payload.config.localization && locale === 'all') {\n adapter.payload.config.localization.localeCodes.forEach((code) => {\n const as = `${join.schemaPath}${code}`\n\n aggregate.push(\n {\n $lookup: {\n as: `${as}.docs`,\n foreignField: `${join.field.on}${code}`,\n from: slug,\n localField: '_id',\n pipeline,\n },\n },\n {\n $addFields: {\n [`${as}.docs`]: {\n $map: {\n as: 'doc',\n in: '$$doc._id',\n input: `$${as}.docs`,\n },\n }, // Slicing the docs to match the limit\n [`${as}.hasNextPage`]: limitJoin\n ? { $gt: [{ $size: `$${as}.docs` }, limitJoin] }\n : false,\n // Boolean indicating if more docs than limit\n },\n },\n )\n if (limitJoin > 0) {\n aggregate.push({\n $addFields: {\n [`${as}.docs`]: {\n $slice: [`$${as}.docs`, limitJoin],\n },\n },\n })\n }\n })\n } else {\n const localeSuffix =\n join.field.localized && adapter.payload.config.localization && locale ? `.${locale}` : ''\n const as = `${join.schemaPath}${localeSuffix}`\n\n aggregate.push(\n {\n $lookup: {\n as: `${as}.docs`,\n foreignField: `${join.field.on}${localeSuffix}`,\n from: slug,\n localField: '_id',\n pipeline,\n },\n },\n {\n $addFields: {\n [`${as}.docs`]: {\n $map: {\n as: 'doc',\n in: '$$doc._id',\n input: `$${as}.docs`,\n },\n }, // Slicing the docs to match the limit\n [`${as}.hasNextPage`]: {\n $gt: [{ $size: `$${as}.docs` }, limitJoin || Number.MAX_VALUE],\n }, // Boolean indicating if more docs than limit\n },\n },\n )\n if (limitJoin > 0) {\n aggregate.push({\n $addFields: {\n [`${as}.docs`]: {\n $slice: [`$${as}.docs`, limitJoin],\n },\n },\n })\n }\n }\n }\n }\n\n return aggregate\n}\n"],"names":["buildSortParam","buildJoinAggregation","adapter","collection","collectionConfig","joins","limit","locale","query","Object","keys","length","joinConfig","payload","collections","config","aggregate","$sort","createdAt","push","$match","$limit","slug","join","joinModel","field","limitJoin","sort","sortJoin","where","whereJoin","schemaPath","fields","defaultSort","timestamps","sortProperty","sortDirection","buildQuery","pipeline","localization","localeCodes","forEach","code","as","$lookup","foreignField","on","from","localField","$addFields","$map","in","input","$gt","$size","$slice","localeSuffix","localized","Number","MAX_VALUE"],"mappings":"AAKA,SAASA,cAAc,QAAQ,+BAA8B;AAc7D,OAAO,MAAMC,uBAAuB,OAAO,EACzCC,OAAO,EACPC,UAAU,EACVC,gBAAgB,EAChBC,KAAK,EACLC,KAAK,EACLC,MAAM,EACNC,KAAK,EACoB;IACzB,IAAIC,OAAOC,IAAI,CAACN,iBAAiBC,KAAK,EAAEM,MAAM,KAAK,KAAKN,UAAU,OAAO;QACvE;IACF;IAEA,MAAMO,aAAaV,QAAQW,OAAO,CAACC,WAAW,CAACX,WAAW,CAACY,MAAM,CAACV,KAAK;IACvE,MAAMW,YAA6B;QACjC;YACEC,OAAO;gBAAEC,WAAW,CAAC;YAAE;QACzB;KACD;IAED,IAAIV,OAAO;QACTQ,UAAUG,IAAI,CAAC;YACbC,QAAQZ;QACV;IACF;IAEA,IAAIF,OAAO;QACTU,UAAUG,IAAI,CAAC;YACbE,QAAQf;QACV;IACF;IAEA,KAAK,MAAMgB,QAAQb,OAAOC,IAAI,CAACE,YAAa;QAC1C,KAAK,MAAMW,QAAQX,UAAU,CAACU,KAAK,CAAE;YACnC,MAAME,YAAYtB,QAAQY,WAAW,CAACS,KAAKE,KAAK,CAACtB,UAAU,CAAC;YAE5D,MAAM,EACJG,OAAOoB,YAAY,EAAE,EACrBC,MAAMC,QAAQ,EACdC,OAAOC,SAAS,EACjB,GAAGzB,OAAO,CAACkB,KAAKQ,UAAU,CAAC,IAAI,CAAC;YAEjC,MAAMJ,OAAO3B,eAAe;gBAC1Be,QAAQb,QAAQW,OAAO,CAACE,MAAM;gBAC9BiB,QAAQ9B,QAAQW,OAAO,CAACC,WAAW,CAACQ,KAAK,CAACP,MAAM,CAACiB,MAAM;gBACvDzB;gBACAoB,MAAMC,YAAYxB,iBAAiB6B,WAAW;gBAC9CC,YAAY;YACd;YACA,MAAMC,eAAe1B,OAAOC,IAAI,CAACiB,KAAK,CAAC,EAAE;YACzC,MAAM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F;QACF;IACF;IAEA,OAAOV;AACT,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"getDBName.d.ts","sourceRoot":"","sources":["../../src/utilities/getDBName.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAE/C,KAAK,IAAI,GAAG;IACV,MAAM,EAAE;QACN,MAAM,CAAC,EAAE,gBAAgB,CAAA;QACzB,QAAQ,CAAC,EAAE,gBAAgB,CAAA;QAC3B,IAAI,CAAC,EAAE,MAAM,CAAA;QACb,IAAI,CAAC,EAAE,MAAM,CAAA;KACd,CAAA;IACD,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,MAAM,CAAC,EAAE,QAAQ,GAAG,UAAU,CAAA;IAC9B,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,SAAS,0DAKnB,IAAI,KAAG,MAiBT,CAAA"}
1
+ {"version":3,"file":"getDBName.d.ts","sourceRoot":"","sources":["../../src/utilities/getDBName.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAE/C,KAAK,IAAI,GAAG;IACV,MAAM,EAAE;QACN,MAAM,CAAC,EAAE,gBAAgB,CAAA;QACzB,QAAQ,CAAC,EAAE,gBAAgB,CAAA;QAC3B,IAAI,CAAC,EAAE,MAAM,CAAA;QACb,IAAI,CAAC,EAAE,MAAM,CAAA;KACd,CAAA;IACD,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,MAAM,CAAC,EAAE,QAAQ,GAAG,UAAU,CAAA;IAC9B,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,SAAS,0DAKnB,IAAI,KAAG,MAmBT,CAAA"}