@airtable/blocks 1.10.1 → 1.10.2-experimental-640bd10-20220211

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 (74) hide show
  1. package/CHANGELOG.md +5 -1
  2. package/dist/cjs/error_utils.js +44 -2
  3. package/dist/cjs/models/grouped_record_query_result.js +5 -14
  4. package/dist/cjs/models/linked_records_query_result.js +78 -27
  5. package/dist/cjs/models/mutations.js +18 -162
  6. package/dist/cjs/models/query_manager.js +328 -0
  7. package/dist/cjs/models/record.js +310 -55
  8. package/dist/cjs/models/record_query_result.js +4 -1
  9. package/dist/cjs/models/record_store.js +557 -765
  10. package/dist/cjs/models/table.js +6 -6
  11. package/dist/cjs/models/table_or_view_query_result.js +526 -419
  12. package/dist/cjs/models/view_data_store.js +255 -295
  13. package/dist/cjs/private_utils.js +40 -0
  14. package/dist/cjs/sdk.js +12 -2
  15. package/dist/cjs/testing/abstract_mock_airtable_interface.js +57 -11
  16. package/dist/cjs/testing/fixture_data.js +268 -0
  17. package/dist/cjs/testing/mock_base_data_stores.js +876 -0
  18. package/dist/cjs/types/airtable_interface.js +17 -2
  19. package/dist/cjs/types/block_query_spec.js +85 -0
  20. package/dist/cjs/ui/use_records.js +5 -1
  21. package/dist/cjs/unstable_testing_utils.js +55 -1
  22. package/dist/cjs/watchable.js +15 -1
  23. package/dist/types/src/error_utils.d.ts +6 -0
  24. package/dist/types/src/error_utils.d.ts.map +1 -1
  25. package/dist/types/src/models/grouped_record_query_result.d.ts +3 -3
  26. package/dist/types/src/models/grouped_record_query_result.d.ts.map +1 -1
  27. package/dist/types/src/models/linked_records_query_result.d.ts.map +1 -1
  28. package/dist/types/src/models/mutations.d.ts.map +1 -1
  29. package/dist/types/src/models/query_manager.d.ts +2 -0
  30. package/dist/types/src/models/query_manager.d.ts.map +1 -0
  31. package/dist/types/src/models/record.d.ts +12 -3
  32. package/dist/types/src/models/record.d.ts.map +1 -1
  33. package/dist/types/src/models/record_query_result.d.ts +3 -2
  34. package/dist/types/src/models/record_query_result.d.ts.map +1 -1
  35. package/dist/types/src/models/record_store.d.ts.map +1 -1
  36. package/dist/types/src/models/table_or_view_query_result.d.ts +3 -5
  37. package/dist/types/src/models/table_or_view_query_result.d.ts.map +1 -1
  38. package/dist/types/src/models/view_data_store.d.ts +0 -1
  39. package/dist/types/src/models/view_data_store.d.ts.map +1 -1
  40. package/dist/types/src/models/view_metadata_query_result.d.ts +1 -1
  41. package/dist/types/src/models/view_metadata_query_result.d.ts.map +1 -1
  42. package/dist/types/src/private_utils.d.ts +24 -1
  43. package/dist/types/src/private_utils.d.ts.map +1 -1
  44. package/dist/types/src/sdk.d.ts.map +1 -1
  45. package/dist/types/src/testing/abstract_mock_airtable_interface.d.ts +11 -11
  46. package/dist/types/src/testing/abstract_mock_airtable_interface.d.ts.map +1 -1
  47. package/dist/types/{test/airtable_interface_mocks → src/testing}/fixture_data.d.ts +42 -19
  48. package/dist/types/src/testing/fixture_data.d.ts.map +1 -0
  49. package/dist/types/src/testing/mock_base_data_stores.d.ts +55 -0
  50. package/dist/types/src/testing/mock_base_data_stores.d.ts.map +1 -0
  51. package/dist/types/src/types/airtable_interface.d.ts +59 -20
  52. package/dist/types/src/types/airtable_interface.d.ts.map +1 -1
  53. package/dist/types/src/types/block_query_spec.d.ts +139 -0
  54. package/dist/types/src/types/block_query_spec.d.ts.map +1 -0
  55. package/dist/types/src/types/table.d.ts +0 -2
  56. package/dist/types/src/types/table.d.ts.map +1 -1
  57. package/dist/types/src/types/view.d.ts +3 -8
  58. package/dist/types/src/types/view.d.ts.map +1 -1
  59. package/dist/types/src/ui/record_card.d.ts +1 -1
  60. package/dist/types/src/unstable_testing_utils.d.ts +4 -1
  61. package/dist/types/src/unstable_testing_utils.d.ts.map +1 -1
  62. package/dist/types/src/watchable.d.ts.map +1 -1
  63. package/dist/types/test/airtable_interface_mocks/linked_records.d.ts +1 -1
  64. package/dist/types/test/airtable_interface_mocks/linked_records.d.ts.map +1 -1
  65. package/dist/types/test/airtable_interface_mocks/mock_airtable_interface.d.ts +19 -12
  66. package/dist/types/test/airtable_interface_mocks/mock_airtable_interface.d.ts.map +1 -1
  67. package/dist/types/test/airtable_interface_mocks/project_tracker.d.ts +1 -1
  68. package/dist/types/test/airtable_interface_mocks/project_tracker.d.ts.map +1 -1
  69. package/dist/types/test/test_helpers.d.ts +2 -0
  70. package/dist/types/test/test_helpers.d.ts.map +1 -1
  71. package/dist/types/test/testing/fixture_data.test.d.ts +2 -0
  72. package/dist/types/test/testing/fixture_data.test.d.ts.map +1 -0
  73. package/package.json +2 -1
  74. package/dist/types/test/airtable_interface_mocks/fixture_data.d.ts.map +0 -1
package/CHANGELOG.md CHANGED
@@ -9,10 +9,14 @@ Not every commit needs to result in a change to this file (e.g. docs and chore c
9
9
  commit that affects the code in a way that consumers might care about should include edits to the
10
10
  'Unreleased' section though. Breaking changes should be prefixed with `**BREAKING:**`.
11
11
 
12
- ## [Unreleased](https://github.com/airtable/blocks/compare/@airtable/blocks@1.10.1...HEAD)
12
+ ## [Unreleased](https://github.com/airtable/blocks/compare/@airtable/blocks@1.10.2...HEAD)
13
13
 
14
14
  No changes.
15
15
 
16
+ ## [1.10.2](https://github.com/airtable/blocks/compare/@airtable/blocks@1.10.1...@airtable/blocks@1.10.2) - 2022-01-25
17
+
18
+ - Rare invariant failure addressed
19
+
16
20
  ## [1.10.1](https://github.com/airtable/blocks/compare/@airtable/blocks@1.10.0...@airtable/blocks@1.10.1) - 2021-12-22
17
21
 
18
22
  - Update examples for table, view and field URLs.
@@ -1,13 +1,19 @@
1
1
  "use strict";
2
2
 
3
+ require("core-js/modules/es.array.iterator");
4
+
3
5
  require("core-js/modules/es.string.replace");
4
6
 
7
+ require("core-js/modules/web.dom-collections.iterator");
8
+
5
9
  Object.defineProperty(exports, "__esModule", {
6
10
  value: true
7
11
  });
8
12
  exports.spawnError = spawnError;
13
+ exports.logErrorToRollbar = logErrorToRollbar;
9
14
  exports.invariant = invariant;
10
15
  exports.spawnUnknownSwitchCaseError = spawnUnknownSwitchCaseError;
16
+ exports.spawnExhaustiveSwitchError = spawnExhaustiveSwitchError;
11
17
  exports.spawnAbstractMethodError = spawnAbstractMethodError;
12
18
 
13
19
  // If errorOriginFn is specified, all frames above and including the call to errorOriginFn
@@ -52,6 +58,26 @@ function spawnError(errorMessageFormat) {
52
58
  }
53
59
 
54
60
  return spawnErrorWithOriginOmittedFromStackTrace(errorMessageFormat, errorMessageArgs, spawnError);
61
+ } // istanbul ignore next
62
+
63
+ /**
64
+ * Logs an error to Rollbar
65
+ *
66
+ * @hidden
67
+ */
68
+
69
+
70
+ function logErrorToRollbar(errorMessageFormat) {
71
+ // See this comment for how to log via Rollbar: https://github.com/Hyperbase/hyperbase/blob/009dcd1dc4c5204277c2939e7f61dfce74535f30/client/run_block_frame.tsx#L548
72
+ var rollbar = window.Rollbar;
73
+
74
+ if (rollbar === null || rollbar === void 0 ? void 0 : rollbar.warn) {
75
+ for (var _len2 = arguments.length, errorMessageArgs = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
76
+ errorMessageArgs[_key2 - 1] = arguments[_key2];
77
+ }
78
+
79
+ rollbar.warn(spawnError(errorMessageFormat, ...errorMessageArgs));
80
+ }
55
81
  }
56
82
  /**
57
83
  * An alternative to facebook's invariant that's safe to use with base data
@@ -62,8 +88,8 @@ function spawnError(errorMessageFormat) {
62
88
 
63
89
  function invariant(condition, errorMessageFormat) {
64
90
  if (!condition) {
65
- for (var _len2 = arguments.length, errorMessageArgs = new Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) {
66
- errorMessageArgs[_key2 - 2] = arguments[_key2];
91
+ for (var _len3 = arguments.length, errorMessageArgs = new Array(_len3 > 2 ? _len3 - 2 : 0), _key3 = 2; _key3 < _len3; _key3++) {
92
+ errorMessageArgs[_key3 - 2] = arguments[_key3];
67
93
  }
68
94
 
69
95
  throw spawnErrorWithOriginOmittedFromStackTrace(errorMessageFormat, errorMessageArgs, invariant);
@@ -79,6 +105,22 @@ function spawnUnknownSwitchCaseError(valueDescription, providedValue, key) {
79
105
  var providedValueKeyString = providedValueKey !== null && providedValueKey !== undefined ? providedValueKey : 'null';
80
106
  return spawnErrorWithOriginOmittedFromStackTrace('Unknown value %s for %s', [providedValueKeyString, valueDescription], spawnUnknownSwitchCaseError);
81
107
  }
108
+ /**
109
+ * Forces TypeScript to prove that calling this function is impossible at a
110
+ * type level by accepting `never`. In the unlikely case this function is
111
+ * called we infer a useful error message.
112
+ *
113
+ * @internal
114
+ */
115
+
116
+
117
+ function spawnExhaustiveSwitchError(impossibleValue) {
118
+ if (impossibleValue === null) {
119
+ return spawnErrorWithOriginOmittedFromStackTrace('Unexpected null in exhaustive switch', undefined, spawnExhaustiveSwitchError);
120
+ } else {
121
+ return spawnErrorWithOriginOmittedFromStackTrace("Unexpected %s in exhaustive switch", [typeof impossibleValue], spawnExhaustiveSwitchError);
122
+ }
123
+ }
82
124
  /**
83
125
  * @internal
84
126
  */
@@ -245,19 +245,13 @@ function (_RecordQueryResult) {
245
245
  while (1) {
246
246
  switch (_context2.prev = _context2.next) {
247
247
  case 0:
248
- this._parentQueryResult.__groupedRecordQueryResultPool.registerObjectForReuseStrong(this); // Ensure we invalidate our memoized computed recordIds whenever a relevant hook changes
249
- // TODO: (SeanKeenan) At the moment this should never be relevant, because groups are recreated
250
- // anytime the groups change - but this is how it should work once groups persist AND
251
- // watching recordIds only changes if records in this group change.
252
- // In the meantime this does ensure that a deleted GroupedRecordQuery with stale recordIds
253
- // doesn't return the cached array.
248
+ // TODO: This entire class assumes it is torn down and re-created by the parent whenever
249
+ // a change to the group is made.
250
+ this._parentQueryResult.__groupedRecordQueryResultPool.registerObjectForReuseStrong(this);
254
251
 
255
-
256
- this.watch(['recordIds', 'groups', 'groupLevels'], this._invalidateComputedRecordIds, this);
257
- this.watch(['recordIds'], this._invalidateRecordIdsSet, this);
258
252
  return _context2.abrupt("return", this._getChangedKeysOnLoad());
259
253
 
260
- case 4:
254
+ case 2:
261
255
  case "end":
262
256
  return _context2.stop();
263
257
  }
@@ -269,10 +263,7 @@ function (_RecordQueryResult) {
269
263
  }, {
270
264
  key: "_unloadData",
271
265
  value: function _unloadData() {
272
- // Ensure we invalidate our memoized computed recordIds whenever a relevant hook changes
273
- this.unwatch(['recordIds', 'groups', 'groupLevels'], this._invalidateComputedRecordIds, this);
274
- this.unwatch(['recordIds'], this._invalidateRecordIdsSet, this); // Invalidate both of the caches, as this object can no longer be accessed
275
-
266
+ // Invalidate both of the caches, as this object can no longer be accessed
276
267
  this._invalidateComputedRecordIds();
277
268
 
278
269
  this._invalidateRecordIdsSet();
@@ -29,6 +29,8 @@ Object.defineProperty(exports, "__esModule", {
29
29
  });
30
30
  exports.default = exports.getLinkedTableId = void 0;
31
31
 
32
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
33
+
32
34
  var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
33
35
 
34
36
  require("regenerator-runtime/runtime");
@@ -53,8 +55,14 @@ var _field = require("../types/field");
53
55
 
54
56
  var _error_utils = require("../error_utils");
55
57
 
58
+ var _block_query_spec = require("../types/block_query_spec");
59
+
60
+ var _airtable_interface = require("../types/airtable_interface");
61
+
56
62
  var _record_query_result = _interopRequireDefault(require("./record_query_result"));
57
63
 
64
+ var _record_store = require("./record_store");
65
+
58
66
  /** @module @airtable/blocks/models: RecordQueryResult */
59
67
 
60
68
  /** */
@@ -118,6 +126,8 @@ function (_RecordQueryResult) {
118
126
 
119
127
  /** @internal */
120
128
 
129
+ /** @internal */
130
+
121
131
  /** @internal */
122
132
  function LinkedRecordsQueryResult(record, field, normalizedOpts, sdk) {
123
133
  var _this;
@@ -134,6 +144,7 @@ function (_RecordQueryResult) {
134
144
  (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "_computedRecordIdsSet", null);
135
145
  (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "_computedFilteredSortedRecordIds", null);
136
146
  (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "_cellValueChangeHandlerByFieldId", {});
147
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "_recordStoreQueryId", null);
137
148
  (0, _error_utils.invariant)(record.parentTable === field.parentTable, 'record and field must belong to the same table');
138
149
  _this._record = record;
139
150
  _this._field = field;
@@ -279,7 +290,7 @@ function (_RecordQueryResult) {
279
290
  }, {
280
291
  key: "_loadDataAsync",
281
292
  value: function _loadDataAsync() {
282
- var initiallyLoaded, changedKeys, fieldIds, _iteratorNormalCompletion3, _didIteratorError3, _iteratorError3, _iterator3, _step3, fieldId;
293
+ var initiallyLoaded, _ref, _ref2, recordStoreQueryId, changedKeys, fieldIds, _iteratorNormalCompletion3, _didIteratorError3, _iteratorError3, _iterator3, _step3, fieldId;
283
294
 
284
295
  return _regenerator.default.async(function _loadDataAsync$(_context2) {
285
296
  while (1) {
@@ -291,11 +302,21 @@ function (_RecordQueryResult) {
291
302
 
292
303
  this._watchLinkedQueryResult();
293
304
 
294
- initiallyLoaded = this._linkedQueryResult.isDataLoaded;
305
+ initiallyLoaded = this._linkedQueryResult.isDataLoaded; // https://airtable.com/appahuJQw7qfQTBBU/tblSbpimM8Spp9txp/viweAFIus3MhU9Gxa/recNjFYJpeV23LPhH?blocks=hide
306
+ // TODO: (#proj-blocks-sdk-record-limits) Currently queries all cell values in a table
307
+ // when loading linked record data. Must add a LinkedRecord query type in the future.
308
+ // Since _loadDataAsync can only be called once, this recordStoreQueryId is only set once,
309
+ // although it is guaranteed to be stable if needed (so long as this._field.id is stable)
310
+
295
311
  _context2.next = 6;
296
- return _regenerator.default.awrap(Promise.all([this._sdk.base.__getRecordStore(this._record.parentTable.id).loadCellValuesInFieldIdsAsync([this._field.id]), this._linkedQueryResult.loadDataAsync(), this._loadRecordColorsAsync()]));
312
+ return _regenerator.default.awrap(Promise.all([this._sdk.base.__getRecordStore(this._record.parentTable.id).loadAllCellValuesInFieldIdsAsync([this._field.id]), this._linkedQueryResult.loadDataAsync(), this._loadRecordColorsAsync()]));
297
313
 
298
314
  case 6:
315
+ _ref = _context2.sent;
316
+ _ref2 = (0, _slicedToArray2.default)(_ref, 1);
317
+ recordStoreQueryId = _ref2[0];
318
+ this._recordStoreQueryId = recordStoreQueryId;
319
+
299
320
  this._invalidateComputedData();
300
321
 
301
322
  changedKeys = ['records', 'recordIds', 'recordColors']; // If the linked query result was not initially loaded, then the
@@ -311,55 +332,55 @@ function (_RecordQueryResult) {
311
332
  _iteratorNormalCompletion3 = true;
312
333
  _didIteratorError3 = false;
313
334
  _iteratorError3 = undefined;
314
- _context2.prev = 13;
335
+ _context2.prev = 17;
315
336
 
316
337
  for (_iterator3 = fieldIds[Symbol.iterator](); !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
317
338
  fieldId = _step3.value;
318
339
  changedKeys.push(_record_query_result.default.WatchableCellValuesInFieldKeyPrefix + fieldId);
319
340
  }
320
341
 
321
- _context2.next = 21;
342
+ _context2.next = 25;
322
343
  break;
323
344
 
324
- case 17:
325
- _context2.prev = 17;
326
- _context2.t0 = _context2["catch"](13);
345
+ case 21:
346
+ _context2.prev = 21;
347
+ _context2.t0 = _context2["catch"](17);
327
348
  _didIteratorError3 = true;
328
349
  _iteratorError3 = _context2.t0;
329
350
 
330
- case 21:
331
- _context2.prev = 21;
332
- _context2.prev = 22;
351
+ case 25:
352
+ _context2.prev = 25;
353
+ _context2.prev = 26;
333
354
 
334
355
  if (!_iteratorNormalCompletion3 && _iterator3.return != null) {
335
356
  _iterator3.return();
336
357
  }
337
358
 
338
- case 24:
339
- _context2.prev = 24;
359
+ case 28:
360
+ _context2.prev = 28;
340
361
 
341
362
  if (!_didIteratorError3) {
342
- _context2.next = 27;
363
+ _context2.next = 31;
343
364
  break;
344
365
  }
345
366
 
346
367
  throw _iteratorError3;
347
368
 
348
- case 27:
349
- return _context2.finish(24);
369
+ case 31:
370
+ return _context2.finish(28);
350
371
 
351
- case 28:
352
- return _context2.finish(21);
372
+ case 32:
373
+ return _context2.finish(25);
353
374
 
354
- case 29:
375
+ case 33:
355
376
  return _context2.abrupt("return", changedKeys);
356
377
 
357
- case 30:
378
+ case 34:
358
379
  case "end":
359
380
  return _context2.stop();
360
381
  }
361
382
  }
362
- }, null, this, [[13, 17, 21, 29], [22,, 24, 28]]);
383
+ }, null, this, [[17, 21, 25, 33], [26,, 28, 32]]);
363
384
  }
364
385
  /** @internal */
365
386
 
@@ -376,7 +397,9 @@ function (_RecordQueryResult) {
376
397
 
377
398
  this._unwatchLinkedQueryResult();
378
399
 
379
- this._originRecordStore.unloadCellValuesInFieldIds([this._field.id]);
400
+ (0, _error_utils.invariant)(this._recordStoreQueryId, 'Unsubscribing from linked record record store without queryId');
401
+
402
+ this._originRecordStore.unloadCellValuesForQueryIdsThatAreSubscribedToAllCells([this._recordStoreQueryId]);
380
403
 
381
404
  this._linkedQueryResult.unloadData();
382
405
 
@@ -448,7 +471,13 @@ function (_RecordQueryResult) {
448
471
  // result
449
472
 
450
473
 
451
- this._originRecordStore.watch('recordIds', this._onOriginRecordsChange, this); // if the linked field in the origin table is deleted, we need to
474
+ this._originRecordStore.watchWithRecordQueryResult({
475
+ priority: _airtable_interface.BlockQueryCallbackPriority.SDK,
476
+ recordQueryResult: this,
477
+ keys: _record_store.WatchableRecordStoreKeys.recordIds,
478
+ callbackForRegistration: this._onOriginRecordsChange,
479
+ context: this
480
+ }); // if the linked field in the origin table is deleted, we need to
452
481
  // invalidate this result
453
482
 
454
483
 
@@ -592,11 +621,12 @@ function (_RecordQueryResult) {
592
621
  if (Array.isArray(recordIds)) {
593
622
  var recordIdsSet = this._getOrGenerateRecordIdsSet();
594
623
 
595
- var filteredRecordIds = recordIds.filter(id => typeof id === 'string' && recordIdsSet[id] === true);
624
+ var filteredRecordIds = recordIds.filter(id => typeof id === 'string' && recordIdsSet[id] === true); // There should always be a filteredRecordIds found for this query
625
+ // type - not finding any is a fundamental mistake in our query engine
596
626
 
597
- if (filteredRecordIds.length) {
598
- this._onChange(_record_query_result.default.WatchableCellValuesInFieldKeyPrefix + fieldId, filteredRecordIds);
599
- }
627
+ (0, _error_utils.invariant)(filteredRecordIds.length, 'Filtered record change on incorrect record, query engine issue');
628
+
629
+ this._onChange(_record_query_result.default.WatchableCellValuesInFieldKeyPrefix + fieldId, filteredRecordIds);
600
630
  } else {
601
631
  this._onChange(_record_query_result.default.WatchableCellValuesInFieldKeyPrefix + fieldId);
602
632
  }
@@ -776,6 +806,27 @@ function (_RecordQueryResult) {
776
806
  (0, _error_utils.invariant)(recordIdsSet, 'recordIdsSet must exist');
777
807
  return recordIdsSet;
778
808
  }
809
+ /**
810
+ * This allows a record query result to specify the source of the query
811
+ * eg: View, Table, Linked record when watching fields.
812
+ * This scopes the watch to those fields + rows in the query.
813
+ *
814
+ * @internal
815
+ */
816
+
817
+ }, {
818
+ key: "__constructQuerySpecForBlockFieldSelectionSpec",
819
+ value: function __constructQuerySpecForBlockFieldSelectionSpec(fieldSelection) {
820
+ // The origin tableId is always the one referred to here as we must watch the origin record for deletion
821
+ var originTableId = this._record.parentTable.id;
822
+ return {
823
+ sourceType: _block_query_spec.BlockQuerySourceType.TABLE,
824
+ sourceTableId: originTableId,
825
+ recordSelection: {
826
+ fieldSelection
827
+ }
828
+ };
829
+ }
779
830
  }, {
780
831
  key: "isValid",
781
832
  get: function get() {
@@ -6,18 +6,12 @@ require("core-js/modules/es.symbol");
6
6
 
7
7
  require("core-js/modules/es.symbol.description");
8
8
 
9
- require("core-js/modules/es.array.filter");
10
-
11
- require("core-js/modules/es.array.flat-map");
12
-
13
9
  require("core-js/modules/es.array.includes");
14
10
 
15
11
  require("core-js/modules/es.array.iterator");
16
12
 
17
13
  require("core-js/modules/es.array.map");
18
14
 
19
- require("core-js/modules/es.array.unscopables.flat-map");
20
-
21
15
  require("core-js/modules/es.object.to-string");
22
16
 
23
17
  require("core-js/modules/es.promise");
@@ -28,15 +22,11 @@ require("core-js/modules/es.string.includes");
28
22
 
29
23
  require("core-js/modules/web.dom-collections.iterator");
30
24
 
31
- require("core-js/modules/web.url.to-json");
32
-
33
25
  Object.defineProperty(exports, "__esModule", {
34
26
  value: true
35
27
  });
36
28
  exports.default = void 0;
37
29
 
38
- var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
39
-
40
30
  var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
41
31
 
42
32
  require("regenerator-runtime/runtime");
@@ -51,8 +41,6 @@ var _airtable_interface = require("../types/airtable_interface");
51
41
 
52
42
  var _mutations = require("../types/mutations");
53
43
 
54
- var _private_utils = require("../private_utils");
55
-
56
44
  var _error_utils = require("../error_utils");
57
45
 
58
46
  var _mutation_constants = require("./mutation_constants");
@@ -81,22 +69,18 @@ function () {
81
69
 
82
70
  /** @internal */
83
71
 
84
- /** @internal */
85
-
86
72
  /** @hidden */
87
- function Mutations(sdk, session, base, applyModelChanges, applyGlobalConfigUpdates) {
73
+ function Mutations(sdk, session, base, applyGlobalConfigUpdates) {
88
74
  (0, _classCallCheck2.default)(this, Mutations);
89
75
  (0, _defineProperty2.default)(this, "_airtableInterface", void 0);
90
76
  (0, _defineProperty2.default)(this, "_session", void 0);
91
77
  (0, _defineProperty2.default)(this, "_sdk", void 0);
92
78
  (0, _defineProperty2.default)(this, "_base", void 0);
93
- (0, _defineProperty2.default)(this, "_applyModelChanges", void 0);
94
79
  (0, _defineProperty2.default)(this, "_applyGlobalConfigUpdates", void 0);
95
80
  this._airtableInterface = sdk.__airtableInterface;
96
81
  this._session = session;
97
82
  this._sdk = sdk;
98
83
  this._base = base;
99
- this._applyModelChanges = applyModelChanges;
100
84
  this._applyGlobalConfigUpdates = applyGlobalConfigUpdates;
101
85
  }
102
86
  /** @hidden */
@@ -270,9 +254,12 @@ function () {
270
254
  try {
271
255
  for (var _iterator = records[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
272
256
  var record = _step.value;
273
- var existingRecord = null;
257
+ var existingRecord = null; // Note - if isSubscribedToAllRecordsInTable is true then we know the record
258
+ // doesn't exist (or is deleted) but otherwise we can issue a mutation to a record
259
+ // that does not exist, having to deal with the error thrown by PublicAirtableInterfaceFrontend
260
+ // TODO: (#proj-blocks-sdk-record-limits) Write tests around this behavior
274
261
 
275
- if (recordStore.isRecordMetadataLoaded) {
262
+ if (recordStore.isSubscribedToAllRecordsInTable || recordStore.isRecordLoaded(record.id)) {
276
263
  existingRecord = recordStore.getRecordByIdIfExists(record.id);
277
264
 
278
265
  if (!existingRecord) {
@@ -294,7 +281,7 @@ function () {
294
281
  checkedFieldIds.add(fieldId);
295
282
  }
296
283
 
297
- if (existingRecord && recordStore.areCellValuesLoadedForFieldId(fieldId)) {
284
+ if (existingRecord && recordStore.isRecordCellValueLoadedForFieldId(record.id, fieldId)) {
298
285
  var validationResult = this._airtableInterface.fieldTypeProvider.validateCellValueForUpdate(appInterface, record.cellValuesByFieldId[fieldId], existingRecord._getRawCellValue(field), field._data);
299
286
 
300
287
  if (!validationResult.isValid) {
@@ -332,9 +319,15 @@ function () {
332
319
  throw (0, _error_utils.spawnError)("Can't delete records: No table with id %s exists", _tableId);
333
320
  }
334
321
 
335
- var _recordStore = this._base.__getRecordStore(_tableId);
322
+ var _recordStore = this._base.__getRecordStore(_tableId); // TODO: (#proj-blocks-sdk-record-limits) We substantially weaken our check here
323
+ // because we can only be sure if the record exists inside the SDK if we've loaded
324
+ // all records. It is possible to change this logic to ensure we don't double-delete
325
+ // records by caching previously deleted records (if the delete is undone, but
326
+ // we're not watching the record be re-created from the undo we would have to fail
327
+ // the delete if we detect double deletion). TODO to add tests around this behavior.
328
+
336
329
 
337
- if (_recordStore.isRecordMetadataLoaded) {
330
+ if (_recordStore.isSubscribedToAllRecordsInTable) {
338
331
  var _iteratorNormalCompletion2 = true;
339
332
  var _didIteratorError2 = false;
340
333
  var _iteratorError2 = undefined;
@@ -672,150 +665,13 @@ function () {
672
665
  this._applyGlobalConfigUpdates(mutation.updates);
673
666
 
674
667
  return true;
675
- }
676
-
677
- var modelChanges = this._getOptimisticModelChangesForMutation(mutation);
668
+ } // https://airtable.com/appahuJQw7qfQTBBU/tblSbpimM8Spp9txp/viweAFIus3MhU9Gxa/recHOckY4V9QmM6JV?blocks=hide
669
+ // TODO: (#proj-blocks-sdk-record-limits) Fix this in a future stacked diff where optimistic
670
+ // updates are re-enabled https://docs.google.com/document/d/1CVZ4ZoPWEtpzKq_9cRLASGwgY71WI4nl6RVvs8S7Ubw/edit#
678
671
 
679
- if (modelChanges.length > 0) {
680
- this._applyModelChanges(modelChanges);
681
-
682
- return true;
683
- }
684
672
 
685
673
  return false;
686
674
  }
687
- /** @internal */
688
-
689
- }, {
690
- key: "_getOptimisticModelChangesForMutation",
691
- value: function _getOptimisticModelChangesForMutation(mutation) {
692
- switch (mutation.type) {
693
- case _mutations.MutationTypes.SET_MULTIPLE_RECORDS_CELL_VALUES:
694
- {
695
- var tableId = mutation.tableId,
696
- records = mutation.records;
697
-
698
- var recordStore = this._base.__getRecordStore(tableId);
699
-
700
- return records.flatMap(record => Object.keys(record.cellValuesByFieldId).filter(fieldId => recordStore.areCellValuesLoadedForFieldId(fieldId)).map(fieldId => ({
701
- path: ['tablesById', tableId, 'recordsById', record.id, 'cellValuesByFieldId', fieldId],
702
- value: record.cellValuesByFieldId[fieldId]
703
- })));
704
- }
705
-
706
- case _mutations.MutationTypes.DELETE_MULTIPLE_RECORDS:
707
- {
708
- var _tableId7 = mutation.tableId,
709
- recordIds = mutation.recordIds;
710
-
711
- var _recordStore2 = this._base.__getRecordStore(_tableId7);
712
-
713
- if (!_recordStore2.isRecordMetadataLoaded) {
714
- return [];
715
- }
716
-
717
- return [...recordIds.map(recordId => ({
718
- path: ['tablesById', _tableId7, 'recordsById', recordId],
719
- value: undefined
720
- })), ...this._base.getTableById(_tableId7).views.flatMap(view => {
721
- var viewDataStore = _recordStore2.getViewDataStore(view.id);
722
-
723
- if (!viewDataStore.isDataLoaded) {
724
- return [];
725
- }
726
-
727
- return viewDataStore.__generateChangesForParentTableDeleteMultipleRecords(recordIds);
728
- })];
729
- }
730
-
731
- case _mutations.MutationTypes.CREATE_MULTIPLE_RECORDS:
732
- {
733
- var _tableId8 = mutation.tableId,
734
- _records2 = mutation.records;
735
-
736
- var _recordStore3 = this._base.__getRecordStore(_tableId8);
737
-
738
- if (!_recordStore3.isRecordMetadataLoaded) {
739
- return [];
740
- }
741
-
742
- return [..._records2.map(record => {
743
- // Only apply optimistic changes for fields that are loaded
744
- var filteredCellValuesByFieldId = {};
745
- var _iteratorNormalCompletion5 = true;
746
- var _didIteratorError5 = false;
747
- var _iteratorError5 = undefined;
748
-
749
- try {
750
- for (var _iterator5 = (0, _private_utils.entries)(record.cellValuesByFieldId)[Symbol.iterator](), _step5; !(_iteratorNormalCompletion5 = (_step5 = _iterator5.next()).done); _iteratorNormalCompletion5 = true) {
751
- var _step5$value = (0, _slicedToArray2.default)(_step5.value, 2),
752
- fieldId = _step5$value[0],
753
- cellValue = _step5$value[1];
754
-
755
- if (_recordStore3.areCellValuesLoadedForFieldId(fieldId)) {
756
- filteredCellValuesByFieldId[fieldId] = cellValue;
757
- }
758
- }
759
- } catch (err) {
760
- _didIteratorError5 = true;
761
- _iteratorError5 = err;
762
- } finally {
763
- try {
764
- if (!_iteratorNormalCompletion5 && _iterator5.return != null) {
765
- _iterator5.return();
766
- }
767
- } finally {
768
- if (_didIteratorError5) {
769
- throw _iteratorError5;
770
- }
771
- }
772
- }
773
-
774
- return {
775
- path: ['tablesById', _tableId8, 'recordsById', record.id],
776
- value: {
777
- id: record.id,
778
- cellValuesByFieldId: filteredCellValuesByFieldId,
779
- commentCount: 0,
780
- createdTime: new Date().toJSON()
781
- }
782
- };
783
- }), ...this._base.getTableById(_tableId8).views.flatMap(view => {
784
- var viewDataStore = _recordStore3.getViewDataStore(view.id);
785
-
786
- if (!viewDataStore.isDataLoaded) {
787
- return [];
788
- }
789
-
790
- return viewDataStore.__generateChangesForParentTableAddMultipleRecords(_records2.map(record => record.id));
791
- })];
792
- }
793
- // The following branch is unreachable because this method's only
794
- // call site is preceded by an explicit guard for this condition.
795
- // istanbul ignore next
796
-
797
- case _mutations.MutationTypes.SET_MULTIPLE_GLOBAL_CONFIG_PATHS:
798
- {
799
- throw (0, _error_utils.spawnError)('attempting to generate model updates for SET_MULTIPLE_GLOBAL_CONFIG_PATH');
800
- }
801
-
802
- case _mutations.MutationTypes.CREATE_SINGLE_FIELD:
803
- case _mutations.MutationTypes.UPDATE_SINGLE_FIELD_CONFIG:
804
- case _mutations.MutationTypes.UPDATE_SINGLE_FIELD_DESCRIPTION:
805
- case _mutations.MutationTypes.UPDATE_VIEW_METADATA:
806
- case _mutations.MutationTypes.CREATE_SINGLE_TABLE:
807
- {
808
- // No optimistic updates for field, view metadata, or table mutations.
809
- return [];
810
- }
811
- // The following branch is unreachable because this method's only
812
- // call site is preceded by an explicit guard for this condition.
813
- // istanbul ignore next
814
-
815
- default:
816
- throw (0, _error_utils.spawnUnknownSwitchCaseError)('mutation type', mutation, 'type');
817
- }
818
- }
819
675
  }]);
820
676
  return Mutations;
821
677
  }();