@airtable/blocks 1.10.2-experimental-640bd10-20220211 → 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 +10 -17
- package/dist/cjs/models/base.js +16 -1
- package/dist/cjs/models/cursor.js +4 -6
- package/dist/cjs/models/field.js +99 -4
- package/dist/cjs/models/linked_records_query_result.js +17 -8
- package/dist/cjs/models/mutations.js +71 -35
- package/dist/cjs/sdk.js +1 -1
- package/dist/cjs/testing/fixture_data.js +3 -0
- package/dist/cjs/testing/mock_base_data_stores.js +40 -25
- package/dist/cjs/types/mutations.js +1 -0
- package/dist/cjs/ui/icon_config.js +4 -2
- package/dist/cjs/unstable_testing_utils.js +6 -0
- 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/base.d.ts +10 -0
- package/dist/types/src/models/base.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/field.d.ts +58 -0
- package/dist/types/src/models/field.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/testing/fixture_data.d.ts +1 -0
- package/dist/types/src/testing/fixture_data.d.ts.map +1 -1
- package/dist/types/src/testing/mock_base_data_stores.d.ts +5 -1
- package/dist/types/src/testing/mock_base_data_stores.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/ui/icon_config.d.ts +5 -3
- package/dist/types/src/ui/icon_config.d.ts.map +1 -1
- package/dist/types/src/unstable_testing_utils.d.ts +1 -1
- package/dist/types/src/unstable_testing_utils.d.ts.map +1 -1
- package/package.json +2 -2
- package/CHANGELOG.md +0 -484
package/dist/cjs/error_utils.js
CHANGED
|
@@ -1,16 +1,12 @@
|
|
|
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;
|
|
16
12
|
exports.spawnExhaustiveSwitchError = spawnExhaustiveSwitchError;
|
|
@@ -61,22 +57,19 @@ function spawnError(errorMessageFormat) {
|
|
|
61
57
|
} // istanbul ignore next
|
|
62
58
|
|
|
63
59
|
/**
|
|
64
|
-
* 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.
|
|
65
62
|
*
|
|
66
63
|
* @hidden
|
|
67
64
|
*/
|
|
68
65
|
|
|
69
66
|
|
|
70
|
-
function
|
|
71
|
-
// See this comment for how to log via
|
|
72
|
-
var
|
|
73
|
-
|
|
74
|
-
if (rollbar === null || rollbar === void 0 ? void 0 : rollbar.warn) {
|
|
75
|
-
for (var _len2 = arguments.length, errorMessageArgs = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
|
76
|
-
errorMessageArgs[_key2 - 1] = arguments[_key2];
|
|
77
|
-
}
|
|
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;
|
|
78
70
|
|
|
79
|
-
|
|
71
|
+
if (blocksErrorReporter === null || blocksErrorReporter === void 0 ? void 0 : blocksErrorReporter.reportWarning) {
|
|
72
|
+
blocksErrorReporter.reportWarning(errorMessage, metadata);
|
|
80
73
|
}
|
|
81
74
|
}
|
|
82
75
|
/**
|
|
@@ -88,8 +81,8 @@ function logErrorToRollbar(errorMessageFormat) {
|
|
|
88
81
|
|
|
89
82
|
function invariant(condition, errorMessageFormat) {
|
|
90
83
|
if (!condition) {
|
|
91
|
-
for (var
|
|
92
|
-
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];
|
|
93
86
|
}
|
|
94
87
|
|
|
95
88
|
throw spawnErrorWithOriginOmittedFromStackTrace(errorMessageFormat, errorMessageArgs, invariant);
|
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
|
|
@@ -864,6 +864,21 @@ function (_AbstractModel) {
|
|
|
864
864
|
get: function get() {
|
|
865
865
|
return this._data.name;
|
|
866
866
|
}
|
|
867
|
+
/**
|
|
868
|
+
* The workspace id of the base.
|
|
869
|
+
*
|
|
870
|
+
* @example
|
|
871
|
+
* ```js
|
|
872
|
+
* import {base} from '@airtable/blocks';
|
|
873
|
+
* console.log('The workspace id of your base is', base.workspaceId);
|
|
874
|
+
* ```
|
|
875
|
+
*/
|
|
876
|
+
|
|
877
|
+
}, {
|
|
878
|
+
key: "workspaceId",
|
|
879
|
+
get: function get() {
|
|
880
|
+
return this._data.workspaceId;
|
|
881
|
+
}
|
|
867
882
|
/**
|
|
868
883
|
* The color of the base.
|
|
869
884
|
*
|
|
@@ -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.
|
package/dist/cjs/models/field.js
CHANGED
|
@@ -279,6 +279,101 @@ function (_AbstractModel) {
|
|
|
279
279
|
}
|
|
280
280
|
}, null, this);
|
|
281
281
|
}
|
|
282
|
+
/**
|
|
283
|
+
* Checks whether the current user has permission to perform the given name update.
|
|
284
|
+
*
|
|
285
|
+
* Accepts partial input, in the same format as {@link updateNameAsync}.
|
|
286
|
+
*
|
|
287
|
+
* Returns `{hasPermission: true}` if the current user can update the specified field,
|
|
288
|
+
* `{hasPermission: false, reasonDisplayString: string}` otherwise. `reasonDisplayString` may be
|
|
289
|
+
* used to display an error message to the user.
|
|
290
|
+
*
|
|
291
|
+
* @param name new name for the field
|
|
292
|
+
*
|
|
293
|
+
* @example
|
|
294
|
+
* ```js
|
|
295
|
+
* const updateFieldCheckResult = field.checkPermissionsForUpdateName();
|
|
296
|
+
*
|
|
297
|
+
* if (!updateFieldCheckResult.hasPermission) {
|
|
298
|
+
* alert(updateFieldCheckResult.reasonDisplayString);
|
|
299
|
+
* }
|
|
300
|
+
* ```
|
|
301
|
+
*/
|
|
302
|
+
|
|
303
|
+
}, {
|
|
304
|
+
key: "checkPermissionsForUpdateName",
|
|
305
|
+
value: function checkPermissionsForUpdateName(name) {
|
|
306
|
+
return this._sdk.__mutations.checkPermissionsForMutation({
|
|
307
|
+
type: _mutations.MutationTypes.UPDATE_SINGLE_FIELD_NAME,
|
|
308
|
+
tableId: this.parentTable.id,
|
|
309
|
+
id: this.id,
|
|
310
|
+
name
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* An alias for `checkPermissionsForUpdateName(options).hasPermission`.
|
|
315
|
+
*
|
|
316
|
+
* Checks whether the current user has permission to perform the name update.
|
|
317
|
+
*
|
|
318
|
+
* Accepts partial input, in the same format as {@link updateNameAsync}.
|
|
319
|
+
*
|
|
320
|
+
* @param name new name for the field
|
|
321
|
+
*
|
|
322
|
+
* @example
|
|
323
|
+
* ```js
|
|
324
|
+
* const canUpdateField = field.hasPermissionToUpdateName();
|
|
325
|
+
*
|
|
326
|
+
* if (!canUpdateField) {
|
|
327
|
+
* alert('not allowed!');
|
|
328
|
+
* }
|
|
329
|
+
* ```
|
|
330
|
+
*/
|
|
331
|
+
|
|
332
|
+
}, {
|
|
333
|
+
key: "hasPermissionToUpdateName",
|
|
334
|
+
value: function hasPermissionToUpdateName(name) {
|
|
335
|
+
return this.checkPermissionsForUpdateName(name).hasPermission;
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* Updates the name for this field.
|
|
339
|
+
*
|
|
340
|
+
* Throws an error if the user does not have permission to update the field, or if an invalid
|
|
341
|
+
* name is provided.
|
|
342
|
+
*
|
|
343
|
+
* This action is asynchronous. Unlike updates to cell values, updates to field name are
|
|
344
|
+
* **not** applied optimistically locally. You must `await` the returned promise before
|
|
345
|
+
* relying on the change in your app.
|
|
346
|
+
*
|
|
347
|
+
* @param name new name for the field
|
|
348
|
+
*
|
|
349
|
+
* @example
|
|
350
|
+
* ```js
|
|
351
|
+
* await myTextField.updateNameAsync('My New Name');
|
|
352
|
+
* ```
|
|
353
|
+
*/
|
|
354
|
+
|
|
355
|
+
}, {
|
|
356
|
+
key: "updateNameAsync",
|
|
357
|
+
value: function updateNameAsync(name) {
|
|
358
|
+
return _regenerator.default.async(function updateNameAsync$(_context2) {
|
|
359
|
+
while (1) {
|
|
360
|
+
switch (_context2.prev = _context2.next) {
|
|
361
|
+
case 0:
|
|
362
|
+
_context2.next = 2;
|
|
363
|
+
return _regenerator.default.awrap(this._sdk.__mutations.applyMutationAsync({
|
|
364
|
+
type: _mutations.MutationTypes.UPDATE_SINGLE_FIELD_NAME,
|
|
365
|
+
tableId: this.parentTable.id,
|
|
366
|
+
id: this.id,
|
|
367
|
+
name
|
|
368
|
+
}));
|
|
369
|
+
|
|
370
|
+
case 2:
|
|
371
|
+
case "end":
|
|
372
|
+
return _context2.stop();
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
}, null, this);
|
|
376
|
+
}
|
|
282
377
|
/**
|
|
283
378
|
* Checks whether the current user has permission to perform the given description update.
|
|
284
379
|
*
|
|
@@ -358,11 +453,11 @@ function (_AbstractModel) {
|
|
|
358
453
|
}, {
|
|
359
454
|
key: "updateDescriptionAsync",
|
|
360
455
|
value: function updateDescriptionAsync(description) {
|
|
361
|
-
return _regenerator.default.async(function updateDescriptionAsync$(
|
|
456
|
+
return _regenerator.default.async(function updateDescriptionAsync$(_context3) {
|
|
362
457
|
while (1) {
|
|
363
|
-
switch (
|
|
458
|
+
switch (_context3.prev = _context3.next) {
|
|
364
459
|
case 0:
|
|
365
|
-
|
|
460
|
+
_context3.next = 2;
|
|
366
461
|
return _regenerator.default.awrap(this._sdk.__mutations.applyMutationAsync({
|
|
367
462
|
type: _mutations.MutationTypes.UPDATE_SINGLE_FIELD_DESCRIPTION,
|
|
368
463
|
tableId: this.parentTable.id,
|
|
@@ -372,7 +467,7 @@ function (_AbstractModel) {
|
|
|
372
467
|
|
|
373
468
|
case 2:
|
|
374
469
|
case "end":
|
|
375
|
-
return
|
|
470
|
+
return _context3.stop();
|
|
376
471
|
}
|
|
377
472
|
}
|
|
378
473
|
}, null, this);
|
|
@@ -549,12 +549,17 @@ function (_RecordQueryResult) {
|
|
|
549
549
|
}, {
|
|
550
550
|
key: "_onLinkedRecordIdsChange",
|
|
551
551
|
value: function _onLinkedRecordIdsChange() {
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
552
|
+
if (!this.isDataLoaded || this._record.isDeleted) {
|
|
553
|
+
//TODO(jamesmoody-at): Adding this._dataOrNullIfDeleted as an exit condition here is a temporary fix to address an issue where
|
|
554
|
+
// we are not reseting isValid to true while restoring deleted records that contain linked record fields. It seems the only way
|
|
555
|
+
// to do this is by creating a new LinkRecordsQueryResult instance but it seems like we might be reusing the original instance
|
|
556
|
+
// that we've already set isValid to false with. We'll need to do more investigating to figure out the right way to restore these
|
|
557
|
+
// records while keeping the behavior of isValid consistent
|
|
555
558
|
return;
|
|
556
559
|
}
|
|
557
560
|
|
|
561
|
+
(0, _error_utils.invariant)(this.isValid, 'watch key change event whilst invalid');
|
|
562
|
+
|
|
558
563
|
this._invalidateComputedData(); // we don't actually know at this stage whether anything changed or
|
|
559
564
|
// not. it may have done though, so notify watchers
|
|
560
565
|
|
|
@@ -640,15 +645,19 @@ function (_RecordQueryResult) {
|
|
|
640
645
|
}, {
|
|
641
646
|
key: "_onOriginCellValueChange",
|
|
642
647
|
value: function _onOriginCellValueChange() {
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
648
|
+
if (!this.isDataLoaded || this._field.isDeleted) {
|
|
649
|
+
//TODO(jamesmoody-at): Adding this._dataOrNullIfDeleted as an exit condition here is a temporary fix to address an issue where
|
|
650
|
+
// we are not resetting isValid to true while restoring deleted records that contain linked record fields. It seems the only way
|
|
651
|
+
// to do this is by creating a new LinkRecordsQueryResult instance but it seems like we might be reusing the original instance
|
|
652
|
+
// that we've already set isValid to false with. We'll need to do more investigating to figure out the right way to restore these
|
|
653
|
+
// records while keeping the behavior of isValid consistent
|
|
646
654
|
return;
|
|
647
|
-
}
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
(0, _error_utils.invariant)(this.isValid, 'watch key change event whilst invalid'); // when the origin cell value (listing all the linked records) changes,
|
|
648
658
|
// invalidate all the data we have stored - we need to completely
|
|
649
659
|
// regenerate it
|
|
650
660
|
|
|
651
|
-
|
|
652
661
|
this._invalidateComputedData(); // notify watchers that our set of linked records has changed
|
|
653
662
|
|
|
654
663
|
|
|
@@ -215,6 +215,26 @@ function () {
|
|
|
215
215
|
}
|
|
216
216
|
/** @internal */
|
|
217
217
|
|
|
218
|
+
}, {
|
|
219
|
+
key: "_assertFieldNameIsValidForMutation",
|
|
220
|
+
value: function _assertFieldNameIsValidForMutation(name, table) {
|
|
221
|
+
if (!name) {
|
|
222
|
+
throw (0, _error_utils.spawnError)("Can't create or update field: must provide non-empty name");
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
if (name.length > _mutation_constants.MAX_FIELD_NAME_LENGTH) {
|
|
226
|
+
throw (0, _error_utils.spawnError)("Can't create or update field: name '%s' exceeds maximum length of %s characters", name, _mutation_constants.MAX_FIELD_NAME_LENGTH);
|
|
227
|
+
} // Verify the new name doesn't collide with any existing field name.
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
var existingLowercaseFieldNames = table.fields.map(field => field.name.toLowerCase());
|
|
231
|
+
|
|
232
|
+
if (existingLowercaseFieldNames.includes(name.toLowerCase())) {
|
|
233
|
+
throw (0, _error_utils.spawnError)("Can't create or update field: field with name '%s' already exists", name);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
/** @internal */
|
|
237
|
+
|
|
218
238
|
}, {
|
|
219
239
|
key: "_assertMutationIsValid",
|
|
220
240
|
value: function _assertMutationIsValid(mutation) {
|
|
@@ -448,19 +468,7 @@ function () {
|
|
|
448
468
|
throw (0, _error_utils.spawnError)("Can't create field: table already has the maximum of %s fields", _mutation_constants.MAX_NUM_FIELDS_PER_TABLE);
|
|
449
469
|
}
|
|
450
470
|
|
|
451
|
-
|
|
452
|
-
throw (0, _error_utils.spawnError)("Can't create field: must provide non-empty name");
|
|
453
|
-
}
|
|
454
|
-
|
|
455
|
-
if (name.length > _mutation_constants.MAX_FIELD_NAME_LENGTH) {
|
|
456
|
-
throw (0, _error_utils.spawnError)("Can't create field: name '%s' exceeds maximum length of %s characters", name, _mutation_constants.MAX_FIELD_NAME_LENGTH);
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
var existingLowercaseFieldNames = _table3.fields.map(field => field.name.toLowerCase());
|
|
460
|
-
|
|
461
|
-
if (existingLowercaseFieldNames.includes(name.toLowerCase())) {
|
|
462
|
-
throw (0, _error_utils.spawnError)("Can't create field: field with name '%s' already exists", name);
|
|
463
|
-
} // Current config / field data is null since the field doesn't exist.
|
|
471
|
+
this._assertFieldNameIsValidForMutation(name, _table3); // Current config / field data is null since the field doesn't exist.
|
|
464
472
|
|
|
465
473
|
|
|
466
474
|
var _validationResult2 = this._airtableInterface.fieldTypeProvider.validateConfigForUpdate(appInterface, config, null, null, billingPlanGrouping);
|
|
@@ -534,23 +542,51 @@ function () {
|
|
|
534
542
|
return;
|
|
535
543
|
}
|
|
536
544
|
|
|
545
|
+
case _mutations.MutationTypes.UPDATE_SINGLE_FIELD_NAME:
|
|
546
|
+
{
|
|
547
|
+
var _tableId6 = mutation.tableId,
|
|
548
|
+
_id2 = mutation.id,
|
|
549
|
+
_name = mutation.name;
|
|
550
|
+
|
|
551
|
+
var _table6 = this._base.getTableByIdIfExists(_tableId6);
|
|
552
|
+
|
|
553
|
+
if (!_table6) {
|
|
554
|
+
throw (0, _error_utils.spawnError)("Can't update field: No table with id %s exists", _tableId6);
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
var _field4 = _table6.getFieldByIdIfExists(_id2);
|
|
558
|
+
|
|
559
|
+
if (!_field4) {
|
|
560
|
+
throw (0, _error_utils.spawnError)("Can't update field: No field with id %s exists", _id2);
|
|
561
|
+
} // We skip name validation if it's the same name:
|
|
562
|
+
// If it's exactly same name, this will result in no-op;
|
|
563
|
+
// If it's only case change, we allow update and we know this name is already validated before;
|
|
564
|
+
|
|
565
|
+
|
|
566
|
+
if (_field4.name.toLowerCase() !== _name.toLowerCase()) {
|
|
567
|
+
this._assertFieldNameIsValidForMutation(_name, _table6);
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
return;
|
|
571
|
+
}
|
|
572
|
+
|
|
537
573
|
case _mutations.MutationTypes.CREATE_SINGLE_TABLE:
|
|
538
574
|
{
|
|
539
|
-
var
|
|
575
|
+
var _name2 = mutation.name,
|
|
540
576
|
fields = mutation.fields;
|
|
541
577
|
|
|
542
|
-
if (!
|
|
578
|
+
if (!_name2) {
|
|
543
579
|
throw (0, _error_utils.spawnError)("Can't create table: must provide non-empty name");
|
|
544
580
|
}
|
|
545
581
|
|
|
546
|
-
if (
|
|
547
|
-
throw (0, _error_utils.spawnError)("Can't create table: name '%s' exceeds maximum length of %s characters",
|
|
582
|
+
if (_name2.length > _mutation_constants.MAX_TABLE_NAME_LENGTH) {
|
|
583
|
+
throw (0, _error_utils.spawnError)("Can't create table: name '%s' exceeds maximum length of %s characters", _name2, _mutation_constants.MAX_TABLE_NAME_LENGTH);
|
|
548
584
|
}
|
|
549
585
|
|
|
550
586
|
var existingLowercaseTableNames = this._base.tables.map(table => table.name.toLowerCase());
|
|
551
587
|
|
|
552
|
-
if (existingLowercaseTableNames.includes(
|
|
553
|
-
throw (0, _error_utils.spawnError)("Can't create table: table with name '%s' already exists",
|
|
588
|
+
if (existingLowercaseTableNames.includes(_name2.toLowerCase())) {
|
|
589
|
+
throw (0, _error_utils.spawnError)("Can't create table: table with name '%s' already exists", _name2);
|
|
554
590
|
}
|
|
555
591
|
|
|
556
592
|
if (fields.length === 0) {
|
|
@@ -568,32 +604,32 @@ function () {
|
|
|
568
604
|
|
|
569
605
|
try {
|
|
570
606
|
for (var _iterator4 = fields[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) {
|
|
571
|
-
var
|
|
607
|
+
var _field5 = _step4.value;
|
|
572
608
|
|
|
573
|
-
if (!
|
|
609
|
+
if (!_field5.name) {
|
|
574
610
|
throw (0, _error_utils.spawnError)("Can't create table: must provide non-empty name for every field");
|
|
575
611
|
}
|
|
576
612
|
|
|
577
|
-
if (
|
|
578
|
-
throw (0, _error_utils.spawnError)("Can't create table: field name '%s' exceeds maximum length of %s characters",
|
|
613
|
+
if (_field5.name.length > _mutation_constants.MAX_FIELD_NAME_LENGTH) {
|
|
614
|
+
throw (0, _error_utils.spawnError)("Can't create table: field name '%s' exceeds maximum length of %s characters", _field5.name, _mutation_constants.MAX_FIELD_NAME_LENGTH);
|
|
579
615
|
}
|
|
580
616
|
|
|
581
|
-
var lowercaseFieldName =
|
|
617
|
+
var lowercaseFieldName = _field5.name.toLowerCase();
|
|
582
618
|
|
|
583
619
|
if (lowercaseFieldNames.has(lowercaseFieldName)) {
|
|
584
|
-
throw (0, _error_utils.spawnError)("Can't create table: duplicate field name '%s'",
|
|
620
|
+
throw (0, _error_utils.spawnError)("Can't create table: duplicate field name '%s'", _field5.name);
|
|
585
621
|
}
|
|
586
622
|
|
|
587
623
|
lowercaseFieldNames.add(lowercaseFieldName); // Current config / field data is null since the field doesn't exist.
|
|
588
624
|
|
|
589
|
-
var _validationResult4 = this._airtableInterface.fieldTypeProvider.validateConfigForUpdate(appInterface,
|
|
625
|
+
var _validationResult4 = this._airtableInterface.fieldTypeProvider.validateConfigForUpdate(appInterface, _field5.config, null, null, billingPlanGrouping);
|
|
590
626
|
|
|
591
627
|
if (!_validationResult4.isValid) {
|
|
592
|
-
throw (0, _error_utils.spawnError)("Can't create table: invalid field config for field '%s'.\n%s",
|
|
628
|
+
throw (0, _error_utils.spawnError)("Can't create table: invalid field config for field '%s'.\n%s", _field5.name, _validationResult4.reason);
|
|
593
629
|
}
|
|
594
630
|
|
|
595
|
-
if (
|
|
596
|
-
throw (0, _error_utils.spawnError)("Can't create table: description for field '%s' exceeds maximum length of %s characters",
|
|
631
|
+
if (_field5.description && _field5.description.length > _mutation_constants.MAX_FIELD_DESCRIPTION_LENGTH) {
|
|
632
|
+
throw (0, _error_utils.spawnError)("Can't create table: description for field '%s' exceeds maximum length of %s characters", _field5.name, _mutation_constants.MAX_FIELD_DESCRIPTION_LENGTH);
|
|
597
633
|
}
|
|
598
634
|
}
|
|
599
635
|
} catch (err) {
|
|
@@ -622,7 +658,7 @@ function () {
|
|
|
622
658
|
|
|
623
659
|
case _mutations.MutationTypes.UPDATE_VIEW_METADATA:
|
|
624
660
|
{
|
|
625
|
-
var
|
|
661
|
+
var _tableId7 = mutation.tableId,
|
|
626
662
|
viewId = mutation.viewId;
|
|
627
663
|
var runContext = this._airtableInterface.sdkInitData.runContext;
|
|
628
664
|
|
|
@@ -630,17 +666,17 @@ function () {
|
|
|
630
666
|
throw (0, _error_utils.spawnError)('Setting view metadata is only valid for views');
|
|
631
667
|
}
|
|
632
668
|
|
|
633
|
-
if (runContext.viewId !== viewId || runContext.tableId !==
|
|
669
|
+
if (runContext.viewId !== viewId || runContext.tableId !== _tableId7) {
|
|
634
670
|
throw (0, _error_utils.spawnError)('Custom views can only set view metadata on themselves');
|
|
635
671
|
}
|
|
636
672
|
|
|
637
|
-
var
|
|
673
|
+
var _table7 = this._base.getTableByIdIfExists(_tableId7);
|
|
638
674
|
|
|
639
|
-
if (!
|
|
640
|
-
throw (0, _error_utils.spawnError)("Can't update metadata: No table with id %s exists",
|
|
675
|
+
if (!_table7) {
|
|
676
|
+
throw (0, _error_utils.spawnError)("Can't update metadata: No table with id %s exists", _tableId7);
|
|
641
677
|
}
|
|
642
678
|
|
|
643
|
-
var view =
|
|
679
|
+
var view = _table7.getViewByIdIfExists(viewId);
|
|
644
680
|
|
|
645
681
|
if (!view) {
|
|
646
682
|
throw (0, _error_utils.spawnError)("Can't update metadata: No view with id %s exists", viewId);
|
package/dist/cjs/sdk.js
CHANGED
|
@@ -49,6 +49,7 @@ var MOCK_BASE_PERMISSION_LEVEL = 'create';
|
|
|
49
49
|
var MOCK_CURRENT_USER_ID = 'usrGalSamari';
|
|
50
50
|
var MOCK_BASE_COLOR = 'purple';
|
|
51
51
|
var MOCK_BILLING_GROUP = 'pro';
|
|
52
|
+
var MOCK_WORKSPACE_ID = 'wspUai0ZmWFWfSBtb';
|
|
52
53
|
/** @hidden */
|
|
53
54
|
|
|
54
55
|
function convertFixtureDataToSdkInitData(fixtureData) {
|
|
@@ -58,6 +59,7 @@ function convertFixtureDataToSdkInitData(fixtureData) {
|
|
|
58
59
|
color = _fixtureData$base.color,
|
|
59
60
|
tables = _fixtureData$base.tables,
|
|
60
61
|
collaborators = _fixtureData$base.collaborators,
|
|
62
|
+
workspaceId = _fixtureData$base.workspaceId,
|
|
61
63
|
globalConfig = fixtureData.globalConfig;
|
|
62
64
|
var tablesById = {};
|
|
63
65
|
|
|
@@ -126,6 +128,7 @@ function convertFixtureDataToSdkInitData(fixtureData) {
|
|
|
126
128
|
};
|
|
127
129
|
}), _private_utils.getId),
|
|
128
130
|
activeCollaboratorIds: collaborators.filter(c => c.isActive).map(c => c.id),
|
|
131
|
+
workspaceId: workspaceId !== null && workspaceId !== void 0 ? workspaceId : MOCK_WORKSPACE_ID,
|
|
129
132
|
cursorData: null,
|
|
130
133
|
billingPlanGrouping: MOCK_BILLING_GROUP,
|
|
131
134
|
appInterface: {},
|
|
@@ -83,6 +83,7 @@ var unmodifiableFieldData = {
|
|
|
83
83
|
};
|
|
84
84
|
/** @hidden */
|
|
85
85
|
|
|
86
|
+
/** @hidden */
|
|
86
87
|
var MockBaseDataStore =
|
|
87
88
|
/*#__PURE__*/
|
|
88
89
|
function () {
|
|
@@ -286,46 +287,51 @@ function () {
|
|
|
286
287
|
// mock implementation of isRecordPartiallyLoaded still returns `true`
|
|
287
288
|
// for this given recordId
|
|
288
289
|
|
|
289
|
-
this._deletedRecordIds.push(recordId);
|
|
290
|
+
this._deletedRecordIds.push(recordId); // But we do remove the records from the views
|
|
291
|
+
|
|
290
292
|
|
|
293
|
+
table.views.forEach(view => {
|
|
294
|
+
var viewRecords = view.records.filter(r => r.id !== recordId);
|
|
295
|
+
view.records = viewRecords;
|
|
296
|
+
});
|
|
291
297
|
_i = 0, _Object$values = Object.values(this._subscribedQuerySpecs);
|
|
292
298
|
|
|
293
|
-
case
|
|
299
|
+
case 7:
|
|
294
300
|
if (!(_i < _Object$values.length)) {
|
|
295
|
-
_context4.next =
|
|
301
|
+
_context4.next = 17;
|
|
296
302
|
break;
|
|
297
303
|
}
|
|
298
304
|
|
|
299
305
|
_Object$values$_i = _Object$values[_i], querySpec = _Object$values$_i.querySpec, onChangeCallback = _Object$values$_i.onChangeCallback;
|
|
300
306
|
|
|
301
307
|
if (onChangeCallback) {
|
|
302
|
-
_context4.next =
|
|
308
|
+
_context4.next = 11;
|
|
303
309
|
break;
|
|
304
310
|
}
|
|
305
311
|
|
|
306
|
-
return _context4.abrupt("continue",
|
|
312
|
+
return _context4.abrupt("continue", 14);
|
|
307
313
|
|
|
308
|
-
case
|
|
314
|
+
case 11:
|
|
309
315
|
if (!(querySpec.sourceTableId !== tableId)) {
|
|
310
|
-
_context4.next =
|
|
316
|
+
_context4.next = 13;
|
|
311
317
|
break;
|
|
312
318
|
}
|
|
313
319
|
|
|
314
|
-
return _context4.abrupt("continue",
|
|
320
|
+
return _context4.abrupt("continue", 14);
|
|
315
321
|
|
|
316
|
-
case
|
|
322
|
+
case 13:
|
|
317
323
|
onChangeCallback([{
|
|
318
324
|
type: _block_query_spec.BlockQuerySubscriptionChangeType.REMOVED_RECORD_IDS,
|
|
319
325
|
tableId,
|
|
320
326
|
recordIds: [recordId]
|
|
321
327
|
}]);
|
|
322
328
|
|
|
323
|
-
case
|
|
329
|
+
case 14:
|
|
324
330
|
_i++;
|
|
325
|
-
_context4.next =
|
|
331
|
+
_context4.next = 7;
|
|
326
332
|
break;
|
|
327
333
|
|
|
328
|
-
case
|
|
334
|
+
case 17:
|
|
329
335
|
case "end":
|
|
330
336
|
return _context4.stop();
|
|
331
337
|
}
|
|
@@ -343,45 +349,51 @@ function () {
|
|
|
343
349
|
case 0:
|
|
344
350
|
table = this._tablesById[tableId];
|
|
345
351
|
(0, _error_utils.invariant)(table, 'updateRecord called with missing table %s', tableId);
|
|
346
|
-
table.records.push(initialFixtureRecord);
|
|
352
|
+
table.records.push(initialFixtureRecord); // By default add records to all views within the table
|
|
353
|
+
|
|
354
|
+
table.views.forEach(view => {
|
|
355
|
+
view.records.push(_objectSpread({}, initialFixtureRecord, {
|
|
356
|
+
color: null
|
|
357
|
+
}));
|
|
358
|
+
});
|
|
347
359
|
_i2 = 0, _Object$values2 = Object.values(this._subscribedQuerySpecs);
|
|
348
360
|
|
|
349
|
-
case
|
|
361
|
+
case 5:
|
|
350
362
|
if (!(_i2 < _Object$values2.length)) {
|
|
351
|
-
_context5.next =
|
|
363
|
+
_context5.next = 15;
|
|
352
364
|
break;
|
|
353
365
|
}
|
|
354
366
|
|
|
355
367
|
_Object$values2$_i = _Object$values2[_i2], querySpec = _Object$values2$_i.querySpec, onChangeCallback = _Object$values2$_i.onChangeCallback;
|
|
356
368
|
|
|
357
369
|
if (onChangeCallback) {
|
|
358
|
-
_context5.next =
|
|
370
|
+
_context5.next = 9;
|
|
359
371
|
break;
|
|
360
372
|
}
|
|
361
373
|
|
|
362
|
-
return _context5.abrupt("continue",
|
|
374
|
+
return _context5.abrupt("continue", 12);
|
|
363
375
|
|
|
364
|
-
case
|
|
376
|
+
case 9:
|
|
365
377
|
if (!(querySpec.sourceTableId !== tableId)) {
|
|
366
|
-
_context5.next =
|
|
378
|
+
_context5.next = 11;
|
|
367
379
|
break;
|
|
368
380
|
}
|
|
369
381
|
|
|
370
|
-
return _context5.abrupt("continue",
|
|
382
|
+
return _context5.abrupt("continue", 12);
|
|
371
383
|
|
|
372
|
-
case
|
|
384
|
+
case 11:
|
|
373
385
|
onChangeCallback([{
|
|
374
386
|
type: _block_query_spec.BlockQuerySubscriptionChangeType.ADDED_RECORD_IDS,
|
|
375
387
|
tableId,
|
|
376
388
|
recordIds: [initialFixtureRecord.id]
|
|
377
389
|
}]);
|
|
378
390
|
|
|
379
|
-
case
|
|
391
|
+
case 12:
|
|
380
392
|
_i2++;
|
|
381
|
-
_context5.next =
|
|
393
|
+
_context5.next = 5;
|
|
382
394
|
break;
|
|
383
395
|
|
|
384
|
-
case
|
|
396
|
+
case 15:
|
|
385
397
|
case "end":
|
|
386
398
|
return _context5.stop();
|
|
387
399
|
}
|
|
@@ -542,7 +554,10 @@ function () {
|
|
|
542
554
|
isRecordCellValueLoadedForFieldId: (recordId, fieldId) => this._isRecordCellValueLoadedForFieldId(fixtureTable, recordId, fieldId),
|
|
543
555
|
getRecordCellValueByFieldId: (recordId, fieldId) => this._getRecordCellValueByFieldId(fixtureTable, recordId, fieldId),
|
|
544
556
|
getRecordCommentCount: recordId => this._getRecordCommentCount(fixtureTable, recordId),
|
|
545
|
-
getRecordCreatedTime: recordId => this._getRecordCreatedTime(fixtureTable, recordId)
|
|
557
|
+
getRecordCreatedTime: recordId => this._getRecordCreatedTime(fixtureTable, recordId),
|
|
558
|
+
// This doesn't concern loadedness; but allows test fixtures to do things like
|
|
559
|
+
// "pretend this record is highlighted", even if it isn't loaded by the block
|
|
560
|
+
hasRecordForTestsOnly: recordId => fixtureTable.records.some(record => record.id === recordId)
|
|
546
561
|
};
|
|
547
562
|
}
|
|
548
563
|
}, {
|
|
@@ -18,6 +18,7 @@ var MutationTypes = Object.freeze({
|
|
|
18
18
|
CREATE_SINGLE_FIELD: 'createSingleField',
|
|
19
19
|
UPDATE_SINGLE_FIELD_CONFIG: 'updateSingleFieldConfig',
|
|
20
20
|
UPDATE_SINGLE_FIELD_DESCRIPTION: 'updateSingleFieldDescription',
|
|
21
|
+
UPDATE_SINGLE_FIELD_NAME: 'updateSingleFieldName',
|
|
21
22
|
CREATE_SINGLE_TABLE: 'createSingleTable',
|
|
22
23
|
UPDATE_VIEW_METADATA: 'updateViewMetadata'
|
|
23
24
|
});
|