@payloadcms/db-mongodb 3.91.0-internal.c1569dc → 3.92.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.
@@ -0,0 +1,21 @@
1
+ import type { Connection, Schema } from 'mongoose';
2
+ import type { SchemaBuildContext } from 'payload/internal';
3
+ import type { BuildSchemaOptions } from './buildSchema.js';
4
+ export type MongoSchemaBuildContext = SchemaBuildContext<Schema>;
5
+ /**
6
+ * Connection and global plugins can keep state on each nested schema. Mongoose does not clone
7
+ * those nested schemas when it attaches a discriminator, so cached templates would change plugin
8
+ * application.
9
+ */
10
+ export declare const createMongoSchemaBuildContext: ({ connection, }: {
11
+ connection: Connection;
12
+ }) => MongoSchemaBuildContext;
13
+ export declare const getBlockSchemaCacheKey: ({ blockSlug, buildSchemaOptions, fieldPath, isLocalized, isReference, isVersion, }: {
14
+ blockSlug: string;
15
+ buildSchemaOptions: BuildSchemaOptions;
16
+ fieldPath: string;
17
+ isLocalized: boolean;
18
+ isReference: boolean;
19
+ isVersion: boolean;
20
+ }) => string;
21
+ //# sourceMappingURL=schemaBuildContext.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schemaBuildContext.d.ts","sourceRoot":"","sources":["../../src/models/schemaBuildContext.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AAClD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAA;AAK1D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAA;AAE1D,MAAM,MAAM,uBAAuB,GAAG,kBAAkB,CAAC,MAAM,CAAC,CAAA;AAiBhE;;;;GAIG;AACH,eAAO,MAAM,6BAA6B,oBAEvC;IACD,UAAU,EAAE,UAAU,CAAA;CACvB,KAAG,uBAQH,CAAA;AAED,eAAO,MAAM,sBAAsB,uFAOhC;IACD,SAAS,EAAE,MAAM,CAAA;IACjB,kBAAkB,EAAE,kBAAkB,CAAA;IACtC,SAAS,EAAE,MAAM,CAAA;IACjB,WAAW,EAAE,OAAO,CAAA;IACpB,WAAW,EAAE,OAAO,CAAA;IACpB,SAAS,EAAE,OAAO,CAAA;CACnB,KAAG,MASU,CAAA"}
@@ -0,0 +1,29 @@
1
+ import mongoose from 'mongoose';
2
+ import { createSchemaBuildContext } from 'payload/internal';
3
+ const getMongoosePluginRegistry = ({ mongooseInstance })=>mongooseInstance.plugins;
4
+ const defaultMongoosePluginFunctions = new Set(getMongoosePluginRegistry({
5
+ mongooseInstance: new mongoose.Mongoose({
6
+ createInitialConnection: false
7
+ })
8
+ }).map(([plugin])=>plugin));
9
+ /**
10
+ * Connection and global plugins can keep state on each nested schema. Mongoose does not clone
11
+ * those nested schemas when it attaches a discriminator, so cached templates would change plugin
12
+ * application.
13
+ */ export const createMongoSchemaBuildContext = ({ connection })=>{
14
+ const hasCustomGlobalPlugins = getMongoosePluginRegistry({
15
+ mongooseInstance: connection.base
16
+ }).some(([plugin])=>!defaultMongoosePluginFunctions.has(plugin));
17
+ return createSchemaBuildContext({
18
+ isCacheEnabled: connection.plugins.length === 0 && !hasCustomGlobalPlugins
19
+ });
20
+ };
21
+ export const getBlockSchemaCacheKey = ({ blockSlug, buildSchemaOptions, fieldPath, isLocalized, isReference, isVersion })=>[
22
+ `${isReference ? `block:${blockSlug}` : `inline:${fieldPath}/block:${blockSlug}`}${isVersion ? '-version' : ''}`,
23
+ buildSchemaOptions.disableUnique && 'disableUnique:true',
24
+ buildSchemaOptions.draftsEnabled && 'draftsEnabled:true',
25
+ buildSchemaOptions.indexSortableFields && 'indexSortableFields:true',
26
+ isLocalized && 'isLocalized:true'
27
+ ].filter(Boolean).join('|');
28
+
29
+ //# sourceMappingURL=schemaBuildContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/models/schemaBuildContext.ts"],"sourcesContent":["import type { Connection, Schema } from 'mongoose'\nimport type { SchemaBuildContext } from 'payload/internal'\n\nimport mongoose from 'mongoose'\nimport { createSchemaBuildContext } from 'payload/internal'\n\nimport type { BuildSchemaOptions } from './buildSchema.js'\n\nexport type MongoSchemaBuildContext = SchemaBuildContext<Schema>\n\ntype MongoosePluginRegistry = Array<[Parameters<typeof mongoose.plugin>[0], unknown]>\n\nconst getMongoosePluginRegistry = ({\n mongooseInstance,\n}: {\n mongooseInstance: typeof mongoose\n}): MongoosePluginRegistry =>\n (mongooseInstance as { plugins: MongoosePluginRegistry } & typeof mongoose).plugins\n\nconst defaultMongoosePluginFunctions = new Set(\n getMongoosePluginRegistry({\n mongooseInstance: new mongoose.Mongoose({ createInitialConnection: false }),\n }).map(([plugin]) => plugin),\n)\n\n/**\n * Connection and global plugins can keep state on each nested schema. Mongoose does not clone\n * those nested schemas when it attaches a discriminator, so cached templates would change plugin\n * application.\n */\nexport const createMongoSchemaBuildContext = ({\n connection,\n}: {\n connection: Connection\n}): MongoSchemaBuildContext => {\n const hasCustomGlobalPlugins = getMongoosePluginRegistry({\n mongooseInstance: connection.base,\n }).some(([plugin]) => !defaultMongoosePluginFunctions.has(plugin))\n\n return createSchemaBuildContext<Schema>({\n isCacheEnabled: connection.plugins.length === 0 && !hasCustomGlobalPlugins,\n })\n}\n\nexport const getBlockSchemaCacheKey = ({\n blockSlug,\n buildSchemaOptions,\n fieldPath,\n isLocalized,\n isReference,\n isVersion,\n}: {\n blockSlug: string\n buildSchemaOptions: BuildSchemaOptions\n fieldPath: string\n isLocalized: boolean\n isReference: boolean\n isVersion: boolean\n}): string =>\n [\n `${isReference ? `block:${blockSlug}` : `inline:${fieldPath}/block:${blockSlug}`}${isVersion ? '-version' : ''}`,\n buildSchemaOptions.disableUnique && 'disableUnique:true',\n buildSchemaOptions.draftsEnabled && 'draftsEnabled:true',\n buildSchemaOptions.indexSortableFields && 'indexSortableFields:true',\n isLocalized && 'isLocalized:true',\n ]\n .filter(Boolean)\n .join('|')\n"],"names":["mongoose","createSchemaBuildContext","getMongoosePluginRegistry","mongooseInstance","plugins","defaultMongoosePluginFunctions","Set","Mongoose","createInitialConnection","map","plugin","createMongoSchemaBuildContext","connection","hasCustomGlobalPlugins","base","some","has","isCacheEnabled","length","getBlockSchemaCacheKey","blockSlug","buildSchemaOptions","fieldPath","isLocalized","isReference","isVersion","disableUnique","draftsEnabled","indexSortableFields","filter","Boolean","join"],"mappings":"AAGA,OAAOA,cAAc,WAAU;AAC/B,SAASC,wBAAwB,QAAQ,mBAAkB;AAQ3D,MAAMC,4BAA4B,CAAC,EACjCC,gBAAgB,EAGjB,GACC,AAACA,iBAA2EC,OAAO;AAErF,MAAMC,iCAAiC,IAAIC,IACzCJ,0BAA0B;IACxBC,kBAAkB,IAAIH,SAASO,QAAQ,CAAC;QAAEC,yBAAyB;IAAM;AAC3E,GAAGC,GAAG,CAAC,CAAC,CAACC,OAAO,GAAKA;AAGvB;;;;CAIC,GACD,OAAO,MAAMC,gCAAgC,CAAC,EAC5CC,UAAU,EAGX;IACC,MAAMC,yBAAyBX,0BAA0B;QACvDC,kBAAkBS,WAAWE,IAAI;IACnC,GAAGC,IAAI,CAAC,CAAC,CAACL,OAAO,GAAK,CAACL,+BAA+BW,GAAG,CAACN;IAE1D,OAAOT,yBAAiC;QACtCgB,gBAAgBL,WAAWR,OAAO,CAACc,MAAM,KAAK,KAAK,CAACL;IACtD;AACF,EAAC;AAED,OAAO,MAAMM,yBAAyB,CAAC,EACrCC,SAAS,EACTC,kBAAkB,EAClBC,SAAS,EACTC,WAAW,EACXC,WAAW,EACXC,SAAS,EAQV,GACC;QACE,GAAGD,cAAc,CAAC,MAAM,EAAEJ,WAAW,GAAG,CAAC,OAAO,EAAEE,UAAU,OAAO,EAAEF,WAAW,GAAGK,YAAY,aAAa,IAAI;QAChHJ,mBAAmBK,aAAa,IAAI;QACpCL,mBAAmBM,aAAa,IAAI;QACpCN,mBAAmBO,mBAAmB,IAAI;QAC1CL,eAAe;KAChB,CACEM,MAAM,CAACC,SACPC,IAAI,CAAC,KAAI"}
@@ -0,0 +1,72 @@
1
+ import mongoose from 'mongoose';
2
+ import { describe, expect, test, vi } from 'vitest';
3
+ import { createMongoSchemaBuildContext } from './schemaBuildContext.js';
4
+ describe('createMongoSchemaBuildContext', ()=>{
5
+ test('should reuse schemas when the connection has no custom plugins', ()=>{
6
+ const connection = mongoose.createConnection();
7
+ const context = createMongoSchemaBuildContext({
8
+ connection
9
+ });
10
+ const definition = {};
11
+ const build = vi.fn(()=>new mongoose.Schema());
12
+ const first = context.getOrCreate({
13
+ build,
14
+ definition,
15
+ cacheKey: 'block:shared'
16
+ });
17
+ const second = context.getOrCreate({
18
+ build,
19
+ definition,
20
+ cacheKey: 'block:shared'
21
+ });
22
+ expect(first).toBe(second);
23
+ expect(build).toHaveBeenCalledOnce();
24
+ });
25
+ test('should build independent schemas when the connection has a custom plugin', ()=>{
26
+ const connection = mongoose.createConnection();
27
+ connection.plugin(()=>undefined);
28
+ const context = createMongoSchemaBuildContext({
29
+ connection
30
+ });
31
+ const definition = {};
32
+ const build = vi.fn(()=>new mongoose.Schema());
33
+ const first = context.getOrCreate({
34
+ build,
35
+ definition,
36
+ cacheKey: 'block:shared'
37
+ });
38
+ const second = context.getOrCreate({
39
+ build,
40
+ definition,
41
+ cacheKey: 'block:shared'
42
+ });
43
+ expect(first).not.toBe(second);
44
+ expect(build).toHaveBeenCalledTimes(2);
45
+ });
46
+ test('should build independent schemas when the Mongoose instance has a custom plugin', ()=>{
47
+ const mongooseWithCustomPlugin = new mongoose.Mongoose({
48
+ createInitialConnection: false
49
+ });
50
+ mongooseWithCustomPlugin.plugin(()=>undefined);
51
+ const connection = mongooseWithCustomPlugin.createConnection();
52
+ const context = createMongoSchemaBuildContext({
53
+ connection
54
+ });
55
+ const definition = {};
56
+ const build = vi.fn(()=>new mongoose.Schema());
57
+ const first = context.getOrCreate({
58
+ build,
59
+ definition,
60
+ cacheKey: 'block:shared'
61
+ });
62
+ const second = context.getOrCreate({
63
+ build,
64
+ definition,
65
+ cacheKey: 'block:shared'
66
+ });
67
+ expect(first).not.toBe(second);
68
+ expect(build).toHaveBeenCalledTimes(2);
69
+ });
70
+ });
71
+
72
+ //# sourceMappingURL=schemaBuildContext.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/models/schemaBuildContext.spec.ts"],"sourcesContent":["import mongoose from 'mongoose'\nimport { describe, expect, test, vi } from 'vitest'\n\nimport { createMongoSchemaBuildContext } from './schemaBuildContext.js'\n\ndescribe('createMongoSchemaBuildContext', () => {\n test('should reuse schemas when the connection has no custom plugins', () => {\n const connection = mongoose.createConnection()\n const context = createMongoSchemaBuildContext({ connection })\n const definition = {}\n const build = vi.fn(() => new mongoose.Schema())\n\n const first = context.getOrCreate({\n build,\n definition,\n cacheKey: 'block:shared',\n })\n const second = context.getOrCreate({\n build,\n definition,\n cacheKey: 'block:shared',\n })\n\n expect(first).toBe(second)\n expect(build).toHaveBeenCalledOnce()\n })\n\n test('should build independent schemas when the connection has a custom plugin', () => {\n const connection = mongoose.createConnection()\n connection.plugin(() => undefined)\n const context = createMongoSchemaBuildContext({ connection })\n const definition = {}\n const build = vi.fn(() => new mongoose.Schema())\n\n const first = context.getOrCreate({\n build,\n definition,\n cacheKey: 'block:shared',\n })\n const second = context.getOrCreate({\n build,\n definition,\n cacheKey: 'block:shared',\n })\n\n expect(first).not.toBe(second)\n expect(build).toHaveBeenCalledTimes(2)\n })\n\n test('should build independent schemas when the Mongoose instance has a custom plugin', () => {\n const mongooseWithCustomPlugin = new mongoose.Mongoose({ createInitialConnection: false })\n mongooseWithCustomPlugin.plugin(() => undefined)\n const connection = mongooseWithCustomPlugin.createConnection()\n const context = createMongoSchemaBuildContext({ connection })\n const definition = {}\n const build = vi.fn(() => new mongoose.Schema())\n\n const first = context.getOrCreate({\n build,\n definition,\n cacheKey: 'block:shared',\n })\n const second = context.getOrCreate({\n build,\n definition,\n cacheKey: 'block:shared',\n })\n\n expect(first).not.toBe(second)\n expect(build).toHaveBeenCalledTimes(2)\n })\n})\n"],"names":["mongoose","describe","expect","test","vi","createMongoSchemaBuildContext","connection","createConnection","context","definition","build","fn","Schema","first","getOrCreate","cacheKey","second","toBe","toHaveBeenCalledOnce","plugin","undefined","not","toHaveBeenCalledTimes","mongooseWithCustomPlugin","Mongoose","createInitialConnection"],"mappings":"AAAA,OAAOA,cAAc,WAAU;AAC/B,SAASC,QAAQ,EAAEC,MAAM,EAAEC,IAAI,EAAEC,EAAE,QAAQ,SAAQ;AAEnD,SAASC,6BAA6B,QAAQ,0BAAyB;AAEvEJ,SAAS,iCAAiC;IACxCE,KAAK,kEAAkE;QACrE,MAAMG,aAAaN,SAASO,gBAAgB;QAC5C,MAAMC,UAAUH,8BAA8B;YAAEC;QAAW;QAC3D,MAAMG,aAAa,CAAC;QACpB,MAAMC,QAAQN,GAAGO,EAAE,CAAC,IAAM,IAAIX,SAASY,MAAM;QAE7C,MAAMC,QAAQL,QAAQM,WAAW,CAAC;YAChCJ;YACAD;YACAM,UAAU;QACZ;QACA,MAAMC,SAASR,QAAQM,WAAW,CAAC;YACjCJ;YACAD;YACAM,UAAU;QACZ;QAEAb,OAAOW,OAAOI,IAAI,CAACD;QACnBd,OAAOQ,OAAOQ,oBAAoB;IACpC;IAEAf,KAAK,4EAA4E;QAC/E,MAAMG,aAAaN,SAASO,gBAAgB;QAC5CD,WAAWa,MAAM,CAAC,IAAMC;QACxB,MAAMZ,UAAUH,8BAA8B;YAAEC;QAAW;QAC3D,MAAMG,aAAa,CAAC;QACpB,MAAMC,QAAQN,GAAGO,EAAE,CAAC,IAAM,IAAIX,SAASY,MAAM;QAE7C,MAAMC,QAAQL,QAAQM,WAAW,CAAC;YAChCJ;YACAD;YACAM,UAAU;QACZ;QACA,MAAMC,SAASR,QAAQM,WAAW,CAAC;YACjCJ;YACAD;YACAM,UAAU;QACZ;QAEAb,OAAOW,OAAOQ,GAAG,CAACJ,IAAI,CAACD;QACvBd,OAAOQ,OAAOY,qBAAqB,CAAC;IACtC;IAEAn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C;IACvC,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB,CAAA;AAED,eAAO,MAAM,oBAAoB,mGAS9B,wBAAwB,KAAG,OAAO,CAAC,aAAa,EAAE,CA0cpD,CAAA"}
1
+ {"version":3,"file":"buildJoinAggregation.d.ts","sourceRoot":"","sources":["../../src/utilities/buildJoinAggregation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAE7C,OAAO,EAIL,KAAK,cAAc,EAInB,KAAK,SAAS,EACd,KAAK,yBAAyB,EAC/B,MAAM,SAAS,CAAA;AAGhB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAOlD,KAAK,wBAAwB,GAAG;IAC9B,OAAO,EAAE,eAAe,CAAA;IACxB,UAAU,EAAE,cAAc,CAAA;IAC1B,gBAAgB,EAAE,yBAAyB,CAAA;IAC3C,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,KAAK,CAAC,EAAE,SAAS,CAAA;IACjB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAA;IAEjC,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC/B,uCAAuC;IACvC,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB,CAAA;AAED,eAAO,MAAM,oBAAoB,mGAS9B,wBAAwB,KAAG,OAAO,CAAC,aAAa,EAAE,CAgdpD,CAAA"}
@@ -104,10 +104,12 @@ export const buildJoinAggregation = async ({ adapter, collection, collectionConf
104
104
  [sortProperty]: sortDirection
105
105
  }
106
106
  },
107
- {
108
- // Unfortunately, we can't use $skip here because we can lose data, instead we do $slice then
109
- $limit: page ? page * limitJoin : limitJoin
110
- },
107
+ ...limitJoin > 0 ? [
108
+ {
109
+ // Unfortunately, we can't use $skip here because we can lose data, instead we do $slice then
110
+ $limit: page ? page * limitJoin : limitJoin
111
+ }
112
+ ] : [],
111
113
  {
112
114
  $project: {
113
115
  value: '$_id',
@@ -191,16 +193,18 @@ export const buildJoinAggregation = async ({ adapter, collection, collectionConf
191
193
  }
192
194
  }
193
195
  });
194
- aggregate.push({
195
- $set: {
196
- [`${as}.docs`]: {
197
- $slice: [
198
- `$${as}.docs`,
199
- ...sliceValue
200
- ]
196
+ if (limitJoin > 0) {
197
+ aggregate.push({
198
+ $set: {
199
+ [`${as}.docs`]: {
200
+ $slice: [
201
+ `$${as}.docs`,
202
+ ...sliceValue
203
+ ]
204
+ }
201
205
  }
202
- }
203
- });
206
+ });
207
+ }
204
208
  }
205
209
  for (const slug of Object.keys(joinConfig)){
206
210
  const joinsList = joinConfig[slug];
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utilities/buildJoinAggregation.ts"],"sourcesContent":["import type { PipelineStage } from 'mongoose'\n\nimport {\n APIError,\n appendVersionToQueryKey,\n buildVersionCollectionFields,\n type CollectionSlug,\n combineQueries,\n type FlattenedField,\n getQueryDraftsSort,\n type JoinQuery,\n type SanitizedCollectionConfig,\n} from 'payload'\nimport { fieldShouldBeLocalized, hasDraftsEnabled } from 'payload/shared'\n\nimport type { MongooseAdapter } from '../index.js'\nimport type { CollectionModel } from '../types.js'\n\nimport { buildQuery } from '../queries/buildQuery.js'\nimport { buildSortParam } from '../queries/buildSortParam.js'\nimport { getCollection } from './getEntity.js'\n\ntype BuildJoinAggregationArgs = {\n adapter: MongooseAdapter\n collection: CollectionSlug\n collectionConfig: SanitizedCollectionConfig\n draftsEnabled?: boolean\n joins?: JoinQuery\n locale?: string\n projection?: Record<string, true>\n // the where clause for the top collection\n query?: Record<string, unknown>\n /** whether the query is from drafts */\n versions?: boolean\n}\n\nexport const buildJoinAggregation = async ({\n adapter,\n collection,\n collectionConfig,\n draftsEnabled,\n joins,\n locale,\n projection,\n versions,\n}: BuildJoinAggregationArgs): Promise<PipelineStage[]> => {\n if (!adapter.useJoinAggregations) {\n return []\n }\n if (\n (Object.keys(collectionConfig.joins).length === 0 &&\n collectionConfig.polymorphicJoins.length == 0) ||\n joins === false\n ) {\n return []\n }\n\n const joinConfig = adapter.payload.collections[collection]?.config?.joins\n\n if (!joinConfig) {\n throw new APIError(`Could not retrieve sanitized join config for ${collection}.`)\n }\n\n const aggregate: PipelineStage[] = []\n const polymorphicJoinsConfig = adapter.payload.collections[collection]?.config?.polymorphicJoins\n\n if (!polymorphicJoinsConfig) {\n throw new APIError(`Could not retrieve sanitized polymorphic joins config for ${collection}.`)\n }\n\n for (const join of polymorphicJoinsConfig) {\n if (projection && !projection[join.joinPath]) {\n continue\n }\n\n if (joins?.[join.joinPath] === false) {\n continue\n }\n\n const {\n count = false,\n limit: limitJoin = join.field.defaultLimit ?? 10,\n page,\n sort: sortJoin = join.field.defaultSort || collectionConfig.defaultSort,\n where: whereJoin = {},\n } = joins?.[join.joinPath] || {}\n\n const aggregatedFields: FlattenedField[] = []\n for (const collectionSlug of join.field.collection) {\n const { collectionConfig } = getCollection({ adapter, collectionSlug })\n\n for (const field of collectionConfig.flattenedFields) {\n if (!aggregatedFields.some((eachField) => eachField.name === field.name)) {\n aggregatedFields.push(field)\n }\n }\n }\n\n const sort = buildSortParam({\n adapter,\n config: adapter.payload.config,\n fields: aggregatedFields,\n locale,\n sort: sortJoin,\n timestamps: true,\n })\n\n const $match = await buildQuery({\n adapter,\n fields: aggregatedFields,\n locale,\n where: whereJoin,\n })\n\n const sortProperty = Object.keys(sort)[0]! // assert because buildSortParam always returns at least 1 key.\n const sortDirection = sort[sortProperty] === 'asc' ? 1 : -1\n\n const projectSort = sortProperty !== '_id' && sortProperty !== 'relationTo'\n\n const aliases: string[] = []\n\n const as = join.joinPath\n\n for (const collectionSlug of join.field.collection) {\n const alias = `${as}.docs.${collectionSlug}`\n aliases.push(alias)\n\n const basePipeline = [\n {\n $addFields: {\n relationTo: {\n $literal: collectionSlug,\n },\n },\n },\n {\n $match: {\n $and: [\n {\n $expr: {\n $eq: [`$${join.field.on}`, '$$root_id_'],\n },\n },\n $match,\n ],\n },\n },\n ]\n\n const { Model: JoinModel } = getCollection({ adapter, collectionSlug })\n\n aggregate.push({\n $lookup: {\n as: alias,\n from: JoinModel.collection.name,\n let: {\n root_id_: '$_id',\n },\n pipeline: [\n ...basePipeline,\n {\n $sort: {\n [sortProperty]: sortDirection,\n },\n },\n {\n // Unfortunately, we can't use $skip here because we can lose data, instead we do $slice then\n $limit: page ? page * limitJoin : limitJoin,\n },\n {\n $project: {\n value: '$_id',\n ...(projectSort && {\n [sortProperty]: 1,\n }),\n relationTo: 1,\n },\n },\n ],\n },\n })\n\n if (count) {\n aggregate.push({\n $lookup: {\n as: `${as}.totalDocs.${alias}`,\n from: JoinModel.collection.name,\n let: {\n root_id_: '$_id',\n },\n pipeline: [\n ...basePipeline,\n {\n $count: 'result',\n },\n ],\n },\n })\n }\n }\n\n aggregate.push({\n $addFields: {\n [`${as}.docs`]: {\n $concatArrays: aliases.map((alias) => `$${alias}`),\n },\n },\n })\n\n if (count) {\n aggregate.push({\n $addFields: {\n [`${as}.totalDocs`]: {\n $add: aliases.map((alias) => ({\n $ifNull: [\n {\n $first: `$${as}.totalDocs.${alias}.result`,\n },\n 0,\n ],\n })),\n },\n },\n })\n }\n\n aggregate.push({\n $set: {\n [`${as}.docs`]: {\n $sortArray: {\n input: `$${as}.docs`,\n sortBy: {\n [sortProperty]: sortDirection,\n },\n },\n },\n },\n })\n\n const sliceValue = page ? [(page - 1) * limitJoin, limitJoin] : [limitJoin]\n\n aggregate.push({\n $addFields: {\n [`${as}.hasNextPage`]: {\n $gt: [{ $size: `$${as}.docs` }, limitJoin || Number.MAX_VALUE],\n },\n },\n })\n\n aggregate.push({\n $set: {\n [`${as}.docs`]: {\n $slice: [`$${as}.docs`, ...sliceValue],\n },\n },\n })\n }\n\n for (const slug of Object.keys(joinConfig)) {\n const joinsList = joinConfig[slug]\n\n if (!joinsList) {\n throw new APIError(`Failed to retrieve array of joins for ${slug} in collectio ${collection}`)\n }\n\n for (const join of joinsList) {\n const projectionPath = versions ? `version.${join.joinPath}` : join.joinPath\n if (projection && !projection[projectionPath]) {\n continue\n }\n\n if (joins?.[join.joinPath] === false) {\n continue\n }\n\n const collectionConfig = adapter.payload.collections[join.field.collection as string]?.config\n\n if (!collectionConfig) {\n throw new APIError(\n `Collection config for ${join.field.collection.toString()} was not found`,\n )\n }\n\n let JoinModel: CollectionModel | undefined\n\n const useDrafts = (draftsEnabled || versions) && hasDraftsEnabled(collectionConfig)\n\n if (useDrafts) {\n JoinModel = adapter.versions[collectionConfig.slug]\n } else {\n JoinModel = adapter.collections[collectionConfig.slug]\n }\n\n if (!JoinModel) {\n throw new APIError(`Join Model was not found for ${collectionConfig.slug}`)\n }\n\n const {\n count,\n limit: limitJoin = join.field.defaultLimit ?? 10,\n page,\n sort: sortJoin = join.field.defaultSort || collectionConfig.defaultSort,\n where: whereJoin = {},\n } = joins?.[join.joinPath] || {}\n\n if (Array.isArray(join.field.collection)) {\n throw new Error('Unreachable')\n }\n\n const fields = useDrafts\n ? buildVersionCollectionFields(adapter.payload.config, collectionConfig, true)\n : collectionConfig.flattenedFields\n\n const sort = buildSortParam({\n adapter,\n config: adapter.payload.config,\n fields,\n locale,\n sort: useDrafts ? getQueryDraftsSort({ collectionConfig, sort: sortJoin }) : 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: useDrafts\n ? combineQueries(appendVersionToQueryKey(whereJoin), {\n latest: {\n equals: true,\n },\n })\n : whereJoin,\n })\n\n const pipeline: Exclude<PipelineStage, PipelineStage.Merge | PipelineStage.Out>[] = [\n { $match },\n {\n $sort: { [sortProperty]: sortDirection },\n },\n ]\n\n if (page) {\n pipeline.push({\n $skip: (page - 1) * limitJoin,\n })\n }\n\n if (limitJoin > 0) {\n pipeline.push({\n $limit: limitJoin + 1,\n })\n }\n\n let polymorphicSuffix = ''\n if (Array.isArray(join.targetField.relationTo)) {\n polymorphicSuffix = '.value'\n }\n\n const addTotalDocsAggregation = (as: string, foreignField: string) =>\n aggregate.push(\n {\n $lookup: {\n as: `${as}.totalDocs`,\n foreignField,\n from: JoinModel.collection.name,\n localField: versions ? 'parent' : '_id',\n pipeline: [\n {\n $match,\n },\n {\n $count: 'result',\n },\n ],\n },\n },\n {\n $addFields: {\n [`${as}.totalDocs`]: { $ifNull: [{ $first: `$${as}.totalDocs.result` }, 0] },\n },\n },\n )\n\n let foreignFieldPrefix = ''\n\n if (useDrafts) {\n foreignFieldPrefix = 'version.'\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: `${foreignFieldPrefix}${join.field.on}${code}${polymorphicSuffix}`,\n from: JoinModel.collection.name,\n localField: versions ? 'parent' : '_id',\n pipeline,\n },\n },\n {\n $addFields: {\n [`${as}.docs`]: {\n $map: {\n as: 'doc',\n in: useDrafts ? `$$doc.parent` : '$$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\n if (limitJoin > 0) {\n aggregate.push({\n $addFields: {\n [`${as}.docs`]: {\n $slice: [`$${as}.docs`, limitJoin],\n },\n },\n })\n }\n\n if (count) {\n addTotalDocsAggregation(\n as,\n `${foreignFieldPrefix}${join.field.on}${code}${polymorphicSuffix}`,\n )\n }\n })\n } else {\n const localeSuffix =\n fieldShouldBeLocalized({\n field: join.field,\n parentIsLocalized: join.parentIsLocalized,\n }) &&\n adapter.payload.config.localization &&\n locale\n ? `.${locale}`\n : ''\n const as = `${versions ? `version.${join.joinPath}` : join.joinPath}${localeSuffix}`\n\n let foreignField: string\n\n if (join.getForeignPath) {\n foreignField = `${join.getForeignPath({ locale })}${polymorphicSuffix}`\n } else {\n foreignField = `${join.field.on}${polymorphicSuffix}`\n }\n\n aggregate.push(\n {\n $lookup: {\n as: `${as}.docs`,\n foreignField: `${foreignFieldPrefix}${foreignField}`,\n from: JoinModel.collection.name,\n localField: versions ? 'parent' : '_id',\n pipeline,\n },\n },\n {\n $addFields: {\n [`${as}.docs`]: {\n $map: {\n as: 'doc',\n in: useDrafts ? `$$doc.parent` : '$$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\n if (count) {\n addTotalDocsAggregation(as, `${foreignFieldPrefix}${foreignField}`)\n }\n\n if (limitJoin > 0) {\n aggregate.push({\n $addFields: {\n [`${as}.docs`]: {\n $slice: [`$${as}.docs`, limitJoin],\n },\n },\n })\n }\n }\n }\n }\n\n return aggregate\n}\n"],"names":["APIError","appendVersionToQueryKey","buildVersionCollectionFields","combineQueries","getQueryDraftsSort","fieldShouldBeLocalized","hasDraftsEnabled","buildQuery","buildSortParam","getCollection","buildJoinAggregation","adapter","collection","collectionConfig","draftsEnabled","joins","locale","projection","versions","useJoinAggregations","Object","keys","length","polymorphicJoins","joinConfig","payload","collections","config","aggregate","polymorphicJoinsConfig","join","joinPath","count","limit","limitJoin","field","defaultLimit","page","sort","sortJoin","defaultSort","where","whereJoin","aggregatedFields","collectionSlug","flattenedFields","some","eachField","name","push","fields","timestamps","$match","sortProperty","sortDirection","projectSort","aliases","as","alias","basePipeline","$addFields","relationTo","$literal","$and","$expr","$eq","on","Model","JoinModel","$lookup","from","let","root_id_","pipeline","$sort","$limit","$project","value","$count","$concatArrays","map","$add","$ifNull","$first","$set","$sortArray","input","sortBy","sliceValue","$gt","$size","Number","MAX_VALUE","$slice","slug","joinsList","projectionPath","toString","useDrafts","Array","isArray","Error","latest","equals","$skip","polymorphicSuffix","targetField","addTotalDocsAggregation","foreignField","localField","foreignFieldPrefix","localization","localeCodes","forEach","code","$map","in","localeSuffix","parentIsLocalized","getForeignPath"],"mappings":"AAEA,SACEA,QAAQ,EACRC,uBAAuB,EACvBC,4BAA4B,EAE5BC,cAAc,EAEdC,kBAAkB,QAGb,UAAS;AAChB,SAASC,sBAAsB,EAAEC,gBAAgB,QAAQ,iBAAgB;AAKzE,SAASC,UAAU,QAAQ,2BAA0B;AACrD,SAASC,cAAc,QAAQ,+BAA8B;AAC7D,SAASC,aAAa,QAAQ,iBAAgB;AAgB9C,OAAO,MAAMC,uBAAuB,OAAO,EACzCC,OAAO,EACPC,UAAU,EACVC,gBAAgB,EAChBC,aAAa,EACbC,KAAK,EACLC,MAAM,EACNC,UAAU,EACVC,QAAQ,EACiB;IACzB,IAAI,CAACP,QAAQQ,mBAAmB,EAAE;QAChC,OAAO,EAAE;IACX;IACA,IACE,AAACC,OAAOC,IAAI,CAACR,iBAAiBE,KAAK,EAAEO,MAAM,KAAK,KAC9CT,iBAAiBU,gBAAgB,CAACD,MAAM,IAAI,KAC9CP,UAAU,OACV;QACA,OAAO,EAAE;IACX;IAEA,MAAMS,aAAab,QAAQc,OAAO,CAACC,WAAW,CAACd,WAAW,EAAEe,QAAQZ;IAEpE,IAAI,CAACS,YAAY;QACf,MAAM,IAAIxB,SAAS,CAAC,6CAA6C,EAAEY,WAAW,CAAC,CAAC;IAClF;IAEA,MAAMgB,YAA6B,EAAE;IACrC,MAAMC,yBAAyBlB,QAAQc,OAAO,CAACC,WAAW,CAACd,WAAW,EAAEe,QAAQJ;IAEhF,IAAI,CAACM,wBAAwB;QAC3B,MAAM,IAAI7B,SAAS,CAAC,0DAA0D,EAAEY,WAAW,CAAC,CAAC;IAC/F;IAEA,KAAK,MAAMkB,QAAQD,uBAAwB;QACzC,IAAIZ,cAAc,CAACA,UAAU,CAACa,KAAKC,QAA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AClCuD;oBACF;gBACF,GACA;oBACEb,YAAY;wBACV,CAAC,GAAGH,GAAG,KAAK,CAAC,CAAC,EAAE;4BACd0D,MAAM;gCACJ1D,IAAI;gCACJ2D,IAAIlB,YAAY,CAAC,YAAY,CAAC,GAAG;gCACjCZ,OAAO,CAAC,CAAC,EAAE7B,GAAG,KAAK,CAAC;4BACtB;wBACF;wBACA,CAAC,GAAGA,GAAG,YAAY,CAAC,CAAC,EAAE;4BACrBgC,KAAK;gCAAC;oCAAEC,OAAO,CAAC,CAAC,EAAEjC,GAAG,KAAK,CAAC;gCAAC;gCAAGvB,aAAayD,OAAOC,SAAS;6BAAC;wBAChE;oBACF;gBACF;gBAGF,IAAI5D,OAAO;oBACT2E,wBAAwBlD,IAAI,GAAGqD,qBAAqBF,cAAc;gBACpE;gBAEA,IAAI1E,YAAY,GAAG;oBACjBN,UAAUqB,IAAI,CAAC;wBACbW,YAAY;4BACV,CAAC,GAAGH,GAAG,KAAK,CAAC,CAAC,EAAE;gCACdoC,QAAQ;oCAAC,CAAC,CAAC,EAAEpC,GAAG,KAAK,CAAC;oCAAEvB;iCAAU;4BACpC;wBACF;oBACF;gBACF;YACF;QACF;IACF;IAEA,OAAON;AACT,EAAC"}
1
+ {"version":3,"sources":["../../src/utilities/buildJoinAggregation.ts"],"sourcesContent":["import type { PipelineStage } from 'mongoose'\n\nimport {\n APIError,\n appendVersionToQueryKey,\n buildVersionCollectionFields,\n type CollectionSlug,\n combineQueries,\n type FlattenedField,\n getQueryDraftsSort,\n type JoinQuery,\n type SanitizedCollectionConfig,\n} from 'payload'\nimport { fieldShouldBeLocalized, hasDraftsEnabled } from 'payload/shared'\n\nimport type { MongooseAdapter } from '../index.js'\nimport type { CollectionModel } from '../types.js'\n\nimport { buildQuery } from '../queries/buildQuery.js'\nimport { buildSortParam } from '../queries/buildSortParam.js'\nimport { getCollection } from './getEntity.js'\n\ntype BuildJoinAggregationArgs = {\n adapter: MongooseAdapter\n collection: CollectionSlug\n collectionConfig: SanitizedCollectionConfig\n draftsEnabled?: boolean\n joins?: JoinQuery\n locale?: string\n projection?: Record<string, true>\n // the where clause for the top collection\n query?: Record<string, unknown>\n /** whether the query is from drafts */\n versions?: boolean\n}\n\nexport const buildJoinAggregation = async ({\n adapter,\n collection,\n collectionConfig,\n draftsEnabled,\n joins,\n locale,\n projection,\n versions,\n}: BuildJoinAggregationArgs): Promise<PipelineStage[]> => {\n if (!adapter.useJoinAggregations) {\n return []\n }\n if (\n (Object.keys(collectionConfig.joins).length === 0 &&\n collectionConfig.polymorphicJoins.length == 0) ||\n joins === false\n ) {\n return []\n }\n\n const joinConfig = adapter.payload.collections[collection]?.config?.joins\n\n if (!joinConfig) {\n throw new APIError(`Could not retrieve sanitized join config for ${collection}.`)\n }\n\n const aggregate: PipelineStage[] = []\n const polymorphicJoinsConfig = adapter.payload.collections[collection]?.config?.polymorphicJoins\n\n if (!polymorphicJoinsConfig) {\n throw new APIError(`Could not retrieve sanitized polymorphic joins config for ${collection}.`)\n }\n\n for (const join of polymorphicJoinsConfig) {\n if (projection && !projection[join.joinPath]) {\n continue\n }\n\n if (joins?.[join.joinPath] === false) {\n continue\n }\n\n const {\n count = false,\n limit: limitJoin = join.field.defaultLimit ?? 10,\n page,\n sort: sortJoin = join.field.defaultSort || collectionConfig.defaultSort,\n where: whereJoin = {},\n } = joins?.[join.joinPath] || {}\n\n const aggregatedFields: FlattenedField[] = []\n for (const collectionSlug of join.field.collection) {\n const { collectionConfig } = getCollection({ adapter, collectionSlug })\n\n for (const field of collectionConfig.flattenedFields) {\n if (!aggregatedFields.some((eachField) => eachField.name === field.name)) {\n aggregatedFields.push(field)\n }\n }\n }\n\n const sort = buildSortParam({\n adapter,\n config: adapter.payload.config,\n fields: aggregatedFields,\n locale,\n sort: sortJoin,\n timestamps: true,\n })\n\n const $match = await buildQuery({\n adapter,\n fields: aggregatedFields,\n locale,\n where: whereJoin,\n })\n\n const sortProperty = Object.keys(sort)[0]! // assert because buildSortParam always returns at least 1 key.\n const sortDirection = sort[sortProperty] === 'asc' ? 1 : -1\n\n const projectSort = sortProperty !== '_id' && sortProperty !== 'relationTo'\n\n const aliases: string[] = []\n\n const as = join.joinPath\n\n for (const collectionSlug of join.field.collection) {\n const alias = `${as}.docs.${collectionSlug}`\n aliases.push(alias)\n\n const basePipeline = [\n {\n $addFields: {\n relationTo: {\n $literal: collectionSlug,\n },\n },\n },\n {\n $match: {\n $and: [\n {\n $expr: {\n $eq: [`$${join.field.on}`, '$$root_id_'],\n },\n },\n $match,\n ],\n },\n },\n ]\n\n const { Model: JoinModel } = getCollection({ adapter, collectionSlug })\n\n aggregate.push({\n $lookup: {\n as: alias,\n from: JoinModel.collection.name,\n let: {\n root_id_: '$_id',\n },\n pipeline: [\n ...basePipeline,\n {\n $sort: {\n [sortProperty]: sortDirection,\n },\n },\n ...(limitJoin > 0\n ? [\n {\n // Unfortunately, we can't use $skip here because we can lose data, instead we do $slice then\n $limit: page ? page * limitJoin : limitJoin,\n },\n ]\n : []),\n {\n $project: {\n value: '$_id',\n ...(projectSort && {\n [sortProperty]: 1,\n }),\n relationTo: 1,\n },\n },\n ],\n },\n })\n\n if (count) {\n aggregate.push({\n $lookup: {\n as: `${as}.totalDocs.${alias}`,\n from: JoinModel.collection.name,\n let: {\n root_id_: '$_id',\n },\n pipeline: [\n ...basePipeline,\n {\n $count: 'result',\n },\n ],\n },\n })\n }\n }\n\n aggregate.push({\n $addFields: {\n [`${as}.docs`]: {\n $concatArrays: aliases.map((alias) => `$${alias}`),\n },\n },\n })\n\n if (count) {\n aggregate.push({\n $addFields: {\n [`${as}.totalDocs`]: {\n $add: aliases.map((alias) => ({\n $ifNull: [\n {\n $first: `$${as}.totalDocs.${alias}.result`,\n },\n 0,\n ],\n })),\n },\n },\n })\n }\n\n aggregate.push({\n $set: {\n [`${as}.docs`]: {\n $sortArray: {\n input: `$${as}.docs`,\n sortBy: {\n [sortProperty]: sortDirection,\n },\n },\n },\n },\n })\n\n const sliceValue = page ? [(page - 1) * limitJoin, limitJoin] : [limitJoin]\n\n aggregate.push({\n $addFields: {\n [`${as}.hasNextPage`]: {\n $gt: [{ $size: `$${as}.docs` }, limitJoin || Number.MAX_VALUE],\n },\n },\n })\n\n if (limitJoin > 0) {\n aggregate.push({\n $set: {\n [`${as}.docs`]: {\n $slice: [`$${as}.docs`, ...sliceValue],\n },\n },\n })\n }\n }\n\n for (const slug of Object.keys(joinConfig)) {\n const joinsList = joinConfig[slug]\n\n if (!joinsList) {\n throw new APIError(`Failed to retrieve array of joins for ${slug} in collectio ${collection}`)\n }\n\n for (const join of joinsList) {\n const projectionPath = versions ? `version.${join.joinPath}` : join.joinPath\n if (projection && !projection[projectionPath]) {\n continue\n }\n\n if (joins?.[join.joinPath] === false) {\n continue\n }\n\n const collectionConfig = adapter.payload.collections[join.field.collection as string]?.config\n\n if (!collectionConfig) {\n throw new APIError(\n `Collection config for ${join.field.collection.toString()} was not found`,\n )\n }\n\n let JoinModel: CollectionModel | undefined\n\n const useDrafts = (draftsEnabled || versions) && hasDraftsEnabled(collectionConfig)\n\n if (useDrafts) {\n JoinModel = adapter.versions[collectionConfig.slug]\n } else {\n JoinModel = adapter.collections[collectionConfig.slug]\n }\n\n if (!JoinModel) {\n throw new APIError(`Join Model was not found for ${collectionConfig.slug}`)\n }\n\n const {\n count,\n limit: limitJoin = join.field.defaultLimit ?? 10,\n page,\n sort: sortJoin = join.field.defaultSort || collectionConfig.defaultSort,\n where: whereJoin = {},\n } = joins?.[join.joinPath] || {}\n\n if (Array.isArray(join.field.collection)) {\n throw new Error('Unreachable')\n }\n\n const fields = useDrafts\n ? buildVersionCollectionFields(adapter.payload.config, collectionConfig, true)\n : collectionConfig.flattenedFields\n\n const sort = buildSortParam({\n adapter,\n config: adapter.payload.config,\n fields,\n locale,\n sort: useDrafts ? getQueryDraftsSort({ collectionConfig, sort: sortJoin }) : 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: useDrafts\n ? combineQueries(appendVersionToQueryKey(whereJoin), {\n latest: {\n equals: true,\n },\n })\n : whereJoin,\n })\n\n const pipeline: Exclude<PipelineStage, PipelineStage.Merge | PipelineStage.Out>[] = [\n { $match },\n {\n $sort: { [sortProperty]: sortDirection },\n },\n ]\n\n if (page) {\n pipeline.push({\n $skip: (page - 1) * limitJoin,\n })\n }\n\n if (limitJoin > 0) {\n pipeline.push({\n $limit: limitJoin + 1,\n })\n }\n\n let polymorphicSuffix = ''\n if (Array.isArray(join.targetField.relationTo)) {\n polymorphicSuffix = '.value'\n }\n\n const addTotalDocsAggregation = (as: string, foreignField: string) =>\n aggregate.push(\n {\n $lookup: {\n as: `${as}.totalDocs`,\n foreignField,\n from: JoinModel.collection.name,\n localField: versions ? 'parent' : '_id',\n pipeline: [\n {\n $match,\n },\n {\n $count: 'result',\n },\n ],\n },\n },\n {\n $addFields: {\n [`${as}.totalDocs`]: { $ifNull: [{ $first: `$${as}.totalDocs.result` }, 0] },\n },\n },\n )\n\n let foreignFieldPrefix = ''\n\n if (useDrafts) {\n foreignFieldPrefix = 'version.'\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: `${foreignFieldPrefix}${join.field.on}${code}${polymorphicSuffix}`,\n from: JoinModel.collection.name,\n localField: versions ? 'parent' : '_id',\n pipeline,\n },\n },\n {\n $addFields: {\n [`${as}.docs`]: {\n $map: {\n as: 'doc',\n in: useDrafts ? `$$doc.parent` : '$$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\n if (limitJoin > 0) {\n aggregate.push({\n $addFields: {\n [`${as}.docs`]: {\n $slice: [`$${as}.docs`, limitJoin],\n },\n },\n })\n }\n\n if (count) {\n addTotalDocsAggregation(\n as,\n `${foreignFieldPrefix}${join.field.on}${code}${polymorphicSuffix}`,\n )\n }\n })\n } else {\n const localeSuffix =\n fieldShouldBeLocalized({\n field: join.field,\n parentIsLocalized: join.parentIsLocalized,\n }) &&\n adapter.payload.config.localization &&\n locale\n ? `.${locale}`\n : ''\n const as = `${versions ? `version.${join.joinPath}` : join.joinPath}${localeSuffix}`\n\n let foreignField: string\n\n if (join.getForeignPath) {\n foreignField = `${join.getForeignPath({ locale })}${polymorphicSuffix}`\n } else {\n foreignField = `${join.field.on}${polymorphicSuffix}`\n }\n\n aggregate.push(\n {\n $lookup: {\n as: `${as}.docs`,\n foreignField: `${foreignFieldPrefix}${foreignField}`,\n from: JoinModel.collection.name,\n localField: versions ? 'parent' : '_id',\n pipeline,\n },\n },\n {\n $addFields: {\n [`${as}.docs`]: {\n $map: {\n as: 'doc',\n in: useDrafts ? `$$doc.parent` : '$$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\n if (count) {\n addTotalDocsAggregation(as, `${foreignFieldPrefix}${foreignField}`)\n }\n\n if (limitJoin > 0) {\n aggregate.push({\n $addFields: {\n [`${as}.docs`]: {\n $slice: [`$${as}.docs`, limitJoin],\n },\n },\n })\n }\n }\n }\n }\n\n return aggregate\n}\n"],"names":["APIError","appendVersionToQueryKey","buildVersionCollectionFields","combineQueries","getQueryDraftsSort","fieldShouldBeLocalized","hasDraftsEnabled","buildQuery","buildSortParam","getCollection","buildJoinAggregation","adapter","collection","collectionConfig","draftsEnabled","joins","locale","projection","versions","useJoinAggregations","Object","keys","length","polymorphicJoins","joinConfig","payload","collections","config","aggregate","polymorphicJoinsConfig","join","joinPath","count","limit","limitJoin","field","defaultLimit","page","sort","sortJoin","defaultSort","where","whereJoin","aggregatedFields","collectionSlug","flattenedFields","some","eachField","name","push","fields","timestamps","$match","sortProperty","sortDirection","projectSort","aliases","as","alias","basePipeline","$addFields","relationTo","$literal","$and","$expr","$eq","on","Model","JoinModel","$lookup","from","let","root_id_","pipeline","$sort","$limit","$project","value","$count","$concatArrays","map","$add","$ifNull","$first","$set","$sortArray","input","sortBy","sliceValue","$gt","$size","Number","MAX_VALUE","$slice","slug","joinsList","projectionPath","toString","useDrafts","Array","isArray","Error","latest","equals","$skip","polymorphicSuffix","targetField","addTotalDocsAggregation","foreignField","localField","foreignFieldPrefix","localization","localeCodes","forEach","code","$map","in","localeSuffix","parentIsLocalized","getForeignPath"],"mappings":"AAEA,SACEA,QAAQ,EACRC,uBAAuB,EACvBC,4BAA4B,EAE5BC,cAAc,EAEdC,kBAAkB,QAGb,UAAS;AAChB,SAASC,sBAAsB,EAAEC,gBAAgB,QAAQ,iBAAgB;AAKzE,SAASC,UAAU,QAAQ,2BAA0B;AACrD,SAASC,cAAc,QAAQ,+BAA8B;AAC7D,SAASC,aAAa,QAAQ,iBAAgB;AAgB9C,OAAO,MAAMC,uBAAuB,OAAO,EACzCC,OAAO,EACPC,UAAU,EACVC,gBAAgB,EAChBC,aAAa,EACbC,KAAK,EACLC,MAAM,EACNC,UAAU,EACVC,QAAQ,EACiB;IACzB,IAAI,CAACP,QAAQQ,mBAAmB,EAAE;QAChC,OAAO,EAAE;IACX;IACA,IACE,AAACC,OAAOC,IAAI,CAACR,iBAAiBE,KAAK,EAAEO,MAAM,KAAK,KAC9CT,iBAAiBU,gBAAgB,CAACD,MAAM,IAAI,KAC9CP,UAAU,OACV;QACA,OAAO,EAAE;IACX;IAEA,MAAMS,aAAab,QAAQc,OAAO,CAACC,WAAW,CAACd,WAAW,EAAEe,QAAQZ;IAEpE,IAAI,CAACS,YAAY;QACf,MAAM,IAAI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payloadcms/db-mongodb",
3
- "version": "3.91.0-internal.c1569dc",
3
+ "version": "3.92.0",
4
4
  "description": "The officially supported MongoDB database adapter for Payload",
5
5
  "homepage": "https://payloadcms.com",
6
6
  "repository": {
@@ -49,15 +49,15 @@
49
49
  "uuid": "13.0.2"
50
50
  },
51
51
  "devDependencies": {
52
+ "@payloadcms/eslint-config": "3.28.0",
52
53
  "@types/mongoose-aggregate-paginate-v2": "1.0.12",
53
54
  "@types/prompts": "^2.4.5",
54
55
  "mongodb": "6.20.0",
55
56
  "mongodb-memory-server": "10.1.4",
56
- "payload": "3.91.0-internal.c1569dc",
57
- "@payloadcms/eslint-config": "3.28.0"
57
+ "payload": "3.92.0"
58
58
  },
59
59
  "peerDependencies": {
60
- "payload": "3.91.0-internal.c1569dc"
60
+ "payload": "3.92.0"
61
61
  },
62
62
  "scripts": {
63
63
  "build": "pnpm build:types && pnpm build:swc",