@webiny/api-headless-cms 5.19.0-beta.4 → 5.19.0-beta.5

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.
@@ -7,6 +7,7 @@ interface Params {
7
7
  context: CmsContext;
8
8
  model: CmsModel;
9
9
  input: Record<string, ReferenceObject | ReferenceObject[]>;
10
+ validateEntries?: boolean;
10
11
  }
11
12
  export declare const referenceFieldsMapping: (params: Params) => Promise<Record<string, any>>;
12
13
  export {};
@@ -13,6 +13,8 @@ var _error = _interopRequireDefault(require("@webiny/error"));
13
13
 
14
14
  var _dotProp = _interopRequireDefault(require("dot-prop"));
15
15
 
16
+ var _utils = require("@webiny/utils");
17
+
16
18
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
17
19
 
18
20
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
@@ -134,7 +136,8 @@ const referenceFieldsMapping = async params => {
134
136
  const {
135
137
  context,
136
138
  model,
137
- input
139
+ input,
140
+ validateEntries = false
138
141
  } = params;
139
142
 
140
143
  let output = _objectSpread({}, input);
@@ -216,7 +219,11 @@ const referenceFieldsMapping = async params => {
216
219
  const results = await Promise.all(promises);
217
220
  const records = results.reduce((collection, entries) => {
218
221
  for (const entry of entries) {
219
- collection[entry.id] = entry;
222
+ collection[entry.id] = {
223
+ id: entry.id,
224
+ entryId: entry.entryId,
225
+ modelId: entry.modelId
226
+ };
220
227
  }
221
228
 
222
229
  return collection;
@@ -228,15 +235,24 @@ const referenceFieldsMapping = async params => {
228
235
  for (const modelId in referencesByModel) {
229
236
  const entries = referencesByModel[modelId];
230
237
 
231
- for (const entry of entries) {
232
- if (records[entry]) {
238
+ for (const id of entries) {
239
+ if (records[id]) {
233
240
  continue;
241
+ } else if (validateEntries === true) {
242
+ throw new _error.default(`Missing referenced entry with id "${id}" in model "${modelId}".`, "ENTRY_NOT_FOUND", {
243
+ id,
244
+ model: modelId
245
+ });
234
246
  }
235
247
 
236
- throw new _error.default(`Missing referenced entry with id "${entry}" in model "${modelId}".`, "ENTRY_NOT_FOUND", {
237
- entry,
238
- model: modelId
239
- });
248
+ const {
249
+ id: entryId
250
+ } = (0, _utils.parseIdentifier)(id);
251
+ records[id] = {
252
+ id,
253
+ entryId,
254
+ modelId
255
+ };
240
256
  }
241
257
  }
242
258
  /**
@@ -249,10 +265,14 @@ const referenceFieldsMapping = async params => {
249
265
  const paths = pathsByReferenceId[id];
250
266
 
251
267
  if (!entry) {
252
- throw new _error.default("Missing entry in records.", "ENTRY_ERROR", {
253
- id,
254
- paths
255
- });
268
+ if (validateEntries === true) {
269
+ throw new _error.default("Missing entry in records.", "ENTRY_ERROR", {
270
+ id,
271
+ paths
272
+ });
273
+ }
274
+
275
+ continue;
256
276
  }
257
277
 
258
278
  for (const path of paths) {
@@ -380,7 +380,8 @@ const createContentEntryCrud = params => {
380
380
  const input = await (0, _referenceFieldsMapping.referenceFieldsMapping)({
381
381
  context,
382
382
  model,
383
- input: initialInput
383
+ input: initialInput,
384
+ validateEntries: true
384
385
  });
385
386
  const identity = context.security.getIdentity();
386
387
  const locale = context.cms.getLocale();
@@ -480,7 +481,8 @@ const createContentEntryCrud = params => {
480
481
  const values = await (0, _referenceFieldsMapping.referenceFieldsMapping)({
481
482
  context,
482
483
  model,
483
- input: initialValues
484
+ input: initialValues,
485
+ validateEntries: false
484
486
  });
485
487
  utils.checkOwnership(context, permission, originalEntry);
486
488
  const latestEntry = await (0, _entryStorage.entryFromStorageTransform)(context, model, latestStorageEntry);
@@ -578,7 +580,8 @@ const createContentEntryCrud = params => {
578
580
  const values = await (0, _referenceFieldsMapping.referenceFieldsMapping)({
579
581
  context,
580
582
  model,
581
- input: initialValues
583
+ input: initialValues,
584
+ validateEntries: false
582
585
  });
583
586
  /**
584
587
  * We always send the full entry to the hooks and storage operations update.
@@ -656,7 +659,8 @@ const createContentEntryCrud = params => {
656
659
  const values = await (0, _referenceFieldsMapping.referenceFieldsMapping)({
657
660
  context,
658
661
  model,
659
- input: originalEntry.values
662
+ input: originalEntry.values,
663
+ validateEntries: false
660
664
  });
661
665
 
662
666
  const entry = _objectSpread(_objectSpread({}, originalEntry), {}, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webiny/api-headless-cms",
3
- "version": "5.19.0-beta.4",
3
+ "version": "5.19.0-beta.5",
4
4
  "main": "index.js",
5
5
  "keywords": [
6
6
  "cms:base"
@@ -21,23 +21,23 @@
21
21
  "@babel/runtime": "7.16.3",
22
22
  "@commodo/fields": "1.1.2-beta.20",
23
23
  "@graphql-tools/schema": "7.1.5",
24
- "@webiny/api-file-manager": "5.19.0-beta.4",
25
- "@webiny/api-i18n": "5.19.0-beta.4",
26
- "@webiny/api-i18n-content": "5.19.0-beta.4",
27
- "@webiny/api-i18n-ddb": "5.19.0-beta.4",
28
- "@webiny/api-security": "5.19.0-beta.4",
29
- "@webiny/api-tenancy": "5.19.0-beta.4",
30
- "@webiny/api-upgrade": "5.19.0-beta.4",
31
- "@webiny/error": "5.19.0-beta.4",
32
- "@webiny/handler": "5.19.0-beta.4",
33
- "@webiny/handler-aws": "5.19.0-beta.4",
34
- "@webiny/handler-db": "5.19.0-beta.4",
35
- "@webiny/handler-graphql": "5.19.0-beta.4",
36
- "@webiny/handler-http": "5.19.0-beta.4",
37
- "@webiny/plugins": "5.19.0-beta.4",
38
- "@webiny/pubsub": "5.19.0-beta.4",
39
- "@webiny/utils": "5.19.0-beta.4",
40
- "@webiny/validation": "5.19.0-beta.4",
24
+ "@webiny/api-file-manager": "5.19.0-beta.5",
25
+ "@webiny/api-i18n": "5.19.0-beta.5",
26
+ "@webiny/api-i18n-content": "5.19.0-beta.5",
27
+ "@webiny/api-i18n-ddb": "5.19.0-beta.5",
28
+ "@webiny/api-security": "5.19.0-beta.5",
29
+ "@webiny/api-tenancy": "5.19.0-beta.5",
30
+ "@webiny/api-upgrade": "5.19.0-beta.5",
31
+ "@webiny/error": "5.19.0-beta.5",
32
+ "@webiny/handler": "5.19.0-beta.5",
33
+ "@webiny/handler-aws": "5.19.0-beta.5",
34
+ "@webiny/handler-db": "5.19.0-beta.5",
35
+ "@webiny/handler-graphql": "5.19.0-beta.5",
36
+ "@webiny/handler-http": "5.19.0-beta.5",
37
+ "@webiny/plugins": "5.19.0-beta.5",
38
+ "@webiny/pubsub": "5.19.0-beta.5",
39
+ "@webiny/utils": "5.19.0-beta.5",
40
+ "@webiny/validation": "5.19.0-beta.5",
41
41
  "boolean": "3.1.4",
42
42
  "commodo-fields-object": "1.0.6",
43
43
  "dataloader": "2.0.0",
@@ -54,10 +54,10 @@
54
54
  "@babel/core": "^7.5.5",
55
55
  "@babel/preset-env": "^7.5.5",
56
56
  "@babel/preset-flow": "^7.0.0",
57
- "@webiny/api-security-so-ddb": "^5.19.0-beta.4",
58
- "@webiny/api-tenancy-so-ddb": "^5.19.0-beta.4",
59
- "@webiny/cli": "^5.19.0-beta.4",
60
- "@webiny/project-utils": "^5.19.0-beta.4",
57
+ "@webiny/api-security-so-ddb": "^5.19.0-beta.5",
58
+ "@webiny/api-tenancy-so-ddb": "^5.19.0-beta.5",
59
+ "@webiny/cli": "^5.19.0-beta.5",
60
+ "@webiny/project-utils": "^5.19.0-beta.5",
61
61
  "apollo-graphql": "^0.4.1",
62
62
  "get-yarn-workspaces": "^1.0.2",
63
63
  "graphql": "^14.6.0",
@@ -77,5 +77,5 @@
77
77
  "build": "yarn webiny run build",
78
78
  "watch": "yarn webiny run watch"
79
79
  },
80
- "gitHead": "d115a87beb3ad3979c91a4ddf14082883be241f0"
80
+ "gitHead": "839188911bbaee4a596724c729c0a78f681fa614"
81
81
  }