@webiny/app-record-locking 5.43.2 → 6.0.0-alpha.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.
Files changed (88) hide show
  1. package/components/HeadlessCmsActionsAcoCell.js +46 -57
  2. package/components/HeadlessCmsActionsAcoCell.js.map +1 -1
  3. package/components/HeadlessCmsContentEntry/ContentEntryGuard.js +22 -29
  4. package/components/HeadlessCmsContentEntry/ContentEntryGuard.js.map +1 -1
  5. package/components/HeadlessCmsContentEntry/ContentEntryLocker.js +43 -60
  6. package/components/HeadlessCmsContentEntry/ContentEntryLocker.js.map +1 -1
  7. package/components/HeadlessCmsContentEntry/HeadlessCmsContentEntry.js +54 -67
  8. package/components/HeadlessCmsContentEntry/HeadlessCmsContentEntry.js.map +1 -1
  9. package/components/HeadlessCmsContentEntry/index.js +1 -16
  10. package/components/HeadlessCmsContentEntry/index.js.map +1 -1
  11. package/components/LockedRecord/LockedRecord.js +49 -144
  12. package/components/LockedRecord/LockedRecord.js.map +1 -1
  13. package/components/LockedRecord/LockedRecordForceUnlock.js +51 -93
  14. package/components/LockedRecord/LockedRecordForceUnlock.js.map +1 -1
  15. package/components/LockedRecord/index.js +1 -16
  16. package/components/LockedRecord/index.js.map +1 -1
  17. package/components/RecordLockingProvider.js +47 -67
  18. package/components/RecordLockingProvider.js.map +1 -1
  19. package/components/decorators/UseContentEntriesListHookDecorator.js +10 -17
  20. package/components/decorators/UseContentEntriesListHookDecorator.js.map +1 -1
  21. package/components/decorators/UseRecordsDecorator.js +11 -16
  22. package/components/decorators/UseRecordsDecorator.js.map +1 -1
  23. package/components/decorators/UseSaveEntryDecorator.js +34 -32
  24. package/components/decorators/UseSaveEntryDecorator.js.map +1 -1
  25. package/components/permissionRenderer/RecordLockingPermissions.js +39 -53
  26. package/components/permissionRenderer/RecordLockingPermissions.js.map +1 -1
  27. package/components/permissionRenderer/index.js +13 -17
  28. package/components/permissionRenderer/index.js.map +1 -1
  29. package/domain/RecordLocking.js +271 -311
  30. package/domain/RecordLocking.js.map +1 -1
  31. package/domain/RecordLockingClient.js +15 -29
  32. package/domain/RecordLockingClient.js.map +1 -1
  33. package/domain/RecordLockingGetLockRecord.js +16 -29
  34. package/domain/RecordLockingGetLockRecord.js.map +1 -1
  35. package/domain/RecordLockingGetLockedEntryLockRecord.js +14 -27
  36. package/domain/RecordLockingGetLockedEntryLockRecord.js.map +1 -1
  37. package/domain/RecordLockingIsEntryLocked.js +14 -27
  38. package/domain/RecordLockingIsEntryLocked.js.map +1 -1
  39. package/domain/RecordLockingListLockRecords.js +26 -37
  40. package/domain/RecordLockingListLockRecords.js.map +1 -1
  41. package/domain/RecordLockingLockEntry.js +9 -22
  42. package/domain/RecordLockingLockEntry.js.map +1 -1
  43. package/domain/RecordLockingUnlockEntry.js +14 -27
  44. package/domain/RecordLockingUnlockEntry.js.map +1 -1
  45. package/domain/RecordLockingUpdateEntryLock.js +14 -27
  46. package/domain/RecordLockingUpdateEntryLock.js.map +1 -1
  47. package/domain/abstractions/IRecordLocking.js +1 -5
  48. package/domain/abstractions/IRecordLockingClient.js +1 -5
  49. package/domain/abstractions/IRecordLockingGetLockRecord.js +1 -5
  50. package/domain/abstractions/IRecordLockingGetLockedEntryLockRecord.js +1 -5
  51. package/domain/abstractions/IRecordLockingIsEntryLocked.js +1 -5
  52. package/domain/abstractions/IRecordLockingListLockRecords.js +1 -5
  53. package/domain/abstractions/IRecordLockingLockEntry.js +1 -5
  54. package/domain/abstractions/IRecordLockingUnlockEntry.js +1 -5
  55. package/domain/abstractions/IRecordLockingUpdateEntryLock.js +1 -5
  56. package/domain/graphql/fields.js +28 -8
  57. package/domain/graphql/fields.js.map +1 -1
  58. package/domain/graphql/getLockRecord.js +16 -12
  59. package/domain/graphql/getLockRecord.js.map +1 -1
  60. package/domain/graphql/getLockedEntryLockRecord.js +16 -12
  61. package/domain/graphql/getLockedEntryLockRecord.js.map +1 -1
  62. package/domain/graphql/isEntryLocked.js +14 -12
  63. package/domain/graphql/isEntryLocked.js.map +1 -1
  64. package/domain/graphql/listLockRecords.js +23 -14
  65. package/domain/graphql/listLockRecords.js.map +1 -1
  66. package/domain/graphql/lockEntry.js +17 -13
  67. package/domain/graphql/lockEntry.js.map +1 -1
  68. package/domain/graphql/unlockEntry.js +16 -12
  69. package/domain/graphql/unlockEntry.js.map +1 -1
  70. package/domain/graphql/updateEntryLock.js +16 -12
  71. package/domain/graphql/updateEntryLock.js.map +1 -1
  72. package/domain/utils/createRecordLockingClient.js +6 -12
  73. package/domain/utils/createRecordLockingClient.js.map +1 -1
  74. package/domain/utils/createRecordLockingError.js +1 -7
  75. package/domain/utils/createRecordLockingError.js.map +1 -1
  76. package/hooks/index.js +2 -27
  77. package/hooks/index.js.map +1 -1
  78. package/hooks/usePermission.js +11 -16
  79. package/hooks/usePermission.js.map +1 -1
  80. package/hooks/useRecordLocking.js +6 -12
  81. package/hooks/useRecordLocking.js.map +1 -1
  82. package/index.js +20 -50
  83. package/index.js.map +1 -1
  84. package/package.json +17 -18
  85. package/types.js +1 -5
  86. package/utils/createCacheKey.js +5 -11
  87. package/utils/createCacheKey.js.map +1 -1
  88. package/components/assets/lock.svg +0 -13
@@ -1,32 +1,19 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.createRecordLocking = void 0;
8
- var _createForOfIteratorHelper2 = _interopRequireDefault(require("@babel/runtime/helpers/createForOfIteratorHelper"));
9
- var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
10
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
11
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
12
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
13
- var _RecordLockingGetLockRecord = require("./RecordLockingGetLockRecord");
14
- var _RecordLockingIsEntryLocked = require("./RecordLockingIsEntryLocked");
15
- var _RecordLockingListLockRecords = require("./RecordLockingListLockRecords");
16
- var _RecordLockingLockEntry = require("./RecordLockingLockEntry");
17
- var _RecordLockingUnlockEntry = require("./RecordLockingUnlockEntry");
18
- var _RecordLockingClient = require("./RecordLockingClient");
19
- var _createRecordLockingError = require("./utils/createRecordLockingError");
20
- var _parseIdentifier9 = require("@webiny/utils/parseIdentifier");
21
- var _createCacheKey = require("../utils/createCacheKey");
22
- var _RecordLockingUpdateEntryLock = require("./RecordLockingUpdateEntryLock");
23
- var _RecordLockingGetLockedEntryLockRecord = require("./RecordLockingGetLockedEntryLockRecord");
24
- var RecordLocking = /*#__PURE__*/function () {
25
- function RecordLocking(params) {
26
- (0, _classCallCheck2.default)(this, RecordLocking);
27
- (0, _defineProperty2.default)(this, "loading", false);
28
- (0, _defineProperty2.default)(this, "records", []);
29
- (0, _defineProperty2.default)(this, "onErrorCb", null);
1
+ import { RecordLockingGetLockRecord } from "./RecordLockingGetLockRecord";
2
+ import { RecordLockingIsEntryLocked } from "./RecordLockingIsEntryLocked";
3
+ import { RecordLockingListLockRecords } from "./RecordLockingListLockRecords";
4
+ import { RecordLockingLockEntry } from "./RecordLockingLockEntry";
5
+ import { RecordLockingUnlockEntry } from "./RecordLockingUnlockEntry";
6
+ import { RecordLockingClient } from "./RecordLockingClient";
7
+ import { createRecordLockingError } from "./utils/createRecordLockingError";
8
+ import { parseIdentifier } from "@webiny/utils/parseIdentifier";
9
+ import { createCacheKey } from "../utils/createCacheKey";
10
+ import { RecordLockingUpdateEntryLock } from "./RecordLockingUpdateEntryLock";
11
+ import { RecordLockingGetLockedEntryLockRecord } from "./RecordLockingGetLockedEntryLockRecord";
12
+ class RecordLocking {
13
+ loading = false;
14
+ records = [];
15
+ onErrorCb = null;
16
+ constructor(params) {
30
17
  this._setLoading = params.setLoading;
31
18
  this._getLockRecord = params.getLockRecord;
32
19
  this._getLockedEntryLockRecord = params.getLockedEntryLockRecord;
@@ -34,326 +21,299 @@ var RecordLocking = /*#__PURE__*/function () {
34
21
  this._unlockEntry = params.unlockEntry;
35
22
  this._updateEntryLock = params.updateEntryLock;
36
23
  }
37
- return (0, _createClass2.default)(RecordLocking, [{
38
- key: "setRecords",
39
- value: async function setRecords(folderId, type, records) {
40
- var result = await this.fetchAndAssignRecords(folderId, type, records);
41
- if (!result) {
42
- return undefined;
43
- }
44
- return result.map(function (record) {
45
- var _parseIdentifier = (0, _parseIdentifier9.parseIdentifier)(record.id),
46
- entryId = _parseIdentifier.id;
47
- return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, record), {}, {
48
- $lockingType: type,
49
- $locked: record.$locked,
50
- $selectable: record.$locked ? false : record.$selectable,
51
- entryId: entryId
52
- });
53
- });
24
+ async setRecords(folderId, type, records) {
25
+ const result = await this.fetchAndAssignRecords(folderId, type, records);
26
+ if (!result) {
27
+ return undefined;
54
28
  }
55
- }, {
56
- key: "fetchLockRecord",
57
- value: async function fetchLockRecord(params) {
58
- var id = params.id,
59
- $lockingType = params.$lockingType;
60
- var _parseIdentifier2 = (0, _parseIdentifier9.parseIdentifier)(id),
61
- entryId = _parseIdentifier2.id;
62
- try {
63
- var result = await this._getLockRecord.execute({
64
- id: entryId,
65
- type: $lockingType
66
- });
67
- return {
68
- data: result.data,
69
- error: result.error
70
- };
71
- } catch (ex) {
72
- return {
73
- data: null,
74
- error: ex
75
- };
76
- }
77
- }
78
- }, {
79
- key: "fetchLockedEntryLockRecord",
80
- value: async function fetchLockedEntryLockRecord(params) {
81
- var id = params.id,
82
- $lockingType = params.$lockingType;
83
- var _parseIdentifier3 = (0, _parseIdentifier9.parseIdentifier)(id),
84
- entryId = _parseIdentifier3.id;
85
- var result = await this._getLockedEntryLockRecord.execute({
29
+ return result.map(record => {
30
+ const {
31
+ id: entryId
32
+ } = parseIdentifier(record.id);
33
+ return {
34
+ ...record,
35
+ $lockingType: type,
36
+ $locked: record.$locked,
37
+ $selectable: record.$locked ? false : record.$selectable,
38
+ entryId
39
+ };
40
+ });
41
+ }
42
+ async fetchLockRecord(params) {
43
+ const {
44
+ id,
45
+ $lockingType
46
+ } = params;
47
+ const {
48
+ id: entryId
49
+ } = parseIdentifier(id);
50
+ try {
51
+ const result = await this._getLockRecord.execute({
86
52
  id: entryId,
87
53
  type: $lockingType
88
54
  });
89
- return result.data;
55
+ return {
56
+ data: result.data,
57
+ error: result.error
58
+ };
59
+ } catch (ex) {
60
+ return {
61
+ data: null,
62
+ error: ex
63
+ };
90
64
  }
91
- }, {
92
- key: "getLockRecordEntry",
93
- value: function getLockRecordEntry(id) {
94
- return this.records.find(function (record) {
95
- var _parseIdentifier4 = (0, _parseIdentifier9.parseIdentifier)(id),
96
- entryId = _parseIdentifier4.id;
97
- return record.entryId === entryId;
98
- });
65
+ }
66
+ async fetchLockedEntryLockRecord(params) {
67
+ const {
68
+ id,
69
+ $lockingType
70
+ } = params;
71
+ const {
72
+ id: entryId
73
+ } = parseIdentifier(id);
74
+ const result = await this._getLockedEntryLockRecord.execute({
75
+ id: entryId,
76
+ type: $lockingType
77
+ });
78
+ return result.data;
79
+ }
80
+ getLockRecordEntry(id) {
81
+ return this.records.find(record => {
82
+ const {
83
+ id: entryId
84
+ } = parseIdentifier(id);
85
+ return record.entryId === entryId;
86
+ });
87
+ }
88
+ isRecordLocked(record) {
89
+ const result = this.records.find(r => {
90
+ const {
91
+ id: entryId
92
+ } = parseIdentifier(record.id);
93
+ return r.entryId === entryId && !!r.$locked && r.$lockingType === record.$lockingType;
94
+ });
95
+ if (!result?.$locked?.expiresOn) {
96
+ return false;
99
97
  }
100
- }, {
101
- key: "isRecordLocked",
102
- value: function isRecordLocked(record) {
103
- var result = this.records.find(function (r) {
104
- var _parseIdentifier5 = (0, _parseIdentifier9.parseIdentifier)(record.id),
105
- entryId = _parseIdentifier5.id;
106
- return r.entryId === entryId && !!r.$locked && r.$lockingType === record.$lockingType;
98
+ const isExpired = this.isLockExpired(result.$locked.expiresOn);
99
+ return !isExpired;
100
+ }
101
+ async updateEntryLock(params) {
102
+ try {
103
+ return await this._updateEntryLock.execute({
104
+ id: params.id,
105
+ type: params.$lockingType
107
106
  });
108
- if (!result?.$locked?.expiresOn) {
109
- return false;
110
- }
111
- var isExpired = this.isLockExpired(result.$locked.expiresOn);
112
- return !isExpired;
107
+ } catch (ex) {
108
+ this.triggerOnError(ex);
109
+ return {
110
+ data: null,
111
+ error: ex
112
+ };
113
113
  }
114
- }, {
115
- key: "updateEntryLock",
116
- value: async function updateEntryLock(params) {
117
- try {
118
- return await this._updateEntryLock.execute({
119
- id: params.id,
120
- type: params.$lockingType
121
- });
122
- } catch (ex) {
123
- this.triggerOnError(ex);
124
- return {
125
- data: null,
126
- error: ex
127
- };
128
- }
114
+ }
115
+ removeEntryLock(params) {
116
+ const index = this.records.findIndex(record => {
117
+ return record.entryId === params.id && record.$lockingType === params.$lockingType;
118
+ });
119
+ if (index === -1) {
120
+ return;
129
121
  }
130
- }, {
131
- key: "removeEntryLock",
132
- value: function removeEntryLock(params) {
133
- var index = this.records.findIndex(function (record) {
134
- return record.entryId === params.id && record.$lockingType === params.$lockingType;
122
+ this.records[index] = {
123
+ ...this.records[index],
124
+ $locked: null,
125
+ $selectable: true
126
+ };
127
+ }
128
+ async unlockEntry(params, force) {
129
+ try {
130
+ const result = await this._unlockEntry.execute({
131
+ id: params.id,
132
+ type: params.$lockingType,
133
+ force
135
134
  });
136
- if (index === -1) {
137
- return;
135
+ const id = result.data?.id;
136
+ if (!id) {
137
+ return result;
138
138
  }
139
- this.records[index] = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, this.records[index]), {}, {
140
- $locked: null,
141
- $selectable: true
139
+ this.removeEntryLock({
140
+ ...params
142
141
  });
142
+ return result;
143
+ } catch (ex) {
144
+ this.triggerOnError(ex);
145
+ return {
146
+ data: null,
147
+ error: ex
148
+ };
143
149
  }
144
- }, {
145
- key: "unlockEntry",
146
- value: async function unlockEntry(params, force) {
147
- try {
148
- var result = await this._unlockEntry.execute({
149
- id: params.id,
150
- type: params.$lockingType,
151
- force: force
152
- });
153
- var id = result.data?.id;
154
- if (!id) {
155
- return result;
156
- }
157
- this.removeEntryLock((0, _objectSpread2.default)({}, params));
158
- return result;
159
- } catch (ex) {
160
- this.triggerOnError(ex);
161
- return {
162
- data: null,
163
- error: ex
164
- };
165
- }
150
+ }
151
+ onError(cb) {
152
+ this.onErrorCb = cb;
153
+ }
154
+ triggerOnError(error) {
155
+ this.setIsLoading(false);
156
+ if (!this.onErrorCb) {
157
+ return;
166
158
  }
167
- }, {
168
- key: "onError",
169
- value: function onError(cb) {
170
- this.onErrorCb = cb;
159
+ this.onErrorCb(error);
160
+ }
161
+ isLockExpired(input) {
162
+ const expiresOn = new Date(input);
163
+ return expiresOn <= new Date();
164
+ }
165
+ setIsLoading(loading) {
166
+ this._setLoading(loading);
167
+ this.loading = loading;
168
+ }
169
+ async fetchAndAssignRecords(folderId, type, records) {
170
+ if (records.length === 0) {
171
+ return;
172
+ } else if (this.loading) {
173
+ return;
171
174
  }
172
- }, {
173
- key: "triggerOnError",
174
- value: function triggerOnError(error) {
175
- this.setIsLoading(false);
176
- if (!this.onErrorCb) {
177
- return;
178
- }
179
- this.onErrorCb(error);
175
+ const assignedIdList = await this.assignRecords(folderId, type, records);
176
+ if (assignedIdList.length === 0) {
177
+ return;
180
178
  }
181
- }, {
182
- key: "isLockExpired",
183
- value: function isLockExpired(input) {
184
- var expiresOn = new Date(input);
185
- return expiresOn <= new Date();
179
+ this.setIsLoading(true);
180
+ let result;
181
+ try {
182
+ result = await this._listLockRecords.execute({
183
+ where: {
184
+ id_in: assignedIdList,
185
+ type
186
+ },
187
+ limit: 10000
188
+ });
189
+ } catch (ex) {
190
+ console.error(ex);
191
+ this.triggerOnError(ex);
192
+ return;
193
+ } finally {
194
+ this.setIsLoading(false);
186
195
  }
187
- }, {
188
- key: "setIsLoading",
189
- value: function setIsLoading(loading) {
190
- this._setLoading(loading);
191
- this.loading = loading;
196
+ if (result.error) {
197
+ this.triggerOnError(result.error);
198
+ return;
199
+ } else if (!result.data) {
200
+ this.triggerOnError(createRecordLockingError({
201
+ message: `There is no data in the result and there is no error. Please check the network tab for more info.`,
202
+ code: "NO_DATA_IN_RESULT"
203
+ }));
204
+ return;
205
+ } else if (result.data.length === 0) {
206
+ return;
192
207
  }
193
- }, {
194
- key: "fetchAndAssignRecords",
195
- value: async function fetchAndAssignRecords(folderId, type, records) {
196
- var _this = this;
197
- if (records.length === 0) {
198
- return;
199
- } else if (this.loading) {
200
- return;
201
- }
202
- var assignedIdList = await this.assignRecords(folderId, type, records);
203
- if (assignedIdList.length === 0) {
204
- return;
205
- }
206
- this.setIsLoading(true);
207
- var result;
208
- try {
209
- result = await this._listLockRecords.execute({
210
- where: {
211
- id_in: assignedIdList,
212
- type: type
213
- },
214
- limit: 10000
215
- });
216
- } catch (ex) {
217
- console.error(ex);
218
- this.triggerOnError(ex);
219
- return;
220
- } finally {
221
- this.setIsLoading(false);
222
- }
223
- if (result.error) {
224
- this.triggerOnError(result.error);
225
- return;
226
- } else if (!result.data) {
227
- this.triggerOnError((0, _createRecordLockingError.createRecordLockingError)({
228
- message: "There is no data in the result and there is no error. Please check the network tab for more info.",
229
- code: "NO_DATA_IN_RESULT"
230
- }));
231
- return;
232
- } else if (result.data.length === 0) {
233
- return;
208
+ for (const record of result.data) {
209
+ const index = this.records.findIndex(r => {
210
+ const {
211
+ id: entryId
212
+ } = parseIdentifier(record.id);
213
+ return r.entryId === entryId;
214
+ });
215
+ if (index < 0) {
216
+ console.error(`There is no record with id ${record.id} in the records array.`);
217
+ continue;
234
218
  }
235
- var _iterator = (0, _createForOfIteratorHelper2.default)(result.data),
236
- _step;
237
- try {
238
- var _loop = async function _loop() {
239
- var record = _step.value;
240
- var index = _this.records.findIndex(function (r) {
241
- var _parseIdentifier6 = (0, _parseIdentifier9.parseIdentifier)(record.id),
242
- entryId = _parseIdentifier6.id;
243
- return r.entryId === entryId;
244
- });
245
- if (index < 0) {
246
- console.error("There is no record with id ".concat(record.id, " in the records array."));
247
- return 1; // continue
248
- }
249
- _this.records[index] = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, _this.records[index]), {}, {
250
- $locked: {
251
- lockedBy: record.lockedBy,
252
- expiresOn: record.expiresOn,
253
- lockedOn: record.lockedOn,
254
- actions: record.actions
255
- }
256
- });
257
- };
258
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
259
- if (await _loop()) continue;
219
+ this.records[index] = {
220
+ ...this.records[index],
221
+ $locked: {
222
+ lockedBy: record.lockedBy,
223
+ expiresOn: record.expiresOn,
224
+ lockedOn: record.lockedOn,
225
+ actions: record.actions
260
226
  }
261
- } catch (err) {
262
- _iterator.e(err);
263
- } finally {
264
- _iterator.f();
265
- }
266
- return this.records;
227
+ };
267
228
  }
229
+ return this.records;
230
+ }
231
+ /**
232
+ * Assign records and return the assigned ID list.
233
+ */
234
+ async assignRecords(folderId, type, records) {
268
235
  /**
269
- * Assign records and return the assigned ID list.
236
+ * First we check the record keys against ones in the local cache.
270
237
  */
271
- }, {
272
- key: "assignRecords",
273
- value: async function assignRecords(folderId, type, records) {
274
- var _this2 = this;
275
- /**
276
- * First we check the record keys against ones in the local cache.
277
- */
278
- var keys = records.map(function (record) {
279
- if (record.entryId) {
280
- return record.entryId;
281
- }
282
- var _parseIdentifier7 = (0, _parseIdentifier9.parseIdentifier)(record.id),
283
- entryId = _parseIdentifier7.id;
284
- return entryId;
285
- });
286
- var cacheKey = await (0, _createCacheKey.createCacheKey)(keys);
287
- if (this.currentRecordsCacheKey === cacheKey) {
288
- return [];
238
+ const keys = records.map(record => {
239
+ if (record.entryId) {
240
+ return record.entryId;
289
241
  }
290
- this.currentRecordsCacheKey = cacheKey;
242
+ const {
243
+ id: entryId
244
+ } = parseIdentifier(record.id);
245
+ return entryId;
246
+ });
247
+ const cacheKey = await createCacheKey(keys);
248
+ if (this.currentRecordsCacheKey === cacheKey) {
249
+ return [];
250
+ }
251
+ this.currentRecordsCacheKey = cacheKey;
291
252
 
292
- /**
293
- * Reset records if new type is not as same as the old type / folderId.
294
- */
295
- if (this.currentRecordType !== type || this.currentFolderId !== folderId) {
296
- this.records = [];
297
- this.currentRecordType = type;
298
- this.currentFolderId = folderId;
253
+ /**
254
+ * Reset records if new type is not as same as the old type / folderId.
255
+ */
256
+ if (this.currentRecordType !== type || this.currentFolderId !== folderId) {
257
+ this.records = [];
258
+ this.currentRecordType = type;
259
+ this.currentFolderId = folderId;
260
+ }
261
+ return records.reduce((collection, record) => {
262
+ const {
263
+ id: entryId
264
+ } = parseIdentifier(record.id);
265
+ const index = this.records.findIndex(r => r.entryId === entryId);
266
+ if (index >= 0) {
267
+ return collection;
299
268
  }
300
- return records.reduce(function (collection, record) {
301
- var _parseIdentifier8 = (0, _parseIdentifier9.parseIdentifier)(record.id),
302
- entryId = _parseIdentifier8.id;
303
- var index = _this2.records.findIndex(function (r) {
304
- return r.entryId === entryId;
305
- });
306
- if (index >= 0) {
307
- return collection;
308
- }
309
- _this2.records.push((0, _objectSpread2.default)((0, _objectSpread2.default)({}, record), {}, {
310
- entryId: entryId,
311
- $lockingType: type,
312
- $locked: undefined
313
- }));
314
- if (record.$type !== "RECORD") {
315
- return collection;
316
- }
317
- collection.push(entryId);
269
+ this.records.push({
270
+ ...record,
271
+ entryId,
272
+ $lockingType: type,
273
+ $locked: undefined
274
+ });
275
+ if (record.$type !== "RECORD") {
318
276
  return collection;
319
- }, []);
320
- }
321
- }]);
322
- }();
323
- var createRecordLocking = exports.createRecordLocking = function createRecordLocking(config) {
324
- var client = new _RecordLockingClient.RecordLockingClient({
277
+ }
278
+ collection.push(entryId);
279
+ return collection;
280
+ }, []);
281
+ }
282
+ }
283
+ export const createRecordLocking = config => {
284
+ const client = new RecordLockingClient({
325
285
  client: config.client
326
286
  });
327
- var getLockRecord = new _RecordLockingGetLockRecord.RecordLockingGetLockRecord({
328
- client: client
287
+ const getLockRecord = new RecordLockingGetLockRecord({
288
+ client
329
289
  });
330
- var getLockedEntryLockRecord = new _RecordLockingGetLockedEntryLockRecord.RecordLockingGetLockedEntryLockRecord({
331
- client: client
290
+ const getLockedEntryLockRecord = new RecordLockingGetLockedEntryLockRecord({
291
+ client
332
292
  });
333
- var isEntryLocked = new _RecordLockingIsEntryLocked.RecordLockingIsEntryLocked({
334
- client: client
293
+ const isEntryLocked = new RecordLockingIsEntryLocked({
294
+ client
335
295
  });
336
- var listLockRecords = new _RecordLockingListLockRecords.RecordLockingListLockRecords({
337
- client: client
296
+ const listLockRecords = new RecordLockingListLockRecords({
297
+ client
338
298
  });
339
- var lockEntry = new _RecordLockingLockEntry.RecordLockingLockEntry({
340
- client: client
299
+ const lockEntry = new RecordLockingLockEntry({
300
+ client
341
301
  });
342
- var unlockEntry = new _RecordLockingUnlockEntry.RecordLockingUnlockEntry({
343
- client: client
302
+ const unlockEntry = new RecordLockingUnlockEntry({
303
+ client
344
304
  });
345
- var updateEntryLock = new _RecordLockingUpdateEntryLock.RecordLockingUpdateEntryLock({
346
- client: client
305
+ const updateEntryLock = new RecordLockingUpdateEntryLock({
306
+ client
347
307
  });
348
308
  return new RecordLocking({
349
309
  setLoading: config.setLoading,
350
- getLockRecord: getLockRecord,
351
- getLockedEntryLockRecord: getLockedEntryLockRecord,
352
- isEntryLocked: isEntryLocked,
353
- listLockRecords: listLockRecords,
354
- updateEntryLock: updateEntryLock,
355
- lockEntry: lockEntry,
356
- unlockEntry: unlockEntry
310
+ getLockRecord,
311
+ getLockedEntryLockRecord,
312
+ isEntryLocked,
313
+ listLockRecords,
314
+ updateEntryLock,
315
+ lockEntry,
316
+ unlockEntry
357
317
  });
358
318
  };
359
319