@payloadcms/db-mongodb 3.0.1-canary.34c6cc0 → 3.0.1-canary.9494866
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/queries/parseParams.d.ts +8 -0
- package/dist/queries/parseParams.d.ts.map +1 -1
- package/dist/queries/parseParams.js +22 -1
- package/dist/queries/parseParams.js.map +1 -1
- package/package.json +4 -4
- package/dist/queries/buildAndOrConditions.d.ts +0 -10
- package/dist/queries/buildAndOrConditions.d.ts.map +0 -1
- package/dist/queries/buildAndOrConditions.js +0 -25
- package/dist/queries/buildAndOrConditions.js.map +0 -1
@@ -7,4 +7,12 @@ export declare function parseParams({ collectionSlug, fields, globalSlug, locale
|
|
7
7
|
payload: Payload;
|
8
8
|
where: Where;
|
9
9
|
}): Promise<Record<string, unknown>>;
|
10
|
+
export declare function buildAndOrConditions({ collectionSlug, fields, globalSlug, locale, payload, where, }: {
|
11
|
+
collectionSlug?: string;
|
12
|
+
fields: Field[];
|
13
|
+
globalSlug?: string;
|
14
|
+
locale?: string;
|
15
|
+
payload: Payload;
|
16
|
+
where: Where[];
|
17
|
+
}): Promise<Record<string, unknown>[]>;
|
10
18
|
//# sourceMappingURL=parseParams.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"parseParams.d.ts","sourceRoot":"","sources":["../../src/queries/parseParams.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAY,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;
|
1
|
+
{"version":3,"file":"parseParams.d.ts","sourceRoot":"","sources":["../../src/queries/parseParams.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAY,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAO9D,wBAAsB,WAAW,CAAC,EAChC,cAAc,EACd,MAAM,EACN,UAAU,EACV,MAAM,EACN,OAAO,EACP,KAAK,GACN,EAAE;IACD,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,MAAM,EAAE,KAAK,EAAE,CAAA;IACf,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,EAAE,OAAO,CAAA;IAChB,KAAK,EAAE,KAAK,CAAA;CACb,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CA+DnC;AAED,wBAAsB,oBAAoB,CAAC,EACzC,cAAc,EACd,MAAM,EACN,UAAU,EACV,MAAM,EACN,OAAO,EACP,KAAK,GACN,EAAE;IACD,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,MAAM,EAAE,KAAK,EAAE,CAAA;IACf,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,OAAO,EAAE,OAAO,CAAA;IAChB,KAAK,EAAE,KAAK,EAAE,CAAA;CACf,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC,CAsBrC"}
|
@@ -1,6 +1,5 @@
|
|
1
1
|
import { deepMergeWithCombinedArrays } from 'payload';
|
2
2
|
import { validOperators } from 'payload/shared';
|
3
|
-
import { buildAndOrConditions } from './buildAndOrConditions.js';
|
4
3
|
import { buildSearchParam } from './buildSearchParams.js';
|
5
4
|
export async function parseParams({ collectionSlug, fields, globalSlug, locale, payload, where }) {
|
6
5
|
let result = {};
|
@@ -63,5 +62,27 @@ export async function parseParams({ collectionSlug, fields, globalSlug, locale,
|
|
63
62
|
}
|
64
63
|
return result;
|
65
64
|
}
|
65
|
+
export async function buildAndOrConditions({ collectionSlug, fields, globalSlug, locale, payload, where }) {
|
66
|
+
const completedConditions = [];
|
67
|
+
// Loop over all AND / OR operations and add them to the AND / OR query param
|
68
|
+
// Operations should come through as an array
|
69
|
+
for (const condition of where){
|
70
|
+
// If the operation is properly formatted as an object
|
71
|
+
if (typeof condition === 'object') {
|
72
|
+
const result = await parseParams({
|
73
|
+
collectionSlug,
|
74
|
+
fields,
|
75
|
+
globalSlug,
|
76
|
+
locale,
|
77
|
+
payload,
|
78
|
+
where: condition
|
79
|
+
});
|
80
|
+
if (Object.keys(result).length > 0) {
|
81
|
+
completedConditions.push(result);
|
82
|
+
}
|
83
|
+
}
|
84
|
+
}
|
85
|
+
return completedConditions;
|
86
|
+
}
|
66
87
|
|
67
88
|
//# sourceMappingURL=parseParams.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/queries/parseParams.ts"],"sourcesContent":["import type { FilterQuery } from 'mongoose'\nimport type { Field, Operator, Payload, Where } from 'payload'\n\nimport { deepMergeWithCombinedArrays } from 'payload'\nimport { validOperators } from 'payload/shared'\n\nimport {
|
1
|
+
{"version":3,"sources":["../../src/queries/parseParams.ts"],"sourcesContent":["import type { FilterQuery } from 'mongoose'\nimport type { Field, Operator, Payload, Where } from 'payload'\n\nimport { deepMergeWithCombinedArrays } from 'payload'\nimport { validOperators } from 'payload/shared'\n\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) {\n result[conditionOperator] = builtConditions\n }\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 = deepMergeWithCombinedArrays(result, searchParam.value, {\n // dont clone Types.ObjectIDs\n clone: false,\n })\n }\n }\n }\n }\n }\n }\n }\n\n return result\n}\n\nexport async function buildAndOrConditions({\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 const completedConditions = []\n // Loop over all AND / OR operations and add them to the AND / OR query param\n // Operations should come through as an array\n\n for (const condition of where) {\n // If the operation is properly formatted as an object\n if (typeof condition === 'object') {\n const result = await parseParams({\n collectionSlug,\n fields,\n globalSlug,\n locale,\n payload,\n where: condition,\n })\n if (Object.keys(result).length > 0) {\n completedConditions.push(result)\n }\n }\n }\n return completedConditions\n}\n"],"names":["deepMergeWithCombinedArrays","validOperators","buildSearchParam","parseParams","collectionSlug","fields","globalSlug","locale","payload","where","result","relationOrPath","Object","keys","condition","conditionOperator","toLowerCase","Array","isArray","builtConditions","buildAndOrConditions","length","pathOperators","operator","includes","searchParam","incomingPath","val","value","path","clone","completedConditions","push"],"mappings":"AAGA,SAASA,2BAA2B,QAAQ,UAAS;AACrD,SAASC,cAAc,QAAQ,iBAAgB;AAE/C,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,UA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M,EACNC,UAAU,EACVC,MAAM,EACNC,OAAO,EACPC,KAAK,EAQN;IACC,MAAMsB,sBAAsB,EAAE;IAC9B,6EAA6E;IAC7E,6CAA6C;IAE7C,KAAK,MAAMjB,aAAaL,MAAO;QAC7B,sDAAsD;QACtD,IAAI,OAAOK,cAAc,UAAU;YACjC,MAAMJ,SAAS,MAAMP,YAAY;gBAC/BC;gBACAC;gBACAC;gBACAC;gBACAC;gBACAC,OAAOK;YACT;YACA,IAAIF,OAAOC,IAAI,CAACH,QAAQW,MAAM,GAAG,GAAG;gBAClCU,oBAAoBC,IAAI,CAACtB;YAC3B;QACF;IACF;IACA,OAAOqB;AACT"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@payloadcms/db-mongodb",
|
3
|
-
"version": "3.0.1-canary.
|
3
|
+
"version": "3.0.1-canary.9494866",
|
4
4
|
"description": "The officially supported MongoDB database adapter for Payload",
|
5
5
|
"homepage": "https://payloadcms.com",
|
6
6
|
"repository": {
|
@@ -48,11 +48,11 @@
|
|
48
48
|
"@types/mongoose-aggregate-paginate-v2": "1.0.12",
|
49
49
|
"mongodb": "6.10.0",
|
50
50
|
"mongodb-memory-server": "^9",
|
51
|
-
"@payloadcms/eslint-config": "3.0.0
|
52
|
-
"payload": "3.0.1-canary.
|
51
|
+
"@payloadcms/eslint-config": "3.0.0",
|
52
|
+
"payload": "3.0.1-canary.9494866"
|
53
53
|
},
|
54
54
|
"peerDependencies": {
|
55
|
-
"payload": "3.0.1-canary.
|
55
|
+
"payload": "3.0.1-canary.9494866"
|
56
56
|
},
|
57
57
|
"scripts": {
|
58
58
|
"build": "pnpm build:types && pnpm build:swc",
|
@@ -1,10 +0,0 @@
|
|
1
|
-
import type { Field, Payload, Where } from 'payload';
|
2
|
-
export declare function buildAndOrConditions({ collectionSlug, fields, globalSlug, locale, payload, where, }: {
|
3
|
-
collectionSlug?: string;
|
4
|
-
fields: Field[];
|
5
|
-
globalSlug?: string;
|
6
|
-
locale?: string;
|
7
|
-
payload: Payload;
|
8
|
-
where: Where[];
|
9
|
-
}): Promise<Record<string, unknown>[]>;
|
10
|
-
//# sourceMappingURL=buildAndOrConditions.d.ts.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"buildAndOrConditions.d.ts","sourceRoot":"","sources":["../../src/queries/buildAndOrConditions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAIpD,wBAAsB,oBAAoB,CAAC,EACzC,cAAc,EACd,MAAM,EACN,UAAU,EACV,MAAM,EACN,OAAO,EACP,KAAK,GACN,EAAE;IACD,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,MAAM,EAAE,KAAK,EAAE,CAAA;IACf,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,OAAO,EAAE,OAAO,CAAA;IAChB,KAAK,EAAE,KAAK,EAAE,CAAA;CACf,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC,CAsBrC"}
|
@@ -1,25 +0,0 @@
|
|
1
|
-
import { parseParams } from './parseParams.js';
|
2
|
-
export async function buildAndOrConditions({ collectionSlug, fields, globalSlug, locale, payload, where }) {
|
3
|
-
const completedConditions = [];
|
4
|
-
// Loop over all AND / OR operations and add them to the AND / OR query param
|
5
|
-
// Operations should come through as an array
|
6
|
-
for (const condition of where){
|
7
|
-
// If the operation is properly formatted as an object
|
8
|
-
if (typeof condition === 'object') {
|
9
|
-
const result = await parseParams({
|
10
|
-
collectionSlug,
|
11
|
-
fields,
|
12
|
-
globalSlug,
|
13
|
-
locale,
|
14
|
-
payload,
|
15
|
-
where: condition
|
16
|
-
});
|
17
|
-
if (Object.keys(result).length > 0) {
|
18
|
-
completedConditions.push(result);
|
19
|
-
}
|
20
|
-
}
|
21
|
-
}
|
22
|
-
return completedConditions;
|
23
|
-
}
|
24
|
-
|
25
|
-
//# sourceMappingURL=buildAndOrConditions.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"sources":["../../src/queries/buildAndOrConditions.ts"],"sourcesContent":["import type { Field, Payload, Where } from 'payload'\n\nimport { parseParams } from './parseParams.js'\n\nexport async function buildAndOrConditions({\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 const completedConditions = []\n // Loop over all AND / OR operations and add them to the AND / OR query param\n // Operations should come through as an array\n\n for (const condition of where) {\n // If the operation is properly formatted as an object\n if (typeof condition === 'object') {\n const result = await parseParams({\n collectionSlug,\n fields,\n globalSlug,\n locale,\n payload,\n where: condition,\n })\n if (Object.keys(result).length > 0) {\n completedConditions.push(result)\n }\n }\n }\n return completedConditions\n}\n"],"names":["parseParams","buildAndOrConditions","collectionSlug","fields","globalSlug","locale","payload","where","completedConditions","condition","result","Object","keys","length","push"],"mappings":"AAEA,SAASA,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,eAAeC,qBAAqB,EACzCC,cAAc,EACdC,MAAM,EACNC,UAAU,EACVC,MAAM,EACNC,OAAO,EACPC,KAAK,EAQN;IACC,MAAMC,sBAAsB,EAAE;IAC9B,6EAA6E;IAC7E,6CAA6C;IAE7C,KAAK,MAAMC,aAAaF,MAAO;QAC7B,sDAAsD;QACtD,IAAI,OAAOE,cAAc,UAAU;YACjC,MAAMC,SAAS,MAAMV,YAAY;gBAC/BE;gBACAC;gBACAC;gBACAC;gBACAC;gBACAC,OAAOE;YACT;YACA,IAAIE,OAAOC,IAAI,CAACF,QAAQG,MAAM,GAAG,GAAG;gBAClCL,oBAAoBM,IAAI,CAACJ;YAC3B;QACF;IACF;IACA,OAAOF;AACT"}
|