@payloadcms/db-mongodb 3.0.0-canary.f6e77b8 → 3.0.0-canary.fb04843
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +1 -1
- package/dist/connect.d.ts +1 -1
- package/dist/connect.d.ts.map +1 -1
- package/dist/connect.js +18 -4
- package/dist/connect.js.map +1 -1
- package/dist/count.d.ts +1 -1
- package/dist/count.d.ts.map +1 -1
- package/dist/count.js +10 -3
- package/dist/count.js.map +1 -1
- package/dist/countGlobalVersions.d.ts +3 -0
- package/dist/countGlobalVersions.d.ts.map +1 -0
- package/dist/countGlobalVersions.js +40 -0
- package/dist/countGlobalVersions.js.map +1 -0
- package/dist/countVersions.d.ts +3 -0
- package/dist/countVersions.d.ts.map +1 -0
- package/dist/countVersions.js +40 -0
- package/dist/countVersions.js.map +1 -0
- package/dist/create.d.ts +1 -1
- package/dist/create.d.ts.map +1 -1
- package/dist/create.js +17 -4
- package/dist/create.js.map +1 -1
- package/dist/createGlobal.d.ts +1 -1
- package/dist/createGlobal.d.ts.map +1 -1
- package/dist/createGlobal.js +11 -6
- package/dist/createGlobal.js.map +1 -1
- package/dist/createGlobalVersion.d.ts +1 -1
- package/dist/createGlobalVersion.d.ts.map +1 -1
- package/dist/createGlobalVersion.js +14 -5
- package/dist/createGlobalVersion.js.map +1 -1
- package/dist/createMigration.d.ts +1 -1
- package/dist/createMigration.d.ts.map +1 -1
- package/dist/createMigration.js +20 -32
- package/dist/createMigration.js.map +1 -1
- package/dist/createVersion.d.ts +1 -1
- package/dist/createVersion.d.ts.map +1 -1
- package/dist/createVersion.js +32 -10
- package/dist/createVersion.js.map +1 -1
- package/dist/deleteMany.d.ts +1 -1
- package/dist/deleteMany.d.ts.map +1 -1
- package/dist/deleteMany.js +1 -1
- package/dist/deleteMany.js.map +1 -1
- package/dist/deleteOne.d.ts +1 -1
- package/dist/deleteOne.d.ts.map +1 -1
- package/dist/deleteOne.js +12 -4
- 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 +1 -1
- package/dist/deleteVersions.js.map +1 -1
- package/dist/destroy.d.ts +1 -1
- package/dist/destroy.d.ts.map +1 -1
- package/dist/destroy.js.map +1 -1
- package/dist/exports/migration-utils.d.ts +3 -0
- package/dist/exports/migration-utils.d.ts.map +1 -0
- package/dist/exports/migration-utils.js +4 -0
- package/dist/exports/migration-utils.js.map +1 -0
- package/dist/find.d.ts +1 -1
- package/dist/find.d.ts.map +1 -1
- package/dist/find.js +36 -7
- package/dist/find.js.map +1 -1
- package/dist/findGlobal.d.ts +1 -1
- package/dist/findGlobal.d.ts.map +1 -1
- package/dist/findGlobal.js +11 -5
- package/dist/findGlobal.js.map +1 -1
- package/dist/findGlobalVersions.d.ts +1 -1
- package/dist/findGlobalVersions.d.ts.map +1 -1
- package/dist/findGlobalVersions.js +19 -9
- package/dist/findGlobalVersions.js.map +1 -1
- package/dist/findOne.d.ts +1 -1
- package/dist/findOne.d.ts.map +1 -1
- package/dist/findOne.js +28 -4
- package/dist/findOne.js.map +1 -1
- package/dist/findVersions.d.ts +1 -1
- package/dist/findVersions.d.ts.map +1 -1
- package/dist/findVersions.js +17 -6
- package/dist/findVersions.js.map +1 -1
- package/dist/index.d.ts +59 -35
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +18 -7
- package/dist/index.js.map +1 -1
- package/dist/init.d.ts +1 -1
- package/dist/init.d.ts.map +1 -1
- package/dist/init.js +19 -17
- package/dist/init.js.map +1 -1
- package/dist/migrateFresh.d.ts.map +1 -1
- package/dist/migrateFresh.js +1 -1
- package/dist/migrateFresh.js.map +1 -1
- package/dist/models/buildCollectionSchema.d.ts +2 -29
- package/dist/models/buildCollectionSchema.d.ts.map +1 -1
- package/dist/models/buildCollectionSchema.js +16 -4
- package/dist/models/buildCollectionSchema.js.map +1 -1
- package/dist/models/buildGlobalModel.d.ts +1 -1
- package/dist/models/buildGlobalModel.d.ts.map +1 -1
- package/dist/models/buildGlobalModel.js +2 -2
- package/dist/models/buildGlobalModel.js.map +1 -1
- package/dist/models/buildSchema.d.ts +2 -29
- package/dist/models/buildSchema.d.ts.map +1 -1
- package/dist/models/buildSchema.js +116 -23
- package/dist/models/buildSchema.js.map +1 -1
- package/dist/predefinedMigrations/migrateRelationshipsV2_V3.d.ts +6 -0
- package/dist/predefinedMigrations/migrateRelationshipsV2_V3.d.ts.map +1 -0
- package/dist/predefinedMigrations/migrateRelationshipsV2_V3.js +141 -0
- package/dist/predefinedMigrations/migrateRelationshipsV2_V3.js.map +1 -0
- package/dist/predefinedMigrations/migrateVersionsV1_V2.d.ts +5 -0
- package/dist/predefinedMigrations/migrateVersionsV1_V2.d.ts.map +1 -0
- package/dist/predefinedMigrations/migrateVersionsV1_V2.js +107 -0
- package/dist/predefinedMigrations/migrateVersionsV1_V2.js.map +1 -0
- package/dist/predefinedMigrations/relationships-v2-v3.d.ts +4 -0
- package/dist/predefinedMigrations/relationships-v2-v3.d.ts.map +1 -0
- package/dist/predefinedMigrations/relationships-v2-v3.js +9 -0
- package/dist/predefinedMigrations/relationships-v2-v3.js.map +1 -0
- package/dist/predefinedMigrations/versions-v1-v2.d.ts +4 -0
- package/dist/predefinedMigrations/versions-v1-v2.d.ts.map +1 -0
- package/dist/predefinedMigrations/versions-v1-v2.js +8 -0
- package/dist/predefinedMigrations/versions-v1-v2.js.map +1 -0
- package/dist/queries/buildAndOrConditions.d.ts +1 -2
- package/dist/queries/buildAndOrConditions.d.ts.map +1 -1
- package/dist/queries/buildAndOrConditions.js +0 -2
- package/dist/queries/buildAndOrConditions.js.map +1 -1
- package/dist/queries/buildQuery.d.ts +3 -4
- package/dist/queries/buildQuery.d.ts.map +1 -1
- package/dist/queries/buildQuery.js +2 -3
- package/dist/queries/buildQuery.js.map +1 -1
- package/dist/queries/buildSearchParams.d.ts +1 -2
- package/dist/queries/buildSearchParams.d.ts.map +1 -1
- package/dist/queries/buildSearchParams.js +34 -22
- package/dist/queries/buildSearchParams.js.map +1 -1
- package/dist/queries/buildSortParam.d.ts +3 -29
- package/dist/queries/buildSortParam.d.ts.map +1 -1
- package/dist/queries/buildSortParam.js +26 -17
- package/dist/queries/buildSortParam.js.map +1 -1
- package/dist/queries/getLocalizedSortProperty.d.ts +1 -2
- package/dist/queries/getLocalizedSortProperty.d.ts.map +1 -1
- package/dist/queries/getLocalizedSortProperty.js +2 -2
- package/dist/queries/getLocalizedSortProperty.js.map +1 -1
- package/dist/queries/getLocalizedSortProperty.spec.js +44 -44
- package/dist/queries/getLocalizedSortProperty.spec.js.map +1 -1
- package/dist/queries/mock.js.map +1 -1
- package/dist/queries/operatorMap.js.map +1 -1
- package/dist/queries/parseParams.d.ts +1 -3
- package/dist/queries/parseParams.d.ts.map +1 -1
- package/dist/queries/parseParams.js +8 -6
- package/dist/queries/parseParams.js.map +1 -1
- package/dist/queries/sanitizeQueryValue.d.ts +1 -1
- package/dist/queries/sanitizeQueryValue.d.ts.map +1 -1
- package/dist/queries/sanitizeQueryValue.js +145 -28
- package/dist/queries/sanitizeQueryValue.js.map +1 -1
- package/dist/queryDrafts.d.ts +1 -1
- package/dist/queryDrafts.d.ts.map +1 -1
- package/dist/queryDrafts.js +37 -10
- package/dist/queryDrafts.js.map +1 -1
- package/dist/testCredentials.js.map +1 -1
- package/dist/transactions/beginTransaction.d.ts +1 -1
- package/dist/transactions/beginTransaction.d.ts.map +1 -1
- package/dist/transactions/beginTransaction.js +3 -1
- package/dist/transactions/beginTransaction.js.map +1 -1
- package/dist/transactions/commitTransaction.d.ts +1 -1
- package/dist/transactions/commitTransaction.d.ts.map +1 -1
- package/dist/transactions/commitTransaction.js +3 -0
- package/dist/transactions/commitTransaction.js.map +1 -1
- package/dist/transactions/rollbackTransaction.d.ts +1 -1
- package/dist/transactions/rollbackTransaction.d.ts.map +1 -1
- package/dist/transactions/rollbackTransaction.js +13 -7
- package/dist/transactions/rollbackTransaction.js.map +1 -1
- package/dist/types.d.ts +7 -31
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/updateGlobal.d.ts +1 -1
- package/dist/updateGlobal.d.ts.map +1 -1
- package/dist/updateGlobal.js +18 -5
- package/dist/updateGlobal.js.map +1 -1
- package/dist/updateGlobalVersion.d.ts +2 -3
- package/dist/updateGlobalVersion.d.ts.map +1 -1
- package/dist/updateGlobalVersion.js +19 -5
- package/dist/updateGlobalVersion.js.map +1 -1
- package/dist/updateOne.d.ts +1 -1
- package/dist/updateOne.d.ts.map +1 -1
- package/dist/updateOne.js +25 -7
- package/dist/updateOne.js.map +1 -1
- package/dist/updateVersion.d.ts +1 -1
- package/dist/updateVersion.d.ts.map +1 -1
- package/dist/updateVersion.js +18 -4
- package/dist/updateVersion.js.map +1 -1
- package/dist/upsert.d.ts +3 -0
- package/dist/upsert.d.ts.map +1 -0
- package/dist/upsert.js +15 -0
- package/dist/upsert.js.map +1 -0
- package/dist/utilities/buildJoinAggregation.d.ts +18 -0
- package/dist/utilities/buildJoinAggregation.d.ts.map +1 -0
- package/dist/utilities/buildJoinAggregation.js +159 -0
- package/dist/utilities/buildJoinAggregation.js.map +1 -0
- package/dist/utilities/buildProjectionFromSelect.d.ts +8 -0
- package/dist/utilities/buildProjectionFromSelect.d.ts.map +1 -0
- package/dist/utilities/buildProjectionFromSelect.js +171 -0
- package/dist/utilities/buildProjectionFromSelect.js.map +1 -0
- package/dist/utilities/getDBName.d.ts +1 -1
- package/dist/utilities/getDBName.d.ts.map +1 -1
- package/dist/utilities/getDBName.js +3 -1
- package/dist/utilities/getDBName.js.map +1 -1
- package/dist/utilities/handleError.d.ts +6 -2
- package/dist/utilities/handleError.d.ts.map +1 -1
- package/dist/utilities/handleError.js +12 -9
- package/dist/utilities/handleError.js.map +1 -1
- package/dist/utilities/sanitizeInternalFields.d.ts +1 -2
- package/dist/utilities/sanitizeInternalFields.d.ts.map +1 -1
- package/dist/utilities/sanitizeInternalFields.js +1 -2
- package/dist/utilities/sanitizeInternalFields.js.map +1 -1
- package/dist/utilities/sanitizeRelationshipIDs.d.ts +9 -0
- package/dist/utilities/sanitizeRelationshipIDs.d.ts.map +1 -0
- package/dist/utilities/sanitizeRelationshipIDs.js +115 -0
- package/dist/utilities/sanitizeRelationshipIDs.js.map +1 -0
- package/dist/utilities/sanitizeRelationshipIDs.spec.js +383 -0
- package/dist/utilities/sanitizeRelationshipIDs.spec.js.map +1 -0
- package/dist/withSession.d.ts +3 -27
- package/dist/withSession.d.ts.map +1 -1
- package/dist/withSession.js +10 -4
- package/dist/withSession.js.map +1 -1
- package/license.md +22 -0
- package/package.json +29 -17
- package/predefinedMigrations/versions-v1-v2.js +0 -96
package/dist/types.d.ts
CHANGED
@@ -1,34 +1,7 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
/// <reference types="mongoose/types/collection.js" />
|
4
|
-
/// <reference types="mongoose/types/connection.js" />
|
5
|
-
/// <reference types="mongoose/types/cursor.js" />
|
6
|
-
/// <reference types="mongoose/types/document.js" />
|
7
|
-
/// <reference types="mongoose/types/error.js" />
|
8
|
-
/// <reference types="mongoose/types/expressions.js" />
|
9
|
-
/// <reference types="mongoose/types/helpers.js" />
|
10
|
-
/// <reference types="mongoose/types/middlewares.js" />
|
11
|
-
/// <reference types="mongoose/types/indexes.js" />
|
12
|
-
/// <reference types="mongoose/types/models.js" />
|
13
|
-
/// <reference types="mongoose/types/mongooseoptions.js" />
|
14
|
-
/// <reference types="mongoose/types/pipelinestage.js" />
|
15
|
-
/// <reference types="mongoose/types/populate.js" />
|
16
|
-
/// <reference types="mongoose/types/query.js" />
|
17
|
-
/// <reference types="mongoose/types/schemaoptions.js" />
|
18
|
-
/// <reference types="mongoose/types/schematypes.js" />
|
19
|
-
/// <reference types="mongoose/types/session.js" />
|
20
|
-
/// <reference types="mongoose/types/types.js" />
|
21
|
-
/// <reference types="mongoose/types/utility.js" />
|
22
|
-
/// <reference types="mongoose/types/validation.js" />
|
23
|
-
/// <reference types="mongoose/types/virtuals.js" />
|
24
|
-
/// <reference types="mongoose/types/inferschematype.js" />
|
25
|
-
/// <reference types="mongoose-paginate-v2" />
|
26
|
-
import type { IndexDefinition, IndexOptions, Model, PaginateModel, SchemaOptions } from 'mongoose';
|
27
|
-
import type { Payload } from 'payload';
|
28
|
-
import type { SanitizedConfig } from 'payload/config';
|
29
|
-
import type { ArrayField, BlockField, CheckboxField, CodeField, CollapsibleField, DateField, EmailField, Field, GroupField, JSONField, NumberField, PointField, RadioField, RelationshipField, RichTextField, RowField, SelectField, TabsField, TextField, TextareaField, UploadField } from 'payload/types';
|
1
|
+
import type { AggregatePaginateModel, IndexDefinition, IndexOptions, Model, PaginateModel, SchemaOptions } from 'mongoose';
|
2
|
+
import type { ArrayField, BlocksField, CheckboxField, CodeField, CollapsibleField, DateField, EmailField, Field, GroupField, JoinField, JSONField, NumberField, Payload, PayloadRequest, PointField, RadioField, RelationshipField, RichTextField, RowField, SanitizedConfig, SelectField, TabsField, TextareaField, TextField, UploadField } from 'payload';
|
30
3
|
import type { BuildQueryArgs } from './queries/buildQuery.js';
|
31
|
-
export interface CollectionModel extends Model<any>, PaginateModel<any> {
|
4
|
+
export interface CollectionModel extends Model<any>, PaginateModel<any>, AggregatePaginateModel<any> {
|
32
5
|
/** buildQuery is used to transform payload's where operator into what can be used by mongoose (e.g. id => _id) */
|
33
6
|
buildQuery: (args: BuildQueryArgs) => Promise<Record<string, unknown>>;
|
34
7
|
}
|
@@ -67,13 +40,14 @@ export type FieldGeneratorFunction<TSchema, TField extends Field> = (args: Field
|
|
67
40
|
*/
|
68
41
|
export type FieldToSchemaMap<TSchema> = {
|
69
42
|
array: FieldGeneratorFunction<TSchema, ArrayField>;
|
70
|
-
blocks: FieldGeneratorFunction<TSchema,
|
43
|
+
blocks: FieldGeneratorFunction<TSchema, BlocksField>;
|
71
44
|
checkbox: FieldGeneratorFunction<TSchema, CheckboxField>;
|
72
45
|
code: FieldGeneratorFunction<TSchema, CodeField>;
|
73
46
|
collapsible: FieldGeneratorFunction<TSchema, CollapsibleField>;
|
74
47
|
date: FieldGeneratorFunction<TSchema, DateField>;
|
75
48
|
email: FieldGeneratorFunction<TSchema, EmailField>;
|
76
49
|
group: FieldGeneratorFunction<TSchema, GroupField>;
|
50
|
+
join: FieldGeneratorFunction<TSchema, JoinField>;
|
77
51
|
json: FieldGeneratorFunction<TSchema, JSONField>;
|
78
52
|
number: FieldGeneratorFunction<TSchema, NumberField>;
|
79
53
|
point: FieldGeneratorFunction<TSchema, PointField>;
|
@@ -89,8 +63,10 @@ export type FieldToSchemaMap<TSchema> = {
|
|
89
63
|
};
|
90
64
|
export type MigrateUpArgs = {
|
91
65
|
payload: Payload;
|
66
|
+
req: PayloadRequest;
|
92
67
|
};
|
93
68
|
export type MigrateDownArgs = {
|
94
69
|
payload: Payload;
|
70
|
+
req: PayloadRequest;
|
95
71
|
};
|
96
72
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"
|
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 {
|
1
|
+
{"version":3,"sources":["../src/types.ts"],"sourcesContent":["import 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/buildQuery.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 = { payload: Payload; req: PayloadRequest }\nexport type MigrateDownArgs = { payload: Payload; req: PayloadRequest }\n"],"names":[],"mappings":"AAiHA,WAAuE"}
|
package/dist/updateGlobal.d.ts
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"updateGlobal.d.ts","sourceRoot":"","sources":["../src/updateGlobal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
1
|
+
{"version":3,"file":"updateGlobal.d.ts","sourceRoot":"","sources":["../src/updateGlobal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAkB,YAAY,EAAE,MAAM,SAAS,CAAA;AAS3D,eAAO,MAAM,YAAY,EAAE,YA+B1B,CAAA"}
|
package/dist/updateGlobal.js
CHANGED
@@ -1,16 +1,29 @@
|
|
1
|
-
import
|
1
|
+
import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js';
|
2
|
+
import { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js';
|
3
|
+
import { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.js';
|
2
4
|
import { withSession } from './withSession.js';
|
3
|
-
export const updateGlobal = async function updateGlobal({ slug, data, req = {} }) {
|
5
|
+
export const updateGlobal = async function updateGlobal({ slug, data, req = {}, select }) {
|
4
6
|
const Model = this.globals;
|
7
|
+
const fields = this.payload.config.globals.find((global)=>global.slug === slug).fields;
|
5
8
|
const options = {
|
6
|
-
...withSession(this, req
|
9
|
+
...await withSession(this, req),
|
7
10
|
lean: true,
|
8
|
-
new: true
|
11
|
+
new: true,
|
12
|
+
projection: buildProjectionFromSelect({
|
13
|
+
adapter: this,
|
14
|
+
fields,
|
15
|
+
select
|
16
|
+
})
|
9
17
|
};
|
10
18
|
let result;
|
19
|
+
const sanitizedData = sanitizeRelationshipIDs({
|
20
|
+
config: this.payload.config,
|
21
|
+
data,
|
22
|
+
fields
|
23
|
+
});
|
11
24
|
result = await Model.findOneAndUpdate({
|
12
25
|
globalType: slug
|
13
|
-
},
|
26
|
+
}, sanitizedData, options);
|
14
27
|
result = JSON.parse(JSON.stringify(result));
|
15
28
|
// custom id type reset
|
16
29
|
result.id = result._id;
|
package/dist/updateGlobal.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/updateGlobal.ts"],"sourcesContent":["import type { UpdateGlobal } from 'payload
|
1
|
+
{"version":3,"sources":["../src/updateGlobal.ts"],"sourcesContent":["import type { PayloadRequest, UpdateGlobal } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js'\nimport { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.js'\nimport { withSession } from './withSession.js'\n\nexport const updateGlobal: UpdateGlobal = async function updateGlobal(\n this: MongooseAdapter,\n { slug, data, req = {} as PayloadRequest, select },\n) {\n const Model = this.globals\n const fields = this.payload.config.globals.find((global) => global.slug === slug).fields\n\n const options = {\n ...(await withSession(this, req)),\n lean: true,\n new: true,\n projection: buildProjectionFromSelect({ adapter: this, fields, select }),\n }\n\n let result\n\n const sanitizedData = sanitizeRelationshipIDs({\n config: this.payload.config,\n data,\n fields,\n })\n\n result = await Model.findOneAndUpdate({ globalType: slug }, sanitizedData, options)\n\n result = JSON.parse(JSON.stringify(result))\n\n // custom id type reset\n result.id = result._id\n result = sanitizeInternalFields(result)\n\n return result\n}\n"],"names":["buildProjectionFromSelect","sanitizeInternalFields","sanitizeRelationshipIDs","withSession","updateGlobal","slug","data","req","select","Model","globals","fields","payload","config","find","global","options","lean","new","projection","adapter","result","sanitizedData","findOneAndUpdate","globalType","JSON","parse","stringify","id","_id"],"mappings":"AAIA,SAASA,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,sBAAsB,QAAQ,wCAAuC;AAC9E,SAASC,uBAAuB,QAAQ,yCAAwC;AAChF,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,eAA6B,eAAeA,aAEvD,EAAEC,IAAI,EAAEC,IAAI,EAAEC,MAAM,CAAC,CAAmB,EAAEC,MAAM,EAAE;IAElD,MAAMC,QAAQ,IAAI,CAACC,OAAO;IAC1B,MAAMC,SAAS,IAAI,CAACC,OAAO,CAACC,MAAM,CAACH,OAAO,CAACI,IAAI,CAAC,CAACC,SAAWA,OAAOV,IAAI,KAAKA,MAAMM,MAAM;IAExF,MAAMK,UAAU;QACd,GAAI,MAAMb,YAAY,IAAI,EAAEI,IAAI;QAChCU,MAAM;QACNC,KAAK;QACLC,YAAYnB,0BAA0B;YAAEoB,SAAS,IAAI;YAAET;YAAQH;QAAO;IACxE;IAEA,IAAIa;IAEJ,MAAMC,gBAAgBpB,wBAAwB;QAC5CW,QAAQ,IAAI,CAACD,OAAO,CAACC,MAAM;QAC3BP;QACAK;IACF;IAEAU,SAAS,MAAMZ,MAAMc,gBAAgB,CAAC;QAAEC,YAAYnB;IAAK,GAAGiB,eAAeN;IAE3EK,SAASI,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACN;IAEnC,uBAAuB;IACvBA,OAAOO,EAAE,GAAGP,OAAOQ,GAAG;IACtBR,SAASpB,uBAAuBoB;IAEhC,OAAOA;AACT,EAAC"}
|
@@ -1,5 +1,4 @@
|
|
1
|
-
import type
|
2
|
-
import type { TypeWithID } from 'payload/types';
|
1
|
+
import { type TypeWithID, type UpdateGlobalVersionArgs } from 'payload';
|
3
2
|
import type { MongooseAdapter } from './index.js';
|
4
|
-
export declare function updateGlobalVersion<T extends TypeWithID>(this: MongooseAdapter, { id, global, locale, req, versionData, where, }: UpdateGlobalVersionArgs<T>): Promise<any>;
|
3
|
+
export declare function updateGlobalVersion<T extends TypeWithID>(this: MongooseAdapter, { id, global: globalSlug, locale, req, select, versionData, where, }: UpdateGlobalVersionArgs<T>): Promise<any>;
|
5
4
|
//# sourceMappingURL=updateGlobalVersion.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"updateGlobalVersion.d.ts","sourceRoot":"","sources":["../src/updateGlobalVersion.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
1
|
+
{"version":3,"file":"updateGlobalVersion.d.ts","sourceRoot":"","sources":["../src/updateGlobalVersion.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,UAAU,EACf,KAAK,uBAAuB,EAC7B,MAAM,SAAS,CAAA;AAEhB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAMjD,wBAAsB,mBAAmB,CAAC,CAAC,SAAS,UAAU,EAC5D,IAAI,EAAE,eAAe,EACrB,EACE,EAAE,EACF,MAAM,EAAE,UAAU,EAClB,MAAM,EACN,GAA0B,EAC1B,MAAM,EACN,WAAW,EACX,KAAK,GACN,EAAE,uBAAuB,CAAC,CAAC,CAAC,gBAwC9B"}
|
@@ -1,22 +1,36 @@
|
|
1
|
+
import { buildVersionGlobalFields } from 'payload';
|
2
|
+
import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js';
|
3
|
+
import { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.js';
|
1
4
|
import { withSession } from './withSession.js';
|
2
|
-
export async function updateGlobalVersion({ id, global, locale, req = {}, versionData, where }) {
|
3
|
-
const VersionModel = this.versions[
|
5
|
+
export async function updateGlobalVersion({ id, global: globalSlug, locale, req = {}, select, versionData, where }) {
|
6
|
+
const VersionModel = this.versions[globalSlug];
|
4
7
|
const whereToUse = where || {
|
5
8
|
id: {
|
6
9
|
equals: id
|
7
10
|
}
|
8
11
|
};
|
12
|
+
const fields = buildVersionGlobalFields(this.payload.config, this.payload.config.globals.find((global)=>global.slug === globalSlug));
|
9
13
|
const options = {
|
10
|
-
...withSession(this, req
|
14
|
+
...await withSession(this, req),
|
11
15
|
lean: true,
|
12
|
-
new: true
|
16
|
+
new: true,
|
17
|
+
projection: buildProjectionFromSelect({
|
18
|
+
adapter: this,
|
19
|
+
fields,
|
20
|
+
select
|
21
|
+
})
|
13
22
|
};
|
14
23
|
const query = await VersionModel.buildQuery({
|
15
24
|
locale,
|
16
25
|
payload: this.payload,
|
17
26
|
where: whereToUse
|
18
27
|
});
|
19
|
-
const
|
28
|
+
const sanitizedData = sanitizeRelationshipIDs({
|
29
|
+
config: this.payload.config,
|
30
|
+
data: versionData,
|
31
|
+
fields
|
32
|
+
});
|
33
|
+
const doc = await VersionModel.findOneAndUpdate(query, sanitizedData, options);
|
20
34
|
const result = JSON.parse(JSON.stringify(doc));
|
21
35
|
const verificationToken = doc._verificationToken;
|
22
36
|
// custom id type reset
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/updateGlobalVersion.ts"],"sourcesContent":["import type
|
1
|
+
{"version":3,"sources":["../src/updateGlobalVersion.ts"],"sourcesContent":["import {\n buildVersionGlobalFields,\n type PayloadRequest,\n type TypeWithID,\n type UpdateGlobalVersionArgs,\n} from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.js'\nimport { withSession } from './withSession.js'\n\nexport async function updateGlobalVersion<T extends TypeWithID>(\n this: MongooseAdapter,\n {\n id,\n global: globalSlug,\n locale,\n req = {} as PayloadRequest,\n select,\n versionData,\n where,\n }: UpdateGlobalVersionArgs<T>,\n) {\n const VersionModel = this.versions[globalSlug]\n const whereToUse = where || { id: { equals: id } }\n const fields = buildVersionGlobalFields(\n this.payload.config,\n this.payload.config.globals.find((global) => global.slug === globalSlug),\n )\n\n const options = {\n ...(await withSession(this, req)),\n lean: true,\n new: true,\n projection: buildProjectionFromSelect({ adapter: this, fields, select }),\n }\n\n const query = await VersionModel.buildQuery({\n locale,\n payload: this.payload,\n where: whereToUse,\n })\n\n const sanitizedData = sanitizeRelationshipIDs({\n config: this.payload.config,\n data: versionData,\n fields,\n })\n\n const doc = await VersionModel.findOneAndUpdate(query, sanitizedData, options)\n\n const result = JSON.parse(JSON.stringify(doc))\n\n const verificationToken = doc._verificationToken\n\n // custom id type reset\n result.id = result._id\n if (verificationToken) {\n result._verificationToken = verificationToken\n }\n return result\n}\n"],"names":["buildVersionGlobalFields","buildProjectionFromSelect","sanitizeRelationshipIDs","withSession","updateGlobalVersion","id","global","globalSlug","locale","req","select","versionData","where","VersionModel","versions","whereToUse","equals","fields","payload","config","globals","find","slug","options","lean","new","projection","adapter","query","buildQuery","sanitizedData","data","doc","findOneAndUpdate","result","JSON","parse","stringify","verificationToken","_verificationToken","_id"],"mappings":"AAAA,SACEA,wBAAwB,QAInB,UAAS;AAIhB,SAASC,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,uBAAuB,QAAQ,yCAAwC;AAChF,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,eAAeC,oBAEpB,EACEC,EAAE,EACFC,QAAQC,UAAU,EAClBC,MAAM,EACNC,MAAM,CAAC,CAAmB,EAC1BC,MAAM,EACNC,WAAW,EACXC,KAAK,EACsB;IAE7B,MAAMC,eAAe,IAAI,CAACC,QAAQ,CAACP,WAAW;IAC9C,MAAMQ,aAAaH,SAAS;QAAEP,IAAI;YAAEW,QAAQX;QAAG;IAAE;IACjD,MAAMY,SAASjB,yBACb,IAAI,CAACkB,OAAO,CAACC,MAAM,EACnB,IAAI,CAACD,OAAO,CAACC,MAAM,CAACC,OAAO,CAACC,IAAI,CAAC,CAACf,SAAWA,OAAOgB,IAAI,KAAKf;IAG/D,MAAMgB,UAAU;QACd,GAAI,MAAMpB,YAAY,IAAI,EAAEM,IAAI;QAChCe,MAAM;QACNC,KAAK;QACLC,YAAYzB,0BAA0B;YAAE0B,SAAS,IAAI;YAAEV;YAAQP;QAAO;IACxE;IAEA,MAAMkB,QAAQ,MAAMf,aAAagB,UAAU,CAAC;QAC1CrB;QACAU,SAAS,IAAI,CAACA,OAAO;QACrBN,OAAOG;IACT;IAEA,MAAMe,gBAAgB5B,wBAAwB;QAC5CiB,QAAQ,IAAI,CAACD,OAAO,CAACC,MAAM;QAC3BY,MAAMpB;QACNM;IACF;IAEA,MAAMe,MAAM,MAAMnB,aAAaoB,gBAAgB,CAACL,OAAOE,eAAeP;IAEtE,MAAMW,SAASC,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACL;IAEzC,MAAMM,oBAAoBN,IAAIO,kBAAkB;IAEhD,uBAAuB;IACvBL,OAAO7B,EAAE,GAAG6B,OAAOM,GAAG;IACtB,IAAIF,mBAAmB;QACrBJ,OAAOK,kBAAkB,GAAGD;IAC9B;IACA,OAAOJ;AACT"}
|
package/dist/updateOne.d.ts
CHANGED
package/dist/updateOne.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"updateOne.d.ts","sourceRoot":"","sources":["../src/updateOne.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"updateOne.d.ts","sourceRoot":"","sources":["../src/updateOne.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAkB,SAAS,EAAE,MAAM,SAAS,CAAA;AAUxD,eAAO,MAAM,SAAS,EAAE,SAiDvB,CAAA"}
|
package/dist/updateOne.js
CHANGED
@@ -1,17 +1,26 @@
|
|
1
|
-
import
|
2
|
-
import
|
1
|
+
import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js';
|
2
|
+
import { handleError } from './utilities/handleError.js';
|
3
|
+
import { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js';
|
4
|
+
import { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.js';
|
3
5
|
import { withSession } from './withSession.js';
|
4
|
-
export const updateOne = async function updateOne({ id, collection, data, locale, req = {}, where: whereArg }) {
|
6
|
+
export const updateOne = async function updateOne({ id, collection, data, locale, options: optionsArgs = {}, req = {}, select, where: whereArg }) {
|
5
7
|
const where = id ? {
|
6
8
|
id: {
|
7
9
|
equals: id
|
8
10
|
}
|
9
11
|
} : whereArg;
|
10
12
|
const Model = this.collections[collection];
|
13
|
+
const fields = this.payload.collections[collection].config.fields;
|
11
14
|
const options = {
|
12
|
-
...
|
15
|
+
...optionsArgs,
|
16
|
+
...await withSession(this, req),
|
13
17
|
lean: true,
|
14
|
-
new: true
|
18
|
+
new: true,
|
19
|
+
projection: buildProjectionFromSelect({
|
20
|
+
adapter: this,
|
21
|
+
fields,
|
22
|
+
select
|
23
|
+
})
|
15
24
|
};
|
16
25
|
const query = await Model.buildQuery({
|
17
26
|
locale,
|
@@ -19,10 +28,19 @@ export const updateOne = async function updateOne({ id, collection, data, locale
|
|
19
28
|
where
|
20
29
|
});
|
21
30
|
let result;
|
31
|
+
const sanitizedData = sanitizeRelationshipIDs({
|
32
|
+
config: this.payload.config,
|
33
|
+
data,
|
34
|
+
fields
|
35
|
+
});
|
22
36
|
try {
|
23
|
-
result = await Model.findOneAndUpdate(query,
|
37
|
+
result = await Model.findOneAndUpdate(query, sanitizedData, options);
|
24
38
|
} catch (error) {
|
25
|
-
handleError(
|
39
|
+
handleError({
|
40
|
+
collection,
|
41
|
+
error,
|
42
|
+
req
|
43
|
+
});
|
26
44
|
}
|
27
45
|
result = JSON.parse(JSON.stringify(result));
|
28
46
|
result.id = result._id;
|
package/dist/updateOne.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/updateOne.ts"],"sourcesContent":["import type {
|
1
|
+
{"version":3,"sources":["../src/updateOne.ts"],"sourcesContent":["import type { QueryOptions } from 'mongoose'\nimport type { PayloadRequest, UpdateOne } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { handleError } from './utilities/handleError.js'\nimport { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js'\nimport { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.js'\nimport { withSession } from './withSession.js'\n\nexport const updateOne: UpdateOne = async function updateOne(\n this: MongooseAdapter,\n {\n id,\n collection,\n data,\n locale,\n options: optionsArgs = {},\n req = {} as PayloadRequest,\n select,\n where: whereArg,\n },\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 ...(await withSession(this, req)),\n lean: true,\n new: true,\n projection: buildProjectionFromSelect({ adapter: this, fields, select }),\n }\n\n const query = await Model.buildQuery({\n locale,\n payload: this.payload,\n where,\n })\n\n let result\n\n const sanitizedData = sanitizeRelationshipIDs({\n config: this.payload.config,\n data,\n fields,\n })\n\n try {\n result = await Model.findOneAndUpdate(query, sanitizedData, options)\n } catch (error) {\n handleError({ collection, error, req })\n }\n\n result = JSON.parse(JSON.stringify(result))\n result.id = result._id\n result = sanitizeInternalFields(result)\n\n return result\n}\n"],"names":["buildProjectionFromSelect","handleError","sanitizeInternalFields","sanitizeRelationshipIDs","withSession","updateOne","id","collection","data","locale","options","optionsArgs","req","select","where","whereArg","equals","Model","collections","fields","payload","config","lean","new","projection","adapter","query","buildQuery","result","sanitizedData","findOneAndUpdate","error","JSON","parse","stringify","_id"],"mappings":"AAKA,SAASA,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,WAAW,QAAQ,6BAA4B;AACxD,SAASC,sBAAsB,QAAQ,wCAAuC;AAC9E,SAASC,uBAAuB,QAAQ,yCAAwC;AAChF,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,YAAuB,eAAeA,UAEjD,EACEC,EAAE,EACFC,UAAU,EACVC,IAAI,EACJC,MAAM,EACNC,SAASC,cAAc,CAAC,CAAC,EACzBC,MAAM,CAAC,CAAmB,EAC1BC,MAAM,EACNC,OAAOC,QAAQ,EAChB;IAED,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;QACd,GAAI,MAAMP,YAAY,IAAI,EAAEQ,IAAI;QAChCU,MAAM;QACNC,KAAK;QACLC,YAAYxB,0BAA0B;YAAEyB,SAAS,IAAI;YAAEN;YAAQN;QAAO;IACxE;IAEA,MAAMa,QAAQ,MAAMT,MAAMU,UAAU,CAAC;QACnClB;QACAW,SAAS,IAAI,CAACA,OAAO;QACrBN;IACF;IAEA,IAAIc;IAEJ,MAAMC,gBAAgB1B,wBAAwB;QAC5CkB,QAAQ,IAAI,CAACD,OAAO,CAACC,MAAM;QAC3Bb;QACAW;IACF;IAEA,IAAI;QACFS,SAAS,MAAMX,MAAMa,gBAAgB,CAACJ,OAAOG,eAAenB;IAC9D,EAAE,OAAOqB,OAAO;QACd9B,YAAY;YAAEM;YAAYwB;YAAOnB;QAAI;IACvC;IAEAgB,SAASI,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACN;IACnCA,OAAOtB,EAAE,GAAGsB,OAAOO,GAAG;IACtBP,SAAS1B,uBAAuB0B;IAEhC,OAAOA;AACT,EAAC"}
|
package/dist/updateVersion.d.ts
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"updateVersion.d.ts","sourceRoot":"","sources":["../src/updateVersion.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
1
|
+
{"version":3,"file":"updateVersion.d.ts","sourceRoot":"","sources":["../src/updateVersion.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqD,KAAK,aAAa,EAAE,MAAM,SAAS,CAAA;AAQ/F,eAAO,MAAM,aAAa,EAAE,aA0C3B,CAAA"}
|
package/dist/updateVersion.js
CHANGED
@@ -1,22 +1,36 @@
|
|
1
|
+
import { buildVersionCollectionFields } from 'payload';
|
2
|
+
import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js';
|
3
|
+
import { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.js';
|
1
4
|
import { withSession } from './withSession.js';
|
2
|
-
export const updateVersion = async function updateVersion({ id, collection, locale, req = {}, versionData, where }) {
|
5
|
+
export const updateVersion = async function updateVersion({ id, collection, locale, req = {}, select, versionData, where }) {
|
3
6
|
const VersionModel = this.versions[collection];
|
4
7
|
const whereToUse = where || {
|
5
8
|
id: {
|
6
9
|
equals: id
|
7
10
|
}
|
8
11
|
};
|
12
|
+
const fields = buildVersionCollectionFields(this.payload.config, this.payload.collections[collection].config);
|
9
13
|
const options = {
|
10
|
-
...withSession(this, req
|
14
|
+
...await withSession(this, req),
|
11
15
|
lean: true,
|
12
|
-
new: true
|
16
|
+
new: true,
|
17
|
+
projection: buildProjectionFromSelect({
|
18
|
+
adapter: this,
|
19
|
+
fields,
|
20
|
+
select
|
21
|
+
})
|
13
22
|
};
|
14
23
|
const query = await VersionModel.buildQuery({
|
15
24
|
locale,
|
16
25
|
payload: this.payload,
|
17
26
|
where: whereToUse
|
18
27
|
});
|
19
|
-
const
|
28
|
+
const sanitizedData = sanitizeRelationshipIDs({
|
29
|
+
config: this.payload.config,
|
30
|
+
data: versionData,
|
31
|
+
fields
|
32
|
+
});
|
33
|
+
const doc = await VersionModel.findOneAndUpdate(query, sanitizedData, options);
|
20
34
|
const result = JSON.parse(JSON.stringify(doc));
|
21
35
|
const verificationToken = doc._verificationToken;
|
22
36
|
// custom id type reset
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/updateVersion.ts"],"sourcesContent":["import type
|
1
|
+
{"version":3,"sources":["../src/updateVersion.ts"],"sourcesContent":["import { buildVersionCollectionFields, type PayloadRequest, type UpdateVersion } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { sanitizeRelationshipIDs } from './utilities/sanitizeRelationshipIDs.js'\nimport { withSession } from './withSession.js'\n\nexport const updateVersion: UpdateVersion = async function updateVersion(\n this: MongooseAdapter,\n { id, collection, locale, req = {} as PayloadRequest, 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 options = {\n ...(await withSession(this, req)),\n lean: true,\n new: true,\n projection: buildProjectionFromSelect({ adapter: this, fields, select }),\n }\n\n const query = await VersionModel.buildQuery({\n locale,\n payload: this.payload,\n where: whereToUse,\n })\n\n const sanitizedData = sanitizeRelationshipIDs({\n config: this.payload.config,\n data: versionData,\n fields,\n })\n\n const doc = await VersionModel.findOneAndUpdate(query, sanitizedData, options)\n\n const result = JSON.parse(JSON.stringify(doc))\n\n const verificationToken = doc._verificationToken\n\n // custom id type reset\n result.id = result._id\n if (verificationToken) {\n result._verificationToken = verificationToken\n }\n return result\n}\n"],"names":["buildVersionCollectionFields","buildProjectionFromSelect","sanitizeRelationshipIDs","withSession","updateVersion","id","collection","locale","req","select","versionData","where","VersionModel","versions","whereToUse","equals","fields","payload","config","collections","options","lean","new","projection","adapter","query","buildQuery","sanitizedData","data","doc","findOneAndUpdate","result","JSON","parse","stringify","verificationToken","_verificationToken","_id"],"mappings":"AAAA,SAASA,4BAA4B,QAAiD,UAAS;AAI/F,SAASC,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,uBAAuB,QAAQ,yCAAwC;AAChF,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,gBAA+B,eAAeA,cAEzD,EAAEC,EAAE,EAAEC,UAAU,EAAEC,MAAM,EAAEC,MAAM,CAAC,CAAmB,EAAEC,MAAM,EAAEC,WAAW,EAAEC,KAAK,EAAE;IAElF,MAAMC,eAAe,IAAI,CAACC,QAAQ,CAACP,WAAW;IAC9C,MAAMQ,aAAaH,SAAS;QAAEN,IAAI;YAAEU,QAAQV;QAAG;IAAE;IACjD,MAAMW,SAAShB,6BACb,IAAI,CAACiB,OAAO,CAACC,MAAM,EACnB,IAAI,CAACD,OAAO,CAACE,WAAW,CAACb,WAAW,CAACY,MAAM;IAG7C,MAAME,UAAU;QACd,GAAI,MAAMjB,YAAY,IAAI,EAAEK,IAAI;QAChCa,MAAM;QACNC,KAAK;QACLC,YAAYtB,0BAA0B;YAAEuB,SAAS,IAAI;YAAER;YAAQP;QAAO;IACxE;IAEA,MAAMgB,QAAQ,MAAMb,aAAac,UAAU,CAAC;QAC1CnB;QACAU,SAAS,IAAI,CAACA,OAAO;QACrBN,OAAOG;IACT;IAEA,MAAMa,gBAAgBzB,wBAAwB;QAC5CgB,QAAQ,IAAI,CAACD,OAAO,CAACC,MAAM;QAC3BU,MAAMlB;QACNM;IACF;IAEA,MAAMa,MAAM,MAAMjB,aAAakB,gBAAgB,CAACL,OAAOE,eAAeP;IAEtE,MAAMW,SAASC,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACL;IAEzC,MAAMM,oBAAoBN,IAAIO,kBAAkB;IAEhD,uBAAuB;IACvBL,OAAO1B,EAAE,GAAG0B,OAAOM,GAAG;IACtB,IAAIF,mBAAmB;QACrBJ,OAAOK,kBAAkB,GAAGD;IAC9B;IACA,OAAOJ;AACT,EAAC"}
|
package/dist/upsert.d.ts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"upsert.d.ts","sourceRoot":"","sources":["../src/upsert.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAkB,MAAM,EAAE,MAAM,SAAS,CAAA;AAIrD,eAAO,MAAM,MAAM,EAAE,MAKpB,CAAA"}
|
package/dist/upsert.js
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
export const upsert = async function upsert({ collection, data, locale, req = {}, select, where }) {
|
2
|
+
return this.updateOne({
|
3
|
+
collection,
|
4
|
+
data,
|
5
|
+
locale,
|
6
|
+
options: {
|
7
|
+
upsert: true
|
8
|
+
},
|
9
|
+
req,
|
10
|
+
select,
|
11
|
+
where
|
12
|
+
});
|
13
|
+
};
|
14
|
+
|
15
|
+
//# sourceMappingURL=upsert.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../src/upsert.ts"],"sourcesContent":["import type { PayloadRequest, Upsert } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nexport const upsert: Upsert = async function upsert(\n this: MongooseAdapter,\n { collection, data, locale, req = {} as PayloadRequest, select, where },\n) {\n return this.updateOne({ collection, data, locale, options: { upsert: true }, req, select, where })\n}\n"],"names":["upsert","collection","data","locale","req","select","where","updateOne","options"],"mappings":"AAIA,OAAO,MAAMA,SAAiB,eAAeA,OAE3C,EAAEC,UAAU,EAAEC,IAAI,EAAEC,MAAM,EAAEC,MAAM,CAAC,CAAmB,EAAEC,MAAM,EAAEC,KAAK,EAAE;IAEvE,OAAO,IAAI,CAACC,SAAS,CAAC;QAAEN;QAAYC;QAAMC;QAAQK,SAAS;YAAER,QAAQ;QAAK;QAAGI;QAAKC;QAAQC;IAAM;AAClG,EAAC"}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
import type { PipelineStage } from 'mongoose';
|
2
|
+
import type { CollectionSlug, JoinQuery, SanitizedCollectionConfig, Where } from 'payload';
|
3
|
+
import type { MongooseAdapter } from '../index.js';
|
4
|
+
type BuildJoinAggregationArgs = {
|
5
|
+
adapter: MongooseAdapter;
|
6
|
+
collection: CollectionSlug;
|
7
|
+
collectionConfig: SanitizedCollectionConfig;
|
8
|
+
joins: JoinQuery;
|
9
|
+
limit?: number;
|
10
|
+
locale: string;
|
11
|
+
projection?: Record<string, true>;
|
12
|
+
query?: Where;
|
13
|
+
/** whether the query is from drafts */
|
14
|
+
versions?: boolean;
|
15
|
+
};
|
16
|
+
export declare const buildJoinAggregation: ({ adapter, collection, collectionConfig, joins, limit, locale, projection, query, versions, }: BuildJoinAggregationArgs) => Promise<PipelineStage[] | undefined>;
|
17
|
+
export {};
|
18
|
+
//# sourceMappingURL=buildJoinAggregation.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"buildJoinAggregation.d.ts","sourceRoot":"","sources":["../../src/utilities/buildJoinAggregation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAC7C,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,yBAAyB,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAE1F,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAIlD,KAAK,wBAAwB,GAAG;IAC9B,OAAO,EAAE,eAAe,CAAA;IACxB,UAAU,EAAE,cAAc,CAAA;IAC1B,gBAAgB,EAAE,yBAAyB,CAAA;IAC3C,KAAK,EAAE,SAAS,CAAA;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,CA+JhE,CAAA"}
|
@@ -0,0 +1,159 @@
|
|
1
|
+
import { buildSortParam } from '../queries/buildSortParam.js';
|
2
|
+
export const buildJoinAggregation = async ({ adapter, collection, collectionConfig, joins, limit, locale, projection, query, versions })=>{
|
3
|
+
if (Object.keys(collectionConfig.joins).length === 0 || joins === false) {
|
4
|
+
return;
|
5
|
+
}
|
6
|
+
const joinConfig = adapter.payload.collections[collection].config.joins;
|
7
|
+
const aggregate = [
|
8
|
+
{
|
9
|
+
$sort: {
|
10
|
+
createdAt: -1
|
11
|
+
}
|
12
|
+
}
|
13
|
+
];
|
14
|
+
if (query) {
|
15
|
+
aggregate.push({
|
16
|
+
$match: query
|
17
|
+
});
|
18
|
+
}
|
19
|
+
if (limit) {
|
20
|
+
aggregate.push({
|
21
|
+
$limit: limit
|
22
|
+
});
|
23
|
+
}
|
24
|
+
for (const slug of Object.keys(joinConfig)){
|
25
|
+
for (const join of joinConfig[slug]){
|
26
|
+
const joinModel = adapter.collections[join.field.collection];
|
27
|
+
if (projection && !projection[join.joinPath]) {
|
28
|
+
continue;
|
29
|
+
}
|
30
|
+
if (joins?.[join.joinPath] === false) {
|
31
|
+
continue;
|
32
|
+
}
|
33
|
+
const { limit: limitJoin = join.field.defaultLimit ?? 10, sort: sortJoin = join.field.defaultSort || collectionConfig.defaultSort, where: whereJoin } = joins?.[join.joinPath] || {};
|
34
|
+
const sort = buildSortParam({
|
35
|
+
config: adapter.payload.config,
|
36
|
+
fields: adapter.payload.collections[slug].config.fields,
|
37
|
+
locale,
|
38
|
+
sort: sortJoin,
|
39
|
+
timestamps: true
|
40
|
+
});
|
41
|
+
const sortProperty = Object.keys(sort)[0];
|
42
|
+
const sortDirection = sort[sortProperty] === 'asc' ? 1 : -1;
|
43
|
+
const $match = await joinModel.buildQuery({
|
44
|
+
locale,
|
45
|
+
payload: adapter.payload,
|
46
|
+
where: whereJoin
|
47
|
+
});
|
48
|
+
const pipeline = [
|
49
|
+
{
|
50
|
+
$match
|
51
|
+
},
|
52
|
+
{
|
53
|
+
$sort: {
|
54
|
+
[sortProperty]: sortDirection
|
55
|
+
}
|
56
|
+
}
|
57
|
+
];
|
58
|
+
if (limitJoin > 0) {
|
59
|
+
pipeline.push({
|
60
|
+
$limit: limitJoin + 1
|
61
|
+
});
|
62
|
+
}
|
63
|
+
if (adapter.payload.config.localization && locale === 'all') {
|
64
|
+
adapter.payload.config.localization.localeCodes.forEach((code)=>{
|
65
|
+
const as = `${versions ? `version.${join.joinPath}` : join.joinPath}${code}`;
|
66
|
+
aggregate.push({
|
67
|
+
$lookup: {
|
68
|
+
as: `${as}.docs`,
|
69
|
+
foreignField: `${join.field.on}${code}`,
|
70
|
+
from: adapter.collections[slug].collection.name,
|
71
|
+
localField: versions ? 'parent' : '_id',
|
72
|
+
pipeline
|
73
|
+
}
|
74
|
+
}, {
|
75
|
+
$addFields: {
|
76
|
+
[`${as}.docs`]: {
|
77
|
+
$map: {
|
78
|
+
as: 'doc',
|
79
|
+
in: '$$doc._id',
|
80
|
+
input: `$${as}.docs`
|
81
|
+
}
|
82
|
+
},
|
83
|
+
[`${as}.hasNextPage`]: limitJoin ? {
|
84
|
+
$gt: [
|
85
|
+
{
|
86
|
+
$size: `$${as}.docs`
|
87
|
+
},
|
88
|
+
limitJoin
|
89
|
+
]
|
90
|
+
} : false
|
91
|
+
}
|
92
|
+
});
|
93
|
+
if (limitJoin > 0) {
|
94
|
+
aggregate.push({
|
95
|
+
$addFields: {
|
96
|
+
[`${as}.docs`]: {
|
97
|
+
$slice: [
|
98
|
+
`$${as}.docs`,
|
99
|
+
limitJoin
|
100
|
+
]
|
101
|
+
}
|
102
|
+
}
|
103
|
+
});
|
104
|
+
}
|
105
|
+
});
|
106
|
+
} else {
|
107
|
+
const localeSuffix = join.field.localized && adapter.payload.config.localization && locale ? `.${locale}` : '';
|
108
|
+
const as = `${versions ? `version.${join.joinPath}` : join.joinPath}${localeSuffix}`;
|
109
|
+
aggregate.push({
|
110
|
+
$lookup: {
|
111
|
+
as: `${as}.docs`,
|
112
|
+
foreignField: `${join.field.on}${localeSuffix}`,
|
113
|
+
from: adapter.collections[slug].collection.name,
|
114
|
+
localField: versions ? 'parent' : '_id',
|
115
|
+
pipeline
|
116
|
+
}
|
117
|
+
}, {
|
118
|
+
$addFields: {
|
119
|
+
[`${as}.docs`]: {
|
120
|
+
$map: {
|
121
|
+
as: 'doc',
|
122
|
+
in: '$$doc._id',
|
123
|
+
input: `$${as}.docs`
|
124
|
+
}
|
125
|
+
},
|
126
|
+
[`${as}.hasNextPage`]: {
|
127
|
+
$gt: [
|
128
|
+
{
|
129
|
+
$size: `$${as}.docs`
|
130
|
+
},
|
131
|
+
limitJoin || Number.MAX_VALUE
|
132
|
+
]
|
133
|
+
}
|
134
|
+
}
|
135
|
+
});
|
136
|
+
if (limitJoin > 0) {
|
137
|
+
aggregate.push({
|
138
|
+
$addFields: {
|
139
|
+
[`${as}.docs`]: {
|
140
|
+
$slice: [
|
141
|
+
`$${as}.docs`,
|
142
|
+
limitJoin
|
143
|
+
]
|
144
|
+
}
|
145
|
+
}
|
146
|
+
});
|
147
|
+
}
|
148
|
+
}
|
149
|
+
}
|
150
|
+
}
|
151
|
+
if (projection) {
|
152
|
+
aggregate.push({
|
153
|
+
$project: projection
|
154
|
+
});
|
155
|
+
}
|
156
|
+
return aggregate;
|
157
|
+
};
|
158
|
+
|
159
|
+
//# sourceMappingURL=buildJoinAggregation.js.map
|