@payloadcms/db-mongodb 3.24.0-canary.f229d8d → 3.25.0-canary.36940b2
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 +5 -2
- package/dist/count.js.map +1 -1
- package/dist/countGlobalVersions.d.ts.map +1 -1
- package/dist/countGlobalVersions.js +5 -3
- package/dist/countGlobalVersions.js.map +1 -1
- package/dist/countVersions.d.ts.map +1 -1
- package/dist/countVersions.js +5 -3
- package/dist/countVersions.js.map +1 -1
- package/dist/create.js +15 -15
- package/dist/create.js.map +1 -1
- package/dist/createGlobal.d.ts.map +1 -1
- package/dist/createGlobal.js +15 -14
- package/dist/createGlobal.js.map +1 -1
- package/dist/createGlobalVersion.d.ts.map +1 -1
- package/dist/createGlobalVersion.js +26 -23
- package/dist/createGlobalVersion.js.map +1 -1
- package/dist/createVersion.d.ts.map +1 -1
- package/dist/createVersion.js +26 -31
- package/dist/createVersion.js.map +1 -1
- package/dist/deleteMany.d.ts.map +1 -1
- package/dist/deleteMany.js +5 -2
- package/dist/deleteMany.js.map +1 -1
- package/dist/deleteOne.d.ts.map +1 -1
- package/dist/deleteOne.js +17 -9
- package/dist/deleteOne.js.map +1 -1
- package/dist/deleteVersions.d.ts +1 -1
- package/dist/deleteVersions.d.ts.map +1 -1
- package/dist/deleteVersions.js +5 -2
- package/dist/deleteVersions.js.map +1 -1
- package/dist/find.d.ts.map +1 -1
- package/dist/find.js +13 -11
- package/dist/find.js.map +1 -1
- package/dist/findGlobal.d.ts.map +1 -1
- package/dist/findGlobal.js +15 -11
- package/dist/findGlobal.js.map +1 -1
- package/dist/findGlobalVersions.d.ts.map +1 -1
- package/dist/findGlobalVersions.js +14 -13
- package/dist/findGlobalVersions.js.map +1 -1
- package/dist/findOne.d.ts.map +1 -1
- package/dist/findOne.js +13 -8
- package/dist/findOne.js.map +1 -1
- package/dist/findVersions.d.ts.map +1 -1
- package/dist/findVersions.js +14 -12
- package/dist/findVersions.js.map +1 -1
- package/dist/init.d.ts.map +1 -1
- package/dist/init.js +25 -17
- package/dist/init.js.map +1 -1
- package/dist/models/buildCollectionSchema.d.ts.map +1 -1
- package/dist/models/buildCollectionSchema.js +14 -10
- package/dist/models/buildCollectionSchema.js.map +1 -1
- package/dist/models/buildGlobalModel.d.ts.map +1 -1
- package/dist/models/buildGlobalModel.js +9 -5
- package/dist/models/buildGlobalModel.js.map +1 -1
- package/dist/models/buildSchema.d.ts +6 -1
- package/dist/models/buildSchema.d.ts.map +1 -1
- package/dist/models/buildSchema.js +222 -99
- package/dist/models/buildSchema.js.map +1 -1
- package/dist/predefinedMigrations/migrateRelationshipsV2_V3.d.ts.map +1 -1
- package/dist/predefinedMigrations/migrateRelationshipsV2_V3.js +17 -8
- package/dist/predefinedMigrations/migrateRelationshipsV2_V3.js.map +1 -1
- package/dist/queries/buildAndOrConditions.d.ts +2 -1
- package/dist/queries/buildAndOrConditions.d.ts.map +1 -1
- package/dist/queries/buildAndOrConditions.js +2 -1
- package/dist/queries/buildAndOrConditions.js.map +1 -1
- package/dist/queries/buildQuery.d.ts +6 -9
- package/dist/queries/buildQuery.d.ts.map +1 -1
- package/dist/queries/buildQuery.js +11 -34
- package/dist/queries/buildQuery.js.map +1 -1
- package/dist/queries/buildSearchParams.d.ts +2 -1
- package/dist/queries/buildSearchParams.d.ts.map +1 -1
- package/dist/queries/buildSearchParams.js +20 -1
- package/dist/queries/buildSearchParams.js.map +1 -1
- package/dist/queries/buildSortParam.d.ts +2 -1
- package/dist/queries/buildSortParam.d.ts.map +1 -1
- package/dist/queries/buildSortParam.js +2 -1
- package/dist/queries/buildSortParam.js.map +1 -1
- package/dist/queries/getBuildQueryPlugin.d.ts +14 -0
- package/dist/queries/getBuildQueryPlugin.d.ts.map +1 -0
- package/dist/queries/getBuildQueryPlugin.js +40 -0
- package/dist/queries/getBuildQueryPlugin.js.map +1 -0
- package/dist/queries/getLocalizedSortProperty.d.ts +2 -1
- package/dist/queries/getLocalizedSortProperty.d.ts.map +1 -1
- package/dist/queries/getLocalizedSortProperty.js +11 -3
- package/dist/queries/getLocalizedSortProperty.js.map +1 -1
- package/dist/queries/parseParams.d.ts +2 -1
- package/dist/queries/parseParams.d.ts.map +1 -1
- package/dist/queries/parseParams.js +3 -1
- package/dist/queries/parseParams.js.map +1 -1
- package/dist/queries/sanitizeQueryValue.d.ts +2 -1
- package/dist/queries/sanitizeQueryValue.d.ts.map +1 -1
- package/dist/queries/sanitizeQueryValue.js +6 -2
- package/dist/queries/sanitizeQueryValue.js.map +1 -1
- package/dist/queryDrafts.d.ts.map +1 -1
- package/dist/queryDrafts.js +19 -16
- package/dist/queryDrafts.js.map +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/updateGlobal.d.ts.map +1 -1
- package/dist/updateGlobal.js +15 -12
- package/dist/updateGlobal.js.map +1 -1
- package/dist/updateGlobalVersion.d.ts.map +1 -1
- package/dist/updateGlobalVersion.js +21 -15
- package/dist/updateGlobalVersion.js.map +1 -1
- package/dist/updateOne.js +20 -11
- package/dist/updateOne.js.map +1 -1
- package/dist/updateVersion.d.ts.map +1 -1
- package/dist/updateVersion.js +21 -15
- package/dist/updateVersion.js.map +1 -1
- package/dist/utilities/buildJoinAggregation.d.ts.map +1 -1
- package/dist/utilities/buildJoinAggregation.js +155 -4
- package/dist/utilities/buildJoinAggregation.js.map +1 -1
- package/dist/utilities/buildProjectionFromSelect.d.ts.map +1 -1
- package/dist/utilities/buildProjectionFromSelect.js +18 -17
- package/dist/utilities/buildProjectionFromSelect.js.map +1 -1
- package/dist/utilities/transform.d.ts +27 -0
- package/dist/utilities/transform.d.ts.map +1 -0
- package/dist/utilities/transform.js +224 -0
- package/dist/utilities/transform.js.map +1 -0
- package/dist/utilities/{sanitizeRelationshipIDs.spec.js → transform.spec.js} +55 -5
- package/dist/utilities/transform.spec.js.map +1 -0
- package/package.json +3 -3
- package/dist/utilities/sanitizeInternalFields.d.ts +0 -2
- package/dist/utilities/sanitizeInternalFields.d.ts.map +0 -1
- package/dist/utilities/sanitizeInternalFields.js +0 -20
- package/dist/utilities/sanitizeInternalFields.js.map +0 -1
- package/dist/utilities/sanitizeRelationshipIDs.d.ts +0 -9
- package/dist/utilities/sanitizeRelationshipIDs.d.ts.map +0 -1
- package/dist/utilities/sanitizeRelationshipIDs.js +0 -126
- package/dist/utilities/sanitizeRelationshipIDs.js.map +0 -1
- package/dist/utilities/sanitizeRelationshipIDs.spec.js.map +0 -1
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAC5C,OAAO,KAAK,EACV,sBAAsB,EACtB,eAAe,EACf,YAAY,EACZ,KAAK,EACL,aAAa,EACb,aAAa,EACd,MAAM,UAAU,CAAA;AACjB,OAAO,KAAK,EACV,UAAU,EACV,WAAW,EACX,aAAa,EACb,SAAS,EACT,gBAAgB,EAChB,SAAS,EACT,UAAU,EACV,KAAK,EACL,UAAU,EACV,SAAS,EACT,SAAS,EACT,WAAW,EACX,OAAO,EACP,cAAc,EACd,UAAU,EACV,UAAU,EACV,iBAAiB,EACjB,aAAa,EACb,QAAQ,EACR,eAAe,EACf,WAAW,EACX,SAAS,EACT,aAAa,EACb,SAAS,EACT,WAAW,EACZ,MAAM,SAAS,CAAA;AAEhB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"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"}
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type { ClientSession } from 'mongodb'\nimport type {\n AggregatePaginateModel,\n IndexDefinition,\n IndexOptions,\n Model,\n PaginateModel,\n SchemaOptions,\n} from 'mongoose'\nimport type {\n ArrayField,\n BlocksField,\n CheckboxField,\n CodeField,\n CollapsibleField,\n DateField,\n EmailField,\n Field,\n GroupField,\n JoinField,\n JSONField,\n NumberField,\n Payload,\n PayloadRequest,\n PointField,\n RadioField,\n RelationshipField,\n RichTextField,\n RowField,\n SanitizedConfig,\n SelectField,\n TabsField,\n TextareaField,\n TextField,\n UploadField,\n} from 'payload'\n\nimport type { BuildQueryArgs } from './queries/
|
|
1
|
+
{"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type { ClientSession } from 'mongodb'\nimport type {\n AggregatePaginateModel,\n IndexDefinition,\n IndexOptions,\n Model,\n PaginateModel,\n SchemaOptions,\n} from 'mongoose'\nimport type {\n ArrayField,\n BlocksField,\n CheckboxField,\n CodeField,\n CollapsibleField,\n DateField,\n EmailField,\n Field,\n GroupField,\n JoinField,\n JSONField,\n NumberField,\n Payload,\n PayloadRequest,\n PointField,\n RadioField,\n RelationshipField,\n RichTextField,\n RowField,\n SanitizedConfig,\n SelectField,\n TabsField,\n TextareaField,\n TextField,\n UploadField,\n} from 'payload'\n\nimport type { BuildQueryArgs } from './queries/getBuildQueryPlugin.js'\n\nexport interface CollectionModel\n extends Model<any>,\n PaginateModel<any>,\n AggregatePaginateModel<any> {\n /** buildQuery is used to transform payload's where operator into what can be used by mongoose (e.g. id => _id) */\n buildQuery: (args: BuildQueryArgs) => Promise<Record<string, unknown>> // TODO: Delete this\n}\n\nexport interface AuthCollectionModel extends CollectionModel {\n resetPasswordExpiration: Date\n resetPasswordToken: string\n}\n\nexport type TypeOfIndex = {\n fields: IndexDefinition\n options?: IndexOptions\n}\n\nexport interface GlobalModel extends Model<Document> {\n buildQuery: (query: unknown, locale?: string) => Promise<Record<string, unknown>>\n}\n\nexport type BuildSchema<TSchema> = (args: {\n config: SanitizedConfig\n fields: Field[]\n options: BuildSchemaOptions\n}) => TSchema\n\nexport type BuildSchemaOptions = {\n allowIDField?: boolean\n disableUnique?: boolean\n draftsEnabled?: boolean\n indexSortableFields?: boolean\n options?: SchemaOptions\n}\n\nexport type FieldGenerator<TSchema, TField> = {\n config: SanitizedConfig\n field: TField\n options: BuildSchemaOptions\n schema: TSchema\n}\n\nexport type FieldGeneratorFunction<TSchema, TField extends Field> = (\n args: FieldGenerator<TSchema, TField>,\n) => void\n\n/**\n * Object mapping types to a schema based on TSchema\n */\nexport type FieldToSchemaMap<TSchema> = {\n array: FieldGeneratorFunction<TSchema, ArrayField>\n blocks: FieldGeneratorFunction<TSchema, BlocksField>\n checkbox: FieldGeneratorFunction<TSchema, CheckboxField>\n code: FieldGeneratorFunction<TSchema, CodeField>\n collapsible: FieldGeneratorFunction<TSchema, CollapsibleField>\n date: FieldGeneratorFunction<TSchema, DateField>\n email: FieldGeneratorFunction<TSchema, EmailField>\n group: FieldGeneratorFunction<TSchema, GroupField>\n join: FieldGeneratorFunction<TSchema, JoinField>\n json: FieldGeneratorFunction<TSchema, JSONField>\n number: FieldGeneratorFunction<TSchema, NumberField>\n point: FieldGeneratorFunction<TSchema, PointField>\n radio: FieldGeneratorFunction<TSchema, RadioField>\n relationship: FieldGeneratorFunction<TSchema, RelationshipField>\n richText: FieldGeneratorFunction<TSchema, RichTextField>\n row: FieldGeneratorFunction<TSchema, RowField>\n select: FieldGeneratorFunction<TSchema, SelectField>\n tabs: FieldGeneratorFunction<TSchema, TabsField>\n text: FieldGeneratorFunction<TSchema, TextField>\n textarea: FieldGeneratorFunction<TSchema, TextareaField>\n upload: FieldGeneratorFunction<TSchema, UploadField>\n}\n\nexport type MigrateUpArgs = {\n /**\n * The Payload instance that you can use to execute Local API methods\n * To use the current transaction you must pass `req` to arguments\n * @example\n * ```ts\n * import { type MigrateUpArgs } from '@payloadcms/db-mongodb'\n *\n * export async function up({ session, payload, req }: MigrateUpArgs): Promise<void> {\n * const posts = await payload.find({ collection: 'posts', req })\n * }\n * ```\n */\n payload: Payload\n /**\n * The `PayloadRequest` object that contains the current transaction\n */\n req: PayloadRequest\n /**\n * The MongoDB client session that you can use to execute MongoDB methods directly within the current transaction.\n * @example\n * ```ts\n * import { type MigrateUpArgs } from '@payloadcms/db-mongodb'\n *\n * export async function up({ session, payload, req }: MigrateUpArgs): Promise<void> {\n * const { rows: posts } = await payload.db.collections.posts.collection.find({ session }).toArray()\n * }\n * ```\n */\n session?: ClientSession\n}\nexport type MigrateDownArgs = {\n /**\n * The Payload instance that you can use to execute Local API methods\n * To use the current transaction you must pass `req` to arguments\n * @example\n * ```ts\n * import { type MigrateDownArgs } from '@payloadcms/db-mongodb'\n *\n * export async function down({ session, payload, req }: MigrateDownArgs): Promise<void> {\n * const posts = await payload.find({ collection: 'posts', req })\n * }\n * ```\n */\n payload: Payload\n /**\n * The `PayloadRequest` object that contains the current transaction\n */\n req: PayloadRequest\n /**\n * The MongoDB client session that you can use to execute MongoDB methods directly within the current transaction.\n * @example\n * ```ts\n * import { type MigrateDownArgs } from '@payloadcms/db-mongodb'\n *\n * export async function down({ session, payload, req }: MigrateDownArgs): Promise<void> {\n * const { rows: posts } = await payload.db.collections.posts.collection.find({ session }).toArray()\n * }\n * ```\n */\n session?: ClientSession\n}\n"],"names":[],"mappings":"AAgJA,WA8BC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"updateGlobal.d.ts","sourceRoot":"","sources":["../src/updateGlobal.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"updateGlobal.d.ts","sourceRoot":"","sources":["../src/updateGlobal.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAQ3C,eAAO,MAAM,YAAY,EAAE,YA0B1B,CAAA"}
|
package/dist/updateGlobal.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js';
|
|
2
2
|
import { getSession } from './utilities/getSession.js';
|
|
3
|
-
import {
|
|
4
|
-
import { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.js';
|
|
3
|
+
import { transform } from './utilities/transform.js';
|
|
5
4
|
export const updateGlobal = async function updateGlobal({ slug, data, options: optionsArgs = {}, req, select }) {
|
|
6
5
|
const Model = this.globals;
|
|
7
6
|
const fields = this.payload.config.globals.find((global)=>global.slug === slug).fields;
|
|
@@ -16,19 +15,23 @@ export const updateGlobal = async function updateGlobal({ slug, data, options: o
|
|
|
16
15
|
}),
|
|
17
16
|
session: await getSession(this, req)
|
|
18
17
|
};
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
config: this.payload.config,
|
|
18
|
+
transform({
|
|
19
|
+
adapter: this,
|
|
22
20
|
data,
|
|
23
|
-
fields
|
|
21
|
+
fields,
|
|
22
|
+
globalSlug: slug,
|
|
23
|
+
operation: 'write'
|
|
24
24
|
});
|
|
25
|
-
result = await Model.findOneAndUpdate({
|
|
25
|
+
const result = await Model.findOneAndUpdate({
|
|
26
26
|
globalType: slug
|
|
27
|
-
},
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
27
|
+
}, data, options);
|
|
28
|
+
transform({
|
|
29
|
+
adapter: this,
|
|
30
|
+
data: result,
|
|
31
|
+
fields,
|
|
32
|
+
globalSlug: slug,
|
|
33
|
+
operation: 'read'
|
|
34
|
+
});
|
|
32
35
|
return result;
|
|
33
36
|
};
|
|
34
37
|
|
package/dist/updateGlobal.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/updateGlobal.ts"],"sourcesContent":["import type { QueryOptions } from 'mongoose'\nimport type { UpdateGlobal } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getSession } from './utilities/getSession.js'\nimport {
|
|
1
|
+
{"version":3,"sources":["../src/updateGlobal.ts"],"sourcesContent":["import type { QueryOptions } from 'mongoose'\nimport type { UpdateGlobal } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getSession } from './utilities/getSession.js'\nimport { transform } from './utilities/transform.js'\n\nexport const updateGlobal: UpdateGlobal = async function updateGlobal(\n this: MongooseAdapter,\n { slug, data, options: optionsArgs = {}, req, select },\n) {\n const Model = this.globals\n const fields = this.payload.config.globals.find((global) => global.slug === slug).fields\n\n const options: QueryOptions = {\n ...optionsArgs,\n lean: true,\n new: true,\n projection: buildProjectionFromSelect({\n adapter: this,\n fields: this.payload.config.globals.find((global) => global.slug === slug).flattenedFields,\n select,\n }),\n session: await getSession(this, req),\n }\n\n transform({ adapter: this, data, fields, globalSlug: slug, operation: 'write' })\n\n const result: any = await Model.findOneAndUpdate({ globalType: slug }, data, options)\n\n transform({ adapter: this, data: result, fields, globalSlug: slug, operation: 'read' })\n\n return result\n}\n"],"names":["buildProjectionFromSelect","getSession","transform","updateGlobal","slug","data","options","optionsArgs","req","select","Model","globals","fields","payload","config","find","global","lean","new","projection","adapter","flattenedFields","session","globalSlug","operation","result","findOneAndUpdate","globalType"],"mappings":"AAKA,SAASA,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAASC,SAAS,QAAQ,2BAA0B;AAEpD,OAAO,MAAMC,eAA6B,eAAeA,aAEvD,EAAEC,IAAI,EAAEC,IAAI,EAAEC,SAASC,cAAc,CAAC,CAAC,EAAEC,GAAG,EAAEC,MAAM,EAAE;IAEtD,MAAMC,QAAQ,IAAI,CAACC,OAAO;IAC1B,MAAMC,SAAS,IAAI,CAACC,OAAO,CAACC,MAAM,CAACH,OAAO,CAACI,IAAI,CAAC,CAACC,SAAWA,OAAOZ,IAAI,KAAKA,MAAMQ,MAAM;IAExF,MAAMN,UAAwB;QAC5B,GAAGC,WAAW;QACdU,MAAM;QACNC,KAAK;QACLC,YAAYnB,0BAA0B;YACpCoB,SAAS,IAAI;YACbR,QAAQ,IAAI,CAACC,OAAO,CAACC,MAAM,CAACH,OAAO,CAACI,IAAI,CAAC,CAACC,SAAWA,OAAOZ,IAAI,KAAKA,MAAMiB,eAAe;YAC1FZ;QACF;QACAa,SAAS,MAAMrB,WAAW,IAAI,EAAEO;IAClC;IAEAN,UAAU;QAAEkB,SAAS,IAAI;QAAEf;QAAMO;QAAQW,YAAYnB;QAAMoB,WAAW;IAAQ;IAE9E,MAAMC,SAAc,MAAMf,MAAMgB,gBAAgB,CAAC;QAAEC,YAAYvB;IAAK,GAAGC,MAAMC;IAE7EJ,UAAU;QAAEkB,SAAS,IAAI;QAAEf,MAAMoB;QAAQb;QAAQW,YAAYnB;QAAMoB,WAAW;IAAO;IAErF,OAAOC;AACT,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"updateGlobalVersion.d.ts","sourceRoot":"","sources":["../src/updateGlobalVersion.ts"],"names":[],"mappings":"AAEA,OAAO,EAA4B,KAAK,UAAU,EAAE,KAAK,uBAAuB,EAAE,MAAM,SAAS,CAAA;AAEjG,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"updateGlobalVersion.d.ts","sourceRoot":"","sources":["../src/updateGlobalVersion.ts"],"names":[],"mappings":"AAEA,OAAO,EAA4B,KAAK,UAAU,EAAE,KAAK,uBAAuB,EAAE,MAAM,SAAS,CAAA;AAEjG,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAOjD,wBAAsB,mBAAmB,CAAC,CAAC,SAAS,UAAU,EAC5D,IAAI,EAAE,eAAe,EACrB,EACE,EAAE,EACF,MAAM,EAAE,UAAU,EAClB,MAAM,EACN,OAAO,EAAE,WAAgB,EACzB,GAAG,EACH,MAAM,EACN,WAAW,EACX,KAAK,GACN,EAAE,uBAAuB,CAAC,CAAC,CAAC,gBAsC9B"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { buildVersionGlobalFields } from 'payload';
|
|
2
|
+
import { buildQuery } from './queries/buildQuery.js';
|
|
2
3
|
import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js';
|
|
3
4
|
import { getSession } from './utilities/getSession.js';
|
|
4
|
-
import {
|
|
5
|
+
import { transform } from './utilities/transform.js';
|
|
5
6
|
export async function updateGlobalVersion({ id, global: globalSlug, locale, options: optionsArgs = {}, req, select, versionData, where }) {
|
|
6
7
|
const VersionModel = this.versions[globalSlug];
|
|
7
8
|
const whereToUse = where || {
|
|
@@ -11,36 +12,41 @@ export async function updateGlobalVersion({ id, global: globalSlug, locale, opti
|
|
|
11
12
|
};
|
|
12
13
|
const currentGlobal = this.payload.config.globals.find((global)=>global.slug === globalSlug);
|
|
13
14
|
const fields = buildVersionGlobalFields(this.payload.config, currentGlobal);
|
|
15
|
+
const flattenedFields = buildVersionGlobalFields(this.payload.config, currentGlobal, true);
|
|
14
16
|
const options = {
|
|
15
17
|
...optionsArgs,
|
|
16
18
|
lean: true,
|
|
17
19
|
new: true,
|
|
18
20
|
projection: buildProjectionFromSelect({
|
|
19
21
|
adapter: this,
|
|
20
|
-
fields:
|
|
22
|
+
fields: flattenedFields,
|
|
21
23
|
select
|
|
22
24
|
}),
|
|
23
25
|
session: await getSession(this, req)
|
|
24
26
|
};
|
|
25
|
-
const query = await
|
|
27
|
+
const query = await buildQuery({
|
|
28
|
+
adapter: this,
|
|
29
|
+
fields: flattenedFields,
|
|
26
30
|
locale,
|
|
27
|
-
payload: this.payload,
|
|
28
31
|
where: whereToUse
|
|
29
32
|
});
|
|
30
|
-
|
|
31
|
-
|
|
33
|
+
transform({
|
|
34
|
+
adapter: this,
|
|
32
35
|
data: versionData,
|
|
33
|
-
fields
|
|
36
|
+
fields,
|
|
37
|
+
operation: 'write'
|
|
34
38
|
});
|
|
35
|
-
const doc = await VersionModel.findOneAndUpdate(query,
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
// custom id type reset
|
|
39
|
-
result.id = result._id;
|
|
40
|
-
if (verificationToken) {
|
|
41
|
-
result._verificationToken = verificationToken;
|
|
39
|
+
const doc = await VersionModel.findOneAndUpdate(query, versionData, options);
|
|
40
|
+
if (!doc) {
|
|
41
|
+
return null;
|
|
42
42
|
}
|
|
43
|
-
|
|
43
|
+
transform({
|
|
44
|
+
adapter: this,
|
|
45
|
+
data: doc,
|
|
46
|
+
fields,
|
|
47
|
+
operation: 'read'
|
|
48
|
+
});
|
|
49
|
+
return doc;
|
|
44
50
|
}
|
|
45
51
|
|
|
46
52
|
//# sourceMappingURL=updateGlobalVersion.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/updateGlobalVersion.ts"],"sourcesContent":["import type { QueryOptions } from 'mongoose'\n\nimport { buildVersionGlobalFields, type TypeWithID, type UpdateGlobalVersionArgs } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getSession } from './utilities/getSession.js'\nimport {
|
|
1
|
+
{"version":3,"sources":["../src/updateGlobalVersion.ts"],"sourcesContent":["import type { QueryOptions } from 'mongoose'\n\nimport { buildVersionGlobalFields, type TypeWithID, type UpdateGlobalVersionArgs } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getSession } from './utilities/getSession.js'\nimport { transform } from './utilities/transform.js'\n\nexport async function updateGlobalVersion<T extends TypeWithID>(\n this: MongooseAdapter,\n {\n id,\n global: globalSlug,\n locale,\n options: optionsArgs = {},\n req,\n select,\n versionData,\n where,\n }: UpdateGlobalVersionArgs<T>,\n) {\n const VersionModel = this.versions[globalSlug]\n const whereToUse = where || { id: { equals: id } }\n\n const currentGlobal = this.payload.config.globals.find((global) => global.slug === globalSlug)\n const fields = buildVersionGlobalFields(this.payload.config, currentGlobal)\n const flattenedFields = buildVersionGlobalFields(this.payload.config, currentGlobal, true)\n const options: QueryOptions = {\n ...optionsArgs,\n lean: true,\n new: true,\n projection: buildProjectionFromSelect({\n adapter: this,\n fields: flattenedFields,\n select,\n }),\n session: await getSession(this, req),\n }\n\n const query = await buildQuery({\n adapter: this,\n fields: flattenedFields,\n locale,\n where: whereToUse,\n })\n\n transform({ adapter: this, data: versionData, fields, operation: 'write' })\n\n const doc = await VersionModel.findOneAndUpdate(query, versionData, options)\n\n if (!doc) {\n return null\n }\n\n transform({ adapter: this, data: doc, fields, operation: 'read' })\n\n return doc\n}\n"],"names":["buildVersionGlobalFields","buildQuery","buildProjectionFromSelect","getSession","transform","updateGlobalVersion","id","global","globalSlug","locale","options","optionsArgs","req","select","versionData","where","VersionModel","versions","whereToUse","equals","currentGlobal","payload","config","globals","find","slug","fields","flattenedFields","lean","new","projection","adapter","session","query","data","operation","doc","findOneAndUpdate"],"mappings":"AAEA,SAASA,wBAAwB,QAAuD,UAAS;AAIjG,SAASC,UAAU,QAAQ,0BAAyB;AACpD,SAASC,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAASC,SAAS,QAAQ,2BAA0B;AAEpD,OAAO,eAAeC,oBAEpB,EACEC,EAAE,EACFC,QAAQC,UAAU,EAClBC,MAAM,EACNC,SAASC,cAAc,CAAC,CAAC,EACzBC,GAAG,EACHC,MAAM,EACNC,WAAW,EACXC,KAAK,EACsB;IAE7B,MAAMC,eAAe,IAAI,CAACC,QAAQ,CAACT,WAAW;IAC9C,MAAMU,aAAaH,SAAS;QAAET,IAAI;YAAEa,QAAQb;QAAG;IAAE;IAEjD,MAAMc,gBAAgB,IAAI,CAACC,OAAO,CAACC,MAAM,CAACC,OAAO,CAACC,IAAI,CAAC,CAACjB,SAAWA,OAAOkB,IAAI,KAAKjB;IACnF,MAAMkB,SAAS1B,yBAAyB,IAAI,CAACqB,OAAO,CAACC,MAAM,EAAEF;IAC7D,MAAMO,kBAAkB3B,yBAAyB,IAAI,CAACqB,OAAO,CAACC,MAAM,EAAEF,eAAe;IACrF,MAAMV,UAAwB;QAC5B,GAAGC,WAAW;QACdiB,MAAM;QACNC,KAAK;QACLC,YAAY5B,0BAA0B;YACpC6B,SAAS,IAAI;YACbL,QAAQC;YACRd;QACF;QACAmB,SAAS,MAAM7B,WAAW,IAAI,EAAES;IAClC;IAEA,MAAMqB,QAAQ,MAAMhC,WAAW;QAC7B8B,SAAS,IAAI;QACbL,QAAQC;QACRlB;QACAM,OAAOG;IACT;IAEAd,UAAU;QAAE2B,SAAS,IAAI;QAAEG,MAAMpB;QAAaY;QAAQS,WAAW;IAAQ;IAEzE,MAAMC,MAAM,MAAMpB,aAAaqB,gBAAgB,CAACJ,OAAOnB,aAAaJ;IAEpE,IAAI,CAAC0B,KAAK;QACR,OAAO;IACT;IAEAhC,UAAU;QAAE2B,SAAS,IAAI;QAAEG,MAAME;QAAKV;QAAQS,WAAW;IAAO;IAEhE,OAAOC;AACT"}
|
package/dist/updateOne.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import { buildQuery } from './queries/buildQuery.js';
|
|
1
2
|
import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js';
|
|
2
3
|
import { getSession } from './utilities/getSession.js';
|
|
3
4
|
import { handleError } from './utilities/handleError.js';
|
|
4
|
-
import {
|
|
5
|
-
import { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.js';
|
|
5
|
+
import { transform } from './utilities/transform.js';
|
|
6
6
|
export const updateOne = async function updateOne({ id, collection, data, locale, options: optionsArgs = {}, req, select, where: whereArg }) {
|
|
7
7
|
const where = id ? {
|
|
8
8
|
id: {
|
|
@@ -22,19 +22,22 @@ export const updateOne = async function updateOne({ id, collection, data, locale
|
|
|
22
22
|
}),
|
|
23
23
|
session: await getSession(this, req)
|
|
24
24
|
};
|
|
25
|
-
const query = await
|
|
25
|
+
const query = await buildQuery({
|
|
26
|
+
adapter: this,
|
|
27
|
+
collectionSlug: collection,
|
|
28
|
+
fields: this.payload.collections[collection].config.flattenedFields,
|
|
26
29
|
locale,
|
|
27
|
-
payload: this.payload,
|
|
28
30
|
where
|
|
29
31
|
});
|
|
30
32
|
let result;
|
|
31
|
-
|
|
32
|
-
|
|
33
|
+
transform({
|
|
34
|
+
adapter: this,
|
|
33
35
|
data,
|
|
34
|
-
fields
|
|
36
|
+
fields,
|
|
37
|
+
operation: 'write'
|
|
35
38
|
});
|
|
36
39
|
try {
|
|
37
|
-
result = await Model.findOneAndUpdate(query,
|
|
40
|
+
result = await Model.findOneAndUpdate(query, data, options);
|
|
38
41
|
} catch (error) {
|
|
39
42
|
handleError({
|
|
40
43
|
collection,
|
|
@@ -42,9 +45,15 @@ export const updateOne = async function updateOne({ id, collection, data, locale
|
|
|
42
45
|
req
|
|
43
46
|
});
|
|
44
47
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
+
if (!result) {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
transform({
|
|
52
|
+
adapter: this,
|
|
53
|
+
data: result,
|
|
54
|
+
fields,
|
|
55
|
+
operation: 'read'
|
|
56
|
+
});
|
|
48
57
|
return result;
|
|
49
58
|
};
|
|
50
59
|
|
package/dist/updateOne.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/updateOne.ts"],"sourcesContent":["import type { QueryOptions } from 'mongoose'\nimport type { UpdateOne } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport {
|
|
1
|
+
{"version":3,"sources":["../src/updateOne.ts"],"sourcesContent":["import type { QueryOptions } from 'mongoose'\nimport type { UpdateOne } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getSession } from './utilities/getSession.js'\nimport { handleError } from './utilities/handleError.js'\nimport { transform } from './utilities/transform.js'\n\nexport const updateOne: UpdateOne = async function updateOne(\n this: MongooseAdapter,\n { id, collection, data, locale, options: optionsArgs = {}, req, select, where: whereArg },\n) {\n const where = id ? { id: { equals: id } } : whereArg\n const Model = this.collections[collection]\n const fields = this.payload.collections[collection].config.fields\n const options: QueryOptions = {\n ...optionsArgs,\n lean: true,\n new: true,\n projection: buildProjectionFromSelect({\n adapter: this,\n fields: this.payload.collections[collection].config.flattenedFields,\n select,\n }),\n session: await getSession(this, req),\n }\n\n const query = await buildQuery({\n adapter: this,\n collectionSlug: collection,\n fields: this.payload.collections[collection].config.flattenedFields,\n locale,\n where,\n })\n\n let result\n\n transform({ adapter: this, data, fields, operation: 'write' })\n\n try {\n result = await Model.findOneAndUpdate(query, data, options)\n } catch (error) {\n handleError({ collection, error, req })\n }\n\n if (!result) {\n return null\n }\n\n transform({ adapter: this, data: result, fields, operation: 'read' })\n\n return result\n}\n"],"names":["buildQuery","buildProjectionFromSelect","getSession","handleError","transform","updateOne","id","collection","data","locale","options","optionsArgs","req","select","where","whereArg","equals","Model","collections","fields","payload","config","lean","new","projection","adapter","flattenedFields","session","query","collectionSlug","result","operation","findOneAndUpdate","error"],"mappings":"AAKA,SAASA,UAAU,QAAQ,0BAAyB;AACpD,SAASC,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAASC,WAAW,QAAQ,6BAA4B;AACxD,SAASC,SAAS,QAAQ,2BAA0B;AAEpD,OAAO,MAAMC,YAAuB,eAAeA,UAEjD,EAAEC,EAAE,EAAEC,UAAU,EAAEC,IAAI,EAAEC,MAAM,EAAEC,SAASC,cAAc,CAAC,CAAC,EAAEC,GAAG,EAAEC,MAAM,EAAEC,OAAOC,QAAQ,EAAE;IAEzF,MAAMD,QAAQR,KAAK;QAAEA,IAAI;YAAEU,QAAQV;QAAG;IAAE,IAAIS;IAC5C,MAAME,QAAQ,IAAI,CAACC,WAAW,CAACX,WAAW;IAC1C,MAAMY,SAAS,IAAI,CAACC,OAAO,CAACF,WAAW,CAACX,WAAW,CAACc,MAAM,CAACF,MAAM;IACjE,MAAMT,UAAwB;QAC5B,GAAGC,WAAW;QACdW,MAAM;QACNC,KAAK;QACLC,YAAYvB,0BAA0B;YACpCwB,SAAS,IAAI;YACbN,QAAQ,IAAI,CAACC,OAAO,CAACF,WAAW,CAACX,WAAW,CAACc,MAAM,CAACK,eAAe;YACnEb;QACF;QACAc,SAAS,MAAMzB,WAAW,IAAI,EAAEU;IAClC;IAEA,MAAMgB,QAAQ,MAAM5B,WAAW;QAC7ByB,SAAS,IAAI;QACbI,gBAAgBtB;QAChBY,QAAQ,IAAI,CAACC,OAAO,CAACF,WAAW,CAACX,WAAW,CAACc,MAAM,CAACK,eAAe;QACnEjB;QACAK;IACF;IAEA,IAAIgB;IAEJ1B,UAAU;QAAEqB,SAAS,IAAI;QAAEjB;QAAMW;QAAQY,WAAW;IAAQ;IAE5D,IAAI;QACFD,SAAS,MAAMb,MAAMe,gBAAgB,CAACJ,OAAOpB,MAAME;IACrD,EAAE,OAAOuB,OAAO;QACd9B,YAAY;YAAEI;YAAY0B;YAAOrB;QAAI;IACvC;IAEA,IAAI,CAACkB,QAAQ;QACX,OAAO;IACT;IAEA1B,UAAU;QAAEqB,SAAS,IAAI;QAAEjB,MAAMsB;QAAQX;QAAQY,WAAW;IAAO;IAEnE,OAAOD;AACT,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"updateVersion.d.ts","sourceRoot":"","sources":["../src/updateVersion.ts"],"names":[],"mappings":"AAEA,OAAO,EAAgC,KAAK,aAAa,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"updateVersion.d.ts","sourceRoot":"","sources":["../src/updateVersion.ts"],"names":[],"mappings":"AAEA,OAAO,EAAgC,KAAK,aAAa,EAAE,MAAM,SAAS,CAAA;AAS1E,eAAO,MAAM,aAAa,EAAE,aA+C3B,CAAA"}
|
package/dist/updateVersion.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { buildVersionCollectionFields } from 'payload';
|
|
2
|
+
import { buildQuery } from './queries/buildQuery.js';
|
|
2
3
|
import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js';
|
|
3
4
|
import { getSession } from './utilities/getSession.js';
|
|
4
|
-
import {
|
|
5
|
+
import { transform } from './utilities/transform.js';
|
|
5
6
|
export const updateVersion = async function updateVersion({ id, collection, locale, options: optionsArgs = {}, req, select, versionData, where }) {
|
|
6
7
|
const VersionModel = this.versions[collection];
|
|
7
8
|
const whereToUse = where || {
|
|
@@ -10,36 +11,41 @@ export const updateVersion = async function updateVersion({ id, collection, loca
|
|
|
10
11
|
}
|
|
11
12
|
};
|
|
12
13
|
const fields = buildVersionCollectionFields(this.payload.config, this.payload.collections[collection].config);
|
|
14
|
+
const flattenedFields = buildVersionCollectionFields(this.payload.config, this.payload.collections[collection].config, true);
|
|
13
15
|
const options = {
|
|
14
16
|
...optionsArgs,
|
|
15
17
|
lean: true,
|
|
16
18
|
new: true,
|
|
17
19
|
projection: buildProjectionFromSelect({
|
|
18
20
|
adapter: this,
|
|
19
|
-
fields:
|
|
21
|
+
fields: flattenedFields,
|
|
20
22
|
select
|
|
21
23
|
}),
|
|
22
24
|
session: await getSession(this, req)
|
|
23
25
|
};
|
|
24
|
-
const query = await
|
|
26
|
+
const query = await buildQuery({
|
|
27
|
+
adapter: this,
|
|
28
|
+
fields: flattenedFields,
|
|
25
29
|
locale,
|
|
26
|
-
payload: this.payload,
|
|
27
30
|
where: whereToUse
|
|
28
31
|
});
|
|
29
|
-
|
|
30
|
-
|
|
32
|
+
transform({
|
|
33
|
+
adapter: this,
|
|
31
34
|
data: versionData,
|
|
32
|
-
fields
|
|
35
|
+
fields,
|
|
36
|
+
operation: 'write'
|
|
33
37
|
});
|
|
34
|
-
const doc = await VersionModel.findOneAndUpdate(query,
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
// custom id type reset
|
|
38
|
-
result.id = result._id;
|
|
39
|
-
if (verificationToken) {
|
|
40
|
-
result._verificationToken = verificationToken;
|
|
38
|
+
const doc = await VersionModel.findOneAndUpdate(query, versionData, options);
|
|
39
|
+
if (!doc) {
|
|
40
|
+
return null;
|
|
41
41
|
}
|
|
42
|
-
|
|
42
|
+
transform({
|
|
43
|
+
adapter: this,
|
|
44
|
+
data: doc,
|
|
45
|
+
fields,
|
|
46
|
+
operation: 'write'
|
|
47
|
+
});
|
|
48
|
+
return doc;
|
|
43
49
|
};
|
|
44
50
|
|
|
45
51
|
//# sourceMappingURL=updateVersion.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/updateVersion.ts"],"sourcesContent":["import type { QueryOptions } from 'mongoose'\n\nimport { buildVersionCollectionFields, type UpdateVersion } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getSession } from './utilities/getSession.js'\nimport {
|
|
1
|
+
{"version":3,"sources":["../src/updateVersion.ts"],"sourcesContent":["import type { QueryOptions } from 'mongoose'\n\nimport { buildVersionCollectionFields, type UpdateVersion } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getSession } from './utilities/getSession.js'\nimport { transform } from './utilities/transform.js'\n\nexport const updateVersion: UpdateVersion = async function updateVersion(\n this: MongooseAdapter,\n { id, collection, locale, options: optionsArgs = {}, req, select, versionData, where },\n) {\n const VersionModel = this.versions[collection]\n const whereToUse = where || { id: { equals: id } }\n const fields = buildVersionCollectionFields(\n this.payload.config,\n this.payload.collections[collection].config,\n )\n\n const flattenedFields = buildVersionCollectionFields(\n this.payload.config,\n this.payload.collections[collection].config,\n true,\n )\n\n const options: QueryOptions = {\n ...optionsArgs,\n lean: true,\n new: true,\n projection: buildProjectionFromSelect({\n adapter: this,\n fields: flattenedFields,\n select,\n }),\n session: await getSession(this, req),\n }\n\n const query = await buildQuery({\n adapter: this,\n fields: flattenedFields,\n locale,\n where: whereToUse,\n })\n\n transform({ adapter: this, data: versionData, fields, operation: 'write' })\n\n const doc = await VersionModel.findOneAndUpdate(query, versionData, options)\n\n if (!doc) {\n return null\n }\n\n transform({ adapter: this, data: doc, fields, operation: 'write' })\n\n return doc\n}\n"],"names":["buildVersionCollectionFields","buildQuery","buildProjectionFromSelect","getSession","transform","updateVersion","id","collection","locale","options","optionsArgs","req","select","versionData","where","VersionModel","versions","whereToUse","equals","fields","payload","config","collections","flattenedFields","lean","new","projection","adapter","session","query","data","operation","doc","findOneAndUpdate"],"mappings":"AAEA,SAASA,4BAA4B,QAA4B,UAAS;AAI1E,SAASC,UAAU,QAAQ,0BAAyB;AACpD,SAASC,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAASC,SAAS,QAAQ,2BAA0B;AAEpD,OAAO,MAAMC,gBAA+B,eAAeA,cAEzD,EAAEC,EAAE,EAAEC,UAAU,EAAEC,MAAM,EAAEC,SAASC,cAAc,CAAC,CAAC,EAAEC,GAAG,EAAEC,MAAM,EAAEC,WAAW,EAAEC,KAAK,EAAE;IAEtF,MAAMC,eAAe,IAAI,CAACC,QAAQ,CAACT,WAAW;IAC9C,MAAMU,aAAaH,SAAS;QAAER,IAAI;YAAEY,QAAQZ;QAAG;IAAE;IACjD,MAAMa,SAASnB,6BACb,IAAI,CAACoB,OAAO,CAACC,MAAM,EACnB,IAAI,CAACD,OAAO,CAACE,WAAW,CAACf,WAAW,CAACc,MAAM;IAG7C,MAAME,kBAAkBvB,6BACtB,IAAI,CAACoB,OAAO,CAACC,MAAM,EACnB,IAAI,CAACD,OAAO,CAACE,WAAW,CAACf,WAAW,CAACc,MAAM,EAC3C;IAGF,MAAMZ,UAAwB;QAC5B,GAAGC,WAAW;QACdc,MAAM;QACNC,KAAK;QACLC,YAAYxB,0BAA0B;YACpCyB,SAAS,IAAI;YACbR,QAAQI;YACRX;QACF;QACAgB,SAAS,MAAMzB,WAAW,IAAI,EAAEQ;IAClC;IAEA,MAAMkB,QAAQ,MAAM5B,WAAW;QAC7B0B,SAAS,IAAI;QACbR,QAAQI;QACRf;QACAM,OAAOG;IACT;IAEAb,UAAU;QAAEuB,SAAS,IAAI;QAAEG,MAAMjB;QAAaM;QAAQY,WAAW;IAAQ;IAEzE,MAAMC,MAAM,MAAMjB,aAAakB,gBAAgB,CAACJ,OAAOhB,aAAaJ;IAEpE,IAAI,CAACuB,KAAK;QACR,OAAO;IACT;IAEA5B,UAAU;QAAEuB,SAAS,IAAI;QAAEG,MAAME;QAAKb;QAAQY,WAAW;IAAQ;IAEjE,OAAOC;AACT,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildJoinAggregation.d.ts","sourceRoot":"","sources":["../../src/utilities/buildJoinAggregation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAC7C,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"buildJoinAggregation.d.ts","sourceRoot":"","sources":["../../src/utilities/buildJoinAggregation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAC7C,OAAO,KAAK,EACV,cAAc,EAEd,SAAS,EACT,yBAAyB,EACzB,KAAK,EACN,MAAM,SAAS,CAAA;AAIhB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAKlD,KAAK,wBAAwB,GAAG;IAC9B,OAAO,EAAE,eAAe,CAAA;IACxB,UAAU,EAAE,cAAc,CAAA;IAC1B,gBAAgB,EAAE,yBAAyB,CAAA;IAC3C,KAAK,EAAE,SAAS,CAAA;IAEhB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,MAAM,CAAA;IACd,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAA;IAEjC,KAAK,CAAC,EAAE,KAAK,CAAA;IACb,uCAAuC;IACvC,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB,CAAA;AAED,eAAO,MAAM,oBAAoB,kGAU9B,wBAAwB,KAAG,OAAO,CAAC,aAAa,EAAE,GAAG,SAAS,CAkVhE,CAAA"}
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
+
import { fieldShouldBeLocalized } from 'payload/shared';
|
|
2
|
+
import { buildQuery } from '../queries/buildQuery.js';
|
|
1
3
|
import { buildSortParam } from '../queries/buildSortParam.js';
|
|
2
4
|
export const buildJoinAggregation = async ({ adapter, collection, collectionConfig, joins, limit, locale, projection, query, versions })=>{
|
|
3
|
-
if (Object.keys(collectionConfig.joins).length === 0 || joins === false) {
|
|
5
|
+
if (Object.keys(collectionConfig.joins).length === 0 && collectionConfig.polymorphicJoins.length == 0 || joins === false) {
|
|
4
6
|
return;
|
|
5
7
|
}
|
|
6
8
|
const joinConfig = adapter.payload.collections[collection].config.joins;
|
|
9
|
+
const polymorphicJoinsConfig = adapter.payload.collections[collection].config.polymorphicJoins;
|
|
7
10
|
const aggregate = [
|
|
8
11
|
{
|
|
9
12
|
$sort: {
|
|
@@ -21,16 +24,156 @@ export const buildJoinAggregation = async ({ adapter, collection, collectionConf
|
|
|
21
24
|
$limit: limit
|
|
22
25
|
});
|
|
23
26
|
}
|
|
27
|
+
for (const join of polymorphicJoinsConfig){
|
|
28
|
+
if (projection && !projection[join.joinPath]) {
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
if (joins?.[join.joinPath] === false) {
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
const { limit: limitJoin = join.field.defaultLimit ?? 10, page, sort: sortJoin = join.field.defaultSort || collectionConfig.defaultSort, where: whereJoin } = joins?.[join.joinPath] || {};
|
|
35
|
+
const aggregatedFields = [];
|
|
36
|
+
for (const collectionSlug of join.field.collection){
|
|
37
|
+
for (const field of adapter.payload.collections[collectionSlug].config.flattenedFields){
|
|
38
|
+
if (!aggregatedFields.some((eachField)=>eachField.name === field.name)) {
|
|
39
|
+
aggregatedFields.push(field);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
const sort = buildSortParam({
|
|
44
|
+
config: adapter.payload.config,
|
|
45
|
+
fields: aggregatedFields,
|
|
46
|
+
locale,
|
|
47
|
+
sort: sortJoin,
|
|
48
|
+
timestamps: true
|
|
49
|
+
});
|
|
50
|
+
const $match = await buildQuery({
|
|
51
|
+
adapter,
|
|
52
|
+
fields: aggregatedFields,
|
|
53
|
+
locale,
|
|
54
|
+
where: whereJoin
|
|
55
|
+
});
|
|
56
|
+
const sortProperty = Object.keys(sort)[0];
|
|
57
|
+
const sortDirection = sort[sortProperty] === 'asc' ? 1 : -1;
|
|
58
|
+
const projectSort = sortProperty !== '_id' && sortProperty !== 'relationTo';
|
|
59
|
+
const aliases = [];
|
|
60
|
+
const as = join.joinPath;
|
|
61
|
+
for (const collectionSlug of join.field.collection){
|
|
62
|
+
const alias = `${as}.docs.${collectionSlug}`;
|
|
63
|
+
aliases.push(alias);
|
|
64
|
+
aggregate.push({
|
|
65
|
+
$lookup: {
|
|
66
|
+
as: alias,
|
|
67
|
+
from: adapter.collections[collectionSlug].collection.name,
|
|
68
|
+
let: {
|
|
69
|
+
root_id_: '$_id'
|
|
70
|
+
},
|
|
71
|
+
pipeline: [
|
|
72
|
+
{
|
|
73
|
+
$addFields: {
|
|
74
|
+
relationTo: {
|
|
75
|
+
$literal: collectionSlug
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
$match: {
|
|
81
|
+
$and: [
|
|
82
|
+
{
|
|
83
|
+
$expr: {
|
|
84
|
+
$eq: [
|
|
85
|
+
`$${join.field.on}`,
|
|
86
|
+
'$$root_id_'
|
|
87
|
+
]
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
$match
|
|
91
|
+
]
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
$sort: {
|
|
96
|
+
[sortProperty]: sortDirection
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
// Unfortunately, we can't use $skip here because we can lose data, instead we do $slice then
|
|
101
|
+
$limit: page ? page * limitJoin : limitJoin
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
$project: {
|
|
105
|
+
value: '$_id',
|
|
106
|
+
...projectSort && {
|
|
107
|
+
[sortProperty]: 1
|
|
108
|
+
},
|
|
109
|
+
relationTo: 1
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
]
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
aggregate.push({
|
|
117
|
+
$addFields: {
|
|
118
|
+
[`${as}.docs`]: {
|
|
119
|
+
$concatArrays: aliases.map((alias)=>`$${alias}`)
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
aggregate.push({
|
|
124
|
+
$set: {
|
|
125
|
+
[`${as}.docs`]: {
|
|
126
|
+
$sortArray: {
|
|
127
|
+
input: `$${as}.docs`,
|
|
128
|
+
sortBy: {
|
|
129
|
+
[sortProperty]: sortDirection
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
const sliceValue = page ? [
|
|
136
|
+
(page - 1) * limitJoin,
|
|
137
|
+
limitJoin
|
|
138
|
+
] : [
|
|
139
|
+
limitJoin
|
|
140
|
+
];
|
|
141
|
+
aggregate.push({
|
|
142
|
+
$set: {
|
|
143
|
+
[`${as}.docs`]: {
|
|
144
|
+
$slice: [
|
|
145
|
+
`$${as}.docs`,
|
|
146
|
+
...sliceValue
|
|
147
|
+
]
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
aggregate.push({
|
|
152
|
+
$addFields: {
|
|
153
|
+
[`${as}.hasNextPage`]: {
|
|
154
|
+
$gt: [
|
|
155
|
+
{
|
|
156
|
+
$size: `$${as}.docs`
|
|
157
|
+
},
|
|
158
|
+
limitJoin || Number.MAX_VALUE
|
|
159
|
+
]
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
}
|
|
24
164
|
for (const slug of Object.keys(joinConfig)){
|
|
25
165
|
for (const join of joinConfig[slug]){
|
|
26
|
-
const joinModel = adapter.collections[join.field.collection];
|
|
27
166
|
if (projection && !projection[join.joinPath]) {
|
|
28
167
|
continue;
|
|
29
168
|
}
|
|
30
169
|
if (joins?.[join.joinPath] === false) {
|
|
31
170
|
continue;
|
|
32
171
|
}
|
|
33
|
-
const { limit: limitJoin = join.field.defaultLimit ?? 10, sort: sortJoin = join.field.defaultSort || collectionConfig.defaultSort, where: whereJoin } = joins?.[join.joinPath] || {};
|
|
172
|
+
const { limit: limitJoin = join.field.defaultLimit ?? 10, page, sort: sortJoin = join.field.defaultSort || collectionConfig.defaultSort, where: whereJoin } = joins?.[join.joinPath] || {};
|
|
173
|
+
if (Array.isArray(join.field.collection)) {
|
|
174
|
+
throw new Error('Unreachable');
|
|
175
|
+
}
|
|
176
|
+
const joinModel = adapter.collections[join.field.collection];
|
|
34
177
|
const sort = buildSortParam({
|
|
35
178
|
config: adapter.payload.config,
|
|
36
179
|
fields: adapter.payload.collections[slug].config.flattenedFields,
|
|
@@ -55,6 +198,11 @@ export const buildJoinAggregation = async ({ adapter, collection, collectionConf
|
|
|
55
198
|
}
|
|
56
199
|
}
|
|
57
200
|
];
|
|
201
|
+
if (page) {
|
|
202
|
+
pipeline.push({
|
|
203
|
+
$skip: (page - 1) * limitJoin
|
|
204
|
+
});
|
|
205
|
+
}
|
|
58
206
|
if (limitJoin > 0) {
|
|
59
207
|
pipeline.push({
|
|
60
208
|
$limit: limitJoin + 1
|
|
@@ -108,7 +256,10 @@ export const buildJoinAggregation = async ({ adapter, collection, collectionConf
|
|
|
108
256
|
}
|
|
109
257
|
});
|
|
110
258
|
} else {
|
|
111
|
-
const localeSuffix =
|
|
259
|
+
const localeSuffix = fieldShouldBeLocalized({
|
|
260
|
+
field: join.field,
|
|
261
|
+
parentIsLocalized: join.parentIsLocalized
|
|
262
|
+
}) && adapter.payload.config.localization && locale ? `.${locale}` : '';
|
|
112
263
|
const as = `${versions ? `version.${join.joinPath}` : join.joinPath}${localeSuffix}`;
|
|
113
264
|
let foreignField;
|
|
114
265
|
if (join.getForeignPath) {
|