@atlaskit/editor-synced-block-provider 3.3.0 → 3.4.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.
@@ -2,11 +2,14 @@ import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
2
2
  import _createClass from "@babel/runtime/helpers/createClass";
3
3
  import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
4
4
  import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
5
+ function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
6
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
7
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
5
8
  import _regeneratorRuntime from "@babel/runtime/regenerator";
6
9
  /* eslint-disable require-unicode-regexp */
7
10
  import { useMemo } from 'react';
8
11
  import { generateBlockAri, generateBlockAriFromReference } from '../../clients/block-service/ari';
9
- import { BlockError, createSyncedBlock, deleteSyncedBlock, getReferenceSyncedBlocks, getSyncedBlockContent, updateReferenceSyncedBlockOnDocument, updateSyncedBlock } from '../../clients/block-service/blockService';
12
+ import { batchRetrieveSyncedBlocks, BlockError, createSyncedBlock, deleteSyncedBlock, getReferenceSyncedBlocks, getSyncedBlockContent, updateReferenceSyncedBlockOnDocument, updateSyncedBlock } from '../../clients/block-service/blockService';
10
13
  import { SyncBlockError } from '../../common/types';
11
14
  import { stringifyError } from '../../utils/errorHandling';
12
15
  var mapBlockError = function mapBlockError(error) {
@@ -197,6 +200,192 @@ var BlockServiceADFFetchProvider = /*#__PURE__*/function () {
197
200
  }
198
201
  return fetchData;
199
202
  }()
203
+ /**
204
+ * Extracts the resourceId from a block ARI.
205
+ * Block ARI format: ari:cloud:blocks:<cloudId>:synced-block/<resourceId>
206
+ */
207
+ }, {
208
+ key: "extractResourceIdFromBlockAri",
209
+ value: function extractResourceIdFromBlockAri(blockAri) {
210
+ var match = blockAri.match(/ari:cloud:blocks:[^:]+:synced-block\/(.+)$/);
211
+ return match === null || match === void 0 ? void 0 : match[1];
212
+ }
213
+
214
+ /**
215
+ * Batch fetches multiple synced blocks by their resource IDs.
216
+ * @param resourceIds - Array of resource IDs to fetch
217
+ * @returns Array of SyncBlockInstance results
218
+ */
219
+ }, {
220
+ key: "batchFetchData",
221
+ value: (function () {
222
+ var _batchFetchData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(resourceIds) {
223
+ var _this = this;
224
+ var blockAris, validResourceIds, processedResourceIds, response, results, _iterator, _step, blockContentResponse, resourceId, value, syncedBlockData, _iterator2, _step2, errorResponse, _resourceId, _iterator3, _step3, _resourceId2;
225
+ return _regeneratorRuntime.wrap(function _callee3$(_context3) {
226
+ while (1) switch (_context3.prev = _context3.next) {
227
+ case 0:
228
+ blockAris = resourceIds.map(function (resourceId) {
229
+ return generateBlockAriFromReference({
230
+ cloudId: _this.cloudId,
231
+ resourceId: resourceId
232
+ });
233
+ }); // Create a set of valid resourceIds for validation
234
+ validResourceIds = new Set(resourceIds); // Track which resourceIds have been processed
235
+ processedResourceIds = new Set();
236
+ _context3.prev = 3;
237
+ _context3.next = 6;
238
+ return batchRetrieveSyncedBlocks({
239
+ blockAris: blockAris
240
+ });
241
+ case 6:
242
+ response = _context3.sent;
243
+ results = []; // Process successful blocks
244
+ if (!response.success) {
245
+ _context3.next = 33;
246
+ break;
247
+ }
248
+ _iterator = _createForOfIteratorHelper(response.success);
249
+ _context3.prev = 10;
250
+ _iterator.s();
251
+ case 12:
252
+ if ((_step = _iterator.n()).done) {
253
+ _context3.next = 25;
254
+ break;
255
+ }
256
+ blockContentResponse = _step.value;
257
+ // Extract resourceId from the returned blockAri
258
+ resourceId = this.extractResourceIdFromBlockAri(blockContentResponse.blockAri);
259
+ if (!(!resourceId || !validResourceIds.has(resourceId))) {
260
+ _context3.next = 17;
261
+ break;
262
+ }
263
+ return _context3.abrupt("continue", 23);
264
+ case 17:
265
+ processedResourceIds.add(resourceId);
266
+ value = blockContentResponse.content;
267
+ if (value) {
268
+ _context3.next = 22;
269
+ break;
270
+ }
271
+ results.push({
272
+ error: SyncBlockError.NotFound,
273
+ resourceId: resourceId
274
+ });
275
+ return _context3.abrupt("continue", 23);
276
+ case 22:
277
+ try {
278
+ syncedBlockData = JSON.parse(value);
279
+ results.push({
280
+ data: {
281
+ content: syncedBlockData,
282
+ resourceId: blockContentResponse.blockAri,
283
+ blockInstanceId: blockContentResponse.blockInstanceId,
284
+ sourceAri: blockContentResponse.sourceAri,
285
+ product: blockContentResponse.product
286
+ },
287
+ resourceId: resourceId
288
+ });
289
+ } catch (_unused2) {
290
+ results.push({
291
+ error: SyncBlockError.Errored,
292
+ resourceId: resourceId
293
+ });
294
+ }
295
+ case 23:
296
+ _context3.next = 12;
297
+ break;
298
+ case 25:
299
+ _context3.next = 30;
300
+ break;
301
+ case 27:
302
+ _context3.prev = 27;
303
+ _context3.t0 = _context3["catch"](10);
304
+ _iterator.e(_context3.t0);
305
+ case 30:
306
+ _context3.prev = 30;
307
+ _iterator.f();
308
+ return _context3.finish(30);
309
+ case 33:
310
+ if (!response.error) {
311
+ _context3.next = 54;
312
+ break;
313
+ }
314
+ _iterator2 = _createForOfIteratorHelper(response.error);
315
+ _context3.prev = 35;
316
+ _iterator2.s();
317
+ case 37:
318
+ if ((_step2 = _iterator2.n()).done) {
319
+ _context3.next = 46;
320
+ break;
321
+ }
322
+ errorResponse = _step2.value;
323
+ // Extract resourceId from the returned blockAri
324
+ _resourceId = this.extractResourceIdFromBlockAri(errorResponse.blockAri);
325
+ if (!(!_resourceId || !validResourceIds.has(_resourceId))) {
326
+ _context3.next = 42;
327
+ break;
328
+ }
329
+ return _context3.abrupt("continue", 44);
330
+ case 42:
331
+ processedResourceIds.add(_resourceId);
332
+ results.push({
333
+ error: SyncBlockError.Errored,
334
+ resourceId: _resourceId
335
+ });
336
+ case 44:
337
+ _context3.next = 37;
338
+ break;
339
+ case 46:
340
+ _context3.next = 51;
341
+ break;
342
+ case 48:
343
+ _context3.prev = 48;
344
+ _context3.t1 = _context3["catch"](35);
345
+ _iterator2.e(_context3.t1);
346
+ case 51:
347
+ _context3.prev = 51;
348
+ _iterator2.f();
349
+ return _context3.finish(51);
350
+ case 54:
351
+ // Ensure all resourceIds have a result - return NotFound for any missing ones
352
+ _iterator3 = _createForOfIteratorHelper(resourceIds);
353
+ try {
354
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
355
+ _resourceId2 = _step3.value;
356
+ if (!processedResourceIds.has(_resourceId2)) {
357
+ results.push({
358
+ error: SyncBlockError.NotFound,
359
+ resourceId: _resourceId2
360
+ });
361
+ }
362
+ }
363
+ } catch (err) {
364
+ _iterator3.e(err);
365
+ } finally {
366
+ _iterator3.f();
367
+ }
368
+ return _context3.abrupt("return", results);
369
+ case 59:
370
+ _context3.prev = 59;
371
+ _context3.t2 = _context3["catch"](3);
372
+ return _context3.abrupt("return", resourceIds.map(function (resourceId) {
373
+ return {
374
+ error: _context3.t2 instanceof BlockError ? mapBlockError(_context3.t2) : SyncBlockError.Errored,
375
+ resourceId: resourceId
376
+ };
377
+ }));
378
+ case 62:
379
+ case "end":
380
+ return _context3.stop();
381
+ }
382
+ }, _callee3, this, [[3, 59], [10, 27, 30, 33], [35, 48, 51, 54]]);
383
+ }));
384
+ function batchFetchData(_x3) {
385
+ return _batchFetchData.apply(this, arguments);
386
+ }
387
+ return batchFetchData;
388
+ }())
200
389
  }]);
201
390
  }();
202
391
  /**
@@ -221,10 +410,10 @@ var BlockServiceADFWriteProvider = /*#__PURE__*/function () {
221
410
  return _createClass(BlockServiceADFWriteProvider, [{
222
411
  key: "writeData",
223
412
  value: function () {
224
- var _writeData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(data) {
413
+ var _writeData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(data) {
225
414
  var resourceId, blockAri, stepVersion;
226
- return _regeneratorRuntime.wrap(function _callee3$(_context3) {
227
- while (1) switch (_context3.prev = _context3.next) {
415
+ return _regeneratorRuntime.wrap(function _callee4$(_context4) {
416
+ while (1) switch (_context4.prev = _context4.next) {
228
417
  case 0:
229
418
  resourceId = data.resourceId;
230
419
  blockAri = generateBlockAri({
@@ -234,40 +423,40 @@ var BlockServiceADFWriteProvider = /*#__PURE__*/function () {
234
423
  resourceId: resourceId
235
424
  });
236
425
  stepVersion = this.getVersion ? this.getVersion() : undefined;
237
- _context3.prev = 3;
238
- _context3.next = 6;
426
+ _context4.prev = 3;
427
+ _context4.next = 6;
239
428
  return updateSyncedBlock({
240
429
  blockAri: blockAri,
241
430
  content: JSON.stringify(data.content),
242
431
  stepVersion: stepVersion
243
432
  });
244
433
  case 6:
245
- return _context3.abrupt("return", {
434
+ return _context4.abrupt("return", {
246
435
  resourceId: resourceId
247
436
  });
248
437
  case 9:
249
- _context3.prev = 9;
250
- _context3.t0 = _context3["catch"](3);
251
- if (!(_context3.t0 instanceof BlockError)) {
252
- _context3.next = 13;
438
+ _context4.prev = 9;
439
+ _context4.t0 = _context4["catch"](3);
440
+ if (!(_context4.t0 instanceof BlockError)) {
441
+ _context4.next = 13;
253
442
  break;
254
443
  }
255
- return _context3.abrupt("return", {
256
- error: mapBlockError(_context3.t0),
444
+ return _context4.abrupt("return", {
445
+ error: mapBlockError(_context4.t0),
257
446
  resourceId: resourceId
258
447
  });
259
448
  case 13:
260
- return _context3.abrupt("return", {
261
- error: stringifyError(_context3.t0),
449
+ return _context4.abrupt("return", {
450
+ error: stringifyError(_context4.t0),
262
451
  resourceId: resourceId
263
452
  });
264
453
  case 14:
265
454
  case "end":
266
- return _context3.stop();
455
+ return _context4.stop();
267
456
  }
268
- }, _callee3, this, [[3, 9]]);
457
+ }, _callee4, this, [[3, 9]]);
269
458
  }));
270
- function writeData(_x3) {
459
+ function writeData(_x4) {
271
460
  return _writeData.apply(this, arguments);
272
461
  }
273
462
  return writeData;
@@ -275,10 +464,10 @@ var BlockServiceADFWriteProvider = /*#__PURE__*/function () {
275
464
  }, {
276
465
  key: "createData",
277
466
  value: function () {
278
- var _createData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(data) {
467
+ var _createData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(data) {
279
468
  var resourceId, blockAri, stepVersion;
280
- return _regeneratorRuntime.wrap(function _callee4$(_context4) {
281
- while (1) switch (_context4.prev = _context4.next) {
469
+ return _regeneratorRuntime.wrap(function _callee5$(_context5) {
470
+ while (1) switch (_context5.prev = _context5.next) {
282
471
  case 0:
283
472
  resourceId = data.resourceId;
284
473
  blockAri = generateBlockAri({
@@ -288,8 +477,8 @@ var BlockServiceADFWriteProvider = /*#__PURE__*/function () {
288
477
  resourceId: resourceId
289
478
  });
290
479
  stepVersion = this.getVersion ? this.getVersion() : undefined;
291
- _context4.prev = 3;
292
- _context4.next = 6;
480
+ _context5.prev = 3;
481
+ _context5.next = 6;
293
482
  return createSyncedBlock({
294
483
  blockAri: blockAri,
295
484
  blockInstanceId: data.blockInstanceId,
@@ -299,32 +488,32 @@ var BlockServiceADFWriteProvider = /*#__PURE__*/function () {
299
488
  stepVersion: stepVersion
300
489
  });
301
490
  case 6:
302
- return _context4.abrupt("return", {
491
+ return _context5.abrupt("return", {
303
492
  resourceId: resourceId
304
493
  });
305
494
  case 9:
306
- _context4.prev = 9;
307
- _context4.t0 = _context4["catch"](3);
308
- if (!(_context4.t0 instanceof BlockError)) {
309
- _context4.next = 13;
495
+ _context5.prev = 9;
496
+ _context5.t0 = _context5["catch"](3);
497
+ if (!(_context5.t0 instanceof BlockError)) {
498
+ _context5.next = 13;
310
499
  break;
311
500
  }
312
- return _context4.abrupt("return", {
313
- error: mapBlockError(_context4.t0),
501
+ return _context5.abrupt("return", {
502
+ error: mapBlockError(_context5.t0),
314
503
  resourceId: resourceId
315
504
  });
316
505
  case 13:
317
- return _context4.abrupt("return", {
318
- error: stringifyError(_context4.t0),
506
+ return _context5.abrupt("return", {
507
+ error: stringifyError(_context5.t0),
319
508
  resourceId: resourceId
320
509
  });
321
510
  case 14:
322
511
  case "end":
323
- return _context4.stop();
512
+ return _context5.stop();
324
513
  }
325
- }, _callee4, this, [[3, 9]]);
514
+ }, _callee5, this, [[3, 9]]);
326
515
  }));
327
- function createData(_x4) {
516
+ function createData(_x5) {
328
517
  return _createData.apply(this, arguments);
329
518
  }
330
519
  return createData;
@@ -332,10 +521,10 @@ var BlockServiceADFWriteProvider = /*#__PURE__*/function () {
332
521
  }, {
333
522
  key: "deleteData",
334
523
  value: function () {
335
- var _deleteData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(resourceId) {
524
+ var _deleteData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(resourceId) {
336
525
  var blockAri;
337
- return _regeneratorRuntime.wrap(function _callee5$(_context5) {
338
- while (1) switch (_context5.prev = _context5.next) {
526
+ return _regeneratorRuntime.wrap(function _callee6$(_context6) {
527
+ while (1) switch (_context6.prev = _context6.next) {
339
528
  case 0:
340
529
  blockAri = generateBlockAri({
341
530
  cloudId: this.cloudId,
@@ -343,51 +532,51 @@ var BlockServiceADFWriteProvider = /*#__PURE__*/function () {
343
532
  product: this.product,
344
533
  resourceId: resourceId
345
534
  });
346
- _context5.prev = 1;
347
- _context5.next = 4;
535
+ _context6.prev = 1;
536
+ _context6.next = 4;
348
537
  return deleteSyncedBlock({
349
538
  blockAri: blockAri
350
539
  });
351
540
  case 4:
352
- return _context5.abrupt("return", {
541
+ return _context6.abrupt("return", {
353
542
  resourceId: resourceId,
354
543
  success: true,
355
544
  error: undefined
356
545
  });
357
546
  case 7:
358
- _context5.prev = 7;
359
- _context5.t0 = _context5["catch"](1);
360
- if (!(_context5.t0 instanceof BlockError)) {
361
- _context5.next = 13;
547
+ _context6.prev = 7;
548
+ _context6.t0 = _context6["catch"](1);
549
+ if (!(_context6.t0 instanceof BlockError)) {
550
+ _context6.next = 13;
362
551
  break;
363
552
  }
364
- if (!(_context5.t0.status === 404)) {
365
- _context5.next = 12;
553
+ if (!(_context6.t0.status === 404)) {
554
+ _context6.next = 12;
366
555
  break;
367
556
  }
368
- return _context5.abrupt("return", {
557
+ return _context6.abrupt("return", {
369
558
  resourceId: resourceId,
370
559
  success: true
371
560
  });
372
561
  case 12:
373
- return _context5.abrupt("return", {
562
+ return _context6.abrupt("return", {
374
563
  resourceId: resourceId,
375
564
  success: false,
376
- error: mapBlockError(_context5.t0)
565
+ error: mapBlockError(_context6.t0)
377
566
  });
378
567
  case 13:
379
- return _context5.abrupt("return", {
568
+ return _context6.abrupt("return", {
380
569
  resourceId: resourceId,
381
570
  success: false,
382
- error: stringifyError(_context5.t0)
571
+ error: stringifyError(_context6.t0)
383
572
  });
384
573
  case 14:
385
574
  case "end":
386
- return _context5.stop();
575
+ return _context6.stop();
387
576
  }
388
- }, _callee5, this, [[1, 7]]);
577
+ }, _callee6, this, [[1, 7]]);
389
578
  }));
390
- function deleteData(_x5) {
579
+ function deleteData(_x6) {
391
580
  return _deleteData.apply(this, arguments);
392
581
  }
393
582
  return deleteData;
@@ -405,19 +594,19 @@ var BlockServiceADFWriteProvider = /*#__PURE__*/function () {
405
594
  }, {
406
595
  key: "updateReferenceData",
407
596
  value: function () {
408
- var _updateReferenceData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(blocks, noContent) {
409
- var _this = this;
410
- return _regeneratorRuntime.wrap(function _callee6$(_context6) {
411
- while (1) switch (_context6.prev = _context6.next) {
597
+ var _updateReferenceData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7(blocks, noContent) {
598
+ var _this2 = this;
599
+ return _regeneratorRuntime.wrap(function _callee7$(_context7) {
600
+ while (1) switch (_context7.prev = _context7.next) {
412
601
  case 0:
413
- _context6.prev = 0;
414
- _context6.next = 3;
602
+ _context7.prev = 0;
603
+ _context7.next = 3;
415
604
  return updateReferenceSyncedBlockOnDocument({
416
605
  documentAri: this.parentAri,
417
606
  blocks: blocks.map(function (block) {
418
607
  return {
419
608
  blockAri: generateBlockAriFromReference({
420
- cloudId: _this.cloudId,
609
+ cloudId: _this2.cloudId,
421
610
  resourceId: block.resourceId
422
611
  }),
423
612
  blockInstanceId: block.localId
@@ -426,32 +615,32 @@ var BlockServiceADFWriteProvider = /*#__PURE__*/function () {
426
615
  noContent: noContent
427
616
  });
428
617
  case 3:
429
- return _context6.abrupt("return", {
618
+ return _context7.abrupt("return", {
430
619
  success: true
431
620
  });
432
621
  case 6:
433
- _context6.prev = 6;
434
- _context6.t0 = _context6["catch"](0);
435
- if (!(_context6.t0 instanceof BlockError)) {
436
- _context6.next = 10;
622
+ _context7.prev = 6;
623
+ _context7.t0 = _context7["catch"](0);
624
+ if (!(_context7.t0 instanceof BlockError)) {
625
+ _context7.next = 10;
437
626
  break;
438
627
  }
439
- return _context6.abrupt("return", {
628
+ return _context7.abrupt("return", {
440
629
  success: false,
441
- error: mapBlockError(_context6.t0)
630
+ error: mapBlockError(_context7.t0)
442
631
  });
443
632
  case 10:
444
- return _context6.abrupt("return", {
633
+ return _context7.abrupt("return", {
445
634
  success: false,
446
- error: stringifyError(_context6.t0)
635
+ error: stringifyError(_context7.t0)
447
636
  });
448
637
  case 11:
449
638
  case "end":
450
- return _context6.stop();
639
+ return _context7.stop();
451
640
  }
452
- }, _callee6, this, [[0, 6]]);
641
+ }, _callee7, this, [[0, 6]]);
453
642
  }));
454
- function updateReferenceData(_x6, _x7) {
643
+ function updateReferenceData(_x7, _x8) {
455
644
  return _updateReferenceData.apply(this, arguments);
456
645
  }
457
646
  return updateReferenceData;