@payloadcms/db-mongodb 3.25.0-canary.f62445f → 3.25.0
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/create.js +15 -15
- package/dist/create.js.map +1 -1
- package/dist/createGlobal.d.ts.map +1 -1
- package/dist/createGlobal.js +15 -14
- package/dist/createGlobal.js.map +1 -1
- package/dist/createGlobalVersion.d.ts.map +1 -1
- package/dist/createGlobalVersion.js +26 -23
- package/dist/createGlobalVersion.js.map +1 -1
- package/dist/createVersion.d.ts.map +1 -1
- package/dist/createVersion.js +26 -31
- package/dist/createVersion.js.map +1 -1
- package/dist/deleteOne.d.ts.map +1 -1
- package/dist/deleteOne.js +8 -6
- package/dist/deleteOne.js.map +1 -1
- package/dist/find.d.ts.map +1 -1
- package/dist/find.js +8 -9
- package/dist/find.js.map +1 -1
- package/dist/findGlobal.d.ts.map +1 -1
- package/dist/findGlobal.js +10 -9
- package/dist/findGlobal.js.map +1 -1
- package/dist/findGlobalVersions.d.ts.map +1 -1
- package/dist/findGlobalVersions.js +10 -10
- package/dist/findGlobalVersions.js.map +1 -1
- package/dist/findOne.d.ts.map +1 -1
- package/dist/findOne.js +8 -6
- package/dist/findOne.js.map +1 -1
- package/dist/findVersions.js +8 -9
- package/dist/findVersions.js.map +1 -1
- package/dist/models/buildSchema.js +2 -0
- package/dist/models/buildSchema.js.map +1 -1
- package/dist/predefinedMigrations/migrateRelationshipsV2_V3.d.ts.map +1 -1
- package/dist/predefinedMigrations/migrateRelationshipsV2_V3.js +12 -7
- package/dist/predefinedMigrations/migrateRelationshipsV2_V3.js.map +1 -1
- package/dist/queries/buildSearchParams.d.ts.map +1 -1
- package/dist/queries/buildSearchParams.js +16 -0
- package/dist/queries/buildSearchParams.js.map +1 -1
- package/dist/queryDrafts.js +13 -13
- package/dist/queryDrafts.js.map +1 -1
- package/dist/updateGlobal.d.ts.map +1 -1
- package/dist/updateGlobal.js +15 -15
- package/dist/updateGlobal.js.map +1 -1
- package/dist/updateGlobalVersion.d.ts.map +1 -1
- package/dist/updateGlobalVersion.js +13 -13
- package/dist/updateGlobalVersion.js.map +1 -1
- package/dist/updateOne.d.ts.map +1 -1
- package/dist/updateOne.js +12 -9
- package/dist/updateOne.js.map +1 -1
- package/dist/updateVersion.d.ts.map +1 -1
- package/dist/updateVersion.js +13 -13
- package/dist/updateVersion.js.map +1 -1
- package/dist/utilities/buildJoinAggregation.d.ts.map +1 -1
- package/dist/utilities/buildJoinAggregation.js +103 -34
- package/dist/utilities/buildJoinAggregation.js.map +1 -1
- package/dist/utilities/transform.d.ts +27 -0
- package/dist/utilities/transform.d.ts.map +1 -0
- package/dist/utilities/transform.js +224 -0
- package/dist/utilities/transform.js.map +1 -0
- package/dist/utilities/{sanitizeRelationshipIDs.spec.js → transform.spec.js} +11 -5
- package/dist/utilities/transform.spec.js.map +1 -0
- package/package.json +3 -3
- package/dist/utilities/sanitizeInternalFields.d.ts +0 -2
- package/dist/utilities/sanitizeInternalFields.d.ts.map +0 -1
- package/dist/utilities/sanitizeInternalFields.js +0 -20
- package/dist/utilities/sanitizeInternalFields.js.map +0 -1
- package/dist/utilities/sanitizeRelationshipIDs.d.ts +0 -10
- package/dist/utilities/sanitizeRelationshipIDs.d.ts.map +0 -1
- package/dist/utilities/sanitizeRelationshipIDs.js +0 -130
- package/dist/utilities/sanitizeRelationshipIDs.js.map +0 -1
- package/dist/utilities/sanitizeRelationshipIDs.spec.js.map +0 -1
package/dist/queryDrafts.js
CHANGED
|
@@ -4,7 +4,7 @@ import { buildSortParam } from './queries/buildSortParam.js';
|
|
|
4
4
|
import { buildJoinAggregation } from './utilities/buildJoinAggregation.js';
|
|
5
5
|
import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js';
|
|
6
6
|
import { getSession } from './utilities/getSession.js';
|
|
7
|
-
import {
|
|
7
|
+
import { transform } from './utilities/transform.js';
|
|
8
8
|
export const queryDrafts = async function queryDrafts({ collection, joins, limit, locale, page, pagination, req, select, sort: sortArg, where }) {
|
|
9
9
|
const VersionModel = this.versions[collection];
|
|
10
10
|
const collectionConfig = this.payload.collections[collection].config;
|
|
@@ -97,18 +97,18 @@ export const queryDrafts = async function queryDrafts({ collection, joins, limit
|
|
|
97
97
|
} else {
|
|
98
98
|
result = await VersionModel.paginate(versionQuery, paginationOptions);
|
|
99
99
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
100
|
+
transform({
|
|
101
|
+
adapter: this,
|
|
102
|
+
data: result.docs,
|
|
103
|
+
fields: buildVersionCollectionFields(this.payload.config, collectionConfig),
|
|
104
|
+
operation: 'read'
|
|
105
|
+
});
|
|
106
|
+
for(let i = 0; i < result.docs.length; i++){
|
|
107
|
+
const id = result.docs[i].parent;
|
|
108
|
+
result.docs[i] = result.docs[i].version;
|
|
109
|
+
result.docs[i].id = id;
|
|
110
|
+
}
|
|
111
|
+
return result;
|
|
112
112
|
};
|
|
113
113
|
|
|
114
114
|
//# sourceMappingURL=queryDrafts.js.map
|
package/dist/queryDrafts.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/queryDrafts.ts"],"sourcesContent":["import type { PaginateOptions, QueryOptions } from 'mongoose'\nimport type { QueryDrafts } from 'payload'\n\nimport { buildVersionCollectionFields, combineQueries, flattenWhereToOperators } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { buildSortParam } from './queries/buildSortParam.js'\nimport { buildJoinAggregation } from './utilities/buildJoinAggregation.js'\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getSession } from './utilities/getSession.js'\nimport {
|
|
1
|
+
{"version":3,"sources":["../src/queryDrafts.ts"],"sourcesContent":["import type { PaginateOptions, QueryOptions } from 'mongoose'\nimport type { QueryDrafts } from 'payload'\n\nimport { buildVersionCollectionFields, combineQueries, flattenWhereToOperators } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { buildSortParam } from './queries/buildSortParam.js'\nimport { buildJoinAggregation } from './utilities/buildJoinAggregation.js'\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getSession } from './utilities/getSession.js'\nimport { transform } from './utilities/transform.js'\n\nexport const queryDrafts: QueryDrafts = async function queryDrafts(\n this: MongooseAdapter,\n { collection, joins, limit, locale, page, pagination, req, select, sort: sortArg, where },\n) {\n const VersionModel = this.versions[collection]\n const collectionConfig = this.payload.collections[collection].config\n const options: QueryOptions = {\n session: await getSession(this, req),\n }\n\n let hasNearConstraint\n let sort\n\n if (where) {\n const constraints = flattenWhereToOperators(where)\n hasNearConstraint = constraints.some((prop) => Object.keys(prop).some((key) => key === 'near'))\n }\n\n if (!hasNearConstraint) {\n sort = buildSortParam({\n config: this.payload.config,\n fields: collectionConfig.flattenedFields,\n locale,\n sort: sortArg || collectionConfig.defaultSort,\n timestamps: true,\n })\n }\n\n const combinedWhere = combineQueries({ latest: { equals: true } }, where)\n\n const fields = buildVersionCollectionFields(this.payload.config, collectionConfig, true)\n const versionQuery = await buildQuery({\n adapter: this,\n fields,\n locale,\n where: combinedWhere,\n })\n\n const projection = buildProjectionFromSelect({\n adapter: this,\n fields,\n select,\n })\n // useEstimatedCount is faster, but not accurate, as it ignores any filters. It is thus set to true if there are no filters.\n const useEstimatedCount =\n hasNearConstraint || !versionQuery || Object.keys(versionQuery).length === 0\n const paginationOptions: PaginateOptions = {\n lean: true,\n leanWithId: true,\n options,\n page,\n pagination,\n projection,\n sort,\n useEstimatedCount,\n }\n\n if (this.collation) {\n const defaultLocale = 'en'\n paginationOptions.collation = {\n locale: locale && locale !== 'all' && locale !== '*' ? locale : defaultLocale,\n ...this.collation,\n }\n }\n\n if (\n !useEstimatedCount &&\n Object.keys(versionQuery).length === 0 &&\n this.disableIndexHints !== true\n ) {\n // Improve the performance of the countDocuments query which is used if useEstimatedCount is set to false by adding\n // a hint. By default, if no hint is provided, MongoDB does not use an indexed field to count the returned documents,\n // which makes queries very slow. This only happens when no query (filter) is provided. If one is provided, it uses\n // the correct indexed field\n paginationOptions.useCustomCountFn = () => {\n return Promise.resolve(\n VersionModel.countDocuments(versionQuery, {\n hint: { _id: 1 },\n }),\n )\n }\n }\n\n if (limit > 0) {\n paginationOptions.limit = limit\n // limit must also be set here, it's ignored when pagination is false\n paginationOptions.options.limit = limit\n }\n\n let result\n\n const aggregate = await buildJoinAggregation({\n adapter: this,\n collection,\n collectionConfig,\n joins,\n locale,\n projection,\n query: versionQuery,\n versions: true,\n })\n\n // build join aggregation\n if (aggregate) {\n result = await VersionModel.aggregatePaginate(\n VersionModel.aggregate(aggregate),\n paginationOptions,\n )\n } else {\n result = await VersionModel.paginate(versionQuery, paginationOptions)\n }\n\n transform({\n adapter: this,\n data: result.docs,\n fields: buildVersionCollectionFields(this.payload.config, collectionConfig),\n operation: 'read',\n })\n\n for (let i = 0; i < result.docs.length; i++) {\n const id = result.docs[i].parent\n result.docs[i] = result.docs[i].version\n result.docs[i].id = id\n }\n\n return result\n}\n"],"names":["buildVersionCollectionFields","combineQueries","flattenWhereToOperators","buildQuery","buildSortParam","buildJoinAggregation","buildProjectionFromSelect","getSession","transform","queryDrafts","collection","joins","limit","locale","page","pagination","req","select","sort","sortArg","where","VersionModel","versions","collectionConfig","payload","collections","config","options","session","hasNearConstraint","constraints","some","prop","Object","keys","key","fields","flattenedFields","defaultSort","timestamps","combinedWhere","latest","equals","versionQuery","adapter","projection","useEstimatedCount","length","paginationOptions","lean","leanWithId","collation","defaultLocale","disableIndexHints","useCustomCountFn","Promise","resolve","countDocuments","hint","_id","result","aggregate","query","aggregatePaginate","paginate","data","docs","operation","i","id","parent","version"],"mappings":"AAGA,SAASA,4BAA4B,EAAEC,cAAc,EAAEC,uB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,SAAS,IAAI;QACbqB,MAAML,OAAOM,IAAI;QACjB9B,QAAQpC,6BAA6B,IAAI,CAACwB,OAAO,CAACE,MAAM,EAAEH;QAC1D4C,WAAW;IACb;IAEA,IAAK,IAAIC,IAAI,GAAGA,IAAIR,OAAOM,IAAI,CAACnB,MAAM,EAAEqB,IAAK;QAC3C,MAAMC,KAAKT,OAAOM,IAAI,CAACE,EAAE,CAACE,MAAM;QAChCV,OAAOM,IAAI,CAACE,EAAE,GAAGR,OAAOM,IAAI,CAACE,EAAE,CAACG,OAAO;QACvCX,OAAOM,IAAI,CAACE,EAAE,CAACC,EAAE,GAAGA;IACtB;IAEA,OAAOT;AACT,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"updateGlobal.d.ts","sourceRoot":"","sources":["../src/updateGlobal.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"updateGlobal.d.ts","sourceRoot":"","sources":["../src/updateGlobal.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAQ3C,eAAO,MAAM,YAAY,EAAE,YA0B1B,CAAA"}
|
package/dist/updateGlobal.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js';
|
|
2
2
|
import { getSession } from './utilities/getSession.js';
|
|
3
|
-
import {
|
|
4
|
-
import { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.js';
|
|
3
|
+
import { transform } from './utilities/transform.js';
|
|
5
4
|
export const updateGlobal = async function updateGlobal({ slug, data, options: optionsArgs = {}, req, select }) {
|
|
6
5
|
const Model = this.globals;
|
|
7
6
|
const fields = this.payload.config.globals.find((global)=>global.slug === slug).fields;
|
|
@@ -16,22 +15,23 @@ export const updateGlobal = async function updateGlobal({ slug, data, options: o
|
|
|
16
15
|
}),
|
|
17
16
|
session: await getSession(this, req)
|
|
18
17
|
};
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
config: this.payload.config,
|
|
18
|
+
transform({
|
|
19
|
+
adapter: this,
|
|
22
20
|
data,
|
|
23
|
-
fields
|
|
21
|
+
fields,
|
|
22
|
+
globalSlug: slug,
|
|
23
|
+
operation: 'write'
|
|
24
24
|
});
|
|
25
|
-
result = await Model.findOneAndUpdate({
|
|
25
|
+
const result = await Model.findOneAndUpdate({
|
|
26
26
|
globalType: slug
|
|
27
|
-
},
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
27
|
+
}, data, options);
|
|
28
|
+
transform({
|
|
29
|
+
adapter: this,
|
|
30
|
+
data: result,
|
|
31
|
+
fields,
|
|
32
|
+
globalSlug: slug,
|
|
33
|
+
operation: 'read'
|
|
34
|
+
});
|
|
35
35
|
return result;
|
|
36
36
|
};
|
|
37
37
|
|
package/dist/updateGlobal.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/updateGlobal.ts"],"sourcesContent":["import type { QueryOptions } from 'mongoose'\nimport type { UpdateGlobal } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getSession } from './utilities/getSession.js'\nimport {
|
|
1
|
+
{"version":3,"sources":["../src/updateGlobal.ts"],"sourcesContent":["import type { QueryOptions } from 'mongoose'\nimport type { UpdateGlobal } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getSession } from './utilities/getSession.js'\nimport { transform } from './utilities/transform.js'\n\nexport const updateGlobal: UpdateGlobal = async function updateGlobal(\n this: MongooseAdapter,\n { slug, data, options: optionsArgs = {}, req, select },\n) {\n const Model = this.globals\n const fields = this.payload.config.globals.find((global) => global.slug === slug).fields\n\n const options: QueryOptions = {\n ...optionsArgs,\n lean: true,\n new: true,\n projection: buildProjectionFromSelect({\n adapter: this,\n fields: this.payload.config.globals.find((global) => global.slug === slug).flattenedFields,\n select,\n }),\n session: await getSession(this, req),\n }\n\n transform({ adapter: this, data, fields, globalSlug: slug, operation: 'write' })\n\n const result: any = await Model.findOneAndUpdate({ globalType: slug }, data, options)\n\n transform({ adapter: this, data: result, fields, globalSlug: slug, operation: 'read' })\n\n return result\n}\n"],"names":["buildProjectionFromSelect","getSession","transform","updateGlobal","slug","data","options","optionsArgs","req","select","Model","globals","fields","payload","config","find","global","lean","new","projection","adapter","flattenedFields","session","globalSlug","operation","result","findOneAndUpdate","globalType"],"mappings":"AAKA,SAASA,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAASC,SAAS,QAAQ,2BAA0B;AAEpD,OAAO,MAAMC,eAA6B,eAAeA,aAEvD,EAAEC,IAAI,EAAEC,IAAI,EAAEC,SAASC,cAAc,CAAC,CAAC,EAAEC,GAAG,EAAEC,MAAM,EAAE;IAEtD,MAAMC,QAAQ,IAAI,CAACC,OAAO;IAC1B,MAAMC,SAAS,IAAI,CAACC,OAAO,CAACC,MAAM,CAACH,OAAO,CAACI,IAAI,CAAC,CAACC,SAAWA,OAAOZ,IAAI,KAAKA,MAAMQ,MAAM;IAExF,MAAMN,UAAwB;QAC5B,GAAGC,WAAW;QACdU,MAAM;QACNC,KAAK;QACLC,YAAYnB,0BAA0B;YACpCoB,SAAS,IAAI;YACbR,QAAQ,IAAI,CAACC,OAAO,CAACC,MAAM,CAACH,OAAO,CAACI,IAAI,CAAC,CAACC,SAAWA,OAAOZ,IAAI,KAAKA,MAAMiB,eAAe;YAC1FZ;QACF;QACAa,SAAS,MAAMrB,WAAW,IAAI,EAAEO;IAClC;IAEAN,UAAU;QAAEkB,SAAS,IAAI;QAAEf;QAAMO;QAAQW,YAAYnB;QAAMoB,WAAW;IAAQ;IAE9E,MAAMC,SAAc,MAAMf,MAAMgB,gBAAgB,CAAC;QAAEC,YAAYvB;IAAK,GAAGC,MAAMC;IAE7EJ,UAAU;QAAEkB,SAAS,IAAI;QAAEf,MAAMoB;QAAQb;QAAQW,YAAYnB;QAAMoB,WAAW;IAAO;IAErF,OAAOC;AACT,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"updateGlobalVersion.d.ts","sourceRoot":"","sources":["../src/updateGlobalVersion.ts"],"names":[],"mappings":"AAEA,OAAO,EAA4B,KAAK,UAAU,EAAE,KAAK,uBAAuB,EAAE,MAAM,SAAS,CAAA;AAEjG,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAOjD,wBAAsB,mBAAmB,CAAC,CAAC,SAAS,UAAU,EAC5D,IAAI,EAAE,eAAe,EACrB,EACE,EAAE,EACF,MAAM,EAAE,UAAU,EAClB,MAAM,EACN,OAAO,EAAE,WAAgB,EACzB,GAAG,EACH,MAAM,EACN,WAAW,EACX,KAAK,GACN,EAAE,uBAAuB,CAAC,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"updateGlobalVersion.d.ts","sourceRoot":"","sources":["../src/updateGlobalVersion.ts"],"names":[],"mappings":"AAEA,OAAO,EAA4B,KAAK,UAAU,EAAE,KAAK,uBAAuB,EAAE,MAAM,SAAS,CAAA;AAEjG,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAOjD,wBAAsB,mBAAmB,CAAC,CAAC,SAAS,UAAU,EAC5D,IAAI,EAAE,eAAe,EACrB,EACE,EAAE,EACF,MAAM,EAAE,UAAU,EAClB,MAAM,EACN,OAAO,EAAE,WAAgB,EACzB,GAAG,EACH,MAAM,EACN,WAAW,EACX,KAAK,GACN,EAAE,uBAAuB,CAAC,CAAC,CAAC,gBAsC9B"}
|
|
@@ -2,7 +2,7 @@ import { buildVersionGlobalFields } from 'payload';
|
|
|
2
2
|
import { buildQuery } from './queries/buildQuery.js';
|
|
3
3
|
import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js';
|
|
4
4
|
import { getSession } from './utilities/getSession.js';
|
|
5
|
-
import {
|
|
5
|
+
import { transform } from './utilities/transform.js';
|
|
6
6
|
export async function updateGlobalVersion({ id, global: globalSlug, locale, options: optionsArgs = {}, req, select, versionData, where }) {
|
|
7
7
|
const VersionModel = this.versions[globalSlug];
|
|
8
8
|
const whereToUse = where || {
|
|
@@ -30,23 +30,23 @@ export async function updateGlobalVersion({ id, global: globalSlug, locale, opti
|
|
|
30
30
|
locale,
|
|
31
31
|
where: whereToUse
|
|
32
32
|
});
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
transform({
|
|
34
|
+
adapter: this,
|
|
35
35
|
data: versionData,
|
|
36
|
-
fields
|
|
36
|
+
fields,
|
|
37
|
+
operation: 'write'
|
|
37
38
|
});
|
|
38
|
-
const doc = await VersionModel.findOneAndUpdate(query,
|
|
39
|
+
const doc = await VersionModel.findOneAndUpdate(query, versionData, options);
|
|
39
40
|
if (!doc) {
|
|
40
41
|
return null;
|
|
41
42
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
return result;
|
|
43
|
+
transform({
|
|
44
|
+
adapter: this,
|
|
45
|
+
data: doc,
|
|
46
|
+
fields,
|
|
47
|
+
operation: 'read'
|
|
48
|
+
});
|
|
49
|
+
return doc;
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
//# sourceMappingURL=updateGlobalVersion.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/updateGlobalVersion.ts"],"sourcesContent":["import type { QueryOptions } from 'mongoose'\n\nimport { buildVersionGlobalFields, type TypeWithID, type UpdateGlobalVersionArgs } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getSession } from './utilities/getSession.js'\nimport {
|
|
1
|
+
{"version":3,"sources":["../src/updateGlobalVersion.ts"],"sourcesContent":["import type { QueryOptions } from 'mongoose'\n\nimport { buildVersionGlobalFields, type TypeWithID, type UpdateGlobalVersionArgs } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getSession } from './utilities/getSession.js'\nimport { transform } from './utilities/transform.js'\n\nexport async function updateGlobalVersion<T extends TypeWithID>(\n this: MongooseAdapter,\n {\n id,\n global: globalSlug,\n locale,\n options: optionsArgs = {},\n req,\n select,\n versionData,\n where,\n }: UpdateGlobalVersionArgs<T>,\n) {\n const VersionModel = this.versions[globalSlug]\n const whereToUse = where || { id: { equals: id } }\n\n const currentGlobal = this.payload.config.globals.find((global) => global.slug === globalSlug)\n const fields = buildVersionGlobalFields(this.payload.config, currentGlobal)\n const flattenedFields = buildVersionGlobalFields(this.payload.config, currentGlobal, true)\n const options: QueryOptions = {\n ...optionsArgs,\n lean: true,\n new: true,\n projection: buildProjectionFromSelect({\n adapter: this,\n fields: flattenedFields,\n select,\n }),\n session: await getSession(this, req),\n }\n\n const query = await buildQuery({\n adapter: this,\n fields: flattenedFields,\n locale,\n where: whereToUse,\n })\n\n transform({ adapter: this, data: versionData, fields, operation: 'write' })\n\n const doc = await VersionModel.findOneAndUpdate(query, versionData, options)\n\n if (!doc) {\n return null\n }\n\n transform({ adapter: this, data: doc, fields, operation: 'read' })\n\n return doc\n}\n"],"names":["buildVersionGlobalFields","buildQuery","buildProjectionFromSelect","getSession","transform","updateGlobalVersion","id","global","globalSlug","locale","options","optionsArgs","req","select","versionData","where","VersionModel","versions","whereToUse","equals","currentGlobal","payload","config","globals","find","slug","fields","flattenedFields","lean","new","projection","adapter","session","query","data","operation","doc","findOneAndUpdate"],"mappings":"AAEA,SAASA,wBAAwB,QAAuD,UAAS;AAIjG,SA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"}
|
package/dist/updateOne.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"updateOne.d.ts","sourceRoot":"","sources":["../src/updateOne.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"updateOne.d.ts","sourceRoot":"","sources":["../src/updateOne.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAUxC,eAAO,MAAM,SAAS,EAAE,SA4CvB,CAAA"}
|
package/dist/updateOne.js
CHANGED
|
@@ -2,8 +2,7 @@ import { buildQuery } from './queries/buildQuery.js';
|
|
|
2
2
|
import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js';
|
|
3
3
|
import { getSession } from './utilities/getSession.js';
|
|
4
4
|
import { handleError } from './utilities/handleError.js';
|
|
5
|
-
import {
|
|
6
|
-
import { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.js';
|
|
5
|
+
import { transform } from './utilities/transform.js';
|
|
7
6
|
export const updateOne = async function updateOne({ id, collection, data, locale, options: optionsArgs = {}, req, select, where: whereArg }) {
|
|
8
7
|
const where = id ? {
|
|
9
8
|
id: {
|
|
@@ -31,13 +30,14 @@ export const updateOne = async function updateOne({ id, collection, data, locale
|
|
|
31
30
|
where
|
|
32
31
|
});
|
|
33
32
|
let result;
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
transform({
|
|
34
|
+
adapter: this,
|
|
36
35
|
data,
|
|
37
|
-
fields
|
|
36
|
+
fields,
|
|
37
|
+
operation: 'write'
|
|
38
38
|
});
|
|
39
39
|
try {
|
|
40
|
-
result = await Model.findOneAndUpdate(query,
|
|
40
|
+
result = await Model.findOneAndUpdate(query, data, options);
|
|
41
41
|
} catch (error) {
|
|
42
42
|
handleError({
|
|
43
43
|
collection,
|
|
@@ -48,9 +48,12 @@ export const updateOne = async function updateOne({ id, collection, data, locale
|
|
|
48
48
|
if (!result) {
|
|
49
49
|
return null;
|
|
50
50
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
51
|
+
transform({
|
|
52
|
+
adapter: this,
|
|
53
|
+
data: result,
|
|
54
|
+
fields,
|
|
55
|
+
operation: 'read'
|
|
56
|
+
});
|
|
54
57
|
return result;
|
|
55
58
|
};
|
|
56
59
|
|
package/dist/updateOne.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/updateOne.ts"],"sourcesContent":["import type { QueryOptions } from 'mongoose'\nimport type { UpdateOne } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getSession } from './utilities/getSession.js'\nimport { handleError } from './utilities/handleError.js'\nimport {
|
|
1
|
+
{"version":3,"sources":["../src/updateOne.ts"],"sourcesContent":["import type { QueryOptions } from 'mongoose'\nimport type { UpdateOne } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getSession } from './utilities/getSession.js'\nimport { handleError } from './utilities/handleError.js'\nimport { transform } from './utilities/transform.js'\n\nexport const updateOne: UpdateOne = async function updateOne(\n this: MongooseAdapter,\n { id, collection, data, locale, options: optionsArgs = {}, req, select, where: whereArg },\n) {\n const where = id ? { id: { equals: id } } : whereArg\n const Model = this.collections[collection]\n const fields = this.payload.collections[collection].config.fields\n const options: QueryOptions = {\n ...optionsArgs,\n lean: true,\n new: true,\n projection: buildProjectionFromSelect({\n adapter: this,\n fields: this.payload.collections[collection].config.flattenedFields,\n select,\n }),\n session: await getSession(this, req),\n }\n\n const query = await buildQuery({\n adapter: this,\n collectionSlug: collection,\n fields: this.payload.collections[collection].config.flattenedFields,\n locale,\n where,\n })\n\n let result\n\n transform({ adapter: this, data, fields, operation: 'write' })\n\n try {\n result = await Model.findOneAndUpdate(query, data, options)\n } catch (error) {\n handleError({ collection, error, req })\n }\n\n if (!result) {\n return null\n }\n\n transform({ adapter: this, data: result, fields, operation: 'read' })\n\n return result\n}\n"],"names":["buildQuery","buildProjectionFromSelect","getSession","handleError","transform","updateOne","id","collection","data","locale","options","optionsArgs","req","select","where","whereArg","equals","Model","collections","fields","payload","config","lean","new","projection","adapter","flattenedFields","session","query","collectionSlug","result","operation","findOneAndUpdate","error"],"mappings":"AAKA,SAASA,UAAU,QAAQ,0BAAyB;AACpD,SAASC,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAASC,WAAW,QAAQ,6BAA4B;AACxD,SAASC,SAAS,QAAQ,2BAA0B;AAEpD,OAAO,MAAMC,YAAuB,eAAeA,UAEjD,EAAEC,EAAE,EAAEC,UAAU,EAAEC,IAAI,EAAEC,MAAM,EAAEC,SAASC,cAAc,CAAC,CAAC,EAAEC,GAAG,EAAEC,MAAM,EAAEC,OAAOC,QAAQ,EAAE;IAEzF,MAAMD,QAAQR,KAAK;QAAEA,IAAI;YAAEU,QAAQV;QAAG;IAAE,IAAIS;IAC5C,MAAME,QAAQ,IAAI,CAACC,WAAW,CAACX,WAAW;IAC1C,MAAMY,SAAS,IAAI,CAACC,OAAO,CAACF,WAAW,CAACX,WAAW,CAACc,MAAM,CAACF,MAAM;IACjE,MAAMT,UAAwB;QAC5B,GAAGC,WAAW;QACdW,MAAM;QACNC,KAAK;QACLC,YAAYvB,0BAA0B;YACpCwB,SAAS,IAAI;YACbN,QAAQ,IAAI,CAACC,OAAO,CAACF,WAAW,CAACX,WAAW,CAACc,MAAM,CAACK,eAAe;YACnEb;QACF;QACAc,SAAS,MAAMzB,WAAW,IAAI,EAAEU;IAClC;IAEA,MAAMgB,QAAQ,MAAM5B,WAAW;QAC7ByB,SAAS,IAAI;QACbI,gBAAgBtB;QAChBY,QAAQ,IAAI,CAACC,OAAO,CAACF,WAAW,CAACX,WAAW,CAACc,MAAM,CAACK,eAAe;QACnEjB;QACAK;IACF;IAEA,IAAIgB;IAEJ1B,UAAU;QAAEqB,SAAS,IAAI;QAAEjB;QAAMW;QAAQY,WAAW;IAAQ;IAE5D,IAAI;QACFD,SAAS,MAAMb,MAAMe,gBAAgB,CAACJ,OAAOpB,MAAME;IACrD,EAAE,OAAOuB,OAAO;QACd9B,YAAY;YAAEI;YAAY0B;YAAOrB;QAAI;IACvC;IAEA,IAAI,CAACkB,QAAQ;QACX,OAAO;IACT;IAEA1B,UAAU;QAAEqB,SAAS,IAAI;QAAEjB,MAAMsB;QAAQX;QAAQY,WAAW;IAAO;IAEnE,OAAOD;AACT,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"updateVersion.d.ts","sourceRoot":"","sources":["../src/updateVersion.ts"],"names":[],"mappings":"AAEA,OAAO,EAAgC,KAAK,aAAa,EAAE,MAAM,SAAS,CAAA;AAS1E,eAAO,MAAM,aAAa,EAAE,
|
|
1
|
+
{"version":3,"file":"updateVersion.d.ts","sourceRoot":"","sources":["../src/updateVersion.ts"],"names":[],"mappings":"AAEA,OAAO,EAAgC,KAAK,aAAa,EAAE,MAAM,SAAS,CAAA;AAS1E,eAAO,MAAM,aAAa,EAAE,aA+C3B,CAAA"}
|
package/dist/updateVersion.js
CHANGED
|
@@ -2,7 +2,7 @@ import { buildVersionCollectionFields } from 'payload';
|
|
|
2
2
|
import { buildQuery } from './queries/buildQuery.js';
|
|
3
3
|
import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js';
|
|
4
4
|
import { getSession } from './utilities/getSession.js';
|
|
5
|
-
import {
|
|
5
|
+
import { transform } from './utilities/transform.js';
|
|
6
6
|
export const updateVersion = async function updateVersion({ id, collection, locale, options: optionsArgs = {}, req, select, versionData, where }) {
|
|
7
7
|
const VersionModel = this.versions[collection];
|
|
8
8
|
const whereToUse = where || {
|
|
@@ -29,23 +29,23 @@ export const updateVersion = async function updateVersion({ id, collection, loca
|
|
|
29
29
|
locale,
|
|
30
30
|
where: whereToUse
|
|
31
31
|
});
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
transform({
|
|
33
|
+
adapter: this,
|
|
34
34
|
data: versionData,
|
|
35
|
-
fields
|
|
35
|
+
fields,
|
|
36
|
+
operation: 'write'
|
|
36
37
|
});
|
|
37
|
-
const doc = await VersionModel.findOneAndUpdate(query,
|
|
38
|
+
const doc = await VersionModel.findOneAndUpdate(query, versionData, options);
|
|
38
39
|
if (!doc) {
|
|
39
40
|
return null;
|
|
40
41
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
return result;
|
|
42
|
+
transform({
|
|
43
|
+
adapter: this,
|
|
44
|
+
data: doc,
|
|
45
|
+
fields,
|
|
46
|
+
operation: 'write'
|
|
47
|
+
});
|
|
48
|
+
return doc;
|
|
49
49
|
};
|
|
50
50
|
|
|
51
51
|
//# sourceMappingURL=updateVersion.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/updateVersion.ts"],"sourcesContent":["import type { QueryOptions } from 'mongoose'\n\nimport { buildVersionCollectionFields, type UpdateVersion } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getSession } from './utilities/getSession.js'\nimport {
|
|
1
|
+
{"version":3,"sources":["../src/updateVersion.ts"],"sourcesContent":["import type { QueryOptions } from 'mongoose'\n\nimport { buildVersionCollectionFields, type UpdateVersion } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getSession } from './utilities/getSession.js'\nimport { transform } from './utilities/transform.js'\n\nexport const updateVersion: UpdateVersion = async function updateVersion(\n this: MongooseAdapter,\n { id, collection, locale, options: optionsArgs = {}, req, select, versionData, where },\n) {\n const VersionModel = this.versions[collection]\n const whereToUse = where || { id: { equals: id } }\n const fields = buildVersionCollectionFields(\n this.payload.config,\n this.payload.collections[collection].config,\n )\n\n const flattenedFields = buildVersionCollectionFields(\n this.payload.config,\n this.payload.collections[collection].config,\n true,\n )\n\n const options: QueryOptions = {\n ...optionsArgs,\n lean: true,\n new: true,\n projection: buildProjectionFromSelect({\n adapter: this,\n fields: flattenedFields,\n select,\n }),\n session: await getSession(this, req),\n }\n\n const query = await buildQuery({\n adapter: this,\n fields: flattenedFields,\n locale,\n where: whereToUse,\n })\n\n transform({ adapter: this, data: versionData, fields, operation: 'write' })\n\n const doc = await VersionModel.findOneAndUpdate(query, versionData, options)\n\n if (!doc) {\n return null\n }\n\n transform({ adapter: this, data: doc, fields, operation: 'write' })\n\n return doc\n}\n"],"names":["buildVersionCollectionFields","buildQuery","buildProjectionFromSelect","getSession","transform","updateVersion","id","collection","locale","options","optionsArgs","req","select","versionData","where","VersionModel","versions","whereToUse","equals","fields","payload","config","collections","flattenedFields","lean","new","projection","adapter","session","query","data","operation","doc","findOneAndUpdate"],"mappings":"AAEA,SAASA,4BAA4B,QAA4B,UAAS;AAI1E,SAASC,UAAU,QAAQ,0BAAyB;AACpD,SAASC,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAASC,SAAS,QAAQ,2BAA0B;AAEpD,OAAO,MAAMC,gBAA+B,eAAeA,cAEzD,EAAEC,EAAE,EAAEC,UAAU,EAAEC,MAAM,EAAEC,SAASC,cAAc,CAAC,CAAC,EAAEC,GAAG,EAAEC,MAAM,EAAEC,WAAW,EAAEC,KAAK,EAAE;IAEtF,MAAMC,eAAe,IAAI,CAACC,QAAQ,CAACT,WAAW;IAC9C,MAAMU,aAAaH,SAAS;QAAER,IAAI;YAAEY,QAAQZ;QAAG;IAAE;IACjD,MAAMa,SAASnB,6BACb,IAAI,CAACoB,OAAO,CAACC,MAAM,EACnB,IAAI,CAACD,OAAO,CAACE,WAAW,CAACf,WAAW,CAACc,MAAM;IAG7C,MAAME,kBAAkBvB,6BACtB,IAAI,CAACoB,OAAO,CAACC,MAAM,EACnB,IAAI,CAACD,OAAO,CAACE,WAAW,CAACf,WAAW,CAACc,MAAM,EAC3C;IAGF,MAAMZ,UAAwB;QAC5B,GAAGC,WAAW;QACdc,MAAM;QACNC,KAAK;QACLC,YAAYxB,0BAA0B;YACpCyB,SAAS,IAAI;YACbR,QAAQI;YACRX;QACF;QACAgB,SAAS,MAAMzB,WAAW,IAAI,EAAEQ;IAClC;IAEA,MAAMkB,QAAQ,MAAM5B,WAAW;QAC7B0B,SAAS,IAAI;QACbR,QAAQI;QACRf;QACAM,OAAOG;IACT;IAEAb,UAAU;QAAEuB,SAAS,IAAI;QAAEG,MAAMjB;QAAaM;QAAQY,WAAW;IAAQ;IAEzE,MAAMC,MAAM,MAAMjB,aAAakB,gBAAgB,CAACJ,OAAOhB,aAAaJ;IAEpE,IAAI,CAACuB,KAAK;QACR,OAAO;IACT;IAEA5B,UAAU;QAAEuB,SAAS,IAAI;QAAEG,MAAME;QAAKb;QAAQY,WAAW;IAAQ;IAEjE,OAAOC;AACT,EAAC"}
|
|
@@ -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;AAC7C,OAAO,KAAK,EACV,cAAc,EAEd,SAAS,EACT,yBAAyB,EACzB,KAAK,EACN,MAAM,SAAS,CAAA;AAIhB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAKlD,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;IACd,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAA;IAEjC,KAAK,CAAC,EAAE,KAAK,CAAA;IACb,uCAAuC;IACvC,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB,CAAA;AAED,eAAO,MAAM,oBAAoB,kGAU9B,wBAAwB,KAAG,OAAO,CAAC,aAAa,EAAE,GAAG,SAAS,
|
|
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,EACV,cAAc,EAEd,SAAS,EACT,yBAAyB,EACzB,KAAK,EACN,MAAM,SAAS,CAAA;AAIhB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAKlD,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;IACd,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAA;IAEjC,KAAK,CAAC,EAAE,KAAK,CAAA;IACb,uCAAuC;IACvC,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB,CAAA;AAED,eAAO,MAAM,oBAAoB,kGAU9B,wBAAwB,KAAG,OAAO,CAAC,aAAa,EAAE,GAAG,SAAS,CA8ZhE,CAAA"}
|
|
@@ -31,7 +31,7 @@ export const buildJoinAggregation = async ({ adapter, collection, collectionConf
|
|
|
31
31
|
if (joins?.[join.joinPath] === false) {
|
|
32
32
|
continue;
|
|
33
33
|
}
|
|
34
|
-
const { limit: limitJoin = join.field.defaultLimit ?? 10, page, sort: sortJoin = join.field.defaultSort || collectionConfig.defaultSort, where: whereJoin } = joins?.[join.joinPath] || {};
|
|
34
|
+
const { count = false, limit: limitJoin = join.field.defaultLimit ?? 10, page, sort: sortJoin = join.field.defaultSort || collectionConfig.defaultSort, where: whereJoin } = joins?.[join.joinPath] || {};
|
|
35
35
|
const aggregatedFields = [];
|
|
36
36
|
for (const collectionSlug of join.field.collection){
|
|
37
37
|
for (const field of adapter.payload.collections[collectionSlug].config.flattenedFields){
|
|
@@ -61,6 +61,30 @@ export const buildJoinAggregation = async ({ adapter, collection, collectionConf
|
|
|
61
61
|
for (const collectionSlug of join.field.collection){
|
|
62
62
|
const alias = `${as}.docs.${collectionSlug}`;
|
|
63
63
|
aliases.push(alias);
|
|
64
|
+
const basePipeline = [
|
|
65
|
+
{
|
|
66
|
+
$addFields: {
|
|
67
|
+
relationTo: {
|
|
68
|
+
$literal: collectionSlug
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
$match: {
|
|
74
|
+
$and: [
|
|
75
|
+
{
|
|
76
|
+
$expr: {
|
|
77
|
+
$eq: [
|
|
78
|
+
`$${join.field.on}`,
|
|
79
|
+
'$$root_id_'
|
|
80
|
+
]
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
$match
|
|
84
|
+
]
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
];
|
|
64
88
|
aggregate.push({
|
|
65
89
|
$lookup: {
|
|
66
90
|
as: alias,
|
|
@@ -69,28 +93,7 @@ export const buildJoinAggregation = async ({ adapter, collection, collectionConf
|
|
|
69
93
|
root_id_: '$_id'
|
|
70
94
|
},
|
|
71
95
|
pipeline: [
|
|
72
|
-
|
|
73
|
-
$addFields: {
|
|
74
|
-
relationTo: {
|
|
75
|
-
$literal: collectionSlug
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
},
|
|
79
|
-
{
|
|
80
|
-
$match: {
|
|
81
|
-
$and: [
|
|
82
|
-
{
|
|
83
|
-
$expr: {
|
|
84
|
-
$eq: [
|
|
85
|
-
`$${join.field.on}`,
|
|
86
|
-
'$$root_id_'
|
|
87
|
-
]
|
|
88
|
-
}
|
|
89
|
-
},
|
|
90
|
-
$match
|
|
91
|
-
]
|
|
92
|
-
}
|
|
93
|
-
},
|
|
96
|
+
...basePipeline,
|
|
94
97
|
{
|
|
95
98
|
$sort: {
|
|
96
99
|
[sortProperty]: sortDirection
|
|
@@ -112,6 +115,23 @@ export const buildJoinAggregation = async ({ adapter, collection, collectionConf
|
|
|
112
115
|
]
|
|
113
116
|
}
|
|
114
117
|
});
|
|
118
|
+
if (count) {
|
|
119
|
+
aggregate.push({
|
|
120
|
+
$lookup: {
|
|
121
|
+
as: `${as}.totalDocs.${alias}`,
|
|
122
|
+
from: adapter.collections[collectionSlug].collection.name,
|
|
123
|
+
let: {
|
|
124
|
+
root_id_: '$_id'
|
|
125
|
+
},
|
|
126
|
+
pipeline: [
|
|
127
|
+
...basePipeline,
|
|
128
|
+
{
|
|
129
|
+
$count: 'result'
|
|
130
|
+
}
|
|
131
|
+
]
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
}
|
|
115
135
|
}
|
|
116
136
|
aggregate.push({
|
|
117
137
|
$addFields: {
|
|
@@ -120,6 +140,22 @@ export const buildJoinAggregation = async ({ adapter, collection, collectionConf
|
|
|
120
140
|
}
|
|
121
141
|
}
|
|
122
142
|
});
|
|
143
|
+
if (count) {
|
|
144
|
+
aggregate.push({
|
|
145
|
+
$addFields: {
|
|
146
|
+
[`${as}.totalDocs`]: {
|
|
147
|
+
$add: aliases.map((alias)=>({
|
|
148
|
+
$ifNull: [
|
|
149
|
+
{
|
|
150
|
+
$first: `$${as}.totalDocs.${alias}.result`
|
|
151
|
+
},
|
|
152
|
+
0
|
|
153
|
+
]
|
|
154
|
+
}))
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
}
|
|
123
159
|
aggregate.push({
|
|
124
160
|
$set: {
|
|
125
161
|
[`${as}.docs`]: {
|
|
@@ -138,16 +174,6 @@ export const buildJoinAggregation = async ({ adapter, collection, collectionConf
|
|
|
138
174
|
] : [
|
|
139
175
|
limitJoin
|
|
140
176
|
];
|
|
141
|
-
aggregate.push({
|
|
142
|
-
$set: {
|
|
143
|
-
[`${as}.docs`]: {
|
|
144
|
-
$slice: [
|
|
145
|
-
`$${as}.docs`,
|
|
146
|
-
...sliceValue
|
|
147
|
-
]
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
});
|
|
151
177
|
aggregate.push({
|
|
152
178
|
$addFields: {
|
|
153
179
|
[`${as}.hasNextPage`]: {
|
|
@@ -160,6 +186,16 @@ export const buildJoinAggregation = async ({ adapter, collection, collectionConf
|
|
|
160
186
|
}
|
|
161
187
|
}
|
|
162
188
|
});
|
|
189
|
+
aggregate.push({
|
|
190
|
+
$set: {
|
|
191
|
+
[`${as}.docs`]: {
|
|
192
|
+
$slice: [
|
|
193
|
+
`$${as}.docs`,
|
|
194
|
+
...sliceValue
|
|
195
|
+
]
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
});
|
|
163
199
|
}
|
|
164
200
|
for (const slug of Object.keys(joinConfig)){
|
|
165
201
|
for (const join of joinConfig[slug]){
|
|
@@ -169,7 +205,7 @@ export const buildJoinAggregation = async ({ adapter, collection, collectionConf
|
|
|
169
205
|
if (joins?.[join.joinPath] === false) {
|
|
170
206
|
continue;
|
|
171
207
|
}
|
|
172
|
-
const { limit: limitJoin = join.field.defaultLimit ?? 10, page, sort: sortJoin = join.field.defaultSort || collectionConfig.defaultSort, where: whereJoin } = joins?.[join.joinPath] || {};
|
|
208
|
+
const { count, limit: limitJoin = join.field.defaultLimit ?? 10, page, sort: sortJoin = join.field.defaultSort || collectionConfig.defaultSort, where: whereJoin } = joins?.[join.joinPath] || {};
|
|
173
209
|
if (Array.isArray(join.field.collection)) {
|
|
174
210
|
throw new Error('Unreachable');
|
|
175
211
|
}
|
|
@@ -212,6 +248,33 @@ export const buildJoinAggregation = async ({ adapter, collection, collectionConf
|
|
|
212
248
|
if (Array.isArray(join.targetField.relationTo)) {
|
|
213
249
|
polymorphicSuffix = '.value';
|
|
214
250
|
}
|
|
251
|
+
const addTotalDocsAggregation = (as, foreignField)=>aggregate.push({
|
|
252
|
+
$lookup: {
|
|
253
|
+
as: `${as}.totalDocs`,
|
|
254
|
+
foreignField,
|
|
255
|
+
from: adapter.collections[slug].collection.name,
|
|
256
|
+
localField: versions ? 'parent' : '_id',
|
|
257
|
+
pipeline: [
|
|
258
|
+
{
|
|
259
|
+
$match
|
|
260
|
+
},
|
|
261
|
+
{
|
|
262
|
+
$count: 'result'
|
|
263
|
+
}
|
|
264
|
+
]
|
|
265
|
+
}
|
|
266
|
+
}, {
|
|
267
|
+
$addFields: {
|
|
268
|
+
[`${as}.totalDocs`]: {
|
|
269
|
+
$ifNull: [
|
|
270
|
+
{
|
|
271
|
+
$first: `$${as}.totalDocs.result`
|
|
272
|
+
},
|
|
273
|
+
0
|
|
274
|
+
]
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
});
|
|
215
278
|
if (adapter.payload.config.localization && locale === 'all') {
|
|
216
279
|
adapter.payload.config.localization.localeCodes.forEach((code)=>{
|
|
217
280
|
const as = `${versions ? `version.${join.joinPath}` : join.joinPath}${code}`;
|
|
@@ -254,6 +317,9 @@ export const buildJoinAggregation = async ({ adapter, collection, collectionConf
|
|
|
254
317
|
}
|
|
255
318
|
});
|
|
256
319
|
}
|
|
320
|
+
if (count) {
|
|
321
|
+
addTotalDocsAggregation(as, `${join.field.on}${code}${polymorphicSuffix}`);
|
|
322
|
+
}
|
|
257
323
|
});
|
|
258
324
|
} else {
|
|
259
325
|
const localeSuffix = fieldShouldBeLocalized({
|
|
@@ -296,6 +362,9 @@ export const buildJoinAggregation = async ({ adapter, collection, collectionConf
|
|
|
296
362
|
}
|
|
297
363
|
}
|
|
298
364
|
});
|
|
365
|
+
if (count) {
|
|
366
|
+
addTotalDocsAggregation(as, foreignField);
|
|
367
|
+
}
|
|
299
368
|
if (limitJoin > 0) {
|
|
300
369
|
aggregate.push({
|
|
301
370
|
$addFields: {
|