@airtable/blocks 0.0.0-experimental-f52bc4e5e-20250709 → 0.0.0-experimental-75d011284-20250904
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/base/assert_run_context.js +12 -0
- package/dist/cjs/base/index.js +30 -30
- package/dist/cjs/base/models/abstract_model_with_async_data.js +154 -237
- package/dist/cjs/base/models/base.js +188 -267
- package/dist/cjs/base/models/create_aggregators.js +29 -46
- package/dist/cjs/base/models/cursor.js +206 -294
- package/dist/cjs/base/models/field.js +307 -395
- package/dist/cjs/base/models/grouped_record_query_result.js +219 -338
- package/dist/cjs/base/models/linked_records_query_result.js +450 -625
- package/dist/cjs/base/models/models.js +19 -22
- package/dist/cjs/base/models/mutations.js +267 -293
- package/dist/cjs/base/models/object_pool.js +117 -156
- package/dist/cjs/base/models/record.js +191 -256
- package/dist/cjs/base/models/record_coloring.js +6 -6
- package/dist/cjs/base/models/record_query_result.js +351 -435
- package/dist/cjs/base/models/record_store.js +403 -753
- package/dist/cjs/base/models/session.js +125 -153
- package/dist/cjs/base/models/table.js +457 -605
- package/dist/cjs/base/models/table_or_view_query_result.js +656 -920
- package/dist/cjs/base/models/view.js +284 -389
- package/dist/cjs/base/models/view_data_store.js +218 -356
- package/dist/cjs/base/models/view_metadata_query_result.js +109 -157
- package/dist/cjs/base/perform_record_action.js +89 -131
- package/dist/cjs/base/sdk.js +129 -184
- package/dist/cjs/base/settings_button.js +54 -74
- package/dist/cjs/base/types/airtable_interface.js +1 -1
- package/dist/cjs/base/types/mutations.js +5 -11
- package/dist/cjs/base/types/undo_redo.js +1 -1
- package/dist/cjs/base/types/view.js +1 -1
- package/dist/cjs/base/ui/base_provider.js +6 -8
- package/dist/cjs/base/ui/baymax_utils.js +436 -108
- package/dist/cjs/base/ui/block_wrapper.js +81 -106
- package/dist/cjs/base/ui/box.js +34 -60
- package/dist/cjs/base/ui/button.js +44 -74
- package/dist/cjs/base/ui/cell_renderer.js +132 -189
- package/dist/cjs/base/ui/choice_token.js +25 -42
- package/dist/cjs/base/ui/collaborator_token.js +31 -53
- package/dist/cjs/base/ui/color_palette.js +130 -173
- package/dist/cjs/base/ui/color_palette_synced.js +41 -70
- package/dist/cjs/base/ui/confirmation_dialog.js +70 -120
- package/dist/cjs/base/ui/control_sizes.js +24 -22
- package/dist/cjs/base/ui/create_detect_element_resize.js +6 -10
- package/dist/cjs/base/ui/css_helpers.js +1 -1
- package/dist/cjs/base/ui/dialog.js +57 -98
- package/dist/cjs/base/ui/dialog_close_button.js +52 -98
- package/dist/cjs/base/ui/expand_record.js +1 -2
- package/dist/cjs/base/ui/expand_record_list.js +3 -4
- package/dist/cjs/base/ui/expand_record_picker_async.js +28 -57
- package/dist/cjs/base/ui/field_icon.js +15 -33
- package/dist/cjs/base/ui/field_picker.js +25 -70
- package/dist/cjs/base/ui/field_picker_synced.js +18 -40
- package/dist/cjs/base/ui/form_field.js +27 -55
- package/dist/cjs/base/ui/geometry/geometry.js +5 -5
- package/dist/cjs/base/ui/geometry/point.js +10 -12
- package/dist/cjs/base/ui/geometry/rect.js +36 -52
- package/dist/cjs/base/ui/geometry/size.js +10 -12
- package/dist/cjs/base/ui/global_alert.js +31 -52
- package/dist/cjs/base/ui/heading.js +45 -94
- package/dist/cjs/base/ui/icon.js +39 -59
- package/dist/cjs/base/ui/icon_config.js +6 -12
- package/dist/cjs/base/ui/initialize_block.js +16 -35
- package/dist/cjs/base/ui/input.js +62 -101
- package/dist/cjs/base/ui/input_synced.js +17 -40
- package/dist/cjs/base/ui/key_codes.js +2 -3
- package/dist/cjs/base/ui/label.js +30 -55
- package/dist/cjs/base/ui/link.js +54 -87
- package/dist/cjs/base/ui/loader.js +15 -36
- package/dist/cjs/base/ui/modal.js +88 -127
- package/dist/cjs/base/ui/model_picker_select.js +18 -44
- package/dist/cjs/base/ui/popover.js +236 -328
- package/dist/cjs/base/ui/progress_bar.js +34 -47
- package/dist/cjs/base/ui/record_card.js +389 -478
- package/dist/cjs/base/ui/record_card_list.js +150 -224
- package/dist/cjs/base/ui/select.js +60 -116
- package/dist/cjs/base/ui/select_and_select_buttons_helpers.js +15 -39
- package/dist/cjs/base/ui/select_buttons.js +50 -83
- package/dist/cjs/base/ui/select_buttons_synced.js +17 -39
- package/dist/cjs/base/ui/select_synced.js +17 -39
- package/dist/cjs/base/ui/switch.js +42 -71
- package/dist/cjs/base/ui/switch_synced.js +16 -38
- package/dist/cjs/base/ui/synced.js +27 -48
- package/dist/cjs/base/ui/system/all_styles_set.js +4 -12
- package/dist/cjs/base/ui/system/appearance/appearance_set.js +10 -13
- package/dist/cjs/base/ui/system/appearance/background_color.js +3 -6
- package/dist/cjs/base/ui/system/appearance/border.js +3 -6
- package/dist/cjs/base/ui/system/appearance/border_radius.js +3 -6
- package/dist/cjs/base/ui/system/appearance/box_shadow.js +3 -6
- package/dist/cjs/base/ui/system/appearance/opacity.js +3 -6
- package/dist/cjs/base/ui/system/dimensions/dimensions_set.js +11 -13
- package/dist/cjs/base/ui/system/dimensions/height.js +3 -6
- package/dist/cjs/base/ui/system/dimensions/max_height.js +3 -6
- package/dist/cjs/base/ui/system/dimensions/max_width.js +3 -6
- package/dist/cjs/base/ui/system/dimensions/min_height.js +3 -6
- package/dist/cjs/base/ui/system/dimensions/min_width.js +3 -6
- package/dist/cjs/base/ui/system/dimensions/width.js +3 -6
- package/dist/cjs/base/ui/system/display.js +3 -6
- package/dist/cjs/base/ui/system/flex_container/align_content.js +3 -6
- package/dist/cjs/base/ui/system/flex_container/align_items.js +3 -6
- package/dist/cjs/base/ui/system/flex_container/flex_container_set.js +11 -13
- package/dist/cjs/base/ui/system/flex_container/flex_direction.js +3 -6
- package/dist/cjs/base/ui/system/flex_container/flex_wrap.js +3 -6
- package/dist/cjs/base/ui/system/flex_container/justify_content.js +3 -6
- package/dist/cjs/base/ui/system/flex_container/justify_items.js +3 -6
- package/dist/cjs/base/ui/system/flex_item/align_self.js +3 -6
- package/dist/cjs/base/ui/system/flex_item/flex.js +3 -6
- package/dist/cjs/base/ui/system/flex_item/flex_basis.js +3 -6
- package/dist/cjs/base/ui/system/flex_item/flex_grow.js +3 -6
- package/dist/cjs/base/ui/system/flex_item/flex_item_set.js +12 -13
- package/dist/cjs/base/ui/system/flex_item/flex_shrink.js +3 -6
- package/dist/cjs/base/ui/system/flex_item/justify_self.js +3 -6
- package/dist/cjs/base/ui/system/flex_item/order.js +3 -6
- package/dist/cjs/base/ui/system/index.js +104 -416
- package/dist/cjs/base/ui/system/overflow.js +3 -6
- package/dist/cjs/base/ui/system/position/bottom.js +4 -6
- package/dist/cjs/base/ui/system/position/left.js +4 -6
- package/dist/cjs/base/ui/system/position/position.js +3 -6
- package/dist/cjs/base/ui/system/position/position_set.js +11 -13
- package/dist/cjs/base/ui/system/position/right.js +4 -6
- package/dist/cjs/base/ui/system/position/top.js +4 -6
- package/dist/cjs/base/ui/system/position/z_index.js +3 -6
- package/dist/cjs/base/ui/system/spacing/margin.js +4 -6
- package/dist/cjs/base/ui/system/spacing/padding.js +4 -6
- package/dist/cjs/base/ui/system/spacing/spacing_set.js +7 -13
- package/dist/cjs/base/ui/system/typography/font_family.js +3 -6
- package/dist/cjs/base/ui/system/typography/font_size.js +3 -6
- package/dist/cjs/base/ui/system/typography/font_style.js +3 -6
- package/dist/cjs/base/ui/system/typography/font_weight.js +3 -6
- package/dist/cjs/base/ui/system/typography/letter_spacing.js +3 -6
- package/dist/cjs/base/ui/system/typography/line_height.js +3 -6
- package/dist/cjs/base/ui/system/typography/text_align.js +3 -6
- package/dist/cjs/base/ui/system/typography/text_color.js +3 -6
- package/dist/cjs/base/ui/system/typography/text_decoration.js +3 -6
- package/dist/cjs/base/ui/system/typography/text_transform.js +3 -6
- package/dist/cjs/base/ui/system/typography/typography_set.js +15 -13
- package/dist/cjs/base/ui/system/utils/ensure_numbers_are_within_scale.js +3 -4
- package/dist/cjs/base/ui/system/utils/get_style_props_for_responsive_prop.js +47 -87
- package/dist/cjs/base/ui/table_picker.js +18 -42
- package/dist/cjs/base/ui/table_picker_synced.js +17 -39
- package/dist/cjs/base/ui/text.js +40 -73
- package/dist/cjs/base/ui/text_button.js +51 -83
- package/dist/cjs/base/ui/theme/default_theme/button_variants.js +3 -3
- package/dist/cjs/base/ui/theme/default_theme/control_sizes.js +51 -45
- package/dist/cjs/base/ui/theme/default_theme/heading_styles.js +1 -1
- package/dist/cjs/base/ui/theme/default_theme/index.js +9 -15
- package/dist/cjs/base/ui/theme/default_theme/input_variants.js +3 -3
- package/dist/cjs/base/ui/theme/default_theme/link_variants.js +3 -3
- package/dist/cjs/base/ui/theme/default_theme/select_buttons_variants.js +4 -4
- package/dist/cjs/base/ui/theme/default_theme/select_variants.js +8 -17
- package/dist/cjs/base/ui/theme/default_theme/switch_variants.js +23 -29
- package/dist/cjs/base/ui/theme/default_theme/text_button_variants.js +5 -5
- package/dist/cjs/base/ui/theme/default_theme/text_styles.js +1 -1
- package/dist/cjs/base/ui/theme/default_theme/tokens.js +14 -14
- package/dist/cjs/base/ui/theme/theme_context.js +2 -2
- package/dist/cjs/base/ui/theme/use_theme.js +2 -2
- package/dist/cjs/base/ui/tooltip.js +134 -174
- package/dist/cjs/base/ui/types/aria_props.js +1 -23
- package/dist/cjs/base/ui/types/data_attributes_prop.js +1 -18
- package/dist/cjs/base/ui/types/tooltip_anchor_props.js +1 -17
- package/dist/cjs/base/ui/ui.js +48 -49
- package/dist/cjs/base/ui/unstable_standalone_ui.js +27 -27
- package/dist/cjs/base/ui/use_base.js +1 -1
- package/dist/cjs/base/ui/use_cursor.js +5 -4
- package/dist/cjs/base/ui/use_form_field.js +1 -1
- package/dist/cjs/base/ui/use_loadable.js +25 -91
- package/dist/cjs/base/ui/use_record_action_data.js +4 -3
- package/dist/cjs/base/ui/use_records.js +9 -13
- package/dist/cjs/base/ui/use_session.js +1 -1
- package/dist/cjs/base/ui/use_settings_button.js +4 -3
- package/dist/cjs/base/ui/use_styled_system.js +7 -14
- package/dist/cjs/base/ui/use_text_color_for_background_color.js +4 -3
- package/dist/cjs/base/ui/use_view_metadata.js +4 -4
- package/dist/cjs/base/ui/use_viewport.js +2 -2
- package/dist/cjs/base/ui/view_picker.js +26 -70
- package/dist/cjs/base/ui/view_picker_synced.js +18 -40
- package/dist/cjs/base/ui/viewport_constraint.js +67 -114
- package/dist/cjs/base/ui/with_styled_system.js +25 -61
- package/dist/cjs/base/undo_redo.js +21 -32
- package/dist/cjs/base/unstable_testing_utils.js +27 -27
- package/dist/cjs/base/viewport.js +268 -312
- package/dist/cjs/injected/airtable_interface.js +4 -4
- package/dist/cjs/interface/assert_run_context.js +12 -0
- package/dist/cjs/interface/index.js +4 -18
- package/dist/cjs/interface/models/base.js +15 -34
- package/dist/cjs/interface/models/field.js +5 -19
- package/dist/cjs/interface/models/models.js +8 -7
- package/dist/cjs/interface/models/mutations.js +50 -66
- package/dist/cjs/interface/models/record.js +29 -49
- package/dist/cjs/interface/models/record_store.js +25 -57
- package/dist/cjs/interface/models/session.js +2 -16
- package/dist/cjs/interface/models/table.js +66 -95
- package/dist/cjs/interface/sdk.js +61 -87
- package/dist/cjs/interface/types/airtable_interface.js +2 -2
- package/dist/cjs/interface/types/mutations.js +3 -10
- package/dist/cjs/interface/ui/block_wrapper.js +56 -48
- package/dist/cjs/interface/ui/initialize_block.js +13 -28
- package/dist/cjs/interface/ui/ui.js +20 -19
- package/dist/cjs/interface/ui/use_base.js +1 -1
- package/dist/cjs/interface/ui/use_custom_properties.js +19 -35
- package/dist/cjs/interface/ui/use_records.js +6 -5
- package/dist/cjs/interface/ui/use_run_info.js +2 -2
- package/dist/cjs/interface/ui/use_session.js +1 -1
- package/dist/cjs/shared/color_utils.js +9 -16
- package/dist/cjs/shared/colors.js +2 -2
- package/dist/cjs/shared/error_utils.js +9 -11
- package/dist/cjs/shared/event_tracker.js +3 -3
- package/dist/cjs/shared/global_config.js +337 -449
- package/dist/cjs/shared/models/abstract_model.js +72 -97
- package/dist/cjs/shared/models/base_core.js +394 -514
- package/dist/cjs/shared/models/field_core.js +236 -279
- package/dist/cjs/shared/models/mutations_core.js +283 -379
- package/dist/cjs/shared/models/record_core.js +174 -231
- package/dist/cjs/shared/models/record_store_core.js +119 -172
- package/dist/cjs/shared/models/session_core.js +116 -170
- package/dist/cjs/shared/models/table_core.js +1258 -1501
- package/dist/cjs/shared/private_utils.js +54 -124
- package/dist/cjs/shared/sdk_core.js +68 -70
- package/dist/cjs/shared/types/field_core.js +1 -1
- package/dist/cjs/shared/types/mutation_constants.js +4 -4
- package/dist/cjs/shared/types/mutations_core.js +1 -1
- package/dist/cjs/shared/types/permission_levels.js +1 -1
- package/dist/cjs/shared/ui/global_config_synced_component_helpers.js +9 -9
- package/dist/cjs/shared/ui/loader.js +14 -35
- package/dist/cjs/shared/ui/remote_utils.js +5 -7
- package/dist/cjs/shared/ui/sdk_context.js +4 -8
- package/dist/cjs/shared/ui/use_array_identity.js +2 -2
- package/dist/cjs/shared/ui/use_base.js +6 -5
- package/dist/cjs/shared/ui/use_color_scheme.js +3 -8
- package/dist/cjs/shared/ui/use_global_config.js +5 -4
- package/dist/cjs/shared/ui/use_session.js +6 -5
- package/dist/cjs/shared/ui/use_synced.js +7 -5
- package/dist/cjs/shared/ui/use_watchable.js +13 -42
- package/dist/cjs/shared/ui/with_hooks.js +6 -13
- package/dist/cjs/shared/unstable_private_utils.js +4 -6
- package/dist/cjs/shared/warning.js +5 -5
- package/dist/cjs/shared/watchable.js +110 -176
- package/dist/cjs/stats/block_stats.js +62 -85
- package/dist/cjs/testing/base/abstract_mock_airtable_interface.js +208 -0
- package/dist/cjs/testing/interface/abstract_mock_airtable_interface.js +124 -0
- package/dist/types/src/base/assert_run_context.d.ts +2 -0
- package/dist/types/src/base/assert_run_context.d.ts.map +1 -0
- package/dist/types/src/base/index.d.ts +1 -0
- package/dist/types/src/base/index.d.ts.map +1 -1
- package/dist/types/src/base/models/models.d.ts +1 -0
- package/dist/types/src/base/models/models.d.ts.map +1 -1
- package/dist/types/src/base/models/mutations.d.ts.map +1 -1
- package/dist/types/src/base/sdk.d.ts.map +1 -1
- package/dist/types/src/base/ui/block_wrapper.d.ts +1 -1
- package/dist/types/src/base/ui/box.d.ts.map +1 -1
- package/dist/types/src/base/ui/button.d.ts +0 -5
- package/dist/types/src/base/ui/button.d.ts.map +1 -1
- package/dist/types/src/base/ui/cell_renderer.d.ts +1 -22
- package/dist/types/src/base/ui/cell_renderer.d.ts.map +1 -1
- package/dist/types/src/base/ui/choice_token.d.ts +1 -21
- package/dist/types/src/base/ui/choice_token.d.ts.map +1 -1
- package/dist/types/src/base/ui/collaborator_token.d.ts +0 -20
- package/dist/types/src/base/ui/collaborator_token.d.ts.map +1 -1
- package/dist/types/src/base/ui/color_palette.d.ts +1 -32
- package/dist/types/src/base/ui/color_palette.d.ts.map +1 -1
- package/dist/types/src/base/ui/color_palette_synced.d.ts +0 -14
- package/dist/types/src/base/ui/color_palette_synced.d.ts.map +1 -1
- package/dist/types/src/base/ui/confirmation_dialog.d.ts +0 -17
- package/dist/types/src/base/ui/confirmation_dialog.d.ts.map +1 -1
- package/dist/types/src/base/ui/control_sizes.d.ts +0 -1
- package/dist/types/src/base/ui/control_sizes.d.ts.map +1 -1
- package/dist/types/src/base/ui/dialog.d.ts +1 -23
- package/dist/types/src/base/ui/dialog.d.ts.map +1 -1
- package/dist/types/src/base/ui/dialog_close_button.d.ts +2 -24
- package/dist/types/src/base/ui/dialog_close_button.d.ts.map +1 -1
- package/dist/types/src/base/ui/field_icon.d.ts +1 -17
- package/dist/types/src/base/ui/field_icon.d.ts.map +1 -1
- package/dist/types/src/base/ui/field_picker.d.ts +0 -23
- package/dist/types/src/base/ui/field_picker.d.ts.map +1 -1
- package/dist/types/src/base/ui/field_picker_synced.d.ts.map +1 -1
- package/dist/types/src/base/ui/form_field.d.ts +0 -4
- package/dist/types/src/base/ui/form_field.d.ts.map +1 -1
- package/dist/types/src/base/ui/heading.d.ts +1 -1
- package/dist/types/src/base/ui/heading.d.ts.map +1 -1
- package/dist/types/src/base/ui/icon.d.ts +0 -16
- package/dist/types/src/base/ui/icon.d.ts.map +1 -1
- package/dist/types/src/base/ui/icon_config.d.ts +50 -51
- package/dist/types/src/base/ui/icon_config.d.ts.map +1 -1
- package/dist/types/src/base/ui/initialize_block.d.ts.map +1 -1
- package/dist/types/src/base/ui/input.d.ts +12 -46
- package/dist/types/src/base/ui/input.d.ts.map +1 -1
- package/dist/types/src/base/ui/input_synced.d.ts.map +1 -1
- package/dist/types/src/base/ui/label.d.ts.map +1 -1
- package/dist/types/src/base/ui/link.d.ts +1 -5
- package/dist/types/src/base/ui/link.d.ts.map +1 -1
- package/dist/types/src/base/ui/loader.d.ts +3 -20
- package/dist/types/src/base/ui/loader.d.ts.map +1 -1
- package/dist/types/src/base/ui/modal.d.ts +1 -14
- package/dist/types/src/base/ui/modal.d.ts.map +1 -1
- package/dist/types/src/base/ui/model_picker_select.d.ts.map +1 -1
- package/dist/types/src/base/ui/popover.d.ts +1 -17
- package/dist/types/src/base/ui/popover.d.ts.map +1 -1
- package/dist/types/src/base/ui/progress_bar.d.ts +1 -24
- package/dist/types/src/base/ui/progress_bar.d.ts.map +1 -1
- package/dist/types/src/base/ui/record_card.d.ts +1 -23
- package/dist/types/src/base/ui/record_card.d.ts.map +1 -1
- package/dist/types/src/base/ui/record_card_list.d.ts +1 -18
- package/dist/types/src/base/ui/record_card_list.d.ts.map +1 -1
- package/dist/types/src/base/ui/select.d.ts +0 -44
- package/dist/types/src/base/ui/select.d.ts.map +1 -1
- package/dist/types/src/base/ui/select_and_select_buttons_helpers.d.ts +0 -2
- package/dist/types/src/base/ui/select_and_select_buttons_helpers.d.ts.map +1 -1
- package/dist/types/src/base/ui/select_buttons.d.ts +0 -22
- package/dist/types/src/base/ui/select_buttons.d.ts.map +1 -1
- package/dist/types/src/base/ui/select_buttons_synced.d.ts.map +1 -1
- package/dist/types/src/base/ui/select_synced.d.ts.map +1 -1
- package/dist/types/src/base/ui/switch.d.ts +0 -22
- package/dist/types/src/base/ui/switch.d.ts.map +1 -1
- package/dist/types/src/base/ui/switch_synced.d.ts.map +1 -1
- package/dist/types/src/base/ui/synced.d.ts +2 -8
- package/dist/types/src/base/ui/synced.d.ts.map +1 -1
- package/dist/types/src/base/ui/system/all_styles_set.d.ts +0 -3
- package/dist/types/src/base/ui/system/all_styles_set.d.ts.map +1 -1
- package/dist/types/src/base/ui/system/appearance/appearance_set.d.ts +0 -1
- package/dist/types/src/base/ui/system/appearance/appearance_set.d.ts.map +1 -1
- package/dist/types/src/base/ui/system/appearance/background_color.d.ts +0 -1
- package/dist/types/src/base/ui/system/appearance/background_color.d.ts.map +1 -1
- package/dist/types/src/base/ui/system/appearance/border.d.ts +0 -1
- package/dist/types/src/base/ui/system/appearance/border.d.ts.map +1 -1
- package/dist/types/src/base/ui/system/appearance/border_radius.d.ts +0 -1
- package/dist/types/src/base/ui/system/appearance/border_radius.d.ts.map +1 -1
- package/dist/types/src/base/ui/system/appearance/box_shadow.d.ts +0 -1
- package/dist/types/src/base/ui/system/appearance/box_shadow.d.ts.map +1 -1
- package/dist/types/src/base/ui/system/appearance/opacity.d.ts +0 -1
- package/dist/types/src/base/ui/system/appearance/opacity.d.ts.map +1 -1
- package/dist/types/src/base/ui/system/dimensions/dimensions_set.d.ts +0 -1
- package/dist/types/src/base/ui/system/dimensions/dimensions_set.d.ts.map +1 -1
- package/dist/types/src/base/ui/system/dimensions/height.d.ts +0 -1
- package/dist/types/src/base/ui/system/dimensions/height.d.ts.map +1 -1
- package/dist/types/src/base/ui/system/dimensions/max_height.d.ts +0 -1
- package/dist/types/src/base/ui/system/dimensions/max_height.d.ts.map +1 -1
- package/dist/types/src/base/ui/system/dimensions/max_width.d.ts +0 -1
- package/dist/types/src/base/ui/system/dimensions/max_width.d.ts.map +1 -1
- package/dist/types/src/base/ui/system/dimensions/min_height.d.ts +0 -1
- package/dist/types/src/base/ui/system/dimensions/min_height.d.ts.map +1 -1
- package/dist/types/src/base/ui/system/dimensions/min_width.d.ts +0 -1
- package/dist/types/src/base/ui/system/dimensions/min_width.d.ts.map +1 -1
- package/dist/types/src/base/ui/system/dimensions/width.d.ts +0 -1
- package/dist/types/src/base/ui/system/dimensions/width.d.ts.map +1 -1
- package/dist/types/src/base/ui/system/display.d.ts +0 -1
- package/dist/types/src/base/ui/system/display.d.ts.map +1 -1
- package/dist/types/src/base/ui/system/flex_container/align_content.d.ts +0 -1
- package/dist/types/src/base/ui/system/flex_container/align_content.d.ts.map +1 -1
- package/dist/types/src/base/ui/system/flex_container/align_items.d.ts +0 -1
- package/dist/types/src/base/ui/system/flex_container/align_items.d.ts.map +1 -1
- package/dist/types/src/base/ui/system/flex_container/flex_container_set.d.ts +0 -1
- package/dist/types/src/base/ui/system/flex_container/flex_container_set.d.ts.map +1 -1
- package/dist/types/src/base/ui/system/flex_container/flex_direction.d.ts +0 -1
- package/dist/types/src/base/ui/system/flex_container/flex_direction.d.ts.map +1 -1
- package/dist/types/src/base/ui/system/flex_container/flex_wrap.d.ts +0 -1
- package/dist/types/src/base/ui/system/flex_container/flex_wrap.d.ts.map +1 -1
- package/dist/types/src/base/ui/system/flex_container/justify_content.d.ts +0 -1
- package/dist/types/src/base/ui/system/flex_container/justify_content.d.ts.map +1 -1
- package/dist/types/src/base/ui/system/flex_container/justify_items.d.ts +0 -1
- package/dist/types/src/base/ui/system/flex_container/justify_items.d.ts.map +1 -1
- package/dist/types/src/base/ui/system/flex_item/align_self.d.ts +0 -1
- package/dist/types/src/base/ui/system/flex_item/align_self.d.ts.map +1 -1
- package/dist/types/src/base/ui/system/flex_item/flex.d.ts +0 -1
- package/dist/types/src/base/ui/system/flex_item/flex.d.ts.map +1 -1
- package/dist/types/src/base/ui/system/flex_item/flex_basis.d.ts +0 -1
- package/dist/types/src/base/ui/system/flex_item/flex_basis.d.ts.map +1 -1
- package/dist/types/src/base/ui/system/flex_item/flex_grow.d.ts +0 -1
- package/dist/types/src/base/ui/system/flex_item/flex_grow.d.ts.map +1 -1
- package/dist/types/src/base/ui/system/flex_item/flex_item_set.d.ts +0 -1
- package/dist/types/src/base/ui/system/flex_item/flex_item_set.d.ts.map +1 -1
- package/dist/types/src/base/ui/system/flex_item/flex_shrink.d.ts +0 -1
- package/dist/types/src/base/ui/system/flex_item/flex_shrink.d.ts.map +1 -1
- package/dist/types/src/base/ui/system/flex_item/justify_self.d.ts +0 -1
- package/dist/types/src/base/ui/system/flex_item/justify_self.d.ts.map +1 -1
- package/dist/types/src/base/ui/system/flex_item/order.d.ts +0 -1
- package/dist/types/src/base/ui/system/flex_item/order.d.ts.map +1 -1
- package/dist/types/src/base/ui/system/index.d.ts +52 -52
- package/dist/types/src/base/ui/system/index.d.ts.map +1 -1
- package/dist/types/src/base/ui/system/overflow.d.ts +0 -1
- package/dist/types/src/base/ui/system/overflow.d.ts.map +1 -1
- package/dist/types/src/base/ui/system/position/bottom.d.ts +0 -1
- package/dist/types/src/base/ui/system/position/bottom.d.ts.map +1 -1
- package/dist/types/src/base/ui/system/position/left.d.ts +0 -1
- package/dist/types/src/base/ui/system/position/left.d.ts.map +1 -1
- package/dist/types/src/base/ui/system/position/position.d.ts +0 -1
- package/dist/types/src/base/ui/system/position/position.d.ts.map +1 -1
- package/dist/types/src/base/ui/system/position/position_set.d.ts +0 -1
- package/dist/types/src/base/ui/system/position/position_set.d.ts.map +1 -1
- package/dist/types/src/base/ui/system/position/right.d.ts +0 -1
- package/dist/types/src/base/ui/system/position/right.d.ts.map +1 -1
- package/dist/types/src/base/ui/system/position/top.d.ts +0 -1
- package/dist/types/src/base/ui/system/position/top.d.ts.map +1 -1
- package/dist/types/src/base/ui/system/position/z_index.d.ts +0 -1
- package/dist/types/src/base/ui/system/position/z_index.d.ts.map +1 -1
- package/dist/types/src/base/ui/system/spacing/margin.d.ts +0 -1
- package/dist/types/src/base/ui/system/spacing/margin.d.ts.map +1 -1
- package/dist/types/src/base/ui/system/spacing/padding.d.ts +0 -1
- package/dist/types/src/base/ui/system/spacing/padding.d.ts.map +1 -1
- package/dist/types/src/base/ui/system/spacing/spacing_set.d.ts +0 -1
- package/dist/types/src/base/ui/system/spacing/spacing_set.d.ts.map +1 -1
- package/dist/types/src/base/ui/system/typography/font_family.d.ts +0 -1
- package/dist/types/src/base/ui/system/typography/font_family.d.ts.map +1 -1
- package/dist/types/src/base/ui/system/typography/font_size.d.ts +0 -1
- package/dist/types/src/base/ui/system/typography/font_size.d.ts.map +1 -1
- package/dist/types/src/base/ui/system/typography/font_style.d.ts +0 -1
- package/dist/types/src/base/ui/system/typography/font_style.d.ts.map +1 -1
- package/dist/types/src/base/ui/system/typography/font_weight.d.ts +0 -1
- package/dist/types/src/base/ui/system/typography/font_weight.d.ts.map +1 -1
- package/dist/types/src/base/ui/system/typography/letter_spacing.d.ts +0 -1
- package/dist/types/src/base/ui/system/typography/letter_spacing.d.ts.map +1 -1
- package/dist/types/src/base/ui/system/typography/line_height.d.ts +0 -1
- package/dist/types/src/base/ui/system/typography/line_height.d.ts.map +1 -1
- package/dist/types/src/base/ui/system/typography/text_align.d.ts +0 -1
- package/dist/types/src/base/ui/system/typography/text_align.d.ts.map +1 -1
- package/dist/types/src/base/ui/system/typography/text_color.d.ts +0 -1
- package/dist/types/src/base/ui/system/typography/text_color.d.ts.map +1 -1
- package/dist/types/src/base/ui/system/typography/text_decoration.d.ts +0 -1
- package/dist/types/src/base/ui/system/typography/text_decoration.d.ts.map +1 -1
- package/dist/types/src/base/ui/system/typography/text_transform.d.ts +0 -1
- package/dist/types/src/base/ui/system/typography/text_transform.d.ts.map +1 -1
- package/dist/types/src/base/ui/system/typography/typography_set.d.ts +0 -1
- package/dist/types/src/base/ui/system/typography/typography_set.d.ts.map +1 -1
- package/dist/types/src/base/ui/table_picker.d.ts +0 -21
- package/dist/types/src/base/ui/table_picker.d.ts.map +1 -1
- package/dist/types/src/base/ui/table_picker_synced.d.ts.map +1 -1
- package/dist/types/src/base/ui/text.d.ts +0 -3
- package/dist/types/src/base/ui/text.d.ts.map +1 -1
- package/dist/types/src/base/ui/text_button.d.ts +1 -5
- package/dist/types/src/base/ui/text_button.d.ts.map +1 -1
- package/dist/types/src/base/ui/theme/default_theme/index.d.ts +1 -1
- package/dist/types/src/base/ui/theme/theme_context.d.ts +1 -1
- package/dist/types/src/base/ui/theme/use_theme.d.ts +1 -1
- package/dist/types/src/base/ui/tooltip.d.ts +0 -16
- package/dist/types/src/base/ui/tooltip.d.ts.map +1 -1
- package/dist/types/src/base/ui/types/aria_props.d.ts.map +1 -1
- package/dist/types/src/base/ui/types/data_attributes_prop.d.ts +0 -4
- package/dist/types/src/base/ui/types/data_attributes_prop.d.ts.map +1 -1
- package/dist/types/src/base/ui/types/tooltip_anchor_props.d.ts +0 -7
- package/dist/types/src/base/ui/types/tooltip_anchor_props.d.ts.map +1 -1
- package/dist/types/src/base/ui/ui.d.ts +1 -0
- package/dist/types/src/base/ui/ui.d.ts.map +1 -1
- package/dist/types/src/base/ui/view_picker.d.ts +0 -23
- package/dist/types/src/base/ui/view_picker.d.ts.map +1 -1
- package/dist/types/src/base/ui/view_picker_synced.d.ts.map +1 -1
- package/dist/types/src/base/ui/viewport_constraint.d.ts +1 -14
- package/dist/types/src/base/ui/viewport_constraint.d.ts.map +1 -1
- package/dist/types/src/base/unstable_testing_utils.d.ts +1 -1
- package/dist/types/src/base/unstable_testing_utils.d.ts.map +1 -1
- package/dist/types/src/interface/assert_run_context.d.ts +2 -0
- package/dist/types/src/interface/assert_run_context.d.ts.map +1 -0
- package/dist/types/src/interface/index.d.ts +1 -6
- package/dist/types/src/interface/index.d.ts.map +1 -1
- package/dist/types/src/interface/models/models.d.ts +1 -0
- package/dist/types/src/interface/models/models.d.ts.map +1 -1
- package/dist/types/src/interface/models/mutations.d.ts.map +1 -1
- package/dist/types/src/interface/ui/initialize_block.d.ts.map +1 -1
- package/dist/types/src/interface/ui/ui.d.ts +1 -0
- package/dist/types/src/interface/ui/ui.d.ts.map +1 -1
- package/dist/types/src/interface/ui/use_custom_properties.d.ts +1 -1
- package/dist/types/src/shared/models/mutations_core.d.ts.map +1 -1
- package/dist/types/src/shared/private_utils.d.ts +0 -9
- package/dist/types/src/shared/private_utils.d.ts.map +1 -1
- package/dist/types/src/shared/ui/global_config_synced_component_helpers.d.ts +0 -2
- package/dist/types/src/shared/ui/global_config_synced_component_helpers.d.ts.map +1 -1
- package/dist/types/src/shared/ui/loader.d.ts.map +1 -1
- package/dist/types/src/shared/ui/with_hooks.d.ts +2 -2
- package/dist/types/src/shared/ui/with_hooks.d.ts.map +1 -1
- package/dist/types/src/testing/{abstract_mock_airtable_interface.d.ts → base/abstract_mock_airtable_interface.d.ts} +13 -13
- package/dist/types/src/testing/base/abstract_mock_airtable_interface.d.ts.map +1 -0
- package/dist/types/src/testing/interface/abstract_mock_airtable_interface.d.ts +51 -0
- package/dist/types/src/testing/interface/abstract_mock_airtable_interface.d.ts.map +1 -0
- package/package.json +13 -13
- package/dist/cjs/base/ui/system/utils/create_responsive_prop_type.js +0 -19
- package/dist/cjs/base/ui/system/utils/create_style_prop_types.js +0 -24
- package/dist/cjs/base/ui/system/utils/enum_prop_type_utils.js +0 -35
- package/dist/cjs/testing/abstract_mock_airtable_interface.js +0 -277
- package/dist/types/src/base/ui/system/utils/create_responsive_prop_type.d.ts +0 -2
- package/dist/types/src/base/ui/system/utils/create_responsive_prop_type.d.ts.map +0 -1
- package/dist/types/src/base/ui/system/utils/create_style_prop_types.d.ts +0 -4
- package/dist/types/src/base/ui/system/utils/create_style_prop_types.d.ts.map +0 -1
- package/dist/types/src/base/ui/system/utils/enum_prop_type_utils.d.ts +0 -21
- package/dist/types/src/base/ui/system/utils/enum_prop_type_utils.d.ts.map +0 -1
- package/dist/types/src/testing/abstract_mock_airtable_interface.d.ts.map +0 -1
|
@@ -1,1561 +1,1318 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
require("core-js/modules/es.array.from.js");
|
|
4
|
-
require("core-js/modules/es.array.slice.js");
|
|
5
|
-
require("core-js/modules/es.object.to-string.js");
|
|
6
|
-
require("core-js/modules/es.regexp.exec.js");
|
|
7
|
-
require("core-js/modules/es.regexp.to-string.js");
|
|
8
|
-
require("core-js/modules/web.dom-collections.iterator.js");
|
|
9
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
10
3
|
Object.defineProperty(exports, "__esModule", {
|
|
11
4
|
value: true
|
|
12
5
|
});
|
|
13
6
|
exports.WatchableTableKeysCore = exports.TableCore = void 0;
|
|
14
|
-
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
15
|
-
require("core-js/modules/es.symbol.js");
|
|
16
|
-
require("core-js/modules/es.symbol.description.js");
|
|
17
|
-
require("core-js/modules/es.array.iterator.js");
|
|
18
|
-
require("core-js/modules/es.array.map.js");
|
|
19
|
-
require("core-js/modules/es.object.from-entries.js");
|
|
20
|
-
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
21
|
-
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
22
|
-
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
23
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
24
|
-
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
25
|
-
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
26
|
-
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
27
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
28
7
|
var _private_utils = require("../private_utils");
|
|
29
8
|
var _error_utils = require("../error_utils");
|
|
30
9
|
var _mutations_core = require("../types/mutations_core");
|
|
31
10
|
var _abstract_model = _interopRequireDefault(require("./abstract_model"));
|
|
32
11
|
var _field_core = require("./field_core");
|
|
33
|
-
function
|
|
34
|
-
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
35
|
-
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
36
|
-
function _callSuper(t, o, e) { return o = (0, _getPrototypeOf2.default)(o), (0, _possibleConstructorReturn2.default)(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], (0, _getPrototypeOf2.default)(t).constructor) : o.apply(t, e)); }
|
|
37
|
-
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
12
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
38
13
|
// This doesn't follow our enum naming conventions because we want the keys
|
|
39
14
|
// to mirror the method/getter names on the model class.
|
|
40
|
-
|
|
15
|
+
const WatchableTableKeysCore = exports.WatchableTableKeysCore = Object.freeze({
|
|
41
16
|
name: 'name',
|
|
42
17
|
description: 'description',
|
|
43
18
|
fields: 'fields'
|
|
44
19
|
});
|
|
45
20
|
|
|
46
21
|
/** @hidden */
|
|
22
|
+
|
|
47
23
|
/** @hidden */
|
|
48
|
-
|
|
24
|
+
class TableCore extends _abstract_model.default {
|
|
25
|
+
/** @internal */
|
|
26
|
+
static _className = 'TableCore';
|
|
27
|
+
/** @internal */
|
|
28
|
+
static _isWatchableKey(key) {
|
|
29
|
+
return (0, _private_utils.isEnumValue)(WatchableTableKeysCore, key);
|
|
30
|
+
}
|
|
31
|
+
/** @internal */
|
|
32
|
+
|
|
33
|
+
/** @internal */
|
|
34
|
+
|
|
35
|
+
/** @internal */
|
|
36
|
+
|
|
37
|
+
/** @internal */
|
|
38
|
+
|
|
49
39
|
/**
|
|
50
40
|
* @internal
|
|
51
41
|
*/
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
/** @internal */
|
|
59
|
-
(0, _defineProperty2.default)(_this, "_recordStore", void 0);
|
|
60
|
-
/** @internal */
|
|
61
|
-
(0, _defineProperty2.default)(_this, "_fieldModelsById", void 0);
|
|
62
|
-
/** @internal */
|
|
63
|
-
(0, _defineProperty2.default)(_this, "_cachedFieldNamesById", void 0);
|
|
64
|
-
_this._parentBase = parentBase;
|
|
65
|
-
_this._recordStore = recordStore;
|
|
66
|
-
_this._fieldModelsById = {}; // Field instances are lazily created by getFieldById.
|
|
67
|
-
_this._cachedFieldNamesById = null;
|
|
68
|
-
return _this;
|
|
42
|
+
constructor(parentBase, recordStore, tableId, sdk) {
|
|
43
|
+
super(sdk, tableId);
|
|
44
|
+
this._parentBase = parentBase;
|
|
45
|
+
this._recordStore = recordStore;
|
|
46
|
+
this._fieldModelsById = {}; // Field instances are lazily created by getFieldById.
|
|
47
|
+
this._cachedFieldNamesById = null;
|
|
69
48
|
}
|
|
70
49
|
|
|
71
50
|
/**
|
|
72
51
|
* @internal
|
|
73
52
|
*/
|
|
74
|
-
(
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
* ```js
|
|
150
|
-
* console.log(`This table has ${myTable.fields.length} fields`);
|
|
151
|
-
* ```
|
|
152
|
-
*/
|
|
153
|
-
}, {
|
|
154
|
-
key: "fields",
|
|
155
|
-
get: function get() {
|
|
156
|
-
// TODO(kasra): is it confusing that this returns an array, since the order
|
|
157
|
-
// is arbitrary?
|
|
158
|
-
// TODO(kasra): cache and freeze this so it isn't O(n)
|
|
159
|
-
var fields = [];
|
|
160
|
-
for (var _i = 0, _Object$keys = Object.keys(this._data.fieldsById); _i < _Object$keys.length; _i++) {
|
|
161
|
-
var _fieldId = _Object$keys[_i];
|
|
162
|
-
var field = this.getFieldById(_fieldId);
|
|
163
|
-
fields.push(field);
|
|
164
|
-
}
|
|
165
|
-
return fields;
|
|
166
|
-
}
|
|
167
|
-
/**
|
|
168
|
-
* Gets the field matching the given ID, or `null` if that field does not exist in this table.
|
|
169
|
-
* @param fieldId The ID of the field.
|
|
170
|
-
* @example
|
|
171
|
-
* ```js
|
|
172
|
-
* const fieldId = 'fldxxxxxxxxxxxxxx';
|
|
173
|
-
* const field = myTable.getFieldByIdIfExists(fieldId);
|
|
174
|
-
* if (field !== null) {
|
|
175
|
-
* console.log(field.name);
|
|
176
|
-
* } else {
|
|
177
|
-
* console.log('No field exists with that ID');
|
|
178
|
-
* }
|
|
179
|
-
* ```
|
|
180
|
-
*/
|
|
181
|
-
}, {
|
|
182
|
-
key: "getFieldByIdIfExists",
|
|
183
|
-
value: function getFieldByIdIfExists(fieldId) {
|
|
184
|
-
if (!this._data.fieldsById[fieldId]) {
|
|
185
|
-
return null;
|
|
186
|
-
} else {
|
|
187
|
-
if (!this._fieldModelsById[fieldId]) {
|
|
188
|
-
this._fieldModelsById[fieldId] = this._constructField(fieldId);
|
|
189
|
-
}
|
|
190
|
-
return this._fieldModelsById[fieldId];
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
/** @internal */
|
|
194
|
-
}, {
|
|
195
|
-
key: "getFieldById",
|
|
196
|
-
value:
|
|
197
|
-
/**
|
|
198
|
-
* Gets the field matching the given ID. Throws if that field does not exist in this table. Use
|
|
199
|
-
* {@link getFieldByIdIfExists} instead if you are unsure whether a field exists with the given
|
|
200
|
-
* ID.
|
|
201
|
-
*
|
|
202
|
-
* @param fieldId The ID of the field.
|
|
203
|
-
* @example
|
|
204
|
-
* ```js
|
|
205
|
-
* const fieldId = 'fldxxxxxxxxxxxxxx';
|
|
206
|
-
* const field = myTable.getFieldById(fieldId);
|
|
207
|
-
* console.log(field.name);
|
|
208
|
-
* // => 'Name'
|
|
209
|
-
* ```
|
|
210
|
-
*/
|
|
211
|
-
function getFieldById(fieldId) {
|
|
212
|
-
var field = this.getFieldByIdIfExists(fieldId);
|
|
213
|
-
if (!field) {
|
|
214
|
-
throw (0, _error_utils.spawnError)("No field with ID %s in table '%s'", fieldId, this.name);
|
|
215
|
-
}
|
|
216
|
-
return field;
|
|
53
|
+
get _dataOrNullIfDeleted() {
|
|
54
|
+
return this._baseData.tablesById[this._id] ?? null;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* The base that this table belongs to.
|
|
58
|
+
*
|
|
59
|
+
* @internal (since we may not be able to return parent model instances in the immutable models world)
|
|
60
|
+
* @example
|
|
61
|
+
* ```js
|
|
62
|
+
* import {base} from '@airtable/blocks/base';
|
|
63
|
+
* const table = base.getTableByName('Table 1');
|
|
64
|
+
* console.log(table.parentBase.id === base.id);
|
|
65
|
+
* // => true
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
get parentBase() {
|
|
69
|
+
return this._parentBase;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* The name of the table. Can be watched.
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```js
|
|
76
|
+
* console.log(myTable.name);
|
|
77
|
+
* // => 'Table 1'
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
get name() {
|
|
81
|
+
return this._data.name;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* The description of the table, if it has one. Can be watched.
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```js
|
|
88
|
+
* console.log(myTable.description);
|
|
89
|
+
* // => 'This is my table'
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
get description() {
|
|
93
|
+
return this._data.description;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* The table's primary field. Every table has exactly one primary
|
|
97
|
+
* field. The primary field of a table will not change.
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* ```js
|
|
101
|
+
* console.log(myTable.primaryField.name);
|
|
102
|
+
* // => 'Name'
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
get primaryField() {
|
|
106
|
+
const primaryField = this.getFieldById(this._data.primaryFieldId);
|
|
107
|
+
return primaryField;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* The fields in this table. The order is arbitrary, since fields are
|
|
111
|
+
* only ordered in the context of a specific view.
|
|
112
|
+
*
|
|
113
|
+
* Can be watched to know when fields are created or deleted.
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* ```js
|
|
117
|
+
* console.log(`This table has ${myTable.fields.length} fields`);
|
|
118
|
+
* ```
|
|
119
|
+
*/
|
|
120
|
+
get fields() {
|
|
121
|
+
// TODO(kasra): is it confusing that this returns an array, since the order
|
|
122
|
+
// is arbitrary?
|
|
123
|
+
// TODO(kasra): cache and freeze this so it isn't O(n)
|
|
124
|
+
const fields = [];
|
|
125
|
+
for (const fieldId of Object.keys(this._data.fieldsById)) {
|
|
126
|
+
const field = this.getFieldById(fieldId);
|
|
127
|
+
fields.push(field);
|
|
217
128
|
}
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
var _iterator = _createForOfIteratorHelper((0, _private_utils.entries)(this._data.fieldsById)),
|
|
237
|
-
_step;
|
|
238
|
-
try {
|
|
239
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
240
|
-
var _step$value = (0, _slicedToArray2.default)(_step.value, 2),
|
|
241
|
-
_fieldId2 = _step$value[0],
|
|
242
|
-
fieldData = _step$value[1];
|
|
243
|
-
if (fieldData.name === fieldName) {
|
|
244
|
-
return this.getFieldByIdIfExists(_fieldId2);
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
} catch (err) {
|
|
248
|
-
_iterator.e(err);
|
|
249
|
-
} finally {
|
|
250
|
-
_iterator.f();
|
|
251
|
-
}
|
|
129
|
+
return fields;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Gets the field matching the given ID, or `null` if that field does not exist in this table.
|
|
133
|
+
* @param fieldId The ID of the field.
|
|
134
|
+
* @example
|
|
135
|
+
* ```js
|
|
136
|
+
* const fieldId = 'fldxxxxxxxxxxxxxx';
|
|
137
|
+
* const field = myTable.getFieldByIdIfExists(fieldId);
|
|
138
|
+
* if (field !== null) {
|
|
139
|
+
* console.log(field.name);
|
|
140
|
+
* } else {
|
|
141
|
+
* console.log('No field exists with that ID');
|
|
142
|
+
* }
|
|
143
|
+
* ```
|
|
144
|
+
*/
|
|
145
|
+
getFieldByIdIfExists(fieldId) {
|
|
146
|
+
if (!this._data.fieldsById[fieldId]) {
|
|
252
147
|
return null;
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
* table. Use {@link getFieldByNameIfExists} instead if you are unsure whether a field exists
|
|
257
|
-
* with the given name.
|
|
258
|
-
*
|
|
259
|
-
* @param fieldName The name of the field you're looking for.
|
|
260
|
-
* @example
|
|
261
|
-
* ```js
|
|
262
|
-
* const field = myTable.getFieldByName('Name');
|
|
263
|
-
* console.log(field.id);
|
|
264
|
-
* // => 'fldxxxxxxxxxxxxxx'
|
|
265
|
-
* ```
|
|
266
|
-
*/
|
|
267
|
-
}, {
|
|
268
|
-
key: "getFieldByName",
|
|
269
|
-
value: function getFieldByName(fieldName) {
|
|
270
|
-
var field = this.getFieldByNameIfExists(fieldName);
|
|
271
|
-
if (!field) {
|
|
272
|
-
throw (0, _error_utils.spawnError)("No field named '%s' in table '%s'", fieldName, this.name);
|
|
148
|
+
} else {
|
|
149
|
+
if (!this._fieldModelsById[fieldId]) {
|
|
150
|
+
this._fieldModelsById[fieldId] = this._constructField(fieldId);
|
|
273
151
|
}
|
|
274
|
-
return
|
|
152
|
+
return this._fieldModelsById[fieldId];
|
|
275
153
|
}
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
154
|
+
}
|
|
155
|
+
/** @internal */
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Gets the field matching the given ID. Throws if that field does not exist in this table. Use
|
|
159
|
+
* {@link getFieldByIdIfExists} instead if you are unsure whether a field exists with the given
|
|
160
|
+
* ID.
|
|
161
|
+
*
|
|
162
|
+
* @param fieldId The ID of the field.
|
|
163
|
+
* @example
|
|
164
|
+
* ```js
|
|
165
|
+
* const fieldId = 'fldxxxxxxxxxxxxxx';
|
|
166
|
+
* const field = myTable.getFieldById(fieldId);
|
|
167
|
+
* console.log(field.name);
|
|
168
|
+
* // => 'Name'
|
|
169
|
+
* ```
|
|
170
|
+
*/
|
|
171
|
+
getFieldById(fieldId) {
|
|
172
|
+
const field = this.getFieldByIdIfExists(fieldId);
|
|
173
|
+
if (!field) {
|
|
174
|
+
throw (0, _error_utils.spawnError)("No field with ID %s in table '%s'", fieldId, this.name);
|
|
291
175
|
}
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
176
|
+
return field;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Gets the field matching the given name, or `null` if no field exists with that name in this
|
|
180
|
+
* table.
|
|
181
|
+
*
|
|
182
|
+
* @param fieldName The name of the field you're looking for.
|
|
183
|
+
* @example
|
|
184
|
+
* ```js
|
|
185
|
+
* const field = myTable.getFieldByNameIfExists('Name');
|
|
186
|
+
* if (field !== null) {
|
|
187
|
+
* console.log(field.id);
|
|
188
|
+
* } else {
|
|
189
|
+
* console.log('No field exists with that name');
|
|
190
|
+
* }
|
|
191
|
+
* ```
|
|
192
|
+
*/
|
|
193
|
+
getFieldByNameIfExists(fieldName) {
|
|
194
|
+
for (const [fieldId, fieldData] of (0, _private_utils.entries)(this._data.fieldsById)) {
|
|
195
|
+
if (fieldData.name === fieldName) {
|
|
196
|
+
return this.getFieldByIdIfExists(fieldId);
|
|
309
197
|
}
|
|
310
|
-
return field;
|
|
311
198
|
}
|
|
312
|
-
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
199
|
+
return null;
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Gets the field matching the given name. Throws if no field exists with that name in this
|
|
203
|
+
* table. Use {@link getFieldByNameIfExists} instead if you are unsure whether a field exists
|
|
204
|
+
* with the given name.
|
|
205
|
+
*
|
|
206
|
+
* @param fieldName The name of the field you're looking for.
|
|
207
|
+
* @example
|
|
208
|
+
* ```js
|
|
209
|
+
* const field = myTable.getFieldByName('Name');
|
|
210
|
+
* console.log(field.id);
|
|
211
|
+
* // => 'fldxxxxxxxxxxxxxx'
|
|
212
|
+
* ```
|
|
213
|
+
*/
|
|
214
|
+
getFieldByName(fieldName) {
|
|
215
|
+
const field = this.getFieldByNameIfExists(fieldName);
|
|
216
|
+
if (!field) {
|
|
217
|
+
throw (0, _error_utils.spawnError)("No field named '%s' in table '%s'", fieldName, this.name);
|
|
323
218
|
}
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
219
|
+
return field;
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* The field matching the given ID or name. Returns `null` if no matching field exists within
|
|
223
|
+
* this table.
|
|
224
|
+
*
|
|
225
|
+
* This method is convenient when building an extension for a specific base, but for more generic
|
|
226
|
+
* extensions the best practice is to use the {@link getFieldByIdIfExists} or
|
|
227
|
+
* {@link getFieldByNameIfExists} methods instead.
|
|
228
|
+
*
|
|
229
|
+
* @param fieldIdOrName The ID or name of the field you're looking for.
|
|
230
|
+
*/
|
|
231
|
+
getFieldIfExists(fieldIdOrName) {
|
|
232
|
+
return this.getFieldByIdIfExists(fieldIdOrName) ?? this.getFieldByNameIfExists(fieldIdOrName);
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* The field matching the given ID or name. Throws if no matching field exists within this table.
|
|
236
|
+
* Use {@link getFieldIfExists} instead if you are unsure whether a field exists with the given
|
|
237
|
+
* name/ID.
|
|
238
|
+
*
|
|
239
|
+
* This method is convenient when building an extension for a specific base, but for more generic
|
|
240
|
+
* extensions the best practice is to use the {@link getFieldById} or {@link getFieldByName} methods
|
|
241
|
+
* instead.
|
|
242
|
+
*
|
|
243
|
+
* @param fieldIdOrName The ID or name of the field you're looking for.
|
|
244
|
+
*/
|
|
245
|
+
getField(fieldIdOrName) {
|
|
246
|
+
const field = this.getFieldIfExists(fieldIdOrName);
|
|
247
|
+
if (!field) {
|
|
248
|
+
throw (0, _error_utils.spawnError)("No field with ID or name '%s' in table '%s'", fieldIdOrName, this.name);
|
|
330
249
|
}
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
250
|
+
return field;
|
|
251
|
+
}
|
|
252
|
+
/** @internal */
|
|
253
|
+
_cellValuesByFieldIdOrNameToCellValuesByFieldId(cellValuesByFieldIdOrName, onGenerateIdForNewForeignRecord) {
|
|
254
|
+
return Object.fromEntries((0, _private_utils.entries)(cellValuesByFieldIdOrName).map(_ref => {
|
|
255
|
+
let [fieldIdOrName, cellValue] = _ref;
|
|
256
|
+
const field = this.__getFieldMatching(fieldIdOrName);
|
|
257
|
+
return [field.id, this._adjustCellValueForFieldIfNecessary(field, cellValue, onGenerateIdForNewForeignRecord)];
|
|
258
|
+
}));
|
|
259
|
+
}
|
|
260
|
+
// This can be overridden by subclasses. See sdk/src/interface/models/table.ts.
|
|
261
|
+
/** @internal */
|
|
262
|
+
_adjustCellValueForFieldIfNecessary(field, cellValue, onGenerateIdForNewForeignRecord) {
|
|
263
|
+
return cellValue;
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* @internal
|
|
267
|
+
*/
|
|
268
|
+
__getFieldMatching(fieldOrFieldIdOrFieldName) {
|
|
269
|
+
let field;
|
|
270
|
+
if (fieldOrFieldIdOrFieldName instanceof _field_core.FieldCore) {
|
|
271
|
+
if (fieldOrFieldIdOrFieldName.parentTable.id !== this.id) {
|
|
272
|
+
throw (0, _error_utils.spawnError)("Field '%s' is from a different table than table '%s'", fieldOrFieldIdOrFieldName.name, this.name);
|
|
348
273
|
}
|
|
349
|
-
|
|
350
|
-
|
|
274
|
+
field = fieldOrFieldIdOrFieldName;
|
|
275
|
+
} else {
|
|
276
|
+
field = this.getFieldByIdIfExists(fieldOrFieldIdOrFieldName) || this.getFieldByNameIfExists(fieldOrFieldIdOrFieldName);
|
|
277
|
+
if (field === null) {
|
|
278
|
+
throw (0, _error_utils.spawnError)("Field '%s' does not exist in table '%s'", fieldOrFieldIdOrFieldName, this.name);
|
|
351
279
|
}
|
|
352
|
-
return field;
|
|
353
280
|
}
|
|
281
|
+
if (field.isDeleted) {
|
|
282
|
+
throw (0, _error_utils.spawnError)("Field '%s' was deleted from table '%s'", field.name, this.name);
|
|
283
|
+
}
|
|
284
|
+
return field;
|
|
285
|
+
}
|
|
354
286
|
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
287
|
+
/**
|
|
288
|
+
* Updates cell values for a record.
|
|
289
|
+
*
|
|
290
|
+
* Throws an error if the user does not have permission to update the given cell values in
|
|
291
|
+
* the record, or if invalid input is provided (eg. invalid cell values).
|
|
292
|
+
*
|
|
293
|
+
* Refer to {@link FieldType} for cell value write formats.
|
|
294
|
+
*
|
|
295
|
+
* This action is asynchronous: `await` the returned promise if you wish to wait for the updated
|
|
296
|
+
* cell values to be persisted to Airtable servers.
|
|
297
|
+
* Updates are applied optimistically locally, so your changes will be reflected in your extension
|
|
298
|
+
* before the promise resolves.
|
|
299
|
+
*
|
|
300
|
+
* @param recordOrRecordId the record to update
|
|
301
|
+
* @param fields cell values to update in that record, specified as object mapping `FieldId` or field name to value for that field.
|
|
302
|
+
* @example
|
|
303
|
+
* ```js
|
|
304
|
+
* function updateRecord(record, recordFields) {
|
|
305
|
+
* if (table.hasPermissionToUpdateRecord(record, recordFields)) {
|
|
306
|
+
* table.updateRecordAsync(record, recordFields);
|
|
307
|
+
* }
|
|
308
|
+
* // The updated values will now show in your extension (eg in
|
|
309
|
+
* // `table.selectRecords()` result) but are still being saved to Airtable
|
|
310
|
+
* // servers (e.g. other users may not be able to see them yet).
|
|
311
|
+
* }
|
|
312
|
+
*
|
|
313
|
+
* async function updateRecordAsync(record, recordFields) {
|
|
314
|
+
* if (table.hasPermissionToUpdateRecord(record, recordFields)) {
|
|
315
|
+
* await table.updateRecordAsync(record, recordFields);
|
|
316
|
+
* }
|
|
317
|
+
* // New record has been saved to Airtable servers.
|
|
318
|
+
* alert(`record with ID ${record.id} has been updated`);
|
|
319
|
+
* }
|
|
320
|
+
*
|
|
321
|
+
* // Fields can be specified by name or ID
|
|
322
|
+
* updateRecord(record1, {
|
|
323
|
+
* 'Post Title': 'How to make: orange-mango pound cake',
|
|
324
|
+
* 'Publication Date': '2020-01-01',
|
|
325
|
+
* });
|
|
326
|
+
* updateRecord(record2, {
|
|
327
|
+
* [postTitleField.id]: 'Cake decorating tips & tricks',
|
|
328
|
+
* [publicationDateField.id]: '2020-02-02',
|
|
329
|
+
* });
|
|
330
|
+
*
|
|
331
|
+
* // Cell values should generally have format matching the output of
|
|
332
|
+
* // record.getCellValue() for the field being updated
|
|
333
|
+
* updateRecord(record1, {
|
|
334
|
+
* 'Category (single select)': {name: 'Recipe'},
|
|
335
|
+
* 'Tags (multiple select)': [{name: 'Desserts'}, {id: 'someChoiceId'}],
|
|
336
|
+
* 'Images (attachment)': [{url: 'http://mywebsite.com/cake.png'}],
|
|
337
|
+
* 'Related posts (linked records)': [{id: 'someRecordId'}],
|
|
338
|
+
* });
|
|
339
|
+
* ```
|
|
340
|
+
*/
|
|
341
|
+
async updateRecordAsync(recordOrRecordId, fields) {
|
|
342
|
+
const recordId = typeof recordOrRecordId === 'string' ? recordOrRecordId : recordOrRecordId.id;
|
|
343
|
+
await this.updateRecordsAsync([{
|
|
344
|
+
id: recordId,
|
|
345
|
+
fields
|
|
346
|
+
}]);
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* Checks whether the current user has permission to perform the given record update.
|
|
350
|
+
*
|
|
351
|
+
* Accepts partial input, in the same format as {@link updateRecordAsync}.
|
|
352
|
+
* The more information provided, the more accurate the permissions check will be.
|
|
353
|
+
*
|
|
354
|
+
* Returns `{hasPermission: true}` if the current user can update the specified record,
|
|
355
|
+
* `{hasPermission: false, reasonDisplayString: string}` otherwise. `reasonDisplayString` may be
|
|
356
|
+
* used to display an error message to the user.
|
|
357
|
+
*
|
|
358
|
+
* @param recordOrRecordId the record to update
|
|
359
|
+
* @param fields cell values to update in that record, specified as object mapping `FieldId` or field name to value for that field.
|
|
360
|
+
* @example
|
|
361
|
+
* ```js
|
|
362
|
+
* // Check if user can update specific fields for a specific record.
|
|
363
|
+
* const updateRecordCheckResult =
|
|
364
|
+
* table.checkPermissionsForUpdateRecord(record, {
|
|
365
|
+
* 'Post Title': 'How to make: orange-mango pound cake',
|
|
366
|
+
* 'Publication Date': '2020-01-01',
|
|
367
|
+
* });
|
|
368
|
+
* if (!updateRecordCheckResult.hasPermission) {
|
|
369
|
+
* alert(updateRecordCheckResult.reasonDisplayString);
|
|
370
|
+
* }
|
|
371
|
+
*
|
|
372
|
+
* // Like updateRecordAsync, you can use either field names or field IDs.
|
|
373
|
+
* const updateRecordCheckResultWithFieldIds =
|
|
374
|
+
* table.checkPermissionsForUpdateRecord(record, {
|
|
375
|
+
* [postTitleField.id]: 'Cake decorating tips & tricks',
|
|
376
|
+
* [publicationDateField.id]: '2020-02-02',
|
|
377
|
+
* });
|
|
378
|
+
*
|
|
379
|
+
* // Check if user could update a given record, when you don't know the
|
|
380
|
+
* // specific fields that will be updated yet (e.g. to check whether you should
|
|
381
|
+
* // allow a user to select a certain record to update).
|
|
382
|
+
* const updateUnknownFieldsCheckResult =
|
|
383
|
+
* table.checkPermissionsForUpdateRecord(record);
|
|
384
|
+
*
|
|
385
|
+
* // Check if user could update specific fields, when you don't know the
|
|
386
|
+
* // specific record that will be updated yet. (for example, if the field is
|
|
387
|
+
* // selected by the user and you want to check if your extension can write to it).
|
|
388
|
+
* const updateUnknownRecordCheckResult =
|
|
389
|
+
* table.checkPermissionsForUpdateRecord(undefined, {
|
|
390
|
+
* 'My field name': 'updated value',
|
|
391
|
+
* // You can use undefined if you know you're going to update a field,
|
|
392
|
+
* // but don't know the new cell value yet.
|
|
393
|
+
* 'Another field name': undefined,
|
|
394
|
+
* });
|
|
395
|
+
*
|
|
396
|
+
* // Check if user could perform updates within the table, without knowing the
|
|
397
|
+
* // specific record or fields that will be updated yet (e.g., to render your
|
|
398
|
+
* // extension in "read only" mode).
|
|
399
|
+
* const updateUnknownRecordAndFieldsCheckResult =
|
|
400
|
+
* table.checkPermissionsForUpdateRecord();
|
|
401
|
+
* ```
|
|
402
|
+
*/
|
|
403
|
+
checkPermissionsForUpdateRecord(recordOrRecordId, fields) {
|
|
404
|
+
const recordId = typeof recordOrRecordId === 'object' && recordOrRecordId !== null ? recordOrRecordId.id : recordOrRecordId;
|
|
405
|
+
return this.checkPermissionsForUpdateRecords([{
|
|
406
|
+
id: recordId,
|
|
407
|
+
fields
|
|
408
|
+
}]);
|
|
409
|
+
}
|
|
410
|
+
/**
|
|
411
|
+
* An alias for `checkPermissionsForUpdateRecord(recordOrRecordId, fields).hasPermission`.
|
|
412
|
+
*
|
|
413
|
+
* Checks whether the current user has permission to perform the given record update.
|
|
414
|
+
*
|
|
415
|
+
* Accepts partial input, in the same format as {@link updateRecordAsync}.
|
|
416
|
+
* The more information provided, the more accurate the permissions check will be.
|
|
417
|
+
*
|
|
418
|
+
* @param recordOrRecordId the record to update
|
|
419
|
+
* @param fields cell values to update in that record, specified as object mapping `FieldId` or field name to value for that field.
|
|
420
|
+
* @example
|
|
421
|
+
* ```js
|
|
422
|
+
* // Check if user can update specific fields for a specific record.
|
|
423
|
+
* const canUpdateRecord = table.hasPermissionToUpdateRecord(record, {
|
|
424
|
+
* 'Post Title': 'How to make: orange-mango pound cake',
|
|
425
|
+
* 'Publication Date': '2020-01-01',
|
|
426
|
+
* });
|
|
427
|
+
* if (!canUpdateRecord) {
|
|
428
|
+
* alert('not allowed!');
|
|
429
|
+
* }
|
|
430
|
+
*
|
|
431
|
+
* // Like updateRecordAsync, you can use either field names or field IDs.
|
|
432
|
+
* const canUpdateRecordWithFieldIds =
|
|
433
|
+
* table.hasPermissionToUpdateRecord(record, {
|
|
434
|
+
* [postTitleField.id]: 'Cake decorating tips & tricks',
|
|
435
|
+
* [publicationDateField.id]: '2020-02-02',
|
|
436
|
+
* });
|
|
437
|
+
*
|
|
438
|
+
* // Check if user could update a given record, when you don't know the
|
|
439
|
+
* // specific fields that will be updated yet (e.g. to check whether you should
|
|
440
|
+
* // allow a user to select a certain record to update).
|
|
441
|
+
* const canUpdateUnknownFields = table.hasPermissionToUpdateRecord(record);
|
|
442
|
+
*
|
|
443
|
+
* // Check if user could update specific fields, when you don't know the
|
|
444
|
+
* // specific record that will be updated yet (e.g. if the field is selected
|
|
445
|
+
* // by the user and you want to check if your extension can write to it).
|
|
446
|
+
* const canUpdateUnknownRecord =
|
|
447
|
+
* table.hasPermissionToUpdateRecord(undefined, {
|
|
448
|
+
* 'My field name': 'updated value',
|
|
449
|
+
* // You can use undefined if you know you're going to update a field,
|
|
450
|
+
* // but don't know the new cell value yet.
|
|
451
|
+
* 'Another field name': undefined,
|
|
452
|
+
* });
|
|
453
|
+
*
|
|
454
|
+
* // Check if user could perform updates within the table, without knowing the
|
|
455
|
+
* // specific record or fields that will be updated yet. (for example, to
|
|
456
|
+
* // render your extension in "read only" mode)
|
|
457
|
+
* const canUpdateUnknownRecordAndFields = table.hasPermissionToUpdateRecord();
|
|
458
|
+
* ```
|
|
459
|
+
*/
|
|
460
|
+
hasPermissionToUpdateRecord(recordOrRecordId, fields) {
|
|
461
|
+
return this.checkPermissionsForUpdateRecord(recordOrRecordId, fields).hasPermission;
|
|
462
|
+
}
|
|
463
|
+
/**
|
|
464
|
+
* Updates cell values for records.
|
|
465
|
+
*
|
|
466
|
+
* Throws an error if the user does not have permission to update the given cell values in
|
|
467
|
+
* the records, or if invalid input is provided (eg. invalid cell values).
|
|
468
|
+
*
|
|
469
|
+
* Refer to {@link FieldType} for cell value write formats.
|
|
470
|
+
*
|
|
471
|
+
* You may only update up to 50 records in one call to `updateRecordsAsync`.
|
|
472
|
+
* See [Write back to Airtable](/guides/write-back-to-airtable) for more information
|
|
473
|
+
* about write limits.
|
|
474
|
+
*
|
|
475
|
+
* This action is asynchronous: `await` the returned promise if you wish to wait for the
|
|
476
|
+
* updates to be persisted to Airtable servers.
|
|
477
|
+
* Updates are applied optimistically locally, so your changes will be reflected in your extension
|
|
478
|
+
* before the promise resolves.
|
|
479
|
+
*
|
|
480
|
+
* @param records Array of objects containing recordId and fields/cellValues to update for that record (specified as an object mapping `FieldId` or field name to cell value)
|
|
481
|
+
* @example
|
|
482
|
+
* ```js
|
|
483
|
+
* const recordsToUpdate = [
|
|
484
|
+
* // Fields can be specified by name or ID
|
|
485
|
+
* {
|
|
486
|
+
* id: record1.id,
|
|
487
|
+
* fields: {
|
|
488
|
+
* 'Post Title': 'How to make: orange-mango pound cake',
|
|
489
|
+
* 'Publication Date': '2020-01-01',
|
|
490
|
+
* },
|
|
491
|
+
* },
|
|
492
|
+
* {
|
|
493
|
+
* id: record2.id,
|
|
494
|
+
* fields: {
|
|
495
|
+
* // Sets the cell values to be empty.
|
|
496
|
+
* 'Post Title': '',
|
|
497
|
+
* 'Publication Date': '',
|
|
498
|
+
* },
|
|
499
|
+
* },
|
|
500
|
+
* {
|
|
501
|
+
* id: record3.id,
|
|
502
|
+
* fields: {
|
|
503
|
+
* [postTitleField.id]: 'Cake decorating tips & tricks',
|
|
504
|
+
* [publicationDateField.id]: '2020-02-02',
|
|
505
|
+
* },
|
|
506
|
+
* },
|
|
507
|
+
* // Cell values should generally have format matching the output of
|
|
508
|
+
* // record.getCellValue() for the field being updated
|
|
509
|
+
* {
|
|
510
|
+
* id: record4.id,
|
|
511
|
+
* fields: {
|
|
512
|
+
* 'Category (single select)': {name: 'Recipe'},
|
|
513
|
+
* 'Tags (multiple select)': [{name: 'Desserts'}, {id: 'choiceId'}],
|
|
514
|
+
* 'Images (attachment)': [{url: 'http://mywebsite.com/cake.png'}],
|
|
515
|
+
* 'Related posts (linked records)': [{id: 'someRecordId'}],
|
|
516
|
+
* },
|
|
517
|
+
* },
|
|
518
|
+
* ];
|
|
519
|
+
*
|
|
520
|
+
* function updateRecords() {
|
|
521
|
+
* if (table.hasPermissionToUpdateRecords(recordsToUpdate)) {
|
|
522
|
+
* table.updateRecordsAsync(recordsToUpdate);
|
|
523
|
+
* }
|
|
524
|
+
* // The records are now updated within your extension (eg will be reflected in
|
|
525
|
+
* // `table.selectRecords()`) but are still being saved to Airtable servers
|
|
526
|
+
* // (e.g. they may not be updated for other users yet).
|
|
527
|
+
* }
|
|
528
|
+
*
|
|
529
|
+
* async function updateRecordsAsync() {
|
|
530
|
+
* if (table.hasPermissionToUpdateRecords(recordsToUpdate)) {
|
|
531
|
+
* await table.updateRecordsAsync(recordsToUpdate);
|
|
532
|
+
* }
|
|
533
|
+
* // Record updates have been saved to Airtable servers.
|
|
534
|
+
* alert('records have been updated');
|
|
535
|
+
* }
|
|
536
|
+
* ```
|
|
537
|
+
*/
|
|
538
|
+
async updateRecordsAsync(records) {
|
|
539
|
+
let includesForeignRowsThatShouldBeCreated = false;
|
|
540
|
+
const recordsWithCellValuesByFieldId = records.map(record => ({
|
|
541
|
+
id: record.id,
|
|
542
|
+
cellValuesByFieldId: this._cellValuesByFieldIdOrNameToCellValuesByFieldId(record.fields, () => {
|
|
543
|
+
includesForeignRowsThatShouldBeCreated = true;
|
|
544
|
+
})
|
|
545
|
+
}));
|
|
546
|
+
await this._sdk.__mutations.applyMutationAsync({
|
|
547
|
+
type: _mutations_core.MutationTypesCore.SET_MULTIPLE_RECORDS_CELL_VALUES,
|
|
548
|
+
tableId: this.id,
|
|
549
|
+
records: recordsWithCellValuesByFieldId,
|
|
550
|
+
opts: {
|
|
551
|
+
parseDateCellValueInColumnTimeZone: true,
|
|
552
|
+
includesForeignRowsThatShouldBeCreated
|
|
431
553
|
}
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
* @param fields cell values to update in that record, specified as object mapping `FieldId` or field name to value for that field.
|
|
509
|
-
* @example
|
|
510
|
-
* ```js
|
|
511
|
-
* // Check if user can update specific fields for a specific record.
|
|
512
|
-
* const canUpdateRecord = table.hasPermissionToUpdateRecord(record, {
|
|
513
|
-
* 'Post Title': 'How to make: orange-mango pound cake',
|
|
514
|
-
* 'Publication Date': '2020-01-01',
|
|
515
|
-
* });
|
|
516
|
-
* if (!canUpdateRecord) {
|
|
517
|
-
* alert('not allowed!');
|
|
518
|
-
* }
|
|
519
|
-
*
|
|
520
|
-
* // Like updateRecordAsync, you can use either field names or field IDs.
|
|
521
|
-
* const canUpdateRecordWithFieldIds =
|
|
522
|
-
* table.hasPermissionToUpdateRecord(record, {
|
|
523
|
-
* [postTitleField.id]: 'Cake decorating tips & tricks',
|
|
524
|
-
* [publicationDateField.id]: '2020-02-02',
|
|
525
|
-
* });
|
|
526
|
-
*
|
|
527
|
-
* // Check if user could update a given record, when you don't know the
|
|
528
|
-
* // specific fields that will be updated yet (e.g. to check whether you should
|
|
529
|
-
* // allow a user to select a certain record to update).
|
|
530
|
-
* const canUpdateUnknownFields = table.hasPermissionToUpdateRecord(record);
|
|
531
|
-
*
|
|
532
|
-
* // Check if user could update specific fields, when you don't know the
|
|
533
|
-
* // specific record that will be updated yet (e.g. if the field is selected
|
|
534
|
-
* // by the user and you want to check if your extension can write to it).
|
|
535
|
-
* const canUpdateUnknownRecord =
|
|
536
|
-
* table.hasPermissionToUpdateRecord(undefined, {
|
|
537
|
-
* 'My field name': 'updated value',
|
|
538
|
-
* // You can use undefined if you know you're going to update a field,
|
|
539
|
-
* // but don't know the new cell value yet.
|
|
540
|
-
* 'Another field name': undefined,
|
|
541
|
-
* });
|
|
542
|
-
*
|
|
543
|
-
* // Check if user could perform updates within the table, without knowing the
|
|
544
|
-
* // specific record or fields that will be updated yet. (for example, to
|
|
545
|
-
* // render your extension in "read only" mode)
|
|
546
|
-
* const canUpdateUnknownRecordAndFields = table.hasPermissionToUpdateRecord();
|
|
547
|
-
* ```
|
|
548
|
-
*/
|
|
549
|
-
}, {
|
|
550
|
-
key: "hasPermissionToUpdateRecord",
|
|
551
|
-
value: function hasPermissionToUpdateRecord(recordOrRecordId, fields) {
|
|
552
|
-
return this.checkPermissionsForUpdateRecord(recordOrRecordId, fields).hasPermission;
|
|
553
|
-
}
|
|
554
|
-
/**
|
|
555
|
-
* Updates cell values for records.
|
|
556
|
-
*
|
|
557
|
-
* Throws an error if the user does not have permission to update the given cell values in
|
|
558
|
-
* the records, or if invalid input is provided (eg. invalid cell values).
|
|
559
|
-
*
|
|
560
|
-
* Refer to {@link FieldType} for cell value write formats.
|
|
561
|
-
*
|
|
562
|
-
* You may only update up to 50 records in one call to `updateRecordsAsync`.
|
|
563
|
-
* See [Write back to Airtable](/guides/write-back-to-airtable) for more information
|
|
564
|
-
* about write limits.
|
|
565
|
-
*
|
|
566
|
-
* This action is asynchronous: `await` the returned promise if you wish to wait for the
|
|
567
|
-
* updates to be persisted to Airtable servers.
|
|
568
|
-
* Updates are applied optimistically locally, so your changes will be reflected in your extension
|
|
569
|
-
* before the promise resolves.
|
|
570
|
-
*
|
|
571
|
-
* @param records Array of objects containing recordId and fields/cellValues to update for that record (specified as an object mapping `FieldId` or field name to cell value)
|
|
572
|
-
* @example
|
|
573
|
-
* ```js
|
|
574
|
-
* const recordsToUpdate = [
|
|
575
|
-
* // Fields can be specified by name or ID
|
|
576
|
-
* {
|
|
577
|
-
* id: record1.id,
|
|
578
|
-
* fields: {
|
|
579
|
-
* 'Post Title': 'How to make: orange-mango pound cake',
|
|
580
|
-
* 'Publication Date': '2020-01-01',
|
|
581
|
-
* },
|
|
582
|
-
* },
|
|
583
|
-
* {
|
|
584
|
-
* id: record2.id,
|
|
585
|
-
* fields: {
|
|
586
|
-
* // Sets the cell values to be empty.
|
|
587
|
-
* 'Post Title': '',
|
|
588
|
-
* 'Publication Date': '',
|
|
589
|
-
* },
|
|
590
|
-
* },
|
|
591
|
-
* {
|
|
592
|
-
* id: record3.id,
|
|
593
|
-
* fields: {
|
|
594
|
-
* [postTitleField.id]: 'Cake decorating tips & tricks',
|
|
595
|
-
* [publicationDateField.id]: '2020-02-02',
|
|
596
|
-
* },
|
|
597
|
-
* },
|
|
598
|
-
* // Cell values should generally have format matching the output of
|
|
599
|
-
* // record.getCellValue() for the field being updated
|
|
600
|
-
* {
|
|
601
|
-
* id: record4.id,
|
|
602
|
-
* fields: {
|
|
603
|
-
* 'Category (single select)': {name: 'Recipe'},
|
|
604
|
-
* 'Tags (multiple select)': [{name: 'Desserts'}, {id: 'choiceId'}],
|
|
605
|
-
* 'Images (attachment)': [{url: 'http://mywebsite.com/cake.png'}],
|
|
606
|
-
* 'Related posts (linked records)': [{id: 'someRecordId'}],
|
|
607
|
-
* },
|
|
608
|
-
* },
|
|
609
|
-
* ];
|
|
610
|
-
*
|
|
611
|
-
* function updateRecords() {
|
|
612
|
-
* if (table.hasPermissionToUpdateRecords(recordsToUpdate)) {
|
|
613
|
-
* table.updateRecordsAsync(recordsToUpdate);
|
|
614
|
-
* }
|
|
615
|
-
* // The records are now updated within your extension (eg will be reflected in
|
|
616
|
-
* // `table.selectRecords()`) but are still being saved to Airtable servers
|
|
617
|
-
* // (e.g. they may not be updated for other users yet).
|
|
618
|
-
* }
|
|
619
|
-
*
|
|
620
|
-
* async function updateRecordsAsync() {
|
|
621
|
-
* if (table.hasPermissionToUpdateRecords(recordsToUpdate)) {
|
|
622
|
-
* await table.updateRecordsAsync(recordsToUpdate);
|
|
623
|
-
* }
|
|
624
|
-
* // Record updates have been saved to Airtable servers.
|
|
625
|
-
* alert('records have been updated');
|
|
626
|
-
* }
|
|
627
|
-
* ```
|
|
628
|
-
*/
|
|
629
|
-
}, {
|
|
630
|
-
key: "updateRecordsAsync",
|
|
631
|
-
value: (function () {
|
|
632
|
-
var _updateRecordsAsync = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(records) {
|
|
633
|
-
var includesForeignRowsThatShouldBeCreated, recordsWithCellValuesByFieldId;
|
|
634
|
-
return _regenerator.default.wrap(function _callee2$(_context2) {
|
|
635
|
-
while (1) switch (_context2.prev = _context2.next) {
|
|
636
|
-
case 0:
|
|
637
|
-
includesForeignRowsThatShouldBeCreated = false;
|
|
638
|
-
recordsWithCellValuesByFieldId = records.map(record => ({
|
|
639
|
-
id: record.id,
|
|
640
|
-
cellValuesByFieldId: this._cellValuesByFieldIdOrNameToCellValuesByFieldId(record.fields, () => {
|
|
641
|
-
includesForeignRowsThatShouldBeCreated = true;
|
|
642
|
-
})
|
|
643
|
-
}));
|
|
644
|
-
_context2.next = 4;
|
|
645
|
-
return this._sdk.__mutations.applyMutationAsync({
|
|
646
|
-
type: _mutations_core.MutationTypesCore.SET_MULTIPLE_RECORDS_CELL_VALUES,
|
|
647
|
-
tableId: this.id,
|
|
648
|
-
records: recordsWithCellValuesByFieldId,
|
|
649
|
-
opts: {
|
|
650
|
-
parseDateCellValueInColumnTimeZone: true,
|
|
651
|
-
includesForeignRowsThatShouldBeCreated
|
|
652
|
-
}
|
|
653
|
-
});
|
|
654
|
-
case 4:
|
|
655
|
-
case "end":
|
|
656
|
-
return _context2.stop();
|
|
657
|
-
}
|
|
658
|
-
}, _callee2, this);
|
|
659
|
-
}));
|
|
660
|
-
function updateRecordsAsync(_x3) {
|
|
661
|
-
return _updateRecordsAsync.apply(this, arguments);
|
|
554
|
+
});
|
|
555
|
+
}
|
|
556
|
+
/**
|
|
557
|
+
* Checks whether the current user has permission to perform the given record updates.
|
|
558
|
+
*
|
|
559
|
+
* Accepts partial input, in the same format as {@link updateRecordsAsync}.
|
|
560
|
+
* The more information provided, the more accurate the permissions check will be.
|
|
561
|
+
*
|
|
562
|
+
* Returns `{hasPermission: true}` if the current user can update the specified records,
|
|
563
|
+
* `{hasPermission: false, reasonDisplayString: string}` otherwise. `reasonDisplayString` may be
|
|
564
|
+
* used to display an error message to the user.
|
|
565
|
+
*
|
|
566
|
+
* @param records Array of objects containing recordId and fields/cellValues to update for that record (specified as an object mapping `FieldId` or field name to cell value)
|
|
567
|
+
* @example
|
|
568
|
+
* ```js
|
|
569
|
+
* const recordsToUpdate = [
|
|
570
|
+
* {
|
|
571
|
+
* // Validating a complete record update
|
|
572
|
+
* id: record1.id,
|
|
573
|
+
* fields: {
|
|
574
|
+
* 'Post Title': 'How to make: orange-mango pound cake',
|
|
575
|
+
* 'Publication Date': '2020-01-01',
|
|
576
|
+
* },
|
|
577
|
+
* },
|
|
578
|
+
* {
|
|
579
|
+
* // Like updateRecordsAsync, fields can be specified by name or ID
|
|
580
|
+
* id: record2.id,
|
|
581
|
+
* fields: {
|
|
582
|
+
* [postTitleField.id]: 'Cake decorating tips & tricks',
|
|
583
|
+
* [publicationDateField.id]: '2020-02-02',
|
|
584
|
+
* },
|
|
585
|
+
* },
|
|
586
|
+
* {
|
|
587
|
+
* // Validating an update to a specific record, not knowing what
|
|
588
|
+
* // fields will be updated
|
|
589
|
+
* id: record3.id,
|
|
590
|
+
* },
|
|
591
|
+
* {
|
|
592
|
+
* // Validating an update to specific cell values, not knowing what
|
|
593
|
+
* // record will be updated
|
|
594
|
+
* fields: {
|
|
595
|
+
* 'My field name': 'updated value for unknown record',
|
|
596
|
+
* // You can use undefined if you know you're going to update a
|
|
597
|
+
* // field, but don't know the new cell value yet.
|
|
598
|
+
* 'Another field name': undefined,
|
|
599
|
+
* },
|
|
600
|
+
* },
|
|
601
|
+
* ];
|
|
602
|
+
*
|
|
603
|
+
* const updateRecordsCheckResult =
|
|
604
|
+
* table.checkPermissionsForUpdateRecords(recordsToUpdate);
|
|
605
|
+
* if (!updateRecordsCheckResult.hasPermission) {
|
|
606
|
+
* alert(updateRecordsCheckResult.reasonDisplayString);
|
|
607
|
+
* }
|
|
608
|
+
*
|
|
609
|
+
* // Check if user could potentially update records.
|
|
610
|
+
* // Equivalent to table.checkPermissionsForUpdateRecord()
|
|
611
|
+
* const updateUnknownRecordAndFieldsCheckResult =
|
|
612
|
+
* table.checkPermissionsForUpdateRecords();
|
|
613
|
+
* ```
|
|
614
|
+
*/
|
|
615
|
+
checkPermissionsForUpdateRecords(records) {
|
|
616
|
+
let includesForeignRowsThatShouldBeCreated = false;
|
|
617
|
+
const recordsWithCellValuesByFieldId = records ? records.map(record => ({
|
|
618
|
+
id: record.id || undefined,
|
|
619
|
+
cellValuesByFieldId: record.fields ? this._cellValuesByFieldIdOrNameToCellValuesByFieldId(record.fields, () => {
|
|
620
|
+
includesForeignRowsThatShouldBeCreated = true;
|
|
621
|
+
}) : undefined
|
|
622
|
+
})) : undefined;
|
|
623
|
+
return this._sdk.__mutations.checkPermissionsForMutation({
|
|
624
|
+
type: _mutations_core.MutationTypesCore.SET_MULTIPLE_RECORDS_CELL_VALUES,
|
|
625
|
+
tableId: this.id,
|
|
626
|
+
records: recordsWithCellValuesByFieldId,
|
|
627
|
+
opts: {
|
|
628
|
+
parseDateCellValueInColumnTimeZone: true,
|
|
629
|
+
includesForeignRowsThatShouldBeCreated
|
|
662
630
|
}
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
631
|
+
});
|
|
632
|
+
}
|
|
633
|
+
/**
|
|
634
|
+
* An alias for `checkPermissionsForUpdateRecords(records).hasPermission`.
|
|
635
|
+
*
|
|
636
|
+
* Checks whether the current user has permission to perform the given record updates.
|
|
637
|
+
*
|
|
638
|
+
* Accepts partial input, in the same format as {@link updateRecordsAsync}.
|
|
639
|
+
* The more information provided, the more accurate the permissions check will be.
|
|
640
|
+
*
|
|
641
|
+
* @param records Array of objects containing recordId and fields/cellValues to update for that record (specified as an object mapping `FieldId` or field name to cell value)
|
|
642
|
+
* @example
|
|
643
|
+
* ```js
|
|
644
|
+
* const recordsToUpdate = [
|
|
645
|
+
* {
|
|
646
|
+
* // Validating a complete record update
|
|
647
|
+
* id: record1.id,
|
|
648
|
+
* fields: {
|
|
649
|
+
* 'Post Title': 'How to make: orange-mango pound cake',
|
|
650
|
+
* 'Publication Date': '2020-01-01',
|
|
651
|
+
* },
|
|
652
|
+
* },
|
|
653
|
+
* {
|
|
654
|
+
* // Like updateRecordsAsync, fields can be specified by name or ID
|
|
655
|
+
* id: record2.id,
|
|
656
|
+
* fields: {
|
|
657
|
+
* [postTitleField.id]: 'Cake decorating tips & tricks',
|
|
658
|
+
* [publicationDateField.id]: '2020-02-02',
|
|
659
|
+
* },
|
|
660
|
+
* },
|
|
661
|
+
* {
|
|
662
|
+
* // Validating an update to a specific record, not knowing what
|
|
663
|
+
* // fields will be updated
|
|
664
|
+
* id: record3.id,
|
|
665
|
+
* },
|
|
666
|
+
* {
|
|
667
|
+
* // Validating an update to specific cell values, not knowing what
|
|
668
|
+
* // record will be updated
|
|
669
|
+
* fields: {
|
|
670
|
+
* 'My field name': 'updated value for unknown record',
|
|
671
|
+
* // You can use undefined if you know you're going to update a
|
|
672
|
+
* // field, but don't know the new cell value yet.
|
|
673
|
+
* 'Another field name': undefined,
|
|
674
|
+
* },
|
|
675
|
+
* },
|
|
676
|
+
* ];
|
|
677
|
+
*
|
|
678
|
+
* const canUpdateRecords = table.hasPermissionToUpdateRecords(recordsToUpdate);
|
|
679
|
+
* if (!canUpdateRecords) {
|
|
680
|
+
* alert('not allowed');
|
|
681
|
+
* }
|
|
682
|
+
*
|
|
683
|
+
* // Check if user could potentially update records.
|
|
684
|
+
* // Equivalent to table.hasPermissionToUpdateRecord()
|
|
685
|
+
* const canUpdateUnknownRecordsAndFields =
|
|
686
|
+
* table.hasPermissionToUpdateRecords();
|
|
687
|
+
* ```
|
|
688
|
+
*/
|
|
689
|
+
hasPermissionToUpdateRecords(records) {
|
|
690
|
+
return this.checkPermissionsForUpdateRecords(records).hasPermission;
|
|
691
|
+
}
|
|
692
|
+
/**
|
|
693
|
+
* Delete the given record.
|
|
694
|
+
*
|
|
695
|
+
* Throws an error if the user does not have permission to delete the given record.
|
|
696
|
+
*
|
|
697
|
+
* This action is asynchronous: `await` the returned promise if you wish to wait for the
|
|
698
|
+
* delete to be persisted to Airtable servers.
|
|
699
|
+
* Updates are applied optimistically locally, so your changes will be reflected in your extension
|
|
700
|
+
* before the promise resolves.
|
|
701
|
+
*
|
|
702
|
+
* @param recordOrRecordId the record to be deleted
|
|
703
|
+
* @example
|
|
704
|
+
* ```js
|
|
705
|
+
* function deleteRecord(record) {
|
|
706
|
+
* if (table.hasPermissionToDeleteRecord(record)) {
|
|
707
|
+
* table.deleteRecordAsync(record);
|
|
708
|
+
* }
|
|
709
|
+
* // The record is now deleted within your extension (eg will not be returned
|
|
710
|
+
* // in `table.selectRecords`) but it is still being saved to Airtable
|
|
711
|
+
* // servers (e.g. it may not look deleted to other users yet).
|
|
712
|
+
* }
|
|
713
|
+
*
|
|
714
|
+
* async function deleteRecordAsync(record) {
|
|
715
|
+
* if (table.hasPermissionToDeleteRecord(record)) {
|
|
716
|
+
* await table.deleteRecordAsync(record);
|
|
717
|
+
* }
|
|
718
|
+
* // Record deletion has been saved to Airtable servers.
|
|
719
|
+
* alert('record has been deleted');
|
|
720
|
+
* }
|
|
721
|
+
* ```
|
|
722
|
+
*/
|
|
723
|
+
async deleteRecordAsync(recordOrRecordId) {
|
|
724
|
+
await this.deleteRecordsAsync([recordOrRecordId]);
|
|
725
|
+
}
|
|
726
|
+
/**
|
|
727
|
+
* Checks whether the current user has permission to delete the specified record.
|
|
728
|
+
*
|
|
729
|
+
* Accepts optional input, in the same format as {@link deleteRecordAsync}.
|
|
730
|
+
* The more information provided, the more accurate the permissions check will be.
|
|
731
|
+
*
|
|
732
|
+
* Returns `{hasPermission: true}` if the current user can delete the specified record,
|
|
733
|
+
* `{hasPermission: false, reasonDisplayString: string}` otherwise. `reasonDisplayString` may be
|
|
734
|
+
* used to display an error message to the user.
|
|
735
|
+
*
|
|
736
|
+
* @param recordOrRecordId the record to be deleted
|
|
737
|
+
* @example
|
|
738
|
+
* ```js
|
|
739
|
+
* // Check if user can delete a specific record
|
|
740
|
+
* const deleteRecordCheckResult =
|
|
741
|
+
* table.checkPermissionsForDeleteRecord(record);
|
|
742
|
+
* if (!deleteRecordCheckResult.hasPermission) {
|
|
743
|
+
* alert(deleteRecordCheckResult.reasonDisplayString);
|
|
744
|
+
* }
|
|
745
|
+
*
|
|
746
|
+
* // Check if user could potentially delete a record.
|
|
747
|
+
* // Use when you don't know the specific record you want to delete yet (for
|
|
748
|
+
* // example, to show/hide UI controls that let you select a record to delete).
|
|
749
|
+
* const deleteUnknownRecordCheckResult =
|
|
750
|
+
* table.checkPermissionsForDeleteRecord();
|
|
751
|
+
* ```
|
|
752
|
+
*/
|
|
753
|
+
checkPermissionsForDeleteRecord(recordOrRecordId) {
|
|
754
|
+
return this.checkPermissionsForDeleteRecords(recordOrRecordId ? [recordOrRecordId] : undefined);
|
|
755
|
+
}
|
|
756
|
+
/**
|
|
757
|
+
* An alias for `checkPermissionsForDeleteRecord(recordOrRecordId).hasPermission`.
|
|
758
|
+
*
|
|
759
|
+
* Checks whether the current user has permission to delete the specified record.
|
|
760
|
+
*
|
|
761
|
+
* Accepts optional input, in the same format as {@link deleteRecordAsync}.
|
|
762
|
+
* The more information provided, the more accurate the permissions check will be.
|
|
763
|
+
*
|
|
764
|
+
* @param recordOrRecordId the record to be deleted
|
|
765
|
+
* @example
|
|
766
|
+
* ```js
|
|
767
|
+
* // Check if user can delete a specific record
|
|
768
|
+
* const canDeleteRecord = table.hasPermissionToDeleteRecord(record);
|
|
769
|
+
* if (!canDeleteRecord) {
|
|
770
|
+
* alert('not allowed');
|
|
771
|
+
* }
|
|
772
|
+
*
|
|
773
|
+
* // Check if user could potentially delete a record.
|
|
774
|
+
* // Use when you don't know the specific record you want to delete yet (for
|
|
775
|
+
* // example, to show/hide UI controls that let you select a record to delete).
|
|
776
|
+
* const canDeleteUnknownRecord = table.hasPermissionToDeleteRecord();
|
|
777
|
+
* ```
|
|
778
|
+
*/
|
|
779
|
+
hasPermissionToDeleteRecord(recordOrRecordId) {
|
|
780
|
+
return this.checkPermissionsForDeleteRecord(recordOrRecordId).hasPermission;
|
|
781
|
+
}
|
|
782
|
+
/**
|
|
783
|
+
* Delete the given records.
|
|
784
|
+
*
|
|
785
|
+
* Throws an error if the user does not have permission to delete the given records.
|
|
786
|
+
*
|
|
787
|
+
* You may only delete up to 50 records in one call to `deleteRecordsAsync`.
|
|
788
|
+
* See [Write back to Airtable](/guides/write-back-to-airtable#size-limits-rate-limits) for
|
|
789
|
+
* more information about write limits.
|
|
790
|
+
*
|
|
791
|
+
* This action is asynchronous: `await` the returned promise if you wish to wait for the
|
|
792
|
+
* delete to be persisted to Airtable servers.
|
|
793
|
+
* Updates are applied optimistically locally, so your changes will be reflected in your extension
|
|
794
|
+
* before the promise resolves.
|
|
795
|
+
*
|
|
796
|
+
* @param recordsOrRecordIds Array of Records and RecordIds
|
|
797
|
+
* @example
|
|
798
|
+
* ```js
|
|
799
|
+
*
|
|
800
|
+
* function deleteRecords(records) {
|
|
801
|
+
* if (table.hasPermissionToDeleteRecords(records)) {
|
|
802
|
+
* table.deleteRecordsAsync(records);
|
|
803
|
+
* }
|
|
804
|
+
* // The records are now deleted within your extension (eg will not be
|
|
805
|
+
* // returned in `table.selectRecords()`) but are still being saved to
|
|
806
|
+
* // Airtable servers (e.g. they may not look deleted to other users yet).
|
|
807
|
+
* }
|
|
808
|
+
*
|
|
809
|
+
* async function deleteRecordsAsync(records) {
|
|
810
|
+
* if (table.hasPermissionToDeleteRecords(records)) {
|
|
811
|
+
* await table.deleteRecordsAsync(records);
|
|
812
|
+
* }
|
|
813
|
+
* // Record deletions have been saved to Airtable servers.
|
|
814
|
+
* alert('records have been deleted');
|
|
815
|
+
* }
|
|
816
|
+
* ```
|
|
817
|
+
*/
|
|
818
|
+
async deleteRecordsAsync(recordsOrRecordIds) {
|
|
819
|
+
const recordIds = recordsOrRecordIds.map(recordOrRecordId => typeof recordOrRecordId === 'string' ? recordOrRecordId : recordOrRecordId.id);
|
|
820
|
+
await this._sdk.__mutations.applyMutationAsync({
|
|
821
|
+
type: _mutations_core.MutationTypesCore.DELETE_MULTIPLE_RECORDS,
|
|
822
|
+
tableId: this.id,
|
|
823
|
+
recordIds
|
|
824
|
+
});
|
|
825
|
+
}
|
|
826
|
+
/**
|
|
827
|
+
* Checks whether the current user has permission to delete the specified records.
|
|
828
|
+
*
|
|
829
|
+
* Accepts optional input, in the same format as {@link deleteRecordsAsync}.
|
|
830
|
+
* The more information provided, the more accurate the permissions check will be.
|
|
831
|
+
*
|
|
832
|
+
* Returns `{hasPermission: true}` if the current user can delete the specified records,
|
|
833
|
+
* `{hasPermission: false, reasonDisplayString: string}` otherwise. `reasonDisplayString` may be
|
|
834
|
+
* used to display an error message to the user.
|
|
835
|
+
*
|
|
836
|
+
* @param recordsOrRecordIds the records to be deleted
|
|
837
|
+
* @example
|
|
838
|
+
* ```js
|
|
839
|
+
* // Check if user can delete specific records
|
|
840
|
+
* const deleteRecordsCheckResult =
|
|
841
|
+
* table.checkPermissionsForDeleteRecords([record1, record2]);
|
|
842
|
+
* if (!deleteRecordsCheckResult.hasPermission) {
|
|
843
|
+
* alert(deleteRecordsCheckResult.reasonDisplayString);
|
|
844
|
+
* }
|
|
845
|
+
*
|
|
846
|
+
* // Check if user could potentially delete records.
|
|
847
|
+
* // Use when you don't know the specific records you want to delete yet (for
|
|
848
|
+
* // example, to show/hide UI controls that let you select records to delete).
|
|
849
|
+
* // Equivalent to table.hasPermissionToDeleteRecord()
|
|
850
|
+
* const deleteUnknownRecordsCheckResult =
|
|
851
|
+
* table.checkPermissionsForDeleteRecords();
|
|
852
|
+
* ```
|
|
853
|
+
*/
|
|
854
|
+
checkPermissionsForDeleteRecords(recordsOrRecordIds) {
|
|
855
|
+
return this._sdk.__mutations.checkPermissionsForMutation({
|
|
856
|
+
type: _mutations_core.MutationTypesCore.DELETE_MULTIPLE_RECORDS,
|
|
857
|
+
tableId: this.id,
|
|
858
|
+
recordIds: recordsOrRecordIds ? recordsOrRecordIds.map(recordOrRecordId => typeof recordOrRecordId === 'string' ? recordOrRecordId : recordOrRecordId.id) : undefined
|
|
859
|
+
});
|
|
860
|
+
}
|
|
861
|
+
/**
|
|
862
|
+
* An alias for `checkPermissionsForDeleteRecords(recordsOrRecordIds).hasPermission`.
|
|
863
|
+
*
|
|
864
|
+
* Checks whether the current user has permission to delete the specified records.
|
|
865
|
+
*
|
|
866
|
+
* Accepts optional input, in the same format as {@link deleteRecordsAsync}.
|
|
867
|
+
* The more information provided, the more accurate the permissions check will be.
|
|
868
|
+
*
|
|
869
|
+
* @param recordsOrRecordIds the records to be deleted
|
|
870
|
+
* @example
|
|
871
|
+
* ```js
|
|
872
|
+
* // Check if user can delete specific records
|
|
873
|
+
* const canDeleteRecords =
|
|
874
|
+
* table.hasPermissionToDeleteRecords([record1, record2]);
|
|
875
|
+
* if (!canDeleteRecords) {
|
|
876
|
+
* alert('not allowed!');
|
|
877
|
+
* }
|
|
878
|
+
*
|
|
879
|
+
* // Check if user could potentially delete records.
|
|
880
|
+
* // Use when you don't know the specific records you want to delete yet (for
|
|
881
|
+
* // example, to show/hide UI controls that let you select records to delete).
|
|
882
|
+
* // Equivalent to table.hasPermissionToDeleteRecord()
|
|
883
|
+
* const canDeleteUnknownRecords = table.hasPermissionToDeleteRecords();
|
|
884
|
+
* ```
|
|
885
|
+
*/
|
|
886
|
+
hasPermissionToDeleteRecords(recordsOrRecordIds) {
|
|
887
|
+
return this.checkPermissionsForDeleteRecords(recordsOrRecordIds).hasPermission;
|
|
888
|
+
}
|
|
889
|
+
|
|
890
|
+
/**
|
|
891
|
+
* Creates a new record with the specified cell values.
|
|
892
|
+
*
|
|
893
|
+
* Throws an error if the user does not have permission to create the given records, or
|
|
894
|
+
* if invalid input is provided (eg. invalid cell values).
|
|
895
|
+
*
|
|
896
|
+
* Refer to {@link FieldType} for cell value write formats.
|
|
897
|
+
*
|
|
898
|
+
* This action is asynchronous: `await` the returned promise if you wish to wait for the new
|
|
899
|
+
* record to be persisted to Airtable servers.
|
|
900
|
+
* Updates are applied optimistically locally, so your changes will be reflected in your extension
|
|
901
|
+
* before the promise resolves.
|
|
902
|
+
*
|
|
903
|
+
* The returned promise will resolve to the RecordId of the new record once it is persisted.
|
|
904
|
+
*
|
|
905
|
+
* @param fields object mapping `FieldId` or field name to value for that field.
|
|
906
|
+
* @example
|
|
907
|
+
* ```js
|
|
908
|
+
* function createNewRecord(recordFields) {
|
|
909
|
+
* if (table.hasPermissionToCreateRecord(recordFields)) {
|
|
910
|
+
* table.createRecordAsync(recordFields);
|
|
911
|
+
* }
|
|
912
|
+
* // You can now access the new record in your extension (eg
|
|
913
|
+
* // `table.selectRecords()`) but it is still being saved to Airtable
|
|
914
|
+
* // servers (e.g. other users may not be able to see it yet).
|
|
915
|
+
* }
|
|
916
|
+
*
|
|
917
|
+
* async function createNewRecordAsync(recordFields) {
|
|
918
|
+
* if (table.hasPermissionToCreateRecord(recordFields)) {
|
|
919
|
+
* const newRecordId = await table.createRecordAsync(recordFields);
|
|
920
|
+
* }
|
|
921
|
+
* // New record has been saved to Airtable servers.
|
|
922
|
+
* alert(`new record with ID ${newRecordId} has been created`);
|
|
923
|
+
* }
|
|
924
|
+
*
|
|
925
|
+
* // Fields can be specified by name or ID
|
|
926
|
+
* createNewRecord({
|
|
927
|
+
* 'Project Name': 'Advertising campaign',
|
|
928
|
+
* 'Budget': 100,
|
|
929
|
+
* });
|
|
930
|
+
* createNewRecord({
|
|
931
|
+
* [projectNameField.id]: 'Cat video',
|
|
932
|
+
* [budgetField.id]: 200,
|
|
933
|
+
* });
|
|
934
|
+
*
|
|
935
|
+
* // Cell values should generally have format matching the output of
|
|
936
|
+
* // record.getCellValue() for the field being updated
|
|
937
|
+
* createNewRecord({
|
|
938
|
+
* 'Project Name': 'Cat video 2'
|
|
939
|
+
* 'Category (single select)': {name: 'Video'},
|
|
940
|
+
* 'Tags (multiple select)': [{name: 'Cats'}, {id: 'someChoiceId'}],
|
|
941
|
+
* 'Assets (attachment)': [{url: 'http://mywebsite.com/cats.mp4'}],
|
|
942
|
+
* 'Related projects (linked records)': [{id: 'someRecordId'}],
|
|
943
|
+
* });
|
|
944
|
+
* ```
|
|
945
|
+
*/
|
|
946
|
+
async createRecordAsync() {
|
|
947
|
+
let fields = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
948
|
+
const recordIds = await this.createRecordsAsync([{
|
|
949
|
+
fields
|
|
950
|
+
}]);
|
|
951
|
+
return recordIds[0];
|
|
952
|
+
}
|
|
953
|
+
|
|
954
|
+
/**
|
|
955
|
+
* Checks whether the current user has permission to create the specified record.
|
|
956
|
+
*
|
|
957
|
+
* Accepts partial input, in the same format as {@link createRecordAsync}.
|
|
958
|
+
* The more information provided, the more accurate the permissions check will be.
|
|
959
|
+
*
|
|
960
|
+
* Returns `{hasPermission: true}` if the current user can create the specified record,
|
|
961
|
+
* `{hasPermission: false, reasonDisplayString: string}` otherwise. `reasonDisplayString` may be
|
|
962
|
+
* used to display an error message to the user.
|
|
963
|
+
*
|
|
964
|
+
* @param fields object mapping `FieldId` or field name to value for that field.
|
|
965
|
+
* @example
|
|
966
|
+
* ```js
|
|
967
|
+
* // Check if user can create a specific record, when you already know what
|
|
968
|
+
* // fields/cell values will be set for the record.
|
|
969
|
+
* const createRecordCheckResult = table.checkPermissionsForCreateRecord({
|
|
970
|
+
* 'Project Name': 'Advertising campaign',
|
|
971
|
+
* 'Budget': 100,
|
|
972
|
+
* });
|
|
973
|
+
* if (!createRecordCheckResult.hasPermission) {
|
|
974
|
+
* alert(createRecordCheckResult.reasonDisplayString);
|
|
975
|
+
* }
|
|
976
|
+
*
|
|
977
|
+
* // Like createRecordAsync, you can use either field names or field IDs.
|
|
978
|
+
* const checkResultWithFieldIds = table.checkPermissionsForCreateRecord({
|
|
979
|
+
* [projectNameField.id]: 'Cat video',
|
|
980
|
+
* [budgetField.id]: 200,
|
|
981
|
+
* });
|
|
982
|
+
*
|
|
983
|
+
* // Check if user could potentially create a record.
|
|
984
|
+
* // Use when you don't know the specific fields/cell values yet (for example,
|
|
985
|
+
* // to show or hide UI controls that let you start creating a record.)
|
|
986
|
+
* const createUnknownRecordCheckResult =
|
|
987
|
+
* table.checkPermissionsForCreateRecord();
|
|
988
|
+
* ```
|
|
989
|
+
*/
|
|
990
|
+
checkPermissionsForCreateRecord(fields) {
|
|
991
|
+
return this.checkPermissionsForCreateRecords([{
|
|
992
|
+
fields: fields || undefined
|
|
993
|
+
}]);
|
|
994
|
+
}
|
|
995
|
+
/**
|
|
996
|
+
* An alias for `checkPermissionsForCreateRecord(fields).hasPermission`.
|
|
997
|
+
*
|
|
998
|
+
* Checks whether the current user has permission to create the specified record.
|
|
999
|
+
*
|
|
1000
|
+
* Accepts partial input, in the same format as {@link createRecordAsync}.
|
|
1001
|
+
* The more information provided, the more accurate the permissions check will be.
|
|
1002
|
+
*
|
|
1003
|
+
* @param fields object mapping `FieldId` or field name to value for that field.
|
|
1004
|
+
* @example
|
|
1005
|
+
* ```js
|
|
1006
|
+
* // Check if user can create a specific record, when you already know what
|
|
1007
|
+
* // fields/cell values will be set for the record.
|
|
1008
|
+
* const canCreateRecord = table.hasPermissionToCreateRecord({
|
|
1009
|
+
* 'Project Name': 'Advertising campaign',
|
|
1010
|
+
* 'Budget': 100,
|
|
1011
|
+
* });
|
|
1012
|
+
* if (!canCreateRecord) {
|
|
1013
|
+
* alert('not allowed!');
|
|
1014
|
+
* }
|
|
1015
|
+
*
|
|
1016
|
+
* // Like createRecordAsync, you can use either field names or field IDs.
|
|
1017
|
+
* const canCreateRecordWithFieldIds = table.hasPermissionToCreateRecord({
|
|
1018
|
+
* [projectNameField.id]: 'Cat video',
|
|
1019
|
+
* [budgetField.id]: 200,
|
|
1020
|
+
* });
|
|
1021
|
+
*
|
|
1022
|
+
* // Check if user could potentially create a record.
|
|
1023
|
+
* // Use when you don't know the specific fields/cell values yet (for example,
|
|
1024
|
+
* // to show or hide UI controls that let you start creating a record.)
|
|
1025
|
+
* const canCreateUnknownRecord = table.hasPermissionToCreateRecord();
|
|
1026
|
+
* ```
|
|
1027
|
+
*/
|
|
1028
|
+
hasPermissionToCreateRecord(fields) {
|
|
1029
|
+
return this.checkPermissionsForCreateRecord(fields).hasPermission;
|
|
1030
|
+
}
|
|
1031
|
+
/**
|
|
1032
|
+
* Creates new records with the specified cell values.
|
|
1033
|
+
*
|
|
1034
|
+
* Throws an error if the user does not have permission to create the given records, or
|
|
1035
|
+
* if invalid input is provided (eg. invalid cell values).
|
|
1036
|
+
*
|
|
1037
|
+
* Refer to {@link FieldType} for cell value write formats.
|
|
1038
|
+
*
|
|
1039
|
+
* You may only create up to 50 records in one call to `createRecordsAsync`.
|
|
1040
|
+
* See [Write back to Airtable](/guides/write-back-to-airtable#size-limits-rate-limits) for
|
|
1041
|
+
* more information about write limits.
|
|
1042
|
+
*
|
|
1043
|
+
* This action is asynchronous: `await` the returned promise if you wish to wait for the new
|
|
1044
|
+
* record to be persisted to Airtable servers.
|
|
1045
|
+
* Updates are applied optimistically locally, so your changes will be reflected in your extension
|
|
1046
|
+
* before the promise resolves.
|
|
1047
|
+
*
|
|
1048
|
+
* The returned promise will resolve to an array of RecordIds of the new records once the new
|
|
1049
|
+
* records are persisted.
|
|
1050
|
+
*
|
|
1051
|
+
* @param records Array of objects with a `fields` key mapping `FieldId` or field name to value for that field.
|
|
1052
|
+
* @example
|
|
1053
|
+
* ```js
|
|
1054
|
+
* const recordDefs = [
|
|
1055
|
+
* // Fields can be specified by name or ID
|
|
1056
|
+
* {
|
|
1057
|
+
* fields: {
|
|
1058
|
+
* 'Project Name': 'Advertising campaign',
|
|
1059
|
+
* 'Budget': 100,
|
|
1060
|
+
* },
|
|
1061
|
+
* },
|
|
1062
|
+
* {
|
|
1063
|
+
* fields: {
|
|
1064
|
+
* [projectNameField.id]: 'Cat video',
|
|
1065
|
+
* [budgetField.id]: 200,
|
|
1066
|
+
* },
|
|
1067
|
+
* },
|
|
1068
|
+
* // Specifying no fields will create a new record with no cell values set
|
|
1069
|
+
* {
|
|
1070
|
+
* fields: {},
|
|
1071
|
+
* },
|
|
1072
|
+
* // Cell values should generally have format matching the output of
|
|
1073
|
+
* // record.getCellValue() for the field being updated
|
|
1074
|
+
* {
|
|
1075
|
+
* fields: {
|
|
1076
|
+
* 'Project Name': 'Cat video 2'
|
|
1077
|
+
* 'Category (single select)': {name: 'Video'},
|
|
1078
|
+
* 'Tags (multiple select)': [{name: 'Cats'}, {id: 'choiceId'}],
|
|
1079
|
+
* 'Assets (attachment)': [{url: 'http://mywebsite.com/cats.mp4'}],
|
|
1080
|
+
* 'Related projects (linked records)': [{id: 'someRecordId'}],
|
|
1081
|
+
* },
|
|
1082
|
+
* },
|
|
1083
|
+
* ];
|
|
1084
|
+
*
|
|
1085
|
+
* function createNewRecords() {
|
|
1086
|
+
* if (table.hasPermissionToCreateRecords(recordDefs)) {
|
|
1087
|
+
* table.createRecordsAsync(recordDefs);
|
|
1088
|
+
* }
|
|
1089
|
+
* // You can now access the new records in your extension (e.g.
|
|
1090
|
+
* // `table.selectRecords()`) but they are still being saved to Airtable
|
|
1091
|
+
* // servers (e.g. other users may not be able to see them yet.)
|
|
1092
|
+
* }
|
|
1093
|
+
*
|
|
1094
|
+
* async function createNewRecordsAsync() {
|
|
1095
|
+
* if (table.hasPermissionToCreateRecords(recordDefs)) {
|
|
1096
|
+
* const newRecordIds = await table.createRecordsAsync(recordDefs);
|
|
1097
|
+
* }
|
|
1098
|
+
* // New records have been saved to Airtable servers.
|
|
1099
|
+
* alert(`new records with IDs ${newRecordIds} have been created`);
|
|
1100
|
+
* }
|
|
1101
|
+
* ```
|
|
1102
|
+
*/
|
|
1103
|
+
async createRecordsAsync(records) {
|
|
1104
|
+
let includesForeignRowsThatShouldBeCreated = false;
|
|
1105
|
+
const recordsToCreate = records.map(recordDef => {
|
|
1106
|
+
const recordDefKeys = (0, _private_utils.keys)(recordDef);
|
|
1107
|
+
let fields;
|
|
1108
|
+
if (recordDefKeys.length === 1 && recordDefKeys[0] === 'fields') {
|
|
1109
|
+
fields = recordDef.fields;
|
|
1110
|
+
} else {
|
|
1111
|
+
throw (0, _error_utils.spawnError)('Invalid record format. Please define field mappings using a `fields` key for each record definition object');
|
|
1112
|
+
}
|
|
1113
|
+
return {
|
|
1114
|
+
id: this._sdk.__airtableInterface.idGenerator.generateRecordId(),
|
|
1115
|
+
cellValuesByFieldId: this._cellValuesByFieldIdOrNameToCellValuesByFieldId(fields, () => {
|
|
732
1116
|
includesForeignRowsThatShouldBeCreated = true;
|
|
733
|
-
})
|
|
734
|
-
}
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
});
|
|
744
|
-
}
|
|
745
|
-
/**
|
|
746
|
-
* An alias for `checkPermissionsForUpdateRecords(records).hasPermission`.
|
|
747
|
-
*
|
|
748
|
-
* Checks whether the current user has permission to perform the given record updates.
|
|
749
|
-
*
|
|
750
|
-
* Accepts partial input, in the same format as {@link updateRecordsAsync}.
|
|
751
|
-
* The more information provided, the more accurate the permissions check will be.
|
|
752
|
-
*
|
|
753
|
-
* @param records Array of objects containing recordId and fields/cellValues to update for that record (specified as an object mapping `FieldId` or field name to cell value)
|
|
754
|
-
* @example
|
|
755
|
-
* ```js
|
|
756
|
-
* const recordsToUpdate = [
|
|
757
|
-
* {
|
|
758
|
-
* // Validating a complete record update
|
|
759
|
-
* id: record1.id,
|
|
760
|
-
* fields: {
|
|
761
|
-
* 'Post Title': 'How to make: orange-mango pound cake',
|
|
762
|
-
* 'Publication Date': '2020-01-01',
|
|
763
|
-
* },
|
|
764
|
-
* },
|
|
765
|
-
* {
|
|
766
|
-
* // Like updateRecordsAsync, fields can be specified by name or ID
|
|
767
|
-
* id: record2.id,
|
|
768
|
-
* fields: {
|
|
769
|
-
* [postTitleField.id]: 'Cake decorating tips & tricks',
|
|
770
|
-
* [publicationDateField.id]: '2020-02-02',
|
|
771
|
-
* },
|
|
772
|
-
* },
|
|
773
|
-
* {
|
|
774
|
-
* // Validating an update to a specific record, not knowing what
|
|
775
|
-
* // fields will be updated
|
|
776
|
-
* id: record3.id,
|
|
777
|
-
* },
|
|
778
|
-
* {
|
|
779
|
-
* // Validating an update to specific cell values, not knowing what
|
|
780
|
-
* // record will be updated
|
|
781
|
-
* fields: {
|
|
782
|
-
* 'My field name': 'updated value for unknown record',
|
|
783
|
-
* // You can use undefined if you know you're going to update a
|
|
784
|
-
* // field, but don't know the new cell value yet.
|
|
785
|
-
* 'Another field name': undefined,
|
|
786
|
-
* },
|
|
787
|
-
* },
|
|
788
|
-
* ];
|
|
789
|
-
*
|
|
790
|
-
* const canUpdateRecords = table.hasPermissionToUpdateRecords(recordsToUpdate);
|
|
791
|
-
* if (!canUpdateRecords) {
|
|
792
|
-
* alert('not allowed');
|
|
793
|
-
* }
|
|
794
|
-
*
|
|
795
|
-
* // Check if user could potentially update records.
|
|
796
|
-
* // Equivalent to table.hasPermissionToUpdateRecord()
|
|
797
|
-
* const canUpdateUnknownRecordsAndFields =
|
|
798
|
-
* table.hasPermissionToUpdateRecords();
|
|
799
|
-
* ```
|
|
800
|
-
*/
|
|
801
|
-
}, {
|
|
802
|
-
key: "hasPermissionToUpdateRecords",
|
|
803
|
-
value: function hasPermissionToUpdateRecords(records) {
|
|
804
|
-
return this.checkPermissionsForUpdateRecords(records).hasPermission;
|
|
805
|
-
}
|
|
806
|
-
/**
|
|
807
|
-
* Delete the given record.
|
|
808
|
-
*
|
|
809
|
-
* Throws an error if the user does not have permission to delete the given record.
|
|
810
|
-
*
|
|
811
|
-
* This action is asynchronous: `await` the returned promise if you wish to wait for the
|
|
812
|
-
* delete to be persisted to Airtable servers.
|
|
813
|
-
* Updates are applied optimistically locally, so your changes will be reflected in your extension
|
|
814
|
-
* before the promise resolves.
|
|
815
|
-
*
|
|
816
|
-
* @param recordOrRecordId the record to be deleted
|
|
817
|
-
* @example
|
|
818
|
-
* ```js
|
|
819
|
-
* function deleteRecord(record) {
|
|
820
|
-
* if (table.hasPermissionToDeleteRecord(record)) {
|
|
821
|
-
* table.deleteRecordAsync(record);
|
|
822
|
-
* }
|
|
823
|
-
* // The record is now deleted within your extension (eg will not be returned
|
|
824
|
-
* // in `table.selectRecords`) but it is still being saved to Airtable
|
|
825
|
-
* // servers (e.g. it may not look deleted to other users yet).
|
|
826
|
-
* }
|
|
827
|
-
*
|
|
828
|
-
* async function deleteRecordAsync(record) {
|
|
829
|
-
* if (table.hasPermissionToDeleteRecord(record)) {
|
|
830
|
-
* await table.deleteRecordAsync(record);
|
|
831
|
-
* }
|
|
832
|
-
* // Record deletion has been saved to Airtable servers.
|
|
833
|
-
* alert('record has been deleted');
|
|
834
|
-
* }
|
|
835
|
-
* ```
|
|
836
|
-
*/
|
|
837
|
-
}, {
|
|
838
|
-
key: "deleteRecordAsync",
|
|
839
|
-
value: (function () {
|
|
840
|
-
var _deleteRecordAsync = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3(recordOrRecordId) {
|
|
841
|
-
return _regenerator.default.wrap(function _callee3$(_context3) {
|
|
842
|
-
while (1) switch (_context3.prev = _context3.next) {
|
|
843
|
-
case 0:
|
|
844
|
-
_context3.next = 2;
|
|
845
|
-
return this.deleteRecordsAsync([recordOrRecordId]);
|
|
846
|
-
case 2:
|
|
847
|
-
case "end":
|
|
848
|
-
return _context3.stop();
|
|
849
|
-
}
|
|
850
|
-
}, _callee3, this);
|
|
851
|
-
}));
|
|
852
|
-
function deleteRecordAsync(_x4) {
|
|
853
|
-
return _deleteRecordAsync.apply(this, arguments);
|
|
1117
|
+
})
|
|
1118
|
+
};
|
|
1119
|
+
});
|
|
1120
|
+
await this._sdk.__mutations.applyMutationAsync({
|
|
1121
|
+
type: _mutations_core.MutationTypesCore.CREATE_MULTIPLE_RECORDS,
|
|
1122
|
+
tableId: this.id,
|
|
1123
|
+
records: recordsToCreate,
|
|
1124
|
+
opts: {
|
|
1125
|
+
parseDateCellValueInColumnTimeZone: true,
|
|
1126
|
+
includesForeignRowsThatShouldBeCreated
|
|
854
1127
|
}
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
return this.checkPermissionsForDeleteRecord(recordOrRecordId).hasPermission;
|
|
917
|
-
}
|
|
918
|
-
/**
|
|
919
|
-
* Delete the given records.
|
|
920
|
-
*
|
|
921
|
-
* Throws an error if the user does not have permission to delete the given records.
|
|
922
|
-
*
|
|
923
|
-
* You may only delete up to 50 records in one call to `deleteRecordsAsync`.
|
|
924
|
-
* See [Write back to Airtable](/guides/write-back-to-airtable#size-limits-rate-limits) for
|
|
925
|
-
* more information about write limits.
|
|
926
|
-
*
|
|
927
|
-
* This action is asynchronous: `await` the returned promise if you wish to wait for the
|
|
928
|
-
* delete to be persisted to Airtable servers.
|
|
929
|
-
* Updates are applied optimistically locally, so your changes will be reflected in your extension
|
|
930
|
-
* before the promise resolves.
|
|
931
|
-
*
|
|
932
|
-
* @param recordsOrRecordIds Array of Records and RecordIds
|
|
933
|
-
* @example
|
|
934
|
-
* ```js
|
|
935
|
-
*
|
|
936
|
-
* function deleteRecords(records) {
|
|
937
|
-
* if (table.hasPermissionToDeleteRecords(records)) {
|
|
938
|
-
* table.deleteRecordsAsync(records);
|
|
939
|
-
* }
|
|
940
|
-
* // The records are now deleted within your extension (eg will not be
|
|
941
|
-
* // returned in `table.selectRecords()`) but are still being saved to
|
|
942
|
-
* // Airtable servers (e.g. they may not look deleted to other users yet).
|
|
943
|
-
* }
|
|
944
|
-
*
|
|
945
|
-
* async function deleteRecordsAsync(records) {
|
|
946
|
-
* if (table.hasPermissionToDeleteRecords(records)) {
|
|
947
|
-
* await table.deleteRecordsAsync(records);
|
|
948
|
-
* }
|
|
949
|
-
* // Record deletions have been saved to Airtable servers.
|
|
950
|
-
* alert('records have been deleted');
|
|
951
|
-
* }
|
|
952
|
-
* ```
|
|
953
|
-
*/
|
|
954
|
-
}, {
|
|
955
|
-
key: "deleteRecordsAsync",
|
|
956
|
-
value: (function () {
|
|
957
|
-
var _deleteRecordsAsync = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4(recordsOrRecordIds) {
|
|
958
|
-
var recordIds;
|
|
959
|
-
return _regenerator.default.wrap(function _callee4$(_context4) {
|
|
960
|
-
while (1) switch (_context4.prev = _context4.next) {
|
|
961
|
-
case 0:
|
|
962
|
-
recordIds = recordsOrRecordIds.map(recordOrRecordId => typeof recordOrRecordId === 'string' ? recordOrRecordId : recordOrRecordId.id);
|
|
963
|
-
_context4.next = 3;
|
|
964
|
-
return this._sdk.__mutations.applyMutationAsync({
|
|
965
|
-
type: _mutations_core.MutationTypesCore.DELETE_MULTIPLE_RECORDS,
|
|
966
|
-
tableId: this.id,
|
|
967
|
-
recordIds
|
|
968
|
-
});
|
|
969
|
-
case 3:
|
|
970
|
-
case "end":
|
|
971
|
-
return _context4.stop();
|
|
972
|
-
}
|
|
973
|
-
}, _callee4, this);
|
|
974
|
-
}));
|
|
975
|
-
function deleteRecordsAsync(_x5) {
|
|
976
|
-
return _deleteRecordsAsync.apply(this, arguments);
|
|
1128
|
+
});
|
|
1129
|
+
return recordsToCreate.map(record => record.id);
|
|
1130
|
+
}
|
|
1131
|
+
/**
|
|
1132
|
+
* Checks whether the current user has permission to create the specified records.
|
|
1133
|
+
*
|
|
1134
|
+
* Accepts partial input, in the same format as {@link createRecordsAsync}.
|
|
1135
|
+
* The more information provided, the more accurate the permissions check will be.
|
|
1136
|
+
*
|
|
1137
|
+
* Returns `{hasPermission: true}` if the current user can create the specified records,
|
|
1138
|
+
* `{hasPermission: false, reasonDisplayString: string}` otherwise. `reasonDisplayString` may be
|
|
1139
|
+
* used to display an error message to the user.
|
|
1140
|
+
*
|
|
1141
|
+
* @param records Array of objects mapping `FieldId` or field name to value for that field.
|
|
1142
|
+
* @example
|
|
1143
|
+
* ```js
|
|
1144
|
+
* // Check if user can create specific records, when you already know what
|
|
1145
|
+
* // fields/cell values will be set for the records.
|
|
1146
|
+
* const createRecordsCheckResult = table.checkPermissionsForCreateRecords([
|
|
1147
|
+
* // Like createRecordsAsync, fields can be specified by name or ID
|
|
1148
|
+
* {
|
|
1149
|
+
* fields: {
|
|
1150
|
+
* 'Project Name': 'Advertising campaign',
|
|
1151
|
+
* 'Budget': 100,
|
|
1152
|
+
* },
|
|
1153
|
+
* },
|
|
1154
|
+
* {
|
|
1155
|
+
* fields: {
|
|
1156
|
+
* [projectNameField.id]: 'Cat video',
|
|
1157
|
+
* [budgetField.id]: 200,
|
|
1158
|
+
* },
|
|
1159
|
+
* },
|
|
1160
|
+
* {},
|
|
1161
|
+
* ]);
|
|
1162
|
+
* if (!createRecordsCheckResult.hasPermission) {
|
|
1163
|
+
* alert(createRecordsCheckResult.reasonDisplayString);
|
|
1164
|
+
* }
|
|
1165
|
+
*
|
|
1166
|
+
* // Check if user could potentially create records.
|
|
1167
|
+
* // Use when you don't know the specific fields/cell values yet (for example,
|
|
1168
|
+
* // to show or hide UI controls that let you start creating records.)
|
|
1169
|
+
* // Equivalent to table.checkPermissionsForCreateRecord()
|
|
1170
|
+
* const createUnknownRecordCheckResult =
|
|
1171
|
+
* table.checkPermissionsForCreateRecords();
|
|
1172
|
+
* ```
|
|
1173
|
+
*/
|
|
1174
|
+
checkPermissionsForCreateRecords(records) {
|
|
1175
|
+
let includesForeignRowsThatShouldBeCreated = false;
|
|
1176
|
+
const recordsWithCellValuesByFieldId = records ? records.map(record => ({
|
|
1177
|
+
id: undefined,
|
|
1178
|
+
cellValuesByFieldId: record.fields ? this._cellValuesByFieldIdOrNameToCellValuesByFieldId(record.fields, () => {
|
|
1179
|
+
includesForeignRowsThatShouldBeCreated = true;
|
|
1180
|
+
}) : undefined
|
|
1181
|
+
})) : undefined;
|
|
1182
|
+
return this._sdk.__mutations.checkPermissionsForMutation({
|
|
1183
|
+
type: _mutations_core.MutationTypesCore.CREATE_MULTIPLE_RECORDS,
|
|
1184
|
+
tableId: this.id,
|
|
1185
|
+
records: recordsWithCellValuesByFieldId,
|
|
1186
|
+
opts: {
|
|
1187
|
+
parseDateCellValueInColumnTimeZone: true,
|
|
1188
|
+
includesForeignRowsThatShouldBeCreated
|
|
977
1189
|
}
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
* Accepts optional input, in the same format as {@link deleteRecordsAsync}.
|
|
1024
|
-
* The more information provided, the more accurate the permissions check will be.
|
|
1025
|
-
*
|
|
1026
|
-
* @param recordsOrRecordIds the records to be deleted
|
|
1027
|
-
* @example
|
|
1028
|
-
* ```js
|
|
1029
|
-
* // Check if user can delete specific records
|
|
1030
|
-
* const canDeleteRecords =
|
|
1031
|
-
* table.hasPermissionToDeleteRecords([record1, record2]);
|
|
1032
|
-
* if (!canDeleteRecords) {
|
|
1033
|
-
* alert('not allowed!');
|
|
1034
|
-
* }
|
|
1035
|
-
*
|
|
1036
|
-
* // Check if user could potentially delete records.
|
|
1037
|
-
* // Use when you don't know the specific records you want to delete yet (for
|
|
1038
|
-
* // example, to show/hide UI controls that let you select records to delete).
|
|
1039
|
-
* // Equivalent to table.hasPermissionToDeleteRecord()
|
|
1040
|
-
* const canDeleteUnknownRecords = table.hasPermissionToDeleteRecords();
|
|
1041
|
-
* ```
|
|
1042
|
-
*/
|
|
1043
|
-
}, {
|
|
1044
|
-
key: "hasPermissionToDeleteRecords",
|
|
1045
|
-
value: function hasPermissionToDeleteRecords(recordsOrRecordIds) {
|
|
1046
|
-
return this.checkPermissionsForDeleteRecords(recordsOrRecordIds).hasPermission;
|
|
1047
|
-
}
|
|
1190
|
+
});
|
|
1191
|
+
}
|
|
1192
|
+
/**
|
|
1193
|
+
* An alias for `checkPermissionsForCreateRecords(records).hasPermission`.
|
|
1194
|
+
*
|
|
1195
|
+
* Checks whether the current user has permission to create the specified records.
|
|
1196
|
+
*
|
|
1197
|
+
* Accepts partial input, in the same format as {@link createRecordsAsync}.
|
|
1198
|
+
* The more information provided, the more accurate the permissions check will be.
|
|
1199
|
+
*
|
|
1200
|
+
* @param records Array of objects mapping `FieldId` or field name to value for that field.
|
|
1201
|
+
* @example
|
|
1202
|
+
* ```js
|
|
1203
|
+
* // Check if user can create specific records, when you already know what fields/cell values
|
|
1204
|
+
* // will be set for the records.
|
|
1205
|
+
* const canCreateRecords = table.hasPermissionToCreateRecords([
|
|
1206
|
+
* // Like createRecordsAsync, fields can be specified by name or ID
|
|
1207
|
+
* {
|
|
1208
|
+
* fields: {
|
|
1209
|
+
* 'Project Name': 'Advertising campaign',
|
|
1210
|
+
* 'Budget': 100,
|
|
1211
|
+
* }
|
|
1212
|
+
* },
|
|
1213
|
+
* {
|
|
1214
|
+
* fields: {
|
|
1215
|
+
* [projectNameField.id]: 'Cat video',
|
|
1216
|
+
* [budgetField.id]: 200,
|
|
1217
|
+
* }
|
|
1218
|
+
* },
|
|
1219
|
+
* {},
|
|
1220
|
+
* ]);
|
|
1221
|
+
* if (!canCreateRecords) {
|
|
1222
|
+
* alert('not allowed');
|
|
1223
|
+
* }
|
|
1224
|
+
*
|
|
1225
|
+
* // Check if user could potentially create records.
|
|
1226
|
+
* // Use when you don't know the specific fields/cell values yet (for example,
|
|
1227
|
+
* // to show or hide UI controls that let you start creating records).
|
|
1228
|
+
* // Equivalent to table.hasPermissionToCreateRecord()
|
|
1229
|
+
* const canCreateUnknownRecords = table.hasPermissionToCreateRecords();
|
|
1230
|
+
* ```
|
|
1231
|
+
*/
|
|
1232
|
+
hasPermissionToCreateRecords(records) {
|
|
1233
|
+
return this.checkPermissionsForCreateRecords(records).hasPermission;
|
|
1234
|
+
}
|
|
1048
1235
|
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
* This action is asynchronous: `await` the returned promise if you wish to wait for the new
|
|
1058
|
-
* record to be persisted to Airtable servers.
|
|
1059
|
-
* Updates are applied optimistically locally, so your changes will be reflected in your extension
|
|
1060
|
-
* before the promise resolves.
|
|
1061
|
-
*
|
|
1062
|
-
* The returned promise will resolve to the RecordId of the new record once it is persisted.
|
|
1063
|
-
*
|
|
1064
|
-
* @param fields object mapping `FieldId` or field name to value for that field.
|
|
1065
|
-
* @example
|
|
1066
|
-
* ```js
|
|
1067
|
-
* function createNewRecord(recordFields) {
|
|
1068
|
-
* if (table.hasPermissionToCreateRecord(recordFields)) {
|
|
1069
|
-
* table.createRecordAsync(recordFields);
|
|
1070
|
-
* }
|
|
1071
|
-
* // You can now access the new record in your extension (eg
|
|
1072
|
-
* // `table.selectRecords()`) but it is still being saved to Airtable
|
|
1073
|
-
* // servers (e.g. other users may not be able to see it yet).
|
|
1074
|
-
* }
|
|
1075
|
-
*
|
|
1076
|
-
* async function createNewRecordAsync(recordFields) {
|
|
1077
|
-
* if (table.hasPermissionToCreateRecord(recordFields)) {
|
|
1078
|
-
* const newRecordId = await table.createRecordAsync(recordFields);
|
|
1079
|
-
* }
|
|
1080
|
-
* // New record has been saved to Airtable servers.
|
|
1081
|
-
* alert(`new record with ID ${newRecordId} has been created`);
|
|
1082
|
-
* }
|
|
1083
|
-
*
|
|
1084
|
-
* // Fields can be specified by name or ID
|
|
1085
|
-
* createNewRecord({
|
|
1086
|
-
* 'Project Name': 'Advertising campaign',
|
|
1087
|
-
* 'Budget': 100,
|
|
1088
|
-
* });
|
|
1089
|
-
* createNewRecord({
|
|
1090
|
-
* [projectNameField.id]: 'Cat video',
|
|
1091
|
-
* [budgetField.id]: 200,
|
|
1092
|
-
* });
|
|
1093
|
-
*
|
|
1094
|
-
* // Cell values should generally have format matching the output of
|
|
1095
|
-
* // record.getCellValue() for the field being updated
|
|
1096
|
-
* createNewRecord({
|
|
1097
|
-
* 'Project Name': 'Cat video 2'
|
|
1098
|
-
* 'Category (single select)': {name: 'Video'},
|
|
1099
|
-
* 'Tags (multiple select)': [{name: 'Cats'}, {id: 'someChoiceId'}],
|
|
1100
|
-
* 'Assets (attachment)': [{url: 'http://mywebsite.com/cats.mp4'}],
|
|
1101
|
-
* 'Related projects (linked records)': [{id: 'someRecordId'}],
|
|
1102
|
-
* });
|
|
1103
|
-
* ```
|
|
1104
|
-
*/
|
|
1105
|
-
}, {
|
|
1106
|
-
key: "createRecordAsync",
|
|
1107
|
-
value: (function () {
|
|
1108
|
-
var _createRecordAsync = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee5() {
|
|
1109
|
-
var fields,
|
|
1110
|
-
recordIds,
|
|
1111
|
-
_args5 = arguments;
|
|
1112
|
-
return _regenerator.default.wrap(function _callee5$(_context5) {
|
|
1113
|
-
while (1) switch (_context5.prev = _context5.next) {
|
|
1114
|
-
case 0:
|
|
1115
|
-
fields = _args5.length > 0 && _args5[0] !== undefined ? _args5[0] : {};
|
|
1116
|
-
_context5.next = 3;
|
|
1117
|
-
return this.createRecordsAsync([{
|
|
1118
|
-
fields
|
|
1119
|
-
}]);
|
|
1120
|
-
case 3:
|
|
1121
|
-
recordIds = _context5.sent;
|
|
1122
|
-
return _context5.abrupt("return", recordIds[0]);
|
|
1123
|
-
case 5:
|
|
1124
|
-
case "end":
|
|
1125
|
-
return _context5.stop();
|
|
1126
|
-
}
|
|
1127
|
-
}, _callee5, this);
|
|
1128
|
-
}));
|
|
1129
|
-
function createRecordAsync() {
|
|
1130
|
-
return _createRecordAsync.apply(this, arguments);
|
|
1131
|
-
}
|
|
1132
|
-
return createRecordAsync;
|
|
1133
|
-
}()
|
|
1134
|
-
/**
|
|
1135
|
-
* Checks whether the current user has permission to create the specified record.
|
|
1136
|
-
*
|
|
1137
|
-
* Accepts partial input, in the same format as {@link createRecordAsync}.
|
|
1138
|
-
* The more information provided, the more accurate the permissions check will be.
|
|
1139
|
-
*
|
|
1140
|
-
* Returns `{hasPermission: true}` if the current user can create the specified record,
|
|
1141
|
-
* `{hasPermission: false, reasonDisplayString: string}` otherwise. `reasonDisplayString` may be
|
|
1142
|
-
* used to display an error message to the user.
|
|
1143
|
-
*
|
|
1144
|
-
* @param fields object mapping `FieldId` or field name to value for that field.
|
|
1145
|
-
* @example
|
|
1146
|
-
* ```js
|
|
1147
|
-
* // Check if user can create a specific record, when you already know what
|
|
1148
|
-
* // fields/cell values will be set for the record.
|
|
1149
|
-
* const createRecordCheckResult = table.checkPermissionsForCreateRecord({
|
|
1150
|
-
* 'Project Name': 'Advertising campaign',
|
|
1151
|
-
* 'Budget': 100,
|
|
1152
|
-
* });
|
|
1153
|
-
* if (!createRecordCheckResult.hasPermission) {
|
|
1154
|
-
* alert(createRecordCheckResult.reasonDisplayString);
|
|
1155
|
-
* }
|
|
1156
|
-
*
|
|
1157
|
-
* // Like createRecordAsync, you can use either field names or field IDs.
|
|
1158
|
-
* const checkResultWithFieldIds = table.checkPermissionsForCreateRecord({
|
|
1159
|
-
* [projectNameField.id]: 'Cat video',
|
|
1160
|
-
* [budgetField.id]: 200,
|
|
1161
|
-
* });
|
|
1162
|
-
*
|
|
1163
|
-
* // Check if user could potentially create a record.
|
|
1164
|
-
* // Use when you don't know the specific fields/cell values yet (for example,
|
|
1165
|
-
* // to show or hide UI controls that let you start creating a record.)
|
|
1166
|
-
* const createUnknownRecordCheckResult =
|
|
1167
|
-
* table.checkPermissionsForCreateRecord();
|
|
1168
|
-
* ```
|
|
1169
|
-
*/
|
|
1170
|
-
)
|
|
1171
|
-
}, {
|
|
1172
|
-
key: "checkPermissionsForCreateRecord",
|
|
1173
|
-
value: function checkPermissionsForCreateRecord(fields) {
|
|
1174
|
-
return this.checkPermissionsForCreateRecords([{
|
|
1175
|
-
fields: fields || undefined
|
|
1176
|
-
}]);
|
|
1236
|
+
/**
|
|
1237
|
+
* @internal
|
|
1238
|
+
*/
|
|
1239
|
+
__triggerOnChangeForDirtyPaths(dirtyPaths) {
|
|
1240
|
+
let didTableSchemaChange = false;
|
|
1241
|
+
if (dirtyPaths.name) {
|
|
1242
|
+
this._onChange(WatchableTableKeysCore.name);
|
|
1243
|
+
didTableSchemaChange = true;
|
|
1177
1244
|
}
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
*
|
|
1181
|
-
* Checks whether the current user has permission to create the specified record.
|
|
1182
|
-
*
|
|
1183
|
-
* Accepts partial input, in the same format as {@link createRecordAsync}.
|
|
1184
|
-
* The more information provided, the more accurate the permissions check will be.
|
|
1185
|
-
*
|
|
1186
|
-
* @param fields object mapping `FieldId` or field name to value for that field.
|
|
1187
|
-
* @example
|
|
1188
|
-
* ```js
|
|
1189
|
-
* // Check if user can create a specific record, when you already know what
|
|
1190
|
-
* // fields/cell values will be set for the record.
|
|
1191
|
-
* const canCreateRecord = table.hasPermissionToCreateRecord({
|
|
1192
|
-
* 'Project Name': 'Advertising campaign',
|
|
1193
|
-
* 'Budget': 100,
|
|
1194
|
-
* });
|
|
1195
|
-
* if (!canCreateRecord) {
|
|
1196
|
-
* alert('not allowed!');
|
|
1197
|
-
* }
|
|
1198
|
-
*
|
|
1199
|
-
* // Like createRecordAsync, you can use either field names or field IDs.
|
|
1200
|
-
* const canCreateRecordWithFieldIds = table.hasPermissionToCreateRecord({
|
|
1201
|
-
* [projectNameField.id]: 'Cat video',
|
|
1202
|
-
* [budgetField.id]: 200,
|
|
1203
|
-
* });
|
|
1204
|
-
*
|
|
1205
|
-
* // Check if user could potentially create a record.
|
|
1206
|
-
* // Use when you don't know the specific fields/cell values yet (for example,
|
|
1207
|
-
* // to show or hide UI controls that let you start creating a record.)
|
|
1208
|
-
* const canCreateUnknownRecord = table.hasPermissionToCreateRecord();
|
|
1209
|
-
* ```
|
|
1210
|
-
*/
|
|
1211
|
-
}, {
|
|
1212
|
-
key: "hasPermissionToCreateRecord",
|
|
1213
|
-
value: function hasPermissionToCreateRecord(fields) {
|
|
1214
|
-
return this.checkPermissionsForCreateRecord(fields).hasPermission;
|
|
1245
|
+
if (dirtyPaths.lock) {
|
|
1246
|
+
didTableSchemaChange = true;
|
|
1215
1247
|
}
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
*
|
|
1219
|
-
* Throws an error if the user does not have permission to create the given records, or
|
|
1220
|
-
* if invalid input is provided (eg. invalid cell values).
|
|
1221
|
-
*
|
|
1222
|
-
* Refer to {@link FieldType} for cell value write formats.
|
|
1223
|
-
*
|
|
1224
|
-
* You may only create up to 50 records in one call to `createRecordsAsync`.
|
|
1225
|
-
* See [Write back to Airtable](/guides/write-back-to-airtable#size-limits-rate-limits) for
|
|
1226
|
-
* more information about write limits.
|
|
1227
|
-
*
|
|
1228
|
-
* This action is asynchronous: `await` the returned promise if you wish to wait for the new
|
|
1229
|
-
* record to be persisted to Airtable servers.
|
|
1230
|
-
* Updates are applied optimistically locally, so your changes will be reflected in your extension
|
|
1231
|
-
* before the promise resolves.
|
|
1232
|
-
*
|
|
1233
|
-
* The returned promise will resolve to an array of RecordIds of the new records once the new
|
|
1234
|
-
* records are persisted.
|
|
1235
|
-
*
|
|
1236
|
-
* @param records Array of objects with a `fields` key mapping `FieldId` or field name to value for that field.
|
|
1237
|
-
* @example
|
|
1238
|
-
* ```js
|
|
1239
|
-
* const recordDefs = [
|
|
1240
|
-
* // Fields can be specified by name or ID
|
|
1241
|
-
* {
|
|
1242
|
-
* fields: {
|
|
1243
|
-
* 'Project Name': 'Advertising campaign',
|
|
1244
|
-
* 'Budget': 100,
|
|
1245
|
-
* },
|
|
1246
|
-
* },
|
|
1247
|
-
* {
|
|
1248
|
-
* fields: {
|
|
1249
|
-
* [projectNameField.id]: 'Cat video',
|
|
1250
|
-
* [budgetField.id]: 200,
|
|
1251
|
-
* },
|
|
1252
|
-
* },
|
|
1253
|
-
* // Specifying no fields will create a new record with no cell values set
|
|
1254
|
-
* {
|
|
1255
|
-
* fields: {},
|
|
1256
|
-
* },
|
|
1257
|
-
* // Cell values should generally have format matching the output of
|
|
1258
|
-
* // record.getCellValue() for the field being updated
|
|
1259
|
-
* {
|
|
1260
|
-
* fields: {
|
|
1261
|
-
* 'Project Name': 'Cat video 2'
|
|
1262
|
-
* 'Category (single select)': {name: 'Video'},
|
|
1263
|
-
* 'Tags (multiple select)': [{name: 'Cats'}, {id: 'choiceId'}],
|
|
1264
|
-
* 'Assets (attachment)': [{url: 'http://mywebsite.com/cats.mp4'}],
|
|
1265
|
-
* 'Related projects (linked records)': [{id: 'someRecordId'}],
|
|
1266
|
-
* },
|
|
1267
|
-
* },
|
|
1268
|
-
* ];
|
|
1269
|
-
*
|
|
1270
|
-
* function createNewRecords() {
|
|
1271
|
-
* if (table.hasPermissionToCreateRecords(recordDefs)) {
|
|
1272
|
-
* table.createRecordsAsync(recordDefs);
|
|
1273
|
-
* }
|
|
1274
|
-
* // You can now access the new records in your extension (e.g.
|
|
1275
|
-
* // `table.selectRecords()`) but they are still being saved to Airtable
|
|
1276
|
-
* // servers (e.g. other users may not be able to see them yet.)
|
|
1277
|
-
* }
|
|
1278
|
-
*
|
|
1279
|
-
* async function createNewRecordsAsync() {
|
|
1280
|
-
* if (table.hasPermissionToCreateRecords(recordDefs)) {
|
|
1281
|
-
* const newRecordIds = await table.createRecordsAsync(recordDefs);
|
|
1282
|
-
* }
|
|
1283
|
-
* // New records have been saved to Airtable servers.
|
|
1284
|
-
* alert(`new records with IDs ${newRecordIds} have been created`);
|
|
1285
|
-
* }
|
|
1286
|
-
* ```
|
|
1287
|
-
*/
|
|
1288
|
-
}, {
|
|
1289
|
-
key: "createRecordsAsync",
|
|
1290
|
-
value: (function () {
|
|
1291
|
-
var _createRecordsAsync = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee6(records) {
|
|
1292
|
-
var includesForeignRowsThatShouldBeCreated, recordsToCreate;
|
|
1293
|
-
return _regenerator.default.wrap(function _callee6$(_context6) {
|
|
1294
|
-
while (1) switch (_context6.prev = _context6.next) {
|
|
1295
|
-
case 0:
|
|
1296
|
-
includesForeignRowsThatShouldBeCreated = false;
|
|
1297
|
-
recordsToCreate = records.map(recordDef => {
|
|
1298
|
-
var recordDefKeys = (0, _private_utils.keys)(recordDef);
|
|
1299
|
-
var fields;
|
|
1300
|
-
if (recordDefKeys.length === 1 && recordDefKeys[0] === 'fields') {
|
|
1301
|
-
fields = recordDef.fields;
|
|
1302
|
-
} else {
|
|
1303
|
-
throw (0, _error_utils.spawnError)('Invalid record format. Please define field mappings using a `fields` key for each record definition object');
|
|
1304
|
-
}
|
|
1305
|
-
return {
|
|
1306
|
-
id: this._sdk.__airtableInterface.idGenerator.generateRecordId(),
|
|
1307
|
-
cellValuesByFieldId: this._cellValuesByFieldIdOrNameToCellValuesByFieldId(fields, () => {
|
|
1308
|
-
includesForeignRowsThatShouldBeCreated = true;
|
|
1309
|
-
})
|
|
1310
|
-
};
|
|
1311
|
-
});
|
|
1312
|
-
_context6.next = 4;
|
|
1313
|
-
return this._sdk.__mutations.applyMutationAsync({
|
|
1314
|
-
type: _mutations_core.MutationTypesCore.CREATE_MULTIPLE_RECORDS,
|
|
1315
|
-
tableId: this.id,
|
|
1316
|
-
records: recordsToCreate,
|
|
1317
|
-
opts: {
|
|
1318
|
-
parseDateCellValueInColumnTimeZone: true,
|
|
1319
|
-
includesForeignRowsThatShouldBeCreated
|
|
1320
|
-
}
|
|
1321
|
-
});
|
|
1322
|
-
case 4:
|
|
1323
|
-
return _context6.abrupt("return", recordsToCreate.map(record => record.id));
|
|
1324
|
-
case 5:
|
|
1325
|
-
case "end":
|
|
1326
|
-
return _context6.stop();
|
|
1327
|
-
}
|
|
1328
|
-
}, _callee6, this);
|
|
1329
|
-
}));
|
|
1330
|
-
function createRecordsAsync(_x6) {
|
|
1331
|
-
return _createRecordsAsync.apply(this, arguments);
|
|
1332
|
-
}
|
|
1333
|
-
return createRecordsAsync;
|
|
1334
|
-
}()
|
|
1335
|
-
/**
|
|
1336
|
-
* Checks whether the current user has permission to create the specified records.
|
|
1337
|
-
*
|
|
1338
|
-
* Accepts partial input, in the same format as {@link createRecordsAsync}.
|
|
1339
|
-
* The more information provided, the more accurate the permissions check will be.
|
|
1340
|
-
*
|
|
1341
|
-
* Returns `{hasPermission: true}` if the current user can create the specified records,
|
|
1342
|
-
* `{hasPermission: false, reasonDisplayString: string}` otherwise. `reasonDisplayString` may be
|
|
1343
|
-
* used to display an error message to the user.
|
|
1344
|
-
*
|
|
1345
|
-
* @param records Array of objects mapping `FieldId` or field name to value for that field.
|
|
1346
|
-
* @example
|
|
1347
|
-
* ```js
|
|
1348
|
-
* // Check if user can create specific records, when you already know what
|
|
1349
|
-
* // fields/cell values will be set for the records.
|
|
1350
|
-
* const createRecordsCheckResult = table.checkPermissionsForCreateRecords([
|
|
1351
|
-
* // Like createRecordsAsync, fields can be specified by name or ID
|
|
1352
|
-
* {
|
|
1353
|
-
* fields: {
|
|
1354
|
-
* 'Project Name': 'Advertising campaign',
|
|
1355
|
-
* 'Budget': 100,
|
|
1356
|
-
* },
|
|
1357
|
-
* },
|
|
1358
|
-
* {
|
|
1359
|
-
* fields: {
|
|
1360
|
-
* [projectNameField.id]: 'Cat video',
|
|
1361
|
-
* [budgetField.id]: 200,
|
|
1362
|
-
* },
|
|
1363
|
-
* },
|
|
1364
|
-
* {},
|
|
1365
|
-
* ]);
|
|
1366
|
-
* if (!createRecordsCheckResult.hasPermission) {
|
|
1367
|
-
* alert(createRecordsCheckResult.reasonDisplayString);
|
|
1368
|
-
* }
|
|
1369
|
-
*
|
|
1370
|
-
* // Check if user could potentially create records.
|
|
1371
|
-
* // Use when you don't know the specific fields/cell values yet (for example,
|
|
1372
|
-
* // to show or hide UI controls that let you start creating records.)
|
|
1373
|
-
* // Equivalent to table.checkPermissionsForCreateRecord()
|
|
1374
|
-
* const createUnknownRecordCheckResult =
|
|
1375
|
-
* table.checkPermissionsForCreateRecords();
|
|
1376
|
-
* ```
|
|
1377
|
-
*/
|
|
1378
|
-
)
|
|
1379
|
-
}, {
|
|
1380
|
-
key: "checkPermissionsForCreateRecords",
|
|
1381
|
-
value: function checkPermissionsForCreateRecords(records) {
|
|
1382
|
-
var includesForeignRowsThatShouldBeCreated = false;
|
|
1383
|
-
var recordsWithCellValuesByFieldId = records ? records.map(record => ({
|
|
1384
|
-
id: undefined,
|
|
1385
|
-
cellValuesByFieldId: record.fields ? this._cellValuesByFieldIdOrNameToCellValuesByFieldId(record.fields, () => {
|
|
1386
|
-
includesForeignRowsThatShouldBeCreated = true;
|
|
1387
|
-
}) : undefined
|
|
1388
|
-
})) : undefined;
|
|
1389
|
-
return this._sdk.__mutations.checkPermissionsForMutation({
|
|
1390
|
-
type: _mutations_core.MutationTypesCore.CREATE_MULTIPLE_RECORDS,
|
|
1391
|
-
tableId: this.id,
|
|
1392
|
-
records: recordsWithCellValuesByFieldId,
|
|
1393
|
-
opts: {
|
|
1394
|
-
parseDateCellValueInColumnTimeZone: true,
|
|
1395
|
-
includesForeignRowsThatShouldBeCreated
|
|
1396
|
-
}
|
|
1397
|
-
});
|
|
1248
|
+
if (dirtyPaths.externalSyncById) {
|
|
1249
|
+
didTableSchemaChange = true;
|
|
1398
1250
|
}
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
* Checks whether the current user has permission to create the specified records.
|
|
1403
|
-
*
|
|
1404
|
-
* Accepts partial input, in the same format as {@link createRecordsAsync}.
|
|
1405
|
-
* The more information provided, the more accurate the permissions check will be.
|
|
1406
|
-
*
|
|
1407
|
-
* @param records Array of objects mapping `FieldId` or field name to value for that field.
|
|
1408
|
-
* @example
|
|
1409
|
-
* ```js
|
|
1410
|
-
* // Check if user can create specific records, when you already know what fields/cell values
|
|
1411
|
-
* // will be set for the records.
|
|
1412
|
-
* const canCreateRecords = table.hasPermissionToCreateRecords([
|
|
1413
|
-
* // Like createRecordsAsync, fields can be specified by name or ID
|
|
1414
|
-
* {
|
|
1415
|
-
* fields: {
|
|
1416
|
-
* 'Project Name': 'Advertising campaign',
|
|
1417
|
-
* 'Budget': 100,
|
|
1418
|
-
* }
|
|
1419
|
-
* },
|
|
1420
|
-
* {
|
|
1421
|
-
* fields: {
|
|
1422
|
-
* [projectNameField.id]: 'Cat video',
|
|
1423
|
-
* [budgetField.id]: 200,
|
|
1424
|
-
* }
|
|
1425
|
-
* },
|
|
1426
|
-
* {},
|
|
1427
|
-
* ]);
|
|
1428
|
-
* if (!canCreateRecords) {
|
|
1429
|
-
* alert('not allowed');
|
|
1430
|
-
* }
|
|
1431
|
-
*
|
|
1432
|
-
* // Check if user could potentially create records.
|
|
1433
|
-
* // Use when you don't know the specific fields/cell values yet (for example,
|
|
1434
|
-
* // to show or hide UI controls that let you start creating records).
|
|
1435
|
-
* // Equivalent to table.hasPermissionToCreateRecord()
|
|
1436
|
-
* const canCreateUnknownRecords = table.hasPermissionToCreateRecords();
|
|
1437
|
-
* ```
|
|
1438
|
-
*/
|
|
1439
|
-
}, {
|
|
1440
|
-
key: "hasPermissionToCreateRecords",
|
|
1441
|
-
value: function hasPermissionToCreateRecords(records) {
|
|
1442
|
-
return this.checkPermissionsForCreateRecords(records).hasPermission;
|
|
1251
|
+
if (dirtyPaths.description) {
|
|
1252
|
+
this._onChange(WatchableTableKeysCore.description);
|
|
1253
|
+
didTableSchemaChange = true;
|
|
1443
1254
|
}
|
|
1255
|
+
if (dirtyPaths.fieldsById) {
|
|
1256
|
+
// TODO: don't trigger schema change when autonumber typeOptions change.
|
|
1257
|
+
// That currently happens every time you create a row in a table with an
|
|
1258
|
+
// autonumber field.
|
|
1259
|
+
didTableSchemaChange = true;
|
|
1444
1260
|
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
didTableSchemaChange = true;
|
|
1461
|
-
}
|
|
1462
|
-
if (dirtyPaths.description) {
|
|
1463
|
-
this._onChange(WatchableTableKeysCore.description);
|
|
1464
|
-
didTableSchemaChange = true;
|
|
1465
|
-
}
|
|
1466
|
-
if (dirtyPaths.fieldsById) {
|
|
1467
|
-
// TODO: don't trigger schema change when autonumber typeOptions change.
|
|
1468
|
-
// That currently happens every time you create a row in a table with an
|
|
1469
|
-
// autonumber field.
|
|
1470
|
-
didTableSchemaChange = true;
|
|
1471
|
-
|
|
1472
|
-
// Since tables don't have a field order, need to detect if a field
|
|
1473
|
-
// was created or deleted and trigger onChange for fields.
|
|
1474
|
-
var addedFieldIds = [];
|
|
1475
|
-
var removedFieldIds = [];
|
|
1476
|
-
var _iterator2 = _createForOfIteratorHelper((0, _private_utils.entries)(dirtyPaths.fieldsById)),
|
|
1477
|
-
_step2;
|
|
1478
|
-
try {
|
|
1479
|
-
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
1480
|
-
var _step2$value = (0, _slicedToArray2.default)(_step2.value, 2),
|
|
1481
|
-
_fieldId3 = _step2$value[0],
|
|
1482
|
-
dirtyFieldPaths = _step2$value[1];
|
|
1483
|
-
if (dirtyFieldPaths && dirtyFieldPaths._isDirty) {
|
|
1484
|
-
// If the entire field is dirty, it was either created or deleted.
|
|
1485
|
-
if ((0, _private_utils.has)(this._data.fieldsById, _fieldId3)) {
|
|
1486
|
-
addedFieldIds.push(_fieldId3);
|
|
1487
|
-
} else {
|
|
1488
|
-
removedFieldIds.push(_fieldId3);
|
|
1489
|
-
var fieldModel = this._fieldModelsById[_fieldId3];
|
|
1490
|
-
if (fieldModel) {
|
|
1491
|
-
// Remove the Field model if it was deleted.
|
|
1492
|
-
delete this._fieldModelsById[_fieldId3];
|
|
1493
|
-
}
|
|
1494
|
-
}
|
|
1495
|
-
} else {
|
|
1496
|
-
// Directly access from _fieldModelsById to avoid creating
|
|
1497
|
-
// a field model if it doesn't already exist. If it doesn't exist,
|
|
1498
|
-
// nothing can be subscribed to any events on it.
|
|
1499
|
-
var field = this._fieldModelsById[_fieldId3];
|
|
1500
|
-
if (field) {
|
|
1501
|
-
field.__triggerOnChangeForDirtyPaths(dirtyFieldPaths);
|
|
1502
|
-
}
|
|
1261
|
+
// Since tables don't have a field order, need to detect if a field
|
|
1262
|
+
// was created or deleted and trigger onChange for fields.
|
|
1263
|
+
const addedFieldIds = [];
|
|
1264
|
+
const removedFieldIds = [];
|
|
1265
|
+
for (const [fieldId, dirtyFieldPaths] of (0, _private_utils.entries)(dirtyPaths.fieldsById)) {
|
|
1266
|
+
if (dirtyFieldPaths && dirtyFieldPaths._isDirty) {
|
|
1267
|
+
// If the entire field is dirty, it was either created or deleted.
|
|
1268
|
+
if ((0, _private_utils.has)(this._data.fieldsById, fieldId)) {
|
|
1269
|
+
addedFieldIds.push(fieldId);
|
|
1270
|
+
} else {
|
|
1271
|
+
removedFieldIds.push(fieldId);
|
|
1272
|
+
const fieldModel = this._fieldModelsById[fieldId];
|
|
1273
|
+
if (fieldModel) {
|
|
1274
|
+
// Remove the Field model if it was deleted.
|
|
1275
|
+
delete this._fieldModelsById[fieldId];
|
|
1503
1276
|
}
|
|
1504
1277
|
}
|
|
1505
|
-
}
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
removedFieldIds
|
|
1514
|
-
});
|
|
1278
|
+
} else {
|
|
1279
|
+
// Directly access from _fieldModelsById to avoid creating
|
|
1280
|
+
// a field model if it doesn't already exist. If it doesn't exist,
|
|
1281
|
+
// nothing can be subscribed to any events on it.
|
|
1282
|
+
const field = this._fieldModelsById[fieldId];
|
|
1283
|
+
if (field) {
|
|
1284
|
+
field.__triggerOnChangeForDirtyPaths(dirtyFieldPaths);
|
|
1285
|
+
}
|
|
1515
1286
|
}
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
this.
|
|
1287
|
+
}
|
|
1288
|
+
if (addedFieldIds.length > 0 || removedFieldIds.length > 0) {
|
|
1289
|
+
this._onChange(WatchableTableKeysCore.fields, {
|
|
1290
|
+
addedFieldIds,
|
|
1291
|
+
removedFieldIds
|
|
1292
|
+
});
|
|
1519
1293
|
}
|
|
1520
1294
|
|
|
1521
|
-
//
|
|
1522
|
-
|
|
1523
|
-
this._recordStore.triggerOnChangeForDirtyPaths(dirtyPaths);
|
|
1524
|
-
return didTableSchemaChange;
|
|
1295
|
+
// Clear out cached field names in case a field was added/removed/renamed.
|
|
1296
|
+
this._cachedFieldNamesById = null;
|
|
1525
1297
|
}
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
fieldData = _step3$value[1];
|
|
1541
|
-
fieldNamesById[_fieldId4] = fieldData.name;
|
|
1542
|
-
}
|
|
1543
|
-
} catch (err) {
|
|
1544
|
-
_iterator3.e(err);
|
|
1545
|
-
} finally {
|
|
1546
|
-
_iterator3.f();
|
|
1547
|
-
}
|
|
1548
|
-
this._cachedFieldNamesById = fieldNamesById;
|
|
1298
|
+
|
|
1299
|
+
// NOTE: Record store onChange triggers must be performed AFTER field onChange triggers to
|
|
1300
|
+
// ensure the column type providers are not stale.
|
|
1301
|
+
this._recordStore.triggerOnChangeForDirtyPaths(dirtyPaths);
|
|
1302
|
+
return didTableSchemaChange;
|
|
1303
|
+
}
|
|
1304
|
+
/**
|
|
1305
|
+
* @internal
|
|
1306
|
+
*/
|
|
1307
|
+
__getFieldNamesById() {
|
|
1308
|
+
if (!this._cachedFieldNamesById) {
|
|
1309
|
+
const fieldNamesById = {};
|
|
1310
|
+
for (const [fieldId, fieldData] of (0, _private_utils.entries)(this._data.fieldsById)) {
|
|
1311
|
+
fieldNamesById[fieldId] = fieldData.name;
|
|
1549
1312
|
}
|
|
1550
|
-
|
|
1313
|
+
this._cachedFieldNamesById = fieldNamesById;
|
|
1551
1314
|
}
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
return (0, _private_utils.isEnumValue)(WatchableTableKeysCore, key);
|
|
1557
|
-
}
|
|
1558
|
-
}]);
|
|
1559
|
-
}(_abstract_model.default);
|
|
1560
|
-
/** @internal */
|
|
1561
|
-
(0, _defineProperty2.default)(TableCore, "_className", 'TableCore');
|
|
1315
|
+
return this._cachedFieldNamesById;
|
|
1316
|
+
}
|
|
1317
|
+
}
|
|
1318
|
+
exports.TableCore = TableCore;
|