@payloadcms/db-mongodb 3.2.2-canary.b072173 → 3.2.2-canary.d2399ed
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/count.d.ts.map +1 -1
- package/dist/count.js +19 -21
- package/dist/count.js.map +1 -1
- package/dist/countGlobalVersions.d.ts.map +1 -1
- package/dist/countGlobalVersions.js +19 -21
- package/dist/countGlobalVersions.js.map +1 -1
- package/dist/countVersions.d.ts.map +1 -1
- package/dist/countVersions.js +19 -21
- package/dist/countVersions.js.map +1 -1
- package/dist/create.d.ts.map +1 -1
- package/dist/create.js +22 -22
- package/dist/create.js.map +1 -1
- package/dist/createGlobal.d.ts.map +1 -1
- package/dist/createGlobal.js +21 -19
- package/dist/createGlobal.js.map +1 -1
- package/dist/createGlobalVersion.d.ts.map +1 -1
- package/dist/createGlobalVersion.js +35 -30
- package/dist/createGlobalVersion.js.map +1 -1
- package/dist/createVersion.d.ts.map +1 -1
- package/dist/createVersion.js +35 -30
- package/dist/createVersion.js.map +1 -1
- package/dist/deleteMany.d.ts.map +1 -1
- package/dist/deleteMany.js +6 -6
- package/dist/deleteMany.js.map +1 -1
- package/dist/deleteOne.d.ts.map +1 -1
- package/dist/deleteOne.js +17 -13
- package/dist/deleteOne.js.map +1 -1
- package/dist/deleteVersions.d.ts.map +1 -1
- package/dist/deleteVersions.js +6 -6
- package/dist/deleteVersions.js.map +1 -1
- package/dist/find.d.ts.map +1 -1
- package/dist/find.js +41 -74
- package/dist/find.js.map +1 -1
- package/dist/findGlobal.d.ts.map +1 -1
- package/dist/findGlobal.js +19 -18
- package/dist/findGlobal.js.map +1 -1
- package/dist/findGlobalVersions.d.ts.map +1 -1
- package/dist/findGlobalVersions.js +33 -62
- package/dist/findGlobalVersions.js.map +1 -1
- package/dist/findOne.d.ts.map +1 -1
- package/dist/findOne.js +32 -19
- package/dist/findOne.js.map +1 -1
- package/dist/findVersions.d.ts.map +1 -1
- package/dist/findVersions.js +34 -62
- package/dist/findVersions.js.map +1 -1
- package/dist/{withSession.d.ts → getSession.d.ts} +2 -4
- package/dist/getSession.d.ts.map +1 -0
- package/dist/{withSession.js → getSession.js} +3 -5
- package/dist/getSession.js.map +1 -0
- package/dist/predefinedMigrations/migrateRelationshipsV2_V3.d.ts.map +1 -1
- package/dist/predefinedMigrations/migrateRelationshipsV2_V3.js +20 -16
- package/dist/predefinedMigrations/migrateRelationshipsV2_V3.js.map +1 -1
- package/dist/predefinedMigrations/migrateVersionsV1_V2.js +2 -2
- package/dist/predefinedMigrations/migrateVersionsV1_V2.js.map +1 -1
- package/dist/queries/buildAndOrConditions.d.ts +3 -1
- package/dist/queries/buildAndOrConditions.d.ts.map +1 -1
- package/dist/queries/buildAndOrConditions.js +2 -1
- package/dist/queries/buildAndOrConditions.js.map +1 -1
- package/dist/queries/buildQuery.d.ts +2 -0
- package/dist/queries/buildQuery.d.ts.map +1 -1
- package/dist/queries/buildQuery.js +2 -6
- package/dist/queries/buildQuery.js.map +1 -1
- package/dist/queries/buildSearchParams.d.ts +3 -1
- package/dist/queries/buildSearchParams.d.ts.map +1 -1
- package/dist/queries/buildSearchParams.js +14 -10
- package/dist/queries/buildSearchParams.js.map +1 -1
- package/dist/queries/buildSortParam.d.ts +1 -7
- package/dist/queries/buildSortParam.d.ts.map +1 -1
- package/dist/queries/buildSortParam.js +2 -2
- package/dist/queries/buildSortParam.js.map +1 -1
- package/dist/queries/getLocalizedSortProperty.js +2 -2
- package/dist/queries/getLocalizedSortProperty.js.map +1 -1
- package/dist/queries/parseParams.d.ts +3 -1
- package/dist/queries/parseParams.d.ts.map +1 -1
- package/dist/queries/parseParams.js +2 -1
- package/dist/queries/parseParams.js.map +1 -1
- package/dist/queries/sanitizeQueryValue.d.ts.map +1 -1
- package/dist/queries/sanitizeQueryValue.js +16 -0
- package/dist/queries/sanitizeQueryValue.js.map +1 -1
- package/dist/queryDrafts.d.ts.map +1 -1
- package/dist/queryDrafts.js +41 -65
- package/dist/queryDrafts.js.map +1 -1
- package/dist/updateGlobal.d.ts.map +1 -1
- package/dist/updateGlobal.js +25 -23
- package/dist/updateGlobal.js.map +1 -1
- package/dist/updateGlobalVersion.d.ts.map +1 -1
- package/dist/updateGlobalVersion.js +28 -27
- package/dist/updateGlobalVersion.js.map +1 -1
- package/dist/updateOne.d.ts.map +1 -1
- package/dist/updateOne.js +28 -24
- package/dist/updateOne.js.map +1 -1
- package/dist/updateVersion.d.ts.map +1 -1
- package/dist/updateVersion.js +28 -26
- package/dist/updateVersion.js.map +1 -1
- package/dist/utilities/buildJoinAggregation.d.ts +4 -4
- package/dist/utilities/buildJoinAggregation.d.ts.map +1 -1
- package/dist/utilities/buildJoinAggregation.js +7 -28
- package/dist/utilities/buildJoinAggregation.js.map +1 -1
- package/dist/utilities/buildProjectionFromSelect.d.ts.map +1 -1
- package/dist/utilities/buildProjectionFromSelect.js +18 -1
- package/dist/utilities/buildProjectionFromSelect.js.map +1 -1
- package/dist/utilities/findMany.d.ts +20 -0
- package/dist/utilities/findMany.d.ts.map +1 -0
- package/dist/utilities/findMany.js +84 -0
- package/dist/utilities/findMany.js.map +1 -0
- package/dist/utilities/getHasNearConstraint.d.ts +3 -0
- package/dist/utilities/getHasNearConstraint.d.ts.map +1 -0
- package/dist/utilities/getHasNearConstraint.js +26 -0
- package/dist/utilities/getHasNearConstraint.js.map +1 -0
- package/dist/utilities/transform.d.ts +17 -0
- package/dist/utilities/transform.d.ts.map +1 -0
- package/dist/utilities/transform.js +250 -0
- package/dist/utilities/transform.js.map +1 -0
- package/dist/utilities/{sanitizeRelationshipIDs.spec.js → transform.spec.js} +23 -7
- 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 -9
- package/dist/utilities/sanitizeRelationshipIDs.d.ts.map +0 -1
- package/dist/utilities/sanitizeRelationshipIDs.js +0 -125
- package/dist/utilities/sanitizeRelationshipIDs.js.map +0 -1
- package/dist/utilities/sanitizeRelationshipIDs.spec.js.map +0 -1
- package/dist/withSession.d.ts.map +0 -1
- package/dist/withSession.js.map +0 -1
package/dist/updateVersion.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { buildVersionCollectionFields } from 'payload';
|
|
2
|
+
import { getSession } from './getSession.js';
|
|
2
3
|
import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js';
|
|
3
|
-
import {
|
|
4
|
-
import { withSession } from './withSession.js';
|
|
4
|
+
import { transform } from './utilities/transform.js';
|
|
5
5
|
export const updateVersion = async function updateVersion({ id, collection, locale, options: optionsArgs = {}, req = {}, select, versionData, where }) {
|
|
6
6
|
const VersionModel = this.versions[collection];
|
|
7
7
|
const whereToUse = where || {
|
|
@@ -9,37 +9,39 @@ export const updateVersion = async function updateVersion({ id, collection, loca
|
|
|
9
9
|
equals: id
|
|
10
10
|
}
|
|
11
11
|
};
|
|
12
|
-
const fields = buildVersionCollectionFields(this.payload.config, this.payload.collections[collection].config);
|
|
13
|
-
const
|
|
14
|
-
...optionsArgs,
|
|
15
|
-
...await withSession(this, req),
|
|
16
|
-
lean: true,
|
|
17
|
-
new: true,
|
|
18
|
-
projection: buildProjectionFromSelect({
|
|
19
|
-
adapter: this,
|
|
20
|
-
fields: buildVersionCollectionFields(this.payload.config, this.payload.collections[collection].config, true),
|
|
21
|
-
select
|
|
22
|
-
})
|
|
23
|
-
};
|
|
12
|
+
const fields = buildVersionCollectionFields(this.payload.config, this.payload.collections[collection].config, true);
|
|
13
|
+
const session = await getSession(this, req);
|
|
24
14
|
const query = await VersionModel.buildQuery({
|
|
25
15
|
locale,
|
|
26
16
|
payload: this.payload,
|
|
17
|
+
session,
|
|
27
18
|
where: whereToUse
|
|
28
19
|
});
|
|
29
|
-
|
|
30
|
-
|
|
20
|
+
transform({
|
|
21
|
+
adapter: this,
|
|
31
22
|
data: versionData,
|
|
32
|
-
fields
|
|
23
|
+
fields,
|
|
24
|
+
operation: 'update'
|
|
25
|
+
});
|
|
26
|
+
const doc = await VersionModel.collection.findOneAndUpdate(query, {
|
|
27
|
+
$set: versionData
|
|
28
|
+
}, {
|
|
29
|
+
...optionsArgs,
|
|
30
|
+
projection: buildProjectionFromSelect({
|
|
31
|
+
adapter: this,
|
|
32
|
+
fields: buildVersionCollectionFields(this.payload.config, this.payload.collections[collection].config, true),
|
|
33
|
+
select
|
|
34
|
+
}),
|
|
35
|
+
returnDocument: 'after',
|
|
36
|
+
session
|
|
37
|
+
});
|
|
38
|
+
transform({
|
|
39
|
+
adapter: this,
|
|
40
|
+
data: doc,
|
|
41
|
+
fields,
|
|
42
|
+
operation: 'read'
|
|
33
43
|
});
|
|
34
|
-
|
|
35
|
-
const result = JSON.parse(JSON.stringify(doc));
|
|
36
|
-
const verificationToken = doc._verificationToken;
|
|
37
|
-
// custom id type reset
|
|
38
|
-
result.id = result._id;
|
|
39
|
-
if (verificationToken) {
|
|
40
|
-
result._verificationToken = verificationToken;
|
|
41
|
-
}
|
|
42
|
-
return result;
|
|
44
|
+
return doc;
|
|
43
45
|
};
|
|
44
46
|
|
|
45
47
|
//# sourceMappingURL=updateVersion.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/updateVersion.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"sources":["../src/updateVersion.ts"],"sourcesContent":["import { buildVersionCollectionFields, type PayloadRequest, type UpdateVersion } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { getSession } from './getSession.js'\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { transform } from './utilities/transform.js'\n\nexport const updateVersion: UpdateVersion = async function updateVersion(\n this: MongooseAdapter,\n {\n id,\n collection,\n locale,\n options: optionsArgs = {},\n req = {} as PayloadRequest,\n select,\n versionData,\n where,\n },\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 true,\n )\n\n const session = await getSession(this, req)\n\n const query = await VersionModel.buildQuery({\n locale,\n payload: this.payload,\n session,\n where: whereToUse,\n })\n\n transform({\n adapter: this,\n data: versionData,\n fields,\n operation: 'update',\n })\n\n const doc = await VersionModel.collection.findOneAndUpdate(\n query,\n { $set: versionData },\n {\n ...optionsArgs,\n projection: buildProjectionFromSelect({\n adapter: this,\n fields: buildVersionCollectionFields(\n this.payload.config,\n this.payload.collections[collection].config,\n true,\n ),\n select,\n }),\n returnDocument: 'after',\n session,\n },\n )\n\n transform({\n adapter: this,\n data: doc,\n fields,\n operation: 'read',\n })\n\n return doc as any\n}\n"],"names":["buildVersionCollectionFields","getSession","buildProjectionFromSelect","transform","updateVersion","id","collection","locale","options","optionsArgs","req","select","versionData","where","VersionModel","versions","whereToUse","equals","fields","payload","config","collections","session","query","buildQuery","adapter","data","operation","doc","findOneAndUpdate","$set","projection","returnDocument"],"mappings":"AAAA,SAASA,4BAA4B,QAAiD,UAAS;AAI/F,SAASC,UAAU,QAAQ,kBAAiB;AAC5C,SAASC,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,SAAS,QAAQ,2BAA0B;AAEpD,OAAO,MAAMC,gBAA+B,eAAeA,cAEzD,EACEC,EAAE,EACFC,UAAU,EACVC,MAAM,EACNC,SAASC,cAAc,CAAC,CAAC,EACzBC,MAAM,CAAC,CAAmB,EAC1BC,MAAM,EACNC,WAAW,EACXC,KAAK,EACN;IAED,MAAMC,eAAe,IAAI,CAACC,QAAQ,CAACT,WAAW;IAC9C,MAAMU,aAAaH,SAAS;QAAER,IAAI;YAAEY,QAAQZ;QAAG;IAAE;IACjD,MAAMa,SAASlB,6BACb,IAAI,CAACmB,OAAO,CAACC,MAAM,EACnB,IAAI,CAACD,OAAO,CAACE,WAAW,CAACf,WAAW,CAACc,MAAM,EAC3C;IAGF,MAAME,UAAU,MAAMrB,WAAW,IAAI,EAAES;IAEvC,MAAMa,QAAQ,MAAMT,aAAaU,UAAU,CAAC;QAC1CjB;QACAY,SAAS,IAAI,CAACA,OAAO;QACrBG;QACAT,OAAOG;IACT;IAEAb,UAAU;QACRsB,SAAS,IAAI;QACbC,MAAMd;QACNM;QACAS,WAAW;IACb;IAEA,MAAMC,MAAM,MAAMd,aAAaR,UAAU,CAACuB,gBAAgB,CACxDN,OACA;QAAEO,MAAMlB;IAAY,GACpB;QACE,GAAGH,WAAW;QACdsB,YAAY7B,0BAA0B;YACpCuB,SAAS,IAAI;YACbP,QAAQlB,6BACN,IAAI,CAACmB,OAAO,CAACC,MAAM,EACnB,IAAI,CAACD,OAAO,CAACE,WAAW,CAACf,WAAW,CAACc,MAAM,EAC3C;YAEFT;QACF;QACAqB,gBAAgB;QAChBV;IACF;IAGFnB,UAAU;QACRsB,SAAS,IAAI;QACbC,MAAME;QACNV;QACAS,WAAW;IACb;IAEA,OAAOC;AACT,EAAC"}
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
+
import type { ClientSession } from 'mongodb';
|
|
1
2
|
import type { PipelineStage } from 'mongoose';
|
|
2
|
-
import type { CollectionSlug, JoinQuery, SanitizedCollectionConfig
|
|
3
|
+
import type { CollectionSlug, JoinQuery, SanitizedCollectionConfig } from 'payload';
|
|
3
4
|
import type { MongooseAdapter } from '../index.js';
|
|
4
5
|
type BuildJoinAggregationArgs = {
|
|
5
6
|
adapter: MongooseAdapter;
|
|
6
7
|
collection: CollectionSlug;
|
|
7
8
|
collectionConfig: SanitizedCollectionConfig;
|
|
8
9
|
joins: JoinQuery;
|
|
9
|
-
limit?: number;
|
|
10
10
|
locale: string;
|
|
11
11
|
projection?: Record<string, true>;
|
|
12
|
-
|
|
12
|
+
session?: ClientSession;
|
|
13
13
|
/** whether the query is from drafts */
|
|
14
14
|
versions?: boolean;
|
|
15
15
|
};
|
|
16
|
-
export declare const buildJoinAggregation: ({ adapter, collection, collectionConfig, joins,
|
|
16
|
+
export declare const buildJoinAggregation: ({ adapter, collection, collectionConfig, joins, locale, projection, session, versions, }: BuildJoinAggregationArgs) => Promise<PipelineStage[] | undefined>;
|
|
17
17
|
export {};
|
|
18
18
|
//# 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;AAC7C,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,yBAAyB,
|
|
1
|
+
{"version":3,"file":"buildJoinAggregation.d.ts","sourceRoot":"","sources":["../../src/utilities/buildJoinAggregation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAC5C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAC7C,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,yBAAyB,EAAS,MAAM,SAAS,CAAA;AAE1F,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAIlD,KAAK,wBAAwB,GAAG;IAC9B,OAAO,EAAE,eAAe,CAAA;IACxB,UAAU,EAAE,cAAc,CAAA;IAC1B,gBAAgB,EAAE,yBAAyB,CAAA;IAC3C,KAAK,EAAE,SAAS,CAAA;IAChB,MAAM,EAAE,MAAM,CAAA;IACd,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAA;IACjC,OAAO,CAAC,EAAE,aAAa,CAAA;IACvB,uCAAuC;IACvC,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB,CAAA;AAED,eAAO,MAAM,oBAAoB,6FAS9B,wBAAwB,KAAG,OAAO,CAAC,aAAa,EAAE,GAAG,SAAS,CA8IhE,CAAA"}
|
|
@@ -1,26 +1,10 @@
|
|
|
1
1
|
import { buildSortParam } from '../queries/buildSortParam.js';
|
|
2
|
-
export const buildJoinAggregation = async ({ adapter, collection, collectionConfig, joins,
|
|
2
|
+
export const buildJoinAggregation = async ({ adapter, collection, collectionConfig, joins, locale, projection, session, versions })=>{
|
|
3
3
|
if (Object.keys(collectionConfig.joins).length === 0 || joins === false) {
|
|
4
4
|
return;
|
|
5
5
|
}
|
|
6
6
|
const joinConfig = adapter.payload.collections[collection].config.joins;
|
|
7
|
-
const aggregate = [
|
|
8
|
-
{
|
|
9
|
-
$sort: {
|
|
10
|
-
createdAt: -1
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
];
|
|
14
|
-
if (query) {
|
|
15
|
-
aggregate.push({
|
|
16
|
-
$match: query
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
if (limit) {
|
|
20
|
-
aggregate.push({
|
|
21
|
-
$limit: limit
|
|
22
|
-
});
|
|
23
|
-
}
|
|
7
|
+
const aggregate = [];
|
|
24
8
|
for (const slug of Object.keys(joinConfig)){
|
|
25
9
|
for (const join of joinConfig[slug]){
|
|
26
10
|
const joinModel = adapter.collections[join.field.collection];
|
|
@@ -31,18 +15,17 @@ export const buildJoinAggregation = async ({ adapter, collection, collectionConf
|
|
|
31
15
|
continue;
|
|
32
16
|
}
|
|
33
17
|
const { limit: limitJoin = join.field.defaultLimit ?? 10, sort: sortJoin = join.field.defaultSort || collectionConfig.defaultSort, where: whereJoin } = joins?.[join.joinPath] || {};
|
|
34
|
-
const sort = buildSortParam({
|
|
18
|
+
const $sort = buildSortParam({
|
|
35
19
|
config: adapter.payload.config,
|
|
36
20
|
fields: adapter.payload.collections[slug].config.flattenedFields,
|
|
37
21
|
locale,
|
|
38
22
|
sort: sortJoin,
|
|
39
23
|
timestamps: true
|
|
40
24
|
});
|
|
41
|
-
const sortProperty = Object.keys(sort)[0];
|
|
42
|
-
const sortDirection = sort[sortProperty] === 'asc' ? 1 : -1;
|
|
43
25
|
const $match = await joinModel.buildQuery({
|
|
44
26
|
locale,
|
|
45
27
|
payload: adapter.payload,
|
|
28
|
+
session,
|
|
46
29
|
where: whereJoin
|
|
47
30
|
});
|
|
48
31
|
const pipeline = [
|
|
@@ -50,9 +33,7 @@ export const buildJoinAggregation = async ({ adapter, collection, collectionConf
|
|
|
50
33
|
$match
|
|
51
34
|
},
|
|
52
35
|
{
|
|
53
|
-
$sort
|
|
54
|
-
[sortProperty]: sortDirection
|
|
55
|
-
}
|
|
36
|
+
$sort
|
|
56
37
|
}
|
|
57
38
|
];
|
|
58
39
|
if (limitJoin > 0) {
|
|
@@ -148,10 +129,8 @@ export const buildJoinAggregation = async ({ adapter, collection, collectionConf
|
|
|
148
129
|
}
|
|
149
130
|
}
|
|
150
131
|
}
|
|
151
|
-
if (
|
|
152
|
-
|
|
153
|
-
$project: projection
|
|
154
|
-
});
|
|
132
|
+
if (!aggregate.length) {
|
|
133
|
+
return;
|
|
155
134
|
}
|
|
156
135
|
return aggregate;
|
|
157
136
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utilities/buildJoinAggregation.ts"],"sourcesContent":["import type { PipelineStage } from 'mongoose'\nimport type { CollectionSlug, JoinQuery, SanitizedCollectionConfig, Where } from 'payload'\n\nimport type { MongooseAdapter } from '../index.js'\n\nimport { buildSortParam } from '../queries/buildSortParam.js'\n\ntype BuildJoinAggregationArgs = {\n adapter: MongooseAdapter\n collection: CollectionSlug\n collectionConfig: SanitizedCollectionConfig\n joins: JoinQuery\n // the number of docs to get at the top collection level\n limit?: number\n locale: string\n projection?: Record<string, true>\n // the where clause for the top collection\n query?: Where\n /** whether the query is from drafts */\n versions?: boolean\n}\n\nexport const buildJoinAggregation = async ({\n adapter,\n collection,\n collectionConfig,\n joins,\n limit,\n locale,\n projection,\n query,\n versions,\n}: BuildJoinAggregationArgs): Promise<PipelineStage[] | undefined> => {\n if (Object.keys(collectionConfig.joins).length === 0 || joins === false) {\n return\n }\n\n const joinConfig = adapter.payload.collections[collection].config.joins\n const aggregate: PipelineStage[] = [\n {\n $sort: { createdAt: -1 },\n },\n ]\n\n if (query) {\n aggregate.push({\n $match: query,\n })\n }\n\n if (limit) {\n aggregate.push({\n $limit: limit,\n })\n }\n\n for (const slug of Object.keys(joinConfig)) {\n for (const join of joinConfig[slug]) {\n const joinModel = adapter.collections[join.field.collection]\n\n if (projection && !projection[join.joinPath]) {\n continue\n }\n\n if (joins?.[join.joinPath] === false) {\n continue\n }\n\n const {\n limit: limitJoin = join.field.defaultLimit ?? 10,\n sort: sortJoin = join.field.defaultSort || collectionConfig.defaultSort,\n where: whereJoin,\n } = joins?.[join.joinPath] || {}\n\n const sort = buildSortParam({\n config: adapter.payload.config,\n fields: adapter.payload.collections[slug].config.flattenedFields,\n locale,\n sort: sortJoin,\n timestamps: true,\n })\n const sortProperty = Object.keys(sort)[0]\n const sortDirection = sort[sortProperty] === 'asc' ? 1 : -1\n\n const $match = await joinModel.buildQuery({\n locale,\n payload: adapter.payload,\n where: whereJoin,\n })\n\n const pipeline: Exclude<PipelineStage, PipelineStage.Merge | PipelineStage.Out>[] = [\n { $match },\n {\n $sort: { [sortProperty]: sortDirection },\n },\n ]\n\n if (limitJoin > 0) {\n pipeline.push({\n $limit: limitJoin + 1,\n })\n }\n\n if (adapter.payload.config.localization && locale === 'all') {\n adapter.payload.config.localization.localeCodes.forEach((code) => {\n const as = `${versions ? `version.${join.joinPath}` : join.joinPath}${code}`\n\n aggregate.push(\n {\n $lookup: {\n as: `${as}.docs`,\n foreignField: `${join.field.on}${code}`,\n from: adapter.collections[slug].collection.name,\n localField: versions ? 'parent' : '_id',\n pipeline,\n },\n },\n {\n $addFields: {\n [`${as}.docs`]: {\n $map: {\n as: 'doc',\n in: '$$doc._id',\n input: `$${as}.docs`,\n },\n }, // Slicing the docs to match the limit\n [`${as}.hasNextPage`]: limitJoin\n ? { $gt: [{ $size: `$${as}.docs` }, limitJoin] }\n : false,\n // Boolean indicating if more docs than limit\n },\n },\n )\n if (limitJoin > 0) {\n aggregate.push({\n $addFields: {\n [`${as}.docs`]: {\n $slice: [`$${as}.docs`, limitJoin],\n },\n },\n })\n }\n })\n } else {\n const localeSuffix =\n join.field.localized && adapter.payload.config.localization && locale ? `.${locale}` : ''\n const as = `${versions ? `version.${join.joinPath}` : join.joinPath}${localeSuffix}`\n\n aggregate.push(\n {\n $lookup: {\n as: `${as}.docs`,\n foreignField: `${join.field.on}${localeSuffix}`,\n from: adapter.collections[slug].collection.name,\n localField: versions ? 'parent' : '_id',\n pipeline,\n },\n },\n {\n $addFields: {\n [`${as}.docs`]: {\n $map: {\n as: 'doc',\n in: '$$doc._id',\n input: `$${as}.docs`,\n },\n }, // Slicing the docs to match the limit\n [`${as}.hasNextPage`]: {\n $gt: [{ $size: `$${as}.docs` }, limitJoin || Number.MAX_VALUE],\n }, // Boolean indicating if more docs than limit\n },\n },\n )\n if (limitJoin > 0) {\n aggregate.push({\n $addFields: {\n [`${as}.docs`]: {\n $slice: [`$${as}.docs`, limitJoin],\n },\n },\n })\n }\n }\n }\n }\n\n if (projection) {\n aggregate.push({ $project: projection })\n }\n\n return aggregate\n}\n"],"names":["buildSortParam","buildJoinAggregation","adapter","collection","collectionConfig","joins","limit","locale","projection","query","versions","Object","keys","length","joinConfig","payload","collections","config","aggregate","$sort","createdAt","push","$match","$limit","slug","join","joinModel","field","joinPath","limitJoin","defaultLimit","sort","sortJoin","defaultSort","where","whereJoin","fields","flattenedFields","timestamps","sortProperty","sortDirection","buildQuery","pipeline","localization","localeCodes","forEach","code","as","$lookup","foreignField","on","from","name","localField","$addFields","$map","in","input","$gt","$size","$slice","localeSuffix","localized","Number","MAX_VALUE","$project"],"mappings":"AAKA,SAASA,cAAc,QAAQ,+BAA8B;AAiB7D,OAAO,MAAMC,uBAAuB,OAAO,EACzCC,OAAO,EACPC,UAAU,EACVC,gBAAgB,EAChBC,KAAK,EACLC,KAA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KAAK,CAAC;gCAAC;gCAAGlB,aAAakC,OAAOC,SAAS;6BAAC;wBAChE;oBACF;gBACF;gBAEF,IAAInC,YAAY,GAAG;oBACjBX,UAAUG,IAAI,CAAC;wBACbiC,YAAY;4BACV,CAAC,CAAC,EAAEP,GAAG,KAAK,CAAC,CAAC,EAAE;gCACda,QAAQ;oCAAC,CAAC,CAAC,EAAEb,GAAG,KAAK,CAAC;oCAAElB;iCAAU;4BACpC;wBACF;oBACF;gBACF;YACF;QACF;IACF;IAEA,IAAIrB,YAAY;QACdU,UAAUG,IAAI,CAAC;YAAE4C,UAAUzD;QAAW;IACxC;IAEA,OAAOU;AACT,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/buildJoinAggregation.ts"],"sourcesContent":["import type { ClientSession } from 'mongodb'\nimport type { PipelineStage } from 'mongoose'\nimport type { CollectionSlug, JoinQuery, SanitizedCollectionConfig, Where } from 'payload'\n\nimport type { MongooseAdapter } from '../index.js'\n\nimport { buildSortParam } from '../queries/buildSortParam.js'\n\ntype BuildJoinAggregationArgs = {\n adapter: MongooseAdapter\n collection: CollectionSlug\n collectionConfig: SanitizedCollectionConfig\n joins: JoinQuery\n locale: string\n projection?: Record<string, true>\n session?: ClientSession\n /** whether the query is from drafts */\n versions?: boolean\n}\n\nexport const buildJoinAggregation = async ({\n adapter,\n collection,\n collectionConfig,\n joins,\n locale,\n projection,\n session,\n versions,\n}: BuildJoinAggregationArgs): Promise<PipelineStage[] | undefined> => {\n if (Object.keys(collectionConfig.joins).length === 0 || joins === false) {\n return\n }\n\n const joinConfig = adapter.payload.collections[collection].config.joins\n const aggregate: PipelineStage[] = []\n\n for (const slug of Object.keys(joinConfig)) {\n for (const join of joinConfig[slug]) {\n const joinModel = adapter.collections[join.field.collection]\n\n if (projection && !projection[join.joinPath]) {\n continue\n }\n\n if (joins?.[join.joinPath] === false) {\n continue\n }\n\n const {\n limit: limitJoin = join.field.defaultLimit ?? 10,\n sort: sortJoin = join.field.defaultSort || collectionConfig.defaultSort,\n where: whereJoin,\n } = joins?.[join.joinPath] || {}\n\n const $sort = buildSortParam({\n config: adapter.payload.config,\n fields: adapter.payload.collections[slug].config.flattenedFields,\n locale,\n sort: sortJoin,\n timestamps: true,\n })\n\n const $match = await joinModel.buildQuery({\n locale,\n payload: adapter.payload,\n session,\n where: whereJoin,\n })\n\n const pipeline: Exclude<PipelineStage, PipelineStage.Merge | PipelineStage.Out>[] = [\n { $match },\n {\n $sort,\n },\n ]\n\n if (limitJoin > 0) {\n pipeline.push({\n $limit: limitJoin + 1,\n })\n }\n\n if (adapter.payload.config.localization && locale === 'all') {\n adapter.payload.config.localization.localeCodes.forEach((code) => {\n const as = `${versions ? `version.${join.joinPath}` : join.joinPath}${code}`\n\n aggregate.push(\n {\n $lookup: {\n as: `${as}.docs`,\n foreignField: `${join.field.on}${code}`,\n from: adapter.collections[slug].collection.name,\n localField: versions ? 'parent' : '_id',\n pipeline,\n },\n },\n {\n $addFields: {\n [`${as}.docs`]: {\n $map: {\n as: 'doc',\n in: '$$doc._id',\n input: `$${as}.docs`,\n },\n }, // Slicing the docs to match the limit\n [`${as}.hasNextPage`]: limitJoin\n ? { $gt: [{ $size: `$${as}.docs` }, limitJoin] }\n : false,\n // Boolean indicating if more docs than limit\n },\n },\n )\n if (limitJoin > 0) {\n aggregate.push({\n $addFields: {\n [`${as}.docs`]: {\n $slice: [`$${as}.docs`, limitJoin],\n },\n },\n })\n }\n })\n } else {\n const localeSuffix =\n join.field.localized && adapter.payload.config.localization && locale ? `.${locale}` : ''\n const as = `${versions ? `version.${join.joinPath}` : join.joinPath}${localeSuffix}`\n\n aggregate.push(\n {\n $lookup: {\n as: `${as}.docs`,\n foreignField: `${join.field.on}${localeSuffix}`,\n from: adapter.collections[slug].collection.name,\n localField: versions ? 'parent' : '_id',\n pipeline,\n },\n },\n {\n $addFields: {\n [`${as}.docs`]: {\n $map: {\n as: 'doc',\n in: '$$doc._id',\n input: `$${as}.docs`,\n },\n }, // Slicing the docs to match the limit\n [`${as}.hasNextPage`]: {\n $gt: [{ $size: `$${as}.docs` }, limitJoin || Number.MAX_VALUE],\n }, // Boolean indicating if more docs than limit\n },\n },\n )\n if (limitJoin > 0) {\n aggregate.push({\n $addFields: {\n [`${as}.docs`]: {\n $slice: [`$${as}.docs`, limitJoin],\n },\n },\n })\n }\n }\n }\n }\n\n if (!aggregate.length) {\n return\n }\n\n return aggregate\n}\n"],"names":["buildSortParam","buildJoinAggregation","adapter","collection","collectionConfig","joins","locale","projection","session","versions","Object","keys","length","joinConfig","payload","collections","config","aggregate","slug","join","joinModel","field","joinPath","limit","limitJoin","defaultLimit","sort","sortJoin","defaultSort","where","whereJoin","$sort","fields","flattenedFields","timestamps","$match","buildQuery","pipeline","push","$limit","localization","localeCodes","forEach","code","as","$lookup","foreignField","on","from","name","localField","$addFields","$map","in","input","$gt","$size","$slice","localeSuffix","localized","Number","MAX_VALUE"],"mappings":"AAMA,SAASA,cAAc,QAAQ,+BAA8B;AAc7D,OAAO,MAAMC,uBAAuB,OAAO,EACzCC,OAAO,EACPC,UAAU,EACVC,gBAAgB,EAChBC,KAAK,EACLC,MAAM,EACNC,UAAU,EACVC,OAAO,EACPC,QAAQ,EACiB;IACzB,IAAIC,OAAOC,IAAI,CAACP,iBAAiBC,KAAK,EAAEO,MAAM,KAAK,KAAKP,UAAU,OAAO;QACvE;IACF;IAEA,MAAMQ,aAAaX,QAAQY,OAAO,CAACC,WAAW,CAACZ,WAAW,CAACa,MAAM,CAACX,KAAK;IACvE,MAAMY,YAA6B,EAAE;IAErC,KAAK,MAAMC,QAAQR,OAAOC,IAAI,CAACE,YAAa;QAC1C,KAAK,MAAMM,QAAQN,UAAU,CAACK,KAAK,CAAE;YACnC,MAAME,YAAYlB,QAAQa,WAAW,CAACI,KAAKE,KAAK,CAAClB,UAAU,CAAC;YAE5D,IAAII,cAAc,CAACA,UAAU,CAACY,KAAKG,QAAQ,CAAC,EAAE;gBAC5C;YACF;YAEA,IAAIjB,O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AC/CC,YAAYzC,WAAW,WAAW;wBAClC4B;oBACF;gBACF,GACA;oBACEc,YAAY;wBACV,CAAC,CAAC,EAAEP,GAAG,KAAK,CAAC,CAAC,EAAE;4BACdQ,MAAM;gCACJR,IAAI;gCACJS,IAAI;gCACJC,OAAO,CAAC,CAAC,EAAEV,GAAG,KAAK,CAAC;4BACtB;wBACF;wBACA,CAAC,CAAC,EAAEA,GAAG,YAAY,CAAC,CAAC,EAAE;4BACrBW,KAAK;gCAAC;oCAAEC,OAAO,CAAC,CAAC,EAAEZ,GAAG,KAAK,CAAC;gCAAC;gCAAGpB,aAAaoC,OAAOC,SAAS;6BAAC;wBAChE;oBACF;gBACF;gBAEF,IAAIrC,YAAY,GAAG;oBACjBP,UAAUqB,IAAI,CAAC;wBACba,YAAY;4BACV,CAAC,CAAC,EAAEP,GAAG,KAAK,CAAC,CAAC,EAAE;gCACda,QAAQ;oCAAC,CAAC,CAAC,EAAEb,GAAG,KAAK,CAAC;oCAAEpB;iCAAU;4BACpC;wBACF;oBACF;gBACF;YACF;QACF;IACF;IAEA,IAAI,CAACP,UAAUL,MAAM,EAAE;QACrB;IACF;IAEA,OAAOK;AACT,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildProjectionFromSelect.d.ts","sourceRoot":"","sources":["../../src/utilities/buildProjectionFromSelect.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"buildProjectionFromSelect.d.ts","sourceRoot":"","sources":["../../src/utilities/buildProjectionFromSelect.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAA6B,cAAc,EAAc,UAAU,EAAE,MAAM,SAAS,CAAA;AAIhG,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAiMlD,eAAO,MAAM,yBAAyB,iCAInC;IACD,OAAO,EAAE,eAAe,CAAA;IACxB,MAAM,EAAE,cAAc,EAAE,CAAA;IACxB,MAAM,CAAC,EAAE,UAAU,CAAA;CACpB,KAAG,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,SAmB1B,CAAA"}
|
|
@@ -10,6 +10,10 @@ const addFieldToProjection = ({ adapter, databaseSchemaPath, field, projection,
|
|
|
10
10
|
projection[`${databaseSchemaPath}${field.name}`] = true;
|
|
11
11
|
}
|
|
12
12
|
};
|
|
13
|
+
const blockTypeField = {
|
|
14
|
+
name: 'blockType',
|
|
15
|
+
type: 'text'
|
|
16
|
+
};
|
|
13
17
|
const traverseFields = ({ adapter, databaseSchemaPath = '', fields, projection, select, selectAllOnCurrentLevel = false, selectMode, withinLocalizedField = false })=>{
|
|
14
18
|
for (const field of fields){
|
|
15
19
|
if (fieldAffectsData(field)) {
|
|
@@ -78,6 +82,13 @@ const traverseFields = ({ adapter, databaseSchemaPath = '', fields, projection,
|
|
|
78
82
|
const blocksSelect = select[field.name];
|
|
79
83
|
for (const block of field.blocks){
|
|
80
84
|
if (selectMode === 'include' && blocksSelect[block.slug] === true || selectMode === 'exclude' && typeof blocksSelect[block.slug] === 'undefined') {
|
|
85
|
+
addFieldToProjection({
|
|
86
|
+
adapter,
|
|
87
|
+
databaseSchemaPath: fieldDatabaseSchemaPath,
|
|
88
|
+
field: blockTypeField,
|
|
89
|
+
projection,
|
|
90
|
+
withinLocalizedField: fieldWithinLocalizedField
|
|
91
|
+
});
|
|
81
92
|
traverseFields({
|
|
82
93
|
adapter,
|
|
83
94
|
databaseSchemaPath: fieldDatabaseSchemaPath,
|
|
@@ -99,7 +110,13 @@ const traverseFields = ({ adapter, databaseSchemaPath = '', fields, projection,
|
|
|
99
110
|
}
|
|
100
111
|
if (blockSelectMode === 'include') {
|
|
101
112
|
blocksSelect[block.slug]['id'] = true;
|
|
102
|
-
|
|
113
|
+
addFieldToProjection({
|
|
114
|
+
adapter,
|
|
115
|
+
databaseSchemaPath: fieldDatabaseSchemaPath,
|
|
116
|
+
field: blockTypeField,
|
|
117
|
+
projection,
|
|
118
|
+
withinLocalizedField: fieldWithinLocalizedField
|
|
119
|
+
});
|
|
103
120
|
}
|
|
104
121
|
traverseFields({
|
|
105
122
|
adapter,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utilities/buildProjectionFromSelect.ts"],"sourcesContent":["import type { FieldAffectingData, FlattenedField, SelectMode, SelectType } from 'payload'\n\nimport { deepCopyObjectSimple, fieldAffectsData, getSelectMode } from 'payload/shared'\n\nimport type { MongooseAdapter } from '../index.js'\n\nconst addFieldToProjection = ({\n adapter,\n databaseSchemaPath,\n field,\n projection,\n withinLocalizedField,\n}: {\n adapter: MongooseAdapter\n databaseSchemaPath: string\n field: FieldAffectingData\n projection: Record<string, true>\n withinLocalizedField: boolean\n}) => {\n const { config } = adapter.payload\n\n if (withinLocalizedField && config.localization) {\n for (const locale of config.localization.localeCodes) {\n const localeDatabaseSchemaPath = databaseSchemaPath.replace('<locale>', locale)\n projection[`${localeDatabaseSchemaPath}${field.name}`] = true\n }\n } else {\n projection[`${databaseSchemaPath}${field.name}`] = true\n }\n}\n\nconst traverseFields = ({\n adapter,\n databaseSchemaPath = '',\n fields,\n projection,\n select,\n selectAllOnCurrentLevel = false,\n selectMode,\n withinLocalizedField = false,\n}: {\n adapter: MongooseAdapter\n databaseSchemaPath?: string\n fields: FlattenedField[]\n projection: Record<string, true>\n select: SelectType\n selectAllOnCurrentLevel?: boolean\n selectMode: SelectMode\n withinLocalizedField?: boolean\n}) => {\n for (const field of fields) {\n if (fieldAffectsData(field)) {\n if (selectMode === 'include') {\n if (select[field.name] === true || selectAllOnCurrentLevel) {\n addFieldToProjection({\n adapter,\n databaseSchemaPath,\n field,\n projection,\n withinLocalizedField,\n })\n continue\n }\n\n if (!select[field.name]) {\n continue\n }\n }\n\n if (selectMode === 'exclude') {\n if (typeof select[field.name] === 'undefined') {\n addFieldToProjection({\n adapter,\n databaseSchemaPath,\n field,\n projection,\n withinLocalizedField,\n })\n continue\n }\n\n if (select[field.name] === false) {\n continue\n }\n }\n }\n\n let fieldDatabaseSchemaPath = databaseSchemaPath\n let fieldWithinLocalizedField = withinLocalizedField\n\n if (fieldAffectsData(field)) {\n fieldDatabaseSchemaPath = `${databaseSchemaPath}${field.name}.`\n\n if (field.localized) {\n fieldDatabaseSchemaPath = `${fieldDatabaseSchemaPath}<locale>.`\n fieldWithinLocalizedField = true\n }\n }\n\n switch (field.type) {\n case 'array':\n case 'group':\n case 'tab': {\n const fieldSelect = select[field.name] as SelectType\n\n if (field.type === 'array' && selectMode === 'include') {\n fieldSelect['id'] = true\n }\n\n traverseFields({\n adapter,\n databaseSchemaPath: fieldDatabaseSchemaPath,\n fields: field.flattenedFields,\n projection,\n select: fieldSelect,\n selectMode,\n withinLocalizedField: fieldWithinLocalizedField,\n })\n\n break\n }\n\n case 'blocks': {\n const blocksSelect = select[field.name] as SelectType\n\n for (const block of field.blocks) {\n if (\n (selectMode === 'include' && blocksSelect[block.slug] === true) ||\n (selectMode === 'exclude' && typeof blocksSelect[block.slug] === 'undefined')\n ) {\n traverseFields({\n adapter,\n databaseSchemaPath: fieldDatabaseSchemaPath,\n fields: block.flattenedFields,\n projection,\n select: {},\n selectAllOnCurrentLevel: true,\n selectMode: 'include',\n withinLocalizedField: fieldWithinLocalizedField,\n })\n continue\n }\n\n let blockSelectMode = selectMode\n\n if (selectMode === 'exclude' && blocksSelect[block.slug] === false) {\n blockSelectMode = 'include'\n }\n\n if (typeof blocksSelect[block.slug] !== 'object') {\n blocksSelect[block.slug] = {}\n }\n\n if (blockSelectMode === 'include') {\n blocksSelect[block.slug]['id'] = true\n
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/buildProjectionFromSelect.ts"],"sourcesContent":["import type { Field, FieldAffectingData, FlattenedField, SelectMode, SelectType } from 'payload'\n\nimport { deepCopyObjectSimple, fieldAffectsData, getSelectMode } from 'payload/shared'\n\nimport type { MongooseAdapter } from '../index.js'\n\nconst addFieldToProjection = ({\n adapter,\n databaseSchemaPath,\n field,\n projection,\n withinLocalizedField,\n}: {\n adapter: MongooseAdapter\n databaseSchemaPath: string\n field: FieldAffectingData\n projection: Record<string, true>\n withinLocalizedField: boolean\n}) => {\n const { config } = adapter.payload\n\n if (withinLocalizedField && config.localization) {\n for (const locale of config.localization.localeCodes) {\n const localeDatabaseSchemaPath = databaseSchemaPath.replace('<locale>', locale)\n projection[`${localeDatabaseSchemaPath}${field.name}`] = true\n }\n } else {\n projection[`${databaseSchemaPath}${field.name}`] = true\n }\n}\n\nconst blockTypeField: Field = {\n name: 'blockType',\n type: 'text',\n}\n\nconst traverseFields = ({\n adapter,\n databaseSchemaPath = '',\n fields,\n projection,\n select,\n selectAllOnCurrentLevel = false,\n selectMode,\n withinLocalizedField = false,\n}: {\n adapter: MongooseAdapter\n databaseSchemaPath?: string\n fields: FlattenedField[]\n projection: Record<string, true>\n select: SelectType\n selectAllOnCurrentLevel?: boolean\n selectMode: SelectMode\n withinLocalizedField?: boolean\n}) => {\n for (const field of fields) {\n if (fieldAffectsData(field)) {\n if (selectMode === 'include') {\n if (select[field.name] === true || selectAllOnCurrentLevel) {\n addFieldToProjection({\n adapter,\n databaseSchemaPath,\n field,\n projection,\n withinLocalizedField,\n })\n continue\n }\n\n if (!select[field.name]) {\n continue\n }\n }\n\n if (selectMode === 'exclude') {\n if (typeof select[field.name] === 'undefined') {\n addFieldToProjection({\n adapter,\n databaseSchemaPath,\n field,\n projection,\n withinLocalizedField,\n })\n continue\n }\n\n if (select[field.name] === false) {\n continue\n }\n }\n }\n\n let fieldDatabaseSchemaPath = databaseSchemaPath\n let fieldWithinLocalizedField = withinLocalizedField\n\n if (fieldAffectsData(field)) {\n fieldDatabaseSchemaPath = `${databaseSchemaPath}${field.name}.`\n\n if (field.localized) {\n fieldDatabaseSchemaPath = `${fieldDatabaseSchemaPath}<locale>.`\n fieldWithinLocalizedField = true\n }\n }\n\n switch (field.type) {\n case 'array':\n case 'group':\n case 'tab': {\n const fieldSelect = select[field.name] as SelectType\n\n if (field.type === 'array' && selectMode === 'include') {\n fieldSelect['id'] = true\n }\n\n traverseFields({\n adapter,\n databaseSchemaPath: fieldDatabaseSchemaPath,\n fields: field.flattenedFields,\n projection,\n select: fieldSelect,\n selectMode,\n withinLocalizedField: fieldWithinLocalizedField,\n })\n\n break\n }\n\n case 'blocks': {\n const blocksSelect = select[field.name] as SelectType\n\n for (const block of field.blocks) {\n if (\n (selectMode === 'include' && blocksSelect[block.slug] === true) ||\n (selectMode === 'exclude' && typeof blocksSelect[block.slug] === 'undefined')\n ) {\n addFieldToProjection({\n adapter,\n databaseSchemaPath: fieldDatabaseSchemaPath,\n field: blockTypeField,\n projection,\n withinLocalizedField: fieldWithinLocalizedField,\n })\n\n traverseFields({\n adapter,\n databaseSchemaPath: fieldDatabaseSchemaPath,\n fields: block.flattenedFields,\n projection,\n select: {},\n selectAllOnCurrentLevel: true,\n selectMode: 'include',\n withinLocalizedField: fieldWithinLocalizedField,\n })\n continue\n }\n\n let blockSelectMode = selectMode\n\n if (selectMode === 'exclude' && blocksSelect[block.slug] === false) {\n blockSelectMode = 'include'\n }\n\n if (typeof blocksSelect[block.slug] !== 'object') {\n blocksSelect[block.slug] = {}\n }\n\n if (blockSelectMode === 'include') {\n blocksSelect[block.slug]['id'] = true\n addFieldToProjection({\n adapter,\n databaseSchemaPath: fieldDatabaseSchemaPath,\n field: blockTypeField,\n projection,\n withinLocalizedField: fieldWithinLocalizedField,\n })\n }\n\n traverseFields({\n adapter,\n databaseSchemaPath: fieldDatabaseSchemaPath,\n fields: block.flattenedFields,\n projection,\n select: blocksSelect[block.slug] as SelectType,\n selectMode: blockSelectMode,\n withinLocalizedField: fieldWithinLocalizedField,\n })\n }\n\n break\n }\n\n default:\n break\n }\n }\n}\n\nexport const buildProjectionFromSelect = ({\n adapter,\n fields,\n select,\n}: {\n adapter: MongooseAdapter\n fields: FlattenedField[]\n select?: SelectType\n}): Record<string, true> | undefined => {\n if (!select) {\n return\n }\n\n const projection: Record<string, true> = {\n _id: true,\n }\n\n traverseFields({\n adapter,\n fields,\n projection,\n // Clone to safely mutate it later\n select: deepCopyObjectSimple(select),\n selectMode: getSelectMode(select),\n })\n\n return projection\n}\n"],"names":["deepCopyObjectSimple","fieldAffectsData","getSelectMode","addFieldToProjection","adapter","databaseSchemaPath","field","projection","withinLocalizedField","config","payload","localization","locale","localeCodes","localeDatabaseSchemaPath","replace","name","blockTypeField","type","traverseFields","fields","select","selectAllOnCurrentLevel","selectMode","fieldDatabaseSchemaPath","fieldWithinLocalizedField","localized","fieldSelect","flattenedFields","blocksSelect","block","blocks","slug","blockSelectMode","buildProjectionFromSelect","_id"],"mappings":"AAEA,SAASA,oBAAoB,EAAEC,gBAAgB,EAAEC,aAAa,QAAQ,iBAAgB;AAItF,MAAMC,uBAAuB,CAAC,EAC5BC,OAAO,EACPC,kBAAkB,EAClBC,KAAK,EACLC,UAAU,EACVC,oBAAoB,EAOrB;IACC,MAAM,EAAEC,MAAM,EAAE,GAAGL,QAAQM,OAAO;IAElC,IAAIF,wBAAwBC,OAAOE,YAAY,EAAE;QAC/C,KAAK,MAAMC,UAAUH,OAAOE,YAAY,CAACE,WAAW,CAAE;YACpD,MAAMC,2BAA2BT,mBAAmBU,OAAO,CAAC,YAAYH;YACxEL,UAAU,CAAC,CAAC,EAAEO,yBAAyB,EAAER,MAAMU,IAAI,CAAC,CAAC,CAAC,GAAG;QAC3D;IACF,OAAO;QACLT,UAAU,CAAC,CAAC,EAAEF,mBAAmB,EAAEC,MAAMU,IAAI,CAAC,CAAC,CAAC,GAAG;IACrD;AACF;AAEA,MAAMC,iBAAwB;IAC5BD,MAAM;IACNE,MAAM;AACR;AAEA,MAAMC,iBAAiB,CAAC,EACtBf,OAAO,EACPC,qBAAqB,EAAE,EACvBe,MAAM,EACNb,UAAU,EACVc,MAAM,EACNC,0BAA0B,KAAK,EAC/BC,UAAU,EACVf,uBAAuB,KAAK,EAU7B;IACC,KAAK,MAAMF,SAASc,OAAQ;QAC1B,IAAInB,iBAAiBK,QAAQ;YAC3B,IAAI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ACA,kCAAkC;QAClCc,QAAQrB,qBAAqBqB;QAC7BE,YAAYrB,cAAcmB;IAC5B;IAEA,OAAOd;AACT,EAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { ClientSession, CollationOptions, Collection } from 'mongodb';
|
|
2
|
+
import type { PipelineStage } from 'mongoose';
|
|
3
|
+
import type { PaginatedDocs } from 'payload';
|
|
4
|
+
import type { MongooseAdapter } from '../index.js';
|
|
5
|
+
export declare const findMany: ({ adapter, collation, collection, joinAgreggation, limit, page, pagination, projection, query, session, skip, sort, useEstimatedCount, }: {
|
|
6
|
+
adapter: MongooseAdapter;
|
|
7
|
+
collation?: CollationOptions;
|
|
8
|
+
collection: Collection;
|
|
9
|
+
joinAgreggation?: PipelineStage[];
|
|
10
|
+
limit?: number;
|
|
11
|
+
page?: number;
|
|
12
|
+
pagination?: boolean;
|
|
13
|
+
projection?: Record<string, unknown>;
|
|
14
|
+
query?: Record<string, unknown>;
|
|
15
|
+
session?: ClientSession;
|
|
16
|
+
skip?: number;
|
|
17
|
+
sort?: Record<string, -1 | 1>;
|
|
18
|
+
useEstimatedCount?: boolean;
|
|
19
|
+
}) => Promise<PaginatedDocs>;
|
|
20
|
+
//# sourceMappingURL=findMany.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"findMany.d.ts","sourceRoot":"","sources":["../../src/utilities/findMany.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,gBAAgB,EAAE,UAAU,EAAY,MAAM,SAAS,CAAA;AACpF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAC7C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAE5C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAElD,eAAO,MAAM,QAAQ,6IAclB;IACD,OAAO,EAAE,eAAe,CAAA;IACxB,SAAS,CAAC,EAAE,gBAAgB,CAAA;IAC5B,UAAU,EAAE,UAAU,CAAA;IACtB,eAAe,CAAC,EAAE,aAAa,EAAE,CAAA;IACjC,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACpC,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC/B,OAAO,CAAC,EAAE,aAAa,CAAA;IACvB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAA;IAC7B,iBAAiB,CAAC,EAAE,OAAO,CAAA;CAC5B,KAAG,OAAO,CAAC,aAAa,CA6FxB,CAAA"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
export const findMany = async ({ adapter, collation, collection, joinAgreggation, limit, page = 1, pagination, projection, query = {}, session, skip, sort, useEstimatedCount })=>{
|
|
2
|
+
if (!skip) {
|
|
3
|
+
skip = (page - 1) * (limit ?? 0);
|
|
4
|
+
}
|
|
5
|
+
let docsPromise;
|
|
6
|
+
let countPromise = Promise.resolve(null);
|
|
7
|
+
if (joinAgreggation) {
|
|
8
|
+
const cursor = collection.aggregate([
|
|
9
|
+
{
|
|
10
|
+
$match: query
|
|
11
|
+
}
|
|
12
|
+
], {
|
|
13
|
+
collation,
|
|
14
|
+
session
|
|
15
|
+
});
|
|
16
|
+
if (sort) {
|
|
17
|
+
cursor.sort(sort);
|
|
18
|
+
}
|
|
19
|
+
if (skip) {
|
|
20
|
+
cursor.skip(skip);
|
|
21
|
+
}
|
|
22
|
+
if (limit) {
|
|
23
|
+
cursor.limit(limit);
|
|
24
|
+
}
|
|
25
|
+
for (const stage of joinAgreggation){
|
|
26
|
+
cursor.addStage(stage);
|
|
27
|
+
}
|
|
28
|
+
if (projection) {
|
|
29
|
+
cursor.project(projection);
|
|
30
|
+
}
|
|
31
|
+
docsPromise = cursor.toArray();
|
|
32
|
+
} else {
|
|
33
|
+
docsPromise = collection.find(query, {
|
|
34
|
+
collation,
|
|
35
|
+
limit,
|
|
36
|
+
projection,
|
|
37
|
+
session,
|
|
38
|
+
skip,
|
|
39
|
+
sort
|
|
40
|
+
}).toArray();
|
|
41
|
+
}
|
|
42
|
+
if (pagination !== false && limit) {
|
|
43
|
+
if (useEstimatedCount) {
|
|
44
|
+
countPromise = collection.estimatedDocumentCount();
|
|
45
|
+
} else {
|
|
46
|
+
// Improve the performance of the countDocuments query which is used if useEstimatedCount is set to false by adding
|
|
47
|
+
// a hint. By default, if no hint is provided, MongoDB does not use an indexed field to count the returned documents,
|
|
48
|
+
// which makes queries very slow. This only happens when no query (filter) is provided. If one is provided, it uses
|
|
49
|
+
// the correct indexed field
|
|
50
|
+
const hint = adapter.disableIndexHints !== true ? {
|
|
51
|
+
_id: 1
|
|
52
|
+
} : undefined;
|
|
53
|
+
countPromise = collection.countDocuments(query, {
|
|
54
|
+
collation,
|
|
55
|
+
hint,
|
|
56
|
+
session
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
const [docs, countResult] = await Promise.all([
|
|
61
|
+
docsPromise,
|
|
62
|
+
countPromise
|
|
63
|
+
]);
|
|
64
|
+
const count = countResult === null ? docs.length : countResult;
|
|
65
|
+
const totalPages = pagination !== false && typeof limit === 'number' && limit !== 0 ? Math.ceil(count / limit) : 1;
|
|
66
|
+
const hasPrevPage = pagination !== false && page > 1;
|
|
67
|
+
const hasNextPage = pagination !== false && totalPages > page;
|
|
68
|
+
const pagingCounter = pagination !== false && typeof limit === 'number' ? (page - 1) * limit + 1 : 1;
|
|
69
|
+
const result = {
|
|
70
|
+
docs,
|
|
71
|
+
hasNextPage,
|
|
72
|
+
hasPrevPage,
|
|
73
|
+
limit,
|
|
74
|
+
nextPage: hasNextPage ? page + 1 : null,
|
|
75
|
+
page,
|
|
76
|
+
pagingCounter,
|
|
77
|
+
prevPage: hasPrevPage ? page - 1 : null,
|
|
78
|
+
totalDocs: count,
|
|
79
|
+
totalPages
|
|
80
|
+
};
|
|
81
|
+
return result;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
//# sourceMappingURL=findMany.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/findMany.ts"],"sourcesContent":["import type { ClientSession, CollationOptions, Collection, Document } from 'mongodb'\nimport type { PipelineStage } from 'mongoose'\nimport type { PaginatedDocs } from 'payload'\n\nimport type { MongooseAdapter } from '../index.js'\n\nexport const findMany = async ({\n adapter,\n collation,\n collection,\n joinAgreggation,\n limit,\n page = 1,\n pagination,\n projection,\n query = {},\n session,\n skip,\n sort,\n useEstimatedCount,\n}: {\n adapter: MongooseAdapter\n collation?: CollationOptions\n collection: Collection\n joinAgreggation?: PipelineStage[]\n limit?: number\n page?: number\n pagination?: boolean\n projection?: Record<string, unknown>\n query?: Record<string, unknown>\n session?: ClientSession\n skip?: number\n sort?: Record<string, -1 | 1>\n useEstimatedCount?: boolean\n}): Promise<PaginatedDocs> => {\n if (!skip) {\n skip = (page - 1) * (limit ?? 0)\n }\n\n let docsPromise: Promise<Document[]>\n let countPromise: Promise<null | number> = Promise.resolve(null)\n\n if (joinAgreggation) {\n const cursor = collection.aggregate(\n [\n {\n $match: query,\n },\n ],\n { collation, session },\n )\n\n if (sort) {\n cursor.sort(sort)\n }\n\n if (skip) {\n cursor.skip(skip)\n }\n\n if (limit) {\n cursor.limit(limit)\n }\n\n for (const stage of joinAgreggation) {\n cursor.addStage(stage)\n }\n\n if (projection) {\n cursor.project(projection)\n }\n\n docsPromise = cursor.toArray()\n } else {\n docsPromise = collection\n .find(query, {\n collation,\n limit,\n projection,\n session,\n skip,\n sort,\n })\n .toArray()\n }\n\n if (pagination !== false && limit) {\n if (useEstimatedCount) {\n countPromise = collection.estimatedDocumentCount()\n } else {\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\n const hint = adapter.disableIndexHints !== true ? { _id: 1 } : undefined\n\n countPromise = collection.countDocuments(query, { collation, hint, session })\n }\n }\n\n const [docs, countResult] = await Promise.all([docsPromise, countPromise])\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 = pagination !== false && page > 1\n const hasNextPage = pagination !== false && totalPages > page\n const pagingCounter =\n pagination !== false && typeof limit === 'number' ? (page - 1) * limit + 1 : 1\n\n const result = {\n docs,\n hasNextPage,\n hasPrevPage,\n limit,\n nextPage: hasNextPage ? page + 1 : null,\n page,\n pagingCounter,\n prevPage: hasPrevPage ? page - 1 : null,\n totalDocs: count,\n totalPages,\n } as PaginatedDocs<Record<string, unknown>>\n\n return result\n}\n"],"names":["findMany","adapter","collation","collection","joinAgreggation","limit","page","pagination","projection","query","session","skip","sort","useEstimatedCount","docsPromise","countPromise","Promise","resolve","cursor","aggregate","$match","stage","addStage","project","toArray","find","estimatedDocumentCount","hint","disableIndexHints","_id","undefined","countDocuments","docs","countResult","all","count","length","totalPages","Math","ceil","hasPrevPage","hasNextPage","pagingCounter","result","nextPage","prevPage","totalDocs"],"mappings":"AAMA,OAAO,MAAMA,WAAW,OAAO,EAC7BC,OAAO,EACPC,SAAS,EACTC,UAAU,EACVC,eAAe,EACfC,KAAK,EACLC,OAAO,CAAC,EACRC,UAAU,EACVC,UAAU,EACVC,QAAQ,CAAC,CAAC,EACVC,OAAO,EACPC,IAAI,EACJC,IAAI,EACJC,iBAAiB,EAelB;IACC,IAAI,CAACF,MAAM;QACTA,OAAO,AAACL,CAAAA,OAAO,CAAA,IAAMD,CAAAA,SAAS,CAAA;IAChC;IAEA,IAAI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a/B;IACzD,MAAMoC,gBACJnC,eAAe,SAAS,OAAOF,UAAU,WAAW,AAACC,CAAAA,OAAO,CAAA,IAAKD,QAAQ,IAAI;IAE/E,MAAMsC,SAAS;QACbX;QACAS;QACAD;QACAnC;QACAuC,UAAUH,cAAcnC,OAAO,IAAI;QACnCA;QACAoC;QACAG,UAAUL,cAAclC,OAAO,IAAI;QACnCwC,WAAWX;QACXE;IACF;IAEA,OAAOM;AACT,EAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getHasNearConstraint.d.ts","sourceRoot":"","sources":["../../src/utilities/getHasNearConstraint.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAEpC,eAAO,MAAM,oBAAoB,WAAY,KAAK,KAAG,OAwBpD,CAAA"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export const getHasNearConstraint = (where)=>{
|
|
2
|
+
if (!where) {
|
|
3
|
+
return false;
|
|
4
|
+
}
|
|
5
|
+
for(const key in where){
|
|
6
|
+
const value = where[key];
|
|
7
|
+
if (Array.isArray(value) && [
|
|
8
|
+
'AND',
|
|
9
|
+
'OR'
|
|
10
|
+
].includes(key.toUpperCase())) {
|
|
11
|
+
for (const where of value){
|
|
12
|
+
if (getHasNearConstraint(where)) {
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
for(const key in value){
|
|
18
|
+
if (key === 'near') {
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return false;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
//# sourceMappingURL=getHasNearConstraint.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/getHasNearConstraint.ts"],"sourcesContent":["import type { Where } from 'payload'\n\nexport const getHasNearConstraint = (where?: Where): boolean => {\n if (!where) {\n return false\n }\n\n for (const key in where) {\n const value = where[key]\n\n if (Array.isArray(value) && ['AND', 'OR'].includes(key.toUpperCase())) {\n for (const where of value) {\n if (getHasNearConstraint(where)) {\n return true\n }\n }\n }\n\n for (const key in value) {\n if (key === 'near') {\n return true\n }\n }\n }\n\n return false\n}\n"],"names":["getHasNearConstraint","where","key","value","Array","isArray","includes","toUpperCase"],"mappings":"AAEA,OAAO,MAAMA,uBAAuB,CAACC;IACnC,IAAI,CAACA,OAAO;QACV,OAAO;IACT;IAEA,IAAK,MAAMC,OAAOD,MAAO;QACvB,MAAME,QAAQF,KAAK,CAACC,IAAI;QAExB,IAAIE,MAAMC,OAAO,CAACF,UAAU;YAAC;YAAO;SAAK,CAACG,QAAQ,CAACJ,IAAIK,WAAW,KAAK;YACrE,KAAK,MAAMN,SAASE,MAAO;gBACzB,IAAIH,qBAAqBC,QAAQ;oBAC/B,OAAO;gBACT;YACF;QACF;QAEA,IAAK,MAAMC,OAAOC,MAAO;YACvB,IAAID,QAAQ,QAAQ;gBAClB,OAAO;YACT;QACF;IACF;IAEA,OAAO;AACT,EAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { FlattenedField } from 'payload';
|
|
2
|
+
import type { MongooseAdapter } from '../index.js';
|
|
3
|
+
type Args = {
|
|
4
|
+
adapter: MongooseAdapter;
|
|
5
|
+
data: Record<string, unknown> | Record<string, unknown>[];
|
|
6
|
+
fields: FlattenedField[];
|
|
7
|
+
globalSlug?: string;
|
|
8
|
+
operation: 'create' | 'read' | 'update';
|
|
9
|
+
/**
|
|
10
|
+
* Throw errors on invalid relationships
|
|
11
|
+
* @default true
|
|
12
|
+
*/
|
|
13
|
+
validateRelationships?: boolean;
|
|
14
|
+
};
|
|
15
|
+
export declare const transform: ({ adapter, data, fields, globalSlug, operation, validateRelationships, }: Args) => void;
|
|
16
|
+
export {};
|
|
17
|
+
//# sourceMappingURL=transform.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transform.d.ts","sourceRoot":"","sources":["../../src/utilities/transform.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,cAAc,EAMf,MAAM,SAAS,CAAA;AAMhB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAElD,KAAK,IAAI,GAAG;IACV,OAAO,EAAE,eAAe,CAAA;IACxB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAA;IACzD,MAAM,EAAE,cAAc,EAAE,CAAA;IACxB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,SAAS,EAAE,QAAQ,GAAG,MAAM,GAAG,QAAQ,CAAA;IACvC;;;OAGG;IACH,qBAAqB,CAAC,EAAE,OAAO,CAAA;CAChC,CAAA;AAwMD,eAAO,MAAM,SAAS,6EAOnB,IAAI,SA0IN,CAAA"}
|