@payloadcms/db-mongodb 4.0.0-internal.f05c47f → 4.0.0-internal.f715c6e
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 +2 -8
- package/dist/count.js.map +1 -1
- package/dist/createGlobalVersion.d.ts.map +1 -1
- package/dist/createGlobalVersion.js +0 -22
- package/dist/createGlobalVersion.js.map +1 -1
- package/dist/createVersion.d.ts.map +1 -1
- package/dist/createVersion.js +3 -16
- package/dist/createVersion.js.map +1 -1
- package/dist/deleteOne.d.ts.map +1 -1
- package/dist/deleteOne.js +1 -18
- package/dist/deleteOne.js.map +1 -1
- package/dist/find.d.ts.map +1 -1
- package/dist/find.js +3 -16
- package/dist/find.js.map +1 -1
- package/dist/findGlobal.d.ts.map +1 -1
- package/dist/findGlobal.js +4 -26
- package/dist/findGlobal.js.map +1 -1
- package/dist/findGlobalVersions.d.ts.map +1 -1
- package/dist/findGlobalVersions.js +2 -8
- package/dist/findGlobalVersions.js.map +1 -1
- package/dist/findOne.d.ts.map +1 -1
- package/dist/findOne.js +2 -18
- package/dist/findOne.js.map +1 -1
- package/dist/queries/buildSortParam.spec.js +1 -1
- package/dist/queries/buildSortParam.spec.js.map +1 -1
- package/dist/queries/getLocalizedSortProperty.spec.js +1 -1
- package/dist/queries/getLocalizedSortProperty.spec.js.map +1 -1
- package/dist/queryDrafts.d.ts.map +1 -1
- package/dist/queryDrafts.js +3 -11
- package/dist/queryDrafts.js.map +1 -1
- package/dist/updateGlobal.d.ts.map +1 -1
- package/dist/updateGlobal.js +7 -60
- package/dist/updateGlobal.js.map +1 -1
- package/dist/updateOne.d.ts.map +1 -1
- package/dist/updateOne.js +1 -10
- package/dist/updateOne.js.map +1 -1
- package/dist/utilities/buildJoinAggregation.d.ts +2 -3
- package/dist/utilities/buildJoinAggregation.d.ts.map +1 -1
- package/dist/utilities/buildJoinAggregation.js +4 -31
- package/dist/utilities/buildJoinAggregation.js.map +1 -1
- package/dist/utilities/resolveJoins.d.ts +2 -4
- package/dist/utilities/resolveJoins.d.ts.map +1 -1
- package/dist/utilities/resolveJoins.js +2 -16
- package/dist/utilities/resolveJoins.js.map +1 -1
- package/dist/utilities/transform.d.ts.map +1 -1
- package/dist/utilities/transform.js +0 -15
- package/dist/utilities/transform.js.map +1 -1
- package/dist/utilities/transform.spec.js +0 -67
- package/dist/utilities/transform.spec.js.map +1 -1
- package/package.json +4 -4
package/dist/findOne.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/findOne.ts"],"sourcesContent":["import type { AggregateOptions, QueryOptions } from 'mongoose'\n\nimport {
|
|
1
|
+
{"version":3,"sources":["../src/findOne.ts"],"sourcesContent":["import type { AggregateOptions, QueryOptions } from 'mongoose'\n\nimport { type FindOne } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { aggregatePaginate } from './utilities/aggregatePaginate.js'\nimport { buildJoinAggregation } from './utilities/buildJoinAggregation.js'\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getCollection } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\nimport { resolveJoins } from './utilities/resolveJoins.js'\nimport { transform } from './utilities/transform.js'\n\nexport const findOne: FindOne = async function findOne(\n this: MongooseAdapter,\n { collection: collectionSlug, draftsEnabled, joins, locale, req, select, where = {} },\n) {\n const { collectionConfig, Model } = getCollection({ adapter: this, collectionSlug })\n\n const query = await buildQuery({\n adapter: this,\n collectionSlug,\n fields: collectionConfig.flattenedFields,\n locale,\n where,\n })\n\n const projection = buildProjectionFromSelect({\n adapter: this,\n fields: collectionConfig.flattenedFields,\n select,\n })\n\n const aggregate = await buildJoinAggregation({\n adapter: this,\n collection: collectionSlug,\n collectionConfig,\n draftsEnabled,\n joins,\n locale,\n projection,\n query,\n })\n\n const session = await getSession(this, req)\n const options: AggregateOptions & QueryOptions = {\n lean: true,\n session,\n }\n\n let doc\n if (aggregate) {\n const { docs } = await aggregatePaginate({\n adapter: this,\n joinAggregation: aggregate,\n limit: 1,\n Model,\n pagination: false,\n projection,\n query,\n session,\n })\n doc = docs[0]\n } else {\n ;(options as Record<string, unknown>).projection = projection\n doc = await Model.findOne(query, {}, options)\n }\n\n if (doc && !this.useJoinAggregations) {\n await resolveJoins({\n adapter: this,\n collectionSlug,\n docs: [doc] as Record<string, unknown>[],\n joins,\n locale,\n })\n }\n\n if (!doc) {\n return null\n }\n\n transform({ adapter: this, data: doc, fields: collectionConfig.fields, operation: 'read' })\n\n return doc\n}\n"],"names":["buildQuery","aggregatePaginate","buildJoinAggregation","buildProjectionFromSelect","getCollection","getSession","resolveJoins","transform","findOne","collection","collectionSlug","draftsEnabled","joins","locale","req","select","where","collectionConfig","Model","adapter","query","fields","flattenedFields","projection","aggregate","session","options","lean","doc","docs","joinAggregation","limit","pagination","useJoinAggregations","data","operation"],"mappings":"AAMA,SAASA,UAAU,QAAQ,0BAAyB;AACpD,SAASC,iBAAiB,QAAQ,mCAAkC;AACpE,SAASC,oBAAoB,QAAQ,sCAAqC;AAC1E,SAASC,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,aAAa,QAAQ,2BAA0B;AACxD,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAASC,YAAY,QAAQ,8BAA6B;AAC1D,SAASC,SAAS,QAAQ,2BAA0B;AAEpD,OAAO,MAAMC,UAAmB,eAAeA,QAE7C,EAAEC,YAAYC,cAAc,EAAEC,aAAa,EAAEC,KAAK,EAAEC,MAAM,EAAEC,GAAG,EAAEC,MAAM,EAAEC,QAAQ,CAAC,CAAC,EAAE;IAErF,MAAM,EAAEC,gBAAgB,EAAEC,KAAK,EAAE,GAAGd,cAAc;QAAEe,SAAS,IAAI;QAAET;IAAe;IAElF,MAAMU,QAAQ,MAAMpB,WAAW;QAC7BmB,SAAS,IAAI;QACbT;QACAW,QAAQJ,iBAAiBK,eAAe;QACxCT;QACAG;IACF;IAEA,MAAMO,aAAapB,0BAA0B;QAC3CgB,SAAS,IAAI;QACbE,QAAQJ,iBAAiBK,eAAe;QACxCP;IACF;IAEA,MAAMS,YAAY,MAAMtB,qBAAqB;QAC3CiB,SAAS,IAAI;QACbV,YAAYC;QACZO;QACAN;QACAC;QACAC;QACAU;QACAH;IACF;IAEA,MAAMK,UAAU,MAAMpB,WAAW,IAAI,EAAES;IACvC,MAAMY,UAA2C;QAC/CC,MAAM;QACNF;IACF;IAEA,IAAIG;IACJ,IAAIJ,WAAW;QACb,MAAM,EAAEK,IAAI,EAAE,GAAG,MAAM5B,kBAAkB;YACvCkB,SAAS,IAAI;YACbW,iBAAiBN;YACjBO,OAAO;YACPb;YACAc,YAAY;YACZT;YACAH;YACAK;QACF;QACAG,MAAMC,IAAI,CAAC,EAAE;IACf,OAAO;;QACHH,QAAoCH,UAAU,GAAGA;QACnDK,MAAM,MAAMV,MAAMV,OAAO,CAACY,OAAO,CAAC,GAAGM;IACvC;IAEA,IAAIE,OAAO,CAAC,IAAI,CAACK,mBAAmB,EAAE;QACpC,MAAM3B,aAAa;YACjBa,SAAS,IAAI;YACbT;YACAmB,MAAM;gBAACD;aAAI;YACXhB;YACAC;QACF;IACF;IAEA,IAAI,CAACe,KAAK;QACR,OAAO;IACT;IAEArB,UAAU;QAAEY,SAAS,IAAI;QAAEe,MAAMN;QAAKP,QAAQJ,iBAAiBI,MAAM;QAAEc,WAAW;IAAO;IAEzF,OAAOP;AACT,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/queries/buildSortParam.spec.ts"],"sourcesContent":["import type { Config, SanitizedConfig } from 'payload'\nimport { describe, beforeAll, it, expect } from 'vitest'\n\nimport { sanitizeConfig } from 'payload'\n\nimport { buildSortParam } from './buildSortParam.js'\nimport { MongooseAdapter } from '../index.js'\n\nlet config: SanitizedConfig\n\ndescribe('builds sort params', () => {\n beforeAll(async () => {\n config = sanitizeConfig({\n localization: {\n defaultLocale: 'en',\n fallback: true,\n locales: ['en', 'es'],\n },\n } as Config)\n })\n it('adds a fallback on non-unique field', () => {\n const result = buildSortParam({\n config,\n parentIsLocalized: false,\n fields: [\n {\n name: 'title',\n type: 'text',\n },\n {\n name: 'order',\n type: 'number',\n },\n ],\n locale: 'en',\n sort: 'order',\n timestamps: true,\n adapter: {\n disableFallbackSort: false,\n } as MongooseAdapter,\n })\n\n expect(result).toStrictEqual({ order: 'asc', createdAt: 'desc' })\n })\n\n it('adds a fallback when sort isnt provided', () => {\n const result = buildSortParam({\n config,\n parentIsLocalized: false,\n fields: [\n {\n name: 'title',\n type: 'text',\n },\n {\n name: 'order',\n type: 'number',\n },\n ],\n locale: 'en',\n sort: undefined,\n timestamps: true,\n adapter: {\n disableFallbackSort: false,\n } as MongooseAdapter,\n })\n\n expect(result).toStrictEqual({ createdAt: 'desc' })\n })\n\n it('does not add a fallback on non-unique field when disableFallbackSort is true', () => {\n const result = buildSortParam({\n config,\n parentIsLocalized: false,\n fields: [\n {\n name: 'title',\n type: 'text',\n },\n {\n name: 'order',\n type: 'number',\n },\n ],\n locale: 'en',\n sort: 'order',\n timestamps: true,\n adapter: {\n disableFallbackSort: true,\n } as MongooseAdapter,\n })\n\n expect(result).toStrictEqual({ order: 'asc' })\n })\n\n // This test should be true even when disableFallbackSort is false\n it('does not add a fallback on unique field', () => {\n const result = buildSortParam({\n config,\n parentIsLocalized: false,\n fields: [\n {\n name: 'title',\n type: 'text',\n },\n {\n name: 'order',\n type: 'number',\n unique: true, // Marking this field as unique\n },\n ],\n locale: 'en',\n sort: 'order',\n timestamps: true,\n adapter: {\n disableFallbackSort: false,\n } as MongooseAdapter,\n })\n\n expect(result).toStrictEqual({ order: 'asc' })\n })\n})\n"],"names":["describe","beforeAll","it","expect","sanitizeConfig","buildSortParam","config","localization","defaultLocale","fallback","locales","result","parentIsLocalized","fields","name","type","locale","sort","timestamps","adapter","disableFallbackSort","toStrictEqual","order","createdAt","undefined","unique"],"mappings":"AACA,SAASA,QAAQ,EAAEC,SAAS,EAAEC,EAAE,EAAEC,MAAM,QAAQ,SAAQ;AAExD,SAASC,cAAc,QAAQ,UAAS;AAExC,SAASC,cAAc,QAAQ,sBAAqB;AAGpD,IAAIC;AAEJN,SAAS,sBAAsB;IAC7BC,UAAU;QACRK,
|
|
1
|
+
{"version":3,"sources":["../../src/queries/buildSortParam.spec.ts"],"sourcesContent":["import type { Config, SanitizedConfig } from 'payload'\nimport { describe, beforeAll, it, expect } from 'vitest'\n\nimport { sanitizeConfig } from 'payload'\n\nimport { buildSortParam } from './buildSortParam.js'\nimport { MongooseAdapter } from '../index.js'\n\nlet config: SanitizedConfig\n\ndescribe('builds sort params', () => {\n beforeAll(async () => {\n config = await sanitizeConfig({\n localization: {\n defaultLocale: 'en',\n fallback: true,\n locales: ['en', 'es'],\n },\n } as Config)\n })\n it('adds a fallback on non-unique field', () => {\n const result = buildSortParam({\n config,\n parentIsLocalized: false,\n fields: [\n {\n name: 'title',\n type: 'text',\n },\n {\n name: 'order',\n type: 'number',\n },\n ],\n locale: 'en',\n sort: 'order',\n timestamps: true,\n adapter: {\n disableFallbackSort: false,\n } as MongooseAdapter,\n })\n\n expect(result).toStrictEqual({ order: 'asc', createdAt: 'desc' })\n })\n\n it('adds a fallback when sort isnt provided', () => {\n const result = buildSortParam({\n config,\n parentIsLocalized: false,\n fields: [\n {\n name: 'title',\n type: 'text',\n },\n {\n name: 'order',\n type: 'number',\n },\n ],\n locale: 'en',\n sort: undefined,\n timestamps: true,\n adapter: {\n disableFallbackSort: false,\n } as MongooseAdapter,\n })\n\n expect(result).toStrictEqual({ createdAt: 'desc' })\n })\n\n it('does not add a fallback on non-unique field when disableFallbackSort is true', () => {\n const result = buildSortParam({\n config,\n parentIsLocalized: false,\n fields: [\n {\n name: 'title',\n type: 'text',\n },\n {\n name: 'order',\n type: 'number',\n },\n ],\n locale: 'en',\n sort: 'order',\n timestamps: true,\n adapter: {\n disableFallbackSort: true,\n } as MongooseAdapter,\n })\n\n expect(result).toStrictEqual({ order: 'asc' })\n })\n\n // This test should be true even when disableFallbackSort is false\n it('does not add a fallback on unique field', () => {\n const result = buildSortParam({\n config,\n parentIsLocalized: false,\n fields: [\n {\n name: 'title',\n type: 'text',\n },\n {\n name: 'order',\n type: 'number',\n unique: true, // Marking this field as unique\n },\n ],\n locale: 'en',\n sort: 'order',\n timestamps: true,\n adapter: {\n disableFallbackSort: false,\n } as MongooseAdapter,\n })\n\n expect(result).toStrictEqual({ order: 'asc' })\n })\n})\n"],"names":["describe","beforeAll","it","expect","sanitizeConfig","buildSortParam","config","localization","defaultLocale","fallback","locales","result","parentIsLocalized","fields","name","type","locale","sort","timestamps","adapter","disableFallbackSort","toStrictEqual","order","createdAt","undefined","unique"],"mappings":"AACA,SAASA,QAAQ,EAAEC,SAAS,EAAEC,EAAE,EAAEC,MAAM,QAAQ,SAAQ;AAExD,SAASC,cAAc,QAAQ,UAAS;AAExC,SAASC,cAAc,QAAQ,sBAAqB;AAGpD,IAAIC;AAEJN,SAAS,sBAAsB;IAC7BC,UAAU;QACRK,SAAS,MAAMF,eAAe;YAC5BG,cAAc;gBACZC,eAAe;gBACfC,UAAU;gBACVC,SAAS;oBAAC;oBAAM;iBAAK;YACvB;QACF;IACF;IACAR,GAAG,uCAAuC;QACxC,MAAMS,SAASN,eAAe;YAC5BC;YACAM,mBAAmB;YACnBC,QAAQ;gBACN;oBACEC,MAAM;oBACNC,MAAM;gBACR;gBACA;oBACED,MAAM;oBACNC,MAAM;gBACR;aACD;YACDC,QAAQ;YACRC,MAAM;YACNC,YAAY;YACZC,SAAS;gBACPC,qBAAqB;YACvB;QACF;QAEAjB,OAAOQ,QAAQU,aAAa,CAAC;YAAEC,OAAO;YAAOC,WAAW;QAAO;IACjE;IAEArB,GAAG,2CAA2C;QAC5C,MAAMS,SAASN,eAAe;YAC5BC;YACAM,mBAAmB;YACnBC,QAAQ;gBACN;oBACEC,MAAM;oBACNC,MAAM;gBACR;gBACA;oBACED,MAAM;oBACNC,MAAM;gBACR;aACD;YACDC,QAAQ;YACRC,MAAMO;YACNN,YAAY;YACZC,SAAS;gBACPC,qBAAqB;YACvB;QACF;QAEAjB,OAAOQ,QAAQU,aAAa,CAAC;YAAEE,WAAW;QAAO;IACnD;IAEArB,GAAG,gFAAgF;QACjF,MAAMS,SAASN,eAAe;YAC5BC;YACAM,mBAAmB;YACnBC,QAAQ;gBACN;oBACEC,MAAM;oBACNC,MAAM;gBACR;gBACA;oBACED,MAAM;oBACNC,MAAM;gBACR;aACD;YACDC,QAAQ;YACRC,MAAM;YACNC,YAAY;YACZC,SAAS;gBACPC,qBAAqB;YACvB;QACF;QAEAjB,OAAOQ,QAAQU,aAAa,CAAC;YAAEC,OAAO;QAAM;IAC9C;IAEA,kEAAkE;IAClEpB,GAAG,2CAA2C;QAC5C,MAAMS,SAASN,eAAe;YAC5BC;YACAM,mBAAmB;YACnBC,QAAQ;gBACN;oBACEC,MAAM;oBACNC,MAAM;gBACR;gBACA;oBACED,MAAM;oBACNC,MAAM;oBACNU,QAAQ;gBACV;aACD;YACDT,QAAQ;YACRC,MAAM;YACNC,YAAY;YACZC,SAAS;gBACPC,qBAAqB;YACvB;QACF;QAEAjB,OAAOQ,QAAQU,aAAa,CAAC;YAAEC,OAAO;QAAM;IAC9C;AACF"}
|
|
@@ -4,7 +4,7 @@ import { getLocalizedSortProperty } from './getLocalizedSortProperty.js';
|
|
|
4
4
|
let config;
|
|
5
5
|
describe('get localized sort property', ()=>{
|
|
6
6
|
beforeAll(async ()=>{
|
|
7
|
-
config = sanitizeConfig({
|
|
7
|
+
config = await sanitizeConfig({
|
|
8
8
|
localization: {
|
|
9
9
|
defaultLocale: 'en',
|
|
10
10
|
fallback: true,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/queries/getLocalizedSortProperty.spec.ts"],"sourcesContent":["import { describe, beforeAll, it, expect } from 'vitest'\nimport type { Config, SanitizedConfig } from 'payload'\nimport { flattenAllFields, sanitizeConfig } from 'payload'\n\nimport { getLocalizedSortProperty } from './getLocalizedSortProperty.js'\n\nlet config: SanitizedConfig\n\ndescribe('get localized sort property', () => {\n beforeAll(async () => {\n config = sanitizeConfig({\n localization: {\n defaultLocale: 'en',\n fallback: true,\n locales: ['en', 'es'],\n },\n } as Config)\n })\n it('passes through a non-localized sort property', () => {\n const result = getLocalizedSortProperty({\n config,\n parentIsLocalized: false,\n fields: [\n {\n name: 'title',\n type: 'text',\n },\n ],\n locale: 'en',\n segments: ['title'],\n })\n\n expect(result).toStrictEqual('title')\n })\n\n it('properly localizes an un-localized sort property', () => {\n const result = getLocalizedSortProperty({\n config,\n parentIsLocalized: false,\n fields: [\n {\n name: 'title',\n type: 'text',\n localized: true,\n },\n ],\n locale: 'en',\n segments: ['title'],\n })\n\n expect(result).toStrictEqual('title.en')\n })\n\n it('keeps specifically asked-for localized sort properties', () => {\n const result = getLocalizedSortProperty({\n config,\n parentIsLocalized: false,\n fields: [\n {\n name: 'title',\n type: 'text',\n localized: true,\n },\n ],\n locale: 'en',\n segments: ['title', 'es'],\n })\n\n expect(result).toStrictEqual('title.es')\n })\n\n it('properly localizes nested sort properties', () => {\n const result = getLocalizedSortProperty({\n config,\n parentIsLocalized: false,\n fields: flattenAllFields({\n fields: [\n {\n name: 'group',\n type: 'group',\n fields: [\n {\n name: 'title',\n type: 'text',\n localized: true,\n },\n ],\n },\n ],\n }),\n locale: 'en',\n segments: ['group', 'title'],\n })\n\n expect(result).toStrictEqual('group.title.en')\n })\n\n it('keeps requested locale with nested sort properties', () => {\n const result = getLocalizedSortProperty({\n config,\n parentIsLocalized: false,\n fields: flattenAllFields({\n fields: [\n {\n name: 'group',\n type: 'group',\n fields: [\n {\n name: 'title',\n type: 'text',\n localized: true,\n },\n ],\n },\n ],\n }),\n locale: 'en',\n segments: ['group', 'title', 'es'],\n })\n\n expect(result).toStrictEqual('group.title.es')\n })\n\n it('properly localizes field within row', () => {\n const result = getLocalizedSortProperty({\n config,\n parentIsLocalized: false,\n fields: flattenAllFields({\n fields: [\n {\n type: 'row',\n fields: [\n {\n name: 'title',\n type: 'text',\n localized: true,\n },\n ],\n },\n ],\n }),\n locale: 'en',\n segments: ['title'],\n })\n\n expect(result).toStrictEqual('title.en')\n })\n\n it('properly localizes field within named tab', () => {\n const result = getLocalizedSortProperty({\n config,\n parentIsLocalized: false,\n fields: flattenAllFields({\n fields: [\n {\n type: 'tabs',\n tabs: [\n {\n name: 'tab',\n fields: [\n {\n name: 'title',\n type: 'text',\n localized: true,\n },\n ],\n },\n ],\n },\n ],\n }),\n locale: 'en',\n segments: ['tab', 'title'],\n })\n\n expect(result).toStrictEqual('tab.title.en')\n })\n\n it('properly localizes field within unnamed tab', () => {\n const result = getLocalizedSortProperty({\n config,\n parentIsLocalized: false,\n fields: flattenAllFields({\n fields: [\n {\n type: 'tabs',\n tabs: [\n {\n fields: [\n {\n name: 'title',\n type: 'text',\n localized: true,\n },\n ],\n label: 'Tab',\n },\n ],\n },\n ],\n }),\n locale: 'en',\n segments: ['title'],\n })\n\n expect(result).toStrictEqual('title.en')\n })\n})\n"],"names":["describe","beforeAll","it","expect","flattenAllFields","sanitizeConfig","getLocalizedSortProperty","config","localization","defaultLocale","fallback","locales","result","parentIsLocalized","fields","name","type","locale","segments","toStrictEqual","localized","tabs","label"],"mappings":"AAAA,SAASA,QAAQ,EAAEC,SAAS,EAAEC,EAAE,EAAEC,MAAM,QAAQ,SAAQ;AAExD,SAASC,gBAAgB,EAAEC,cAAc,QAAQ,UAAS;AAE1D,SAASC,wBAAwB,QAAQ,gCAA+B;AAExE,IAAIC;AAEJP,SAAS,+BAA+B;IACtCC,UAAU;QACRM,
|
|
1
|
+
{"version":3,"sources":["../../src/queries/getLocalizedSortProperty.spec.ts"],"sourcesContent":["import { describe, beforeAll, it, expect } from 'vitest'\nimport type { Config, SanitizedConfig } from 'payload'\nimport { flattenAllFields, sanitizeConfig } from 'payload'\n\nimport { getLocalizedSortProperty } from './getLocalizedSortProperty.js'\n\nlet config: SanitizedConfig\n\ndescribe('get localized sort property', () => {\n beforeAll(async () => {\n config = await sanitizeConfig({\n localization: {\n defaultLocale: 'en',\n fallback: true,\n locales: ['en', 'es'],\n },\n } as Config)\n })\n it('passes through a non-localized sort property', () => {\n const result = getLocalizedSortProperty({\n config,\n parentIsLocalized: false,\n fields: [\n {\n name: 'title',\n type: 'text',\n },\n ],\n locale: 'en',\n segments: ['title'],\n })\n\n expect(result).toStrictEqual('title')\n })\n\n it('properly localizes an un-localized sort property', () => {\n const result = getLocalizedSortProperty({\n config,\n parentIsLocalized: false,\n fields: [\n {\n name: 'title',\n type: 'text',\n localized: true,\n },\n ],\n locale: 'en',\n segments: ['title'],\n })\n\n expect(result).toStrictEqual('title.en')\n })\n\n it('keeps specifically asked-for localized sort properties', () => {\n const result = getLocalizedSortProperty({\n config,\n parentIsLocalized: false,\n fields: [\n {\n name: 'title',\n type: 'text',\n localized: true,\n },\n ],\n locale: 'en',\n segments: ['title', 'es'],\n })\n\n expect(result).toStrictEqual('title.es')\n })\n\n it('properly localizes nested sort properties', () => {\n const result = getLocalizedSortProperty({\n config,\n parentIsLocalized: false,\n fields: flattenAllFields({\n fields: [\n {\n name: 'group',\n type: 'group',\n fields: [\n {\n name: 'title',\n type: 'text',\n localized: true,\n },\n ],\n },\n ],\n }),\n locale: 'en',\n segments: ['group', 'title'],\n })\n\n expect(result).toStrictEqual('group.title.en')\n })\n\n it('keeps requested locale with nested sort properties', () => {\n const result = getLocalizedSortProperty({\n config,\n parentIsLocalized: false,\n fields: flattenAllFields({\n fields: [\n {\n name: 'group',\n type: 'group',\n fields: [\n {\n name: 'title',\n type: 'text',\n localized: true,\n },\n ],\n },\n ],\n }),\n locale: 'en',\n segments: ['group', 'title', 'es'],\n })\n\n expect(result).toStrictEqual('group.title.es')\n })\n\n it('properly localizes field within row', () => {\n const result = getLocalizedSortProperty({\n config,\n parentIsLocalized: false,\n fields: flattenAllFields({\n fields: [\n {\n type: 'row',\n fields: [\n {\n name: 'title',\n type: 'text',\n localized: true,\n },\n ],\n },\n ],\n }),\n locale: 'en',\n segments: ['title'],\n })\n\n expect(result).toStrictEqual('title.en')\n })\n\n it('properly localizes field within named tab', () => {\n const result = getLocalizedSortProperty({\n config,\n parentIsLocalized: false,\n fields: flattenAllFields({\n fields: [\n {\n type: 'tabs',\n tabs: [\n {\n name: 'tab',\n fields: [\n {\n name: 'title',\n type: 'text',\n localized: true,\n },\n ],\n },\n ],\n },\n ],\n }),\n locale: 'en',\n segments: ['tab', 'title'],\n })\n\n expect(result).toStrictEqual('tab.title.en')\n })\n\n it('properly localizes field within unnamed tab', () => {\n const result = getLocalizedSortProperty({\n config,\n parentIsLocalized: false,\n fields: flattenAllFields({\n fields: [\n {\n type: 'tabs',\n tabs: [\n {\n fields: [\n {\n name: 'title',\n type: 'text',\n localized: true,\n },\n ],\n label: 'Tab',\n },\n ],\n },\n ],\n }),\n locale: 'en',\n segments: ['title'],\n })\n\n expect(result).toStrictEqual('title.en')\n })\n})\n"],"names":["describe","beforeAll","it","expect","flattenAllFields","sanitizeConfig","getLocalizedSortProperty","config","localization","defaultLocale","fallback","locales","result","parentIsLocalized","fields","name","type","locale","segments","toStrictEqual","localized","tabs","label"],"mappings":"AAAA,SAASA,QAAQ,EAAEC,SAAS,EAAEC,EAAE,EAAEC,MAAM,QAAQ,SAAQ;AAExD,SAASC,gBAAgB,EAAEC,cAAc,QAAQ,UAAS;AAE1D,SAASC,wBAAwB,QAAQ,gCAA+B;AAExE,IAAIC;AAEJP,SAAS,+BAA+B;IACtCC,UAAU;QACRM,SAAS,MAAMF,eAAe;YAC5BG,cAAc;gBACZC,eAAe;gBACfC,UAAU;gBACVC,SAAS;oBAAC;oBAAM;iBAAK;YACvB;QACF;IACF;IACAT,GAAG,gDAAgD;QACjD,MAAMU,SAASN,yBAAyB;YACtCC;YACAM,mBAAmB;YACnBC,QAAQ;gBACN;oBACEC,MAAM;oBACNC,MAAM;gBACR;aACD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CAAuC;QACxC,MAAMU,SAASN,yBAAyB;YACtCC;YACAM,mBAAmB;YACnBC,QAAQV,iBAAiB;gBACvBU,QAAQ;oBACN;wBACEE,MAAM;wBACNF,QAAQ;4BACN;gCACEC,MAAM;gCACNC,MAAM;gCACNI,WAAW;4BACb;yBACD;oBACH;iBACD;YACH;YACAH,QAAQ;YACRC,UAAU;gBAAC;aAAQ;QACrB;QAEAf,OAAOS,QAAQO,aAAa,CAAC;IAC/B;IAEAjB,GAAG,6CAA6C;QAC9C,MAAMU,SAASN,yBAAyB;YACtCC;YACAM,mBAAmB;YACnBC,QAAQV,iBAAiB;gBACvBU,QAAQ;oBACN;wBACEE,MAAM;wBACNK,MAAM;4BACJ;gCACEN,MAAM;gCACND,QAAQ;oCACN;wCACEC,MAAM;wCACNC,MAAM;wCACNI,WAAW;oCACb;iCACD;4BACH;yBACD;oBACH;iBACD;YACH;YACAH,QAAQ;YACRC,UAAU;gBAAC;gBAAO;aAAQ;QAC5B;QAEAf,OAAOS,QAAQO,aAAa,CAAC;IAC/B;IAEAjB,GAAG,+CAA+C;QAChD,MAAMU,SAASN,yBAAyB;YACtCC;YACAM,mBAAmB;YACnBC,QAAQV,iBAAiB;gBACvBU,QAAQ;oBACN;wBACEE,MAAM;wBACNK,MAAM;4BACJ;gCACEP,QAAQ;oCACN;wCACEC,MAAM;wCACNC,MAAM;wCACNI,WAAW;oCACb;iCACD;gCACDE,OAAO;4BACT;yBACD;oBACH;iBACD;YACH;YACAL,QAAQ;YACRC,UAAU;gBAAC;aAAQ;QACrB;QAEAf,OAAOS,QAAQO,aAAa,CAAC;IAC/B;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"queryDrafts.d.ts","sourceRoot":"","sources":["../src/queryDrafts.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"queryDrafts.d.ts","sourceRoot":"","sources":["../src/queryDrafts.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAgB1C,eAAO,MAAM,WAAW,EAAE,WA+KzB,CAAA"}
|
package/dist/queryDrafts.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { buildVersionCollectionFields, combineQueries, flattenWhereToOperators
|
|
1
|
+
import { buildVersionCollectionFields, combineQueries, flattenWhereToOperators } from 'payload';
|
|
2
2
|
import { buildQuery } from './queries/buildQuery.js';
|
|
3
3
|
import { buildSortParam } from './queries/buildSortParam.js';
|
|
4
4
|
import { aggregatePaginate } from './utilities/aggregatePaginate.js';
|
|
@@ -34,16 +34,11 @@ export const queryDrafts = async function queryDrafts({ collection: collectionSl
|
|
|
34
34
|
versions: true
|
|
35
35
|
});
|
|
36
36
|
}
|
|
37
|
-
const branchedWhere = await resolveBranchVersionQuery({
|
|
38
|
-
collectionSlug,
|
|
39
|
-
req,
|
|
40
|
-
where
|
|
41
|
-
});
|
|
42
37
|
const combinedWhere = combineQueries({
|
|
43
38
|
latest: {
|
|
44
39
|
equals: true
|
|
45
40
|
}
|
|
46
|
-
},
|
|
41
|
+
}, where);
|
|
47
42
|
const versionQuery = await buildQuery({
|
|
48
43
|
adapter: this,
|
|
49
44
|
fields,
|
|
@@ -108,7 +103,6 @@ export const queryDrafts = async function queryDrafts({ collection: collectionSl
|
|
|
108
103
|
locale,
|
|
109
104
|
projection,
|
|
110
105
|
query: versionQuery,
|
|
111
|
-
req,
|
|
112
106
|
versions: true
|
|
113
107
|
});
|
|
114
108
|
if (aggregate || sortAggregation.length > 0) {
|
|
@@ -147,9 +141,7 @@ export const queryDrafts = async function queryDrafts({ collection: collectionSl
|
|
|
147
141
|
operation: 'read'
|
|
148
142
|
});
|
|
149
143
|
for(let i = 0; i < result.docs.length; i++){
|
|
150
|
-
|
|
151
|
-
// canonical document ID comes from `_branchParent` when present.
|
|
152
|
-
const id = projectBranchVersionParent(result.docs[i]);
|
|
144
|
+
const id = result.docs[i].parent;
|
|
153
145
|
result.docs[i] = result.docs[i].version ?? {};
|
|
154
146
|
result.docs[i].id = id;
|
|
155
147
|
}
|
package/dist/queryDrafts.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/queryDrafts.ts"],"sourcesContent":["import type { PaginateOptions, PipelineStage, QueryOptions } from 'mongoose'\nimport type { QueryDrafts } from 'payload'\n\nimport {\n buildVersionCollectionFields,\n combineQueries,\n flattenWhereToOperators,\n projectBranchVersionParent,\n resolveBranchVersionQuery,\n} from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { buildSortParam } from './queries/buildSortParam.js'\nimport { aggregatePaginate } from './utilities/aggregatePaginate.js'\nimport { buildJoinAggregation } from './utilities/buildJoinAggregation.js'\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getCollection } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\nimport { resolveJoins } from './utilities/resolveJoins.js'\nimport { transform } from './utilities/transform.js'\n\nexport const queryDrafts: QueryDrafts = async function queryDrafts(\n this: MongooseAdapter,\n {\n collection: collectionSlug,\n joins,\n limit,\n locale,\n page,\n pagination,\n req,\n select,\n sort: sortArg,\n where = {},\n },\n) {\n const { collectionConfig, Model } = getCollection({\n adapter: this,\n collectionSlug,\n versions: true,\n })\n\n let hasNearConstraint\n let sort\n\n if (where) {\n const constraints = flattenWhereToOperators(where)\n hasNearConstraint = constraints.some((prop) => Object.keys(prop).some((key) => key === 'near'))\n }\n\n const fields = buildVersionCollectionFields(this.payload.config, collectionConfig, true)\n\n const sortAggregation: PipelineStage[] = []\n if (!hasNearConstraint) {\n sort = buildSortParam({\n adapter: this,\n config: this.payload.config,\n fields,\n locale,\n sort: sortArg || collectionConfig.defaultSort,\n sortAggregation,\n timestamps: true,\n versions: true,\n })\n }\n\n const branchedWhere = await resolveBranchVersionQuery({\n collectionSlug,\n req,\n where,\n })\n\n const combinedWhere = combineQueries({ latest: { equals: true } }, branchedWhere ?? {})\n\n const versionQuery = await buildQuery({\n adapter: this,\n fields,\n locale,\n where: combinedWhere,\n })\n\n const projection = buildProjectionFromSelect({\n adapter: this,\n fields,\n select,\n })\n\n const session = await getSession(this, req)\n const options: QueryOptions = {\n session,\n }\n\n // useEstimatedCount is faster, but not accurate, as it ignores any filters. It is thus set to true if there are no filters.\n const useEstimatedCount =\n hasNearConstraint || !versionQuery || Object.keys(versionQuery).length === 0\n const paginationOptions: PaginateOptions = {\n lean: true,\n leanWithId: true,\n options,\n page,\n pagination,\n projection,\n sort,\n useEstimatedCount,\n }\n\n if (this.collation) {\n const localizationConfig = this.payload.config.localization\n const defaultLocale =\n (typeof localizationConfig === 'object' && localizationConfig?.defaultLocale) || 'en'\n\n paginationOptions.collation = {\n locale: locale && locale !== 'all' && locale !== '*' ? locale : defaultLocale,\n ...this.collation,\n }\n }\n\n if (\n !useEstimatedCount &&\n Object.keys(versionQuery).length === 0 &&\n this.disableIndexHints !== true\n ) {\n // Improve the performance of the countDocuments query which is used if useEstimatedCount is set to false by adding\n // a hint. By default, if no hint is provided, MongoDB does not use an indexed field to count the returned documents,\n // which makes queries very slow. This only happens when no query (filter) is provided. If one is provided, it uses\n // the correct indexed field\n paginationOptions.useCustomCountFn = () => {\n return Promise.resolve(\n Model.countDocuments(versionQuery, {\n collation: paginationOptions.collation,\n hint: { _id: 1 },\n session,\n }),\n )\n }\n }\n\n if (limit && limit > 0) {\n paginationOptions.limit = limit\n // limit must also be set here, it's ignored when pagination is false\n\n paginationOptions.options!.limit = limit\n }\n\n let result\n\n const aggregate = await buildJoinAggregation({\n adapter: this,\n collection: collectionSlug,\n collectionConfig,\n joins,\n locale,\n projection,\n query: versionQuery,\n req,\n versions: true,\n })\n\n if (aggregate || sortAggregation.length > 0) {\n result = await aggregatePaginate({\n adapter: this,\n collation: paginationOptions.collation,\n joinAggregation: aggregate,\n limit: paginationOptions.limit,\n Model,\n page: paginationOptions.page,\n pagination: paginationOptions.pagination,\n projection: paginationOptions.projection,\n query: versionQuery,\n session: paginationOptions.options?.session ?? undefined,\n sort: paginationOptions.sort as object,\n sortAggregation,\n useEstimatedCount: paginationOptions.useEstimatedCount,\n })\n } else {\n result = await Model.paginate(versionQuery, paginationOptions)\n }\n\n if (!this.useJoinAggregations) {\n await resolveJoins({\n adapter: this,\n collectionSlug,\n docs: result.docs as Record<string, unknown>[],\n joins,\n locale,\n versions: true,\n })\n }\n\n transform({\n adapter: this,\n data: result.docs,\n fields: buildVersionCollectionFields(this.payload.config, collectionConfig),\n operation: 'read',\n })\n\n for (let i = 0; i < result.docs.length; i++) {\n // A branch version's `parent` is the shadow row's primary key, so the\n // canonical document ID comes from `_branchParent` when present.\n const id = projectBranchVersionParent(result.docs[i] as Record<string, unknown>)\n result.docs[i] = result.docs[i].version ?? {}\n result.docs[i].id = id\n }\n\n return result\n}\n"],"names":["buildVersionCollectionFields","combineQueries","flattenWhereToOperators","projectBranchVersionParent","resolveBranchVersionQuery","buildQuery","buildSortParam","aggregatePaginate","buildJoinAggregation","buildProjectionFromSelect","getCollection","getSession","resolveJoins","transform","queryDrafts","collection","collectionSlug","joins","limit","locale","page","pagination","req","select","sort","sortArg","where","collectionConfig","Model","adapter","versions","hasNearConstraint","constraints","some","prop","Object","keys","key","fields","payload","config","sortAggregation","defaultSort","timestamps","branchedWhere","combinedWhere","latest","equals","versionQuery","projection","session","options","useEstimatedCount","length","paginationOptions","lean","leanWithId","collation","localizationConfig","localization","defaultLocale","disableIndexHints","useCustomCountFn","Promise","resolve","countDocuments","hint","_id","result","aggregate","query","joinAggregation","undefined","paginate","useJoinAggregations","docs","data","operation","i","id","version"],"mappings":"AAGA,SACEA,4BAA4B,EAC5BC,cAAc,EACdC,uBAAuB,EACvBC,0BAA0B,EAC1BC,yBAAyB,QACpB,UAAS;AAIhB,SAASC,UAAU,QAAQ,0BAAyB;AACpD,SAASC,cAAc,QAAQ,8BAA6B;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;IACtB;IAEA,OAAOX;AACT,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../src/queryDrafts.ts"],"sourcesContent":["import type { PaginateOptions, PipelineStage, QueryOptions } from 'mongoose'\nimport type { QueryDrafts } from 'payload'\n\nimport { buildVersionCollectionFields, combineQueries, flattenWhereToOperators } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { buildSortParam } from './queries/buildSortParam.js'\nimport { aggregatePaginate } from './utilities/aggregatePaginate.js'\nimport { buildJoinAggregation } from './utilities/buildJoinAggregation.js'\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getCollection } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\nimport { resolveJoins } from './utilities/resolveJoins.js'\nimport { transform } from './utilities/transform.js'\n\nexport const queryDrafts: QueryDrafts = async function queryDrafts(\n this: MongooseAdapter,\n {\n collection: collectionSlug,\n joins,\n limit,\n locale,\n page,\n pagination,\n req,\n select,\n sort: sortArg,\n where = {},\n },\n) {\n const { collectionConfig, Model } = getCollection({\n adapter: this,\n collectionSlug,\n versions: true,\n })\n\n let hasNearConstraint\n let sort\n\n if (where) {\n const constraints = flattenWhereToOperators(where)\n hasNearConstraint = constraints.some((prop) => Object.keys(prop).some((key) => key === 'near'))\n }\n\n const fields = buildVersionCollectionFields(this.payload.config, collectionConfig, true)\n\n const sortAggregation: PipelineStage[] = []\n if (!hasNearConstraint) {\n sort = buildSortParam({\n adapter: this,\n config: this.payload.config,\n fields,\n locale,\n sort: sortArg || collectionConfig.defaultSort,\n sortAggregation,\n timestamps: true,\n versions: true,\n })\n }\n\n const combinedWhere = combineQueries({ latest: { equals: true } }, where)\n\n const versionQuery = await buildQuery({\n adapter: this,\n fields,\n locale,\n where: combinedWhere,\n })\n\n const projection = buildProjectionFromSelect({\n adapter: this,\n fields,\n select,\n })\n\n const session = await getSession(this, req)\n const options: QueryOptions = {\n session,\n }\n\n // useEstimatedCount is faster, but not accurate, as it ignores any filters. It is thus set to true if there are no filters.\n const useEstimatedCount =\n hasNearConstraint || !versionQuery || Object.keys(versionQuery).length === 0\n const paginationOptions: PaginateOptions = {\n lean: true,\n leanWithId: true,\n options,\n page,\n pagination,\n projection,\n sort,\n useEstimatedCount,\n }\n\n if (this.collation) {\n const localizationConfig = this.payload.config.localization\n const defaultLocale =\n (typeof localizationConfig === 'object' && localizationConfig?.defaultLocale) || 'en'\n\n paginationOptions.collation = {\n locale: locale && locale !== 'all' && locale !== '*' ? locale : defaultLocale,\n ...this.collation,\n }\n }\n\n if (\n !useEstimatedCount &&\n Object.keys(versionQuery).length === 0 &&\n this.disableIndexHints !== true\n ) {\n // Improve the performance of the countDocuments query which is used if useEstimatedCount is set to false by adding\n // a hint. By default, if no hint is provided, MongoDB does not use an indexed field to count the returned documents,\n // which makes queries very slow. This only happens when no query (filter) is provided. If one is provided, it uses\n // the correct indexed field\n paginationOptions.useCustomCountFn = () => {\n return Promise.resolve(\n Model.countDocuments(versionQuery, {\n collation: paginationOptions.collation,\n hint: { _id: 1 },\n session,\n }),\n )\n }\n }\n\n if (limit && limit > 0) {\n paginationOptions.limit = limit\n // limit must also be set here, it's ignored when pagination is false\n\n paginationOptions.options!.limit = limit\n }\n\n let result\n\n const aggregate = await buildJoinAggregation({\n adapter: this,\n collection: collectionSlug,\n collectionConfig,\n joins,\n locale,\n projection,\n query: versionQuery,\n versions: true,\n })\n\n if (aggregate || sortAggregation.length > 0) {\n result = await aggregatePaginate({\n adapter: this,\n collation: paginationOptions.collation,\n joinAggregation: aggregate,\n limit: paginationOptions.limit,\n Model,\n page: paginationOptions.page,\n pagination: paginationOptions.pagination,\n projection: paginationOptions.projection,\n query: versionQuery,\n session: paginationOptions.options?.session ?? undefined,\n sort: paginationOptions.sort as object,\n sortAggregation,\n useEstimatedCount: paginationOptions.useEstimatedCount,\n })\n } else {\n result = await Model.paginate(versionQuery, paginationOptions)\n }\n\n if (!this.useJoinAggregations) {\n await resolveJoins({\n adapter: this,\n collectionSlug,\n docs: result.docs as Record<string, unknown>[],\n joins,\n locale,\n versions: true,\n })\n }\n\n transform({\n adapter: this,\n data: result.docs,\n fields: buildVersionCollectionFields(this.payload.config, collectionConfig),\n operation: 'read',\n })\n\n for (let i = 0; i < result.docs.length; i++) {\n const id = result.docs[i].parent\n result.docs[i] = result.docs[i].version ?? {}\n result.docs[i].id = id\n }\n\n return result\n}\n"],"names":["buildVersionCollectionFields","combineQueries","flattenWhereToOperators","buildQuery","buildSortParam","aggregatePaginate","buildJoinAggregation","buildProjectionFromSelect","getCollection","getSession","resolveJoins","transform","queryDrafts","collection","collectionSlug","joins","limit","locale","page","pagination","req","select","sort","sortArg","where","collectionConfig","Model","adapter","versions","hasNearConstraint","constraints","some","prop","Object","keys","key","fields","payload","config","sortAggregation","defaultSort","timestamps","combinedWhere","latest","equals","versionQuery","projection","session","options","useEstimatedCount","length","paginationOptions","lean","leanWithId","collation","localizationConfig","localization","defaultLocale","disableIndexHints","useCustomCountFn","Promise","resolve","countDocuments","hint","_id","result","aggregate","query","joinAggregation","undefined","paginate","useJoinAggregations","docs","data","operation","i","id","parent","version"],"mappings":"AAGA,SAASA,4BAA4B,EAAEC,cAAc,EAAEC,uBAAuB,QAAQ,UAAS;AAI/F,SAASC,UAAU,QAAQ,0BAAyB;AACpD,SAASC,cAAc,QAAQ,8BAA6B;AAC5D,SAASC,iBAAiB,QAAQ,mCAAkC;AACpE,SAASC,oBAAoB,QAAQ,sCAAqC;AAC1E,SAASC,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,aAAa,QAAQ,2BAA0B;AACxD,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAASC,YAAY,QAAQ,8BAA6B;AAC1D,SAASC,SAAS,QAAQ,2BAA0B;AAEpD,OAAO,MAAMC,cAA2B,eAAeA,YAErD,EACEC,YAAYC,cAAc,EAC1BC,KAAK,EACLC,KAAK,EACLC,MAAM,EACNC,IAAI,EACJC,UAAU,EACVC,G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WsB;YAC/C/C,MAAM6B,kBAAkB7B,IAAI;YAC5BiB;YACAU,mBAAmBE,kBAAkBF,iBAAiB;QACxD;IACF,OAAO;QACLgB,SAAS,MAAMvC,MAAM4C,QAAQ,CAACzB,cAAcM;IAC9C;IAEA,IAAI,CAAC,IAAI,CAACoB,mBAAmB,EAAE;QAC7B,MAAM7D,aAAa;YACjBiB,SAAS,IAAI;YACbb;YACA0D,MAAMP,OAAOO,IAAI;YACjBzD;YACAE;YACAW,UAAU;QACZ;IACF;IAEAjB,UAAU;QACRgB,SAAS,IAAI;QACb8C,MAAMR,OAAOO,IAAI;QACjBpC,QAAQpC,6BAA6B,IAAI,CAACqC,OAAO,CAACC,MAAM,EAAEb;QAC1DiD,WAAW;IACb;IAEA,IAAK,IAAIC,IAAI,GAAGA,IAAIV,OAAOO,IAAI,CAACtB,MAAM,EAAEyB,IAAK;QAC3C,MAAMC,KAAKX,OAAOO,IAAI,CAACG,EAAE,CAACE,MAAM;QAChCZ,OAAOO,IAAI,CAACG,EAAE,GAAGV,OAAOO,IAAI,CAACG,EAAE,CAACG,OAAO,IAAI,CAAC;QAC5Cb,OAAOO,IAAI,CAACG,EAAE,CAACC,EAAE,GAAGA;IACtB;IAEA,OAAOX;AACT,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"updateGlobal.d.ts","sourceRoot":"","sources":["../src/updateGlobal.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"updateGlobal.d.ts","sourceRoot":"","sources":["../src/updateGlobal.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAS3C,eAAO,MAAM,YAAY,EAAE,YAsC1B,CAAA"}
|
package/dist/updateGlobal.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { recordBranchGlobalChange, resolveBranchGlobalWrite } from 'payload';
|
|
2
1
|
import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js';
|
|
3
2
|
import { getGlobal } from './utilities/getEntity.js';
|
|
4
3
|
import { getSession } from './utilities/getSession.js';
|
|
5
4
|
import { transform } from './utilities/transform.js';
|
|
6
|
-
export const updateGlobal = async function updateGlobal({ slug: globalSlug,
|
|
5
|
+
export const updateGlobal = async function updateGlobal({ slug: globalSlug, data, options: optionsArgs = {}, req, returning, select }) {
|
|
7
6
|
const { globalConfig, Model } = getGlobal({
|
|
8
7
|
adapter: this,
|
|
9
8
|
globalSlug
|
|
@@ -32,67 +31,15 @@ export const updateGlobal = async function updateGlobal({ slug: globalSlug, bran
|
|
|
32
31
|
select
|
|
33
32
|
})
|
|
34
33
|
};
|
|
35
|
-
const writeBranch = resolveBranchGlobalWrite({
|
|
36
|
-
branch,
|
|
37
|
-
globalSlug,
|
|
38
|
-
req
|
|
39
|
-
});
|
|
40
|
-
// On a branch the write targets that branch's own row, upserting it from
|
|
41
|
-
// main's current content the first time the global is touched.
|
|
42
|
-
const filter = writeBranch ? {
|
|
43
|
-
_branch: {
|
|
44
|
-
$eq: writeBranch
|
|
45
|
-
},
|
|
46
|
-
globalType: globalSlug
|
|
47
|
-
} : {
|
|
48
|
-
globalType: globalSlug
|
|
49
|
-
};
|
|
50
|
-
if (writeBranch) {
|
|
51
|
-
const existing = await Model.findOne(filter, {}, baseOptions).lean();
|
|
52
|
-
if (!existing) {
|
|
53
|
-
const mainDoc = await Model.findOne({
|
|
54
|
-
_branch: {
|
|
55
|
-
$eq: 'main'
|
|
56
|
-
},
|
|
57
|
-
globalType: globalSlug
|
|
58
|
-
}, {}, baseOptions).lean();
|
|
59
|
-
const { _id, __v, ...mainData } = mainDoc ?? {};
|
|
60
|
-
await Model.create([
|
|
61
|
-
{
|
|
62
|
-
...mainData,
|
|
63
|
-
...data,
|
|
64
|
-
_branch: writeBranch
|
|
65
|
-
}
|
|
66
|
-
], baseOptions, req);
|
|
67
|
-
await recordBranchGlobalChange({
|
|
68
|
-
branch: writeBranch,
|
|
69
|
-
globalSlug,
|
|
70
|
-
req
|
|
71
|
-
});
|
|
72
|
-
if (returning === false) {
|
|
73
|
-
return null;
|
|
74
|
-
}
|
|
75
|
-
const created = await Model.findOne(filter, findOptions.projection, findOptions);
|
|
76
|
-
transform({
|
|
77
|
-
adapter: this,
|
|
78
|
-
data: created,
|
|
79
|
-
fields,
|
|
80
|
-
globalSlug,
|
|
81
|
-
operation: 'read'
|
|
82
|
-
});
|
|
83
|
-
return created;
|
|
84
|
-
}
|
|
85
|
-
await recordBranchGlobalChange({
|
|
86
|
-
branch: writeBranch,
|
|
87
|
-
globalSlug,
|
|
88
|
-
req
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
34
|
if (returning === false) {
|
|
92
|
-
await Model.updateOne(
|
|
35
|
+
await Model.updateOne({
|
|
36
|
+
globalType: globalSlug
|
|
37
|
+
}, data, baseOptions);
|
|
93
38
|
return null;
|
|
94
39
|
}
|
|
95
|
-
const result = await Model.findOneAndUpdate(
|
|
40
|
+
const result = await Model.findOneAndUpdate({
|
|
41
|
+
globalType: globalSlug
|
|
42
|
+
}, data, findOptions);
|
|
96
43
|
transform({
|
|
97
44
|
adapter: this,
|
|
98
45
|
data: result,
|
package/dist/updateGlobal.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/updateGlobal.ts"],"sourcesContent":["import type { QueryOptions } from 'mongoose'\nimport type { UpdateGlobal } from 'payload'\n\nimport
|
|
1
|
+
{"version":3,"sources":["../src/updateGlobal.ts"],"sourcesContent":["import type { QueryOptions } from 'mongoose'\nimport type { UpdateGlobal } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getGlobal } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\nimport { transform } from './utilities/transform.js'\n\nexport const updateGlobal: UpdateGlobal = async function updateGlobal(\n this: MongooseAdapter,\n { slug: globalSlug, data, options: optionsArgs = {}, req, returning, select },\n) {\n const { globalConfig, Model } = getGlobal({ adapter: this, globalSlug })\n\n const fields = globalConfig.fields\n\n transform({ adapter: this, data, fields, globalSlug, operation: 'write' })\n\n const baseOptions = {\n ...optionsArgs,\n session: await getSession(this, req),\n // Timestamps are manually added by the write transform\n timestamps: false,\n } satisfies QueryOptions\n\n const findOptions: QueryOptions = {\n ...baseOptions,\n lean: true,\n new: true,\n projection: buildProjectionFromSelect({\n adapter: this,\n fields: globalConfig.flattenedFields,\n select,\n }),\n }\n\n if (returning === false) {\n await Model.updateOne({ globalType: globalSlug }, data, baseOptions)\n return null\n }\n\n const result: any = await Model.findOneAndUpdate({ globalType: globalSlug }, data, findOptions)\n\n transform({ adapter: this, data: result, fields, globalSlug, operation: 'read' })\n\n return result\n}\n"],"names":["buildProjectionFromSelect","getGlobal","getSession","transform","updateGlobal","slug","globalSlug","data","options","optionsArgs","req","returning","select","globalConfig","Model","adapter","fields","operation","baseOptions","session","timestamps","findOptions","lean","new","projection","flattenedFields","updateOne","globalType","result","findOneAndUpdate"],"mappings":"AAKA,SAASA,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,SAAS,QAAQ,2BAA0B;AACpD,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAASC,SAAS,QAAQ,2BAA0B;AAEpD,OAAO,MAAMC,eAA6B,eAAeA,aAEvD,EAAEC,MAAMC,UAAU,EAAEC,IAAI,EAAEC,SAASC,cAAc,CAAC,CAAC,EAAEC,GAAG,EAAEC,SAAS,EAAEC,MAAM,EAAE;IAE7E,MAAM,EAAEC,YAAY,EAAEC,KAAK,EAAE,GAAGb,UAAU;QAAEc,SAAS,IAAI;QAAET;IAAW;IAEtE,MAAMU,SAASH,aAAaG,MAAM;IAElCb,UAAU;QAAEY,SAAS,IAAI;QAAER;QAAMS;QAAQV;QAAYW,WAAW;IAAQ;IAExE,MAAMC,cAAc;QAClB,GAAGT,WAAW;QACdU,SAAS,MAAMjB,WAAW,IAAI,EAAEQ;QAChC,uDAAuD;QACvDU,YAAY;IACd;IAEA,MAAMC,cAA4B;QAChC,GAAGH,WAAW;QACdI,MAAM;QACNC,KAAK;QACLC,YAAYxB,0BAA0B;YACpCe,SAAS,IAAI;YACbC,QAAQH,aAAaY,eAAe;YACpCb;QACF;IACF;IAEA,IAAID,cAAc,OAAO;QACvB,MAAMG,MAAMY,SAAS,CAAC;YAAEC,YAAYrB;QAAW,GAAGC,MAAMW;QACxD,OAAO;IACT;IAEA,MAAMU,SAAc,MAAMd,MAAMe,gBAAgB,CAAC;QAAEF,YAAYrB;IAAW,GAAGC,MAAMc;IAEnFlB,UAAU;QAAEY,SAAS,IAAI;QAAER,MAAMqB;QAAQZ;QAAQV;QAAYW,WAAW;IAAO;IAE/E,OAAOW;AACT,EAAC"}
|
package/dist/updateOne.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"updateOne.d.ts","sourceRoot":"","sources":["../src/updateOne.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"updateOne.d.ts","sourceRoot":"","sources":["../src/updateOne.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAWxC,eAAO,MAAM,SAAS,EAAE,SAsGvB,CAAA"}
|
package/dist/updateOne.js
CHANGED
|
@@ -1,23 +1,14 @@
|
|
|
1
|
-
import { resolveBranchRowID } from 'payload';
|
|
2
1
|
import { buildQuery } from './queries/buildQuery.js';
|
|
3
2
|
import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js';
|
|
4
3
|
import { getCollection } from './utilities/getEntity.js';
|
|
5
4
|
import { getSession } from './utilities/getSession.js';
|
|
6
5
|
import { handleError } from './utilities/handleError.js';
|
|
7
6
|
import { transform } from './utilities/transform.js';
|
|
8
|
-
export const updateOne = async function updateOne({ id,
|
|
7
|
+
export const updateOne = async function updateOne({ id, collection: collectionSlug, data, locale, options: optionsArgs = {}, req, returning, select, where: whereArg = {} }) {
|
|
9
8
|
const { collectionConfig, Model } = getCollection({
|
|
10
9
|
adapter: this,
|
|
11
10
|
collectionSlug
|
|
12
11
|
});
|
|
13
|
-
if (id !== undefined && id !== null) {
|
|
14
|
-
id = await resolveBranchRowID({
|
|
15
|
-
id,
|
|
16
|
-
branch,
|
|
17
|
-
collectionSlug,
|
|
18
|
-
req
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
12
|
const where = id ? {
|
|
22
13
|
id: {
|
|
23
14
|
equals: id
|
package/dist/updateOne.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/updateOne.ts"],"sourcesContent":["import type { QueryOptions, UpdateQuery } from 'mongoose'\nimport type { UpdateOne } from 'payload'\n\nimport
|
|
1
|
+
{"version":3,"sources":["../src/updateOne.ts"],"sourcesContent":["import type { QueryOptions, UpdateQuery } from 'mongoose'\nimport type { UpdateOne } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getCollection } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\nimport { handleError } from './utilities/handleError.js'\nimport { transform } from './utilities/transform.js'\n\nexport const updateOne: UpdateOne = async function updateOne(\n this: MongooseAdapter,\n {\n id,\n collection: collectionSlug,\n data,\n locale,\n options: optionsArgs = {},\n req,\n returning,\n select,\n where: whereArg = {},\n },\n) {\n const { collectionConfig, Model } = getCollection({ adapter: this, collectionSlug })\n const where = id ? { id: { equals: id } } : whereArg\n const fields = collectionConfig.fields\n\n const query = await buildQuery({\n adapter: this,\n collectionSlug,\n fields: collectionConfig.flattenedFields,\n locale,\n where,\n })\n\n let result\n\n let updateData: UpdateQuery<any> = data\n\n const $inc: Record<string, number> = {}\n const $push: Record<string, { $each: any[] } | any> = {}\n const $addToSet: Record<string, { $each: any[] } | any> = {}\n const $pull: Record<string, { $in: any[] } | any> = {}\n\n transform({\n $addToSet,\n $inc,\n $pull,\n $push,\n adapter: this,\n data,\n fields,\n operation: 'write',\n })\n\n const updateOps: UpdateQuery<any> = {}\n\n if (Object.keys($inc).length) {\n updateOps.$inc = $inc\n }\n if (Object.keys($push).length) {\n updateOps.$push = $push\n }\n if (Object.keys($addToSet).length) {\n updateOps.$addToSet = $addToSet\n }\n if (Object.keys($pull).length) {\n updateOps.$pull = $pull\n }\n if (Object.keys(updateOps).length) {\n updateOps.$set = updateData\n updateData = updateOps\n }\n\n const baseOptions = {\n ...optionsArgs,\n session: await getSession(this, req),\n // Timestamps are manually added by the write transform\n timestamps: false,\n } satisfies QueryOptions\n\n const findOptions: QueryOptions = {\n ...baseOptions,\n lean: true,\n new: true,\n projection: buildProjectionFromSelect({\n adapter: this,\n fields: collectionConfig.flattenedFields,\n select,\n }),\n }\n\n try {\n if (returning === false) {\n await Model.updateOne(query, updateData, baseOptions)\n transform({ adapter: this, data, fields, operation: 'read' })\n return null\n } else {\n result = await Model.findOneAndUpdate(query, updateData, findOptions)\n }\n } catch (error) {\n handleError({ collection: collectionSlug, error, req })\n }\n\n if (!result) {\n return null\n }\n\n transform({ adapter: this, data: result, fields, operation: 'read' })\n\n return result\n}\n"],"names":["buildQuery","buildProjectionFromSelect","getCollection","getSession","handleError","transform","updateOne","id","collection","collectionSlug","data","locale","options","optionsArgs","req","returning","select","where","whereArg","collectionConfig","Model","adapter","equals","fields","query","flattenedFields","result","updateData","$inc","$push","$addToSet","$pull","operation","updateOps","Object","keys","length","$set","baseOptions","session","timestamps","findOptions","lean","new","projection","findOneAndUpdate","error"],"mappings":"AAKA,SAASA,UAAU,QAAQ,0BAAyB;AACpD,SAASC,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,aAAa,QAAQ,2BAA0B;AACxD,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAASC,WAAW,QA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,UAAUI,IAAI,GAAGV;QACjBA,aAAaM;IACf;IAEA,MAAMK,cAAc;QAClB,GAAGzB,WAAW;QACd0B,SAAS,MAAMpC,WAAW,IAAI,EAAEW;QAChC,uDAAuD;QACvD0B,YAAY;IACd;IAEA,MAAMC,cAA4B;QAChC,GAAGH,WAAW;QACdI,MAAM;QACNC,KAAK;QACLC,YAAY3C,0BAA0B;YACpCoB,SAAS,IAAI;YACbE,QAAQJ,iBAAiBM,eAAe;YACxCT;QACF;IACF;IAEA,IAAI;QACF,IAAID,cAAc,OAAO;YACvB,MAAMK,MAAMd,SAAS,CAACkB,OAAOG,YAAYW;YACzCjC,UAAU;gBAAEgB,SAAS,IAAI;gBAAEX;gBAAMa;gBAAQS,WAAW;YAAO;YAC3D,OAAO;QACT,OAAO;YACLN,SAAS,MAAMN,MAAMyB,gBAAgB,CAACrB,OAAOG,YAAYc;QAC3D;IACF,EAAE,OAAOK,OAAO;QACd1C,YAAY;YAAEI,YAAYC;YAAgBqC;YAAOhC;QAAI;IACvD;IAEA,IAAI,CAACY,QAAQ;QACX,OAAO;IACT;IAEArB,UAAU;QAAEgB,SAAS,IAAI;QAAEX,MAAMgB;QAAQH;QAAQS,WAAW;IAAO;IAEnE,OAAON;AACT,EAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { PipelineStage } from 'mongoose';
|
|
2
|
-
import { type CollectionSlug, type JoinQuery, type
|
|
2
|
+
import { type CollectionSlug, type JoinQuery, type SanitizedCollectionConfig } from 'payload';
|
|
3
3
|
import type { MongooseAdapter } from '../index.js';
|
|
4
4
|
type BuildJoinAggregationArgs = {
|
|
5
5
|
adapter: MongooseAdapter;
|
|
@@ -10,10 +10,9 @@ type BuildJoinAggregationArgs = {
|
|
|
10
10
|
locale?: string;
|
|
11
11
|
projection?: Record<string, true>;
|
|
12
12
|
query?: Record<string, unknown>;
|
|
13
|
-
req?: Partial<PayloadRequest>;
|
|
14
13
|
/** whether the query is from drafts */
|
|
15
14
|
versions?: boolean;
|
|
16
15
|
};
|
|
17
|
-
export declare const buildJoinAggregation: ({ adapter, collection, collectionConfig, draftsEnabled, joins, locale, projection,
|
|
16
|
+
export declare const buildJoinAggregation: ({ adapter, collection, collectionConfig, draftsEnabled, joins, locale, projection, versions, }: BuildJoinAggregationArgs) => Promise<PipelineStage[] | undefined>;
|
|
18
17
|
export {};
|
|
19
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;AAE7C,OAAO,EAIL,KAAK,cAAc,
|
|
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,GAAG,SAAS,CA0chE,CAAA"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { APIError, appendVersionToQueryKey, buildVersionCollectionFields, combineQueries,
|
|
1
|
+
import { APIError, appendVersionToQueryKey, buildVersionCollectionFields, combineQueries, getQueryDraftsSort } from 'payload';
|
|
2
2
|
import { fieldShouldBeLocalized, hasDraftsEnabled } from 'payload/shared';
|
|
3
3
|
import { buildQuery } from '../queries/buildQuery.js';
|
|
4
4
|
import { buildSortParam } from '../queries/buildSortParam.js';
|
|
5
5
|
import { getCollection } from './getEntity.js';
|
|
6
|
-
export const buildJoinAggregation = async ({ adapter, collection, collectionConfig, draftsEnabled, joins, locale, projection,
|
|
6
|
+
export const buildJoinAggregation = async ({ adapter, collection, collectionConfig, draftsEnabled, joins, locale, projection, versions })=>{
|
|
7
7
|
if (!adapter.useJoinAggregations) {
|
|
8
8
|
return;
|
|
9
9
|
}
|
|
@@ -247,46 +247,19 @@ export const buildJoinAggregation = async ({ adapter, collection, collectionConf
|
|
|
247
247
|
});
|
|
248
248
|
const sortProperty = Object.keys(sort)[0];
|
|
249
249
|
const sortDirection = sort[sortProperty] === 'asc' ? 1 : -1;
|
|
250
|
-
// A join subquery must carry the same branch predicate as the top-level
|
|
251
|
-
// read, or a branch would see main's related documents.
|
|
252
|
-
const joinBranchPredicate = getBranchPredicateSync({
|
|
253
|
-
collectionSlug: collectionConfig.slug,
|
|
254
|
-
req
|
|
255
|
-
});
|
|
256
|
-
const branchedWhereJoin = joinBranchPredicate ? {
|
|
257
|
-
and: [
|
|
258
|
-
whereJoin,
|
|
259
|
-
joinBranchPredicate
|
|
260
|
-
]
|
|
261
|
-
} : whereJoin;
|
|
262
250
|
const $match = await JoinModel.buildQuery({
|
|
263
251
|
locale,
|
|
264
252
|
payload: adapter.payload,
|
|
265
|
-
where: useDrafts ? combineQueries(appendVersionToQueryKey(
|
|
253
|
+
where: useDrafts ? combineQueries(appendVersionToQueryKey(whereJoin), {
|
|
266
254
|
latest: {
|
|
267
255
|
equals: true
|
|
268
256
|
}
|
|
269
|
-
}) :
|
|
257
|
+
}) : whereJoin
|
|
270
258
|
});
|
|
271
259
|
const pipeline = [
|
|
272
260
|
{
|
|
273
261
|
$match
|
|
274
262
|
},
|
|
275
|
-
// Surface the canonical document ID rather than the shadow row's own
|
|
276
|
-
// primary key, so join results address documents the same way every
|
|
277
|
-
// other read does.
|
|
278
|
-
...joinBranchPredicate ? [
|
|
279
|
-
{
|
|
280
|
-
$set: {
|
|
281
|
-
_id: {
|
|
282
|
-
$ifNull: [
|
|
283
|
-
'$_branchDocID',
|
|
284
|
-
'$_id'
|
|
285
|
-
]
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
] : [],
|
|
290
263
|
{
|
|
291
264
|
$sort: {
|
|
292
265
|
[sortProperty]: sortDirection
|