@payloadcms/db-mongodb 4.0.0-internal.314c594 → 4.0.0-internal.31ba7ee
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/connect.d.ts.map +1 -1
- package/dist/connect.js +8 -2
- package/dist/connect.js.map +1 -1
- package/dist/createMigration.d.ts.map +1 -1
- package/dist/createMigration.js +9 -2
- package/dist/createMigration.js.map +1 -1
- package/dist/findDistinct.d.ts.map +1 -1
- package/dist/findDistinct.js +52 -8
- package/dist/findDistinct.js.map +1 -1
- package/dist/init.d.ts.map +1 -1
- package/dist/init.js +89 -67
- package/dist/init.js.map +1 -1
- package/dist/migrateFresh.d.ts +4 -2
- package/dist/migrateFresh.d.ts.map +1 -1
- package/dist/migrateFresh.js +21 -6
- package/dist/migrateFresh.js.map +1 -1
- package/dist/models/buildCollectionSchema.d.ts +8 -2
- package/dist/models/buildCollectionSchema.d.ts.map +1 -1
- package/dist/models/buildCollectionSchema.js +4 -2
- package/dist/models/buildCollectionSchema.js.map +1 -1
- package/dist/models/buildGlobalModel.d.ts +5 -1
- package/dist/models/buildGlobalModel.d.ts.map +1 -1
- package/dist/models/buildGlobalModel.js +4 -2
- package/dist/models/buildGlobalModel.js.map +1 -1
- package/dist/models/buildSchema.d.ts +4 -0
- package/dist/models/buildSchema.d.ts.map +1 -1
- package/dist/models/buildSchema.js +64 -26
- package/dist/models/buildSchema.js.map +1 -1
- package/dist/models/schemaBuildContext.d.ts +21 -0
- package/dist/models/schemaBuildContext.d.ts.map +1 -0
- package/dist/models/schemaBuildContext.js +29 -0
- package/dist/models/schemaBuildContext.js.map +1 -0
- package/dist/queries/buildSearchParams.d.ts.map +1 -1
- package/dist/queries/buildSearchParams.js +50 -0
- package/dist/queries/buildSearchParams.js.map +1 -1
- package/dist/updateGlobal.js +2 -2
- package/dist/updateGlobal.js.map +1 -1
- package/dist/updateGlobalVersion.js +2 -2
- package/dist/updateGlobalVersion.js.map +1 -1
- package/dist/updateJobs.js +1 -1
- package/dist/updateJobs.js.map +1 -1
- package/dist/updateMany.d.ts.map +1 -1
- package/dist/updateMany.js +0 -1
- package/dist/updateMany.js.map +1 -1
- package/dist/updateOne.js +2 -2
- package/dist/updateOne.js.map +1 -1
- package/dist/updateVersion.js +2 -2
- package/dist/updateVersion.js.map +1 -1
- package/package.json +3 -3
- package/dist/queries/buildSortParam.spec.js +0 -123
- package/dist/queries/buildSortParam.spec.js.map +0 -1
- package/dist/queries/getLocalizedSortProperty.spec.js +0 -215
- package/dist/queries/getLocalizedSortProperty.spec.js.map +0 -1
- package/dist/utilities/transform.spec.js +0 -546
- package/dist/utilities/transform.spec.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schemaBuildContext.d.ts","sourceRoot":"","sources":["../../src/models/schemaBuildContext.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AAClD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAA;AAK1D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAA;AAE1D,MAAM,MAAM,uBAAuB,GAAG,kBAAkB,CAAC,MAAM,CAAC,CAAA;AAiBhE;;;;GAIG;AACH,eAAO,MAAM,6BAA6B,oBAEvC;IACD,UAAU,EAAE,UAAU,CAAA;CACvB,KAAG,uBAQH,CAAA;AAED,eAAO,MAAM,sBAAsB,uFAOhC;IACD,SAAS,EAAE,MAAM,CAAA;IACjB,kBAAkB,EAAE,kBAAkB,CAAA;IACtC,SAAS,EAAE,MAAM,CAAA;IACjB,WAAW,EAAE,OAAO,CAAA;IACpB,WAAW,EAAE,OAAO,CAAA;IACpB,SAAS,EAAE,OAAO,CAAA;CACnB,KAAG,MASU,CAAA"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import mongoose from 'mongoose';
|
|
2
|
+
import { createSchemaBuildContext } from 'payload/internal';
|
|
3
|
+
const getMongoosePluginRegistry = ({ mongooseInstance })=>mongooseInstance.plugins;
|
|
4
|
+
const defaultMongoosePluginFunctions = new Set(getMongoosePluginRegistry({
|
|
5
|
+
mongooseInstance: new mongoose.Mongoose({
|
|
6
|
+
createInitialConnection: false
|
|
7
|
+
})
|
|
8
|
+
}).map(([plugin])=>plugin));
|
|
9
|
+
/**
|
|
10
|
+
* Connection and global plugins can keep state on each nested schema. Mongoose does not clone
|
|
11
|
+
* those nested schemas when it attaches a discriminator, so cached templates would change plugin
|
|
12
|
+
* application.
|
|
13
|
+
*/ export const createMongoSchemaBuildContext = ({ connection })=>{
|
|
14
|
+
const hasCustomGlobalPlugins = getMongoosePluginRegistry({
|
|
15
|
+
mongooseInstance: connection.base
|
|
16
|
+
}).some(([plugin])=>!defaultMongoosePluginFunctions.has(plugin));
|
|
17
|
+
return createSchemaBuildContext({
|
|
18
|
+
isCacheEnabled: connection.plugins.length === 0 && !hasCustomGlobalPlugins
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
export const getBlockSchemaCacheKey = ({ blockSlug, buildSchemaOptions, fieldPath, isLocalized, isReference, isVersion })=>[
|
|
22
|
+
`${isReference ? `block:${blockSlug}` : `inline:${fieldPath}/block:${blockSlug}`}${isVersion ? '-version' : ''}`,
|
|
23
|
+
buildSchemaOptions.disableUnique && 'disableUnique:true',
|
|
24
|
+
buildSchemaOptions.draftsEnabled && 'draftsEnabled:true',
|
|
25
|
+
buildSchemaOptions.indexSortableFields && 'indexSortableFields:true',
|
|
26
|
+
isLocalized && 'isLocalized:true'
|
|
27
|
+
].filter(Boolean).join('|');
|
|
28
|
+
|
|
29
|
+
//# sourceMappingURL=schemaBuildContext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/models/schemaBuildContext.ts"],"sourcesContent":["import type { Connection, Schema } from 'mongoose'\nimport type { SchemaBuildContext } from 'payload/internal'\n\nimport mongoose from 'mongoose'\nimport { createSchemaBuildContext } from 'payload/internal'\n\nimport type { BuildSchemaOptions } from './buildSchema.js'\n\nexport type MongoSchemaBuildContext = SchemaBuildContext<Schema>\n\ntype MongoosePluginRegistry = Array<[Parameters<typeof mongoose.plugin>[0], unknown]>\n\nconst getMongoosePluginRegistry = ({\n mongooseInstance,\n}: {\n mongooseInstance: typeof mongoose\n}): MongoosePluginRegistry =>\n (mongooseInstance as { plugins: MongoosePluginRegistry } & typeof mongoose).plugins\n\nconst defaultMongoosePluginFunctions = new Set(\n getMongoosePluginRegistry({\n mongooseInstance: new mongoose.Mongoose({ createInitialConnection: false }),\n }).map(([plugin]) => plugin),\n)\n\n/**\n * Connection and global plugins can keep state on each nested schema. Mongoose does not clone\n * those nested schemas when it attaches a discriminator, so cached templates would change plugin\n * application.\n */\nexport const createMongoSchemaBuildContext = ({\n connection,\n}: {\n connection: Connection\n}): MongoSchemaBuildContext => {\n const hasCustomGlobalPlugins = getMongoosePluginRegistry({\n mongooseInstance: connection.base,\n }).some(([plugin]) => !defaultMongoosePluginFunctions.has(plugin))\n\n return createSchemaBuildContext<Schema>({\n isCacheEnabled: connection.plugins.length === 0 && !hasCustomGlobalPlugins,\n })\n}\n\nexport const getBlockSchemaCacheKey = ({\n blockSlug,\n buildSchemaOptions,\n fieldPath,\n isLocalized,\n isReference,\n isVersion,\n}: {\n blockSlug: string\n buildSchemaOptions: BuildSchemaOptions\n fieldPath: string\n isLocalized: boolean\n isReference: boolean\n isVersion: boolean\n}): string =>\n [\n `${isReference ? `block:${blockSlug}` : `inline:${fieldPath}/block:${blockSlug}`}${isVersion ? '-version' : ''}`,\n buildSchemaOptions.disableUnique && 'disableUnique:true',\n buildSchemaOptions.draftsEnabled && 'draftsEnabled:true',\n buildSchemaOptions.indexSortableFields && 'indexSortableFields:true',\n isLocalized && 'isLocalized:true',\n ]\n .filter(Boolean)\n .join('|')\n"],"names":["mongoose","createSchemaBuildContext","getMongoosePluginRegistry","mongooseInstance","plugins","defaultMongoosePluginFunctions","Set","Mongoose","createInitialConnection","map","plugin","createMongoSchemaBuildContext","connection","hasCustomGlobalPlugins","base","some","has","isCacheEnabled","length","getBlockSchemaCacheKey","blockSlug","buildSchemaOptions","fieldPath","isLocalized","isReference","isVersion","disableUnique","draftsEnabled","indexSortableFields","filter","Boolean","join"],"mappings":"AAGA,OAAOA,cAAc,WAAU;AAC/B,SAASC,wBAAwB,QAAQ,mBAAkB;AAQ3D,MAAMC,4BAA4B,CAAC,EACjCC,gBAAgB,EAGjB,GACC,AAACA,iBAA2EC,OAAO;AAErF,MAAMC,iCAAiC,IAAIC,IACzCJ,0BAA0B;IACxBC,kBAAkB,IAAIH,SAASO,QAAQ,CAAC;QAAEC,yBAAyB;IAAM;AAC3E,GAAGC,GAAG,CAAC,CAAC,CAACC,OAAO,GAAKA;AAGvB;;;;CAIC,GACD,OAAO,MAAMC,gCAAgC,CAAC,EAC5CC,UAAU,EAGX;IACC,MAAMC,yBAAyBX,0BAA0B;QACvDC,kBAAkBS,WAAWE,IAAI;IACnC,GAAGC,IAAI,CAAC,CAAC,CAACL,OAAO,GAAK,CAACL,+BAA+BW,GAAG,CAACN;IAE1D,OAAOT,yBAAiC;QACtCgB,gBAAgBL,WAAWR,OAAO,CAACc,MAAM,KAAK,KAAK,CAACL;IACtD;AACF,EAAC;AAED,OAAO,MAAMM,yBAAyB,CAAC,EACrCC,SAAS,EACTC,kBAAkB,EAClBC,SAAS,EACTC,WAAW,EACXC,WAAW,EACXC,SAAS,EAQV,GACC;QACE,GAAGD,cAAc,CAAC,MAAM,EAAEJ,WAAW,GAAG,CAAC,OAAO,EAAEE,UAAU,OAAO,EAAEF,WAAW,GAAGK,YAAY,aAAa,IAAI;QAChHJ,mBAAmBK,aAAa,IAAI;QACpCL,mBAAmBM,aAAa,IAAI;QACpCN,mBAAmBO,mBAAmB,IAAI;QAC1CL,eAAe;KAChB,CACEM,MAAM,CAACC,SACPC,IAAI,CAAC,KAAI"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildSearchParams.d.ts","sourceRoot":"","sources":["../../src/queries/buildSearchParams.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,cAAc,EAEd,QAAQ,EAER,OAAO,EACR,MAAM,SAAS,CAAA;AAkBhB,KAAK,WAAW,GAAG;IACjB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,KAAK,CAAC,EAAE,OAAO,CAAA;CAChB,CAAA;AAMD;;GAEG;AACH,wBAAsB,gBAAgB,CAAC,EACrC,cAAc,EACd,MAAM,EACN,UAAU,EACV,YAAY,EACZ,MAAM,EACN,QAAQ,EACR,iBAAiB,EACjB,OAAO,EACP,GAAG,GACJ,EAAE;IACD,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,MAAM,EAAE,cAAc,EAAE,CAAA;IACxB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,YAAY,EAAE,MAAM,CAAA;IACpB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,QAAQ,EAAE,QAAQ,CAAA;IAClB,iBAAiB,EAAE,OAAO,CAAA;IAC1B,OAAO,EAAE,OAAO,CAAA;IAChB,GAAG,EAAE,OAAO,CAAA;CACb,GAAG,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC,
|
|
1
|
+
{"version":3,"file":"buildSearchParams.d.ts","sourceRoot":"","sources":["../../src/queries/buildSearchParams.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,cAAc,EAEd,QAAQ,EAER,OAAO,EACR,MAAM,SAAS,CAAA;AAkBhB,KAAK,WAAW,GAAG;IACjB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,KAAK,CAAC,EAAE,OAAO,CAAA;CAChB,CAAA;AAMD;;GAEG;AACH,wBAAsB,gBAAgB,CAAC,EACrC,cAAc,EACd,MAAM,EACN,UAAU,EACV,YAAY,EACZ,MAAM,EACN,QAAQ,EACR,iBAAiB,EACjB,OAAO,EACP,GAAG,GACJ,EAAE;IACD,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,MAAM,EAAE,cAAc,EAAE,CAAA;IACxB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,YAAY,EAAE,MAAM,CAAA;IACpB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,QAAQ,EAAE,QAAQ,CAAA;IAClB,iBAAiB,EAAE,OAAO,CAAA;IAC1B,OAAO,EAAE,OAAO,CAAA;IAChB,GAAG,EAAE,OAAO,CAAA;CACb,GAAG,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC,CAmZnC"}
|
|
@@ -60,6 +60,17 @@ const subQueryOptions = {
|
|
|
60
60
|
payload
|
|
61
61
|
});
|
|
62
62
|
}
|
|
63
|
+
if (operator === 'contains' && paths.length === 1 && field.type === 'join' && typeof field.collection === 'string' && isNestedRelationshipQuery(val)) {
|
|
64
|
+
return buildJoinContainsSearchParam({
|
|
65
|
+
field,
|
|
66
|
+
locale,
|
|
67
|
+
nestedWhere: val,
|
|
68
|
+
payload
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
if ((operator === 'contains' || operator === 'like' || operator === 'not_like') && (isNestedRelationshipQuery(val) || Array.isArray(val) && val.some((entry)=>isNestedRelationshipQuery(entry)))) {
|
|
72
|
+
throw new APIError(`Invalid value for "${operator}" on path "${path}": expected a string.`, 400);
|
|
73
|
+
}
|
|
63
74
|
if (path) {
|
|
64
75
|
const sanitizedQueryValue = sanitizeQueryValue({
|
|
65
76
|
field,
|
|
@@ -432,5 +443,44 @@ const subQueryOptions = {
|
|
|
432
443
|
}
|
|
433
444
|
}
|
|
434
445
|
}
|
|
446
|
+
/**
|
|
447
|
+
* Builds a MongoDB condition for a `contains` query nested on a join field.
|
|
448
|
+
*
|
|
449
|
+
* Finds documents in the joined collection that match the nested query, then follows the join's
|
|
450
|
+
* `on` relationship to collect the parent IDs those documents point back to. Because the nested
|
|
451
|
+
* query resolves against a single joined document, the user's filter and any injected access
|
|
452
|
+
* constraint must be satisfied by the same document.
|
|
453
|
+
*/ async function buildJoinContainsSearchParam({ field, locale, nestedWhere, payload }) {
|
|
454
|
+
if (field.type !== 'join' || typeof field.collection !== 'string' || !isNestedRelationshipQuery(nestedWhere)) {
|
|
455
|
+
return undefined;
|
|
456
|
+
}
|
|
457
|
+
const { collectionConfig, Model: JoinedModel } = getCollection({
|
|
458
|
+
adapter: payload.db,
|
|
459
|
+
collectionSlug: field.collection
|
|
460
|
+
});
|
|
461
|
+
const relationshipField = getFieldByPath({
|
|
462
|
+
fields: collectionConfig.flattenedFields,
|
|
463
|
+
path: field.on
|
|
464
|
+
});
|
|
465
|
+
if (!relationshipField) {
|
|
466
|
+
throw new APIError('Relationship field was not found');
|
|
467
|
+
}
|
|
468
|
+
let joinPath = relationshipField.localizedPath;
|
|
469
|
+
if (relationshipField.pathHasLocalized && payload.config.localization) {
|
|
470
|
+
joinPath = joinPath.replace('<locale>', locale || payload.config.localization.defaultLocale);
|
|
471
|
+
}
|
|
472
|
+
const subQuery = await JoinedModel.buildQuery({
|
|
473
|
+
locale,
|
|
474
|
+
payload,
|
|
475
|
+
where: nestedWhere
|
|
476
|
+
});
|
|
477
|
+
const parentIDs = await JoinedModel.distinct(joinPath, subQuery);
|
|
478
|
+
return {
|
|
479
|
+
path: '_id',
|
|
480
|
+
value: {
|
|
481
|
+
$in: parentIDs
|
|
482
|
+
}
|
|
483
|
+
};
|
|
484
|
+
}
|
|
435
485
|
|
|
436
486
|
//# sourceMappingURL=buildSearchParams.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/queries/buildSearchParams.ts"],"sourcesContent":["import type { QueryFilter } from 'mongoose'\nimport type {\n FlattenedField,\n HasManyRelationshipOperator,\n Operator,\n PathToQuery,\n Payload,\n} from 'payload'\n\nimport { Types } from 'mongoose'\nimport { APIError, escapeRegExp, getFieldByPath, getLocalizedPaths } from 'payload'\nimport {\n hasManyRelationshipOperatorSet,\n isNestedRelationshipQuery,\n validOperatorSet,\n} from 'payload/shared'\n\nimport type { MongooseAdapter } from '../index.js'\nimport type { OperatorMapKey } from './operatorMap.js'\n\nimport { getCollection } from '../utilities/getEntity.js'\nimport { isObjectID } from '../utilities/isObjectID.js'\nimport { operatorMap } from './operatorMap.js'\nimport { sanitizeQueryValue } from './sanitizeQueryValue.js'\n\ntype SearchParam = {\n path?: string\n rawQuery?: unknown\n value?: unknown\n}\n\nconst subQueryOptions = {\n lean: true,\n}\n\n/**\n * Convert the Payload key / value / operator into a MongoDB query\n */\nexport async function buildSearchParam({\n collectionSlug,\n fields,\n globalSlug,\n incomingPath,\n locale,\n operator,\n parentIsLocalized,\n payload,\n val,\n}: {\n collectionSlug?: string\n fields: FlattenedField[]\n globalSlug?: string\n incomingPath: string\n locale?: string\n operator: Operator\n parentIsLocalized: boolean\n payload: Payload\n val: unknown\n}): Promise<SearchParam | undefined> {\n // Replace GraphQL nested field double underscore formatting\n let sanitizedPath = incomingPath.replace(/__/g, '.')\n if (sanitizedPath === 'id') {\n sanitizedPath = '_id'\n }\n\n let paths: PathToQuery[] = []\n\n let hasCustomID = false\n\n if (sanitizedPath === '_id') {\n const customIDFieldType = collectionSlug\n ? payload.collections[collectionSlug]?.customIDType\n : undefined\n\n let idFieldType: 'number' | 'text' = 'text'\n\n if (customIDFieldType) {\n idFieldType = customIDFieldType\n hasCustomID = true\n }\n\n paths.push({\n collectionSlug,\n complete: true,\n field: {\n name: 'id',\n type: idFieldType,\n } as FlattenedField,\n parentIsLocalized: parentIsLocalized ?? false,\n path: '_id',\n })\n } else {\n paths = getLocalizedPaths({\n collectionSlug,\n fields,\n globalSlug,\n incomingPath: sanitizedPath,\n locale,\n parentIsLocalized,\n payload,\n })\n }\n\n if (!paths[0]) {\n return undefined\n }\n\n const [{ field, path }] = paths\n\n if (\n hasManyRelationshipOperatorSet.has(operator as HasManyRelationshipOperator) &&\n paths.length === 1 &&\n (field.type === 'relationship' || field.type === 'upload') &&\n field.hasMany &&\n typeof field.relationTo === 'string' &&\n isNestedRelationshipQuery(val)\n ) {\n return buildHasManyRelationshipSearchParam({\n field,\n locale,\n nestedWhere: val,\n operator: operator as HasManyRelationshipOperator,\n path,\n payload,\n })\n }\n\n if (path) {\n const sanitizedQueryValue = sanitizeQueryValue({\n field,\n hasCustomID,\n locale,\n operator,\n parentIsLocalized,\n path,\n payload,\n val,\n })\n\n if (!sanitizedQueryValue) {\n return undefined\n }\n\n const { operator: formattedOperator, rawQuery, val: formattedValue } = sanitizedQueryValue\n\n if (rawQuery && paths.length === 1) {\n return { value: rawQuery }\n }\n\n if (!formattedOperator) {\n return undefined\n }\n\n // If there are multiple collections to search through,\n // Recursively build up a list of query constraints\n if (paths.length > 1) {\n // Remove top collection and reverse array\n // to work backwards from top\n const pathsToQuery = paths.slice(1).reverse()\n const parentPaths = paths.slice(0, -1).reverse()\n\n let relationshipQuery: SearchParam = {\n value: {},\n }\n\n for (const [i, { collectionSlug, path: subPath }] of pathsToQuery.entries()) {\n // The arrays are reversed together, so both entries describe the same relationship hop.\n const parentField = parentPaths[i]?.field\n\n if (!parentField) {\n return undefined\n }\n\n if (!collectionSlug) {\n throw new APIError(`Collection with the slug ${collectionSlug} was not found.`)\n }\n\n const { collectionConfig, Model: SubModel } = getCollection({\n adapter: payload.db as MongooseAdapter,\n collectionSlug,\n })\n\n if (i === 0) {\n const subQuery = await SubModel.buildQuery({\n locale,\n payload,\n where: {\n [subPath]: {\n [formattedOperator]: val,\n },\n },\n })\n\n const select: Record<string, boolean> = {\n _id: true,\n }\n\n let joinPath: null | string = null\n\n if (parentField.type === 'join') {\n const relationshipField = getFieldByPath({\n fields: collectionConfig.flattenedFields,\n path: parentField.on,\n })\n if (!relationshipField) {\n throw new APIError('Relationship field was not found')\n }\n\n let path = relationshipField.localizedPath\n if (relationshipField.pathHasLocalized && payload.config.localization) {\n path = path.replace('<locale>', locale || payload.config.localization.defaultLocale)\n }\n select[path] = true\n\n joinPath = path\n }\n\n if (joinPath) {\n select[joinPath] = true\n }\n\n const result = await SubModel.find(subQuery).lean().select(select)\n\n const $in: unknown[] = []\n\n result.forEach((doc: any) => {\n if (joinPath) {\n let ref = doc\n\n for (const segment of joinPath.split('.')) {\n if (Array.isArray(ref)) {\n ref = ref\n .map((item) => (typeof item === 'object' && item ? item[segment] : undefined))\n .flat()\n .filter((item) => item != null)\n } else if (typeof ref === 'object' && ref) {\n ref = ref[segment]\n } else {\n ref = undefined\n break\n }\n }\n\n if (Array.isArray(ref)) {\n for (const item of ref) {\n if (isObjectID(item)) {\n $in.push(item)\n }\n }\n } else if (isObjectID(ref)) {\n $in.push(ref)\n }\n } else {\n const stringID = doc._id.toString()\n if (Types.ObjectId.isValid(stringID)) {\n $in.push(doc._id)\n } else {\n $in.push(stringID)\n }\n }\n })\n\n if (pathsToQuery.length === 1) {\n return {\n path: joinPath ? '_id' : path,\n value: { $in },\n }\n }\n\n const nextSubPath = pathsToQuery[i + 1]?.path\n\n if (nextSubPath) {\n relationshipQuery = {\n value: joinPath ? { _id: { $in } } : { [nextSubPath]: { $in } },\n }\n }\n\n continue\n }\n\n const subQuery = relationshipQuery.value as QueryFilter<any>\n\n /**\n * Follow this join back to its parent IDs.\n * For example, matching songs yield album IDs, then artist IDs.\n */\n if (parentField.type === 'join') {\n const relationshipField = getFieldByPath({\n fields: collectionConfig.flattenedFields,\n path: parentField.on,\n })\n if (!relationshipField) {\n throw new APIError('Relationship field was not found')\n }\n\n let joinPath = relationshipField.localizedPath\n if (relationshipField.pathHasLocalized && payload.config.localization) {\n joinPath = joinPath.replace(\n '<locale>',\n locale || payload.config.localization.defaultLocale,\n )\n }\n\n const $in = await SubModel.distinct(joinPath, subQuery)\n if (i + 1 === pathsToQuery.length) {\n return { path: '_id', value: { $in } }\n }\n\n relationshipQuery = { value: { _id: { $in } } }\n continue\n }\n\n const result = await SubModel.find(subQuery, subQueryOptions)\n\n const $in = result.map((doc) => doc._id)\n\n // If it is the last recursion\n // then pass through the search param\n if (i + 1 === pathsToQuery.length) {\n relationshipQuery = {\n path,\n value: { $in },\n }\n } else {\n const nextSubPath = pathsToQuery[i + 1]?.path\n if (nextSubPath) {\n relationshipQuery = {\n value: {\n [nextSubPath]: { $in },\n },\n }\n }\n }\n }\n\n return relationshipQuery\n }\n\n if (formattedOperator && validOperatorSet.has(formattedOperator as Operator)) {\n const operatorKey = operatorMap[formattedOperator as OperatorMapKey]\n\n if (field.type === 'relationship' || field.type === 'upload') {\n let hasNumberIDRelation\n let multiIDCondition = '$or'\n if (operatorKey === '$ne') {\n multiIDCondition = '$and'\n }\n\n const result = {\n value: {\n [multiIDCondition]: [{ [path]: { [operatorKey]: formattedValue } }],\n },\n }\n\n if (typeof formattedValue === 'string') {\n if (Types.ObjectId.isValid(formattedValue)) {\n result.value[multiIDCondition]?.push({\n [path]: { [operatorKey]: new Types.ObjectId(formattedValue) },\n })\n } else {\n ;(Array.isArray(field.relationTo) ? field.relationTo : [field.relationTo]).forEach(\n (relationTo) => {\n const isRelatedToCustomNumberID =\n payload.collections[relationTo]?.customIDType === 'number'\n\n if (isRelatedToCustomNumberID) {\n hasNumberIDRelation = true\n }\n },\n )\n\n if (hasNumberIDRelation) {\n result.value[multiIDCondition]?.push({\n [path]: { [operatorKey]: parseFloat(formattedValue) },\n })\n }\n }\n }\n\n const length = result.value[multiIDCondition]?.length\n\n if (typeof length === 'number' && length > 1) {\n return result\n }\n }\n\n if (formattedOperator === 'like' && typeof formattedValue === 'string') {\n const words = formattedValue.split(' ')\n\n const result = {\n value: {\n $and: words.map((word) => ({\n [path]: {\n $options: 'i',\n $regex: escapeRegExp(word),\n },\n })),\n },\n }\n\n return result\n }\n\n if (formattedOperator === 'not_like' && typeof formattedValue === 'string') {\n const words = formattedValue.split(' ')\n\n const result = {\n value: {\n $and: words.map((word) => ({\n [path]: {\n $not: {\n $options: 'i',\n $regex: escapeRegExp(word),\n },\n },\n })),\n },\n }\n\n return result\n }\n\n // Some operators like 'near' need to define a full query\n // so if there is no operator key, just return the value\n if (!operatorKey) {\n return {\n path,\n value: formattedValue,\n }\n }\n\n return {\n path,\n value: { [operatorKey]: formattedValue },\n }\n }\n }\n return undefined\n}\n\n/**\n * Builds a MongoDB condition for an operator containing a nested has-many relationship query.\n *\n * First, it finds IDs from the related collection that match the nested query. The parent\n * collection can then use `$in` or `$nin` against its stored relationship IDs.\n *\n * @example\n * ```ts\n * // Input\n * { ingredients: { not_equals: { isHealthy: { equals: false } } } }\n *\n * // Simplified MongoDB result, after finding the matching ingredient IDs\n * { ingredients: { $nin: [unhealthyIngredientID] } }\n * ```\n */\nasync function buildHasManyRelationshipSearchParam({\n field,\n locale,\n nestedWhere,\n operator,\n path,\n payload,\n}: {\n field: FlattenedField\n locale?: string\n nestedWhere: unknown\n operator: HasManyRelationshipOperator\n path: string\n payload: Payload\n}): Promise<SearchParam | undefined> {\n if (\n (field.type !== 'relationship' && field.type !== 'upload') ||\n !field.hasMany ||\n typeof field.relationTo !== 'string' ||\n !isNestedRelationshipQuery(nestedWhere)\n ) {\n return undefined\n }\n\n const { Model: RelatedModel } = getCollection({\n adapter: payload.db as MongooseAdapter,\n collectionSlug: field.relationTo,\n })\n const pathLocale = payload.config.localization\n ? payload.config.localization.localeCodes.find(\n (localeCode) => path.split('.').at(-1) === localeCode,\n )\n : undefined\n const matchingRelatedDocumentsQuery = await RelatedModel.buildQuery({\n locale: pathLocale ?? locale,\n payload,\n where: nestedWhere,\n })\n\n const findRelatedDocumentIDs = async (query: Record<string, unknown>) =>\n (await RelatedModel.find(query).lean().select({ _id: true })).map((document) => document._id)\n\n switch (operator) {\n case 'contains': {\n const matchingRelatedDocumentIDs = await findRelatedDocumentIDs(matchingRelatedDocumentsQuery)\n\n return {\n path,\n value: { $in: matchingRelatedDocumentIDs },\n }\n }\n\n case 'equals': {\n // Every related document satisfies an empty nested query.\n if (!Object.keys(matchingRelatedDocumentsQuery).length) {\n return {\n path,\n value: { $nin: [] },\n }\n }\n\n // MongoDB rejects `$near` and `$text` when they are inverted with `$nor`. Check the parent\n // instead: none of its IDs may fall outside the matching IDs.\n const matchingRelatedDocumentIDs = await findRelatedDocumentIDs(matchingRelatedDocumentsQuery)\n\n return {\n path,\n value: { $not: { $elemMatch: { $nin: matchingRelatedDocumentIDs } } },\n }\n }\n\n case 'not_equals': {\n const matchingRelatedDocumentIDs = await findRelatedDocumentIDs(matchingRelatedDocumentsQuery)\n\n return {\n path,\n value: { $nin: matchingRelatedDocumentIDs },\n }\n }\n }\n}\n"],"names":["Types","APIError","escapeRegExp","getFieldByPath","getLocalizedPaths","hasManyRelationshipOperatorSet","isNestedRelationshipQuery","validOperatorSet","getCollection","isObjectID","operatorMap","sanitizeQueryValue","subQueryOptions","lean","buildSearchParam","collectionSlug","fields","globalSlug","incomingPath","locale","operator","parentIsLocalized","payload","val","sanitizedPath","replace","paths","hasCustomID","customIDFieldType","collections","customIDType","undefined","idFieldType","push","complete","field","name","type","path","has","length","hasMany","relationTo","buildHasManyRelationshipSearchParam","nestedWhere","sanitizedQueryValue","formattedOperator","rawQuery","formattedValue","value","pathsToQuery","slice","reverse","parentPaths","relationshipQuery","i","subPath","entries","parentField","collectionConfig","Model","SubModel","adapter","db","subQuery","buildQuery","where","select","_id","joinPath","relationshipField","flattenedFields","on","localizedPath","pathHasLocalized","config","localization","defaultLocale","result","find","$in","forEach","doc","ref","segment","split","Array","isArray","map","item","flat","filter","stringID","toString","ObjectId","isValid","nextSubPath","distinct","operatorKey","hasNumberIDRelation","multiIDCondition","isRelatedToCustomNumberID","parseFloat","words","$and","word","$options","$regex","$not","RelatedModel","pathLocale","localeCodes","localeCode","at","matchingRelatedDocumentsQuery","findRelatedDocumentIDs","query","document","matchingRelatedDocumentIDs","Object","keys","$nin","$elemMatch"],"mappings":"AASA,SAASA,KAAK,QAAQ,WAAU;AAChC,SAASC,QAAQ,EAAEC,YAAY,EAAEC,cAAc,EAAEC,iBAAiB,QAAQ,UAAS;AACnF,SACEC,8BAA8B,EAC9BC,y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ACT;IAEA,MAAMuE,yBAAyB,OAAOC,QACpC,AAAC,CAAA,MAAMP,aAAa9B,IAAI,CAACqC,OAAOvG,IAAI,GAAGsD,MAAM,CAAC;YAAEC,KAAK;QAAK,EAAC,EAAGoB,GAAG,CAAC,CAAC6B,WAAaA,SAASjD,GAAG;IAE9F,OAAQhD;QACN,KAAK;YAAY;gBACf,MAAMkG,6BAA6B,MAAMH,uBAAuBD;gBAEhE,OAAO;oBACL5E;oBACAW,OAAO;wBAAE+B,KAAKsC;oBAA2B;gBAC3C;YACF;QAEA,KAAK;YAAU;gBACb,0DAA0D;gBAC1D,IAAI,CAACC,OAAOC,IAAI,CAACN,+BAA+B1E,MAAM,EAAE;oBACtD,OAAO;wBACLF;wBACAW,OAAO;4BAAEwE,MAAM,EAAE;wBAAC;oBACpB;gBACF;gBAEA,2FAA2F;gBAC3F,8DAA8D;gBAC9D,MAAMH,6BAA6B,MAAMH,uBAAuBD;gBAEhE,OAAO;oBACL5E;oBACAW,OAAO;wBAAE2D,MAAM;4BAAEc,YAAY;gCAAED,MAAMH;4BAA2B;wBAAE;oBAAE;gBACtE;YACF;QAEA,KAAK;YAAc;gBACjB,MAAMA,6BAA6B,MAAMH,uBAAuBD;gBAEhE,OAAO;oBACL5E;oBACAW,OAAO;wBAAEwE,MAAMH;oBAA2B;gBAC5C;YACF;IACF;AACF"}
|
|
1
|
+
{"version":3,"sources":["../../src/queries/buildSearchParams.ts"],"sourcesContent":["import type { QueryFilter } from 'mongoose'\nimport type {\n FlattenedField,\n HasManyRelationshipOperator,\n Operator,\n PathToQuery,\n Payload,\n} from 'payload'\n\nimport { Types } from 'mongoose'\nimport { APIError, escapeRegExp, getFieldByPath, getLocalizedPaths } from 'payload'\nimport {\n hasManyRelationshipOperatorSet,\n isNestedRelationshipQuery,\n validOperatorSet,\n} from 'payload/shared'\n\nimport type { MongooseAdapter } from '../index.js'\nimport type { OperatorMapKey } from './operatorMap.js'\n\nimport { getCollection } from '../utilities/getEntity.js'\nimport { isObjectID } from '../utilities/isObjectID.js'\nimport { operatorMap } from './operatorMap.js'\nimport { sanitizeQueryValue } from './sanitizeQueryValue.js'\n\ntype SearchParam = {\n path?: string\n rawQuery?: unknown\n value?: unknown\n}\n\nconst subQueryOptions = {\n lean: true,\n}\n\n/**\n * Convert the Payload key / value / operator into a MongoDB query\n */\nexport async function buildSearchParam({\n collectionSlug,\n fields,\n globalSlug,\n incomingPath,\n locale,\n operator,\n parentIsLocalized,\n payload,\n val,\n}: {\n collectionSlug?: string\n fields: FlattenedField[]\n globalSlug?: string\n incomingPath: string\n locale?: string\n operator: Operator\n parentIsLocalized: boolean\n payload: Payload\n val: unknown\n}): Promise<SearchParam | undefined> {\n // Replace GraphQL nested field double underscore formatting\n let sanitizedPath = incomingPath.replace(/__/g, '.')\n if (sanitizedPath === 'id') {\n sanitizedPath = '_id'\n }\n\n let paths: PathToQuery[] = []\n\n let hasCustomID = false\n\n if (sanitizedPath === '_id') {\n const customIDFieldType = collectionSlug\n ? payload.collections[collectionSlug]?.customIDType\n : undefined\n\n let idFieldType: 'number' | 'text' = 'text'\n\n if (customIDFieldType) {\n idFieldType = customIDFieldType\n hasCustomID = true\n }\n\n paths.push({\n collectionSlug,\n complete: true,\n field: {\n name: 'id',\n type: idFieldType,\n } as FlattenedField,\n parentIsLocalized: parentIsLocalized ?? false,\n path: '_id',\n })\n } else {\n paths = getLocalizedPaths({\n collectionSlug,\n fields,\n globalSlug,\n incomingPath: sanitizedPath,\n locale,\n parentIsLocalized,\n payload,\n })\n }\n\n if (!paths[0]) {\n return undefined\n }\n\n const [{ field, path }] = paths\n\n if (\n hasManyRelationshipOperatorSet.has(operator as HasManyRelationshipOperator) &&\n paths.length === 1 &&\n (field.type === 'relationship' || field.type === 'upload') &&\n field.hasMany &&\n typeof field.relationTo === 'string' &&\n isNestedRelationshipQuery(val)\n ) {\n return buildHasManyRelationshipSearchParam({\n field,\n locale,\n nestedWhere: val,\n operator: operator as HasManyRelationshipOperator,\n path,\n payload,\n })\n }\n\n if (\n operator === 'contains' &&\n paths.length === 1 &&\n field.type === 'join' &&\n typeof field.collection === 'string' &&\n isNestedRelationshipQuery(val)\n ) {\n return buildJoinContainsSearchParam({\n field,\n locale,\n nestedWhere: val,\n payload,\n })\n }\n\n if (\n (operator === 'contains' || operator === 'like' || operator === 'not_like') &&\n (isNestedRelationshipQuery(val) ||\n (Array.isArray(val) && val.some((entry) => isNestedRelationshipQuery(entry))))\n ) {\n throw new APIError(`Invalid value for \"${operator}\" on path \"${path}\": expected a string.`, 400)\n }\n\n if (path) {\n const sanitizedQueryValue = sanitizeQueryValue({\n field,\n hasCustomID,\n locale,\n operator,\n parentIsLocalized,\n path,\n payload,\n val,\n })\n\n if (!sanitizedQueryValue) {\n return undefined\n }\n\n const { operator: formattedOperator, rawQuery, val: formattedValue } = sanitizedQueryValue\n\n if (rawQuery && paths.length === 1) {\n return { value: rawQuery }\n }\n\n if (!formattedOperator) {\n return undefined\n }\n\n // If there are multiple collections to search through,\n // Recursively build up a list of query constraints\n if (paths.length > 1) {\n // Remove top collection and reverse array\n // to work backwards from top\n const pathsToQuery = paths.slice(1).reverse()\n const parentPaths = paths.slice(0, -1).reverse()\n\n let relationshipQuery: SearchParam = {\n value: {},\n }\n\n for (const [i, { collectionSlug, path: subPath }] of pathsToQuery.entries()) {\n // The arrays are reversed together, so both entries describe the same relationship hop.\n const parentField = parentPaths[i]?.field\n\n if (!parentField) {\n return undefined\n }\n\n if (!collectionSlug) {\n throw new APIError(`Collection with the slug ${collectionSlug} was not found.`)\n }\n\n const { collectionConfig, Model: SubModel } = getCollection({\n adapter: payload.db as MongooseAdapter,\n collectionSlug,\n })\n\n if (i === 0) {\n const subQuery = await SubModel.buildQuery({\n locale,\n payload,\n where: {\n [subPath]: {\n [formattedOperator]: val,\n },\n },\n })\n\n const select: Record<string, boolean> = {\n _id: true,\n }\n\n let joinPath: null | string = null\n\n if (parentField.type === 'join') {\n const relationshipField = getFieldByPath({\n fields: collectionConfig.flattenedFields,\n path: parentField.on,\n })\n if (!relationshipField) {\n throw new APIError('Relationship field was not found')\n }\n\n let path = relationshipField.localizedPath\n if (relationshipField.pathHasLocalized && payload.config.localization) {\n path = path.replace('<locale>', locale || payload.config.localization.defaultLocale)\n }\n select[path] = true\n\n joinPath = path\n }\n\n if (joinPath) {\n select[joinPath] = true\n }\n\n const result = await SubModel.find(subQuery).lean().select(select)\n\n const $in: unknown[] = []\n\n result.forEach((doc: any) => {\n if (joinPath) {\n let ref = doc\n\n for (const segment of joinPath.split('.')) {\n if (Array.isArray(ref)) {\n ref = ref\n .map((item) => (typeof item === 'object' && item ? item[segment] : undefined))\n .flat()\n .filter((item) => item != null)\n } else if (typeof ref === 'object' && ref) {\n ref = ref[segment]\n } else {\n ref = undefined\n break\n }\n }\n\n if (Array.isArray(ref)) {\n for (const item of ref) {\n if (isObjectID(item)) {\n $in.push(item)\n }\n }\n } else if (isObjectID(ref)) {\n $in.push(ref)\n }\n } else {\n const stringID = doc._id.toString()\n if (Types.ObjectId.isValid(stringID)) {\n $in.push(doc._id)\n } else {\n $in.push(stringID)\n }\n }\n })\n\n if (pathsToQuery.length === 1) {\n return {\n path: joinPath ? '_id' : path,\n value: { $in },\n }\n }\n\n const nextSubPath = pathsToQuery[i + 1]?.path\n\n if (nextSubPath) {\n relationshipQuery = {\n value: joinPath ? { _id: { $in } } : { [nextSubPath]: { $in } },\n }\n }\n\n continue\n }\n\n const subQuery = relationshipQuery.value as QueryFilter<any>\n\n /**\n * Follow this join back to its parent IDs.\n * For example, matching songs yield album IDs, then artist IDs.\n */\n if (parentField.type === 'join') {\n const relationshipField = getFieldByPath({\n fields: collectionConfig.flattenedFields,\n path: parentField.on,\n })\n if (!relationshipField) {\n throw new APIError('Relationship field was not found')\n }\n\n let joinPath = relationshipField.localizedPath\n if (relationshipField.pathHasLocalized && payload.config.localization) {\n joinPath = joinPath.replace(\n '<locale>',\n locale || payload.config.localization.defaultLocale,\n )\n }\n\n const $in = await SubModel.distinct(joinPath, subQuery)\n if (i + 1 === pathsToQuery.length) {\n return { path: '_id', value: { $in } }\n }\n\n relationshipQuery = { value: { _id: { $in } } }\n continue\n }\n\n const result = await SubModel.find(subQuery, subQueryOptions)\n\n const $in = result.map((doc) => doc._id)\n\n // If it is the last recursion\n // then pass through the search param\n if (i + 1 === pathsToQuery.length) {\n relationshipQuery = {\n path,\n value: { $in },\n }\n } else {\n const nextSubPath = pathsToQuery[i + 1]?.path\n if (nextSubPath) {\n relationshipQuery = {\n value: {\n [nextSubPath]: { $in },\n },\n }\n }\n }\n }\n\n return relationshipQuery\n }\n\n if (formattedOperator && validOperatorSet.has(formattedOperator as Operator)) {\n const operatorKey = operatorMap[formattedOperator as OperatorMapKey]\n\n if (field.type === 'relationship' || field.type === 'upload') {\n let hasNumberIDRelation\n let multiIDCondition = '$or'\n if (operatorKey === '$ne') {\n multiIDCondition = '$and'\n }\n\n const result = {\n value: {\n [multiIDCondition]: [{ [path]: { [operatorKey]: formattedValue } }],\n },\n }\n\n if (typeof formattedValue === 'string') {\n if (Types.ObjectId.isValid(formattedValue)) {\n result.value[multiIDCondition]?.push({\n [path]: { [operatorKey]: new Types.ObjectId(formattedValue) },\n })\n } else {\n ;(Array.isArray(field.relationTo) ? field.relationTo : [field.relationTo]).forEach(\n (relationTo) => {\n const isRelatedToCustomNumberID =\n payload.collections[relationTo]?.customIDType === 'number'\n\n if (isRelatedToCustomNumberID) {\n hasNumberIDRelation = true\n }\n },\n )\n\n if (hasNumberIDRelation) {\n result.value[multiIDCondition]?.push({\n [path]: { [operatorKey]: parseFloat(formattedValue) },\n })\n }\n }\n }\n\n const length = result.value[multiIDCondition]?.length\n\n if (typeof length === 'number' && length > 1) {\n return result\n }\n }\n\n if (formattedOperator === 'like' && typeof formattedValue === 'string') {\n const words = formattedValue.split(' ')\n\n const result = {\n value: {\n $and: words.map((word) => ({\n [path]: {\n $options: 'i',\n $regex: escapeRegExp(word),\n },\n })),\n },\n }\n\n return result\n }\n\n if (formattedOperator === 'not_like' && typeof formattedValue === 'string') {\n const words = formattedValue.split(' ')\n\n const result = {\n value: {\n $and: words.map((word) => ({\n [path]: {\n $not: {\n $options: 'i',\n $regex: escapeRegExp(word),\n },\n },\n })),\n },\n }\n\n return result\n }\n\n // Some operators like 'near' need to define a full query\n // so if there is no operator key, just return the value\n if (!operatorKey) {\n return {\n path,\n value: formattedValue,\n }\n }\n\n return {\n path,\n value: { [operatorKey]: formattedValue },\n }\n }\n }\n return undefined\n}\n\n/**\n * Builds a MongoDB condition for an operator containing a nested has-many relationship query.\n *\n * First, it finds IDs from the related collection that match the nested query. The parent\n * collection can then use `$in` or `$nin` against its stored relationship IDs.\n *\n * @example\n * ```ts\n * // Input\n * { ingredients: { not_equals: { isHealthy: { equals: false } } } }\n *\n * // Simplified MongoDB result, after finding the matching ingredient IDs\n * { ingredients: { $nin: [unhealthyIngredientID] } }\n * ```\n */\nasync function buildHasManyRelationshipSearchParam({\n field,\n locale,\n nestedWhere,\n operator,\n path,\n payload,\n}: {\n field: FlattenedField\n locale?: string\n nestedWhere: unknown\n operator: HasManyRelationshipOperator\n path: string\n payload: Payload\n}): Promise<SearchParam | undefined> {\n if (\n (field.type !== 'relationship' && field.type !== 'upload') ||\n !field.hasMany ||\n typeof field.relationTo !== 'string' ||\n !isNestedRelationshipQuery(nestedWhere)\n ) {\n return undefined\n }\n\n const { Model: RelatedModel } = getCollection({\n adapter: payload.db as MongooseAdapter,\n collectionSlug: field.relationTo,\n })\n const pathLocale = payload.config.localization\n ? payload.config.localization.localeCodes.find(\n (localeCode) => path.split('.').at(-1) === localeCode,\n )\n : undefined\n const matchingRelatedDocumentsQuery = await RelatedModel.buildQuery({\n locale: pathLocale ?? locale,\n payload,\n where: nestedWhere,\n })\n\n const findRelatedDocumentIDs = async (query: Record<string, unknown>) =>\n (await RelatedModel.find(query).lean().select({ _id: true })).map((document) => document._id)\n\n switch (operator) {\n case 'contains': {\n const matchingRelatedDocumentIDs = await findRelatedDocumentIDs(matchingRelatedDocumentsQuery)\n\n return {\n path,\n value: { $in: matchingRelatedDocumentIDs },\n }\n }\n\n case 'equals': {\n // Every related document satisfies an empty nested query.\n if (!Object.keys(matchingRelatedDocumentsQuery).length) {\n return {\n path,\n value: { $nin: [] },\n }\n }\n\n // MongoDB rejects `$near` and `$text` when they are inverted with `$nor`. Check the parent\n // instead: none of its IDs may fall outside the matching IDs.\n const matchingRelatedDocumentIDs = await findRelatedDocumentIDs(matchingRelatedDocumentsQuery)\n\n return {\n path,\n value: { $not: { $elemMatch: { $nin: matchingRelatedDocumentIDs } } },\n }\n }\n\n case 'not_equals': {\n const matchingRelatedDocumentIDs = await findRelatedDocumentIDs(matchingRelatedDocumentsQuery)\n\n return {\n path,\n value: { $nin: matchingRelatedDocumentIDs },\n }\n }\n }\n}\n\n/**\n * Builds a MongoDB condition for a `contains` query nested on a join field.\n *\n * Finds documents in the joined collection that match the nested query, then follows the join's\n * `on` relationship to collect the parent IDs those documents point back to. Because the nested\n * query resolves against a single joined document, the user's filter and any injected access\n * constraint must be satisfied by the same document.\n */\nasync function buildJoinContainsSearchParam({\n field,\n locale,\n nestedWhere,\n payload,\n}: {\n field: FlattenedField\n locale?: string\n nestedWhere: unknown\n payload: Payload\n}): Promise<SearchParam | undefined> {\n if (\n field.type !== 'join' ||\n typeof field.collection !== 'string' ||\n !isNestedRelationshipQuery(nestedWhere)\n ) {\n return undefined\n }\n\n const { collectionConfig, Model: JoinedModel } = getCollection({\n adapter: payload.db as MongooseAdapter,\n collectionSlug: field.collection,\n })\n\n const relationshipField = getFieldByPath({\n fields: collectionConfig.flattenedFields,\n path: field.on,\n })\n\n if (!relationshipField) {\n throw new APIError('Relationship field was not found')\n }\n\n let joinPath = relationshipField.localizedPath\n if (relationshipField.pathHasLocalized && payload.config.localization) {\n joinPath = joinPath.replace('<locale>', locale || payload.config.localization.defaultLocale)\n }\n\n const subQuery = await JoinedModel.buildQuery({\n locale,\n payload,\n where: nestedWhere,\n })\n\n const parentIDs = await JoinedModel.distinct(joinPath, subQuery)\n\n return {\n path: '_id',\n value: { $in: parentIDs },\n }\n}\n"],"names":["Types","APIError","escapeRegExp","getFieldByPath","getLocalizedPaths","hasManyRelationshipOperatorSet","isNestedRelationshipQuery","validOperatorSet","getCollection","isObjectID","operatorMap","sanitizeQueryValue","subQueryOptions","lean","buildSearchParam","collectionSlug","fields","globalSlug","incomingPath","locale","operator","parentIsLocalized","payload","val","sanitizedPath","replace","paths","hasCustomID","customIDFieldType","collections","customIDType","undefined","idFieldType","push","complete","field","name","type","path","has","length","hasMany","relationTo","buildHasManyRelationshipSearchParam","nestedWhere","collection","buildJoinContainsSearchParam","Array","isArray","some","entry","sanitizedQueryValue","formattedOperator","rawQuery","formattedValue","value","pathsToQuery","slice","reverse","parentPaths","relationshipQuery","i","subPath","entries","parentField","collectionConfig","Model","SubModel","adapter","db","subQuery","buildQuery","where","select","_id","joinPath","relationshipField","flattenedFields","on","localizedPath","pathHasLocalized","config","localization","defaultLocale","result","find","$in","forEach","doc","ref","segment","split","map","item","flat","filter","stringID","toString","ObjectId","isValid","nextSubPath","distinct","operatorKey","hasNumberIDRelation","multiIDCondition","isRelatedToCustomNumberID","parseFloat","words","$and","word","$options","$regex","$not","RelatedModel","pathLocale","localeCodes","localeCode","at","matchingRelatedDocumentsQuery","findRelatedDocumentIDs","query","document","matchingRelatedDocumentIDs","Object","keys","$nin","$elemMatch","JoinedModel","parentIDs"],"mappings":"AASA,SAASA,KAAK,QAAQ,WAAU;AAChC,SAASC,QAAQ,EAAEC,YAAY,EAAEC,cAAc,EAAEC,iBAAiB,QAAQ,UAAS;AACnF,SACEC,8BAA8B,EAC9BC,yBAAyB,EACzBC,gBAAgB,QACX,iBAAgB;AAKvB,SAASC,aAAa,QAAQ,4BAA2B;AACzD,SAASC,UAAU,QAAQ,6BAA4B;AACvD,SAASC,WAAW,QAAQ,mBAAkB;AAC9C,SAASC,kBAAkB,QAAQ,0BAAyB;AAQ5D,MAAMC,kBAAkB;IACtBC,MA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B,OAAO,EAMR;IACC,IACEa,MAAME,IAAI,KAAK,UACf,OAAOF,MAAMU,UAAU,KAAK,YAC5B,CAACvC,0BAA0BsC,cAC3B;QACA,OAAOb;IACT;IAEA,MAAM,EAAEkC,gBAAgB,EAAEC,OAAO6D,WAAW,EAAE,GAAGvH,cAAc;QAC7D4D,SAAS9C,QAAQ+C,EAAE;QACnBtD,gBAAgBoB,MAAMU,UAAU;IAClC;IAEA,MAAM+B,oBAAoBzE,eAAe;QACvCa,QAAQiD,iBAAiBY,eAAe;QACxCvC,MAAMH,MAAM2C,EAAE;IAChB;IAEA,IAAI,CAACF,mBAAmB;QACtB,MAAM,IAAI3E,SAAS;IACrB;IAEA,IAAI0E,WAAWC,kBAAkBG,aAAa;IAC9C,IAAIH,kBAAkBI,gBAAgB,IAAI1D,QAAQ2D,MAAM,CAACC,YAAY,EAAE;QACrEP,WAAWA,SAASlD,OAAO,CAAC,YAAYN,UAAUG,QAAQ2D,MAAM,CAACC,YAAY,CAACC,aAAa;IAC7F;IAEA,MAAMb,WAAW,MAAMyD,YAAYxD,UAAU,CAAC;QAC5CpD;QACAG;QACAkD,OAAO5B;IACT;IAEA,MAAMoF,YAAY,MAAMD,YAAY1B,QAAQ,CAAC1B,UAAUL;IAEvD,OAAO;QACLhC,MAAM;QACNiB,OAAO;YAAE+B,KAAK0C;QAAU;IAC1B;AACF"}
|
package/dist/updateGlobal.js
CHANGED
|
@@ -24,12 +24,12 @@ export const updateGlobal = async function updateGlobal({ slug: globalSlug, data
|
|
|
24
24
|
const findOptions = {
|
|
25
25
|
...baseOptions,
|
|
26
26
|
lean: true,
|
|
27
|
-
new: true,
|
|
28
27
|
projection: buildProjectionFromSelect({
|
|
29
28
|
adapter: this,
|
|
30
29
|
fields: globalConfig.flattenedFields,
|
|
31
30
|
select
|
|
32
|
-
})
|
|
31
|
+
}),
|
|
32
|
+
returnDocument: 'after'
|
|
33
33
|
};
|
|
34
34
|
if (returning === false) {
|
|
35
35
|
await Model.updateOne({
|
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 { getGlobal } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\nimport { transform } from './utilities/transform.js'\n\nexport const updateGlobal: UpdateGlobal = async function updateGlobal(\n this: MongooseAdapter,\n { slug: globalSlug, data, options: optionsArgs = {}, req, returning, select },\n) {\n const { globalConfig, Model } = getGlobal({ adapter: this, globalSlug })\n\n const fields = globalConfig.fields\n\n transform({ adapter: this, data, fields, globalSlug, operation: 'write' })\n\n const baseOptions = {\n ...optionsArgs,\n session: await getSession(this, req),\n // Timestamps are manually added by the write transform\n timestamps: false,\n } satisfies QueryOptions\n\n const findOptions: QueryOptions = {\n ...baseOptions,\n lean: true,\n
|
|
1
|
+
{"version":3,"sources":["../src/updateGlobal.ts"],"sourcesContent":["import type { QueryOptions } from 'mongoose'\nimport type { UpdateGlobal } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getGlobal } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\nimport { transform } from './utilities/transform.js'\n\nexport const updateGlobal: UpdateGlobal = async function updateGlobal(\n this: MongooseAdapter,\n { slug: globalSlug, data, options: optionsArgs = {}, req, returning, select },\n) {\n const { globalConfig, Model } = getGlobal({ adapter: this, globalSlug })\n\n const fields = globalConfig.fields\n\n transform({ adapter: this, data, fields, globalSlug, operation: 'write' })\n\n const baseOptions = {\n ...optionsArgs,\n session: await getSession(this, req),\n // Timestamps are manually added by the write transform\n timestamps: false,\n } satisfies QueryOptions\n\n const findOptions: QueryOptions = {\n ...baseOptions,\n lean: true,\n projection: buildProjectionFromSelect({\n adapter: this,\n fields: globalConfig.flattenedFields,\n select,\n }),\n returnDocument: 'after',\n }\n\n if (returning === false) {\n await Model.updateOne({ globalType: globalSlug }, data, baseOptions)\n return null\n }\n\n const result: any = await Model.findOneAndUpdate({ globalType: globalSlug }, data, findOptions)\n\n transform({ adapter: this, data: result, fields, globalSlug, operation: 'read' })\n\n return result\n}\n"],"names":["buildProjectionFromSelect","getGlobal","getSession","transform","updateGlobal","slug","globalSlug","data","options","optionsArgs","req","returning","select","globalConfig","Model","adapter","fields","operation","baseOptions","session","timestamps","findOptions","lean","projection","flattenedFields","returnDocument","updateOne","globalType","result","findOneAndUpdate"],"mappings":"AAKA,SAASA,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,SAAS,QAAQ,2BAA0B;AACpD,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAASC,SAAS,QAAQ,2BAA0B;AAEpD,OAAO,MAAMC,eAA6B,eAAeA,aAEvD,EAAEC,MAAMC,UAAU,EAAEC,IAAI,EAAEC,SAASC,cAAc,CAAC,CAAC,EAAEC,GAAG,EAAEC,SAAS,EAAEC,MAAM,EAAE;IAE7E,MAAM,EAAEC,YAAY,EAAEC,KAAK,EAAE,GAAGb,UAAU;QAAEc,SAAS,IAAI;QAAET;IAAW;IAEtE,MAAMU,SAASH,aAAaG,MAAM;IAElCb,UAAU;QAAEY,SAAS,IAAI;QAAER;QAAMS;QAAQV;QAAYW,WAAW;IAAQ;IAExE,MAAMC,cAAc;QAClB,GAAGT,WAAW;QACdU,SAAS,MAAMjB,WAAW,IAAI,EAAEQ;QAChC,uDAAuD;QACvDU,YAAY;IACd;IAEA,MAAMC,cAA4B;QAChC,GAAGH,WAAW;QACdI,MAAM;QACNC,YAAYvB,0BAA0B;YACpCe,SAAS,IAAI;YACbC,QAAQH,aAAaW,eAAe;YACpCZ;QACF;QACAa,gBAAgB;IAClB;IAEA,IAAId,cAAc,OAAO;QACvB,MAAMG,MAAMY,SAAS,CAAC;YAAEC,YAAYrB;QAAW,GAAGC,MAAMW;QACxD,OAAO;IACT;IAEA,MAAMU,SAAc,MAAMd,MAAMe,gBAAgB,CAAC;QAAEF,YAAYrB;IAAW,GAAGC,MAAMc;IAEnFlB,UAAU;QAAEY,SAAS,IAAI;QAAER,MAAMqB;QAAQZ;QAAQV;QAAYW,WAAW;IAAO;IAE/E,OAAOW;AACT,EAAC"}
|
|
@@ -38,12 +38,12 @@ export async function updateGlobalVersion({ id, global: globalSlug, locale, opti
|
|
|
38
38
|
const findOptions = {
|
|
39
39
|
...baseOptions,
|
|
40
40
|
lean: true,
|
|
41
|
-
new: true,
|
|
42
41
|
projection: buildProjectionFromSelect({
|
|
43
42
|
adapter: this,
|
|
44
43
|
fields: flattenedFields,
|
|
45
44
|
select
|
|
46
|
-
})
|
|
45
|
+
}),
|
|
46
|
+
returnDocument: 'after'
|
|
47
47
|
};
|
|
48
48
|
if (returning === false) {
|
|
49
49
|
await Model.updateOne(query, versionData, baseOptions);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/updateGlobalVersion.ts"],"sourcesContent":["import type { QueryOptions } from 'mongoose'\nimport type { JsonObject, UpdateGlobalVersionArgs } from 'payload'\n\nimport { buildVersionGlobalFields } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getGlobal } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\nimport { transform } from './utilities/transform.js'\n\nexport async function updateGlobalVersion<T extends JsonObject = JsonObject>(\n this: MongooseAdapter,\n {\n id,\n global: globalSlug,\n locale,\n options: optionsArgs = {},\n req,\n returning,\n select,\n versionData,\n where,\n }: UpdateGlobalVersionArgs<T>,\n) {\n const { globalConfig, Model } = getGlobal({ adapter: this, globalSlug, versions: true })\n const whereToUse = where || { id: { equals: id } }\n\n const fields = buildVersionGlobalFields(this.payload.config, globalConfig)\n const flattenedFields = buildVersionGlobalFields(this.payload.config, globalConfig, true)\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 baseOptions = {\n ...optionsArgs,\n session: await getSession(this, req),\n // Timestamps are manually added by the write transform\n timestamps: false,\n } satisfies QueryOptions\n\n const findOptions: QueryOptions = {\n ...baseOptions,\n lean: true,\n
|
|
1
|
+
{"version":3,"sources":["../src/updateGlobalVersion.ts"],"sourcesContent":["import type { QueryOptions } from 'mongoose'\nimport type { JsonObject, UpdateGlobalVersionArgs } from 'payload'\n\nimport { buildVersionGlobalFields } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getGlobal } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\nimport { transform } from './utilities/transform.js'\n\nexport async function updateGlobalVersion<T extends JsonObject = JsonObject>(\n this: MongooseAdapter,\n {\n id,\n global: globalSlug,\n locale,\n options: optionsArgs = {},\n req,\n returning,\n select,\n versionData,\n where,\n }: UpdateGlobalVersionArgs<T>,\n) {\n const { globalConfig, Model } = getGlobal({ adapter: this, globalSlug, versions: true })\n const whereToUse = where || { id: { equals: id } }\n\n const fields = buildVersionGlobalFields(this.payload.config, globalConfig)\n const flattenedFields = buildVersionGlobalFields(this.payload.config, globalConfig, true)\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 baseOptions = {\n ...optionsArgs,\n session: await getSession(this, req),\n // Timestamps are manually added by the write transform\n timestamps: false,\n } satisfies QueryOptions\n\n const findOptions: QueryOptions = {\n ...baseOptions,\n lean: true,\n projection: buildProjectionFromSelect({\n adapter: this,\n fields: flattenedFields,\n select,\n }),\n returnDocument: 'after',\n }\n\n if (returning === false) {\n await Model.updateOne(query, versionData, baseOptions)\n return null\n }\n\n const doc = await Model.findOneAndUpdate(query, versionData, findOptions)\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","getGlobal","getSession","transform","updateGlobalVersion","id","global","globalSlug","locale","options","optionsArgs","req","returning","select","versionData","where","globalConfig","Model","adapter","versions","whereToUse","equals","fields","payload","config","flattenedFields","query","data","operation","baseOptions","session","timestamps","findOptions","lean","projection","returnDocument","updateOne","doc","findOneAndUpdate"],"mappings":"AAGA,SAASA,wBAAwB,QAAQ,UAAS;AAIlD,SAASC,UAAU,QAAQ,0BAAyB;AACpD,SAASC,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,SAAS,QAAQ,2BAA0B;AACpD,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,SAAS,EACTC,MAAM,EACNC,WAAW,EACXC,KAAK,EACsB;IAE7B,MAAM,EAAEC,YAAY,EAAEC,KAAK,EAAE,GAAGhB,UAAU;QAAEiB,SAAS,IAAI;QAAEX;QAAYY,UAAU;IAAK;IACtF,MAAMC,aAAaL,SAAS;QAAEV,IAAI;YAAEgB,QAAQhB;QAAG;IAAE;IAEjD,MAAMiB,SAASxB,yBAAyB,IAAI,CAACyB,OAAO,CAACC,MAAM,EAAER;IAC7D,MAAMS,kBAAkB3B,yBAAyB,IAAI,CAACyB,OAAO,CAACC,MAAM,EAAER,cAAc;IAEpF,MAAMU,QAAQ,MAAM3B,WAAW;QAC7BmB,SAAS,IAAI;QACbI,QAAQG;QACRjB;QACAO,OAAOK;IACT;IAEAjB,UAAU;QAAEe,SAAS,IAAI;QAAES,MAAMb;QAAaQ;QAAQM,WAAW;IAAQ;IAEzE,MAAMC,cAAc;QAClB,GAAGnB,WAAW;QACdoB,SAAS,MAAM5B,WAAW,IAAI,EAAES;QAChC,uDAAuD;QACvDoB,YAAY;IACd;IAEA,MAAMC,cAA4B;QAChC,GAAGH,WAAW;QACdI,MAAM;QACNC,YAAYlC,0BAA0B;YACpCkB,SAAS,IAAI;YACbI,QAAQG;YACRZ;QACF;QACAsB,gBAAgB;IAClB;IAEA,IAAIvB,cAAc,OAAO;QACvB,MAAMK,MAAMmB,SAAS,CAACV,OAAOZ,aAAae;QAC1C,OAAO;IACT;IAEA,MAAMQ,MAAM,MAAMpB,MAAMqB,gBAAgB,CAACZ,OAAOZ,aAAakB;IAE7D,IAAI,CAACK,KAAK;QACR,OAAO;IACT;IAEAlC,UAAU;QAAEe,SAAS,IAAI;QAAES,MAAMU;QAAKf;QAAQM,WAAW;IAAO;IAEhE,OAAOS;AACT"}
|
package/dist/updateJobs.js
CHANGED
package/dist/updateJobs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/updateJobs.ts"],"sourcesContent":["import type { QueryOptions, UpdateQuery } from 'mongoose'\nimport type { Job, UpdateJobs, Where } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { buildSortParam } from './queries/buildSortParam.js'\nimport { getCollection } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\nimport { handleError } from './utilities/handleError.js'\nimport { transform } from './utilities/transform.js'\n\nexport const updateJobs: UpdateJobs = async function updateMany(\n this: MongooseAdapter,\n { id, data, limit, req, returning, sort: sortArg, where: whereArg },\n) {\n if (\n !(data?.log as object[])?.length &&\n !(data.log && typeof data.log === 'object' && '$push' in data.log)\n ) {\n delete data.log\n }\n\n const where = id ? { id: { equals: id } } : (whereArg as Where)\n\n const { collectionConfig, Model } = getCollection({\n adapter: this,\n collectionSlug: 'payload-jobs',\n })\n\n const sort: Record<string, unknown> | undefined = buildSortParam({\n adapter: this,\n config: this.payload.config,\n fields: collectionConfig.flattenedFields,\n sort: sortArg || collectionConfig.defaultSort,\n timestamps: true,\n })\n\n const query = await buildQuery({\n adapter: this,\n collectionSlug: collectionConfig.slug,\n fields: collectionConfig.flattenedFields,\n where,\n })\n\n let updateData: UpdateQuery<any> = data\n\n const $inc: Record<string, number> = {}\n const $push: Record<string, { $each: any[] } | any> = {}\n const $addToSet: Record<string, { $each: any[] } | any> = {}\n const $pull: Record<string, { $in: any[] } | any> = {}\n\n transform({\n $addToSet,\n $inc,\n $pull,\n $push,\n adapter: this,\n data,\n fields: collectionConfig.fields,\n operation: 'write',\n })\n\n const updateOps: UpdateQuery<any> = {}\n\n if (Object.keys($inc).length) {\n updateOps.$inc = $inc\n }\n if (Object.keys($push).length) {\n updateOps.$push = $push\n }\n if (Object.keys($addToSet).length) {\n updateOps.$addToSet = $addToSet\n }\n if (Object.keys($pull).length) {\n updateOps.$pull = $pull\n }\n if (Object.keys(updateOps).length) {\n updateOps.$set = updateData\n updateData = updateOps\n }\n\n const baseOptions = {\n session: await getSession(this, req),\n // Timestamps are manually added by the write transform\n timestamps: false,\n } satisfies QueryOptions\n\n const findOptions: QueryOptions = {\n ...baseOptions,\n lean: true,\n
|
|
1
|
+
{"version":3,"sources":["../src/updateJobs.ts"],"sourcesContent":["import type { QueryOptions, UpdateQuery } from 'mongoose'\nimport type { Job, UpdateJobs, Where } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { buildSortParam } from './queries/buildSortParam.js'\nimport { getCollection } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\nimport { handleError } from './utilities/handleError.js'\nimport { transform } from './utilities/transform.js'\n\nexport const updateJobs: UpdateJobs = async function updateMany(\n this: MongooseAdapter,\n { id, data, limit, req, returning, sort: sortArg, where: whereArg },\n) {\n if (\n !(data?.log as object[])?.length &&\n !(data.log && typeof data.log === 'object' && '$push' in data.log)\n ) {\n delete data.log\n }\n\n const where = id ? { id: { equals: id } } : (whereArg as Where)\n\n const { collectionConfig, Model } = getCollection({\n adapter: this,\n collectionSlug: 'payload-jobs',\n })\n\n const sort: Record<string, unknown> | undefined = buildSortParam({\n adapter: this,\n config: this.payload.config,\n fields: collectionConfig.flattenedFields,\n sort: sortArg || collectionConfig.defaultSort,\n timestamps: true,\n })\n\n const query = await buildQuery({\n adapter: this,\n collectionSlug: collectionConfig.slug,\n fields: collectionConfig.flattenedFields,\n where,\n })\n\n let updateData: UpdateQuery<any> = data\n\n const $inc: Record<string, number> = {}\n const $push: Record<string, { $each: any[] } | any> = {}\n const $addToSet: Record<string, { $each: any[] } | any> = {}\n const $pull: Record<string, { $in: any[] } | any> = {}\n\n transform({\n $addToSet,\n $inc,\n $pull,\n $push,\n adapter: this,\n data,\n fields: collectionConfig.fields,\n operation: 'write',\n })\n\n const updateOps: UpdateQuery<any> = {}\n\n if (Object.keys($inc).length) {\n updateOps.$inc = $inc\n }\n if (Object.keys($push).length) {\n updateOps.$push = $push\n }\n if (Object.keys($addToSet).length) {\n updateOps.$addToSet = $addToSet\n }\n if (Object.keys($pull).length) {\n updateOps.$pull = $pull\n }\n if (Object.keys(updateOps).length) {\n updateOps.$set = updateData\n updateData = updateOps\n }\n\n const baseOptions = {\n session: await getSession(this, req),\n // Timestamps are manually added by the write transform\n timestamps: false,\n } satisfies QueryOptions\n\n const findOptions: QueryOptions = {\n ...baseOptions,\n lean: true,\n returnDocument: 'after',\n }\n\n let result: Job[] = []\n\n try {\n if (id) {\n if (returning === false) {\n await Model.updateOne(query, updateData, baseOptions)\n transform({ adapter: this, data, fields: collectionConfig.fields, operation: 'read' })\n\n return null\n } else {\n const doc = await Model.findOneAndUpdate(query, updateData, findOptions)\n result = doc ? [doc] : []\n }\n } else if (limit === 1) {\n /**\n * Select, update, and return one job atomically in a single database call.\n * We can only do this with limit === 1, which can be expressed as findOne.\n */\n const doc = await Model.findOneAndUpdate(query, updateData, {\n ...findOptions,\n projection: returning === false ? { _id: 1 } : undefined,\n sort,\n })\n\n if (returning === false) {\n return null\n }\n\n result = doc ? [doc] : []\n } else if (typeof limit === 'number' && limit > 1) {\n const candidates = await Model.find(\n query,\n {},\n { ...findOptions, limit, projection: { _id: 1 }, sort },\n )\n\n if (candidates.length === 0) {\n return null\n }\n\n const candidateIDs = candidates.map((candidate) => candidate._id)\n\n if (typeof data.processingToken === 'string') {\n /**\n * `processingToken` identifies this claim update. `processing: true` cannot, because every\n * worker writes the same value. The token lets us reliably find the jobs this update won.\n */\n const claimQuery = {\n $and: [query, { _id: { $in: candidateIDs } }],\n }\n\n await Model.updateMany(claimQuery, updateData, baseOptions)\n\n if (returning === false) {\n return null\n }\n\n const claimedJobsQuery = {\n _id: { $in: candidateIDs },\n processingToken: { $eq: data.processingToken },\n }\n\n result = await Model.find(claimedJobsQuery, {}, { ...findOptions, sort })\n } else {\n const limitedUpdateQuery = { _id: { $in: candidateIDs } }\n\n await Model.updateMany(limitedUpdateQuery, updateData, baseOptions)\n\n if (returning === false) {\n return null\n }\n\n result = await Model.find(limitedUpdateQuery, {}, { ...findOptions, sort })\n }\n } else {\n await Model.updateMany(query, updateData, baseOptions)\n\n if (returning === false) {\n return null\n }\n\n result = await Model.find(query, {}, { ...findOptions, sort })\n }\n } catch (error) {\n handleError({ collection: collectionConfig.slug, error, req })\n }\n\n transform({\n adapter: this,\n data: result,\n fields: collectionConfig.fields,\n operation: 'read',\n })\n\n return result\n}\n"],"names":["buildQuery","buildSortParam","getCollection","getSession","handleError","transform","updateJobs","updateMany","id","data","limit","req","returning","sort","sortArg","where","whereArg","log","length","equals","collectionConfig","Model","adapter","collectionSlug","config","payload","fields","flattenedFields","defaultSort","timestamps","query","slug","updateData","$inc","$push","$addToSet","$pull","operation","updateOps","Object","keys","$set","baseOptions","session","findOptions","lean","returnDocument","result","updateOne","doc","findOneAndUpdate","projection","_id","undefined","candidates","find","candidateIDs","map","candidate","processingToken","claimQuery","$and","$in","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I,CAACU,oBAAoB,CAAC,GAAG;oBAAE,GAAGrB,WAAW;oBAAE/B;gBAAK;YAC3E;QACF,OAAO;YACL,MAAMQ,MAAMd,UAAU,CAACuB,OAAOE,YAAYU;YAE1C,IAAI9B,cAAc,OAAO;gBACvB,OAAO;YACT;YAEAmC,SAAS,MAAM1B,MAAMkC,IAAI,CAACzB,OAAO,CAAC,GAAG;gBAAE,GAAGc,WAAW;gBAAE/B;YAAK;QAC9D;IACF,EAAE,OAAOqD,OAAO;QACd9D,YAAY;YAAE+D,YAAY/C,iBAAiBW,IAAI;YAAEmC;YAAOvD;QAAI;IAC9D;IAEAN,UAAU;QACRiB,SAAS,IAAI;QACbb,MAAMsC;QACNrB,QAAQN,iBAAiBM,MAAM;QAC/BW,WAAW;IACb;IAEA,OAAOU;AACT,EAAC"}
|
package/dist/updateMany.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"updateMany.d.ts","sourceRoot":"","sources":["../src/updateMany.ts"],"names":[],"mappings":"AAEA,OAAO,EAA2B,KAAK,UAAU,EAAE,MAAM,SAAS,CAAA;AAYlE,eAAO,MAAM,UAAU,EAAE,
|
|
1
|
+
{"version":3,"file":"updateMany.d.ts","sourceRoot":"","sources":["../src/updateMany.ts"],"names":[],"mappings":"AAEA,OAAO,EAA2B,KAAK,UAAU,EAAE,MAAM,SAAS,CAAA;AAYlE,eAAO,MAAM,UAAU,EAAE,UAwIxB,CAAA"}
|
package/dist/updateMany.js
CHANGED
package/dist/updateMany.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/updateMany.ts"],"sourcesContent":["import type { QueryOptions, UpdateQuery } from 'mongoose'\n\nimport { flattenWhereToOperators, type UpdateMany } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { buildSortParam } from './queries/buildSortParam.js'\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getCollection } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\nimport { handleError } from './utilities/handleError.js'\nimport { transform } from './utilities/transform.js'\n\nexport const updateMany: UpdateMany = async function updateMany(\n this: MongooseAdapter,\n {\n collection: collectionSlug,\n data,\n limit,\n locale,\n options: optionsArgs = {},\n req,\n returning,\n select,\n sort: sortArg,\n where,\n },\n) {\n let hasNearConstraint = false\n\n if (where) {\n const constraints = flattenWhereToOperators(where)\n hasNearConstraint = constraints.some((prop) => Object.keys(prop).some((key) => key === 'near'))\n }\n\n const { collectionConfig, Model } = getCollection({ adapter: this, collectionSlug })\n\n let sort: Record<string, unknown> | undefined\n if (!hasNearConstraint) {\n sort = buildSortParam({\n adapter: this,\n config: this.payload.config,\n fields: collectionConfig.flattenedFields,\n locale,\n sort: sortArg || collectionConfig.defaultSort,\n timestamps: true,\n })\n }\n\n let query = await buildQuery({\n adapter: this,\n collectionSlug,\n fields: collectionConfig.flattenedFields,\n locale,\n where,\n })\n\n const $inc: Record<string, number> = {}\n const $push: Record<string, { $each: any[] } | any> = {}\n const $addToSet: Record<string, { $each: any[] } | any> = {}\n const $pull: Record<string, { $in: any[] } | any> = {}\n\n transform({\n $addToSet,\n $inc,\n $pull,\n $push,\n adapter: this,\n data,\n fields: collectionConfig.fields,\n operation: 'write',\n })\n\n const updateOps: UpdateQuery<any> = {}\n\n if (Object.keys($inc).length) {\n updateOps.$inc = $inc\n }\n if (Object.keys($push).length) {\n updateOps.$push = $push\n }\n if (Object.keys($addToSet).length) {\n updateOps.$addToSet = $addToSet\n }\n if (Object.keys($pull).length) {\n updateOps.$pull = $pull\n }\n if (Object.keys(updateOps).length) {\n updateOps.$set = data\n data = updateOps\n }\n\n const baseOptions = {\n ...optionsArgs,\n session: await getSession(this, req),\n // Timestamps are manually added by the write transform\n timestamps: false,\n } satisfies QueryOptions\n\n const findOptions: QueryOptions = {\n ...baseOptions,\n lean: true,\n
|
|
1
|
+
{"version":3,"sources":["../src/updateMany.ts"],"sourcesContent":["import type { QueryOptions, UpdateQuery } from 'mongoose'\n\nimport { flattenWhereToOperators, type UpdateMany } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { buildSortParam } from './queries/buildSortParam.js'\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getCollection } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\nimport { handleError } from './utilities/handleError.js'\nimport { transform } from './utilities/transform.js'\n\nexport const updateMany: UpdateMany = async function updateMany(\n this: MongooseAdapter,\n {\n collection: collectionSlug,\n data,\n limit,\n locale,\n options: optionsArgs = {},\n req,\n returning,\n select,\n sort: sortArg,\n where,\n },\n) {\n let hasNearConstraint = false\n\n if (where) {\n const constraints = flattenWhereToOperators(where)\n hasNearConstraint = constraints.some((prop) => Object.keys(prop).some((key) => key === 'near'))\n }\n\n const { collectionConfig, Model } = getCollection({ adapter: this, collectionSlug })\n\n let sort: Record<string, unknown> | undefined\n if (!hasNearConstraint) {\n sort = buildSortParam({\n adapter: this,\n config: this.payload.config,\n fields: collectionConfig.flattenedFields,\n locale,\n sort: sortArg || collectionConfig.defaultSort,\n timestamps: true,\n })\n }\n\n let query = await buildQuery({\n adapter: this,\n collectionSlug,\n fields: collectionConfig.flattenedFields,\n locale,\n where,\n })\n\n const $inc: Record<string, number> = {}\n const $push: Record<string, { $each: any[] } | any> = {}\n const $addToSet: Record<string, { $each: any[] } | any> = {}\n const $pull: Record<string, { $in: any[] } | any> = {}\n\n transform({\n $addToSet,\n $inc,\n $pull,\n $push,\n adapter: this,\n data,\n fields: collectionConfig.fields,\n operation: 'write',\n })\n\n const updateOps: UpdateQuery<any> = {}\n\n if (Object.keys($inc).length) {\n updateOps.$inc = $inc\n }\n if (Object.keys($push).length) {\n updateOps.$push = $push\n }\n if (Object.keys($addToSet).length) {\n updateOps.$addToSet = $addToSet\n }\n if (Object.keys($pull).length) {\n updateOps.$pull = $pull\n }\n if (Object.keys(updateOps).length) {\n updateOps.$set = data\n data = updateOps\n }\n\n const baseOptions = {\n ...optionsArgs,\n session: await getSession(this, req),\n // Timestamps are manually added by the write transform\n timestamps: false,\n } satisfies QueryOptions\n\n const findOptions: QueryOptions = {\n ...baseOptions,\n lean: true,\n projection: buildProjectionFromSelect({\n adapter: this,\n fields: collectionConfig.flattenedFields,\n select,\n }),\n }\n\n try {\n if (typeof limit === 'number' && limit > 0) {\n const documentsToUpdate = await Model.find(\n query,\n {},\n { ...findOptions, limit, projection: { _id: 1 }, sort },\n )\n if (documentsToUpdate.length === 0) {\n return null\n }\n\n query = { _id: { $in: documentsToUpdate.map((doc) => doc._id) } }\n }\n\n await Model.updateMany(query, data, baseOptions)\n } catch (error) {\n handleError({ collection: collectionSlug, error, req })\n }\n\n if (returning === false) {\n return null\n }\n\n const result = await Model.find(\n query,\n {},\n {\n ...findOptions,\n sort,\n },\n )\n\n transform({\n adapter: this,\n data: result,\n fields: collectionConfig.fields,\n operation: 'read',\n })\n\n return result\n}\n"],"names":["flattenWhereToOperators","buildQuery","buildSortParam","buildProjectionFromSelect","getCollection","getSession","handleError","transform","updateMany","collection","collectionSlug","data","limit","locale","options","optionsArgs","req","returning","select","sort","sortArg","where","hasNearConstraint","constraints","some","prop","Object","keys","key","collectionConfig","Model","adapter","config","payload","fields","flattenedFields","defaultSort","timestamps","query","$inc","$push","$addToSet","$pull","operation","updateOps","length","$set","baseOptions","session","findOptions","lean","projection","documentsToUpdate","find","_id","$in","map","doc","error","result"],"mappings":"AAEA,SAASA,uBAAuB,QAAyB,UAAS;AAIlE,SAASC,UAAU,QAAQ,0BAAyB;AACpD,SAASC,cAAc,QAAQ,8BAA6B;AAC5D,SAASC,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,aAAa,QAAQ,2BAA0B;AACxD,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAASC,WAAW,QAAQ,6BAA4B;AACxD,SAASC,SAAS,QAAQ,2BAA0B;AAEpD,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AAMgD;QACNzB,QAAQL,iBAAiBK,MAAM;QAC/BS,WAAW;IACb;IAEA,OAAOgB;AACT,EAAC"}
|
package/dist/updateOne.js
CHANGED
|
@@ -64,12 +64,12 @@ export const updateOne = async function updateOne({ id, collection: collectionSl
|
|
|
64
64
|
const findOptions = {
|
|
65
65
|
...baseOptions,
|
|
66
66
|
lean: true,
|
|
67
|
-
new: true,
|
|
68
67
|
projection: buildProjectionFromSelect({
|
|
69
68
|
adapter: this,
|
|
70
69
|
fields: collectionConfig.flattenedFields,
|
|
71
70
|
select
|
|
72
|
-
})
|
|
71
|
+
}),
|
|
72
|
+
returnDocument: 'after'
|
|
73
73
|
};
|
|
74
74
|
try {
|
|
75
75
|
if (returning === false) {
|
package/dist/updateOne.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/updateOne.ts"],"sourcesContent":["import type { QueryOptions, UpdateQuery } from 'mongoose'\nimport type { UpdateOne } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getCollection } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\nimport { handleError } from './utilities/handleError.js'\nimport { transform } from './utilities/transform.js'\n\nexport const updateOne: UpdateOne = async function updateOne(\n this: MongooseAdapter,\n {\n id,\n collection: collectionSlug,\n data,\n locale,\n options: optionsArgs = {},\n req,\n returning,\n select,\n where: whereArg = {},\n },\n) {\n const { collectionConfig, Model } = getCollection({ adapter: this, collectionSlug })\n const where = id ? { id: { equals: id } } : whereArg\n const fields = collectionConfig.fields\n\n const query = await buildQuery({\n adapter: this,\n collectionSlug,\n fields: collectionConfig.flattenedFields,\n locale,\n where,\n })\n\n let result\n\n let updateData: UpdateQuery<any> = data\n\n const $inc: Record<string, number> = {}\n const $push: Record<string, { $each: any[] } | any> = {}\n const $addToSet: Record<string, { $each: any[] } | any> = {}\n const $pull: Record<string, { $in: any[] } | any> = {}\n\n transform({\n $addToSet,\n $inc,\n $pull,\n $push,\n adapter: this,\n data,\n fields,\n operation: 'write',\n })\n\n const updateOps: UpdateQuery<any> = {}\n\n if (Object.keys($inc).length) {\n updateOps.$inc = $inc\n }\n if (Object.keys($push).length) {\n updateOps.$push = $push\n }\n if (Object.keys($addToSet).length) {\n updateOps.$addToSet = $addToSet\n }\n if (Object.keys($pull).length) {\n updateOps.$pull = $pull\n }\n if (Object.keys(updateOps).length) {\n updateOps.$set = updateData\n updateData = updateOps\n }\n\n const baseOptions = {\n ...optionsArgs,\n session: await getSession(this, req),\n // Timestamps are manually added by the write transform\n timestamps: false,\n } satisfies QueryOptions\n\n const findOptions: QueryOptions = {\n ...baseOptions,\n lean: true,\n
|
|
1
|
+
{"version":3,"sources":["../src/updateOne.ts"],"sourcesContent":["import type { QueryOptions, UpdateQuery } from 'mongoose'\nimport type { UpdateOne } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getCollection } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\nimport { handleError } from './utilities/handleError.js'\nimport { transform } from './utilities/transform.js'\n\nexport const updateOne: UpdateOne = async function updateOne(\n this: MongooseAdapter,\n {\n id,\n collection: collectionSlug,\n data,\n locale,\n options: optionsArgs = {},\n req,\n returning,\n select,\n where: whereArg = {},\n },\n) {\n const { collectionConfig, Model } = getCollection({ adapter: this, collectionSlug })\n const where = id ? { id: { equals: id } } : whereArg\n const fields = collectionConfig.fields\n\n const query = await buildQuery({\n adapter: this,\n collectionSlug,\n fields: collectionConfig.flattenedFields,\n locale,\n where,\n })\n\n let result\n\n let updateData: UpdateQuery<any> = data\n\n const $inc: Record<string, number> = {}\n const $push: Record<string, { $each: any[] } | any> = {}\n const $addToSet: Record<string, { $each: any[] } | any> = {}\n const $pull: Record<string, { $in: any[] } | any> = {}\n\n transform({\n $addToSet,\n $inc,\n $pull,\n $push,\n adapter: this,\n data,\n fields,\n operation: 'write',\n })\n\n const updateOps: UpdateQuery<any> = {}\n\n if (Object.keys($inc).length) {\n updateOps.$inc = $inc\n }\n if (Object.keys($push).length) {\n updateOps.$push = $push\n }\n if (Object.keys($addToSet).length) {\n updateOps.$addToSet = $addToSet\n }\n if (Object.keys($pull).length) {\n updateOps.$pull = $pull\n }\n if (Object.keys(updateOps).length) {\n updateOps.$set = updateData\n updateData = updateOps\n }\n\n const baseOptions = {\n ...optionsArgs,\n session: await getSession(this, req),\n // Timestamps are manually added by the write transform\n timestamps: false,\n } satisfies QueryOptions\n\n const findOptions: QueryOptions = {\n ...baseOptions,\n lean: true,\n projection: buildProjectionFromSelect({\n adapter: this,\n fields: collectionConfig.flattenedFields,\n select,\n }),\n returnDocument: 'after',\n }\n\n try {\n if (returning === false) {\n await Model.updateOne(query, updateData, baseOptions)\n transform({ adapter: this, data, fields, operation: 'read' })\n return null\n } else {\n result = await Model.findOneAndUpdate(query, updateData, findOptions)\n }\n } catch (error) {\n handleError({ collection: collectionSlug, error, req })\n }\n\n if (!result) {\n return null\n }\n\n transform({ adapter: this, data: result, fields, operation: 'read' })\n\n return result\n}\n"],"names":["buildQuery","buildProjectionFromSelect","getCollection","getSession","handleError","transform","updateOne","id","collection","collectionSlug","data","locale","options","optionsArgs","req","returning","select","where","whereArg","collectionConfig","Model","adapter","equals","fields","query","flattenedFields","result","updateData","$inc","$push","$addToSet","$pull","operation","updateOps","Object","keys","length","$set","baseOptions","session","timestamps","findOptions","lean","projection","returnDocument","findOneAndUpdate","error"],"mappings":"AAKA,SAASA,UAAU,QAAQ,0BAAyB;AACpD,SAASC,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,aAAa,QAAQ,2BAA0B;AACxD,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAASC,WAAW,QAAQ,6BAA4B;AACxD,SAASC,SAAS,QAAQ,2BAA0B;AAEpD,OAAO,MAA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B,GAAGzB,WAAW;QACd0B,SAAS,MAAMpC,WAAW,IAAI,EAAEW;QAChC,uDAAuD;QACvD0B,YAAY;IACd;IAEA,MAAMC,cAA4B;QAChC,GAAGH,WAAW;QACdI,MAAM;QACNC,YAAY1C,0BAA0B;YACpCoB,SAAS,IAAI;YACbE,QAAQJ,iBAAiBM,eAAe;YACxCT;QACF;QACA4B,gBAAgB;IAClB;IAEA,IAAI;QACF,IAAI7B,cAAc,OAAO;YACvB,MAAMK,MAAMd,SAAS,CAACkB,OAAOG,YAAYW;YACzCjC,UAAU;gBAAEgB,SAAS,IAAI;gBAAEX;gBAAMa;gBAAQS,WAAW;YAAO;YAC3D,OAAO;QACT,OAAO;YACLN,SAAS,MAAMN,MAAMyB,gBAAgB,CAACrB,OAAOG,YAAYc;QAC3D;IACF,EAAE,OAAOK,OAAO;QACd1C,YAAY;YAAEI,YAAYC;YAAgBqC;YAAOhC;QAAI;IACvD;IAEA,IAAI,CAACY,QAAQ;QACX,OAAO;IACT;IAEArB,UAAU;QAAEgB,SAAS,IAAI;QAAEX,MAAMgB;QAAQH;QAAQS,WAAW;IAAO;IAEnE,OAAON;AACT,EAAC"}
|
package/dist/updateVersion.js
CHANGED
|
@@ -38,12 +38,12 @@ export const updateVersion = async function updateVersion({ id, collection: coll
|
|
|
38
38
|
const findOptions = {
|
|
39
39
|
...baseOptions,
|
|
40
40
|
lean: true,
|
|
41
|
-
new: true,
|
|
42
41
|
projection: buildProjectionFromSelect({
|
|
43
42
|
adapter: this,
|
|
44
43
|
fields: flattenedFields,
|
|
45
44
|
select
|
|
46
|
-
})
|
|
45
|
+
}),
|
|
46
|
+
returnDocument: 'after'
|
|
47
47
|
};
|
|
48
48
|
if (returning === false) {
|
|
49
49
|
await Model.updateOne(query, versionData, baseOptions);
|
|
@@ -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 { buildQuery } from './queries/buildQuery.js'\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getCollection } from './utilities/getEntity.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 {\n id,\n collection: collectionSlug,\n locale,\n options: optionsArgs = {},\n req,\n returning,\n select,\n versionData,\n where,\n },\n) {\n const { collectionConfig, Model } = getCollection({\n adapter: this,\n collectionSlug,\n versions: true,\n })\n\n const whereToUse = where || { id: { equals: id } }\n const fields = buildVersionCollectionFields(this.payload.config, collectionConfig)\n\n const flattenedFields = buildVersionCollectionFields(this.payload.config, collectionConfig, true)\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 baseOptions = {\n ...optionsArgs,\n session: await getSession(this, req),\n // Timestamps are manually added by the write transform\n timestamps: false,\n } satisfies QueryOptions\n\n const findOptions: QueryOptions = {\n ...baseOptions,\n lean: true,\n
|
|
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 { getCollection } from './utilities/getEntity.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 {\n id,\n collection: collectionSlug,\n locale,\n options: optionsArgs = {},\n req,\n returning,\n select,\n versionData,\n where,\n },\n) {\n const { collectionConfig, Model } = getCollection({\n adapter: this,\n collectionSlug,\n versions: true,\n })\n\n const whereToUse = where || { id: { equals: id } }\n const fields = buildVersionCollectionFields(this.payload.config, collectionConfig)\n\n const flattenedFields = buildVersionCollectionFields(this.payload.config, collectionConfig, true)\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 baseOptions = {\n ...optionsArgs,\n session: await getSession(this, req),\n // Timestamps are manually added by the write transform\n timestamps: false,\n } satisfies QueryOptions\n\n const findOptions: QueryOptions = {\n ...baseOptions,\n lean: true,\n projection: buildProjectionFromSelect({\n adapter: this,\n fields: flattenedFields,\n select,\n }),\n returnDocument: 'after',\n }\n\n if (returning === false) {\n await Model.updateOne(query, versionData, baseOptions)\n return null\n }\n\n const doc = await Model.findOneAndUpdate(query, versionData, findOptions)\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":["buildVersionCollectionFields","buildQuery","buildProjectionFromSelect","getCollection","getSession","transform","updateVersion","id","collection","collectionSlug","locale","options","optionsArgs","req","returning","select","versionData","where","collectionConfig","Model","adapter","versions","whereToUse","equals","fields","payload","config","flattenedFields","query","data","operation","baseOptions","session","timestamps","findOptions","lean","projection","returnDocument","updateOne","doc","findOneAndUpdate"],"mappings":"AAEA,SAASA,4BAA4B,QAA4B,UAAS;AAI1E,SAASC,UAAU,QAAQ,0BAAyB;AACpD,SAASC,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,aAAa,QAAQ,2BAA0B;AACxD,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAASC,SAAS,QAAQ,2BAA0B;AAEpD,OAAO,MAAMC,gBAA+B,eAAeA,cAEzD,EACEC,EAAE,EACFC,YAAYC,cAAc,EAC1BC,MAAM,EACNC,SAASC,cAAc,CAAC,CAAC,EACzBC,GAAG,EACHC,SAAS,EACTC,MAAM,EACNC,WAAW,EACXC,KAAK,EACN;IAED,MAAM,EAAEC,gBAAgB,EAAEC,KAAK,EAAE,GAAGhB,cAAc;QAChDiB,SAAS,IAAI;QACbX;QACAY,UAAU;IACZ;IAEA,MAAMC,aAAaL,SAAS;QAAEV,IAAI;YAAEgB,QAAQhB;QAAG;IAAE;IACjD,MAAMiB,SAASxB,6BAA6B,IAAI,CAACyB,OAAO,CAACC,MAAM,EAAER;IAEjE,MAAMS,kBAAkB3B,6BAA6B,IAAI,CAACyB,OAAO,CAACC,MAAM,EAAER,kBAAkB;IAE5F,MAAMU,QAAQ,MAAM3B,WAAW;QAC7BmB,SAAS,IAAI;QACbI,QAAQG;QACRjB;QACAO,OAAOK;IACT;IAEAjB,UAAU;QAAEe,SAAS,IAAI;QAAES,MAAMb;QAAaQ;QAAQM,WAAW;IAAQ;IAEzE,MAAMC,cAAc;QAClB,GAAGnB,WAAW;QACdoB,SAAS,MAAM5B,WAAW,IAAI,EAAES;QAChC,uDAAuD;QACvDoB,YAAY;IACd;IAEA,MAAMC,cAA4B;QAChC,GAAGH,WAAW;QACdI,MAAM;QACNC,YAAYlC,0BAA0B;YACpCkB,SAAS,IAAI;YACbI,QAAQG;YACRZ;QACF;QACAsB,gBAAgB;IAClB;IAEA,IAAIvB,cAAc,OAAO;QACvB,MAAMK,MAAMmB,SAAS,CAACV,OAAOZ,aAAae;QAC1C,OAAO;IACT;IAEA,MAAMQ,MAAM,MAAMpB,MAAMqB,gBAAgB,CAACZ,OAAOZ,aAAakB;IAE7D,IAAI,CAACK,KAAK;QACR,OAAO;IACT;IAEAlC,UAAU;QAAEe,SAAS,IAAI;QAAES,MAAMU;QAAKf;QAAQM,WAAW;IAAO;IAEhE,OAAOS;AACT,EAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payloadcms/db-mongodb",
|
|
3
|
-
"version": "4.0.0-internal.
|
|
3
|
+
"version": "4.0.0-internal.31ba7ee",
|
|
4
4
|
"description": "The officially supported MongoDB database adapter for Payload",
|
|
5
5
|
"homepage": "https://payloadcms.com",
|
|
6
6
|
"repository": {
|
|
@@ -54,10 +54,10 @@
|
|
|
54
54
|
"mongodb": "7.5.0",
|
|
55
55
|
"mongodb-memory-server": "10.1.4",
|
|
56
56
|
"@payloadcms/eslint-config": "3.28.0",
|
|
57
|
-
"payload": "4.0.0-internal.
|
|
57
|
+
"payload": "4.0.0-internal.31ba7ee"
|
|
58
58
|
},
|
|
59
59
|
"peerDependencies": {
|
|
60
|
-
"payload": "4.0.0-internal.
|
|
60
|
+
"payload": "4.0.0-internal.31ba7ee"
|
|
61
61
|
},
|
|
62
62
|
"scripts": {
|
|
63
63
|
"build": "pnpm build:types && pnpm build:swc",
|