@airtable/blocks 1.11.0 → 1.11.1-experimental-68738f2-20220526
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/error_utils.js +27 -17
- package/dist/cjs/models/base.js +1 -1
- package/dist/cjs/models/cursor.js +4 -6
- package/dist/cjs/models/grouped_record_query_result.js +5 -14
- package/dist/cjs/models/linked_records_query_result.js +78 -27
- package/dist/cjs/models/mutations.js +18 -163
- package/dist/cjs/models/query_manager.js +328 -0
- package/dist/cjs/models/record.js +310 -55
- package/dist/cjs/models/record_query_result.js +4 -1
- package/dist/cjs/models/record_store.js +557 -775
- package/dist/cjs/models/table.js +6 -6
- package/dist/cjs/models/table_or_view_query_result.js +526 -419
- package/dist/cjs/models/view_data_store.js +255 -295
- package/dist/cjs/private_utils.js +40 -0
- package/dist/cjs/sdk.js +12 -2
- package/dist/cjs/testing/abstract_mock_airtable_interface.js +57 -11
- package/dist/cjs/testing/fixture_data.js +271 -0
- package/dist/cjs/testing/mock_base_data_stores.js +891 -0
- package/dist/cjs/types/airtable_interface.js +17 -2
- package/dist/cjs/types/block_query_spec.js +85 -0
- package/dist/cjs/ui/icon_config.js +4 -2
- package/dist/cjs/ui/use_records.js +5 -1
- package/dist/cjs/unstable_testing_utils.js +61 -1
- package/dist/cjs/watchable.js +15 -1
- package/dist/types/src/error_utils.d.ts +5 -2
- package/dist/types/src/error_utils.d.ts.map +1 -1
- package/dist/types/src/models/cursor.d.ts +4 -6
- package/dist/types/src/models/cursor.d.ts.map +1 -1
- package/dist/types/src/models/grouped_record_query_result.d.ts +3 -3
- package/dist/types/src/models/grouped_record_query_result.d.ts.map +1 -1
- package/dist/types/src/models/linked_records_query_result.d.ts.map +1 -1
- package/dist/types/src/models/mutations.d.ts.map +1 -1
- package/dist/types/src/models/query_manager.d.ts +2 -0
- package/dist/types/src/models/query_manager.d.ts.map +1 -0
- package/dist/types/src/models/record.d.ts +12 -3
- package/dist/types/src/models/record.d.ts.map +1 -1
- package/dist/types/src/models/record_query_result.d.ts +3 -2
- package/dist/types/src/models/record_query_result.d.ts.map +1 -1
- package/dist/types/src/models/record_store.d.ts.map +1 -1
- package/dist/types/src/models/table_or_view_query_result.d.ts +3 -5
- package/dist/types/src/models/table_or_view_query_result.d.ts.map +1 -1
- package/dist/types/src/models/view_data_store.d.ts +0 -1
- package/dist/types/src/models/view_data_store.d.ts.map +1 -1
- package/dist/types/src/models/view_metadata_query_result.d.ts +1 -1
- package/dist/types/src/models/view_metadata_query_result.d.ts.map +1 -1
- package/dist/types/src/private_utils.d.ts +24 -1
- package/dist/types/src/private_utils.d.ts.map +1 -1
- package/dist/types/src/sdk.d.ts.map +1 -1
- package/dist/types/src/testing/abstract_mock_airtable_interface.d.ts +11 -11
- package/dist/types/src/testing/abstract_mock_airtable_interface.d.ts.map +1 -1
- package/dist/types/{test/airtable_interface_mocks → src/testing}/fixture_data.d.ts +43 -19
- package/dist/types/src/testing/fixture_data.d.ts.map +1 -0
- package/dist/types/src/testing/mock_base_data_stores.d.ts +59 -0
- package/dist/types/src/testing/mock_base_data_stores.d.ts.map +1 -0
- package/dist/types/src/types/airtable_interface.d.ts +59 -20
- package/dist/types/src/types/airtable_interface.d.ts.map +1 -1
- package/dist/types/src/types/block_query_spec.d.ts +139 -0
- package/dist/types/src/types/block_query_spec.d.ts.map +1 -0
- package/dist/types/src/types/table.d.ts +0 -2
- package/dist/types/src/types/table.d.ts.map +1 -1
- package/dist/types/src/types/view.d.ts +3 -8
- package/dist/types/src/types/view.d.ts.map +1 -1
- package/dist/types/src/ui/icon_config.d.ts +5 -3
- package/dist/types/src/ui/icon_config.d.ts.map +1 -1
- package/dist/types/src/ui/record_card.d.ts +1 -1
- package/dist/types/src/unstable_testing_utils.d.ts +4 -1
- package/dist/types/src/unstable_testing_utils.d.ts.map +1 -1
- package/dist/types/src/watchable.d.ts.map +1 -1
- package/dist/types/test/airtable_interface_mocks/linked_records.d.ts +1 -1
- package/dist/types/test/airtable_interface_mocks/linked_records.d.ts.map +1 -1
- package/dist/types/test/airtable_interface_mocks/mock_airtable_interface.d.ts +19 -12
- package/dist/types/test/airtable_interface_mocks/mock_airtable_interface.d.ts.map +1 -1
- package/dist/types/test/airtable_interface_mocks/project_tracker.d.ts +1 -1
- package/dist/types/test/airtable_interface_mocks/project_tracker.d.ts.map +1 -1
- package/dist/types/test/test_helpers.d.ts +2 -0
- package/dist/types/test/test_helpers.d.ts.map +1 -1
- package/dist/types/test/testing/fixture_data.test.d.ts +2 -0
- package/dist/types/test/testing/fixture_data.test.d.ts.map +1 -0
- package/package.json +3 -2
- package/dist/types/test/airtable_interface_mocks/fixture_data.d.ts.map +0 -1
package/dist/cjs/error_utils.js
CHANGED
|
@@ -1,18 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
require("core-js/modules/es.array.iterator");
|
|
4
|
-
|
|
5
3
|
require("core-js/modules/es.string.replace");
|
|
6
4
|
|
|
7
|
-
require("core-js/modules/web.dom-collections.iterator");
|
|
8
|
-
|
|
9
5
|
Object.defineProperty(exports, "__esModule", {
|
|
10
6
|
value: true
|
|
11
7
|
});
|
|
12
8
|
exports.spawnError = spawnError;
|
|
13
|
-
exports.
|
|
9
|
+
exports.logErrorToSentry = logErrorToSentry;
|
|
14
10
|
exports.invariant = invariant;
|
|
15
11
|
exports.spawnUnknownSwitchCaseError = spawnUnknownSwitchCaseError;
|
|
12
|
+
exports.spawnExhaustiveSwitchError = spawnExhaustiveSwitchError;
|
|
16
13
|
exports.spawnAbstractMethodError = spawnAbstractMethodError;
|
|
17
14
|
|
|
18
15
|
// If errorOriginFn is specified, all frames above and including the call to errorOriginFn
|
|
@@ -60,22 +57,19 @@ function spawnError(errorMessageFormat) {
|
|
|
60
57
|
} // istanbul ignore next
|
|
61
58
|
|
|
62
59
|
/**
|
|
63
|
-
* Logs an error to
|
|
60
|
+
* Logs an error to Sentry. This is currently unused while the SDK is in the experimental status,
|
|
61
|
+
* but we leave the definition here for future usage needs.
|
|
64
62
|
*
|
|
65
63
|
* @hidden
|
|
66
64
|
*/
|
|
67
65
|
|
|
68
66
|
|
|
69
|
-
function
|
|
70
|
-
// See this comment for how to log via
|
|
71
|
-
var
|
|
72
|
-
|
|
73
|
-
if (rollbar === null || rollbar === void 0 ? void 0 : rollbar.warn) {
|
|
74
|
-
for (var _len2 = arguments.length, errorMessageArgs = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
|
75
|
-
errorMessageArgs[_key2 - 1] = arguments[_key2];
|
|
76
|
-
}
|
|
67
|
+
function logErrorToSentry(errorMessage, metadata) {
|
|
68
|
+
// See this comment for how to log via Sentry: https://github.com/Hyperbase/hyperbase/blob/2c5438ecaddcb9fa196e027e40df5e0c68c90989/client/run_block_frame.tsx#L333
|
|
69
|
+
var blocksErrorReporter = window.blocksErrorReporter;
|
|
77
70
|
|
|
78
|
-
|
|
71
|
+
if (blocksErrorReporter === null || blocksErrorReporter === void 0 ? void 0 : blocksErrorReporter.reportWarning) {
|
|
72
|
+
blocksErrorReporter.reportWarning(errorMessage, metadata);
|
|
79
73
|
}
|
|
80
74
|
}
|
|
81
75
|
/**
|
|
@@ -87,8 +81,8 @@ function logErrorToRollbar(errorMessageFormat) {
|
|
|
87
81
|
|
|
88
82
|
function invariant(condition, errorMessageFormat) {
|
|
89
83
|
if (!condition) {
|
|
90
|
-
for (var
|
|
91
|
-
errorMessageArgs[
|
|
84
|
+
for (var _len2 = arguments.length, errorMessageArgs = new Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) {
|
|
85
|
+
errorMessageArgs[_key2 - 2] = arguments[_key2];
|
|
92
86
|
}
|
|
93
87
|
|
|
94
88
|
throw spawnErrorWithOriginOmittedFromStackTrace(errorMessageFormat, errorMessageArgs, invariant);
|
|
@@ -104,6 +98,22 @@ function spawnUnknownSwitchCaseError(valueDescription, providedValue, key) {
|
|
|
104
98
|
var providedValueKeyString = providedValueKey !== null && providedValueKey !== undefined ? providedValueKey : 'null';
|
|
105
99
|
return spawnErrorWithOriginOmittedFromStackTrace('Unknown value %s for %s', [providedValueKeyString, valueDescription], spawnUnknownSwitchCaseError);
|
|
106
100
|
}
|
|
101
|
+
/**
|
|
102
|
+
* Forces TypeScript to prove that calling this function is impossible at a
|
|
103
|
+
* type level by accepting `never`. In the unlikely case this function is
|
|
104
|
+
* called we infer a useful error message.
|
|
105
|
+
*
|
|
106
|
+
* @internal
|
|
107
|
+
*/
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
function spawnExhaustiveSwitchError(impossibleValue) {
|
|
111
|
+
if (impossibleValue === null) {
|
|
112
|
+
return spawnErrorWithOriginOmittedFromStackTrace('Unexpected null in exhaustive switch', undefined, spawnExhaustiveSwitchError);
|
|
113
|
+
} else {
|
|
114
|
+
return spawnErrorWithOriginOmittedFromStackTrace("Unexpected %s in exhaustive switch", [typeof impossibleValue], spawnExhaustiveSwitchError);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
107
117
|
/**
|
|
108
118
|
* @internal
|
|
109
119
|
*/
|
package/dist/cjs/models/base.js
CHANGED
|
@@ -607,7 +607,7 @@ function (_AbstractModel) {
|
|
|
607
607
|
value: function getMaxRecordsPerTable() {
|
|
608
608
|
var _this$_data$maxRowsPe;
|
|
609
609
|
|
|
610
|
-
return (_this$_data$maxRowsPe = this._data.maxRowsPerTable) !== null && _this$_data$maxRowsPe !== void 0 ? _this$_data$maxRowsPe :
|
|
610
|
+
return (_this$_data$maxRowsPe = this._data.maxRowsPerTable) !== null && _this$_data$maxRowsPe !== void 0 ? _this$_data$maxRowsPe : 100000;
|
|
611
611
|
}
|
|
612
612
|
/**
|
|
613
613
|
* @internal
|
|
@@ -268,9 +268,8 @@ function (_AbstractModelWithAsy) {
|
|
|
268
268
|
key: "setActiveTable",
|
|
269
269
|
|
|
270
270
|
/**
|
|
271
|
-
* Sets the specified table to active in the Airtable UI. If the
|
|
272
|
-
*
|
|
273
|
-
* fullscreen.
|
|
271
|
+
* Sets the specified table to active in the Airtable UI. If the app installation or apps pane
|
|
272
|
+
* is fullscreen, fullscreen mode will be exited.
|
|
274
273
|
*
|
|
275
274
|
* @param tableOrTableId The target table or table ID to set as active in the Airtable main page.
|
|
276
275
|
*/
|
|
@@ -280,9 +279,8 @@ function (_AbstractModelWithAsy) {
|
|
|
280
279
|
this._sdk.__airtableInterface.setActiveViewOrTable(tableId);
|
|
281
280
|
}
|
|
282
281
|
/**
|
|
283
|
-
* Sets the specified view (and corresponding table) to active in the Airtable UI. If the
|
|
284
|
-
* pane is fullscreen,
|
|
285
|
-
* to be displayed fullscreen.
|
|
282
|
+
* Sets the specified view (and corresponding table) to active in the Airtable UI. If the app
|
|
283
|
+
* installation or apps pane is fullscreen, fullscreen mode will be exited.
|
|
286
284
|
*
|
|
287
285
|
* @param tableOrTableId The table or table ID that the target view belongs to.
|
|
288
286
|
* @param viewOrViewId The target view or view ID to set as active in the Airtable main page.
|
|
@@ -245,19 +245,13 @@ function (_RecordQueryResult) {
|
|
|
245
245
|
while (1) {
|
|
246
246
|
switch (_context2.prev = _context2.next) {
|
|
247
247
|
case 0:
|
|
248
|
-
|
|
249
|
-
//
|
|
250
|
-
|
|
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
|
|
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
|
-
//
|
|
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).
|
|
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 =
|
|
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 =
|
|
342
|
+
_context2.next = 25;
|
|
322
343
|
break;
|
|
323
344
|
|
|
324
|
-
case
|
|
325
|
-
_context2.prev =
|
|
326
|
-
_context2.t0 = _context2["catch"](
|
|
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
|
|
331
|
-
_context2.prev =
|
|
332
|
-
_context2.prev =
|
|
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
|
|
339
|
-
_context2.prev =
|
|
359
|
+
case 28:
|
|
360
|
+
_context2.prev = 28;
|
|
340
361
|
|
|
341
362
|
if (!_didIteratorError3) {
|
|
342
|
-
_context2.next =
|
|
363
|
+
_context2.next = 31;
|
|
343
364
|
break;
|
|
344
365
|
}
|
|
345
366
|
|
|
346
367
|
throw _iteratorError3;
|
|
347
368
|
|
|
348
|
-
case
|
|
349
|
-
return _context2.finish(
|
|
369
|
+
case 31:
|
|
370
|
+
return _context2.finish(28);
|
|
350
371
|
|
|
351
|
-
case
|
|
352
|
-
return _context2.finish(
|
|
372
|
+
case 32:
|
|
373
|
+
return _context2.finish(25);
|
|
353
374
|
|
|
354
|
-
case
|
|
375
|
+
case 33:
|
|
355
376
|
return _context2.abrupt("return", changedKeys);
|
|
356
377
|
|
|
357
|
-
case
|
|
378
|
+
case 34:
|
|
358
379
|
case "end":
|
|
359
380
|
return _context2.stop();
|
|
360
381
|
}
|
|
361
382
|
}
|
|
362
|
-
}, null, this, [[
|
|
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
|
-
|
|
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.
|
|
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
|
|
|
@@ -597,11 +626,12 @@ function (_RecordQueryResult) {
|
|
|
597
626
|
if (Array.isArray(recordIds)) {
|
|
598
627
|
var recordIdsSet = this._getOrGenerateRecordIdsSet();
|
|
599
628
|
|
|
600
|
-
var filteredRecordIds = recordIds.filter(id => typeof id === 'string' && recordIdsSet[id] === true);
|
|
629
|
+
var filteredRecordIds = recordIds.filter(id => typeof id === 'string' && recordIdsSet[id] === true); // There should always be a filteredRecordIds found for this query
|
|
630
|
+
// type - not finding any is a fundamental mistake in our query engine
|
|
601
631
|
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
632
|
+
(0, _error_utils.invariant)(filteredRecordIds.length, 'Filtered record change on incorrect record, query engine issue');
|
|
633
|
+
|
|
634
|
+
this._onChange(_record_query_result.default.WatchableCellValuesInFieldKeyPrefix + fieldId, filteredRecordIds);
|
|
605
635
|
} else {
|
|
606
636
|
this._onChange(_record_query_result.default.WatchableCellValuesInFieldKeyPrefix + fieldId);
|
|
607
637
|
}
|
|
@@ -785,6 +815,27 @@ function (_RecordQueryResult) {
|
|
|
785
815
|
(0, _error_utils.invariant)(recordIdsSet, 'recordIdsSet must exist');
|
|
786
816
|
return recordIdsSet;
|
|
787
817
|
}
|
|
818
|
+
/**
|
|
819
|
+
* This allows a record query result to specify the source of the query
|
|
820
|
+
* eg: View, Table, Linked record when watching fields.
|
|
821
|
+
* This scopes the watch to those fields + rows in the query.
|
|
822
|
+
*
|
|
823
|
+
* @internal
|
|
824
|
+
*/
|
|
825
|
+
|
|
826
|
+
}, {
|
|
827
|
+
key: "__constructQuerySpecForBlockFieldSelectionSpec",
|
|
828
|
+
value: function __constructQuerySpecForBlockFieldSelectionSpec(fieldSelection) {
|
|
829
|
+
// The origin tableId is always the one referred to here as we must watch the origin record for deletion
|
|
830
|
+
var originTableId = this._record.parentTable.id;
|
|
831
|
+
return {
|
|
832
|
+
sourceType: _block_query_spec.BlockQuerySourceType.TABLE,
|
|
833
|
+
sourceTableId: originTableId,
|
|
834
|
+
recordSelection: {
|
|
835
|
+
fieldSelection
|
|
836
|
+
}
|
|
837
|
+
};
|
|
838
|
+
}
|
|
788
839
|
}, {
|
|
789
840
|
key: "isValid",
|
|
790
841
|
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,
|
|
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 */
|
|
@@ -290,9 +274,12 @@ function () {
|
|
|
290
274
|
try {
|
|
291
275
|
for (var _iterator = records[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
292
276
|
var record = _step.value;
|
|
293
|
-
var existingRecord = null;
|
|
277
|
+
var existingRecord = null; // Note - if isSubscribedToAllRecordsInTable is true then we know the record
|
|
278
|
+
// doesn't exist (or is deleted) but otherwise we can issue a mutation to a record
|
|
279
|
+
// that does not exist, having to deal with the error thrown by PublicAirtableInterfaceFrontend
|
|
280
|
+
// TODO: (#proj-blocks-sdk-record-limits) Write tests around this behavior
|
|
294
281
|
|
|
295
|
-
if (recordStore.
|
|
282
|
+
if (recordStore.isSubscribedToAllRecordsInTable || recordStore.isRecordLoaded(record.id)) {
|
|
296
283
|
existingRecord = recordStore.getRecordByIdIfExists(record.id);
|
|
297
284
|
|
|
298
285
|
if (!existingRecord) {
|
|
@@ -314,7 +301,7 @@ function () {
|
|
|
314
301
|
checkedFieldIds.add(fieldId);
|
|
315
302
|
}
|
|
316
303
|
|
|
317
|
-
if (existingRecord && recordStore.
|
|
304
|
+
if (existingRecord && recordStore.isRecordCellValueLoadedForFieldId(record.id, fieldId)) {
|
|
318
305
|
var validationResult = this._airtableInterface.fieldTypeProvider.validateCellValueForUpdate(appInterface, record.cellValuesByFieldId[fieldId], existingRecord._getRawCellValue(field), field._data);
|
|
319
306
|
|
|
320
307
|
if (!validationResult.isValid) {
|
|
@@ -352,9 +339,15 @@ function () {
|
|
|
352
339
|
throw (0, _error_utils.spawnError)("Can't delete records: No table with id %s exists", _tableId);
|
|
353
340
|
}
|
|
354
341
|
|
|
355
|
-
var _recordStore = this._base.__getRecordStore(_tableId);
|
|
342
|
+
var _recordStore = this._base.__getRecordStore(_tableId); // TODO: (#proj-blocks-sdk-record-limits) We substantially weaken our check here
|
|
343
|
+
// because we can only be sure if the record exists inside the SDK if we've loaded
|
|
344
|
+
// all records. It is possible to change this logic to ensure we don't double-delete
|
|
345
|
+
// records by caching previously deleted records (if the delete is undone, but
|
|
346
|
+
// we're not watching the record be re-created from the undo we would have to fail
|
|
347
|
+
// the delete if we detect double deletion). TODO to add tests around this behavior.
|
|
348
|
+
|
|
356
349
|
|
|
357
|
-
if (_recordStore.
|
|
350
|
+
if (_recordStore.isSubscribedToAllRecordsInTable) {
|
|
358
351
|
var _iteratorNormalCompletion2 = true;
|
|
359
352
|
var _didIteratorError2 = false;
|
|
360
353
|
var _iteratorError2 = undefined;
|
|
@@ -708,151 +701,13 @@ function () {
|
|
|
708
701
|
this._applyGlobalConfigUpdates(mutation.updates);
|
|
709
702
|
|
|
710
703
|
return true;
|
|
711
|
-
}
|
|
712
|
-
|
|
713
|
-
|
|
704
|
+
} // https://airtable.com/appahuJQw7qfQTBBU/tblSbpimM8Spp9txp/viweAFIus3MhU9Gxa/recHOckY4V9QmM6JV?blocks=hide
|
|
705
|
+
// TODO: (#proj-blocks-sdk-record-limits) Fix this in a future stacked diff where optimistic
|
|
706
|
+
// updates are re-enabled https://docs.google.com/document/d/1CVZ4ZoPWEtpzKq_9cRLASGwgY71WI4nl6RVvs8S7Ubw/edit#
|
|
714
707
|
|
|
715
|
-
if (modelChanges.length > 0) {
|
|
716
|
-
this._applyModelChanges(modelChanges);
|
|
717
|
-
|
|
718
|
-
return true;
|
|
719
|
-
}
|
|
720
708
|
|
|
721
709
|
return false;
|
|
722
710
|
}
|
|
723
|
-
/** @internal */
|
|
724
|
-
|
|
725
|
-
}, {
|
|
726
|
-
key: "_getOptimisticModelChangesForMutation",
|
|
727
|
-
value: function _getOptimisticModelChangesForMutation(mutation) {
|
|
728
|
-
switch (mutation.type) {
|
|
729
|
-
case _mutations.MutationTypes.SET_MULTIPLE_RECORDS_CELL_VALUES:
|
|
730
|
-
{
|
|
731
|
-
var tableId = mutation.tableId,
|
|
732
|
-
records = mutation.records;
|
|
733
|
-
|
|
734
|
-
var recordStore = this._base.__getRecordStore(tableId);
|
|
735
|
-
|
|
736
|
-
return records.flatMap(record => Object.keys(record.cellValuesByFieldId).filter(fieldId => recordStore.areCellValuesLoadedForFieldId(fieldId)).map(fieldId => ({
|
|
737
|
-
path: ['tablesById', tableId, 'recordsById', record.id, 'cellValuesByFieldId', fieldId],
|
|
738
|
-
value: record.cellValuesByFieldId[fieldId]
|
|
739
|
-
})));
|
|
740
|
-
}
|
|
741
|
-
|
|
742
|
-
case _mutations.MutationTypes.DELETE_MULTIPLE_RECORDS:
|
|
743
|
-
{
|
|
744
|
-
var _tableId8 = mutation.tableId,
|
|
745
|
-
recordIds = mutation.recordIds;
|
|
746
|
-
|
|
747
|
-
var _recordStore2 = this._base.__getRecordStore(_tableId8);
|
|
748
|
-
|
|
749
|
-
if (!_recordStore2.isRecordMetadataLoaded) {
|
|
750
|
-
return [];
|
|
751
|
-
}
|
|
752
|
-
|
|
753
|
-
return [...recordIds.map(recordId => ({
|
|
754
|
-
path: ['tablesById', _tableId8, 'recordsById', recordId],
|
|
755
|
-
value: undefined
|
|
756
|
-
})), ...this._base.getTableById(_tableId8).views.flatMap(view => {
|
|
757
|
-
var viewDataStore = _recordStore2.getViewDataStore(view.id);
|
|
758
|
-
|
|
759
|
-
if (!viewDataStore.isDataLoaded) {
|
|
760
|
-
return [];
|
|
761
|
-
}
|
|
762
|
-
|
|
763
|
-
return viewDataStore.__generateChangesForParentTableDeleteMultipleRecords(recordIds);
|
|
764
|
-
})];
|
|
765
|
-
}
|
|
766
|
-
|
|
767
|
-
case _mutations.MutationTypes.CREATE_MULTIPLE_RECORDS:
|
|
768
|
-
{
|
|
769
|
-
var _tableId9 = mutation.tableId,
|
|
770
|
-
_records2 = mutation.records;
|
|
771
|
-
|
|
772
|
-
var _recordStore3 = this._base.__getRecordStore(_tableId9);
|
|
773
|
-
|
|
774
|
-
if (!_recordStore3.isRecordMetadataLoaded) {
|
|
775
|
-
return [];
|
|
776
|
-
}
|
|
777
|
-
|
|
778
|
-
return [..._records2.map(record => {
|
|
779
|
-
// Only apply optimistic changes for fields that are loaded
|
|
780
|
-
var filteredCellValuesByFieldId = {};
|
|
781
|
-
var _iteratorNormalCompletion5 = true;
|
|
782
|
-
var _didIteratorError5 = false;
|
|
783
|
-
var _iteratorError5 = undefined;
|
|
784
|
-
|
|
785
|
-
try {
|
|
786
|
-
for (var _iterator5 = (0, _private_utils.entries)(record.cellValuesByFieldId)[Symbol.iterator](), _step5; !(_iteratorNormalCompletion5 = (_step5 = _iterator5.next()).done); _iteratorNormalCompletion5 = true) {
|
|
787
|
-
var _step5$value = (0, _slicedToArray2.default)(_step5.value, 2),
|
|
788
|
-
fieldId = _step5$value[0],
|
|
789
|
-
cellValue = _step5$value[1];
|
|
790
|
-
|
|
791
|
-
if (_recordStore3.areCellValuesLoadedForFieldId(fieldId)) {
|
|
792
|
-
filteredCellValuesByFieldId[fieldId] = cellValue;
|
|
793
|
-
}
|
|
794
|
-
}
|
|
795
|
-
} catch (err) {
|
|
796
|
-
_didIteratorError5 = true;
|
|
797
|
-
_iteratorError5 = err;
|
|
798
|
-
} finally {
|
|
799
|
-
try {
|
|
800
|
-
if (!_iteratorNormalCompletion5 && _iterator5.return != null) {
|
|
801
|
-
_iterator5.return();
|
|
802
|
-
}
|
|
803
|
-
} finally {
|
|
804
|
-
if (_didIteratorError5) {
|
|
805
|
-
throw _iteratorError5;
|
|
806
|
-
}
|
|
807
|
-
}
|
|
808
|
-
}
|
|
809
|
-
|
|
810
|
-
return {
|
|
811
|
-
path: ['tablesById', _tableId9, 'recordsById', record.id],
|
|
812
|
-
value: {
|
|
813
|
-
id: record.id,
|
|
814
|
-
cellValuesByFieldId: filteredCellValuesByFieldId,
|
|
815
|
-
commentCount: 0,
|
|
816
|
-
createdTime: new Date().toJSON()
|
|
817
|
-
}
|
|
818
|
-
};
|
|
819
|
-
}), ...this._base.getTableById(_tableId9).views.flatMap(view => {
|
|
820
|
-
var viewDataStore = _recordStore3.getViewDataStore(view.id);
|
|
821
|
-
|
|
822
|
-
if (!viewDataStore.isDataLoaded) {
|
|
823
|
-
return [];
|
|
824
|
-
}
|
|
825
|
-
|
|
826
|
-
return viewDataStore.__generateChangesForParentTableAddMultipleRecords(_records2.map(record => record.id));
|
|
827
|
-
})];
|
|
828
|
-
}
|
|
829
|
-
// The following branch is unreachable because this method's only
|
|
830
|
-
// call site is preceded by an explicit guard for this condition.
|
|
831
|
-
// istanbul ignore next
|
|
832
|
-
|
|
833
|
-
case _mutations.MutationTypes.SET_MULTIPLE_GLOBAL_CONFIG_PATHS:
|
|
834
|
-
{
|
|
835
|
-
throw (0, _error_utils.spawnError)('attempting to generate model updates for SET_MULTIPLE_GLOBAL_CONFIG_PATH');
|
|
836
|
-
}
|
|
837
|
-
|
|
838
|
-
case _mutations.MutationTypes.CREATE_SINGLE_FIELD:
|
|
839
|
-
case _mutations.MutationTypes.UPDATE_SINGLE_FIELD_CONFIG:
|
|
840
|
-
case _mutations.MutationTypes.UPDATE_SINGLE_FIELD_DESCRIPTION:
|
|
841
|
-
case _mutations.MutationTypes.UPDATE_SINGLE_FIELD_NAME:
|
|
842
|
-
case _mutations.MutationTypes.UPDATE_VIEW_METADATA:
|
|
843
|
-
case _mutations.MutationTypes.CREATE_SINGLE_TABLE:
|
|
844
|
-
{
|
|
845
|
-
// No optimistic updates for field, view metadata, or table mutations.
|
|
846
|
-
return [];
|
|
847
|
-
}
|
|
848
|
-
// The following branch is unreachable because this method's only
|
|
849
|
-
// call site is preceded by an explicit guard for this condition.
|
|
850
|
-
// istanbul ignore next
|
|
851
|
-
|
|
852
|
-
default:
|
|
853
|
-
throw (0, _error_utils.spawnUnknownSwitchCaseError)('mutation type', mutation, 'type');
|
|
854
|
-
}
|
|
855
|
-
}
|
|
856
711
|
}]);
|
|
857
712
|
return Mutations;
|
|
858
713
|
}();
|