@atlaskit/node-data-provider 8.0.0 → 8.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/CHANGELOG.md +18 -0
- package/dist/cjs/node-data-provider.js +92 -4
- package/dist/es2019/node-data-provider.js +78 -4
- package/dist/esm/node-data-provider.js +92 -4
- package/dist/types/node-data-provider.d.ts +34 -0
- package/dist/types-ts4.5/node-data-provider.d.ts +34 -0
- package/package.json +9 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @atlaskit/node-data-provider
|
|
2
2
|
|
|
3
|
+
## 8.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [`c9e2a2b390abf`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/c9e2a2b390abf) -
|
|
8
|
+
Batch retrieve should batch retrieve block calls in renderer
|
|
9
|
+
|
|
10
|
+
## 8.1.0
|
|
11
|
+
|
|
12
|
+
### Minor Changes
|
|
13
|
+
|
|
14
|
+
- [`cfea9d4edb5f0`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/cfea9d4edb5f0) -
|
|
15
|
+
EDITOR-2849 refactor to use unify cache
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- Updated dependencies
|
|
20
|
+
|
|
3
21
|
## 8.0.0
|
|
4
22
|
|
|
5
23
|
### Patch Changes
|
|
@@ -6,11 +6,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.NodeDataProvider = void 0;
|
|
8
8
|
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
9
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
10
|
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
10
11
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
11
12
|
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
12
13
|
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
13
14
|
var _coreUtils = require("@atlaskit/editor-common/core-utils");
|
|
15
|
+
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
14
16
|
/**
|
|
15
17
|
* Represents the SSR data for a single provider.
|
|
16
18
|
* It's a map where each key is a unique node data key and the value is the prefetched data for that node.
|
|
@@ -69,6 +71,13 @@ var NodeDataProvider = exports.NodeDataProvider = /*#__PURE__*/function () {
|
|
|
69
71
|
key: "setSSRData",
|
|
70
72
|
value: function setSSRData() {
|
|
71
73
|
var ssrData = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
74
|
+
if ((0, _platformFeatureFlags.fg)('platform_synced_block_patch_1')) {
|
|
75
|
+
this.updateCache(ssrData, {
|
|
76
|
+
strategy: 'replace',
|
|
77
|
+
source: 'ssr'
|
|
78
|
+
});
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
72
81
|
this.cacheVersion++;
|
|
73
82
|
this.cache = Object.fromEntries(Object.entries(ssrData).map(function (_ref) {
|
|
74
83
|
var _ref2 = (0, _slicedToArray2.default)(_ref, 2),
|
|
@@ -218,10 +227,17 @@ var NodeDataProvider = exports.NodeDataProvider = /*#__PURE__*/function () {
|
|
|
218
227
|
// because it could be stale data.
|
|
219
228
|
if (cacheVersionBeforeRequest === this.cacheVersion) {
|
|
220
229
|
// Replace promise with the resolved data in the cache
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
230
|
+
if ((0, _platformFeatureFlags.fg)('platform_synced_block_patch_1')) {
|
|
231
|
+
this.updateCache((0, _defineProperty2.default)({}, dataKey, _data), {
|
|
232
|
+
strategy: 'merge',
|
|
233
|
+
source: 'network'
|
|
234
|
+
});
|
|
235
|
+
} else {
|
|
236
|
+
this.cache[dataKey] = {
|
|
237
|
+
data: _data,
|
|
238
|
+
source: 'network'
|
|
239
|
+
};
|
|
240
|
+
}
|
|
225
241
|
}
|
|
226
242
|
_context.next = 38;
|
|
227
243
|
break;
|
|
@@ -319,5 +335,77 @@ var NodeDataProvider = exports.NodeDataProvider = /*#__PURE__*/function () {
|
|
|
319
335
|
var dataKey = this.nodeDataKey(jsonNode);
|
|
320
336
|
return this.cache[dataKey];
|
|
321
337
|
}
|
|
338
|
+
|
|
339
|
+
/**
|
|
340
|
+
* Updates the cache with new records using merge or replace strategies.
|
|
341
|
+
* This method should be the only way to modify the cache directly.
|
|
342
|
+
* This allow subclasses to use it when needed. e.g. abstract fetchNodesData implementation.
|
|
343
|
+
*
|
|
344
|
+
* @example
|
|
345
|
+
* ```
|
|
346
|
+
* const newRecords = {
|
|
347
|
+
* 'node-id-1': { value: 'updated data' },
|
|
348
|
+
* 'node-id-3': { value: 'new data' }
|
|
349
|
+
* };
|
|
350
|
+
* nodeDataProvider.updateCache(newRecords, { strategy: 'merge', source: 'network' });
|
|
351
|
+
* ```
|
|
352
|
+
*
|
|
353
|
+
* Supports two strategies:
|
|
354
|
+
* - 'merge' (default): Merges new records into the existing cache.
|
|
355
|
+
* - 'replace': Replaces the entire cache with the new records, invalidating any in-flight requests.
|
|
356
|
+
*
|
|
357
|
+
* @param records A map of node data keys to their corresponding data.
|
|
358
|
+
* @param options Optional settings for the update operation.
|
|
359
|
+
* @param options.strategy The strategy to use for updating the cache ('merge' or 'replace'). Defaults to 'merge'.
|
|
360
|
+
* @param options.source The source of the data being added ('ssr' or 'network'). Defaults to 'network'.
|
|
361
|
+
*/
|
|
362
|
+
}, {
|
|
363
|
+
key: "updateCache",
|
|
364
|
+
value: function updateCache() {
|
|
365
|
+
var _options$strategy, _options$source;
|
|
366
|
+
var records = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
367
|
+
var options = arguments.length > 1 ? arguments[1] : undefined;
|
|
368
|
+
var strategy = (_options$strategy = options === null || options === void 0 ? void 0 : options.strategy) !== null && _options$strategy !== void 0 ? _options$strategy : 'merge';
|
|
369
|
+
var source = (_options$source = options === null || options === void 0 ? void 0 : options.source) !== null && _options$source !== void 0 ? _options$source : 'network';
|
|
370
|
+
if (strategy === 'merge') {
|
|
371
|
+
for (var _i = 0, _Object$entries = Object.entries(records); _i < _Object$entries.length; _i++) {
|
|
372
|
+
var _Object$entries$_i = (0, _slicedToArray2.default)(_Object$entries[_i], 2),
|
|
373
|
+
key = _Object$entries$_i[0],
|
|
374
|
+
data = _Object$entries$_i[1];
|
|
375
|
+
this.cache[key] = {
|
|
376
|
+
data: data,
|
|
377
|
+
source: source
|
|
378
|
+
};
|
|
379
|
+
}
|
|
380
|
+
return;
|
|
381
|
+
} else if (strategy === 'replace') {
|
|
382
|
+
// Replace the entire cache with the new records
|
|
383
|
+
// This will increase the cache version to invalidate any in-flight requests
|
|
384
|
+
this.resetCache();
|
|
385
|
+
this.cache = Object.fromEntries(Object.entries(records).map(function (_ref5) {
|
|
386
|
+
var _ref6 = (0, _slicedToArray2.default)(_ref5, 2),
|
|
387
|
+
key = _ref6[0],
|
|
388
|
+
data = _ref6[1];
|
|
389
|
+
return [key, {
|
|
390
|
+
data: data,
|
|
391
|
+
source: source
|
|
392
|
+
}];
|
|
393
|
+
}));
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
* Removes one or more entries from the cache.
|
|
399
|
+
*
|
|
400
|
+
* @param keys A single data key or array of data keys to remove from the cache.
|
|
401
|
+
*/
|
|
402
|
+
}, {
|
|
403
|
+
key: "removeFromCache",
|
|
404
|
+
value: function removeFromCache(keys) {
|
|
405
|
+
var _this2 = this;
|
|
406
|
+
keys.forEach(function (key) {
|
|
407
|
+
delete _this2.cache[key];
|
|
408
|
+
});
|
|
409
|
+
}
|
|
322
410
|
}]);
|
|
323
411
|
}();
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { isSSR } from '@atlaskit/editor-common/core-utils';
|
|
2
|
+
import { fg } from '@atlaskit/platform-feature-flags';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Represents the SSR data for a single provider.
|
|
@@ -83,6 +84,13 @@ export class NodeDataProvider {
|
|
|
83
84
|
* @param ssrData A map of node data keys to their corresponding data.
|
|
84
85
|
*/
|
|
85
86
|
setSSRData(ssrData = {}) {
|
|
87
|
+
if (fg('platform_synced_block_patch_1')) {
|
|
88
|
+
this.updateCache(ssrData, {
|
|
89
|
+
strategy: 'replace',
|
|
90
|
+
source: 'ssr'
|
|
91
|
+
});
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
86
94
|
this.cacheVersion++;
|
|
87
95
|
this.cache = Object.fromEntries(Object.entries(ssrData).map(([key, data]) => [key, {
|
|
88
96
|
data,
|
|
@@ -202,10 +210,19 @@ export class NodeDataProvider {
|
|
|
202
210
|
// because it could be stale data.
|
|
203
211
|
if (cacheVersionBeforeRequest === this.cacheVersion) {
|
|
204
212
|
// Replace promise with the resolved data in the cache
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
213
|
+
if (fg('platform_synced_block_patch_1')) {
|
|
214
|
+
this.updateCache({
|
|
215
|
+
[dataKey]: data
|
|
216
|
+
}, {
|
|
217
|
+
strategy: 'merge',
|
|
218
|
+
source: 'network'
|
|
219
|
+
});
|
|
220
|
+
} else {
|
|
221
|
+
this.cache[dataKey] = {
|
|
222
|
+
data,
|
|
223
|
+
source: 'network'
|
|
224
|
+
};
|
|
225
|
+
}
|
|
209
226
|
}
|
|
210
227
|
} catch (error) {
|
|
211
228
|
// If an error occurs, we call the callback with the error
|
|
@@ -283,4 +300,61 @@ export class NodeDataProvider {
|
|
|
283
300
|
const dataKey = this.nodeDataKey(jsonNode);
|
|
284
301
|
return this.cache[dataKey];
|
|
285
302
|
}
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* Updates the cache with new records using merge or replace strategies.
|
|
306
|
+
* This method should be the only way to modify the cache directly.
|
|
307
|
+
* This allow subclasses to use it when needed. e.g. abstract fetchNodesData implementation.
|
|
308
|
+
*
|
|
309
|
+
* @example
|
|
310
|
+
* ```
|
|
311
|
+
* const newRecords = {
|
|
312
|
+
* 'node-id-1': { value: 'updated data' },
|
|
313
|
+
* 'node-id-3': { value: 'new data' }
|
|
314
|
+
* };
|
|
315
|
+
* nodeDataProvider.updateCache(newRecords, { strategy: 'merge', source: 'network' });
|
|
316
|
+
* ```
|
|
317
|
+
*
|
|
318
|
+
* Supports two strategies:
|
|
319
|
+
* - 'merge' (default): Merges new records into the existing cache.
|
|
320
|
+
* - 'replace': Replaces the entire cache with the new records, invalidating any in-flight requests.
|
|
321
|
+
*
|
|
322
|
+
* @param records A map of node data keys to their corresponding data.
|
|
323
|
+
* @param options Optional settings for the update operation.
|
|
324
|
+
* @param options.strategy The strategy to use for updating the cache ('merge' or 'replace'). Defaults to 'merge'.
|
|
325
|
+
* @param options.source The source of the data being added ('ssr' or 'network'). Defaults to 'network'.
|
|
326
|
+
*/
|
|
327
|
+
updateCache(records = {}, options) {
|
|
328
|
+
var _options$strategy, _options$source;
|
|
329
|
+
const strategy = (_options$strategy = options === null || options === void 0 ? void 0 : options.strategy) !== null && _options$strategy !== void 0 ? _options$strategy : 'merge';
|
|
330
|
+
const source = (_options$source = options === null || options === void 0 ? void 0 : options.source) !== null && _options$source !== void 0 ? _options$source : 'network';
|
|
331
|
+
if (strategy === 'merge') {
|
|
332
|
+
for (const [key, data] of Object.entries(records)) {
|
|
333
|
+
this.cache[key] = {
|
|
334
|
+
data,
|
|
335
|
+
source
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
return;
|
|
339
|
+
} else if (strategy === 'replace') {
|
|
340
|
+
// Replace the entire cache with the new records
|
|
341
|
+
// This will increase the cache version to invalidate any in-flight requests
|
|
342
|
+
this.resetCache();
|
|
343
|
+
this.cache = Object.fromEntries(Object.entries(records).map(([key, data]) => [key, {
|
|
344
|
+
data,
|
|
345
|
+
source
|
|
346
|
+
}]));
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
/**
|
|
351
|
+
* Removes one or more entries from the cache.
|
|
352
|
+
*
|
|
353
|
+
* @param keys A single data key or array of data keys to remove from the cache.
|
|
354
|
+
*/
|
|
355
|
+
removeFromCache(keys) {
|
|
356
|
+
keys.forEach(key => {
|
|
357
|
+
delete this.cache[key];
|
|
358
|
+
});
|
|
359
|
+
}
|
|
286
360
|
}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
1
2
|
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
2
3
|
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
3
4
|
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
4
5
|
import _createClass from "@babel/runtime/helpers/createClass";
|
|
5
6
|
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
6
7
|
import { isSSR } from '@atlaskit/editor-common/core-utils';
|
|
8
|
+
import { fg } from '@atlaskit/platform-feature-flags';
|
|
7
9
|
|
|
8
10
|
/**
|
|
9
11
|
* Represents the SSR data for a single provider.
|
|
@@ -66,6 +68,13 @@ export var NodeDataProvider = /*#__PURE__*/function () {
|
|
|
66
68
|
key: "setSSRData",
|
|
67
69
|
value: function setSSRData() {
|
|
68
70
|
var ssrData = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
71
|
+
if (fg('platform_synced_block_patch_1')) {
|
|
72
|
+
this.updateCache(ssrData, {
|
|
73
|
+
strategy: 'replace',
|
|
74
|
+
source: 'ssr'
|
|
75
|
+
});
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
69
78
|
this.cacheVersion++;
|
|
70
79
|
this.cache = Object.fromEntries(Object.entries(ssrData).map(function (_ref) {
|
|
71
80
|
var _ref2 = _slicedToArray(_ref, 2),
|
|
@@ -215,10 +224,17 @@ export var NodeDataProvider = /*#__PURE__*/function () {
|
|
|
215
224
|
// because it could be stale data.
|
|
216
225
|
if (cacheVersionBeforeRequest === this.cacheVersion) {
|
|
217
226
|
// Replace promise with the resolved data in the cache
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
227
|
+
if (fg('platform_synced_block_patch_1')) {
|
|
228
|
+
this.updateCache(_defineProperty({}, dataKey, _data), {
|
|
229
|
+
strategy: 'merge',
|
|
230
|
+
source: 'network'
|
|
231
|
+
});
|
|
232
|
+
} else {
|
|
233
|
+
this.cache[dataKey] = {
|
|
234
|
+
data: _data,
|
|
235
|
+
source: 'network'
|
|
236
|
+
};
|
|
237
|
+
}
|
|
222
238
|
}
|
|
223
239
|
_context.next = 38;
|
|
224
240
|
break;
|
|
@@ -316,5 +332,77 @@ export var NodeDataProvider = /*#__PURE__*/function () {
|
|
|
316
332
|
var dataKey = this.nodeDataKey(jsonNode);
|
|
317
333
|
return this.cache[dataKey];
|
|
318
334
|
}
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* Updates the cache with new records using merge or replace strategies.
|
|
338
|
+
* This method should be the only way to modify the cache directly.
|
|
339
|
+
* This allow subclasses to use it when needed. e.g. abstract fetchNodesData implementation.
|
|
340
|
+
*
|
|
341
|
+
* @example
|
|
342
|
+
* ```
|
|
343
|
+
* const newRecords = {
|
|
344
|
+
* 'node-id-1': { value: 'updated data' },
|
|
345
|
+
* 'node-id-3': { value: 'new data' }
|
|
346
|
+
* };
|
|
347
|
+
* nodeDataProvider.updateCache(newRecords, { strategy: 'merge', source: 'network' });
|
|
348
|
+
* ```
|
|
349
|
+
*
|
|
350
|
+
* Supports two strategies:
|
|
351
|
+
* - 'merge' (default): Merges new records into the existing cache.
|
|
352
|
+
* - 'replace': Replaces the entire cache with the new records, invalidating any in-flight requests.
|
|
353
|
+
*
|
|
354
|
+
* @param records A map of node data keys to their corresponding data.
|
|
355
|
+
* @param options Optional settings for the update operation.
|
|
356
|
+
* @param options.strategy The strategy to use for updating the cache ('merge' or 'replace'). Defaults to 'merge'.
|
|
357
|
+
* @param options.source The source of the data being added ('ssr' or 'network'). Defaults to 'network'.
|
|
358
|
+
*/
|
|
359
|
+
}, {
|
|
360
|
+
key: "updateCache",
|
|
361
|
+
value: function updateCache() {
|
|
362
|
+
var _options$strategy, _options$source;
|
|
363
|
+
var records = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
364
|
+
var options = arguments.length > 1 ? arguments[1] : undefined;
|
|
365
|
+
var strategy = (_options$strategy = options === null || options === void 0 ? void 0 : options.strategy) !== null && _options$strategy !== void 0 ? _options$strategy : 'merge';
|
|
366
|
+
var source = (_options$source = options === null || options === void 0 ? void 0 : options.source) !== null && _options$source !== void 0 ? _options$source : 'network';
|
|
367
|
+
if (strategy === 'merge') {
|
|
368
|
+
for (var _i = 0, _Object$entries = Object.entries(records); _i < _Object$entries.length; _i++) {
|
|
369
|
+
var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
|
|
370
|
+
key = _Object$entries$_i[0],
|
|
371
|
+
data = _Object$entries$_i[1];
|
|
372
|
+
this.cache[key] = {
|
|
373
|
+
data: data,
|
|
374
|
+
source: source
|
|
375
|
+
};
|
|
376
|
+
}
|
|
377
|
+
return;
|
|
378
|
+
} else if (strategy === 'replace') {
|
|
379
|
+
// Replace the entire cache with the new records
|
|
380
|
+
// This will increase the cache version to invalidate any in-flight requests
|
|
381
|
+
this.resetCache();
|
|
382
|
+
this.cache = Object.fromEntries(Object.entries(records).map(function (_ref5) {
|
|
383
|
+
var _ref6 = _slicedToArray(_ref5, 2),
|
|
384
|
+
key = _ref6[0],
|
|
385
|
+
data = _ref6[1];
|
|
386
|
+
return [key, {
|
|
387
|
+
data: data,
|
|
388
|
+
source: source
|
|
389
|
+
}];
|
|
390
|
+
}));
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
/**
|
|
395
|
+
* Removes one or more entries from the cache.
|
|
396
|
+
*
|
|
397
|
+
* @param keys A single data key or array of data keys to remove from the cache.
|
|
398
|
+
*/
|
|
399
|
+
}, {
|
|
400
|
+
key: "removeFromCache",
|
|
401
|
+
value: function removeFromCache(keys) {
|
|
402
|
+
var _this2 = this;
|
|
403
|
+
keys.forEach(function (key) {
|
|
404
|
+
delete _this2.cache[key];
|
|
405
|
+
});
|
|
406
|
+
}
|
|
319
407
|
}]);
|
|
320
408
|
}();
|
|
@@ -13,6 +13,7 @@ import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
|
13
13
|
type SSRData<Data> = {
|
|
14
14
|
[dataKey: string]: Data;
|
|
15
15
|
};
|
|
16
|
+
type CacheRecords<Data> = SSRData<Data>;
|
|
16
17
|
/**
|
|
17
18
|
* Represents the cached data for a Node Data Provider.
|
|
18
19
|
* Each key is a unique node data key, and the value is an object containing:
|
|
@@ -170,5 +171,38 @@ export declare abstract class NodeDataProvider<Node extends JSONNode, Data> {
|
|
|
170
171
|
* @returns The cached data object containing `data` and `source`, or `undefined` if no cache entry exists.
|
|
171
172
|
*/
|
|
172
173
|
getNodeDataFromCache(node: JSONNode | PMNode): CacheData<Data>[string] | undefined;
|
|
174
|
+
/**
|
|
175
|
+
* Updates the cache with new records using merge or replace strategies.
|
|
176
|
+
* This method should be the only way to modify the cache directly.
|
|
177
|
+
* This allow subclasses to use it when needed. e.g. abstract fetchNodesData implementation.
|
|
178
|
+
*
|
|
179
|
+
* @example
|
|
180
|
+
* ```
|
|
181
|
+
* const newRecords = {
|
|
182
|
+
* 'node-id-1': { value: 'updated data' },
|
|
183
|
+
* 'node-id-3': { value: 'new data' }
|
|
184
|
+
* };
|
|
185
|
+
* nodeDataProvider.updateCache(newRecords, { strategy: 'merge', source: 'network' });
|
|
186
|
+
* ```
|
|
187
|
+
*
|
|
188
|
+
* Supports two strategies:
|
|
189
|
+
* - 'merge' (default): Merges new records into the existing cache.
|
|
190
|
+
* - 'replace': Replaces the entire cache with the new records, invalidating any in-flight requests.
|
|
191
|
+
*
|
|
192
|
+
* @param records A map of node data keys to their corresponding data.
|
|
193
|
+
* @param options Optional settings for the update operation.
|
|
194
|
+
* @param options.strategy The strategy to use for updating the cache ('merge' or 'replace'). Defaults to 'merge'.
|
|
195
|
+
* @param options.source The source of the data being added ('ssr' or 'network'). Defaults to 'network'.
|
|
196
|
+
*/
|
|
197
|
+
updateCache(records?: CacheRecords<Data>, options?: {
|
|
198
|
+
source?: 'ssr' | 'network';
|
|
199
|
+
strategy?: 'merge' | 'replace';
|
|
200
|
+
}): void;
|
|
201
|
+
/**
|
|
202
|
+
* Removes one or more entries from the cache.
|
|
203
|
+
*
|
|
204
|
+
* @param keys A single data key or array of data keys to remove from the cache.
|
|
205
|
+
*/
|
|
206
|
+
removeFromCache(keys: string[]): void;
|
|
173
207
|
}
|
|
174
208
|
export {};
|
|
@@ -13,6 +13,7 @@ import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
|
13
13
|
type SSRData<Data> = {
|
|
14
14
|
[dataKey: string]: Data;
|
|
15
15
|
};
|
|
16
|
+
type CacheRecords<Data> = SSRData<Data>;
|
|
16
17
|
/**
|
|
17
18
|
* Represents the cached data for a Node Data Provider.
|
|
18
19
|
* Each key is a unique node data key, and the value is an object containing:
|
|
@@ -170,5 +171,38 @@ export declare abstract class NodeDataProvider<Node extends JSONNode, Data> {
|
|
|
170
171
|
* @returns The cached data object containing `data` and `source`, or `undefined` if no cache entry exists.
|
|
171
172
|
*/
|
|
172
173
|
getNodeDataFromCache(node: JSONNode | PMNode): CacheData<Data>[string] | undefined;
|
|
174
|
+
/**
|
|
175
|
+
* Updates the cache with new records using merge or replace strategies.
|
|
176
|
+
* This method should be the only way to modify the cache directly.
|
|
177
|
+
* This allow subclasses to use it when needed. e.g. abstract fetchNodesData implementation.
|
|
178
|
+
*
|
|
179
|
+
* @example
|
|
180
|
+
* ```
|
|
181
|
+
* const newRecords = {
|
|
182
|
+
* 'node-id-1': { value: 'updated data' },
|
|
183
|
+
* 'node-id-3': { value: 'new data' }
|
|
184
|
+
* };
|
|
185
|
+
* nodeDataProvider.updateCache(newRecords, { strategy: 'merge', source: 'network' });
|
|
186
|
+
* ```
|
|
187
|
+
*
|
|
188
|
+
* Supports two strategies:
|
|
189
|
+
* - 'merge' (default): Merges new records into the existing cache.
|
|
190
|
+
* - 'replace': Replaces the entire cache with the new records, invalidating any in-flight requests.
|
|
191
|
+
*
|
|
192
|
+
* @param records A map of node data keys to their corresponding data.
|
|
193
|
+
* @param options Optional settings for the update operation.
|
|
194
|
+
* @param options.strategy The strategy to use for updating the cache ('merge' or 'replace'). Defaults to 'merge'.
|
|
195
|
+
* @param options.source The source of the data being added ('ssr' or 'network'). Defaults to 'network'.
|
|
196
|
+
*/
|
|
197
|
+
updateCache(records?: CacheRecords<Data>, options?: {
|
|
198
|
+
source?: 'ssr' | 'network';
|
|
199
|
+
strategy?: 'merge' | 'replace';
|
|
200
|
+
}): void;
|
|
201
|
+
/**
|
|
202
|
+
* Removes one or more entries from the cache.
|
|
203
|
+
*
|
|
204
|
+
* @param keys A single data key or array of data keys to remove from the cache.
|
|
205
|
+
*/
|
|
206
|
+
removeFromCache(keys: string[]): void;
|
|
173
207
|
}
|
|
174
208
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/node-data-provider",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.2.0",
|
|
4
4
|
"description": "Node data provider for @atlaskit/editor-core plugins and @atlaskit/renderer",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -20,11 +20,12 @@
|
|
|
20
20
|
"atlaskit:src": "src/index.ts",
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"@atlaskit/editor-json-transformer": "^8.31.0",
|
|
23
|
-
"@atlaskit/editor-prosemirror": "^7.
|
|
23
|
+
"@atlaskit/editor-prosemirror": "^7.3.0",
|
|
24
|
+
"@atlaskit/platform-feature-flags": "^1.1.0",
|
|
24
25
|
"@babel/runtime": "^7.0.0"
|
|
25
26
|
},
|
|
26
27
|
"peerDependencies": {
|
|
27
|
-
"@atlaskit/editor-common": "^111.
|
|
28
|
+
"@atlaskit/editor-common": "^111.11.0"
|
|
28
29
|
},
|
|
29
30
|
"techstack": {
|
|
30
31
|
"@atlassian/frontend": {
|
|
@@ -49,6 +50,11 @@
|
|
|
49
50
|
]
|
|
50
51
|
}
|
|
51
52
|
},
|
|
53
|
+
"platform-feature-flags": {
|
|
54
|
+
"platform_synced_block_patch_1": {
|
|
55
|
+
"type": "boolean"
|
|
56
|
+
}
|
|
57
|
+
},
|
|
52
58
|
"stricter": {
|
|
53
59
|
"no-unused-dependencies": {
|
|
54
60
|
"checkDevDependencies": true
|