@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.
- package/CHANGELOG.md +12 -1
- package/dist/cjs/error_utils.js +9 -34
- package/dist/cjs/models/base.js +15 -0
- package/dist/cjs/models/field.js +99 -4
- package/dist/cjs/models/grouped_record_query_result.js +14 -5
- package/dist/cjs/models/linked_records_query_result.js +44 -86
- package/dist/cjs/models/mutations.js +234 -53
- package/dist/cjs/models/record.js +55 -310
- package/dist/cjs/models/record_query_result.js +1 -4
- package/dist/cjs/models/record_store.js +779 -557
- package/dist/cjs/models/table.js +6 -6
- package/dist/cjs/models/table_or_view_query_result.js +419 -526
- package/dist/cjs/models/view_data_store.js +295 -255
- package/dist/cjs/private_utils.js +0 -40
- package/dist/cjs/sdk.js +2 -12
- package/dist/cjs/testing/abstract_mock_airtable_interface.js +11 -57
- package/dist/cjs/types/airtable_interface.js +2 -17
- package/dist/cjs/types/mutations.js +1 -0
- package/dist/cjs/ui/use_records.js +1 -5
- package/dist/cjs/unstable_testing_utils.js +1 -55
- package/dist/cjs/watchable.js +1 -15
- package/dist/types/src/error_utils.d.ts +4 -2
- package/dist/types/src/error_utils.d.ts.map +1 -1
- package/dist/types/src/models/base.d.ts +10 -0
- package/dist/types/src/models/base.d.ts.map +1 -1
- package/dist/types/src/models/field.d.ts +58 -0
- package/dist/types/src/models/field.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/record.d.ts +3 -12
- package/dist/types/src/models/record.d.ts.map +1 -1
- package/dist/types/src/models/record_query_result.d.ts +2 -3
- 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 +5 -3
- 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 +1 -0
- 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 +1 -24
- 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/src/types/airtable_interface.d.ts +20 -59
- package/dist/types/src/types/airtable_interface.d.ts.map +1 -1
- package/dist/types/src/types/base.d.ts +1 -0
- package/dist/types/src/types/base.d.ts.map +1 -1
- package/dist/types/src/types/mutations.d.ts +25 -2
- package/dist/types/src/types/mutations.d.ts.map +1 -1
- package/dist/types/src/types/table.d.ts +2 -0
- package/dist/types/src/types/table.d.ts.map +1 -1
- package/dist/types/src/types/view.d.ts +8 -3
- package/dist/types/src/types/view.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 +1 -4
- 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/{src/testing → test/airtable_interface_mocks}/fixture_data.d.ts +19 -42
- package/dist/types/test/airtable_interface_mocks/fixture_data.d.ts.map +1 -0
- 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 +12 -19
- 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 +0 -2
- package/dist/types/test/test_helpers.d.ts.map +1 -1
- package/package.json +1 -2
- package/dist/cjs/models/query_manager.js +0 -328
- package/dist/cjs/testing/fixture_data.js +0 -268
- package/dist/cjs/testing/mock_base_data_stores.js +0 -876
- package/dist/cjs/types/block_query_spec.js +0 -85
- package/dist/types/src/models/query_manager.d.ts +0 -2
- package/dist/types/src/models/query_manager.d.ts.map +0 -1
- package/dist/types/src/testing/fixture_data.d.ts.map +0 -1
- package/dist/types/src/testing/mock_base_data_stores.d.ts +0 -55
- package/dist/types/src/testing/mock_base_data_stores.d.ts.map +0 -1
- package/dist/types/src/types/block_query_spec.d.ts +0 -139
- package/dist/types/src/types/block_query_spec.d.ts.map +0 -1
- package/dist/types/test/testing/fixture_data.test.d.ts +0 -2
- package/dist/types/test/testing/fixture_data.test.d.ts.map +0 -1
|
@@ -6,20 +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.concat");
|
|
10
|
-
|
|
11
|
-
require("core-js/modules/es.array.filter");
|
|
12
|
-
|
|
13
|
-
require("core-js/modules/es.array.includes");
|
|
14
|
-
|
|
15
9
|
require("core-js/modules/es.array.iterator");
|
|
16
10
|
|
|
17
11
|
require("core-js/modules/es.object.to-string");
|
|
18
12
|
|
|
19
13
|
require("core-js/modules/es.promise");
|
|
20
14
|
|
|
21
|
-
require("core-js/modules/es.string.includes");
|
|
22
|
-
|
|
23
15
|
require("core-js/modules/es.string.starts-with");
|
|
24
16
|
|
|
25
17
|
require("core-js/modules/web.dom-collections.iterator");
|
|
@@ -37,11 +29,9 @@ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/cl
|
|
|
37
29
|
|
|
38
30
|
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
39
31
|
|
|
40
|
-
var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
|
|
41
|
-
|
|
42
32
|
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
43
33
|
|
|
44
|
-
var
|
|
34
|
+
var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
|
|
45
35
|
|
|
46
36
|
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
47
37
|
|
|
@@ -57,10 +47,6 @@ var _error_utils = require("../error_utils");
|
|
|
57
47
|
|
|
58
48
|
var _color_utils = _interopRequireDefault(require("../color_utils"));
|
|
59
49
|
|
|
60
|
-
var _block_query_spec = require("../types/block_query_spec");
|
|
61
|
-
|
|
62
|
-
var _airtable_interface = require("../types/airtable_interface");
|
|
63
|
-
|
|
64
50
|
var _abstract_model = _interopRequireDefault(require("./abstract_model"));
|
|
65
51
|
|
|
66
52
|
var _object_pool = _interopRequireDefault(require("./object_pool"));
|
|
@@ -94,23 +80,6 @@ var WatchableColorInViewKeyPrefix = 'colorInView:';
|
|
|
94
80
|
* - `'colorInView:' + someViewId`
|
|
95
81
|
*/
|
|
96
82
|
|
|
97
|
-
function _isKeySubscribeableViaRecordQuery(key) {
|
|
98
|
-
switch (key) {
|
|
99
|
-
case WatchableRecordKeys.name:
|
|
100
|
-
case WatchableRecordKeys.commentCount:
|
|
101
|
-
case WatchableRecordKeys.cellValues:
|
|
102
|
-
return true;
|
|
103
|
-
|
|
104
|
-
default:
|
|
105
|
-
if (key.startsWith(WatchableCellValueInFieldKeyPrefix)) {
|
|
106
|
-
return true;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
break;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
return false;
|
|
113
|
-
}
|
|
114
83
|
/**
|
|
115
84
|
* Model class representing a record in a table.
|
|
116
85
|
*
|
|
@@ -119,8 +88,6 @@ function _isKeySubscribeableViaRecordQuery(key) {
|
|
|
119
88
|
*
|
|
120
89
|
* @docsPath models/Record
|
|
121
90
|
*/
|
|
122
|
-
|
|
123
|
-
|
|
124
91
|
var Record =
|
|
125
92
|
/*#__PURE__*/
|
|
126
93
|
function (_AbstractModel) {
|
|
@@ -148,16 +115,9 @@ function (_AbstractModel) {
|
|
|
148
115
|
_this = (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(Record).call(this, sdk, recordId));
|
|
149
116
|
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "_parentRecordStore", void 0);
|
|
150
117
|
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "_parentTable", void 0);
|
|
151
|
-
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "_queryManager", void 0);
|
|
152
118
|
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "__linkedRecordsQueryResultPool", void 0);
|
|
153
|
-
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "_onRecordColorChange", (viewDataStore, key, recordIds) => {
|
|
154
|
-
if (recordIds.includes(_this.id)) {
|
|
155
|
-
_this._onChange(WatchableColorInViewKeyPrefix + viewDataStore.viewId);
|
|
156
|
-
}
|
|
157
|
-
});
|
|
158
119
|
_this._parentRecordStore = parentRecordStore;
|
|
159
120
|
_this._parentTable = parentTable;
|
|
160
|
-
_this._queryManager = sdk._queryManager;
|
|
161
121
|
_this.__linkedRecordsQueryResultPool = new _object_pool.default(_linked_records_query_result.default);
|
|
162
122
|
return _this;
|
|
163
123
|
}
|
|
@@ -167,33 +127,6 @@ function (_AbstractModel) {
|
|
|
167
127
|
|
|
168
128
|
|
|
169
129
|
(0, _createClass2.default)(Record, [{
|
|
170
|
-
key: "_assertExistsAndLoaded",
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* @internal
|
|
174
|
-
*/
|
|
175
|
-
value: function _assertExistsAndLoaded() {
|
|
176
|
-
// Access data in order to throw if the Record has been deleted / isn't loaded
|
|
177
|
-
var data = this._dataOrNullIfDeleted;
|
|
178
|
-
|
|
179
|
-
if (data === null) {
|
|
180
|
-
throw this._spawnErrorForDeletion();
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
/**
|
|
184
|
-
* The table that this record belongs to. Should never change because records aren't moved between tables.
|
|
185
|
-
*
|
|
186
|
-
* @internal (since we may not be able to return parent model instances in the immutable models world)
|
|
187
|
-
* @example
|
|
188
|
-
* ```js
|
|
189
|
-
* import {useRecords} from '@airtable/blocks/ui';
|
|
190
|
-
* const records = useRecords(myTable);
|
|
191
|
-
* console.log(records[0].parentTable.id === myTable.id);
|
|
192
|
-
* // => true
|
|
193
|
-
* ```
|
|
194
|
-
*/
|
|
195
|
-
|
|
196
|
-
}, {
|
|
197
130
|
key: "_getFieldMatching",
|
|
198
131
|
|
|
199
132
|
/**
|
|
@@ -223,20 +156,18 @@ function (_AbstractModel) {
|
|
|
223
156
|
}, {
|
|
224
157
|
key: "_getRawCellValue",
|
|
225
158
|
value: function _getRawCellValue(field) {
|
|
226
|
-
this.
|
|
227
|
-
|
|
159
|
+
(0, _error_utils.invariant)(this._parentRecordStore.areCellValuesLoadedForFieldId(field.id), 'Cell values for field %s are not loaded', field.id);
|
|
160
|
+
var cellValuesByFieldId = this._data.cellValuesByFieldId;
|
|
228
161
|
|
|
162
|
+
if (!cellValuesByFieldId) {
|
|
163
|
+
return null;
|
|
164
|
+
}
|
|
229
165
|
|
|
230
|
-
var
|
|
231
|
-
|
|
232
|
-
(0, _error_utils.invariant)(isCellValueLoadedForField, 'Cell value for field %s and record %s is not loaded', field.id, this._id);
|
|
233
|
-
|
|
234
|
-
var cellValue = this._parentRecordStore.getRecordCellValueByFieldId(this._id, field.id);
|
|
166
|
+
var cellValue = cellValuesByFieldId[field.id] !== undefined ? cellValuesByFieldId[field.id] : null;
|
|
235
167
|
|
|
236
168
|
if (typeof cellValue === 'object' && cellValue !== null) {
|
|
237
169
|
// Copy non-primitives.
|
|
238
|
-
// TODO
|
|
239
|
-
// deeply frozen objects, in a later sdk version we can drop cloning deeply.
|
|
170
|
+
// TODO(kasra): maybe freezeDeep instead?
|
|
240
171
|
return (0, _private_utils.cloneDeep)(cellValue);
|
|
241
172
|
} else {
|
|
242
173
|
return cellValue;
|
|
@@ -347,8 +278,9 @@ function (_AbstractModel) {
|
|
|
347
278
|
}, {
|
|
348
279
|
key: "getCellValueAsString",
|
|
349
280
|
value: function getCellValueAsString(fieldOrFieldIdOrFieldName) {
|
|
350
|
-
var field = this._getFieldMatching(fieldOrFieldIdOrFieldName);
|
|
281
|
+
var field = this._getFieldMatching(fieldOrFieldIdOrFieldName);
|
|
351
282
|
|
|
283
|
+
(0, _error_utils.invariant)(this._parentRecordStore.areCellValuesLoadedForFieldId(field.id), 'Cell values for field %s are not loaded', field.id);
|
|
352
284
|
|
|
353
285
|
var cellValue = this._getRawCellValue(field);
|
|
354
286
|
|
|
@@ -511,256 +443,73 @@ function (_AbstractModel) {
|
|
|
511
443
|
*/
|
|
512
444
|
|
|
513
445
|
}, {
|
|
514
|
-
key: "
|
|
446
|
+
key: "__triggerOnChangeForDirtyPaths",
|
|
515
447
|
|
|
516
448
|
/**
|
|
517
449
|
* @internal
|
|
518
450
|
*/
|
|
519
|
-
value: function
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
451
|
+
value: function __triggerOnChangeForDirtyPaths(dirtyPaths) {
|
|
452
|
+
var cellValuesByFieldId = dirtyPaths.cellValuesByFieldId,
|
|
453
|
+
commentCount = dirtyPaths.commentCount;
|
|
454
|
+
|
|
455
|
+
if (cellValuesByFieldId && !(0, _private_utils.isObjectEmpty)(cellValuesByFieldId)) {
|
|
456
|
+
// TODO: don't trigger changes for fields that aren't supposed to be loaded
|
|
457
|
+
// (in some cases, e.g. record created, liveapp will send cell values
|
|
458
|
+
// that we're not subscribed to).
|
|
459
|
+
this._onChange(WatchableRecordKeys.cellValues, Object.keys(cellValuesByFieldId));
|
|
460
|
+
|
|
461
|
+
if (cellValuesByFieldId[this.parentTable.primaryField.id]) {
|
|
462
|
+
this._onChange(WatchableRecordKeys.name);
|
|
526
463
|
}
|
|
527
|
-
};
|
|
528
|
-
}
|
|
529
|
-
/**
|
|
530
|
-
* @internal
|
|
531
|
-
*/
|
|
532
464
|
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
value: function _findMatchingBlockSubscriptionChanges(changes, changeTypeToMatch) {
|
|
536
|
-
return changes.filter(change => change.type === changeTypeToMatch && change.tableId === this.parentTable.id);
|
|
537
|
-
}
|
|
538
|
-
/**
|
|
539
|
-
* @internal
|
|
540
|
-
*/
|
|
465
|
+
for (var _i = 0, _Object$keys = Object.keys(cellValuesByFieldId); _i < _Object$keys.length; _i++) {
|
|
466
|
+
var fieldId = _Object$keys[_i];
|
|
541
467
|
|
|
542
|
-
|
|
543
|
-
key: "_constructBlockQuerySpecAndCallbackForWatchableKey",
|
|
544
|
-
value: function _constructBlockQuerySpecAndCallbackForWatchableKey(key, callbackForRegistration, context) {
|
|
545
|
-
var fieldSelectionDefinition;
|
|
546
|
-
|
|
547
|
-
var onChangeCallback = () => {
|
|
548
|
-
callbackForRegistration.call(context, this, key);
|
|
549
|
-
};
|
|
550
|
-
|
|
551
|
-
switch (key) {
|
|
552
|
-
case WatchableRecordKeys.name:
|
|
553
|
-
fieldSelectionDefinition = {
|
|
554
|
-
type: _block_query_spec.BlockFieldSelectionSpecType.SPECIFIED_FIELDS,
|
|
555
|
-
fieldIds: [this.parentTable.primaryField.id]
|
|
556
|
-
};
|
|
557
|
-
break;
|
|
558
|
-
|
|
559
|
-
case WatchableRecordKeys.commentCount:
|
|
560
|
-
fieldSelectionDefinition = {
|
|
561
|
-
type: _block_query_spec.BlockFieldSelectionSpecType.SPECIFIED_FIELDS,
|
|
562
|
-
fieldIds: [],
|
|
563
|
-
shouldIncludeCommentCount: true
|
|
564
|
-
};
|
|
565
|
-
break;
|
|
566
|
-
|
|
567
|
-
case WatchableRecordKeys.cellValues:
|
|
568
|
-
// TODO: (#proj-blocks-sdk-record-limits) In the future don't fetch all fields from table
|
|
569
|
-
// old code exhibit this behavior though: https://github.com/Hyperbase/blocks-sdk/blob/aba6fa7b7f8ccc1e364b409ca466d0281f8e9a69/packages/sdk/src/models/record.ts#L414-L416
|
|
570
|
-
// In the future a "subscribe to updates, but don't fetch more data" might be useful here.
|
|
571
|
-
fieldSelectionDefinition = {
|
|
572
|
-
type: _block_query_spec.BlockFieldSelectionSpecType.ALL_FIELDS_FROM_TABLE
|
|
573
|
-
};
|
|
574
|
-
|
|
575
|
-
onChangeCallback = changes => {
|
|
576
|
-
var modifiedCellValuesChanges = this._findMatchingBlockSubscriptionChanges(changes, _block_query_spec.BlockQuerySubscriptionChangeType.MODIFIED_CELL_VALUES_FOR_TABLE); // We do not currently simulate "on load" callback for registration
|
|
577
|
-
// but still handle it.
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
if (modifiedCellValuesChanges.length === 0) {
|
|
581
|
-
callbackForRegistration.call(context, this, key);
|
|
582
|
-
return;
|
|
583
|
-
}
|
|
584
|
-
|
|
585
|
-
var fieldIdsModified = [];
|
|
586
|
-
var _iteratorNormalCompletion3 = true;
|
|
587
|
-
var _didIteratorError3 = false;
|
|
588
|
-
var _iteratorError3 = undefined;
|
|
589
|
-
|
|
590
|
-
try {
|
|
591
|
-
for (var _iterator3 = modifiedCellValuesChanges[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
|
|
592
|
-
var modifiedCellValuesChange = _step3.value;
|
|
593
|
-
(0, _error_utils.invariant)(modifiedCellValuesChange.type === _block_query_spec.BlockQuerySubscriptionChangeType.MODIFIED_CELL_VALUES_FOR_TABLE, 'Modified cell value change is not a supported type in record');
|
|
594
|
-
var fieldIdsByRecordId = modifiedCellValuesChange.fieldIdsByRecordId;
|
|
595
|
-
var fieldIdsForThisRecord = fieldIdsByRecordId[this.id];
|
|
596
|
-
|
|
597
|
-
if (fieldIdsForThisRecord) {
|
|
598
|
-
fieldIdsModified = fieldIdsModified.concat(fieldIdsForThisRecord);
|
|
599
|
-
}
|
|
600
|
-
}
|
|
601
|
-
} catch (err) {
|
|
602
|
-
_didIteratorError3 = true;
|
|
603
|
-
_iteratorError3 = err;
|
|
604
|
-
} finally {
|
|
605
|
-
try {
|
|
606
|
-
if (!_iteratorNormalCompletion3 && _iterator3.return != null) {
|
|
607
|
-
_iterator3.return();
|
|
608
|
-
}
|
|
609
|
-
} finally {
|
|
610
|
-
if (_didIteratorError3) {
|
|
611
|
-
throw _iteratorError3;
|
|
612
|
-
}
|
|
613
|
-
}
|
|
614
|
-
}
|
|
615
|
-
|
|
616
|
-
callbackForRegistration.call(context, this, key, fieldIdsModified);
|
|
617
|
-
};
|
|
618
|
-
|
|
619
|
-
break;
|
|
620
|
-
|
|
621
|
-
default:
|
|
622
|
-
// The else cases should be impossible to reach - they indicate a SDK error.
|
|
623
|
-
// istanbul ignore else
|
|
624
|
-
if (key.startsWith(WatchableCellValueInFieldKeyPrefix)) {
|
|
625
|
-
var fieldId = key.substring(WatchableCellValueInFieldKeyPrefix.length); // Assert that fieldId is validly formatted, not that it is a valid fieldId in this table
|
|
626
|
-
|
|
627
|
-
(0, _error_utils.invariant)((0, _private_utils.isFieldId)(fieldId), 'fieldId passed as watchable fieldId is not a valid format' + fieldId);
|
|
628
|
-
fieldSelectionDefinition = {
|
|
629
|
-
type: _block_query_spec.BlockFieldSelectionSpecType.SPECIFIED_FIELDS,
|
|
630
|
-
fieldIds: [fieldId]
|
|
631
|
-
};
|
|
632
|
-
|
|
633
|
-
onChangeCallback = changes => {
|
|
634
|
-
// We could check if something else changed in the changes array,
|
|
635
|
-
// but our query subscription is targeting only the field in this record
|
|
636
|
-
callbackForRegistration.call(context, this, key, fieldId);
|
|
637
|
-
};
|
|
638
|
-
} else if (key.startsWith(WatchableColorInViewKeyPrefix)) {
|
|
639
|
-
throw (0, _error_utils.spawnError)('WatchableColorInViewKeyPrefix must be handled outside of query system');
|
|
640
|
-
} else {
|
|
641
|
-
throw (0, _error_utils.spawnError)('invalid record (un)watch key %s', key);
|
|
642
|
-
}
|
|
643
|
-
|
|
644
|
-
}
|
|
645
|
-
|
|
646
|
-
return {
|
|
647
|
-
querySpecToSubscribeWith: this._constructBlockFieldSelectionSpec(fieldSelectionDefinition),
|
|
648
|
-
onChangeCallback
|
|
649
|
-
};
|
|
650
|
-
}
|
|
651
|
-
/** @inheritdoc */
|
|
652
|
-
|
|
653
|
-
}, {
|
|
654
|
-
key: "watch",
|
|
655
|
-
value: function watch(keys, callbackForRegistration, context) {
|
|
656
|
-
var validKeys = this._getWatchableValidKeysOrThrow(keys, 'watch');
|
|
657
|
-
|
|
658
|
-
var _iteratorNormalCompletion4 = true;
|
|
659
|
-
var _didIteratorError4 = false;
|
|
660
|
-
var _iteratorError4 = undefined;
|
|
661
|
-
|
|
662
|
-
try {
|
|
663
|
-
for (var _iterator4 = validKeys[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) {
|
|
664
|
-
var key = _step4.value;
|
|
665
|
-
|
|
666
|
-
if (_isKeySubscribeableViaRecordQuery(key)) {
|
|
667
|
-
var _this$_constructBlock = this._constructBlockQuerySpecAndCallbackForWatchableKey(key, callbackForRegistration, context),
|
|
668
|
-
querySpecToSubscribeWith = _this$_constructBlock.querySpecToSubscribeWith,
|
|
669
|
-
onChangeCallback = _this$_constructBlock.onChangeCallback;
|
|
670
|
-
|
|
671
|
-
this._queryManager.watchWithQuerySpec(_airtable_interface.BlockQueryCallbackPriority.BLOCK_CODE, querySpecToSubscribeWith, this, key, onChangeCallback, callbackForRegistration, context);
|
|
672
|
-
} else {
|
|
673
|
-
// fallback to regular watch logic
|
|
674
|
-
(0, _error_utils.invariant)(key.startsWith(WatchableColorInViewKeyPrefix), 'Unexpected key in watch: %s', key);
|
|
675
|
-
var viewId = key.substring(WatchableColorInViewKeyPrefix.length);
|
|
676
|
-
|
|
677
|
-
this._parentRecordStore.getViewDataStore(viewId).watch('recordColors', this._onRecordColorChange);
|
|
678
|
-
|
|
679
|
-
(0, _get2.default)((0, _getPrototypeOf2.default)(Record.prototype), "watch", this).call(this, key, callbackForRegistration, context);
|
|
680
|
-
}
|
|
681
|
-
}
|
|
682
|
-
} catch (err) {
|
|
683
|
-
_didIteratorError4 = true;
|
|
684
|
-
_iteratorError4 = err;
|
|
685
|
-
} finally {
|
|
686
|
-
try {
|
|
687
|
-
if (!_iteratorNormalCompletion4 && _iterator4.return != null) {
|
|
688
|
-
_iterator4.return();
|
|
689
|
-
}
|
|
690
|
-
} finally {
|
|
691
|
-
if (_didIteratorError4) {
|
|
692
|
-
throw _iteratorError4;
|
|
693
|
-
}
|
|
468
|
+
this._onChange(WatchableCellValueInFieldKeyPrefix + fieldId, fieldId);
|
|
694
469
|
}
|
|
695
470
|
}
|
|
696
471
|
|
|
697
|
-
|
|
472
|
+
if (commentCount) {
|
|
473
|
+
this._onChange(WatchableRecordKeys.commentCount);
|
|
474
|
+
}
|
|
698
475
|
}
|
|
699
|
-
/**
|
|
476
|
+
/**
|
|
477
|
+
* @internal
|
|
478
|
+
*/
|
|
700
479
|
|
|
701
480
|
}, {
|
|
702
|
-
key: "
|
|
703
|
-
value: function
|
|
704
|
-
|
|
705
|
-
// want to make a breaking change.
|
|
706
|
-
var validKeys = this._getWatchableValidKeysOrThrow(keys, 'unwatch', true);
|
|
707
|
-
|
|
708
|
-
var _iteratorNormalCompletion5 = true;
|
|
709
|
-
var _didIteratorError5 = false;
|
|
710
|
-
var _iteratorError5 = undefined;
|
|
711
|
-
|
|
712
|
-
try {
|
|
713
|
-
for (var _iterator5 = validKeys[Symbol.iterator](), _step5; !(_iteratorNormalCompletion5 = (_step5 = _iterator5.next()).done); _iteratorNormalCompletion5 = true) {
|
|
714
|
-
var key = _step5.value;
|
|
715
|
-
|
|
716
|
-
if (_isKeySubscribeableViaRecordQuery(key)) {
|
|
717
|
-
this._queryManager.unwatchFromQueryKey(key, callbackForRegistration, context);
|
|
718
|
-
} else {
|
|
719
|
-
// fallback to regular watch logic
|
|
720
|
-
(0, _error_utils.invariant)(key.startsWith(WatchableColorInViewKeyPrefix), 'Unexpected key in unwatch: %s', key);
|
|
721
|
-
var viewId = key.substring(WatchableColorInViewKeyPrefix.length);
|
|
722
|
-
|
|
723
|
-
this._parentRecordStore.getViewDataStore(viewId).unwatch('recordColors', this._onRecordColorChange);
|
|
724
|
-
|
|
725
|
-
(0, _get2.default)((0, _getPrototypeOf2.default)(Record.prototype), "unwatch", this).call(this, key, callbackForRegistration, context);
|
|
726
|
-
}
|
|
727
|
-
}
|
|
728
|
-
} catch (err) {
|
|
729
|
-
_didIteratorError5 = true;
|
|
730
|
-
_iteratorError5 = err;
|
|
731
|
-
} finally {
|
|
732
|
-
try {
|
|
733
|
-
if (!_iteratorNormalCompletion5 && _iterator5.return != null) {
|
|
734
|
-
_iterator5.return();
|
|
735
|
-
}
|
|
736
|
-
} finally {
|
|
737
|
-
if (_didIteratorError5) {
|
|
738
|
-
throw _iteratorError5;
|
|
739
|
-
}
|
|
740
|
-
}
|
|
741
|
-
}
|
|
742
|
-
|
|
743
|
-
return validKeys;
|
|
481
|
+
key: "__triggerOnChangeForRecordColorInViewId",
|
|
482
|
+
value: function __triggerOnChangeForRecordColorInViewId(viewId) {
|
|
483
|
+
this._onChange(WatchableColorInViewKeyPrefix + viewId);
|
|
744
484
|
}
|
|
745
|
-
/** @internal */
|
|
746
|
-
|
|
747
485
|
}, {
|
|
748
486
|
key: "_dataOrNullIfDeleted",
|
|
749
487
|
get: function get() {
|
|
488
|
+
var _recordsById$this$_id;
|
|
489
|
+
|
|
750
490
|
var tableData = this._baseData.tablesById[this.parentTable.id];
|
|
751
491
|
|
|
752
492
|
if (!tableData) {
|
|
753
493
|
return null;
|
|
754
494
|
}
|
|
755
495
|
|
|
756
|
-
var
|
|
757
|
-
|
|
758
|
-
(
|
|
759
|
-
|
|
760
|
-
var isRecordDeleted = this._parentRecordStore.isRecordDeleted(this._id);
|
|
761
|
-
|
|
762
|
-
return isRecordDeleted ? null : true;
|
|
496
|
+
var recordsById = tableData.recordsById;
|
|
497
|
+
(0, _error_utils.invariant)(recordsById, 'Record data is not loaded');
|
|
498
|
+
return (_recordsById$this$_id = recordsById[this._id]) !== null && _recordsById$this$_id !== void 0 ? _recordsById$this$_id : null;
|
|
763
499
|
}
|
|
500
|
+
/**
|
|
501
|
+
* The table that this record belongs to. Should never change because records aren't moved between tables.
|
|
502
|
+
*
|
|
503
|
+
* @internal (since we may not be able to return parent model instances in the immutable models world)
|
|
504
|
+
* @example
|
|
505
|
+
* ```js
|
|
506
|
+
* import {useRecords} from '@airtable/blocks/ui';
|
|
507
|
+
* const records = useRecords(myTable);
|
|
508
|
+
* console.log(records[0].parentTable.id === myTable.id);
|
|
509
|
+
* // => true
|
|
510
|
+
* ```
|
|
511
|
+
*/
|
|
512
|
+
|
|
764
513
|
}, {
|
|
765
514
|
key: "parentTable",
|
|
766
515
|
get: function get() {
|
|
@@ -802,9 +551,7 @@ function (_AbstractModel) {
|
|
|
802
551
|
}, {
|
|
803
552
|
key: "commentCount",
|
|
804
553
|
get: function get() {
|
|
805
|
-
this.
|
|
806
|
-
|
|
807
|
-
return this._parentRecordStore.getRecordCommentCount(this._id);
|
|
554
|
+
return this._data.commentCount;
|
|
808
555
|
}
|
|
809
556
|
/**
|
|
810
557
|
* The created time of this record.
|
|
@@ -820,9 +567,7 @@ function (_AbstractModel) {
|
|
|
820
567
|
}, {
|
|
821
568
|
key: "createdTime",
|
|
822
569
|
get: function get() {
|
|
823
|
-
this.
|
|
824
|
-
|
|
825
|
-
return this._parentRecordStore.getRecordCreatedTime(this._id);
|
|
570
|
+
return new Date(this._data.createdTime);
|
|
826
571
|
}
|
|
827
572
|
}]);
|
|
828
573
|
return Record;
|
|
@@ -22,7 +22,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
22
22
|
value: true
|
|
23
23
|
});
|
|
24
24
|
exports.normalizeSortsOrGroups = normalizeSortsOrGroups;
|
|
25
|
-
exports.default =
|
|
25
|
+
exports.default = void 0;
|
|
26
26
|
|
|
27
27
|
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
28
28
|
|
|
@@ -61,8 +61,6 @@ var _record_coloring = require("./record_coloring");
|
|
|
61
61
|
/** @module @airtable/blocks/models: RecordQueryResult */
|
|
62
62
|
|
|
63
63
|
/** */
|
|
64
|
-
|
|
65
|
-
/** @hidden */
|
|
66
64
|
var WatchableRecordQueryResultKeys = Object.freeze({
|
|
67
65
|
records: 'records',
|
|
68
66
|
recordIds: 'recordIds',
|
|
@@ -72,7 +70,6 @@ var WatchableRecordQueryResultKeys = Object.freeze({
|
|
|
72
70
|
groupLevels: 'groupLevels',
|
|
73
71
|
isDataLoaded: 'isDataLoaded'
|
|
74
72
|
});
|
|
75
|
-
exports.WatchableRecordQueryResultKeys = WatchableRecordQueryResultKeys;
|
|
76
73
|
var WatchableCellValuesInFieldKeyPrefix = 'cellValuesInField:'; // The string case is to accommodate cellValuesInField:$FieldId.
|
|
77
74
|
|
|
78
75
|
/**
|