@airtable/blocks 1.11.1-experimental-68738f2-20220526 → 1.13.0
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/README.md +2 -2
- package/dist/cjs/error_utils.js +1 -19
- package/dist/cjs/global_config.js +3 -3
- package/dist/cjs/injected/airtable_interface.js +1 -1
- package/dist/cjs/models/base.js +9 -9
- package/dist/cjs/models/cursor.js +3 -3
- package/dist/cjs/models/field.js +3 -3
- package/dist/cjs/models/grouped_record_query_result.js +14 -5
- package/dist/cjs/models/linked_records_query_result.js +27 -78
- package/dist/cjs/models/mutations.js +163 -18
- package/dist/cjs/models/record.js +55 -310
- package/dist/cjs/models/record_query_result.js +2 -5
- package/dist/cjs/models/record_store.js +829 -555
- package/dist/cjs/models/session.js +3 -3
- package/dist/cjs/models/table.js +31 -31
- package/dist/cjs/models/table_or_view_query_result.js +419 -526
- package/dist/cjs/models/view.js +23 -1
- package/dist/cjs/models/view_data_store.js +295 -255
- package/dist/cjs/private_utils.js +0 -40
- package/dist/cjs/sdk.js +9 -12
- package/dist/cjs/settings_button.js +1 -1
- package/dist/cjs/testing/abstract_mock_airtable_interface.js +11 -57
- package/dist/cjs/types/airtable_interface.js +2 -17
- package/dist/cjs/ui/block_wrapper.js +2 -5
- package/dist/cjs/ui/expand_record_picker_async.js +1 -1
- package/dist/cjs/ui/global_config_synced_component_helpers.js +6 -0
- package/dist/cjs/ui/initialize_block.js +3 -3
- package/dist/cjs/ui/use_global_config.js +1 -1
- package/dist/cjs/ui/use_loadable.js +3 -3
- package/dist/cjs/ui/use_record_action_data.js +11 -11
- package/dist/cjs/ui/use_records.js +1 -5
- package/dist/cjs/ui/use_settings_button.js +1 -1
- package/dist/cjs/ui/viewport_constraint.js +1 -1
- package/dist/cjs/unstable_testing_utils.js +1 -61
- package/dist/cjs/viewport.js +9 -9
- package/dist/cjs/watchable.js +1 -15
- package/dist/types/src/error_utils.d.ts +1 -2
- package/dist/types/src/error_utils.d.ts.map +1 -1
- package/dist/types/src/global_config.d.ts +3 -3
- package/dist/types/src/models/base.d.ts +9 -9
- package/dist/types/src/models/cursor.d.ts +3 -3
- package/dist/types/src/models/field.d.ts +3 -3
- 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 +4 -5
- 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/session.d.ts +3 -3
- package/dist/types/src/models/table.d.ts +25 -25
- 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 +11 -0
- package/dist/types/src/models/view.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 +3 -1
- package/dist/types/src/sdk.d.ts.map +1 -1
- package/dist/types/src/settings_button.d.ts +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/field.d.ts +10 -5
- package/dist/types/src/types/field.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 +9 -3
- package/dist/types/src/types/view.d.ts.map +1 -1
- package/dist/types/src/ui/block_wrapper.d.ts.map +1 -1
- package/dist/types/src/ui/expand_record_picker_async.d.ts +1 -1
- package/dist/types/src/ui/global_config_synced_component_helpers.d.ts.map +1 -1
- package/dist/types/src/ui/initialize_block.d.ts +1 -1
- package/dist/types/src/ui/record_card.d.ts +1 -1
- package/dist/types/src/ui/use_global_config.d.ts +1 -1
- package/dist/types/src/ui/use_loadable.d.ts +2 -2
- package/dist/types/src/ui/use_record_action_data.d.ts +11 -11
- package/dist/types/src/ui/use_settings_button.d.ts +1 -1
- package/dist/types/src/ui/viewport_constraint.d.ts +3 -3
- package/dist/types/src/ui/viewport_constraint.d.ts.map +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/viewport.d.ts +9 -9
- package/dist/types/src/watchable.d.ts.map +1 -1
- package/dist/types/{src/testing → test/airtable_interface_mocks}/fixture_data.d.ts +25 -44
- 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 +2 -3
- package/dist/cjs/models/query_manager.js +0 -328
- package/dist/cjs/testing/fixture_data.js +0 -271
- package/dist/cjs/testing/mock_base_data_stores.js +0 -891
- 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 -59
- 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,12 +6,18 @@ 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
|
+
|
|
9
13
|
require("core-js/modules/es.array.includes");
|
|
10
14
|
|
|
11
15
|
require("core-js/modules/es.array.iterator");
|
|
12
16
|
|
|
13
17
|
require("core-js/modules/es.array.map");
|
|
14
18
|
|
|
19
|
+
require("core-js/modules/es.array.unscopables.flat-map");
|
|
20
|
+
|
|
15
21
|
require("core-js/modules/es.object.to-string");
|
|
16
22
|
|
|
17
23
|
require("core-js/modules/es.promise");
|
|
@@ -22,11 +28,15 @@ require("core-js/modules/es.string.includes");
|
|
|
22
28
|
|
|
23
29
|
require("core-js/modules/web.dom-collections.iterator");
|
|
24
30
|
|
|
31
|
+
require("core-js/modules/web.url.to-json");
|
|
32
|
+
|
|
25
33
|
Object.defineProperty(exports, "__esModule", {
|
|
26
34
|
value: true
|
|
27
35
|
});
|
|
28
36
|
exports.default = void 0;
|
|
29
37
|
|
|
38
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
39
|
+
|
|
30
40
|
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
31
41
|
|
|
32
42
|
require("regenerator-runtime/runtime");
|
|
@@ -41,6 +51,8 @@ var _airtable_interface = require("../types/airtable_interface");
|
|
|
41
51
|
|
|
42
52
|
var _mutations = require("../types/mutations");
|
|
43
53
|
|
|
54
|
+
var _private_utils = require("../private_utils");
|
|
55
|
+
|
|
44
56
|
var _error_utils = require("../error_utils");
|
|
45
57
|
|
|
46
58
|
var _mutation_constants = require("./mutation_constants");
|
|
@@ -69,18 +81,22 @@ function () {
|
|
|
69
81
|
|
|
70
82
|
/** @internal */
|
|
71
83
|
|
|
84
|
+
/** @internal */
|
|
85
|
+
|
|
72
86
|
/** @hidden */
|
|
73
|
-
function Mutations(sdk, session, base, applyGlobalConfigUpdates) {
|
|
87
|
+
function Mutations(sdk, session, base, applyModelChanges, applyGlobalConfigUpdates) {
|
|
74
88
|
(0, _classCallCheck2.default)(this, Mutations);
|
|
75
89
|
(0, _defineProperty2.default)(this, "_airtableInterface", void 0);
|
|
76
90
|
(0, _defineProperty2.default)(this, "_session", void 0);
|
|
77
91
|
(0, _defineProperty2.default)(this, "_sdk", void 0);
|
|
78
92
|
(0, _defineProperty2.default)(this, "_base", void 0);
|
|
93
|
+
(0, _defineProperty2.default)(this, "_applyModelChanges", void 0);
|
|
79
94
|
(0, _defineProperty2.default)(this, "_applyGlobalConfigUpdates", void 0);
|
|
80
95
|
this._airtableInterface = sdk.__airtableInterface;
|
|
81
96
|
this._session = session;
|
|
82
97
|
this._sdk = sdk;
|
|
83
98
|
this._base = base;
|
|
99
|
+
this._applyModelChanges = applyModelChanges;
|
|
84
100
|
this._applyGlobalConfigUpdates = applyGlobalConfigUpdates;
|
|
85
101
|
}
|
|
86
102
|
/** @hidden */
|
|
@@ -274,12 +290,9 @@ function () {
|
|
|
274
290
|
try {
|
|
275
291
|
for (var _iterator = records[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
276
292
|
var record = _step.value;
|
|
277
|
-
var existingRecord = null;
|
|
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
|
|
293
|
+
var existingRecord = null;
|
|
281
294
|
|
|
282
|
-
if (recordStore.
|
|
295
|
+
if (recordStore.isRecordMetadataLoaded) {
|
|
283
296
|
existingRecord = recordStore.getRecordByIdIfExists(record.id);
|
|
284
297
|
|
|
285
298
|
if (!existingRecord) {
|
|
@@ -301,7 +314,7 @@ function () {
|
|
|
301
314
|
checkedFieldIds.add(fieldId);
|
|
302
315
|
}
|
|
303
316
|
|
|
304
|
-
if (existingRecord && recordStore.
|
|
317
|
+
if (existingRecord && recordStore.areCellValuesLoadedForFieldId(fieldId)) {
|
|
305
318
|
var validationResult = this._airtableInterface.fieldTypeProvider.validateCellValueForUpdate(appInterface, record.cellValuesByFieldId[fieldId], existingRecord._getRawCellValue(field), field._data);
|
|
306
319
|
|
|
307
320
|
if (!validationResult.isValid) {
|
|
@@ -339,15 +352,9 @@ function () {
|
|
|
339
352
|
throw (0, _error_utils.spawnError)("Can't delete records: No table with id %s exists", _tableId);
|
|
340
353
|
}
|
|
341
354
|
|
|
342
|
-
var _recordStore = this._base.__getRecordStore(_tableId);
|
|
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
|
-
|
|
355
|
+
var _recordStore = this._base.__getRecordStore(_tableId);
|
|
349
356
|
|
|
350
|
-
if (_recordStore.
|
|
357
|
+
if (_recordStore.isRecordMetadataLoaded) {
|
|
351
358
|
var _iteratorNormalCompletion2 = true;
|
|
352
359
|
var _didIteratorError2 = false;
|
|
353
360
|
var _iteratorError2 = undefined;
|
|
@@ -701,13 +708,151 @@ function () {
|
|
|
701
708
|
this._applyGlobalConfigUpdates(mutation.updates);
|
|
702
709
|
|
|
703
710
|
return true;
|
|
704
|
-
}
|
|
705
|
-
|
|
706
|
-
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
var modelChanges = this._getOptimisticModelChangesForMutation(mutation);
|
|
707
714
|
|
|
715
|
+
if (modelChanges.length > 0) {
|
|
716
|
+
this._applyModelChanges(modelChanges);
|
|
717
|
+
|
|
718
|
+
return true;
|
|
719
|
+
}
|
|
708
720
|
|
|
709
721
|
return false;
|
|
710
722
|
}
|
|
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
|
+
}
|
|
711
856
|
}]);
|
|
712
857
|
return Mutations;
|
|
713
858
|
}();
|