@payloadcms/db-mongodb 3.0.0-alpha.5 → 3.0.0-alpha.50
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/README.md +0 -2
- package/dist/connect.d.ts.map +1 -1
- package/dist/connect.js +20 -25
- package/dist/connect.js.map +1 -0
- package/dist/create.js +6 -21
- package/dist/create.js.map +1 -0
- package/dist/createGlobal.js +6 -21
- package/dist/createGlobal.js.map +1 -0
- package/dist/createGlobalVersion.js +4 -14
- package/dist/createGlobalVersion.js.map +1 -0
- package/dist/createMigration.d.ts.map +1 -1
- package/dist/createMigration.js +15 -25
- package/dist/createMigration.js.map +1 -0
- package/dist/createVersion.js +4 -14
- package/dist/createVersion.js.map +1 -0
- package/dist/deleteMany.js +4 -14
- package/dist/deleteMany.js.map +1 -0
- package/dist/deleteOne.js +6 -21
- package/dist/deleteOne.js.map +1 -0
- package/dist/deleteVersions.js +4 -14
- package/dist/deleteVersions.js.map +1 -0
- package/dist/destroy.js +5 -21
- package/dist/destroy.js.map +1 -0
- package/dist/find.js +10 -25
- package/dist/find.js.map +1 -0
- package/dist/findGlobal.js +8 -23
- package/dist/findGlobal.js.map +1 -0
- package/dist/findGlobalVersions.js +12 -27
- package/dist/findGlobalVersions.js.map +1 -0
- package/dist/findOne.js +6 -21
- package/dist/findOne.js.map +1 -0
- package/dist/findVersions.js +10 -25
- package/dist/findVersions.js.map +1 -0
- package/dist/index.d.ts +36 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +65 -80
- package/dist/index.js.map +1 -0
- package/dist/init.js +24 -39
- package/dist/init.js.map +1 -0
- package/dist/migrateFresh.d.ts +1 -1
- package/dist/migrateFresh.d.ts.map +1 -1
- package/dist/migrateFresh.js +13 -26
- package/dist/migrateFresh.js.map +1 -0
- package/dist/models/buildCollectionSchema.d.ts +25 -0
- package/dist/models/buildCollectionSchema.d.ts.map +1 -1
- package/dist/models/buildCollectionSchema.js +8 -23
- package/dist/models/buildCollectionSchema.js.map +1 -0
- package/dist/models/buildGlobalModel.d.ts +1 -1
- package/dist/models/buildGlobalModel.d.ts.map +1 -1
- package/dist/models/buildGlobalModel.js +9 -24
- package/dist/models/buildGlobalModel.js.map +1 -0
- package/dist/models/buildSchema.d.ts +26 -2
- package/dist/models/buildSchema.d.ts.map +1 -1
- package/dist/models/buildSchema.js +22 -32
- package/dist/models/buildSchema.js.map +1 -0
- package/dist/queries/buildAndOrConditions.js +4 -14
- package/dist/queries/buildAndOrConditions.js.map +1 -0
- package/dist/queries/buildQuery.js +6 -16
- package/dist/queries/buildQuery.js.map +1 -0
- package/dist/queries/buildSearchParams.d.ts.map +1 -1
- package/dist/queries/buildSearchParams.js +21 -32
- package/dist/queries/buildSearchParams.js.map +1 -0
- package/dist/queries/buildSortParam.d.ts +25 -0
- package/dist/queries/buildSortParam.d.ts.map +1 -1
- package/dist/queries/buildSortParam.js +4 -14
- package/dist/queries/buildSortParam.js.map +1 -0
- package/dist/queries/getLocalizedSortProperty.js +8 -18
- package/dist/queries/getLocalizedSortProperty.js.map +1 -0
- package/dist/queries/getLocalizedSortProperty.spec.js +19 -23
- package/dist/queries/getLocalizedSortProperty.spec.js.map +1 -0
- package/dist/queries/mock.js +1 -2
- package/dist/queries/mock.js.map +1 -0
- package/dist/queries/operatorMap.js +2 -12
- package/dist/queries/operatorMap.js.map +1 -0
- package/dist/queries/parseParams.js +12 -27
- package/dist/queries/parseParams.js.map +1 -0
- package/dist/queries/sanitizeQueryValue.js +9 -24
- package/dist/queries/sanitizeQueryValue.js.map +1 -0
- package/dist/queryDrafts.js +11 -26
- package/dist/queryDrafts.js.map +1 -0
- package/dist/testCredentials.js +4 -25
- package/dist/testCredentials.js.map +1 -0
- package/dist/transactions/beginTransaction.js +6 -16
- package/dist/transactions/beginTransaction.js.map +1 -0
- package/dist/transactions/commitTransaction.js +2 -12
- package/dist/transactions/commitTransaction.js.map +1 -0
- package/dist/transactions/rollbackTransaction.js +2 -12
- package/dist/transactions/rollbackTransaction.js.map +1 -0
- package/dist/types.d.ts +26 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +2 -5
- package/dist/types.js.map +1 -0
- package/dist/updateGlobal.js +6 -21
- package/dist/updateGlobal.js.map +1 -0
- package/dist/updateGlobalVersion.d.ts +1 -1
- package/dist/updateGlobalVersion.d.ts.map +1 -1
- package/dist/updateGlobalVersion.js +4 -14
- package/dist/updateGlobalVersion.js.map +1 -0
- package/dist/updateOne.d.ts.map +1 -1
- package/dist/updateOne.js +8 -23
- package/dist/updateOne.js.map +1 -0
- package/dist/updateVersion.js +4 -14
- package/dist/updateVersion.js.map +1 -0
- package/dist/utilities/handleError.js +6 -21
- package/dist/utilities/handleError.js.map +1 -0
- package/dist/utilities/sanitizeInternalFields.d.ts.map +1 -1
- package/dist/utilities/sanitizeInternalFields.js +2 -12
- package/dist/utilities/sanitizeInternalFields.js.map +1 -0
- package/dist/withSession.d.ts +26 -1
- package/dist/withSession.d.ts.map +1 -1
- package/dist/withSession.js +5 -12
- package/dist/withSession.js.map +1 -0
- package/package.json +18 -9
- package/src/index.ts +198 -0
|
@@ -1,24 +1,9 @@
|
|
|
1
|
-
/* eslint-disable no-restricted-syntax */ /* eslint-disable no-await-in-loop */
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
get: function() {
|
|
8
|
-
return parseParams;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
const _deepmerge = /*#__PURE__*/ _interop_require_default(require("deepmerge"));
|
|
12
|
-
const _types = require("payload/types");
|
|
13
|
-
const _utilities = require("payload/utilities");
|
|
14
|
-
const _buildAndOrConditions = require("./buildAndOrConditions");
|
|
15
|
-
const _buildSearchParams = require("./buildSearchParams");
|
|
16
|
-
function _interop_require_default(obj) {
|
|
17
|
-
return obj && obj.__esModule ? obj : {
|
|
18
|
-
default: obj
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
async function parseParams({ collectionSlug, fields, globalSlug, locale, payload, where }) {
|
|
1
|
+
/* eslint-disable no-restricted-syntax */ /* eslint-disable no-await-in-loop */ import deepmerge from 'deepmerge';
|
|
2
|
+
import { validOperators } from 'payload/types';
|
|
3
|
+
import { combineMerge } from 'payload/utilities';
|
|
4
|
+
import { buildAndOrConditions } from './buildAndOrConditions.js';
|
|
5
|
+
import { buildSearchParam } from './buildSearchParams.js';
|
|
6
|
+
export async function parseParams({ collectionSlug, fields, globalSlug, locale, payload, where }) {
|
|
22
7
|
let result = {};
|
|
23
8
|
if (typeof where === 'object') {
|
|
24
9
|
// We need to determine if the whereKey is an AND, OR, or a schema path
|
|
@@ -31,7 +16,7 @@ async function parseParams({ collectionSlug, fields, globalSlug, locale, payload
|
|
|
31
16
|
conditionOperator = '$or';
|
|
32
17
|
}
|
|
33
18
|
if (Array.isArray(condition)) {
|
|
34
|
-
const builtConditions = await
|
|
19
|
+
const builtConditions = await buildAndOrConditions({
|
|
35
20
|
collectionSlug,
|
|
36
21
|
fields,
|
|
37
22
|
globalSlug,
|
|
@@ -47,8 +32,8 @@ async function parseParams({ collectionSlug, fields, globalSlug, locale, payload
|
|
|
47
32
|
const pathOperators = where[relationOrPath];
|
|
48
33
|
if (typeof pathOperators === 'object') {
|
|
49
34
|
for (const operator of Object.keys(pathOperators)){
|
|
50
|
-
if (
|
|
51
|
-
const searchParam = await
|
|
35
|
+
if (validOperators.includes(operator)) {
|
|
36
|
+
const searchParam = await buildSearchParam({
|
|
52
37
|
collectionSlug,
|
|
53
38
|
fields,
|
|
54
39
|
globalSlug,
|
|
@@ -64,8 +49,8 @@ async function parseParams({ collectionSlug, fields, globalSlug, locale, payload
|
|
|
64
49
|
[searchParam.path]: searchParam.value
|
|
65
50
|
};
|
|
66
51
|
} else if (typeof searchParam?.value === 'object') {
|
|
67
|
-
result = (
|
|
68
|
-
arrayMerge:
|
|
52
|
+
result = deepmerge(result, searchParam.value, {
|
|
53
|
+
arrayMerge: combineMerge
|
|
69
54
|
});
|
|
70
55
|
}
|
|
71
56
|
}
|
|
@@ -77,4 +62,4 @@ async function parseParams({ collectionSlug, fields, globalSlug, locale, payload
|
|
|
77
62
|
return result;
|
|
78
63
|
}
|
|
79
64
|
|
|
80
|
-
//# sourceMappingURL=
|
|
65
|
+
//# sourceMappingURL=parseParams.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/queries/parseParams.ts"],"sourcesContent":["/* eslint-disable no-restricted-syntax */\n/* eslint-disable no-await-in-loop */\nimport type { FilterQuery } from 'mongoose'\nimport type { Payload } from 'payload'\nimport type { Operator, Where } from 'payload/types'\nimport type { Field } from 'payload/types'\n\nimport deepmerge from 'deepmerge'\nimport { validOperators } from 'payload/types'\nimport { combineMerge } from 'payload/utilities'\n\nimport { buildAndOrConditions } from './buildAndOrConditions.js'\nimport { buildSearchParam } from './buildSearchParams.js'\n\nexport async function parseParams({\n collectionSlug,\n fields,\n globalSlug,\n locale,\n payload,\n where,\n}: {\n collectionSlug?: string\n fields: Field[]\n globalSlug?: string\n locale: string\n payload: Payload\n where: Where\n}): Promise<Record<string, unknown>> {\n let result = {} as FilterQuery<any>\n\n if (typeof where === 'object') {\n // We need to determine if the whereKey is an AND, OR, or a schema path\n for (const relationOrPath of Object.keys(where)) {\n const condition = where[relationOrPath]\n let conditionOperator: '$and' | '$or'\n if (relationOrPath.toLowerCase() === 'and') {\n conditionOperator = '$and'\n } else if (relationOrPath.toLowerCase() === 'or') {\n conditionOperator = '$or'\n }\n if (Array.isArray(condition)) {\n const builtConditions = await buildAndOrConditions({\n collectionSlug,\n fields,\n globalSlug,\n locale,\n payload,\n where: condition,\n })\n if (builtConditions.length > 0) result[conditionOperator] = builtConditions\n } else {\n // It's a path - and there can be multiple comparisons on a single path.\n // For example - title like 'test' and title not equal to 'tester'\n // So we need to loop on keys again here to handle each operator independently\n const pathOperators = where[relationOrPath]\n if (typeof pathOperators === 'object') {\n for (const operator of Object.keys(pathOperators)) {\n if (validOperators.includes(operator as Operator)) {\n const searchParam = await buildSearchParam({\n collectionSlug,\n fields,\n globalSlug,\n incomingPath: relationOrPath,\n locale,\n operator,\n payload,\n val: pathOperators[operator],\n })\n\n if (searchParam?.value && searchParam?.path) {\n result = {\n ...result,\n [searchParam.path]: searchParam.value,\n }\n } else if (typeof searchParam?.value === 'object') {\n result = deepmerge(result, searchParam.value, { arrayMerge: combineMerge })\n }\n }\n }\n }\n }\n }\n }\n\n return result\n}\n"],"names":["deepmerge","validOperators","combineMerge","buildAndOrConditions","buildSearchParam","parseParams","collectionSlug","fields","globalSlug","locale","payload","where","result","relationOrPath","Object","keys","condition","conditionOperator","toLowerCase","Array","isArray","builtConditions","length","pathOperators","operator","includes","searchParam","incomingPath","val","value","path","arrayMerge"],"mappings":"AAAA,uCAAuC,GACvC,mCAAmC,GAMnC,OAAOA,eAAe,YAAW;AACjC,SAASC,cAAc,QAAQ,gBAAe;AAC9C,SAASC,YAAY,QAAQ,oBAAmB;AAEhD,SAASC,oBAAoB,QAAQ,4BAA2B;AAChE,SAASC,gBAAgB,QAAQ,yBAAwB;AAEzD,OAAO,eAAeC,YAAY,EAChCC,cAAc,EACdC,MAAM,EACNC,UAAU,EACVC,MAAM,EACNC,OAAO,EACPC,KAAK,EAQN;IACC,IAAIC,SAAS,CAAC;IAEd,IAAI,OAAOD,UAAU,UAAU;QAC7B,uEAAuE;QACvE,KAAK,MAAME,kBAAkBC,OAAOC,IAAI,CAACJ,OAAQ;YAC/C,MAAMK,YAAYL,KAAK,CAACE,eAAe;YACvC,IAAII;YACJ,IAAIJ,eAAeK,WAAW,OAAO,OAAO;gBAC1CD,oBAAoB;YACtB,OAAO,IAAIJ,eAAeK,WAAW,OAAO,MAAM;gBAChDD,oBAAoB;YACtB;YACA,IAAIE,MAAMC,OAAO,CAACJ,YAAY;gBAC5B,MAAMK,kBAAkB,MAAMlB,qBAAqB;oBACjDG;oBACAC;oBACAC;oBACAC;oBACAC;oBACAC,OAAOK;gBACT;gBACA,IAAIK,gBAAgBC,MAAM,GAAG,GAAGV,MAAM,CAACK,kBAAkB,GAAGI;YAC9D,OAAO;gBACL,wEAAwE;gBACxE,kEAAkE;gBAClE,8EAA8E;gBAC9E,MAAME,gBAAgBZ,KAAK,CAACE,eAAe;gBAC3C,IAAI,OAAOU,kBAAkB,UAAU;oBACrC,KAAK,MAAMC,YAAYV,OAAOC,IAAI,CAACQ,eAAgB;wBACjD,IAAItB,eAAewB,QAAQ,CAACD,WAAuB;4BACjD,MAAME,cAAc,MAAMtB,iBAAiB;gCACzCE;gCACAC;gCACAC;gCACAmB,cAAcd;gCACdJ;gCACAe;gCACAd;gCACAkB,KAAKL,aAAa,CAACC,SAAS;4BAC9B;4BAEA,IAAIE,aAAaG,SAASH,aAAaI,MAAM;gCAC3ClB,SAAS;oCACP,GAAGA,MAAM;oCACT,CAACc,YAAYI,IAAI,CAAC,EAAEJ,YAAYG,KAAK;gCACvC;4BACF,OAAO,IAAI,OAAOH,aAAaG,UAAU,UAAU;gCACjDjB,SAASZ,UAAUY,QAAQc,YAAYG,KAAK,EAAE;oCAAEE,YAAY7B;gCAAa;4BAC3E;wBACF;oBACF;gBACF;YACF;QACF;IACF;IAEA,OAAOU;AACT"}
|
|
@@ -1,27 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "sanitizeQueryValue", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function() {
|
|
8
|
-
return sanitizeQueryValue;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
const _mongoose = /*#__PURE__*/ _interop_require_default(require("mongoose"));
|
|
12
|
-
const _utilities = require("payload/utilities");
|
|
13
|
-
function _interop_require_default(obj) {
|
|
14
|
-
return obj && obj.__esModule ? obj : {
|
|
15
|
-
default: obj
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
const sanitizeQueryValue = ({ field, hasCustomID, operator, path, val })=>{
|
|
1
|
+
import mongoose from 'mongoose';
|
|
2
|
+
import { createArrayFromCommaDelineated } from 'payload/utilities';
|
|
3
|
+
export const sanitizeQueryValue = ({ field, hasCustomID, operator, path, val })=>{
|
|
19
4
|
let formattedValue = val;
|
|
20
5
|
let formattedOperator = operator;
|
|
21
6
|
// Disregard invalid _ids
|
|
22
7
|
if (path === '_id' && typeof val === 'string' && val.split(',').length === 1) {
|
|
23
8
|
if (!hasCustomID) {
|
|
24
|
-
const isValid =
|
|
9
|
+
const isValid = mongoose.Types.ObjectId.isValid(val);
|
|
25
10
|
if (!isValid) {
|
|
26
11
|
return {
|
|
27
12
|
operator: formattedOperator,
|
|
@@ -49,7 +34,7 @@ const sanitizeQueryValue = ({ field, hasCustomID, operator, path, val })=>{
|
|
|
49
34
|
'in',
|
|
50
35
|
'not_in'
|
|
51
36
|
].includes(operator) && typeof formattedValue === 'string') {
|
|
52
|
-
formattedValue =
|
|
37
|
+
formattedValue = createArrayFromCommaDelineated(formattedValue);
|
|
53
38
|
if (field.type === 'number') {
|
|
54
39
|
formattedValue = formattedValue.map((arrayVal)=>parseFloat(arrayVal));
|
|
55
40
|
}
|
|
@@ -57,7 +42,7 @@ const sanitizeQueryValue = ({ field, hasCustomID, operator, path, val })=>{
|
|
|
57
42
|
if (field.type === 'number' && typeof formattedValue === 'string') {
|
|
58
43
|
formattedValue = Number(val);
|
|
59
44
|
}
|
|
60
|
-
if (field.type === 'date' && typeof val === 'string') {
|
|
45
|
+
if (field.type === 'date' && typeof val === 'string' && operator !== 'exists') {
|
|
61
46
|
formattedValue = new Date(val);
|
|
62
47
|
if (Number.isNaN(Date.parse(formattedValue))) {
|
|
63
48
|
return undefined;
|
|
@@ -94,7 +79,7 @@ const sanitizeQueryValue = ({ field, hasCustomID, operator, path, val })=>{
|
|
|
94
79
|
const newValues = [
|
|
95
80
|
inVal
|
|
96
81
|
];
|
|
97
|
-
if (
|
|
82
|
+
if (mongoose.Types.ObjectId.isValid(inVal)) newValues.push(new mongoose.Types.ObjectId(inVal));
|
|
98
83
|
const parsedNumber = parseFloat(inVal);
|
|
99
84
|
if (!Number.isNaN(parsedNumber)) newValues.push(parsedNumber);
|
|
100
85
|
return [
|
|
@@ -114,7 +99,7 @@ const sanitizeQueryValue = ({ field, hasCustomID, operator, path, val })=>{
|
|
|
114
99
|
[lng, lat, maxDistance, minDistance] = formattedValue;
|
|
115
100
|
}
|
|
116
101
|
if (typeof formattedValue === 'string') {
|
|
117
|
-
[lng, lat, maxDistance, minDistance] =
|
|
102
|
+
[lng, lat, maxDistance, minDistance] = createArrayFromCommaDelineated(formattedValue);
|
|
118
103
|
}
|
|
119
104
|
if (lng == null || lat == null || maxDistance == null && minDistance == null) {
|
|
120
105
|
formattedValue = undefined;
|
|
@@ -199,4 +184,4 @@ const sanitizeQueryValue = ({ field, hasCustomID, operator, path, val })=>{
|
|
|
199
184
|
};
|
|
200
185
|
};
|
|
201
186
|
|
|
202
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9xdWVyaWVzL3Nhbml0aXplUXVlcnlWYWx1ZS50cyJdLCJzb3VyY2VzQ29udGVudCI6WyJpbXBvcnQgdHlwZSB7IEZpZWxkLCBUYWJBc0ZpZWxkIH0gZnJvbSAncGF5bG9hZC90eXBlcydcblxuaW1wb3J0IG1vbmdvb3NlIGZyb20gJ21vbmdvb3NlJ1xuaW1wb3J0IHsgY3JlYXRlQXJyYXlGcm9tQ29tbWFEZWxpbmVhdGVkIH0gZnJvbSAncGF5bG9hZC91dGlsaXRpZXMnXG5cbnR5cGUgU2FuaXRpemVRdWVyeVZhbHVlQXJncyA9IHtcbiAgZmllbGQ6IEZpZWxkIHwgVGFiQXNGaWVsZFxuICBoYXNDdXN0b21JRDogYm9vbGVhblxuICBvcGVyYXRvcjogc3RyaW5nXG4gIHBhdGg6IHN0cmluZ1xuICB2YWw6IGFueVxufVxuXG5leHBvcnQgY29uc3Qgc2FuaX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|
+
{"version":3,"sources":["../../src/queries/sanitizeQueryValue.ts"],"sourcesContent":["import type { Field, TabAsField } from 'payload/types'\n\nimport mongoose from 'mongoose'\nimport { createArrayFromCommaDelineated } from 'payload/utilities'\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 = { $options: 'i', $regex: formattedValue }\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","$exists","$ne","$or"],"mappings":"AAEA,OAAOA,cAAc,WAAU;AAC/B,SAASC,8BAA8B,QAAQ,oBAAmB;AAUlE,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;gBAC9B,OAAO;oBAAEZ,UAAUI;oBAAmBF,KAAKQ;gBAAU;YACvD;QACF;IACF;IAEA,kDAAkD;IAClD,IAAIZ,MAAMa,IAAI,KAAK,cAAc,OAAOT,QAAQ,UAAU;QACxD,IAAIA,IAAIc,WAAW,OAAO,QAAQb,iBAAiB;QACnD,IAAID,IAAIc,WAAW,OAAO,SAASb,iB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AoB;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;oCAAE2C,SAAS;gCAAK;4BAAE;4BAAG;gCAAE,CAAC3C,KAAK,EAAE;oCAAE4C,KAAK;gCAAK;4BAAE;yBAAE;oBAClE;gBACF;YACF,OAAO;gBACL,OAAO;oBACLrB,UAAU;wBACRsB,KAAK;4BAAC;gCAAE,CAAC7C,KAAK,EAAE;oCAAE2C,SAAS;gCAAM;4BAAE;4BAAG;gCAAE,CAAC3C,KAAK,EAAE;oCAAEyB,KAAK;gCAAK;4BAAE;yBAAE;oBAClE;gBACF;YACF;QACF;IACF;IAEA,OAAO;QAAE1B,UAAUI;QAAmBF,KAAKC;IAAe;AAC5D,EAAC"}
|
package/dist/queryDrafts.js
CHANGED
|
@@ -1,34 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function() {
|
|
8
|
-
return queryDrafts;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
const _database = require("payload/database");
|
|
12
|
-
const _buildSortParam = require("./queries/buildSortParam");
|
|
13
|
-
const _sanitizeInternalFields = /*#__PURE__*/ _interop_require_default(require("./utilities/sanitizeInternalFields"));
|
|
14
|
-
const _withSession = require("./withSession");
|
|
15
|
-
function _interop_require_default(obj) {
|
|
16
|
-
return obj && obj.__esModule ? obj : {
|
|
17
|
-
default: obj
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
const queryDrafts = async function queryDrafts({ collection, limit, locale, page, pagination, req = {}, sort: sortArg, where }) {
|
|
1
|
+
import { combineQueries, flattenWhereToOperators } from 'payload/database';
|
|
2
|
+
import { buildSortParam } from './queries/buildSortParam.js';
|
|
3
|
+
import sanitizeInternalFields from './utilities/sanitizeInternalFields.js';
|
|
4
|
+
import { withSession } from './withSession.js';
|
|
5
|
+
export const queryDrafts = async function queryDrafts({ collection, limit, locale, page, pagination, req = {}, sort: sortArg, where }) {
|
|
21
6
|
const VersionModel = this.versions[collection];
|
|
22
7
|
const collectionConfig = this.payload.collections[collection].config;
|
|
23
|
-
const options =
|
|
8
|
+
const options = withSession(this, req.transactionID);
|
|
24
9
|
let hasNearConstraint;
|
|
25
10
|
let sort;
|
|
26
11
|
if (where) {
|
|
27
|
-
const constraints =
|
|
12
|
+
const constraints = flattenWhereToOperators(where);
|
|
28
13
|
hasNearConstraint = constraints.some((prop)=>Object.keys(prop).some((key)=>key === 'near'));
|
|
29
14
|
}
|
|
30
15
|
if (!hasNearConstraint) {
|
|
31
|
-
sort =
|
|
16
|
+
sort = buildSortParam({
|
|
32
17
|
config: this.payload.config,
|
|
33
18
|
fields: collectionConfig.fields,
|
|
34
19
|
locale,
|
|
@@ -36,7 +21,7 @@ const queryDrafts = async function queryDrafts({ collection, limit, locale, page
|
|
|
36
21
|
timestamps: true
|
|
37
22
|
});
|
|
38
23
|
}
|
|
39
|
-
const combinedWhere =
|
|
24
|
+
const combinedWhere = combineQueries({
|
|
40
25
|
latest: {
|
|
41
26
|
equals: true
|
|
42
27
|
}
|
|
@@ -89,9 +74,9 @@ const queryDrafts = async function queryDrafts({ collection, limit, locale, page
|
|
|
89
74
|
createdAt: doc.createdAt,
|
|
90
75
|
updatedAt: doc.updatedAt
|
|
91
76
|
};
|
|
92
|
-
return (
|
|
77
|
+
return sanitizeInternalFields(doc);
|
|
93
78
|
})
|
|
94
79
|
};
|
|
95
80
|
};
|
|
96
81
|
|
|
97
|
-
//# sourceMappingURL=
|
|
82
|
+
//# sourceMappingURL=queryDrafts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/queryDrafts.ts"],"sourcesContent":["import type { PaginateOptions } from 'mongoose'\nimport type { QueryDrafts } from 'payload/database'\nimport type { PayloadRequest } from 'payload/types'\n\nimport { combineQueries, flattenWhereToOperators } from 'payload/database'\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 { collection, limit, locale, page, pagination, req = {} as PayloadRequest, sort: sortArg, where },\n) {\n const VersionModel = this.versions[collection]\n const collectionConfig = this.payload.collections[collection].config\n const options = withSession(this, req.transactionID)\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 // 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 forceCountFn: hasNearConstraint,\n lean: true,\n leanWithId: true,\n options,\n page,\n pagination,\n sort,\n useEstimatedCount,\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 const result = await VersionModel.paginate(versionQuery, paginationOptions)\n const docs = JSON.parse(JSON.stringify(result.docs))\n\n return {\n ...result,\n docs: docs.map((doc) => {\n // eslint-disable-next-line no-param-reassign\n doc = {\n _id: doc.parent,\n id: doc.parent,\n ...doc.version,\n createdAt: doc.createdAt,\n updatedAt: doc.updatedAt,\n }\n\n return sanitizeInternalFields(doc)\n }),\n }\n}\n"],"names":["combineQueries","flattenWhereToOperators","buildSortParam","sanitizeInternalFields","withSession","queryDrafts","collection","limit","locale","page","pagination","req","sort","sortArg","where","VersionModel","versions","collectionConfig","payload","collections","config","options","transactionID","hasNearConstraint","constraints","some","prop","Object","keys","key","fields","defaultSort","timestamps","combinedWhere","latest","equals","versionQuery","buildQuery","useEstimatedCount","length","paginationOptions","forceCountFn","lean","leanWithId","disableIndexHints","useCustomCountFn","Promise","resolve","countDocuments","hint","_id","result","paginate","docs","JSON","parse","stringify","map","doc","parent","id","version","createdAt","updatedAt"],"mappings":"AAIA,SAASA,cAAc,EAAEC,uBAAuB,QAAQ,mBAAkB;AAI1E,SAASC,cAAc,QAAQ,8BAA6B;AAC5D,OAAOC,4BAA4B,wCAAuC;AAC1E,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,cAA2B,eAAeA,YAErD,EAAEC,UAAU,EAAEC,KAAK,EAAEC,MAAM,EAAEC,IAAI,EAAEC,UAAU,EAAEC,MAAM,CAAC,CAAmB,EAAEC,MAAMC,OAAO,EAAEC,KAAK,EAAE;IAEjG,MAAMC,eAAe,IAAI,CAACC,QAAQ,CAACV,WAAW;IAC9C,MAAMW,mBAAmB,IAAI,CAACC,OAAO,CAACC,WAAW,CAACb,WAAW,CAACc,MAAM;IACpE,MA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,CAACd,KAAK,GAAGA;IACpC;IAEA,MAAM4C,SAAS,MAAMpC,aAAaqC,QAAQ,CAAChB,cAAcI;IACzD,MAAMa,OAAOC,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACL,OAAOE,IAAI;IAElD,OAAO;QACL,GAAGF,MAAM;QACTE,MAAMA,KAAKI,GAAG,CAAC,CAACC;YACd,6CAA6C;YAC7CA,MAAM;gBACJR,KAAKQ,IAAIC,MAAM;gBACfC,IAAIF,IAAIC,MAAM;gBACd,GAAGD,IAAIG,OAAO;gBACdC,WAAWJ,IAAII,SAAS;gBACxBC,WAAWL,IAAIK,SAAS;YAC1B;YAEA,OAAO5D,uBAAuBuD;QAChC;IACF;AACF,EAAC"}
|
package/dist/testCredentials.js
CHANGED
|
@@ -1,30 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
});
|
|
5
|
-
function _export(target, all) {
|
|
6
|
-
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: all[name]
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
_export(exports, {
|
|
12
|
-
connection: function() {
|
|
13
|
-
return connection;
|
|
14
|
-
},
|
|
15
|
-
email: function() {
|
|
16
|
-
return email;
|
|
17
|
-
},
|
|
18
|
-
password: function() {
|
|
19
|
-
return password;
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
const email = 'test@test.com';
|
|
23
|
-
const password = 'test123';
|
|
24
|
-
const connection = {
|
|
1
|
+
export const email = 'test@test.com';
|
|
2
|
+
export const password = 'test123';
|
|
3
|
+
export const connection = {
|
|
25
4
|
name: 'payloadmemory',
|
|
26
5
|
port: 27018,
|
|
27
6
|
url: 'mongodb://127.0.0.1'
|
|
28
7
|
};
|
|
29
8
|
|
|
30
|
-
//# sourceMappingURL=
|
|
9
|
+
//# sourceMappingURL=testCredentials.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/testCredentials.ts"],"sourcesContent":["export const email = 'test@test.com'\nexport const password = 'test123'\nexport const connection = {\n name: 'payloadmemory',\n port: 27018,\n url: 'mongodb://127.0.0.1',\n}\n"],"names":["email","password","connection","name","port","url"],"mappings":"AAAA,OAAO,MAAMA,QAAQ,gBAAe;AACpC,OAAO,MAAMC,WAAW,UAAS;AACjC,OAAO,MAAMC,aAAa;IACxBC,MAAM;IACNC,MAAM;IACNC,KAAK;AACP,EAAC"}
|
|
@@ -1,21 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "beginTransaction", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function() {
|
|
8
|
-
return beginTransaction;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
const _errors = require("payload/errors");
|
|
12
|
-
const _uuid = require("uuid");
|
|
13
|
-
const beginTransaction = async function beginTransaction(options) {
|
|
1
|
+
import { APIError } from 'payload/errors';
|
|
2
|
+
import { v4 as uuid } from 'uuid';
|
|
3
|
+
export const beginTransaction = async function beginTransaction(options) {
|
|
14
4
|
if (!this.connection) {
|
|
15
|
-
throw new
|
|
5
|
+
throw new APIError('beginTransaction called while no connection to the database exists');
|
|
16
6
|
}
|
|
17
7
|
const client = this.connection.getClient();
|
|
18
|
-
const id = (
|
|
8
|
+
const id = uuid();
|
|
19
9
|
if (!this.sessions[id]) {
|
|
20
10
|
this.sessions[id] = client.startSession();
|
|
21
11
|
}
|
|
@@ -27,4 +17,4 @@ const beginTransaction = async function beginTransaction(options) {
|
|
|
27
17
|
return id;
|
|
28
18
|
};
|
|
29
19
|
|
|
30
|
-
//# sourceMappingURL=
|
|
20
|
+
//# sourceMappingURL=beginTransaction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/transactions/beginTransaction.ts"],"sourcesContent":["import type { TransactionOptions } from 'mongodb'\nimport type { BeginTransaction } from 'payload/database'\n\nimport { APIError } from 'payload/errors'\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,iBAAgB;AACzC,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,14 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "commitTransaction", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function() {
|
|
8
|
-
return commitTransaction;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
const commitTransaction = async function commitTransaction(id) {
|
|
1
|
+
export const commitTransaction = async function commitTransaction(id) {
|
|
12
2
|
if (!this.sessions[id]?.inTransaction()) {
|
|
13
3
|
return;
|
|
14
4
|
}
|
|
@@ -17,4 +7,4 @@ const commitTransaction = async function commitTransaction(id) {
|
|
|
17
7
|
delete this.sessions[id];
|
|
18
8
|
};
|
|
19
9
|
|
|
20
|
-
//# sourceMappingURL=
|
|
10
|
+
//# sourceMappingURL=commitTransaction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/transactions/commitTransaction.ts"],"sourcesContent":["import type { CommitTransaction } from 'payload/database'\n\nexport const commitTransaction: CommitTransaction = async function commitTransaction(id) {\n if (!this.sessions[id]?.inTransaction()) {\n return\n }\n\n await this.sessions[id].commitTransaction()\n await this.sessions[id].endSession()\n delete this.sessions[id]\n}\n"],"names":["commitTransaction","id","sessions","inTransaction","endSession"],"mappings":"AAEA,OAAO,MAAMA,oBAAuC,eAAeA,kBAAkBC,EAAE;IACrF,IAAI,CAAC,IAAI,CAACC,QAAQ,CAACD,GAAG,EAAEE,iBAAiB;QACvC;IACF;IAEA,MAAM,IAAI,CAACD,QAAQ,CAACD,GAAG,CAACD,iBAAiB;IACzC,MAAM,IAAI,CAACE,QAAQ,CAACD,GAAG,CAACG,UAAU;IAClC,OAAO,IAAI,CAACF,QAAQ,CAACD,GAAG;AAC1B,EAAC"}
|
|
@@ -1,14 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "rollbackTransaction", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function() {
|
|
8
|
-
return rollbackTransaction;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
const rollbackTransaction = async function rollbackTransaction(id = '') {
|
|
1
|
+
export const rollbackTransaction = async function rollbackTransaction(id = '') {
|
|
12
2
|
// if multiple operations are using the same transaction, the first will flow through and delete the session.
|
|
13
3
|
// subsequent calls should be ignored.
|
|
14
4
|
if (!this.sessions[id]) {
|
|
@@ -30,4 +20,4 @@ const rollbackTransaction = async function rollbackTransaction(id = '') {
|
|
|
30
20
|
delete this.sessions[id];
|
|
31
21
|
};
|
|
32
22
|
|
|
33
|
-
//# sourceMappingURL=
|
|
23
|
+
//# sourceMappingURL=rollbackTransaction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/transactions/rollbackTransaction.ts"],"sourcesContent":["import type { RollbackTransaction } from 'payload/database'\n\nexport const rollbackTransaction: RollbackTransaction = async function rollbackTransaction(\n id = '',\n) {\n // if multiple operations are using the same transaction, the first will flow through and delete the session.\n // subsequent calls should be ignored.\n if (!this.sessions[id]) {\n return\n }\n\n // when session exists but is not inTransaction something unexpected is happening to the session\n if (!this.sessions[id].inTransaction()) {\n this.payload.logger.warn('rollbackTransaction called when no transaction exists')\n delete this.sessions[id]\n return\n }\n\n // the first call for rollback should be aborted and deleted causing any other operations with the same transaction to fail\n try {\n await this.sessions[id].abortTransaction()\n await this.sessions[id].endSession()\n } catch (error) {\n // ignore the error as it is likely a race condition from multiple errors\n }\n delete this.sessions[id]\n}\n"],"names":["rollbackTransaction","id","sessions","inTransaction","payload","logger","warn","abortTransaction","endSession","error"],"mappings":"AAEA,OAAO,MAAMA,sBAA2C,eAAeA,oBACrEC,KAAK,EAAE;IAEP,6GAA6G;IAC7G,sCAAsC;IACtC,IAAI,CAAC,IAAI,CAACC,QAAQ,CAACD,GAAG,EAAE;QACtB;IACF;IAEA,gGAAgG;IAChG,IAAI,CAAC,IAAI,CAACC,QAAQ,CAACD,GAAG,CAACE,aAAa,IAAI;QACtC,IAAI,CAACC,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC;QACzB,OAAO,IAAI,CAACJ,QAAQ,CAACD,GAAG;QACxB;IACF;IAEA,2HAA2H;IAC3H,IAAI;QACF,MAAM,IAAI,CAACC,QAAQ,CAACD,GAAG,CAACM,gBAAgB;QACxC,MAAM,IAAI,CAACL,QAAQ,CAACD,GAAG,CAACO,UAAU;IACpC,EAAE,OAAOC,OAAO;IACd,yEAAyE;IAC3E;IACA,OAAO,IAAI,CAACP,QAAQ,CAACD,GAAG;AAC1B,EAAC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,8 +1,33 @@
|
|
|
1
|
+
/// <reference types="mongoose/types/aggregate.js" />
|
|
2
|
+
/// <reference types="mongoose/types/callback.js" />
|
|
3
|
+
/// <reference types="mongoose/types/collection.js" />
|
|
4
|
+
/// <reference types="mongoose/types/connection.js" />
|
|
5
|
+
/// <reference types="mongoose/types/cursor.js" />
|
|
6
|
+
/// <reference types="mongoose/types/document.js" />
|
|
7
|
+
/// <reference types="mongoose/types/error.js" />
|
|
8
|
+
/// <reference types="mongoose/types/expressions.js" />
|
|
9
|
+
/// <reference types="mongoose/types/helpers.js" />
|
|
10
|
+
/// <reference types="mongoose/types/middlewares.js" />
|
|
11
|
+
/// <reference types="mongoose/types/indexes.js" />
|
|
12
|
+
/// <reference types="mongoose/types/models.js" />
|
|
13
|
+
/// <reference types="mongoose/types/mongooseoptions.js" />
|
|
14
|
+
/// <reference types="mongoose/types/pipelinestage.js" />
|
|
15
|
+
/// <reference types="mongoose/types/populate.js" />
|
|
16
|
+
/// <reference types="mongoose/types/query.js" />
|
|
17
|
+
/// <reference types="mongoose/types/schemaoptions.js" />
|
|
18
|
+
/// <reference types="mongoose/types/schematypes.js" />
|
|
19
|
+
/// <reference types="mongoose/types/session.js" />
|
|
20
|
+
/// <reference types="mongoose/types/types.js" />
|
|
21
|
+
/// <reference types="mongoose/types/utility.js" />
|
|
22
|
+
/// <reference types="mongoose/types/validation.js" />
|
|
23
|
+
/// <reference types="mongoose/types/virtuals.js" />
|
|
24
|
+
/// <reference types="mongoose/types/inferschematype.js" />
|
|
25
|
+
/// <reference types="mongoose-paginate-v2" />
|
|
1
26
|
import type { IndexDefinition, IndexOptions, Model, PaginateModel, SchemaOptions } from 'mongoose';
|
|
2
27
|
import type { Payload } from 'payload';
|
|
3
28
|
import type { SanitizedConfig } from 'payload/config';
|
|
4
29
|
import type { ArrayField, BlockField, CheckboxField, CodeField, CollapsibleField, DateField, EmailField, Field, GroupField, JSONField, NumberField, PointField, RadioField, RelationshipField, RichTextField, RowField, SelectField, TabsField, TextField, TextareaField, UploadField } from 'payload/types';
|
|
5
|
-
import type { BuildQueryArgs } from './queries/buildQuery';
|
|
30
|
+
import type { BuildQueryArgs } from './queries/buildQuery.js';
|
|
6
31
|
export interface CollectionModel extends Model<any>, PaginateModel<any> {
|
|
7
32
|
/** buildQuery is used to transform payload's where operator into what can be used by mongoose (e.g. id => _id) */
|
|
8
33
|
buildQuery: (args: BuildQueryArgs) => Promise<Record<string, unknown>>;
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,KAAK,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAClG,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AACtC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AACrD,OAAO,KAAK,EACV,UAAU,EACV,UAAU,EACV,aAAa,EACb,SAAS,EACT,gBAAgB,EAChB,SAAS,EACT,UAAU,EACV,KAAK,EACL,UAAU,EACV,SAAS,EACT,WAAW,EACX,UAAU,EACV,UAAU,EACV,iBAAiB,EACjB,aAAa,EACb,QAAQ,EACR,WAAW,EACX,SAAS,EACT,SAAS,EACT,aAAa,EACb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aginateModel, SchemaOptions } from 'mongoose'\nimport type { Payload } from 'payload'\nimport type { SanitizedConfig } from 'payload/config'\nimport type {\n ArrayField,\n BlockField,\n CheckboxField,\n CodeField,\n CollapsibleField,\n DateField,\n EmailField,\n Field,\n GroupField,\n JSONField,\n NumberField,\n PointField,\n RadioField,\n RelationshipField,\n RichTextField,\n RowField,\n SelectField,\n TabsField,\n TextField,\n TextareaField,\n UploadField,\n} from 'payload/types'\n\nimport type { BuildQueryArgs } from './queries/buildQuery.js'\n\nexport interface CollectionModel extends Model<any>, PaginateModel<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\n/**\n * Field config types that need representation in the database\n */\ntype FieldType =\n | 'array'\n | 'blocks'\n | 'checkbox'\n | 'code'\n | 'collapsible'\n | 'date'\n | 'email'\n | 'group'\n | 'json'\n | 'number'\n | 'point'\n | 'radio'\n | 'relationship'\n | 'richText'\n | 'row'\n | 'select'\n | 'tabs'\n | 'text'\n | 'textarea'\n | 'upload'\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, BlockField>\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 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 }\nexport type MigrateDownArgs = { payload: Payload }\n"],"names":[],"mappings":"AA6HA,WAAkD"}
|
package/dist/updateGlobal.js
CHANGED
|
@@ -1,24 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "updateGlobal", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function() {
|
|
8
|
-
return updateGlobal;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
const _sanitizeInternalFields = /*#__PURE__*/ _interop_require_default(require("./utilities/sanitizeInternalFields"));
|
|
12
|
-
const _withSession = require("./withSession");
|
|
13
|
-
function _interop_require_default(obj) {
|
|
14
|
-
return obj && obj.__esModule ? obj : {
|
|
15
|
-
default: obj
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
const updateGlobal = async function updateGlobal({ data, req = {}, slug }) {
|
|
1
|
+
import sanitizeInternalFields from './utilities/sanitizeInternalFields.js';
|
|
2
|
+
import { withSession } from './withSession.js';
|
|
3
|
+
export const updateGlobal = async function updateGlobal({ slug, data, req = {} }) {
|
|
19
4
|
const Model = this.globals;
|
|
20
5
|
const options = {
|
|
21
|
-
...
|
|
6
|
+
...withSession(this, req.transactionID),
|
|
22
7
|
lean: true,
|
|
23
8
|
new: true
|
|
24
9
|
};
|
|
@@ -29,8 +14,8 @@ const updateGlobal = async function updateGlobal({ data, req = {}, slug }) {
|
|
|
29
14
|
result = JSON.parse(JSON.stringify(result));
|
|
30
15
|
// custom id type reset
|
|
31
16
|
result.id = result._id;
|
|
32
|
-
result = (
|
|
17
|
+
result = sanitizeInternalFields(result);
|
|
33
18
|
return result;
|
|
34
19
|
};
|
|
35
20
|
|
|
36
|
-
//# sourceMappingURL=
|
|
21
|
+
//# sourceMappingURL=updateGlobal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/updateGlobal.ts"],"sourcesContent":["import type { UpdateGlobal } from 'payload/database'\nimport type { PayloadRequest } from 'payload/types'\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 ...withSession(this, req.transactionID),\n lean: true,\n new: true,\n }\n\n let result\n result = await Model.findOneAndUpdate({ globalType: slug }, data, 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":["sanitizeInternalFields","withSession","updateGlobal","slug","data","req","Model","globals","options","transactionID","lean","new","result","findOneAndUpdate","globalType","JSON","parse","stringify","id","_id"],"mappings":"AAKA,OAAOA,4BAA4B,wCAAuC;AAC1E,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,eAA6B,eAAeA,aAEvD,EAAEC,IAAI,EAAEC,IAAI,EAAEC,MAAM,CAAC,CAAmB,EAAE;IAE1C,MAAMC,QAAQ,IAAI,CAACC,OAAO;IAC1B,MAAMC,UAAU;QACd,GAAGP,YAAY,IAAI,EAAEI,IAAII,aAAa,CAAC;QACvCC,MAAM;QACNC,KAAK;IACP;IAEA,IAAIC;IACJA,SAAS,MAAMN,MAAMO,gBAAgB,CAAC;QAAEC,YAAYX;IAAK,GAAGC,MAAMI;IAElEI,SAASG,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACL;IAEnC,uBAAuB;IACvBA,OAAOM,EAAE,GAAGN,OAAOO,GAAG;IACtBP,SAASZ,uBAAuBY;IAEhC,OAAOA;AACT,EAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { UpdateGlobalVersionArgs } from 'payload/database';
|
|
2
2
|
import type { TypeWithID } from 'payload/types';
|
|
3
|
-
import type { MongooseAdapter } from '.';
|
|
3
|
+
import type { MongooseAdapter } from './index.js';
|
|
4
4
|
export declare function updateGlobalVersion<T extends TypeWithID>(this: MongooseAdapter, { id, global, locale, req, versionData, where, }: UpdateGlobalVersionArgs<T>): Promise<any>;
|
|
5
5
|
//# sourceMappingURL=updateGlobalVersion.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"updateGlobalVersion.d.ts","sourceRoot":"","sources":["../src/updateGlobalVersion.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAA;AAC/D,OAAO,KAAK,EAAkB,UAAU,EAAE,MAAM,eAAe,CAAA;AAE/D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"updateGlobalVersion.d.ts","sourceRoot":"","sources":["../src/updateGlobalVersion.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAA;AAC/D,OAAO,KAAK,EAAkB,UAAU,EAAE,MAAM,eAAe,CAAA;AAE/D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAIjD,wBAAsB,mBAAmB,CAAC,CAAC,SAAS,UAAU,EAC5D,IAAI,EAAE,eAAe,EACrB,EACE,EAAE,EACF,MAAM,EACN,MAAM,EACN,GAA0B,EAC1B,WAAW,EACX,KAAK,GACN,EAAE,uBAAuB,CAAC,CAAC,CAAC,gBA4B9B"}
|