@payload-cc/payload-collection-cli 1.1.0 → 1.2.0
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/bin.js +16 -2
- package/dist/bin.mjs +1 -1
- package/dist/{chunk-I7HHN7EL.mjs → chunk-RIXWYITK.mjs} +16 -2
- package/dist/index.d.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +16 -2
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
package/dist/bin.js
CHANGED
|
@@ -42,12 +42,20 @@ async function resolveRelations(payload, collectionSlug, data, config) {
|
|
|
42
42
|
const collection = payload.collections[collectionSlug];
|
|
43
43
|
if (!collection) throw new Error(`Collection "${collectionSlug}" not found.`);
|
|
44
44
|
const resolved = { ...data };
|
|
45
|
+
const mappingConfig = config.mappings[collectionSlug];
|
|
46
|
+
if (mappingConfig?.defaults) {
|
|
47
|
+
for (const [k, v] of Object.entries(mappingConfig.defaults)) {
|
|
48
|
+
if (resolved[k] === void 0 || resolved[k] === null) {
|
|
49
|
+
resolved[k] = v;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
45
53
|
for (const field of collection.config.fields) {
|
|
46
|
-
if (field.type === "relationship" &&
|
|
54
|
+
if (field.type === "relationship" && resolved[field.name]) {
|
|
47
55
|
const relationTo = Array.isArray(field.relationTo) ? field.relationTo[0] : field.relationTo;
|
|
48
56
|
const mapping = config.mappings[relationTo];
|
|
49
57
|
if (!mapping) continue;
|
|
50
|
-
const rawValue =
|
|
58
|
+
const rawValue = resolved[field.name];
|
|
51
59
|
const isArray = Array.isArray(rawValue);
|
|
52
60
|
const values = isArray ? rawValue : [rawValue];
|
|
53
61
|
const resolvedIds = [];
|
|
@@ -60,6 +68,12 @@ async function resolveRelations(payload, collectionSlug, data, config) {
|
|
|
60
68
|
});
|
|
61
69
|
if (found.docs.length > 0) {
|
|
62
70
|
resolvedIds.push(found.docs[0].id);
|
|
71
|
+
} else if (mapping.onNotFound === "create") {
|
|
72
|
+
const created = await payload.create({
|
|
73
|
+
collection: relationTo,
|
|
74
|
+
data: { [mapping.lookupField]: val }
|
|
75
|
+
});
|
|
76
|
+
resolvedIds.push(created.id);
|
|
63
77
|
} else if (mapping.onNotFound === "error") {
|
|
64
78
|
throw new Error(`Relation not found: ${relationTo} (${mapping.lookupField}=${val})`);
|
|
65
79
|
} else {
|
package/dist/bin.mjs
CHANGED
|
@@ -10,12 +10,20 @@ async function resolveRelations(payload, collectionSlug, data, config) {
|
|
|
10
10
|
const collection = payload.collections[collectionSlug];
|
|
11
11
|
if (!collection) throw new Error(`Collection "${collectionSlug}" not found.`);
|
|
12
12
|
const resolved = { ...data };
|
|
13
|
+
const mappingConfig = config.mappings[collectionSlug];
|
|
14
|
+
if (mappingConfig?.defaults) {
|
|
15
|
+
for (const [k, v] of Object.entries(mappingConfig.defaults)) {
|
|
16
|
+
if (resolved[k] === void 0 || resolved[k] === null) {
|
|
17
|
+
resolved[k] = v;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
13
21
|
for (const field of collection.config.fields) {
|
|
14
|
-
if (field.type === "relationship" &&
|
|
22
|
+
if (field.type === "relationship" && resolved[field.name]) {
|
|
15
23
|
const relationTo = Array.isArray(field.relationTo) ? field.relationTo[0] : field.relationTo;
|
|
16
24
|
const mapping = config.mappings[relationTo];
|
|
17
25
|
if (!mapping) continue;
|
|
18
|
-
const rawValue =
|
|
26
|
+
const rawValue = resolved[field.name];
|
|
19
27
|
const isArray = Array.isArray(rawValue);
|
|
20
28
|
const values = isArray ? rawValue : [rawValue];
|
|
21
29
|
const resolvedIds = [];
|
|
@@ -28,6 +36,12 @@ async function resolveRelations(payload, collectionSlug, data, config) {
|
|
|
28
36
|
});
|
|
29
37
|
if (found.docs.length > 0) {
|
|
30
38
|
resolvedIds.push(found.docs[0].id);
|
|
39
|
+
} else if (mapping.onNotFound === "create") {
|
|
40
|
+
const created = await payload.create({
|
|
41
|
+
collection: relationTo,
|
|
42
|
+
data: { [mapping.lookupField]: val }
|
|
43
|
+
});
|
|
44
|
+
resolvedIds.push(created.id);
|
|
31
45
|
} else if (mapping.onNotFound === "error") {
|
|
32
46
|
throw new Error(`Relation not found: ${relationTo} (${mapping.lookupField}=${val})`);
|
|
33
47
|
} else {
|
package/dist/index.d.mts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -40,12 +40,20 @@ async function resolveRelations(payload, collectionSlug, data, config) {
|
|
|
40
40
|
const collection = payload.collections[collectionSlug];
|
|
41
41
|
if (!collection) throw new Error(`Collection "${collectionSlug}" not found.`);
|
|
42
42
|
const resolved = { ...data };
|
|
43
|
+
const mappingConfig = config.mappings[collectionSlug];
|
|
44
|
+
if (mappingConfig?.defaults) {
|
|
45
|
+
for (const [k, v] of Object.entries(mappingConfig.defaults)) {
|
|
46
|
+
if (resolved[k] === void 0 || resolved[k] === null) {
|
|
47
|
+
resolved[k] = v;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
43
51
|
for (const field of collection.config.fields) {
|
|
44
|
-
if (field.type === "relationship" &&
|
|
52
|
+
if (field.type === "relationship" && resolved[field.name]) {
|
|
45
53
|
const relationTo = Array.isArray(field.relationTo) ? field.relationTo[0] : field.relationTo;
|
|
46
54
|
const mapping = config.mappings[relationTo];
|
|
47
55
|
if (!mapping) continue;
|
|
48
|
-
const rawValue =
|
|
56
|
+
const rawValue = resolved[field.name];
|
|
49
57
|
const isArray = Array.isArray(rawValue);
|
|
50
58
|
const values = isArray ? rawValue : [rawValue];
|
|
51
59
|
const resolvedIds = [];
|
|
@@ -58,6 +66,12 @@ async function resolveRelations(payload, collectionSlug, data, config) {
|
|
|
58
66
|
});
|
|
59
67
|
if (found.docs.length > 0) {
|
|
60
68
|
resolvedIds.push(found.docs[0].id);
|
|
69
|
+
} else if (mapping.onNotFound === "create") {
|
|
70
|
+
const created = await payload.create({
|
|
71
|
+
collection: relationTo,
|
|
72
|
+
data: { [mapping.lookupField]: val }
|
|
73
|
+
});
|
|
74
|
+
resolvedIds.push(created.id);
|
|
61
75
|
} else if (mapping.onNotFound === "error") {
|
|
62
76
|
throw new Error(`Relation not found: ${relationTo} (${mapping.lookupField}=${val})`);
|
|
63
77
|
} else {
|
package/dist/index.mjs
CHANGED