@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.
Files changed (481) hide show
  1. package/dist/cjs/base/assert_run_context.js +12 -0
  2. package/dist/cjs/base/index.js +30 -30
  3. package/dist/cjs/base/models/abstract_model_with_async_data.js +154 -237
  4. package/dist/cjs/base/models/base.js +188 -267
  5. package/dist/cjs/base/models/create_aggregators.js +29 -46
  6. package/dist/cjs/base/models/cursor.js +206 -294
  7. package/dist/cjs/base/models/field.js +307 -395
  8. package/dist/cjs/base/models/grouped_record_query_result.js +219 -338
  9. package/dist/cjs/base/models/linked_records_query_result.js +450 -625
  10. package/dist/cjs/base/models/models.js +19 -22
  11. package/dist/cjs/base/models/mutations.js +267 -293
  12. package/dist/cjs/base/models/object_pool.js +117 -156
  13. package/dist/cjs/base/models/record.js +191 -256
  14. package/dist/cjs/base/models/record_coloring.js +6 -6
  15. package/dist/cjs/base/models/record_query_result.js +351 -435
  16. package/dist/cjs/base/models/record_store.js +403 -753
  17. package/dist/cjs/base/models/session.js +125 -153
  18. package/dist/cjs/base/models/table.js +457 -605
  19. package/dist/cjs/base/models/table_or_view_query_result.js +656 -920
  20. package/dist/cjs/base/models/view.js +284 -389
  21. package/dist/cjs/base/models/view_data_store.js +218 -356
  22. package/dist/cjs/base/models/view_metadata_query_result.js +109 -157
  23. package/dist/cjs/base/perform_record_action.js +89 -131
  24. package/dist/cjs/base/sdk.js +129 -184
  25. package/dist/cjs/base/settings_button.js +54 -74
  26. package/dist/cjs/base/types/airtable_interface.js +1 -1
  27. package/dist/cjs/base/types/mutations.js +5 -11
  28. package/dist/cjs/base/types/undo_redo.js +1 -1
  29. package/dist/cjs/base/types/view.js +1 -1
  30. package/dist/cjs/base/ui/base_provider.js +6 -8
  31. package/dist/cjs/base/ui/baymax_utils.js +436 -108
  32. package/dist/cjs/base/ui/block_wrapper.js +81 -106
  33. package/dist/cjs/base/ui/box.js +34 -60
  34. package/dist/cjs/base/ui/button.js +44 -74
  35. package/dist/cjs/base/ui/cell_renderer.js +132 -189
  36. package/dist/cjs/base/ui/choice_token.js +25 -42
  37. package/dist/cjs/base/ui/collaborator_token.js +31 -53
  38. package/dist/cjs/base/ui/color_palette.js +130 -173
  39. package/dist/cjs/base/ui/color_palette_synced.js +41 -70
  40. package/dist/cjs/base/ui/confirmation_dialog.js +70 -120
  41. package/dist/cjs/base/ui/control_sizes.js +24 -22
  42. package/dist/cjs/base/ui/create_detect_element_resize.js +6 -10
  43. package/dist/cjs/base/ui/css_helpers.js +1 -1
  44. package/dist/cjs/base/ui/dialog.js +57 -98
  45. package/dist/cjs/base/ui/dialog_close_button.js +52 -98
  46. package/dist/cjs/base/ui/expand_record.js +1 -2
  47. package/dist/cjs/base/ui/expand_record_list.js +3 -4
  48. package/dist/cjs/base/ui/expand_record_picker_async.js +28 -57
  49. package/dist/cjs/base/ui/field_icon.js +15 -33
  50. package/dist/cjs/base/ui/field_picker.js +25 -70
  51. package/dist/cjs/base/ui/field_picker_synced.js +18 -40
  52. package/dist/cjs/base/ui/form_field.js +27 -55
  53. package/dist/cjs/base/ui/geometry/geometry.js +5 -5
  54. package/dist/cjs/base/ui/geometry/point.js +10 -12
  55. package/dist/cjs/base/ui/geometry/rect.js +36 -52
  56. package/dist/cjs/base/ui/geometry/size.js +10 -12
  57. package/dist/cjs/base/ui/global_alert.js +31 -52
  58. package/dist/cjs/base/ui/heading.js +45 -94
  59. package/dist/cjs/base/ui/icon.js +39 -59
  60. package/dist/cjs/base/ui/icon_config.js +6 -12
  61. package/dist/cjs/base/ui/initialize_block.js +16 -35
  62. package/dist/cjs/base/ui/input.js +62 -101
  63. package/dist/cjs/base/ui/input_synced.js +17 -40
  64. package/dist/cjs/base/ui/key_codes.js +2 -3
  65. package/dist/cjs/base/ui/label.js +30 -55
  66. package/dist/cjs/base/ui/link.js +54 -87
  67. package/dist/cjs/base/ui/loader.js +15 -36
  68. package/dist/cjs/base/ui/modal.js +88 -127
  69. package/dist/cjs/base/ui/model_picker_select.js +18 -44
  70. package/dist/cjs/base/ui/popover.js +236 -328
  71. package/dist/cjs/base/ui/progress_bar.js +34 -47
  72. package/dist/cjs/base/ui/record_card.js +389 -478
  73. package/dist/cjs/base/ui/record_card_list.js +150 -224
  74. package/dist/cjs/base/ui/select.js +60 -116
  75. package/dist/cjs/base/ui/select_and_select_buttons_helpers.js +15 -39
  76. package/dist/cjs/base/ui/select_buttons.js +50 -83
  77. package/dist/cjs/base/ui/select_buttons_synced.js +17 -39
  78. package/dist/cjs/base/ui/select_synced.js +17 -39
  79. package/dist/cjs/base/ui/switch.js +42 -71
  80. package/dist/cjs/base/ui/switch_synced.js +16 -38
  81. package/dist/cjs/base/ui/synced.js +27 -48
  82. package/dist/cjs/base/ui/system/all_styles_set.js +4 -12
  83. package/dist/cjs/base/ui/system/appearance/appearance_set.js +10 -13
  84. package/dist/cjs/base/ui/system/appearance/background_color.js +3 -6
  85. package/dist/cjs/base/ui/system/appearance/border.js +3 -6
  86. package/dist/cjs/base/ui/system/appearance/border_radius.js +3 -6
  87. package/dist/cjs/base/ui/system/appearance/box_shadow.js +3 -6
  88. package/dist/cjs/base/ui/system/appearance/opacity.js +3 -6
  89. package/dist/cjs/base/ui/system/dimensions/dimensions_set.js +11 -13
  90. package/dist/cjs/base/ui/system/dimensions/height.js +3 -6
  91. package/dist/cjs/base/ui/system/dimensions/max_height.js +3 -6
  92. package/dist/cjs/base/ui/system/dimensions/max_width.js +3 -6
  93. package/dist/cjs/base/ui/system/dimensions/min_height.js +3 -6
  94. package/dist/cjs/base/ui/system/dimensions/min_width.js +3 -6
  95. package/dist/cjs/base/ui/system/dimensions/width.js +3 -6
  96. package/dist/cjs/base/ui/system/display.js +3 -6
  97. package/dist/cjs/base/ui/system/flex_container/align_content.js +3 -6
  98. package/dist/cjs/base/ui/system/flex_container/align_items.js +3 -6
  99. package/dist/cjs/base/ui/system/flex_container/flex_container_set.js +11 -13
  100. package/dist/cjs/base/ui/system/flex_container/flex_direction.js +3 -6
  101. package/dist/cjs/base/ui/system/flex_container/flex_wrap.js +3 -6
  102. package/dist/cjs/base/ui/system/flex_container/justify_content.js +3 -6
  103. package/dist/cjs/base/ui/system/flex_container/justify_items.js +3 -6
  104. package/dist/cjs/base/ui/system/flex_item/align_self.js +3 -6
  105. package/dist/cjs/base/ui/system/flex_item/flex.js +3 -6
  106. package/dist/cjs/base/ui/system/flex_item/flex_basis.js +3 -6
  107. package/dist/cjs/base/ui/system/flex_item/flex_grow.js +3 -6
  108. package/dist/cjs/base/ui/system/flex_item/flex_item_set.js +12 -13
  109. package/dist/cjs/base/ui/system/flex_item/flex_shrink.js +3 -6
  110. package/dist/cjs/base/ui/system/flex_item/justify_self.js +3 -6
  111. package/dist/cjs/base/ui/system/flex_item/order.js +3 -6
  112. package/dist/cjs/base/ui/system/index.js +104 -416
  113. package/dist/cjs/base/ui/system/overflow.js +3 -6
  114. package/dist/cjs/base/ui/system/position/bottom.js +4 -6
  115. package/dist/cjs/base/ui/system/position/left.js +4 -6
  116. package/dist/cjs/base/ui/system/position/position.js +3 -6
  117. package/dist/cjs/base/ui/system/position/position_set.js +11 -13
  118. package/dist/cjs/base/ui/system/position/right.js +4 -6
  119. package/dist/cjs/base/ui/system/position/top.js +4 -6
  120. package/dist/cjs/base/ui/system/position/z_index.js +3 -6
  121. package/dist/cjs/base/ui/system/spacing/margin.js +4 -6
  122. package/dist/cjs/base/ui/system/spacing/padding.js +4 -6
  123. package/dist/cjs/base/ui/system/spacing/spacing_set.js +7 -13
  124. package/dist/cjs/base/ui/system/typography/font_family.js +3 -6
  125. package/dist/cjs/base/ui/system/typography/font_size.js +3 -6
  126. package/dist/cjs/base/ui/system/typography/font_style.js +3 -6
  127. package/dist/cjs/base/ui/system/typography/font_weight.js +3 -6
  128. package/dist/cjs/base/ui/system/typography/letter_spacing.js +3 -6
  129. package/dist/cjs/base/ui/system/typography/line_height.js +3 -6
  130. package/dist/cjs/base/ui/system/typography/text_align.js +3 -6
  131. package/dist/cjs/base/ui/system/typography/text_color.js +3 -6
  132. package/dist/cjs/base/ui/system/typography/text_decoration.js +3 -6
  133. package/dist/cjs/base/ui/system/typography/text_transform.js +3 -6
  134. package/dist/cjs/base/ui/system/typography/typography_set.js +15 -13
  135. package/dist/cjs/base/ui/system/utils/ensure_numbers_are_within_scale.js +3 -4
  136. package/dist/cjs/base/ui/system/utils/get_style_props_for_responsive_prop.js +47 -87
  137. package/dist/cjs/base/ui/table_picker.js +18 -42
  138. package/dist/cjs/base/ui/table_picker_synced.js +17 -39
  139. package/dist/cjs/base/ui/text.js +40 -73
  140. package/dist/cjs/base/ui/text_button.js +51 -83
  141. package/dist/cjs/base/ui/theme/default_theme/button_variants.js +3 -3
  142. package/dist/cjs/base/ui/theme/default_theme/control_sizes.js +51 -45
  143. package/dist/cjs/base/ui/theme/default_theme/heading_styles.js +1 -1
  144. package/dist/cjs/base/ui/theme/default_theme/index.js +9 -15
  145. package/dist/cjs/base/ui/theme/default_theme/input_variants.js +3 -3
  146. package/dist/cjs/base/ui/theme/default_theme/link_variants.js +3 -3
  147. package/dist/cjs/base/ui/theme/default_theme/select_buttons_variants.js +4 -4
  148. package/dist/cjs/base/ui/theme/default_theme/select_variants.js +8 -17
  149. package/dist/cjs/base/ui/theme/default_theme/switch_variants.js +23 -29
  150. package/dist/cjs/base/ui/theme/default_theme/text_button_variants.js +5 -5
  151. package/dist/cjs/base/ui/theme/default_theme/text_styles.js +1 -1
  152. package/dist/cjs/base/ui/theme/default_theme/tokens.js +14 -14
  153. package/dist/cjs/base/ui/theme/theme_context.js +2 -2
  154. package/dist/cjs/base/ui/theme/use_theme.js +2 -2
  155. package/dist/cjs/base/ui/tooltip.js +134 -174
  156. package/dist/cjs/base/ui/types/aria_props.js +1 -23
  157. package/dist/cjs/base/ui/types/data_attributes_prop.js +1 -18
  158. package/dist/cjs/base/ui/types/tooltip_anchor_props.js +1 -17
  159. package/dist/cjs/base/ui/ui.js +48 -49
  160. package/dist/cjs/base/ui/unstable_standalone_ui.js +27 -27
  161. package/dist/cjs/base/ui/use_base.js +1 -1
  162. package/dist/cjs/base/ui/use_cursor.js +5 -4
  163. package/dist/cjs/base/ui/use_form_field.js +1 -1
  164. package/dist/cjs/base/ui/use_loadable.js +25 -91
  165. package/dist/cjs/base/ui/use_record_action_data.js +4 -3
  166. package/dist/cjs/base/ui/use_records.js +9 -13
  167. package/dist/cjs/base/ui/use_session.js +1 -1
  168. package/dist/cjs/base/ui/use_settings_button.js +4 -3
  169. package/dist/cjs/base/ui/use_styled_system.js +7 -14
  170. package/dist/cjs/base/ui/use_text_color_for_background_color.js +4 -3
  171. package/dist/cjs/base/ui/use_view_metadata.js +4 -4
  172. package/dist/cjs/base/ui/use_viewport.js +2 -2
  173. package/dist/cjs/base/ui/view_picker.js +26 -70
  174. package/dist/cjs/base/ui/view_picker_synced.js +18 -40
  175. package/dist/cjs/base/ui/viewport_constraint.js +67 -114
  176. package/dist/cjs/base/ui/with_styled_system.js +25 -61
  177. package/dist/cjs/base/undo_redo.js +21 -32
  178. package/dist/cjs/base/unstable_testing_utils.js +27 -27
  179. package/dist/cjs/base/viewport.js +268 -312
  180. package/dist/cjs/injected/airtable_interface.js +4 -4
  181. package/dist/cjs/interface/assert_run_context.js +12 -0
  182. package/dist/cjs/interface/index.js +4 -18
  183. package/dist/cjs/interface/models/base.js +15 -34
  184. package/dist/cjs/interface/models/field.js +5 -19
  185. package/dist/cjs/interface/models/models.js +8 -7
  186. package/dist/cjs/interface/models/mutations.js +50 -66
  187. package/dist/cjs/interface/models/record.js +29 -49
  188. package/dist/cjs/interface/models/record_store.js +25 -57
  189. package/dist/cjs/interface/models/session.js +2 -16
  190. package/dist/cjs/interface/models/table.js +66 -95
  191. package/dist/cjs/interface/sdk.js +61 -87
  192. package/dist/cjs/interface/types/airtable_interface.js +2 -2
  193. package/dist/cjs/interface/types/mutations.js +3 -10
  194. package/dist/cjs/interface/ui/block_wrapper.js +56 -48
  195. package/dist/cjs/interface/ui/initialize_block.js +13 -28
  196. package/dist/cjs/interface/ui/ui.js +20 -19
  197. package/dist/cjs/interface/ui/use_base.js +1 -1
  198. package/dist/cjs/interface/ui/use_custom_properties.js +19 -35
  199. package/dist/cjs/interface/ui/use_records.js +6 -5
  200. package/dist/cjs/interface/ui/use_run_info.js +2 -2
  201. package/dist/cjs/interface/ui/use_session.js +1 -1
  202. package/dist/cjs/shared/color_utils.js +9 -16
  203. package/dist/cjs/shared/colors.js +2 -2
  204. package/dist/cjs/shared/error_utils.js +9 -11
  205. package/dist/cjs/shared/event_tracker.js +3 -3
  206. package/dist/cjs/shared/global_config.js +337 -449
  207. package/dist/cjs/shared/models/abstract_model.js +72 -97
  208. package/dist/cjs/shared/models/base_core.js +394 -514
  209. package/dist/cjs/shared/models/field_core.js +236 -279
  210. package/dist/cjs/shared/models/mutations_core.js +283 -379
  211. package/dist/cjs/shared/models/record_core.js +174 -231
  212. package/dist/cjs/shared/models/record_store_core.js +119 -172
  213. package/dist/cjs/shared/models/session_core.js +116 -170
  214. package/dist/cjs/shared/models/table_core.js +1258 -1501
  215. package/dist/cjs/shared/private_utils.js +54 -124
  216. package/dist/cjs/shared/sdk_core.js +68 -70
  217. package/dist/cjs/shared/types/field_core.js +1 -1
  218. package/dist/cjs/shared/types/mutation_constants.js +4 -4
  219. package/dist/cjs/shared/types/mutations_core.js +1 -1
  220. package/dist/cjs/shared/types/permission_levels.js +1 -1
  221. package/dist/cjs/shared/ui/global_config_synced_component_helpers.js +9 -9
  222. package/dist/cjs/shared/ui/loader.js +14 -35
  223. package/dist/cjs/shared/ui/remote_utils.js +5 -7
  224. package/dist/cjs/shared/ui/sdk_context.js +4 -8
  225. package/dist/cjs/shared/ui/use_array_identity.js +2 -2
  226. package/dist/cjs/shared/ui/use_base.js +6 -5
  227. package/dist/cjs/shared/ui/use_color_scheme.js +3 -8
  228. package/dist/cjs/shared/ui/use_global_config.js +5 -4
  229. package/dist/cjs/shared/ui/use_session.js +6 -5
  230. package/dist/cjs/shared/ui/use_synced.js +7 -5
  231. package/dist/cjs/shared/ui/use_watchable.js +13 -42
  232. package/dist/cjs/shared/ui/with_hooks.js +6 -13
  233. package/dist/cjs/shared/unstable_private_utils.js +4 -6
  234. package/dist/cjs/shared/warning.js +5 -5
  235. package/dist/cjs/shared/watchable.js +110 -176
  236. package/dist/cjs/stats/block_stats.js +62 -85
  237. package/dist/cjs/testing/base/abstract_mock_airtable_interface.js +208 -0
  238. package/dist/cjs/testing/interface/abstract_mock_airtable_interface.js +124 -0
  239. package/dist/types/src/base/assert_run_context.d.ts +2 -0
  240. package/dist/types/src/base/assert_run_context.d.ts.map +1 -0
  241. package/dist/types/src/base/index.d.ts +1 -0
  242. package/dist/types/src/base/index.d.ts.map +1 -1
  243. package/dist/types/src/base/models/models.d.ts +1 -0
  244. package/dist/types/src/base/models/models.d.ts.map +1 -1
  245. package/dist/types/src/base/models/mutations.d.ts.map +1 -1
  246. package/dist/types/src/base/sdk.d.ts.map +1 -1
  247. package/dist/types/src/base/ui/block_wrapper.d.ts +1 -1
  248. package/dist/types/src/base/ui/box.d.ts.map +1 -1
  249. package/dist/types/src/base/ui/button.d.ts +0 -5
  250. package/dist/types/src/base/ui/button.d.ts.map +1 -1
  251. package/dist/types/src/base/ui/cell_renderer.d.ts +1 -22
  252. package/dist/types/src/base/ui/cell_renderer.d.ts.map +1 -1
  253. package/dist/types/src/base/ui/choice_token.d.ts +1 -21
  254. package/dist/types/src/base/ui/choice_token.d.ts.map +1 -1
  255. package/dist/types/src/base/ui/collaborator_token.d.ts +0 -20
  256. package/dist/types/src/base/ui/collaborator_token.d.ts.map +1 -1
  257. package/dist/types/src/base/ui/color_palette.d.ts +1 -32
  258. package/dist/types/src/base/ui/color_palette.d.ts.map +1 -1
  259. package/dist/types/src/base/ui/color_palette_synced.d.ts +0 -14
  260. package/dist/types/src/base/ui/color_palette_synced.d.ts.map +1 -1
  261. package/dist/types/src/base/ui/confirmation_dialog.d.ts +0 -17
  262. package/dist/types/src/base/ui/confirmation_dialog.d.ts.map +1 -1
  263. package/dist/types/src/base/ui/control_sizes.d.ts +0 -1
  264. package/dist/types/src/base/ui/control_sizes.d.ts.map +1 -1
  265. package/dist/types/src/base/ui/dialog.d.ts +1 -23
  266. package/dist/types/src/base/ui/dialog.d.ts.map +1 -1
  267. package/dist/types/src/base/ui/dialog_close_button.d.ts +2 -24
  268. package/dist/types/src/base/ui/dialog_close_button.d.ts.map +1 -1
  269. package/dist/types/src/base/ui/field_icon.d.ts +1 -17
  270. package/dist/types/src/base/ui/field_icon.d.ts.map +1 -1
  271. package/dist/types/src/base/ui/field_picker.d.ts +0 -23
  272. package/dist/types/src/base/ui/field_picker.d.ts.map +1 -1
  273. package/dist/types/src/base/ui/field_picker_synced.d.ts.map +1 -1
  274. package/dist/types/src/base/ui/form_field.d.ts +0 -4
  275. package/dist/types/src/base/ui/form_field.d.ts.map +1 -1
  276. package/dist/types/src/base/ui/heading.d.ts +1 -1
  277. package/dist/types/src/base/ui/heading.d.ts.map +1 -1
  278. package/dist/types/src/base/ui/icon.d.ts +0 -16
  279. package/dist/types/src/base/ui/icon.d.ts.map +1 -1
  280. package/dist/types/src/base/ui/icon_config.d.ts +50 -51
  281. package/dist/types/src/base/ui/icon_config.d.ts.map +1 -1
  282. package/dist/types/src/base/ui/initialize_block.d.ts.map +1 -1
  283. package/dist/types/src/base/ui/input.d.ts +12 -46
  284. package/dist/types/src/base/ui/input.d.ts.map +1 -1
  285. package/dist/types/src/base/ui/input_synced.d.ts.map +1 -1
  286. package/dist/types/src/base/ui/label.d.ts.map +1 -1
  287. package/dist/types/src/base/ui/link.d.ts +1 -5
  288. package/dist/types/src/base/ui/link.d.ts.map +1 -1
  289. package/dist/types/src/base/ui/loader.d.ts +3 -20
  290. package/dist/types/src/base/ui/loader.d.ts.map +1 -1
  291. package/dist/types/src/base/ui/modal.d.ts +1 -14
  292. package/dist/types/src/base/ui/modal.d.ts.map +1 -1
  293. package/dist/types/src/base/ui/model_picker_select.d.ts.map +1 -1
  294. package/dist/types/src/base/ui/popover.d.ts +1 -17
  295. package/dist/types/src/base/ui/popover.d.ts.map +1 -1
  296. package/dist/types/src/base/ui/progress_bar.d.ts +1 -24
  297. package/dist/types/src/base/ui/progress_bar.d.ts.map +1 -1
  298. package/dist/types/src/base/ui/record_card.d.ts +1 -23
  299. package/dist/types/src/base/ui/record_card.d.ts.map +1 -1
  300. package/dist/types/src/base/ui/record_card_list.d.ts +1 -18
  301. package/dist/types/src/base/ui/record_card_list.d.ts.map +1 -1
  302. package/dist/types/src/base/ui/select.d.ts +0 -44
  303. package/dist/types/src/base/ui/select.d.ts.map +1 -1
  304. package/dist/types/src/base/ui/select_and_select_buttons_helpers.d.ts +0 -2
  305. package/dist/types/src/base/ui/select_and_select_buttons_helpers.d.ts.map +1 -1
  306. package/dist/types/src/base/ui/select_buttons.d.ts +0 -22
  307. package/dist/types/src/base/ui/select_buttons.d.ts.map +1 -1
  308. package/dist/types/src/base/ui/select_buttons_synced.d.ts.map +1 -1
  309. package/dist/types/src/base/ui/select_synced.d.ts.map +1 -1
  310. package/dist/types/src/base/ui/switch.d.ts +0 -22
  311. package/dist/types/src/base/ui/switch.d.ts.map +1 -1
  312. package/dist/types/src/base/ui/switch_synced.d.ts.map +1 -1
  313. package/dist/types/src/base/ui/synced.d.ts +2 -8
  314. package/dist/types/src/base/ui/synced.d.ts.map +1 -1
  315. package/dist/types/src/base/ui/system/all_styles_set.d.ts +0 -3
  316. package/dist/types/src/base/ui/system/all_styles_set.d.ts.map +1 -1
  317. package/dist/types/src/base/ui/system/appearance/appearance_set.d.ts +0 -1
  318. package/dist/types/src/base/ui/system/appearance/appearance_set.d.ts.map +1 -1
  319. package/dist/types/src/base/ui/system/appearance/background_color.d.ts +0 -1
  320. package/dist/types/src/base/ui/system/appearance/background_color.d.ts.map +1 -1
  321. package/dist/types/src/base/ui/system/appearance/border.d.ts +0 -1
  322. package/dist/types/src/base/ui/system/appearance/border.d.ts.map +1 -1
  323. package/dist/types/src/base/ui/system/appearance/border_radius.d.ts +0 -1
  324. package/dist/types/src/base/ui/system/appearance/border_radius.d.ts.map +1 -1
  325. package/dist/types/src/base/ui/system/appearance/box_shadow.d.ts +0 -1
  326. package/dist/types/src/base/ui/system/appearance/box_shadow.d.ts.map +1 -1
  327. package/dist/types/src/base/ui/system/appearance/opacity.d.ts +0 -1
  328. package/dist/types/src/base/ui/system/appearance/opacity.d.ts.map +1 -1
  329. package/dist/types/src/base/ui/system/dimensions/dimensions_set.d.ts +0 -1
  330. package/dist/types/src/base/ui/system/dimensions/dimensions_set.d.ts.map +1 -1
  331. package/dist/types/src/base/ui/system/dimensions/height.d.ts +0 -1
  332. package/dist/types/src/base/ui/system/dimensions/height.d.ts.map +1 -1
  333. package/dist/types/src/base/ui/system/dimensions/max_height.d.ts +0 -1
  334. package/dist/types/src/base/ui/system/dimensions/max_height.d.ts.map +1 -1
  335. package/dist/types/src/base/ui/system/dimensions/max_width.d.ts +0 -1
  336. package/dist/types/src/base/ui/system/dimensions/max_width.d.ts.map +1 -1
  337. package/dist/types/src/base/ui/system/dimensions/min_height.d.ts +0 -1
  338. package/dist/types/src/base/ui/system/dimensions/min_height.d.ts.map +1 -1
  339. package/dist/types/src/base/ui/system/dimensions/min_width.d.ts +0 -1
  340. package/dist/types/src/base/ui/system/dimensions/min_width.d.ts.map +1 -1
  341. package/dist/types/src/base/ui/system/dimensions/width.d.ts +0 -1
  342. package/dist/types/src/base/ui/system/dimensions/width.d.ts.map +1 -1
  343. package/dist/types/src/base/ui/system/display.d.ts +0 -1
  344. package/dist/types/src/base/ui/system/display.d.ts.map +1 -1
  345. package/dist/types/src/base/ui/system/flex_container/align_content.d.ts +0 -1
  346. package/dist/types/src/base/ui/system/flex_container/align_content.d.ts.map +1 -1
  347. package/dist/types/src/base/ui/system/flex_container/align_items.d.ts +0 -1
  348. package/dist/types/src/base/ui/system/flex_container/align_items.d.ts.map +1 -1
  349. package/dist/types/src/base/ui/system/flex_container/flex_container_set.d.ts +0 -1
  350. package/dist/types/src/base/ui/system/flex_container/flex_container_set.d.ts.map +1 -1
  351. package/dist/types/src/base/ui/system/flex_container/flex_direction.d.ts +0 -1
  352. package/dist/types/src/base/ui/system/flex_container/flex_direction.d.ts.map +1 -1
  353. package/dist/types/src/base/ui/system/flex_container/flex_wrap.d.ts +0 -1
  354. package/dist/types/src/base/ui/system/flex_container/flex_wrap.d.ts.map +1 -1
  355. package/dist/types/src/base/ui/system/flex_container/justify_content.d.ts +0 -1
  356. package/dist/types/src/base/ui/system/flex_container/justify_content.d.ts.map +1 -1
  357. package/dist/types/src/base/ui/system/flex_container/justify_items.d.ts +0 -1
  358. package/dist/types/src/base/ui/system/flex_container/justify_items.d.ts.map +1 -1
  359. package/dist/types/src/base/ui/system/flex_item/align_self.d.ts +0 -1
  360. package/dist/types/src/base/ui/system/flex_item/align_self.d.ts.map +1 -1
  361. package/dist/types/src/base/ui/system/flex_item/flex.d.ts +0 -1
  362. package/dist/types/src/base/ui/system/flex_item/flex.d.ts.map +1 -1
  363. package/dist/types/src/base/ui/system/flex_item/flex_basis.d.ts +0 -1
  364. package/dist/types/src/base/ui/system/flex_item/flex_basis.d.ts.map +1 -1
  365. package/dist/types/src/base/ui/system/flex_item/flex_grow.d.ts +0 -1
  366. package/dist/types/src/base/ui/system/flex_item/flex_grow.d.ts.map +1 -1
  367. package/dist/types/src/base/ui/system/flex_item/flex_item_set.d.ts +0 -1
  368. package/dist/types/src/base/ui/system/flex_item/flex_item_set.d.ts.map +1 -1
  369. package/dist/types/src/base/ui/system/flex_item/flex_shrink.d.ts +0 -1
  370. package/dist/types/src/base/ui/system/flex_item/flex_shrink.d.ts.map +1 -1
  371. package/dist/types/src/base/ui/system/flex_item/justify_self.d.ts +0 -1
  372. package/dist/types/src/base/ui/system/flex_item/justify_self.d.ts.map +1 -1
  373. package/dist/types/src/base/ui/system/flex_item/order.d.ts +0 -1
  374. package/dist/types/src/base/ui/system/flex_item/order.d.ts.map +1 -1
  375. package/dist/types/src/base/ui/system/index.d.ts +52 -52
  376. package/dist/types/src/base/ui/system/index.d.ts.map +1 -1
  377. package/dist/types/src/base/ui/system/overflow.d.ts +0 -1
  378. package/dist/types/src/base/ui/system/overflow.d.ts.map +1 -1
  379. package/dist/types/src/base/ui/system/position/bottom.d.ts +0 -1
  380. package/dist/types/src/base/ui/system/position/bottom.d.ts.map +1 -1
  381. package/dist/types/src/base/ui/system/position/left.d.ts +0 -1
  382. package/dist/types/src/base/ui/system/position/left.d.ts.map +1 -1
  383. package/dist/types/src/base/ui/system/position/position.d.ts +0 -1
  384. package/dist/types/src/base/ui/system/position/position.d.ts.map +1 -1
  385. package/dist/types/src/base/ui/system/position/position_set.d.ts +0 -1
  386. package/dist/types/src/base/ui/system/position/position_set.d.ts.map +1 -1
  387. package/dist/types/src/base/ui/system/position/right.d.ts +0 -1
  388. package/dist/types/src/base/ui/system/position/right.d.ts.map +1 -1
  389. package/dist/types/src/base/ui/system/position/top.d.ts +0 -1
  390. package/dist/types/src/base/ui/system/position/top.d.ts.map +1 -1
  391. package/dist/types/src/base/ui/system/position/z_index.d.ts +0 -1
  392. package/dist/types/src/base/ui/system/position/z_index.d.ts.map +1 -1
  393. package/dist/types/src/base/ui/system/spacing/margin.d.ts +0 -1
  394. package/dist/types/src/base/ui/system/spacing/margin.d.ts.map +1 -1
  395. package/dist/types/src/base/ui/system/spacing/padding.d.ts +0 -1
  396. package/dist/types/src/base/ui/system/spacing/padding.d.ts.map +1 -1
  397. package/dist/types/src/base/ui/system/spacing/spacing_set.d.ts +0 -1
  398. package/dist/types/src/base/ui/system/spacing/spacing_set.d.ts.map +1 -1
  399. package/dist/types/src/base/ui/system/typography/font_family.d.ts +0 -1
  400. package/dist/types/src/base/ui/system/typography/font_family.d.ts.map +1 -1
  401. package/dist/types/src/base/ui/system/typography/font_size.d.ts +0 -1
  402. package/dist/types/src/base/ui/system/typography/font_size.d.ts.map +1 -1
  403. package/dist/types/src/base/ui/system/typography/font_style.d.ts +0 -1
  404. package/dist/types/src/base/ui/system/typography/font_style.d.ts.map +1 -1
  405. package/dist/types/src/base/ui/system/typography/font_weight.d.ts +0 -1
  406. package/dist/types/src/base/ui/system/typography/font_weight.d.ts.map +1 -1
  407. package/dist/types/src/base/ui/system/typography/letter_spacing.d.ts +0 -1
  408. package/dist/types/src/base/ui/system/typography/letter_spacing.d.ts.map +1 -1
  409. package/dist/types/src/base/ui/system/typography/line_height.d.ts +0 -1
  410. package/dist/types/src/base/ui/system/typography/line_height.d.ts.map +1 -1
  411. package/dist/types/src/base/ui/system/typography/text_align.d.ts +0 -1
  412. package/dist/types/src/base/ui/system/typography/text_align.d.ts.map +1 -1
  413. package/dist/types/src/base/ui/system/typography/text_color.d.ts +0 -1
  414. package/dist/types/src/base/ui/system/typography/text_color.d.ts.map +1 -1
  415. package/dist/types/src/base/ui/system/typography/text_decoration.d.ts +0 -1
  416. package/dist/types/src/base/ui/system/typography/text_decoration.d.ts.map +1 -1
  417. package/dist/types/src/base/ui/system/typography/text_transform.d.ts +0 -1
  418. package/dist/types/src/base/ui/system/typography/text_transform.d.ts.map +1 -1
  419. package/dist/types/src/base/ui/system/typography/typography_set.d.ts +0 -1
  420. package/dist/types/src/base/ui/system/typography/typography_set.d.ts.map +1 -1
  421. package/dist/types/src/base/ui/table_picker.d.ts +0 -21
  422. package/dist/types/src/base/ui/table_picker.d.ts.map +1 -1
  423. package/dist/types/src/base/ui/table_picker_synced.d.ts.map +1 -1
  424. package/dist/types/src/base/ui/text.d.ts +0 -3
  425. package/dist/types/src/base/ui/text.d.ts.map +1 -1
  426. package/dist/types/src/base/ui/text_button.d.ts +1 -5
  427. package/dist/types/src/base/ui/text_button.d.ts.map +1 -1
  428. package/dist/types/src/base/ui/theme/default_theme/index.d.ts +1 -1
  429. package/dist/types/src/base/ui/theme/theme_context.d.ts +1 -1
  430. package/dist/types/src/base/ui/theme/use_theme.d.ts +1 -1
  431. package/dist/types/src/base/ui/tooltip.d.ts +0 -16
  432. package/dist/types/src/base/ui/tooltip.d.ts.map +1 -1
  433. package/dist/types/src/base/ui/types/aria_props.d.ts.map +1 -1
  434. package/dist/types/src/base/ui/types/data_attributes_prop.d.ts +0 -4
  435. package/dist/types/src/base/ui/types/data_attributes_prop.d.ts.map +1 -1
  436. package/dist/types/src/base/ui/types/tooltip_anchor_props.d.ts +0 -7
  437. package/dist/types/src/base/ui/types/tooltip_anchor_props.d.ts.map +1 -1
  438. package/dist/types/src/base/ui/ui.d.ts +1 -0
  439. package/dist/types/src/base/ui/ui.d.ts.map +1 -1
  440. package/dist/types/src/base/ui/view_picker.d.ts +0 -23
  441. package/dist/types/src/base/ui/view_picker.d.ts.map +1 -1
  442. package/dist/types/src/base/ui/view_picker_synced.d.ts.map +1 -1
  443. package/dist/types/src/base/ui/viewport_constraint.d.ts +1 -14
  444. package/dist/types/src/base/ui/viewport_constraint.d.ts.map +1 -1
  445. package/dist/types/src/base/unstable_testing_utils.d.ts +1 -1
  446. package/dist/types/src/base/unstable_testing_utils.d.ts.map +1 -1
  447. package/dist/types/src/interface/assert_run_context.d.ts +2 -0
  448. package/dist/types/src/interface/assert_run_context.d.ts.map +1 -0
  449. package/dist/types/src/interface/index.d.ts +1 -6
  450. package/dist/types/src/interface/index.d.ts.map +1 -1
  451. package/dist/types/src/interface/models/models.d.ts +1 -0
  452. package/dist/types/src/interface/models/models.d.ts.map +1 -1
  453. package/dist/types/src/interface/models/mutations.d.ts.map +1 -1
  454. package/dist/types/src/interface/ui/initialize_block.d.ts.map +1 -1
  455. package/dist/types/src/interface/ui/ui.d.ts +1 -0
  456. package/dist/types/src/interface/ui/ui.d.ts.map +1 -1
  457. package/dist/types/src/interface/ui/use_custom_properties.d.ts +1 -1
  458. package/dist/types/src/shared/models/mutations_core.d.ts.map +1 -1
  459. package/dist/types/src/shared/private_utils.d.ts +0 -9
  460. package/dist/types/src/shared/private_utils.d.ts.map +1 -1
  461. package/dist/types/src/shared/ui/global_config_synced_component_helpers.d.ts +0 -2
  462. package/dist/types/src/shared/ui/global_config_synced_component_helpers.d.ts.map +1 -1
  463. package/dist/types/src/shared/ui/loader.d.ts.map +1 -1
  464. package/dist/types/src/shared/ui/with_hooks.d.ts +2 -2
  465. package/dist/types/src/shared/ui/with_hooks.d.ts.map +1 -1
  466. package/dist/types/src/testing/{abstract_mock_airtable_interface.d.ts → base/abstract_mock_airtable_interface.d.ts} +13 -13
  467. package/dist/types/src/testing/base/abstract_mock_airtable_interface.d.ts.map +1 -0
  468. package/dist/types/src/testing/interface/abstract_mock_airtable_interface.d.ts +51 -0
  469. package/dist/types/src/testing/interface/abstract_mock_airtable_interface.d.ts.map +1 -0
  470. package/package.json +13 -13
  471. package/dist/cjs/base/ui/system/utils/create_responsive_prop_type.js +0 -19
  472. package/dist/cjs/base/ui/system/utils/create_style_prop_types.js +0 -24
  473. package/dist/cjs/base/ui/system/utils/enum_prop_type_utils.js +0 -35
  474. package/dist/cjs/testing/abstract_mock_airtable_interface.js +0 -277
  475. package/dist/types/src/base/ui/system/utils/create_responsive_prop_type.d.ts +0 -2
  476. package/dist/types/src/base/ui/system/utils/create_responsive_prop_type.d.ts.map +0 -1
  477. package/dist/types/src/base/ui/system/utils/create_style_prop_types.d.ts +0 -4
  478. package/dist/types/src/base/ui/system/utils/create_style_prop_types.d.ts.map +0 -1
  479. package/dist/types/src/base/ui/system/utils/enum_prop_type_utils.d.ts +0 -21
  480. package/dist/types/src/base/ui/system/utils/enum_prop_type_utils.d.ts.map +0 -1
  481. 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 _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
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
- var WatchableTableKeysCore = exports.WatchableTableKeysCore = Object.freeze({
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
- var TableCore = exports.TableCore = /*#__PURE__*/function (_AbstractModel) {
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
- function TableCore(parentBase, recordStore, tableId, sdk) {
53
- var _this;
54
- (0, _classCallCheck2.default)(this, TableCore);
55
- _this = _callSuper(this, TableCore, [sdk, tableId]);
56
- /** @internal */
57
- (0, _defineProperty2.default)(_this, "_parentBase", void 0);
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
- (0, _inherits2.default)(TableCore, _AbstractModel);
75
- return (0, _createClass2.default)(TableCore, [{
76
- key: "_dataOrNullIfDeleted",
77
- get: function get() {
78
- var _this$_baseData$table;
79
- return (_this$_baseData$table = this._baseData.tablesById[this._id]) !== null && _this$_baseData$table !== void 0 ? _this$_baseData$table : null;
80
- }
81
- /**
82
- * The base that this table belongs to.
83
- *
84
- * @internal (since we may not be able to return parent model instances in the immutable models world)
85
- * @example
86
- * ```js
87
- * import {base} from '@airtable/blocks/base';
88
- * const table = base.getTableByName('Table 1');
89
- * console.log(table.parentBase.id === base.id);
90
- * // => true
91
- * ```
92
- */
93
- }, {
94
- key: "parentBase",
95
- get: function get() {
96
- return this._parentBase;
97
- }
98
- /**
99
- * The name of the table. Can be watched.
100
- *
101
- * @example
102
- * ```js
103
- * console.log(myTable.name);
104
- * // => 'Table 1'
105
- * ```
106
- */
107
- }, {
108
- key: "name",
109
- get: function get() {
110
- return this._data.name;
111
- }
112
- /**
113
- * The description of the table, if it has one. Can be watched.
114
- *
115
- * @example
116
- * ```js
117
- * console.log(myTable.description);
118
- * // => 'This is my table'
119
- * ```
120
- */
121
- }, {
122
- key: "description",
123
- get: function get() {
124
- return this._data.description;
125
- }
126
- /**
127
- * The table's primary field. Every table has exactly one primary
128
- * field. The primary field of a table will not change.
129
- *
130
- * @example
131
- * ```js
132
- * console.log(myTable.primaryField.name);
133
- * // => 'Name'
134
- * ```
135
- */
136
- }, {
137
- key: "primaryField",
138
- get: function get() {
139
- var primaryField = this.getFieldById(this._data.primaryFieldId);
140
- return primaryField;
141
- }
142
- /**
143
- * The fields in this table. The order is arbitrary, since fields are
144
- * only ordered in the context of a specific view.
145
- *
146
- * Can be watched to know when fields are created or deleted.
147
- *
148
- * @example
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
- * Gets the field matching the given name, or `null` if no field exists with that name in this
220
- * table.
221
- *
222
- * @param fieldName The name of the field you're looking for.
223
- * @example
224
- * ```js
225
- * const field = myTable.getFieldByNameIfExists('Name');
226
- * if (field !== null) {
227
- * console.log(field.id);
228
- * } else {
229
- * console.log('No field exists with that name');
230
- * }
231
- * ```
232
- */
233
- }, {
234
- key: "getFieldByNameIfExists",
235
- value: function getFieldByNameIfExists(fieldName) {
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
- * Gets the field matching the given name. Throws if no field exists with that name in this
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 field;
152
+ return this._fieldModelsById[fieldId];
275
153
  }
276
- /**
277
- * The field matching the given ID or name. Returns `null` if no matching field exists within
278
- * this table.
279
- *
280
- * This method is convenient when building an extension for a specific base, but for more generic
281
- * extensions the best practice is to use the {@link getFieldByIdIfExists} or
282
- * {@link getFieldByNameIfExists} methods instead.
283
- *
284
- * @param fieldIdOrName The ID or name of the field you're looking for.
285
- */
286
- }, {
287
- key: "getFieldIfExists",
288
- value: function getFieldIfExists(fieldIdOrName) {
289
- var _this$getFieldByIdIfE;
290
- return (_this$getFieldByIdIfE = this.getFieldByIdIfExists(fieldIdOrName)) !== null && _this$getFieldByIdIfE !== void 0 ? _this$getFieldByIdIfE : this.getFieldByNameIfExists(fieldIdOrName);
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
- * The field matching the given ID or name. Throws if no matching field exists within this table.
294
- * Use {@link getFieldIfExists} instead if you are unsure whether a field exists with the given
295
- * name/ID.
296
- *
297
- * This method is convenient when building an extension for a specific base, but for more generic
298
- * extensions the best practice is to use the {@link getFieldById} or {@link getFieldByName} methods
299
- * instead.
300
- *
301
- * @param fieldIdOrName The ID or name of the field you're looking for.
302
- */
303
- }, {
304
- key: "getField",
305
- value: function getField(fieldIdOrName) {
306
- var field = this.getFieldIfExists(fieldIdOrName);
307
- if (!field) {
308
- throw (0, _error_utils.spawnError)("No field with ID or name '%s' in table '%s'", fieldIdOrName, this.name);
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
- /** @internal */
313
- }, {
314
- key: "_cellValuesByFieldIdOrNameToCellValuesByFieldId",
315
- value: function _cellValuesByFieldIdOrNameToCellValuesByFieldId(cellValuesByFieldIdOrName, onGenerateIdForNewForeignRecord) {
316
- return Object.fromEntries((0, _private_utils.entries)(cellValuesByFieldIdOrName).map(_ref => {
317
- var _ref2 = (0, _slicedToArray2.default)(_ref, 2),
318
- fieldIdOrName = _ref2[0],
319
- cellValue = _ref2[1];
320
- var field = this.__getFieldMatching(fieldIdOrName);
321
- return [field.id, this._adjustCellValueForFieldIfNecessary(field, cellValue, onGenerateIdForNewForeignRecord)];
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
- // This can be overridden by subclasses. See sdk/src/interface/models/table.ts.
325
- /** @internal */
326
- }, {
327
- key: "_adjustCellValueForFieldIfNecessary",
328
- value: function _adjustCellValueForFieldIfNecessary(field, cellValue, onGenerateIdForNewForeignRecord) {
329
- return cellValue;
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
- * @internal
333
- */
334
- }, {
335
- key: "__getFieldMatching",
336
- value: function __getFieldMatching(fieldOrFieldIdOrFieldName) {
337
- var field;
338
- if (fieldOrFieldIdOrFieldName instanceof _field_core.FieldCore) {
339
- if (fieldOrFieldIdOrFieldName.parentTable.id !== this.id) {
340
- throw (0, _error_utils.spawnError)("Field '%s' is from a different table than table '%s'", fieldOrFieldIdOrFieldName.name, this.name);
341
- }
342
- field = fieldOrFieldIdOrFieldName;
343
- } else {
344
- field = this.getFieldByIdIfExists(fieldOrFieldIdOrFieldName) || this.getFieldByNameIfExists(fieldOrFieldIdOrFieldName);
345
- if (field === null) {
346
- throw (0, _error_utils.spawnError)("Field '%s' does not exist in table '%s'", fieldOrFieldIdOrFieldName, this.name);
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
- if (field.isDeleted) {
350
- throw (0, _error_utils.spawnError)("Field '%s' was deleted from table '%s'", field.name, this.name);
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
- * Updates cell values for a record.
357
- *
358
- * Throws an error if the user does not have permission to update the given cell values in
359
- * the record, or if invalid input is provided (eg. invalid cell values).
360
- *
361
- * Refer to {@link FieldType} for cell value write formats.
362
- *
363
- * This action is asynchronous: `await` the returned promise if you wish to wait for the updated
364
- * cell values to be persisted to Airtable servers.
365
- * Updates are applied optimistically locally, so your changes will be reflected in your extension
366
- * before the promise resolves.
367
- *
368
- * @param recordOrRecordId the record to update
369
- * @param fields cell values to update in that record, specified as object mapping `FieldId` or field name to value for that field.
370
- * @example
371
- * ```js
372
- * function updateRecord(record, recordFields) {
373
- * if (table.hasPermissionToUpdateRecord(record, recordFields)) {
374
- * table.updateRecordAsync(record, recordFields);
375
- * }
376
- * // The updated values will now show in your extension (eg in
377
- * // `table.selectRecords()` result) but are still being saved to Airtable
378
- * // servers (e.g. other users may not be able to see them yet).
379
- * }
380
- *
381
- * async function updateRecordAsync(record, recordFields) {
382
- * if (table.hasPermissionToUpdateRecord(record, recordFields)) {
383
- * await table.updateRecordAsync(record, recordFields);
384
- * }
385
- * // New record has been saved to Airtable servers.
386
- * alert(`record with ID ${record.id} has been updated`);
387
- * }
388
- *
389
- * // Fields can be specified by name or ID
390
- * updateRecord(record1, {
391
- * 'Post Title': 'How to make: orange-mango pound cake',
392
- * 'Publication Date': '2020-01-01',
393
- * });
394
- * updateRecord(record2, {
395
- * [postTitleField.id]: 'Cake decorating tips & tricks',
396
- * [publicationDateField.id]: '2020-02-02',
397
- * });
398
- *
399
- * // Cell values should generally have format matching the output of
400
- * // record.getCellValue() for the field being updated
401
- * updateRecord(record1, {
402
- * 'Category (single select)': {name: 'Recipe'},
403
- * 'Tags (multiple select)': [{name: 'Desserts'}, {id: 'someChoiceId'}],
404
- * 'Images (attachment)': [{url: 'http://mywebsite.com/cake.png'}],
405
- * 'Related posts (linked records)': [{id: 'someRecordId'}],
406
- * });
407
- * ```
408
- */
409
- }, {
410
- key: "updateRecordAsync",
411
- value: (function () {
412
- var _updateRecordAsync = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(recordOrRecordId, fields) {
413
- var recordId;
414
- return _regenerator.default.wrap(function _callee$(_context) {
415
- while (1) switch (_context.prev = _context.next) {
416
- case 0:
417
- recordId = typeof recordOrRecordId === 'string' ? recordOrRecordId : recordOrRecordId.id;
418
- _context.next = 3;
419
- return this.updateRecordsAsync([{
420
- id: recordId,
421
- fields
422
- }]);
423
- case 3:
424
- case "end":
425
- return _context.stop();
426
- }
427
- }, _callee, this);
428
- }));
429
- function updateRecordAsync(_x, _x2) {
430
- return _updateRecordAsync.apply(this, arguments);
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
- return updateRecordAsync;
433
- }()
434
- /**
435
- * Checks whether the current user has permission to perform the given record update.
436
- *
437
- * Accepts partial input, in the same format as {@link updateRecordAsync}.
438
- * The more information provided, the more accurate the permissions check will be.
439
- *
440
- * Returns `{hasPermission: true}` if the current user can update the specified record,
441
- * `{hasPermission: false, reasonDisplayString: string}` otherwise. `reasonDisplayString` may be
442
- * used to display an error message to the user.
443
- *
444
- * @param recordOrRecordId the record to update
445
- * @param fields cell values to update in that record, specified as object mapping `FieldId` or field name to value for that field.
446
- * @example
447
- * ```js
448
- * // Check if user can update specific fields for a specific record.
449
- * const updateRecordCheckResult =
450
- * table.checkPermissionsForUpdateRecord(record, {
451
- * 'Post Title': 'How to make: orange-mango pound cake',
452
- * 'Publication Date': '2020-01-01',
453
- * });
454
- * if (!updateRecordCheckResult.hasPermission) {
455
- * alert(updateRecordCheckResult.reasonDisplayString);
456
- * }
457
- *
458
- * // Like updateRecordAsync, you can use either field names or field IDs.
459
- * const updateRecordCheckResultWithFieldIds =
460
- * table.checkPermissionsForUpdateRecord(record, {
461
- * [postTitleField.id]: 'Cake decorating tips & tricks',
462
- * [publicationDateField.id]: '2020-02-02',
463
- * });
464
- *
465
- * // Check if user could update a given record, when you don't know the
466
- * // specific fields that will be updated yet (e.g. to check whether you should
467
- * // allow a user to select a certain record to update).
468
- * const updateUnknownFieldsCheckResult =
469
- * table.checkPermissionsForUpdateRecord(record);
470
- *
471
- * // Check if user could update specific fields, when you don't know the
472
- * // specific record that will be updated yet. (for example, if the field is
473
- * // selected by the user and you want to check if your extension can write to it).
474
- * const updateUnknownRecordCheckResult =
475
- * table.checkPermissionsForUpdateRecord(undefined, {
476
- * 'My field name': 'updated value',
477
- * // You can use undefined if you know you're going to update a field,
478
- * // but don't know the new cell value yet.
479
- * 'Another field name': undefined,
480
- * });
481
- *
482
- * // Check if user could perform updates within the table, without knowing the
483
- * // specific record or fields that will be updated yet (e.g., to render your
484
- * // extension in "read only" mode).
485
- * const updateUnknownRecordAndFieldsCheckResult =
486
- * table.checkPermissionsForUpdateRecord();
487
- * ```
488
- */
489
- )
490
- }, {
491
- key: "checkPermissionsForUpdateRecord",
492
- value: function checkPermissionsForUpdateRecord(recordOrRecordId, fields) {
493
- var recordId = typeof recordOrRecordId === 'object' && recordOrRecordId !== null ? recordOrRecordId.id : recordOrRecordId;
494
- return this.checkPermissionsForUpdateRecords([{
495
- id: recordId,
496
- fields
497
- }]);
498
- }
499
- /**
500
- * An alias for `checkPermissionsForUpdateRecord(recordOrRecordId, fields).hasPermission`.
501
- *
502
- * Checks whether the current user has permission to perform the given record update.
503
- *
504
- * Accepts partial input, in the same format as {@link updateRecordAsync}.
505
- * The more information provided, the more accurate the permissions check will be.
506
- *
507
- * @param recordOrRecordId the record to update
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
- return updateRecordsAsync;
664
- }()
665
- /**
666
- * Checks whether the current user has permission to perform the given record updates.
667
- *
668
- * Accepts partial input, in the same format as {@link updateRecordsAsync}.
669
- * The more information provided, the more accurate the permissions check will be.
670
- *
671
- * Returns `{hasPermission: true}` if the current user can update the specified records,
672
- * `{hasPermission: false, reasonDisplayString: string}` otherwise. `reasonDisplayString` may be
673
- * used to display an error message to the user.
674
- *
675
- * @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)
676
- * @example
677
- * ```js
678
- * const recordsToUpdate = [
679
- * {
680
- * // Validating a complete record update
681
- * id: record1.id,
682
- * fields: {
683
- * 'Post Title': 'How to make: orange-mango pound cake',
684
- * 'Publication Date': '2020-01-01',
685
- * },
686
- * },
687
- * {
688
- * // Like updateRecordsAsync, fields can be specified by name or ID
689
- * id: record2.id,
690
- * fields: {
691
- * [postTitleField.id]: 'Cake decorating tips & tricks',
692
- * [publicationDateField.id]: '2020-02-02',
693
- * },
694
- * },
695
- * {
696
- * // Validating an update to a specific record, not knowing what
697
- * // fields will be updated
698
- * id: record3.id,
699
- * },
700
- * {
701
- * // Validating an update to specific cell values, not knowing what
702
- * // record will be updated
703
- * fields: {
704
- * 'My field name': 'updated value for unknown record',
705
- * // You can use undefined if you know you're going to update a
706
- * // field, but don't know the new cell value yet.
707
- * 'Another field name': undefined,
708
- * },
709
- * },
710
- * ];
711
- *
712
- * const updateRecordsCheckResult =
713
- * table.checkPermissionsForUpdateRecords(recordsToUpdate);
714
- * if (!updateRecordsCheckResult.hasPermission) {
715
- * alert(updateRecordsCheckResult.reasonDisplayString);
716
- * }
717
- *
718
- * // Check if user could potentially update records.
719
- * // Equivalent to table.checkPermissionsForUpdateRecord()
720
- * const updateUnknownRecordAndFieldsCheckResult =
721
- * table.checkPermissionsForUpdateRecords();
722
- * ```
723
- */
724
- )
725
- }, {
726
- key: "checkPermissionsForUpdateRecords",
727
- value: function checkPermissionsForUpdateRecords(records) {
728
- var includesForeignRowsThatShouldBeCreated = false;
729
- var recordsWithCellValuesByFieldId = records ? records.map(record => ({
730
- id: record.id || undefined,
731
- cellValuesByFieldId: record.fields ? this._cellValuesByFieldIdOrNameToCellValuesByFieldId(record.fields, () => {
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
- }) : undefined
734
- })) : undefined;
735
- return this._sdk.__mutations.checkPermissionsForMutation({
736
- type: _mutations_core.MutationTypesCore.SET_MULTIPLE_RECORDS_CELL_VALUES,
737
- tableId: this.id,
738
- records: recordsWithCellValuesByFieldId,
739
- opts: {
740
- parseDateCellValueInColumnTimeZone: true,
741
- includesForeignRowsThatShouldBeCreated
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
- return deleteRecordAsync;
856
- }()
857
- /**
858
- * Checks whether the current user has permission to delete the specified record.
859
- *
860
- * Accepts optional input, in the same format as {@link deleteRecordAsync}.
861
- * The more information provided, the more accurate the permissions check will be.
862
- *
863
- * Returns `{hasPermission: true}` if the current user can delete the specified record,
864
- * `{hasPermission: false, reasonDisplayString: string}` otherwise. `reasonDisplayString` may be
865
- * used to display an error message to the user.
866
- *
867
- * @param recordOrRecordId the record to be deleted
868
- * @example
869
- * ```js
870
- * // Check if user can delete a specific record
871
- * const deleteRecordCheckResult =
872
- * table.checkPermissionsForDeleteRecord(record);
873
- * if (!deleteRecordCheckResult.hasPermission) {
874
- * alert(deleteRecordCheckResult.reasonDisplayString);
875
- * }
876
- *
877
- * // Check if user could potentially delete a record.
878
- * // Use when you don't know the specific record you want to delete yet (for
879
- * // example, to show/hide UI controls that let you select a record to delete).
880
- * const deleteUnknownRecordCheckResult =
881
- * table.checkPermissionsForDeleteRecord();
882
- * ```
883
- */
884
- )
885
- }, {
886
- key: "checkPermissionsForDeleteRecord",
887
- value: function checkPermissionsForDeleteRecord(recordOrRecordId) {
888
- return this.checkPermissionsForDeleteRecords(recordOrRecordId ? [recordOrRecordId] : undefined);
889
- }
890
- /**
891
- * An alias for `checkPermissionsForDeleteRecord(recordOrRecordId).hasPermission`.
892
- *
893
- * Checks whether the current user has permission to delete the specified record.
894
- *
895
- * Accepts optional input, in the same format as {@link deleteRecordAsync}.
896
- * The more information provided, the more accurate the permissions check will be.
897
- *
898
- * @param recordOrRecordId the record to be deleted
899
- * @example
900
- * ```js
901
- * // Check if user can delete a specific record
902
- * const canDeleteRecord = table.hasPermissionToDeleteRecord(record);
903
- * if (!canDeleteRecord) {
904
- * alert('not allowed');
905
- * }
906
- *
907
- * // Check if user could potentially delete a record.
908
- * // Use when you don't know the specific record you want to delete yet (for
909
- * // example, to show/hide UI controls that let you select a record to delete).
910
- * const canDeleteUnknownRecord = table.hasPermissionToDeleteRecord();
911
- * ```
912
- */
913
- }, {
914
- key: "hasPermissionToDeleteRecord",
915
- value: function hasPermissionToDeleteRecord(recordOrRecordId) {
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
- return deleteRecordsAsync;
979
- }()
980
- /**
981
- * Checks whether the current user has permission to delete the specified records.
982
- *
983
- * Accepts optional input, in the same format as {@link deleteRecordsAsync}.
984
- * The more information provided, the more accurate the permissions check will be.
985
- *
986
- * Returns `{hasPermission: true}` if the current user can delete the specified records,
987
- * `{hasPermission: false, reasonDisplayString: string}` otherwise. `reasonDisplayString` may be
988
- * used to display an error message to the user.
989
- *
990
- * @param recordsOrRecordIds the records to be deleted
991
- * @example
992
- * ```js
993
- * // Check if user can delete specific records
994
- * const deleteRecordsCheckResult =
995
- * table.checkPermissionsForDeleteRecords([record1, record2]);
996
- * if (!deleteRecordsCheckResult.hasPermission) {
997
- * alert(deleteRecordsCheckResult.reasonDisplayString);
998
- * }
999
- *
1000
- * // Check if user could potentially delete records.
1001
- * // Use when you don't know the specific records you want to delete yet (for
1002
- * // example, to show/hide UI controls that let you select records to delete).
1003
- * // Equivalent to table.hasPermissionToDeleteRecord()
1004
- * const deleteUnknownRecordsCheckResult =
1005
- * table.checkPermissionsForDeleteRecords();
1006
- * ```
1007
- */
1008
- )
1009
- }, {
1010
- key: "checkPermissionsForDeleteRecords",
1011
- value: function checkPermissionsForDeleteRecords(recordsOrRecordIds) {
1012
- return this._sdk.__mutations.checkPermissionsForMutation({
1013
- type: _mutations_core.MutationTypesCore.DELETE_MULTIPLE_RECORDS,
1014
- tableId: this.id,
1015
- recordIds: recordsOrRecordIds ? recordsOrRecordIds.map(recordOrRecordId => typeof recordOrRecordId === 'string' ? recordOrRecordId : recordOrRecordId.id) : undefined
1016
- });
1017
- }
1018
- /**
1019
- * An alias for `checkPermissionsForDeleteRecords(recordsOrRecordIds).hasPermission`.
1020
- *
1021
- * Checks whether the current user has permission to delete the specified records.
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
- * Creates a new record with the specified cell values.
1051
- *
1052
- * Throws an error if the user does not have permission to create the given records, or
1053
- * if invalid input is provided (eg. invalid cell values).
1054
- *
1055
- * Refer to {@link FieldType} for cell value write formats.
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
- * An alias for `checkPermissionsForCreateRecord(fields).hasPermission`.
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
- * Creates new records with the specified cell values.
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
- * An alias for `checkPermissionsForCreateRecords(records).hasPermission`.
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
- * @internal
1447
- */
1448
- }, {
1449
- key: "__triggerOnChangeForDirtyPaths",
1450
- value: function __triggerOnChangeForDirtyPaths(dirtyPaths) {
1451
- var didTableSchemaChange = false;
1452
- if (dirtyPaths.name) {
1453
- this._onChange(WatchableTableKeysCore.name);
1454
- didTableSchemaChange = true;
1455
- }
1456
- if (dirtyPaths.lock) {
1457
- didTableSchemaChange = true;
1458
- }
1459
- if (dirtyPaths.externalSyncById) {
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
- } catch (err) {
1506
- _iterator2.e(err);
1507
- } finally {
1508
- _iterator2.f();
1509
- }
1510
- if (addedFieldIds.length > 0 || removedFieldIds.length > 0) {
1511
- this._onChange(WatchableTableKeysCore.fields, {
1512
- addedFieldIds,
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
- // Clear out cached field names in case a field was added/removed/renamed.
1518
- this._cachedFieldNamesById = null;
1287
+ }
1288
+ if (addedFieldIds.length > 0 || removedFieldIds.length > 0) {
1289
+ this._onChange(WatchableTableKeysCore.fields, {
1290
+ addedFieldIds,
1291
+ removedFieldIds
1292
+ });
1519
1293
  }
1520
1294
 
1521
- // NOTE: Record store onChange triggers must be performed AFTER field onChange triggers to
1522
- // ensure the column type providers are not stale.
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
- * @internal
1528
- */
1529
- }, {
1530
- key: "__getFieldNamesById",
1531
- value: function __getFieldNamesById() {
1532
- if (!this._cachedFieldNamesById) {
1533
- var fieldNamesById = {};
1534
- var _iterator3 = _createForOfIteratorHelper((0, _private_utils.entries)(this._data.fieldsById)),
1535
- _step3;
1536
- try {
1537
- for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
1538
- var _step3$value = (0, _slicedToArray2.default)(_step3.value, 2),
1539
- _fieldId4 = _step3$value[0],
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
- return this._cachedFieldNamesById;
1313
+ this._cachedFieldNamesById = fieldNamesById;
1551
1314
  }
1552
- }], [{
1553
- key: "_isWatchableKey",
1554
- value: /** @internal */
1555
- function _isWatchableKey(key) {
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;