@nitrogenbuilder/connector-payload 1.2.2 → 1.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/endpoints/batch.js +27 -20
- package/package.json +3 -2
package/dist/endpoints/batch.js
CHANGED
|
@@ -29,10 +29,10 @@ function requestSignature(batchReq) {
|
|
|
29
29
|
.map((k) => [k, params[k]]));
|
|
30
30
|
return JSON.stringify({ endpoint: batchReq.endpoint, params: sortedParams });
|
|
31
31
|
}
|
|
32
|
-
async function resolveRelationshipIds(payload, collection, values) {
|
|
32
|
+
async function resolveRelationshipIds(payload, collection, values, includeDirectIds = false) {
|
|
33
33
|
if (values.length === 0)
|
|
34
34
|
return [];
|
|
35
|
-
const [slugMatches, titleMatches] = await Promise.all([
|
|
35
|
+
const [slugMatches, titleMatches, idMatches] = await Promise.all([
|
|
36
36
|
payload.find({
|
|
37
37
|
collection,
|
|
38
38
|
where: {
|
|
@@ -51,8 +51,19 @@ async function resolveRelationshipIds(payload, collection, values) {
|
|
|
51
51
|
depth: 0,
|
|
52
52
|
pagination: false,
|
|
53
53
|
}),
|
|
54
|
+
includeDirectIds
|
|
55
|
+
? payload.find({
|
|
56
|
+
collection,
|
|
57
|
+
where: {
|
|
58
|
+
id: { in: values },
|
|
59
|
+
},
|
|
60
|
+
limit: values.length,
|
|
61
|
+
depth: 0,
|
|
62
|
+
pagination: false,
|
|
63
|
+
})
|
|
64
|
+
: Promise.resolve({ docs: [] }),
|
|
54
65
|
]);
|
|
55
|
-
return [...slugMatches.docs, ...titleMatches.docs].map((doc) => doc.id);
|
|
66
|
+
return [...slugMatches.docs, ...titleMatches.docs, ...idMatches.docs].map((doc) => doc.id);
|
|
56
67
|
}
|
|
57
68
|
async function resolveAllRelationshipIds(payload, collection) {
|
|
58
69
|
const result = await payload.find({
|
|
@@ -63,8 +74,8 @@ async function resolveAllRelationshipIds(payload, collection) {
|
|
|
63
74
|
});
|
|
64
75
|
return result.docs.map((doc) => doc.id);
|
|
65
76
|
}
|
|
66
|
-
async function applyRelationshipFilter({ payload, results, key, where, field, collection, includeValues, excludeValues = [], }) {
|
|
67
|
-
const includeIds = await resolveRelationshipIds(payload, collection, includeValues);
|
|
77
|
+
async function applyRelationshipFilter({ payload, results, key, where, field, collection, includeValues, excludeValues = [], includeDirectIds = false, }) {
|
|
78
|
+
const includeIds = await resolveRelationshipIds(payload, collection, includeValues, includeDirectIds);
|
|
68
79
|
if (includeValues.length > 0) {
|
|
69
80
|
if (includeIds.length === 0) {
|
|
70
81
|
results[key] = {
|
|
@@ -265,21 +276,17 @@ export const batchEndpoints = [
|
|
|
265
276
|
const authors = toArray(params.authors);
|
|
266
277
|
if (authors.length > 0) {
|
|
267
278
|
if (collectionSlug === "posts") {
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
})
|
|
278
|
-
|
|
279
|
-
Object.assign(where, authorFilters[0]);
|
|
280
|
-
}
|
|
281
|
-
else {
|
|
282
|
-
where.or = [...(where.or ?? []), ...authorFilters];
|
|
279
|
+
if (!(await applyRelationshipFilter({
|
|
280
|
+
payload,
|
|
281
|
+
results,
|
|
282
|
+
key,
|
|
283
|
+
where,
|
|
284
|
+
field: "contentAuthors",
|
|
285
|
+
collection: "author",
|
|
286
|
+
includeValues: authors,
|
|
287
|
+
includeDirectIds: true,
|
|
288
|
+
}))) {
|
|
289
|
+
return;
|
|
283
290
|
}
|
|
284
291
|
}
|
|
285
292
|
else {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nitrogenbuilder/connector-payload",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.3",
|
|
4
4
|
"description": "Nitrogen page builder connector plugin for Payload CMS 3.x",
|
|
5
5
|
"author": "Leonardo Dentzien <leo@torchmedia.ca>",
|
|
6
6
|
"type": "module",
|
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
],
|
|
32
32
|
"scripts": {
|
|
33
33
|
"build": "tsc && node ./scripts/copy-editor-assets.mjs",
|
|
34
|
+
"test": "pnpm build && node --test tests/*.test.mjs",
|
|
34
35
|
"typecheck": "tsc --noEmit",
|
|
35
36
|
"prepublishOnly": "pnpm build"
|
|
36
37
|
},
|
|
@@ -56,4 +57,4 @@
|
|
|
56
57
|
"@nitrogenbuilder/client-core": "link:../monogen/packages/client-core",
|
|
57
58
|
"@nitrogenbuilder/types": "link:../monogen/packages/types"
|
|
58
59
|
}
|
|
59
|
-
}
|
|
60
|
+
}
|