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