@webiny/app-record-locking 6.0.0-beta.0 → 6.0.0-rc.1

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