@webiny/api-headless-cms 5.19.0-beta.3 → 5.19.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.
@@ -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; }
@@ -116,11 +118,26 @@ const buildReferenceFieldPaths = params => {
116
118
  }, []);
117
119
  };
118
120
 
121
+ const getReferenceFieldValue = ref => {
122
+ if (!ref) {
123
+ return {
124
+ id: null,
125
+ modelId: null
126
+ };
127
+ }
128
+
129
+ return {
130
+ id: (ref.id || ref.entryId || "").trim() || null,
131
+ modelId: (ref.modelId || "").trim() || null
132
+ };
133
+ };
134
+
119
135
  const referenceFieldsMapping = async params => {
120
136
  const {
121
137
  context,
122
138
  model,
123
- input
139
+ input,
140
+ validateEntries = false
124
141
  } = params;
125
142
 
126
143
  let output = _objectSpread({}, input);
@@ -141,21 +158,26 @@ const referenceFieldsMapping = async params => {
141
158
  for (const path of referenceFieldPaths) {
142
159
  const ref = _dotProp.default.get(output, path);
143
160
 
144
- if (!ref || !ref.id || !ref.modelId) {
161
+ const {
162
+ id,
163
+ modelId
164
+ } = getReferenceFieldValue(ref);
165
+
166
+ if (!id || !modelId) {
145
167
  continue;
146
168
  }
147
169
 
148
- if (!referencesByModel[ref.modelId]) {
149
- referencesByModel[ref.modelId] = [];
170
+ if (!referencesByModel[modelId]) {
171
+ referencesByModel[modelId] = [];
150
172
  }
151
173
 
152
- referencesByModel[ref.modelId].push(ref.id);
174
+ referencesByModel[modelId].push(id);
153
175
 
154
- if (!pathsByReferenceId[ref.id]) {
155
- pathsByReferenceId[ref.id] = [];
176
+ if (!pathsByReferenceId[id]) {
177
+ pathsByReferenceId[id] = [];
156
178
  }
157
179
 
158
- pathsByReferenceId[ref.id].push(path);
180
+ pathsByReferenceId[id].push(path);
159
181
  }
160
182
  /**
161
183
  * Again, no point in going further.
@@ -197,7 +219,11 @@ const referenceFieldsMapping = async params => {
197
219
  const results = await Promise.all(promises);
198
220
  const records = results.reduce((collection, entries) => {
199
221
  for (const entry of entries) {
200
- collection[entry.id] = entry;
222
+ collection[entry.id] = {
223
+ id: entry.id,
224
+ entryId: entry.entryId,
225
+ modelId: entry.modelId
226
+ };
201
227
  }
202
228
 
203
229
  return collection;
@@ -209,15 +235,24 @@ const referenceFieldsMapping = async params => {
209
235
  for (const modelId in referencesByModel) {
210
236
  const entries = referencesByModel[modelId];
211
237
 
212
- for (const entry of entries) {
213
- if (records[entry]) {
238
+ for (const id of entries) {
239
+ if (records[id]) {
214
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
+ });
215
246
  }
216
247
 
217
- throw new _error.default(`Missing referenced entry with id "${entry}" in model "${modelId}".`, "ENTRY_NOT_FOUND", {
218
- entry,
219
- model: modelId
220
- });
248
+ const {
249
+ id: entryId
250
+ } = (0, _utils.parseIdentifier)(id);
251
+ records[id] = {
252
+ id,
253
+ entryId,
254
+ modelId
255
+ };
221
256
  }
222
257
  }
223
258
  /**
@@ -230,10 +265,14 @@ const referenceFieldsMapping = async params => {
230
265
  const paths = pathsByReferenceId[id];
231
266
 
232
267
  if (!entry) {
233
- throw new _error.default("Missing entry in records.", "ENTRY_ERROR", {
234
- id,
235
- paths
236
- });
268
+ if (validateEntries === true) {
269
+ throw new _error.default("Missing entry in records.", "ENTRY_ERROR", {
270
+ id,
271
+ paths
272
+ });
273
+ }
274
+
275
+ continue;
237
276
  }
238
277
 
239
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), {}, {
@@ -35,7 +35,8 @@ const assignBeforeModelDelete = params => {
35
35
  const result = await storageOperations.entries.list(model, {
36
36
  where: {
37
37
  tenant: model.tenant,
38
- locale: model.locale
38
+ locale: model.locale,
39
+ latest: true
39
40
  },
40
41
  limit: 1
41
42
  });
@@ -42,7 +42,7 @@ const createContentCruds = params => {
42
42
  }
43
43
 
44
44
  const getLocale = () => {
45
- return context.i18n.getCurrentLocale();
45
+ return context.cms.getLocale();
46
46
  };
47
47
 
48
48
  const getIdentity = () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webiny/api-headless-cms",
3
- "version": "5.19.0-beta.3",
3
+ "version": "5.19.0",
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.3",
25
- "@webiny/api-i18n": "5.19.0-beta.3",
26
- "@webiny/api-i18n-content": "5.19.0-beta.3",
27
- "@webiny/api-i18n-ddb": "5.19.0-beta.3",
28
- "@webiny/api-security": "5.19.0-beta.3",
29
- "@webiny/api-tenancy": "5.19.0-beta.3",
30
- "@webiny/api-upgrade": "5.19.0-beta.3",
31
- "@webiny/error": "5.19.0-beta.3",
32
- "@webiny/handler": "5.19.0-beta.3",
33
- "@webiny/handler-aws": "5.19.0-beta.3",
34
- "@webiny/handler-db": "5.19.0-beta.3",
35
- "@webiny/handler-graphql": "5.19.0-beta.3",
36
- "@webiny/handler-http": "5.19.0-beta.3",
37
- "@webiny/plugins": "5.19.0-beta.3",
38
- "@webiny/pubsub": "5.19.0-beta.3",
39
- "@webiny/utils": "5.19.0-beta.3",
40
- "@webiny/validation": "5.19.0-beta.3",
24
+ "@webiny/api-file-manager": "5.19.0",
25
+ "@webiny/api-i18n": "5.19.0",
26
+ "@webiny/api-i18n-content": "5.19.0",
27
+ "@webiny/api-i18n-ddb": "5.19.0",
28
+ "@webiny/api-security": "5.19.0",
29
+ "@webiny/api-tenancy": "5.19.0",
30
+ "@webiny/api-upgrade": "5.19.0",
31
+ "@webiny/error": "5.19.0",
32
+ "@webiny/handler": "5.19.0",
33
+ "@webiny/handler-aws": "5.19.0",
34
+ "@webiny/handler-db": "5.19.0",
35
+ "@webiny/handler-graphql": "5.19.0",
36
+ "@webiny/handler-http": "5.19.0",
37
+ "@webiny/plugins": "5.19.0",
38
+ "@webiny/pubsub": "5.19.0",
39
+ "@webiny/utils": "5.19.0",
40
+ "@webiny/validation": "5.19.0",
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.3",
58
- "@webiny/api-tenancy-so-ddb": "^5.19.0-beta.3",
59
- "@webiny/cli": "^5.19.0-beta.3",
60
- "@webiny/project-utils": "^5.19.0-beta.3",
57
+ "@webiny/api-security-so-ddb": "^5.19.0",
58
+ "@webiny/api-tenancy-so-ddb": "^5.19.0",
59
+ "@webiny/cli": "^5.19.0",
60
+ "@webiny/project-utils": "^5.19.0",
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": "a1cca819f83172183b907de16fd5746d07d13ad0"
80
+ "gitHead": "9cb14e343f881e70ce71967ff525b52f385b64d3"
81
81
  }
@@ -17,7 +17,7 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
17
17
 
18
18
  var _default = () => {
19
19
  return new _ContextPlugin.ContextPlugin(context => {
20
- const locale = context.i18n.getCurrentLocale();
20
+ const locale = context.i18nContent.getLocale();
21
21
  context.cms = _objectSpread(_objectSpread({}, context.cms || {}), {}, {
22
22
  locale: locale ? locale.code : "en-US",
23
23
 
@@ -42,7 +42,7 @@ const createAdminCruds = params => {
42
42
  }
43
43
 
44
44
  const getLocale = () => {
45
- return context.i18n.getCurrentLocale();
45
+ return context.cms.getLocale();
46
46
  };
47
47
 
48
48
  const getIdentity = () => {