@payloadcms/db-mongodb 4.0.0-internal.d21c039 → 4.0.0-internal.d3909a9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/exports/migration-utils.d.ts +1 -0
- package/dist/exports/migration-utils.d.ts.map +1 -1
- package/dist/exports/migration-utils.js +1 -0
- package/dist/exports/migration-utils.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/init.d.ts.map +1 -1
- package/dist/init.js +89 -67
- package/dist/init.js.map +1 -1
- package/dist/migrateFresh.d.ts.map +1 -1
- package/dist/migrateFresh.js +1 -0
- package/dist/migrateFresh.js.map +1 -1
- package/dist/models/buildCollectionSchema.d.ts +8 -2
- package/dist/models/buildCollectionSchema.d.ts.map +1 -1
- package/dist/models/buildCollectionSchema.js +4 -2
- package/dist/models/buildCollectionSchema.js.map +1 -1
- package/dist/models/buildGlobalModel.d.ts +5 -1
- package/dist/models/buildGlobalModel.d.ts.map +1 -1
- package/dist/models/buildGlobalModel.js +4 -2
- package/dist/models/buildGlobalModel.js.map +1 -1
- package/dist/models/buildSchema.d.ts +4 -0
- package/dist/models/buildSchema.d.ts.map +1 -1
- package/dist/models/buildSchema.js +64 -26
- package/dist/models/buildSchema.js.map +1 -1
- package/dist/models/schemaBuildContext.d.ts +21 -0
- package/dist/models/schemaBuildContext.d.ts.map +1 -0
- package/dist/models/schemaBuildContext.js +29 -0
- package/dist/models/schemaBuildContext.js.map +1 -0
- package/dist/predefinedMigrations/migrateSizesToVariants.d.ts +13 -0
- package/dist/predefinedMigrations/migrateSizesToVariants.d.ts.map +1 -0
- package/dist/predefinedMigrations/migrateSizesToVariants.js +368 -0
- package/dist/predefinedMigrations/migrateSizesToVariants.js.map +1 -0
- package/dist/predefinedMigrations/sizes-to-variants.d.ts +5 -0
- package/dist/predefinedMigrations/sizes-to-variants.d.ts.map +1 -0
- package/dist/predefinedMigrations/sizes-to-variants.js +8 -0
- package/dist/predefinedMigrations/sizes-to-variants.js.map +1 -0
- package/dist/updateGlobal.js +2 -2
- package/dist/updateGlobal.js.map +1 -1
- package/dist/updateGlobalVersion.js +2 -2
- package/dist/updateGlobalVersion.js.map +1 -1
- package/dist/updateJobs.js +1 -1
- package/dist/updateJobs.js.map +1 -1
- package/dist/updateMany.d.ts.map +1 -1
- package/dist/updateMany.js +0 -1
- package/dist/updateMany.js.map +1 -1
- package/dist/updateOne.js +2 -2
- package/dist/updateOne.js.map +1 -1
- package/dist/updateVersion.js +2 -2
- package/dist/updateVersion.js.map +1 -1
- package/dist/utilities/aggregatePaginate.d.ts.map +1 -1
- package/dist/utilities/aggregatePaginate.js +3 -1
- package/dist/utilities/aggregatePaginate.js.map +1 -1
- package/package.json +16 -19
package/dist/updateOne.js
CHANGED
|
@@ -64,12 +64,12 @@ export const updateOne = async function updateOne({ id, collection: collectionSl
|
|
|
64
64
|
const findOptions = {
|
|
65
65
|
...baseOptions,
|
|
66
66
|
lean: true,
|
|
67
|
-
new: true,
|
|
68
67
|
projection: buildProjectionFromSelect({
|
|
69
68
|
adapter: this,
|
|
70
69
|
fields: collectionConfig.flattenedFields,
|
|
71
70
|
select
|
|
72
|
-
})
|
|
71
|
+
}),
|
|
72
|
+
returnDocument: 'after'
|
|
73
73
|
};
|
|
74
74
|
try {
|
|
75
75
|
if (returning === false) {
|
package/dist/updateOne.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/updateOne.ts"],"sourcesContent":["import type { QueryOptions, UpdateQuery } 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 { getCollection } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\nimport { handleError } from './utilities/handleError.js'\nimport { transform } from './utilities/transform.js'\n\nexport const updateOne: UpdateOne = async function updateOne(\n this: MongooseAdapter,\n {\n id,\n collection: collectionSlug,\n data,\n locale,\n options: optionsArgs = {},\n req,\n returning,\n select,\n where: whereArg = {},\n },\n) {\n const { collectionConfig, Model } = getCollection({ adapter: this, collectionSlug })\n const where = id ? { id: { equals: id } } : whereArg\n const fields = collectionConfig.fields\n\n const query = await buildQuery({\n adapter: this,\n collectionSlug,\n fields: collectionConfig.flattenedFields,\n locale,\n where,\n })\n\n let result\n\n let updateData: UpdateQuery<any> = data\n\n const $inc: Record<string, number> = {}\n const $push: Record<string, { $each: any[] } | any> = {}\n const $addToSet: Record<string, { $each: any[] } | any> = {}\n const $pull: Record<string, { $in: any[] } | any> = {}\n\n transform({\n $addToSet,\n $inc,\n $pull,\n $push,\n adapter: this,\n data,\n fields,\n operation: 'write',\n })\n\n const updateOps: UpdateQuery<any> = {}\n\n if (Object.keys($inc).length) {\n updateOps.$inc = $inc\n }\n if (Object.keys($push).length) {\n updateOps.$push = $push\n }\n if (Object.keys($addToSet).length) {\n updateOps.$addToSet = $addToSet\n }\n if (Object.keys($pull).length) {\n updateOps.$pull = $pull\n }\n if (Object.keys(updateOps).length) {\n updateOps.$set = updateData\n updateData = updateOps\n }\n\n const baseOptions = {\n ...optionsArgs,\n session: await getSession(this, req),\n // Timestamps are manually added by the write transform\n timestamps: false,\n } satisfies QueryOptions\n\n const findOptions: QueryOptions = {\n ...baseOptions,\n lean: true,\n
|
|
1
|
+
{"version":3,"sources":["../src/updateOne.ts"],"sourcesContent":["import type { QueryOptions, UpdateQuery } 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 { getCollection } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\nimport { handleError } from './utilities/handleError.js'\nimport { transform } from './utilities/transform.js'\n\nexport const updateOne: UpdateOne = async function updateOne(\n this: MongooseAdapter,\n {\n id,\n collection: collectionSlug,\n data,\n locale,\n options: optionsArgs = {},\n req,\n returning,\n select,\n where: whereArg = {},\n },\n) {\n const { collectionConfig, Model } = getCollection({ adapter: this, collectionSlug })\n const where = id ? { id: { equals: id } } : whereArg\n const fields = collectionConfig.fields\n\n const query = await buildQuery({\n adapter: this,\n collectionSlug,\n fields: collectionConfig.flattenedFields,\n locale,\n where,\n })\n\n let result\n\n let updateData: UpdateQuery<any> = data\n\n const $inc: Record<string, number> = {}\n const $push: Record<string, { $each: any[] } | any> = {}\n const $addToSet: Record<string, { $each: any[] } | any> = {}\n const $pull: Record<string, { $in: any[] } | any> = {}\n\n transform({\n $addToSet,\n $inc,\n $pull,\n $push,\n adapter: this,\n data,\n fields,\n operation: 'write',\n })\n\n const updateOps: UpdateQuery<any> = {}\n\n if (Object.keys($inc).length) {\n updateOps.$inc = $inc\n }\n if (Object.keys($push).length) {\n updateOps.$push = $push\n }\n if (Object.keys($addToSet).length) {\n updateOps.$addToSet = $addToSet\n }\n if (Object.keys($pull).length) {\n updateOps.$pull = $pull\n }\n if (Object.keys(updateOps).length) {\n updateOps.$set = updateData\n updateData = updateOps\n }\n\n const baseOptions = {\n ...optionsArgs,\n session: await getSession(this, req),\n // Timestamps are manually added by the write transform\n timestamps: false,\n } satisfies QueryOptions\n\n const findOptions: QueryOptions = {\n ...baseOptions,\n lean: true,\n projection: buildProjectionFromSelect({\n adapter: this,\n fields: collectionConfig.flattenedFields,\n select,\n }),\n returnDocument: 'after',\n }\n\n try {\n if (returning === false) {\n await Model.updateOne(query, updateData, baseOptions)\n transform({ adapter: this, data, fields, operation: 'read' })\n return null\n } else {\n result = await Model.findOneAndUpdate(query, updateData, findOptions)\n }\n } catch (error) {\n handleError({ collection: collectionSlug, 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","getCollection","getSession","handleError","transform","updateOne","id","collection","collectionSlug","data","locale","options","optionsArgs","req","returning","select","where","whereArg","collectionConfig","Model","adapter","equals","fields","query","flattenedFields","result","updateData","$inc","$push","$addToSet","$pull","operation","updateOps","Object","keys","length","$set","baseOptions","session","timestamps","findOptions","lean","projection","returnDocument","findOneAndUpdate","error"],"mappings":"AAKA,SAASA,UAAU,QAAQ,0BAAyB;AACpD,SAASC,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,aAAa,QAAQ,2BAA0B;AACxD,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAASC,WAAW,QAAQ,6BAA4B;AACxD,SAASC,SAAS,QAAQ,2BAA0B;AAEpD,OAAO,MAAMC,YAAuB,eAAeA,UAEjD,EACEC,EAAE,EACFC,YAAYC,cAAc,EAC1BC,IAAI,EACJC,MAAM,EACNC,SAASC,cAAc,CAAC,CAAC,EACzBC,GAAG,EACHC,SAAS,EACTC,MAAM,EACNC,OAAOC,WAAW,CAAC,CAAC,EACrB;IAED,MAAM,EAAEC,gBAAgB,EAAEC,KAAK,EAAE,GAAGlB,cAAc;QAAEmB,SAAS,IAAI;QAAEZ;IAAe;IAClF,MAAMQ,QAAQV,KAAK;QAAEA,IAAI;YAAEe,QAAQf;QAAG;IAAE,IAAIW;IAC5C,MAAMK,SAASJ,iBAAiBI,MAAM;IAEtC,MAAMC,QAAQ,MAAMxB,WAAW;QAC7BqB,SAAS,IAAI;QACbZ;QACAc,QAAQJ,iBAAiBM,eAAe;QACxCd;QACAM;IACF;IAEA,IAAIS;IAEJ,IAAIC,aAA+BjB;IAEnC,MAAMkB,OAA+B,CAAC;IACtC,MAAMC,QAAgD,CAAC;IACvD,MAAMC,YAAoD,CAAC;IAC3D,MAAMC,QAA8C,CAAC;IAErD1B,UAAU;QACRyB;QACAF;QACAG;QACAF;QACAR,SAAS,IAAI;QACbX;QACAa;QACAS,WAAW;IACb;IAEA,MAAMC,YAA8B,CAAC;IAErC,IAAIC,OAAOC,IAAI,CAACP,MAAMQ,MAAM,EAAE;QAC5BH,UAAUL,IAAI,GAAGA;IACnB;IACA,IAAIM,OAAOC,IAAI,CAACN,OAAOO,MAAM,EAAE;QAC7BH,UAAUJ,KAAK,GAAGA;IACpB;IACA,IAAIK,OAAOC,IAAI,CAACL,WAAWM,MAAM,EAAE;QACjCH,UAAUH,SAAS,GAAGA;IACxB;IACA,IAAII,OAAOC,IAAI,CAACJ,OAAOK,MAAM,EAAE;QAC7BH,UAAUF,KAAK,GAAGA;IACpB;IACA,IAAIG,OAAOC,IAAI,CAACF,WAAWG,MAAM,EAAE;QACjCH,UAAUI,IAAI,GAAGV;QACjBA,aAAaM;IACf;IAEA,MAAMK,cAAc;QAClB,GAAGzB,WAAW;QACd0B,SAAS,MAAMpC,WAAW,IAAI,EAAEW;QAChC,uDAAuD;QACvD0B,YAAY;IACd;IAEA,MAAMC,cAA4B;QAChC,GAAGH,WAAW;QACdI,MAAM;QACNC,YAAY1C,0BAA0B;YACpCoB,SAAS,IAAI;YACbE,QAAQJ,iBAAiBM,eAAe;YACxCT;QACF;QACA4B,gBAAgB;IAClB;IAEA,IAAI;QACF,IAAI7B,cAAc,OAAO;YACvB,MAAMK,MAAMd,SAAS,CAACkB,OAAOG,YAAYW;YACzCjC,UAAU;gBAAEgB,SAAS,IAAI;gBAAEX;gBAAMa;gBAAQS,WAAW;YAAO;YAC3D,OAAO;QACT,OAAO;YACLN,SAAS,MAAMN,MAAMyB,gBAAgB,CAACrB,OAAOG,YAAYc;QAC3D;IACF,EAAE,OAAOK,OAAO;QACd1C,YAAY;YAAEI,YAAYC;YAAgBqC;YAAOhC;QAAI;IACvD;IAEA,IAAI,CAACY,QAAQ;QACX,OAAO;IACT;IAEArB,UAAU;QAAEgB,SAAS,IAAI;QAAEX,MAAMgB;QAAQH;QAAQS,WAAW;IAAO;IAEnE,OAAON;AACT,EAAC"}
|
package/dist/updateVersion.js
CHANGED
|
@@ -38,12 +38,12 @@ export const updateVersion = async function updateVersion({ id, collection: coll
|
|
|
38
38
|
const findOptions = {
|
|
39
39
|
...baseOptions,
|
|
40
40
|
lean: true,
|
|
41
|
-
new: true,
|
|
42
41
|
projection: buildProjectionFromSelect({
|
|
43
42
|
adapter: this,
|
|
44
43
|
fields: flattenedFields,
|
|
45
44
|
select
|
|
46
|
-
})
|
|
45
|
+
}),
|
|
46
|
+
returnDocument: 'after'
|
|
47
47
|
};
|
|
48
48
|
if (returning === false) {
|
|
49
49
|
await Model.updateOne(query, versionData, baseOptions);
|
|
@@ -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 { getCollection } from './utilities/getEntity.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 {\n id,\n collection: collectionSlug,\n locale,\n options: optionsArgs = {},\n req,\n returning,\n select,\n versionData,\n where,\n },\n) {\n const { collectionConfig, Model } = getCollection({\n adapter: this,\n collectionSlug,\n versions: true,\n })\n\n const whereToUse = where || { id: { equals: id } }\n const fields = buildVersionCollectionFields(this.payload.config, collectionConfig)\n\n const flattenedFields = buildVersionCollectionFields(this.payload.config, collectionConfig, true)\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 baseOptions = {\n ...optionsArgs,\n session: await getSession(this, req),\n // Timestamps are manually added by the write transform\n timestamps: false,\n } satisfies QueryOptions\n\n const findOptions: QueryOptions = {\n ...baseOptions,\n lean: true,\n
|
|
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 { getCollection } from './utilities/getEntity.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 {\n id,\n collection: collectionSlug,\n locale,\n options: optionsArgs = {},\n req,\n returning,\n select,\n versionData,\n where,\n },\n) {\n const { collectionConfig, Model } = getCollection({\n adapter: this,\n collectionSlug,\n versions: true,\n })\n\n const whereToUse = where || { id: { equals: id } }\n const fields = buildVersionCollectionFields(this.payload.config, collectionConfig)\n\n const flattenedFields = buildVersionCollectionFields(this.payload.config, collectionConfig, true)\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 baseOptions = {\n ...optionsArgs,\n session: await getSession(this, req),\n // Timestamps are manually added by the write transform\n timestamps: false,\n } satisfies QueryOptions\n\n const findOptions: QueryOptions = {\n ...baseOptions,\n lean: true,\n projection: buildProjectionFromSelect({\n adapter: this,\n fields: flattenedFields,\n select,\n }),\n returnDocument: 'after',\n }\n\n if (returning === false) {\n await Model.updateOne(query, versionData, baseOptions)\n return null\n }\n\n const doc = await Model.findOneAndUpdate(query, versionData, findOptions)\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":["buildVersionCollectionFields","buildQuery","buildProjectionFromSelect","getCollection","getSession","transform","updateVersion","id","collection","collectionSlug","locale","options","optionsArgs","req","returning","select","versionData","where","collectionConfig","Model","adapter","versions","whereToUse","equals","fields","payload","config","flattenedFields","query","data","operation","baseOptions","session","timestamps","findOptions","lean","projection","returnDocument","updateOne","doc","findOneAndUpdate"],"mappings":"AAEA,SAASA,4BAA4B,QAA4B,UAAS;AAI1E,SAAS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,CAACZ,OAAOZ,aAAakB;IAE7D,IAAI,CAACK,KAAK;QACR,OAAO;IACT;IAEAlC,UAAU;QAAEe,SAAS,IAAI;QAAES,MAAMU;QAAKf;QAAQM,WAAW;IAAO;IAEhE,OAAOS;AACT,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aggregatePaginate.d.ts","sourceRoot":"","sources":["../../src/utilities/aggregatePaginate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAC/C,OAAO,KAAK,EAAE,aAAa,EAAE,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AACnE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAE5C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAElD,eAAO,MAAM,iBAAiB,mJAc3B;IACD,OAAO,EAAE,eAAe,CAAA;IACxB,SAAS,CAAC,EAAE,gBAAgB,CAAA;IAC5B,eAAe,CAAC,EAAE,aAAa,EAAE,CAAA;IACjC,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,CAAA;IACjB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACpC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC9B,OAAO,CAAC,EAAE,aAAa,CAAA;IACvB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,eAAe,CAAC,EAAE,aAAa,EAAE,CAAA;IACjC,iBAAiB,CAAC,EAAE,OAAO,CAAA;CAC5B,KAAG,OAAO,CAAC,aAAa,CAAC,GAAG,CAAC,
|
|
1
|
+
{"version":3,"file":"aggregatePaginate.d.ts","sourceRoot":"","sources":["../../src/utilities/aggregatePaginate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAC/C,OAAO,KAAK,EAAE,aAAa,EAAE,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AACnE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAE5C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAElD,eAAO,MAAM,iBAAiB,mJAc3B;IACD,OAAO,EAAE,eAAe,CAAA;IACxB,SAAS,CAAC,EAAE,gBAAgB,CAAA;IAC5B,eAAe,CAAC,EAAE,aAAa,EAAE,CAAA;IACjC,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,CAAA;IACjB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACpC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC9B,OAAO,CAAC,EAAE,aAAa,CAAA;IACvB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,eAAe,CAAC,EAAE,aAAa,EAAE,CAAA;IACjC,iBAAiB,CAAC,EAAE,OAAO,CAAA;CAC5B,KAAG,OAAO,CAAC,aAAa,CAAC,GAAG,CAAC,CAwF7B,CAAA"}
|
|
@@ -43,7 +43,9 @@ export const aggregatePaginate = async ({ adapter, collation, joinAggregation, l
|
|
|
43
43
|
if (useEstimatedCount) {
|
|
44
44
|
countPromise = Model.estimatedDocumentCount(query);
|
|
45
45
|
} else {
|
|
46
|
-
|
|
46
|
+
// Only hint the _id index for unfiltered counts. With a filter, MongoDB picks the matching index on its own,
|
|
47
|
+
// while forcing _id would make it scan the whole collection.
|
|
48
|
+
const hint = adapter.disableIndexHints !== true && Object.keys(query).length === 0 ? {
|
|
47
49
|
_id: 1
|
|
48
50
|
} : undefined;
|
|
49
51
|
countPromise = Model.countDocuments(query, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utilities/aggregatePaginate.ts"],"sourcesContent":["import type { CollationOptions } from 'mongodb'\nimport type { ClientSession, Model, PipelineStage } from 'mongoose'\nimport type { PaginatedDocs } from 'payload'\n\nimport type { MongooseAdapter } from '../index.js'\n\nexport const aggregatePaginate = async ({\n adapter,\n collation,\n joinAggregation,\n limit,\n Model,\n page,\n pagination,\n projection,\n query,\n session,\n sort,\n sortAggregation,\n useEstimatedCount,\n}: {\n adapter: MongooseAdapter\n collation?: CollationOptions\n joinAggregation?: PipelineStage[]\n limit?: number\n Model: Model<any>\n page?: number\n pagination?: boolean\n projection?: Record<string, boolean>\n query: Record<string, unknown>\n session?: ClientSession\n sort?: object\n sortAggregation?: PipelineStage[]\n useEstimatedCount?: boolean\n}): Promise<PaginatedDocs<any>> => {\n const aggregation: PipelineStage[] = [{ $match: query }]\n\n if (sortAggregation && sortAggregation.length > 0) {\n for (const stage of sortAggregation) {\n aggregation.push(stage)\n }\n }\n\n if (sort) {\n const $sort: Record<string, -1 | 1> = {}\n\n Object.entries(sort).forEach(([key, value]) => {\n $sort[key] = value === 'desc' ? -1 : 1\n })\n\n aggregation.push({ $sort })\n }\n\n if (page) {\n aggregation.push({ $skip: (page - 1) * (limit ?? 0) })\n }\n\n if (limit) {\n aggregation.push({ $limit: limit })\n }\n\n if (joinAggregation) {\n for (const stage of joinAggregation) {\n aggregation.push(stage)\n }\n }\n\n if (projection) {\n aggregation.push({ $project: projection })\n }\n\n let countPromise: Promise<null | number> = Promise.resolve(null)\n\n if (pagination !== false && limit) {\n if (useEstimatedCount) {\n countPromise = Model.estimatedDocumentCount(query)\n } else {\n const hint
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/aggregatePaginate.ts"],"sourcesContent":["import type { CollationOptions } from 'mongodb'\nimport type { ClientSession, Model, PipelineStage } from 'mongoose'\nimport type { PaginatedDocs } from 'payload'\n\nimport type { MongooseAdapter } from '../index.js'\n\nexport const aggregatePaginate = async ({\n adapter,\n collation,\n joinAggregation,\n limit,\n Model,\n page,\n pagination,\n projection,\n query,\n session,\n sort,\n sortAggregation,\n useEstimatedCount,\n}: {\n adapter: MongooseAdapter\n collation?: CollationOptions\n joinAggregation?: PipelineStage[]\n limit?: number\n Model: Model<any>\n page?: number\n pagination?: boolean\n projection?: Record<string, boolean>\n query: Record<string, unknown>\n session?: ClientSession\n sort?: object\n sortAggregation?: PipelineStage[]\n useEstimatedCount?: boolean\n}): Promise<PaginatedDocs<any>> => {\n const aggregation: PipelineStage[] = [{ $match: query }]\n\n if (sortAggregation && sortAggregation.length > 0) {\n for (const stage of sortAggregation) {\n aggregation.push(stage)\n }\n }\n\n if (sort) {\n const $sort: Record<string, -1 | 1> = {}\n\n Object.entries(sort).forEach(([key, value]) => {\n $sort[key] = value === 'desc' ? -1 : 1\n })\n\n aggregation.push({ $sort })\n }\n\n if (page) {\n aggregation.push({ $skip: (page - 1) * (limit ?? 0) })\n }\n\n if (limit) {\n aggregation.push({ $limit: limit })\n }\n\n if (joinAggregation) {\n for (const stage of joinAggregation) {\n aggregation.push(stage)\n }\n }\n\n if (projection) {\n aggregation.push({ $project: projection })\n }\n\n let countPromise: Promise<null | number> = Promise.resolve(null)\n\n if (pagination !== false && limit) {\n if (useEstimatedCount) {\n countPromise = Model.estimatedDocumentCount(query)\n } else {\n // Only hint the _id index for unfiltered counts. With a filter, MongoDB picks the matching index on its own,\n // while forcing _id would make it scan the whole collection.\n const hint =\n adapter.disableIndexHints !== true && Object.keys(query).length === 0\n ? { _id: 1 }\n : undefined\n countPromise = Model.countDocuments(query, {\n collation,\n session,\n ...(hint ? { hint } : {}),\n })\n }\n }\n\n const [docs, countResult] = await Promise.all([\n Model.aggregate(aggregation, { collation, session }),\n countPromise,\n ])\n\n const count = countResult === null ? docs.length : countResult\n\n const totalPages =\n pagination !== false && typeof limit === 'number' && limit !== 0 ? Math.ceil(count / limit) : 1\n\n const hasPrevPage = typeof page === 'number' && pagination !== false && page > 1\n const hasNextPage = typeof page === 'number' && pagination !== false && totalPages > page\n const pagingCounter =\n typeof page === 'number' && pagination !== false && typeof limit === 'number'\n ? (page - 1) * limit + 1\n : 1\n\n const result: PaginatedDocs = {\n docs,\n hasNextPage,\n hasPrevPage,\n limit: limit ?? 0,\n nextPage: hasNextPage ? page + 1 : null,\n page,\n pagingCounter,\n prevPage: hasPrevPage ? page - 1 : null,\n totalDocs: count,\n totalPages,\n }\n\n return result\n}\n"],"names":["aggregatePaginate","adapter","collation","joinAggregation","limit","Model","page","pagination","projection","query","session","sort","sortAggregation","useEstimatedCount","aggregation","$match","length","stage","push","$sort","Object","entries","forEach","key","value","$skip","$limit","$project","countPromise","Promise","resolve","estimatedDocumentCount","hint","disableIndexHints","keys","_id","undefined","countDocuments","docs","countResult","all","aggregate","count","totalPages","Math","ceil","hasPrevPage","hasNextPage","pagingCounter","result","nextPage","prevPage","totalDocs"],"mappings":"AAMA,OAAO,MAAMA,oBAAoB,OAAO,EACtCC,OAAO,EACPC,SAAS,EACTC,eAAe,EACfC,KAAK,EACLC,KAAK,EACLC,IAAI,EACJC,UAAU,EACVC,UAAU,EACVC,KAAK,EACLC,OAAO,EACPC,IAAI,EACJC,eAAe,EACfC,iBAAiB,EAelB;IACC,MAAMC,cAA+B;QAAC;YAAEC,QAAQN;QAAM;KAAE;IAExD,IAAIG,mBAAmBA,gBAAgBI,MAAM,GAAG,GAAG;QACjD,KAAK,MAAMC,SAASL,gBAAiB;YACnCE,YAAYI,IAAI,CAACD;QACnB;IACF;IAEA,IAAIN,MAAM;QACR,MAAMQ,QAAgC,CAAC;QAEvCC,OAAOC,OAAO,CAACV,MAAMW,OAAO,CAAC,CAAC,CAACC,KAAKC,MAAM;YACxCL,KAAK,CAACI,IAAI,GAAGC,UAAU,SAAS,CAAC,IAAI;QACvC;QAEAV,YAAYI,IAAI,CAAC;YAAEC;QAAM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rF,MAAM0C,gBACJ,OAAO1C,SAAS,YAAYC,eAAe,SAAS,OAAOH,UAAU,WACjE,AAACE,CAAAA,OAAO,CAAA,IAAKF,QAAQ,IACrB;IAEN,MAAM6C,SAAwB;QAC5BX;QACAS;QACAD;QACA1C,OAAOA,SAAS;QAChB8C,UAAUH,cAAczC,OAAO,IAAI;QACnCA;QACA0C;QACAG,UAAUL,cAAcxC,OAAO,IAAI;QACnC8C,WAAWV;QACXC;IACF;IAEA,OAAOM;AACT,EAAC"}
|
package/package.json
CHANGED
|
@@ -1,13 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payloadcms/db-mongodb",
|
|
3
|
-
"version": "4.0.0-internal.
|
|
3
|
+
"version": "4.0.0-internal.d3909a9",
|
|
4
4
|
"description": "The officially supported MongoDB database adapter for Payload",
|
|
5
5
|
"homepage": "https://payloadcms.com",
|
|
6
|
-
"repository": {
|
|
7
|
-
"type": "git",
|
|
8
|
-
"url": "https://github.com/payloadcms/payload.git",
|
|
9
|
-
"directory": "packages/db-mongodb"
|
|
10
|
-
},
|
|
11
6
|
"license": "MIT",
|
|
12
7
|
"author": "Payload <dev@payloadcms.com> (https://payloadcms.com)",
|
|
13
8
|
"maintainers": [
|
|
@@ -17,8 +12,19 @@
|
|
|
17
12
|
"url": "https://payloadcms.com"
|
|
18
13
|
}
|
|
19
14
|
],
|
|
20
|
-
"
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "https://github.com/payloadcms/payload.git",
|
|
18
|
+
"directory": "packages/db-mongodb"
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"dist",
|
|
22
|
+
"predefinedMigrations"
|
|
23
|
+
],
|
|
21
24
|
"type": "module",
|
|
25
|
+
"sideEffects": false,
|
|
26
|
+
"main": "./dist/index.js",
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
22
28
|
"exports": {
|
|
23
29
|
".": {
|
|
24
30
|
"import": "./dist/index.js",
|
|
@@ -36,12 +42,6 @@
|
|
|
36
42
|
"default": "./dist/exports/internal.js"
|
|
37
43
|
}
|
|
38
44
|
},
|
|
39
|
-
"main": "./dist/index.js",
|
|
40
|
-
"types": "./dist/index.d.ts",
|
|
41
|
-
"files": [
|
|
42
|
-
"dist",
|
|
43
|
-
"predefinedMigrations"
|
|
44
|
-
],
|
|
45
45
|
"dependencies": {
|
|
46
46
|
"mongoose": "9.9.2",
|
|
47
47
|
"mongoose-paginate-v2": "1.9.4",
|
|
@@ -53,19 +53,16 @@
|
|
|
53
53
|
"@types/prompts": "^2.4.5",
|
|
54
54
|
"mongodb": "7.5.0",
|
|
55
55
|
"mongodb-memory-server": "10.1.4",
|
|
56
|
-
"
|
|
57
|
-
"payload": "4.0.0-internal.d21c039"
|
|
56
|
+
"payload": "4.0.0-internal.d3909a9"
|
|
58
57
|
},
|
|
59
58
|
"peerDependencies": {
|
|
60
|
-
"payload": "4.0.0-internal.
|
|
59
|
+
"payload": "4.0.0-internal.d3909a9"
|
|
61
60
|
},
|
|
62
61
|
"scripts": {
|
|
63
62
|
"build": "pnpm build:types && pnpm build:swc",
|
|
64
63
|
"build:debug": "pnpm build",
|
|
65
64
|
"build:swc": "swc ./src -d ./dist --config-file .swcrc-build --strip-leading-paths",
|
|
66
65
|
"build:types": "tsc --emitDeclarationOnly --outDir dist",
|
|
67
|
-
"clean": "rimraf -g {dist,*.tsbuildinfo}"
|
|
68
|
-
"lint": "eslint .",
|
|
69
|
-
"lint:fix": "eslint . --fix"
|
|
66
|
+
"clean": "rimraf -g {dist,*.tsbuildinfo}"
|
|
70
67
|
}
|
|
71
68
|
}
|