@payloadcms/db-mongodb 3.0.0-canary.98cbdb9 → 3.0.0-canary.99cbde3
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/connect.d.ts.map +1 -1
- package/dist/connect.js +12 -3
- package/dist/connect.js.map +1 -1
- package/dist/count.d.ts.map +1 -1
- package/dist/count.js +8 -1
- 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.map +1 -1
- package/dist/create.js +10 -1
- package/dist/create.js.map +1 -1
- package/dist/createGlobal.d.ts.map +1 -1
- package/dist/createGlobal.js +10 -5
- 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 +13 -4
- package/dist/createGlobalVersion.js.map +1 -1
- package/dist/createMigration.d.ts.map +1 -1
- package/dist/createMigration.js +8 -6
- 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 +31 -9
- package/dist/createVersion.js.map +1 -1
- package/dist/deleteOne.d.ts.map +1 -1
- package/dist/deleteOne.js +11 -3
- package/dist/deleteOne.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.map +1 -1
- package/dist/find.js +27 -4
- package/dist/find.js.map +1 -1
- package/dist/findGlobal.d.ts.map +1 -1
- package/dist/findGlobal.js +9 -3
- package/dist/findGlobal.js.map +1 -1
- package/dist/findGlobalVersions.d.ts.map +1 -1
- package/dist/findGlobalVersions.js +9 -4
- package/dist/findGlobalVersions.js.map +1 -1
- package/dist/findOne.d.ts.map +1 -1
- package/dist/findOne.js +27 -3
- package/dist/findOne.js.map +1 -1
- package/dist/findVersions.d.ts.map +1 -1
- package/dist/findVersions.js +9 -4
- package/dist/findVersions.js.map +1 -1
- package/dist/index.d.ts +23 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +17 -7
- package/dist/index.js.map +1 -1
- package/dist/init.d.ts.map +1 -1
- package/dist/init.js +20 -18
- package/dist/init.js.map +1 -1
- package/dist/models/buildCollectionSchema.d.ts +2 -3
- package/dist/models/buildCollectionSchema.d.ts.map +1 -1
- package/dist/models/buildCollectionSchema.js +10 -7
- package/dist/models/buildCollectionSchema.js.map +1 -1
- package/dist/models/buildGlobalModel.d.ts +2 -2
- package/dist/models/buildGlobalModel.d.ts.map +1 -1
- package/dist/models/buildGlobalModel.js +6 -6
- package/dist/models/buildGlobalModel.js.map +1 -1
- package/dist/models/buildSchema.d.ts +2 -3
- package/dist/models/buildSchema.d.ts.map +1 -1
- package/dist/models/buildSchema.js +179 -66
- 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 +5 -95
- package/dist/predefinedMigrations/versions-v1-v2.js.map +1 -1
- package/dist/queries/buildQuery.d.ts +2 -2
- package/dist/queries/buildQuery.d.ts.map +1 -1
- package/dist/queries/buildQuery.js +1 -2
- package/dist/queries/buildQuery.js.map +1 -1
- package/dist/queries/buildSearchParams.d.ts.map +1 -1
- package/dist/queries/buildSearchParams.js +29 -18
- package/dist/queries/buildSearchParams.js.map +1 -1
- package/dist/queries/buildSortParam.d.ts +2 -2
- 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.spec.js +1 -1
- package/dist/queries/getLocalizedSortProperty.spec.js.map +1 -1
- package/dist/queries/parseParams.d.ts.map +1 -1
- package/dist/queries/parseParams.js +7 -2
- package/dist/queries/parseParams.js.map +1 -1
- package/dist/queries/sanitizeQueryValue.d.ts +3 -2
- package/dist/queries/sanitizeQueryValue.d.ts.map +1 -1
- package/dist/queries/sanitizeQueryValue.js +263 -37
- package/dist/queries/sanitizeQueryValue.js.map +1 -1
- package/dist/queryDrafts.d.ts.map +1 -1
- package/dist/queryDrafts.js +29 -8
- package/dist/queryDrafts.js.map +1 -1
- package/dist/transactions/beginTransaction.d.ts.map +1 -1
- package/dist/transactions/beginTransaction.js +2 -0
- package/dist/transactions/beginTransaction.js.map +1 -1
- package/dist/transactions/commitTransaction.d.ts.map +1 -1
- package/dist/transactions/commitTransaction.js +3 -1
- package/dist/transactions/commitTransaction.js.map +1 -1
- package/dist/types.d.ts +7 -4
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/updateGlobal.d.ts.map +1 -1
- package/dist/updateGlobal.js +18 -4
- package/dist/updateGlobal.js.map +1 -1
- package/dist/updateGlobalVersion.d.ts +2 -2
- package/dist/updateGlobalVersion.d.ts.map +1 -1
- package/dist/updateGlobalVersion.js +19 -4
- package/dist/updateGlobalVersion.js.map +1 -1
- package/dist/updateOne.d.ts.map +1 -1
- package/dist/updateOne.js +18 -4
- 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 -3
- 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.map +1 -1
- package/dist/utilities/getDBName.js +3 -1
- package/dist/utilities/getDBName.js.map +1 -1
- package/dist/utilities/handleError.js +2 -2
- 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 +116 -0
- package/dist/utilities/sanitizeRelationshipIDs.js.map +1 -0
- package/dist/utilities/sanitizeRelationshipIDs.spec.js +408 -0
- package/dist/utilities/sanitizeRelationshipIDs.spec.js.map +1 -0
- package/dist/withSession.d.ts +1 -1
- package/dist/withSession.d.ts.map +1 -1
- package/dist/withSession.js +5 -3
- package/dist/withSession.js.map +1 -1
- package/license.md +22 -0
- package/package.json +24 -11
- package/dist/queries/mock.js +0 -2
- package/dist/queries/mock.js.map +0 -1
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/queries/sanitizeQueryValue.ts"],"sourcesContent":["import type { Field, TabAsField } from 'payload'\n\nimport mongoose from 'mongoose'\nimport { createArrayFromCommaDelineated } from 'payload'\n\ntype SanitizeQueryValueArgs = {\n field: Field | TabAsField\n hasCustomID: boolean\n operator: string\n path: string\n val: any\n}\n\nexport const sanitizeQueryValue = ({\n field,\n hasCustomID,\n operator,\n path,\n val,\n}: SanitizeQueryValueArgs): {\n operator?: string\n rawQuery?: unknown\n val?: unknown\n} => {\n let formattedValue = val\n let formattedOperator = operator\n\n // Disregard invalid _ids\n if (path === '_id' && typeof val === 'string' && val.split(',').length === 1) {\n if (!hasCustomID) {\n const isValid = mongoose.Types.ObjectId.isValid(val)\n\n if (!isValid) {\n return { operator: formattedOperator, val: undefined }\n }\n }\n\n if (field.type === 'number') {\n const parsedNumber = parseFloat(val)\n\n if (Number.isNaN(parsedNumber)) {\n return { operator: formattedOperator, val: undefined }\n }\n }\n }\n\n // Cast incoming values as proper searchable types\n if (field.type === 'checkbox' && typeof val === 'string') {\n if (val.toLowerCase() === 'true') formattedValue = true\n if (val.toLowerCase() === 'false') formattedValue = false\n }\n\n if (['all', 'in', 'not_in'].includes(operator) && typeof formattedValue === 'string') {\n formattedValue = createArrayFromCommaDelineated(formattedValue)\n\n if (field.type === 'number') {\n formattedValue = formattedValue.map((arrayVal) => parseFloat(arrayVal))\n }\n }\n\n if (field.type === 'number' && typeof formattedValue === 'string') {\n formattedValue = Number(val)\n }\n\n if (field.type === 'date' && typeof val === 'string' && operator !== 'exists') {\n formattedValue = new Date(val)\n if (Number.isNaN(Date.parse(formattedValue))) {\n return undefined\n }\n }\n\n if (['relationship', 'upload'].includes(field.type)) {\n if (val === 'null') {\n formattedValue = null\n }\n\n // Object equality requires the value to be the first key in the object that is being queried.\n if (\n operator === 'equals' &&\n formattedValue &&\n typeof formattedValue === 'object' &&\n formattedValue.value &&\n formattedValue.relationTo\n ) {\n return {\n rawQuery: {\n $and: [\n { [`${path}.value`]: { $eq: formattedValue.value } },\n { [`${path}.relationTo`]: { $eq: formattedValue.relationTo } },\n ],\n },\n }\n }\n\n if (operator === 'in' && Array.isArray(formattedValue)) {\n formattedValue = formattedValue.reduce((formattedValues, inVal) => {\n const newValues = [inVal]\n if (mongoose.Types.ObjectId.isValid(inVal))\n newValues.push(new mongoose.Types.ObjectId(inVal))\n\n const parsedNumber = parseFloat(inVal)\n if (!Number.isNaN(parsedNumber)) newValues.push(parsedNumber)\n\n return [...formattedValues, ...newValues]\n }, [])\n }\n }\n\n // Set up specific formatting necessary by operators\n\n if (operator === 'near') {\n let lng\n let lat\n let maxDistance\n let minDistance\n\n if (Array.isArray(formattedValue)) {\n ;[lng, lat, maxDistance, minDistance] = formattedValue\n }\n\n if (typeof formattedValue === 'string') {\n ;[lng, lat, maxDistance, minDistance] = createArrayFromCommaDelineated(formattedValue)\n }\n\n if (lng == null || lat == null || (maxDistance == null && minDistance == null)) {\n formattedValue = undefined\n } else {\n formattedValue = {\n $geometry: { type: 'Point', coordinates: [parseFloat(lng), parseFloat(lat)] },\n }\n\n if (maxDistance) formattedValue.$maxDistance = parseFloat(maxDistance)\n if (minDistance) formattedValue.$minDistance = parseFloat(minDistance)\n }\n }\n\n if (operator === 'within' || operator === 'intersects') {\n formattedValue = {\n $geometry: formattedValue,\n }\n }\n\n if (path !== '_id' || (path === '_id' && hasCustomID && field.type === 'text')) {\n if (operator === 'contains') {\n formattedValue = {\n $options: 'i',\n $regex: formattedValue.replace(/[\\\\^$*+?.()|[\\]{}]/g, '\\\\$&'),\n }\n }\n }\n\n if (\n (path === '_id' || path === 'parent') &&\n operator === 'like' &&\n formattedValue.length === 24 &&\n !hasCustomID\n ) {\n formattedOperator = 'equals'\n }\n\n if (operator === 'exists') {\n formattedValue = formattedValue === 'true' || formattedValue === true\n\n // Clearable fields\n if (['relationship', 'select', 'upload'].includes(field.type)) {\n if (formattedValue) {\n return {\n rawQuery: {\n $and: [{ [path]: { $exists: true } }, { [path]: { $ne: null } }],\n },\n }\n } else {\n return {\n rawQuery: {\n $or: [{ [path]: { $exists: false } }, { [path]: { $eq: null } }],\n },\n }\n }\n }\n }\n\n return { operator: formattedOperator, val: formattedValue }\n}\n"],"names":["mongoose","createArrayFromCommaDelineated","sanitizeQueryValue","field","hasCustomID","operator","path","val","formattedValue","formattedOperator","split","length","isValid","Types","ObjectId","undefined","type","parsedNumber","parseFloat","Number","isNaN","toLowerCase","includes","map","arrayVal","Date","parse","value","relationTo","rawQuery","$and","$eq","Array","isArray","reduce","formattedValues","inVal","newValues","push","lng","lat","maxDistance","minDistance","$geometry","coordinates","$maxDistance","$minDistance","$options","$regex","replace","$exists","$ne","$or"],"mappings":"AAEA,OAAOA,cAAc,WAAU;AAC/B,SAASC,8BAA8B,QAAQ,UAAS;AAUxD,OAAO,MAAMC,qBAAqB,CAAC,EACjCC,KAAK,EACLC,WAAW,EACXC,QAAQ,EACRC,IAAI,EACJC,GAAG,EACoB;IAKvB,IAAIC,iBAAiBD;IACrB,IAAIE,oBAAoBJ;IAExB,yBAAyB;IACzB,IAAIC,SAAS,SAAS,OAAOC,QAAQ,YAAYA,IAAIG,KAAK,CAAC,KAAKC,MAAM,KAAK,GAAG;QAC5E,IAAI,CAACP,aAAa;YAChB,MAAMQ,UAAUZ,SAASa,KAAK,CAACC,QAAQ,CAACF,OAAO,CAACL;YAEhD,IAAI,CAACK,SAAS;gBACZ,OAAO;oBAAEP,UAAUI;oBAAmBF,KAAKQ;gBAAU;YACvD;QACF;QAEA,IAAIZ,MAAMa,IAAI,KAAK,UAAU;YAC3B,MAAMC,eAAeC,WAAWX;YAEhC,IAAIY,OAAOC,KAAK,CAACH,eAAe;gBAC9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a,IAAI,KAAK,QAAS;QAC9E,IAAIX,aAAa,YAAY;YAC3BG,iBAAiB;gBACfuC,UAAU;gBACVC,QAAQxC,eAAeyC,OAAO,CAAC,uBAAuB;YACxD;QACF;IACF;IAEA,IACE,AAAC3C,CAAAA,SAAS,SAASA,SAAS,QAAO,KACnCD,aAAa,UACbG,eAAeG,MAAM,KAAK,MAC1B,CAACP,aACD;QACAK,oBAAoB;IACtB;IAEA,IAAIJ,aAAa,UAAU;QACzBG,iBAAiBA,mBAAmB,UAAUA,mBAAmB;QAEjE,mBAAmB;QACnB,IAAI;YAAC;YAAgB;YAAU;SAAS,CAACc,QAAQ,CAACnB,MAAMa,IAAI,GAAG;YAC7D,IAAIR,gBAAgB;gBAClB,OAAO;oBACLqB,UAAU;wBACRC,MAAM;4BAAC;gCAAE,CAACxB,KAAK,EAAE;oCAAE4C,SAAS;gCAAK;4BAAE;4BAAG;gCAAE,CAAC5C,KAAK,EAAE;oCAAE6C,KAAK;gCAAK;4BAAE;yBAAE;oBAClE;gBACF;YACF,OAAO;gBACL,OAAO;oBACLtB,UAAU;wBACRuB,KAAK;4BAAC;gCAAE,CAAC9C,KAAK,EAAE;oCAAE4C,SAAS;gCAAM;4BAAE;4BAAG;gCAAE,CAAC5C,KAAK,EAAE;oCAAEyB,KAAK;gCAAK;4BAAE;yBAAE;oBAClE;gBACF;YACF;QACF;IACF;IAEA,OAAO;QAAE1B,UAAUI;QAAmBF,KAAKC;IAAe;AAC5D,EAAC"}
|
1
|
+
{"version":3,"sources":["../../src/queries/sanitizeQueryValue.ts"],"sourcesContent":["import type { Block, Field, Payload, RelationshipField, TabAsField } from 'payload'\n\nimport { Types } from 'mongoose'\nimport { createArrayFromCommaDelineated, flattenTopLevelFields } from 'payload'\n\ntype SanitizeQueryValueArgs = {\n field: Field | TabAsField\n hasCustomID: boolean\n operator: string\n path: string\n payload: Payload\n val: any\n}\n\nconst buildExistsQuery = (formattedValue, path, treatEmptyString = true) => {\n if (formattedValue) {\n return {\n rawQuery: {\n $and: [\n { [path]: { $exists: true } },\n { [path]: { $ne: null } },\n ...(treatEmptyString ? [{ [path]: { $ne: '' } }] : []), // Treat empty string as null / undefined\n ],\n },\n }\n } else {\n return {\n rawQuery: {\n $or: [\n { [path]: { $exists: false } },\n { [path]: { $eq: null } },\n ...(treatEmptyString ? [{ [path]: { $eq: '' } }] : []), // Treat empty string as null / undefined\n ],\n },\n }\n }\n}\n\n// returns nestedField Field object from blocks.nestedField path because getLocalizedPaths splits them only for relationships\nconst getFieldFromSegments = ({\n field,\n segments,\n}: {\n field: Block | Field | TabAsField\n segments: string[]\n}) => {\n if ('blocks' in field) {\n for (const block of field.blocks) {\n const field = getFieldFromSegments({ field: block, segments })\n if (field) {\n return field\n }\n }\n }\n\n if ('fields' in field) {\n for (let i = 0; i < segments.length; i++) {\n const foundField = flattenTopLevelFields(field.fields).find(\n (each) => each.name === segments[i],\n )\n\n if (!foundField) {\n break\n }\n\n if (foundField && segments.length - 1 === i) {\n return foundField\n }\n\n segments.shift()\n return getFieldFromSegments({ field: foundField, segments })\n }\n }\n}\n\nexport const sanitizeQueryValue = ({\n field,\n hasCustomID,\n operator,\n path,\n payload,\n val,\n}: SanitizeQueryValueArgs): {\n operator?: string\n rawQuery?: unknown\n val?: unknown\n} => {\n let formattedValue = val\n let formattedOperator = operator\n\n if (['array', 'blocks', 'group', 'tab'].includes(field.type) && path.includes('.')) {\n const segments = path.split('.')\n segments.shift()\n const foundField = getFieldFromSegments({ field, segments })\n\n if (foundField) {\n field = foundField\n }\n }\n\n // Disregard invalid _ids\n if (path === '_id') {\n if (typeof val === 'string' && val.split(',').length === 1) {\n if (!hasCustomID) {\n const isValid = Types.ObjectId.isValid(val)\n\n if (!isValid) {\n return { operator: formattedOperator, val: undefined }\n } else {\n if (['in', 'not_in'].includes(operator)) {\n formattedValue = createArrayFromCommaDelineated(formattedValue).map(\n (id) => new Types.ObjectId(id),\n )\n } else {\n formattedValue = new Types.ObjectId(val)\n }\n }\n }\n\n if (field.type === 'number') {\n const parsedNumber = parseFloat(val)\n\n if (Number.isNaN(parsedNumber)) {\n return { operator: formattedOperator, val: undefined }\n }\n }\n } else if (Array.isArray(val) || (typeof val === 'string' && val.split(',').length > 1)) {\n if (typeof val === 'string') {\n formattedValue = createArrayFromCommaDelineated(val)\n }\n\n formattedValue = formattedValue.reduce((formattedValues, inVal) => {\n if (!hasCustomID) {\n if (Types.ObjectId.isValid(inVal)) {\n formattedValues.push(new Types.ObjectId(inVal))\n }\n }\n\n if (field.type === 'number') {\n const parsedNumber = parseFloat(inVal)\n if (!Number.isNaN(parsedNumber)) {\n formattedValues.push(parsedNumber)\n }\n } else {\n formattedValues.push(inVal)\n }\n\n return formattedValues\n }, [])\n }\n }\n\n // Cast incoming values as proper searchable types\n if (field.type === 'checkbox' && typeof val === 'string') {\n if (val.toLowerCase() === 'true') {\n formattedValue = true\n }\n if (val.toLowerCase() === 'false') {\n formattedValue = false\n }\n }\n\n if (['all', 'in', 'not_in'].includes(operator) && typeof formattedValue === 'string') {\n formattedValue = createArrayFromCommaDelineated(formattedValue)\n\n if (field.type === 'number') {\n formattedValue = formattedValue.map((arrayVal) => parseFloat(arrayVal))\n }\n }\n\n if (field.type === 'number') {\n if (typeof formattedValue === 'string' && operator !== 'exists') {\n formattedValue = Number(val)\n }\n\n if (operator === 'exists') {\n formattedValue = val === 'true' ? true : val === 'false' ? false : Boolean(val)\n\n return buildExistsQuery(formattedValue, path)\n }\n }\n\n if (field.type === 'date' && typeof val === 'string' && operator !== 'exists') {\n formattedValue = new Date(val)\n if (Number.isNaN(Date.parse(formattedValue))) {\n return undefined\n }\n }\n\n if (['relationship', 'upload'].includes(field.type)) {\n if (val === 'null') {\n formattedValue = null\n }\n\n // Object equality requires the value to be the first key in the object that is being queried.\n if (\n operator === 'equals' &&\n formattedValue &&\n typeof formattedValue === 'object' &&\n formattedValue.value &&\n formattedValue.relationTo\n ) {\n const { value } = formattedValue\n const isValid = Types.ObjectId.isValid(value)\n\n if (isValid) {\n formattedValue.value = new Types.ObjectId(value)\n }\n\n return {\n rawQuery: {\n $and: [\n { [`${path}.value`]: { $eq: formattedValue.value } },\n { [`${path}.relationTo`]: { $eq: formattedValue.relationTo } },\n ],\n },\n }\n }\n\n const relationTo = (field as RelationshipField).relationTo\n\n if (['in', 'not_in'].includes(operator) && Array.isArray(formattedValue)) {\n formattedValue = formattedValue.reduce((formattedValues, inVal) => {\n if (!inVal) {\n return formattedValues\n }\n\n if (typeof relationTo === 'string' && payload.collections[relationTo].customIDType) {\n if (payload.collections[relationTo].customIDType === 'number') {\n const parsedNumber = parseFloat(inVal)\n if (!Number.isNaN(parsedNumber)) {\n formattedValues.push(parsedNumber)\n return formattedValues\n }\n }\n\n formattedValues.push(inVal)\n return formattedValues\n }\n\n if (\n Array.isArray(relationTo) &&\n relationTo.some((relationTo) => !!payload.collections[relationTo].customIDType)\n ) {\n if (Types.ObjectId.isValid(inVal.toString())) {\n formattedValues.push(new Types.ObjectId(inVal))\n } else {\n formattedValues.push(inVal)\n }\n return formattedValues\n }\n\n if (Types.ObjectId.isValid(inVal.toString())) {\n formattedValues.push(new Types.ObjectId(inVal))\n }\n\n return formattedValues\n }, [])\n }\n\n if (\n ['contains', 'equals', 'like', 'not_equals'].includes(operator) &&\n (!Array.isArray(relationTo) || !path.endsWith('.relationTo'))\n ) {\n if (typeof relationTo === 'string') {\n const customIDType = payload.collections[relationTo].customIDType\n\n if (customIDType) {\n if (customIDType === 'number') {\n formattedValue = parseFloat(val)\n\n if (Number.isNaN(formattedValue)) {\n return { operator: formattedOperator, val: undefined }\n }\n }\n } else {\n if (!Types.ObjectId.isValid(formattedValue)) {\n return { operator: formattedOperator, val: undefined }\n }\n formattedValue = new Types.ObjectId(formattedValue)\n }\n } else {\n const hasCustomIDType = relationTo.some(\n (relationTo) => !!payload.collections[relationTo].customIDType,\n )\n\n if (hasCustomIDType) {\n if (typeof val === 'string') {\n const formattedNumber = Number(val)\n formattedValue = [Types.ObjectId.isValid(val) ? new Types.ObjectId(val) : val]\n formattedOperator = operator === 'not_equals' ? 'not_in' : 'in'\n if (!Number.isNaN(formattedNumber)) {\n formattedValue.push(formattedNumber)\n }\n }\n } else {\n if (!Types.ObjectId.isValid(formattedValue)) {\n return { operator: formattedOperator, val: undefined }\n }\n formattedValue = new Types.ObjectId(formattedValue)\n }\n }\n }\n }\n\n // Set up specific formatting necessary by operators\n\n if (operator === 'near') {\n let lng\n let lat\n let maxDistance\n let minDistance\n\n if (Array.isArray(formattedValue)) {\n ;[lng, lat, maxDistance, minDistance] = formattedValue\n }\n\n if (typeof formattedValue === 'string') {\n ;[lng, lat, maxDistance, minDistance] = createArrayFromCommaDelineated(formattedValue)\n }\n\n if (lng == null || lat == null || (maxDistance == null && minDistance == null)) {\n formattedValue = undefined\n } else {\n formattedValue = {\n $geometry: { type: 'Point', coordinates: [parseFloat(lng), parseFloat(lat)] },\n }\n\n if (maxDistance) {\n formattedValue.$maxDistance = parseFloat(maxDistance)\n }\n if (minDistance) {\n formattedValue.$minDistance = parseFloat(minDistance)\n }\n }\n }\n\n if (operator === 'within' || operator === 'intersects') {\n formattedValue = {\n $geometry: formattedValue,\n }\n }\n\n if (path !== '_id' || (path === '_id' && hasCustomID && field.type === 'text')) {\n if (operator === 'contains' && !Types.ObjectId.isValid(formattedValue)) {\n formattedValue = {\n $options: 'i',\n $regex: formattedValue.replace(/[\\\\^$*+?.()|[\\]{}]/g, '\\\\$&'),\n }\n }\n\n if (operator === 'exists') {\n formattedValue = formattedValue === 'true' || formattedValue === true\n\n // _id can't be empty string, will error Cast to ObjectId failed for value \"\"\n return buildExistsQuery(\n formattedValue,\n path,\n !['relationship', 'upload'].includes(field.type),\n )\n }\n }\n\n if (\n (path === '_id' || path === 'parent') &&\n operator === 'like' &&\n formattedValue.length === 24 &&\n !hasCustomID\n ) {\n formattedOperator = 'equals'\n }\n\n if (operator === 'exists') {\n formattedValue = formattedValue === 'true' || formattedValue === true\n\n // Clearable fields\n if (['relationship', 'select', 'upload'].includes(field.type)) {\n if (formattedValue) {\n return {\n rawQuery: {\n $and: [{ [path]: { $exists: true } }, { [path]: { $ne: null } }],\n },\n }\n } else {\n return {\n rawQuery: {\n $or: [{ [path]: { $exists: false } }, { [path]: { $eq: null } }],\n },\n }\n }\n }\n }\n\n return { operator: formattedOperator, val: formattedValue }\n}\n"],"names":["Types","createArrayFromCommaDelineated","flattenTopLevelFields","buildExistsQuery","formattedValue","path","treatEmptyString","rawQuery","$and","$exists","$ne","$or","$eq","getFieldFromSegments","field","segments","block","blocks","i","length","foundField","fields","find","each","name","shift","sanitizeQueryValue","hasCustomID","operator","payload","val","formattedOperator","includes","type","split","isValid","ObjectId","undefined","map","id","parsedNumber","parseFloat","Number","isNaN","Array","isArray","reduce","formattedValues","inVal","push","toLowerCase","arrayVal","Boolean","Date","parse","value","relationTo","collections","customIDType","some","toString","endsWith","hasCustomIDType","formattedNumber","lng","lat","maxDistance","minDistance","$geometry","coordinates","$maxDistance","$minDistance","$options","$regex","replace"],"mappings":"AAEA,SAASA,KAAK,QAAQ,WAAU;AAChC,SAASC,8BAA8B,EAAEC,qBAAqB,QAAQ,UAAS;AAW/E,MAAMC,mBAAmB,CAACC,gBAAgBC,MAAMC,mBAAmB,IAAI;IACrE,IAAIF,gBAAgB;QAClB,OAAO;YACLG,UAAU;gBACRC,MAAM;oBACJ;wBAAE,CAACH,KAAK,EAAE;4BAAEI,SAAS;wBAAK;oBAAE;oBAC5B;wBAAE,CAACJ,KAAK,EAAE;4BAAEK,KAAK;wBAAK;oBAAE;uBACpBJ,mBAAmB;wBAAC;4BAAE,CAACD,KAAK,EAAE;gCAAEK,KAAK;4BAAG;wBAAE;qBAAE,GAAG,EAAE;iBACtD;YACH;QACF;IACF,OAAO;QACL,OAAO;YACLH,UAAU;gBACRI,KAAK;oBACH;wBAAE,CAACN,KAAK,EAAE;4BAAEI,SAAS;wBAAM;oBAAE;oBAC7B;wBAAE,CAACJ,KAAK,EAAE;4BAAEO,KAAK;wB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
+
{"version":3,"file":"queryDrafts.d.ts","sourceRoot":"","sources":["../src/queryDrafts.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAkB,WAAW,EAAE,MAAM,SAAS,CAAA;AAY1D,eAAO,MAAM,WAAW,EAAE,WAqIzB,CAAA"}
|
package/dist/queryDrafts.js
CHANGED
@@ -1,8 +1,10 @@
|
|
1
|
-
import { combineQueries, flattenWhereToOperators } from 'payload';
|
1
|
+
import { buildVersionCollectionFields, combineQueries, flattenWhereToOperators } from 'payload';
|
2
2
|
import { buildSortParam } from './queries/buildSortParam.js';
|
3
|
-
import
|
3
|
+
import { buildJoinAggregation } from './utilities/buildJoinAggregation.js';
|
4
|
+
import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js';
|
5
|
+
import { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js';
|
4
6
|
import { withSession } from './withSession.js';
|
5
|
-
export const queryDrafts = async function queryDrafts({ collection, limit, locale, page, pagination, req = {}, sort: sortArg, where }) {
|
7
|
+
export const queryDrafts = async function queryDrafts({ collection, joins, limit, locale, page, pagination, req = {}, select, sort: sortArg, where }) {
|
6
8
|
const VersionModel = this.versions[collection];
|
7
9
|
const collectionConfig = this.payload.collections[collection].config;
|
8
10
|
const options = await withSession(this, req);
|
@@ -31,15 +33,20 @@ export const queryDrafts = async function queryDrafts({ collection, limit, local
|
|
31
33
|
payload: this.payload,
|
32
34
|
where: combinedWhere
|
33
35
|
});
|
36
|
+
const projection = buildProjectionFromSelect({
|
37
|
+
adapter: this,
|
38
|
+
fields: buildVersionCollectionFields(this.payload.config, collectionConfig),
|
39
|
+
select
|
40
|
+
});
|
34
41
|
// useEstimatedCount is faster, but not accurate, as it ignores any filters. It is thus set to true if there are no filters.
|
35
42
|
const useEstimatedCount = hasNearConstraint || !versionQuery || Object.keys(versionQuery).length === 0;
|
36
43
|
const paginationOptions = {
|
37
|
-
forceCountFn: hasNearConstraint,
|
38
44
|
lean: true,
|
39
45
|
leanWithId: true,
|
40
46
|
options,
|
41
47
|
page,
|
42
48
|
pagination,
|
49
|
+
projection,
|
43
50
|
sort,
|
44
51
|
useEstimatedCount
|
45
52
|
};
|
@@ -68,7 +75,23 @@ export const queryDrafts = async function queryDrafts({ collection, limit, local
|
|
68
75
|
// limit must also be set here, it's ignored when pagination is false
|
69
76
|
paginationOptions.options.limit = limit;
|
70
77
|
}
|
71
|
-
|
78
|
+
let result;
|
79
|
+
const aggregate = await buildJoinAggregation({
|
80
|
+
adapter: this,
|
81
|
+
collection,
|
82
|
+
collectionConfig,
|
83
|
+
joins,
|
84
|
+
locale,
|
85
|
+
projection,
|
86
|
+
query: versionQuery,
|
87
|
+
versions: true
|
88
|
+
});
|
89
|
+
// build join aggregation
|
90
|
+
if (aggregate) {
|
91
|
+
result = await VersionModel.aggregatePaginate(VersionModel.aggregate(aggregate), paginationOptions);
|
92
|
+
} else {
|
93
|
+
result = await VersionModel.paginate(versionQuery, paginationOptions);
|
94
|
+
}
|
72
95
|
const docs = JSON.parse(JSON.stringify(result.docs));
|
73
96
|
return {
|
74
97
|
...result,
|
@@ -76,9 +99,7 @@ export const queryDrafts = async function queryDrafts({ collection, limit, local
|
|
76
99
|
doc = {
|
77
100
|
_id: doc.parent,
|
78
101
|
id: doc.parent,
|
79
|
-
...doc.version
|
80
|
-
createdAt: doc.createdAt,
|
81
|
-
updatedAt: doc.updatedAt
|
102
|
+
...doc.version
|
82
103
|
};
|
83
104
|
return sanitizeInternalFields(doc);
|
84
105
|
})
|
package/dist/queryDrafts.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/queryDrafts.ts"],"sourcesContent":["import type { PaginateOptions } from 'mongoose'\nimport type { PayloadRequest, QueryDrafts } from 'payload'\n\nimport { combineQueries, flattenWhereToOperators } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildSortParam } from './queries/buildSortParam.js'\nimport sanitizeInternalFields from './utilities/sanitizeInternalFields.js'\nimport { withSession } from './withSession.js'\n\nexport const queryDrafts: QueryDrafts = async function queryDrafts(\n this: MongooseAdapter,\n {
|
1
|
+
{"version":3,"sources":["../src/queryDrafts.ts"],"sourcesContent":["import type { PaginateOptions } from 'mongoose'\nimport type { PayloadRequest, QueryDrafts } from 'payload'\n\nimport { buildVersionCollectionFields, combineQueries, flattenWhereToOperators } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildSortParam } from './queries/buildSortParam.js'\nimport { buildJoinAggregation } from './utilities/buildJoinAggregation.js'\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { sanitizeInternalFields } from './utilities/sanitizeInternalFields.js'\nimport { withSession } from './withSession.js'\n\nexport const queryDrafts: QueryDrafts = async function queryDrafts(\n this: MongooseAdapter,\n {\n collection,\n joins,\n limit,\n locale,\n page,\n pagination,\n req = {} as PayloadRequest,\n select,\n sort: sortArg,\n where,\n },\n) {\n const VersionModel = this.versions[collection]\n const collectionConfig = this.payload.collections[collection].config\n const options = await withSession(this, req)\n\n let hasNearConstraint\n let sort\n\n if (where) {\n const constraints = flattenWhereToOperators(where)\n hasNearConstraint = constraints.some((prop) => Object.keys(prop).some((key) => key === 'near'))\n }\n\n if (!hasNearConstraint) {\n sort = buildSortParam({\n config: this.payload.config,\n fields: collectionConfig.fields,\n locale,\n sort: sortArg || collectionConfig.defaultSort,\n timestamps: true,\n })\n }\n\n const combinedWhere = combineQueries({ latest: { equals: true } }, where)\n\n const versionQuery = await VersionModel.buildQuery({\n locale,\n payload: this.payload,\n where: combinedWhere,\n })\n\n const projection = buildProjectionFromSelect({\n adapter: this,\n fields: buildVersionCollectionFields(this.payload.config, collectionConfig),\n select,\n })\n // useEstimatedCount is faster, but not accurate, as it ignores any filters. It is thus set to true if there are no filters.\n const useEstimatedCount =\n hasNearConstraint || !versionQuery || Object.keys(versionQuery).length === 0\n const paginationOptions: PaginateOptions = {\n lean: true,\n leanWithId: true,\n options,\n page,\n pagination,\n projection,\n sort,\n useEstimatedCount,\n }\n\n if (this.collation) {\n const defaultLocale = 'en'\n paginationOptions.collation = {\n locale: locale && locale !== 'all' && locale !== '*' ? locale : defaultLocale,\n ...this.collation,\n }\n }\n\n if (\n !useEstimatedCount &&\n Object.keys(versionQuery).length === 0 &&\n this.disableIndexHints !== true\n ) {\n // Improve the performance of the countDocuments query which is used if useEstimatedCount is set to false by adding\n // a hint. By default, if no hint is provided, MongoDB does not use an indexed field to count the returned documents,\n // which makes queries very slow. This only happens when no query (filter) is provided. If one is provided, it uses\n // the correct indexed field\n paginationOptions.useCustomCountFn = () => {\n return Promise.resolve(\n VersionModel.countDocuments(versionQuery, {\n hint: { _id: 1 },\n }),\n )\n }\n }\n\n if (limit > 0) {\n paginationOptions.limit = limit\n // limit must also be set here, it's ignored when pagination is false\n paginationOptions.options.limit = limit\n }\n\n let result\n\n const aggregate = await buildJoinAggregation({\n adapter: this,\n collection,\n collectionConfig,\n joins,\n locale,\n projection,\n query: versionQuery,\n versions: true,\n })\n\n // build join aggregation\n if (aggregate) {\n result = await VersionModel.aggregatePaginate(\n VersionModel.aggregate(aggregate),\n paginationOptions,\n )\n } else {\n result = await VersionModel.paginate(versionQuery, paginationOptions)\n }\n\n const docs = JSON.parse(JSON.stringify(result.docs))\n\n return {\n ...result,\n docs: docs.map((doc) => {\n doc = {\n _id: doc.parent,\n id: doc.parent,\n ...doc.version,\n }\n\n return sanitizeInternalFields(doc)\n }),\n }\n}\n"],"names":["buildVersionCollectionFields","combineQueries","flattenWhereToOperators","buildSortParam","buildJoinAggregation","buildProjectionFromSelect","sanitizeInternalFields","withSession","queryDrafts","collection","joins","limit","locale","page","pagination","req","select","sort","sortArg","where","VersionModel","versions","collectionConfig","payload","collections","config","options","hasNearConstraint","constraints","some","prop","Object","keys","key","fields","defaultSort","timestamps","combinedWhere","latest","equals","versionQuery","buildQuery","projection","adapter","useEstimatedCount","length","paginationOptions","lean","leanWithId","collation","defaultLocale","disableIndexHints","useCustomCountFn","Promise","resolve","countDocuments","hint","_id","result","aggregate","query","aggregatePaginate","paginate","docs","JSON","parse","stringify","map","doc","parent","id","version"],"mappings":"AAGA,SAASA,4BAA4B,EAAEC,cAAc,EAAEC,uBAAuB,QAAQ,UAAS;AAI/F,SAASC,cAAc,QAAQ,8BAA6B;AAC5D,SAASC,oBAAoB,QAAQ,sCAAqC;AAC1E,SAASC,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,sBAAsB,QAAQ,wCAAuC;AAC9E,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,cAA2B,eAAeA,YAErD,EACEC,UAAU,EACVC,KAAK,EACLC,KAAK,EACLC,MAAM,EACNC,IAAI,EACJC,UAAU,EACVC,MAAM,CAAC,CAAmB,EAC1BC,MAAM,EACNC,MAAMC,OAAO,EACbC,KAAK,EACN;IAED,MAAMC,eAAe,IAAI,CAACC,QAAQ,CAACZ,WAAW;IAC9C,MAAMa,mBAAmB,IAAI,CAACC,OAAO,CAACC,WAAW,CAACf,WAAW,CAACgB,MAAM;IACpE,MAAMC,UAAU,MAAMnB,YAAY,IAAI,EAAEQ;IAExC,IAAIY;IACJ,IAAIV;IAEJ,IAAIE,OAAO;QACT,MAAMS,cAAc1B,wBAAwBiB;QAC5CQ,oBAAoBC,YAAYC,IAAI,CAAC,CAACC,OAASC,OAAOC,IAAI,CAACF,MAAMD,IAAI,CAAC,CAACI,MAAQA,QAAQ;IACzF;IAEA,IAAI,CAACN,mBAAmB;QACtBV,OAAOd,eAAe;YACpBsB,QAAQ,IAAI,CAACF,OAAO,CAACE,MAAM;YAC3BS,QAAQZ,iBAAiBY,MAAM;YAC/BtB;YACAK,MAAMC,WAAWI,iBAAiBa,WAAW;YAC7CC,YAAY;QACd;IACF;IAEA,MAAMC,gBAAgBpC,eAAe;QAAEqC,QAAQ;YAAEC,QAAQ;QAAK;IAAE,GAAGpB;IAEnE,MAAMqB,eAAe,MAAMpB,aAAaqB,UAAU,CAAC;QACjD7B;QACAW,SAAS,IAAI,CAACA,O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SAAS,MAAMtC,aAAa0C,QAAQ,CAACtB,cAAcM;IACrD;IAEA,MAAMiB,OAAOC,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACR,OAAOK,IAAI;IAElD,OAAO;QACL,GAAGL,MAAM;QACTK,MAAMA,KAAKI,GAAG,CAAC,CAACC;YACdA,MAAM;gBACJX,KAAKW,IAAIC,MAAM;gBACfC,IAAIF,IAAIC,MAAM;gBACd,GAAGD,IAAIG,OAAO;YAChB;YAEA,OAAOjE,uBAAuB8D;QAChC;IACF;AACF,EAAC"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"beginTransaction.d.ts","sourceRoot":"","sources":["../../src/transactions/beginTransaction.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;
|
1
|
+
{"version":3,"file":"beginTransaction.d.ts","sourceRoot":"","sources":["../../src/transactions/beginTransaction.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAS/C,eAAO,MAAM,gBAAgB,EAAE,gBAqB9B,CAAA"}
|
@@ -1,5 +1,7 @@
|
|
1
1
|
import { APIError } from 'payload';
|
2
2
|
import { v4 as uuid } from 'uuid';
|
3
|
+
// Needs await to fulfill the interface
|
4
|
+
// eslint-disable-next-line @typescript-eslint/require-await
|
3
5
|
export const beginTransaction = async function beginTransaction(options) {
|
4
6
|
if (!this.connection) {
|
5
7
|
throw new APIError('beginTransaction called while no connection to the database exists');
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/transactions/beginTransaction.ts"],"sourcesContent":["import type { TransactionOptions } from 'mongodb'\nimport type { BeginTransaction } from 'payload'\n\nimport { APIError } from 'payload'\nimport { v4 as uuid } from 'uuid'\n\nimport type { MongooseAdapter } from '../index.js'\n\nexport const beginTransaction: BeginTransaction = async function beginTransaction(\n this: MongooseAdapter,\n options: TransactionOptions,\n) {\n if (!this.connection) {\n throw new APIError('beginTransaction called while no connection to the database exists')\n }\n\n const client = this.connection.getClient()\n const id = uuid()\n\n if (!this.sessions[id]) {\n this.sessions[id] = client.startSession()\n }\n if (this.sessions[id].inTransaction()) {\n this.payload.logger.warn('beginTransaction called while transaction already exists')\n } else {\n this.sessions[id].startTransaction(options || (this.transactionOptions as TransactionOptions))\n }\n\n return id\n}\n"],"names":["APIError","v4","uuid","beginTransaction","options","connection","client","getClient","id","sessions","startSession","inTransaction","payload","logger","warn","startTransaction","transactionOptions"],"mappings":"AAGA,SAASA,QAAQ,QAAQ,UAAS;AAClC,SAASC,MAAMC,IAAI,QAAQ,OAAM;AAIjC,OAAO,MAAMC,mBAAqC,eAAeA,iBAE/DC,OAA2B;IAE3B,IAAI,CAAC,IAAI,CAACC,UAAU,EAAE;QACpB,MAAM,IAAIL,SAAS;IACrB;IAEA,MAAMM,SAAS,IAAI,CAACD,UAAU,CAACE,SAAS;IACxC,MAAMC,KAAKN;IAEX,IAAI,CAAC,IAAI,CAACO,QAAQ,CAACD,GAAG,EAAE;QACtB,IAAI,CAACC,QAAQ,CAACD,GAAG,GAAGF,OAAOI,YAAY;IACzC;IACA,IAAI,IAAI,CAACD,QAAQ,CAACD,GAAG,CAACG,aAAa,IAAI;QACrC,IAAI,CAACC,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC;IAC3B,OAAO;QACL,IAAI,CAACL,QAAQ,CAACD,GAAG,CAACO,gBAAgB,CAACX,WAAY,IAAI,CAACY,kBAAkB;IACxE;IAEA,OAAOR;AACT,EAAC"}
|
1
|
+
{"version":3,"sources":["../../src/transactions/beginTransaction.ts"],"sourcesContent":["import type { TransactionOptions } from 'mongodb'\nimport type { BeginTransaction } from 'payload'\n\nimport { APIError } from 'payload'\nimport { v4 as uuid } from 'uuid'\n\nimport type { MongooseAdapter } from '../index.js'\n\n// Needs await to fulfill the interface\n// eslint-disable-next-line @typescript-eslint/require-await\nexport const beginTransaction: BeginTransaction = async function beginTransaction(\n this: MongooseAdapter,\n options: TransactionOptions,\n) {\n if (!this.connection) {\n throw new APIError('beginTransaction called while no connection to the database exists')\n }\n\n const client = this.connection.getClient()\n const id = uuid()\n\n if (!this.sessions[id]) {\n this.sessions[id] = client.startSession()\n }\n if (this.sessions[id].inTransaction()) {\n this.payload.logger.warn('beginTransaction called while transaction already exists')\n } else {\n this.sessions[id].startTransaction(options || (this.transactionOptions as TransactionOptions))\n }\n\n return id\n}\n"],"names":["APIError","v4","uuid","beginTransaction","options","connection","client","getClient","id","sessions","startSession","inTransaction","payload","logger","warn","startTransaction","transactionOptions"],"mappings":"AAGA,SAASA,QAAQ,QAAQ,UAAS;AAClC,SAASC,MAAMC,IAAI,QAAQ,OAAM;AAIjC,uCAAuC;AACvC,4DAA4D;AAC5D,OAAO,MAAMC,mBAAqC,eAAeA,iBAE/DC,OAA2B;IAE3B,IAAI,CAAC,IAAI,CAACC,UAAU,EAAE;QACpB,MAAM,IAAIL,SAAS;IACrB;IAEA,MAAMM,SAAS,IAAI,CAACD,UAAU,CAACE,SAAS;IACxC,MAAMC,KAAKN;IAEX,IAAI,CAAC,IAAI,CAACO,QAAQ,CAACD,GAAG,EAAE;QACtB,IAAI,CAACC,QAAQ,CAACD,GAAG,GAAGF,OAAOI,YAAY;IACzC;IACA,IAAI,IAAI,CAACD,QAAQ,CAACD,GAAG,CAACG,aAAa,IAAI;QACrC,IAAI,CAACC,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC;IAC3B,OAAO;QACL,IAAI,CAACL,QAAQ,CAACD,GAAG,CAACO,gBAAgB,CAACX,WAAY,IAAI,CAACY,kBAAkB;IACxE;IAEA,OAAOR;AACT,EAAC"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"commitTransaction.d.ts","sourceRoot":"","sources":["../../src/transactions/commitTransaction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAEhD,eAAO,MAAM,iBAAiB,EAAE,
|
1
|
+
{"version":3,"file":"commitTransaction.d.ts","sourceRoot":"","sources":["../../src/transactions/commitTransaction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAEhD,eAAO,MAAM,iBAAiB,EAAE,iBAgB/B,CAAA"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/transactions/commitTransaction.ts"],"sourcesContent":["import type { CommitTransaction } from 'payload'\n\nexport const commitTransaction: CommitTransaction = async function commitTransaction(id) {\n if (id instanceof Promise) return\n\n if (!this.sessions[id]?.inTransaction()) {\n return\n }\n\n await this.sessions[id].commitTransaction()\n try {\n await this.sessions[id].endSession()\n } catch (error) {\n // ending sessions is only best effort and won't impact anything if it fails since the transaction was committed\n }\n delete this.sessions[id]\n}\n"],"names":["commitTransaction","id","Promise","sessions","inTransaction","endSession","error"],"mappings":"AAEA,OAAO,MAAMA,oBAAuC,eAAeA,kBAAkBC,EAAE;IACrF,IAAIA,cAAcC,SAAS;
|
1
|
+
{"version":3,"sources":["../../src/transactions/commitTransaction.ts"],"sourcesContent":["import type { CommitTransaction } from 'payload'\n\nexport const commitTransaction: CommitTransaction = async function commitTransaction(id) {\n if (id instanceof Promise) {\n return\n }\n\n if (!this.sessions[id]?.inTransaction()) {\n return\n }\n\n await this.sessions[id].commitTransaction()\n try {\n await this.sessions[id].endSession()\n } catch (error) {\n // ending sessions is only best effort and won't impact anything if it fails since the transaction was committed\n }\n delete this.sessions[id]\n}\n"],"names":["commitTransaction","id","Promise","sessions","inTransaction","endSession","error"],"mappings":"AAEA,OAAO,MAAMA,oBAAuC,eAAeA,kBAAkBC,EAAE;IACrF,IAAIA,cAAcC,SAAS;QACzB;IACF;IAEA,IAAI,CAAC,IAAI,CAACC,QAAQ,CAACF,GAAG,EAAEG,iBAAiB;QACvC;IACF;IAEA,MAAM,IAAI,CAACD,QAAQ,CAACF,GAAG,CAACD,iBAAiB;IACzC,IAAI;QACF,MAAM,IAAI,CAACG,QAAQ,CAACF,GAAG,CAACI,UAAU;IACpC,EAAE,OAAOC,OAAO;IACd,gHAAgH;IAClH;IACA,OAAO,IAAI,CAACH,QAAQ,CAACF,GAAG;AAC1B,EAAC"}
|
package/dist/types.d.ts
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
import type { IndexDefinition, IndexOptions, Model, PaginateModel, SchemaOptions } from 'mongoose';
|
2
|
-
import type { ArrayField,
|
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';
|
3
3
|
import type { BuildQueryArgs } from './queries/buildQuery.js';
|
4
|
-
export interface CollectionModel extends Model<any>, PaginateModel<any> {
|
4
|
+
export interface CollectionModel extends Model<any>, PaginateModel<any>, AggregatePaginateModel<any> {
|
5
5
|
/** buildQuery is used to transform payload's where operator into what can be used by mongoose (e.g. id => _id) */
|
6
6
|
buildQuery: (args: BuildQueryArgs) => Promise<Record<string, unknown>>;
|
7
7
|
}
|
@@ -40,13 +40,14 @@ export type FieldGeneratorFunction<TSchema, TField extends Field> = (args: Field
|
|
40
40
|
*/
|
41
41
|
export type FieldToSchemaMap<TSchema> = {
|
42
42
|
array: FieldGeneratorFunction<TSchema, ArrayField>;
|
43
|
-
blocks: FieldGeneratorFunction<TSchema,
|
43
|
+
blocks: FieldGeneratorFunction<TSchema, BlocksField>;
|
44
44
|
checkbox: FieldGeneratorFunction<TSchema, CheckboxField>;
|
45
45
|
code: FieldGeneratorFunction<TSchema, CodeField>;
|
46
46
|
collapsible: FieldGeneratorFunction<TSchema, CollapsibleField>;
|
47
47
|
date: FieldGeneratorFunction<TSchema, DateField>;
|
48
48
|
email: FieldGeneratorFunction<TSchema, EmailField>;
|
49
49
|
group: FieldGeneratorFunction<TSchema, GroupField>;
|
50
|
+
join: FieldGeneratorFunction<TSchema, JoinField>;
|
50
51
|
json: FieldGeneratorFunction<TSchema, JSONField>;
|
51
52
|
number: FieldGeneratorFunction<TSchema, NumberField>;
|
52
53
|
point: FieldGeneratorFunction<TSchema, PointField>;
|
@@ -62,8 +63,10 @@ export type FieldToSchemaMap<TSchema> = {
|
|
62
63
|
};
|
63
64
|
export type MigrateUpArgs = {
|
64
65
|
payload: Payload;
|
66
|
+
req: PayloadRequest;
|
65
67
|
};
|
66
68
|
export type MigrateDownArgs = {
|
67
69
|
payload: Payload;
|
70
|
+
req: PayloadRequest;
|
68
71
|
};
|
69
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":"AAAA,OAAO,KAAK,
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,sBAAsB,EACtB,eAAe,EACf,YAAY,EACZ,KAAK,EACL,aAAa,EACb,aAAa,EACd,MAAM,UAAU,CAAA;AACjB,OAAO,KAAK,EACV,UAAU,EACV,WAAW,EACX,aAAa,EACb,SAAS,EACT,gBAAgB,EAChB,SAAS,EACT,UAAU,EACV,KAAK,EACL,UAAU,EACV,SAAS,EACT,SAAS,EACT,WAAW,EACX,OAAO,EACP,cAAc,EACd,UAAU,EACV,UAAU,EACV,iBAAiB,EACjB,aAAa,EACb,QAAQ,EACR,eAAe,EACf,WAAW,EACX,SAAS,EACT,aAAa,EACb,SAAS,EACT,WAAW,EACZ,MAAM,SAAS,CAAA;AAEhB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AAE7D,MAAM,WAAW,eACf,SAAQ,KAAK,CAAC,GAAG,CAAC,EAChB,aAAa,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CAAA;IACpD,IAAI,EAAE,sBAAsB,CAAC,OAAO,EAAE,SAAS,CAAC,CAAA;IAChD,IAAI,EAAE,sBAAsB,CAAC,OAAO,EAAE,SAAS,CAAC,CAAA;IAChD,QAAQ,EAAE,sBAAsB,CAAC,OAAO,EAAE,aAAa,CAAC,CAAA;IACxD,MAAM,EAAE,sBAAsB,CAAC,OAAO,EAAE,WAAW,CAAC,CAAA;CACrD,CAAA;AAED,MAAM,MAAM,aAAa,GAAG;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,GAAG,EAAE,cAAc,CAAA;CAAE,CAAA;AACrE,MAAM,MAAM,eAAe,GAAG;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,GAAG,EAAE,cAAc,CAAA;CAAE,CAAA"}
|
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"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"updateGlobal.d.ts","sourceRoot":"","sources":["../src/updateGlobal.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"updateGlobal.d.ts","sourceRoot":"","sources":["../src/updateGlobal.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAkB,YAAY,EAAE,MAAM,SAAS,CAAA;AAS3D,eAAO,MAAM,YAAY,EAAE,YAgC1B,CAAA"}
|
package/dist/updateGlobal.js
CHANGED
@@ -1,16 +1,30 @@
|
|
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, options: optionsArgs = {}, 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 = {
|
9
|
+
...optionsArgs,
|
6
10
|
...await withSession(this, req),
|
7
11
|
lean: true,
|
8
|
-
new: true
|
12
|
+
new: true,
|
13
|
+
projection: buildProjectionFromSelect({
|
14
|
+
adapter: this,
|
15
|
+
fields,
|
16
|
+
select
|
17
|
+
})
|
9
18
|
};
|
10
19
|
let result;
|
20
|
+
const sanitizedData = sanitizeRelationshipIDs({
|
21
|
+
config: this.payload.config,
|
22
|
+
data,
|
23
|
+
fields
|
24
|
+
});
|
11
25
|
result = await Model.findOneAndUpdate({
|
12
26
|
globalType: slug
|
13
|
-
},
|
27
|
+
}, sanitizedData, options);
|
14
28
|
result = JSON.parse(JSON.stringify(result));
|
15
29
|
// custom id type reset
|
16
30
|
result.id = result._id;
|
package/dist/updateGlobal.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/updateGlobal.ts"],"sourcesContent":["import type { PayloadRequest, UpdateGlobal } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport sanitizeInternalFields from './utilities/sanitizeInternalFields.js'\nimport { withSession } from './withSession.js'\n\nexport const updateGlobal: UpdateGlobal = async function updateGlobal(\n this: MongooseAdapter,\n { slug, data, req = {} as PayloadRequest },\n) {\n const Model = this.globals\n const options = {\n ...(await withSession(this, req)),\n lean: true,\n new: true,\n }\n\n let result\n result = await Model.findOneAndUpdate({ globalType: slug },
|
1
|
+
{"version":3,"sources":["../src/updateGlobal.ts"],"sourcesContent":["import type { QueryOptions } from 'mongoose'\nimport 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, options: optionsArgs = {}, 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: QueryOptions = {\n ...optionsArgs,\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","options","optionsArgs","req","select","Model","globals","fields","payload","config","find","global","lean","new","projection","adapter","result","sanitizedData","findOneAndUpdate","globalType","JSON","parse","stringify","id","_id"],"mappings":"AAKA,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,SAASC,cAAc,CAAC,CAAC,EAAEC,MAAM,CAAC,CAAmB,EAAEC,MAAM,EAAE;IAE7E,MAAMC,QAAQ,IAAI,CAACC,OAAO;IAC1B,MAAMC,SAAS,IAAI,CAACC,OAAO,CAACC,MAAM,CAACH,OAAO,CAACI,IAAI,CAAC,CAACC,SAAWA,OAAOZ,IAAI,KAAKA,MAAMQ,MAAM;IAExF,MAAMN,UAAwB;QAC5B,GAAGC,WAAW;QACd,GAAI,MAAML,YAAY,IAAI,EAAEM,IAAI;QAChCS,MAAM;QACNC,KAAK;QACLC,YAAYpB,0BAA0B;YAAEqB,SAAS,IAAI;YAAER;YAAQH;QAAO;IACxE;IAEA,IAAIY;IAEJ,MAAMC,gBAAgBrB,wBAAwB;QAC5Ca,QAAQ,IAAI,CAACD,OAAO,CAACC,MAAM;QAC3BT;QACAO;IACF;IAEAS,SAAS,MAAMX,MAAMa,gBAAgB,CAAC;QAAEC,YAAYpB;IAAK,GAAGkB,eAAehB;IAE3Ee,SAASI,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACN;IAEnC,uBAAuB;IACvBA,OAAOO,EAAE,GAAGP,OAAOQ,GAAG;IACtBR,SAASrB,uBAAuBqB;IAEhC,OAAOA;AACT,EAAC"}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import type
|
1
|
+
import { type TypeWithID, type UpdateGlobalVersionArgs } from 'payload';
|
2
2
|
import type { MongooseAdapter } from './index.js';
|
3
|
-
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, options: optionsArgs, req, select, versionData, where, }: UpdateGlobalVersionArgs<T>): Promise<any>;
|
4
4
|
//# sourceMappingURL=updateGlobalVersion.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"updateGlobalVersion.d.ts","sourceRoot":"","sources":["../src/updateGlobalVersion.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"updateGlobalVersion.d.ts","sourceRoot":"","sources":["../src/updateGlobalVersion.ts"],"names":[],"mappings":"AAEA,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,OAAO,EAAE,WAAgB,EACzB,GAA0B,EAC1B,MAAM,EACN,WAAW,EACX,KAAK,GACN,EAAE,uBAAuB,CAAC,CAAC,CAAC,gBAyC9B"}
|
@@ -1,22 +1,37 @@
|
|
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, options: optionsArgs = {}, 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 = {
|
14
|
+
...optionsArgs,
|
10
15
|
...await withSession(this, req),
|
11
16
|
lean: true,
|
12
|
-
new: true
|
17
|
+
new: true,
|
18
|
+
projection: buildProjectionFromSelect({
|
19
|
+
adapter: this,
|
20
|
+
fields,
|
21
|
+
select
|
22
|
+
})
|
13
23
|
};
|
14
24
|
const query = await VersionModel.buildQuery({
|
15
25
|
locale,
|
16
26
|
payload: this.payload,
|
17
27
|
where: whereToUse
|
18
28
|
});
|
19
|
-
const
|
29
|
+
const sanitizedData = sanitizeRelationshipIDs({
|
30
|
+
config: this.payload.config,
|
31
|
+
data: versionData,
|
32
|
+
fields
|
33
|
+
});
|
34
|
+
const doc = await VersionModel.findOneAndUpdate(query, sanitizedData, options);
|
20
35
|
const result = JSON.parse(JSON.stringify(doc));
|
21
36
|
const verificationToken = doc._verificationToken;
|
22
37
|
// custom id type reset
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/updateGlobalVersion.ts"],"sourcesContent":["import type { PayloadRequest
|
1
|
+
{"version":3,"sources":["../src/updateGlobalVersion.ts"],"sourcesContent":["import type { QueryOptions } from 'mongoose'\n\nimport {\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 options: optionsArgs = {},\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: 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 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","options","optionsArgs","req","select","versionData","where","VersionModel","versions","whereToUse","equals","fields","payload","config","globals","find","slug","lean","new","projection","adapter","query","buildQuery","sanitizedData","data","doc","findOneAndUpdate","result","JSON","parse","stringify","verificationToken","_verificationToken","_id"],"mappings":"AAEA,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,SAASC,cAAc,CAAC,CAAC,EACzBC,MAAM,CAAC,CAAmB,EAC1BC,MAAM,EACNC,WAAW,EACXC,KAAK,EACsB;IAE7B,MAAMC,eAAe,IAAI,CAACC,QAAQ,CAACT,WAAW;IAC9C,MAAMU,aAAaH,SAAS;QAAET,IAAI;YAAEa,QAAQb;QAAG;IAAE;IACjD,MAAMc,SAASnB,yBACb,IAAI,CAACoB,OAAO,CAACC,MAAM,EACnB,IAAI,CAACD,OAAO,CAACC,MAAM,CAACC,OAAO,CAACC,IAAI,CAAC,CAACjB,SAAWA,OAAOkB,IAAI,KAAKjB;IAG/D,MAAME,UAAwB;QAC5B,GAAGC,WAAW;QACd,GAAI,MAAMP,YAAY,IAAI,EAAEQ,IAAI;QAChCc,MAAM;QACNC,KAAK;QACLC,YAAY1B,0BAA0B;YAAE2B,SAAS,IAAI;YAAET;YAAQP;QAAO;IACxE;IAEA,MAAMiB,QAAQ,MAAMd,aAAae,UAAU,CAAC;QAC1CtB;QACAY,SAAS,IAAI,CAACA,OAAO;QACrBN,OAAOG;IACT;IAEA,MAAMc,gBAAgB7B,wBAAwB;QAC5CmB,QAAQ,IAAI,CAACD,OAAO,CAACC,MAAM;QAC3BW,MAAMnB;QACNM;IACF;IAEA,MAAMc,MAAM,MAAMlB,aAAamB,gBAAgB,CAACL,OAAOE,eAAetB;IAEtE,MAAM0B,SAASC,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACL;IAEzC,MAAMM,oBAAoBN,IAAIO,kBAAkB;IAEhD,uBAAuB;IACvBL,OAAO9B,EAAE,GAAG8B,OAAOM,GAAG;IACtB,IAAIF,mBAAmB;QACrBJ,OAAOK,kBAAkB,GAAGD;IAC9B;IACA,OAAOJ;AACT"}
|
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 { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js';
|
1
2
|
import { handleError } from './utilities/handleError.js';
|
2
|
-
import sanitizeInternalFields from './utilities/sanitizeInternalFields.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 = {
|
15
|
+
...optionsArgs,
|
12
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,8 +28,13 @@ 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
39
|
handleError({
|
26
40
|
collection,
|
package/dist/updateOne.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/updateOne.ts"],"sourcesContent":["import type { PayloadRequest, UpdateOne } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { handleError } from './utilities/handleError.js'\nimport sanitizeInternalFields from './utilities/sanitizeInternalFields.js'\nimport { withSession } from './withSession.js'\n\nexport const updateOne: UpdateOne = async function updateOne(\n this: MongooseAdapter,\n {
|
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,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ts
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"updateVersion.d.ts","sourceRoot":"","sources":["../src/updateVersion.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"updateVersion.d.ts","sourceRoot":"","sources":["../src/updateVersion.ts"],"names":[],"mappings":"AAEA,OAAO,EAAqD,KAAK,aAAa,EAAE,MAAM,SAAS,CAAA;AAQ/F,eAAO,MAAM,aAAa,EAAE,aAoD3B,CAAA"}
|
package/dist/updateVersion.js
CHANGED
@@ -1,22 +1,37 @@
|
|
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, options: optionsArgs = {}, 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 = {
|
14
|
+
...optionsArgs,
|
10
15
|
...await withSession(this, req),
|
11
16
|
lean: true,
|
12
|
-
new: true
|
17
|
+
new: true,
|
18
|
+
projection: buildProjectionFromSelect({
|
19
|
+
adapter: this,
|
20
|
+
fields,
|
21
|
+
select
|
22
|
+
})
|
13
23
|
};
|
14
24
|
const query = await VersionModel.buildQuery({
|
15
25
|
locale,
|
16
26
|
payload: this.payload,
|
17
27
|
where: whereToUse
|
18
28
|
});
|
19
|
-
const
|
29
|
+
const sanitizedData = sanitizeRelationshipIDs({
|
30
|
+
config: this.payload.config,
|
31
|
+
data: versionData,
|
32
|
+
fields
|
33
|
+
});
|
34
|
+
const doc = await VersionModel.findOneAndUpdate(query, sanitizedData, options);
|
20
35
|
const result = JSON.parse(JSON.stringify(doc));
|
21
36
|
const verificationToken = doc._verificationToken;
|
22
37
|
// custom id type reset
|