@airtable/blocks 1.10.2-experimental-640bd10-20220211 → 1.11.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 (85) hide show
  1. package/CHANGELOG.md +12 -1
  2. package/dist/cjs/error_utils.js +9 -34
  3. package/dist/cjs/models/base.js +15 -0
  4. package/dist/cjs/models/field.js +99 -4
  5. package/dist/cjs/models/grouped_record_query_result.js +14 -5
  6. package/dist/cjs/models/linked_records_query_result.js +44 -86
  7. package/dist/cjs/models/mutations.js +234 -53
  8. package/dist/cjs/models/record.js +55 -310
  9. package/dist/cjs/models/record_query_result.js +1 -4
  10. package/dist/cjs/models/record_store.js +779 -557
  11. package/dist/cjs/models/table.js +6 -6
  12. package/dist/cjs/models/table_or_view_query_result.js +419 -526
  13. package/dist/cjs/models/view_data_store.js +295 -255
  14. package/dist/cjs/private_utils.js +0 -40
  15. package/dist/cjs/sdk.js +2 -12
  16. package/dist/cjs/testing/abstract_mock_airtable_interface.js +11 -57
  17. package/dist/cjs/types/airtable_interface.js +2 -17
  18. package/dist/cjs/types/mutations.js +1 -0
  19. package/dist/cjs/ui/use_records.js +1 -5
  20. package/dist/cjs/unstable_testing_utils.js +1 -55
  21. package/dist/cjs/watchable.js +1 -15
  22. package/dist/types/src/error_utils.d.ts +4 -2
  23. package/dist/types/src/error_utils.d.ts.map +1 -1
  24. package/dist/types/src/models/base.d.ts +10 -0
  25. package/dist/types/src/models/base.d.ts.map +1 -1
  26. package/dist/types/src/models/field.d.ts +58 -0
  27. package/dist/types/src/models/field.d.ts.map +1 -1
  28. package/dist/types/src/models/grouped_record_query_result.d.ts +3 -3
  29. package/dist/types/src/models/grouped_record_query_result.d.ts.map +1 -1
  30. package/dist/types/src/models/linked_records_query_result.d.ts.map +1 -1
  31. package/dist/types/src/models/mutations.d.ts.map +1 -1
  32. package/dist/types/src/models/record.d.ts +3 -12
  33. package/dist/types/src/models/record.d.ts.map +1 -1
  34. package/dist/types/src/models/record_query_result.d.ts +2 -3
  35. package/dist/types/src/models/record_query_result.d.ts.map +1 -1
  36. package/dist/types/src/models/record_store.d.ts.map +1 -1
  37. package/dist/types/src/models/table_or_view_query_result.d.ts +5 -3
  38. package/dist/types/src/models/table_or_view_query_result.d.ts.map +1 -1
  39. package/dist/types/src/models/view_data_store.d.ts +1 -0
  40. package/dist/types/src/models/view_data_store.d.ts.map +1 -1
  41. package/dist/types/src/models/view_metadata_query_result.d.ts +1 -1
  42. package/dist/types/src/models/view_metadata_query_result.d.ts.map +1 -1
  43. package/dist/types/src/private_utils.d.ts +1 -24
  44. package/dist/types/src/private_utils.d.ts.map +1 -1
  45. package/dist/types/src/sdk.d.ts.map +1 -1
  46. package/dist/types/src/testing/abstract_mock_airtable_interface.d.ts +11 -11
  47. package/dist/types/src/testing/abstract_mock_airtable_interface.d.ts.map +1 -1
  48. package/dist/types/src/types/airtable_interface.d.ts +20 -59
  49. package/dist/types/src/types/airtable_interface.d.ts.map +1 -1
  50. package/dist/types/src/types/base.d.ts +1 -0
  51. package/dist/types/src/types/base.d.ts.map +1 -1
  52. package/dist/types/src/types/mutations.d.ts +25 -2
  53. package/dist/types/src/types/mutations.d.ts.map +1 -1
  54. package/dist/types/src/types/table.d.ts +2 -0
  55. package/dist/types/src/types/table.d.ts.map +1 -1
  56. package/dist/types/src/types/view.d.ts +8 -3
  57. package/dist/types/src/types/view.d.ts.map +1 -1
  58. package/dist/types/src/ui/record_card.d.ts +1 -1
  59. package/dist/types/src/unstable_testing_utils.d.ts +1 -4
  60. package/dist/types/src/unstable_testing_utils.d.ts.map +1 -1
  61. package/dist/types/src/watchable.d.ts.map +1 -1
  62. package/dist/types/{src/testing → test/airtable_interface_mocks}/fixture_data.d.ts +19 -42
  63. package/dist/types/test/airtable_interface_mocks/fixture_data.d.ts.map +1 -0
  64. package/dist/types/test/airtable_interface_mocks/linked_records.d.ts +1 -1
  65. package/dist/types/test/airtable_interface_mocks/linked_records.d.ts.map +1 -1
  66. package/dist/types/test/airtable_interface_mocks/mock_airtable_interface.d.ts +12 -19
  67. package/dist/types/test/airtable_interface_mocks/mock_airtable_interface.d.ts.map +1 -1
  68. package/dist/types/test/airtable_interface_mocks/project_tracker.d.ts +1 -1
  69. package/dist/types/test/airtable_interface_mocks/project_tracker.d.ts.map +1 -1
  70. package/dist/types/test/test_helpers.d.ts +0 -2
  71. package/dist/types/test/test_helpers.d.ts.map +1 -1
  72. package/package.json +1 -2
  73. package/dist/cjs/models/query_manager.js +0 -328
  74. package/dist/cjs/testing/fixture_data.js +0 -268
  75. package/dist/cjs/testing/mock_base_data_stores.js +0 -876
  76. package/dist/cjs/types/block_query_spec.js +0 -85
  77. package/dist/types/src/models/query_manager.d.ts +0 -2
  78. package/dist/types/src/models/query_manager.d.ts.map +0 -1
  79. package/dist/types/src/testing/fixture_data.d.ts.map +0 -1
  80. package/dist/types/src/testing/mock_base_data_stores.d.ts +0 -55
  81. package/dist/types/src/testing/mock_base_data_stores.d.ts.map +0 -1
  82. package/dist/types/src/types/block_query_spec.d.ts +0 -139
  83. package/dist/types/src/types/block_query_spec.d.ts.map +0 -1
  84. package/dist/types/test/testing/fixture_data.test.d.ts +0 -2
  85. package/dist/types/test/testing/fixture_data.test.d.ts.map +0 -1
@@ -12,8 +12,6 @@ require("core-js/modules/es.array.concat");
12
12
 
13
13
  require("core-js/modules/es.array.filter");
14
14
 
15
- require("core-js/modules/es.array.includes");
16
-
17
15
  require("core-js/modules/es.array.iterator");
18
16
 
19
17
  require("core-js/modules/es.array.map");
@@ -26,8 +24,6 @@ require("core-js/modules/es.promise");
26
24
 
27
25
  require("core-js/modules/es.set");
28
26
 
29
- require("core-js/modules/es.string.includes");
30
-
31
27
  require("core-js/modules/es.string.starts-with");
32
28
 
33
29
  require("core-js/modules/web.dom-collections.for-each");
@@ -63,14 +59,8 @@ var _private_utils = require("../private_utils");
63
59
 
64
60
  var _error_utils = require("../error_utils");
65
61
 
66
- var _airtable_interface = require("../types/airtable_interface");
67
-
68
- var _block_query_spec = require("../types/block_query_spec");
69
-
70
62
  var _table = _interopRequireWildcard(require("./table"));
71
63
 
72
- var _view = _interopRequireDefault(require("./view"));
73
-
74
64
  var _record_query_result = _interopRequireDefault(require("./record_query_result"));
75
65
 
76
66
  var _record_coloring = require("./record_coloring");
@@ -107,17 +97,6 @@ function (_RecordQueryResult) {
107
97
 
108
98
  /** @internal */
109
99
 
110
- /**
111
- * Tracks a unique ID for each model query that has been loaded.
112
- * Note that hyperbase may return a new model query ID even if the
113
- * query itself is identical to a previous one. Having these unique
114
- * IDs allows the SDK to maintain an accurate reference count of
115
- * all model loads. _loadedSourceModelQueryIds must only be updated
116
- * before unloading occurs.
117
- *
118
- * @internal
119
- */
120
-
121
100
  /** @internal */
122
101
 
123
102
  /** @internal */
@@ -145,6 +124,17 @@ function (_RecordQueryResult) {
145
124
  /** @internal */
146
125
  // lazily generated set of record ids
147
126
 
127
+ /** @internal */
128
+ // NOTE: when a cellValue key (cellValues or cellValuesInField:) is watched, we want
129
+ // to make sure we watch the associated key on the table. However, we need to make
130
+ // sure that we only watch the table once for each key. Otherwise, the callbacks
131
+ // for each key will get called more than once for each change event. This is because
132
+ // Watchable stores references to callbacks for each key, and on each _onChange event
133
+ // calls each callback for that key. If we watch the table more than once, then we'll
134
+ // call _onChange more than once, and each callback will be called more than once, which
135
+ // is undesirable. Instead, we'll store watch counts for each key to make sure we only
136
+ // watch the table once.
137
+
148
138
  /** @internal */
149
139
 
150
140
  /** @internal */
@@ -156,8 +146,7 @@ function (_RecordQueryResult) {
156
146
  (0, _classCallCheck2.default)(this, TableOrViewQueryResult);
157
147
  _this = (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(TableOrViewQueryResult).call(this, sdk, normalizedOpts));
158
148
  (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "_sourceModel", void 0);
159
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "_mostRecentSourceModelLoadedPromise", void 0);
160
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "_loadedSourceModelQueryIds", void 0);
149
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "_mostRecentSourceModelLoadPromise", void 0);
161
150
  (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "_table", void 0);
162
151
  (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "_fieldIdsSetToLoadOrNullIfAllFields", void 0);
163
152
  (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "_visList", void 0);
@@ -167,156 +156,10 @@ function (_RecordQueryResult) {
167
156
  (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "_orderedGroups", void 0);
168
157
  (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "_loadedGroupLevels", void 0);
169
158
  (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "_recordIdsSet", null);
159
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "_cellValueKeyWatchCounts", void 0);
170
160
  (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "__groupedRecordQueryResultPool", void 0);
171
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "_watchConfigByWatchableKey", {
172
- // Handles if this is a prefix
173
- [_record_query_result.default.WatchableCellValuesInFieldKeyPrefix]: (key, _ref) => {
174
- var callOnRecordStoreWithKey = _ref.callOnRecordStoreWithKey;
175
- var fieldId = key.substring(_record_query_result.default.WatchableCellValuesInFieldKeyPrefix.length);
176
-
177
- if (_this._fieldIdsSetToLoadOrNullIfAllFields && !(0, _private_utils.has)(_this._fieldIdsSetToLoadOrNullIfAllFields, fieldId)) {
178
- throw (0, _error_utils.spawnError)("Can't watch or unwatch field because it wasn't included in RecordQueryResult fields: %s", fieldId);
179
- }
180
-
181
- callOnRecordStoreWithKey(_record_query_result.default.WatchableCellValuesInFieldKeyPrefix + fieldId);
182
- },
183
- [_record_query_result.default.WatchableKeys.cellValues]: (key, _ref2) => {
184
- var callOnRecordStoreWithKey = _ref2.callOnRecordStoreWithKey;
185
-
186
- if (_this._fieldIdsSetToLoadOrNullIfAllFields) {
187
- for (var _i = 0, _Object$keys = Object.keys(_this._fieldIdsSetToLoadOrNullIfAllFields); _i < _Object$keys.length; _i++) {
188
- var fieldId = _Object$keys[_i];
189
- callOnRecordStoreWithKey(_record_query_result.default.WatchableCellValuesInFieldKeyPrefix + fieldId);
190
- }
191
- } else {
192
- callOnRecordStoreWithKey(_record_query_result.default.WatchableKeys.cellValues);
193
- }
194
- },
195
- [_record_query_result.default.WatchableKeys.groupLevels]: (key, _ref3) => {
196
- var callOnViewDataStoreWithKey = _ref3.callOnViewDataStoreWithKey;
197
- callOnViewDataStoreWithKey(_view_data_store.WatchableViewDataStoreKeys.groupLevels);
198
- },
199
- [_record_query_result.default.WatchableKeys.groups]: (key, _ref4) => {
200
- var callOnViewDataStoreWithKey = _ref4.callOnViewDataStoreWithKey;
201
- callOnViewDataStoreWithKey(_view_data_store.WatchableViewDataStoreKeys.groups);
202
- }
203
- });
204
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "_unloadDataAsync", () => {
205
- var viewDataStore, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, sort, field;
206
-
207
- return _regenerator.default.async(function _callee$(_context) {
208
- while (1) {
209
- switch (_context.prev = _context.next) {
210
- case 0:
211
- if (!_this._mostRecentSourceModelLoadedPromise) {
212
- _context.next = 3;
213
- break;
214
- }
215
-
216
- _context.next = 3;
217
- return _regenerator.default.awrap(_this._mostRecentSourceModelLoadedPromise);
218
-
219
- case 3:
220
- // Unload all queries that were subscribed to the entire query
221
- if (_this._sourceModel instanceof _table.default) {
222
- _this._recordStore.unloadCellValuesForQueryIdsThatAreSubscribedToAllCells(_this._loadedSourceModelQueryIds);
223
- } else {
224
- // Even if the view is deleted, we can still unsubscribe from the cells
225
- _this._recordStore.unloadViewDataStoreAndCellValuesWithQueryIds(_this._loadedSourceModelQueryIds);
226
- }
227
-
228
- _this._mostRecentSourceModelLoadedPromise = null;
229
-
230
- if (_this._sourceModel instanceof _table.default) {
231
- _this._recordStore.unwatch(_record_store.WatchableRecordStoreKeys.records, _this._onRecordsChanged, (0, _assertThisInitialized2.default)(_this));
232
- } else {
233
- if (!_this._sourceModel.isDeleted) {
234
- viewDataStore = _this._recordStore.getViewDataStore(_this._sourceModel.id);
235
- viewDataStore.unwatch(_view_data_store.WatchableViewDataStoreKeys.visibleRecords, _this._onRecordsChanged, (0, _assertThisInitialized2.default)(_this));
236
- viewDataStore.unwatch(_view_data_store.WatchableViewDataStoreKeys.groups, _this._onGroupsChanged, (0, _assertThisInitialized2.default)(_this));
237
- viewDataStore.unwatch(_view_data_store.WatchableViewDataStoreKeys.groupLevels, _this._onGroupLevelsChanged, (0, _assertThisInitialized2.default)(_this));
238
- }
239
- }
240
-
241
- _this._recordStore.unwatch(_this._cellValuesForSortWatchKeys, _this._onCellValuesForSortChanged, (0, _assertThisInitialized2.default)(_this));
242
-
243
- _this._recordStore.unwatch(_this._cellValuesForGroupWatchKeys, _this._onCellValuesForGroupChanged, (0, _assertThisInitialized2.default)(_this));
244
-
245
- _this._table.unwatch(_table.WatchableTableKeys.fields, _this._onTableFieldsChanged, (0, _assertThisInitialized2.default)(_this)); // If the table is deleted, can't call getFieldById on it below.
246
-
247
-
248
- if (!(!_this._table.isDeleted && _this._sorts)) {
249
- _context.next = 29;
250
- break;
251
- }
252
-
253
- _iteratorNormalCompletion = true;
254
- _didIteratorError = false;
255
- _iteratorError = undefined;
256
- _context.prev = 13;
257
-
258
- for (_iterator = _this._sorts[Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
259
- sort = _step.value;
260
- field = _this._table.getFieldByIdIfExists(sort.fieldId);
261
-
262
- if (field) {
263
- field.unwatch('type', _this._onFieldConfigChanged, (0, _assertThisInitialized2.default)(_this));
264
- field.unwatch('options', _this._onFieldConfigChanged, (0, _assertThisInitialized2.default)(_this));
265
- }
266
- }
267
-
268
- _context.next = 21;
269
- break;
270
-
271
- case 17:
272
- _context.prev = 17;
273
- _context.t0 = _context["catch"](13);
274
- _didIteratorError = true;
275
- _iteratorError = _context.t0;
276
-
277
- case 21:
278
- _context.prev = 21;
279
- _context.prev = 22;
280
-
281
- if (!_iteratorNormalCompletion && _iterator.return != null) {
282
- _iterator.return();
283
- }
284
-
285
- case 24:
286
- _context.prev = 24;
287
-
288
- if (!_didIteratorError) {
289
- _context.next = 27;
290
- break;
291
- }
292
-
293
- throw _iteratorError;
294
-
295
- case 27:
296
- return _context.finish(24);
297
-
298
- case 28:
299
- return _context.finish(21);
300
-
301
- case 29:
302
- _this._unloadOrderedGroupsIfNeeded();
303
-
304
- _this._visList = null;
305
- _this._orderedRecordIds = null;
306
- _this._recordIdsSet = null;
307
-
308
- _this._table.__tableOrViewQueryResultPool.unregisterObjectForReuseStrong((0, _assertThisInitialized2.default)(_this));
309
-
310
- case 34:
311
- case "end":
312
- return _context.stop();
313
- }
314
- }
315
- }, null, null, [[13, 17, 21, 29], [22,, 24, 28]]);
316
- });
317
161
  _this._sourceModel = sourceModel;
318
- _this._mostRecentSourceModelLoadedPromise = null;
319
- _this._loadedSourceModelQueryIds = [];
162
+ _this._mostRecentSourceModelLoadPromise = null;
320
163
  _this._table = normalizedOpts.table;
321
164
  var sorts = _this._normalizedOpts.sorts;
322
165
  _this._sorts = sorts !== null && sorts !== void 0 ? sorts : null; // TODO (SeanKeenan): Placeholder until we support groups from normalizedOpts
@@ -326,57 +169,58 @@ function (_RecordQueryResult) {
326
169
  _this._orderedRecordIds = null;
327
170
  _this._orderedGroups = null;
328
171
  _this._loadedGroupLevels = null;
172
+ _this._cellValueKeyWatchCounts = {};
329
173
  var fieldIdsSetToLoadOrNullIfAllFields = null;
330
174
 
331
175
  if (_this._normalizedOpts.fieldIdsOrNullIfAllFields) {
332
176
  fieldIdsSetToLoadOrNullIfAllFields = {};
333
- var _iteratorNormalCompletion2 = true;
334
- var _didIteratorError2 = false;
335
- var _iteratorError2 = undefined;
177
+ var _iteratorNormalCompletion = true;
178
+ var _didIteratorError = false;
179
+ var _iteratorError = undefined;
336
180
 
337
181
  try {
338
- for (var _iterator2 = _this._normalizedOpts.fieldIdsOrNullIfAllFields[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
339
- var fieldId = _step2.value;
182
+ for (var _iterator = _this._normalizedOpts.fieldIdsOrNullIfAllFields[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
183
+ var fieldId = _step.value;
340
184
  fieldIdsSetToLoadOrNullIfAllFields[fieldId] = true;
341
185
  } // Need to load data for fields we're sorting by, even if
342
186
  // they're not explicitly requested in the `fields` opt.
343
187
 
344
188
  } catch (err) {
345
- _didIteratorError2 = true;
346
- _iteratorError2 = err;
189
+ _didIteratorError = true;
190
+ _iteratorError = err;
347
191
  } finally {
348
192
  try {
349
- if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
350
- _iterator2.return();
193
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
194
+ _iterator.return();
351
195
  }
352
196
  } finally {
353
- if (_didIteratorError2) {
354
- throw _iteratorError2;
197
+ if (_didIteratorError) {
198
+ throw _iteratorError;
355
199
  }
356
200
  }
357
201
  }
358
202
 
359
203
  if (_this._sorts !== null) {
360
- var _iteratorNormalCompletion3 = true;
361
- var _didIteratorError3 = false;
362
- var _iteratorError3 = undefined;
204
+ var _iteratorNormalCompletion2 = true;
205
+ var _didIteratorError2 = false;
206
+ var _iteratorError2 = undefined;
363
207
 
364
208
  try {
365
- for (var _iterator3 = _this._sorts[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
366
- var sort = _step3.value;
209
+ for (var _iterator2 = _this._sorts[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
210
+ var sort = _step2.value;
367
211
  fieldIdsSetToLoadOrNullIfAllFields[sort.fieldId] = true;
368
212
  }
369
213
  } catch (err) {
370
- _didIteratorError3 = true;
371
- _iteratorError3 = err;
214
+ _didIteratorError2 = true;
215
+ _iteratorError2 = err;
372
216
  } finally {
373
217
  try {
374
- if (!_iteratorNormalCompletion3 && _iterator3.return != null) {
375
- _iterator3.return();
218
+ if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
219
+ _iterator2.return();
376
220
  }
377
221
  } finally {
378
- if (_didIteratorError3) {
379
- throw _iteratorError3;
222
+ if (_didIteratorError2) {
223
+ throw _iteratorError2;
380
224
  }
381
225
  }
382
226
  }
@@ -416,26 +260,26 @@ function (_RecordQueryResult) {
416
260
  value: function _getOrGenerateRecordIdsSet() {
417
261
  if (!this._recordIdsSet) {
418
262
  var recordIdsSet = {};
419
- var _iteratorNormalCompletion4 = true;
420
- var _didIteratorError4 = false;
421
- var _iteratorError4 = undefined;
263
+ var _iteratorNormalCompletion3 = true;
264
+ var _didIteratorError3 = false;
265
+ var _iteratorError3 = undefined;
422
266
 
423
267
  try {
424
- for (var _iterator4 = this.recordIds[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) {
425
- var recordId = _step4.value;
268
+ for (var _iterator3 = this.recordIds[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
269
+ var recordId = _step3.value;
426
270
  recordIdsSet[recordId] = true;
427
271
  }
428
272
  } catch (err) {
429
- _didIteratorError4 = true;
430
- _iteratorError4 = err;
273
+ _didIteratorError3 = true;
274
+ _iteratorError3 = err;
431
275
  } finally {
432
276
  try {
433
- if (!_iteratorNormalCompletion4 && _iterator4.return != null) {
434
- _iterator4.return();
277
+ if (!_iteratorNormalCompletion3 && _iterator3.return != null) {
278
+ _iterator3.return();
435
279
  }
436
280
  } finally {
437
- if (_didIteratorError4) {
438
- throw _iteratorError4;
281
+ if (_didIteratorError3) {
282
+ throw _iteratorError3;
439
283
  }
440
284
  }
441
285
  }
@@ -452,72 +296,85 @@ function (_RecordQueryResult) {
452
296
  */
453
297
 
454
298
  }, {
455
- key: "watch",
299
+ key: "_incrementCellValueKeyWatchCountAndWatchIfNecessary",
456
300
 
457
- /** @inheritdoc */
458
- value: function watch(keys, callback, context) {
459
- var validKeys = (0, _get2.default)((0, _getPrototypeOf2.default)(TableOrViewQueryResult.prototype), "watch", this).call(this, keys, callback, context);
301
+ /** @internal */
302
+ value: function _incrementCellValueKeyWatchCountAndWatchIfNecessary(key, watchCallback) {
303
+ if (!this._cellValueKeyWatchCounts[key]) {
304
+ this._cellValueKeyWatchCounts[key] = 0;
460
305
 
461
- var callWatchOnRecordStoreWithKey = keyToWatch => {
462
- this._recordStore.watchWithRecordQueryResult({
463
- priority: _airtable_interface.BlockQueryCallbackPriority.BLOCK_CODE,
464
- recordQueryResult: this,
465
- keys: keyToWatch,
466
- callbackForRegistration: callback,
467
- context
468
- });
469
- };
306
+ this._recordStore.watch(key, watchCallback, this);
307
+ }
470
308
 
471
- var callWatchOnViewDataStoreWithKey = keyToWatch => {
472
- (0, _error_utils.invariant)(this._sourceModel instanceof _view.default, 'To watch %s you must be subscribed to a view', keyToWatch);
309
+ this._cellValueKeyWatchCounts[key]++;
310
+ }
311
+ /** @internal */
473
312
 
474
- var viewDataStore = this._recordStore.getViewDataStore(this._sourceModel.id);
313
+ }, {
314
+ key: "_decrementCellValueKeyWatchCountAndUnwatchIfPossible",
315
+ value: function _decrementCellValueKeyWatchCountAndUnwatchIfPossible(key, watchCallback) {
316
+ if (!this._cellValueKeyWatchCounts[key]) {
317
+ // Key isn't watched, so just skip it. This matches behavior of Watchable,
318
+ // where calling unwatch on a key that isn't watched just no-ops.
319
+ return;
320
+ }
475
321
 
476
- viewDataStore.watch(keyToWatch, callback, context);
477
- };
322
+ this._cellValueKeyWatchCounts[key]--;
478
323
 
479
- var callWatchFunctions = {
480
- callOnRecordStoreWithKey: callWatchOnRecordStoreWithKey,
481
- callOnViewDataStoreWithKey: callWatchOnViewDataStoreWithKey
482
- };
483
- var _iteratorNormalCompletion5 = true;
484
- var _didIteratorError5 = false;
485
- var _iteratorError5 = undefined;
324
+ if (this._cellValueKeyWatchCounts[key] === 0) {
325
+ // We're down to zero watches for this key, so we can actually unwatch it now.
326
+ this._recordStore.unwatch(key, watchCallback, this);
327
+
328
+ delete this._cellValueKeyWatchCounts[key];
329
+ }
330
+ }
331
+ /** @inheritdoc */
332
+
333
+ }, {
334
+ key: "watch",
335
+ value: function watch(keys, callback, context) {
336
+ var validKeys = (0, _get2.default)((0, _getPrototypeOf2.default)(TableOrViewQueryResult.prototype), "watch", this).call(this, keys, callback, context);
337
+ var _iteratorNormalCompletion4 = true;
338
+ var _didIteratorError4 = false;
339
+ var _iteratorError4 = undefined;
486
340
 
487
341
  try {
488
- for (var _iterator5 = validKeys[Symbol.iterator](), _step5; !(_iteratorNormalCompletion5 = (_step5 = _iterator5.next()).done); _iteratorNormalCompletion5 = true) {
489
- var _key2 = _step5.value;
490
-
491
- // There are two watch systems:
492
- // 1) the query-based watch
493
- // 2) the non-query-based watch (through super)
494
- // Depending on the key, we may use one or both of the systems.
495
- // The non-query based watch system is used when when:
496
- // - watching: records, recordIds
497
- // - _loadDataAsync calls all watch keys on initial load
498
- // - Support for _watchRecordColorsIfNeeded
499
- // For all changes to the remaining keys - the query-based system is used.
342
+ for (var _iterator4 = validKeys[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) {
343
+ var _key2 = _step4.value;
344
+
500
345
  if (_key2.startsWith(_record_query_result.default.WatchableCellValuesInFieldKeyPrefix)) {
501
- this._watchConfigByWatchableKey[_record_query_result.default.WatchableCellValuesInFieldKeyPrefix](_key2, callWatchFunctions);
502
- } else {
503
- var functionToCallWithKey = this._watchConfigByWatchableKey[_key2];
346
+ var fieldId = _key2.substring(_record_query_result.default.WatchableCellValuesInFieldKeyPrefix.length);
347
+
348
+ if (this._fieldIdsSetToLoadOrNullIfAllFields && !(0, _private_utils.has)(this._fieldIdsSetToLoadOrNullIfAllFields, fieldId)) {
349
+ throw (0, _error_utils.spawnError)("Can't watch field because it wasn't included in RecordQueryResult fields: %s", fieldId);
350
+ }
351
+
352
+ this._incrementCellValueKeyWatchCountAndWatchIfNecessary(_key2, this._onCellValuesInFieldChanged);
353
+ }
504
354
 
505
- if (functionToCallWithKey) {
506
- functionToCallWithKey(_key2, callWatchFunctions);
355
+ if (_key2 === _record_query_result.default.WatchableKeys.cellValues) {
356
+ if (this._fieldIdsSetToLoadOrNullIfAllFields) {
357
+ for (var _i = 0, _Object$keys = Object.keys(this._fieldIdsSetToLoadOrNullIfAllFields); _i < _Object$keys.length; _i++) {
358
+ var _fieldId = _Object$keys[_i];
359
+
360
+ this._incrementCellValueKeyWatchCountAndWatchIfNecessary(_record_query_result.default.WatchableCellValuesInFieldKeyPrefix + _fieldId, this._onCellValuesChanged);
361
+ }
362
+ } else {
363
+ this._incrementCellValueKeyWatchCountAndWatchIfNecessary(_key2, this._onCellValuesChanged);
507
364
  }
508
365
  }
509
366
  }
510
367
  } catch (err) {
511
- _didIteratorError5 = true;
512
- _iteratorError5 = err;
368
+ _didIteratorError4 = true;
369
+ _iteratorError4 = err;
513
370
  } finally {
514
371
  try {
515
- if (!_iteratorNormalCompletion5 && _iterator5.return != null) {
516
- _iterator5.return();
372
+ if (!_iteratorNormalCompletion4 && _iterator4.return != null) {
373
+ _iterator4.return();
517
374
  }
518
375
  } finally {
519
- if (_didIteratorError5) {
520
- throw _iteratorError5;
376
+ if (_didIteratorError4) {
377
+ throw _iteratorError4;
521
378
  }
522
379
  }
523
380
  }
@@ -530,53 +387,41 @@ function (_RecordQueryResult) {
530
387
  key: "unwatch",
531
388
  value: function unwatch(keys, callback, context) {
532
389
  var validKeys = (0, _get2.default)((0, _getPrototypeOf2.default)(TableOrViewQueryResult.prototype), "unwatch", this).call(this, keys, callback, context);
533
-
534
- var callUnwatchOnRecordStoreWithKey = keysToUnwatch => {
535
- this._recordStore.unwatch(keysToUnwatch, callback, context);
536
- };
537
-
538
- var callUnwatchOnViewDataStoreWithKey = keyToWatch => {
539
- (0, _error_utils.invariant)(this._sourceModel instanceof _view.default, 'To watch %s you must be subscribed to a view', keyToWatch);
540
-
541
- var viewDataStore = this._recordStore.getViewDataStore(this._sourceModel.id);
542
-
543
- viewDataStore.unwatch(keyToWatch, callback, context);
544
- };
545
-
546
- var callWatchFunctions = {
547
- callOnRecordStoreWithKey: callUnwatchOnRecordStoreWithKey,
548
- callOnViewDataStoreWithKey: callUnwatchOnViewDataStoreWithKey
549
- };
550
- var _iteratorNormalCompletion6 = true;
551
- var _didIteratorError6 = false;
552
- var _iteratorError6 = undefined;
390
+ var _iteratorNormalCompletion5 = true;
391
+ var _didIteratorError5 = false;
392
+ var _iteratorError5 = undefined;
553
393
 
554
394
  try {
555
- for (var _iterator6 = validKeys[Symbol.iterator](), _step6; !(_iteratorNormalCompletion6 = (_step6 = _iterator6.next()).done); _iteratorNormalCompletion6 = true) {
556
- var _key3 = _step6.value;
395
+ for (var _iterator5 = validKeys[Symbol.iterator](), _step5; !(_iteratorNormalCompletion5 = (_step5 = _iterator5.next()).done); _iteratorNormalCompletion5 = true) {
396
+ var _key3 = _step5.value;
557
397
 
558
- // This is the inverse of the watch logic
559
398
  if (_key3.startsWith(_record_query_result.default.WatchableCellValuesInFieldKeyPrefix)) {
560
- this._watchConfigByWatchableKey[_record_query_result.default.WatchableCellValuesInFieldKeyPrefix](_key3, callWatchFunctions);
561
- } else {
562
- var functionToCallWithKey = this._watchConfigByWatchableKey[_key3];
399
+ this._decrementCellValueKeyWatchCountAndUnwatchIfPossible(_key3, this._onCellValuesInFieldChanged);
400
+ }
401
+
402
+ if (_key3 === _record_query_result.default.WatchableKeys.cellValues) {
403
+ if (this._fieldIdsSetToLoadOrNullIfAllFields) {
404
+ for (var _i2 = 0, _Object$keys2 = Object.keys(this._fieldIdsSetToLoadOrNullIfAllFields); _i2 < _Object$keys2.length; _i2++) {
405
+ var fieldId = _Object$keys2[_i2];
563
406
 
564
- if (functionToCallWithKey) {
565
- functionToCallWithKey(_key3, callWatchFunctions);
407
+ this._decrementCellValueKeyWatchCountAndUnwatchIfPossible(_record_query_result.default.WatchableCellValuesInFieldKeyPrefix + fieldId, this._onCellValuesChanged);
408
+ }
409
+ } else {
410
+ this._decrementCellValueKeyWatchCountAndUnwatchIfPossible(_key3, this._onCellValuesChanged);
566
411
  }
567
412
  }
568
413
  }
569
414
  } catch (err) {
570
- _didIteratorError6 = true;
571
- _iteratorError6 = err;
415
+ _didIteratorError5 = true;
416
+ _iteratorError5 = err;
572
417
  } finally {
573
418
  try {
574
- if (!_iteratorNormalCompletion6 && _iterator6.return != null) {
575
- _iterator6.return();
419
+ if (!_iteratorNormalCompletion5 && _iterator5.return != null) {
420
+ _iterator5.return();
576
421
  }
577
422
  } finally {
578
- if (_didIteratorError6) {
579
- throw _iteratorError6;
423
+ if (_didIteratorError5) {
424
+ throw _iteratorError5;
580
425
  }
581
426
  }
582
427
  }
@@ -588,54 +433,45 @@ function (_RecordQueryResult) {
588
433
  }, {
589
434
  key: "loadDataAsync",
590
435
  value: function loadDataAsync() {
591
- var sourceModelLoadPromise, fieldIdsToLoadOrNullIfAllFields, allFieldsToQuery, metadataFieldId, sourceModelLoadedPromise;
592
- return _regenerator.default.async(function loadDataAsync$(_context2) {
436
+ var sourceModelLoadPromise, cellValuesInFieldsLoadPromise;
437
+ return _regenerator.default.async(function loadDataAsync$(_context) {
593
438
  while (1) {
594
- switch (_context2.prev = _context2.next) {
439
+ switch (_context.prev = _context.next) {
595
440
  case 0:
596
441
  if (!this._sourceModel.isDeleted) {
597
- _context2.next = 2;
442
+ _context.next = 2;
598
443
  break;
599
444
  }
600
445
 
601
446
  throw this._spawnErrorForDeletion();
602
447
 
603
448
  case 2:
604
- fieldIdsToLoadOrNullIfAllFields = this._fieldIdsSetToLoadOrNullIfAllFields ? Object.keys(this._fieldIdsSetToLoadOrNullIfAllFields) : null;
449
+ if (this._fieldIdsSetToLoadOrNullIfAllFields) {
450
+ cellValuesInFieldsLoadPromise = this._recordStore.loadCellValuesInFieldIdsAsync(Object.keys(this._fieldIdsSetToLoadOrNullIfAllFields));
451
+ } else {
452
+ // Load all fields.
453
+ cellValuesInFieldsLoadPromise = this._recordStore.loadDataAsync();
454
+ }
605
455
 
606
456
  if (this._sourceModel instanceof _table.default) {
607
- if (fieldIdsToLoadOrNullIfAllFields) {
608
- // TODO: (#proj-blocks-sdk-record-limits) Do we need to load the recordData metadata field
609
- // in order to load any record data? If we do - this should be encapsulated entirely
610
- // inside of the RecordStore in publicAirtableInterface.
611
- // (should the queryModel be able to specify metadata requirements?)
612
- allFieldsToQuery = fieldIdsToLoadOrNullIfAllFields;
613
- metadataFieldId = this._recordStore._getFieldIdForCausingRecordMetadataToLoad();
614
-
615
- if (!allFieldsToQuery.includes(metadataFieldId)) {
616
- allFieldsToQuery = [...allFieldsToQuery, metadataFieldId];
617
- }
618
-
619
- sourceModelLoadPromise = this._recordStore.loadAllCellValuesInFieldIdsAsync(allFieldsToQuery);
457
+ if (this._fieldIdsSetToLoadOrNullIfAllFields) {
458
+ sourceModelLoadPromise = this._recordStore.loadRecordMetadataAsync();
620
459
  } else {
621
- // Load all fields.
622
- sourceModelLoadPromise = this._recordStore.loadAllCellValuesAsync();
460
+ // table.loadDataAsync is a superset of loadRecordMetadataAsync,
461
+ // so no need to load record metadata again.
462
+ sourceModelLoadPromise = null;
623
463
  }
624
464
  } else {
625
- sourceModelLoadPromise = this._recordStore.loadViewDataStoreAndCellValuesForFieldIdsAsync(this._sourceModel.id, fieldIdsToLoadOrNullIfAllFields);
626
- } // See comment on _loadedSourceModelQueryIds declaration for details
627
-
465
+ sourceModelLoadPromise = this._recordStore.getViewDataStore(this._sourceModel.id).loadDataAsync();
466
+ }
628
467
 
629
- sourceModelLoadedPromise = sourceModelLoadPromise.then(sourceModelQueryId => {
630
- this._loadedSourceModelQueryIds.push(sourceModelQueryId);
631
- });
632
- this._mostRecentSourceModelLoadedPromise = Promise.all([sourceModelLoadedPromise, this._loadRecordColorsAsync()]);
633
- _context2.next = 8;
468
+ this._mostRecentSourceModelLoadPromise = Promise.all([sourceModelLoadPromise, cellValuesInFieldsLoadPromise, this._loadRecordColorsAsync()]);
469
+ _context.next = 7;
634
470
  return _regenerator.default.awrap((0, _get2.default)((0, _getPrototypeOf2.default)(TableOrViewQueryResult.prototype), "loadDataAsync", this).call(this));
635
471
 
636
- case 8:
472
+ case 7:
637
473
  case "end":
638
- return _context2.stop();
474
+ return _context.stop();
639
475
  }
640
476
  }
641
477
  }, null, this);
@@ -651,26 +487,26 @@ function (_RecordQueryResult) {
651
487
 
652
488
  var fieldIds = this._normalizedOpts.fieldIdsOrNullIfAllFields || this._table.fields.map(field => field.id);
653
489
 
654
- var _iteratorNormalCompletion7 = true;
655
- var _didIteratorError7 = false;
656
- var _iteratorError7 = undefined;
490
+ var _iteratorNormalCompletion6 = true;
491
+ var _didIteratorError6 = false;
492
+ var _iteratorError6 = undefined;
657
493
 
658
494
  try {
659
- for (var _iterator7 = fieldIds[Symbol.iterator](), _step7; !(_iteratorNormalCompletion7 = (_step7 = _iterator7.next()).done); _iteratorNormalCompletion7 = true) {
660
- var fieldId = _step7.value;
495
+ for (var _iterator6 = fieldIds[Symbol.iterator](), _step6; !(_iteratorNormalCompletion6 = (_step6 = _iterator6.next()).done); _iteratorNormalCompletion6 = true) {
496
+ var fieldId = _step6.value;
661
497
  changedKeys.push(_record_query_result.default.WatchableCellValuesInFieldKeyPrefix + fieldId);
662
498
  }
663
499
  } catch (err) {
664
- _didIteratorError7 = true;
665
- _iteratorError7 = err;
500
+ _didIteratorError6 = true;
501
+ _iteratorError6 = err;
666
502
  } finally {
667
503
  try {
668
- if (!_iteratorNormalCompletion7 && _iterator7.return != null) {
669
- _iterator7.return();
504
+ if (!_iteratorNormalCompletion6 && _iterator6.return != null) {
505
+ _iterator6.return();
670
506
  }
671
507
  } finally {
672
- if (_didIteratorError7) {
673
- throw _iteratorError7;
508
+ if (_didIteratorError6) {
509
+ throw _iteratorError6;
674
510
  }
675
511
  }
676
512
  }
@@ -682,79 +518,55 @@ function (_RecordQueryResult) {
682
518
  }, {
683
519
  key: "_loadDataAsync",
684
520
  value: function _loadDataAsync() {
685
- var viewDataStore, _iteratorNormalCompletion8, _didIteratorError8, _iteratorError8, _iterator8, _step8, sort, field;
521
+ var viewDataStore, _iteratorNormalCompletion7, _didIteratorError7, _iteratorError7, _iterator7, _step7, sort, field;
686
522
 
687
- return _regenerator.default.async(function _loadDataAsync$(_context3) {
523
+ return _regenerator.default.async(function _loadDataAsync$(_context2) {
688
524
  while (1) {
689
- switch (_context3.prev = _context3.next) {
525
+ switch (_context2.prev = _context2.next) {
690
526
  case 0:
691
527
  this._table.__tableOrViewQueryResultPool.registerObjectForReuseStrong(this);
692
528
 
693
- (0, _error_utils.invariant)(this._mostRecentSourceModelLoadedPromise, 'No source model load promises');
694
- _context3.next = 4;
695
- return _regenerator.default.awrap(this._mostRecentSourceModelLoadedPromise);
529
+ (0, _error_utils.invariant)(this._mostRecentSourceModelLoadPromise, 'No source model load promises');
530
+ _context2.next = 4;
531
+ return _regenerator.default.awrap(this._mostRecentSourceModelLoadPromise);
696
532
 
697
533
  case 4:
698
534
  if (this._sorts) {
699
535
  this._replaceVisList();
700
536
  }
701
537
 
702
- this._orderedRecordIds = this._generateOrderedRecordIds(); // Ensure that groups are not loaded
538
+ this._orderedRecordIds = this._generateOrderedRecordIds();
539
+ this._orderedGroups = this._generateAndLoadOrderedGroups(); // The server provided value and developer supplied value are the same, no conversion needed
703
540
 
704
- this._orderedGroups = null; // The server provided value and developer supplied value are the same, no conversion needed
705
-
706
- this._loadedGroupLevels = null;
541
+ this._loadedGroupLevels = this._sourceModelGroupLevels;
707
542
 
708
543
  if (this._sourceModel instanceof _table.default) {
709
- // _onRecordsChanged actually just transforms data and passes to
710
- // user provided watches
711
- this._recordStore.watchWithRecordQueryResult({
712
- priority: _airtable_interface.BlockQueryCallbackPriority.BLOCK_CODE,
713
- recordQueryResult: this,
714
- keys: _record_store.WatchableRecordStoreKeys.records,
715
- callbackForRegistration: this._onRecordsChanged,
716
- context: this
717
- });
544
+ this._recordStore.watch(_record_store.WatchableRecordStoreKeys.records, this._onRecordsChanged, this);
718
545
  } else {
719
- viewDataStore = this._recordStore.getViewDataStore(this._sourceModel.id); // _onRecordsChanged actually just transforms data and passes to
720
- // user provided watches
721
-
546
+ viewDataStore = this._recordStore.getViewDataStore(this._sourceModel.id);
722
547
  viewDataStore.watch(_view_data_store.WatchableViewDataStoreKeys.visibleRecords, this._onRecordsChanged, this);
723
- viewDataStore.watchFromSdk(_view_data_store.WatchableViewDataStoreKeys.groups, this._onGroupsChanged, this);
724
- viewDataStore.watchFromSdk(_view_data_store.WatchableViewDataStoreKeys.groupLevels, this._onGroupLevelsChanged, this);
725
- } // This only watches cell values if a sort is specified
726
-
727
-
728
- this._recordStore.watchWithRecordQueryResult({
729
- priority: _airtable_interface.BlockQueryCallbackPriority.SDK,
730
- recordQueryResult: this,
731
- keys: this._cellValuesForSortWatchKeys,
732
- callbackForRegistration: this._onCellValuesForSortChanged,
733
- context: this
734
- });
735
-
736
- this._recordStore.watchWithRecordQueryResult({
737
- priority: _airtable_interface.BlockQueryCallbackPriority.SDK,
738
- recordQueryResult: this,
739
- keys: this._cellValuesForGroupWatchKeys,
740
- callbackForRegistration: this._onCellValuesForGroupChanged,
741
- context: this
742
- });
548
+ viewDataStore.watch(_view_data_store.WatchableViewDataStoreKeys.groups, this._onGroupsChanged, this);
549
+ viewDataStore.watch(_view_data_store.WatchableViewDataStoreKeys.groupLevels, this._onGroupLevelsChanged, this);
550
+ }
551
+
552
+ this._recordStore.watch(this._cellValuesForSortWatchKeys, this._onCellValuesForSortChanged, this);
553
+
554
+ this._recordStore.watch(this._cellValuesForGroupWatchKeys, this._onCellValuesForGroupChanged, this);
743
555
 
744
556
  this._table.watch(_table.WatchableTableKeys.fields, this._onTableFieldsChanged, this);
745
557
 
746
558
  if (!this._sorts) {
747
- _context3.next = 32;
559
+ _context2.next = 32;
748
560
  break;
749
561
  }
750
562
 
751
- _iteratorNormalCompletion8 = true;
752
- _didIteratorError8 = false;
753
- _iteratorError8 = undefined;
754
- _context3.prev = 16;
563
+ _iteratorNormalCompletion7 = true;
564
+ _didIteratorError7 = false;
565
+ _iteratorError7 = undefined;
566
+ _context2.prev = 16;
755
567
 
756
- for (_iterator8 = this._sorts[Symbol.iterator](); !(_iteratorNormalCompletion8 = (_step8 = _iterator8.next()).done); _iteratorNormalCompletion8 = true) {
757
- sort = _step8.value;
568
+ for (_iterator7 = this._sorts[Symbol.iterator](); !(_iteratorNormalCompletion7 = (_step7 = _iterator7.next()).done); _iteratorNormalCompletion7 = true) {
569
+ sort = _step7.value;
758
570
  field = this._table.getFieldByIdIfExists(sort.fieldId);
759
571
 
760
572
  if (field) {
@@ -763,45 +575,45 @@ function (_RecordQueryResult) {
763
575
  }
764
576
  }
765
577
 
766
- _context3.next = 24;
578
+ _context2.next = 24;
767
579
  break;
768
580
 
769
581
  case 20:
770
- _context3.prev = 20;
771
- _context3.t0 = _context3["catch"](16);
772
- _didIteratorError8 = true;
773
- _iteratorError8 = _context3.t0;
582
+ _context2.prev = 20;
583
+ _context2.t0 = _context2["catch"](16);
584
+ _didIteratorError7 = true;
585
+ _iteratorError7 = _context2.t0;
774
586
 
775
587
  case 24:
776
- _context3.prev = 24;
777
- _context3.prev = 25;
588
+ _context2.prev = 24;
589
+ _context2.prev = 25;
778
590
 
779
- if (!_iteratorNormalCompletion8 && _iterator8.return != null) {
780
- _iterator8.return();
591
+ if (!_iteratorNormalCompletion7 && _iterator7.return != null) {
592
+ _iterator7.return();
781
593
  }
782
594
 
783
595
  case 27:
784
- _context3.prev = 27;
596
+ _context2.prev = 27;
785
597
 
786
- if (!_didIteratorError8) {
787
- _context3.next = 30;
598
+ if (!_didIteratorError7) {
599
+ _context2.next = 30;
788
600
  break;
789
601
  }
790
602
 
791
- throw _iteratorError8;
603
+ throw _iteratorError7;
792
604
 
793
605
  case 30:
794
- return _context3.finish(27);
606
+ return _context2.finish(27);
795
607
 
796
608
  case 31:
797
- return _context3.finish(24);
609
+ return _context2.finish(24);
798
610
 
799
611
  case 32:
800
- return _context3.abrupt("return", this._getChangedKeysOnLoad());
612
+ return _context2.abrupt("return", this._getChangedKeysOnLoad());
801
613
 
802
614
  case 33:
803
615
  case "end":
804
- return _context3.stop();
616
+ return _context2.stop();
805
617
  }
806
618
  }
807
619
  }, null, this, [[16, 20, 24, 32], [25,, 27, 31]]);
@@ -813,9 +625,21 @@ function (_RecordQueryResult) {
813
625
  value: function unloadData() {
814
626
  (0, _get2.default)((0, _getPrototypeOf2.default)(TableOrViewQueryResult.prototype), "unloadData", this).call(this);
815
627
 
816
- if (this._loadedSourceModelQueryIds.length === 0) {
817
- // Source model must have loaded a queryId to unload
818
- return;
628
+ if (this._sourceModel instanceof _table.default) {
629
+ if (this._fieldIdsSetToLoadOrNullIfAllFields) {
630
+ this._recordStore.unloadRecordMetadata();
631
+ } else {
632
+ this._recordStore.unloadData();
633
+ }
634
+ } else {
635
+ // If the view is deleted, we can't get a data store for it.
636
+ if (!this._sourceModel.isDeleted) {
637
+ this._recordStore.getViewDataStore(this._sourceModel.id).unloadData();
638
+ }
639
+ }
640
+
641
+ if (this._fieldIdsSetToLoadOrNullIfAllFields) {
642
+ this._recordStore.unloadCellValuesInFieldIds(Object.keys(this._fieldIdsSetToLoadOrNullIfAllFields));
819
643
  }
820
644
 
821
645
  this._unloadRecordColors();
@@ -825,32 +649,119 @@ function (_RecordQueryResult) {
825
649
  }, {
826
650
  key: "_unloadData",
827
651
  value: function _unloadData() {
828
- (0, _private_utils.fireAndForgetPromise)(this._unloadDataAsync);
652
+ this._mostRecentSourceModelLoadPromise = null;
653
+
654
+ if (this._sourceModel instanceof _table.default) {
655
+ this._recordStore.unwatch(_record_store.WatchableRecordStoreKeys.records, this._onRecordsChanged, this);
656
+ } else {
657
+ if (!this._sourceModel.isDeleted) {
658
+ var viewDataStore = this._recordStore.getViewDataStore(this._sourceModel.id);
659
+
660
+ viewDataStore.unwatch(_view_data_store.WatchableViewDataStoreKeys.visibleRecords, this._onRecordsChanged, this);
661
+ viewDataStore.unwatch(_view_data_store.WatchableViewDataStoreKeys.groups, this._onGroupsChanged, this);
662
+ viewDataStore.unwatch(_view_data_store.WatchableViewDataStoreKeys.groupLevels, this._onGroupLevelsChanged, this);
663
+ }
664
+ }
665
+
666
+ this._recordStore.unwatch(this._cellValuesForSortWatchKeys, this._onCellValuesForSortChanged, this);
667
+
668
+ this._recordStore.unwatch(this._cellValuesForGroupWatchKeys, this._onCellValuesForGroupChanged, this);
669
+
670
+ this._table.unwatch(_table.WatchableTableKeys.fields, this._onTableFieldsChanged, this); // If the table is deleted, can't call getFieldById on it below.
671
+
672
+
673
+ if (!this._table.isDeleted && this._sorts) {
674
+ var _iteratorNormalCompletion8 = true;
675
+ var _didIteratorError8 = false;
676
+ var _iteratorError8 = undefined;
677
+
678
+ try {
679
+ for (var _iterator8 = this._sorts[Symbol.iterator](), _step8; !(_iteratorNormalCompletion8 = (_step8 = _iterator8.next()).done); _iteratorNormalCompletion8 = true) {
680
+ var sort = _step8.value;
681
+
682
+ var field = this._table.getFieldByIdIfExists(sort.fieldId);
683
+
684
+ if (field) {
685
+ field.unwatch('type', this._onFieldConfigChanged, this);
686
+ field.unwatch('options', this._onFieldConfigChanged, this);
687
+ }
688
+ }
689
+ } catch (err) {
690
+ _didIteratorError8 = true;
691
+ _iteratorError8 = err;
692
+ } finally {
693
+ try {
694
+ if (!_iteratorNormalCompletion8 && _iterator8.return != null) {
695
+ _iterator8.return();
696
+ }
697
+ } finally {
698
+ if (_didIteratorError8) {
699
+ throw _iteratorError8;
700
+ }
701
+ }
702
+ }
703
+ }
704
+
705
+ this._unloadOrderedGroupsIfNeeded();
706
+
707
+ this._visList = null;
708
+ this._orderedRecordIds = null;
709
+ this._recordIdsSet = null;
710
+
711
+ this._table.__tableOrViewQueryResultPool.unregisterObjectForReuseStrong(this);
829
712
  }
713
+ /** @internal */
714
+
830
715
  }, {
831
716
  key: "_addRecordIdsToVisList",
832
-
833
- /** @internal */
834
717
  value: function _addRecordIdsToVisList(recordIds) {
835
718
  var visList = this._visList;
836
719
  (0, _error_utils.invariant)(visList, 'No vis list');
837
- visList.addRecordIds(recordIds);
720
+ var _iteratorNormalCompletion9 = true;
721
+ var _didIteratorError9 = false;
722
+ var _iteratorError9 = undefined;
723
+
724
+ try {
725
+ for (var _iterator9 = recordIds[Symbol.iterator](), _step9; !(_iteratorNormalCompletion9 = (_step9 = _iterator9.next()).done); _iteratorNormalCompletion9 = true) {
726
+ var recordId = _step9.value;
727
+
728
+ var record = this._recordStore.getRecordByIdIfExists(recordId);
729
+
730
+ (0, _error_utils.invariant)(record, 'Record missing in table');
731
+ visList.addRecordData(record._data);
732
+ }
733
+ } catch (err) {
734
+ _didIteratorError9 = true;
735
+ _iteratorError9 = err;
736
+ } finally {
737
+ try {
738
+ if (!_iteratorNormalCompletion9 && _iterator9.return != null) {
739
+ _iterator9.return();
740
+ }
741
+ } finally {
742
+ if (_didIteratorError9) {
743
+ throw _iteratorError9;
744
+ }
745
+ }
746
+ }
838
747
  }
839
748
  /** @internal */
840
749
 
841
750
  }, {
842
751
  key: "_onGroupLevelsChanged",
843
752
  value: function _onGroupLevelsChanged(model, key, updates) {
844
- this._loadedGroupLevels = null;
753
+ this._loadedGroupLevels = this._sourceModelGroupLevels;
754
+
755
+ this._unloadRemovedGroupsAndLoadNewGroupsAndTriggerWatches();
845
756
 
846
- this._unloadGroups();
757
+ this._onChange(_record_query_result.default.WatchableKeys.groupLevels);
847
758
  }
848
759
  /** @internal */
849
760
 
850
761
  }, {
851
762
  key: "_onGroupsChanged",
852
763
  value: function _onGroupsChanged(model, key, updates) {
853
- this._unloadGroups();
764
+ this._unloadRemovedGroupsAndLoadNewGroupsAndTriggerWatches();
854
765
  }
855
766
  /** @internal */
856
767
 
@@ -873,11 +784,7 @@ function (_RecordQueryResult) {
873
784
  addedRecordIds: _addedRecordIds,
874
785
  removedRecordIds: _removedRecordIds
875
786
  };
876
- } // We never need to handle an initial empty update coming from record_store
877
- // since it does not issue empty initial updates.
878
- // Keep the if statement for type safety. Invariant would also work, but is riskier.
879
- // istanbul ignore if
880
-
787
+ }
881
788
 
882
789
  if (!updates) {
883
790
  // If there are no updates, do nothing, since we'll handle the initial
@@ -904,50 +811,50 @@ function (_RecordQueryResult) {
904
811
  }
905
812
 
906
813
  if (this._recordIdsSet) {
907
- var _iteratorNormalCompletion9 = true;
908
- var _didIteratorError9 = false;
909
- var _iteratorError9 = undefined;
814
+ var _iteratorNormalCompletion10 = true;
815
+ var _didIteratorError10 = false;
816
+ var _iteratorError10 = undefined;
910
817
 
911
818
  try {
912
- for (var _iterator9 = addedRecordIds[Symbol.iterator](), _step9; !(_iteratorNormalCompletion9 = (_step9 = _iterator9.next()).done); _iteratorNormalCompletion9 = true) {
913
- var recordId = _step9.value;
819
+ for (var _iterator10 = addedRecordIds[Symbol.iterator](), _step10; !(_iteratorNormalCompletion10 = (_step10 = _iterator10.next()).done); _iteratorNormalCompletion10 = true) {
820
+ var recordId = _step10.value;
914
821
  this._recordIdsSet[recordId] = true;
915
822
  }
916
823
  } catch (err) {
917
- _didIteratorError9 = true;
918
- _iteratorError9 = err;
824
+ _didIteratorError10 = true;
825
+ _iteratorError10 = err;
919
826
  } finally {
920
827
  try {
921
- if (!_iteratorNormalCompletion9 && _iterator9.return != null) {
922
- _iterator9.return();
828
+ if (!_iteratorNormalCompletion10 && _iterator10.return != null) {
829
+ _iterator10.return();
923
830
  }
924
831
  } finally {
925
- if (_didIteratorError9) {
926
- throw _iteratorError9;
832
+ if (_didIteratorError10) {
833
+ throw _iteratorError10;
927
834
  }
928
835
  }
929
836
  }
930
837
 
931
- var _iteratorNormalCompletion10 = true;
932
- var _didIteratorError10 = false;
933
- var _iteratorError10 = undefined;
838
+ var _iteratorNormalCompletion11 = true;
839
+ var _didIteratorError11 = false;
840
+ var _iteratorError11 = undefined;
934
841
 
935
842
  try {
936
- for (var _iterator10 = removedRecordIds[Symbol.iterator](), _step10; !(_iteratorNormalCompletion10 = (_step10 = _iterator10.next()).done); _iteratorNormalCompletion10 = true) {
937
- var _recordId = _step10.value;
843
+ for (var _iterator11 = removedRecordIds[Symbol.iterator](), _step11; !(_iteratorNormalCompletion11 = (_step11 = _iterator11.next()).done); _iteratorNormalCompletion11 = true) {
844
+ var _recordId = _step11.value;
938
845
  this._recordIdsSet[_recordId] = undefined;
939
846
  }
940
847
  } catch (err) {
941
- _didIteratorError10 = true;
942
- _iteratorError10 = err;
848
+ _didIteratorError11 = true;
849
+ _iteratorError11 = err;
943
850
  } finally {
944
851
  try {
945
- if (!_iteratorNormalCompletion10 && _iterator10.return != null) {
946
- _iterator10.return();
852
+ if (!_iteratorNormalCompletion11 && _iterator11.return != null) {
853
+ _iterator11.return();
947
854
  }
948
855
  } finally {
949
- if (_didIteratorError10) {
950
- throw _iteratorError10;
856
+ if (_didIteratorError11) {
857
+ throw _iteratorError11;
951
858
  }
952
859
  }
953
860
  }
@@ -976,10 +883,6 @@ function (_RecordQueryResult) {
976
883
  }, {
977
884
  key: "_onCellValuesForSortChanged",
978
885
  value: function _onCellValuesForSortChanged(recordStore, key, recordIds, fieldId) {
979
- // We never need to handle an initial empty update coming from record_store
980
- // since it does not issue empty initial updates.
981
- // Keep the if statement for type safety. Invariant would also work, but is riskier.
982
- // istanbul ignore if
983
886
  if (!recordIds || !fieldId) {
984
887
  // If there are no updates, do nothing, since we'll handle the initial
985
888
  // callback when the record set is loaded (and we don't want to fire
@@ -1045,13 +948,13 @@ function (_RecordQueryResult) {
1045
948
  // deleted and then undeleted.
1046
949
 
1047
950
  var wereAnyFieldsCreatedOrDeleted = false;
1048
- var _iteratorNormalCompletion11 = true;
1049
- var _didIteratorError11 = false;
1050
- var _iteratorError11 = undefined;
951
+ var _iteratorNormalCompletion12 = true;
952
+ var _didIteratorError12 = false;
953
+ var _iteratorError12 = undefined;
1051
954
 
1052
955
  try {
1053
- for (var _iterator11 = addedFieldIds[Symbol.iterator](), _step11; !(_iteratorNormalCompletion11 = (_step11 = _iterator11.next()).done); _iteratorNormalCompletion11 = true) {
1054
- var fieldId = _step11.value;
956
+ for (var _iterator12 = addedFieldIds[Symbol.iterator](), _step12; !(_iteratorNormalCompletion12 = (_step12 = _iterator12.next()).done); _iteratorNormalCompletion12 = true) {
957
+ var fieldId = _step12.value;
1055
958
 
1056
959
  // If a field that we rely on was created (i.e. it was undeleted), we need to
1057
960
  // make sure we're watching it's config.
@@ -1068,16 +971,16 @@ function (_RecordQueryResult) {
1068
971
  // istanbul ignore else
1069
972
 
1070
973
  } catch (err) {
1071
- _didIteratorError11 = true;
1072
- _iteratorError11 = err;
974
+ _didIteratorError12 = true;
975
+ _iteratorError12 = err;
1073
976
  } finally {
1074
977
  try {
1075
- if (!_iteratorNormalCompletion11 && _iterator11.return != null) {
1076
- _iterator11.return();
978
+ if (!_iteratorNormalCompletion12 && _iterator12.return != null) {
979
+ _iterator12.return();
1077
980
  }
1078
981
  } finally {
1079
- if (_didIteratorError11) {
1080
- throw _iteratorError11;
982
+ if (_didIteratorError12) {
983
+ throw _iteratorError12;
1081
984
  }
1082
985
  }
1083
986
  }
@@ -1107,6 +1010,34 @@ function (_RecordQueryResult) {
1107
1010
  }
1108
1011
  /** @internal */
1109
1012
 
1013
+ }, {
1014
+ key: "_onCellValuesChanged",
1015
+ value: function _onCellValuesChanged(table, key, updates) {
1016
+ if (!updates) {
1017
+ // If there are no updates, do nothing, since we'll handle the initial
1018
+ // callback when the record set is loaded (and we don't want to fire
1019
+ // a cellValues change twice with no data).
1020
+ return;
1021
+ }
1022
+
1023
+ this._onChange(_record_query_result.default.WatchableKeys.cellValues, updates);
1024
+ }
1025
+ /** @internal */
1026
+
1027
+ }, {
1028
+ key: "_onCellValuesInFieldChanged",
1029
+ value: function _onCellValuesInFieldChanged(table, key, recordIds, fieldId) {
1030
+ if (!recordIds && !fieldId) {
1031
+ // If there are no updates, do nothing, since we'll handle the initial
1032
+ // callback when the record set is loaded (and we don't want to fire
1033
+ // a cellValuesInField change twice with no data).
1034
+ return;
1035
+ }
1036
+
1037
+ this._onChange(key, recordIds, fieldId);
1038
+ }
1039
+ /** @internal */
1040
+
1110
1041
  }, {
1111
1042
  key: "_generateOrderedRecordIds",
1112
1043
  value: function _generateOrderedRecordIds() {
@@ -1124,6 +1055,7 @@ function (_RecordQueryResult) {
1124
1055
  value: function _generateAndLoadOrderedGroups() {
1125
1056
  // istanbul ignore next
1126
1057
  if (this._groupLevels) {
1058
+ (0, _error_utils.invariant)(this._visList, 'Cannot generate record ids without a vis list');
1127
1059
  throw (0, _error_utils.spawnError)('custom group configs not supported');
1128
1060
  } else {
1129
1061
  // Get the group from the view itself
@@ -1149,26 +1081,26 @@ function (_RecordQueryResult) {
1149
1081
  key: "_unloadOrderedGroupsIfNeeded",
1150
1082
  value: function _unloadOrderedGroupsIfNeeded() {
1151
1083
  if (this._orderedGroups) {
1152
- var _iteratorNormalCompletion12 = true;
1153
- var _didIteratorError12 = false;
1154
- var _iteratorError12 = undefined;
1084
+ var _iteratorNormalCompletion13 = true;
1085
+ var _didIteratorError13 = false;
1086
+ var _iteratorError13 = undefined;
1155
1087
 
1156
1088
  try {
1157
- for (var _iterator12 = this._orderedGroups[Symbol.iterator](), _step12; !(_iteratorNormalCompletion12 = (_step12 = _iterator12.next()).done); _iteratorNormalCompletion12 = true) {
1158
- var group = _step12.value;
1089
+ for (var _iterator13 = this._orderedGroups[Symbol.iterator](), _step13; !(_iteratorNormalCompletion13 = (_step13 = _iterator13.next()).done); _iteratorNormalCompletion13 = true) {
1090
+ var group = _step13.value;
1159
1091
  group.unloadData();
1160
1092
  }
1161
1093
  } catch (err) {
1162
- _didIteratorError12 = true;
1163
- _iteratorError12 = err;
1094
+ _didIteratorError13 = true;
1095
+ _iteratorError13 = err;
1164
1096
  } finally {
1165
1097
  try {
1166
- if (!_iteratorNormalCompletion12 && _iterator12.return != null) {
1167
- _iterator12.return();
1098
+ if (!_iteratorNormalCompletion13 && _iterator13.return != null) {
1099
+ _iterator13.return();
1168
1100
  }
1169
1101
  } finally {
1170
- if (_didIteratorError12) {
1171
- throw _iteratorError12;
1102
+ if (_didIteratorError13) {
1103
+ throw _iteratorError13;
1172
1104
  }
1173
1105
  }
1174
1106
  }
@@ -1176,21 +1108,24 @@ function (_RecordQueryResult) {
1176
1108
  }
1177
1109
  /**
1178
1110
  * If groupings change then some groups will need to be created, and some removed
1179
- * Triggers the WatchableKeys.group, as by necessity this will have changed.
1180
- * TODO: This _should_ handle the diffing necessary to unload, and reload only the changed groups.
1111
+ * This (TODO: will) handle the diffing necessary to unload, and reload only the changed groups.
1112
+ * Also triggers the WatchableKeys.group, as by necessity this will have changed.
1181
1113
  *
1182
1114
  * @internal
1183
1115
  */
1184
1116
  // TODO: (SeanKeenan) Properly diff and only unload groups that need to be unloaded
1185
1117
  // In the meantime it's not too expensive to just unload everything, and GroupedRecordQueryResults
1186
1118
  // don't yet properly watch changes relevant to updating, so this isn't too bad.
1119
+ // (They do invalidate their recordId caches, which is some very cheap work that we could remove)
1187
1120
 
1188
1121
  }, {
1189
- key: "_unloadGroups",
1190
- value: function _unloadGroups() {
1122
+ key: "_unloadRemovedGroupsAndLoadNewGroupsAndTriggerWatches",
1123
+ value: function _unloadRemovedGroupsAndLoadNewGroupsAndTriggerWatches() {
1191
1124
  this._unloadOrderedGroupsIfNeeded();
1192
1125
 
1193
- this._orderedGroups = null;
1126
+ this._orderedGroups = this._generateAndLoadOrderedGroups();
1127
+
1128
+ this._onChange(_record_query_result.default.WatchableKeys.groups);
1194
1129
  }
1195
1130
  /** @internal */
1196
1131
 
@@ -1198,14 +1133,15 @@ function (_RecordQueryResult) {
1198
1133
  key: "_replaceVisList",
1199
1134
  value: function _replaceVisList() {
1200
1135
  var airtableInterface = this._sdk.__airtableInterface;
1136
+ var appInterface = this._sdk.__appInterface;
1201
1137
 
1202
- var recordIds = this._sourceModelRecords.map(record => record.id);
1138
+ var recordDatas = this._sourceModelRecords.map(record => record._data);
1203
1139
 
1204
1140
  var fieldDatas = this._table.fields.map(field => field._data);
1205
1141
 
1206
1142
  var filteredSorts = this._getSortsWithDeletedFieldsFiltered();
1207
1143
 
1208
- this._visList = airtableInterface.createVisListWithRecordIds(recordIds, fieldDatas, filteredSorts, this._table.id);
1144
+ this._visList = airtableInterface.createVisList(appInterface, recordDatas, fieldDatas, filteredSorts);
1209
1145
  }
1210
1146
  /** @internal */
1211
1147
 
@@ -1231,31 +1167,6 @@ function (_RecordQueryResult) {
1231
1167
  var sourceModelName = this._sourceModel instanceof _table.default ? 'table' : 'view';
1232
1168
  return (0, _error_utils.spawnError)("RecordQueryResult's underlying %s has been deleted", sourceModelName);
1233
1169
  }
1234
- /** @internal */
1235
-
1236
- }, {
1237
- key: "__constructQuerySpecForBlockFieldSelectionSpec",
1238
- value: function __constructQuerySpecForBlockFieldSelectionSpec(fieldSelection) {
1239
- if (this._sourceModel instanceof _view.default) {
1240
- return {
1241
- sourceType: _block_query_spec.BlockQuerySourceType.VIEW,
1242
- sourceTableId: this._table.id,
1243
- sourceViewId: this._sourceModel.id,
1244
- recordSelection: {
1245
- fieldSelection
1246
- },
1247
- viewMetadataSelection: {}
1248
- };
1249
- } else {
1250
- return {
1251
- sourceType: _block_query_spec.BlockQuerySourceType.TABLE,
1252
- sourceTableId: this._table.id,
1253
- recordSelection: {
1254
- fieldSelection
1255
- }
1256
- };
1257
- }
1258
- }
1259
1170
  }, {
1260
1171
  key: "_dataOrNullIfDeleted",
1261
1172
  get: function get() {
@@ -1264,7 +1175,9 @@ function (_RecordQueryResult) {
1264
1175
  }
1265
1176
 
1266
1177
  return {
1267
- recordIds: this._orderedRecordIds
1178
+ recordIds: this._orderedRecordIds,
1179
+ groups: this._orderedGroups,
1180
+ groupLevels: this._loadedGroupLevels
1268
1181
  };
1269
1182
  }
1270
1183
  /** @internal */
@@ -1318,10 +1231,8 @@ function (_RecordQueryResult) {
1318
1231
  var recordIds = this._data.recordIds; // Throws when the model has been deleted.
1319
1232
 
1320
1233
  (0, _error_utils.invariant)(this.isDataLoaded, 'RecordQueryResult data is not loaded');
1321
- (0, _error_utils.invariant)(recordIds, 'No recordIds'); // TODO: (#proj-blocks-sdk-record-limits) Change this to readonly upon the
1322
- // next breaking change.
1323
-
1324
- return [...recordIds];
1234
+ (0, _error_utils.invariant)(recordIds, 'No recordIds');
1235
+ return recordIds;
1325
1236
  }
1326
1237
  /**
1327
1238
  * The ordered GroupedRecordQueryResult's in this RecordQueryResult.
@@ -1334,19 +1245,12 @@ function (_RecordQueryResult) {
1334
1245
  }, {
1335
1246
  key: "groups",
1336
1247
  get: function get() {
1337
- var _this$_orderedGroups;
1338
-
1339
1248
  // The following statements have been carefully sequenced to ensure
1340
1249
  // that when this method fails, it reports the most salient error.
1341
- (0, _error_utils.invariant)(this._data, 'RecordQueryResult must not be deleted'); // Throws when the model has been deleted.
1250
+ var groups = this._data.groups; // Throws when the model has been deleted.
1342
1251
 
1343
1252
  (0, _error_utils.invariant)(this.isDataLoaded, 'RecordQueryResult data is not loaded');
1344
-
1345
- if (!this._orderedGroups) {
1346
- this._orderedGroups = this._generateAndLoadOrderedGroups();
1347
- }
1348
-
1349
- return (_this$_orderedGroups = this._orderedGroups) !== null && _this$_orderedGroups !== void 0 ? _this$_orderedGroups : null;
1253
+ return groups !== null && groups !== void 0 ? groups : null;
1350
1254
  }
1351
1255
  /**
1352
1256
  * The GroupLevels in this RecordQueryResult.
@@ -1359,15 +1263,10 @@ function (_RecordQueryResult) {
1359
1263
  }, {
1360
1264
  key: "groupLevels",
1361
1265
  get: function get() {
1362
- (0, _error_utils.invariant)(this._data, 'RecordQueryResult must not be deleted'); // Throws when the model has been deleted.
1266
+ var groupLevels = this._data.groupLevels; // Throws when the model has been deleted.
1363
1267
 
1364
1268
  (0, _error_utils.invariant)(this.isDataLoaded, 'RecordQueryResult data is not loaded');
1365
-
1366
- if (!this._loadedGroupLevels) {
1367
- this._loadedGroupLevels = this._sourceModelGroupLevels;
1368
- }
1369
-
1370
- return this._loadedGroupLevels ? this._loadedGroupLevels.map(singleLevel => _objectSpread({}, singleLevel, {
1269
+ return groupLevels ? groupLevels.map(singleLevel => _objectSpread({}, singleLevel, {
1371
1270
  field: this.parentTable.getFieldById(singleLevel.fieldId)
1372
1271
  })) : null;
1373
1272
  }
@@ -1382,13 +1281,13 @@ function (_RecordQueryResult) {
1382
1281
  // using RecordQueryResult) if the user had to manually watch for deletion
1383
1282
  // on all the fields and recreate the RecordQueryResult.
1384
1283
 
1385
- var _iteratorNormalCompletion13 = true;
1386
- var _didIteratorError13 = false;
1387
- var _iteratorError13 = undefined;
1284
+ var _iteratorNormalCompletion14 = true;
1285
+ var _didIteratorError14 = false;
1286
+ var _iteratorError14 = undefined;
1388
1287
 
1389
1288
  try {
1390
- for (var _iterator13 = fieldIdsOrNullIfAllFields[Symbol.iterator](), _step13; !(_iteratorNormalCompletion13 = (_step13 = _iterator13.next()).done); _iteratorNormalCompletion13 = true) {
1391
- var fieldId = _step13.value;
1289
+ for (var _iterator14 = fieldIdsOrNullIfAllFields[Symbol.iterator](), _step14; !(_iteratorNormalCompletion14 = (_step14 = _iterator14.next()).done); _iteratorNormalCompletion14 = true) {
1290
+ var fieldId = _step14.value;
1392
1291
 
1393
1292
  var field = this._table.getFieldByIdIfExists(fieldId);
1394
1293
 
@@ -1397,16 +1296,16 @@ function (_RecordQueryResult) {
1397
1296
  }
1398
1297
  }
1399
1298
  } catch (err) {
1400
- _didIteratorError13 = true;
1401
- _iteratorError13 = err;
1299
+ _didIteratorError14 = true;
1300
+ _iteratorError14 = err;
1402
1301
  } finally {
1403
1302
  try {
1404
- if (!_iteratorNormalCompletion13 && _iterator13.return != null) {
1405
- _iterator13.return();
1303
+ if (!_iteratorNormalCompletion14 && _iterator14.return != null) {
1304
+ _iterator14.return();
1406
1305
  }
1407
1306
  } finally {
1408
- if (_didIteratorError13) {
1409
- throw _iteratorError13;
1307
+ if (_didIteratorError14) {
1308
+ throw _iteratorError14;
1410
1309
  }
1411
1310
  }
1412
1311
  }
@@ -1460,12 +1359,6 @@ function (_RecordQueryResult) {
1460
1359
  get: function get() {
1461
1360
  return this._sourceModel instanceof _table.default ? this._recordStore.records : this._recordStore.getViewDataStore(this._sourceModel.id).visibleRecords;
1462
1361
  }
1463
- /**
1464
- * This is just a helper structure to better colocate watch and unwatch logic
1465
- *
1466
- * @internal
1467
- */
1468
-
1469
1362
  }]);
1470
1363
  return TableOrViewQueryResult;
1471
1364
  }(_record_query_result.default);