@payloadcms/db-mongodb 3.26.0-canary.bbb3083 → 3.27.0-canary.ecc3f49
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/connect.d.ts.map +1 -1
- package/dist/connect.js +5 -1
- package/dist/connect.js.map +1 -1
- package/dist/count.d.ts.map +1 -1
- package/dist/count.js +8 -4
- package/dist/count.js.map +1 -1
- package/dist/countGlobalVersions.d.ts.map +1 -1
- package/dist/countGlobalVersions.js +8 -3
- package/dist/countGlobalVersions.js.map +1 -1
- package/dist/countVersions.d.ts.map +1 -1
- package/dist/countVersions.js +8 -3
- package/dist/countVersions.js.map +1 -1
- package/dist/create.d.ts.map +1 -1
- package/dist/create.js +13 -6
- package/dist/create.js.map +1 -1
- package/dist/createGlobal.d.ts +1 -1
- package/dist/createGlobal.d.ts.map +1 -1
- package/dist/createGlobal.js +12 -5
- package/dist/createGlobal.js.map +1 -1
- package/dist/createGlobalVersion.d.ts.map +1 -1
- package/dist/createGlobalVersion.js +13 -5
- package/dist/createGlobalVersion.js.map +1 -1
- package/dist/createMigration.d.ts.map +1 -1
- package/dist/createMigration.js.map +1 -1
- package/dist/createVersion.d.ts.map +1 -1
- package/dist/createVersion.js +13 -5
- package/dist/createVersion.js.map +1 -1
- package/dist/deleteMany.d.ts +1 -1
- package/dist/deleteMany.d.ts.map +1 -1
- package/dist/deleteMany.js +8 -4
- package/dist/deleteMany.js.map +1 -1
- package/dist/deleteOne.d.ts.map +1 -1
- package/dist/deleteOne.js +14 -6
- package/dist/deleteOne.js.map +1 -1
- package/dist/deleteVersions.d.ts.map +1 -1
- package/dist/deleteVersions.js +9 -4
- package/dist/deleteVersions.js.map +1 -1
- package/dist/find.d.ts.map +1 -1
- package/dist/find.js +25 -8
- package/dist/find.js.map +1 -1
- package/dist/findGlobal.d.ts.map +1 -1
- package/dist/findGlobal.js +8 -5
- package/dist/findGlobal.js.map +1 -1
- package/dist/findGlobalVersions.d.ts.map +1 -1
- package/dist/findGlobalVersions.js +8 -4
- package/dist/findGlobalVersions.js.map +1 -1
- package/dist/findOne.d.ts +1 -1
- package/dist/findOne.d.ts.map +1 -1
- package/dist/findOne.js +18 -8
- package/dist/findOne.js.map +1 -1
- package/dist/findVersions.d.ts.map +1 -1
- package/dist/findVersions.js +8 -4
- package/dist/findVersions.js.map +1 -1
- package/dist/index.d.ts +6 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -1
- package/dist/index.js.map +1 -1
- package/dist/init.d.ts.map +1 -1
- package/dist/init.js +1 -5
- package/dist/init.js.map +1 -1
- package/dist/migrateFresh.d.ts.map +1 -1
- package/dist/migrateFresh.js.map +1 -1
- package/dist/models/buildCollectionSchema.d.ts.map +1 -1
- package/dist/models/buildCollectionSchema.js +0 -4
- package/dist/models/buildCollectionSchema.js.map +1 -1
- package/dist/models/buildSchema.d.ts.map +1 -1
- package/dist/models/buildSchema.js +545 -515
- package/dist/models/buildSchema.js.map +1 -1
- package/dist/predefinedMigrations/migrateRelationshipsV2_V3.d.ts.map +1 -1
- package/dist/predefinedMigrations/migrateRelationshipsV2_V3.js +21 -8
- package/dist/predefinedMigrations/migrateRelationshipsV2_V3.js.map +1 -1
- package/dist/predefinedMigrations/migrateVersionsV1_V2.d.ts.map +1 -1
- package/dist/predefinedMigrations/migrateVersionsV1_V2.js +20 -8
- package/dist/predefinedMigrations/migrateVersionsV1_V2.js.map +1 -1
- package/dist/queries/buildSearchParams.d.ts +1 -1
- package/dist/queries/buildSearchParams.d.ts.map +1 -1
- package/dist/queries/buildSearchParams.js +42 -29
- package/dist/queries/buildSearchParams.js.map +1 -1
- package/dist/queries/buildSortParam.d.ts +2 -3
- package/dist/queries/buildSortParam.d.ts.map +1 -1
- package/dist/queries/buildSortParam.js +1 -1
- package/dist/queries/buildSortParam.js.map +1 -1
- package/dist/queries/getBuildQueryPlugin.d.ts.map +1 -1
- package/dist/queries/getBuildQueryPlugin.js +15 -8
- package/dist/queries/getBuildQueryPlugin.js.map +1 -1
- package/dist/queries/getLocalizedSortProperty.d.ts +1 -1
- package/dist/queries/getLocalizedSortProperty.d.ts.map +1 -1
- package/dist/queries/getLocalizedSortProperty.js +11 -6
- package/dist/queries/getLocalizedSortProperty.js.map +1 -1
- package/dist/queries/getLocalizedSortProperty.spec.js +8 -0
- package/dist/queries/getLocalizedSortProperty.spec.js.map +1 -1
- package/dist/queries/operatorMap.d.ts +1 -0
- package/dist/queries/operatorMap.d.ts.map +1 -1
- package/dist/queries/operatorMap.js.map +1 -1
- package/dist/queries/parseParams.d.ts +1 -1
- package/dist/queries/parseParams.d.ts.map +1 -1
- package/dist/queries/parseParams.js +3 -3
- package/dist/queries/parseParams.js.map +1 -1
- package/dist/queries/sanitizeQueryValue.d.ts +1 -1
- package/dist/queries/sanitizeQueryValue.d.ts.map +1 -1
- package/dist/queries/sanitizeQueryValue.js +30 -26
- package/dist/queries/sanitizeQueryValue.js.map +1 -1
- package/dist/queryDrafts.d.ts.map +1 -1
- package/dist/queryDrafts.js +26 -8
- package/dist/queryDrafts.js.map +1 -1
- package/dist/transactions/beginTransaction.d.ts.map +1 -1
- package/dist/transactions/beginTransaction.js +4 -2
- package/dist/transactions/beginTransaction.js.map +1 -1
- package/dist/transactions/commitTransaction.d.ts.map +1 -1
- package/dist/transactions/commitTransaction.js +1 -1
- package/dist/transactions/commitTransaction.js.map +1 -1
- package/dist/transactions/rollbackTransaction.d.ts.map +1 -1
- package/dist/transactions/rollbackTransaction.js +3 -3
- package/dist/transactions/rollbackTransaction.js.map +1 -1
- package/dist/types.d.ts +2 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/updateGlobal.d.ts.map +1 -1
- package/dist/updateGlobal.js +17 -7
- package/dist/updateGlobal.js.map +1 -1
- package/dist/updateGlobalVersion.d.ts +1 -1
- package/dist/updateGlobalVersion.d.ts.map +1 -1
- package/dist/updateGlobalVersion.js +14 -6
- package/dist/updateGlobalVersion.js.map +1 -1
- package/dist/updateMany.d.ts +3 -0
- package/dist/updateMany.d.ts.map +1 -0
- package/dist/updateMany.js +75 -0
- package/dist/updateMany.js.map +1 -0
- package/dist/updateOne.d.ts.map +1 -1
- package/dist/updateOne.js +17 -8
- package/dist/updateOne.js.map +1 -1
- package/dist/updateVersion.d.ts.map +1 -1
- package/dist/updateVersion.js +14 -5
- package/dist/updateVersion.js.map +1 -1
- package/dist/upsert.d.ts.map +1 -1
- package/dist/upsert.js +2 -1
- package/dist/upsert.js.map +1 -1
- package/dist/utilities/aggregatePaginate.d.ts +19 -0
- package/dist/utilities/aggregatePaginate.d.ts.map +1 -0
- package/dist/utilities/aggregatePaginate.js +78 -0
- package/dist/utilities/aggregatePaginate.js.map +1 -0
- package/dist/utilities/buildJoinAggregation.d.ts +5 -6
- package/dist/utilities/buildJoinAggregation.d.ts.map +1 -1
- package/dist/utilities/buildJoinAggregation.js +39 -36
- package/dist/utilities/buildJoinAggregation.js.map +1 -1
- package/dist/utilities/buildProjectionFromSelect.d.ts.map +1 -1
- package/dist/utilities/buildProjectionFromSelect.js +8 -4
- package/dist/utilities/buildProjectionFromSelect.js.map +1 -1
- package/dist/utilities/getDBName.d.ts +1 -1
- package/dist/utilities/getDBName.d.ts.map +1 -1
- package/dist/utilities/getDBName.js +6 -2
- package/dist/utilities/getDBName.js.map +1 -1
- package/dist/utilities/getEntity.d.ts +33 -0
- package/dist/utilities/getEntity.d.ts.map +1 -0
- package/dist/utilities/getEntity.js +49 -0
- package/dist/utilities/getEntity.js.map +1 -0
- package/dist/utilities/handleError.d.ts +1 -1
- package/dist/utilities/handleError.d.ts.map +1 -1
- package/dist/utilities/handleError.js +3 -2
- package/dist/utilities/handleError.js.map +1 -1
- package/dist/utilities/transform.d.ts.map +1 -1
- package/dist/utilities/transform.js +10 -9
- package/dist/utilities/transform.js.map +1 -1
- package/package.json +6 -5
|
@@ -1,4 +1,4 @@
|
|
|
1
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: globalSlug, locale, options: optionsArgs, req, select, versionData, where, }: UpdateGlobalVersionArgs<T>): Promise<any>;
|
|
3
|
+
export declare function updateGlobalVersion<T extends TypeWithID>(this: MongooseAdapter, { id, global: globalSlug, locale, options: optionsArgs, req, returning, select, 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":"AAEA,OAAO,EAA4B,KAAK,UAAU,EAAE,KAAK,uBAAuB,EAAE,MAAM,SAAS,CAAA;AAEjG,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"updateGlobalVersion.d.ts","sourceRoot":"","sources":["../src/updateGlobalVersion.ts"],"names":[],"mappings":"AAEA,OAAO,EAA4B,KAAK,UAAU,EAAE,KAAK,uBAAuB,EAAE,MAAM,SAAS,CAAA;AAEjG,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAQjD,wBAAsB,mBAAmB,CAAC,CAAC,SAAS,UAAU,EAC5D,IAAI,EAAE,eAAe,EACrB,EACE,EAAE,EACF,MAAM,EAAE,UAAU,EAClB,MAAM,EACN,OAAO,EAAE,WAAgB,EACzB,GAAG,EACH,SAAS,EACT,MAAM,EACN,WAAW,EACX,KAAK,GACN,EAAE,uBAAuB,CAAC,CAAC,CAAC,gBA0C9B"}
|
|
@@ -1,18 +1,22 @@
|
|
|
1
1
|
import { buildVersionGlobalFields } from 'payload';
|
|
2
2
|
import { buildQuery } from './queries/buildQuery.js';
|
|
3
3
|
import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js';
|
|
4
|
+
import { getGlobal } from './utilities/getEntity.js';
|
|
4
5
|
import { getSession } from './utilities/getSession.js';
|
|
5
6
|
import { transform } from './utilities/transform.js';
|
|
6
|
-
export async function updateGlobalVersion({ id, global: globalSlug, locale, options: optionsArgs = {}, req, select, versionData, where }) {
|
|
7
|
-
const
|
|
7
|
+
export async function updateGlobalVersion({ id, global: globalSlug, locale, options: optionsArgs = {}, req, returning, select, versionData, where }) {
|
|
8
|
+
const { globalConfig, Model } = getGlobal({
|
|
9
|
+
adapter: this,
|
|
10
|
+
globalSlug,
|
|
11
|
+
versions: true
|
|
12
|
+
});
|
|
8
13
|
const whereToUse = where || {
|
|
9
14
|
id: {
|
|
10
15
|
equals: id
|
|
11
16
|
}
|
|
12
17
|
};
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const flattenedFields = buildVersionGlobalFields(this.payload.config, currentGlobal, true);
|
|
18
|
+
const fields = buildVersionGlobalFields(this.payload.config, globalConfig);
|
|
19
|
+
const flattenedFields = buildVersionGlobalFields(this.payload.config, globalConfig, true);
|
|
16
20
|
const options = {
|
|
17
21
|
...optionsArgs,
|
|
18
22
|
lean: true,
|
|
@@ -36,7 +40,11 @@ export async function updateGlobalVersion({ id, global: globalSlug, locale, opti
|
|
|
36
40
|
fields,
|
|
37
41
|
operation: 'write'
|
|
38
42
|
});
|
|
39
|
-
|
|
43
|
+
if (returning === false) {
|
|
44
|
+
await Model.updateOne(query, versionData, options);
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
const doc = await Model.findOneAndUpdate(query, versionData, options);
|
|
40
48
|
if (!doc) {
|
|
41
49
|
return null;
|
|
42
50
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/updateGlobalVersion.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"sources":["../src/updateGlobalVersion.ts"],"sourcesContent":["import type { MongooseUpdateQueryOptions } from 'mongoose'\n\nimport { buildVersionGlobalFields, type TypeWithID, type UpdateGlobalVersionArgs } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getGlobal } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\nimport { transform } from './utilities/transform.js'\n\nexport async function updateGlobalVersion<T extends TypeWithID>(\n this: MongooseAdapter,\n {\n id,\n global: globalSlug,\n locale,\n options: optionsArgs = {},\n req,\n returning,\n select,\n versionData,\n where,\n }: UpdateGlobalVersionArgs<T>,\n) {\n const { globalConfig, Model } = getGlobal({ adapter: this, globalSlug, versions: true })\n const whereToUse = where || { id: { equals: id } }\n\n const fields = buildVersionGlobalFields(this.payload.config, globalConfig)\n const flattenedFields = buildVersionGlobalFields(this.payload.config, globalConfig, true)\n const options: MongooseUpdateQueryOptions = {\n ...optionsArgs,\n lean: true,\n new: true,\n projection: buildProjectionFromSelect({\n adapter: this,\n fields: flattenedFields,\n select,\n }),\n session: await getSession(this, req),\n }\n\n const query = await buildQuery({\n adapter: this,\n fields: flattenedFields,\n locale,\n where: whereToUse,\n })\n\n transform({ adapter: this, data: versionData, fields, operation: 'write' })\n\n if (returning === false) {\n await Model.updateOne(query, versionData, options)\n return null\n }\n\n const doc = await Model.findOneAndUpdate(query, versionData, options)\n\n if (!doc) {\n return null\n }\n\n transform({ adapter: this, data: doc, fields, operation: 'read' })\n\n return doc\n}\n"],"names":["buildVersionGlobalFields","buildQuery","buildProjectionFromSelect","getGlobal","getSession","transform","updateGlobalVersion","id","global","globalSlug","locale","options","optionsArgs","req","returning","select","versionData","where","globalConfig","Model","adapter","versions","whereToUse","equals","fields","payload","config","flattenedFields","lean","new","projection","session","query","data","operation","updateOne","doc","findOneAndUpdate"],"mappings":"AAEA,SAASA,wBAAwB,QAAuD,UAAS;AAIjG,SAASC,UAAU,QAAQ,0BAAyB;AACpD,SAASC,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,SAAS,QAAQ,2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-0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"updateMany.d.ts","sourceRoot":"","sources":["../src/updateMany.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAWzC,eAAO,MAAM,UAAU,EAAE,UAuExB,CAAA"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { buildQuery } from './queries/buildQuery.js';
|
|
2
|
+
import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js';
|
|
3
|
+
import { getCollection } from './utilities/getEntity.js';
|
|
4
|
+
import { getSession } from './utilities/getSession.js';
|
|
5
|
+
import { handleError } from './utilities/handleError.js';
|
|
6
|
+
import { transform } from './utilities/transform.js';
|
|
7
|
+
export const updateMany = async function updateMany({ collection: collectionSlug, data, limit, locale, options: optionsArgs = {}, req, returning, select, where }) {
|
|
8
|
+
const { collectionConfig, Model } = getCollection({
|
|
9
|
+
adapter: this,
|
|
10
|
+
collectionSlug
|
|
11
|
+
});
|
|
12
|
+
const options = {
|
|
13
|
+
...optionsArgs,
|
|
14
|
+
lean: true,
|
|
15
|
+
new: true,
|
|
16
|
+
projection: buildProjectionFromSelect({
|
|
17
|
+
adapter: this,
|
|
18
|
+
fields: collectionConfig.flattenedFields,
|
|
19
|
+
select
|
|
20
|
+
}),
|
|
21
|
+
session: await getSession(this, req)
|
|
22
|
+
};
|
|
23
|
+
let query = await buildQuery({
|
|
24
|
+
adapter: this,
|
|
25
|
+
collectionSlug,
|
|
26
|
+
fields: collectionConfig.flattenedFields,
|
|
27
|
+
locale,
|
|
28
|
+
where
|
|
29
|
+
});
|
|
30
|
+
transform({
|
|
31
|
+
adapter: this,
|
|
32
|
+
data,
|
|
33
|
+
fields: collectionConfig.fields,
|
|
34
|
+
operation: 'write'
|
|
35
|
+
});
|
|
36
|
+
try {
|
|
37
|
+
if (typeof limit === 'number' && limit > 0) {
|
|
38
|
+
const documentsToUpdate = await Model.find(query, {}, {
|
|
39
|
+
...options,
|
|
40
|
+
limit,
|
|
41
|
+
projection: {
|
|
42
|
+
_id: 1
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
if (documentsToUpdate.length === 0) {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
query = {
|
|
49
|
+
_id: {
|
|
50
|
+
$in: documentsToUpdate.map((doc)=>doc._id)
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
await Model.updateMany(query, data, options);
|
|
55
|
+
} catch (error) {
|
|
56
|
+
handleError({
|
|
57
|
+
collection: collectionSlug,
|
|
58
|
+
error,
|
|
59
|
+
req
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
if (returning === false) {
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
const result = await Model.find(query, {}, options);
|
|
66
|
+
transform({
|
|
67
|
+
adapter: this,
|
|
68
|
+
data: result,
|
|
69
|
+
fields: collectionConfig.fields,
|
|
70
|
+
operation: 'read'
|
|
71
|
+
});
|
|
72
|
+
return result;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
//# sourceMappingURL=updateMany.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/updateMany.ts"],"sourcesContent":["import type { MongooseUpdateQueryOptions } from 'mongoose'\nimport type { UpdateMany } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getCollection } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\nimport { handleError } from './utilities/handleError.js'\nimport { transform } from './utilities/transform.js'\n\nexport const updateMany: UpdateMany = async function updateMany(\n this: MongooseAdapter,\n {\n collection: collectionSlug,\n data,\n limit,\n locale,\n options: optionsArgs = {},\n req,\n returning,\n select,\n where,\n },\n) {\n const { collectionConfig, Model } = getCollection({ adapter: this, collectionSlug })\n\n const options: MongooseUpdateQueryOptions = {\n ...optionsArgs,\n lean: true,\n new: true,\n projection: buildProjectionFromSelect({\n adapter: this,\n fields: collectionConfig.flattenedFields,\n select,\n }),\n session: await getSession(this, req),\n }\n\n let query = await buildQuery({\n adapter: this,\n collectionSlug,\n fields: collectionConfig.flattenedFields,\n locale,\n where,\n })\n\n transform({ adapter: this, data, fields: collectionConfig.fields, operation: 'write' })\n\n try {\n if (typeof limit === 'number' && limit > 0) {\n const documentsToUpdate = await Model.find(\n query,\n {},\n { ...options, limit, projection: { _id: 1 } },\n )\n if (documentsToUpdate.length === 0) {\n return null\n }\n\n query = { _id: { $in: documentsToUpdate.map((doc) => doc._id) } }\n }\n\n await Model.updateMany(query, data, options)\n } catch (error) {\n handleError({ collection: collectionSlug, error, req })\n }\n\n if (returning === false) {\n return null\n }\n\n const result = await Model.find(query, {}, options)\n\n transform({\n adapter: this,\n data: result,\n fields: collectionConfig.fields,\n operation: 'read',\n })\n\n return result\n}\n"],"names":["buildQuery","buildProjectionFromSelect","getCollection","getSession","handleError","transform","updateMany","collection","collectionSlug","data","limit","locale","options","optionsArgs","req","returning","select","where","collectionConfig","Model","adapter","lean","new","projection","fields","flattenedFields","session","query","operation","documentsToUpdate","find","_id","length","$in","map","doc","error","result"],"mappings":"AAKA,SAASA,UAAU,QAAQ,0BAAyB;AACpD,SAASC,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,aAAa,QAAQ,2BAA0B;AACxD,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAASC,WAAW,QAAQ,6BAA4B;AACxD,SAASC,SAAS,QAAQ,2BAA0B;AAEpD,OAAO,MAAMC,aAAyB,eAAeA,WAEnD,EACEC,YAAYC,cAAc,EAC1BC,IAAI,EACJC,KAAK,EACLC,MAAM,EACNC,SAASC,cAAc,CAAC,CAAC,EACzBC,GAAG,EACHC,SAAS,EACTC,MAAM,EACNC,KAAK,EACN;IAED,MAAM,EAAEC,gBAAgB,EAAEC,KAAK,EAAE,GAAGjB,cAAc;QAAEk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3,"file":"updateOne.d.ts","sourceRoot":"","sources":["../src/updateOne.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"updateOne.d.ts","sourceRoot":"","sources":["../src/updateOne.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAWxC,eAAO,MAAM,SAAS,EAAE,SA4DvB,CAAA"}
|
package/dist/updateOne.js
CHANGED
|
@@ -1,31 +1,35 @@
|
|
|
1
1
|
import { buildQuery } from './queries/buildQuery.js';
|
|
2
2
|
import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js';
|
|
3
|
+
import { getCollection } from './utilities/getEntity.js';
|
|
3
4
|
import { getSession } from './utilities/getSession.js';
|
|
4
5
|
import { handleError } from './utilities/handleError.js';
|
|
5
6
|
import { transform } from './utilities/transform.js';
|
|
6
|
-
export const updateOne = async function updateOne({ id, collection, data, locale, options: optionsArgs = {}, req, select, where: whereArg }) {
|
|
7
|
+
export const updateOne = async function updateOne({ id, collection: collectionSlug, data, locale, options: optionsArgs = {}, req, returning, select, where: whereArg = {} }) {
|
|
8
|
+
const { collectionConfig, Model } = getCollection({
|
|
9
|
+
adapter: this,
|
|
10
|
+
collectionSlug
|
|
11
|
+
});
|
|
7
12
|
const where = id ? {
|
|
8
13
|
id: {
|
|
9
14
|
equals: id
|
|
10
15
|
}
|
|
11
16
|
} : whereArg;
|
|
12
|
-
const
|
|
13
|
-
const fields = this.payload.collections[collection].config.fields;
|
|
17
|
+
const fields = collectionConfig.fields;
|
|
14
18
|
const options = {
|
|
15
19
|
...optionsArgs,
|
|
16
20
|
lean: true,
|
|
17
21
|
new: true,
|
|
18
22
|
projection: buildProjectionFromSelect({
|
|
19
23
|
adapter: this,
|
|
20
|
-
fields:
|
|
24
|
+
fields: collectionConfig.flattenedFields,
|
|
21
25
|
select
|
|
22
26
|
}),
|
|
23
27
|
session: await getSession(this, req)
|
|
24
28
|
};
|
|
25
29
|
const query = await buildQuery({
|
|
26
30
|
adapter: this,
|
|
27
|
-
collectionSlug
|
|
28
|
-
fields:
|
|
31
|
+
collectionSlug,
|
|
32
|
+
fields: collectionConfig.flattenedFields,
|
|
29
33
|
locale,
|
|
30
34
|
where
|
|
31
35
|
});
|
|
@@ -37,10 +41,15 @@ export const updateOne = async function updateOne({ id, collection, data, locale
|
|
|
37
41
|
operation: 'write'
|
|
38
42
|
});
|
|
39
43
|
try {
|
|
40
|
-
|
|
44
|
+
if (returning === false) {
|
|
45
|
+
await Model.updateOne(query, data, options);
|
|
46
|
+
return null;
|
|
47
|
+
} else {
|
|
48
|
+
result = await Model.findOneAndUpdate(query, data, options);
|
|
49
|
+
}
|
|
41
50
|
} catch (error) {
|
|
42
51
|
handleError({
|
|
43
|
-
collection,
|
|
52
|
+
collection: collectionSlug,
|
|
44
53
|
error,
|
|
45
54
|
req
|
|
46
55
|
});
|
package/dist/updateOne.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/updateOne.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"sources":["../src/updateOne.ts"],"sourcesContent":["import type { MongooseUpdateQueryOptions } 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 options: MongooseUpdateQueryOptions = {\n ...optionsArgs,\n lean: true,\n new: true,\n projection: buildProjectionFromSelect({\n adapter: this,\n fields: collectionConfig.flattenedFields,\n select,\n }),\n session: await getSession(this, req),\n }\n\n const query = await buildQuery({\n adapter: this,\n collectionSlug,\n fields: collectionConfig.flattenedFields,\n locale,\n where,\n })\n\n let result\n\n transform({ adapter: this, data, fields, operation: 'write' })\n\n try {\n if (returning === false) {\n await Model.updateOne(query, data, options)\n return null\n } else {\n result = await Model.findOneAndUpdate(query, data, options)\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","lean","new","projection","flattenedFields","session","query","result","operation","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,MAAMX,UAAsC;QAC1C,GAAGC,WAAW;QACdW,MAAM;QACNC,KAAK;QACLC,YAAYzB,0BAA0B;YACpCoB,SAAS,IAAI;YACbE,QAAQJ,iBAAiBQ,eAAe;YACxCX;QACF;QACAY,SAAS,MAAMzB,WAAW,IAAI,EAAEW;IAClC;IAEA,MAAMe,QAAQ,MAAM7B,WAAW;QAC7BqB,SAAS,IAAI;QACbZ;QACAc,QAAQJ,iBAAiBQ,eAAe;QACxChB;QACAM;IACF;IAEA,IAAIa;IAEJzB,UAAU;QAAEgB,SAAS,IAAI;QAAEX;QAAMa;QAAQQ,WAAW;IAAQ;IAE5D,IAAI;QACF,IAAIhB,cAAc,OAAO;YACvB,MAAMK,MAAMd,SAAS,CAACuB,OAAOnB,MAAME;YACnC,OAAO;QACT,OAAO;YACLkB,SAAS,MAAMV,MAAMY,gBAAgB,CAACH,OAAOnB,MAAME;QACrD;IACF,EAAE,OAAOqB,OAAO;QACd7B,YAAY;YAAEI,YAAYC;YAAgBwB;YAAOnB;QAAI;IACvD;IAEA,IAAI,CAACgB,QAAQ;QACX,OAAO;IACT;IAEAzB,UAAU;QAAEgB,SAAS,IAAI;QAAEX,MAAMoB;QAAQP;QAAQQ,WAAW;IAAO;IAEnE,OAAOD;AACT,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"updateVersion.d.ts","sourceRoot":"","sources":["../src/updateVersion.ts"],"names":[],"mappings":"AAEA,OAAO,EAAgC,KAAK,aAAa,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"updateVersion.d.ts","sourceRoot":"","sources":["../src/updateVersion.ts"],"names":[],"mappings":"AAEA,OAAO,EAAgC,KAAK,aAAa,EAAE,MAAM,SAAS,CAAA;AAU1E,eAAO,MAAM,aAAa,EAAE,aA4D3B,CAAA"}
|
package/dist/updateVersion.js
CHANGED
|
@@ -1,17 +1,22 @@
|
|
|
1
1
|
import { buildVersionCollectionFields } from 'payload';
|
|
2
2
|
import { buildQuery } from './queries/buildQuery.js';
|
|
3
3
|
import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js';
|
|
4
|
+
import { getCollection } from './utilities/getEntity.js';
|
|
4
5
|
import { getSession } from './utilities/getSession.js';
|
|
5
6
|
import { transform } from './utilities/transform.js';
|
|
6
|
-
export const updateVersion = async function updateVersion({ id, collection, locale, options: optionsArgs = {}, req, select, versionData, where }) {
|
|
7
|
-
const
|
|
7
|
+
export const updateVersion = async function updateVersion({ id, collection: collectionSlug, locale, options: optionsArgs = {}, req, returning, select, versionData, where }) {
|
|
8
|
+
const { collectionConfig, Model } = getCollection({
|
|
9
|
+
adapter: this,
|
|
10
|
+
collectionSlug,
|
|
11
|
+
versions: true
|
|
12
|
+
});
|
|
8
13
|
const whereToUse = where || {
|
|
9
14
|
id: {
|
|
10
15
|
equals: id
|
|
11
16
|
}
|
|
12
17
|
};
|
|
13
|
-
const fields = buildVersionCollectionFields(this.payload.config,
|
|
14
|
-
const flattenedFields = buildVersionCollectionFields(this.payload.config,
|
|
18
|
+
const fields = buildVersionCollectionFields(this.payload.config, collectionConfig);
|
|
19
|
+
const flattenedFields = buildVersionCollectionFields(this.payload.config, collectionConfig, true);
|
|
15
20
|
const options = {
|
|
16
21
|
...optionsArgs,
|
|
17
22
|
lean: true,
|
|
@@ -35,7 +40,11 @@ export const updateVersion = async function updateVersion({ id, collection, loca
|
|
|
35
40
|
fields,
|
|
36
41
|
operation: 'write'
|
|
37
42
|
});
|
|
38
|
-
|
|
43
|
+
if (returning === false) {
|
|
44
|
+
await Model.updateOne(query, versionData, options);
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
const doc = await Model.findOneAndUpdate(query, versionData, options);
|
|
39
48
|
if (!doc) {
|
|
40
49
|
return null;
|
|
41
50
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/updateVersion.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"sources":["../src/updateVersion.ts"],"sourcesContent":["import type { MongooseUpdateQueryOptions } 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 options: MongooseUpdateQueryOptions = {\n ...optionsArgs,\n lean: true,\n new: true,\n projection: buildProjectionFromSelect({\n adapter: this,\n fields: flattenedFields,\n select,\n }),\n session: await getSession(this, req),\n }\n\n const query = await buildQuery({\n adapter: this,\n fields: flattenedFields,\n locale,\n where: whereToUse,\n })\n\n transform({ adapter: this, data: versionData, fields, operation: 'write' })\n\n if (returning === false) {\n await Model.updateOne(query, versionData, options)\n return null\n }\n\n const doc = await Model.findOneAndUpdate(query, versionData, options)\n\n if (!doc) {\n return null\n }\n\n transform({ adapter: this, data: doc, fields, operation: 'write' })\n\n return doc\n}\n"],"names":["buildVersionCollectionFields","buildQuery","buildProjectionFromSelect","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","lean","new","projection","session","query","data","operation","updateOne","doc","findOneAndUpdate"],"mappings":"AAEA,SAASA,4BAA4B,QAA4B,UAAS;AAI1E,SAASC,UAAU,QAAQ,0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SAAS,IAAI;QAAEa,MAAMG;QAAKZ;QAAQU,WAAW;IAAQ;IAEjE,OAAOE;AACT,EAAC"}
|
package/dist/upsert.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"upsert.d.ts","sourceRoot":"","sources":["../src/upsert.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAIrC,eAAO,MAAM,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"upsert.d.ts","sourceRoot":"","sources":["../src/upsert.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAIrC,eAAO,MAAM,MAAM,EAAE,MAcpB,CAAA"}
|
package/dist/upsert.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export const upsert = async function upsert({ collection, data, locale, req, select, where }) {
|
|
1
|
+
export const upsert = async function upsert({ collection, data, locale, req, returning, select, where }) {
|
|
2
2
|
return this.updateOne({
|
|
3
3
|
collection,
|
|
4
4
|
data,
|
|
@@ -7,6 +7,7 @@ export const upsert = async function upsert({ collection, data, locale, req, sel
|
|
|
7
7
|
upsert: true
|
|
8
8
|
},
|
|
9
9
|
req,
|
|
10
|
+
returning,
|
|
10
11
|
select,
|
|
11
12
|
where
|
|
12
13
|
});
|
package/dist/upsert.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/upsert.ts"],"sourcesContent":["import type { 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, select, where },\n) {\n return this.updateOne({
|
|
1
|
+
{"version":3,"sources":["../src/upsert.ts"],"sourcesContent":["import type { 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, returning, select, where },\n) {\n return this.updateOne({\n collection,\n data,\n locale,\n options: { upsert: true },\n req,\n returning,\n select,\n where,\n })\n}\n"],"names":["upsert","collection","data","locale","req","returning","select","where","updateOne","options"],"mappings":"AAIA,OAAO,MAAMA,SAAiB,eAAeA,OAE3C,EAAEC,UAAU,EAAEC,IAAI,EAAEC,MAAM,EAAEC,GAAG,EAAEC,SAAS,EAAEC,MAAM,EAAEC,KAAK,EAAE;IAE3D,OAAO,IAAI,CAACC,SAAS,CAAC;QACpBP;QACAC;QACAC;QACAM,SAAS;YAAET,QAAQ;QAAK;QACxBI;QACAC;QACAC;QACAC;IACF;AACF,EAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { CollationOptions } from 'mongodb';
|
|
2
|
+
import type { ClientSession, Model, PipelineStage } from 'mongoose';
|
|
3
|
+
import type { PaginatedDocs } from 'payload';
|
|
4
|
+
import type { MongooseAdapter } from '../index.js';
|
|
5
|
+
export declare const aggregatePaginate: ({ adapter, collation, joinAggregation, limit, Model, page, pagination, projection, query, session, sort, useEstimatedCount, }: {
|
|
6
|
+
adapter: MongooseAdapter;
|
|
7
|
+
collation?: CollationOptions;
|
|
8
|
+
joinAggregation?: PipelineStage[];
|
|
9
|
+
limit?: number;
|
|
10
|
+
Model: Model<any>;
|
|
11
|
+
page?: number;
|
|
12
|
+
pagination?: boolean;
|
|
13
|
+
projection?: Record<string, boolean>;
|
|
14
|
+
query: Record<string, unknown>;
|
|
15
|
+
session?: ClientSession;
|
|
16
|
+
sort?: object;
|
|
17
|
+
useEstimatedCount?: boolean;
|
|
18
|
+
}) => Promise<PaginatedDocs<any>>;
|
|
19
|
+
//# sourceMappingURL=aggregatePaginate.d.ts.map
|
|
@@ -0,0 +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,kIAa3B;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,iBAAiB,CAAC,EAAE,OAAO,CAAA;CAC5B,KAAG,OAAO,CAAC,aAAa,CAAC,GAAG,CAAC,CAyE7B,CAAA"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
export const aggregatePaginate = async ({ adapter, collation, joinAggregation, limit, Model, page, pagination, projection, query, session, sort, useEstimatedCount })=>{
|
|
2
|
+
const aggregation = [
|
|
3
|
+
{
|
|
4
|
+
$match: query
|
|
5
|
+
}
|
|
6
|
+
];
|
|
7
|
+
if (sort) {
|
|
8
|
+
const $sort = {};
|
|
9
|
+
Object.entries(sort).forEach(([key, value])=>{
|
|
10
|
+
$sort[key] = value === 'desc' ? -1 : 1;
|
|
11
|
+
});
|
|
12
|
+
aggregation.push({
|
|
13
|
+
$sort
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
if (page) {
|
|
17
|
+
aggregation.push({
|
|
18
|
+
$skip: (page - 1) * (limit ?? 0)
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
if (limit) {
|
|
22
|
+
aggregation.push({
|
|
23
|
+
$limit: limit
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
if (joinAggregation) {
|
|
27
|
+
for (const stage of joinAggregation){
|
|
28
|
+
aggregation.push(stage);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
if (projection) {
|
|
32
|
+
aggregation.push({
|
|
33
|
+
$project: projection
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
let countPromise = Promise.resolve(null);
|
|
37
|
+
if (pagination !== false && limit) {
|
|
38
|
+
if (useEstimatedCount) {
|
|
39
|
+
countPromise = Model.estimatedDocumentCount(query);
|
|
40
|
+
} else {
|
|
41
|
+
const hint = adapter.disableIndexHints !== true ? {
|
|
42
|
+
_id: 1
|
|
43
|
+
} : undefined;
|
|
44
|
+
countPromise = Model.countDocuments(query, {
|
|
45
|
+
collation,
|
|
46
|
+
hint,
|
|
47
|
+
session
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
const [docs, countResult] = await Promise.all([
|
|
52
|
+
Model.aggregate(aggregation, {
|
|
53
|
+
collation,
|
|
54
|
+
session
|
|
55
|
+
}),
|
|
56
|
+
countPromise
|
|
57
|
+
]);
|
|
58
|
+
const count = countResult === null ? docs.length : countResult;
|
|
59
|
+
const totalPages = pagination !== false && typeof limit === 'number' && limit !== 0 ? Math.ceil(count / limit) : 1;
|
|
60
|
+
const hasPrevPage = typeof page === 'number' && pagination !== false && page > 1;
|
|
61
|
+
const hasNextPage = typeof page === 'number' && pagination !== false && totalPages > page;
|
|
62
|
+
const pagingCounter = typeof page === 'number' && pagination !== false && typeof limit === 'number' ? (page - 1) * limit + 1 : 1;
|
|
63
|
+
const result = {
|
|
64
|
+
docs,
|
|
65
|
+
hasNextPage,
|
|
66
|
+
hasPrevPage,
|
|
67
|
+
limit: limit ?? 0,
|
|
68
|
+
nextPage: hasNextPage ? page + 1 : null,
|
|
69
|
+
page,
|
|
70
|
+
pagingCounter,
|
|
71
|
+
prevPage: hasPrevPage ? page - 1 : null,
|
|
72
|
+
totalDocs: count,
|
|
73
|
+
totalPages
|
|
74
|
+
};
|
|
75
|
+
return result;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
//# sourceMappingURL=aggregatePaginate.js.map
|
|
@@ -0,0 +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 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 useEstimatedCount?: boolean\n}): Promise<PaginatedDocs<any>> => {\n const aggregation: PipelineStage[] = [{ $match: query }]\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 = adapter.disableIndexHints !== true ? { _id: 1 } : undefined\n countPromise = Model.countDocuments(query, { collation, hint, session })\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","useEstimatedCount","aggregation","$match","$sort","Object","entries","forEach","key","value","push","$skip","$limit","stage","$project","countPromise","Promise","resolve","estimatedDocumentCount","hint","disableIndexHints","_id","undefined","countDocuments","docs","countResult","all","aggregate","count","length","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,iBAAiB,EAclB;IACC,MAAMC,cAA+B;QAAC;YAAEC,QAAQL;QAAM;KAAE;IAExD,IAAIE,MAAM;QACR,MAAMI,QAAgC,CAAC;QAEvCC,OAAOC,OAAO,CAACN,MAAMO,OAAO,CAAC,CAAC,CAACC,KAAKC,MAAM;YACxCL,KAAK,CAACI,IAAI,GAAGC,UAAU,SAAS,CAAC,IAAI;QACvC;QAEAP,Y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AAAA,OAAO,CAAA,IAAKF,QAAQ,IACrB;IAEN,MAAM2C,SAAwB;QAC5BZ;QACAU;QACAD;QACAxC,OAAOA,SAAS;QAChB4C,UAAUH,cAAcvC,OAAO,IAAI;QACnCA;QACAwC;QACAG,UAAUL,cAActC,OAAO,IAAI;QACnC4C,WAAWX;QACXE;IACF;IAEA,OAAOM;AACT,EAAC"}
|
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
import type { PipelineStage } from 'mongoose';
|
|
2
|
-
import type
|
|
2
|
+
import { type CollectionSlug, type JoinQuery, type SanitizedCollectionConfig } from 'payload';
|
|
3
3
|
import type { MongooseAdapter } from '../index.js';
|
|
4
4
|
type BuildJoinAggregationArgs = {
|
|
5
5
|
adapter: MongooseAdapter;
|
|
6
6
|
collection: CollectionSlug;
|
|
7
7
|
collectionConfig: SanitizedCollectionConfig;
|
|
8
|
-
joins
|
|
9
|
-
|
|
10
|
-
locale: string;
|
|
8
|
+
joins?: JoinQuery;
|
|
9
|
+
locale?: string;
|
|
11
10
|
projection?: Record<string, true>;
|
|
12
|
-
query?:
|
|
11
|
+
query?: Record<string, unknown>;
|
|
13
12
|
/** whether the query is from drafts */
|
|
14
13
|
versions?: boolean;
|
|
15
14
|
};
|
|
16
|
-
export declare const buildJoinAggregation: ({ adapter, collection, collectionConfig, joins,
|
|
15
|
+
export declare const buildJoinAggregation: ({ adapter, collection, collectionConfig, joins, locale, projection, versions, }: BuildJoinAggregationArgs) => Promise<PipelineStage[] | undefined>;
|
|
17
16
|
export {};
|
|
18
17
|
//# sourceMappingURL=buildJoinAggregation.d.ts.map
|
|
@@ -1 +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;
|
|
1
|
+
{"version":3,"file":"buildJoinAggregation.d.ts","sourceRoot":"","sources":["../../src/utilities/buildJoinAggregation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAE7C,OAAO,EAEL,KAAK,cAAc,EAEnB,KAAK,SAAS,EACd,KAAK,yBAAyB,EAC/B,MAAM,SAAS,CAAA;AAGhB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAMlD,KAAK,wBAAwB,GAAG;IAC9B,OAAO,EAAE,eAAe,CAAA;IACxB,UAAU,EAAE,cAAc,CAAA;IAC1B,gBAAgB,EAAE,yBAAyB,CAAA;IAC3C,KAAK,CAAC,EAAE,SAAS,CAAA;IACjB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAA;IAEjC,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC/B,uCAAuC;IACvC,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB,CAAA;AAED,eAAO,MAAM,oBAAoB,oFAQ9B,wBAAwB,KAAG,OAAO,CAAC,aAAa,EAAE,GAAG,SAAS,CAgahE,CAAA"}
|